function FormVal(form)
{

//	var form = eval("document."+form);
//alert(form)



	if(form.pcolor.options[form.pcolor.selectedIndex].value == '')
	{
		alert("Please select color");
		form.pcolor.focus();
		return false;
	}
	
	if(form.ptype.options[form.ptype.selectedIndex].value == '')
	{
		alert("Please select type");
		form.ptype.focus();
		return false;
	}
	
	if(form.width.length == undefined)
	{
		if(form.width.checked == false)
		{
			alert("Please select width");
			form.width.focus();
			return false;
		}
	}
	else
	{		
		var checkFlag = '0';
		
		for(var i=0;i<form.width.length;i++)
		{
		
			if(form.width[i].checked == true)
			{
				checkFlag = '1';			
			}
		}

		if(checkFlag == '0')
		{
			alert("Please select width");
			form.width[0].focus();
			return false;
		}
	}

	if (form.pquantity.value=="" || form.pquantity.value==0)
	{
		alert ("Enter quantity to view price");

		if (form.pquantity.value==0)		{		form.pquantity.value = '';		}

		form.pquantity.focus();						return false;
	}
	if (!(form.pquantity.value <= 99999 && form.pquantity.value >= 0))
	{
		alert("Please enter a numeric value for quantity");				form.pquantity.focus();

		form.pquantity.value = '';										return false;
	}
	if (form.pquantity.value < 3)
	{
		alert("Please order at least 3 linear yards");					form.pquantity.value = '';

		form.pquantity.focus();											return false;
	}

	if(checkDotIndex(form.pquantity.value)==true)
	{
		alert("Invalid Quantity");					form.pquantity.value = '';

		form.pquantity.focus();											return false;
	}
	return true;
}

function checkDotIndex(objValue)
{
	var indexValue =objValue.indexOf(".");	
	
	if (indexValue != -1)
	{		
		return true;
	}
	else
	{
		return false;
	}
}

function FormVal1(form)
{
	if (form.pquantity.value=="")
	{
		alert ("Enter quantity to view price");		form.pquantity.focus();				return false;
	}
	if (!(form.pquantity.value <= 99999))
	{
		alert("Please enter a numeric value for quantity");			form.pquantity.focus();			return false;
	}
	return true;
}


function changeColor(form)
{
	for(var i=0;i<form.width.length;i++)
	{
		form.width[i].checked = false;		
	}
	
	form.pquantity.value='';
	
	form.ptype.options[0].selected = true;
	
	document.getElementById("pquantity").disabled = true;
	document.getElementById("width1").disabled = true;
	document.getElementById("width2").disabled = true;
	
	if(form.pcolor.options[form.pcolor.selectedIndex].value == '')
	{
		document.getElementById("ptype").disabled = true;
	}
	else
	{
		document.getElementById("ptype").disabled = false;
	}



}
function changeType(form)
{
	for(var i=0;i<form.width.length;i++)
	{
		form.width[i].checked = false;		
	}
	form.pquantity.value='';
	document.getElementById("pquantity").disabled = true;
	
	if(form.ptype.options[form.ptype.selectedIndex].value == '')
	{
		document.getElementById("width1").disabled = true;
		document.getElementById("width2").disabled = true;
	}
	else
	{		
		document.getElementById("width1").disabled = false;
		document.getElementById("width2").disabled = false;
	}
}
function changeWidth(form)
{	
	document.getElementById("pquantity").disabled = false;
}


function calPrice(form)
{
	totPrice = 0;
	optProd  = new Array(5)
	optProd["black1"] = 16.29;	
	optProd["black2"] = 17.39;
	optProd["blue1"] = 18.26;
	optProd["blue2"] = 19.38;	
	optProd["green1"] = 18.26;
	optProd["green2"] = 19.38;
	optProd["purple1"] = 18.26;	
	optProd["purple2"] = 19.38;	
	optProd["tan1"] = 18.26;
	optProd["tan2"] = 19.38;	
	optProd["grey1"] = 18.26;	
	optProd["grey2"] = 19.38;
	optProd["white1"] = 19.38;	
	optProd["white2"] = 20.50;	
	optProd["rblue1"] = 19.38;
	optProd["rblue2"] = 20.50;
	optProd["champagne1"] = 19.38;
	optProd["champagne2"] = 20.50;

	qty = form.pquantity.value;

	color = document.Form.pcolor.options[document.Form.pcolor.selectedIndex].value;

	//if(color=="0")	{		alert('Please select Color');	}

	if(qty > 0 && !isNaN(qty) && color!="0")
	{
		if (form.width[0].checked==true)
		{
			if(color == "Black")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["black1"])), 2);
			}
			else if(color == "Deep Blue")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["blue1"])), 2);
			}
			else if(color == "Forest Green")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["green1"])), 2);
			}
			else if(color == "Plum Purple")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["purple1"])), 2);
			}
			else if(color == "Pecan Tan")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["tan1"])), 2);
			}
			else if(color == "Grey")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["grey1"])), 2);
			}
			else if(color == "White")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["white1"])), 2);
			}
			else if(color == "Royal Blue")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["rblue1"])), 2);
			}
			else if(color == "Champagne")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["champagne1"])), 2);
			}

			document.Form.txtPrice.value="$ "+totPrice;
		}
		if (form.width[1].checked==true)
		{
			if(color == "Black")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["black2"])), 2);
			}
			else if(color == "Deep Blue")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["blue2"])), 2);
			}
			else if(color == "Forest Green")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["green2"])), 2);
			}
			else if(color == "Plum Purple")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["purple2"])), 2);
			}
			else if(color == "Pecan Tan")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["tan2"])), 2);
			}
			else if(color == "Grey")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["grey2"])), 2);
			}
			else if(color == "White")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["white2"])), 2);
			}
			else if(color == "Royal Blue")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["rblue2"])), 2);
			}
			else if(color == "Champagne")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["champagne2"])), 2);
			}
			document.Form.txtPrice.value="$ "+totPrice;
		}
	}
}

