var cityArr = new Array();
var actvArr = new Array();
var attArr = new Array();
var hgrpArr = new Array();
var hlocArr = new Array();
var starArr = new Array();
var searchError=false;
var errorMsg=false;
var searchMessage="";
var schemaName="studio92";
var subURL="http://www.studios92.eu/"+schemaName+"";
var searchLoc="";
var searchLocHA="";
var showAllLoc=false;
var fireFox=false;
var showAllLoc=false;
if (navigator.userAgent.indexOf("Firefox")>-1){fireFox=true;}
var _month = new Array("January","February","March","April","May","June","July","August","September","October","November","Decemober");

function loadAct(){
searchError=false;
document.forms["form1"].elements["H_cmbNoOfRooms"].selectedIndex=0;
}

if (!fireFox){
var ixp_ie = (document.all)? true:false;
if (!ixp_ie) window.captureEvents(Event.CLICK)
document.onclick = getMouseXY;
}

calShown=false;
var activeDateObjNM="";
var activeDateObjIO="";
function retDate(add){
	var tmpd= new Date();
	var tmpd1= new Date(tmpd.setDate(tmpd.getDate()+add));
	return new Date(tmpd1.getFullYear(),tmpd1.getMonth(),tmpd1.getDate(),0,0,0,0);
}
var maxChis=0;
var _MouseX=0;
var _MouseY=0;

function getMouseXY(e) {
if (ixp_ie) {_MouseX=event.clientX+document.body.scrollLeft;_MouseY=event.clientY+document.body.scrollTop;
}else{if (fireFox){_MouseX = e.pageX;_MouseY = e.pageY;}}  
if (_MouseX<0){_MouseX=0}
if (_MouseY<0){_MouseY=0}  
hide_things();
return true
}

function hide_things(){
setObjPos("ixpDataFrame",0,0,0,0,"none");
setObjPos("maskFrame",0,0,0,0,"none");
}

var toDay = new retDate(0);
var _InDate = new retDate(2);
var _OutDate = new retDate(3);
function twoChar(val){
var tval=""+val+"";
if (tval.length<2){return "0"+val+"";}else{return ""+val+"";}
}
var numToday=Number(""+toDay.getFullYear()+""+twoChar(Number(toDay.getMonth())+1)+""+twoChar(toDay.getDate())+"");


function maxdays(mm,yy){
var maxd;
if (mm==1){
if(yy%4==0){return 29;}else{maxd=28;}
}else if (mm==0 || mm==2 || mm==4 || mm==6 || mm==7 || mm==9 || mm==11){
maxd=31;
}else{
maxd=30;
}
return maxd;
}

function dateOpts(days,date){
var ixpoptDays="";
var sel="";
	for (var ixpa=0; ixpa<days; ixpa++){
		if (date==(ixpa+1)){sel=" selected";}else{sel="";}
		if (ixpa<9){
			ixpoptDays+="<option value=\"0"+(ixpa+1)+"\""+sel+">0"+(ixpa+1)+"</option>";
		}else{
			ixpoptDays+="<option value=\""+(ixpa+1)+"\""+sel+">"+(ixpa+1)+"</option>";	
		}
	}
	return ixpoptDays;
}
function monthOpts(setmonth){
	var sel="";
	var  m_months= new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
	var optMonths="";
	for (var ixpb=0; ixpb<m_months.length; ixpb++){
		if (setmonth==ixpb){sel=" selected";}else{sel="";}
			optMonths+="<option value=\""+ixpb+"\""+sel+">"+m_months[ixpb]+"</option>";
	}
    return optMonths;
}
function dateCombo(objNm,inout,year,month,date) {
	retStr="";
	if (inout=="_In"){
		retStr="<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"+
		"<tr>"+
		"<td><select name=\""+objNm+inout+"Date\" onChange=\"setDtOptIn('"+objNm+"','"+inout+"',this);\">"+dateOpts(maxdays(month,year),date)+
		"</select></td>"+
		"<td><img src=\"images/s.gif\" width=\"1\" height=\"1\"></td>"+
		"<td><select name=\""+objNm+inout+"Month\" onChange=\"setDtOptIn('"+objNm+"','"+inout+"',this);\">"+monthOpts(month)+
		"</select></td>"+
		"<td><img src=\"images/s.gif\" width=\"1\" height=\"1\"></td>"+
		"<td><select name=\""+objNm+inout+"Year\" onChange=\"setDtOptIn('"+objNm+"','"+inout+"',this);\">";	
	}else{
		retStr="<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"+
		"<tr>"+
		"<td><select name=\""+objNm+inout+"Date\" onChange=\"setDtOptIn('"+objNm+"','"+inout+"',this);\">"+dateOpts(maxdays(month,year),date)+
		"</select></td>"+
		"<td><img src=\"images/s.gif\" width=\"1\" height=\"1\"></td>"+
		"<td><select name=\""+objNm+inout+"Month\" onChange=\"setDtOptIn('"+objNm+"','"+inout+"',this);\">"+monthOpts(month)+
		"</select></td>"+
		"<td><img src=\"images/s.gif\" width=\"1\" height=\"1\"></td>"+
		"<td><select name=\""+objNm+inout+"Year\" onChange=\"setDtOptIn('"+objNm+"','"+inout+"',this);\">";	
	}
		
	var ixpc=3;
	if (inout.indexOf("_Out")>-1){ixpc=4;}
	for (ixpd=0; ixpd<ixpc; ixpd++){
		var tmpy=""+(toDay.getFullYear()+ixpd)+"";
		if (year==tmpy){
			retStr+="<option value=\""+tmpy+"\" selected>"+tmpy+"</option>";	
		}else{
			retStr+="<option value=\""+tmpy+"\">"+tmpy+"</option>";	
		}
	}
	retStr+="</select></td>"+
	"<td><img src=\"images/s.gif\" width=\"3\" height=\"1\"></td>"+
	"<td><a href=\"JavaScript:void(0)\" onClick=\"loadixpCal('"+objNm+"','"+inout+"');\"><img name=\""+objNm+""+inout+"\" src=\"images/cal_new.gif\" width=\"18\" height=\"18\" border=\"0\"></a></td>"+
	"</tr>"+
	"</table>";
    return retStr;
}

function loadixpCal(nm,inout){
activeDateObjNM=nm;
activeDateObjIO=inout;
setcalPos('show',""+nm+""+inout+"");
}

function setcalPos(stat,obj){
	with(document.getElementById("calFrame")){
		if (stat=="show"){
		style.left=getPosImg(obj,"left")-167;
		style.top=getPosImg(obj,"top");
		style.width=185;style.height=215;
		style.display="block";
		calShown=true;
		}else{
		style.display="none";
		style.left=0;style.top=0;style.width=0;style.height=0;
		calShown=false;
		}	
	}
}

