function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function checkContactFields() {
		missinginfo = "";
		
		if ((document.contactform.cTitle[document.contactform.cTitle.selectedIndex].value == "")){
			missinginfo += "\n     -  Title";
		}

		if (document.forms['contactform'].cFName.value == "") {
			missinginfo += "\n     -  First Name";
		}

		if (document.forms['contactform'].cSName.value == "") {
			missinginfo += "\n     -  Surname";
		}

		if (document.forms['contactform'].cTel.value == "") {
			missinginfo += "\n     -  Telephone";
		}
	
		if ((document.forms['contactform'].cEmail.value == "") || 
			(document.forms['contactform'].cEmail.value.indexOf('@') == -1) || 
			(document.forms['contactform'].cEmail.value.indexOf('.') == -1)) {
			missinginfo += "\n     -  Email address";
		}

		if (missinginfo != "") {
			missinginfo ="_____________________________\n" +
			"You failed to correctly fill in your:\n" +
			missinginfo + "\n_____________________________" +
			"\nPlease check your details and submit again";
			alert(missinginfo);
			return false;
		}
		else return true;
	}			


function checkNewsletterFields() {
		missinginfo = "";
		
		
		if ((document.forms['form'].cEmail.value == "") || 
			(document.forms['form'].cEmail.value.indexOf('@') == -1) || 
			(document.forms['form'].cEmail.value.indexOf('.') == -1)) {
			missinginfo += "\n     -  Email address";
		}

		if (missinginfo != "") {
			missinginfo ="_____________________________\n" +
			"You failed to correctly fill in your:\n" +
			missinginfo + "\n_____________________________" +
			"\nPlease check your details and submit again";
			alert(missinginfo);
			return false;
		}
		else return true;
	}			


	function newDeliveryAddress()	{
		//alert('clearing address form fields');
		var oForm = document.forms['addressform']
		
		//clear all the form elements apart from the submit button!
		for(var i=0; i<oForm.elements.length; i++){
			if ((oForm.elements[i].name !== 'submit') && (oForm.elements[i].name !== 'cCountry')){
				oForm.elements[i].value = '';
				oForm.elements[i].readOnly = false;
				oForm.elements[i].disabled = false;
			}
		}
	}
	
	
	function CheckProductVariants()	{
		var oForm = document.forms['product'];
		var oProduct = oForm.elements['variantID'].value;
		var variantRecordID = oForm.elements['variantRecordID'].value;
		
		if (variantRecordID == '')	{	//ONLY VALIDATE WHEN CREATING NEW
			for(var x=0;x<products.length;x++) {
				//alert(oProduct);
				//alert(products[x]);
				if(oProduct == products[x])	{
					alert('This variant code already exists!')
					return false;
				}
			}
		}
	}
		
	function CheckProduct()	{
		var oForm = document.forms['product'];
		var oProduct = oForm.elements['productCode'].value;
		var prodID = oForm.elements['prodID'].value;
		
		if (prodID == '')	{	//ONLY VALIDATE WHEN CREATING NEW
			for(var x=0;x<products.length;x++) {
				//alert(oProduct);
				//alert(products[x]);
				if(oProduct == products[x])	{
					alert('This product code already exists!')
					return false;
				}
			}
		}
	}

	function CheckCategory()	{
		var oForm = document.forms['category'];
		var oCategory = oForm.elements['name'].value;
		var catID = oForm.elements['catID'].value;
		
		if (catID == '')	{	//ONLY VALIDATE WHEN CREATING NEW
			for(var x=0;x<categories.length;x++) {
				//alert(oProduct);
				//alert(products[x]);
				if(oCategory == categories[x])	{
					alert('This category already exists!')
					return false;
				}
			}
		}
	}


	function AddToBasket(variantID)	{
		//alert(document.forms['frmProduct_' + variantID].elements['quantity'].value);
		if (document.forms['frmProduct_' + variantID].elements['quantity_' + variantID].value=='') {
			alert('Please enter your required quantity before adding to basket');
			return false;
		}
		else {
			document.forms['frmProduct_' + variantID].elements['size'].value = variantID;
			document.forms['frmProduct_' + variantID].elements['btnAdd'].value = 'addtobasket';
			//alert('OK');
			document.forms['frmProduct_' + variantID].submit();
		}
	}	


	function AddToBasketOLD()	{
		//alert(variantID);
		variantID = document.forms['frmProduct'].elements['variantID'].value
		
		if (document.forms['frmProduct'].elements['quantity_' + variantID].value=='') {
			alert('Please enter your required quantity before adding to basket');
			return false;
		}
		else {
			document.forms['frmProduct'].elements['size'].value = variantID;
			document.forms['frmProduct'].elements['btnAdd'].value = 'addtobasket';
			document.forms['frmProduct'].submit();
		}
	}	
				
//	function AddToBasket(variantID)	{
		//alert(variantID);
