// JavaScript Document

function bundleCheck() {
	testCheck = true;
	var oopshtml='<div id="oops_sign"><span class="show">Oops an error has occurred!</span></div><p id="oops_text">You failed to select an option from at least 1 Bundle Group, please review your selection!</p><button id="oops_continue_button" onclick="javascript:hideoops();"></button>';
	for (var i = 0, j = arguments.length; i < j; i++){
		var InpName = 'bgroup'+arguments[i];
		var InpOk = false;
		for (var k = 0, p = document.getElementsByName(InpName).length; k < p; k++){
			if (InpOk === false && document.getElementsByName(InpName)[k].checked === true) {
				InpOk = true;
			}
		}
		if (testCheck === true && InpOk === false) {
			testCheck=false;
		}
	}
	if (testCheck === false) {
		document.getElementById('oops').innerHTML=oopshtml;
		document.getElementById('oops').style.display='block';
		return false;
	} else {return true;}
}
function showmoretext(hideElement,showElement,displaystyle) {
	document.getElementById(showElement).style.display=displaystyle;
	document.getElementById(hideElement).style.display='none'; 
}
function hidemoretext(showElement,hideElement,displaystyle) {
	document.getElementById(showElement).style.display=displaystyle;
	document.getElementById(hideElement).style.display='none'; 
}
function SwapMainImage(ImageId,ImageSrc) {
	var newimagesrc='url(core/images/products/full/'+ImageSrc+')';
	document.getElementById(ImageId).style.backgroundImage=newimagesrc;
}
function showblock(hideElement,showElement) {
	document.getElementById(showElement).style.display='block';
	document.getElementById(hideElement).style.display='none'; 
}
function checkQuantity() {
	var xform=document.getElementById('stockform');
	var xlist=xform.getElementsByTagName('select');
	var loopcount=(xlist.length-1);
	var QtyCount=0;
	var oopshtml='<div id="oops_sign"><span class="show">Oops an error has occurred!</span></div><p id="oops_text">You didn&#0039;t specify the quantity of items you wish to purchase!</p><button id="oops_continue_button" onclick="javascript:hideoops();"></button>';
	for (i=0;i<=loopcount;i++) 
	{
		var y=xlist[i].selectedIndex;
		QtyCount=(QtyCount+Math.round(xlist[i].getElementsByTagName('option')[y].value));
	}
	if (QtyCount<=0) {
		document.getElementById('oops').innerHTML=oopshtml;
		document.getElementById('oops').style.display='block';
		return false;
	}
	else {return true;}
}

function checkSearch(searchinput) {
	var searchbox=document.getElementById(searchinput).value;
	var oopshtml='<div id="oops_sign"><span class="show">Oops an error has occurred!</span></div><p id="oops_text">Searches require a search key word/phrase/code with a minimum of 3 characters!</p><button id="oops_continue_button" onclick="javascript:hideoops();"></button>';
	if (searchbox.length<3||searchbox=='Enter Keyword or Code'||searchbox=='Enter Keyword or Phrase') {
		document.getElementById('oops').innerHTML=oopshtml;
		document.getElementById('oops').style.display='block';
		return false;
	}
	else {return true;}
}


