//*---------------------------------------------------------------------
//* UPDATE: 2005-09-12 - Change reply@ to info@.
//*---------------------------------------------------------------------

// Trick to dynamically get the file name of the displayed page.
	var dir = location.href.substring(0,location.href.lastIndexOf('/')+1);
	var fn = location.href.substring(dir.length,location.href.length+1);
	
//	fn = fn.substring(0,fn.length-5)  // chop of .html so we get just the fname
	fn = fn.substring(0,fn.length  )  // Get filename and extention


function validateOrder ( form ) {	
//******************************************************************************* 
//  Validate design-init-order form.  
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";
	var len;

//*** NAME 
    fieldblank=true;
    minlength = 5;
    for (j=0; j < document.form0.Name.value.length; j++) 
    {
      if (document.form0.Name.value.substring(j,j+1) !=" ") {fieldblank=false}
    }
    if (document.form0.Name.value.length < minlength || fieldblank)
      	{errormessage=errormessage+"Name\n"}
      	
//*** Company 
//  Trick to dynamically get the file name of the displayed page.
	var dir = location.href.substring(0,location.href.lastIndexOf('/')+1);
	var thefile = location.href.substring(dir.length,location.href.length+1);
 
//  Company is optional for Residential form	
	if (thefile != "order-res.html") {
	    fieldblank=true;
	    minlength = 3;
	    for (j=0; j < document.form0.Company.value.length; j++) 
	    {
	      if (document.form0.Company.value.substring(j,j+1) !=" ") {fieldblank=false}
	    }
	    if (document.form0.Company.value.length < minlength || fieldblank)
	      	{errormessage=errormessage+"Company\n"}      	
 	}

//*** ADDR1
    minlength = 6;
    fieldblank=true;
    for (j=0; j < document.form0.Addr1.value.length; j++) 
    {
      if (document.form0.Addr1.value.substring(j,j+1) !=" ") {fieldblank=false}
    }
    if (document.form0.Addr1.value.length < minlength || fieldblank)
      	{errormessage=errormessage+"Address\n"}
      	
//*** CITY
    minlength = 3;
    fieldblank=true;
    for (j=0; j < document.form0.City.value.length; j++) 
    {
      if (document.form0.City.value.substring(j,j+1) !=" ") {fieldblank=false}
    }
    if (document.form0.City.value.length < minlength || fieldblank)
      	{errormessage=errormessage+"City\n"}

//*** POSTAL CODE
    minlength = 3;
    fieldblank=true;
    for (j=0; j < document.form0.PostalCode.value.length; j++) 
    {
      if (document.form0.PostalCode.value.substring(j,j+1) !=" ") {fieldblank=false}
    }
    if (document.form0.PostalCode.value.length < minlength || fieldblank)
      	{errormessage=errormessage+"Postal Code/Zip\n"}

//*** PROVINCE
    minlength = 2
    fieldblank=true
    for (j=0; j < document.form0.Province.value.length; j++) 
    {
      if (document.form0.Province.value.substring(j,j+1) !=" ") {fieldblank=false}
    }
    if (document.form0.Province.value.length < minlength || fieldblank)
      	{errormessage=errormessage+"Province/State\n"}

//*** Country 
	var item = document.form0.Country.selectedIndex;
	var countryval = document.form0.Country.options[item].value;
	if (countryval == "") {errormessage=errormessage+"Country\n"}        	

//*** TEL 
	minlength = 6
    fieldblank=true
    for (j=0; j < document.form0.Telephone.value.length; j++) 
    {
      if (document.form0.Telephone.value.substring(j,j+1) !=" ") {fieldblank=false}
    }
    if (document.form0.Telephone.value.length < minlength || fieldblank)
      	{errormessage=errormessage+"Telephone\n"}     	

//*** EMAIL 
//alert(form.Email.value.length);
   if (document.form0.Email.value.length ==0 || document.form0.Email.value.indexOf('@', 0) == -1 || document.form0.Email.value.indexOf('.', 0) == -1) 
	{errormessage=errormessage+"Email address\n"} 

//*** Building Type

	var item = document.form0.Building.selectedIndex;
	var buildval = document.form0.Building.options[item].value;
//	alert(item + "|" + buildval + "|" + document.form0.Building_Other.value);
	if (buildval == "" && document.form0.Building_Other.value == "") {errormessage=errormessage+"Building Type\n"}
	
//*** New Construction or Retrofit	
//	document.form0.BuildingType.text = "value"
	if (document.form0.NewOrRetro[0].checked || document.form0.NewOrRetro[1].checked) {
		if (document.form0.NewOrRetro[0].checked) document.form0.NewOrRetrofit.value = "New Construction";
		if (document.form0.NewOrRetro[1].checked) document.form0.NewOrRetrofit.value = "Retrofit";
	}
	else {errormessage=errormessage+"New Construction or Retrofit\n"}
 
 //*** Help
 
 	var helperr = 0;
//* request quote has a Buget checkbox instead of a Contractor checkbox 	
 	if (thefile == "request-quote.html") {
		if (document.form0.Help_Design.checked == 0 & document.form0.Help_Heater.checked == 0 
		    & document.form0.Help_Budget.checked == 0 & document.form0.Help_Other.checked == 0)    
    	    { helperr = 1; }
    }
     else {	
		if (document.form0.Help_Design.checked == 0 & document.form0.Help_Heater.checked == 0 
		    & document.form0.Help_Contractor.checked == 0 & document.form0.Help_Other.checked == 0)    
    	    { helperr = 1; }
    }   
    if (helperr) { errormessage=errormessage+"I need help to...\n" }	
    
  
  if (spaceTrim(document.form0.Comments.value) == "xx") {errormessage="";}
   if (errormessage !="") { alert (firstmessage + errormessage) ; return false; }
   else { 
 	document.form0.sendemailto.value = "info@schwankgroup.com";
	document.form0.sendemailsubject.value  = "PATIOSCHWANK - Design, Quote or Order";
// 	document.form0.sendemailto.value = "pc@twistedpixel.com"; 	  //* FOR TESTING

		if (spaceTrim(document.form0.Comments.value) == "xx") {			
			document.form0.sendemailto.value  = document.form0.Email.value;
			if (spaceTrim(document.form0.Email.value) == "") {
				document.form0.sendemailto.value = "pc@twistedpixel.com";  
			}
		}

	document.form0.sendemailbcc.value = "pc@twistedpixel.com";
   	document.form0.sendemailfrom.value  = document.form0.Email.value;
    document.form0.redirect.value = "http://www.patioschwank.com/en/des-initorder-confirm.asp";
     
 //	document.form0.action = "../formmail/formsend.asp";  	
 	document.form0.action = "../formmail/mailer2.asp";
  	document.form0.method = "POST";
 	document.form0.submit();  
   }
}  

