/*NEW SHARED SITE*/
//-- Begin
var img = "/images/home/";
//"bkgd24.jpg","kuoni_logo_taj.gif", 
//"bkgd50.jpg""kuoni_logo_people.gif"
//var images=["bkgd-new4.jpg", "leopards.jpg", "bkgd46.jpg",  "bkgd_new_york.jpg", "ski4.jpg" ];
var logo=["kuoni_logo_maldives_island.gif", "kuoni_logo_leopards.gif","kuoni_logo_avignon.gif", "kuoni_logo_new_york.gif", "logo_ski.gif" ];
var bColour =["#b9d5ec", "#88816a",  "#cd9b74", "#dec8c8", "#ffffff" ];
var aColour =["#ffffff", "#ffffff", "#ffffff", "#000000", "#ffffff" ];
var iText = new Array()
iText[0] = '<a href="/holiday/africa_and_indian_ocean/maldives/" title="Maldives holidays">An idyllic Maldivian island paradise</a>';
iText[1] = '<a href="/safari/" title="Safaris">Take a walk on the wild side</a>';
iText[2] = '<a href="/holiday/Europe/" title="Europe holidays">Picturesque cities steeped in history</a>';
//iText[3] = '<a href="/tour/Indian_Subcontinent/India/" title="Tour India">Iconic, exquisite, exotic India</a>';
iText[3] = '<a href="/holiday/USA_and_Canada/United_States/Eastern_States_New_York_index.html" title="New York holidays">Shopping in vibrant New York</a>';
iText[4] = '<a href="/snow/" title="Ski holidays">Carve through fresh powder beneath magnificent mountains</a>';
//iText[5] = '<a href="/snow/" title="Winter holidays">Ski the world</a>';
var imgColour=["img1","img2","img3","img4","img5"];
//var icount = images.length;

var airport = new Array();
airport[0] = 'LHR';
airport[1] = 'LGW';
airport[2] = 'LTN';
airport[3] = 'STN';
airport[4] = 'LCY';
airport[5] = 'BHX';
airport[6] = 'EDI';
airport[7] = 'GLA';
airport[8] = 'MAN';
airport[9] = 'NCL';

var airportField = new Array();
airportField[0] = 'APL001';
airportField[1] = 'APL002';
airportField[2] = 'APL003';
airportField[3] = 'APL004';
airportField[4] = 'APL005';
airportField[5] = 'APO001';
airportField[6] = 'APO002';
airportField[7] = 'APO003';
airportField[8] = 'APO004';
airportField[9] = 'APO005';

//var $ix = rand(images.length);
//var ImgURL = "url(" + img + images[$ix] + ")";
//image1 = new Image();
//image1.src = ImgURL;
//var imgMax = imgColour.length;
//var oldmag;
// End -->


function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


var dom;
dom=document.getElementById?true:false;
var opera;
if(navigator.userAgent.indexOf("Opera")!=-1){opera = true}
var mac;
if(navigator.platform.indexOf("Mac")!=-1){mac = true};

window.onload = init;

//initialisation function
function init(){

	//setupNav();

	if(document.getElementById("book-now")){prePop();}
	if(document.getElementById("book-now")){chkHolType();}
	
	var destField = document.getElementById("destination");
	if(destField){if(destField.type=="text"){destField.onclick=function(){this.value="";}};}
	
	if(document.getElementById("tb")){
		document.getElementById("tb").onfocus = function(){
			document.getElementById("tb").value="";
			}
	}	
}

