var lcids;
lcids='';

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}


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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}

function MM_qschangeidtext(tcid, tctext) { 
	var node;
	lonode = document.getElementById(tcid);
	lonode.innerHTML = tctext;
}

function updatehref(tcid, tcurl)
{
var lonode;
	lonode = document.getElementById(tcid);
	lonode.href = "https://" + document.domain + tcurl.replace(/&amp;/g, "&");
return true
}


function translatepage(tcpage, lclangs)
{

if (tcpage.length == 0)
{
	return false

}

	var lnlength;
	var loxmlhttp;
	var lnlang;
	var lonodes;
	
	lnlang = 0;
	lnlang = 2;
	lonodes = document.getElementsByTagName('span');
	lnlength = lonodes.length  ;
	loxmlhttp = new ActiveXObject("msxml2.xmlhttp");

	for (lni=1; lni < lnlength ; lni++)
	{
		lcid = lonodes.item(lni).id ;
		
		if ((lcid != '') && (lcids.indexOf(lcid) == -1 ))
		{
			lchtml = lonodes.item(lni).innerHTML ;
		    loxmlhttp.open('POST', tcpage + '?langid=' + lnlang  + '&langs='+ lclangs +'&appname=SP&apptag=sp&mtlcode=' + lcid + '&mtltext=' + lchtml.replace('&', '&amp;'), false) ;
	    	loxmlhttp.send();
	    	lcids = lcids + ';' + lcid;
	    	
	    }

	}
}

function GetSiteIDByUrl()
{
    var lcURL 			= window.location.toString();
    var loSites 		= new Array("secretplaces.com","secretplaces.es","secretplaces.de")
    var loSitesId		= new Array("1","2","3")
    var lnIdSite		= 0
    var x ;

    for (x in loSites)
    {	
	    if( lcURL.indexOf(loSites[x]) > 0 )
	    {	
		    lnIdSite = loSitesId[x];
	    }
    }
    return lnIdSite
}




		function setstatusto(tocaller)
		{
			var lnnewstatus = tocaller.getAttribute('value');
	
			//seting global var
			gnstatusactive = lnnewstatus * 1;

		}
		
		function setallday(tocaller){
		
			var loroomsid, i, lctdtoget

			if(!(tocaller.id))
			{
				tocaller = document.getElementById(tocaller)
			
			}

			var lcdebug = ''
			
			if (!(gnstatusactive))
			{
				lcmessagestatus = 'Please choose an \"Availability Status\"';

				alert(lcmessagestatus);

				return false;
			}

			loroomsid = gcroomspkid.split(',')
			lctdtoget = 'tddayroom_' + tocaller.getAttribute("daydate")  

			for (i=0;i< loroomsid.length; i++)
			{
				setdaystatus(lctdtoget +'_' + loroomsid[i], gnstatusactive, 0)
				lcdebug =lcdebug + 'p' + lctdtoget +'_' + loroomsid[i]
			
			}					
		}		


function setdaystatus(tocaller, tnstatus, tntoggle)
		{


			if(!(tocaller.id))
			{
				tocaller = document.getElementById(tocaller)
			
			}

			var lcmessagestatus
			var lcinputtosetname, loinputtoset
			var lctocallerid
			var lcclassname
			var lcactiontype, lnroomstpkid


			if (!(tnstatus))
			{
				lcmessagestatus = 'Please choose an \"Availability Status\"';

				alert(lcmessagestatus);

				return false;
			}

			if (tocaller.getAttribute('actiontype').toLowerCase() == 'hotelclosed')
			{				
				return false;
			}

			lctocallerid 		= tocaller.id
			lcinputtosetname 	= lctocallerid.replace('tddayroom','inproomstatus');
			loinputtoset		= document.getElementById(lcinputtosetname);

			switch (tnstatus)
			{
				case 1:
					lcclassname = 'bo_roomavailable';

				  break;
				case 2:
					lcclassname = 'bo_roomnotavailable';
		
				  break;
				case 3:
					lcclassname = 'bo_roomonrequest';
		
				  break;		  
			}
			//ie
			tocaller.setAttribute('className',lcclassname);
			
			//mozilla
			tocaller.setAttribute('class',lcclassname);
			

			if (tocaller.getAttribute('initialstatus')== tnstatus)
			   {
			   	loinputtoset.value = tnstatus;

				//dont post remove name

				loinputtoset.name= '';
			   }
			else if (!(loinputtoset.value == tnstatus))
			   {
			   	loinputtoset.value = tnstatus;

				lcactiontype = tocaller.getAttribute("actiontype");
				lnroomstpkid = tocaller.getAttribute("roomstpkid");
				
				loinputtoset.name = lcactiontype +'_'+ tocaller.id +'_' + lnroomstpkid ;
			   }
			else if ((tntoggle == 1) && (loinputtoset.value == loinputtoset.value))
			   {
					//alert(tocaller.getAttribute('initialstatus') * 1);

			   		setdaystatus(tocaller, tocaller.getAttribute('initialstatus') * 1, tntoggle)
			   }
			
		}


function isKeyPressed(event)
{
	if (event.ctrlKey==1)
	  {
		return true;
	  }
	else
	  {
	  	return false;
	  }
}


function setdaystatusrange(tocaller, tnstatus)
{

	var lnbegindate, lnbenddate
	var lnbeginroomid, lnendroomid
	var lobegindata, loenddata
	var lctdtocall

	var i

	if (gclastclick.length >0)
	{
		
		lobegindata = gclastclick.split('_')
		loenddata	= tocaller.id.split('_')
		
		lnbegindate = lobegindata[1]*1;
		lnbenddate 	= loenddata[1]*1;

		lnbeginroomid 	= lobegindata[2]*1;
		lnendroomid		= loenddata[2]*1;
		
		//check for the same roomid
		if(lnbeginroomid==lnendroomid)
		{
			for(i=lnbegindate+1;i<=lnbenddate;i++)
			{
				lctdtocall = loenddata[0] + '_' + i + '_' + lnendroomid;	
				
				setdaystatus(lctdtocall, tnstatus, 0);
			}		
		}
		
		gclastclick='';
	}
	else
	{		
		gclastclick = tocaller.id;
		setdaystatus(tocaller, tnstatus,0);			
	}
}


function setalldaystatusrange(tocaller)
{
	
	var lnbegindate, lnbenddate
	var lobegindata, loenddata
	var lctdtocall

	var i

	if (gclastclickallday.length >0)
	{
		
		lobegindata = gclastclickallday.split('_')
		loenddata	= tocaller.id.split('_')
		
		lnbegindate = lobegindata[1]*1;
		lnbenddate 	= loenddata[1]*1;

		
		//check for the same roomid
		if(!(lobegindata[2] && loenddata[2]))
		{
			for(i=lnbegindate+1;i<=lnbenddate;i++)
			{
				lctdtocall = loenddata[0] + '_' + i ;	
				
				setallday(lctdtocall);
			}		
		}
		
		gclastclickallday='';
	}
	else
	{		
		gclastclickallday = tocaller.id;
		setallday(tocaller);			
	}
}



