function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function getDefaultCountry () {

	var CheckCountry = getCookie ('SelectCountry');
		CheckCountry = parseInt (CheckCountry);
	
	var DefaultCountry = 0;

	if (CheckCountry) {
		DefaultCountry = CheckCountry + 1;
	} else {
		DefaultCountry = 1;
	}
	//DefaultCountry=3;
	return parseInt (DefaultCountry);
}
DefaultCountry = getDefaultCountry ();

function getDefaultLanguage () {
	var CheckLanguage = getCookie ('SelectLanguage');
	var DefaultLanguage = '';

	switch (parseInt (CheckLanguage)) {
		case 5:
			DefaultLanguage = 5;
			break;
		case 4:
			DefaultLanguage = 4;
			break;
		case 3:
			DefaultLanguage = 3;
			break;
		default:
			DefaultLanguage = 1;
			break;
	}
	//DefaultLanguage=5;
	return DefaultLanguage;
}
DefaultLanguage = getDefaultLanguage ();

function ChangeLanguage (LanguageCode) {
	LanguageCode = parseInt (LanguageCode);

	switch (LanguageCode) {
		case 1:
			setCookie('SelectLanguage', '1', now);
			window.location = ('http://' + server + '/saa_home.html');
			break;
		case 3:
			setCookie('SelectLanguage', '3', now);
			window.location = ('http://' + server + '/saa_home.html');
			break;
		case 4:
			setCookie('SelectLanguage', '4', now);
			window.location = ('http://' + server + '/saa_home.html');
			break;
		case 5:
			setCookie('SelectLanguage', '5', now);
			window.location = ('http://' + server + '/de');
			break;
	}
}

function SaveCountry (CountryCode) {
	CountryCode = parseInt(CountryCode) - 1;
	setCookie('SelectCountry', CountryCode , now);
}

function disablereturn() {
	document.postForm.retDay1.disabled = true;
	document.postForm.retMonth1.disabled = true;
	document.postForm.retYear1.disabled = true;
}

function enablereturn() {
	document.postForm.retDay1.disabled = false;
	document.postForm.retMonth1.disabled = false;
	document.postForm.retYear1.disabled = false;
}

function disableButton (button) {

	if (document.getElementById) {
		button.disabled = true;

	} else if (button) {

		button.oldOnClick = button.onclick;
		button.onclick = null;
		button.oldValue = button.value;
		button.value = 'DISABLED';
  	}
}

function enableButton (button) {
	if (document.all || document.getElementById) {
		button.disabled = false;
	} else if (button) {
		button.onclick = button.oldOnClick;
		button.value = button.oldValue;
	}
}

function openProcess() {
	var x = ((screen.width - 400) / 2);
	var y = ((screen.height - 280) / 2);
     var destination = "http://" + dynamoserver + "/onlineres/include/resflightprocessing_homepage.html";

     window.open(destination, "processing", "width=400,height=280, resizeable=no, top=" + x + ", left=" + y);
}

function ImageLoadFailed() {

	document.images['specials'].src = '/images/homepage_banner.gif?WT.ad=' + CountryDir + '_homepage_banner';

}

function ShowBiz (CountryCode) {
	CountryCode = parseInt (CountryCode);
	CountryDir= CountryCodes[CountryCode][1];
	LanguageCode = getDefaultLanguage ();
	LanguageCode = parseInt (LanguageCode);

	switch (LanguageCode) {
	//--- For DE Language Site ---//
		case 5:
			document.images.specials.src= "/de/images/homepage_banner.gif?WT.ad=" + CountryDir + "_homepage_banner";
			break;
		default:
			if (CountryCode==1) {
				document.images.specials.src= "/images/travel_banner.gif?WT.ad=avis_southernSun_Banner";
			} else {
				document.images.specials.src= "/" + CountryDir  + "/images/homepage_banner.gif?WT.ad=" + CountryDir + "_homepage_banner";
			}
			break;
	}
		switch (CountryCode) {

		case 1:
			document.images.spacer.src= "/images/homepage_banner.gif";
			document.images.spacer.style.cursor='hand';
			document.images.spacer.style.width='302';
			document.images.spacer.style.height='70';
			
			document.images.saabiz.src= "/images/voyCard.gif";
			document.images.saabiz.style.cursor='hand';
			document.images.saabiz.style.width='302';
			document.images.saabiz.style.height='70';
			break;

		case 4 :
			document.images.spacer.src= "/images/spacer.gif";
			document.images.spacer.style.width='0';
			document.images.spacer.style.height='0';
			document.images.spacer.style.cursor='cursor';
			
			document.images.saabiz.src= "/ch/images/homepage_banner.gif?WT.ad=ch_homepage_banner";
			document.images.saabiz.style.cursor='hand';
			document.images.saabiz.style.width='302';
			document.images.saabiz.style.height='70';
			break;
			
		default :
			document.images.spacer.src= "/images/spacer.gif";
			document.images.spacer.style.cursor='hand';
			document.images.spacer.style.width='0';
			document.images.spacer.style.height='0';
			
			document.images.saabiz.src= "/images/voyCard.gif";
			document.images.saabiz.style.cursor='hand';
			document.images.saabiz.style.width='302';
			document.images.saabiz.style.height='70';
	          break;
		}
}

