// Developed by Ermisoft LLC.

function advSearch(sStpc) 
{
	if (sStpc == '') sStpc = 'dle2e0';
	location.href = 'http://www.holidayroomsdirect.com/default.asp?stpc=' + sStpc;
}

function SubscribeSpecial() 
{
	document.frmSpecial.action = 'http://www.holidayroomsdirect.com/default.asp?stpc=dle2e0';
	document.frmSpecial.submit();
}



function hotelPrices(DestinationCountry, Destination, Establishment) 
{
	location.href = 'http://www.holidayroomsdirect.com/ash_hotel_details.asp?DestinationCountry='+DestinationCountry+'&Destination='+Destination+'&Establishment='+Establishment;
}


function goLink(sURL) 
{
	var re;
	re = /~/g;
	
	sURL = sURL.replace('http|', 'http://');
	sURL = sURL.replace(re, '.');
	
	location.href = sURL;
}

function goLinkBlank(sURL) 
{
	var re;
	re = /~/g;
	
	sURL = sURL.replace('http|', 'http://');
	sURL = sURL.replace(re, '.');
	
	window.open(sURL, '_blank');
}

function goResort() 
{
	var elSel = frmResort.lstItems;
	var sURL = elSel.options[elSel.selectedIndex].value
	if (sURL.length > 0) 
		location.href = sURL
	else {
		alert('Please select item');
		elSel.focus();
	};
}


function openDlg(url, name, id, width, height) 
{
	if(isNaN(numID = parseInt(id, 10)))
		numID = id.substring(1, (id.length > 5)?5:id.length);
	openWindow(url, name + numID, width, height, "status=no,toolbar=no,resizable=yes,scrollbars=no,menubar=no");
}

function openWindow(url, name, width, height, features) {
	var win;
	var top = 0;
	var left = 0;
	
	if (screen.width > width) left = (screen.width - width) / 2;
	if (screen.height > height) top = (screen.height - height) / 2;
	
	if (typeof(features) == "undefined") win = window.open(url, name, 'left='+left+',top='+top+',screenX='+left+',screenY='+top+',width='+width+',height='+ height);
	else win = window.open(url, name, 'left='+left+',top='+top+',screenX='+left+',screenY='+top+',width='+width+',height='+ height +', ' + features);
		
	if (navigator.appName != 'Microsoft Internet Explorer')  { if ( window.focus )  win.focus()};
}

function closeWindow(reload, frmName) {
	if (reload == 'reload') 
		if (!top.opener.closed) {
			eval('frm = top.opener.document.' + frmName);
			if (frm) frm.submit();
		}
	
	top.close();
}

function validateEmail(strValue) {
	var objRegExp  =  /(^\w([\w\.\-\_]*)\@[\w\-\_]+\.([\w\-\_]+\.)*\w+$)/; 
	return objRegExp.test(strValue);
}

function getRandom() {
	return Math.random();
}

function getRandomDlgID() {
	return Math.round(getRandom() * 10000);
}

function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

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];}
}


function FormatN(iNum, iPos) {
	var iNewNum = iNum;
	for (var i=iNewNum.toString().length; i<iPos; i++)
		iNewNum = '0' + iNewNum;
	return iNewNum;
}

function DateAdd(iDays, dtDate) {
	nFullDay = 1000*60*60*24;
	return new Date(dtDate.getTime() + (iDays * nFullDay));
}

function GetDays(dtDate) {
	nFullDay = 1000*60*60*24;
	return dtDate / nFullDay;
}

function ChangeDeparture() {
	var dtNow = new Date();
	var frm = document.frmSearch;
	var nDur = frm.Duration.value;
	
	var iDay = frm.ArrD.options[frm.ArrD.selectedIndex].value;
	var iMonth = frm.ArrM.options[frm.ArrM.selectedIndex].value;
	var iYear = frm.ArrY.options[frm.ArrY.selectedIndex].value;
	var dtArr = new Date(iYear,iMonth - 1,iDay);
	
	if (dtArr < dtNow) {
		dtArr = dtNow;
		SetArrivalToday();
	}
	
	dtDep = DateAdd(nDur, dtArr)
	
	frm.DepD.selectedIndex = dtDep.getDate() - 1;
	frm.DepM.selectedIndex = dtDep.getMonth();
	frm.DepY.selectedIndex = dtDep.getFullYear() - dtNow.getFullYear();
}

function ChangeDuration() {
	var nMaxDur = 30;
	var dtNow = new Date();
	var frm = document.frmSearch;
	
	var iDay = frm.DepD.options[frm.DepD.selectedIndex].value;
	var iMonth = frm.DepM.options[frm.DepM.selectedIndex].value;
	var iYear = frm.DepY.options[frm.DepY.selectedIndex].value;
	var dtDep = new Date(iYear,iMonth - 1,iDay);
	
	var iDay = frm.ArrD.options[frm.ArrD.selectedIndex].value;
	var iMonth = frm.ArrM.options[frm.ArrM.selectedIndex].value;
	var iYear = frm.ArrY.options[frm.ArrY.selectedIndex].value;
	var dtArr = new Date(iYear,iMonth - 1,iDay);
	
	var nDur = GetDays(dtDep - dtArr);
	
	if (nDur < 1) {
		nDur = 1;
		frm.Duration.selectedIndex = nDur - 1;
		SetDeparuteCorrect();
	} else if (nDur > nMaxDur) {
		nDur = nMaxDur;
		frm.Duration.selectedIndex = nDur - 1;
		SetDeparuteCorrect();
	} else {
		frm.Duration.selectedIndex = nDur - 1;
	}
}