function calPrice_new(form, currency, cur_sign, cur_charges)
{
//alert("charges->"+cur_charges+"currency->"+currency+"sign->"+cur_sign);
	totPrice = 0;
	optProd  = new Array(5)
	optProd["black1"] = 16.58;	
	optProd["black2"] = 17.70;
	optProd["blue1"] = 16.30;
	optProd["blue2"] = 17.30;	
	optProd["green1"] = 16.30;
	optProd["green2"] = 17.30;
	optProd["purple1"] = 16.30;	
	optProd["purple2"] = 17.30;	
	optProd["tan1"] = 16.30;
	optProd["tan2"] = 17.30;	
	optProd["grey1"] = 16.30;	
	optProd["grey2"] = 17.30;
	optProd["white1"] = 17.30;	
	optProd["white2"] = 18.30;	
	optProd["rblue1"] = 17.30;
	optProd["rblue2"] = 18.30;
	optProd["champagne1"] = 17.30;
	optProd["champagne2"] = 18.30;

	qty = form.pquantity.value;

	color = document.Form.pcolor.options[document.Form.pcolor.selectedIndex].value;

	//if(color=="0")	{		alert('Please select Color');	}

	if(qty > 0 && !isNaN(qty) && color!="0")
	{
		if (form.width[0].checked==true)
		{
			if(color == "Black")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["black1"])*currency*cur_charges), 2);
				
			}
			else if(color == "Deep Blue")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["blue1"])*currency*cur_charges), 2);
			}
			else if(color == "Forest Green")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["green1"])*currency*cur_charges), 2);
			}
			else if(color == "Plum Purple")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["purple1"])*currency*cur_charges), 2);
			}
			else if(color == "Pecan Tan")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["tan1"])*currency*cur_charges), 2);
			}
			else if(color == "Grey")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["grey1"])*currency*cur_charges), 2);
			}
			else if(color == "White")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["white1"])*currency*cur_charges), 2);
			}
			else if(color == "Royal Blue")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["rblue1"])*currency*cur_charges), 2);
			}
			else if(color == "Champagne")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["champagne1"])*currency*cur_charges), 2);
			}

			document.Form.txtPrice.value=cur_sign+" "+totPrice;
		}
		if (form.width[1].checked==true)
		{
			if(color == "Black")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["black2"])*currency*cur_charges), 2);
			}
			else if(color == "Deep Blue")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["blue2"])*currency*cur_charges), 2);
			}
			else if(color == "Forest Green")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["green2"])*currency*cur_charges), 2);
			}
			else if(color == "Plum Purple")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["purple2"])*currency*cur_charges), 2);
			}
			else if(color == "Pecan Tan")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["tan2"])*currency*cur_charges), 2);
			}
			else if(color == "Grey")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["grey2"])*currency*cur_charges), 2);
			}
			else if(color == "White")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["white2"])*currency*cur_charges), 2);
			}
			else if(color == "Royal Blue")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["rblue2"])*currency*cur_charges), 2);
			}
			else if(color == "Champagne")
			{
				totPrice = round_decimals((parseFloat(qty) * parseFloat(optProd["champagne2"])*currency*cur_charges), 2);
			}
			document.Form.txtPrice.value=cur_sign+" "+totPrice;
		}
	}
}

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 get_price(form)
{
	pcol = document.Form.pcolor.value;
	
	widthObj = document.Form.width;
	if(widthObj[0].checked)
		size = widthObj[0].value;
	else
		size = widthObj[1].value;

	qty = document.Form.pquantity.value;

	var whereToWrite = "tram_fabric"; 
	
	var strVariables = 'action=fabric_price&color='+color+'&size='+size+'&qty='+qty;
//	alert(strVariables);
	makeRequest('ajax_function.php?'+strVariables, whereToWrite);
	
}