function formsubmit(formName,allow,cartQty,btnval)
{

	var form = eval("document."+formName);
	
//	form.quantity.value = form.pquantity.value;
	
	var btn;
	form.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_curr.php", "_self");
			return true;
		}
	}
	if(btnval.value=="Check Out")
	{
		var newqty = eval(eval(form.pquantity.value)+eval(cartQty));
		if((allow==0) && (newqty < 10))
		{
			alert("Either you have ordered less than 10 springs or your shopping cart is empty");
			return false;
		}
	}
	if ((form.pidxx[form.pidxx.selectedIndex].value) <= 0)
	{
		alert ("Please choose the model!!!");
		return false;
	}
	if (form.pquantity.value=="" || form.pquantity.value==0)
	{
		alert ("Please enter quantity");
		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.value="";
		form.pquantity.focus();
		return false;
	}

	if (form.pquantity.value.indexOf(".") > -1)
	{
		//alert("Invalid Quantity");
		alert("Please enter quantity in whole numbers"); 
		form.pquantity.value="";
		form.pquantity.focus();
		return false;
	}

	if(checkBack() == true)
		return true;
	else
		return false;
		

	var i;
	var jj=0;
	var mainStr=form.bpid.value;
	var findStr=(form.pidxx[form.pidxx.selectedIndex].value);
	var cntmainstr = mainStr.split(",");
	for(i=0;i<(cntmainstr.pid);i++)
	{
		var cnt = eval("cntmainstr["+i+"]");
		if(cnt==findStr)
		{
			jj++;
		}
	}
	if (jj > 0)
	{
		return true;
     //window.open ('bkorderspringpopup.php?frmname='+formName,'Popup','HEIGHT=280,WIDTH=416,screenX=60,screenY=50,status=no,scrollbars=no,toolbar=no,directories=no,menubar=no,location=no,left=150,top=205');
	}
	else
	{
		return true;
		eval("document."+formName+".submit()");
	}
	return false;
}
function newcalPrice(form, currency, cur_sign)
{
	//alert ("ok");
	var totPrice = 0;
	var enteredQuantity = 0;
	
	if (isNaN(form.quantity.value))
	{
		enteredQuantity = 0;
	}
    else 
	{
		enteredQuantity =eval(form.quantity.value);
	}
	
	

    var dispPrice = 0 ;
    //newprice = form.newprice.value;
	var newprice = document.getElementById('newprice').value;
    //newqty = form.newqty.value;
	var newqty = document.getElementById('newqty').value;

    Qty = newqty.split(",");
    Price = newprice.split(",");
	
	//alert(Qty[0]);	return false;
	if (!(enteredQuantity>0 && enteredQuantity<9999))
    {
		totPrice = ("Enter quantity to view price");
        dispPrice = ("");
	}
	
	if (enteredQuantity ==0)
	{
		alert("Invalid quantity!!!");
		document.form.pquantity.value='';
		return false;
	}
    if (enteredQuantity=="")
	{
		totPrice= newprice;
        dispPrice = ("");
	}
	if (isNaN(enteredQuantity))
	{
		totPrice= newprice;
        dispPrice = ("Enter valid quantity to view price");
	}
	
	if(enteredQuantity != undefined)
	{
		if (enteredQuantity > 0 && enteredQuantity<Qty[1])
		{
			//	totPrice= (Price[0]+" X "+enteredQuantity+" = $");	//       dispPrice = (Price[0]*enteredQuantity);

			var tprice = round_decimals(parseFloat(Price[0] * currency), 2);
			totPrice= (cur_sign+""+tprice+" X "+enteredQuantity+" = "+cur_sign);
			dispPrice = (Price[0]*enteredQuantity) * currency;

		}
		if ((enteredQuantity>=Qty[1]) && (enteredQuantity<Qty[2]))
		{
			//	totPrice= (Price[1]+" X "+enteredQuantity+" = $");	//        dispPrice = (Price[1]*enteredQuantity);

			var tprice = round_decimals(parseFloat(Price[1] * currency), 2);
			totPrice= (cur_sign+""+tprice+" X "+enteredQuantity+" = "+cur_sign);
			dispPrice = (Price[1]*enteredQuantity) * currency;
		}
		if (enteredQuantity>=(Qty[2]))
		{
			//	totPrice= (Price[2]+" X "+enteredQuantity+" = $");		//		dispPrice = (Price[2]*enteredQuantity);

			var tprice = round_decimals(parseFloat(Price[2] * currency), 2);
			totPrice= (cur_sign+""+tprice+" X "+enteredQuantity+" = "+cur_sign);
			dispPrice = (Price[2]*enteredQuantity) * currency;
		}
		if(enteredQuantity > 0 && eval(form.pidxx.value)=="10.25")
		{		
			if(enteredQuantity < 51)
			{
				//alert("1");
				var tprice = round_decimals(parseFloat(2.99 * currency), 2);
				totPrice= (cur_sign+""+tprice+" X "+enteredQuantity+" = "+cur_sign);
				dispPrice = (2.99 * enteredQuantity) * currency;
			}
			if(enteredQuantity >50 && enteredQuantity < 91)
			{
				//alert("2");
				var tprice = round_decimals(parseFloat(2.49 * currency), 2);
				totPrice= (cur_sign+""+tprice+" X "+enteredQuantity+" = "+cur_sign);
				dispPrice = (2.49 * enteredQuantity) * currency;
			}
			if(enteredQuantity > 90)
			{	
				//alert("3");
				var tprice = round_decimals(parseFloat(1.99 * currency), 2);
				totPrice= (cur_sign+""+tprice+" X "+enteredQuantity+" = "+cur_sign);
				dispPrice = (1.99 * enteredQuantity) * currency;
			}
		}
		if ((form.pquantity.value)>0 && (form.pquantity.value)<=99999)
		{
			dispPrice=round_decimals(parseFloat(dispPrice), 2);
		}

		form.txtPrice.value=dispPrice;

		var decimal = form.txtPrice.value.indexOf('.');
		
		if(decimal!=-1)
		{
			form.txtPrice.value=totPrice+(form.txtPrice.value.substring(0, decimal+3));
		}
		else
		{
			form.txtPrice.value=totPrice + dispPrice;
		}
	}
	else
	{
		form.txtPrice.value = "Enter Quantity";
	}
		//	alert(form.txtPrice.value);	//		form.txtPrice.value = round_decimals(parseFloat(form.txtPrice.value), 2);
}