function chgBkgd(imag){
	var div = "page"
	if (!document.getElementById(div)) return false;
	var $head = document.getElementById(div);
	var $bkgd = $head.style.backgroundImage;
	var ImgAdd = "url(" + img + images[imag] + ")";
	var thisID;
	oldmag = imag;
	document.getElementById('header').style.borderBottom='solid 1px ' + bColour[imag];
	document.getElementById('about').style.color= aColour[imag];
	
	if ($bkgd != ImgAdd) {
		$head.style.backgroundImage = ImgAdd;
	}
	document.getElementById('imgDesc').innerHTML=iText[imag];
	document.getElementById('kunlogo').src = img + logo[imag];
	
		if (oldmag == (imgMax-1)) {
				document.getElementById('prev').innerHTML='<a title="Next image" href="javascript:chgBkgd(oldmag - oldmag)" id="nexti"><small>Next image</small></a>';
	}
		else {
		document.getElementById('prev').innerHTML='<a title="Next image" href="javascript:chgBkgd(oldmag + 1)" id="nexti"><small>Next image</small></a>';
	}
}

//Random background image generator
function bkgrnd() {
var ihtml='Change background image - ';
oldmag = $ix;
var div = "page"
if (!document.getElementById(div)) { return false; }
var $header = document.getElementById(div);
var $backgroundurl = $header.style.backgroundImage;

document.getElementById('prev').innerHTML='<a title="Previous image" href="javascript:chgBkgd(oldmag - 1)" id="previ"><small>Previous image</small></a> <span id="line">|</span> <a title="Next image" href="javascript:chgBkgd(oldmag + 1)" id="nexti"><small>Next image</small></a>';
document.getElementById('imgDesc').innerHTML=iText[$ix];

if (oldmag == (imgMax-1)) {
document.getElementById('prev').innerHTML='<a title="Next image" href="javascript:chgBkgd(oldmag - oldmag)" id="nexti"><small>Next image</small></a>';
	}
	else {
document.getElementById('prev').innerHTML='<a title="Next image" href="javascript:chgBkgd(oldmag + 1)" id="nexti"><small>Next image</small></a>';
	}

document.getElementById('kunlogo').src = img + logo[$ix];
var thisID;

if ($backgroundurl != ImgURL) {
$header.style.backgroundImage = ImgURL; 
}

document.getElementById('header').style.borderBottom='solid 1px ' + bColour[$ix];
document.getElementById('about').style.color=aColour[$ix];


}
function rand(n) {
    return ( Math.floor ( Math.random ( ) * n ) );
}
function addLoadEvent(func) {
    var oldonload = window.onload;
        if (typeof window.onload != 'function') {
        window.onload = func;
        } else {
        window.onload = function() {
    oldonload();
func();
}
}
}
//addLoadEvent(bkgrnd); 

//check to see if the australia option on the book now form is selected- if it is, run the hideDest function
function chkHolType(){
	if(document.getElementById("dest_america_australasia")){if(document.getElementById("dest_america_australasia").checked==true){hideDest();}}
}
//redirect the user base on the value of a dropdown box
function chgURL(x){
	if(x.value=="#" || x.value==""){return false}
	else{document.location.href=x.value;}
}
//Show and hide the predictive text for australia
function hideDest(){
	document.getElementById("dest_ref").className="hide";
	document.getElementById("nights-label").className = "hide";
	document.getElementById("nights").className = "hide";
	document.getElementById("destination-label").value="";
	document.getElementById("code").value="";
}
function showDest(x){
	document.getElementById("dest_ref").className="";
	document.getElementById("nights").className = "";
	document.getElementById("nights-label").className = "";
	if(x.value=="Multiple" || x.value=="M"){document.getElementById("nights-label").innerHTML = "Total nights";}
	else{document.getElementById("nights-label").innerHTML = "Nights";}
	if(x.value=="Multiple" || x.value=="M"){document.getElementById("destination-label").innerHTML = "First destination";}
	else{document.getElementById("destination-label").innerHTML = "Destination";}
}
//popup script
function popup(url,features){window.open(url,'KuoniPopup',features);return false;}
//Switch off features tickboxes--------------------
function unselect(){
	var features = document.getElementById("features-content");
	var input = features.getElementsByTagName("input");
	for(i=0;i<input.length;i++){if(input[i].type=="checkbox"){input[i].checked=false;}}
	chkHotels();
}




