thisURL = window.location.href
	if(thisURL.indexOf("mrwizard") > 0)
	{
		localfolder = "paul-mann/10/";
	}
	else
	{
		localfolder ="";
	}
	
function URLDecode(psEncodeString) 
{
  // Create a regular expression to search all +s in the string
  var lsRegExp = /\+/g;
  // Return the decoded string
  return unescape(String(psEncodeString).replace(lsRegExp, " ")); 
}


function addOption(selectbox,text,value,clearfirst,thisstyle)
{

text = text.replace('&pound;','£')
if (document.getElementById(selectbox))
{
	if (clearfirst){
	document.getElementById(selectbox).options.length = 0
	}
		if (text != "" && value != "")
		{
		
      if (document.getElementById(selectbox))
    	{
      	var optn = document.createElement("OPTION");
        optn.text = URLDecode(text);
        optn.value = value;
    //		optn.backgroundcolor="#676767";
      	document.getElementById(selectbox).options.add(optn);
    	}
		}
	}
	else
	{
	alert(selectbox + " not found ")
	}
}

function updatebaskettotals(loop)
{
	if (document.getElementById('deliveryclass'))
	{
	deliveryclass = document.getElementById('deliveryclass')[document.getElementById('deliveryclass').selectedIndex].value
	}
	else
	{
	deliveryclass = ""
	}
	if (document.getElementById('shippingcountry'))
	{
	shippingcountry = document.getElementById('shippingcountry')[document.getElementById('shippingcountry').selectedIndex].value
	}
	else
	{
	shippingcountry = ""
	}
	ajax('updatebaskettotals','fromman=<%=fromman%>&deliveryclass='+deliveryclass+'&country='+shippingcountry+'&loop='+loop)
}

function copydeliveryaddress_fn()
{
document.getElementById("shippingaddress1").value = document.getElementById("address1").value;
document.getElementById("shippingfirstname").value = document.getElementById("firstname").value;
document.getElementById("shippinglastname").value = document.getElementById("lastname").value;
document.getElementById("shippingtown").value = document.getElementById("town").value;
document.getElementById("shippingcounty").value = document.getElementById("county").value;

document.getElementById("shippingcountry").value = document.getElementById("billingcountry")[document.getElementById("billingcountry").selectedIndex].value;
document.getElementById("shippingpostcode").value = document.getElementById("postcode").value;
updatebaskettotals('')
}

function writetopage(whatdiv,writethis)
{
  	writethis = writethis.replace(/~/g, '"');
  	tothis = whatdiv;
		if (document.getElementById(tothis))
		{
  	document.getElementById(tothis).innerHTML = writethis;
		}
		else
		{
		//alert("element "+tothis+" not found!")
		}
}

	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 = ""
																											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 = ""
																										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 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 showdiv(thisdiv,showhide)
{
thisparent = ""
	
  if (document.getElementById(thisdiv))
  {
  thisparent = ""
  }
  else
  {
		if (parent.document.getElementById(thisdiv))
    {
    	thisparent = "parent."
    }
		else
		{
			if (top.document.getElementById(thisdiv))
      {
      	thisparent = "top."
      }
		}
  }
	
		
	if (showhide != null && showhide != "")
  	{
		
    	if (eval(thisparent+"document.getElementById('"+thisdiv+"') != null") )
    		{
			
					if (navigator.userAgent.indexOf("Firefox")!=-1)
					{
						
					//alert(thisdiv + " - " + showhide)
      			if(showhide == "block")
    				{
    					showhide = "table-row"
    				}
				
						
					}
					
							if (showhide  == "block-block")
						{
						showhide = "block"
						}
						
    			eval(thisparent+"document.getElementById('"+thisdiv+"').style.display = '"+showhide+"'")
    		}
    }
  else
    {
		
						
      if (eval(thisparent+"document.getElementById('"+thisdiv+"').style.display == 'table-row' "))
      	{
					eval(thisparent+"document.getElementById('"+thisdiv+"').style.display = 'none' ")
      	}
      else
      	{	
				eval(thisparent+"document.getElementById('"+thisdiv+"').style.display = 'table-row' ")
      	}
    }

}
																								
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 styleswap(thisid,thisclass){
	document.getElementById(thisid).className=thisclass;
}

function urlencode(str) {
str = escape(str);
str = str.replace('+', '%2B');
str = str.replace('%20', '+');
str = str.replace('*', '%2A');
str = str.replace('/', '%2F');
str = str.replace('@', '%40');
return str;
}

function urldecode(str) {
str = str.replace('+', ' ');
str = unescape(str);
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 styleswap(thisid,thisclass){
	document.getElementById(thisid).className=thisclass;
}

	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 swapimg(imgid,tothisimg,windowvalue,currentfolder,selectid)
{
	if (tothisimg != windowvalue)
	{
		if (imgid != "")
		{
			document.getElementById(imgid).src=tothisimg;
		}
	}
	else
	{
	tb_show("new Window", "uploads.asp?preview="+selectid+"_preview&insertinto="+selectid+"&c=1&currentfolder="+currentfolder+"&height=750&width=870&KeepThis=true&TB_iframe=true", false)
	}
}

	function ajax(dothis,vars)
	{
			ajaxDothis(dothis,"&"+vars,"fromajax","","")
	}
	
	function ajaxDothis(dothis,savewhat,saveid,savethis,extras)
  {
	//alert("dothis: " +dothis + "; savewhat: "+savewhat+"; saveid:" + saveid + "; savethis: " +savethis + "; extras : " +extras)
	savethis = urlencode(savethis)
	
	
	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=="offer_apartments")
		{
			document.getElementById("offer_apartment_results").innerHTML = "<div style='padding:10px;'><p align='center'>Please wait while we load more apartments</p></div>"		
		}
		
		if (dothis == "changeavailability")
		{
			//alert(document.getElementById(savewhat+"_"+saveid).src)
			if (document.getElementById(savewhat+"_"+saveid).src=="http://www.servicedpropertiesdirect.com/images/apart_unavailable.gif")
			{
				//alert("making avaialble")
				document.getElementById(savewhat+"_"+saveid).src="http://www.servicedpropertiesdirect.com/images/apart_available.gif";
			}
			else
			{
				//alert("making "+savewhat+"_"+saveid+"unavailable")
				document.getElementById(savewhat+"_"+saveid).src="http://www.servicedpropertiesdirect.com/images/apart_unavailable.gif";
			}		
		}
		
		if (dothis == "login")
		{
			if (savethis == "")
			{
				document.getElementById("login_error_msg").innerHTML = "<b>Please wait while we log you in...</b>"
			}
			else
			{
				document.getElementById("login_error_msg").innerHTML = "<b>Please wait while find your account details</b>"
			}
		}
		
		
		
		
			
		
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
							var result = xmlHttp.responseText
				//alert(result)
						if (result.indexOf("Microsoft VBScript runtime ") > -1 || result.indexOf("<p>Active Server Pages</font>") > -1 || 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.")
					
							 
							}
							else
							{
						//	alert(result)
								eval(result)
							
							}
							
							
							
        }
  			}
				//alert("savethis: "+savethis)
		//alert("ajax.asp?dothis="+dothis+"&savewhat="+savewhat+"&saveid="+saveid+"&savethis="+savethis+"&extras="+extras)
				//dotdotdash="&dotdotdash&"&
  xmlHttp.open("GET","/"+localfolder+"ajax.asp?dothis="+dothis+"&savewhat="+savewhat+"&saveid="+saveid+"&savethis="+savethis+"&extras="+extras,true);
	xmlHttp.send(null);  
}