function newcalPrice1(form, currency, cur_sign)
{
	//alert(form+"cu"+currency+"si"+cur_sign);
	//alert('Hello');
	var totPrice = 0;
	var enteredQuantity = 0;
	if (isNaN(form.pquantity.value))
	{
		enteredQuantity = 0;
	}
    else 
	{
		enteredQuantity =eval(form.pquantity.value);
	}
	
	//alert(enteredQuantity);	return false;

    var dispPrice = 0 ;

    //alert (form.newprice.value);
	var newprice = document.getElementById('newprice').value;
    //alert (newprice);
	//newqty = form.newqty.value;
	var newqty = document.getElementById('newqty').value;
    Qty = newqty.split(",");
    Price = newprice.split(",");
	//alert("QTY"+Qty[2])
	//alert(Qty[0]);	return false;
	if (!(enteredQuantity>0 && enteredQuantity<9999))
    {
		totPrice = ("Enter quantity to view price");
        dispPrice = ("");
	}
	
	if (enteredQuantity ==0)
	{
		alert("Invalid quantity!!!");
		document.form.pquantity.value='';
		return false;
	}
    if (enteredQuantity=="")
	{
		totPrice= newprice;
        dispPrice = ("");
	}
	if (isNaN(enteredQuantity))
	{
		totPrice= newprice;
        dispPrice = ("Enter valid quantity to view price");
	}
	
	if(enteredQuantity != undefined)
	{
		if (enteredQuantity > 0 && enteredQuantity<Qty[1])
		{
			//	totPrice= (Price[0]+" X "+enteredQuantity+" = $");	//       dispPrice = (Price[0]*enteredQuantity);
			var tprice = round_decimals(parseFloat(Price[0]), 2);
			totPrice= (cur_sign+""+tprice+" X "+enteredQuantity+" = "+cur_sign);
			dispPrice = (Price[0]*enteredQuantity);

		}
		if ((enteredQuantity>=Qty[1]) && (enteredQuantity<Qty[2]))
		{
			//	totPrice= (Price[1]+" X "+enteredQuantity+" = $");	//        dispPrice = (Price[1]*enteredQuantity);

			var tprice = round_decimals(parseFloat(Price[1]), 2);
			totPrice= (cur_sign+""+tprice+" X "+enteredQuantity+" = "+cur_sign);
			dispPrice = (Price[1]*enteredQuantity);
		}
		if (enteredQuantity>=(Qty[2]))
		{
			//	totPrice= (Price[2]+" X "+enteredQuantity+" = $");		//		dispPrice = (Price[2]*enteredQuantity);

			var tprice = round_decimals(parseFloat(Price[2]), 2);
			totPrice= (cur_sign+""+tprice+" X "+enteredQuantity+" = "+cur_sign);
			dispPrice = (Price[2]*enteredQuantity);
		}
		if(enteredQuantity > 0 && eval(form.pidxx.value)=="10.25")
		{		
			if(enteredQuantity < 51)
			{
				//alert("1");
				var tprice = round_decimals(parseFloat(2.99 * currency + 2.99*.02), 2);
				totPrice= (cur_sign+""+tprice+" X "+enteredQuantity+" = "+cur_sign);
				dispPrice = (2.99 * enteredQuantity+2.99*.02) * currency;
				dispPrice = tprice*enteredQuantity;
				//alert(dispPrice);
			}
			if(enteredQuantity >50 && enteredQuantity < 91)
			{
				//alert("2");
				var tprice = round_decimals(parseFloat(2.49 * currency+2.49*.02), 2);
				totPrice= (cur_sign+""+tprice+" X "+enteredQuantity+" = "+cur_sign);
				dispPrice = (2.49 * enteredQuantity+2.49*.02) * currency;
				dispPrice = tprice*enteredQuantity;
			}
			if(enteredQuantity > 90)
			{	
				//alert("3");
				var tprice = round_decimals(parseFloat(1.99 * currency+1.99*.02), 2);
				totPrice= (cur_sign+""+tprice+" X "+enteredQuantity+" = "+cur_sign);
				dispPrice = (1.99 * enteredQuantity+1.99*.02) * currency;
				dispPrice = tprice*enteredQuantity;
			}
		}
		if ((form.pquantity.value)>0 && (form.pquantity.value)<=99999)
		{
			dispPrice=round_decimals(parseFloat(dispPrice), 2);
		}

		form.txtPrice.value=dispPrice;

		var decimal = form.txtPrice.value.indexOf('.');
		
		if(decimal!=-1)
		{
			form.txtPrice.value=totPrice+(form.txtPrice.value.substring(0, decimal+3));
		}
		else
		{
			form.txtPrice.value=totPrice + dispPrice;
		}
	}
	else
	{
		form.txtPrice.value = "Enter Quantity";
	}
		//	alert(form.txtPrice.value);	//		form.txtPrice.value = round_decimals(parseFloat(form.txtPrice.value), 2);
}
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 springBackOrder()
{
	var sizeObj = document.all('pidxx');
	var size = sizeObj.value;
	pid = 0;
//	alert(size)
	if(size.indexOf('|')>0)
	{
	var index1=size.indexOf('|');
	var size_new=size.substring(0,index1);
	var pid_new=size.substring(index1+1);
	size = size_new;
	pid = pid_new;
	}

	for (var i =0; i < document.form.elements.length; i++)
	{
		if (document.form.elements[i].type == 'text')
		{
			if(document.form.elements[i].name=='pquantity')
				var qty = document.form.elements[i].value;
		}
	}

	if(size > 0 && !isNaN(qty) && qty!="")
	{
		var strVariables = 'action=springBackorderDate&size='+size+'&qty='+qty+'&pid='+pid;
		var whereToDisp = "springDetail";
		makeRequest('ajax_function.php?'+strVariables, whereToDisp);
	
	}
}
var k=1;
var temp = 0;
function checkBack()
{
	//alert ("dd")
	var sizeObj = document.all('pidxx');
	
	size = sizeObj.value;
	if(size.indexOf('|') > 1)
	{
	var index1=size.indexOf('|');
	var size_new=size.substring(0,index1);
	size = size_new;
	}
	
	if(temp!=size)
	{
		temp=size;
		k=1;
	}
	var Obj = document.getElementById('springBack');
	var res = Obj.value;
	//alert (res)
	if(res=='0')
		return false;
	else if(res=='1')
		return true;
	else
	{
		if(k==1)
		{
			k=2;
			//alert(res);
			return true;
		}
		else
			return true;
	}
}

