/*
	var _control can have the following values: English, Metric, Inches, Feet, Empty ( Initial ) This variable controls the validations to be done when
    user clicks on Add Cart Button
*/
var _control = "Empty";
var cnter=1;
var cnt=1;

function addLink() { 	
	document.Form.submit();
	}

function check_vars(pid, form )
{
	var form = document.Form;
	qObj = document.all("quantity["+pid+"]");
	
	/*diaObj = document.Form.all.item("PIDXX[]");
	splObj = document.Form.all.item("PID1[]");*/
	diaObj = document.all.item("PIDXX[]");
	splObj = document.all.item("PID1[]");


	var pqty = qObj.value;
    checkFeild = document._control;

	if( checkFeild == "Inches" )
    {
		if( !validText("WD", document.Form.WD.value,"Width",0) )
		{
			return false;
		}
		if( !validText("WDC", document.Form.WDC.value,"Width",0) )
		{
			return false;
		}
		if( !validText("LN", document.Form.LN.value,"Length",0) )
		{
			return false;
		}

		if( !validText("Springsalonglength", document.Form.Springsalonglength.value,"Springs along one long side",0))
		{
			return false;
		}
		if( !validText("Springsalongwidth", document.Form.Springsalongwidth.value,"Springs along one end",0))
		{
			return false;
		}
		if( !validText("SPLN", document.Form.SPLN.value,"Spring Length",0) )
		{
			return false;
		}

		var ln = ( !isNaN(document.Form.LN.value) ) ? parseFloat( document.Form.LN.value ) : 0;
        var wd = ( !isNaN(document.Form.WD.value) ) ? parseFloat( document.Form.WD.value ) : 0;
		var wdc = ( !isNaN(document.Form.WDC.value) ) ? parseFloat( document.Form.WDC.value ) : 0;
        var spln3 = ( !isNaN(document.Form.SPLN.value) ) ? parseFloat( document.Form.SPLN.value ) : 0;

		var pid1 = ( !isNaN(diaObj[0].value) ) ? parseFloat( diaObj[0].value ) : 0;
		var pid2 = ( !isNaN(diaObj[4].value) ) ? parseFloat( diaObj[4].value ) : 0;
		var pid3 = ( !isNaN(diaObj[8].value) ) ? parseFloat( diaObj[8].value ) : 0;
		var pid4 = ( !isNaN(diaObj[12].value) ) ? parseFloat( diaObj[12].value ) : 0;

		document.Form.Width.value = wd + pid1;
		document.Form.WidthCenter.value = wdc + pid2;
		document.Form.Widthc1.value = wdc + pid2;
        document.Form.Length.value = ln + pid3;
        document.Form.Length1.value = ln + pid3;
        document.Form.SpringLength.value = (spln3 + pid4);		
    }

	// rule for avg mat dia less than 30 minhaj 7/14/2009

		var num1 = parseInt(document.Form.Width.value);
		var num2 = parseInt(document.Form.Length.value);
		var avg_dia = (num1+num2)/2;	
		
		if(avg_dia < 30){
			
			if(cnt == 1)
			{
			cnt=2;	
			var new_window = window.open('alert_rectmat_demo.php?size=mat_size'+'&avg_dia='+avg_dia,'mywin','left=250,top=100,width=350,height=300,toolbar=1,resizable=0');						
			//document.Form.SpringLength.focus();			
			new_window.focus();
			
			return false;

			}
	}

// end rule for avg mat dia less than 30 minhaj 7/14/2009




	if( checkFeild == "Feet" )
    {
		if( !validSelect(diaObj[1], "Feet" ) )
		{
			return false;
		}
		if( !validSelect(diaObj[5], "Feet" ) )
		{
			return false;
		}
		if( !validSelect(diaObj[9], "Feet" ) )
		{
			return false;
		}		
		if( !validText("Springsalonglength", document.Form.Springsalonglength.value,"Springs along one long side",0))
		{
			return false;
		}
		if( !validText("Springsalongwidth", document.Form.Springsalongwidth.value,"Springs along one end",0))
		{
			return false;
		}
		if( !validSelect(diaObj[13], "Inch" ) )
		{
			return false;
		}

		//if( !validSelect(document.Form.SPLN.value, "Inch" ) )		{			return false;		}

		//if( !validSelectInch(splObj[1], "Inch" ) )		{			return false;		}

		//if( !validText("SPLN", document.Form.SPLN.value,"Spring Length",0) )		{			return false;		}


		//var feet1 = ( !isNaN(diaObj[0].value) ) ? parseFloat( diaObj[0].value ) : 0;

		var feet1 = ( !isNaN(diaObj[1].value) ) ? parseFloat(diaObj[1].value ) : 0;

		var inch1 = ( !isNaN(diaObj[2].value) ) ? parseFloat( diaObj[2].value ) : 0;
		var fraction1 = ( !isNaN(diaObj[3].value) ) ? parseFloat( diaObj[3].value ) : 0;

		var feet2 = ( !isNaN(diaObj[5].value) ) ? parseFloat( diaObj[5].value ) : 0;
		var inch2 = ( !isNaN(diaObj[6].value) ) ? parseFloat( diaObj[6].value ) : 0;
		var fraction2 = ( !isNaN(diaObj[7].value) ) ? parseFloat( diaObj[7].value ) : 0;

		var feet3 = ( !isNaN(diaObj[9].value) ) ? parseFloat( diaObj[9].value ) : 0;
		var inch3 = ( !isNaN(diaObj[10].value) ) ? parseFloat( diaObj[10].value ) : 0;
		var fraction3 = ( !isNaN(diaObj[11].value) ) ? parseFloat( diaObj[11].value ) : 0;

		// var feet3 = ( !isNaN(document.Form.PID[9].value) ) ? parseFloat( document.Form.PID[9].value ) : 0;

		var inch4 = ( !isNaN(diaObj[13].value) ) ? parseFloat( diaObj[13].value ) : 0;
		var fraction4 = ( !isNaN(diaObj[14].value) ) ? parseFloat( diaObj[14].value ) : 0;
		var input4 = ( inch4 + fraction4 ) ;

		document.Form.SpringLength.value = input4;

		//var input1 = feet1 + "-ft " + (inch1 + fraction1)

		var input1 = feet1 + "-ft " + (inch1 + fraction1);

		var input2 = feet2 + "-ft " + (inch2 + fraction2);
		var input3 = feet3 + "-ft " + (inch3 + fraction3);
		var input4 = ( inch3 + fraction3 ) + ( feet3 * 12 );
		var input5 = ( inch2 + fraction2 ) + ( feet2 * 12 );

		//document.Form.Width.value = input1;
		document.Form.Width.value= input1;
		document.Form.WidthCenter.value = input2;		
		document.Form.Length.value = input3;
		document.Form.Length1.value = input4;
		document.Form.Widthc1.value = input5;
	}
	if( checkFeild == "Metric" )
	{
		if( !validText("WD", document.Form.WD.value,"Width",0))
		{
			return false;
		}
		if( !validText("WDC", document.Form.WDC.value,"Width",0))
		{
			return false;
		}

		if( !validText("LN", document.Form.LN.value,"Length",0))
		{
			return false;
		}

		if( !validText("Springsalonglength", document.Form.Springsalonglength.value,"Springs along one long side",0))
		{
			return false;
		}
		if( !validText("Springsalongwidth", document.Form.Springsalongwidth.value,"Springs along one end",0))
		{
			return false;
		}

		if( !validText("SPLN", document.Form.SPLN.value,"Spring Length",0))
		{
			return false;
		}

		var ln = ( !isNaN(document.Form.LN.value) ) ? parseFloat( document.Form.LN.value ) : 0;
		var wd = ( !isNaN(document.Form.WD.value) ) ? parseFloat( document.Form.WD.value ) : 0;
		var wdc = ( !isNaN(document.Form.WDC.value) ) ? parseFloat( document.Form.WDC.value ) : 0;
		var spln = ( !isNaN(document.Form.SPLN.value) ) ? parseFloat( document.Form.SPLN.value ) : 0;

		var pid1 = ( !isNaN(diaObj[0].value) ) ? parseFloat( diaObj[0].value ) : 0;
		var pid2 = ( !isNaN(diaObj[4].value) ) ? parseFloat( diaObj[4].value ) : 0;
		var pid3 = ( !isNaN(diaObj[8].value) ) ? parseFloat( diaObj[8].value ) : 0;
		var pid4 = ( !isNaN(diaObj[12].value) ) ? parseFloat( diaObj[12].value ) : 0;

		var input1 = wd + pid1;
		var input2 = wdc + pid2;
		var input3 = ln + pid3;		
		var input4 = spln + pid4;

		document.Form.Width.value = input1;
		document.Form.WidthCenter.value = input2;
		document.Form.Length.value = input3;
		document.Form.Length1.value = input3 / 2.54;
		document.Form.SpringLength.value = input4;
		document.Form.Widthc1.value = input2 / 2.54;
	}


	/* start code for generate popup when width is more than length by Minhaj 5/29/2009*/
	if(parseInt(form.Springsalongwidth.value) > parseInt(form.Springsalonglength.value) || (parseFloat(document.Form.Width.value) > parseFloat(document.Form.Length.value))){
		
		var check_cond = 0;
		if((parseFloat(document.Form.Width.value) > parseFloat(document.Form.Length.value)))				
		check_cond = 1;	

		if(parseInt(form.Springsalongwidth.value) > parseInt(form.Springsalonglength.value))
		check_cond = 2;
		if(parseInt(form.Springsalongwidth.value) > parseInt(form.Springsalonglength.value) && (parseFloat(document.Form.Width.value) > parseFloat(document.Form.Length.value)))

		check_cond = 3;			

			
			if(cnter == 1)
			{
			cnter=2;	
			var new_window = window.open('alert_rectmat.php?type='+check_cond+'&formname='+form.name,'mywin','left=120,top=100,width=350,height=300,toolbar=1,resizable=0');						
			document.Form.WD.focus();			
			new_window.focus();
			
			return false;

			}
	}
	/* end code for generate popup when width is more than length by minhaj 5/29/2009*/

	//calPrice(0);

	if (pqty == "")
    {
        alert("Please enter the quantity.");
        qObj.focus();
        return false;
	}
	if (!(pqty <= 99999 && pqty > 0))
	{
		alert("Please enter a numeric value for quantity");
		qObj.value='';
		qObj.focus();
		return false;
    }
	if(pqty.indexOf(".") != -1)
	{
		//alert("Invalid Quantity");
		alert("Please enter quantity in whole numbers"); 
		qObj.value='';
		qObj.focus();
		return false;
	}
	document.Form.submit();
    //calPrice(0);
    return true;
}
function display()
{
	_control = document._control;
    link_control = e ( "chkroundmatselect" );

	//str = "d2,a1,a2,a3,a4,a9,a10,a11,a12,a14,a15,a18,m1,m2,m3,t31,t32";
	str = "d2,a1,a2,a3,a4,a9,a10,a11,a14,a15,a18,m1,m2,m3,t31,t32,aw2,aw14";
	hide( str );
    str1= "td1,td2,td3,td31,td32,td4,td5,td11";
    show( str1 );
    if( link_control[0].checked )
    {
		_control = "English";                // Check Feild
		str = "d2,td1,td2,td3,td31,td32,td4,td5";
		show( str );
		inner_control = e( "chkroundmatinchft" );
		if( inner_control[0].checked )
        {
			str = "a1,a2,a3,a4,a9,a10,a11,a12,m1,m2,m3,t31,t32,aw2,aw1";
			show( str );
            str1= "td1,td2,td3,td31,td32,td4,td5,td11";
            hide( str1 );
            _control = "Inches";
		}
        if( inner_control[1].checked )
        {
			str = "a1,a14,a3,a9,a11,a12,m1,m2,m3,a15,a18,t31,t32,aw14,aw1";
			show( str );
            str1 = "td1,td2,td3,td31,td32,td4,td5,td11";
			hide( str1 );
            _control = "Feet";
		}
    }
    
	if( link_control[1].checked )
    {
        str = "a1,a2,a3,a4,a9,a10,a11,a12,m1,m2,m3,t31,t32,aw1,aw2";
        show( str );
        str1= "td1,td2,td3,td31,td32,td4,td5,td11";
        hide( str1 );
		_control = "Metric";
    }
    document._control = _control;
	if(document._control=="Feet")
    {
		document.Form.txtinchft1.value = "Feet & Inches";
		document.Form.txtinchftw1.value = "Feet & Inches";
        document.Form.txtinchft2.value = "Feet & Inches";
        document.Form.txtinchft3.value = "Inches";
	}
    else if(document._control=="Inches")
    {
		document.Form.txtinch1.value = "Inches";
		document.Form.txtinchw1.value = "Inches";
        document.Form.txtinch2.value = "Inches";
        document.Form.txtinch3.value = "Inches";
	}
    else if(document._control=="Metric")
    {
        document.Form.txtinch1.value = "Centimeters";
		document.Form.txtinchw1.value = "Centimeters";
        document.Form.txtinch2.value = "Centimeters";
        document.Form.txtinch3.value = "Centimeters";
    }
}
function show( str )
{
	var controls = str.split( "," );
    for( i = 0; i < controls.length; i++ )
    {
		element = e( controls[i] );
        if( element.style.display =="none" )
           element.style.display = '';
    }
}
function hide( str )
{
    var controls = str.split( "," );
    for( i = 0; i < controls.length; i++ )
    {
		element = e( controls[i] );
        if( element.style.display !=   "none" )
            element.style.display  =   "none";
    }
}
function e( name )
{
	return document.all[name];
}
var k=1;
function validSelect(fieldName, msg)
{
	

	//element = eval( "document.Form." + fieldName );

	element = eval(fieldName);
	//alert(element)
	if( element.selectedIndex <= 0 )
    {
		alert("Please select a valid option for " + msg );
       // eval( "document.Form." + fieldName + ".focus();" );
	      element.focus();
        return false;
	}
    return true;
}