function hideoops() {document.getElementById('oops').style.display='none';}
function checkEmail(Email) {
	var ndxAt = 0;
	var ndxDot = 0;
	var ndxwww = 0;
	var ndxhttp = 0;
	var EmailLength = 0;
	
	ndxAt  = Email.indexOf("@");
	ndxDot = Email.indexOf(".");
	ndxDot2 = Email.lastIndexOf(".");
	ndxwww = Email.lastIndexOf("www.");
	ndxhttp = Email.lastIndexOf("http://");
	EmailLength = (Email.length-1);
	
	if (EmailLength < 0) {return (true);}
	if ( (ndxDot < 0) || (ndxAt < 0) ) {return (true);}
	if (ndxwww === 0) {return (true);}
	if (ndxDot2 < 0) {return (true);}
	if (ndxhttp === 0) {return (true);}
	if ( (ndxDot2 - 2) <= ndxAt) {return (true);}
	if (ndxDot2 >= EmailLength) {return (true);} 
	return (false);
}
function checkSignup() {
	var signup=document.getElementById('newslettersignup').value;
	var oopshtml='<div id="oops_sign"><span class="show">Oops an error has occurred!</span></div><p id="oops_text">You MUST enter a valid email address!</p><button id="oops_continue_button" onclick="javascript:hideoops();"></button>';
	if (signup=='Email address'||checkEmail(signup)) {
		document.getElementById('oops').innerHTML=oopshtml;
		document.getElementById('oops').style.display='block';
		return false;
	}
	else {return true;}
}
function checkSendPassword() {
	var email=document.getElementById('lostemail').value;
	var oopshtml='<div id="oops_sign"><span class="show">Oops an error has occurred!</span></div><p id="oops_text">You didn&#0039;t enter a valid email address!</p><button id="oops_continue_button" onclick="javascript:hideoops();"></button>';
	if (email=='Email address'||checkEmail(email)) {
		document.getElementById('oops').innerHTML=oopshtml;
		document.getElementById('oops').style.display='block';
		return false;
	}
	else {return true;}
}
function checkSignin() {
	var email=document.getElementById('signinemail').value;
	var password=document.getElementById('signinpassword').value;
	var oopshtml='<div id="oops_sign"><span class="show">Oops an error has occurred!</span></div><p id="oops_text">You didn&#0039;t enter a valid email address!</p><button id="oops_continue_button" onclick="javascript:hideoops();"></button>';
	var oopshtml2='<div id="oops_sign"><span class="show">Oops an error has occurred!</span></div><p id="oops_text">You didn&#0039;t enter a valid password!</p><button id="oops_continue_button" onclick="javascript:hideoops();"></button>';
	if (email=='Email address'||checkEmail(email)) {
		document.getElementById('oops').innerHTML=oopshtml;
		document.getElementById('oops').style.display='block';
		return false;
	}
	else {
		if (password.length<5||password.length>20) {
		document.getElementById('oops').innerHTML=oopshtml2;
		document.getElementById('oops').style.display='block';
		return false;
		}
		else {return true;}
	}
}
function deleteAddress(AddressId) {
	var oopshtml='<div id="oops_sure"><span class="show">Confirmation Required!</span></div><p id="oops_text">Are you sure you wish to DELETE this Address, this action CANNOT be undone!</p><form method="post" name="deleteaddressform"><button type="submit" id="oops_button"><span class="show">Confirm</span></button><br /><a id="oopssurecancel" href="javascript:hideoops();"><span class="show">Cancel</span></a><input type="hidden" name="action" value="3"><input type="hidden" name="address" value="'+AddressId+'"></form>';
	document.getElementById('oops').innerHTML=oopshtml;
	document.getElementById('oops').style.display='block';
}

function deleteAddress2(AddressId,FormLocation) {
	var oopshtml='<div id="oops_sure"><span class="show">Confirmation Required!</span></div><p id="oops_text">Are you sure you wish to DELETE this Address, this action CANNOT be undone!</p><form method="post" name="deleteaddressform" action="'+FormLocation+'"><button type="submit" id="oops_button"><span class="show">Confirm</span></button><br /><a id="oopssurecancel" href="javascript:hideoops();"><span class="show">Cancel</span></a><input type="hidden" name="action" value="3"><input type="hidden" name="address" value="'+AddressId+'"></form>';
	document.getElementById('oops').innerHTML=oopshtml;
	document.getElementById('oops').style.display='block';
}

function deleteCard(PaymentId) {
	var oopshtml='<div id="oops_sure"><span class="show">Confirmation Required!</span></div><p id="oops_text">Are you sure you wish to DELETE this Credit/Debit Card, this action CANNOT be undone!</p><form method="post" name="deletecardform"><button type="submit" id="oops_button"><span class="show">Confirm</span></button><br /><a id="oopssurecancel" href="javascript:hideoops();"><span class="show">Cancel</span></a><input type="hidden" name="action" value="3"><input type="hidden" name="card" value="'+PaymentId+'"></form>';
	document.getElementById('oops').innerHTML=oopshtml;
	document.getElementById('oops').style.display='block';
}

function deleteCard2(PaymentId,FormLocation) {
	var oopshtml='<div id="oops_sure"><span class="show">Confirmation Required!</span></div><p id="oops_text">Are you sure you wish to DELETE this Credit/Debit Card, this action CANNOT be undone!</p><form method="post" name="deletecardform" action="'+FormLocation+'"><button type="submit" id="oops_button"><span class="show">Confirm</span></button><br /><a id="oopssurecancel" href="javascript:hideoops();"><span class="show">Cancel</span></a><input type="hidden" name="action" value="3"><input type="hidden" name="card" value="'+PaymentId+'"></form>';
	document.getElementById('oops').innerHTML=oopshtml;
	document.getElementById('oops').style.display='block';
}

function swapBorder(ElementId,BorderColour) {document.getElementById(ElementId).style.borderColor=BorderColour;}