function UpdateSpringPrice(currSign, ttyp)
{

var qty = document.getElementById('springSizeID').value;
var size = document.getElementById('pidxx').value;

var url = 'springs_intl.php?qtySpr='+qty+'&size='+size+'&currSign='+currSign+'&ttyp='+ttyp;
req = false;
		if(window.XMLHttpRequest) {		// branch for native XMLHttpRequest object
			try {
				req = new XMLHttpRequest();
			} catch(e) {
				req = false;
			}
		}
		else if(window.ActiveXObject) {		// branch for IE/Windows ActiveX version
			try {
				req = new ActiveXObject("Msxml2.XMLHTTP");
			} catch(e) {
				try {
					req = new ActiveXObject("Microsoft.XMLHTTP");
				} catch(e) {
					req = false;
				}
			}
		}
		if(req)
		{
			req.onreadystatechange = showResultN;
			req.open("GET", url, true);
			req.send(null);
		}
}

function showResultN()
{ 
		if (req.readyState == 4) {
	            if (req.status == 200) {
				
	               	document.getElementById('SpringIntl').innerHTML=req.responseText;
	            } else {
	                alert('There was a problem with the request.');
	            }
	        }
			else if (req.readyState == 1)
	        {
								
	        		document.getElementById('SpringIntl').innerHTML = "";
				
	        }
}

