function fn_checkloginform()
{
	if (document.getElementById('useremailaddress'))
	{
	email = document.getElementById('useremailaddress').value
	}
	else
	{
	email = "";
	}
	username = document.getElementById('userloginname').value
	password = document.getElementById('userpassword').value
	
	errormsg = "";
	if (username == "")
	{
		errormsg = "<span class='red'>Please enter your Login ID</span><br />"
	}
	
	if (password == "")
	{
		errormsg += "<span class='red'>Please enter your password</span>"
	}
	

	//alert(errormsg + " " + email)
	if (errormsg != "" && email == "")
	{
		document.getElementById("login_error_msg").innerHTML = errormsg
		return false;
	}
	else
	{
//	alert("calling Login AJAX")
		ajax("login","username="+username+"&password="+password+"&email="+email)
	}
}


function checktc()
	{
   if (document.getElementById("tcs").checked != true)
   	{
      alert('Please tick the box to indicate you have read our terms and conditions')
      return false;
    }
  }

	function showmoreoptions()
	{
		
		if (document.getElementById("showmoreoptions_value").value != "")
		{
				document.getElementById("showmoreoptions_value").value = ""
		}
		else
		{
			document.getElementById("showmoreoptions_value").value = "show"
		}
		showdiv('moreoptions')
	
	}
	
function checkstay(thisstay)
{
	
	if (thisstay == "longstay")
	{
		showdiv('longstay_options','block')
		showdiv("div_cmbnights","none")
	}
	else
	{
		showdiv('longstay_options','none')
		showdiv("div_cmbnights","block")
	}

} 
	
function reloadarrivaldate()
{
	
	arrivaldate = document.getElementById("arrivaldate").value
	property_id = document.getElementById("property_id").value
	nights = document.getElementById("nights").value
	
	writetopage("thisarrivaldate","<a style='cursor:pointer'  onclick=~ajax('changearrivaldate','arrivaldate="+arrivaldate+"&property_id="+property_id+"&nights="+nights+"')~>"+arrivaldate+"</a>")
}

function checkcard(thiscard)
	{
		if (thiscard == "VISA" || thiscard == "DELTA" || thiscard == "MC" || thiscard == "American Express")
		{
			if (thiscard != "DELTA")
			{
			document.getElementById("cc_charge").value = ((document.getElementById("totalprice").value * 1) / 100) * 2.5
			document.getElementById("confirmtotal_price").innerHTML = formatCurrency((document.getElementById("totalprice").value)*1 + (document.getElementById("cc_charge").value*1))
			document.getElementById("cc_chargedescription").style.display = ""
			}
			else
			{
				document.getElementById("cc_charge").value = "0"
				document.getElementById("confirmtotal_price").innerHTML = formatCurrency((document.getElementById("totalprice").value)*1 + (document.getElementById("cc_charge").value*1))
				document.getElementById("cc_chargedescription").style.display = "none"
			}
			document.getElementById("startdate").style.display = ""
			document.getElementById("issuenumber").style.display = "none"
		}
		else
		{
			document.getElementById("cc_charge").value = "0"
			document.getElementById("confirmtotal_price").innerHTML = formatCurrency((document.getElementById("totalprice").value)*1 + (document.getElementById("cc_charge").value*1))
			document.getElementById("startdate").style.display = "none"
			document.getElementById("issuenumber").style.display = ""
			document.getElementById("cc_chargedescription").style.display = "none"
		}
	}
																								
function checkavailability(checkwhat,property_id)
	{
		
		if (checkwhat == "dates")
			{
				arrivaldate = document.getElementById('arrival_day')[document.getElementById('arrival_day').selectedIndex].value+" "+document.getElementById('arrival_month')[document.getElementById('arrival_month').selectedIndex].value
				nights = document.getElementById('nights').value
			}
		else
			{
				arrivaldate = document.getElementById('arrivaldate').value
				nights = document.getElementById('thisnights')[document.getElementById('thisnights').selectedIndex].value
			}
			ajax("checkavailability","property_id="+property_id+"&arrivaldate="+arrivaldate+"&nights="+nights+"&checkwhat="+checkwhat)
//			ajaxDothis('checkavailability',property_id,''+arrivaldate,''+nights,''+checkwhat)
	}
		