function opts(st,end,sel){
	var retStr="";
	for (var ixpe=st; ixpe<=end; ixpe++){
		if (!isNaN(sel)){
			if (sel==ixpe){
			retStr+="<option value=\""+ixpe+"\" selected>"+ixpe+"</option>\n";
			}else{
			retStr+="<option value=\""+ixpe+"\">"+ixpe+"</option>\n";
			}		
		}else{
			retStr+="<option value=\""+ixpe+"\">"+ixpe+"</option>\n";
		}
	}
	return retStr;
}

function showRooms(num){
setTimeout("showRoomsset("+num+")",1);
}

function showRoomsset(num){
for (ixpg=1; ixpg<=5; ixpg++){
if (ixpg<=num){
try{document.getElementById("occR"+ixpg+"").style.display="block";}catch(ex){}
}else{
try{document.getElementById("occR"+ixpg+"").style.display="none";}catch(ex){}
}
}
setSelRoomOcc();
}


function setDtOptIn(type,inout,obj){
var maxDates = maxdays(Number(document.forms["form1"].elements[""+(type+inout)+"Month"].options[document.forms["form1"].elements[""+(type+inout)+"Month"].selectedIndex].value),Number(document.forms["form1"].elements[""+(type+inout)+"Year"].options[document.forms["form1"].elements[""+(type+inout)+"Year"].selectedIndex].value));
var addopts=true;
try{
if (obj.name.indexOf("Date")>-1 && document.forms["form1"].elements[""+(type+inout)+"Date"].options.length==maxDates){addopts=false;}
}catch(ex){}
if (addopts){
setTimeout("loadOpts("+maxDates+",'"+type+inout+"Date')",0);
}
if (inout=="_Out"){
	setNights(type);
}else{
setOutDate(type,inout);
}
}

function setOutDate(type,inout){
var tmpOutDate;
with(document.forms["form1"]){
	tmpOutDate = new Date(elements[""+(type+inout)+"Year"].options[elements[""+(type+inout)+"Year"].selectedIndex].value,elements[""+(type+inout)+"Month"].options[elements[""+(type+inout)+"Month"].selectedIndex].value,elements[""+(type+inout)+"Date"].options[elements[""+(type+inout)+"Date"].selectedIndex].value,0,0,0,0);
	tmpOutDate = new Date(tmpOutDate.setDate(tmpOutDate.getDate()+Number(elements[""+type+"_nights"].value)));
	elements[""+type+"_OutYear"].selectedIndex=Number(tmpOutDate.getFullYear())-Number(toDay.getFullYear());
	elements[""+type+"_OutMonth"].selectedIndex=Number(tmpOutDate.getMonth());
	var tmpmaxDates = maxdays(Number(elements[""+type+"_OutMonth"].options[elements[""+type+"_OutMonth"].selectedIndex].value),Number(elements[""+type+"_OutYear"].options[elements[""+type+"_OutYear"].selectedIndex].value));
	setTimeout("loadOpts("+tmpmaxDates+",'"+type+"_OutDate',"+(Number(tmpOutDate.getDate())-1)+")",0);
}

}

function loadOpts(opts,name,setDt){
var selInd=document.forms["form1"].elements[name].selectedIndex;
document.forms["form1"].elements[name].options.length=0;
	for (ixpk=0; ixpk<opts; ixpk++){
		if (ixpk<9){
		document.forms["form1"].elements[name].options[ixpk]= new Option("0"+(ixpk+1)+"","0"+(ixpk+1)+"");
		}else{
		document.forms["form1"].elements[name].options[ixpk]= new Option(ixpk+1,ixpk+1);
		}
	}
	if (setDt>-1){
		document.forms["form1"].elements[name].selectedIndex=setDt;
	}else{
		if (selInd>=opts){
		document.forms["form1"].elements[name].selectedIndex=opts-1;
		}else{
		document.forms["form1"].elements[name].selectedIndex=selInd;
		}
	}
}

function setOut(type){
var tmpInDate = new Date(document.forms["form1"].elements[""+type+"_InYear"].options[document.forms["form1"].elements[""+type+"_InYear"].selectedIndex].value,document.forms["form1"].elements[""+type+"_InMonth"].options[document.forms["form1"].elements[""+type+"_InMonth"].selectedIndex].value,document.forms["form1"].elements[""+type+"_InDate"].options[document.forms["form1"].elements[""+type+"_InDate"].selectedIndex].value,0,0,0,0);
var tmpOutDate = new Date(tmpInDate.setDate(tmpInDate.getDate()+Number(document.forms["form1"].elements[""+type+"_nights"].value)));
document.forms["form1"].elements[""+type+"_OutYear"].selectedIndex=tmpOutDate.getFullYear()-toDay.getFullYear();
document.forms["form1"].elements[""+type+"_OutMonth"].selectedIndex=tmpOutDate.getMonth();
var maxDates = maxdays(Number(document.forms["form1"].elements[""+type+"_OutMonth"].options[document.forms["form1"].elements[""+type+"_OutMonth"].selectedIndex].value),Number(document.forms["form1"].elements[""+type+"_OutYear"].options[document.forms["form1"].elements[""+type+"_OutYear"].selectedIndex].value));
loadOpts(maxDates,""+type+"_OutDate");
document.forms["form1"].elements[""+type+"_OutDate"].selectedIndex=tmpOutDate.getDate()-1;
}

function setNights(type){
var tmpInDate = new Date(document.forms["form1"].elements[""+type+"_InYear"].options[document.forms["form1"].elements[""+type+"_InYear"].selectedIndex].value,document.forms["form1"].elements[""+type+"_InMonth"].options[document.forms["form1"].elements[""+type+"_InMonth"].selectedIndex].value,document.forms["form1"].elements[""+type+"_InDate"].options[document.forms["form1"].elements[""+type+"_InDate"].selectedIndex].value,0,0,0,0);
var tmpOutDate = new Date(document.forms["form1"].elements[""+type+"_OutYear"].options[document.forms["form1"].elements[""+type+"_OutYear"].selectedIndex].value,document.forms["form1"].elements[""+type+"_OutMonth"].options[document.forms["form1"].elements[""+type+"_OutMonth"].selectedIndex].value,document.forms["form1"].elements[""+type+"_OutDate"].options[document.forms["form1"].elements[""+type+"_OutDate"].selectedIndex].value,0,0,0,0);
var diffe=Number(get_deference(tmpInDate,tmpOutDate));
	if (diffe<=31 && diffe>0){
		document.forms["form1"].elements[""+type+"_nights"].value=diffe;
	}
}