function validSelectInch(feildName, msg)
{
		 element                =    eval(feildName);//    eval( "document.Form." + feildName );
        if( element.selectedIndex <= 0 )
        {
                alert("Please select a Inch for Spring Length" );
                element.focus();
                return false;
        }
        return true;
}


function validText(fieldName, fieldValue, msg,decallowed)
{
	if(decallowed !='0')
	{
		decallowed   =   2;
	}
    
	if (isNaN(fieldValue) || fieldValue == "")
    {
		if(fieldValue == "")
		{
			if(fieldName=="Springsalonglength" || fieldName=="Springsalongwidth")
			{
				alert("When entering "+msg+". Please do not enter decimal points.");
			}
			else
			{
				alert("When entering "+msg+", please select fraction using pull down menu. Please do not enter decimal points.");
			}
		}
		else
		{
			if(fieldName=="Springsalonglength" || fieldName=="Springsalongwidth")
			{
				alert("Please enter numeric value for "+msg+". Please do not enter decimal points.");
			}
			else
			{
				alert("Please enter numeric value for "+msg+", please select fraction using pull down menu. Please do not enter decimal points.");
			}
		}
		
		
		eval( "document.Form." + fieldName + ".value='';" );
        eval( "document.Form." + fieldName + ".focus();" );
        return false;
	}
    else
    {
		if (fieldValue.indexOf('.') == -1)
		{
			fieldValue += ".";
		}

		dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);

        if (dectext.length > decallowed)
        {
			if(fieldName=="Springsalonglength" || fieldName=="Springsalongwidth")
			{
				alert("When entering "+msg+". Please do not enter decimal points.");
			}
			else
			{
				alert("When entering "+msg+", please select fraction using pull down menu. Please do not enter decimal points.");
			}
			
			eval( "document.Form." + fieldName + ".value='';" );
			eval( "document.Form." + fieldName + ".focus();" );
			return false;
		}
	}
    if (fieldValue<=0)
    {
		alert("Please enter value greater than '0' for "+msg+".");
		eval( "document.Form." + fieldName + ".value='';" );
        eval( "document.Form." + fieldName + ".focus();" );
        return false;
	}
    return true;
}

