<!--
/*
setCookie(), getCookie(), deleteCookie()
*/
var cookiesEnabled = false;
var cookiesEnabledKey = 'cookiesEnabled';
var cookieCount = 1;
var pageCookie = 'pageMyvisit';
var myVisit = 'myVisit';
var myValue = '';

// client accepts cookies?

if(document.cookie == '' || getCookie( cookiesEnabledKey ) == 'no cookie by that name' ) {
    document.cookie = 'cookiesEnabled=1'; // set a cookie
    if(document.cookie.indexOf('cookiesEnabled=1') != -1) {// is it there?
	cookiesEnabled = true;
	setCookie( myVisit + cookieCount, '|' );
    }
} else { // already a cookie there, so it must have cookies on
  cookiesEnabled = true;
  cookieCount = getCookie( cookiesEnabledKey );
}

function openMyvisitWindow( link ) {
	if( cookiesEnabled ) {
		openNamedWindow('my_visit',link,275,470,150,150,'no');
	}
	else
		alert("My visit is not available unless allow cookies activated for browser");
}

function openMyvisitWindowArabic( link ) {
	if( cookiesEnabled ) {
		openNamedWindow('my_visit',link,260,500,150,150,'no');
	}
	else
		alert("My visit is not available unless allow cookies activated for browser");
}

function myvisit( pageID, parameters, link) {

	if( cookiesEnabled && pageID != " " ) {

		recordPageVisit( pageID + parameters );
		if( popupActive() )
			openNamedWindow('my_visit',link,260,450,150,150,'no');
	}
}

function myvisitLink( link ) {
	document.location = link;
}

function recordPageVisit(value) {

    if (cookiesEnabled) {
	var pageVisits = getCookie( myVisit + cookieCount );
	if( value.length ){
		while( value.length + pageVisits.length > 4090 ){
			var idx = value.indexOf('|');
			pageVisits = pageVisits.substring(idx + 1);
		}
		setCookie( myVisit + cookieCount, pageVisits + value );
	}
    }
}

//function recordPageVisit(value) {
//    if (cookiesEnabled) {
//	var pageVisits = getCookie( myVisit + cookieCount );
//	if( value.length ){
//		if( value.length + pageVisits.length > 4090 ){
//			if( incrementCookieKey() ){
//				setCookie( myVisit + cookieCount, value );
//			}
//			else alert( 'no room in the cookie!' );
//		}
//		else
//		setCookie( myVisit + cookieCount, pageVisits + value );
//	}
//    }
//}

function incrementCookieKey()
{
	//cookieCount = getCookie( cookiesEnabledKey );
	//cookieCount = (cookieCount * 1)	+ 1;
	//if( cookieCount > 3 )
	//	return false;
	//cookieCount = 2;
	//setCookie( cookiesEnabledKey, cookieCount );
	//alert( 'finishing incrememnt key' );
	//return true;

	return false;
}

function setCookie (name, value, hours, path, domain, secure) {

    if (cookiesEnabled) { 
	if(hours) {
	    if ( (typeof(hours) == 'string') && Date.parse(hours) ) { // already a Date string
		var numHours = hours;
	    } else if (typeof(hours) == 'number') { // calculate Date from number of hours
		var numHours = (new Date((new Date()).getTime() + hours*3600000)).toGMTString();
	    }
	}
	document.cookie = name + '=' + value + ((numHours)?(';expires=' + numHours):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':''); // Set the cookie, adding any parameters that were specified.
    }
}

function getCookie(name) {
    if(document.cookie == '') { // no cookies
	return 'no cookies found ' + document.cookie;
	//return false;
    } else { // there is a cookie
	var firstChar, lastChar;
	var wholeCookie = document.cookie;

	firstChar = wholeCookie.indexOf(name);	// find the start of 'name'
	if((firstChar != -1)) { // if the cookie was found
	    firstChar += name.length + 1; // skip 'name' and '='
	    lastChar = wholeCookie.indexOf(';', firstChar); // find the end of the 'value'
	    if(lastChar == -1) lastChar = wholeCookie.length;
	    return wholeCookie.substring(firstChar, lastChar);
	} else { // no cookie by that name
	    //return false;
	    return 'no cookie by that name';
	}
    }
}

function deleteCookie(name, path, domain) {

  var theValue = getCookie(name); // retrieve the value
  if(theValue) {
      document.cookie = name + '=null; expires=Thu, 01-Jan-1970 00:00:00 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:''); // set an already-expired cookie
  }
}

function popupActive() {
	var cStr = getCookie( pageCookie );
	return ( cStr != "no cookie by that name" && cStr != "null" && cStr.charAt(0) != 'N') ? true : false;
}

function setLanguage(cookiename, languageID)
{
		setCookie( cookiename, languageID, 10000 );
}
// -->