function toggleLayer( whichLayer )
{
	var elem, vis;
	if( document.getElementById ) // this is the way the standards work
		elem = document.getElementById( whichLayer );
	else if( document.all ) // this is the way old msie versions work
		elem = document.all[whichLayer];
	else if( document.layers ) // this is the way nn4 works
		elem = document.layers[whichLayer];
	vis = elem.style;
	// if the style.display value is blank we try to figure it out here
	if( vis.display == '' && elem.offsetWidth != undefined && elem.offsetHeight != undefined )
		vis.display = ( elem.offsetWidth != 0 && elem.offsetHeight != 0 ) ? 'block':'none';
	vis.display = ( vis.display == '' || vis.display == 'block' ) ? 'none':'block';
}

function showdiv(divid){
	document.getElementById(divid).style.height=105;
}

function createXMLHttp(){
	if (window.ActiveXObject){
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest){
		xmlhttp = new XMLHttpRequest();
	}
}

function CheckAll(){
  var c = new Array();
  c = document.getElementsByTagName('input');
  for (var i = 0; i < c.length; i++)
  {
    if (c[i].type == 'checkbox')
    {
      c[i].checked = true;
    }
  }
}
function ClearAll(){
  var c = new Array();
  c = document.getElementsByTagName('input');
  for (var i = 0; i < c.length; i++)
  {
    if (c[i].type == 'checkbox')
    {
      c[i].checked = false;
    }
  }
}

function GetInfo(model_no){

	createXMLHttp();
		
	xmlhttp.open("GET", "/functions/moreinfo.asp?model_no=" + model_no, true);
	xmlhttp.onreadystatechange = writeAvail;
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	xmlhttp.send(null);

	function writeAvail(){
		if (xmlhttp.readyState == 4){
			if (xmlhttp.status == 200){
				document.getElementById('moreinfo_' + model_no).innerHTML = xmlhttp.responseText;
				document.getElementById('moreinfo_' + model_no).className = '';
			}
		}
	}
}

function showwait(){
	document.getElementById('stores_span').innerHTML ='<br><center><font size=-2>Getting store list...</font></center>';
	document.getElementById('stores_span').className = '';
}

function showwait_prices(){
	document.getElementById('stores_span').innerHTML ='<br><center><font size=-2>Getting price data...</font></center>';
	document.getElementById('stores_span').className = '';
}

function SetPrice(old_search)
{

var q = location.href;
var pos_min = q.indexOf("min=");
var pos_max = q.indexOf("max=");
var min_price =0;
var max_price =0;

if (pos_min>0)
{
	var subq = q.substring(pos_min);
	var price = subq.split("&")[0];
	min_price =parseFloat(price.substring(4))
	
	if (isNaN(min_price))
	{
		min_price=0;
	}
}
if (pos_max>0)
{

	subq = q.substring(pos_max);
	price = subq.split("&")[0];
	max_price = parseFloat(price.substring(4))
	
	if (isNaN(max_price))
	{
		max_price=0;
	}
}
if (min_price>0 || max_price>0)
{
	var dest_url = q.replace("min=","minx=");
	dest_url = dest_url.replace("max=","maxx=");
	
	document.getElementById('stores_span').innerHTML ='<table width="100%"><tr style="height:60px"><td width="70%"><font size="-2">Show prices from &pound; <input style="font-size:1em" name="min" type=text value=' + min_price.toFixed(2) + ' size=5> to &pound; <input style="font-size:1em" name="max" type=text value=' + max_price.toFixed(2) + ' size=5></font></td><td align="center"><input type="submit" value="Refine results"></td><tr><td></td><td align="center"><font size="-2"><a href="' + dest_url + '"><u>Remove price filter</u></a></font></td></tr></table>';
	document.getElementById('stores_span').className = '';
}
else
{
	createXMLHttp();
	
	var dest_url = location.href.replace("search.asp","functions/getprices.asp");
	
	xmlhttp.open("GET", dest_url + "&old_search=" + old_search, true);
	xmlhttp.onreadystatechange = writeAvail;
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	xmlhttp.send(null);

}
	function writeAvail(){
		if (xmlhttp.readyState == 4){
			if (xmlhttp.status == 200){
				document.getElementById('stores_span').innerHTML = xmlhttp.responseText;
				document.getElementById('stores_span').className = '';
			}
		}
	}

}
function GetStores(ex){

	var dt = new Date(); 

	createXMLHttp();
		
	xmlhttp.open("GET", "/functions/getstores.asp?ex=" + ex + "&rnd=" + dt.getTime(), true);
	xmlhttp.onreadystatechange = writeAvail;
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	xmlhttp.send(null);

	function writeAvail(){
		if (xmlhttp.readyState == 4){
			if (xmlhttp.status == 200){
				document.getElementById('stores_span').innerHTML = xmlhttp.responseText;
				document.getElementById('stores_span').className = '';
			}
		}
	}
}