function getchildbytagname(tocaller,tctag)
{
	var lochildnodes
	
	lochildnodes 	= tocaller.getElementsByTagName(tctag);
	return lochildnodes

}

function checkgroup(tocaller, tcelementsname)
{
	var toelements, larootelementsname, lorootelement, i, n


	//alert(tocaller.name);

	larootelementsname = tcelementsname.split(',')
	
	for (i=0;i<larootelementsname.length;i++)
	{
		lorootelement = document.getElementById(larootelementsname[i])

		toelements = lorootelement.getElementsByTagName(tocaller.tagName);


	//alert(toelements.length +'\ntocaller.tagName:'+ tocaller.tagName);
	
		//alert(toelements.length );

			for (n=0;n<toelements.length;n++)
			{		

				if (tocaller.value == toelements[n].value && tocaller.getAttribute('group') == toelements[n].getAttribute('group'))
				{
					toelements[n].checked = true;
				
				}
			}
	}
}

function addtogcmenulodedid(tctoadd)
{
			if(gcmenulodedid)
			{			
				gcmenulodedid = gcmenulodedid + ',' + tctoadd
			}
			else
			{
				gcmenulodedid = tctoadd
			}

}

function removelinks(tonode)
{
	var lolinks, i

	if(!(tonode.id))
	{
		tonode = document.getElementById(tonode);
	
	}

	lolinks = tonode.getElementsByTagName('a')

	for (i=0;i < lolinks.length;i++)
	{
		lolinks[i].removeAttribute("href");

	}
tonode.innerHTML = ' ';

}




//functions to alternative hotels


function loadalternativehotels(tnhotelid, tnfolderid){

	var lcpage, lcurl, loEl;
	lcurl 	='/vd.asp?WCX=viewdisplay&FOLDERID=' + tnfolderid + '&USERAW=YES&ADDVIEWDIV=YES&SETVAR_sp_ws_hotelid='+tnhotelid


	http_execute('div_alternativehotelslist', lcurl);
	
	loEl = new elUi('sp_roomstatus_root')
	loEl.hide();
	
	loEl = new elUi('div_alternativehotels')
	loEl.show();
	
	loEl = new elUi('div_alternativehotelslist')
	loEl.show();
	
	loEl = new elUi('div_alternativehotels_root')
	loEl.show();
	
	
 	//DIV_hide('sp_roomstatus_root');
	//DIV_show('div_alternativehotels');
	//DIV_show('div_alternativehotelslist');
	//DIV_show('div_alternativehotels_root');

	// setinnerHTML ('div_alternativehotels',lcpage);
	// pushJavaScript(lcpage,0)

}

// end functions to alternative hotels


function printcal(tocaller, tccaldiv, tnhotelid, tnlang, tnfolderid)
{
var lodivcal, lcurl ;
var lccriteria, lcmaxdate, lcmindate;

var lcmessagecheck, lcmessagegetingdata, loEl;


lcmessagecheck		= '';
lcmessagegetingdata	= getinnerHTML('sp_msg_gettingdataplswait');

lcmaxdate = document.getElementById("ckoyear").value;
lcmaxdate = lcmaxdate +'.'+ document.getElementById("ckomonth").value;
lcmaxdate = lcmaxdate +'.'+ document.getElementById("ckoday").value;

lcmindate = document.getElementById("ckiyear").value;
lcmindate = lcmindate +'.'+ document.getElementById("ckimonth").value;
lcmindate = lcmindate +'.'+ document.getElementById("ckiday").value;

lodivcal = document.getElementById(tccaldiv);

tocaller.value	=	lcmessagegetingdata
tocaller.disabled = true;

if(tnlang==0)
{
	tnlang = 1;
}

tnlang = tnlang*1;

lcurl 	='/vd.asp?WCX=viewdisplay&FOLDERID=' + tnfolderid + '&USERAW=YES&ADDVIEWDIV=YES'


lcurl = lcurl + '&SETVAR_SP_wsreqminwdate=' + lcmindate;
lcurl = lcurl + '&SETVAR_SP_wsreqmaxwdate=' + lcmaxdate;
lcurl = lcurl + '&SETVAR_sp_langid='+ tnlang;
lcurl = lcurl + '&SETVAR_spwb_hotelid='+ tnhotelid;
lcurl = lcurl + '&SETVAR_sp_wspricetype=half board';

http_execute(tccaldiv, lcurl)

loEl = new elUi('sp_roomstatus_root')
loEl.show();
// DIV_show("sp_roomstatus_root");

lodivcal.setAttribute('currmaxdate',lcmaxdate);
lodivcal.setAttribute('currmindate',lcmindate);

loEl = new elUi('sp_btnalternative')
loEl.show();
loEl = new elUi('div_alternativehotels_root')
loEl.hide();

//DIV_show("sp_btnalternative");
//DIV_hide('div_alternativehotels_root');


}


function getstrbt(tcstr,tcastr,tcbstr, tnmode)
{

	var lnstrini, lnstrend, lcworkingstr	

	lnstrini 		= tcstr.indexOf(tcastr)
	lnstrend 		= tcstr.length
	tcstr			= tcstr.substring(lnstrini - tnmode,lnstrend)	
	lnstrini 		= tcastr.length
	lnstrend 		= tcstr.substring(lnstrini  ,lnstrend).indexOf(tcbstr)
	lnstrend  		= lnstrend + lnstrini	
	tcstr			= tcstr.substring(lnstrini,lnstrend + tnmode)
	
	return tcstr;
}



function userexists()
{
	var lcurl, lcuseremail, lcworkingstr, lluserexists, loHttp;

	lluserexists = false;

	loHttp = new xmlHttpDom();
	lcuseremail = document.getElementById('email').value

	lcurl 	='/vd.asp?WCX=viewdisplay&FOLDERID=' + lnfiduserexists+ '&USERAW=YES&ADDVIEWDIV=NO'
	lcurl = lcurl + '&vp_inputemail=' + lcuseremail;

	//lcworkingstr 	= http_execute_url('GET',lcurl)
	lcworkingstr 	= loHttp.callUrl('GET',lcurl)
	lcworkingstr	= getstrbt(lcworkingstr,'div_countrecdata','<',1)
	lcworkingstr	= getstrbt(lcworkingstr,'>','<',0)
	
	if(parseInt(lcworkingstr) > 0) 
	{
		lluserexists = true;	
	}
	return lluserexists;
	
}


function printdebug(lctoprint)
{
	document.getElementById('divdebug').innerHTML = lctoprint;


	// xxx
}