img1 = new Image;
img1.src="./images/rect_frame_normal.gif";

img2 = new Image;
img2.src="./images/rect_frame_w_diagonal.gif";

img3 = new Image;
img3.src="./images/rect_frame_diagonal.gif";

img4 = new Image;
img4.src="./images/rect_frame_crowded.gif";

function valid(fieldName, fieldValue,msg) 
{
	decallowed = 2;  // how many decimals are allowed?
	if (isNaN(fieldValue) || fieldValue == "")
	{
		if(fieldName=="Springsalonglength" || fieldName=="Springsalongwidth")
			alert("When entering "+msg+". Please do not enter decimal points.");
		else
			alert("When entering "+msg+", please select fraction using pull down menu. Please do not enter decimal points.");
//		alert("Please enter a valid decimal number for "+msg+".");
		return false;
	}
	else
	{
		if (fieldValue.indexOf('.') == -1) fieldValue += ".";
		dectext = fieldValue.substring(fieldValue.indexOf('.')+1, fieldValue.length);
		if (dectext.length > decallowed)
		{
		if(fieldName=="Springsalonglength" || fieldName=="Springsalongwidth")
			alert("When entering "+msg+". Please do not enter decimal points.");
		else
			alert("When entering "+msg+", please select fraction using pull down menu. Please do not enter decimal points.");
//			alert ("Please enter a valid decimal number up to " + decallowed + " decimal places for "+msg+".");
			return false;
		}
	}
}
//  End -->
function getpid(form, allow, cartQty, pid, btnval)
{
	var frmObj  =  eval( "document." + form );
	var btn;
	frmObj.btn.value = btnval.value;
	if(btnval.value=="View Cart")
	{
		if(cartQty==0)
		{
			alert("Your shopping cart is currently empty");
			return false;
		}
		else
		{
			window.open("shopping_cart.php", "_self");
			return true;
		}
	}
	if(btnval.value=="Check Out")
    {
		qObj = form.all("quantity["+pid+"]");
        var pqty = qObj.value;
        if(allow==0 && pqty<0)
        {
			alert("Your shopping cart is currently empty");
            return false;
		}
	}
   
    if (!(document.Form.corner[0].checked)&& !(document.Form.corner[1].checked)&& !(document.Form.corner[2].checked)&& !(document.Form.corner[3].checked))
    {
		alert("Please select a corner configuration");
        document.Form.corner[0].focus();
        return false;
    }

	if (!(document.Form.chkroundmatselect[0].checked)&& !(document.Form.chkroundmatselect[1].checked))
    {
		alert("Please select measuring unit");
        document.Form.chkroundmatselect[0].focus();
        return false;
    }

	if (!(document.Form.chkroundmatselect[0].checked)&& !(document.Form.chkroundmatselect[1].checked))
    {
		alert("Please select measuring unit");
        document.Form.chkroundmatselect[0].focus();
        return false;
    }
	
	if (document.Form.chkroundmatselect[0].checked == true)
	{
		if (!(document.Form.chkroundmatinchft[0].checked)&& !(document.Form.chkroundmatinchft[1].checked))
		{
			alert("Please select inches or feet");
			document.Form.chkroundmatinchft[0].focus();
			return false;
		}
	}

	if (document.Form.Length1.value >230)
    {
		window.open ('maxFrameLength.php','Popup','HEIGHT=287,WIDTH=417,screenX=20,screenY=5,status=no,scrollbars=no,toolbar=no,directories=no,menubar=no,location=no,left=150,top=225');
        return false;
	}

    if( !check_vars(pid, form ) )
		return false;
    else
        return false;
}
function round_decimals(original_number, decimals) 
{
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}
function pad_with_zeros(rounded_value, decimal_places) 
{
    // Convert the number to a string
    var value_string = rounded_value.toString()
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")
    // Is there a decimal point?
    if (decimal_location == -1) 
	{
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else 
	{
        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    if (pad_total > 0) 
	{
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++)
            value_string += "0"
	}
    return value_string
}

function calPrice_new(pPrice, currency, cur_sign, cur_charges)
{
	cur_charges = cur_charges/100;
	customPrice = new Array(3)
	customPrice["10"]=109.95;
	customPrice["12"]=10;
	customPrice["14"]=35;

	optProd = new Array(5)
	optProd["solidBlackNormal"]=0
	optProd["solidBlackPerformance"]=9.95
	optProd["blue"] = 9.95
	optProd["green"] = 9.95
	optProd["tan"]=9.95
	optProd["purple"]=9.95
	optProd["4-check"]=29.95
	optProd["half_half"]=19.95
	optProd["targeted"]=29.95
	optProd["sunShield"]=29.95
	optProd["taupe"] = 29.95
	optProd["white"] = 29.95
	optProd["irishgreen"]=29.95
	optProd["none"]=0


	var totPrice = document.Form.orignalPrice.value;
	//alert(totPrice);
	var mesunit = 0

	if (eval(document.Form.Length1.value) > eval(document.Form.Width1.value))
	{
		mesunit = document.Form.Length1.value;
	}
	else
	{
		mesunit = document.Form.Width1.value;
	}
	

	if ((mesunit>0) && (mesunit<=150))
	{
		totPrice= totPrice;
	}
	if ((mesunit>150) && (mesunit<=180))
	{
		/*totPrice= customPrice["12"];
		totPrice= totPrice*currency;*/
		//totPrice= totPrice + totPrice*.02;
		extraPrice = customPrice["12"];
		extraPrice= parseFloat(extraPrice) + parseFloat(extraPrice*cur_charges);
		extraPrice= extraPrice*currency;
		totPrice= parseFloat(totPrice)+parseFloat(extraPrice);	


	}

	if ((mesunit>180) && (mesunit<=230))
	{
		/*totPrice= customPrice["14"];
		totPrice= totPrice*currency;*/
		//totPrice= totPrice + totPrice*.02;
		extraPrice= customPrice["14"];
		extraPrice= parseFloat(extraPrice) + parseFloat(extraPrice*cur_charges);
		extraPrice= extraPrice*currency;
		totPrice= parseFloat(totPrice)+parseFloat(extraPrice);
	}
	
	if(document.Form.Length1.value.length==0)
    {
		document.Form.txtPrice.value="(Enter Length)";
		document.Form.txtPricebottom.value="(Enter Length)";
		return false;
		
	}

	if(document.Form.Width1.value.length==0)
	{
		document.Form.txtPrice.value="(Enter measurements to calculate price.)";
		document.Form.txtPricebottom.value="(Enter measurements to calculate price.)";
		return false;
	}

	if(!(mesunit<=230 && mesunit>0))
	{
		document.Form.txtPrice.value="Call:1-800-241-7134";
		document.Form.txtPricebottom.value="Call:1-800-241-7134";
		return false;
	}

	if (document.Form.Fabric[0].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["solidBlackNormal"])*currency);
		var result1 = totPrice * Math.pow(10, 2)
		var result2 = Math.round(result1)
		var totPrice = result2 / Math.pow(10, 2)
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}

	if (document.Form.Fabric[1].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["solidBlackPerformance"])*currency+parseFloat(optProd["solidBlackPerformance"])*currency*cur_charges);
		var result1 = totPrice * Math.pow(10, 2)
		var result2 = Math.round(result1)
		var totPrice = result2 / Math.pow(10, 2)
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}
	if (document.Form.Fabric[2].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["blue"])*currency+parseFloat(optProd["blue"])*currency*cur_charges);
		var result1 = totPrice * Math.pow(10, 2)
		var result2 = Math.round(result1)
		var totPrice = result2 / Math.pow(10, 2)
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}
	if (document.Form.Fabric[3].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["green"])*currency+parseFloat(optProd["green"])*currency*cur_charges);
		var result1 = totPrice * Math.pow(10, 2)
		var result2 = Math.round(result1)
		var totPrice = result2 / Math.pow(10, 2)
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}
/*
	if (document.Form.Fabric[4].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["tan"])*currency+parseFloat(optProd["tan"])*currency*cur_charges);
		var result1 = totPrice * Math.pow(10, 2)
		var result2 = Math.round(result1)
		var totPrice = result2 / Math.pow(10, 2)
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;

	}
*/
	if (document.Form.Fabric[4].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["purple"])*currency+parseFloat(optProd["purple"])*currency*cur_charges);
		var result1 = totPrice * Math.pow(10, 2)
		var result2 = Math.round(result1)
		var totPrice = result2 / Math.pow(10, 2)
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}

	if (document.Form.Fabric[5].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["half_half"])*currency+parseFloat(optProd["half_half"])*currency*cur_charges);
		var result1 = totPrice * Math.pow(10, 2)
		var result2 = Math.round(result1)
		var totPrice = result2 / Math.pow(10, 2)
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}

	if (document.Form.Fabric[6].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["targeted"])*currency+parseFloat(optProd["targeted"])*currency*cur_charges);
		var result1 = totPrice * Math.pow(10, 2)
		var result2 = Math.round(result1)
		var totPrice = result2 / Math.pow(10, 2)
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}
	 if (document.Form.Fabric[7].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["4-check"])*currency+parseFloat(optProd["4-check"])*currency*cur_charges);
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}

	if (document.Form.UVProtection[0].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["none"])*currency+parseFloat(optProd["none"])*currency*cur_charges);
		var result1 = totPrice * Math.pow(10, 2)
		var result2 = Math.round(result1)
		var totPrice = result2 / Math.pow(10, 2)
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}
	if (document.Form.UVProtection[1].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["sunShield"])*currency+parseFloat(optProd["sunShield"])*currency*cur_charges);
		var result1 = totPrice * Math.pow(10, 2)
		var result2 = Math.round(result1)
		var totPrice = result2 / Math.pow(10, 2)
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}
	if (document.Form.UVProtection[2].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["sunShield"])*currency+parseFloat(optProd["sunShield"])*currency*cur_charges);
		var result1 = totPrice * Math.pow(10, 2)
		var result2 = Math.round(result1)
		var totPrice = result2 / Math.pow(10, 2)
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}

	if (document.Form.UVProtection[3].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["white"])*currency+parseFloat(optProd["white"])*currency*cur_charges);
		var result1 = totPrice * Math.pow(10, 2)
		var result2 = Math.round(result1)
		var totPrice = result2 / Math.pow(10, 2)
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}
	if (document.Form.UVProtection[4].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["taupe"])*currency+parseFloat(optProd["taupe"])*currency*cur_charges);
		var result1 = totPrice * Math.pow(10, 2)
		var result2 = Math.round(result1)
		var totPrice = result2 / Math.pow(10, 2)
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}

	if (document.Form.UVProtection[5].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["irishgreen"])*currency+parseFloat(optProd["irishgreen"])*currency*cur_charges);
		var result1 = totPrice * Math.pow(10, 2)
		var result2 = Math.round(result1)
		var totPrice = result2 / Math.pow(10, 2)
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}

	var MID = document.Form.MID.value;

	var form = document.Form;
	qObj = document.all("quantity["+MID+"]");
	var pqty = qObj.value;	
	
	if(pqty == '')
	{
		pqty = 1;
	}	
	//document.Form.txtPrice.value = cur_sign+""+round_decimals((document.Form.txtPrice.value * currency), 2);

	document.Form.txtPrice.value = cur_sign+" "+round_decimals((totPrice * pqty), 2);
    document.Form.txtPricebottom.value = cur_sign+" "+round_decimals((totPrice * pqty), 2);
}


