// ------------------ COOKIES ------------------ //
function updatesum() {
	var maximum;
	if (document.frmpricing.c && document.frmpricing.p)
		maximum = (document.frmpricing.p.options[document.frmpricing.p.selectedIndex].text-0) + (document.frmpricing.c.options[document.frmpricing.c.selectedIndex].text-0); 
	return maximum;
}

function validate_form ( )
{
    valid = true;

    if ( updatesum() > document.frmpricing.maxvalue.value )
    {
        alert ( "You excedeed the maximum number of person" );
        valid = false;
    }

    return valid;
}

function openCalendar(FormElement){
   var calendarwindow;

	   url = "/static/template/calendar.html?updateobj="+FormElement

   calendarwindow = window.open(url,"thewindow","toolbar=no,LEFT=300,TOP=250,WIDTH=170,HEIGHT=140,status=no,scrollbars=no,resize=no,menubar=no");
   calendarwindow.focus();
}


function openCalendarout(FormElement){
   var calendarwindow;

	   url = "/static/template/calendar.html?updateobj="+FormElement

   calendarwindow = window.open(url,"thewindow","toolbar=no,LEFT=300,TOP=250,WIDTH=170,HEIGHT=140,status=no,scrollbars=no,resize=no,menubar=no");
   calendarwindow.focus();
}




//leading whitespaces
function LTrim( value ) {
	
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
	
}

// Removes ending whitespaces
function RTrim( value ) {
	
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
	
}

// Removes leading and ending whitespaces
function trim( value ) {
	
	return LTrim(RTrim(value));
	
}


//billing
function billing_validate (){
	var sErr = "";
	if (trim(document.forms.frmbilling.webRcpName.value) == '')
		sErr+="Please specify a 'Name'\n";
	if (trim(document.forms.frmbilling.webRcpSurname.value) == '')
		sErr+="Please specify a 'Surname'\n";
	if (trim(document.forms.frmbilling.QsWebRcpAddress.value) == '')
		sErr+="Please specify an 'Address'\n";
	if (trim(document.forms.frmbilling.webRcpCity.value) == '')
		sErr+="Please specify a 'City'\n";
	if (trim(document.forms.frmbilling.webRcpZipCode.value) == '')
		sErr+="Please specify a 'Zip Code'\n";
	if (document.forms.frmbilling.webRcpNatId[document.forms.frmbilling.webRcpNatId.selectedIndex].value == '')
		sErr+="Please specify a 'Nation'\n";
	if (trim(document.forms.frmbilling.webRcpPhone.value) == '')
		sErr+="Please specify a 'Phone number'\n";

	if (sErr != ""){
		alert(sErr); 
		return false;
	}
	return true;
}











//purchase
function pay(){
var i=0;
for(i=0;i<document.forms.choosepayment.paymode.length;i++)
	if(document.forms.choosepayment.paymode[i].checked)
		eval("document.forms."+document.forms.choosepayment.paymode[i].value+".submit()");
}

//booking
function holdorbook(a){
if (a=='onhold'){
	document.forms.frmpricingres.action=document.forms.frmpricingres.onhold_to.value;
	document.forms.frmpricingres.s.value=2;
}else if (a=='request'){
	document.forms.frmpricingres.action=document.forms.frmpricingres.onhold_to.value;
	document.forms.frmpricingres.s.value=5;
}else{
	document.forms.frmpricingres.action=document.forms.frmpricingres.book_to.value;
	document.forms.frmpricingres.s.value=3;
}
return true;
}

//suitcase
function del(formname){
if(confirm('Are you sure you want to remove this apartment from your cart?')){
eval("document.forms."+formname+".action=document.URL;");
eval("document.forms."+formname+".mm.value=2;");
return true;
}else{
return false;
}
}


function validate_login (f) {
    if (isEmpty(document.forms.frmlogin.username.value)){
		alert("Specify at least a Username");
		return false;
	}
    return true;
}


function montre(id) {
var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
if (d) {d.style.display='block';}
}


function hide(id) {
var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='block';}
	}
if (d) {d.style.display='none';}
}