function checkcard(thiscard)
	{
								if (thiscard == "VISA" || thiscard == "DELTA" || thiscard == "MC" || thiscard == "American Express")
									{
										document.getElementById("startdate").style.display = ""
										document.getElementById("issuenumber").style.display = "none"
									}
								else
									{
										document.getElementById("startdate").style.display = "none"
										document.getElementById("issuenumber").style.display = ""
									}
									
									document.getElementById("cardtype").value = thiscard;
									
									if(thiscard == "Cheque" || thiscard == "PO")
									{
										showdiv('postal-payment','block')
										showdiv('cardpayment','none')
										showdiv('carddetails','none')
										document.getElementById("action").value = "Submit Order"
									}
									else
									{
										showdiv('postal-payment','none')
										showdiv('cardpayment','block')
										showdiv('carddetails','block')
										document.getElementById("action").value = "Pay Now"
									}
									
									//showdiv('cardtypetext','block')
									showdiv('tc_div','block')
									
	}

						
	function addOption(selectbox,text,value,clearfirst,thisstyle)
{

text = text.replace('&pound;','£')

if (document.getElementById(selectbox))
{
	if (clearfirst){
	document.getElementById(selectbox).options.length = 0
	}
	
  if (document.getElementById(selectbox))
	{
  	var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
//		optn.backgroundcolor="#676767";
  	document.getElementById(selectbox).options.add(optn);
	}
	}
}

function changetocase(whatcase,what,text)
{

	if (whatcase == "p")
	{
		document.getElementById(what).value = pCase(text) 
	}
	else
	{
		document.getElementById(what).value = text.toUpperCase() 
	}

}


function pCase(s) 
    { 
        return s.replace(/(\w)(\w*)/g,function 
        ( 
            strMatch, 
            strFirst, 
            strRest, 
            intMatchPos, 
            strSource 
        ) 
        { 
            return strFirst.toUpperCase() 
            +strRest.toLowerCase(); 
        }); 
    } 


//**********************************product zoomer
 function changeimg(tothis,thisimage)
  {
  	document.getElementById(thisimage).src=tothis
  }
	
	function zoominout(whichway)
	{
		if (whichway == "in")
		{
			document.getElementById("bigimg").style.display = "block"
			document.getElementById("img").style.display = "none"
		}
		else
		{
			document.getElementById("bigimg").style.display = "none"
			document.getElementById("img").style.display = "block"
		}
	}
	
	function swap_apartment_tab(tothis)
	{
	document.getElementById("tab"+document.getElementById("currenttabon").value).style.display = "none";
	document.getElementById("tab"+tothis).style.display = "block";
	
	/*off*/
	document.getElementById("tablink"+document.getElementById("currenttabon").value).style.color ="#adadaf"
	document.getElementById("tablink"+document.getElementById("currenttabon").value).style.border ="1px solid #d6d2cf"
	styleswap("tablink"+document.getElementById("currenttabon").value,"off")
	styleswap("tablink"+tothis,"on")
	/*off*/
	
	document.getElementById("currenttabon").value = tothis
	document.getElementById("tablink"+document.getElementById("currenttabon").value).style.color ="#3697fe"
	document.getElementById("tablink"+document.getElementById("currenttabon").value).style.border ="1px solid #3697fe"
	}

	
	function styleswap(thisid,thisclass){
	document.getElementById(thisid).className=thisclass;
}
	
	function showzoom(imgsrc)
	{
		//alert(imgsrc)
		embed = "<object classid=~clsid:d27cdb6e-ae6d-11cf-96b8-444553540000~ codebase=~http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0~ width=~400~ height=~410~  >"
    embed += "<param name=~allowScriptAccess~ value=~sameDomain~ />"
    embed += "<param name='movie' value='imgviewer2.swf?"+imgsrc+"'>"
		embed += "<param name=~quality~ value=~high~ />"
		embed += "<param name=~bgcolor~ value=~#ffffff~ />"
		embed += "<embed src=~/imgviewer2.swf?"+imgsrc+"~ quality=~high~ bgcolor=~#ffffff~ width=~400~ height=~410~ name=~container~ align=~middle~ allowScriptAccess=~sameDomain~ type=~application/x-shockwave-flash~ pluginspage=~http://www.macromedia.com/go/getflashplayer~ />"
    embed += "</object><br /><br />"
		
		embed += "<a href='#' onclick=~zoominout('out');~ ><img src=~"+dotdotdash+"images/zoom-out.gif~ alt=~zoom out~></a>"
	
	
	
	writetopage('bigimg',embed)
	}
