//Server Path
var server = 'http://www.eastcoastled.com/' ;

var initial_price=0;
function reload(form)
{
	var val=form.category.value;
	var val1=form.pixelpitch.options[form.pixelpitch.options.selectedIndex].value;
	var val2=form.sq.options[form.sq.options.selectedIndex].value;
	if(val2=='')
	{
		val2=1;
	}
	//self.location='?pg=quote&cid=' + val + '&pid=' + val1 + '&sqid=' + val2 ;
	window.location= server+'quote/'+val+'/'+val1+'/'+val2+'.html' ;
}

function initialPrice(form)
{
	var total_amount;
		if(initial_price==0)
		{
			if(isNaN(document.form1.amount.value))
			{
				initial_price=0;
			}	
			else if(form.sq.value==1)
				initial_price = document.form1.amount.value;
			else
				initial_price = Math.round((document.form1.amount.value/form.sq.value)*100)/100;
		}
}
 function update_quantity(form)
	{
			total_amount_final = Math.round(form.sq.value*initial_price*100)/100;
			if(isNaN(total_amount_final))
			{
			total_amount_final=0;
			}	
			document.getElementById('res1').innerHTML = "<b> $ </b>" + "<b>" + total_amount_final + "</b>";		  
	  		document.form1.amount.value = total_amount_final;
	}
     

function changelist(obj1,obj2,form)
{
	
	var temp = 0.0;
	for (var j=0; j < form.rg1.length; j++)
	{
		if (form.rg1[j].checked)
		{
			var rate = form.rg1[j].value;
		}
	}
	
	for (var j=0; j < form.rg2.length; j++)
	{
		if (form.rg2[j].checked)
		{
			var rate1 = form.rg2[j].value;
			temp = temp + parseFloat (rate1); 		 
		}
	}
   
	var val=obj2.options[obj1.options.selectedIndex].value;
	var i;
	var height, width, price, qty, rate, price1;
	
	for(i=0; i<=obj2.options.length; i++)
	{
		if(obj2.options[i].value==val)
		{
			obj2.options.selectedIndex = i;
			height=form.hinch.options[form.hinch.options.selectedIndex].value;
			width = form.winch.options[form.winch.options.selectedIndex].value;
			qty = form.sq.options[form.sq.options.selectedIndex].value;
			height=height/12;
			width=width/12;
			price=(height * width * qty * rate) + (parseFloat (temp)* qty);
			var result = Math.round(price*100)/100;
			dis = form.discount.value;
			var disResult = Math.round(result*dis)/100;
			disResult = result - disResult;

			if(isNaN(result) && isNaN(disResult))
			{
				result=0;
				disResult=0;
			}
		
			document.getElementById('res1').innerHTML = "<b> $ </b>" + "<b>" + result.toFixed(2) + "</b>";
			document.getElementById('disRes1').innerHTML = "<b> $ </b>" + "<b>" + disResult.toFixed(2) + "</b>";								
			document.form1.amount.value = disResult.toFixed(2);
		}
	}  
 }
function printQuote(form)
{
	if(document.form1.amount.value > 0)
	{
		var c=form.category.value;
		var p=form.pixelpitch.options[form.pixelpitch.options.selectedIndex].value;
		var sq=form.sq.options[form.sq.options.selectedIndex].value;
		var hi=form.hinch.options[form.hinch.options.selectedIndex].value;
		var hp=form.hpixel.options[form.hpixel.options.selectedIndex].value;
		var wi=form.winch.options[form.winch.options.selectedIndex].value;
		var wp=form.wpixel.options[form.wpixel.options.selectedIndex].value;
		var tot=document.form1.amount.value;
		var printUrl = 'printQuote.php?c=' + c + '&p=' + p + '&sq=' + sq + '&hi=' + hi + '&hp=' + hp + '&wi=' + wi + '&wp=' + wp + '&tot=' + tot ;
		
		for (var j=0; j < form.rg1.length; j++)
		{
			if (form.rg1[j].checked)
			{
				printUrl = printUrl + '&cl=' + form.rg1[j].title;
			}
		}
			
		for (var j=0; j < form.rg2.length; j++)
		{
			if (form.rg2[j].checked)
			{
				printUrl = printUrl + '&op' + j + '=' + form.rg2[j].title;
			}
		}
		window.location.href = 'http://www.eastcoastled.com/' + printUrl ;	
	}	
}

function validation()
{
	var val=document.getElementById('color').options[document.getElementById('color').options.selectedIndex].value;
	var valc=document.getElementById('color').options[document.getElementById('color').options.selectedIndex].title;
	var val1=document.getElementById('pitch').value;
	var val2=document.getElementById('height').value;
	var val2f=document.getElementById('hf').value;
	var val3=document.getElementById('width').value;
	var val3f=document.getElementById('wf').value;

	if(val=='')
	{	
		alert('Please, select color First !');
		document.getElementById('color').focus();
		return false;
	}
	else if(val1=='')
	{
		alert('Please, select pitch First !');
		document.getElementById('pitch').focus();		
		return false;
	}
	else if(val2=='')
	{
		alert('Please, enter height of pitch !');
		document.getElementById('height').focus();
		return false;
	}
	else if(val3=='')
	{
		alert('Please, enter width of pitch !');
		document.getElementById('width').focus();		
		return false;
	}
	else
	{
		self.location='?pg=searchPitch&caid=' + val + '&clid=' + valc + '&pid=' + val1 + '&h=' + val2 + '&hf=' + val2f + '&w=' + val3 + '&wf=' + val3f;
	}
}
