// (c) RBA Software Ltd 2001
var gDelimiter=new String("|");
var gIsNav=(navigator.appName.indexOf("Netscape") >= 0);
var gIsIE=(navigator.appName.indexOf("Microsoft") >= 0);

var gAdultCounts=new Array(2,2,2,2,1,3,1,4);
var gChildCounts=new Array(0,1,0,1,0,0,0,0);

function getSelectionValue(obj) {
	if (obj && obj.selectedIndex >= 0) {
		return obj.options[obj.selectedIndex].value;
	}
	return '';
}

function getRadioValue(obj) {
	if (obj) {
		for (var i=0; i<obj.length; i++) {
			if (obj[i].checked)
				return obj[i].value;
		}
	}
	return null;
}

function showField(field,show) {
	var obj=getLayer(field);
	if (!obj) return;
	if (obj.style) {
		obj.style.visibility=show ? "visible" : "hidden";
	} else {
		obj.visibility=show ? "show" : "hide";
	}
}

function dspField(field,show) {
	var obj=getLayer(field);
	if (!obj) return;
	if (obj.style) {
		obj.style.display=show ? "inline" : "none";
	} else {
		obj.display=show ? "block" : "none";
	}
	return false;
}

function getLayer(layer) {
	if (document.all)
		return eval('document.all.'+layer);
	if (document.getElementById)
		return document.getElementById(layer);
	return eval('document.'+layer);
}

function writeToLayer(layer,text) {
	if (!layer) return;
	if (document.layers) {
		layer.document.write(text);
		layer.document.close();
	} else {
		layer.innerHTML=text;
	}
}

function setRadioValue(obj,value) {
	if (!obj || value==null)
		return;
	if (value.length>0) {
		for (var i=0; i<obj.length; i++) {
			if (obj[i].value==value) {
				obj[i].checked=true;
				return;
			}
		}
	}
}

function setSelectionValue(obj,value) {
	if (!obj) return;
	if (value!=null) {
		if (value.length>0) {
			obj.selectedIndex= getIndexOfOption(obj, value);
		} else {
			obj.selectedIndex= -1;
		}
	}
}

function buildSelection(options,values,selected,asString) {
	var o=options.split("|");
	var v,s=str='';
	var selectedOpt;
	if (values==null) {
		v=o;
	} else {
		v=values.split("|");
	}
	selectedOpt= (selected==null) ? -1 : selected;
	for (var i=0; i < o.length; i++) {
		s=(i==selectedOpt) ? 'SELECTED ' : '';
		str+='<OPTION '+s+'VALUE="'+v[i]+'">'+o[i];
	}
	str+='</SELECT>';
	if (asString) {
		return str;
	}
	document.writeln(str);
}

function buildCitySelection(prompt,options,values,selected,asString) {
	var srch='<OPTION class="otherDest" value="SOTHR">'+prompt;
	var o=options.split("|");
	var v,s='';
	var str=srch;
	var selectedOpt;
	if (values==null) {
		v=o;
	} else {
		v=values.split("|");
	}
	selectedOpt= (selected==null) ? -1 : selected+1;
	for (var i=0; i < o.length; i++) {
		s=(i==selectedOpt) ? 'SELECTED ' : '';
		str+='<OPTION '+s+'VALUE="'+v[i]+'">'+o[i];
	}
	str+='</SELECT>';
	if (asString) {
		return str;
	}
	document.writeln(str);
}

function buildAdults(adults,selected,asString) {
	var opts="";
	for (var i=1; i<=adults; i++)
		opts+="|"+String(i);
	return buildSelection(opts,opts,selected,asString);
}

function buildChildAges(ages,selected,asString) {
	var opts="  ";
	var vals="00";
	var j=0;
	var len=ages.length / 2;
	for (var i=0; i<len; i++) {
		var age=parseInt(ages.substr(j,2),10);
		opts+="|"+age;
		vals+="|"+age;
		j+=2;
	}
	return buildSelection(opts,vals,selected,asString);
}

function buildDayList(asString) {
	var opts=" ";
	var vals="00";
	for (var i=1; i<=31; i++) {
		opts+="|"+i;
		vals+="|"+(i<10?'0':'')+String(i);
	}
	return buildSelection(opts,vals,0,asString);
}

