	var g_form = true; 


function doClear ( form ) {	
 	document.form0.onReset = " return confirm('Are you sure that you want to clear all the data you have entered on this form?')";
//  	document.form0.method = "";
  	document.form0.reset();	
}	

function askWolf() {
	
	
}

function doCookies () {
//******************************************************************************* 
//  Common rtn for pages with forms. If Name, Title, etc is in cookie, display
//  on form so user does not have to enter it again.

//* NOTE: THis rtn is called form HM)Loader.js-customOnLoad(). Must do this 
//        because The Hier menu system uses the onload handler. See FAQ3.
//******************************************************************************* 		

	var theName 	= getCookie("Name"); 
	var theTitle	= getCookie("Title"); 
	var theCompany	= getCookie("Company"); 
	var theAddress1 = getCookie("Address1"); 
	var theAddress2 = getCookie("Address2"); 
	var theCity 	= getCookie("City"); 
	var theProvince = getCookie("Province"); 
	var theCountry	= getCookie("Country"); 
	var thePostalCode = getCookie("PostalCode"); 
	var theTelephone = getCookie("Telephone"); 
	var theFax		= getCookie("Fax"); 
	var theEmail	= getCookie("Email"); 
	 	
	if (theName == null) 	{theName = "" } // Just in case the cookie is not set.	
	if (theTitle == null)	{theTitle = "" };
	if (theCompany == null)	{theCompany = "" };
	if (theAddress1 == null) {theAddress1 = "" };
	if (theAddress2 == null) {theAddress2 = "" };
	if (theCity == null)	{theCity = "" };
	if (theProvince == null) {theProvince = "" };
	if (theCountry == null) {theCountry = "" };
	if (thePostalCode == null) {thePostalCode = "" };
	if (theTelephone == null) {theTelephone = "" };
	if (theFax == null)		{theFax = "" };
	if (theEmail == null)	{theEmail = "" };

    document.form0.Name.value = theName;	    
    document.form0.Title.value = theTitle;
    document.form0.Company.value = theCompany;
    document.form0.Address1.value = theAddress1;
    document.form0.Address2.value = theAddress2;
    document.form0.City.value = theCity;
    if (theProvince != "") document.form0.Province.value = theProvince;
    if (theCountry != "")  document.form0.Country.value = theCountry;
    document.form0.PostalCode.value = thePostalCode;
    document.form0.Telephone.value = theTelephone;
    document.form0.Fax.value = theFax;
    document.form0.Email.value = theEmail;
   
}	

