<!--
// Important: Before doing a release of this file, please make sure that you changed the http thing to https in the cellLink function
// Check for cookies only in the content window or if it's no nav, then in the main window.

//Initialise the host_name for the set cookie function

//host_name = (window.location.hostname).substring((window.location.hostname).indexOf('.'));
//Important please modify opensecurewindow function to point to https rather then http before pushing to prod

host_name = window.location.hostname;

var NS4 = (document.layers)? true:false;
var NS6=document.getElementById&&!document.all?true:false
var IE4 = (document.all)? true:false;

if(NS4 && GetCookie('NS4') == ''){
	SetCookie('NS4', 'TRUE');
}

//check for cookies only in content windows
if( (window.location.pathname).indexOf('/') == -1 ){

	 //if the hostname hertz.co.uk, hertz.fr, etc then forward customer to the main www.hertz.xx site
	 if( host_name.indexOf('autoshopping') == 0 ){
		window.parent.location = 'http://www.' +  host_name + '/noleggio_breve.htm';
	 	
	 }
	 else if( (window.location.pathname).indexOf('/res/') == -1 ){
		document.cookie="COOKIE_CNR=0; path=/";
		
		//cookies should be enabled only for the following sections

		if ( (document.cookie == null || document.cookie == "" || GetCookie("COOKIE_CNR") == '')
			&&(
				(window.location.pathname).indexOf('/login/') > -1 ||
				(window.location.pathname).indexOf('/member/') > -1  ||
				(window.location.pathname).indexOf('/account/') > -1 ||
				(window.location.pathname).indexOf('/support/') > -1 ||
				(window.location.pathname).indexOf('/noleggio_breve.htm') == 0 ||
				window.location.pathname == '' ||
				window.location.pathname == '/'
			)
		){
			document.location = '/cookies_off.html';
		}

		else{
			var CookiesToSearch = new Array("POS", "RQ","CP","CDP","PC","EXL","CARTYPESEXT","DEST_OAG", "GNAV", "PICKUP_DT", "RETURN_DT", "MSC", 'IATANUMBER');
		
			for(i = 0; i < CookiesToSearch.length; i++ ){
				if (GetURLVar(CookiesToSearch[i]) != null && GetURLVar(CookiesToSearch[i]) != '')
					SetCookie(CookiesToSearch[i], GetURLVar(CookiesToSearch[i]));
			}
		}
	}
}


function openWindow(name, url, attributes){
			//if(eval('this.window.' + name) != 'undefined');
			eval(name + ' = null;');
			setTimeout(name +" = window.open('" + url + "', '" + name + "', '" + attributes +"')", 10);
			setTimeout(name + '.focus();',10)
	}

//xxx
//make sure to change the http to https before pushing into prod
function openSecureWindow(name, url, attributes){
			//if(eval('this.window.' + name) != 'undefined');
			eval(name + ' = null;');
			setTimeout(name +" = window.open('" + "https://" + document.location.hostname + url + "', '" + name + "', '" + attributes +"')", 10);
}


function UpdateLoc(OAG_NAME){
	var params_list = '';
	var OAG_PARTS = OAG_NAME.split('|');
	var LOC_NAME = (OAG_PARTS[4] != '') ? OAG_PARTS[3] + ', ' + OAG_PARTS[4] + ', ' + OAG_PARTS[6] : OAG_PARTS[3] + ', ' + OAG_PARTS[6];
	SetCookie("DEST_OAG", OAG_PARTS[0] + '|' + OAG_PARTS[1] + '|' + OAG_PARTS[2] + '|' + LOC_NAME + '|');

	/* We want to keep bg_image, and nav and lev3nav if they were passed in*/
	var URLToSearch = new Array("BG_IMAGE","NAV", "LEV3NAV");
	
	for(i = 0; i < URLToSearch.length; i++ ){
		if (GetURLVar(URLToSearch[i]) != null && GetURLVar(URLToSearch[i]) != '')
			params_list += URLToSearch[i] + '=' + GetURLVar(URLToSearch[i]) + '&';
	}
	
				
	//setTimeout('document.location.search=params_list;document.location.reload(true);',5)
	document.location = document.location.pathname + '?' + params_list + 'x=1';
}



function GetURLVar(VarName){
	var CommandLine=document.location.search; 
	if(CommandLine.length!=0){
	
		VarName = VarName.toUpperCase() + "=";
		VarPos = (CommandLine.toUpperCase()).indexOf(VarName);
		VarLength =	(CommandLine.indexOf("&", VarPos)>=0) ? CommandLine.indexOf("&", VarPos) : CommandLine.length;
		if(VarPos>=0)
			return(unescape(CommandLine.substring(VarPos+VarName.length, VarLength))); 
		else 
			return null;
	}
	else
		return null;
}

function RemoveURLVar( URLString , VarName){ 
	if(URLString.length!=0){
	
		VarName = VarName.toUpperCase() + "=";
		VarPos = (URLString.toUpperCase()).indexOf(VarName);
		VarLength =	(URLString.indexOf("&", VarPos)>=0) ? URLString.indexOf("&", VarPos) : URLString.length;
		if(VarPos>=0)
			return(unescape(URLString.replace(URLString.substring(VarPos, VarLength + 1), ''))); 
		else 
			return null;
	}
	else
		return null;
}

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 '';
}

