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.cEnqType[document.contactform.cEnqType.selectedIndex].value == "")){
			missinginfo += "\n     -  Nature of Enquiry";
		}

		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 ((document.contactform.cEnqType[document.contactform.cEnqType.selectedIndex].value == "B")){
            
		    if (document.forms['contactform'].cAddress1.value == "") {
			    missinginfo += "\n\n As you are requesting our brochure, please complete the address fields";
		    }
		}
		
		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 checkNewsletterFields2() {
		missinginfo = "";
		
		
		if ((document.forms['nlform'].cEmail.value == "") || 
			(document.forms['nlform'].cEmail.value.indexOf('@') == -1) || 
			(document.forms['nlform'].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()	{
		//alert((document.frmProduct.Size[document.frmProduct.Size.selectedIndex].value));
		if (document.forms['frmProduct'].elements['colour'].value=='') {
			alert('Please select a colour before adding to basket');
			return false;
		}
		//else if (document.frmProduct.Size[document.frmProduct.Size.selectedIndex].value == '')  {
		else if (document.frmProduct.sizeHidden.value == '')  {
			alert('Please select a metal before adding to basket');
			return false;
		}
		else {
		    //alert('submitting');
			//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 enlarge2(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 enlarge()	{

		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('/zoom.asp?variant=' + variantID + '&image=' + image,'ZOOM','width=540,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 enlargeSet(variantID)	{

		image = '';

		if (variantID) {
			window.open('/zoom.asp?variant=' + variantID + '&image=' + image,'ZOOM','width=540,height=400,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 TechnicalSheet(variant) {
		if (variant) {
			window.open('/techsheet.asp?variantID=' + variant,'TECHSHEET','width=450,height=500,scrollbars=yes,resize=no');
		}
	}
	
	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 checkBagBuilderFields() {
		missinginfo = "";

		if (document.forms['bagbuilder'].bb_qty.value == "") {
			missinginfo += "\n     -  Quantity of bags required";
		}

		if ((document.bagbuilder.bb_colouroptions[document.bagbuilder.bb_colouroptions.selectedIndex].value == "")){
			missinginfo += "\n     -  Printing colour option";
		}


		if ((document.bagbuilder.cTitle[document.bagbuilder.cTitle.selectedIndex].value == "")){
			missinginfo += "\n     -  Title";
		}

		if (document.forms['bagbuilder'].cFName.value == "") {
			missinginfo += "\n     -  First Name";
		}

		if (document.forms['bagbuilder'].cSName.value == "") {
			missinginfo += "\n     -  Surname";
		}

		if (document.forms['bagbuilder'].cTel.value == "") {
			missinginfo += "\n     -  Telephone";
		}
	
		if ((document.forms['bagbuilder'].cEmail.value == "") || 
			(document.forms['bagbuilder'].cEmail.value.indexOf('@') == -1) || 
			(document.forms['bagbuilder'].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 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 checkCallbackFields() {
		missinginfo = "";
		
		if (document.forms['callback'].elements['callBackFName'].value == "") {
			missinginfo += "\n     -  First Name";
		}

		if (document.forms['callback'].elements['callBackSName'].value == "") {
			missinginfo += "\n     -  Surname";
		}

		if ((document.forms['callback'].elements['callBackEmail'].value == "") || 
			(document.forms['callback'].elements['callBackEmail'].value.indexOf('@') == -1) || 
			(document.forms['callback'].elements['callBackEmail'].value.indexOf('.') == -1)) {
			missinginfo += "\n     -  Valid email address";
		}

		if (document.forms['callback'].elements['callBackTel'].value == "") {
			missinginfo += "\n     -  Telephone";
		}

		if (missinginfo != "") {
			missinginfo ="___________________________________\n\n" +
			"You failed to correctly fill in your:\n" +
			missinginfo + "\n\n___________________________________" +
			"\nPlease check your details and submit again";
			alert(missinginfo);
			return false;
		}
		else return true;
	}			
	
	function checkSampleRequestFields() {
		missinginfo = "";
		
		if ((document.samplerequest.cTitle[document.samplerequest.cTitle.selectedIndex].value == "")){
			missinginfo += "\n     -  Title";
		}

		if (document.forms['samplerequest'].cFName.value == "") {
			missinginfo += "\n     -  First Name";
		}

		if (document.forms['samplerequest'].cSName.value == "") {
			missinginfo += "\n     -  Surname";
		}

		if (document.forms['samplerequest'].cTel.value == "") {
			missinginfo += "\n     -  Telephone";
		}
	
		if ((document.forms['samplerequest'].cEmail.value == "") || 
			(document.forms['samplerequest'].cEmail.value.indexOf('@') == -1) || 
			(document.forms['samplerequest'].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 checkTellaFriendFields() {
		missinginfo = "";
		
		if (document.forms['tellafriend'].stfName.value == "") {
			missinginfo += "\n     -  Your Name";
		}

		if (document.forms['tellafriend'].stfEmail.value == "") {
			missinginfo += "\n     -  Your 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 populateBasketDiv(intCount, basketContent)	{
	//alert(basketContent);
	parent.document.getElementById('basketCounter').innerHTML = intCount;
	parent.document.getElementById('basketTotalCounter').innerHTML = basketContent;
	
	//parent.location.reload();
	
	
	//moveDown('slider','170','');

	if (parent.document.getElementById('slideblock').style.display == "none")	{
		parent.toggle('title');
		
		setTimeout('parent.toggle("title")',5000);
	}
	//slidein()
}


function getObj(name, nest) {
if (parent.document.getElementById)
return parent.document.getElementById(name).style;
else if (parent.document.all)
return parent.document.all[name].style;
else if (parent.document.layers)
	if (nest != ''){
	return eval('parent.document.'+nest+'.parent.document.layers["'+name+'"]'); 
	}else{
	return parent.document.layers[name];
	}
}

function moveDown(layerName,stopPos, nest){
	var x = getObj(layerName, nest);
	//alert(x);
	var curPos = parseInt(x.top);
	curPos += (stopPos-curPos)/10
	x.top = curPos+1; 
	if(curPos > 150) x.visibility = "visible";
	if (curPos < stopPos) setTimeout("moveDown('"+layerName+"','"+stopPos+"','"+nest+"')",15);
}

//To move linklayers down or up from hiding
function moveUp(layerName,stopPos, nest){
	var x = getObj(layerName, nest);
	var curPos = parseInt(x.top);
	x.top = curPos-8; 
	if(curPos < 140) {
		x.visibility = "hidden";
	}
	//alert('cur=' + curPos + ' : stopPos='+ stopPos);
	if ((curPos > stopPos) && (stopPos > 0)) {
		//alert('moving..');
		
		stopPos = stopPos-6;
		setTimeout("moveUp('"+layerName+"','"+stopPos+"','"+nest+"')",60);
	}
}




//V2

// our global vars
var heightnow;
var targetheight;
var block;
var slideinterval;
var divheights = new Array();

// the delay between the slide in/out, and a little inertia
var inertiabase = 1;
var inertiainc = 1;
var slideintervalinc = 50;
var inertiabaseoriginal = inertiabase;

window.onload = calculateHeights

function calculateHeights()
{
	// detect whether the user has ie or not, how we get the height is different 
	var useragent = navigator.userAgent.toLowerCase();
	var ie = ((useragent.indexOf('msie') != -1) && (useragent.indexOf('opera') == -1) && (useragent.indexOf('webtv') == -1));
	var divs = getElementsByClassName(document, "div", "slideblock");
	
	for(var i=0; i<divs.length; i++)
	{
		// get the original height
		var baseheight = (ie) ? divs[i].offsetHeight + "px" : document.defaultView.getComputedStyle(divs[i], null).getPropertyValue('height', null);
	//	alert(divs[i].offsetHeight);
	//	alert(baseheight);
		
		// explicitly display it (optional, you could use cookies to toggle whether to display it or not)
		divs[i].style.display = "none";

		// "save" our div height, because once it's display is set to none we can't get the original height again
		var d = new div();
		d.el = divs[i];
		d.ht = baseheight.substring(0, baseheight.indexOf("p"));
		
		// store our saved versoin
		divheights[i] = d;		
	}
}

// this is one of our divs, it just has a DOM reference to the element and the original height
function div(_el, _ht)
{
	this.el = _el;
	this.ht = _ht;
}

function toggle(t)
{
	// reset our inertia base and interval
	inertiabase = inertiabaseoriginal;
	clearInterval(slideinterval);

	// get our block
	//block = t.parentNode.nextSibling;
	block = parent.document.getElementById('slideblock');
	
	//alert(block);
	// for mozilla, it doesn't like whitespace between elements
	if(block.className == undefined)
		block = t.parentNode.nextSibling.nextSibling;

	if(block.style.display == "none")
	{
		// link text
	//	t.innerHTML = "Hide";

		block.style.display = "block";
		block.style.height = "1px";

		// our goal and current height
		targetheight = divheight(block);
		heightnow = 1;

		// our interval
		slideinterval = setInterval(slideout, slideintervalinc);
	}
	else
	{
		// linkstext
	//	t.innerHTML = "Show";

		// our goal and current height
		targetheight = 1;
		heightnow = divheight(block);

		// our interval
		slideinterval = setInterval(slidein, slideintervalinc);
	}
}

// this is our slidein function the interval uses, it keeps subtracting
// from the height till it's 1px then it hides it
function slidein()
{
	
	if(heightnow > targetheight)
	{
		// reduce the height by intertiabase * inertiainc
		heightnow -= inertiabase;

		// increase the intertiabase by the amount to keep it changing
		inertiabase += inertiainc;

		// it's possible to exceed the height we want so we use a ternary - (condition) ? when true : when false;
		block.style.height = (heightnow > 1) ? heightnow + "px" : targetheight + "px";
	}
	else
	{
		// finished, so hide the div properly and kill the interval
		clearInterval(slideinterval);
		block.style.display = "none";
	}
}

// this is the function our slideout interval uses, it keeps adding
// to the height till it's fully displayed
function slideout()
{
	if(heightnow < targetheight)
	{
		// increases the height by the inertia stuff
		heightnow += inertiabase;

		// increase the inertia stuff
		inertiabase += inertiainc;

		// it's possible to exceed the height we want so we use a ternary - (condition) ? when true : when false;
		block.style.height = (heightnow < targetheight) ? heightnow + "px" : targetheight + "px";
		
	}
	else
	{
		// finished, so make sure the height is what it's meant to be (inertia can make it off a little)
		// then kill the interval
		clearInterval(slideinterval);
		block.style.height = targetheight + "px";
	}
}

// returns the height of the div from our array of such things
function divheight(d)
{
	for(var i=0; i<divheights.length; i++)
	{
		if(divheights[i].el == d)
		{
			return divheights[i].ht;
		}
	}
}

/*
	the getElementsByClassName function I pilfered from this guy.  It's
	a useful function that'll return any/all tags with a specific css class.

		Written by Jonathan Snook, http://www.snook.ca/jonathan
		Add-ons by Robert Nyman, http://www.robertnyman.com
*/
function getElementsByClassName(oElm, strTagName, strClassName)
{
	// first it gets all of the specified tags
    var arrElements = (strTagName == "*" && document.all) ? document.all : oElm.getElementsByTagName(strTagName);
    
	// then it sets up an array that'll hold the results
	var arrReturnElements = new Array();

	// some regex stuff you don't need to worry about
    strClassName = strClassName.replace(/\-/g, "\\-");

    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
    var oElement;

	// now it iterates through the elements it grabbed above
    for(var i=0; i<arrElements.length; i++)
	{
        oElement = arrElements[i];

		// if the class matches what we're looking for it ads to the results array
        if(oRegExp.test(oElement.className))
		{
            arrReturnElements.push(oElement);
        }   
    }

	// then it kicks the results back to us
    return (arrReturnElements)
}



function PopulateVariantForm(divID, variantID)	{
	//activate selected variant
	document.getElementById('variantColorImage_' + divID).className = 'variantColourImageSelected';
//  NO VARIANT IMAGES FOR KYLES SO SKIP NEXT BIT
//	document.getElementById('mainimage').src = '/images/products/standard/' + variantID + '.jpg'
	document.forms['frmProduct'].elements['variantID'].value = variantID;
	document.forms['frmProduct'].elements['colour'].value = variantID;
}


function change3dview(view) {
    //alert(document.getElementById('3dview'));
    
    if (view==1) {
        //alert(document.getElementById('3dviewobject');
        document.getElementById('3dview').SetURL = 'Kyles_Large.mov';
     //   3dviewembed.src='Kyles_Large.mov'
    }
    
    
}

