function updateMap(im){

	if(im){
		document.getElementById("worldMap").src="/images/map/world-"+im+".gif";
	}
	else{
		document.getElementById("worldMap").src="/images/map/world.gif";
	}

}


function updateLargeMap(im){

	if(im){
		document.getElementById("largeWorld").src="/images/map/world-lg-"+im+".gif";
	}
	else{
		document.getElementById("largeWorld").src="/images/map/world-lg.gif";
	}

}

function updateMapAustralasia(im){

	if(im){
		document.getElementById("mapAustralasia").src="/images/map/australasia/area_aust_"+im+".gif";
	}
	else{
		document.getElementById("mapAustralasia").src="/images/map/australasia/area_aust.gif";
	}

}

function updateMapAfrica(im){
	
	if(im){
		document.getElementById("mapAfrica").src="/images/map/southafrica/area_safrica_"+im+".gif";
	}
	else{
		document.getElementById("mapAfrica").src="/images/map/southafrica/area_safrica.gif";
	}

}
 

function updateMapFarEast(im){
	
	if(im){
		document.getElementById("mapFarEast").src="/images/map/fareast/area_fareast_"+im+".gif";
	}
	else{
		document.getElementById("mapFarEast").src="/images/map/fareast/area_fareast.gif";
	}

}

function updateMapNorthAmerica(im){
	
	if(im){
		document.getElementById("MapNorthAmerica").src="/images/map/northamerica/area_namer_"+im+".gif";
	}
	else{
		document.getElementById("MapNorthAmerica").src="/images/map/northamerica/area_namer.gif";
	}

}


function updateMapSouthAmerica(im){
	
	if(im){
		document.getElementById("MapSouthAmerica").src="/images/map/southamerica/area_samer_"+im+".gif";
	}
	else{
		document.getElementById("MapSouthAmerica").src="/images/map/southamerica/area_samer.gif";
	}

}

function updateMapIndian(im){
	
	if(im){
		document.getElementById("MapIndian").src="/images/map/indiansubcontinent/area_india_"+im+".gif";
	}
	else{
		document.getElementById("MapIndian").src="/images/map/indiansubcontinent/area_india.gif";
	}

}


function updateMapCaribbean(im){
	
	if(im){
		document.getElementById("MapCaribbean").src="/images/map/caribbean/area_carri_"+im+".gif";
	}
	else{
		document.getElementById("MapCaribbean").src="/images/map/caribbean/area_carri.gif";
	}

}


function updateMapEurope(im){
	
	if(im){
		document.getElementById("MapEurope").src="/images/map/europe/europe_wide/area_europe_"+im+".gif";
	}
	else{
		document.getElementById("MapEurope").src="/images/map/europe/europe_wide/area_europe.gif";
	}

}


function updateMapNorthAfrica(im){
	
	if(im){
		document.getElementById("mapNorthAfrica").src="/images/map/northafrica/area_nafrica_"+im+".gif";
	}
	else{
		document.getElementById("mapNorthAfrica").src="/images/map/northafrica/area_nafrica.gif";
	}

}