function get_deference(ind,oud){
ind_d = ind.getDate();
ind_m = ind.getMonth();
ind_y = ind.getYear();
oud_d = oud.getDate();
oud_m = oud.getMonth();
oud_y = oud.getYear();
ret_val=0;
		if (ind_y==oud_y){
				if (ind_m==oud_m){
					ret_val=oud_d-ind_d;
				}else{
					if (ind_m<oud_m){
						if (oud_m-ind_m==1){
							ret_val=(maxdays(ind_m,ind_y)-ind_d)+oud_d;	
						}else{
							ret_val=(maxdays(ind_m,ind_y)-ind_d);
							for (var v=ind_m+1; v<oud_m; v++){
								ret_val+=maxdays(v,ind_y);
							}
							ret_val+=oud_d;
						}
					}
				}
		}else{
				//if (oud_y-ind_y==0) modify on 14/08/2007 by if (oud_y-ind_y==1) because problem of booking for 2 days from 30/11 to 02/12
				if (oud_y-ind_y==1){
					if (ind_m==11 && oud_m==0){
					ret_val=(maxdays(ind_m,ind_y)-ind_d)+oud_d
					}
				}else{
					ret_val=100;
				}
				
		}
return ret_val;
}

var checkMore=0;

//////////////////////
// Start Christophe 10/19/2007

var onKeyBoardPressed = new YAHOO.util.CustomEvent("onKeyBoardPressed"); 

function setChar(ev, obj)
{
	if(ev.keyCode != 38 && ev.keyCode != 40 && ev.keyCode != 13)
	{
		if (obj.ch.value.length >= 1)
		{
			arrCaller('citylist.txt', obj.ch, obj.img);
		}		
	}	
	else
	{
		onKeyBoardPressed.fire(ev);			
	}					
}

 //Previous version of function 'setChar' 
/*function setChar(ch,img)
{
	if (ch.value.length<3){return;}
	arrCaller('citylist.txt',ch,img);
}*/

// End Christoph
//////////////////////

function arrCaller(file,ch,img){
	var callURL="accessFiles.asp?fname="+file+"&str="+ch.value+"";
	makeRequest(callURL,ch,img);
}

function makeRequest(url,ch,img) {
var http_request = null;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
	http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
		http_request.overrideMimeType("application/xhtml+xml");
		
		// See note below about this line
		}
	} else if (window.ActiveXObject) { // IE
		try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
			http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
	alert('Giving up :( Cannot create an XMLHTTP instance');
	return false;
	}
	http_request.onreadystatechange = function() {
		if (http_request.readyState == 4) {
			if (http_request.status == 200) {
				showCities(http_request.responseText,ch,img);
			}
		}
	}
	http_request.open('GET', url, true);
	http_request.send(null);
}

//////////////////////////
//	Start Christophe 10/19/2007
//	Just create a customEvent for showCities
/////////////////////////

var onShowCities = new YAHOO.util.CustomEvent("onShowCities"); 

//////////////////////////
//	End Christophe
/////////////////////////

function showCities(txt,ch,img){
var txtStr=txt.substring(0,txt.length-1);
var txtStr=txtStr.replace(/,/g,"|")
var txtArr=txtStr.split("~");
var tmpArr = new Array();
	for (var j=0; j<txtArr.length; j++){
		// christophe if (!showAllLoc){checkMore++;if (checkMore>14){break;}}
		if (txtArr[j]!=""){
			var tmpStrs=txtArr[j].split("|");
			tmpArr[tmpArr.length]="<tr><td class=\"stripe"+((j%2)+3)+"\" style=\"padding-left:5px;cursor:pointer;\" onMouseOver=\"altcell('ov',this)\" onMouseOut=\"altcell('ou',this,'stripe"+((j%2)+3)+"')\" onClick=\"setVal('"+txtArr[j]+"','"+ch.name+"')\">"+tmpStrs[1]+" - "+tmpStrs[5]+"</td></tr>";
		}
		
	}

	/////// Christophe
	/*if (!showAllLoc){
		if (checkMore>14){tmpArr[tmpArr.length]="<tr><td class=\"morebg\" style=\"padding-left:5px;cursor:pointer;\" title=\"Show All\" align=\"center\"><img src=\"images/more_arrow.gif\" width=\"9\" height=\"6\" border=\"0\" hspace=\"3\" alt=\"Show All\" align=\"absmiddle\">Show All</td></tr>";}
	}*/////////////

	checkMore=0;

	var outSt="";
	if (tmpArr.length==0){
		outSt="<table border=\"0\" width=\"231px\" cellspacing=\"1\" cellpadding=\"3\" class=\"databorder\"><tr><td class=\"stripe4\" onClick=\"setObjPos('ixpDataFrame',0,0,180,0,'none');setObjPos('maskFrame',0,0,180,0,'none');\" align=\"center\">... No Results Available ...</td></tr></table>";
		showRes(img,outSt,1);
	}else{
		outSt="<table border=\"0\" width=\"231px\" cellspacing=\"1\" cellpadding=\"4\" class=\"databorder\">"+tmpArr.join("")+"</table>";
		showRes(img,outSt,tmpArr.length);
	}
	tmpArr.length=0;

//////////////////////////
//	Start Christophe 10/19/2007
//	fire the customEvent for showCities
/////////////////////////

onShowCities.fire(); 

//////////////////////////
//	End Christophe
/////////////////////////

}

function getPosImg(imgElem,ops) {
	if (ops=="top"){
		ixppos = document.images[imgElem].offsetTop;
		tempEl = document.images[imgElem].offsetParent;
				while (tempEl != null) {
					ixppos += tempEl.offsetTop;
					tempEl = tempEl.offsetParent;
				}
		return ixppos;
	}else if (ops=="left"){
		ixppos = document.images[imgElem].offsetLeft;
		tempEl = document.images[imgElem].offsetParent;
				while (tempEl != null) {
					ixppos += tempEl.offsetLeft;
					tempEl = tempEl.offsetParent;
				}
		return ixppos;
	}
}

function showRes(img,outSt,records){
setObjPos('ixpDataFrame',getPosImg(img,'left'),getPosImg(img,'top'),231,records,'block');
setObjPos('maskFrame',getPosImg(img,'left'),getPosImg(img,'top'),231,records,'block');
document.getElementById("ixpDataFrame").innerHTML=outSt;
}

function setObjPos(name,x,y,w,recs,stat,records){
	with(document.getElementById(name).style){
	left=x-22;top=y+5;width=w;height=recs*23;display=stat;
	}
}

//////////////////////////
//	Start Christophe 10/20/2007
//	Just create a customEvent for altcell
//	And fire it at the beginning of the altcell function
/////////////////////////

var onMouseOverItem = new YAHOO.util.CustomEvent("onMouseOverItem"); 


function altcell(st,obj,cls)
{	///////// Christophe
	onMouseOverItem.fire();
	////////
	if (st=="ov"){
		obj.className="overclass";
	}else{
		obj.className=cls;
	}
}

/////////////////
// Creates another custom event fired when user select a city in the city list
var onSetVal = new YAHOO.util.CustomEvent("setVal"); 

function setVal(val,obj){
try{
document.forms["form1"].elements["hid_H_Loc"].value=val;
}catch(exp){}
try{
document.forms["form1"].elements["hid_A_Loc"].value=val;
}catch(exp){}
var vlArr=val.split("|");
document.forms["form1"].elements[obj].value=vlArr[1]+" - "+vlArr[5];
setObjPos('ixpDataFrame',0,0,180,0,'none');
setObjPos('maskFrame',0,0,180,0,'none');
showAllLoc=false;
///////////////////////////////
// Fires event
onSetVal.fire();
}