function buildMonthYearList(monthNames,startMonth,startYear,monthCount,asString) {
	var fullDate="";
	var fullValue="";
	var sep="|";
	var month=startMonth-1;
	var year=startYear;
	var names=monthNames.split("|");
	var isMY=gDateFormat.indexOf('M')<gDateFormat.indexOf('Y');
	for (var i=0; i<=monthCount; i++) {
		if (isMY) {
			fullDate=fullDate + sep + names[month++]+" "+year;
		} else {
			fullDate=fullDate + sep + year +" "+names[month++];
		}
		fullValue=fullValue + sep+year + "-" + ((month<10)?'0':'') + month;
		if (month==12) {
			month=0;
			year++;
		}
	}
	return buildSelection(fullDate,fullValue,0,asString);
}

function buildNumericSelection(from,count,minSize,asString,increment,suppressBlank) {
	var s="  ";
	var delta=1;
	if(increment)
		delta=increment;
	var doSep=true;
	if (suppressBlank!=null) {
		doSep=!suppressBlank;
		s='';
	}
	var max=from+count;
	for (var i=from; i<max; i=i+delta) {
		if (doSep)
			s+="|";
		s+=pad(String(i),"0",minSize);
		doSep = true;
	}
	return buildSelection(s,null,null,asString);
}

function buildTimeSelection(asString) {
	var opts=" ";
	var vals="0";
	for (var h=0; h<24; h++) {
		for (var m=0; m<60; m+=5) {
			opts+="|"+String(h)+':'+pad(String(m),"0",2);
			vals+="|"+String(h*100+m);
		}
	}
	return buildSelection(opts,vals,asString);
}

function statusMsg(msg) {
	window.status=msg;
	parent.canScroll = false;
	return true;
}

function hideMsg() {
	window.status='';
	parent.canScroll = true;
	return true;
}

function trim(text) {
	if (text==null || text.length==0)
		return '';
	var end=text.length;
	do {
		end--;
	} while (end>=0 && text.charAt(end)==' ');
	if (end<0)
		return '';
	var start=0;
	while (text.charAt(start)==' ')
		start++;
	return text.substring(start,end+1);
}

function isEmpty(text) {
	return (trim(text).length==0);
}

function changeSelection(obj, val, newOption, newValue) {
	with (obj) {
		for (var idx= 0; idx< options.length; idx++) {
			if (options[idx].value== val) {
				options[idx].text= newOption;
				options[idx].value= newValue;
				break;
			}
		}
	}
}

function getIndexOfElement(arr, val) {
	for (var idx=0; idx< arr.length; idx++) {
		if (arr[idx]== val) {
			return idx;
		}
	}
	return null;
}

function pad(str,padChar,minLen,right) {
	var count=minLen - str.length;
	while (count-- > 0)
		str=(right)?(str + padChar):(padChar + str);
	return str;
}

function getChildAgeOpt(min,max) {
	var s='';
	var delim='';
	for (var i=min; i<=max; i++) {
		s+=delim+String(i);
		delim="|";
	}
	return s;
}

function getChildAgeVal(min,max) {
	return getChildAgeOpt(min,max);
}
	
function getRoomTypeDesc(type) {
	var i=getIndexOfElement(gRoomTypeVal.split("|"),type);
	if (i==null)
		return '';
	return (gRoomTypeOpt.split("|"))[i];
}

function truncateEmptyOptions(text) {
	var optionListText= new String(text);
	for (var idx= (optionListText.length-1); idx>= 0; idx--) {
		if (optionListText.charAt(idx)!= "|") {
			return (optionListText.substring(0, (idx+1)));
		}
	}
	return optionListText;
}

function ResetForm(form) {
	form.reset();
	initForm(form);
}

function displayCalendar(event,cal) {
	var win=top.gCalWindow;
	if (!win || win.closed) {
		if (!cal)
			cal="Calendar.jsp";
		win=window.open(cal,"Calendar","width=250,height=185,scrollbars=no,resizable="+(document.layers?"no":"yes"));
		top.gCalWindow=win;
		moveWin(win,event.screenX,event.screenY);
	} else {
		if (win.closed) win.open();
		win.crtCal();
		win.focus();
	}
	return false;
}

function showBusy(text,showImage) {
	var s='<html><head>'+ parent.gStyleSheet+ '</head>';
	s+='<body><table width=100% cellspacing="0" cellpadding="0" align="center" border=0><tr>';
	s+='<td class=titlerow width="100%" align="left">'+text+'...</td></tr></table>';
	if (showImage)
		s+=parent.gWaitImage;
	s+='</body></html>';
	return s;
}

function goWait(url,submitter,target) {
	location.replace(url+'?submitter='+submitter+'&target='+target);
}