//		if (document.forms['frmProduct'].elements['quantity_' + variantID].value=='') {
//			alert('Please enter your required quantity before adding to basket');
//			return false;
//		}
//		else {
//			document.forms['frmProduct'].elements['size'].value = variantID;
//			document.forms['frmProduct'].elements['btnAdd'].value = 'addtobasket';
//			document.forms['frmProduct'].submit();
//		}
//	}	

	function confirmDelete()	{
		var agree=confirm("Are you sure you wish to delete?");
		if (agree) {
			return true ;
		}
		else {
			return false ;
		}
	}				
	
	
	function enlarge(variantID)	{

		//variantID = document.forms['frmProduct'].elements['variantID'].value
		image = '';
		
		if (variantID) {
			window.open('/zoom.asp?variant=' + variantID + '&image=' + image,'ZOOM','width=450,height=620,scrollbars=no,resize=yes');
			//window.open('/zoomjs.asp?variant=' + variantID + '&image=' + image,'ZOOM','width=580,height=400,scrollbars=no,resize=yes');
		}
	//	else {
	//		window.open('/zoom.asp?type=image&prID=' + strImage + '&image=' + image,'ZOOM','width=500,height=550,scrollbars=no,resize=yes');
	//	}
	}


/*
	function enlarge(strImage, variant, image)	{
		if (variant) {
			window.open('/zoom.asp?type=image&prID=' + strImage + '&variant=' + variant + '&image=' + image,'ZOOM','width=500,height=500,scrollbars=no,resize=yes');
		}
		else {
			window.open('/zoom.asp?type=image&prID=' + strImage + '&image=' + image,'ZOOM','width=500,height=550,scrollbars=no,resize=yes');
		}
	}
*/

	
	function clearEnlargeDiv()	{
		document.getElementById('enlarger').innerHTML = '';
		//document.getElementById('alternativeA').innerHTML = '';
	}
	
	function changeEnlargeDiv(strImage)	{
		document.getElementById('enlarger').innerHTML = '<a href="#" onClick="javascript:enlarge(\'' + strImage + '\',\'true\');">Enlarge</a>';
		
		//document.getElementById('alternativeA').innerHTML = 'altA';
		
		//alert(document.getElementById('enlarger').innerHTML);
	}
	
	
	function changeAlternative(alt, strFileName, image)	{
		//alert(strFileName);
		document.getElementById('alternative' + alt).innerHTML = '<a href="#" onClick="javascript:enlarge(\'' + strFileName + '\',\'true\',\'' + image + '\');"><img src="/images/products/thumbs/' + strFileName + '_' + alt + '.jpg" border="0"/></a>';
	}
	
	
	function clearAlternative(alt)	{
		document.getElementById('alternative' + alt).innerHTML = '';
	}
	
	
	function GlossaryTerm(glossaryTerm) {
		if (glossaryTerm) {
			window.open('/glossaryTerm.asp?term=' + glossaryTerm,'glossaryTerm','width=450,height=350,scrollbars=yes,resize=no');
		}
	}
	
	function checkAddressFields() {
		missinginfo = "";

		if (document.forms['addressform'].addressName.value == "") {
			missinginfo += "\n     -  Address Name";
		}

		if (document.forms['addressform'].address.value == "") {
			missinginfo += "\n     -  Address";
		}
		
		if (document.forms['addressform'].town.value == "") {
			missinginfo += "\n     -  Town";
		}
		if (document.forms['addressform'].postcode.value == "") {
			missinginfo += "\n     -  Post code";
		}

		if (missinginfo != "") {
			missinginfo ="\n" +
			"You failed to correctly fill in your:\n" +
			missinginfo + "\n" +
			"\nPlease check your details and submit again";
			alert(missinginfo);
			return false;
		}
		else return true;
	}			

	function toggleSpecialDelivery(intCountry)	{
		var oForm = document.forms['delivery']
		
		if (intCountry==1) {
			for(var i=0; i<oForm.elements['specialDelivery'].length; i++){
				oForm.elements['specialDelivery'][i].disabled = false;
			}
		} else {
			for(var i=0; i<oForm.elements['specialDelivery'].length; i++){
				oForm.elements['specialDelivery'][i].disabled = true;
			}
		}
	}
	
	
	function fitPic() {
		if (window.innerWidth){
				iWidth = window.innerWidth;
				iHeight = window.innerHeight;
		}else{
				iWidth = document.body.clientWidth;
				iHeight =document.body.clientHeight;
		}
		iWidth = document.images[0].width - iWidth;
		iHeight = document.images[0].height - iHeight;
		window.resizeBy(iWidth, iHeight);
	};
	
	function changeMainImage(strProductCode)	{
		document.getElementById('mainCatImage').innerHTML = '<img src="/images/products/thumbs/' + strProductCode + '.jpg" border="0"/>';
	}
	
	function changeMainName(strName)	{
		document.getElementById('mainCatName').innerHTML = strName;
	}	
	
	
	