function updateMapIndianSubcontinent(im){
	
	if(im){
		document.getElementById("MapIndianSubcontinent").src="/images/map/indiansubcontinent/area_india_"+im+".gif";
	}
	else{
		document.getElementById("MapIndianSubcontinent").src="/images/map/indiansubcontinent/area_india.gif";
	}

}


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(){
	if(document.getElementById("book-now")){chkHolType();}
	
		roomNum = document.getElementById("total_room_no");

		r1c = document.getElementById("room_1_children");
		r1i = document.getElementById("room_1_infants");
		r2c = document.getElementById("room_2_children");
		r2i = document.getElementById("room_2_infants");
		r3c = document.getElementById("room_3_children");
		r3i = document.getElementById("room_3_infants");
		r4c = document.getElementById("room_4_children");
		r4i = document.getElementById("room_4_infants");
		r5c = document.getElementById("room_5_children");
		r5i = document.getElementById("room_5_infants");
		r6c = document.getElementById("room_6_children");
		r6i = document.getElementById("room_6_infants");
		r7c = document.getElementById("room_7_children");
		r7i = document.getElementById("room_7_infants");
		r8c = document.getElementById("room_8_children");
		r8i = document.getElementById("room_8_infants");
		r9c = document.getElementById("room_9_children");
		r9i = document.getElementById("room_9_infants");
		

                if(roomNum){if(roomNum.value!=""){showHideRooms(roomNum.value)}}
		
		if(r1c){if(r1c.value!=""){showHideDob(1, r1c.value, 1);}}
		if(r2c){if(r2c.value!=""){showHideDob(2, r2c.value, 1);}}
		if(r3c){if(r3c.value!=""){showHideDob(3, r3c.value, 1);}}
		if(r4c){if(r4c.value!=""){showHideDob(4, r4c.value, 1);}}
		if(r5c){if(r5c.value!=""){showHideDob(5, r5c.value, 1);}}
		if(r6c){if(r6c.value!=""){showHideDob(6, r6c.value, 1);}}
		if(r7c){if(r7c.value!=""){showHideDob(7, r7c.value, 1);}}
		if(r8c){if(r8c.value!=""){showHideDob(8, r8c.value, 1);}}
		if(r9c){if(r9c.value!=""){showHideDob(9, r9c.value, 1);}}
		
		
		if(r1i){if(r1i.value!=""){showHideDob(1, r1i.value, 2);}}
		if(r2i){if(r2i.value!=""){showHideDob(2, r2i.value, 2);}}
		if(r3i){if(r3i.value!=""){showHideDob(3, r3i.value, 2);}}
		if(r4i){if(r4i.value!=""){showHideDob(4, r4i.value, 2);}}
		if(r5i){if(r5i.value!=""){showHideDob(5, r5i.value, 2);}}
		if(r6i){if(r6i.value!=""){showHideDob(6, r6i.value, 2);}}
		if(r7i){if(r7i.value!=""){showHideDob(7, r7i.value, 2);}}
		if(r8i){if(r8i.value!=""){showHideDob(8, r8i.value, 2);}}
		if(r9i){if(r9i.value!=""){showHideDob(9, r9i.value, 2);}}
	
}

//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 - and empty out the predictive text values
function hideDest(){
	document.getElementById("dest_ref").className="hide";
	document.getElementById("nights").innerHTML = "Nights";
	document.getElementById("destination-label").value="";
	document.getElementById("code").value="";
}

