var over = new Array();
over['cal']="#000000";
over['dan']="#cc3333";
over['swe']="#ff9900";
over['sch']="#339966";
over['lig']="#006699";
over['vis']="#993399";

var off = new Array();
off['cal']="#dddddd";
off['dan']="#ff9999";
off['swe']="#ffcc99";
off['sch']="#99cc99";
off['lig']="#99cccc";
off['vis']="#cc99cc";

function hilite(theObject, direction){
	theElement = document.getElementById(theObject.id);
	var children=theElement.getElementsByTagName("A");
	if(theObject.id == selected){
		theElement.style.borderLeftColor = over[theObject.id];
	}else{
		if(direction =='out'){
			theElement.style.borderLeftColor = off[theObject.id];
			if(theObject.id !='cal'){
				children[0].style.color = "#999999";
				children[1].style.color = "#999999";
				children[2].style.color = "#999999";
				if(theObject.id !='vis' && theObject.id !='sch'){
					children[3].style.color = "#999999";
				}
			}
		}else if(direction == 'in'){
			theElement.style.borderLeftColor = over[theObject.id];
			if(theObject.id !='cal'){
				children[0].style.color = "#000000";
				children[1].style.color = "#666666";
				children[2].style.color = "#666666";
				if(theObject.id !='vis' && theObject.id !='sch'){
					children[3].style.color = "#666666";
				}
			}
		}
	}
}

function init(section){
	selected = section;
	for(index in over){
		theElement = document.getElementById(index);
		var children=theElement.getElementsByTagName("A");
		if(section == index){
			theElement.style.borderLeftColor = over[index];
			if(index !='cal'){
				children[0].style.color = "#000000";
				children[1].style.color = "#666666";
				children[2].style.color = "#666666";
				if(index != 'vis' && index !='sch'){
					children[3].style.color = "#666666";
				}
			}
		}else{
			theElement.style.borderLeftColor = off[index];
			if(index !='cal'){
				children[0].style.color = "#999999";
				children[1].style.color = "#999999";
				children[2].style.color = "#999999";
				if(index != 'vis' && index !='sch'){
					children[3].style.color = "#999999";
				}
			}
		}
	}
}

function adv_submit()
{
	document.adv.adv_search.value = document.qsearch.search.value;
	document.adv.submit();
}


function switch_details(which)
{
	var description = document.getElementById("itemDesc");
	var price = document.getElementById("itemPrice");
	var buy = document.getElementById("itemBuy");
	var desc = document.getElementById("toggle").getElementsByTagName("div")[0];
	var pricing = document.getElementById("toggle").getElementsByTagName("div")[1];
	var buynow = document.getElementById("toggle").getElementsByTagName("div")[2];
	var switchlink = document.getElementById( 'tabswitcher');
	if (navigator.appName == "Microsoft Internet Explorer"){
		var off = "-1px";
		var on = "-2px";
	}else{
		var off = "0px";
		var on = "-1px";
	}
	if(which == "desc"){
		description.style.display = "block";
		price.style.display = "none";
		//turn desc on
		desc.style.backgroundColor = "#FFFFFF";
		desc.style.border = "dashed 1px #666666";
		desc.style.borderBottom = "solid 1px #FFFFFF";
		desc.style.bottom = on;
		desc.getElementsByTagName("a")[0].style.color = "#000000";
		//turn pricing off
		pricing.style.backgroundColor = "#EEEEEE";
		pricing.style.border = "dashed 1px #CCCCCC";
		pricing.style.borderBottom = "none";
		pricing.style.bottom = off;
		pricing.getElementsByTagName("a")[0].style.color = "#00CC00";
		if( buynow )
		{
			buy.style.display = "none";
			//turn buynow off
			buynow.style.backgroundColor = "#EEEEEE";
			buynow.style.border = "dashed 1px #CCCCCC";
			buynow.style.borderBottom = "none";
			buynow.style.bottom = off;
			buynow.getElementsByTagName("a")[0].style.color = "#DD0000";		
			switchlink.innerHTML = '<a href="#" class="pricing" onclick="switch_details(\'price\');">Check Prices</a>';
		}

	}else if(which == "price"){	
		description.style.display = "none";
		price.style.display = "block";
		//turn desc off
		desc.style.backgroundColor = "#EEEEEE";
		desc.style.border = "dashed 1px #CCCCCC";
		desc.style.borderBottom = "none";
		desc.style.bottom = off;
		desc.getElementsByTagName("a")[0].style.color = "#666666";
		//turn pricing on
		pricing.style.backgroundColor = "#FFFFFF";
		pricing.style.border = "dashed 1px #666666";
		pricing.style.borderBottom = "solid 1px #FFFFFF";
		pricing.style.bottom = on;
		pricing.getElementsByTagName("a")[0].style.color = "#00DD00";
		if( buynow )
		{
			buy.style.display = "none";
			//turn buynow off
			buynow.style.backgroundColor = "#EEEEEE";
			buynow.style.border = "dashed 1px #CCCCCC";
			buynow.style.borderBottom = "none";
			buynow.style.bottom = off;
			buynow.getElementsByTagName("a")[0].style.color = "#DD0000";		
			switchlink.innerHTML = '<a href="#" class="buy" onclick="switch_details(\'options\');">View Options</a>';
		}
	}else {	
		description.style.display = "none";
		price.style.display = "none";
		//turn desc off
		desc.style.backgroundColor = "#EEEEEE";
		desc.style.border = "dashed 1px #CCCCCC";
		desc.style.borderBottom = "none";
		desc.style.bottom = off;
		desc.getElementsByTagName("a")[0].style.color = "#666666";
		//turn pricing off
		pricing.style.backgroundColor = "#EEEEEE";
		pricing.style.border = "dashed 1px #CCCCCC";
		pricing.style.borderBottom = "none";
		pricing.style.bottom = off;
		pricing.getElementsByTagName("a")[0].style.color = "#00CC00";
		if( buynow )
		{
			buy.style.display = "block";
			//turn buynow on
			buynow.style.backgroundColor = "#FFFFFF";
			buynow.style.border = "dashed 1px #666666";
			buynow.style.borderBottom = "solid 1px #FFFFFF";
			buynow.style.bottom = on;
			buynow.getElementsByTagName("a")[0].style.color = "#FF0000";		
			switchlink.innerHTML = '<a href="#" class="pricing" onclick="switch_details(\'price\');">Check Prices</a>';
		}
	}
}


