function validateglass(quantObj)
{
	darea.value=(WW.value *HH.value/188),moneyFormat(darea);
	glasspri.value=parseFloat(glass.value)*(WW.value*HH.value/144),moneyFormat(glasspri);
	dweight.value=(WW.value *HH.value/188)*(glass.value.substring(6,9));
}


function validateW(quantObj)
{
	// Check if form not of Style 4 (4011,etc)
    var p = _GET['p'];
	if(p !== "s4011" && p !== "s4012" && p !== "s4013" && p !== "s4014"){
		if (quantObj.value > 36) {
			alert("The maxium door width (W) is 36 inches");
			quantObj.focus();
			quantObj.select();
		}
		else if (quantObj.value > 32) {
			alert("Use Heavy Duty hinges on this door");
			
		}
	}
	
}
//Max height
function validateH(quantObj)
{
	if (quantObj.value > 98) {
		alert("This door height (H) exceeds the maxium height for online orders. Please contact the sales department.");
		quantObj.focus();
		quantObj.select();
	}
}
//minimun inline width
function validateS(quantObj)
{
	if (quantObj.value < 5) {
		alert("Inline panel must be wider.");
		quantObj.focus();
		quantObj.select();
	}
}


//Check for minimun leg width
function validateSL(quantObj)
{
	if (quantObj.value < 5) {
		alert("The leg width of the notched panel must be wider."); 
		quantObj.focus();
		quantObj.select();
	}
}

function validatehdw(quantObj)
{
(S.value*1 + SH.value*1);
alert("The layout selected has a step. Please enter the step width in inches"); 
		quantObj.focus();
		quantObj.select();
}
function validateFinish()
{
test.value=hdw_finish.value;
	if (hdw_finish.value = 0) {
		alert("Please select the hardware finish first"); 
		hdw_finish.focus();
		hdw_finish.select();
	}
}
function trim_space(str)
{
	var temp = str;
    return temp.replace(/^\s+/,'').replace(/\s+$/,'');
	//alert(str);
	//var reg = "\\s";
	//var reg = /\s/;
	//str.replace(reg,'');
}
function checkispress()
{

	var error = "";

	if(document.form1.txtEmail)
	{
		if(document.form1.txtEmail.value == "")
		{
			error += 'Please enter your email address.\n';
		}
	}
	
	if(document.form1.finalpri.value == 0.00)
	{
		error += 'Please press the calculate button.\n';
	}
	if(document.form1.ddlselService.value == "0")
	{
		error += 'Select the Shipping service.\n';
	}
	if(document.form1.ddlselService.value == "1DP")
	{
			
	}else
	{
		if(document.form1.shippingcost.value == 0.00)
		{
			error += 'Please press the Calculate shipping button.\n';
		}
	}
	if(error){	
	alert('The following error(s) occurred:\n'+error);
    return false;
	}
	return checkemailisvalid(document.form1.txtEmail.value);

}
function picselect(href)
{
	return alert('<a href='+href+' title="Image" rel="gb_page_center[250, 250]">');
}
function popImage(imageURL,imageTitle)
{
	PositionX = 100;
	PositionY = 100;
	defaultWidth  = 500;
	defaultHeight = 500;
	var AutoClose = true;
	if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
	var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
	var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
	if (isNN){imgWin=window.open('about:blank','',optNN);}
	if (isIE){imgWin=window.open('about:blank','',optIE);}
	with (imgWin.document){
	writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
	writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
	writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
	writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(300,300);');
	writeln('width=300-(document.body.clientWidth-document.images[0].width);');
	writeln('height=300-(document.body.clientHeight-document.images[0].height);');
	writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
	writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
	writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</script>');
	if (!AutoClose) writeln('</head><body bgcolor="ffffff"	 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
	else writeln('</head><body bgcolor="ffffff" scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');

	//writeln('<img name="George" src=admin/'+imageURL+' style="display:block"></body></html>');
	//writeln('<img name="George" src="admin/'+imageURL+'" style="display:block"></body></html>');
	writeln('<img name="George" src="admin/' + imageURL + '" style="display:block"></body></html>');
	close();		
	}
}
function newwindow(imageURL)
{
	
	if(imageURL == '')
	{
		//window.open("admin/upload/no-image.png","Image","width=300,height=200,resizable=no");
		imageURL = "upload/no-image.png";
		popImage(imageURL,'');
	}
	else
	{
		popImage(imageURL,'');
	}
	
}
/*
Usage: openWindow( url , w , h , tb , stb , L , mb , sb , rs , x , y )
 
# url - The URL of the page to open. Example: "http://scriptasylum.com".
# w - The width of the window in pixels.
# h - The height of the window in pixels (doesn't include menubars).
# tb - Toolbar visible? 1 = yes, 0 = no.
# stb - Status bar visible? 1 = yes, 0 = no.
# L - Linkbar visible? 1 = yes, 0 = no.
# mb - Menubar visible? 1 = yes, 0 = no.
# sb - Scrollbars visible? 1 = yes, 0 = no.
# rs - Resizable window? 1 = yes, 0 = no.
# x - The horizontal position of the window from the left of the screen.
# y - The vertical position of the window from the top of the screen. 
*/
function checkemailisvalid(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false;
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false;
		 }

 		 return true					
	}function frmlessEmailCheck(email) {

   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

   var address = document.getElementById('txtEmail').value;

   if(reg.test(address) == false) {

      alert('Please enter valid Email Address');

      document.getElementById('txtEmail').focus();

      return false;

   }

   return true;

}



