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 getcountry(){
   if (navigator.browserLanguage.substr(0,2)=='en'){
   	var newHTML = "<img src='/images/uk_flag.gif'>Shopping from the UK? Visit <a href='http://www.offeroftheday.co.uk/'>Offeroftheday.co.uk</a><img src='/images/uk_flag.gif'>";				
   	document.write(newHTML);
   }
}

function createXMLHttp(){
	if (window.ActiveXObject){
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest){
		xmlhttp = new XMLHttpRequest();
	}
}

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 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");
				}
				
				
				
			}
		}
	}

	
	
}