function GetStores_Big(ex){

	var dt = new Date();

	createXMLHttp();
		
	xmlhttp.open("GET", "/functions/getstores_big.asp?ex=" + ex + "&rnd=" + dt.getTime(), true);
	xmlhttp.onreadystatechange = writeAvail;
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	xmlhttp.send(null);

	function writeAvail(){
		if (xmlhttp.readyState == 4){
			if (xmlhttp.status == 200){
				document.getElementById('stores_span').innerHTML = xmlhttp.responseText;
				document.getElementById('stores_span').className = '';
			}
		}
	}
}

function addwatch(spanid){


createXMLHttp();
		
	xmlhttp.open("GET", "/watchadd.asp?add=" + spanid, true);
	xmlhttp.onreadystatechange = writeAvail;
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	xmlhttp.send(null);

	function writeAvail(){
		if (xmlhttp.readyState == 4){
			if (xmlhttp.status == 200){
				
				if (xmlhttp.responseText == "ok") {
					var newHTML = "<span style='font-size: 0.55em; color: rgb(142, 142, 224)'><br><img src='/images/tick_icon.gif' width=7 height=7 border=0>&nbsp;Added - <a style='color: rgb(142, 142, 224)' href='/watch.asp#products'>View watch list</a></span>";				
					document.getElementById('add_' + spanid).innerHTML = newHTML
				}
				else if (xmlhttp.responseText == "generic error") 
				{
					var newHTML = "<span style='font-size: 0.55em; color: rgb(142, 142, 224)'><br><img src='/images/cross_icon.gif' width=7 height=7 border=0>&nbsp;Error - <a style='color: rgb(142, 142, 224)' href='/watch.asp#products'>View watch list</a></span>";				
					document.getElementById('add_' + spanid).innerHTML = newHTML
					window.alert("Unfortunately an error has occured. An email has been sent to our technical team detailing the problem.");
				}
				else if (xmlhttp.responseText == "already") 
				{
					var newHTML = "<span style='font-size: 0.55em; color: rgb(142, 142, 224)'><br><img src='/images/tick_icon.gif'  width=7 height=7 border=0>&nbsp;Already watching - <a style='color: rgb(142, 142, 224)' href='/watch.asp#products'>View watch list</a></span>";				
					document.getElementById('add_' + spanid).innerHTML = newHTML
					window.alert("You are already watching this item");
				}
				else if (xmlhttp.responseText == "login") 
				{
					//user is no longer logged in, redirect to login page
					window.location = "/login.asp?watch=" + spanid
				}
				else if (xmlhttp.responseText == "out of stock") 
				{
					var newHTML = "<span style='font-size: 0.55em; color: rgb(142, 142, 224)'><br><img src='/images/cross_icon.gif' width=7 height=7  border=0>&nbsp;Out of stock - <a style='color: rgb(142, 142, 224)' href='/watch.asp#products'>View watch list</a></span>";				
					document.getElementById('add_' + spanid).innerHTML = newHTML
					window.alert("Unfortunately that product have chosen to watch is now out of stock so can not be watched");
				}
				
				
				
			}
		}
	}

	
	
}

function nominate(spanid){


createXMLHttp();
		
	xmlhttp.open("GET", "/nominate.asp?add=" + spanid, true);
	xmlhttp.onreadystatechange = writeAvail;
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded;");
	xmlhttp.send(null);

	function writeAvail(){
		if (xmlhttp.readyState == 4){
			if (xmlhttp.status == 200){
				
				if (xmlhttp.responseText == "generic error") 
				{
					var newHTML = "<span style='font-size: 0.55em; color: rgb(142, 142, 224)'><img src='/images/cross_icon.gif' width=7 height=7 border=0>&nbsp;Error</a></span>";				
					document.getElementById('nominate_' + spanid).innerHTML = newHTML
					window.alert("Unfortunately an error has occured. An email has been sent to our technical team detailing the problem.");
				}
				else if (xmlhttp.responseText == "already") 
				{
					var newHTML = "<span style='font-size: 0.55em; color: rgb(142, 142, 224)'><img src='/images/tick_icon.gif'  width=7 height=7 border=0>&nbsp;Already nominated</span>";				
					document.getElementById('nominate_' + spanid).innerHTML = newHTML
					window.alert("You have already nominated this item");
				}
				else if (xmlhttp.responseText == "too many") 
				{
					var newHTML = "<span style='font-size: 0.55em; color: rgb(142, 142, 224)'><img src='/images/cross_icon.gif'  width=7 height=7 border=0>&nbsp;Limit reached</span>";				
					document.getElementById('nominate_' + spanid).innerHTML = newHTML
					window.alert("You have already nominated your daily quota of 10 products");
				}
				else if (xmlhttp.responseText == "login") 
				{
					//user is no longer logged in, redirect to login page
					window.location = "/login.asp"
				}
				else
				{
					var newHTML = "<span style='font-size: 0.55em; color: rgb(142, 142, 224)'><img src='/images/tick_icon.gif' width=7 height=7 border=0>&nbsp;" + xmlhttp.responseText + "</span>";				
					document.getElementById('nominate_' + spanid).innerHTML = newHTML

				}
				
				
				
			}
		}
	}

	
	
}
