

function days_between(date1, date2) {
alert(date1);
alert(date2);
    // The number of milliseconds in one day
    var ONE_DAY = 1000 * 60 * 60 * 24

    // Convert both dates to milliseconds
    var date1_ms = date1.getTime()
    var date2_ms = date2.getTime()

    // Calculate the difference in milliseconds
    var difference_ms = Math.abs(date1_ms - date2_ms)
    
    // Convert back to days and return
    alert( Math.round(difference_ms/ONE_DAY))
//    return Math.round(difference_ms/ONE_DAY)

}

function setdeparturedate(xxday, xxmonthyear) {
	
	var xday = encodeURIComponent(xxday);
	
	var s = xxmonthyear.split("/");
	var xmonth = encodeURIComponent(s[0]);
	var xyear = encodeURIComponent(s[1]);

	var parameters = "xday="+xday;
	parameters += "&xmonth="+xmonth;
	parameters += "&xyear="+xyear;
	var url="setdeparturedate.asp";
	
	
	var datesAJAX=new ajaxRequest();
	datesAJAX.onreadystatechange=function(){
	 if (datesAJAX.readyState==4){
		if (datesAJAX.status==200 || window.location.href.indexOf("http")==-1){
			if (document.getElementById("departdiv")) {
						document.getElementById("departdiv").innerHTML = datesAJAX.responseText;
			}

			}
		else{
			alert(datesAJAX.responseText+"okay, it failed to get date!")
		}
	 }
	}
	datesAJAX.open("POST", url, true)
	datesAJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	datesAJAX.send(parameters)
}

function checkCuMessage() {
	document.getElementById("contactuswaiting").innerHTML='<img src="skin3/loading.gif" width="140" height="15" vspace="7" />';
	var errormess = "";
	var theValue = "";
	
	theValue = document.contactusForm.name.value;
	if (alltrim(theValue) == "" || alltrim(theValue)=="Name") {
		errormess += "Please enter your name.\n";
	}

	theValue = document.contactusForm.email.value;
	if (alltrim(theValue) !== "email") {
		if (!isValidEmail(alltrim(theValue))) {
			errormess += "Your email address is not correct.\n";
		}
	}
	
//	theValue = document.contactusForm.telephone.value;
//	if (alltrim(theValue) == ""  || alltrim(theValue)=="Telephone") {
//		errormess += "Please enter your telephone number.\n";
//	}

	theValue = document.contactusForm.message.value;
	if (alltrim(theValue) == ""  || alltrim(theValue)=="Message") {
		errormess += "Please enter your message.\n";
	}


	if (errormess) {
		document.getElementById("contactuswaiting").innerHTML='<div onclick="checkCuMessage();">Send us your message</div>';
		alert("Please check your message form\n\n" + errormess);
	}
	else { 
	var name = encodeURIComponent(document.contactusForm.name.value);
	var email = encodeURIComponent(document.contactusForm.email.value);
	var confirmtext = encodeURIComponent(document.contactusForm.email.value);
	var telephone = encodeURIComponent(document.contactusForm.telephone.value);
	var message = encodeURIComponent(document.contactusForm.message.value);
	var prefc = encodeURIComponent(document.contactusForm.prefc.value);
	

	var parameters = "name="+name;
	parameters += "&email="+email;
	parameters += "&confirm="+confirmtext;
	parameters += "&telephone="+telephone;
	parameters += "&message="+message;
	parameters += "&prefc="+prefc;

	var url="contact_send.asp";
	
	
	var contactusAJAX=new ajaxRequest();
	contactusAJAX.onreadystatechange=function(){
	 if (contactusAJAX.readyState==4){
		if (contactusAJAX.status==200 || window.location.href.indexOf("http")==-1){
			if (document.getElementById("contactuswaiting")) {
				document.getElementById("contactuswaiting").innerHTML = contactusAJAX.responseText;
			}
		}
		else{
			if (document.getElementById("contactuswaiting")) {
				document.getElementById("contactuswaiting").innerHTML = contactusAJAX.responseText;
			}
		}
	 }
	}
	contactusAJAX.open("POST", url, true)
	contactusAJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	contactusAJAX.send(parameters)
	}
}

function doHolidaySearch() {
	document.getElementById('noclick').style.display='block';
	document.getElementById('searchButton').innerHTML='<img src="skin3/loading.gif" width="140" height="15" vspace="7" />'; 
	document.getElementById('search-form').submit();
}

function doHolidayPropertySearch(theForm) {
	//alert(theForm+" - "+document.forms.refSearch.pagelink.value);
	document.getElementById('noclick').style.display='block';
	
	if (document.getElementById('waitarea'+theForm)) {
		document.getElementById('waitarea'+theForm).innerHTML='<img src="skin3/loading.gif" width="140" height="15" style="margin-top:7px;" />';
	}
	document.getElementById(theForm).submit();
}