//old functions////////////////////////////////////////////////////


	function getYear(d)
	{ 
		return (d < 1000) ? d + 1900 : d; 
	}

	function isDate (year, month, day) 
	{
		month = month - 1;
		var tempDate = new Date(year,month,day);
		
		if ( (getYear(tempDate.getYear()) == year) && (month == tempDate.getMonth()) && (day == tempDate.getDate()) )
			return true;
		else
			return false
	}
	



	function Validate(tcoption)
	{	




		var llvalidateok, lcmessage;

		lcmessage = ''

		llvalidateok = false;

		switch(llvalidateok)
		{
		case (!( (document.getElementById('email') && document.getElementById('email').value == '') || document.getElementById('addults').value == '' || (document.getElementById('email') && !(requestValidateEmail(document.getElementById('email').value ))) ) ):

			lcmessage = lcmessage + document.getElementById("sp_msg_reviewdata").innerHTML;			
			
			break;		
				
		case ( ValidateRooms() ):
			lcmessage = lcmessage +  document.getElementById("sp_msg_roomsnotselected").innerHTML;			
			
			break;
		
		case ( validdatebyid('ckiyear','ckimonth','ckiday') ):
			lcmessage = lcmessage +  document.getElementById("sp_msg_invalidcki").innerHTML;		
			
			break;

		case ( validdatebyid('ckoyear','ckomonth','ckoday')  ):
			lcmessage = lcmessage + document.getElementById("sp_msg_invalidcko").innerHTML;			
			
			break;
			
		case(checkdates()):
			lcmessage = lcmessage + document.getElementById("sp_msg_reviewdates").innerHTML;
			
			break;

		default:
			llvalidateok = true;
		
		}


		if (!(llvalidateok))
		{
			alert(lcmessage);		
		}

		return llvalidateok;

	}  


function requestValidateEmail( tcEmail) {

var lobjRegExp  =/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/


  return lobjRegExp.test(tcEmail);
}


function validaterequestdates()
{
	var llvalidaterequestdates, lcmessage;
	
	llvalidaterequestdates 	= true;
	lcmessage 				= '';

	if (!validdatebyid('ckiyear','ckimonth','ckiday'))
	{
		lcmessage = lcmessage +  document.getElementById("sp_msg_invalidcki").innerHTML;	
		llvalidaterequestdates = false;
	}
	else if (!validdatebyid('ckoyear','ckomonth','ckoday'))
	{
		lcmessage = lcmessage + document.getElementById("sp_msg_invalidcko").innerHTML;			
		llvalidaterequestdates = false;	
	}
	else if ( !checkdates())
	{
		llvalidaterequestdates = false;	
		lcmessage = lcmessage + document.getElementById("sp_msg_reviewdates").innerHTML;
	}

	if(!(llvalidaterequestdates))
	{
		alert(lcmessage);	
	}

	return llvalidaterequestdates;

}

	
function validdatebyid(lcyear, lcmonth, lcday)
{
	return isDate(document.getElementById(lcyear).value,document.getElementById(lcmonth).value,document.getElementById(lcday).value);

}


function checkdates()
{

	var din = document.getElementById('ckiyear').value + document.getElementById('ckimonth').value + document.getElementById('ckiday').value;
	var dout = document.getElementById('ckoyear').value + document.getElementById('ckomonth').value + document.getElementById('ckoday').value;

	var dt = new Date();
	var day = dt.getDate();
	var month = dt.getMonth()+1;
	if (day < 10)
	day = "0" + day;	
	if (month < 10)
	month = "0" + month;						
	var today = dt.getFullYear() + "" + month + "" + day;

	if (din < today || dout < din || dout == din)
	{	
		return false;
	}	
	else
	{
		return true;
	}
}

	
	function SubmitReq(tcoption)
	{
		var lobutton1, lobutton2, lotext, loform;
		
		lotext = document.getElementById("sp_plswaitwhileprocess");
	
		lobutton1 	= document.getElementById("sp_btnbooking");
		lobutton2 	= document.getElementById("sp_btnrequest");
		lobutton3 	= document.getElementById("sp_btn_makechanges");
		loform		= document.getElementById("avrequest");
		
		if ( tcoption == 'sendrequest' )
		{			
			document.getElementById('button').value='submit'; 			
			lobutton1.style.display = "none";
			lobutton2.style.display = "none";
			lobutton3.style.display = "none";
			lotext.style.display = "inline";
			lobutton1.disabled = true;
			lobutton2.disabled = true;

			loform.submit();
			return true;
		}
		else if (tcoption == 'nexthotel' )
		{
			document.getElementById('button').value='nexthotel'; 			
			lobutton1.value = lotext.innerHTML;
			lobutton2.value = "";
			lobutton3.value = "";
			lobutton1.style.display = "none";
			lobutton2.style.display = "none";
			lobutton3.style.display = "none";
			lotext.style.display = "inline";
			
			lobutton1.disabled = true;
			lobutton2.disabled = true;
			lobutton3.disabled = true;

			loform.submit();
			return true;
		}
		else if (tcoption == 'reset' )
		{
			document.getElementById('button').value='reset'; 			
			lobutton1.value = lotext.innerHTML ;
			lobutton2.value = "";
			lobutton2.style.display = "none";
			
			lobutton1.disabled = true;
			lobutton2.disabled = true;
			loform.submit();
			return true;
		}
		else
			return false;
	}


function update_calendar_dates()
		{					
			var dt = new Date();		
			var s1 = document.getElementById("cal_checkin").value;
			var s2 = document.getElementById("cal_checkout").value;
			
			document.getElementById("ckiyear").selectedIndex = s1.substring(0,4) - dt.getFullYear();
			document.getElementById("ckimonth").selectedIndex = s1.substring(5,7) - 1;
			document.getElementById("ckiday").selectedIndex = s1.substring(8) - 1;
					
			document.getElementById("ckoyear").selectedIndex = s2.substring(0,4) - dt.getFullYear();
			document.getElementById("ckomonth").selectedIndex = s2.substring(5,7) - 1;
			document.getElementById("ckoday").selectedIndex = s2.substring(8) - 1;		
		}
		
		function update_checkin_calendar()
		{					
			document.getElementById("cal_checkin").value = document.getElementById("ckiyear").value + "." + document.getElementById("ckimonth").value + "." + document.getElementById("ckiday").value;
			thisbooking.setCheckin(document.getElementById("cal_checkin").value);
		}
		
		function update_checkout_calendar()
		{					
			document.getElementById("cal_checkout").value = document.getElementById("ckoyear").value + "." + document.getElementById("ckomonth").value + "." + document.getElementById("ckoday").value;
			thisbooking.setCheckout(document.getElementById("cal_checkout").value );
		}



/// CC validation functions/////////