function SetCookie(name,value){
	document.cookie= name + "=" + value + "; path=/; domain=" + host_name + ";";
}

function DeleteCookie(name){
	document.cookie= name + "=; path=/; domain=" + host_name + "; expires=Mon, 31 Dec 1999 23:59:59 UTC;";
}

function Delete_GNAV(){
	window_toclose = (window.parent != this.window) ? window.parent : this.window;
	if((window_toclose.name).indexOf('popup') != -1)
		window_toclose.onunload = DeleteCookie('GNAV');
}


function SetPermCookie(name, value, expiry_date){
	document.cookie = name + "=" + value +  ";expires=" + expiry_date.toGMTString() + "; path=/; domain=" + host_name + ";";
}

function cellLink(page,secure) {
	//xxx
	// for the production configuration change first 'http' to https
	var HTMLPort = (secure) ? 'https' : 'http'; 
	
	// for non-nav version don't update the parent frame
	if (window.parent.sd2 != null) 
		window.parent.location.href = HTMLPort + '://' + document.location.hostname + page;
	else
		location.href = HTMLPort + '://' + document.location.hostname + page;
}
function GOTORES(params){
	ResPage = (window.parent.sd2 != null) ? '/gaq/index.cfm' : '/resi/index.cfm';

	if( (window.location.pathname).indexOf('/spec/') != -1 )
		params = params + '&spec=y';

	if (params != '')
		ResPage	= ResPage + '?' + params;
	
	cellLink(ResPage, true);
}

function GOTOCLUBS(section){
	var CommandLine=document.location.search;
	// remove the old SECTION value, if there was one
	if(GetURLVar("SECTION") != null)
		CommandLine = RemoveURLVar ( CommandLine , "SECTION");
	CommandLine = (CommandLine.length == 0) ? '?' : CommandLine + '&';
	if((section.split('#')).length == 1)
		CommandLine = CommandLine + 'SECTION=' + section;
	else
		CommandLine = CommandLine + 'SECTION=' + (section.split('#'))[0] + '&' +'SECTION_LINK=' + (section.split('#'))[1];
	window.location = window.location.pathname + CommandLine;
}

function JoinNowClub(Club_Number){
	cellLink('/enroll/index.cfm?MEM_LEV=' + Club_Number + '&lev2=0', true);
}

function CheckPopup(page,secure){

	if((window.parent.name).indexOf('popup') != -1){
		window.parent.close();
		
		if(page.indexOf('resi/') != -1) window.parent.opener.GOTORES('');
		window.parent.opener.cellLink(page, secure);
	}
	else
		if(page.indexOf('resi/') != -1) GOTORES('');
		cellLink(page, secure);
}

function GO_FROM_OLDLOCATION(){

	if( (document.location.pathname).split('/').length > 1)
		MainDir = (document.location.pathname).split('/')[1];
	else
		MainDir = '';

	switch(MainDir.toUpperCase()){
		case 'FLEET': LD = 'FLEET';break;
		case 'POLICY': LD = 'POLICY';break;
		case 'LOC': LD = 'LOCATIONS';break;
		case 'AGENT': LD = 'AGENT';break;
		case 'COMPANY': LD = 'COMPANY'; break;
		case 'LOCATIONS': LD = 'LOCATIONS';break;
		case 'MEMBER': LD = 'MEMBER';break;
		case 'PART': LD = 'PART';break;
		case 'RES': LD = 'RESI';break;
		case 'RESI': LD = 'RESI';break;
		case 'SITEMAP': LD = 'SITEMAP';break;
		case 'SPEC': LD = 'SPEC';break;
		case 'ASSOCIATION': LD = 'ASSOCIATION';break;
		case 'CORP': LD = 'CORP';break;
		case 'GOLD': LD = 'GOLD';break;
		case 'SERV': LD = ((document.location.pathname).split('/').length > 2 && (document.location.pathname).split('/')[2] ) ? 'GOLDCORP' : 'HOME' ;	break;
		default : LD = 'HOME'
	}
	var CommandLine=document.location.search;
	CommandLine = (CommandLine.length == 0) ? '?' : CommandLine + '&';

	var temp = GetURLVar('nav');
	if((MainDir.toUpperCase() == 'RES' || MainDir.toUpperCase() == 'RESI') && temp != null && (temp).toUpperCase() == 'FALSE')
		window.location = 'https://' + document.location.hostname + '/resi/index.cfm' + CommandLine;
	else{
		window.location = '/param.cfm' + CommandLine + 'LD=' + LD;
}
}

function NG_Iframe_Create(size){
	dimensions = size.split('x');

	if(!NS4)
		document.write('<iframe src="/NG_Call.cfm?size=' + size + '" width="' + dimensions[0] + '" height="' + dimensions[1] + '" MARGINwidth=0 MARGINHEIGHT=0 HSPACE=0 VSPACE=0 FRAMEBORDER=0 SCROLLING=no BORDERCOLOR="#000000"></iframe>');
	else
		document.write('<layer top="20" left="200" name="ngad" src="/NG_Call.cfm?size=' + size + '" width="' + dimensions[0] + '" height="' + dimensions[1] + '"  frameborder="0" border="0" scrolling="no" BORDERCOLOR="#000000" class="regular"></layer>');
}

// -->