//////////////////////////
//	End Christophe
/////////////////////////

///////////////////////////////////////////////////////////////

function search(){
	eval("loadData_"+document.forms["form1"].pkgType.value+"()");
}
function getSelVal(fr,nm){
try{
	return document.forms[fr].elements[nm].options[document.forms[fr].elements[nm].selectedIndex].value;
}catch(exp){
	return document.forms[fr].elements[nm].value;
}

}
var sel_adlts=0;
var sel_chis=0;
var set_agelist="";
function setFields(eng){
		with(document.forms["ResSearchFormH"]){
		cmbInMn.value=Number(getSelVal("form1",""+eng+"_InMonth"))+1;
		cmbInDt.value=getSelVal("form1",""+eng+"_InDate");
		cmbInYr.value=getSelVal("form1",""+eng+"_InYear");
		cmbOutMn.value=Number(getSelVal("form1",""+eng+"_OutMonth"))+1;
		cmbOutDt.value=getSelVal("form1",""+eng+"_OutDate");
		cmbOutYr.value=getSelVal("form1",""+eng+"_OutYear");
		
		if (eng!="A"){
			cmbNoRm.value=getSelVal("form1",""+eng+"_cmbNoOfRooms");
			setAdults_Chi_Gstlst(Number(cmbNoRm.value));
			cmbAdlt.value=sel_adlts;
			cmbChi.value=sel_chis;
			gstLst.value=set_agelist;
		}
		cmbNgt.value=getSelVal("form1",""+eng+"_nights");
		searchLoc=document.forms["form1"].elements["hid_"+eng+"_Loc"].value.split("|");
		cmbCty.value=searchLoc[0];
		ctyNm.value=searchLoc[1];
		cmbSte.value=searchLoc[2];
		cmbCtry.value=searchLoc[3];
		}
}

function setFieldsPkg(){
	with(document.forms["ResSearchFormH"]){
		cmbInYr_Activities.value=getSelVal("form1","H_InYear");
		cmbInMn_Activities.value=Number(getSelVal("form1","H_InMonth"))+1;
		cmbInDt_Activities.value=getSelVal("form1","H_InDate");
		cmbOutYr_Activities.value=getSelVal("form1","H_OutYear");
		cmbOutMn_Activities.value=Number(getSelVal("form1","H_OutMonth"))+1;
		cmbOutDt_Activities.value=getSelVal("form1","H_OutDate");
		cmbNgt_Activities.value=getSelVal("form1","H_nights");
		searchLocHA=document.forms["form1"].elements["hid_H_Loc"].value.split("|");
		cmbCty_Activities.value=searchLocHA[0];
		cityLookup_Activities.value=searchLocHA[1];
		cmbCtry_Activities.value=searchLocHA[3];
		
		cmbCtry_Hotels.value=searchLocHA[3];
		cmbCty_Hotels.value=searchLocHA[0];
		cityLookup_Hotels.value=searchLocHA[1];
		cmbSte_Hotels.value=searchLocHA[2];
		cmbInMn_Hotels.value=Number(getSelVal("form1","H_InMonth"))+1;
		cmbInDt_Hotels.value=getSelVal("form1","H_InDate");
		cmbInYr_Hotels.value=getSelVal("form1","H_InYear");
		cmbNgt_Hotels.value=getSelVal("form1","H_nights");
		cmbOutMn_Hotels.value=Number(getSelVal("form1","H_OutMonth"))+1;
		cmbOutDt_Hotels.value=getSelVal("form1","H_OutDate");
		cmbOutYr_Hotels.value=getSelVal("form1","H_OutYear");
		cmbNoRm_Hotels.value=getSelVal("form1","H_cmbNoOfRooms");
		totRooms_Hotels.value=getSelVal("form1","H_cmbNoOfRooms");
		totAdlt_Hotels.value=sel_adlts;
		totChi_Hotels.value=sel_chis;
		gstLst_Hotels.value=set_agelist;
		
		searchCityId.value=searchLocHA[0];
		searchCityName.value=searchLocHA[1];
		searchStateId.value=searchLocHA[2];
		searchCountryId.value=searchLocHA[3];
	}
}

function setAdults_Chi_Gstlst(val){
var AccomVal=document.forms["ResSearchFormH"].elements["accommodationType"].value;
	with (document.forms["form1"]){
		if (AccomVal=="HT"){
			_noR = Number(elements["H_cmbNoOfRooms"].options[elements["H_cmbNoOfRooms"].selectedIndex].value);
				for (var _NOR=0; _NOR<_noR; _NOR++){
					sel_adlts+=Number(elements["R"+(_NOR+1)+"occAdults"].options[elements["R"+(_NOR+1)+"occAdults"].selectedIndex].value);
					sel_chis+=Number(elements["R"+(_NOR+1)+"occChi"].options[elements["R"+(_NOR+1)+"occChi"].selectedIndex].value);
				}
		}else if (AccomVal=="HS"){
			sel_adlts=Number(elements["H_Adults"].options[elements["H_Adults"].selectedIndex].value);
			sel_chis=0;
		}
	}
	set_agelist=document.forms["ResSearchFormH"].elements["gstLst"].value;
}
	
function loadData_H(){
setFields("H");
document.forms["ResSearchFormH"].action=""+subURL+"/hotels/reservation/ResSearchCriteria.do?ActionType=ResSearch&status=search";
document.forms["ResSearchFormH"].target="_parent"	
if (chkDates()){showError();return;}
befSubmit();
document.forms["ResSearchFormH"].submit();
}

function loadData_HA(){
setFields("H");
setFieldsPkg();
document.forms["ResSearchFormH"].elements["pkgType"].value="HA";
document.forms["ResSearchFormH"].elements["progCatagery"].value=getSelVal("form1","HActivity_type");
document.forms["ResSearchFormH"].action=""+subURL+"/packaging/reservation/ResPkgSearchCriteria.do?ActionType=Pkg";	
actStr();
if (chkDates()){showError();return;}
befSubmit();
document.forms["ResSearchFormH"].submit();
}

function printVals(){
var eleStr="";
for (var kk=0; kk<document.forms["ResSearchFormH"].elements.length; kk++){
eleStr+=""+document.forms["ResSearchFormH"].elements[kk].name+" = "+document.forms[0].elements[kk].value+"";
}
document.write("<xmp>"+eleStr+"</xmp>")
}


function loadData_A(){
setFields("A");
document.forms["ResSearchFormH"].elements["progCatagery"].value=getSelVal("form1","Activity_type");
document.forms["ResSearchFormH"].action=""+subURL+"/activities/reservation/ResSearchCriteria.do?ActionType=ResSearch&status=search";	
if (chkDates()){showError();return;}
actStr();
befSubmit();
document.forms["ResSearchFormH"].submit();
}