function Validatecc()
	{

		var llccok;

		llccok = true;
	
		document.getElementById('numbercreditcard').value = '' + document.getElementById('numbercreditcard1').value + document.getElementById('numbercreditcard2').value + document.getElementById('numbercreditcard3').value + document.getElementById('numbercreditcard4').value ;
		
		document.getElementById('amexdata').value = '' + document.getElementById('amexhomeaddress').value + '&#013;' + document.getElementById('amexzipcode').value + "&#013;" +  document.getElementById('amexcity').value + '&#013;' + document.getElementById('amexstate').value + '&#013;' + document.getElementById('amexcountry').value ;

		if ( document.getElementById('typecreditcard').value == '' || document.getElementById('numbercreditcard1').value == '' || document.getElementById('numbercreditcard2').value == '' || document.getElementById('numbercreditcard3').value == '' || document.getElementById('numbercreditcard4').value == '' || document.getElementById('seccodecreditcard').value == '' || document.getElementById('monthcreditcard').value == '' || document.getElementById('yearcreditcard').value == '' || document.getElementById('holdercreditcard').value == '')
		{
			var lcmsg_reviewdata = document.getElementById("sp_msg_reviewdata").innerHTML ;			
			alert(lcmsg_reviewdata) ;	
			llccok = false;		
		}
		else
		{
			
			var date = document.getElementById('yearcreditcard').value + document.getElementById('monthcreditcard').value;
			var dt = new Date();
			var month = dt.getMonth()+1;
			
			if (month < 10)
				month = "0" + month;						
			var today = dt.getFullYear() + "" + month;
		
		
			if (date < today)
			{
				var lcmsg_reviewexpiredate= document.getElementById("sp_msg_reviewexpiredate").innerHTML;
				alert(lcmsg_reviewexpiredate);
				llccok=false;
			}
			else
			{
				//return SubmitReq(tcoption,1);
				null;
			}
		}

		return llccok;

	}  
	
	

function enablecheckrooms()
{
	var lochkbutton
	lochkbutton = document.getElementById('sp_viewroomavailabilitystatus')
	lochkbutton.disabled= false;

}


function submit_booking(localler)
{
	
	var lnactionstatus;
	
	lnactionstatus = localler.getAttribute("actionstatus") ;

	lnactionstatus = lnactionstatus * 1;

	llccform = (typeof document.getElementById('numbercreditcard1') =='undefined' || document.getElementById('numbercreditcard1'));	

	if(!llccform)
	{
		localler.setAttribute('actionstatus', '1');
		// Show CC form
		document.getElementById('sp_btnrequest').style.display= 'none';
		displayitems('div_ordermessage','none');
		showccform();	
		document.getElementById("tr_aceptpolicy").style.display= 'inline';
	}
	else
	{
		localler.setAttribute('actionstatus', '1');
		//already have showen CC form so post it

		if (Validatecc())
		{
			postdata();	
		}
	}
}



function postdata()
{

	var loactiontype, lcactiontype, lldataok;

	var llacceptterms


    if(typeof (document.getElementById('acceptterms')) == 'undefined' || document.getElementById('acceptterms')== null)
    {
        llacceptterms = true;
    
    }
    else
    {
	    llacceptterms = document.getElementById('acceptterms').checked
	}

	lldataok =  false;

	if(!(Validate('sendrequest')))
	{
		return false;
	}
	else if(!document.getElementById('sp_viewroomavailabilitystatus').disabled)
	{			
		alert(getMessageFromId('sp_emp_checkavailindatespressbtn'));
		return false;

	}
	else if(document.getElementById('custfname') && !(validateform_contactdetails()))
	{
		return false;	
	}
	else if(!llacceptterms)
	{
		alert(getMessageFromId('sp_plsaceptcancelpayterms'));
		return false;	
	}
	loactiontype = document.getElementById('inp_actiontype');
	lcactiontype = loactiontype.value;


//alert(lcactiontype)


	if(lcactiontype=='booking')
	{
		//validate CCdetails
		if (Validatecc()){
			lldataok =  true;		
		}
			else
		{
			null;
		}
	}
	else if(ccdataexists())
	{
		//if cc exists then validate them

		if (Validatecc()){
			lldataok =  true;
		}
		else
		{
			null;
		}
	}
	else
	{
		lldataok =  true;
	}

	if(lldataok){
	
		SubmitReq('sendrequest');
	
	}
	
	return lldataok;

}


function ccdataexists()
{

	var lcfieldsname, lofields, lnilofields, loinptfield, lldataexists

	lcfieldsname = 'numbercreditcard1,numbercreditcard2,numbercreditcard3,numbercreditcard4,seccodecreditcard,holdercreditcard'


	lofields = lcfieldsname.split(',')

	lldataexists = false;

	for (lnilofields=0;lnilofields<lofields.length;lnilofields++)
	{
		
		loinptfield = document.getElementById(lofields[lnilofields])

		if (typeof loinptfield =='undefined' || !(loinptfield))
		{
			return false;
		
		}
		
		if (loinptfield.value!='' && loinptfield.value!='0')
		{			
			lldataexists = true;

			break;
		}

	
	
	}

	return lldataexists;

}


function mandatoryfields(lcfieldname)
{

	var lofieldsname, lafields, lnifields;
	var lobox, lcboxvalue;
	var mandatoryfields;

	lafields = lofieldsname.split(',');

	mandatoryfields = true;

	for(lnifields=0;linifields< lafields.length; linifields++)
	{
		lobox		= document.getElementById(lafields[linifields]);
		lcboxvalue 	= lobox.value.replace(/ /g, '');

		if(lcboxvalue=='')
		{
			mandatoryfields = false;			
		}
	}
	return mandatoryfields;
}





function getchildbytagname(tocaller,tctag)
{
	var lochildnodes
	
	lochildnodes 	= tocaller.getElementsByTagName(tctag);
	return lochildnodes

}


