var showblackbarsubnav_var = "";
var feedback = "";
var newsletter = "";
var incrementVal = 20;
var timer;
var flag;

function checkcard(thiscard)
	{
		//document.getElementById("cardtoken").value = "Choose one of your previously saved cards";
		//document.getElementById("cardtoken").selectedIndex = 0;
								if (thiscard == "VISA" || thiscard == "DELTA" || thiscard == "MC" || thiscard == "American Express")
									{
										showdiv("startdate","block")
										//alert("hididng issuenumber_tr")
										showdiv("issuenumber_tr","none")
									}
								else
									{
										showdiv("startdate","block")
										showdiv("issuenumber_tr","block")
										
									}
									
									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')
										
									}
									
									//showdiv('cardtypetext','block')
									showdiv('tc_div','block')
									
	}
	
function change_availability(what,m,d)
{
	d = parseInt(d)
	if (what == "month")
	{
		loopto = d + 31
	}
	else
	{
		loopto = d + 0
	}
	//alert(d+ " to "+loopto)
	for  (a=d;a<=loopto;a++)
		{
			//alert(m+" " +a)
			if(document.getElementById(m+"_"+a).src == "http://mrwizard/utiliseit/images/block_available.png") 
  		{
  			document.getElementById(m+"_"+a).src = "http://mrwizard/utiliseit/images/block_unavailable.png"
				document.getElementById(m+"_"+a+'_val').value = "2";
  		}
  		else
  		{
  			document.getElementById(m+"_"+a).src = "http://mrwizard/utiliseit/images/block_available.png"
				document.getElementById(m+"_"+a+'_val').value = "0";
  		}
		
		}
		
	
		
	

}

function getCheckedValue(radioObj) {
	if(!radioObj)
	
		return "";
	var radioLength = radioObj.length;
	
	if(radioLength == undefined)
		if(radioObj.checked)
			
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}



function swap_dyo_layer(layerno,nolayers,loadimage)
{
	if (document.getElementById("currentlayerno").value < layerno)
	{
		document.getElementById("currentlayerno").value = layerno
	}

		styleswap("icon_"+layerno,'cursorpointer')
		
		productid = document.getElementById("productid").value
		lastlayerno = document.getElementById("lastlayerno").value
		
		thislength = document.getElementById("sel_length").value//getCheckedValue(document.forms['form'].elements['sel_length']) 
		nextlayerno = layerno

		if (document.getElementById("layer"+layerno+"_id"))
		{
  		layerid = document.getElementById("layer"+layerno+"_id").value
		}
		else
		{
		
		}
		
		showdiv('layerno'+lastlayerno,'none');
		
		showdiv('layer'+layerid+'_materials','block')
		showdiv('layer'+layerid+'_colours','none')
		
	
			showdiv('layerno'+layerno,'block')
			
			changeimg("icon_"+lastlayerno,"images/dyo_step"+lastlayerno+"_off.gif")
			changeimg("icon_"+layerno,"images/dyo_step"+layerno+".gif")
		  
			if (document.getElementById("layer"+layerno+"_id") && loadimage == "true")
			{
				//alert("loadingloayer image for "+ layerno)
				if (document.getElementById("layerimg_val2"+layerno).value == "/"+localfolder+"images/none.png" )
				{
					ajax('loadlayerimage','layerno='+layerno+'&layerid='+layerid+'&productid='+productid+"&length="+thislength)
				}
			}
			
		
	document.getElementById("lastlayerno").value = layerno;
}




function dyo_selectcolour(layerno,colour)
{
//alert("dyo_selectcolour")
	thisimage = document.getElementById("layerimg_val2"+layerno).value
//	alert(thisimage)
	ajax('changeimagecolour','layerno='+layerno+'&image='+thisimage+'&colour='+colour)
	
}


function showhidetab(whattab)
{
	currenttab = document.getElementById('currenttabon').value

	if (whattab == currenttab)
	{
		slidediv('left_'+whattab+'tab','-8','');
		slidediv('left_'+whattab,'-315','');
		document.getElementById('currenttabon').value = "";
	}
	else
	{
  	if (currenttab != ""){slidediv('left_'+currenttab+'tab','-8','');slidediv('left_'+currenttab,'-315','')}
  	slidediv('left_'+whattab+'tab','320','');
  	slidediv('left_'+whattab,'25','');
  	document.getElementById('currenttabon').value = whattab;
	}
}