function chkDates(){
with(document.forms["ResSearchFormH"]){
var idtNum=Number(""+cmbInYr.value+""+twoChar(cmbInMn.value)+""+twoChar(cmbInDt.value)+"");
var odtNum=Number(""+cmbOutYr.value+""+twoChar(cmbOutMn.value)+""+twoChar(cmbOutDt.value)+"");
var tpInDate = new Date(cmbInYr.value,cmbInMn.value,cmbInDt.value,0,0,0,0);
var tpOutDate = new Date(cmbOutYr.value,cmbOutMn.value,cmbOutDt.value,0,0,0,0);
}
var diff=Number(get_deference(tpInDate,tpOutDate));
var selLoc="";
if (document.forms["ResSearchFormH"].elements["pkgType"].value!="A"){
selLoc=document.forms["form1"].elements["hid_H_Loc"].value;
}else{
selLoc=document.forms["form1"].elements["hid_A_Loc"].value;
}

if (selLoc.indexOf("|")==-1){
	searchError=true;
	errorMsg="Please Enter The Location";
	return true;
}

if (numToday>idtNum){
	searchError=true;
	errorMsg="Arrival Date Should be Greater Than Today's Date";
	return true;
}
if (idtNum>odtNum){
	searchError=true;
	errorMsg="Departure Date Should be Greater Than Arrival Date";
	return true;
}
if (diff>31){
	searchError=true;
	errorMsg="You Can Book Maximum of 31 Nights";
	return true;
}
return false;
}

function actStr(){
var tmpsr=actvArr.join("$");
tmpsr=tmpsr.split(",");
tmpsr=tmpsr.join("@");
document.forms["ResSearchFormH"].elements["actList"].value=tmpsr;
}

function showError(){
document.getElementById("errorMSG").innerHTML=errorMsg;
document.getElementById("errorTBL").style.display="block";
setTimeout("hideError()",2500);
}

function hideError(){
document.getElementById("errorMSG").innerHTML="";
document.getElementById("errorTBL").style.display="none";
errorMsg="";
searchError=false;
}

function befSubmit(){
var srhdates="<br>Arriving on <b>"+_month[Number(document.forms["ResSearchFormH"].elements["cmbInMn"].value)-1]+"-"+document.forms["ResSearchFormH"].elements["cmbInDt"].value+"-"+document.forms["ResSearchFormH"].elements["cmbInYr"].value+"</b>, Departing <b>"+_month[Number(document.forms["ResSearchFormH"].elements["cmbOutMn"].value)-1]+"-"+document.forms["ResSearchFormH"].elements["cmbOutDt"].value+"-"+document.forms["ResSearchFormH"].elements["cmbOutYr"].value+"</b>";
searchMessage="<strong>We are Searching for Hotels in "+searchLoc[1]+" "+searchLoc[5]+"</strong> "+srhdates+"<br><b>"+document.forms["ResSearchFormH"].elements["cmbNoRm"].value+"</b> Room(s) , <b>"+sel_adlts+"</b> Adult(s) and <b>"+sel_chis+"</b> Children";
document.getElementById("searchMsg").innerHTML=searchMessage;
document.getElementById("waitMsg").style.display="block";
document.getElementById("fullContent").style.display="none";
}

function setSelRoomOcc(){
var _noR="";
var _nChi="";
var tempOcc="";
var AccomVal=document.forms["ResSearchFormH"].elements["accommodationType"].value;

	if (AccomVal=="HT"){
		with (document.forms["form1"]){
		_noR = Number(elements["H_cmbNoOfRooms"].options[elements["H_cmbNoOfRooms"].selectedIndex].value);
			for (var _NOR=0; _NOR<_noR; _NOR++){
			tempOcc+=elements["R"+(_NOR+1)+"occAdults"].options[elements["R"+(_NOR+1)+"occAdults"].selectedIndex].value+"|";
			_nChi=Number(elements["R"+(_NOR+1)+"occChi"].options[elements["R"+(_NOR+1)+"occChi"].selectedIndex].value);
			tempOcc+=_nChi+"|";
				if (_nChi>0){
					for (var _Nch=0; _Nch<_nChi; _Nch++){
						tempOcc+=elements["R"+(_NOR+1)+"occAge"+(_Nch+1)+""].options[elements["R"+(_NOR+1)+"occAge"+(_Nch+1)+""].selectedIndex].value;
						if ((_Nch+1)!=_nChi){tempOcc+=",";}
					}
					tempOcc+="|%|%@";
				}else{
					tempOcc+="-|%|%@";
				}
			}
		}
	}else if (AccomVal=="HS"){
		tempOcc="";
		with (document.forms["form1"]){
		var HSAdults=Number(elements["H_Adults"].options[elements["H_Adults"].selectedIndex].value);
			for (var dfg=0; dfg<HSAdults; dfg++){
				tempOcc+="1|0|-|%|%@";
			}		
		}
	}
document.forms["ResSearchFormH"].elements["gstLst"].value=tempOcc;
}

function showAgCom(val,rm){
setTimeout("showAgComset("+val+",'"+rm+"')",1);
}

function showAgComset(val,rm){
if (val==0){
try{document.getElementById("R"+rm+"ageTbl").style.display="none";}catch(ex){}
}else{
try{document.getElementById("R"+rm+"ageTbl").style.display="block";}catch(ex){}
}

	for (fgh=1; fgh<=3; fgh++){
		if (fgh<=val){
			document.getElementById("R"+rm+"chAgHd"+fgh+"").style.display="block";
			document.getElementById("R"+rm+"occAge"+fgh+"").style.display="block";
		}else{
			document.getElementById("R"+rm+"chAgHd"+fgh+"").style.display="none";
			document.getElementById("R"+rm+"occAge"+fgh+"").style.display="none";
		}
	}
}

function CheckLogin(){
document.forms["form1"].action=""+subURL+"/hotels/reservation/ResSearchCriteria.do?ActionType=CheckLogin";
document.forms["form1"].target="loignCheck";
document.forms["form1"].submit();
}