function showElementsIn(select) {
	var text='';
	var select=window.prompt("Show what?",select);
	var obj=eval(select);
	if (obj) {
		if (typeof(obj)!="object") {
			text=select+'='+obj;
		} else {
		for (var idx in obj) {
			text+=', ' + idx + '=' + obj[idx];
		}}
		alert(text);
	}
}

function addSelection(obj, newOption, newValue) {
	obj.options[obj.options.length]= new Option(newOption, newValue);
	return obj.options.length-1;
}

function addSortedSelection(obj, newOption, newValue) {
	var idx= obj.options.length;
	obj.options[obj.options.length]= new Option(' ', ' ');
	while (idx> 0 && obj.options[idx-1].text> newOption) {
		obj.options[idx].text= obj.options[idx-1].text;
		obj.options[idx].value= obj.options[idx-1].value;
		idx--;
	}
	obj.options[idx].text= newOption;
	obj.options[idx].value= newValue;
	return idx;
}

function addToOptionList(obj, newOption, newValue) {
	var idx= getIndexOfOption(obj, newValue);
	var add= idx< 0 ? true: false;
	if (add)
		idx= addSortedSelection(obj, newOption, newValue);
	setOptionSelected(obj, idx);
	return add;
}

function addToEndOfOptionList(obj, newOption, newValue) {
	var idx= getIndexOfOption(obj, newValue);
	var add= idx< 0 ? true: false;
	if (add) {
		idx= obj.options.length;
		obj.options[idx]= new Option(' ', ' ');
		obj.options[idx].text= newOption;
		obj.options[idx].value= newValue;
	}
	setOptionSelected(obj, idx);
	return add;
}

function getIndexOfOption(obj, value) {
	if (obj.options) {
		for (var idx= 0; idx< obj.options.length; idx++) {
			if (obj.options[idx].value== value)
				return idx;
		}
	}
	return -1;
}

function setOptionSelected(obj, idx) {
	//obj.options[idx].selected= true;
	obj.selectedIndex= idx;
}

function displaySearchDest(url,width,height) {
	var win=top.gSearchDestWindow;
	var w=(width!=null)?width:600;
	var h=(height!=null)?height:450;
	if (!win || win.closed) {
		win= window.open(url,"","width="+w+",height="+h+",resizable,scrollbars");
		moveWin(win,screen.availWidth-600,30);
		top.gSearchDestWindow=win;
	} else {
		if (win.closed) win.open();
		win.location.replace(url);
		win.focus();
	}
	return false;
}

function displayEmailSearch(url,client,value) {
	var win=top.gSearchEmailWindow;
	url+='?searchClientId='+client+'&search='+escape(value);
	if (!win || win.closed) {
		win= window.open(url,"","width=800,height=400,resizable,scrollbars");
		moveWin(win,screen.availWidth-850,30);
		top.gSearchEmailWindow=win;
	} else {
		if (win.closed) win.open();
		win.location.replace(url);
		win.focus();
	}
	return false;
}

function closeWindows() {
	closeCal();
	closePopUp();
	closeSearchDest();
	closeInfo();
	closeSearchEmail();
}

function closeCal() {
	var win=top.gCalWindow;
	if (win!= null && !win.closed)
  		win.close();
}

function closePopUp() {
	var win=top.gPopUpWindow;
	if (win!= null && !win.closed)
  		win.close();
}

function closeSearchDest() {
	var win=top.gSearchDestWindow;
	if (win!= null && !win.closed)
  		win.close();
}

function closeSearchEmail() {
	var win=top.gSearchEmailWindow;
	if (win!= null && !win.closed)
  		win.close();
}

function closeInfo() {
	var win=top.gInfoWindow;
	if (win!= null && !win.closed)
  		win.close();
}

function getStatusDesc(code,descList,codeList) {
	for (var i=0; i<codeList.length; i++) {
		if (code==codeList[i]) {
			return descList[i];
		}
	}
	return " ";
}