function checkCVV2(){
	var x=document.getElementById('security');
	var oopshtml='<div id="oops_sign"><span class="show">Oops an error has occurred!</span></div><p id="oops_text">You didn&#0039;t enter a valid Card Security Code (CVV2) for your selected Credit/Debit Card!</p><button id="oops_continue_button" onclick="javascript:hideoops();"></button>';
	var anum=/(^\d+$)|(^\d+\d+$)/;
	if (x.value.length!=3||!anum.test(x.value)) { 
		document.getElementById('oops').innerHTML=oopshtml;
		document.getElementById('oops').style.display='block';
		x.style.border='1px solid #ff0000';
		return (false);
	}
	else {return (true);}
}

function finalCheckout(phoneCheck,mobileCheck,cvv2Check){
	var checkResult=true;
	var oopshtml='';
	if (phoneCheck==1&&mobileCheck===0&&checkResult===true) {
		var chkNum=document.getElementById('contact_number');
		var chkPref=document.getElementById('num_not_reqd');
		var anum=/^(((\+44\s?\d{4}|\(?0\d{4}\)?)\s?\d{3}\s?\d{3})|((\+44\s?\d{3}|\(?0\d{3}\)?)\s?\d{3}\s?\d{4})|((\+44\s?\d{2}|\(?0\d{2}\)?)\s?\d{4}\s?\d{4}))(\s?\#(\d{4}|\d{3}))?$/;
		if (chkNum.value.length<10||chkNum.value.length>18||!anum.test(chkNum.value)) { 
			if (chkPref.checked===false) {
				oopshtml='<div id="oops_sign"><span class="show">Oops an error has occurred!</span></div><p id="oops_text">You failed to enter a valid contact Phone Number. Please amend number or please select option to indicate you would prefer not to supply one!</p><button id="oops_continue_button" onclick="javascript:hideoops();"></button>';
				checkResult=false;
				highlightField=chkNum;
			} else {chkNum.style.border='1px solid #009900';}
		} else {chkNum.style.border='1px solid #009900';}
	}
	
	if (mobileCheck==1&&checkResult===true) {
		var chkNumA=document.getElementById('contact_number');
		var chkPrefA=document.getElementById('num_not_reqd');
		var anumA=/^(\+44\s?7\d{3}|\(?07\d{3}\)?)\s?\d{3}\s?\d{3}$/;
		if (chkNumA.value.length<10||chkNumA.value.length>18||!anumA.test(chkNumA.value)) { 
			if (chkPrefA.checked===false) {
				oopshtml='<div id="oops_sign"><span class="show">Oops an error has occurred!</span></div><p id="oops_text">You failed to enter a valid contact Mobile Phone Number. Please amend number or please select option to indicate you would prefer not to supply one!</p><button id="oops_continue_button" onclick="javascript:hideoops();"></button>';
				checkResult=false;
				highlightField=chkNumA;
			} else {chkNumA.style.border='1px solid #009900';}
		} else {chkNumA.style.border='1px solid #009900';}
	}
	
	if (cvv2Check==1&&checkResult===true) {
		var x=document.getElementById('security');
		var anumB=/(^\d+$)|(^\d+\d+$)/;
		if (x.value.length!=3||!anumB.test(x.value)) { 
			oopshtml='<div id="oops_sign"><span class="show">Oops an error has occurred!</span></div><p id="oops_text">You failed to enter a valid Card Security Code (CVV2) for your selected Credit/Debit Card!</p><button id="oops_continue_button" onclick="javascript:hideoops();"></button>';
			checkResult=false;
			highlightField=x;
		} else {x.style.border='1px solid #009900';}
	}
	
	if (checkResult===false) {
		document.getElementById('oops').innerHTML=oopshtml;
		document.getElementById('oops').style.display='block';
		highlightField.style.border='1px solid #ff0000';
		return (false);
	} else {return (true);}
}
function showAdvice() {
	var lastAdvice = document.getElementById('lastAdvice');
	var showAdviceField = document.getElementById('contactsubject');
	var y = showAdviceField.selectedIndex;
	showAdviceNow = showAdviceField.getElementsByTagName('option')[y].value;
	if (showAdviceNow==999999) {
		document.getElementById('othersubjectlabel').style.display='inline';
		document.getElementById('othersubject').style.display='inline';
	} else {
		document.getElementById('othersubjectlabel').style.display='none';
		document.getElementById('othersubject').style.display='none';
		document.getElementById('othersubject').style.value='';
	}
	
	var warninglistdiv = document.getElementById('warninglist');
	if (warninglistdiv.getElementsByTagName('div') !== null) {
		
		var warninglistgroup=warninglistdiv.getElementsByTagName('div');
		var loopcount=(warninglistgroup.length-1);
		
		for (i=0;i<=loopcount;i++) 
		{
			if (warninglistgroup[i].id != 'catwarning'+showAdviceNow) {
				warninglistgroup[i].className='helpcatwarninghide';
			} else {warninglistgroup[i].className='helpcatwarning';}
		}
	}
	
	if (showAdviceNow==999999) {showAdviceNow=0;}
	
	var helpcatlistul = document.getElementById('helpcatlist');
	if (helpcatlistul.getElementsByTagName('li') !== null) {
		var helpcatlistgroup=helpcatlistul.getElementsByTagName('li');
		var loopcount2=(helpcatlistgroup.length-1);
		for (i=0;i<=loopcount2;i++) 
		{
			if (helpcatlistgroup[i].id != 'helpcat'+showAdviceNow) {
				helpcatlistgroup[i].className='help_list_hide';
			} else {helpcatlistgroup[i].className='help_list';}
		}
	}
	lastAdvice.value=showAdviceNow;
}

function forceContactHelp() {
	var lastAdvice = document.getElementById('lastAdvice').value;
	var showAdviceNow=0;
	document.getElementById('helpcat'+lastAdvice).className='help_list_hide';
	document.getElementById('helpcat'+showAdviceNow).className='help_list';
	document.getElementById('contactsubject').selectedIndex=0;
	if (document.getElementById('catwarning'+lastAdvice) !== null) {
		document.getElementById('catwarning'+lastAdvice).className='helpcatwarninghide';
	}
	lastAdvice=showAdviceNow;
}

function checkContact() {
	var oopserror='';
	var contactfirstname='';
	var contactlastname='';
	var contactsubject='';
	var contactemail='';
	var contactmessage='';
	if (document.getElementById('needinfo') !== null) {
		contactfirstname=document.getElementById('contactfirstname').value;
		contactlastname=document.getElementById('contactlastname').value;
		contactsubject=document.getElementById('contactsubject').selectedIndex;
		contactemail=document.getElementById('contactemail').value;
		contactmessage=document.getElementById('contactmessage').value;
		if (contactfirstname.length===0) {
			oopserror='You didn&#0039;t enter your First Name';
		} else {
			if (contactlastname.length===0) {
				oopserror='You didn&#0039;t enter your Last Name';
			} else {
				if (contactsubject===0) {
					oopserror='You didn&#0039;t select your Message Subject';
				} else {
					if (contactemail.length===0) {
						oopserror='You didn&#0039;t enter your Email Address';
					} else {
						if (contactmessage.length===0) {
							oopserror='You didn&#0039;t enter your Message/Question/Comment';
						}
					}
				}
			}
		}
	}
	else {
		contactsubject=document.getElementById('contactsubject').selectedIndex;
		contactmessage=document.getElementById('contactmessage').value;
		if (contactsubject===0) {
			oopserror='You didn&#0039;t select your Message Subject';
		} else {
			if (contactmessage.length===0) {
				oopserror='You didn&#0039;t enter your Message/Question/Comment';
			}
		}
	}
	if (oopserror.length>0) {
		var oopshtml='<div id="oops_sign"><span class="show">Oops an error has occurred!</span></div><p id="oops_text">'+oopserror+'</p><button id="oops_continue_button" onclick="javascript:hideoops();"></button>';
		document.getElementById('oops').innerHTML=oopshtml;
		document.getElementById('oops').style.display='block';
		return (false);
	} else {return (true);}
}

function warnOnDemand() {
	var oopshtml='<div id="oops_ondemand"><span class="show">Oops an error has occurred!</span></div><p id="oops_text"><b>PLEASE NOTE</b> This item can only be purchased on an <b>On Demand</b> basis. This means that when you place your order we will order it directly from the supplier. As a result there will be a <b>3-14 day delay</b> before the item is dispatched, no matter which shipping option you later select.</p><button id="oops_continue_button" onclick="javascript:hideoops();"></button>';
	document.getElementById('oops').innerHTML=oopshtml;
	document.getElementById('oops').style.display='block';
}

function warnOnDemandChk(fieldId,actualStock,basketquantity,ondemand)  {
	var selectedQty = Number(document.getElementById(fieldId).value);
	var oopshtml='<div id="oops_ondemand"><span class="show">Oops an error has occurred!</span></div><p id="oops_text"><b>There are only '+actualStock+' of this item in stock!</b><br />This item can only be purchased in the quantity you selected on an <b>On Demand</b> basis. This means that when you place your order we will order it directly from the supplier. There will be a <b>3-14 day delay</b> before the item is dispatched.</p><button id="oops_continue_button" onclick="javascript:hideoops();"></button>';
	if ((selectedQty+basketquantity)>actualStock && ondemand>0) {
	document.getElementById('oops').innerHTML=oopshtml;
	document.getElementById('oops').style.display='block';
	}
}

function onDemandChkSubmit(fieldId,formId,actualStock)  {
	var oopshtml='<div id="oops_ondemand"><span class="show">Oops an error has occurred!</span></div><p id="oops_text"><b>There are only '+actualStock+' of this item in stock!</b><br />This item can only be purchased in the quantity you selected on an <b>On Demand</b> basis. This means that when you place your order we will order it directly from the supplier. There will be a <b>3-14 day delay</b> before the item is dispatched.</p><button id="oops_continue_button" onclick="javascript:hideoopsSubmit();"></button>';
	var selectedQty = Number(document.getElementById(fieldId).value);
	if (selectedQty>actualStock) {
	document.getElementById('oops').innerHTML=oopshtml;
	document.getElementById('oops').style.display='block';
	} else {document.getElementById(formId).submit();}
}

function hideoopsSubmit() {
	document.getElementById('oops').style.display='none';
	document.getElementById('basketsummary').submit();
}

function swaptabs(tabid) {
	var tabgroup = document.getElementById('guides_bar').getElementsByTagName('a');
	var loopcount=(tabgroup.length-1);
	for (i=0;i<=loopcount;i++) 
	{
		if (tabgroup[i].id != tabid) {
			tabgroup[i].style.backgroundImage='url(custom/images/backgrounds/guides_tab_2_background.jpg)';
			tabgroup[i].style.color='#000000';
		} else {
			tabgroup[i].style.backgroundImage='url(custom/images/backgrounds/guides_tab_1_background.jpg)';
			tabgroup[i].style.color='#ffffff';
		}
	}
}

function swaptabs2(tabid) {
	var tabgroup = document.getElementById('guides_bar').getElementsByTagName('a');
	var guidesgroup = document.getElementById('guides_group').getElementsByTagName('div');
	var loopcount=(tabgroup.length-1);
	for (i=0;i<=loopcount;i++) 
	{
		if (tabgroup[i].id != tabid) {
			tabgroup[i].style.backgroundPosition='top';
			guidesgroup[i].style.display='none';
		} else {
			tabgroup[i].style.backgroundPosition='bottom';
			guidesgroup[i].style.display='block';
		}
	}
}

function sendtoguide(guidelink,tabid) {
	swaptabs(tabid);
	document.getElementById('guides_frame').src=guidelink;
}

function checkReview() {
	var reviewtext=document.getElementById('review_text');
	var oopshtml='';
	if (reviewtext.value.length===0) {
		oopshtml='<div id="oops_sign"><span class="show">Oops an error has occurred!</span></div><p id="oops_text">You didn&#0039;t enter Your Review comments for this product.</p><button id="oops_continue_button" onclick="javascript:hideoops();"></button>';
		document.getElementById('oops').innerHTML=oopshtml;
		document.getElementById('oops').style.display='block';
		return (false);
	}
	else {
		if (reviewtext.value.length>2000) {
			oopshtml='<div id="oops_sign"><span class="show">Oops an error has occurred!</span></div><p id="oops_text">Sorry, Review comments are limited to 2000 characters, your review is currently '+reviewtext.value.length+' characters long.</p><button id="oops_continue_button" onclick="javascript:hideoops();"></button>';
			document.getElementById('oops').innerHTML=oopshtml;
			document.getElementById('oops').style.display='block';
			return (false);
		} else {return (true);}
	}
}

function checkFeedback() {
	var feedbacktext=document.getElementById('feedback_text');
	var oopshtml='';
	if (feedbacktext.value.length===0) {
		oopshtml='<div id="oops_sign"><span class="show">Oops an error has occurred!</span></div><p id="oops_text">You didn&#0039;t enter Your feedback comments.</p><button id="oops_continue_button" onclick="javascript:hideoops();"></button>';
		document.getElementById('oops').innerHTML=oopshtml;
		document.getElementById('oops').style.display='block';
		return (false);
	}
	else {
		if (reviewtext.value.length>2000) {
			oopshtml='<div id="oops_sign"><span class="show">Oops an error has occurred!</span></div><p id="oops_text">Sorry, feedback comments are limited to 2000 characters, your feedback is currently '+feedbacktext.value.length+' characters long.</p><button id="oops_continue_button" onclick="javascript:hideoops();"></button>';
			document.getElementById('oops').innerHTML=oopshtml;
			document.getElementById('oops').style.display='block';
			return (false);
		} else {return (true);}
	}
}

function deleteOption(Id,recordType,FormLocation) {
	var oopshtml='<div id="oops_sure"><span class="show">Confirmation Required!</span></div><p id="oops_text">Are you sure you wish to DELETE this '+recordType+', this action CANNOT be undone!</p><form method="post" name="deleteaddressform" action="'+FormLocation+'"><button type="submit" id="oops_button"><span class="show">Confirm</span></button><br /><a id="oopssurecancel" href="javascript:hideoops();"><span class="show">Cancel</span></a><input type="hidden" name="action" value="3"><input type="hidden" name="'+recordType+'" value="'+Id+'"></form>';
	document.getElementById('oops').innerHTML=oopshtml;
	document.getElementById('oops').style.display='block';
}

function stockWatch() {
	var oopshtml='<div id="oops_stockwatch"><span class="show">Stock Watch!</span></div><p id="oops_text">If you want to know the minute this item becomes available, our <b>Stock Watch</b> facility can do all the hard work for you. Set a Stock Watch on this item and our system will automatically send you an email as soon as it comes into stock. To set a Stock Watch on this item simply click this button.</p>';
	document.getElementById('oops').innerHTML=oopshtml;
	document.getElementById('oops').style.display='block';
}
function hideStockWatched(){document.getElementById('stockwatched').style.display='none';}
function delayHideStockWatched(){setTimeout("hideStockWatched()",3000);}
function resetJumpTo(){ 
	if (document.getElementById('jumpto') !== null) {document.getElementById('jumpto').selectedIndex=0;}
	document.getElementById('pageactions').submit();
}

function mustSignIn(baselink) {
	var oopshtml='<div id="oops_sign"><span class="show">Sign In Required!</span></div><p id="oops_text">To use this facility you must first be Signed In to your Account. To Sign in to your account or Create a New Account now please click Sign In button below, otherwise click continue.</p><a href="/login'+baselink+'" id="signinlink"><span class="show">Sign In</span></a><br /><a id="oopssurecancel" href="javascript:hideoops();"><span class="show">Cancel</span></a>';
	document.getElementById('oops').innerHTML=oopshtml;
	document.getElementById('oops').style.display='block';
}

function checkAction() {
	var listoptions = document.getElementById('listoptions');
	var itemaction = document.getElementById('itemaction');
	var y = itemaction.selectedIndex;
	var listoptionsvalue = itemaction.getElementsByTagName('option')[y].value;
	if (listoptionsvalue==3) {
		listoptions.disabled=true;
	} else {listoptions.disabled=false;}
}

function ShowGiftOptions(id1,id2) {
	document.getElementById(id1).style.display='table-row';
	document.getElementById(id2).style.display='none';
}

function showTerms(TermSource,TermsId) {
	var oopshtml='';
	if (TermSource==1) {
		oopshtml='<div id="termsheader"><span id="promodetails">Promotion Details</span><a href="javascript:hideTerms();"><span class="show">Close Terms</span></a></div><iframe id="promotermsframe" frameborder="0" scrolling="auto" src="promoterms.asp?promotype=1&promoId='+TermsId+'"></iframe>';
	} else {
		oopshtml='<div id="termsheader"><span id="promodetails">Promotion Details</span><a href="javascript:hideTerms();"><span class="show">Close Terms</span></a></div><iframe id="promotermsframe" frameborder="0" scrolling="auto" src="promoterms.asp?promotype=2&promoId='+TermsId+'"></iframe>';
	}
	document.getElementById('oops').style.width='40%';
	document.getElementById('oops').style.height='60%';
	document.getElementById('oops').style.top='20%';
	document.getElementById('oops').style.left='30%';
	document.getElementById('oops').innerHTML=oopshtml;
	document.getElementById('oops').style.display='block';
}

function hideTerms() {document.getElementById('oops').style.display='none';}

function showbrands() {
	document.getElementById('brandswrap').style.top='0px';
	document.getElementById('infoouterwrap').style.top='-477px';
}

function hidebrands() {document.getElementById('brandswrap').style.top='-648px';}

function showinfo() {
	document.getElementById('infoouterwrap').style.top='0px';
	document.getElementById('brandswrap').style.top='-648px';
}

function hideinfo() {document.getElementById('infoouterwrap').style.top='-477px';}
function tooltipshow(tooltipid,ytop,xright) {
	document.getElementById(tooltipid).style.top=ytop;
	document.getElementById(tooltipid).style.right=xright;
	document.getElementById(tooltipid).style.display='inline';	
}
function tooltiphide(tooltipid) {
	document.getElementById(tooltipid).style.display='none';
}
function ClickQuantity(LineId) {
	var SelectBox=document.getElementById(LineId);
	if ((SelectBox.length-1)>=(SelectBox.selectedIndex+1)) {
		SelectBox.selectedIndex=(SelectBox.selectedIndex+1);
	}
}

function HideElement(ElementId) {document.getElementById(ElementId).style.display='none';}
function ShowElement(ElementId) {document.getElementById(ElementId).style.display='block';}

function checkCompForm() {
	var AnswerA = document.getElementById('companswerA');
	var AnswerB = document.getElementById('companswerB');
	var AnswerC = document.getElementById('companswerC');
	var AcceptTerms = document.getElementById('acceptterms');
	var oopshtml='';
	if (AnswerA.checked===false&&AnswerB.checked===false&&AnswerC.checked===false) {
		oopshtml='<div id="oops_sign"><span class="show">Oops an error has occurred!</span></div><p id="oops_text">You failed to select an answer!</p><button id="oops_continue_button" onclick="javascript:hideoops();"></button>';
	}
	if (AcceptTerms.checked===false) {
		oopshtml='<div id="oops_sign"><span class="show">Oops an error has occurred!</span></div><p id="oops_text">You must tick the box to indicate that you have read and agree with to the terms and conditions!</p><button id="oops_continue_button" onclick="javascript:hideoops();"></button>';
	}
	if (oopshtml.length>0) {
		document.getElementById('oops').innerHTML=oopshtml;
		document.getElementById('oops').style.display='block';
		return false;
	} else {return true;}
}

function chkBrochure() {
	
	var itemgroup = document.getElementById('select_brochure_depts').getElementsByTagName('input');
	var loopcount=(itemgroup.length-1);
	var selecteditemcount=0;
	var oopshtml='<div id="oops_sign"><span class="show">Oops an error has occurred!</span></div><p id="oops_text">You must select at least one sub-category to print a custom brochure!</p><button id="oops_continue_button" onclick="javascript:hideoops();"></button>';
	for (i=0;i<=loopcount;i++) 
	{
		if (itemgroup[i].checked===true) {
			selecteditemcount++;
		}
	}
	if (selecteditemcount===0) {
		document.getElementById('oops').innerHTML=oopshtml;
		document.getElementById('oops').style.display='block';
		return false;
	} else {return true;}
}

function swapMain(newId) {
	var newImg = 'core/images/products/full/'+document.getElementById('image'+newId).value;
	document.getElementById('product_image').src=newImg;
}
function swapZoom(newId) {
	var newImg = 'core/images/products/zoom/'+document.getElementById('image'+newId).value;
	document.getElementById('product_image').src=newImg;
}

$(document).ready(function(){
	
	$("a#tool_calculator,a#currency_converter_close").click(function() {  
		if ($("#currency_converter").is(":hidden")) {
			var htmlStr = '<iframe src="http://www.xe.com/ecc/input.cgi?Template=se&Amount='+$('#now_price').html(htmlStr)+'&From=GBP" width="620" height="195" name="Currency" frameborder="0" scrolling="no"></iframe>';
			$("#converter_tool").html(htmlStr);
		}
		$("#currency_converter").slideToggle("fast");
		return false;		
	});
	
	$("a#tool_email,a#send_to_a_friend_close").click(function() {  
		$("#send_to_a_friend").slideToggle("fast");
		return false;		
	});
	
	
	$("a#tk-ondemand-link,a#closeondemand").click(function() {  
		$("#tk-ondemand").slideToggle("slow");
		return false;		
	});
	
	$("a#page-info-button,a#hideinfo").click(function() {  
		$("#infowrap").slideToggle("slow");
		return false;		
	});
	
	$("a#show-more-combos,a#show-less-combos").click(function() {  
		$("#more_combo_products").slideToggle("slow");
		$("#show-more-combos").toggle();
		$("#show-less-combos").toggle();
		return false;		
	});
	
	$("a#checkout-basket-button").click(function() {  
		$("#basket_content").slideToggle("slow");
		return false;		
	});
	
	$("a#header_basket_summary, a#minibasketclose").click(function() {  
		if ($("#minibasket_summary").attr('openstate')=='closed') {
			$("#minibasket_summary").animate({top:"0px"},400);
			$("#minibasket_summary").attr('openstate', 'open');
		} else {
			$("#minibasket_summary").animate({top:"-296px"},400);
			$("#minibasket_summary").attr('openstate', 'closed');
		}
		return false;		
	});
	
	$("a.write_review_button").click(function() {  
		$("#review_form").slideToggle("slow");
		return false;		
	});
	
	$("span.switch").click(function() {  
		if ($(this).text() == "[+]") {
			$(this).text("[-]");
		} else if ($(this).text() == "[-]") {
			$(this).text("[+]");
		}
		$(this).parent().parent().find('ul:first').slideToggle();
		return false;		
	});
	
	$("a#free_delivery_icon").click(function() {  
		$("#free_delivery_info").slideToggle("slow");
		return false;		
	});
	
	$("#deptguidebutton").click(function() {  
		$("#deptguidetext").slideToggle("slow");
		return false;		
	});
	
	var more_height = 0;
	$(".read-more").click(function(){
		var div_intro = $("#description_intro");
		var div_more = $("#description_more");

		if(more_height === 0) {
			div_more.show();
			more_height = div_more.height();
			div_more.hide();
			intro_h = div_intro.height();
		}

		if(div_intro.css('display') == 'none') {
			div_more.animate({height: intro_h}, "slow", "linear", function() {
				div_more.hide();
				div_intro.show();
			});
		}
		else {
			div_intro.hide();
			div_more.show();
			div_more.height(intro_h);
			div_more.animate({height: more_height}, "slow", "linear", function() {
				div_more.css('height', 'auto');
			});
		}
		
		if ($("#read_more_description").is(".read-less-link")){
			$("#read_more_description").removeClass("read-less-link").addClass("read-more-link");
			$("#read_more_description").html("read more");
		}else{
			$("#read_more_description").removeClass("read-more-link").addClass("read-less-link");
			$("#read_more_description").html("read less");
		}
		
		return false;
	});
	
});

function viewComboOptions(comboTable) {
	$(comboTable).slideToggle("slow");
}

function newsSwitch() {
	var $active = $('#newslist li.active');

	if ( $active.length == 0 ) $active = $('#newslist li:last');

	var $next =  $active.next().length ? $active.next()
		: $('#newslist li:first');

	$active.addClass('last-active');

	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 100, function() {
			$active.removeClass('active last-active');
		});
}