function loadFilters(){
	with(document.forms["form1"]){
		if (hlocArr.length!=0){
			elements["hLocation"].options.length=0;
			elements["hLocation"].options[0] = new Option("All","All");
			for (var loopr=0; loopr<hlocArr.length; loopr++){
			//try{elements["hLocation"].options[elements["hLocation"].options.length] = new Option(hlocArr[loopr][1],hlocArr[loopr][0]);}catch(ex){}
			elements["hLocation"].options[elements["hLocation"].options.length] = new Option(hlocArr[loopr][1],hlocArr[loopr][0]);
			}
		}
		if (hgrpArr.length!=0){
			elements["hGroup"].options.length=0;
			elements["hGroup"].options[0] = new Option("All","All");
			for (var loopr=0; loopr<hgrpArr.length; loopr++){
			//try{elements["hLocation"].options[elements["hLocation"].options.length] = new Option(hlocArr[loopr][1],hlocArr[loopr][0]);}catch(ex){}
			elements["hLocation"].options[elements["hLocation"].options.length] = new Option(hlocArr[loopr][1],hlocArr[loopr][0]);
			}
		}
		if (starArr.length!=0){
			elements["hstarCat"].options.length=0;
			elements["hstarCat"].options[0] = new Option("All","All");
			for (var loopr=0; loopr<starArr.length; loopr++){
			//try{elements["hstarCat"].options[elements["hstarCat"].options.length] = new Option(starArr[loopr][1],starArr[loopr][0]);}catch(ex){}
			elements["hstarCat"].options[elements["hstarCat"].options.length] = new Option(starArr[loopr][1],starArr[loopr][0]);
			}
		}
		if (attArr.length!=0){
			elements["hAtt"].options.length=0;
			elements["hAtt"].options[0] = new Option("All","All");
			for (var loopr=0; loopr<attArr.length; loopr++){
			//try{elements["hAtt"].options[elements["hAtt"].options.length] = new Option(attArr[loopr][1],attArr[loopr][0]);}catch(ex){}
			elements["hAtt"].options[elements["hAtt"].options.length] = new Option(attArr[loopr][1],attArr[loopr][0]);
			}
		}
	}
}
function setFilter(val,objnm){
document.forms["ResSearchFormH"].elements[objnm].value=val;
}

loadfilt=false;

function chkFilters(chk){
if (chk){
	document.getElementById('hFilt').style.display='block';
}else{
	document.getElementById('hFilt').style.display='none';
}
if (!loadfilt){
	loadFilters();
	loadfilt=true;
}
}

// TO  check the "H_Loc" field
// Christophe changes 11 01 2007
function test_city()
{
	if(cityListHandler.isCitySelected())
	{
	
		if ((getSelVal("form1","H_Loc") == "Please type city here ..."))
		{
			alert ("Enter a city name please !");
		}
		else 
		{
			search();
		}
	}
	else
	{
		alert("Please select a city from the city list");
	}
}
//End-->



function buildOcc(){
var occStr="";
var _sty="";
for (var oc=0; oc<5; oc++){
if(oc==0){_sty="block";}else{_sty="none";}
occStr+="<span id=\"occR"+(oc+1)+"\" style=\"display:"+_sty+";\"><table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">\n"+
"<tr>\n"+
"<td width=\"16%\" class=\"txt\">&nbsp;&nbsp;R&nbsp;"+(oc+1)+"&nbsp;</td>\n"+
"<td width=\"28%\" class=\"txt\">Adults</td>\n"+
"<td width=\"28%\" class=\"txt\">Children</td>\n"+
"<td width=\"28%\" class=\"txt\"><img src=\"images/ixps.gif\" width=\"1\" height=\"1\"></td>\n"+
"</tr>\n"+
"<tr>\n"+
"<td width=\"16%\"><img src=\"images/ixps.gif\" width=\"1\" height=\"1\"></td>\n"+
"<td width=\"28%\"><select name=\"R"+(oc+1)+"occAdults\" style=\"width:40px;\" onChange=\"setSelRoomOcc();\">\n"+opts(1,10,1)+"</select></td>\n"+
"<td width=\"28%\"><select name=\"R"+(oc+1)+"occChi\" style=\"width:40px;\" onChange=\"setSelRoomOcc();showAgCom(Number(this.options[this.selectedIndex].value),"+(oc+1)+");\">\n"+opts(0,3,0)+"</select></td>\n"+
"<td width=\"28%\" class=\"txt\"><img src=\"images/ixps.gif\" width=\"1\" height=\"1\"></td>\n"+
"</tr>\n"+
"<tr>\n"+
"<td colspan=\"4\"><span id=\"R"+(oc+1)+"ageTbl\" style=\"display:none;\"><table width=\"100%\" border=\"0\" align=\"center\" cellpadding=\"0\" cellspacing=\"0\">\n"+
"<tr>\n"+
"<td width=\"16%\"><img src=\"images/ixps.gif\" width=\"1\" height=\"1\"></td>\n"+
"<td width=\"28%\" class=\"txt\"><span id=\"R"+(oc+1)+"chAgHd1\" style=\"display:none;\">Age 1</span></td>\n"+
"<td width=\"28%\" class=\"txt\"><span id=\"R"+(oc+1)+"chAgHd2\" style=\"display:none;\">Age 2</span></td>\n"+
"<td width=\"28%\" class=\"txt\"><span id=\"R"+(oc+1)+"chAgHd3\" style=\"display:none;\">Age 3</span></td>\n"+
"</tr>\n"+
"<tr>\n"+
"<td width=\"16%\"><img src=\"images/ixps.gif\" width=\"1\" height=\"1\"></td>\n"+
"<td width=\"28%\"><select id=\"R"+(oc+1)+"occAge1\" name=\"R"+(oc+1)+"occAge1\" style=\"width:40px;display:none;\" onChange=\"setSelRoomOcc();\">\n"+opts(1,18,1)+"</select></td>\n"+
"<td width=\"28%\"><select id=\"R"+(oc+1)+"occAge2\" name=\"R"+(oc+1)+"occAge2\" style=\"width:40px;display:none;\" onChange=\"setSelRoomOcc();\">\n"+opts(1,18,1)+"</select></td>\n"+
"<td width=\"28%\"><select id=\"R"+(oc+1)+"occAge3\" name=\"R"+(oc+1)+"occAge3\" style=\"width:40px;display:none;\" onChange=\"setSelRoomOcc();\">\n"+opts(1,18,1)+"</select></td>\n"+
"</tr>\n"+
"</table>\n"+
"</span></td>\n"+
"</tr>\n"+
"<tr align=\"center\">\n"+
"<td colspan=\"4\"><img src=\"images/ixps.gif\" width=\"1\" height=\"5\"></td>\n"+
"</tr>\n"+
"</table>\n";
}
return occStr;
}

function setAcType(val){
	document.forms["ResSearchFormH"].elements["accommodationType"].value=val;
	if (val=="HT"){
		document.getElementById("roomsCombo").style.display="block";	
		document.getElementById("adultsCombo").style.display="none";
		document.getElementById("occBox").style.display="block";
	}else if (val=="HS"){
		document.getElementById("roomsCombo").style.display="none";	
		document.getElementById("adultsCombo").style.display="block";
		document.getElementById("occBox").style.display="none";
	}
}


///////////////////////////////////////
//				     //
//	Christophe 10/18/2007	     //
//				     //
///////////////////////////////////////



	///////////////////////////////////////
	//      CalendarIframeManager        //
	///////////////////////////////////////

/*
 * This class is just useful to hide the iframe of the calendar when user click
 * on the page.
 */
var CalendarIframeManager = function ()
{
	YAHOO.util.Event.onDOMReady(this.init, this, true);			
}

/**
 * Inits the CalendarIframeManager
 */