function fn_changearrivaldate(change)
                                              {
																								if (change == "change")
																								{
                                              		document.getElementById("showarrivaldate").style.display = "none";
																									document.getElementById("changearrivaldate").style.display = "block";
																								}
																								else
																								{
																									document.getElementById("showarrivaldate").style.display = "block";
																									document.getElementById("changearrivaldate").style.display = "none";
																								}
																							}
																							
																								function fn_changenights(change)
                                              {
																								if (change == "change")
																								{
                                              		document.getElementById("shownights").style.display = "none";
																									document.getElementById("changenights").style.display = "block";
																								}
																								else
																								{
																									document.getElementById("shownights").style.display = "block";
																									document.getElementById("changenights").style.display = "none";
																								}
                         }

function swap_apartment_tab(tothis)
{
	
	document.getElementById("tab"+document.getElementById("currenttabon").value).style.display = "none";
	document.getElementById("tab"+tothis).style.display = "block";
	
	document.getElementById("tablink"+document.getElementById("currenttabon").value).style.color ="#231a0c"
	styleswap("tablink"+document.getElementById("currenttabon").value,"off")
	styleswap("tablink"+tothis,"on")
	
	document.getElementById("currenttabon").value = tothis
	
	document.getElementById("tablink"+document.getElementById("currenttabon").value).style.color ="#ffffff"
	
	
}

function checknights(thisnights)
{
	if (thisnights == "30")
	{
		alert("To Book more than 29 nights, please call us on 01242 582 201")
	}
}