var tTime;

function slideSwitch(slideId) {
	
	var sSlideName = 'slideshow-slides';
	var sSlideCounter = 'slide-counter';
	var $active = $('#' + sSlideName + ' li.active');
	var elemCounter = document.getElementById(sSlideCounter);
	var delayCount = false;
	var $next = 0;
	
	if ($active.length == 0) {$active = $('#' + sSlideName + ' li:last');}

	if(slideId==null){
		$next = $active.next().length ? $active.next()
		: $('#' + sSlideName + ' li:first');
	} else {
		$next = $(slideId);
		delayCount = true;
	} 
	
	$active.addClass('last-active');
	
	$next.css({opacity: 0.0})
		.addClass('active')
		.animate({opacity: 1.0}, 700, function() {
			$active.removeClass('active last-active');
		});
		
	if(elemCounter!==null){
		var $allCount = $('#' +sSlideCounter + ' li');
		$nextCount = $('#' + $next.attr('id').replace('slide','link'));
		$activeCount = $('#' + $active.attr('id').replace('slide','link'));
		$activeCount.addClass('last-active');		
		$allCount.css({color: '#fff'});
		$nextCount.css({color: '#bc0000'});
		$nextCount.addClass('active');
		$activeCount.removeClass('activecount last-active');
	}
	
	if(delayCount===true){
		clearTimeout(tTime);
		tTime = setTimeout("slideSwitch()",10000);
		
	} else {
		tTime = setTimeout("slideSwitch()",5000);
	}
	
}

$(function() {setTimeout("slideSwitch()",5000);});
$(function() {setInterval("newsSwitch()",10000);});

$("#stars-wrapper1").stars({inputType: "select"});
$("#stars-wrapper2").stars({inputType: "select"});
$("#stars-wrapper3").stars({inputType: "select"});
$(".reviewstars").stars({inputType: "select"});
$("#minibasket_summary").attr('openstate', 'closed');

function resizeDivs() {
  $('.button').each(function()
  {     
	$(this).width($(this).find("img").width());
	$(this).height($(this).find("img").height()); 
  });
}
window.onload = resizeDivs;
