// JavaScript Document
function doRFQSubmit()
{
	var frm = document.forms[0];
	
	//check name
	if ( frm["Name"].value == "" )
	{
		alert( "Please enter your name" );
		frm["Name"].focus();
		return false
	}
	//check email or phone
	if ( !IsEmail( frm["Email"].value ) && !IsPhoneAdv( frm["Phone"].value ) )
	{
		alert( "Please enter your email address and/or your phone number" );
		frm["Email"].focus();
		return false;
	}
	
	frm.submit();
}

	function is_valid_char( char , valid_chars )
	{
		var x = 0;
		var fnd = false;
		
		for ( x in valid_chars )
		{
			if ( char == valid_chars[x] )
			{
				fnd = true;
			}
		}
		
		return fnd;
	}
	function CommaFormatted( amount )
	{
		var delimiter = ","; // replace comma if desired
		var a = amount.split('.',2)
		var d = a[1];
		var i = parseInt(a[0]);
		if(isNaN(i)) { return ''; }
		var minus = '';
		if(i < 0) { minus = '-'; }
		i = Math.abs(i);
		var n = new String(i);
		var a = [];
		while(n.length > 3)
		{
			var nn = n.substr(n.length-3);
			a.unshift(nn);
			n = n.substr(0,n.length-3);
		}
		if(n.length > 0) { a.unshift(n); }
		n = a.join(delimiter);
		if(d.length < 1) { amount = n; }
		else { amount = n + '.' + d; }
		amount = minus + amount;
		return amount;
	}
	function format_currency( amount )
	{
		amount = amount.toString();
		var mx = amount.length;
		var ValidChars = new Array(1,2,3,4,5,6,7,8,9,0,'.');
		var Result = "";
		var y = 0;
		
		for (var x = 0; x < mx; x++){
			y = x+1;
			if (is_valid_char(amount.substring(x,y),ValidChars)){
				Result = Result + "" + amount.substring(x,y);
			}
		}
		
		Result = 1*Result;
		Result = Result.toFixed(2);
		Result = CommaFormatted(Result);
		Result = "$ "+Result;
		return Result;
	}

	function disc( qty )
	{
		for ( var x = 0 ; x < arrDiscAmt.length ; x++ )
		{
			if ( qty >= arrDiscLow[ x ] && qty <= arrDiscHigh[ x ] )
			{
				return arrDiscPrice[ x ];
			}
		}
	
		return 0;
	}
	/*function disc( qty )
	{
		for ( var x = 0 ; x < arrDiscAmt.length ; x++ )
		{
			if ( qty >= arrDiscLow[ x ] && qty <= arrDiscHigh[ x ] )
			{
				var discount = arrDiscAmt[ x ];
				
				if ( discount > 1 )
				{
					discount = discount / 100;
				}
				
				return discount;
			}
		}
	
		return 0;
	}*/

	var arrPriceFilter = [];
	var arrFilterCarton = [];
	var arrPriceCarton = [];
	function calc_ttl( catid )
	{
		var frm = document.frmAddToCart;
		var qty = document.getElementById( "cartonqty_" + catid ).value;
		var discount_price_each = disc( qty );
		var price_each = frm["price_each_" + catid ].value;
		
		var full_price = price_each * qty;
		var discount_price = discount_price_each * qty;
		
		var discount = full_price - discount_price;
		
		document.getElementById( "quantity_discount_" + catid ).innerHTML = format_currency( discount );
		document.getElementById( "final_price_" + catid ).innerHTML = format_currency( discount_price );				
	}
	/*function calc_ttl( catid )
	{
		var frm = document.frmAddToCart;
		var qty = document.getElementById( "cartonqty_" + catid ).value;
		var discount = disc( qty );
		var final_price = qty * frm["price_each_" + catid ].value;
		
		discount = discount * final_price;
		final_price = final_price - discount;
		
		document.getElementById( "quantity_discount_" + catid ).innerHTML = format_currency( discount );
		document.getElementById( "final_price_" + catid ).innerHTML = format_currency( final_price );				
	}*/