function check_radio(ref){
	var check_exists = 0;
	var temp = document.getElementById('buyForm' + ref).getElementsByTagName("INPUT");;
	for (var e = 0; e < temp.length; e++){
		var el = temp[e];
		if(el.type == 'radio'){
			check_exists = 1;
			if(el.checked){
				document.getElementById('buyForm' + ref).submit();
				return 1;
			}
		}
	}
	if(check_exists){
		alert('You need to select an option to buy');
	}else{
		document.getElementById('buyForm' + ref).submit();
	}
}

function uncheck_sets(idx)
{
	var els = document.getElementById('buyForm').elements;
	
	for( var i=0; i < els.length;i++ )
	{
		el = els[i];
		if( (el.type == "radio") && (el.name != "pricing[grids][" + idx + "]") )
		{
			el.checked = false;
		}					
	}
}

function copy_card_address(obj)
{
	//copy the billing address into the delivery address on check
	var fields = new Array( "street", "add", "town", "county", "postcode" );
	for( var i = 0; i < fields.length;i++)
	{
		if( obj.checked )
		{
			document.getElementById( "delivery_address_" + fields[i] ).value = document.getElementById( "card_address_" + fields[i] ).value;
		}
		document.getElementById( "delivery_address_" + fields[i] ).disabled = (obj.checked == true);
	}
	
}

function clear_delivery()
{
	var fields = new Array( "street", "add", "town", "county", "postcode" );
	
	document.getElementById( "use_card_address" ).checked = false;
	for( var i = 0; i < fields.length;i++)
	{
		document.getElementById( "delivery_address_" + fields[i] ).value = "";
	}
}

function copytodelcheck( obj, targ )
{
	if( o = document.getElementById( targ ) )
	{
		if( document.getElementById( "use_card_address" ).checked )
		{
			o.value = obj.value;
		}
	}
}

function OpenCertDetails()
{
	thewindow = window.open('https://www.thawte.com/cgi/server/certdetails.exe?code=GBCALE7-1X', 'anew', config='height=400,width=450,toolbar=no,menubar=no,scrollbars=yes,resizable=no,location=no,directories=no,status=yes');
}

var newwindow = '';

function popitup(url,popwidth,popheight)
{
	if (!newwindow.closed && newwindow.location) {
		newwindow.location.href = url;
	}
	else {
		newwindow=window.open(url,'name','height=' + popheight + ',width=' + popwidth + ',menubar=no,toolbar=no,location=no,status=no');
		if (!newwindow.opener) newwindow.opener = self;
	}
	if (window.focus) {newwindow.focus()}
	return false;
}