function selectroom(tocaller)
{

	var lotrroom, lnroomid, lotrelements, locurrenttd, llpricesok;
	var lni;
	var lntotalvalue;
	var lnroomstatusfinaltype, lnroomstatus, tdftype, lcroomname, lnpricetype;
	var lcday, loday;
	var lnminstay, lncurrminstay, lndaystostay;

	lnpricetype		= tocaller.getAttribute("pricetype");
	lnroomid 		= tocaller.getAttribute("roomid");
	lotrroom 		= document.getElementById('roomtr_'+ lnroomid +'_'+ lnpricetype);
	lotrelements 	= getchildbytagname(lotrroom,'td');
	lntotalvalue	= 0;
	tdftype			= '';
	lcroomname		= '';
	lcday			= '';
	lnminstay		= 0;
	lncurrminstay	= 0;
	lndaystostay	= 0;
	lnroomstatusfinaltype = 0;
		
	llpricesok = true;
	
	for(lni=0; lni < lotrelements.length; lni++)
	{
		locurrenttd = lotrelements[lni]

		tdftype = locurrenttd.getAttribute('ftype');
		
		if(tdftype )
		{
			tdftype = tdftype.toLowerCase();
		
		}

		if (tdftype == 'roomname')
		{
			lcroomname = locurrenttd.innerHTML;
			tocaller.setAttribute('roomname', lcroomname);
		}

		if (lnroomid == locurrenttd.getAttribute('roomid'))
		{
			

			if(locurrenttd.getAttribute('roompriceok') == 0 || !(locurrenttd.getAttribute('roompriceok')))
			{
			    setDisplayPriceType(tocaller, 0);
				llpricesok = false;
			}
			// price not displayed in site
			else if(locurrenttd.getAttribute('roompriceok') == 3 )
			{
				//do not display price				
				setDisplayPriceType(tocaller, 3);
			
			}
			else if(locurrenttd.getAttribute('roompriceok') == 2 )
			{
				//no price
				setDisplayPriceType(tocaller, 2);			
				
			}
			else
			{
				lntotalvalue =  lntotalvalue + parseFloat(locurrenttd.getAttribute('roompriceforseason'));
				setDisplayPriceType(tocaller, 1);
				
			}

			//may check here the minimum stay
			lndaystostay++

			lncurrminstay = locurrenttd.getAttribute('minstay')

			if(lncurrminstay)
			{
				if (lnminstay < lncurrminstay || typeof(lnminstay) =='undefined' )
				{
					lnminstay = lncurrminstay;
				}					
			}

			tocaller.setAttribute('totallineprice', lntotalvalue);			
			tocaller.setAttribute('pricesok', llpricesok);
			
			lnroomstatus = locurrenttd.getAttribute('roomstatus')

			if(lnroomstatus == 2)
			{
				lnroomstatusfinaltype = 2;
			}
			else if (lnroomstatus == 3 && lnroomstatusfinaltype != 2)
			{
				
				lnroomstatusfinaltype = 3;			
			}
			else if (lnroomstatus == 1 && (lnroomstatusfinaltype == 1 || lnroomstatusfinaltype == 0))
			{
				lnroomstatusfinaltype = 1;
			}

			tocaller.setAttribute('roomstatusfinaltype', lnroomstatusfinaltype);
			

			if(locurrenttd.getAttribute('day'))
			{
				if(lcday.length > 0)
				{
					lcday = lcday + ','
				}
				
				lcday = lcday  + locurrenttd.getAttribute('day')
			}			
		}
	}
	
	tocaller.setAttribute('minstay', lnminstay);
	tocaller.setAttribute('daystostay', lndaystostay);

	if(lnminstay > lndaystostay && tocaller.checked)
	{
		alert(getMessageFromId('sp_msg_minstay') + ' ' + lnminstay);			
	}

	loday = lcday.split(',');
	tocaller.setAttribute('maxdate', loday.max());
	tocaller.setAttribute('mindate', loday.min());

	return (lnroomstatusfinaltype!=2 && llpricesok)
}


function setDisplayPriceType(tocaller, tntype)
{

var lnroompriceok

lnroompriceok = tocaller.getAttribute('roompriceok')

    if(lnroompriceok)
    {
        
        if(lnroompriceok == 1)
        {
            tocaller.setAttribute('roompriceok',tntype );
        }
        else if((lnroompriceok== 2 && tntype != 1) || tntype == 3)
        {
            tocaller.setAttribute('roompriceok',tntype ); //(tntype = 2 or 3)    
        }        
        
    }
    else
    {
        tocaller.setAttribute('roompriceok',tntype );


    }
}


function addroom(tocaller)
{

	var lladdlineroom, lnhotelid, lcdivtoadd, lnroomid, lodivtoadd, lnbillinglines, lcroomtype;

	lladdlineroom 		= selectroom(tocaller);
	lnhotelid 			= tocaller.getAttribute('hotelid');
	lcdivtoadd 			= 'tblbilling_'+ lnhotelid;
	lnroomid			= tocaller.getAttribute('roomid');
	lodivtoadd			= document.getElementById(lcdivtoadd);
	lnbillinglines		= lodivtoadd.getAttribute('billinglines');
	loccbutton			= document.getElementById('sp_btnshowccform')
	lcroomtype			= tocaller.getAttribute('roomtype');

	if (tocaller.checked)
	{
		if (lladdlineroom){
			addbillingrow(lcdivtoadd, tocaller);	
			

			if(lcroomtype!='extrabed'){
				lodivtoadd.setAttribute('billinglines', lnbillinglines + 1);
			}
		}
		else
		{
			tocaller.checked = false;		
		}
	}
	else
	{
		//remove
		removerow(tocaller);
		if(lcroomtype!='extrabed'){
			lodivtoadd.setAttribute('billinglines', lnbillinglines - 1);	
		}
	}

	if (lodivtoadd.getAttribute('billinglines') > 0)
	{
		loccbutton.style.display 							= 'inline';
		document.getElementById(lcdivtoadd).style.display 	= 'inline';
	
	}
	else
	{
		loccbutton.style.display 							= 'none';
		document.getElementById(lcdivtoadd).style.display	= 'none';
	
	}


}


function formatPrice(tnprice, tcdecimalchar)
{

tnprice = tnprice.toString()


var lcformatprice

var lcdecimalstoadd
var i

lcdecimalstoadd = (2-(tnprice.length  - (tnprice.lastIndexOf(tcdecimalchar) + 1)) );


	if (tnprice.lastIndexOf(tcdecimalchar) > 0)
        {
		lcformatprice = tnprice;

	for (i=0;i<lcdecimalstoadd ;i++)
		{
			lcformatprice= lcformatprice + '0'
		}	        
    
        }
        else
        {
            	lcformatprice = tnprice + tcdecimalchar + '00';
        }

	return lcformatprice;

}