function showDest(x){
	document.getElementById("dest_ref").className="";
	if(x.value=="Multiple" || x.value=="M"){document.getElementById("nights").innerHTML = "Total nights";}
	else{document.getElementById("nights").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();
}


//Filters
function chkHotels(){

	var features = document.getElementById("features-content");
	var input = features.getElementsByTagName("input");
	var tickboxes = new Array();
	var selected = new Array();
	var j=0;
	var k=0;
	
	for(i=0;i<input.length;i++){
		if(input[i].type=="checkbox"){tickboxes[j]=input[i];j++;}
	}

	for(i=0;i<tickboxes.length;i++){
		if(tickboxes[i].checked==true){selected[k]=1;}
		else{selected[k]=0;}
		k++;
	}

	var hotelCount = 0
	
	for(i=0;i<hFeat.length;i++){
		var f=0;
		amountCheck = new Array();
		
		for(h=0;h<hFeat[i].length;h++){
			if(selected[h]==1 && hFeat[i][h]==0){amountCheck[f]=false;f++;}
			else{amountCheck[f]=true;f++;}
		}		

		validHotel = true;
		
		for(g=0;g<amountCheck.length;g++){
			if(amountCheck[g]==false){validHotel = false;}
		}

		if(validHotel==true){hotelCount++;}			
	}

	if(hotelCount==0){
		document.getElementById("hotel-count").innerHTML = "<strong><span class=\"highlight\" style=\"color:#F00\">"+hotelCount+" hotels</span></strong> are";
		document.getElementById("view-hotels").disabled=true;
		document.getElementById("view-hotels").src="/images/b-view-hotels-disabled.gif";
		document.getElementById("view-hotels").style.cursor="default";
	}
	else if(hotelCount==1){
		document.getElementById("hotel-count").innerHTML = "<strong>"+hotelCount+" hotel</strong> is";
		document.getElementById("view-hotels").disabled=false;
		document.getElementById("view-hotels").src="/images/b-view-hotels.gif";
		document.getElementById("view-hotels").style.cursor="";
	}
	else{
		document.getElementById("hotel-count").innerHTML = "<strong>"+hotelCount+" hotels</strong> are";
		document.getElementById("view-hotels").disabled=false;
		document.getElementById("view-hotels").src="/images/b-view-hotels.gif";
		document.getElementById("view-hotels").style.cursor="";
	}	

	
}

//Show/Hide features on hotel list page ---------------------------
function hideFeatures(){
	if(document.getElementById("features-content")){
		document.getElementById("features-content").className="hide";
		document.getElementById("features-bottom").className="hide";
	}
	document.getElementById("hideL").removeChild(document.getElementById("hideL").firstChild);
	var a = document.createElement("a");
	a.setAttribute("href","javascript:showFeatures();");
	a.setAttribute("class","show");
	a.setAttribute("className","show");
	a.appendChild(document.createTextNode("Show features"));
	document.getElementById("hideL").appendChild(a);
}

function showFeatures(){
	if(document.getElementById("features-content")){
		document.getElementById("features-content").className="";
		document.getElementById("features-bottom").className="clear";
	}
	document.getElementById("hideL").removeChild(document.getElementById("hideL").firstChild);
	var a = document.createElement("a");
	a.setAttribute("href","javascript:hideFeatures();");
	a.setAttribute("class","");
	a.setAttribute("className","");
	a.appendChild(document.createTextNode("Close features"));
	document.getElementById("hideL").appendChild(a);
}



function hideRes(){

	var listDivs = document.getElementsByTagName("div");

	var uncheckL = document.createElement("a");
	uncheckL.setAttribute("href","javascript:unselect();")
	uncheckL.appendChild(document.createTextNode("Uncheck all"));
	document.getElementById("uncheck").appendChild(uncheckL);
	
	var j=0;
	for(i=0;i<listDivs.length;i++){
		if(listDivs[i].id.indexOf("hot-res-")!=-1){resDivs[j]=listDivs[i].id;j++;}
	}
	for(i=dispLength;i<resDivs.length;i++){
		document.getElementById(resDivs[i]).style.display = "none";
	}
	
	var pageDiv = document.getElementById("pagination");

	linkCount = Math.ceil(resDivs.length/dispLength);
	
	var k = 0;
	
	for(i=0;i<linkCount;i++){
		j=i+1;
		links[i] = createLink("#","showRes("+k+");",j);
		k=j*dispLength;
	}
	
	var firstPage = document.createElement("li");
	var prevPage = document.createElement("li");
	var nextPage = document.createElement("li");
	var lastPage = document.createElement("li");
	
	var firstPageA = document.createElement("a");
	var prevPageA = document.createElement("a");
	var nextPageA = document.createElement("a");
	var lastPageA = document.createElement("a");

	var firstPageI = document.createElement("img");
	var prevPageI = document.createElement("img");
	var nextPageI = document.createElement("img");
	var lastPageI = document.createElement("img");
	
	firstPageI.setAttribute("src","/images/ico-pag-start.gif");
	firstPageI.setAttribute("alt","Go to the first page of results");
	prevPageI.setAttribute("src","/images/ico-pag-previous.gif");
	prevPageI.setAttribute("alt","Go to the previous page of results");
	nextPageI.setAttribute("src","/images/ico-pag-next.gif");
	nextPageI.setAttribute("alt","Go to the next page of results");	
	lastPageI.setAttribute("src","/images/ico-pag-last.gif");
	lastPageI.setAttribute("alt","Go to the last page of results");	
	
	firstPageA.setAttribute("href","#");
	firstPageA.setAttribute("href","javascript:showRes(0);");
	prevPageA.setAttribute("id","prevPageL");
	prevPageA.setAttribute("href","javascript:showRes(0);");
	nextPageA.setAttribute("id","nextPageL");
	nextPageA.setAttribute("href","javascript:showRes(5);");
	lastPageC = (linkCount -1)*dispLength
	lastPageA.setAttribute("href","#");
	lastPageA.setAttribute("href","javascript:showRes("+lastPageC+");");
	
	firstPageA.appendChild(firstPageI);
	firstPage.appendChild(firstPageA);
	prevPageA.appendChild(prevPageI);
	prevPage.appendChild(prevPageA);	
	nextPageA.appendChild(nextPageI);
	nextPage.appendChild(nextPageA);	
	lastPageA.appendChild(lastPageI);
	lastPage.appendChild(lastPageA);	
	
	
	pageDiv.appendChild(firstPage);
	pageDiv.appendChild(prevPage);
	
	//This bit calls the createLink function create all the numbered links
	//for(i=0;i<links.length;i++){
	//pageDiv.appendChild(links[i]);
	//}
	
	var pageAmount = document.createElement("li");
	pageAmount.setAttribute("id","page-position")
	pageAmount.appendChild(document.createTextNode("page 1 of "+links.length+""));
	pageDiv.appendChild(pageAmount);
	
	pageDiv.appendChild(nextPage);
	pageDiv.appendChild(lastPage);	

	//Do a check for the amount of hotels matching the selected criteria
	chkHotels();

}

//This function creates the numbered links for the pagination--
function createLink(url,js,txt){
	x = document.createElement("li");
	xa = document.createElement("a");
	xa.setAttribute("href","javascript:"+js);
	//xa.setAttribute("onclick",js);
	xa.appendChild(document.createTextNode(txt));
	x.appendChild(xa);	
	return x;
}


function showRes(start){

	var end = start+dispLength;
	var currentPage = start/dispLength;
	currentPage++;
	for(i=0;i<resDivs.length;i++){
		if(document.getElementById(resDivs[i]))document.getElementById(resDivs[i]).style.display = "none";
	}
	for(i=start;i<end;i++){
		if(document.getElementById(resDivs[i]))document.getElementById(resDivs[i]).style.display = "block";
	}
	
	if(start!=0){
		prevPageC = start-dispLength;
		document.getElementById("prevPageL").setAttribute("href","javascript:showRes("+prevPageC+")");
	}
	else{
		document.getElementById("prevPageL").setAttribute("href","javascript:showRes(0)");
	}
	
	nextPageC = start+dispLength;
	
	if(nextPageC<=((linkCount-1)*dispLength)){
		document.getElementById("nextPageL").setAttribute("href","javascript:showRes("+nextPageC+")");
		//document.getElementById("nextPageL").setAttribute("href",nextPageC);
	}
	else{
		test = end-dispLength;
		document.getElementById("nextPageL").setAttribute("href","javascript:showRes("+test+")");
		//document.getElementById("nextPageL").setAttribute("href",end);
	}
	
	document.getElementById("page-position").innerHTML = "page "+currentPage+" of "+links.length+""
}







//Book Now form waiting screen------------
var test = 0;
function waiting(state){
	
	var targ = document.getElementById("booknowsearch");
	var waitingI = document.createElement("img");
	
	//waitingI.setAttribute("src","/images/searching-button.gif");
	waitingI.setAttribute("src","/images/searching-button.gif");
	
	waitingI.setAttribute("alt","Searching...");
	waitingI.setAttribute("width","157");
	waitingI.setAttribute("height","20");
	targ.appendChild(waitingI);
	targ.removeChild(targ.firstChild);
	
	return true;

}






//SUBMITTING A FORM---------
function subForm(){
	x = checkFormStep1();
	if(x==true){
	loadGoSecure('ob/x1root');
	return true;
	}
	else{return false;}
	
}

function loadGoSecure(x){
	alert(x)
}



//RESOLUTION SWITCHER---------------------------------------------------------------------------------------


function addLoadListener(fn){
	if (typeof window.addEventListener != 'undefined'){window.addEventListener('load', fn, false);}
	else if (typeof document.addEventListener != 'undefined'){document.addEventListener('load', fn, false);}
	else if (typeof window.attachEvent != 'undefined'){window.attachEvent('onload', fn);}
	else{return false;}
	return true;
};

function attachEventListener(target, eventType, functionRef, capture){
    if (typeof target.addEventListener != "undefined"){target.addEventListener(eventType, functionRef, capture);}
    else if (typeof target.attachEvent != "undefined"){target.attachEvent("on" + eventType, functionRef);}
    else{return false;}
    return true;
};

checkBrowserWidth();
attachEventListener(window, "resize", checkBrowserWidth, false);

function checkBrowserWidth(){
	if(mac !=true){
	var theWidth = getBrowserWidth();
	
	if (theWidth == 0){
		var resolutionCookie = document.cookie.match(/(^|;)fc_layout[^;]*(;|$)/);
		if (resolutionCookie != null){
			setStylesheet(unescape(resolutionCookie[0].split("=")[1]));
		}
		
		addLoadListener(checkBrowserWidth);
		return false;
	}

	if (theWidth > 950){
		setStylesheet("Large");
		document.cookie = "kuoni_layout=" + escape("Large");

	}
	else{
		setStylesheet("Small");
		document.cookie = "kuoni_layout=" + escape("Small");		
	}
	return true;
	}
};

function getBrowserWidth(){
	if (window.innerWidth){return window.innerWidth;}
	else if (document.documentElement && document.documentElement.clientWidth != 0){return document.documentElement.clientWidth;}
	else if (document.body){return document.body.clientWidth;}
	return 0;
};

function setStylesheet(styleTitle){
	var currTag;
	if (document.getElementsByTagName){
		for (var i = 0; (currTag = document.getElementsByTagName("link")[i]); i++){
			if (currTag.getAttribute("rel").indexOf("style") != -1 && currTag.getAttribute("title")){
				currTag.disabled = true;
				if(currTag.getAttribute("title") == styleTitle){
					currTag.disabled = false;
				}
			}
		}
	}
	return true;
};



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=560,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=800,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)
 };
};

