function toggleInfo(id){
getObj(id).className=((getObj(id).className=="infoHide") ? "infoShow" : "infoHide");
}

function toggleInfoAll(){
sections=new Array('about','purchase','payment','shipping','shipping2','cancel','cancel2','liability','tax','guarantee','returns','cookies','info','remittance','faq1','faq2','faq3','faq4','faq5','faq6','faq7','faq8','faq9','faq10');
if (getObj("infoAll").innerHTML=="[Show All]"){
	for (i=0;i<sections.length;i++){
		getObj(sections[i]).className="infoShow";
		}
	getObj("infoAll").innerHTML="[Hide All]";
	}
else{
	for (i=0;i<sections.length;i++){
		getObj(sections[i]).className="infoHide";
		}
	getObj("infoAll").innerHTML="[Show All]";
	}
}

// CHECK USER INPUT IS OK
// IF YES, GRAB PRODUCT INFO AND PASS TO SEND PAGE
function checkTell(el){
if (getObj("fName_"+el).value==""){
	getObj("tellMsg_"+el).innerHTML="We need your first name to show the recipient who you are.";
	}
else if (getObj("sName_"+el).value==""){
	getObj("tellMsg_"+el).innerHTML="We need your surname to show the recipient who you are.";
	}
else if (getObj("email1_"+el).value==""){
	getObj("tellMsg_"+el).innerHTML="We need your email to show the recipient who you are.";
	}
else if (!emailValid(getObj("email1_"+el).value)){
	getObj("tellMsg_"+el).innerHTML="Your email is not a valid adddress.";
	}
else if (getObj("email2_"+el).value==""){
	getObj("tellMsg_"+el).innerHTML="We need your friend's address.";
	}
else if (!emailValid(getObj("email2_"+el).value)){
	getObj("tellMsg_"+el).innerHTML="Your friend's email is not a valid adddress.";
	}
else{
	document.tellFriend.fName.value=getObj("fName_"+el).value;
	document.tellFriend.sName.value=getObj("sName_"+el).value;
	document.tellFriend.email1.value=getObj("email1_"+el).value;
	document.tellFriend.email2.value=getObj("email2_"+el).value;
	document.tellFriend.ref.value=el;
	if (getObj("optin_"+el).checked){
		document.tellFriend.optin.value="true";
		}
	else{
		document.tellFriend.optin.value="false";
		}
	document.tellFriend.title.value=getObj("title_"+el).innerHTML;
	document.tellFriend.desc.value=getObj("desc_"+el).innerHTML;

	// USE REGEXP TO GLEAN IMAGE URL FROM SURROUNDING ACTINIC TEMPLATE TEXT
	str=getObj("img_"+el).innerHTML;
	var found = str.match(/src=\"(.*?)\.jpg/gi);
	temp=found[0].substring(5,found[0].length);
	temp=temp.substring(temp.lastIndexOf("/")+1,temp.length);
	document.tellFriend.img.value="http://www.diskdepot.co.uk/acatalog/"+temp;
	
	// USE REGEXP TO GLEAN ACTUAL PRICE FROM SURROUNDING ACTINIC TEMPLATE TEXT
	str=getObj("price_"+el).innerHTML;
	found = str.match(/(£(\d+)\.(\d{2}))/gi);
	document.tellFriend.price.value=found[0];
	window.open("","_tellFriend","height=400,width=400");
	document.tellFriend.submit();
	}
}

function emailValid(email){
var str = email.toLowerCase();
var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
if (!str.match(re)){
  return false;
  }
else{
  return true;
  }
}

function getObj(el){
if (typeof el=="object"){
	return el
	}
if(document.layers){
	return document.layers[el]
	}
if(document.getElementById){
	return document.getElementById(el)
	}
if(document.all){
	return document.all[el]
	}
if(document[el]){
	return document[el]
	}
return false;
}

// RETURNS COORDINATES OF ELEMENT WITHIN WINDOW
function getCoord(el){
if (getObj(el)){
	el=getObj(el);
	var coord={X:0,Y:0};
	if (el.style.position){
		coord.X=parseInt(getCSSValue(el,"left").replace("px",""));
		coord.Y=parseInt(getCSSValue(el,"top").replace("px",""));
		}
	else{
		while (el){
			coord.X+=el.offsetLeft;
			coord.Y+=el.offsetTop;
			el=el.offsetParent;
			}
		if (navigator.userAgent.indexOf("mac")!=-1 && typeof document.body.leftMargin!="undefined"){
			coord.X+=document.body.leftMargin;
			coord.Y+=document.body.topMargin;
			}
		}
	return coord;
	}
return "";
}

// RETURNS COMPUTED VALUE FOR CSS PROPERTY
function getCSSValue(el,prop){
if (getObj(el)){
	el=getObj(el);
	prop=prop.toLowerCase();
	if (el.currentStyle){
		for (i=prop.length;i>0;i--){
			if (prop.substring(i-1,i)=="-"){
				prop=prop.substring(0,i-1)+prop.substring(i,i+1).toUpperCase()+prop.substring(i+1,prop.length);
				}
			}
		return el.currentStyle[prop];
		}
	else if (window.getComputedStyle){
		comp = window.getComputedStyle(el,"")
		return comp.getPropertyValue(prop);
		}
	}
return "";
}

function selectThis(el){
type=el.substring(0,el.lastIndexOf("_"));
ref=el.substring(el.lastIndexOf("_")+1,el.length);
if (type=="info"){
	getObj("info_"+ref).className="bttnDown";
	getObj("tell_"+ref).className="bttnUp";
	getObj("hide_"+ref).style.display="none";
	getObj("telltext_"+ref).style.display="none";
	}
if (type=="tell"){
	getObj("info_"+ref).className="bttnUp";
	getObj("tell_"+ref).className="bttnDown";
	getObj("hide_"+ref).style.top=getCoord("infotext_"+ref).Y+"px";
	getObj("hide_"+ref).style.left=(getCoord("infotext_"+ref).X-50)+"px";
	getObj("hide_"+ref).style.display="block";
	getObj("telltext_"+ref).style.top=getCoord("infotext_"+ref).Y+"px";
	getObj("telltext_"+ref).style.left=getCoord("infotext_"+ref).X+"px";
	getObj("telltext_"+ref).style.display="inline";
	}
}


function checkCoupon(){
if (getObj("COUPONCODE").value != ""){
	for (i=0;i<codes.length;i++){
		if (codes[i].toLowerCase()==(getObj("COUPONCODE").value).toLowerCase()){
			alert("That coupon code has already been used. Please enter another code.");
			getObj("COUPONCODE").value="";
			return false;
			}
		}
	}
return true;
}

function getScreenDim(){
var dim={X:0,Y:0};
if(typeof(window.innerWidth) == 'number'){
	dim.X=window.innerWidth;
	dim.Y=window.innerHeight;
	return dim;
  	}
else if(document.documentElement &&(document.documentElement.clientWidth || document.documentElement.clientHeight)){
  	dim.X=document.documentElement.clientWidth;
	dim.Y=document.documentElement.clientHeight;
	return dim;
 	}
else if(document.body && (document.body.clientWidth || document.body.clientHeight)){
  	dim.X=document.body.clientWidth;
	dim.Y=document.body.clientHeight;
	return dim;
  	}
return "";
}