/////////////////////////////////////product zoomer



/*************************productOptions*/

function getprodoptions(theseoptions,productID,pID,optionids)
{

	document.getElementById("unavailable").value="";
	savewhat = "&";
	optionslist = theseoptions.split("|")
	optionidslist = optionids.split("|")
	//alert(theseoptions)
	for (i=0;i<=(optionslist.length)-2;i++) 
{
	
	//savewhat += optionslist[i]+"="+document.getElementById(optionidslist[i])[document.getElementById(optionidslist[i]).selectedIndex].value+"&"
	savewhat += optionslist[i]+"="+document.getElementById(optionidslist[i]).value+"&"	
}

		savewhat += "optionslength="+((optionslist.length*1)-1)
	//alert(savewhat)
	ajax('getprodoptions',"&optionslist="+savewhat+"&productID="+productID+"&pID="+pID+"&productprice="+document.getElementById("productprice").value)

}
//////////////////////////////////productOptions*/

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 changeimg(thisimage,tothis)
  {
		//alert(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) {
if (num != null)
{
  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)
{
//	alert(thisdiv)
  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 == 'table-row' "))
      	{
					eval(thisparent+"document.getElementById('"+thisdiv+"').style.display = 'none' ")
      	}
      else
      	{	
				eval(thisparent+"document.getElementById('"+thisdiv+"').style.display = 'table-row' ")
      	}
    }

}

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 initprice(pricefrom,priceto)
	{
		
		if (document.getElementById("lowpriceval"))
		{
		document.getElementById("lowpriceval").value = "£"+pricefrom;
		document.getElementById("highpriceval").value = "£"+priceto;
		}
	}
	
	function updateselected_options(pricefrom,priceto)
	{
		pricefrom = document.getElementById("lowpriceval").value
		priceto = document.getElementById("highpriceval").value
		//document.getElementById("lowpricediv").innerHTML = formatCurrency(pricefrom);
		//document.getElementById("highpricediv").innerHTML = formatCurrency(priceto);
		document.getElementById("selected_options").value = "";
		document.getElementById("selected_cats").value = "";
		for (a=1;a<=(document.getElementById("optionno").value)*1;a++)
		{
			if (document.getElementById("option_"+a).checked)
			{
				document.getElementById("selected_options").value = document.getElementById("selected_options").value + "~" + document.getElementById("option_"+a).value
			}
		}
	
		for (a=1;a<=(document.getElementById("subcatno").value)*1;a++)
		{
			if (document.getElementById("subcat_"+a).checked)
			{
				document.getElementById("selected_cats").value = document.getElementById("selected_cats").value + "~" + document.getElementById("subcat_"+a).value
			}
		}
	
	ajax("updateproducts", "cats="+document.getElementById("selected_cats").value+"&pricefrom="+pricefrom+"&priceto="+priceto+"&products="+document.getElementById("productsresult").value+"&options="+document.getElementById("selected_options").value)	
	
	//initprice(pricefrom,priceto)
	}
	
	function ajax(dothis,vars)
  {
	
	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;
						}
			  }
		}
		
    xmlHttp.onreadystatechange=function()
      {
      if(xmlHttp.readyState==4)
        {
							var result = xmlHttp.responseText
							
							if (dothis == "loadproducts")
							{
							//	alert(result)
						//		document.write(result)
							}
//					document.write(result)

						eval(result)

        }
  			}

			//	alert("dothis="+dothis+"&"+vars)
  xmlHttp.open("GET",dotdotdash+"ajax.asp?dothis="+dothis+"&"+vars,true);
	xmlHttp.send(null);  
}