function doQLsearch(theForm) {
	document.getElementById('noclick').style.display='block';
	document.getElementById('qlwaitarea').innerHTML='<img src="skin3/loading.gif" width="140" height="15" style="margin-top:7px;" />'; 
	document.getElementById(theForm).submit();
}

function viewaproperty(url, prop, arrivaldate, departuredate, price) {
	document.getElementById('loading').innerHTML=' <a  href="" class="close" onclick="HideLightBox(); return false;" title="Close" onFocus="if(this.blur)this.blur();"></a><br><img src="skin3/de-icon.png" width="32" height="32" align="absmiddle" />&nbsp;Loading details for '+prop+'<br><br><img src="skin3/loading.gif" width="214" height="15"/>';
	ShowLightBox('loading', true, 0);

	var name = encodeURIComponent(url);
	var arrivaldate = encodeURIComponent(arrivaldate);
	var departuredate = encodeURIComponent(departuredate);
	var price = encodeURIComponent(price);
	

	var parameters = "url="+url;
	parameters += "&arrivaldate="+arrivaldate;
	parameters += "&departuredate="+departuredate;
	parameters += "&price="+price;
	var url="viewaproperty.asp";
	
	
	var vpAJAX=new ajaxRequest();
	vpAJAX.onreadystatechange=function(){
	 if (vpAJAX.readyState==4){
		if (vpAJAX.status==200 || window.location.href.indexOf("http")==-1){
			HideLightBox();
			if (document.getElementById("viewaproperty")) {
				
				document.getElementById("viewaproperty").innerHTML = vpAJAX.responseText;
				ShowLightBox('viewaproperty', false, 0);
			}
		}
		else{
			HideLightBox();
			alert("Error retriving property details");
			
			if (document.getElementById("viewaproperty")) {
				document.getElementById("viewaproperty").innerHTML = vpAJAX.responseText;
				ShowLightBox('viewaproperty', false, 0);
			}
		}
	 }
	}
	vpAJAX.open("POST", url, true)
	vpAJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	vpAJAX.send(parameters)
}


function showshortlistpopup() {
	var parameters = "xx=xx";
	var url="shortlistpopup.asp";

	var vpAJAX=new ajaxRequest();
	vpAJAX.onreadystatechange=function(){
	 if (vpAJAX.readyState==4){
		if (vpAJAX.status==200 || window.location.href.indexOf("http")==-1){
			HideLightBox();
			if (document.getElementById("shortlistpopup")) {
				document.getElementById("shortlistpopup").innerHTML = vpAJAX.responseText;
				ShowLightBox('shortlistpopup', false, 0);
			}
		}
		else{
			HideLightBox();
			alert("Error retriving shortlist");
				document.getElementById("shortlistpopup").innerHTML = vpAJAX.responseText;
				ShowLightBox('shortlistpopup', false, 0);
		}
	 }
	}
	vpAJAX.open("POST", url, true)
	vpAJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	vpAJAX.send(parameters)

}




function showAvailability(availabilitySTR, calendarstartSTR, columns, monthstoshow, arrivaldate, departuredate) {
	startday = 0;
	endday = 0;
	isStart = true;

	var availabilitySTR = encodeURIComponent(availabilitySTR);
	var availabilitySTR = encodeURIComponent(availabilitySTR);
	var columns = encodeURIComponent(columns);
	var monthstoshow = encodeURIComponent(monthstoshow);
	var arrivaldate = encodeURIComponent(arrivaldate);
	var departuredate = encodeURIComponent(departuredate);
	

	var parameters = "availabilitySTR="+availabilitySTR;
	parameters += "&calendarstartSTR="+calendarstartSTR;
	parameters += "&columns="+columns;
	parameters += "&monthstoshow="+monthstoshow;
	parameters += "&arrivaldate="+arrivaldate;
	parameters += "&departuredate="+departuredate;
	var url="showavailability.asp";
	var paneltoshow = "showavalabilitydiv";
//	var header = '<table width="100%" border="0" cellpadding="0" cellspacing="0" style="margin-bottom:10px;"><tr><td><img src="skin2/titles-l.jpg" width="3" height="36" align="absmiddle" /></td><td width="100%" align="center" valign="middle" class="titles">Availability</td><td><img src="skin2/titles-r.jpg" width="3" height="36" /></td></tr></table>';
	var availabilityAJAX=new ajaxRequest();
	availabilityAJAX.onreadystatechange=function(){
	 if (availabilityAJAX.readyState==4){
		if (availabilityAJAX.status==200 || window.location.href.indexOf("http")==-1){
			if (document.getElementById(paneltoshow)) {
				document.getElementById(paneltoshow).innerHTML = availabilityAJAX.responseText;
				viewhidepanels(paneltoshow);
				document.getElementById("availtab").className="tab-l-u";
			}
		}
		else{
			//HideLightBox();
			document.getElementById("showavalabilitydiv").innerHTML = availabilityAJAX.responseText;
				viewhidepanels(paneltoshow);
				document.getElementById("availtab").className="tab-l-u";
			alert("Error retriving availabilty details");
		}
	 }
	}
	availabilityAJAX.open("POST", url, true)
	availabilityAJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	availabilityAJAX.send(parameters)
}