function addbillingrow(tctabletoadd, tocaller) {
    var lorow, lotd, lotxt, lotabletoadd;
    var lcroomname, lnroomid, lorommqt, lntotallineprice, lcroomtype;
    var lcmaxdate, lcmindate;
    var loinsert;
    var lnpricetype;
    var lcpricetoprint


    lcroomname = tocaller.getAttribute("roomname");
    lnroomid = tocaller.getAttribute("roomid");
    lntotallineprice = Math.round(tocaller.getAttribute("totallineprice") * 100) / 100;
    lcmaxdate = " ";
    lcmaxdate = tocaller.getAttribute("maxdate") + " ";
    lcmindate = " ";
    lcmindate = tocaller.getAttribute("mindate") + " ";
    lcroomtype = tocaller.getAttribute("roomtype");
    lotabletoadd = document.getElementById(tctabletoadd);
    lnpricetype = tocaller.getAttribute("pricetype");
    if (lcroomtype.toLowerCase() == "extrabed") {
        loinsert = document.getElementById("tr_extrabeds");
        loinsert.style.display = "inline";
    } else {
        loinsert = document.getElementById("tr_rooms");
    }
    lorow = document.createElement("TR");
    lorow.id = "trbilling_" + lnroomid + "_" + lnpricetype;
    lorow.className = "BlueTxt";
    lorow.setAttribute("totallineprice", lntotallineprice);
    lorow.setAttribute("pricesok", tocaller.getAttribute("pricesok"));
    lorow.setAttribute("roompriceok", tocaller.getAttribute("roompriceok"));
    lorow.setAttribute("roomstatusfinaltype", tocaller.getAttribute("roomstatusfinaltype"));
    lorow.setAttribute("orderline", "true");
    lotd = document.createElement("TD");
    lotd.innerHTML = lcroomname + " " + "(" + getMessageFromId(tocaller.getAttribute("pricetypecaption") )+ ")";
    lorow.appendChild(lotd);
    lotd = document.createElement("TD");
    lorommqt = createselectrange(15);
    lorommqt.options[1].selected = true;
    lorommqt.setAttribute("totallineprice", lntotallineprice);
    lorommqt.setAttribute("roomid", lnroomid);
    lorommqt.setAttribute("pricetype", lnpricetype);
    lorommqt.setAttribute("roompriceok", tocaller.getAttribute("roompriceok"));
    lorommqt.onchange = actlineprice;
    lorommqt.id = "nbrooms1_" + lnroomid + "_" + lnpricetype;
    lorommqt.name = "nbrooms1_" + lnroomid + "_" + lnpricetype;
    lotd.appendChild(lorommqt);
    lorow.appendChild(lotd);
    lotd = document.createElement("TD");
    lotd.id = "tdlineroomprice_" + lnroomid + "_" + lnpricetype;
    if (tocaller.getAttribute("roompriceok") == 1) {
        lcpricetoprint = lntotallineprice * 100 / 100;

       lcpricetoprint = formatPrice(lcpricetoprint, '.')
       lotd.innerHTML = lcpricetoprint

    } else {
        lotd.innerHTML = getMessageFromId("sp_priceavblonrequest");
    }
    lotd.align = "right";
    lorow.appendChild(lotd);
    if (lotabletoadd.tBodies[0]) {
        lotabletoadd.tBodies[0].insertBefore(lorow, loinsert.nextSibling);
    } else {
        lotabletoadd.insertBefore(lorow, loinsert.nextSibling);
    }
}



function removerow(tocaller)
{
	var loparent, lcparentname, lochildtoremove, lcchildtoremovename;
	var lnhotelid, lnroomid, lnpricetype;
	
	lnhotelid 		= tocaller.getAttribute('hotelid');
	lnroomid 		= tocaller.getAttribute('roomid');
	lnpricetype 		= tocaller.getAttribute("pricetype");
	lcparentname		= 'tblbilling_'+ lnhotelid;
	lcchildtoremovename 	= 'trbilling_'+ lnroomid +'_'+lnpricetype;
	loparent		= document.getElementById(lcparentname);
	lochildtoremove 	= document.getElementById(lcchildtoremovename);

	loparent.tBodies[0].removeChild(lochildtoremove);

}


function createselectrange(tnoptions)
{

	var lnopcount;
	var loselect, lootpion;

	loselect = document.createElement('SELECT');

	for (lnopcount=0;lnopcount <= tnoptions; lnopcount++)
	{
		lootpion 		= document.createElement('OPTION');
		lootpion.text 	= lnopcount;
		lootpion.value 	= lnopcount;
		loselect.options.add(lootpion, lnopcount);
		lootpion = null;
	}
	return loselect
}

//xxx2

function actlineprice(loevent) {

    var localler;
    var lnroomid;
    var lnpricetype;
    var lodivroomtotalprice, lntotallineprice;
    if (window.event) {
        localler = window.event.srcElement;
    } else if (loevent) {
        localler = loevent.target;
    }
    lnroomid = localler.getAttribute("roomid");
    lntotallineprice = localler.getAttribute("totallineprice");
    lnpricetype = localler.getAttribute("pricetype");
    lodivroomtotalprice = document.getElementById("tdlineroomprice_" + lnroomid + "_" + lnpricetype);
    if (localler.getAttribute("roompriceok") == 1) {
        lodivroomtotalprice.innerHTML = formatPrice(localler.value * lntotallineprice,'.');

    } else {
        lodivroomtotalprice.innerHTML = getMessageFromId("sp_priceavblonrequest");
    }
}



function loadPolicy()
{

	var lcpage;
	var loHttp = new xmlHttpDom();
	
	lcpage 				= ''

	//cancelation policy
	// lcpage = http_execute_url('GET',lcprintcancelpol);
	lcpage = loHttp.callUrl('GET', lcprintcancelpol)
	setinnerHTML ('div_cancelpol',lcpage)

	loHttp = new xmlHttpDom();

	//pre-payment policy
	// lcpage = http_execute_url('GET',lcprintprepaypol);
	lcpage = loHttp.callUrl('GET', lcprintprepaypol)
	setinnerHTML ('div_prepaypol',lcpage)

	

}


function showccform()
{
	var loccformarea;
	var loHttp = new xmlHttpDom();
	loadUser();
		
	loccformarea		= document.getElementById('ccdetailsform')
	
	lcpage 				= ''

	//cc details form


	// lcpage = http_execute_url('GET',lcprintccformurl);
	lcpage = loHttp.callUrl('GET', lcprintccformurl);
	setinnerHTML ('div_ccdetailsform',lcpage)
	pushJavaScript(lcpage, 0);

	
}

function loadUser()
{

	var lcpage, lluser, loforloaded, llforloaded;
	var loHttp = new xmlHttpDom();


	loforloaded = document.getElementById('div_userformdetailsload')

	llforloaded = ( typeof(loforloaded)!= 'undefined' && loforloaded!= 'null' && loforloaded)

	

	if (document.getElementById('email'))
	{
		lluser 		= userexists();
		
	}
	else
	{
		lluser = true;
	}

		

	if(!(lluser))
	{

            if(llforloaded)
	{
		return false;
	}

		// lcpage = http_execute_url('GET',lcuserform);
		lcpage = loHttp.callUrl('GET', lcuserform)
		setinnerHTML ('div_userform',lcpage);
		pushJavaScript(lcpage,0)
	}
	else
	{
		setinnerHTML ('div_userform','')
	}

}



