
function getCookieVal( offset ) {
	var endstr = document.cookie.indexOf( ";", offset );
	if( endstr == -1 )
	{
		endstr = document.cookie.length;
	}
	return unescape( document.cookie.substring( offset, endstr ) );
}

function GetCookie( name ) {
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while( i < clen ) {
		var j = i + alen;
		if( document.cookie.substring( i, j ) == arg ) {
			return getCookieVal( j );
		}
		i = document.cookie.indexOf(" ", i ) + 1;
		if( i == 0 ) {
		break;
		}
	}
	return null;
}

function FixCookieDate( date ) {
	var base = new Date( 0 );
	var skew = base.getTime(); // dawn of( Unix) time - should be 0
	if( skew > 0 )  // Except on the Mac - ahead of its time
	{
		date.setTime( date.getTime() - skew );
	}
}

function SetCookie( name, value, expires, path, domain, secure ){
	document.cookie = name + "=" + escape( value ) +
	( ( expires ) ? "; expires=" + expires.toGMTString() : "" ) +
	( ( path ) ? "; path=" + path : "" ) +
	( ( domain ) ? "; domain=" + domain : "" ) +
	( ( secure ) ? "; secure" : "" );
}

function setCookies(locn){
	expiry=60*60*24*365*1000;
	var expDate=new Date();
	FixCookieDate(expDate);
	expDate.setTime(expDate.getTime()+expiry);
	SetCookie("dhlcom",locn,expDate,'/',null,null);
}

function setupCookie() {
	var pers_locationText="";
	thisForm = document.forms[0];
	pers_location = thisForm.countrySelect.options[thisForm.countrySelect.selectedIndex].value;
	pers_locationText = thisForm.countrySelect.options[thisForm.countrySelect.selectedIndex].text;
	expdate = new Date ();
	FixCookieDate (expdate); 
	expdate.setTime (expdate.getTime() + (365 * 86400000 * 3));
	cookieVal = "" + "!" + "" + "!" + pers_location + "!" + pers_locationText + "!" + 
				"" + "!" + "" + "!" + ""  + "!" + null + "!" + null + "!" + "" + "!" + 
				null + "!" + null + "!" +"" + "!" + "" + "!" + "" ;
	SetCookie("userDetails", cookieVal,expdate,'/');
}

function fnShowAllCtry( field, formName ) {
	var tmpVal;
	var totalElements = searchcountries.length;
	optElm = document.forms[formName].elements[field];
	for( j = 0 ; j < totalElements ; j++ )
	{
		tmpVal = searchcountries[j][1];
		optElm.options[j] = new Option( searchcountries[j][0], tmpVal );
		if (searchcountries[j][0] == ("Select your Location"))
		{
			optElm.options[j].selected = "true";
		}
	}
}