function calPrice(pPrice, currency, cur_sign)
{
	customPrice = new Array(3)
	customPrice["10"]=109.95
	customPrice["12"]=119.95
	customPrice["14"]=144.95

	optProd = new Array(5)
	optProd["solidBlackNormal"]=0
	optProd["solidBlackPerformance"]=9.95
	optProd["blue"] = 9.95
	optProd["green"] = 9.95
	optProd["tan"]=9.95
	optProd["purple"]=9.95
	optProd["4-check"]=29.95
	optProd["half_half"]=19.95
	optProd["targeted"]=29.95
	optProd["sunShield"]=29.95
	optProd["taupe"] = 29.95
	optProd["white"] = 29.95
	optProd["irishgreen"]=29.95
	optProd["none"]=0

	var totPrice = pPrice;
	var mesunit = 0

	if (eval(document.Form.Length1.value) > eval(document.Form.Width1.value))
	{
		mesunit = document.Form.Length1.value;
	}
	else
	{
		mesunit = document.Form.Width1.value;
	}
	

	if ((mesunit>0) && (mesunit<=150))
	{
		totPrice= customPrice["10"];
	}
	if ((mesunit>150) && (mesunit<=180))
	{
		totPrice= customPrice["12"];
	}

	if ((mesunit>180) && (mesunit<=230))
	{
		totPrice= customPrice["14"];
	}
	
	if(document.Form.Length1.value.length==0)
    {
		document.Form.txtPrice.value="(Enter Length)";
		document.Form.txtPricebottom.value="(Enter Length)";
		return false;
		
	}

	if(document.Form.Width1.value.length==0)
	{
		document.Form.txtPrice.value="(Enter measurements to calculate price.)";
		document.Form.txtPricebottom.value="(Enter measurements to calculate price.)";
		return false;
	}

	if(!(mesunit<=230 && mesunit>0))
	{
		document.Form.txtPrice.value="Call:1-800-241-7134";
		document.Form.txtPricebottom.value="Call:1-800-241-7134";
		return false;
	}

	if (document.Form.Fabric[0].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["solidBlackNormal"]));
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}

	if (document.Form.Fabric[1].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["solidBlackPerformance"]));
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}
	if (document.Form.Fabric[2].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["blue"]));
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}
	if (document.Form.Fabric[3].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["green"]));
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}
/*
	if (document.Form.Fabric[4].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["tan"]));
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;

	}
*/
	if (document.Form.Fabric[4].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["purple"]));
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}

	if (document.Form.Fabric[5].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["half_half"]));
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}

	if (document.Form.Fabric[6].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["targeted"]));
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}

	if (document.Form.Fabric[7].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["4-check"]));
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}

	if (document.Form.UVProtection[0].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["none"]));
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}
	if (document.Form.UVProtection[1].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["sunShield"]));
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}
	if (document.Form.UVProtection[2].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["sunShield"]));
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}

	if (document.Form.UVProtection[3].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["white"]));
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}

	if (document.Form.UVProtection[4].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["taupe"]));
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}

	if (document.Form.UVProtection[5].checked==true)
	{
		totPrice =(parseFloat(totPrice)+parseFloat(optProd["irishgreen"]));
		document.Form.txtPrice.value=totPrice;
		document.Form.txtPricebottom.value=totPrice;
	}

	var MID = document.Form.MID.value;

	var form = document.Form;
	qObj = document.all("quantity["+MID+"]");
	var pqty = qObj.value;	
	if(pqty == '')
	{
	pqty = 1;
	}	
	//document.Form.txtPrice.value = cur_sign+""+round_decimals((document.Form.txtPrice.value * currency), 2);

	document.Form.txtPrice.value = cur_sign+""+round_decimals((document.Form.txtPrice.value * currency * pqty), 2);
    document.Form.txtPricebottom.value = cur_sign+""+round_decimals((document.Form.txtPricebottom.value * currency * pqty), 2);
}

function MM_openBrWindow(site,target,para)
{
	window.open(site,target,para);
}
function mat_options_PopUp(fabric, width, height)
{
    window.open("mat_options.php?type="+fabric+"", "Mat_Options", "toolbar=no, menubar=no, width="+width+", height="+height+", status=no, scrollbars=yes", false)
}