function checkfinalstate(tocaller)
{




	var lcordersheetname, loordersheet;
	var loorderlines, lnilines, lcfinalaction;
	var lctotallineprice, llpricesok, lnroomstatusfinaltype;
	var loccformarea, lcprintccformurl;
	

	lcordersheetname 	= tocaller.getAttribute('ordersheet')
	loordersheet 		= document.getElementById(lcordersheetname)
	loorderlines		= getchildbytagname(loordersheet,'tr')
	lcfinalaction 		= ' ';
	
	for (lnilines=0;lnilines<loorderlines.length;lnilines++)
	{

		if(loorderlines[lnilines].getAttribute('orderline'))
		{	
			llpricesok				= loorderlines[lnilines].getAttribute('pricesok');
			lctotallineprice		= loorderlines[lnilines].getAttribute('totallineprice');
			lnroomstatusfinaltype	= loorderlines[lnilines].getAttribute('roomstatusfinaltype');


			
			//alert(lnilines + '\n' + loorderlines[lnilines].getAttribute('orderline'));
			//alert(lctotallineprice + '\n' + llpricesok + '\n' + lnroomstatusfinaltype);

			if(lnroomstatusfinaltype == 3)
			{
				lcfinalaction = 'request';
			}
			else if((lcfinalaction != 'request'  ) && lnroomstatusfinaltype == 1)
			{
				lcfinalaction = 'booking';
			
			}

		}

	}

return lcfinalaction;
}


function setActionType(toCaller)
{
	var lcactiontype, loactiontype

	lcactiontype = checkfinalstate(toCaller)

	loactiontype = document.getElementById('inp_actiontype')

	loactiontype.setAttribute('actiontype',lcactiontype)

	loactiontype.value = lcactiontype;	

}



function choose_room_quantity(toCaller)
{
	var loactiontype, lcactiontype;
	
	thisbooking.updateDisplay();

	loactiontype = document.getElementById('inp_actiontype');
	lcactiontype = loactiontype.value;


	if(!(Validate('sendrequest')))
	{
		return false;
	
	}
	
	// Update check in and check out date in room selection form


	displayitems('div_avrequest,calendararea,sp_btnshowccform,sp_viewroomavailabilitystatus,div_extrabeds,div_colorcaption,div_alternativehotels,div_link_alternativehotels,hotelcalcolorcaption','none');

	loadPolicy();

	if (lcactiontype=='booking')
	{
		setinnerHTMLgroup('div_ordermessage',getMessageFromId('sp_msgorder_mustbookentercc'))
		document.getElementById('sp_btnbooking').value = getMessageFromId('sp_msgbnt_mustbook')
		showccform();	
		displayitems('sp_btnbooking','inline');
		displayitems('sp_btnrequest','none');			
	}
	else
	{
		loadUser()
		setinnerHTMLgroup('div_ordermessage',getMessageFromId('sp_msgorder_requestpossiblecc'))	
		document.getElementById('sp_btnbooking').value = getMessageFromId('sp_msgbnt_bookifavailable')
		displayitems('sp_btnbooking,sp_btnrequest','inline');
	}
	displayitems('div_custcomment,div_bilingarea,div_carratesandnews,sp_cancelationpol,sp_prepaypol,div_submitarea,tr_ordermessage,tr_aceptpolicy,div_cancelpol,div_prepaypol,div_ccdetailsform,div_userform,sp_btn_makechanges','inline');
	if (document.getElementById("div_showseasoninfo"))
		document.getElementById("div_showseasoninfo").innerHTML = document.getElementById("div_seasoninfo").innerHTML;

}

function copyInnerHTMLTo(tcDestId, tcOrigId)
{
	var lchtml, loOrig
	var loDest

	if (!(document.getElementById(tcOrigId) && document.getElementById(tcDestId)))
	{
		return false;
	
	}

	loOrig = document.getElementById(tcOrigId)
	lchtml = loOrig.innerHTML
	loDest = document.getElementById(tcDestId)
	loDest.innerHTML = lchtml

	return true;
}



function nextstep(tocaller)
{

	var loactiontype, lcfinalaction, lluser;

	if(!(Validate('sendrequest')))
	{
		return false;
	
	}
	
	if (document.getElementById('email'))
	{
		lluser = userexists();
	}
	else
	{
		lluser = true;
	}

	

	//displayitems('div_avrequest,calendararea,sp_btnshowccform,sp_viewroomavailabilitystatus,div_extrabeds,div_colorcaption','none');
	displayitems('div_carratesandnews,div_submitarea,sp_cancelationpol,sp_prepaypol','inline');
	setinnerHTMLgroup('div_cancelationpol,div_prepaypol','Building data')
	
	// execute views
	showccform(tocaller, lluser);


	setActionType(tocaller)

	

	return true;

}


function alterrequest(tocaller)
{
	displayitems('div_custcomment,div_bilingarea,div_carratesandnews,sp_cancelationpol,sp_prepaypol,div_submitarea,tr_ordermessage,tr_aceptpolicy,div_cancelpol,div_prepaypol,div_ccdetailsform,div_userform,sp_btn_makechanges','none');
	displayitems('div_avrequest,calendararea,sp_btnshowccform,sp_viewroomavailabilitystatus,div_extrabeds,div_colorcaption,div_alternativehotels,div_link_alternativehotels,hotelcalcolorcaption','inline');
	
}



function setinnerHTMLgroup(tcnames,tchtml)
{

	var laitem, loitem, lnitem, lcitem;


	laitem = tcnames.split(',')

	for (lnitem=0;lnitem < laitem.length ; lnitem++)
		{

			lcitem = laitem[lnitem]
			loitem = document.getElementById(lcitem);

			if(loitem)
			{

				loitem.innerHTML=tchtml;
			}


		}

}



Array.prototype.max = function () {
if (this.length == 0) return undefined;
var n = Number(this[0]);
for (var i=1; i<this.length; i++) {n = Math.max(n, this[i])};
return n;
}

Array.prototype.min = function () {
if (this.length == 0) return undefined;
var n = Number(this[0]);
for (var i=1; i<this.length; i++) {n = Math.min(n, this[i])};
return n;
}



//functions to validate user details


function setComboDefault(tcControl, tcvalue)
	{
		var loControl, lni;
		loControl= document.getElementById(tcControl);
		
		for (lni = 0; lni < loControl.options.length ; lni++)
		{
			if (loControl.options.item(lni).value == tcvalue)
			{
				loControl.selectedIndex = lni;
			}
		}
	}

function validateform_contactdetails()
	{
		var llret, lcmessage;
		lcmessage = "";
		llret = true;
	
		lcmessage = lcmessage + check_if_empty('custfname', 2);
		lcmessage = lcmessage + check_if_empty('custlname', 2);
		//lcmessage = lcmessage + check_if_empty('custemail', 2);
		lcmessage = lcmessage + check_if_empty('customer_phone', 2);
		lcmessage = lcmessage + check_if_empty('customer_lang', 1);

		if (lcmessage != '')
		{
			alert(lcmessage);
			llret = false;
		}
		else
		
		llret = true;
		return llret;
	}