//Book Now form waiting screen------------
var test = 0;
function waiting(state){
	var targ = document.getElementById("booknowsearch");
	var waitingI = document.createElement("img");
	waitingI.src="images/searching-button.gif";
	waitingI.alt="Searching...";
	waitingI.style.width="157";
	waitingI.style.height="20";
	targ.appendChild(waitingI);
	targ.removeChild(targ.firstChild);
	return true;
}

//SUBMITTING A FORM---------
function subForm(){
	if (document.BasicReq.PDTTXD.value == 'All destinations') {
		document.BasicReq.PDTTXD.value = '';
	}	
	x = checkFormStep1();
	//x = false;
	
	if(x==true){
	updateCode();
	setHomeCookies();
		if (document.BasicReq.PDTTXD.value == '' && document.BasicReq.TURRFD.value == '') {
		var eDate = new Date();
		eDate.setTime(eDate.getTime() + (86400000 * 150));
		var iDate = document.BasicReq.DPDMYD.value;
		var fDate = new Date(iDate.substring(3,5) + '/' + iDate.substring(0,2)+ '/' + iDate.substring(6));
		if (fDate < eDate) {
			document.BasicReq.action = "http://www.kuoni.co.uk/EN/offers/pages/offers.aspx?DPDMYD=" + iDate + '&NRNTSD=' + document.BasicReq.NRNTSD.value;
			if (document.BasicReq.DPAPTD.value == 'LON') {
				document.BasicReq.action += '&APL000=1&APO000=0';
				for (x=0;x<airport.length;x++) {
					document.BasicReq.action += '&' + airportField[x] + '=';
					if (airportField[x].substring(0,3) == 'APL') {
						document.BasicReq.action += '1';
					}
				}
			}
			else {	
				var airportIx = -1;
				for (x=0;x<airport.length;x++) {
					if (airport[x] == document.BasicReq.DPAPTD.value) {
						airportIx = x;
					}
				}
				if (airportIx != -1) {
					document.BasicReq.action += '&APL000=0&APO000=1';
					for (x=0;x<airport.length;x++) {
						document.BasicReq.action += '&' + airportField[x] + '=';
						if ( x == airportIx) {
							document.BasicReq.action += '1';
						}
					}
				}
			}
			var multicentre = 'document.BasicReq.multiple';
			if(multicentre.checked){
				document.BasicReq.action += '&HTLS2D=1';
			}
			document.BasicReq.action += '&HTLGRD=' + document.BasicReq.HTLGRD.value;
			document.BasicReq.method = "post";
		return true;
		}
		}

	//if(x==true){
		document.BasicReq.src='/images/search_button.gif'
		document.getElementById("bookbutton").src=searching.src;
		searchwaitcms();
		loadGoSecure('ob/x1root');			
		return true;
	}
	else{return false;}		
}

function subFormcms(){
	if (document.BasicReq.PDTTXD.value == 'All destinations') {
		document.BasicReq.PDTTXD.value = '';
	}	
	var x = validate_dob();
	//x = false;
	updateCode();
	setHomeCookies();
	if(x==true){
		if (document.BasicReq.PDTTXD.value == '' && document.BasicReq.TURRFD.value == '') {
			var eDate = new Date();
			eDate.setTime(eDate.getTime() + (86400000 * 150));
			var iDate = document.BasicReq.DPDMYD.value;
			var fDate = new Date(iDate.substring(3,5) + '/' + iDate.substring(0,2)+ '/' + iDate.substring(6));
	//		if (fDate < eDate) {
				document.BasicReq.action = "http://www.kuoni.co.uk/en/offers/pages/offers.aspx?DPDMYD=" + iDate + '&NRNTSD=' + document.BasicReq.NRNTSD.value;
			if (document.BasicReq.DPAPTD.value == 'LON') {
				document.BasicReq.action += '&APL000=ALL&APO000=';
			}
			else {

				for (x=0;x<airport.length;x++) {
					if (airport[x] == document.BasicReq.DPAPTD.value) {
						document.BasicReq.action += '&' + airportField[x] + '=' + airport[x];
					}
				}
			}			
			document.BasicReq.action += '&HTLGRD=' + document.BasicReq.HTLGRD.value;
			document.BasicReq.method = "post";
			return true;
//		}
		}

	//if(x==true){
		//document.BasicReq.src='/images/search_button.gif'
		//document.getElementById("bookbutton").src=searching.src;
		searchwaitcms();
		loadGoSecure('ob/x1root');			
		return true;
	}
	else{return false;}		
}