function doForm ( form ) {	
//******************************************************************************* 
//  Common rtn for pages with forms.
//* Contact: 2009-10-18 - Add contact_options Cards, Sales and Other
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n____________________________________\n ";
	var errormessage="";
	var len;
	var testFlag = 0;  // set to 1 if Comments = "cc" - bypass validation.

//  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);

 	//******  Checkboxes for Contact Us page only
	if (thefile == "contact.html") {
		//alert(thefile)
		if (document.form0.Meeting.checked == 0 &
		 document.form0.Call_Me.checked == 0 &
		 document.form0.newSourcing.checked == 0 &
		 document.form0.Marketing_Planning.checked == 0 &
		 document.form0.Retail_Advertising_MakeOver.checked == 0 & 		
		 document.form0.Corporate_Communications.checked == 0 &
		 document.form0.Fund_Raising.checked == 0 &
		 document.form0.Book_Seminar.checked == 0 &
		 document.form0.Ad_TuneUP.checked == 0 &		 
		 document.form0.Startups_Support.checked == 0 &
		 document.form0.Instant_Help.checked == 0 &
		 document.form0.Custom_Holiday_Season_Greeting_Card.checked == 0 &
		 document.form0.Sales_Training.checked == 0 &
		 document.form0.Web_Development_Support.checked == 0 &
		 document.form0.References.checked == 0 & 
		 document.form0.Updates.checked == 0 & 
		 document.form0.Representating_WAW.checked == 0 & 
		 document.form0.Mailing.checked == 0 & 
		 document.form0.Contact_Option_Other.value == ""  )    
   	 	{errormessage=errormessage+"Contact Option (check at least one)\n"}
   	 }

	//**********************
	//*** $49  Solutions
	//**********************
	if (thefile == "solutions-form.html") {
		if (document.form0.Solution_1.checked == 0  & document.form0.Solution_2.checked == 0  & document.form0.Solution_3.checked == 0 &
		    document.form0.Solution_4.checked == 0  & document.form0.Solution_5.checked == 0  & document.form0.Solution_6.checked == 0 &
		    document.form0.Solution_7.checked == 0  & document.form0.Solution_8.checked == 0  & document.form0.Solution_9.checked == 0 &
		    document.form0.Solution_10.checked == 0 & document.form0.Solution_11.checked == 0 & document.form0.Solution_12.checked == 0 &
		    document.form0.Solution_13.checked == 0 & document.form0.Solution_14.checked == 0 & document.form0.Solution_15.checked == 0 &
		    document.form0.Solution_16.checked == 0 & document.form0.Solution_17.checked == 0 & document.form0.Solution_18.checked == 0 &
		    document.form0.Solution_19.checked == 0 )
   	 	{errormessage=errormessage+"Amazing $49 Solutions (check at least one)\n"}
   	 	
   	 	if (document.form0.Solution_19.checked == 1) 
   	 	{
   	 		if (document.form0.Solution_Your_Choice.value.length < 7)  	
   	 		{errormessage=errormessage+"\"Your Choice\" Description\n"}
		}   	 		
   	 	     
   	 }  //* $49  Solutions
   	 
	//**********************
	//*** ADvanced Seminars  
	//**********************
	if (thefile == "seminars.html") {
		if (document.form0.Seminar_Options_1.checked == 0 & document.form0.Seminar_Options_2.checked == 0 & document.form0.Seminar_Options_3.checked == 0)
   	 	{errormessage=errormessage+"Seminars Option (check at least one)\n"}
    
	    //*** SEMINAR DATE 
	    fieldblank=true;
	    minlength = 6;
	    for (j=0; j < document.form0.Seminar_Date.value.length; j++) 
	    {
	      if (document.form0.Seminar_Date.value.substring(j,j+1) !=" ") {fieldblank=false}
	    }
	    if (document.form0.Seminar_Date.value.length < minlength || fieldblank)
	      	{errormessage=errormessage+"Seminar desired date\n"}   	 	
	   	
	   	//*** PARTICIPANTS 
	    fieldblank=true;
	    minlength = 1;
	    for (j=0; j < document.form0.No_of_Participants.value.length; j++) 
	    {
	      if (document.form0.No_of_Participants.value.substring(j,j+1) !=" ") {fieldblank=false}
	    }   	
	    if (document.form0.No_of_Participants.value.length < minlength || fieldblank)
	      	{errormessage=errormessage+"Number of seminar participants\n"}   	 	
   	 }  //* End Advanced 	 

//*** NAME 
    fieldblank=true;
    minlength = 2;
    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"}
      	
//  TITLE	
 
	fieldblank=true;
	minlength = 2;
	for (j=0; j < document.form0.Title.value.length; j++) 
		{
	      if (document.form0.Title.value.substring(j,j+1) !=" ") {fieldblank=false}
	    }
	if (document.form0.Title.value.length < minlength || fieldblank)
		{errormessage=errormessage+"Title\n"}           	
		
//  Company 
 
	fieldblank=true;
	minlength = 2;
	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"}      	

	if (thefile == "solutions-form.html") { 
	
	//*** ADDRESS1
	    minlength = 2; fieldblank=true;
	    for (j=0; j < document.form0.Address1.value.length; j++) 
	    {
	      if (document.form0.Address1.value.substring(j,j+1) !=" ") {fieldblank=false}
	    }
	    if (document.form0.Address1.value.length < minlength || fieldblank)
	      	{errormessage=errormessage+"Address\n"}
	      	      	
	//*** CITY
	    minlength = 2; 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"}
	
	//*** 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"}

		//*** POSTAL CODE  
	    minlength = 5;     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"}	      	
	      	
	//*** Country
	    minlength = 2; fieldblank=true;
	    for (j=0; j < document.form0.Country.value.length; j++) 
	    {
	      if (document.form0.Country.value.substring(j,j+1) !=" ") {fieldblank=false}
	    }
	    if (document.form0.Country.value.length < minlength || fieldblank)
	      	{errormessage=errormessage+"Country\n"}
	} //*END SOLUTIONS-FORM

//*** TEL 
	minlength = 10
    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"} 

	//**********************
	//*** Getting Started  
	//**********************   	 
   	 
   	  if (thefile == "start.html") {
   	  	  	  	
   	  	if (document.form0.Advertising_Budget[0].checked || 
   	  	    document.form0.Advertising_Budget[1].checked ||
   	  	    document.form0.Advertising_Budget[2].checked ||
   	  	    document.form0.Advertising_Budget[3].checked || 
   	  	    document.form0.Advertising_Budget[4].checked || 
   	  	    document.form0.Advertising_Budget[5].checked || 
   	  	    document.form0.Advertising_Budget[6].checked ) { 	}
   	  	else { errormessage=errormessage + "14. Your Advertising budget\n" }	
   	 	
   	  }  //* Getting Started

// 	errormessage ="";  // Uncomment to deactivate validation for Testing


if (spaceTrim(document.form0.Comments.value) == "test") {errormessage=""; testFlag = 0;}   
if (spaceTrim(document.form0.Comments.value) == "xx") {errormessage=""; testFlag = 1;}   
 
   if (errormessage!="") { alert (firstmessage + errormessage)}
   else { 
   	
    if (document.form0.Name.value !="") 		setCookie("Name", document.form0.Name.value); 
    if (document.form0.Title.value !="") 		setCookie("Title", document.form0.Title.value); 
    if (document.form0.Company.value !="") 		setCookie("Company", document.form0.Company.value);
    if (document.form0.Address1.value !="") 	setCookie("Address1", document.form0.Address1.value);
    if (document.form0.Address2.value !="") 	setCookie("Address2", document.form0.Address2.value);
	if (document.form0.City.value !="") 		setCookie("City", document.form0.City.value);
	if (document.form0.Province.value !="") 	setCookie("Province", document.form0.Province.value);        
    if (document.form0.Country.value !="") 		setCookie("Country", document.form0.Country.value); 
    if (document.form0.PostalCode.value !="")	setCookie("PostalCode", document.form0.PostalCode.value);         
    if (document.form0.Telephone.value !="") 	setCookie("Telephone", document.form0.Telephone.value);
    if (document.form0.Fax.value !="") 			setCookie("Fax", document.form0.Fax.value);
    if (document.form0.Email.value !="") 		setCookie("Email", document.form0.Email.value); 

	var subj = "WAW: Form"; // Subject line on email.
	if (thefile == "contact.html") { subj = "WAW: CONTACT" ;}
	else  if (thefile == "adman.html") { subj = "WAW: ASK ADMAN"; }
	else  if (thefile == "start.html") { subj = "WAW: GETTING STARTED"; }	
	else  if (thefile == "ref.html") { subj = "WAW: REQUEST A REFERENCE"; }	
	else  if (thefile == "seminars.html") { subj = "WAW: ADVANCED SEMINAR"; }	
	else  if (thefile == "solutions-form.html") { subj = "WAW: $49 SOLUTIONS"; }				

  	document.form0.recipients.value = "wolfgang@wordsatwork.ca";
  	if (thefile == "seminars.html" || thefile == "solutions-form.html")
  		{ document.form0.recipients.value = "wolfgang@wordsatwork.ca"; }
	
// 	document.form0.sendemailto.value = "wolfgang@wordsatwork.ca";
// 	if (thefile == "seminars.html" || thefile == "solutions-form.html")
// 		{ document.form0.sendemailto.value = "admin@wordsatwork.ca"; }
    
    //* xx in comments field, send to pc
 	
 	if (testFlag) { document.form0.recipients.value = "pc@twistedpixel.com"; } 

//* uses mailer/FORMMAIL.PHP  
 	  	document.form0.email.value = document.form0.Email.value
	  	document.form0.subject.value = subj;
	  	document.form0.good_url.value = "http://www.wordsatwork.ca/html/confirm.html";	
	  	document.form0.bcc.value  = "pc@twistedpixel.com";
	  	document.form0.action = "../mailer/formmail.php";
//	  	document.form0.enctype = "multipart/form-data";  
  		document.form0.method = "POST";
  		document.form0.submit()  
  
//    if (testFlag) document.form0.sendemailto.value = "pc@twistedpixel.com"; 	   
//    document.form0.redirect.value = "http://www.wordsatwork.ca/html/confirm.html";
//    document.form0.sendemailsubject.value = subj;
//    document.form0.sendemailfrom.value  = document.form0.Email.value;
//    document.form0.sendemailbcc.value  = "pc@twistedpixel.com"; 
//    document.form0.action = "http://www.atlis.net/asp/mailer.asp";
//    document.form0.method = "POST";
//    document.form0.submit();
	return(0);  
   }
}  
 