function productsautofilter(prodoptions){
url = window.location.href
		url = url.replace(/%20/g,'');
		url = url.replace(/ /g,'');
		url = url.toLowerCase()
	prodoptions = prodoptions.split("~")
	var optionsno=0;
	//alert(prodoptions.length)
	while (optionsno < prodoptions.length-1)
	{
		thisoption = prodoptions[optionsno].split("-")
		optionsno += 1
		optioname = thisoption[0].replace(' ','')
		option = thisoption[1].replace(' ','')
		fieldid = thisoption[2]
		//alert(optioname+ " "+ option)
		if(url.indexOf(optioname + '='+option) != -1)
    	{  
			//	 alert('found')
				document.getElementById(fieldid).checked = true
    	}
	
	
	
	}
	
	updateselected_options(0,1000)
 
}
function slidediv(divid,dropto,openclose){
	var obj = document.getElementById(divid);
	
	var Y = parseInt(obj.style.left);

	if(dropto>0 && Y< dropto){
	
     Y += incrementVal
		obj.style.left = (Y)+"px";
		timer = setTimeout("slidediv('"+divid+"','"+dropto+"','"+openclose+"')",10);
		
	}
	else if(dropto<0 && Y>dropto){
		
		Y -= incrementVal
		obj.style.left = (Y)+"px";
		timer = setTimeout("slidediv('"+divid+"','"+dropto+"','"+openclose+"')",10);
	}
}



function showblackbarsubnav(catid,showhide)
{

	if (showhide == "show")
	{

		showblackbarsubnav_var = "show";
		showdiv('navtable-container','block');
		if (catid != "" && document.getElementById("currentnav_on").value != catid)
		{
  		ajax('loadnavtable-content','show=products&catid='+catid);
  		document.getElementById("currentnav_on").value = catid;
			styleswap("crumb_"+catid,"blackbar_on")
		}
		else if(catid != ""){
  		styleswap("crumb_"+catid,"blackbar_on")
		}
    
	}
	else
	{
		if(showblackbarsubnav_var == "show"){showdiv('navtable-container','none');showblackbarsubnav_var = "hide"};
			if (catid != "")
     {
     
			styleswap("crumb_"+catid,"blackbar_off")
     }
	}
}



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(){
			
			$('select#speedA').selectmenu();
			
			$('select#speedAa').selectmenu({maxHeight: 150});
			
			$('select#speedB').selectmenu({
				width: 300,
				format: addressFormatting
			});
			
			$('select#speedC').selectmenu({style:'dropdown'});
			
			$('select#speedD').selectmenu({
				style:'dropdown', 
				menuWidth: 400,
				format: addressFormatting
			});
			
			$('select#files, select#filesC').selectmenu({
				icons: [
					{find: '.script', icon: 'ui-icon-script'},
					{find: '.image', icon: 'ui-icon-image'}
				]
			});
			
			$('select#filesB').selectmenu({
				icons: [
					{find: '.video'},
					{find: '.podcast'},
					{find: '.rss'}
				]
			});
			
			
		});
		
		
		//a custom format option callback
		var addressFormatting = function(text){
			var newText = text;
			//array of find replaces
		
	
			return newText;
		}
*/
						