function loadGoSecure(URLString) {
	var Location;
	Location = "https://" + document.location.hostname;
	if(arguments.length != 0) {
		if (URLString.substring(1,1) == "/") {
			Location = Location + URLString;
		}
		else {
			Location = Location + "/" + URLString ;
		};
	};
	document.BasicReq.action = Location ;	
};

function dosort(sorting){
	document.hfinder.SEQUED.value = sorting;
	document.hfinder.submit();
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

// Normal show info window
var infoWindow ;
var infoOpen = false ;

function closeInfoWindow() {infoOpen=false ;}

function showInfoWindow(srcFile) {
	if (infoOpen) infoWindow.close() ;
	infoWindow=open(srcFile,"infoWindow","menubar,scrollbars,resizable,width=800,height=450,top=5 ") ;
	infoWindow.focus() ;
	infoOpen = true ;
}

 //Experiences show info window
function Showinfowindow(srcFile) {
	if (infoOpen) infoWindow.close() ;
	infoWindow=open(srcFile,"infoWindow","menubar,scrollbars,resizable,width=810,height=560,top=5 ") ;
	infoWindow.focus() ;
	infoOpen = true ;
}



// Go secure
function goSecure(URLString) {
	var Location;
	Location = "https://" + document.location.hostname;
	if(arguments.length != 0) {
		if (URLString.substring(1,1) == "/") {Location = Location + URLString;}
		else {Location = Location + "/" + URLString ;};
	};
	document.location.href = Location ;	
};

function goUnsecure(URLString) {
	var Location;
	Location = "http://" + document.location.hostname;
	if(arguments.length != 0) {
		if (URLString.substring(1,1) == "") {Location = Location + URLString;}
		else {Location = Location + "/" + URLString ;};
	};
	document.location.href = Location ;	
};


function getQueryVariable(variable) {
  var query = window.location.search.substring(1);
  var vars = query.split("&");
  for (var i=0;i<vars.length;i++) {
    var pair = vars[i].split("=");
    if (pair[0] == variable) {
      return pair[1];
    }
  } 
  return "nf";
};

function makeAffiliateCookie(acode,days) {
	var date = new Date();
	date.setTime(date.getTime()+(days*24*60*60*1000));
	var expires = "; expires="+date.toGMTString();
 document.cookie =
  'affiliate=' + acode + expires + '; Cache-Control: Private,Max-Age=3456000; path=/'
 };

 function setAffiliateCookie (days) {
  var affiliate = getQueryVariable("source");
  if (affiliate != "nf") {
   makeAffiliateCookie(affiliate,days)
  };
 };





//SET NEW BK FRM COOKIE
function setHomeCookies(){
	if(document.getElementById("ref")){var touRefVal = document.getElementById("ref").value;}
	if(document.getElementById("centre")){var multiCenVal = document.getElementById("centre").value;}
	if(document.getElementById("destination")){var destVal = document.getElementById("destination").value;}
	if(document.getElementById("nights")){var duration = document.getElementById("nights").value;}
	if(document.getElementById("departure1")){var departVal = document.getElementById("departure1").value;}
	if(document.getElementById("multiple")){var multipleVal = document.getElementById("multiple");}

	var cookieStr ="";

	if(destVal){
		if(document.getElementById("destination").type=="text"){cookieStr+= "destinations="+destVal+":";}
		else{cookieStr+= "destinations="+document.getElementById("destination").options[document.getElementById("destination").selectedIndex].innerHTML+":";}
	}
	
	if(duration){cookieStr+= "duration="+duration+":";}
	if(multiCenVal){cookieStr+= "typeVal="+multiCenVal+":";}
	if(touRefVal){cookieStr+= "tourRef="+touRefVal+":";}
	
	if(departVal){cookieStr+= "departure="+departVal+":";}
	if(multipleVal){cookieStr+= "multiple="+multipleVal.checked+":";}

	SetHomeCookie(cookieStr);
}


function prePop(){

	

	//Check to make sure this booking form is not on the secure server. All secure booking forms have a class of "book-now".
	var secure=false;
	var divs = document.getElementsByTagName("div");
	for(i=0;i<divs.length;i++){if(divs[i].className=="book-now"){secure=true}}

	if(secure==false){
		var touRefVal = document.getElementById("ref");
		
		var destVal = document.getElementById("destination");
		var destDateVal = document.getElementById("code");
		
		var duration = document.getElementById("nights");
		var multiVal = document.getElementById("multiple");
		
		var BookDetails = BookCook.readCookie("BookDetails");
	
		if(BookDetails){
			var details = BookDetails.split(":");
			var j = 0;
			
			for(i=0;i<details.length;i++){details[i] = details[i].split("=");	}

			var z = 0;
			var y = 0;
			var x = 0;
			for(i=0;i<details.length;i++){

				if(details[i][0].indexOf("destinations")!=-1){
					if(destVal){
					if(destVal.type=="text"){destVal.value = details[i][1];}
					if(destVal.type=="select-one"){
						for(v=0;v<destVal.length;v++){if(destVal.options[v].innerHTML==details[i][1]){destVal.options[v].selected="selected";}}
					}
					}
				}
				if(details[i][0].indexOf("departure")!=-1){document.getElementById("departure1").value = details[i][1];}
				if(details[i][0].indexOf("duration")!=-1){
					for(u=0;u<duration.length;u++){if(duration.options[u].value==details[i][1]){duration.options[u].selected="selected";}}	
				}

				if(details[i][0].indexOf("tourRef")!=-1){if(touRefVal){touRefVal=details[i][1];}}
				
				if(details[i][0].indexOf("multiple")!=-1){
					if(multiVal){
						if(details[i][1] == "false") {
							multiVal.checked=false;
						}
						else {
							multiVal.checked=true;
							document.getElementById("centre").value = 'M';
						}
					}
				}
				
				/*if(details[i][0].indexOf("typeVal")!=-1){
					document.getElementById("centre").value = details[i][1];
					if(details[i][1] == "M") {
						document.getElementById("multiple").checked = true;
					}
					else {
						document.getElementById("multiple").checked = false;
					}
				}
				else {
					document.getElementById("centre").value = "S";
					document.getElementById("multiple").checked = false;
				}*/
				
			}

		}
	}
}



function SetHomeCookie(val){BookCook.createCookie("BookDetails", val);}

//Read and write cookies
var BookCook = {
	readCookie:function(name){
		var nameEQ, ca, c;
		nameEQ = name + "=";
		ca = document.cookie.split(';');
		for(var i=0, j = Number(ca.length); i < j; i++){
			c = ca[i];
			while (c.charAt(0)==' '){
				c = c.substring(1,c.length);
			}
			if (c.indexOf(nameEQ) === 0){
				return c.substring(c.indexOf("=")+1,c.length);
			}
		}
		return null;
	},
	
	createCookie:function(name,value,days){
		var d, expires;
		if (days){
			d = new Date();
			d.setTime(d.getTime()+(days*86400000));
			expires = "; expires="+d.toGMTString();
		}else{
			expires = "";
		}
		document.cookie = name+"="+value+expires+"; path=/";
	}
};

function deeplink() {
	var query = window.location.search.substring(1);
	var parms = query.split('&');
	for (var i=0; i<parms.length; i++) {
		var pos = parms[i].indexOf('=');
		if (pos > 0) {
			var key = parms[i].substring(0,pos);
			var val = parms[i].substring(pos+1);
		}
		if (key=='URL' || key=='url') {
			window.location = val;
			return;
		}
	}
}




//Added by TH 04/03/2008 - function to update "code" hidden field on booking form. Will empty the code value if destination field is incorrect.
function updateCode(){
	
	var destField = document.getElementById("destination");
	if(destField){
		if(destField.type=="text"){
			var present=0;
			for(i=0;i<labels.length;i++){
				if(labels[i].indexOf(destField.value)!=-1){present=1;}
			}
			if(destField.value=="" || present==0){document.getElementById("code").value="";}
		}
	}
}

//Added by JCC on 28/03/2008 - function to show insurance questions

function questions() {

if (document.getElementById('insQus').style.display == 'none') {
	document.getElementById('insQus').style.display = 'block';
	
} 
}



//---- NAVIGATION ROLLOVERS & MENU EVENTS ----//
function setupNav(){
	var nItems = new Array(), nItemsI;
	
	if (n = document.getElementById("tabs")){
		nItems = n.getElementsByTagName("a");
		
		for (var i = Number(0), j = Number(nItems.length); i < j; i++){
			nItemsI = nItems[i];
			navImg = nItemsI.getElementsByTagName("img");
			
			if (navImg[0]){
				if (navImg[0].src.indexOf("-on") == -1){
					nItemsI.stored = navImg[0].id;
					nItemsI.onmouseover = imgRoll;
					nItemsI.onmouseout = imgOff;
				}
			}
		}
	}
	
}

//---- NAVIGATION ROLLOVERS PRE-LOADERS ----//
if(document.images){
/*
nav01Roll = new Image();
nav01Roll.src = "images/home/tab-n01-on.gif";
nav01Off = new Image();
nav01Off.src = "images/home/tab-n01.gif";

nav02Roll = new Image();
nav02Roll.src = "images/home/tab-n02-on.gif";
nav02Off = new Image();
nav02Off.src = "images/home/tab-n02.gif";

nav03Roll = new Image();//
nav03Roll.src = "images/home/tab-n03-on.gif";
nav03Off = new Image();
nav03Off.src = "images/home/tab-n03.gif";

nav04Roll = new Image();
nav04Roll.src = "images/home/tab-n04-on.gif";
nav04Off = new Image();
nav04Off.src = "images/home/tab-n04.gif";

nav05Roll = new Image();
nav05Roll.src = "images/home/tab-n05-on.gif";
nav05Off = new Image();
nav05Off.src = "images/home/tab-n05.gif";
*/
}

//---- NAVIGATION ROLLOVERS ----//
function imgRoll(){
	var n = this.stored;
	if(document.getElementById(n)){

		document.getElementById(n).src = eval(n+"Roll").src;

	}
}

function imgOff(){
	var n = this.stored;
	if(document.getElementById(n)){

		document.getElementById(n).src = eval(n+"Off").src;	

	}
}

// MULTI CENTRE UPDATE ON HOME PAGE

function multi() {
	if(document.getElementById('multiple').checked == true)
	{
		document.getElementById('centre').value='M';
	} else {
		document.getElementById('centre').value='S';
	}
}

// SEARCHING POPUP

function searchwait(){
	document.getElementById('nights').style.display='none';
	//document.getElementById('wait').innerHTML='<img id="img_interstitial_wait" src="/images/progress.gif" />';
	
	var theImages = new Array()

theImages[0] = 'interstitial1.jpg'
theImages[1] = 'interstitial2.jpg'
theImages[2] = 'interstitial3.jpg'
theImages[3] = 'interstitial4.jpg'

var p = theImages.length;
var whichImage = Math.floor(Math.random() * p);

document.getElementById('interbit').src='/images/'+theImages[whichImage];

if(document.getElementById('map-area-options')){
document.getElementById('map-area-options').style.display='none';
}
if(document.getElementById('discount')){
	document.getElementById('discount').style.display='none';
}
document.getElementById('searching').style.display='block';
	
	}

function searchwaitcms(){

	document.getElementById('searching').style.display='block';
}