function fn_cleardates(pref,vfromday,vfrommonth,vfromyear,vtoday,vtomonth,vtoyear)
{

  document.getElementById(pref+"fromday").value=vfromday
  document.getElementById(pref+"frommonth").value=vfrommonth
  document.getElementById(pref+"fromyear").value=vfromyear
  document.getElementById(pref+"today").value=vtoday
  document.getElementById(pref+"tomonth").value=vtomonth
  document.getElementById(pref+"toyear").value=vtoyear

}


	function checkcardtype(thiscard)
		{
			if (thiscard == "DELTA" || thiscard == "VISA" || thiscard == "MC" || thiscard == "American Express")
			{
				//document.getElementById("cc_charge").value = ((document.getElementById("totalprice").value * 1) / 100) * 2.5
				//document.getElementById("confirmtotal_price").innerHTML = formatCurrency((document.getElementById("totalprice").value)*1 + (document.getElementById("cc_charge").value*1))
				document.getElementById("startdate").style.display = ""
				document.getElementById("issuenumber").style.display = "none"
				//document.getElementById("cc_chargedescription").style.display = ""
			}
			else
			{
				//document.getElementById("cc_charge").value = ""
				//document.getElementById("confirmtotal_price").innerHTML = formatCurrency((document.getElementById("totalprice").value)*1 + (document.getElementById("cc_charge").value*1))
				document.getElementById("startdate").style.display = "none"
				document.getElementById("issuenumber").style.display = ""
				//document.getElementById("cc_chargedescription").style.display = "none"
			}
		}
	
	function getvalue(thisid)
	{
		if (document.getElementById(thisid))
		{
			getvalue = document.getElementById(thisid).value
		}
		
		
		return getvalue
	
	}
		
	function takepayment(inv_id)
	{
	
	
	/*
	strVendorTxCode = booking_code
	Amount = request.querystring("Amount")
	orderdescription = request.querystring("orderdescription")
	*/
	details =  "strCardHolder="+document.getElementById("cardname").value
	details = details+ "&strCardNumber="+document.getElementById("strCardNumber").value
	details = details+ "&strStartDate="+document.getElementById("start_month")[document.getElementById("start_month").selectedIndex].value+document.getElementById("start_year")[document.getElementById("start_year").selectedIndex].value
	details = details+ "&strExpiryDate="+document.getElementById("expiry_month")[document.getElementById("expiry_month").selectedIndex].value+document.getElementById("expiry_year")[document.getElementById("expiry_year").selectedIndex].value
	details = details+ "&strIssueNumber="+document.getElementById("issue_number").value
	details = details+ "&strCV2="+document.getElementById("security_code").value
	details = details+ "&strCardType="+document.getElementById("cardtype")[document.getElementById("cardtype").selectedIndex].value
	details = details+ "&strBillingAddress="+document.getElementById("add_name").value
	details = details+ "&strBillingPostCode="+document.getElementById("add_pcode").value
	details = details+ "&strCustomerName="+document.getElementById("cardname").value
	//details = details+ "&strCustomerEMail="+document.getElementById("strCustomerEMail").value
	
	details = details+"&inv_id="+inv_id
	//alert(details)
	ajax('takepayment',details)
	
	}
	
	
	function urldecode(str) {
	
  	str = unescape(str);
		str = str.replace(/"+"/g, ' ');
	
  	return str;
  }
	
	
	
	
	function writetopage(whatdiv,writethis)
	{
		//alert(writethis)
  	writethis = writethis.replace(/~/g, '"');
		
		//alert(writethis)
		//writethis = writethis.replace(/isrtspce/g, ' ');
		//writethis = writethis.replace(/squote/g, "'");
		//writethis = writethis.replace(/isrtclosearrow/g, ">");
		//writethis = writethis.replace(/isrtdblquote/g, '"');
		
		//writethis = writethis.replace(/isrtbrk/g, "\n");
		 
		//writethis = unescape(writethis)
		//writethis = urldecode(writethis)
		//alert(writethis)
  	tothis = whatdiv;
		if (document.getElementById(tothis))
		{
	  	document.getElementById(tothis).innerHTML = writethis;
		}
		else
		{
			if (parent.document.getElementById(tothis))
  		{
				
  	  	parent.document.getElementById(tothis).innerHTML = writethis;
  		}
  		//else
  		//{
			//	alert("element "+tothis+" not found!")
			//}
		}
	}
	
	function thischange(changewhat,defaultvalue,inputtype,from,to,dothis,showquickdrop,left,top,width,ajaxdropfun,searchfield)
	{
		if(defaultvalue.indexOf("isrtbrk") > -1){
      textarea = "true"
    }
			else
		{
			textarea = "false"
		}

		
		dothis = dothis.replace(/aax/g, 'ajax');
		dothis = dothis.replace(/~/g, '"');
		defaultvalue = defaultvalue.replace(/isrtspce/g, " ");
		defaultvalue = defaultvalue.replace(/isrtbrk/g, "\n");
		defaultvalue = defaultvalue.replace(/insrtperc/g, "%");
		
		//alert(defaultvalue)
		newsel = "";
		
		if (inputtype == "tax")
		{
			dothis = dothis.replace(/thisvalue/g, "'+this[this.selectedIndex].value");
			newsel = "<select onchange="+dothis+">"
			
			////////////////////////////////////T3
      newsel += "<option value='3%'"
			if ("1.03" == defaultvalue){newsel += " selected "}newsel += ">3%</option>";
			newsel += "<option value='0%'"
			if ("0" == defaultvalue){newsel += " selected "}newsel += ">0%</option>";
			newsel += "<option value='17.5%'"
			if ("1.175" == defaultvalue){newsel += " selected "}newsel += ">17.5%</option>";
      newsel += "<option value='15%'"
			if ("1.150" == defaultvalue){newsel += " selected "}newsel += ">15%</option>";
			
			newsel += "</select>"
			
			document.getElementById(changewhat).innerHTML = newsel;
		
		}
		
		if (inputtype == "landlords")
		{
			
			dothis = "onchange="+'"'+dothis.replace(/thisvalue/g, "'+this[this.selectedIndex].value")+'"';
			
			newsel = "<select id='"+changewhat+"_i' "+dothis+">"
			newsel += "</select>"
			
			document.getElementById(changewhat).innerHTML = newsel;
			ajax('load_landlords',"change="+changewhat+"&defaultvalue="+defaultvalue)
		}
		
		if (inputtype == "numbers")
		{
			
			dothis = dothis.replace(/thisvalue/g, "'+this[this.selectedIndex].value");
			newsel = "<select onchange="+dothis+">"
			
			for (nums=from;nums<=to;nums=nums+1)
      {
      newsel += "<option value='"+nums+"'"
			
			if (nums == defaultvalue)
			{	
				newsel += " selected "
			}
			
			newsel += ">"+nums+"</option>"
      }
			
			newsel += "</select>"
			
			document.getElementById(changewhat).innerHTML = newsel;
			
		}
		else
		{
			if (changewhat == "name")
			{
				
				title = defaultvalue
				first_name = from
				last_name = to
				title = title.replace(/isrtspce/g, " ").replace(/squote/g, "'");
				first_name = first_name.replace(/isrtspce/g, " ").replace(/squote/g, "'");
				last_name = last_name.replace(/isrtspce/g, " ").replace(/squote/g, "'");
				
				newname = "name=true&title='+document.getElementById('title').value+'&first_name='+document.getElementById('first_name').value+'&last_name='+document.getElementById('last_name').value+'"
				newname = newname.replace(/~/g, '"');
				
				dothis = dothis.replace(/name=true/g, newname);
				
				newsel = "<input type='text' onkeyup=~ajax('searchcustomer_name','comefrom="+ajaxdropfun+"&title='+this.value+'&first_name='+document.getElementById('first_name').value+'&last_name='+document.getElementById('last_name').value)~ onmouseover=movesearchdrop('"+left+"px','"+top+"px','130px')  name='title' id='title'  style='font-size:8pt; width:20px;' value=~"+title+"~>"
				newsel += "<input type='text' onkeyup=~ajax('searchcustomer_name','comefrom="+ajaxdropfun+"&title='+document.getElementById('title').value+'&first_name='+this.value+'&last_name='+document.getElementById('last_name').value)~ onmouseover=movesearchdrop('"+(left*1+30)+"px','"+top+"px','130px') name='first_name'  id='first_name' style='font-size:8pt; width:70px;' value=~"+first_name+"~>"
				newsel += "<input type='text' onkeyup=~ajax('searchcustomer_name','comefrom="+ajaxdropfun+"&title='+document.getElementById('title').value+'&first_name='+document.getElementById('first_name').value+'&last_name='+this.value)~ onmouseover=movesearchdrop('"+(left*1+130)+"px','"+top+"px','130px') name='last_name'  id='last_name' style='font-size:8pt; width:70px;' value=~"+last_name+"~>"
				newsel += "&nbsp;&nbsp;<a onclick="+dothis+">save</a>"
				
				writetopage(changewhat,newsel)
			}
			else
			{
				if (newsel == "")
				{
					
    			dothis = dothis.replace(/thisvalue/g, "~+escape(this.value)");
					dothis = dothis.replace(/thischecked/g, "~+this.checked");
					
					dothis = dothis.replace(/'"'/g,"~")
					
					//alert(dothis)
    			onkeyup = "";
					
					if (showquickdrop == "true")
					{
						onkeyup = "onmouseover=movesearchdrop('"+left+"px','"+top+"px','"+width+"px')  onkeyup=~ajax('"+ajaxdropfun+"','dothis="+dothis+"&searchwhat="+searchfield+"&searchthis='+this.value)~"
					}
					//alert(dothis)
					//onfocus=~emptyfield('focus','"+changewhat+"_i','"+defaultvalue+"')~
					
					
					if (defaultvalue.length > 50 || textarea == "true")
					{
						newsel = "<textarea style='width:80%; height:250px;font-size:8pt;border:1px solid #d35918' id=~"+changewhat+"_i~ onblur='"+dothis+"'>"+urldecode(defaultvalue)+"</textarea>"
					}
					else
					{
						newsel = "<input type='text' "+onkeyup+" style='font-size:8pt;width:80%;border:1px solid #d35918' id=~"+changewhat+"_i~ value=~"+defaultvalue+"~  onblur='"+dothis+"' >"
					}
					
					writetopage(changewhat,newsel)
				}
			}
			if (document.getElementById(changewhat+"_i"))
			{
				document.getElementById(changewhat+"_i").focus()
			}
		}
	}
	
	

		
	function setvalue(setthis,tothis)
	{
		
		if(document.getElementById(setthis))
		{
			document.getElementById(setthis).value = tothis
		}
		else
		{
			alert(setthis+ " not found" )
		}
	}
	
	function findMyText(haystackText, needle, replacement) 
	{
	
		var match = new RegExp(needle, "g");     
    var replaced = "";
    replaced = haystackText.replace(needle, replacement);
		
		return replaced;
	}
	