function setCommonCity(city, cityName, countryName) {
	var cityAndCountryName= cityName;
	if (trim(countryName).length>0)
		cityAndCountryName+=', '+countryName;
	var obj=getCityField();
	if (addToOptionList(obj, cityAndCountryName, city)) {
		var optArr=valArr=sep='';
		var len=obj.options.length;
		for (var idx=0; idx< len; idx++) {
			if (obj.options[idx].value!='SOTHR') {
				optArr+= sep+obj.options[idx].text;
				valArr+= sep+obj.options[idx].value;
				sep='|';
			}
		}
		parent.gCityOpt=optArr;
		parent.gCityVal=valArr;
	}
	return true;
}
function setCommonArea(city, cityName) {
	var obj=getCityField();
	if (addToOptionList(obj, cityName, city)) {
		var optArr=valArr=sep='';
		var len=obj.options.length;
		for (var idx=0; idx< len; idx++) {
			if (obj.options[idx].value!='SOTHR') {
				optArr+= sep+obj.options[idx].text;
				valArr+= sep+obj.options[idx].value;
				sep='|';
			}
		}
		parent.gCityOpt=optArr;
		parent.gCityVal=valArr;
	}
	return true;
}
function setCommonUI(ui, name, type) {
	var obj=getUI(type);
	if (addToOptionList(obj, name, ui)) {
		var optArr=valArr=sep='';
		var len=obj.options.length;
		for (var idx=0; idx< len; idx++) {
			if (obj.options[idx].value!='SOTHR') {
				optArr+= sep+obj.options[idx].text;
				valArr+= sep+obj.options[idx].value;
				sep='|';
			}
		}
	}
	return true;
}


function moveWin(win,x,y) {
	win.moveTo(x,y);
}

function openPopUp(url,event,width,height,move,centre,options) {
	var win=top.gPopUpWindow;
	if(width==null)
		width = 500;
	if(height==null)
		height = 500;
	if (!win || win.closed) {
		if (!options) {
			options="resizable,scrollbars";
		}
		win=window.open(url,"","width=" + width + ",height=" + height + ","+options);
		top.gPopUpWindow=win;
		var y=(event!=null)?event.screenY:9999;
		if (move!=false)
			if(centre){
				moveWin(win,(screen.availWidth-width)/2,(screen.availHeight-height)/2)
			}else{
				moveWin(win,screen.availWidth-width-20,20);
			}
	} else {
		if (win.closed) win.open();
		win.focus();
		win.location.replace(url);
	}
	return false;
}

function openInfo(url,event,width,height) {
	location=url;
	return false;
}

function showItem(event,url,city,code,lang,book,existBed,immed) {
	return openInfo(url+'?city='+trim(city)+'&item='+trim(code)+(book!=null?'&book='+trim(book)+'&existBed='+trim(existBed)+'&immed='+trim(immed):''),event);
}

function showRSItem(event,url,city,code,lang,date,langList,spcCode) {
	return openInfo(url+'?city='+escape(city)+'&item='+escape(code)+'&date='+escape(date)+'&langlist='+escape(langList)+'&spccode='+escape(spcCode),event);
}

function showTNItem(event,url,city,item,type,vhcInfo) {
	return openInfo(url+'?minCat='+type+'&city='+city+'&item='+escape(item)+'&vhcInfo='+vhcInfo,event);
}

function showAAInfo(event,url,type,city,item,lang,dur,startDate) {
	return openInfo(url+'?apttype='+escape(type)+'&city='+escape(city)+'&item='+escape(item)+'&dur='+escape(dur)+'&startdate='+escape(startDate),event);
}

function showVHInfo(event,url,suppCity,supp,destCity,acriss,servDate,crtDate) {
	return openInfo(url+'?suppCity='+suppCity+'&supp='+supp+'&destCity='+destCity+'&acriss='+acriss+'&servDate='+servDate,event);
} 

function showFlashPrsnt(url,city,item,itemType,imgType,printImgType,itemDesc) {
	gItemDesc=itemDesc;
	return openPopUp(url+'?city='+trim(city)+'&item='+trim(item)+'&itemType='+itemType+'&imgType='+imgType+'&printImgType='+printImgType,null,600,500);
}

function showFlashImage(url,imgType,printImgType,itemDesc,image,srvType) {
	parent.opener.gItemDesc=itemDesc;
	return location.href=url+'?imgType='+imgType+'&printImgType='+printImgType+'&image='+image+'&srvType='+srvType;
}

function showGroupInfo(event,url,ui) {
	return openInfo(url+'?ui='+ui,event);
}
function showClientInfo(event,url,clientId,page,from) {
	if (from != null) {
		if (clientId.length == 0) {
			if (from=='BKG') {
				alert(gMsg5);
				return false;
			}
			if (from=='ITM') {
				alert(gMsg4);
				return false;
			}
		}
}
	return openPopUp(url+'?clientId='+clientId+'&nextPage='+page,event,600,450);
}

function showInfo(event,url,type,city,item,lang,book,existBed,immed,dur,startDate) {
	if (type=='HH') {
		return showItem(event,url,city,item,lang,book,existBed,immed);
	}
	if (type=='AA') {
		return openInfo(url+'?apttype='+escape(type)+'&city='+escape(city)+'&item='+escape(item)+'&dur='+escape(dur)+'&startdate='+escape(startDate),event);
	}
	return openPopUp(url+'?type='+escape(type)+'&city='+escape(city)+'&item='+escape(item),event,400,200,false);
}

