
img1 = new Image;
img1.src="./images/rect_pad1.jpg";
img2 = new Image;
img2.src="./images/rect_pad2.jpg";
img3 = new Image;
img3.src="./images/rect_pad3.jpg";

function contactUsOct()
{
	window.open("Popup.php?pad=octa", "big", "toolbar=no, menubar=no, resize=true, width=423, height=391, scrollbars=yes");
}

function valid(fieldName, fieldValue,msg)
{
	  //alert ("DFG");
	decallowed = 2;  // how many decimals are allowed?
    if (isNaN(fieldValue) || fieldValue == "")
    {
		alert("Please enter a valid decimal number for "+msg+".");
		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)
		{
			alert ("Please enter a valid decimal number up to " + decallowed + " decimal places for "+msg+".");
			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;
}
//  End -->
function getpid(formName,allow,cartQty,btnval)
{
	var frmObj  =  eval( "document." + formName );
	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")
	{
		var pqty = eval(frmObj.pquantity.value);
		if(allow==0 && pqty<0)
		{
			alert("Your shopping cart is currently empty");
			return false;
		}
	}
    if (!(frmObj.corner[0].checked) && !(document.Form.corner[1].checked) && !(document.Form.corner[2].checked))
    {
        alert("Please select a frame type");
        document.Form.corner[0].focus();
        return false;
    }
   
	/*if(document.Form.widthtoedge.value.length==0)
    {
	    document.Form.txtPrice.value="(Enter Width)";
		alert("Enter Width");
		document.Form.widthtoedge.focus();
		return false;
    }
    if(document.Form.lengthtoedge.value.length==0)
	{
	    document.Form.txtPrice.value="(Enter Length)";
		alert("Enter Length");
		document.Form.lengthtoedge.focus();
		return false;
    }
*/
    if(valid("widthtoedge", frmObj.widthtoedge.value,"Mat width at fabric edge")==false)
    {
	    frmObj.widthtoedge.focus();
		return false;
    }

    if(valid("lengthtoedge", frmObj.lengthtoedge.value,"Mat length at fabric length")==false)
    {
	    frmObj.lengthtoedge.focus();
	    return false;
    }

    if(valid("alonglength", frmObj.alonglength.value,"Fabric to outside of main frame (along length)")==false)
    {
		frmObj.alonglength.focus();
	    return false;
    }

    if(valid("alongend", frmObj.alongend.value,"Fabric to outside of main frame (along end)")==false)
    {
		frmObj.alongend.focus();
	    return false;
    }

    if(frmObj.lengthtoedge.value>180)
    {
		alert("Call us on :1-800-241-7134 for longer lengths");
		return false;
    }

	if (frmObj.pquantity.value=="" || frmObj.pquantity.value==0)
    {
        alert ("Please enter quantity!");
		frmObj.pquantity.value='';
        frmObj.pquantity.focus();
        return false;
    }

    if (!(frmObj.pquantity.value <= 99999 && frmObj.pquantity.value >= 0))
    {
        alert("Please enter a numeric value for quantity");
		frmObj.pquantity.value='';
        frmObj.pquantity.focus();
        return false;
    }
    //      document.Form.submit();
	return true;
}
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(pPrice)
{
	var Quantity = document.Form.pquantity.value;
	var totPrice = pPrice;
	var stndsize;
	standardsize = new Array(4)
	standardsize["1"]= "5 X 10";
	standardsize["2"]= "5 X 11";
	standardsize["3"]= "6 X 12";
	standardsize["4"]= "7 X 14";

	customPrice = new Array(12)
	customPrice["11"] = 209.95
	customPrice["12"] = 219.95
	customPrice["13"] = 219.95
	customPrice["14"] = 229.95

	customPrice["21"] = 229.95
	customPrice["22"] = 234.95
	customPrice["23"] = 239.95
	customPrice["24"] = 249.95

	customPrice["31"] = 239.95
	customPrice["32"] = 244.95
	customPrice["33"] = 249.95
	customPrice["34"] = 259.95

  if(document.Form.corner[0].checked)
  {

    if ((document.Form.lengthtoedge.value>0) && (document.Form.lengthtoedge.value<=126))
    {
     totPrice= customPrice["11"];
     stndsize = standardsize["1"];

    }
    if ((document.Form.lengthtoedge.value>126) && (document.Form.lengthtoedge.value<=138))
    {
     totPrice= customPrice["12"];
     stndsize = standardsize["2"];
    }
     if ((document.Form.lengthtoedge.value>138) && (document.Form.lengthtoedge.value<=150))
    {
     totPrice= customPrice["13"];
     stndsize = standardsize["3"];
    }
    if ((document.Form.lengthtoedge.value>150) && (document.Form.lengthtoedge.value<=180))
    {
     totPrice= customPrice["14"];
     stndsize = standardsize["4"];
    }
    else if(document.Form.lengthtoedge.value>180)
    {
     document.Form.txtPrice.value="Call:1-800-241-7134";
     return false;
    }
  }
  else if(document.Form.corner[1].checked)
  {
   if ((document.Form.lengthtoedge.value>0) && (document.Form.lengthtoedge.value<=126))
    {
     totPrice= customPrice["21"];
     stndsize = standardsize["1"];
    }
    if ((document.Form.lengthtoedge.value>126) && (document.Form.lengthtoedge.value<=138))
    {
     totPrice= customPrice["22"];
     stndsize = standardsize["2"];
    }
     if ((document.Form.lengthtoedge.value>138) && (document.Form.lengthtoedge.value<=150))
    {
     totPrice= customPrice["23"];
     stndsize = standardsize["3"];
    }
    if ((document.Form.lengthtoedge.value>156) && (document.Form.lengthtoedge.value<=180))
    {
     totPrice= customPrice["24"];
     stndsize = standardsize["4"];
    }
    else if(document.Form.lengthtoedge.value>180)
    {
     document.Form.txtPrice.value="Call:1-800-241-7134";
     return false;
    }
  }
  else if(document.Form.corner[2].checked)
  {
    if ((document.Form.lengthtoedge.value>0) && (document.Form.lengthtoedge.value<=126))
    {
     totPrice= customPrice["31"];
     stndsize = standardsize["1"];
    }
    if ((document.Form.lengthtoedge.value>126) && (document.Form.lengthtoedge.value<=138))
    {
     totPrice= customPrice["32"];
     stndsize = standardsize["2"];
    }
     if ((document.Form.lengthtoedge.value>138) && (document.Form.lengthtoedge.value<=150))
    {
     totPrice= customPrice["33"];
     stndsize = standardsize["3"];
    }
    if ((document.Form.lengthtoedge.value>156) && (document.Form.lengthtoedge.value<=180))
    {
     totPrice= customPrice["34"];
     stndsize = standardsize["4"];
    }
     else if(document.Form.lengthtoedge.value>180)
    {
     document.Form.txtPrice.value="Call:1-800-241-7134";
     return false;
    }
  }
  else
  {
     document.Form.txtPrice.value = "Please Select a frame type";
     return false;
  }
   if (document.Form.coloropt[1].checked==true)
   {
     totPrice =(parseFloat(totPrice)+parseFloat("10"));
     document.Form.txtPrice.value=totPrice;
   }
   if (document.Form.coloropt[0].checked==true)
   {
     totPrice =(parseFloat(totPrice)+parseFloat("0"));
     document.Form.txtPrice.value=totPrice;
   }
   document.Form.txtPrice.value = "$"+round_decimals((document.Form.txtPrice.value * Quantity), 2);
   document.Form.txtmatsize.value = stndsize;
}