function calc_product(){

	var intHeightLimit=document.getElementById('heightlimit').value;
	var intLengthLimit=document.getElementById('lengthlimit').value;
	var intWidthLimit=document.getElementById('widthlimit').value;
	var intFoldReduction=document.getElementById('foldreduction').value;

	if(isNaN(intFoldReduction)) {
		intFoldReduction=0;
	}
	if(isNaN(intHeightLimit)) {
		intHeightLimit=0;
	}
	if(isNaN(intWidthLimit)) {
		intWidthLimit=0;
	}
	if(isNaN(intLengthLimit)) {
		intLengthLimit=0;
	}

	if(document.getElementById('height_option')) {
		if(document.getElementById('height_option').type=='text'){
			var intPriceMultiplier=document.getElementById('price_multiplier').value;
			var intHeight=document.getElementById('height_option').value;
			var intWidth=document.getElementById('width_option').value;	
			var blnBrushing=false;

			if(document.getElementById('brushing')){
				if(document.getElementById('brushing').value=='None'||document.getElementById('brushing').value==''){
					blnBrushing=false;
				} else {
					blnBrushing=true;
				}
			} else {
				blnBrushing=false;
			}

			if(document.getElementById('mdffolds')){

				switch(document.getElementById('mdffolds').value) {
				case "Left": intWidthLimit=intWidthLimit-intFoldReduction;
					break;
				case "Right": intWidthLimit=intWidthLimit-intFoldReduction;
					break;
				case "Both": intWidthLimit=intWidthLimit-(intFoldReduction*2);
					break;
				}
			}

			var intAdjustedWidth=parseInt(intWidth);
			var intAdjustedHeight=parseInt(intHeight);
			var intRatio;
			var blnMaxWidthFail=false;
			var blnMaxHeightFail=false;
			var blnMaxWidthFail2=false;
			var blnMaxHeightFail2=false;

			if(blnBrushing){
				//normal check - because the metal has been brushed
				if((intWidthLimit>0)&&(intAdjustedWidth>intWidthLimit)) {
					intAdjustedWidth=intWidthLimit;
					alert('This item has a maximum width of '+intWidthLimit+'mm');
					document.getElementById('width_option').value=intWidthLimit+'';
				}
				if((intHeightLimit>0)&&(intAdjustedHeight>intHeightLimit)) {
					intAdjustedheight=intHeightLimit;
					alert('This item has a maximum height of '+intHeightLimit+'mm');
					document.getElementById('height_option').value=intHeightLimit+'';
				}
			} else {
				//normal check
				if((intWidthLimit>0)&&(intAdjustedWidth>intWidthLimit)) {
					blnMaxWidthFail=true;

				}
				if((intHeightLimit>0)&&(intAdjustedHeight>intHeightLimit)) {
					blnMaxHeightFail=true;
				}

				//one or both checks have failed - try swapping dimensions - because the metal has NOT been brushed
				if(blnMaxWidthFail||blnMaxHeightFail) {
					if((intHeightLimit>0)&&(intAdjustedWidth>intHeightLimit)) {
						blnMaxWidthFail2=true;
					}
					if((intWidthLimit>0)&&(intAdjustedHeight>intWidthLimit)) {
						blnMaxHeightFail2=true;
					}
				}



				//nope - still failed, so lets resize the dimensions
				if(blnMaxWidthFail2||blnMaxHeightFail2) {
					if(blnMaxWidthFail) {
						alert('This item has a maximum width of '+intWidthLimit+'mm');
						document.getElementById('width_option').value=intWidthLimit+'';
					}
					if(blnMaxHeightFail) {
						alert('This item has a maximum height of '+intHeightLimit+'mm');
						document.getElementById('height_option').value=intHeightLimit+'';
					}
				} else {
				//swaping dimensions did't cause a failure... so lets accept
				}
			}
			
			var oSheet=document.getElementById('sheet');
			var oSheetContainer=document.getElementById('sheet_container');
			var oSheetWidth=document.getElementById('sheet_width');
			var oSheetHeight=document.getElementById('sheet_height');

			var oSqm=document.getElementById('calc_sqm');
			
			var oCalcPrice=document.getElementById('calc_price');

			var strName=document.getElementById('name').value;

			//perform calculations for resize
			if(intAdjustedWidth>intAdjustedHeight){
				intRatio=120/intAdjustedWidth;
			}else{
				intRatio=120/intAdjustedHeight;
			}
			
			intAdjustedWidth=Math.floor(intAdjustedWidth*intRatio);
			intAdjustedHeight=Math.floor(intAdjustedHeight*intRatio);

			if(oSheet){
				//set styles
				oSheetContainer.style.width=(intAdjustedWidth+11)+'px';
				oSheetContainer.style.height=(intAdjustedHeight+11)+'px';
				oSheetContainer.style.marginLeft=Math.max((140-intAdjustedWidth)/2,0)+'px';
				oSheetContainer.style.marginTop=Math.max((140-intAdjustedHeight)/2,0)+'px';

				//alert("osheetcontainer="+oSheetContainer.style.height);
				//alert("osheetwidth="+oSheet.style.width);
			
				oSheet.style.width=Math.max(intAdjustedWidth-8,1)+'px';
				oSheet.style.height=Math.max(intAdjustedHeight-5,1)+'px';	

				oSheetWidth.style.paddingLeft=Math.max((intAdjustedWidth/2)-7,0)+'px';
				oSheetWidth.style.width=(intAdjustedWidth/2)+5+'px';

				oSheetHeight.style.paddingTop=Math.max((intAdjustedHeight/2)-8,0)+'px';
				oSheetHeight.style.height=(intAdjustedHeight/2)+6+'px';
			}

			//calculate price
			if(document.getElementById('width_option').type=='text'){
				oSqm.value=intHeight*intWidth/1000000;
				var intPrice=intHeight*intWidth*intPriceMultiplier/1000000;
			}else{
				oSqm.value=1000*intWidth/1000000;
				var intPrice=1000*intWidth*intPriceMultiplier/1000000;
			}
			//alert(intPrice);
		
			if(document.getElementById('shapesholesfolds')){
				if(document.getElementById('shapesholesfolds').value=='Yes'){
					intPrice=0;
				}
			}

			if(intPrice==0){
				oCalcPrice.innerHTML='Quote Required';
			}else{
				oCalcPrice.innerHTML='£'+intPrice.toFixed(2);
			}	

		} else {

			if(document.getElementById('length_option')) {

				if(document.getElementById('length_option').type=='text'){

				//var dblLengthPrice=document.getElementById('LengthmmPrice').value;
				var oCalcPrice=document.getElementById('calc_price');
				var dblBasePrice=document.getElementById('price_multiplier').value;
				var intLength=document.getElementById('length_option').value;
				var intSqm=document.getElementById('calc_sqm').value;

				var intAdjustedLength=parseInt(intLength);

				if(document.getElementById('mdffolds')){

					switch(document.getElementById('mdffolds').value) {
					case "Left": intWidthLimit=intWidthLimit-intFoldReduction;
						break;
					case "Right": intWidthLimit=intWidthLimit-intFoldReduction;
						break;
					case "Both": intWidthLimit=intWidthLimit-(intFoldReduction*2);
						break;
					}
				}
				
				if((intLengthLimit>0)&&(intAdjustedLength>intLengthLimit)) {
					intAdjustedLength=intLengthLimit;
					alert('This item has a maximum height of '+intLengthLimit+'mm');
					document.getElementById('length_option').value=intLengthLimit+'';
				}

				dblBasePrice=(dblBasePrice/10);
		
				var intPrice=0;
				intPrice = (dblBasePrice*intAdjustedLength);
				//intPrice += +dblBasePrice;
	
				if(intPrice==0){
					oCalcPrice.innerHTML='Quote Required';
				} else {
					oCalcPrice.innerHTML='£'+intPrice.toFixed(2);
				}

				document.getElementById('calc_sqm').value=(intAdjustedLength/10);
			}

		}
	}

	} else if(document.getElementById('length_option')) {

		if(document.getElementById('length_option').type=='text'){

			//var dblLengthPrice=document.getElementById('LengthmmPrice').value;
			var oCalcPrice=document.getElementById('calc_price');
			var dblBasePrice=document.getElementById('price_multiplier').value;
			var intLength=document.getElementById('length_option').value;
			var intSqm=document.getElementById('calc_sqm').value;	

			var intAdjustedLength=parseInt(intLength);

			if(document.getElementById('mdffolds')){

				switch(document.getElementById('mdffolds').value) {
				case "Left": intWidthLimit=intWidthLimit-intFoldReduction;
					break;
				case "Right": intWidthLimit=intWidthLimit-intFoldReduction;
					break;
				case "Both": intWidthLimit=intWidthLimit-(intFoldReduction*2);
					break;
				}
			}

			if((intLengthLimit>0)&&(intAdjustedLength>intLengthLimit)) {
				intAdjustedLength=intLengthLimit;
				alert('This item has a maximum height of '+intLengthLimit+'mm');
				document.getElementById('length_option').value=intLengthLimit+'';
			}

			dblBasePrice=(dblBasePrice/10);
	
		
			var intPrice=0;
			intPrice = (dblBasePrice*intAdjustedLength);
			//intPrice += +dblBasePrice;
	
			if(intPrice==0){
				oCalcPrice.innerHTML='Quote Required';
			} else {
				oCalcPrice.innerHTML='£'+intPrice.toFixed(2);
			}

			document.getElementById('calc_sqm').value=(intAdjustedLength/10);

		}
	}
}

var preload_imgs;

function swapimage(imagename,elementid) {
	//alert(imagename);
	var img=document.getElementById('mainimage');
	img.src=imagename;
	var defaultbutton=document.getElementById('link1');
	defaultbutton.className='';
	if(document.getElementById('link2')) {
	defaultbutton=document.getElementById('link2');}
	defaultbutton.className='';
	if(document.getElementById('link3')) {
	defaultbutton=document.getElementById('link3');}
	defaultbutton.sclassName='';
	if(document.getElementById('link4')) {
	defaultbutton=document.getElementById('link4');}
	defaultbutton.className='';
	if(document.getElementById('link5')) {
	defaultbutton=document.getElementById('link5');}
	defaultbutton.className='';
		
	var buttonlink=document.getElementById(elementid);
	buttonlink.className='selected';
}

function preloadimages(img1,img2,img3,img4) {
	preload_imgs=new Image(296,222);
	preload_imgs.src=img1;
	preload_imgs.src=img2;
	preload_imgs.src=img3;
	preload_imgs.src=img4;

}