function setOpacity(element, opacity) {
    if (navigator.userAgent.indexOf("MSIE") != -1) {
        var normalized = Math.round(opacity * 100);
        element.style.filter = "alpha(opacity=" + normalized + ")";
    } else {
        element.style.opacity = opacity;
    }
}

function styleswap(thisid,thisclass){

	document.getElementById(thisid).className=thisclass;
}

function changeimg(thisimage,tothis)
  {
		if (document.getElementById(thisimage))
		{
  		document.getElementById(thisimage).src=tothis
		}
		else
		{
			if (parent.document.getElementById(thisimage))
			{
				parent.document.getElementById(thisimage).src=tothis
			}
			else
			{
				alert(thisimage + " not found" )
			}
		}
  }

function formatCurrency(num) {
  num = num.toString();
  if(isNaN(num))
  num = "0";
  sign = (num == (num = Math.abs(num)));
  num = Math.floor(num*100+0.50000000001);
  cents = num%100;
  num = Math.floor(num/100).toString();
  if(cents<10)
  cents = "0" + cents;
  for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
  num = num.substring(0,num.length-(4*i+3))+','+
  num.substring(num.length-(4*i+3));
  return (((sign)?'':'-') + '&pound;' + num + '.' + cents);
  }
	
function pause(millis) 
  {
  var date = new Date();
  var curDate = null;
  
  do { curDate = new Date(); } 
  while(curDate-date < millis);
  } 