//function show(pic,w,h,scroll) {
function show(pic,w,h,dir) {
//*******************************************************************************
//	Display a window with picture   
//*******************************************************************************
//	if (scroll = "s") scroll="yes";
//	else  scroll="no";
	var scroll="no";
	
	var theDir = "../images/";
	if (dir == 1) theDir = "../gallery/";
	
	
	var h = h + 80;
	var w = w + 40;
	var data = '<html><head><title>Schwank Infrared Gas-fired Radiant Heaters</title><body bgcolor="#000020" background="../images/bg-bluemoon.jpg" leftmargin=0 topmargin=0 marginheight="0" >';
	data += '<center>';
	data += '<img name="load" src="../images/b-clickad.gif" width="142" height="11" alt="" border="0"><br>';
	data += '<a href="javascript:self.close()" onMouseOver="self.status=\'Click on image to close window.\'; return true" onMouseOut="self.status=\'\'; return true">';
	data += '<img src="' + theDir + pic + '" alt="Click on image to close window." border="0"></a></center>';
	data += '</body></html>';		
	newWindow = window.open('','newWin', "width=" + w + ",height=" + h + ",scrollbars=" + scroll + ",status=yes,resizable=yes", "alwaysRaised");	
	newWindow.document.write(data);
	newWindow.document.close('newWin'); //* Close the data stream
	newWindow.resizeTo(w,h);			//* Resize the window for latest image 
	newWindow.focus(); 					//* Bring to front	
} 

function showgalx( fn, w, h ) {
//*******************************************************************************
//	Display a window with big pic - For Pubinfo Image Gallery
//******************************************************************************* 
//   alert(fn + w + h)

 	setCookie1("picname", fn);
 	setCookie1("picwidth", w);
 	setCookie1("picheight", h);
     w = w + 60; h = h + 50;  // Increase border area

	newWindow = window.open("showpic.html", "newwin", "width=" + w +  ",height=" + h + ",scrollbars=yes,status=yes,resizable=yes");
	newWindow.document.close('newWin');
}

function privacy() {
//*******************************************************************************
//	Display a popup window with privacy statement
//*******************************************************************************
	window.open("privacy.html", "newwin", "width=300,height=250,scrollbars=yes,status=yes,resizable=yes");
}

// <script language="Javascript"><!-- document.write(showAddr("pc")); //--> </script>
 
function showAddr(part1, part2){
//*******************************************************************************
//	Display mailto link, hide from spam miners.
//*******************************************************************************
//alert(part2);	
  if (part2 == undefined) part2 = "schwankgroup.com";	
  var addr = part1 + "@" + part2;
  var result = ("<a href='" + "mail" + "to:" + addr + "'>" + addr + "</a>")
  return result;
}

function doClear ( form ) {	
//*******************************************************************************
// Clear Form  -  
//*******************************************************************************	
//alert(pagelang);
    var msg_e = "Are you sure that you want to clear all the data you have entered on this form?";
    var msg_f = "Voulez-vous vraiment effacer toutes les données?";
    var clearmsg = msg_e;
 // if (pagelang == "f") clearmsg = msg_f;
    
	var confirmOK = confirm(clearmsg);
  	if (confirmOK) document.form0.reset();    
}

 function spaceTrim(InString) {
//*******************************************************************************
// Trim leading and trailing spaces of form input fields
//*******************************************************************************
	var LoopCtrl=true;
	while (LoopCtrl) {
		if (InString.indexOf("  ") != -1) {
			Temp = InString.substring(0, InString.indexOf("  "))
			InString = Temp + InString.substring(InString.indexOf("  ")+1, 
				InString.length)
		} else
			LoopCtrl = false;
	}
	if (InString.substring(0, 1) == " ")
		InString = InString.substring(1, InString.length)
	if (InString.substring (InString.length-1) == " ")
		InString = InString.substring(0, InString.length-1)
	return (InString)
}
function isInteger(s)
//*******************************************************************************
//	is it an integer?
//*******************************************************************************	
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
} 

 

function setCookie1(name, value, expires, path, domain, secure) {
//*******************************************************************************
// Generic rtn to set a cookie.
//*******************************************************************************
       var curCookie = name + "=" + escape(value) +
           ((expires) ? "; expires=" + expires.toGMTString() : "") +
           ((path) ? "; path=" + path : "") +
           ((domain) ? "; domain=" + domain : "") +
           ((secure) ? "; secure" : "");
       document.cookie = curCookie;
}