function SetArrivalToday() {
	var dtNow = new Date();
	var frm = document.frmSearch;
	var nDur = frm.Duration.value;
	var dtDep;
	
	frm.ArrD.selectedIndex = dtNow.getDate() - 1;
	frm.ArrM.selectedIndex = dtNow.getMonth();
	frm.ArrY.selectedIndex = 0;
	
	dtDep = DateAdd(nDur, dtNow)
	
	frm.DepD.selectedIndex = dtDep.getDate() - 1;
	frm.DepM.selectedIndex = dtDep.getMonth();
	frm.DepY.selectedIndex = dtDep.getFullYear() - dtNow.getFullYear();
}

function SetDeparuteCorrect() {
	var dtNow = new Date();
	var frm = document.frmSearch;
	var nDur = frm.Duration.value;
	
	var iDay = frm.ArrD.options[frm.ArrD.selectedIndex].value;
	var iMonth = frm.ArrM.options[frm.ArrM.selectedIndex].value;
	var iYear = frm.ArrY.options[frm.ArrY.selectedIndex].value;
	var dtArr = new Date(iYear,iMonth - 1,iDay);
	
	var dtDep = DateAdd(nDur, dtArr)
	
	frm.DepD.selectedIndex = dtDep.getDate() - 1;
	frm.DepM.selectedIndex = dtDep.getMonth();
	frm.DepY.selectedIndex = dtDep.getFullYear() - dtNow.getFullYear();
}

function SetChildAges() {
	var frm = document.frmSearch;
	var sParty = frm.AdultsChildren1.options[frm.AdultsChildren1.selectedIndex].value;
	var nChild = parseInt(sParty.substring(2,3));
	
	if (nChild == 0) {
		document.all("spChildAge").style.display = "none";
		document.all("spChildInfo").style.display = "none";
	} else	{
		document.all("spChildAge").style.display = "inline"
		document.all("spChildInfo").style.display = "inline";
	}
	
	for(var j = 1; j <= nChild; j++) {
		var elChildAge = eval("frm.ChildAge1_" + j);
		elChildAge.style.display = "inline";
	}
	for(var j = nChild + 1; j <= 4; j++) {
		var elChildAge = eval("frm.ChildAge1_" + j);
		elChildAge.style.display = "none";
	}

}


function UpdateDates() {
	var frm = document.frmSearch;
	
	frm.Arrival.value = FormatN(frm.ArrD.value, 2) + '/' + FormatN(frm.ArrM.value, 2) + '/' + frm.ArrY.value;
	frm.Departure.value = FormatN(frm.DepD.value, 2) + '/' + FormatN(frm.DepM.value, 2) + '/' + frm.DepY.value;
}

function UpdateAdultsChildren() {
	var frm = document.frmSearch;
	var elAC = frm.AdultsChildren1;
	
	for(var j = 0; j < elAC.length; j++) {
		ss = elAC.options[j].text;
		re = /1 A\./g; 
		ss = ss.replace(re, '1 Adult')
		re = /1 C\./g; 
		ss = ss.replace(re, '1 Child')

		re = /A\./g; 
		ss = ss.replace(re, 'Adults')
		re = /C\./g; 
		ss = ss.replace(re, 'Children')
		elAC.options[j].text = ss;
	}
}

function SearchHotels() {
	var frm = document.frmSearch;
	var sParty = frm.AdultsChildren1.options[frm.AdultsChildren1.selectedIndex].value;
	var nChild = parseInt(sParty.substring(2,3));
	
	frm.action = 'http://www.holidayroomsdirect.com/hotels.asp';

	UpdateDates();
	
	for(var j = 1; j <= nChild; j++) {
		var elChildAge = eval("frm.ChildAge1_" + j);
		if(elChildAge.selectedIndex < 1) {
	   		alert('Please select a child age');
	   		elChildAge.focus();
			return;
	   	}
	}
	
	SearchHBGo();
}

function SearchHBGo() {
	//document.all("divProgressBar").style.display = "block";
	var frm = document.frmSearch;
	var sParty = frm.AdultsChildren1.options[frm.AdultsChildren1.selectedIndex].value;
	var sArr = frm.ArrD.options[frm.ArrD.selectedIndex].value+'/'+
		frm.ArrM.options[frm.ArrM.selectedIndex].value+'/'+
		frm.ArrY.options[frm.ArrY.selectedIndex].value;
	var nChild = parseInt(sParty.substring(2,3));


	var sReturn='';
	var sURL='';
	sReturn+='room1='+sParty.replace('|',',')+',0';
	
	if(nChild>0) {
		sReturn+='_';
		for(var j = 1; j <= nChild; j++) {
			var elChildAge = eval("frm.ChildAge1_" + j);
			var nAge = elChildAge.options[elChildAge.selectedIndex].value;
			sReturn+=nAge;
			if (j != nChild) sReturn+=',';
		}
	};
	sReturn+='&';
	
	sReturn+='date='+sArr+'&';
	sReturn+='duration='+frm.Duration.options[frm.Duration.selectedIndex].value+'&';
	
	sRes=parseInt(frm.resortid.value);
	sReg=parseInt(frm.regionid.value);
	if (sReg == -231) {
		sRes = 231;
		sReg = 53;
	} else if (sReg == -41) {
		sRes = 41;
		sReg = 9;
	}
	if (Math.abs(sRes) > 0 )
		sReturn+='resortid='+Math.abs(sRes)+'&';
	if (Math.abs(sReg) > 0 )
		sReturn+='regionid='+Math.abs(sReg)+'&' ;

	sPrID=frm.propertyid.value;
	if (sPrID!='') sReturn+='propertyid='+sPrID+'&';
	sURL='http://www.holidayroomsdirect.com/property_results.asp?cref=0&'+sReturn;
	window.location=sURL;
}