CalendarIframeManager.prototype.init = function()
{		
	this.attachListenerToItSelft();
}

/**
 * Attachs a listener to the iframe of the booking engine in order to
 * hide the calendar clicking inside
 */
CalendarIframeManager.prototype.attachListenerToItSelft = function()
{	
	YAHOO.util.Event.addListener(window.document.body, "click", this.hide);
}

/**
 * (This method is fired every time user click on the page (in the calendar iframe or not))
 * Hide the calendar (<iframe>) if the user didn't click on one of the icons used to show the iframe.
 * @param {Event} ev : the clicked element
 */
CalendarIframeManager.prototype.hide = function(ev)
{		
	var evSource = YAHOO.util.Event.getTarget(ev);
	if(evSource.tagName.toLowerCase() != "img")
	{
		YAHOO.util.Dom.setStyle(document.getElementById("calFrame"), "display", "none");
	}	
	else if(evSource.src.indexOf("images/cal_new.gif") == -1)
	{
		YAHOO.util.Dom.setStyle(document.getElementById("calFrame"), "display", "none");
	}	
}


// Create CalendarIframeManager instance
var calendarIframeManager = new CalendarIframeManager();	



	///////////////////////////////////////
	//          CityListHandler          //
	///////////////////////////////////////

/**
 * This class lets users use keyboard arrows (up and down) in order to chose a city
 * within the city list. It also lets users hide the city list clicking on the page.
 */ 
var CityListHandler = function()
{	
	/**
 	 * The city list container. It is a <div> element containing a <table> with the cities.
	 */
	this.cityListContainer = null;	

	/**
 	 * The city list. It is an array containing all cities as <td> element.
	 */
	this.cityList = null;

	/**
 	 * The city text field. It is the <input> element in which users type the name of the city.
	 */		
	this.cityTextField;

	/**
	 * This contains the name of the last city selected by user
	 */
	this.citySelectedValue = "";

	/**
 	 * Wait for the this.cityListContainer before initializing CityListHandler.
	 */	
	YAHOO.util.Event.onAvailable("txtboxID", this.init, this, true); 
}

/**
 * Class of the highlighted item
 */
CityListHandler.OVERCLASS = "overclass";
/**
 * Init the CityListHandler
 */
CityListHandler.prototype.init = function()
{		
	// Init this.cityTextField and add some listeners to it
	this.cityTextField = document.getElementById("txtboxID");
	var argsObj = {ch:this.cityTextField, img:'locImg1'};
	YAHOO.util.Event.addListener(this.cityTextField, "keypress", this.blockEnter);
	YAHOO.util.Event.addListener(this.cityTextField, "keyup", setChar, argsObj, false);	

	// Subscribe to some customEvent
	onShowCities.subscribe(this.onShowCitiesEvent, this, true);
	onKeyBoardPressed.subscribe(this.onKeyBoardPressedEvent, this, true);
	onMouseOverItem.subscribe(this.dishighlightItem, this, true);
	onSetVal.subscribe(this.onSetValEvent, this, true);	

	// Attach a listener to the iframe of the booking engine in order to
 	// hide the city list clicking inside
	YAHOO.util.Event.addListener(window.document.body, "click", this.hide, this, true);
}

/**
 * (This method is fired when user press 'enter')
 * Blocks 'enter' effect
 */
CityListHandler.prototype.blockEnter = function(ev)
{
	if(ev.keyCode == 13)
	{
		YAHOO.util.Event.stopEvent(ev);
		return false;			
	}
}

/**
 * Inits this.cityList
 */
CityListHandler.prototype.catchCityList = function()
{
	this.cityList = this.cityListContainer.getElementsByTagName("td");
}

/**
 * Inits this.cityListContainer
 */
CityListHandler.prototype.catchCityListContainer = function()
{
	this.cityListContainer = document.getElementById("ixpDataFrame");
}

/**
 * (This method is fired at the beginning of the altcell function)
 * Dishighlights the current highlighted item
 */
CityListHandler.prototype.dishighlightItem = function()
{
	var highlightedItemIndex = this.getHighlightedItemIndex();	
	YAHOO.util.Dom.addClass(this.cityList[highlightedItemIndex], this.getPreviousHighlightedItemClassName());
	YAHOO.util.Dom.removeClass(this.cityList[highlightedItemIndex], CityListHandler.OVERCLASS);	
}

/**
 * Gets the index of the current highlighted index
 * @return {int} result : The index of the current highlighted index, or null if there is no
 * highlighted index currently
 */
CityListHandler.prototype.getHighlightedItemIndex = function()
{
	var result = null;
	for(var i = 0; i < this.cityList.length; i++)
	{
		if(this.cityList[i].className == CityListHandler.OVERCLASS)
		{
			result = i;
		}
	}
	return result;
}

/**
 * Gets item at the given index
 * @param {int} itemIndex : The index of the item to get
 * @return {HTMLElement} : The item at the given index in the city list
 */
CityListHandler.prototype.getItem = function(itemIndex)
{
	return this.cityList[itemIndex];
}

/**
 * Gets the number of city in the city list
 * @return {int} : The number of city in the city list
 */
CityListHandler.prototype.getNumberOfCity = function()
{	
	return this.cityList.length;
}

/**
 * Gets the class name of the current highlighted item before
 * it has been highlighted.
 * @return {String} result : The class name of the current highlighted item before
 * it has been highlighted (means "stripe3" or "stripe4").
 */
CityListHandler.prototype.getPreviousHighlightedItemClassName = function()
{
	var result;
	var highlightedItemIndex = this.getHighlightedItemIndex();
	if(highlightedItemIndex == 0)
	{
		result = "stripe3";
	}
	else
	{
		var previousItem = this.getItem(highlightedItemIndex - 1);
		var previousItemClassName = previousItem.className;
		if(previousItemClassName == "stripe3")
		{
			result = "stripe4";
		}
		else
		{
			result = "stripe3";
		}
	}
	return result;
}

/**
 * (This method is fired every time user click on the page)
 * Hides the city list container
 */
CityListHandler.prototype.hide = function()
{		
	YAHOO.util.Dom.setStyle(this.cityListContainer, "display", "none");
	// It is although necessary to hide the maskframe displayed when this.cityListContainer
	// is displayed
	YAHOO.util.Dom.setStyle("maskFrame", "display", "none");
}

/**
 * Highlights the item in the city list which has the given itemIndex.
 * @param {int} itemIndex : the index of the item to highlight.
 */
CityListHandler.prototype.highlightItem = function(itemIndex)
{
	var item = this.getItem(itemIndex);	
	YAHOO.util.Dom.removeClass(item, item.className);
	YAHOO.util.Dom.addClass(item, CityListHandler.OVERCLASS);
}

/**
 * Highlights the next item in the list of city. If there is no item highlighted
 * then Highlights the first item. If the highlighted item is the last item of 
 * the lcity list then just dishighlight this item.
 */