function showdiv(thisdiv,showhide)
{

  if (document.getElementById(thisdiv))
  {
  thisparent = ""
  }
  else
  {
		if (parent.document.getElementById(thisdiv))
    {
    	thisparent = "parent."
    }
		else
		{
			if (top.document.getElementById(thisdiv))
      {
      	thisparent = "top."
      }
		}
  }
	
	//	alert(thisdiv + " - " + showhide)
	if (showhide != null && showhide != "")
  	{
    	if (eval(thisparent+"document.getElementById('"+thisdiv+"') != null") )
    		{
    			eval(thisparent+"document.getElementById('"+thisdiv+"').style.display = '"+showhide+"'")
    		}
    }
  else
    {
		
      if (eval(thisparent+"document.getElementById('"+thisdiv+"').style.display == 'block' "))
      	{
					eval(thisparent+"document.getElementById('"+thisdiv+"').style.display = 'none' ")
      	}
      else
      	{	
				eval(thisparent+"document.getElementById('"+thisdiv+"').style.display = 'block' ")
      	}
    }

}

function emptyfield (doingthis, fieldname,defaultvalue)
{

if (doingthis == "blur")
{
	if (document.getElementById(fieldname).value == "")
	{
		document.getElementById(fieldname).value = defaultvalue
	}
}
else
{

	if (document.getElementById(fieldname).value == defaultvalue)
	{
		document.getElementById(fieldname).value = ""
	}
}

}
	