function showPics(event,url,city,code,lang) {
	return showItem(event,url,city,code,lang);
}

function showMap(event,url,city,code) {
	return openPopUp(url+'?city='+trim(city)+'&item='+trim(code),event,800,500,false,false,"resizable,scrollbars,status");
}

function getKeyEvent(event) {
	if (event.keyCode)
		return event.keyCode;
	if (event.which)
		return event.which;
	return 0;
}

function editKey(event,delimiters) {
	var key=getKeyEvent(event);
	if (key==8 || key==9) return true;
	var chr=String.fromCharCode(key);
	if (delimiters==null)
		delimiters='/\\d/';
	var exp=eval(delimiters);
	return chr.match(exp)!=null;
}

function openPaymentPopUp(url,event) {
	var win=top.gPaymentWindow;
	if (!win || win.closed) {
		win=window.open(url,"Payment","width=400,height=500,resizable,scrollbars,status");
		top.gPaymentWindow=win;
		var y=(event!=null)?event.screenY:9999;
	} else {
		if (win.closed) win.open();
		win.focus();
		win.location.replace(url);
	}
	return false;
}

function closePaymentPopUp() {
	var win=top.gPaymentWindow;
	if (win!= null && !win.closed)
  		win.close();
}

function roll(imgName,rollover) {
	document.images[imgName].src = gRoll[rollover].src;
}

function buildDateSelection(dayField,mthField,monthNames,startMonth,startYear,monthCount,asString) {
	var dayList=dayField+buildDayList(true);
	var mthList=mthField+buildMonthYearList(monthNames,startMonth,startYear,monthCount,true);
	var isDM=gDateFormat.indexOf('D')<gDateFormat.indexOf('M');
	var s= isDM ? dayList+mthList: mthList+dayList;
	if (asString) {
		return s;
	}
	document.writeln(s);
}

function getFirstOption(options) {
	var str='';
	var o=options.split("|");
	if (o.length==2)
		str=o[1];
	return str;
}

function addFavourite(url,name) {
	if (window.external) {
		window.external.AddFavorite(url,name);
	} else {
		window.prompt(gFavourite,gHomeUrl);
	}
	return false;
}
function showInfoApt(event,url,type,city,item,aptType,lang,dur,startDate,book) {
	if ((type=='HH') || (type=='AA')){
		return showItemApt(event,url,city,item,aptType,dur,startDate,book);
	}
}

function showItemApt(event,url,city,code,aptType,dur,startDate,book) {
	if (book==null)
		return openInfo(url+'?city='+trim(city)+'&item='+trim(code)+'&apttype='+trim(aptType)+'&dur='+trim(dur)+'&startdate='+trim(startDate),event);
	return openInfo(url+'?city='+trim(city)+'&item='+trim(code)+'&apttype='+trim(aptType)+'&dur='+trim(dur)+'&startdate='+trim(startDate)+(book!=null?'&book='+trim(book):''),event);
}	

function showDuration(days,hrs,mins) {
	var s="";
	if (days>0) {
		s+=days + "&nbsp;" + gDurText[(days==1)?0:1] + " ";
	}
	if (hrs>0) {
		s+=hrs + "&nbsp;" + gDurText[(hrs==1)?2:3] + " ";
	}
	if (mins>0) {
		s+=mins + "&nbsp;" +gDurText[4];
	}
	document.write(s);
}

function showSpecialOffer(event,url,city,code,type,desc,cityName,startDate,endDate) {
	return openPopUp(url+'?city='+trim(city)+'&item='+trim(code)+'&type='+trim(type)+'&desc='+trim(desc)+'&cityName='+trim(cityName)+'&startDate='+trim(startDate)+'&endDate='+trim(endDate),event,600,300,false);
}

function showIdeas(event,url,city,item,cityName,srvType) {
	return openPopUp(url+'?city='+trim(city)+'&item='+trim(item)+'&cityName='+cityName+'&srvType='+srvType,event,600,500);
}

function rtnBasket(url) {
	if (gLoaded) {
		location.href=url;
	}
	return false;
}
function dspTableRow(field,show) {
	var obj=getLayer(field);
	if (!obj) 
		return;
	if (obj.style) {
		if (gIsIE) {
			obj.style.display=show ? "inline" : "none";
		} else {
			obj.style.display=show ? "table-row" : "none";
		}
	} else {
		obj.display=show ? "block" : "none";
	}
	return false;
}