function changeSpacer () {
	//window.open('http://www.saavoyagercreditcard.co.za');
	//window.location="/en/en_content_frameset.html?contents=/travel_support/car_hotel/za_special.html?WT.ac=avis_southernSun_Banner";
	window.open("/travel_support/packages/specials_frameset.html?WT.ac=za_homepage_banner", "Newsletter", "width=600,height=480, resizable=1, scrollbars=1, top=140, left=280");
}

function changeSpecials(checkDefault) {

	var CheckLanguage = getCookie ('SelectLanguage');
	switch (parseInt(CheckLanguage)) {
	case 5:
		var LangDir = "de";
		break;
	default:
		var LangDir = "";
		break;
	}

	CountryDir= CountryCodes[checkDefault][1];
	if (parseInt (checkDefault) > 0) {
		top.frames['specials'].location.replace("http://"+ server + "/" + LangDir + "/homepage/"+ CountryDir +"_specials.html");
	} else {
		top.frames['specials'].location.replace("http://"+ server + "/" + LangDir + "/homepage/default_specials.html");
	}
}

function init() {
	optionTest = true;
	lgth = document.forms['postForm'].depCity1.options.length - 1;

	document.forms['postForm'].depCity1.options[lgth] = null;
	if (document.forms['postForm'].depCity1.options[lgth]) optionTest = false;
}


function populate(Country) {
	if (!optionTest) {
		return;
	}

	var number = parseInt (Country);

	if (!number) {
		return;
	}

	var depCity1 = document.forms['postForm'].depCity1;
	depCity1.options.length = 0;
	var destCity1 = document.forms['postForm'].destCity1;
	destCity1.options.length = 0;

	if (number == 99) {
		list=Departures[number];
		list2=Destinations[number];
		depCity1.options[0]=new Option ("---- Select Region Above ----", "-");
		destCity1.options[0]=new Option ("---- Select Region Above ----", "-");
	} else {
		list=Departures[number].concat(CommonDepartures);
		list2=Destinations[number].concat(CommonDestinations);
		list.sort();
		list2.sort();
		depCity1.options[0]=new Option ("---- Select Departure ----", "-");
		destCity1.options[0]=new Option ("---- Select Destination ----", "-");
	}

	for(i=0;i<list.length;i++) {

		depCity1.options[i+1] = new Option(list[i][0] + " - " + list[i][1], list[i][1]);
	}

	for(j=0;j<list2.length;j++) {
		destCity1.options[j+1] = new Option(list2[j][0] + " - " + list2[j][1], list2[j][1]);
	}
}

function showDefault (Country,NewLanguage) {
	Country=parseInt (Country);
	init ();
	Region=parseInt (CountryCodes[Country][2]);
	document.postForm.DepartRegion.selectedIndex=Region;
	populate (Country);
	ShowBiz (Country);
	changeSpecials(Country);
	SaveCountry (Country);
}

function showSpecials () {
	if (DefaultCountry==1) {
		window.location="/en/en_content_frameset.html?contents=/travel_support/car_hotel/za_special.html?WT.ac=avis_southernSun_Banner";	
	} else {
		hWindow = window.open("/travel_support/packages/specials_frameset.html?WT.ac=" + CountryDir + "_homepage_banner", "Newsletter", "width=600,height=480, resizable=1, scrollbars=1, top=140, left=280");
	}
}

function ChangeBiz () {
	switch (parseInt(DefaultCountry)) {
		case 1 :
			window.open('http://www.saavoyagercreditcard.co.za');
			//window.open('/voyager/en/en_content_frameset.html?contents=/voyager/voy_promo.html');
			break;
		case 4 :
			hWindow = window.open("/travel_support/packages/ch_specials_frameset.html?WT.ac=ch_homepage_banner", "Newsletter", "width=600,height=480, resizable=1, scrollbars=1, top=140, left=280");
			break;
		default :
			//window.open('/voyager/en/en_content_frameset.html?contents=/voyager/voy_promo.html');
			window.open('http://www.saavoyagercreditcard.co.za');
			break;
	}
}

function openWindow(num_window) {
   var hWindow = null;
   switch (num_window) {
	  case 1 :
	      var destination = "https://seal.verisign.com/splash?form_file=fdf/splash.fdf&dn=" + server + "&lang=en";
	      var x = ((screen.width - 550) / 2);
	      var y = ((screen.height - 400) / 2);
	      hWindow = window.open(destination, "Verisign", "width=550,height=400, resizable=1, scrollbars=1, top=" + x + ", left=" +  y + ",location=yes,toolbar=yes");
	      break;
   }
}

function changeHeading(newValue) {
	var aObj = document.getElementById('oldFocus')
	var bObj = document.getElementById('newFocus')
	switch (parseInt (newValue)) {
	case 1:
		bObj.style.fontWeight = 'bolder';
		bObj.style.fontSize = '9pt';
		bObj.style.color = '#0d327e';
		aObj.style.fontWeight = 'normal';
		aObj.style.fontSize = '8pt';
		aObj.style.color = '#3170A9';
		break;
	case 2:
		bObj.style.fontWeight = 'normal';
		bObj.style.fontSize = '8pt';
		bObj.style.color = '#3170A9';
		aObj.style.fontWeight = 'bolder';
		aObj.style.fontSize = '9pt';
		aObj.style.color = '#0d327e';
		break;
	}
}