function urlencode(str) {
str = escape(str);
str = str.replace(' ', '+');
str = str.replace('+', '%2B');
str = str.replace('%20', '+');
str = str.replace('*', '%2A');
str = str.replace('/', '%2F');
str = str.replace('@', '%40');
return str;
}





	function check_tick(dothis,savewhat,saveid,tickon, tickoff)
{
 
 if (document.getElementById(savewhat).checked)
 {
 	savethis = "true"
 }
 else
 {
 	savethis = "false"
 }
	
	if (document.getElementById(savewhat).checked)
	{
		ajaxDothis(dothis,savewhat,saveid,savethis)
	}
	else
	{
		ajaxDothis(dothis,savewhat,saveid,savethis)
	}

}



	function addOption(selectbox,text,value,clearfirst)
{
	if (clearfirst){
	
	document.getElementById(selectbox).options.length = 0
	}
  if (document.getElementById(selectbox))
	{
  	var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
  	document.getElementById(selectbox).options.add(optn);
	}
}


function setfromdate(thisday,thismonth,thisyear,setthisday,setthismonth,setthisyear)
{
	
	if (document.getElementById(setthisday))
	{
		
  document.getElementById(setthisday).value = thisday;
	document.getElementById("cmb_day").value = thisday;
  document.getElementById(setthismonth).value = thismonth;
	document.getElementById("cmb_month").value = thismonth;
  document.getElementById(setthisyear).value = thisyear;
	}
	else
	{
		
	parent.document.getElementById(setthisday).value = thisday;
	parent.document.getElementById("cmb_day").value = thisday;
  parent.document.getElementById(setthismonth).value = thismonth;
	parent.document.getElementById("cmb_month").value = thismonth;
  parent.document.getElementById(setthisyear).value = thisyear;
	}
}

function addOption_list(selectbox,text,value){
	addOption(selectbox, text,value);
}


function qs(variable,querystring) { 
  var query = querystring;
  var vars = query.split("&"); 
  for (var i=0;i<vars.length;i++) { 
    var pair = vars[i].split("="); 
    if (pair[0] == variable) { 
      return pair[1]; 
    } 
  } 
	qs = variable
//  alert('Query Variable ' + variable + ' not found'); 
} 

function changeavailability(id,thismonth,changeto)
{

			//alert(document.getElementById(savewhat+"_"+saveid).src)
			if (document.getElementById(id+"_"+thismonth).src=="http://www.servicedpropertiesdirect.com/images/apart_unavailable.gif")
			{
				//alert("making avaialble")
				document.getElementById(id+"_"+thismonth).src="http://www.servicedpropertiesdirect.com/images/apart_available.gif";
			}
			else
			{
				//alert("making "+savewhat+"_"+saveid+"unavailable")
				document.getElementById(id+"_"+thismonth).src="http://www.servicedpropertiesdirect.com/images/apart_unavailable.gif";
			}		

ajax('changeavailability','id='+id+"&thismonth="+thismonth)
}

	
	function ajax(dothis,variables,other)
  {
	
	
	
	
	//alert("dothis: "+dothis+" : " + variables)
	var xmlHttp;
  try
    {    // Firefox, Opera 8.0+, Safari    
				xmlHttp=new XMLHttpRequest();    }
  catch (e)
    {   
		 // Internet Explorer  
		try
      {      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
				}
    catch (e)
      { 
				try
        {        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
						}
      catch (e)
        {        alert("Your browser does not support AJAX!");
						        return false;
						}
			  }
		}
		
		
		if (dothis == "load_enquiry")
		{
			
			enquiry_id = qs("id",variables)
			rowid = qs("rowid",variables)
			document.getElementById(rowid+"enquiry_"+enquiry_id).innerHTML = "Please wait while we load this enquiry"
		}

    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
					var result = xmlHttp.responseText
					if (result.slice(2,12) == "<!DOCTYPE " || result.slice(2,12) == "font face=" || result.slice(2,12) == "ADODB.Field" )
							{
							document.write(result)
							 alert("Sorry, there has been an error.")
							// ajax("senderror",result,"")
							}
							else
							{
							
								if (dothis == "offer_apartments")
								{
							//		document.write(result)
								}
							
						//	alert(result)
								eval(result)
							}
				}
  		}
				//alert("savethis: "+savethis)
		//alert("ajax.asp?dothis="+dothis+"&"+variables)
				
  xmlHttp.open("GET",dotdotdash+"ajax.asp?dothis="+dothis+"&"+variables,true);
	xmlHttp.send(null);  
}