function check_if_empty(tcvarname, tntype)
	{
		var lonode, lcret, lnret;
		lonode = document.getElementById(tcvarname);
		lcret = '';
		lnret = 0 ;
		
		if (tntype==1)
		{
			// equal to zero 
			if (lonode.value == 0 )
				lcret = get_message(tcvarname);
		}
		else
		{
			// empty
			if (lonode.value == '' )
				lcret = get_message(tcvarname);
		}
		return lcret;
	}

function get_message(tcvarname)
	{
		var lonode, lcret;
		
		lonode = document.getElementById("sp_emp_" + tcvarname);
		if (lonode != null)
			lcret = lonode.innerHTML + '\n' ;
		else
			lcret = '';
			
		return lcret;
	}
	

function choosecard(toControl)
	{
		var loneedextra =  document.getElementById("needextrafields")
	
		if (toControl.options.item(toControl.selectedIndex).innerHTML == "American Express")
		{
			document.getElementById("tableamex").style.display = "block" ;
			document.getElementById("seccodecreditcard").maxLength = 4;
			document.getElementById("sp_mbk_seccodetext").innerHTML=document.getElementById("sp_mbk_seccodetext").innerHTML.replace(/3/,"4");
			loneedextra.value = 1;
		}
		else
		{
			document.getElementById("tableamex").style.display = "none" ;
			document.getElementById("seccodecreditcard").maxLength = 3;
			document.getElementById("sp_mbk_seccodetext").innerHTML=document.getElementById("sp_mbk_seccodetext").innerHTML.replace(/4/,"3");
			loneedextra.value = 0;
		}
	
	}

	

function clickGoToBm(toElement)
{
if(detectNavigator() == 1 ) 
{
	toElement.click()
}
}


function printads_sp(tcadzone, tcadtoprint)
{

var loAdZone;
loAdZone = document.getElementById('div_pubsp');
loAdZone.setAttribute('pubdefinition',tcadtoprint);
printAds(loAdZone);

}


	function loadpricewindowstatic(lnlangid, lnhotelid)
	{

	if (lnlangid > 0 && lnhotelid > 0 )
		{	
			//childwindow = window.open('/sp/' + lnlangid + '/hotels/rates_' + lnhotelid + '.asp', 'window','toolbar=no,scrollbars=yes,width=500px,height=480px');
			//window.onfocus = function(){if (childwindow.closed == false){childwindow.focus();};}	
		}
    else
		{
			//childwindow = window.open('%3cQSS COMMAND=LINKVIEW FID=24981>%3c/QSS>', 'window','toolbar=no,scrollbars=yes,width=500px,height=480px');
			//window.onfocus = function(){if (childwindow.closed == false){childwindow.focus();};}	
		}
	}
/*

	function update_calendar_dates()
		{					
			var dt = new Date();		
			var s1 = document.getElementById("cal_ckin").value;
			var s2 = document.getElementById("cal_ckou").value;
			
			document.getElementById("ckiyear").selectedIndex = s1.substring(0,4) - dt.getFullYear();
			document.getElementById("ckimonth").selectedIndex = s1.substring(5,7) - 1;
			document.getElementById("ckiday").selectedIndex = s1.substring(8) - 1;
					
			document.getElementById("ckoyear").selectedIndex = s2.substring(0,4) - dt.getFullYear();
			document.getElementById("ckomonth").selectedIndex = s2.substring(5,7) - 1;
			document.getElementById("ckoday").selectedIndex = s2.substring(8) - 1;		
		}
	

	function printcal(tocaller, tccaldiv, tnhotelid, tnlang, tnifidtoprint)
	{
		var lodivcal, lcurl ;
		var lccriteria, lcmaxdate, lcmindate;

		var lcformname

		var lnfidtoprint


		

		if(!validateavaidates())
		{
			return false;		
		
		}
		lcmaxdate = document.getElementById("cal_ckou").value;

		lcmindate = document.getElementById("cal_ckin").value;


		lodivcal = document.getElementById(tccaldiv);

		
		if(tnlang==0)
		{
			tnlang = 1;
		}

		tnlang = tnlang*1;

		lcurl = '/vd.asp?WCX=ViewDisplay&amp;FOLDERID='+ tnifidtoprint +'&amp;USECONTEXT=YES&amp;USECONTEXT=YES&amp;USERAW=YES&amp;ADDVIEWDIV=YES'

		lcurl = lcurl + '&SETVAR_SP_wsminwdate=' + lcmindate;
		lcurl = lcurl + '&SETVAR_SP_wsmaxwdate=' + lcmaxdate;
		lcurl = lcurl + '&SETVAR_sp_langid='+ tnlang;
		lcurl = lcurl + '&SETVAR_sp_hotelid='+ tnhotelid;
		
		http_execute(tccaldiv, lcurl)


		lodivcal.setAttribute('currmaxdate',lcmaxdate);
		lodivcal.setAttribute('currmindate',lcmindate);


		}

*/
		
function validateavaidates()
{
	var llvalidaterequestdates, lcmessage;
	
	llvalidaterequestdates 	= true;
	lcmessage 				= '';

	if (!validdatebyid('ckiyear','ckimonth','ckiday'))
	{
		lcmessage = lcmessage +  docum.getElementById("sp_msg_invalidcki").innerHTML;	
		llvalidaterequestdates = false;
	}
	else if (!validdatebyid('ckoyear','ckomonth','ckoday'))
	{
		lcmessage = lcmessage + document.getElementById("sp_msg_invalidcko").innerHTML;			
		llvalidaterequestdates = false;	
	}
	else if ( !checkdates())
	{
		llvalidaterequestdates = false;	
		lcmessage = lcmessage + document.getElementById("sp_msg_reviewdates").innerHTML;
	}

	if(!(llvalidaterequestdates))
	{
		alert(lcmessage);	
	}

	return llvalidaterequestdates;

}


function checkdates()
{

	var din = document.getElementById('ckiyear').value + document.getElementById('ckimonth').value + document.getElementById('ckiday').value;
	var dout = document.getElementById('ckoyear').value + document.getElementById('ckomonth').value + document.getElementById('ckoday').value;

	var dt = new Date();
	var day = dt.getDate();
	var month = dt.getMonth()+1;
	if (day < 10)
	day = "0" + day;	
	if (month < 10)
	month = "0" + month;						
	var today = dt.getFullYear() + "" + month + "" + day;

	if (din < today || dout < din || dout == din)
	{	
		return false;
	}	
	else
	{
		return true;
	}
}

	
function validdatebyid(lcyear, lcmonth, lcday)
{
	return isDate(document.getElementById(lcyear).value,document.getElementById(lcmonth).value,document.getElementById(lcday).value);

}


function getYear(d)
	{ 
		return (d < 1000) ? d + 1900 : d; 
	}

function isDate (year, month, day) 
{
	month = month - 1;
	var tempDate = new Date(year,month,day);
		
	if ( (getYear(tempDate.getYear()) == year) && (month == tempDate.getMonth()) && (day == tempDate.getDate()) )
		return true;
	else
		return false
}