function calcshipping()
{

if(!frmlessEmailCheck()) return false;
	
	var val,weight= 0;
	var service = 0;
	var error = "";
	var txtaddress,txtstate,txtcity;
	
	document.form1.txtPackWeight.value = 0
	document.form1.shippingcost.value = 0;
	
	/*
	 * if Not Will Call condition
	 */
	// if selected method is not "Will Call" then proceed with script functions, else not
	if(document.getElementById('ddlselService').value != '1DP') {
	
		if(document.form1.finalpri.value == 0 )
		{
			error += 'Press the calculate total price button.\n';
		}
		if (document.form1.dweight)
		{
			weight = Number(document.form1.dweight.value) + Number(weight);
		}
		if (document.form1.Kweight)
		{
			weight = Number(document.form1.Kweight.value) + Number(weight);
		}
		if (document.form1.Sweight)
		{
			weight = Number(document.form1.Sweight.value) + Number(weight);
		}
		if (document.form1.Eweight)
		{
			weight = Number(document.form1.Eweight.value) + Number(weight);
		}
		if (document.form1.scrweight)
		{
			weight = Number(document.form1.scrweight.value) + Number(weight);
		}
		if (document.form1.Lscrweight)
		{
			weight = Number(document.form1.Lscrweight.value) + Number(weight);
		}
		if (document.form1.Rscrweight)
		{
			weight = Number(document.form1.Rscrweight.value) + Number(weight);
		}
	//	if (document.form1.street)
	//	{
	//		txtaddress = document.form1.street.value;
	//	}
	//	if (document.form1.state)
	//	{
	//		txtstate = document.form1.state.value;
	//	}
	//	if (document.form1.city)
	//	{
	//		txtcity = document.form1.city.value;
	//	}
		document.form1.txtPackWeight.value = weight;	
		moneyFormat(document.form1.txtPackWeight);
		if(document.form1.txtPackWeight.value == 0.00)
		{
			error += 'No Door/Glass is selected.\n';
		}
		if(document.form1.dest_zipcode.value == "")
		{
			error += 'Enter your Destination zipCode field.\n';
		}
		if(document.form1.ddlselService.value == "0")
		{
			error += 'Select the Shipping service.\n';
		}
		if(document.form1.ddlselService.value == "1DA")
		{
			service = Number(40);
		}
		
	//	if(document.form1.street.value == "")
	//	{
	//		error += 'Enter your Destination Address.\n';
	//	}
	//	if(document.form1.city.value == "")
	//	{
	//		error += 'Enter your Destination City.\n';
	//	}
	//	if(document.form1.state.value == "")
	//	{
	//		error += 'Enter your Destination state.\n';
	//	}
	
	} //end if Not Will Call condition
	
	if(error){	
	alert('The following error(s) occurred:\n'+error);
    return false;
	}
	else
	{
		calcShippingCost(document.form1.txtPackWeight.value,document.form1.dest_zipcode.value,service);
	}
}
function SetAllCheckBoxes(FormName, FieldName, CheckValue)
{
	if(!document.forms[FormName])
		return;
	var objCheckBoxes = document.forms[FormName].elements[FieldName];
	if(!objCheckBoxes)
		return;
	var countCheckBoxes = objCheckBoxes.length;
	if(!countCheckBoxes)
		objCheckBoxes.checked = CheckValue;
	else
		// set the check value for all check boxes
		for(var i = 0; i < countCheckBoxes; i++)
			objCheckBoxes[i].checked = CheckValue;
}
function calcheaderlength()
{
	var headerlength = '';
	field = new Array(4)
	field[0] = "W";
	field[1] = "K";
	field[2] = "S";
	field[3] = "E";
	for(var i =0 ; i < 4 ; i++)
	{
		if(document.getElementById(field[i]))
		{
			headerlength = Number((document.getElementById(field[i]).value*1)) + Number(headerlength);
		}
	}
	return headerlength;
}
function calchdwlength()
{
	var hdwlength = '';
	hdwfield = new Array(10)
	hdwfield[0] = "K";
	hdwfield[1] = "KH";
	hdwfield[2] = "S";
	hdwfield[3] = "SH";
	hdwfield[4] = "E";
	hdwfield[5] = "EH";
	hdwfield[6] = "A";
	hdwfield[7] = "AH";
	hdwfield[8] = "C";
	hdwfield[9] = "CH";
	for(var i =0 ; i < 10 ; i++)
	{
		if(document.getElementById(hdwfield[i]))
		{
			hdwlength = Number((document.getElementById(hdwfield[i]).value*1)) + Number(hdwlength);
		}
	}
	if(document.getElementById('H1'))
	{
		hdwlength =(document.getElementById('W').value*1)+(document.getElementById('H1').value*1);
	}
	return hdwlength;
}
window.GET = function(){
    var url = window.location.href;
    var array = url.indexOf('#') == -1 ?
                url.substring(url.indexOf('?') + 1).split(/&;/):
                url.substring(url.indexOf('?') + 1, url.indexOf('#')).split(/&;/);
                            //URLs can be like either "sample.html?test1=hi&test2=bye" or
                                //"sample.html?test1=hi;test2=bye"
    window._GET = {};
    for(var i = 0; i < array.length; i++){
        var assign = array[i].indexOf('=');
        if(assign == -1){
            _GET[array[i]] = true;//if no value, treat as boolean
        }else{
            _GET[array[i].substring(0, assign)] = array[i].substring(assign + 1);
        }
    }
	return _GET;
}
window.GET();