function addtoshortlist(propref, arrivaldate, departuredate, price, img, name, pagelink) {
	var proprefdiv = propref;
	var propref = encodeURIComponent(propref);
	var arrivaldate = encodeURIComponent(arrivaldate);
	var departuredate = encodeURIComponent(departuredate);
	var price = encodeURIComponent(price);
	var img = encodeURIComponent(img);
	var name = encodeURIComponent(name);
	var pagelink = encodeURIComponent(pagelink);
	

	var parameters = "propref="+propref;
	parameters += "&arrivaldate="+arrivaldate;
	parameters += "&departuredate="+departuredate;
	parameters += "&price="+price;
	parameters += "&img="+img;
	parameters += "&name="+name;
	parameters += "&pagelink="+pagelink;

	var url="addtoshortlist.asp";
	var slAJAX=new ajaxRequest();
	slAJAX.onreadystatechange=function(){
	 if (slAJAX.readyState==4){
		if (slAJAX.status==200 || window.location.href.indexOf("http")==-1){
			if (document.getElementById("addtosldiv")) {
				document.getElementById("addtosldiv").innerHTML = "Added to shortlist";
			}
			if (document.getElementById("addtosldiv"+proprefdiv)) {
				document.getElementById("addtosldiv"+proprefdiv).innerHTML = '<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0"><tr><td><img src="tabs/nav-l.png" width="4" height="29" /></td><td align="center" valign="top" nowrap="nowrap" width="100%"><div class="tabbutton" onFocus="if(this.blur)this.blur();" onclick="showshortlistpopup();">View your shortlist</div></td><td><img src="tabs/nav-r.png" width="4" height="29" /></td></tr></table>';
			}
			if (document.getElementById("shortlistbutton")) {
				document.getElementById("shortlistbutton").style.display="block";
			}
			if (document.getElementById("shortlisttab")) {
				document.getElementById("shortlisttab").innerHTML = slAJAX.responseText;
			}
																	
		}
		else{
			//HideLightBox();
			document.getElementById("errorhere").innerHTML = slAJAX.responseText;
			alert("Error setting shortlist");
		}
	 }
	}
	slAJAX.open("POST", url, true)
	slAJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	slAJAX.send(parameters)
}


function veiwshortlisttab() {
	var parameters = "x=x";
	var paneltoshow = "shortlisttab";

	var url="viewshortlist-tab.asp";
	var slAJAX=new ajaxRequest();
	slAJAX.onreadystatechange=function(){
	 if (slAJAX.readyState==4){
		if (slAJAX.status==200 || window.location.href.indexOf("http")==-1){
			if (document.getElementById(paneltoshow)) {
				document.getElementById(paneltoshow).innerHTML = slAJAX.responseText;
				viewhidepanels(paneltoshow);
			}
		}
		else{
			//HideLightBox();
//			document.getElementById("showavalabilitydiv").innerHTML = slAJAX.responseText;
			alert("Error setting shortlist");
		}
	 }
	}
	slAJAX.open("POST", url, true)
	slAJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	slAJAX.send(parameters)
}

function getvideo(videolink) {
	var videolink = encodeURIComponent(videolink);
	var parameters = "videolink="+videolink;
	var url="getvideo-tab.asp";
	var paneltoshow = "videodiv";
	var slAJAX=new ajaxRequest();
	slAJAX.onreadystatechange=function(){
	 if (slAJAX.readyState==4){
		if (slAJAX.status==200 || window.location.href.indexOf("http")==-1){
			if (document.getElementById(paneltoshow)) {
				document.getElementById(paneltoshow).innerHTML = slAJAX.responseText;
				viewhidepanels(paneltoshow);
			}
		}
		else{
			//HideLightBox();
//			document.getElementById("showavalabilitydiv").innerHTML = slAJAX.responseText;
			alert("Error getting video");
		}
	 }
	}
	slAJAX.open("POST", url, true)
	slAJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
	slAJAX.send(parameters)
}