CityListHandler.prototype.highlightNextItem = function()
{
	var highlightedItemIndex = this.getHighlightedItemIndex();
	if(highlightedItemIndex == null)
	{		
		this.highlightItem(0);
		this.scrollCityListToTop();
	}
	else if(highlightedItemIndex == this.getNumberOfCity() - 1)
	{
		this.dishighlightItem();
	}	
	else
	{
		this.dishighlightItem();	
		this.highlightItem(highlightedItemIndex + 1);
	}
	this.makeHighlightedCityVisible();
}

/**
 * Highlights the previous item in the list of city. If there is no item highlighted
 * then Highlights the last item. If the highlighted item is the first item of
 * the lcity ist then just dishighlight this item.
 */
CityListHandler.prototype.highlightPreviousItem = function()
{
	var highlightedItemIndex = this.getHighlightedItemIndex();
	if(highlightedItemIndex == null)
	{
		this.highlightItem(this.getNumberOfCity() - 1);
		this.scrollCityListToBottom();
	}
	else if(highlightedItemIndex == 0)
	{
		this.dishighlightItem();
	}	
	else
	{
		this.dishighlightItem();
		this.highlightItem(highlightedItemIndex - 1);
	}	
	this.makeHighlightedCityVisible();
}

/**
 * Checks the visibility of the city list container
 * @return {boolean} : True if the city list container is visible, false otherwise
 */
CityListHandler.prototype.isCityListVisible = function()
{
	if(this.cityListContainer == null || YAHOO.util.Dom.getStyle(this.cityListContainer, "display") == "none")
		return false;	
	else
		return true;
}

/**
 * Returns this.citySelected
 * @return {boolean} : this.citySelected
 */
CityListHandler.prototype.isCitySelected = function()
{
	if(this.citySelectedValue == this.cityTextField.value)		
		return true;
	else
		return false;
}

/**
 * Scrolls the city list if the highlighted element is not visible.
 */
CityListHandler.prototype.makeHighlightedCityVisible = function()
{
	// Gets the city list container top position and height		
	var cityListContainerTop = YAHOO.util.Dom.getY(this.cityListContainer);
	var cityListContainerHeight = this.cityListContainer.offsetHeight;
	
	// Gets the the highlighted element top position and height		
	var highlightedItem = this.getItem(this.getHighlightedItemIndex());	
	var highlightedItemHeight = highlightedItem.offsetHeight;
	// Gets the the highlighted element top position
	if(YAHOO.util.Dom.getY(highlightedItem))	
		var highlightedItemTop = YAHOO.util.Dom.getY(highlightedItem);		
	else
		var highlightedItemTop = cityListContainerTop;	

	// Checks if the highlighted item is visible and scrolls if necessary
	if(cityListContainerTop > highlightedItemTop)
	{
		this.cityListContainer.scrollTop = Math.max(0, this.cityListContainer.scrollTop - 150); 
	}
	else if(cityListContainerTop + cityListContainerHeight < highlightedItemTop + highlightedItemHeight)
	{
		this.cityListContainer.scrollTop = this.cityListContainer.scrollTop + 150; 
	}
}

/**
 * Adapts the height of the city list.
 * If the height of the city list is higher than 300px (may be changed), then adds a scrollbar
 * to the city list.
 */
CityListHandler.prototype.manageCityListHeight = function()
{
	var cityListTable = YAHOO.util.Dom.getFirstChild(this.cityListContainer);
	var cityListTableHeight = cityListTable.offsetHeight;
	
	if(cityListTableHeight > 300)
	{
		YAHOO.util.Dom.setStyle(this.cityListContainer, "height", "300px");
		YAHOO.util.Dom.setStyle(this.cityListContainer, "overflow", "auto");
	}
	else
	{
		YAHOO.util.Dom.setStyle(this.cityListContainer, "height", "auto");
	}	
}

/**
 * Adapts the size of the mask iframe to solve a problem in IE6
 */
CityListHandler.prototype.manageMaskFrame = function()
{

	// Gets the region of the city list
	var cityListRegion = YAHOO.util.Dom.getRegion(this.cityListContainer);	
	// And adapt the mask frame	
	YAHOO.util.Dom.setXY("maskFrame", [cityListRegion.left, cityListRegion.top]);
	YAHOO.util.Dom.setStyle("maskFrame", "width", (cityListRegion.right - cityListRegion.left) + "px");
	YAHOO.util.Dom.setStyle("maskFrame", "height", (cityListRegion.bottom - cityListRegion.top) + "px");		
}

/**
 * (This method is fired at the end of the setChar function)
 * Fires the appropriate method according to the key pressed.
 * @param {String} evType : The name of the event (see customEvent at YAHOO!lib)
 * @param {Array} args : The list of the parameters passed in the setChar function ; the event trigger (see customEvent at YAHOO!lib)
 */
CityListHandler.prototype.onKeyBoardPressedEvent = function(evType, args)
{		
	if(this.isCityListVisible())
	{			
		var keyCode = args[0].keyCode;

		if(keyCode == 38)
		{// That means the up arrow has been pressed
			this.highlightPreviousItem();	
		}
		else if (keyCode == 40)
		{// That means the down arrow has been pressed
			this.highlightNextItem();
		}
		else if (keyCode == 13)
		{// That means 'enter' has been pressed
			this.selectHiglightedElement();	
		}		
	}
}

/**
 * (This method is fired when user select a city from the city list)
 * Sets this.citySelectedValue
 */
CityListHandler.prototype.onSetValEvent = function()
{
	this.citySelectedValue = this.cityTextField.value;	
}

/**
 * (This method is fired at the and of the showCities function)
 * Sets this.cityListContainer, this.cityList and hightlights the first item
 * of the cityList.
 */
CityListHandler.prototype.onShowCitiesEvent = function()
{
	this.catchCityListContainer();
	this.catchCityList();
	this.highlightItem(0);
	this.manageCityListHeight();
	this.scrollCityListToTop();

	// Adapt the size of the maskFrame in IE
	this.manageMaskFrame();	
}

/**
 * Scrolls the city list to the top
 */
CityListHandler.prototype.scrollCityListToTop = function()
{
	this.cityListContainer.scrollTop = 0;
}

/**
 * Scrolls the city list to the top
 */
CityListHandler.prototype.scrollCityListToBottom = function()
{
	this.cityListContainer.scrollTop = this.cityListContainer.scrollHeight;
}

/**
 * Selects the current highlighted item and hides the city list container.
 * If there is no highlighted item, just hides the city list container.
 */
CityListHandler.prototype.selectHiglightedElement = function()
{	
	var highlightedItemIndex = this.getHighlightedItemIndex();	
	if(highlightedItemIndex != null)
	{
		var item = this.getItem(highlightedItemIndex);
		var onClickItemProperty = item.attributes.onclick.value;
		eval( '(' + onClickItemProperty + ')');
	}
	this.hide();
}

// Create CityListHandler instance
var cityListHandler = new CityListHandler();	