function addOption(selectbox,text,value,clearfirst,thisstyle)
{
//alert("going to add " +text+ " added to "+ selectbox)
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 ")
	}
	//alert("added")
}

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("currentproducttabon").value).style.display = "none";
	document.getElementById("tab"+tothis).style.display = "block";
	
	styleswap("tablink"+document.getElementById("currentproducttabon").value,"apartment_tab_off")
	document.getElementById("currentproducttabon").value = tothis
	styleswap("tablink"+document.getElementById("currentproducttabon").value,"apartment_tab_on")
	
	/*off
	document.getElementById("tablink"+document.getElementById("currenttabon").value).style.color ="#000";
	document.getElementById("tablink"+document.getElementById("currenttabon").value).style.height ="10px";
	document.getElementById("tablink"+document.getElementById("currenttabon").value).style.bgColor = "#f1f1f1";
	document.getElementById("tablink"+document.getElementById("currenttabon").value).style.border ="1px solid #898c95"
	styleswap("tablink"+document.getElementById("currenttabon").value,"off")
	styleswap("tablink"+tothis,"on")
	/*off*/
	
	/*
	document.getElementById("tablink"+document.getElementById("currenttabon").value).style.color ="#000";
	document.getElementById("tablink"+document.getElementById("currenttabon").value).style.bgColor = "#fff";
	document.getElementById("tablink"+document.getElementById("currenttabon").value).style.height ="10px";
	document.getElementById("tablink"+document.getElementById("currenttabon").value).style.border ="1px solid #898c95"
	*/
	}

	
	function styleswap(thisid,thisclass){
  if (document.getElementById(thisid))
  {
  	
    if (document.getElementById(thisid).className != thisclass)
      {
  				document.getElementById(thisid).className=thisclass;
//       document.getElementById("stat").innerHTML +=thisclass;
      }
    }
    else
    {
   // alert(thisid+ " not found" )
    }
}
var countries = "off";
var sport = "off";
	function showdrops(what)
	{

		if (what == "countries")
		{
  		if (countries != "on")
  		{
  			showdiv('changecountries','block')
  			countries = "on";
  		}
		}
		else
		{

			if (sport != "on")
  		{
  			showdiv('changesports','block')
  			sport = "on";
  		}
		}
	}
	
	function hidedrops(what)
	{
		if (what == "countries")
		{
  		if (countries == "on")
  		{
  			showdiv('changecountries','none')
  			countries = "off"
  		}
		}
		else
		{
			if (sport == "on")
  		{
  			showdiv('changesports','none')
  			sport = "off";
  		}
		}
	}
	
	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,textbox,optiontype,notavailablea)
{
//alert(optionids)
	document.getElementById("unavailable").value="";
	savewhat = "&";
	optionslist = theseoptions.split("|")
	optionidslist = optionids.split("|")
	//alert(optionslist.length)
  for (i=0;i<=(optionslist.length)-2;i++) 
  {
  	if (optionslist[i] == "Personalise")
  	{
  		/*if (textbox == True)
  		{
  			alert("personalise : " + textbox)
  			showdiv("personalise_text","block")
  		}
  		else
  		{
  			
  			showdiv("personalise_text","none")
  		}
  		*/
  	}
  	//alert(optionidslist[i])
  	savewhat += optionidslist[i]+"="+document.getElementById(optionidslist[i]).value+"&"
  }
	
	savewhat += "optionslength="+((optionslist.length*1)-1)
	selectedoptionslist = "optionids="+optionids+"&optiontype="+optiontype+"&textbox="+textbox+savewhat+"&productID="+productID+"&pID="+pID+"&productprice="+document.getElementById("productprice").value+"&notavailable="+notavailablea
	//alert("getting getprodoptions")
	ajax('getprodoptions',selectedoptionslist)
	//alert("done")
}
//////////////////////////////////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)
{
		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 pause(millis) 
{
  var date = new Date();
  var curDate = null;
  
  do { curDate = new Date(); } 
  while(curDate-date < millis);
} 



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 || navigator.userAgent.indexOf("Safari")!=-1){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 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 formatCurrency(num,symbol,chrcode) 
{
  if (num != null)
  {
  	if (symbol == "" || symbol == null){symbol = "\u00A3"}
  
    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));
		
		if (chrcode == "&euro;")
		{
		
			return (num + '.' + cents + ((sign)?'':'-') + symbol);
		}
		else
		{
    	return (((sign)?'':'-') + symbol + num + '.' + cents);
		}
  }
}

function initprice(pricefrom,priceto,chr,chrcode)
{
		if (document.getElementById("lowpriceval"))
		{
		document.getElementById("lowpriceval").value = formatCurrency(pricefrom,chr,chrcode);
		document.getElementById("highpriceval").value = formatCurrency(priceto,chr,chrcode);
		}
}
	
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)
 {
	//alert("ajax")
	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
//							alert(dothis+ ":  "+ result)
//document.write(result)
     						if (result.slice(2,12) == "<!DOCTYPE " || result.slice(2,12) == "font face=")
          			{
          //   	alert(result)
         				document.write(result)
          	//			alert("Sorry, there has been an error.")
          			}
          				else
          			{
        						
												if (dothis == "geturl_fordiv")
												{
												document.getElementById("topnavcontent").innerHTML = result;
												}
												else
												{
													//alert(dothis+ " = " +result)
													eval(result)
													}
          			}
							}
  			}
 if (dothis == "geturl_fordiv")
 {
 	xmlHttp.open("GET",vars,true);
 }
 else
 {
 	thisURL = window.location.href
	
	if(thisURL.indexOf("mrwizard") > 0)
	{
		xmlHttp.open("GET","/utiliseit/ajax.asp?dothis="+dothis+"&"+vars,true);
	}
	else
	{
		xmlHttp.open("GET","/ajax.asp?dothis="+dothis+"&"+vars,true);
	}
 
}
	xmlHttp.send(null);  
}