function viewhidepanels(paneltoshow) {
	changetabs();
	if (document.getElementById('propertyoverview')) {
		document.getElementById('propertyoverview').style.display='none';
	}
	
	if (document.getElementById('showavalabilitydiv')) {
		document.getElementById('showavalabilitydiv').style.display='none';
	}
	
	if (document.getElementById('propertygalleries')) {
		document.getElementById('propertygalleries').style.display='none';
	}
	
	if (document.getElementById('bookingrequestpanel')) {
		document.getElementById('bookingrequestpanel').style.display='none';
	}
	
	if (document.getElementById('shortlisttab')) {
		document.getElementById('shortlisttab').style.display='none';
	}
	
	if (document.getElementById('videodiv')) {
		document.getElementById('videodiv').style.display='none';
	}
	
	if (document.getElementById(paneltoshow)) {
		document.getElementById(paneltoshow).style.display='block';
	}
}

function changetabs() {
//	var setchild;
//	var thebar = document.getElementById("tabbar");
//	var thecount = thebar.getElementsByTagName("span").length;
	var thecount = 7;
	for (var i = 0; i < thecount; i++) {
		if (document.getElementById("tabbar"+i)) {
			document.getElementById("tabbar"+i).className='tab-m-d';
		}
	}
	if (document.getElementById("availtab")) {
		document.getElementById("availtab").className='tab-m-d';
	}

	if (document.getElementById("bookingtab")) {
		document.getElementById("bookingtab").className='tab-m-d';
	}

}

function navBarStatus(tabber) {
	clearNavStatus("navbar")
	document.getElementById(tabber).className="selected";
}

function clearNavStatus(div) {
	if(!div) {
		return;
	}
	div = typeof div === "string" ? document.getElementById(div) : div;
	var elms = div.getElementsByTagName("*");
	for(var i = 0, maxI = elms.length; i < maxI; ++i) {
		var elm = elms[i];
		if (elm.className=="selected") {
			elm.className = "";
		}
	}
}

var flagTimer = 3000;
setTimeout("flagChange();", flagTimer);

function flagChange() {
	if (document.getElementById("callusholder")) {
		if (document.getElementById("callusholder").innerHTML.indexOf('0844')>0) {
			document.getElementById("callusholder").innerHTML = '<img src="http://www.dreamespana.com/skin3/flag-es.png" width="74" height="48" align="top" />Call us on +34 95252 7272';
			setTimeout("flagChange();", flagTimer);
			return;
		}
	}
		

	if (document.getElementById("callusholder")) {
		if (document.getElementById("callusholder").innerHTML.indexOf('+34')>0) {
			document.getElementById("callusholder").innerHTML='<img src="http://www.dreamespana.com/skin3/flag-en.png" width="74" height="48" align="top" />Call us on 0844 734 5300';
			setTimeout("flagChange();", flagTimer);
			return;
		}
	}
		
}




//ajax request
function ajaxRequest(){
 var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"]
 if (window.ActiveXObject){ 
  for (var i=0; i<activexmodes.length; i++){
   try{
    return new ActiveXObject(activexmodes[i])
   }
   catch(e){
   }
  }
 }
 else if (window.XMLHttpRequest) 
  return new XMLHttpRequest()
 else
  return false
}



//Restrict to whole numbers on input	
function isWholeNumber(e){
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8 && unicode!=45){ 
		if (unicode<48||unicode>57) 
		return false 
	}
}

//Restrict to decimal numbers on input	
function isDeclNumber(e){
	var unicode=e.charCode? e.charCode : e.keyCode
	if (unicode!=8){ 
		if (unicode<46||unicode>57) 
		return false 
	}
}

//format to d decimal places
function toDecl(obj,a,d) {
		if (!isNaN(a)) {
		a = a / 1;
		a = a.toFixed(d); 
		document.getElementById(obj).value = a;
	}
}

function alltrim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = / +/g;
   temp = temp.replace(obj, " ");
   if (temp == " ") { temp = ""; }
   return temp;
}

toCamelCase.exp = / ([a-z])/;
function toCamelCase(s) {
	s = ' '+s.toLowerCase();
	for(var exp = toCamelCase.exp; 
		exp.test(s); 
		s = s.replace(exp, ' '+RegExp.$1.toUpperCase()) );
	return alltrim(s);
}

function passwordTrim(value) {
	var obj=/\W/g;
		value = value.replace(obj, "");
		return value;
}

function noSpecials(value) {
//	var obj=/[&/=:#?*\\'\\"<>%$]/g;
//	var obj = /&nbsp;|\*picture\*|\f|\n|\r|\t|[&/=:#?*<>%$\\"\\'\.\,\)\(]/g;
	var obj = /&nbsp;|\*picture\*|\f|\t|[&/=:#?*<>%$\\"\\'\.\,\)\(]/g;
		value = value.replace(obj, " ");
		return value;
}

function isValidEmail(emailAddress) {
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(2([0-4]\d|5[0-5])|1?\d{1,2})(\.(2([0-4]\d|5[0-5])|1?\d{1,2})){3} \])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    return re.test(emailAddress);
}

