//******************************************************************************* 
//  Do Forms  
//* 2006-08-14 Add Free Software radio to res-links-addlink-form.asp
//* 2008-03-08 Make promo mandatory  in doFree()
//* 2008-08-19 Add Category (areas of interest) and Industry validation to RFI form
//* 2008-08-19 Rename Vendor Enrolment form to Media Kit
//* 2008-09-01 Add doSurvey().
//* 2009-02-23 Update doVendorRFI() with Time_Frame field 
//* 2009-04-23 Update doVendorRFI() Trading Partner RFI form (res-serv-rfi3-form) uses different confirm
//* 2009-10-04 res-serv-rfi-form.asp moved/renamed to ref-rfi-form.asp 
//* 2009-10-04 res-askexpert moved/renamed to ref-askexpert
//******************************************************************************* 
	var dir = location.href.substring(0,location.href.lastIndexOf('/')+1);
	var thefile = location.href.substring(dir.length,location.href.length+1);
	
	testdir = "test/";  //* SET TO BLANK FOR PRODUCTION.
	
function doForm ( form ) {	

	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";
	var errorcode=0; 
	var len;
	var testFlag = 0;  // set to 1 if Comments = "cc" - bypass validation.
//***  
	var sEmailto = "pc@twistedpixel.com";			// Default if script fails to set it  

//** NEWS FORMS
	var emailto_subrel = "orders@ec-edi.biz";
//** RESOURCE FORMS	
 	var emailto_vendorenrol	= "leem@ec-edi.biz";
	var emailto_mediakit	= "leem@ec-edi.biz";
	var emailto_affil		= "leem@ec-edi.biz";
	var emailto_askexpert	= "coach@ec-edi.biz";
	var emailto_coach		= "coach@ec-edi.biz";
	var emailto_rfi			= "coach@ec-edi.biz";
	var emailto_askrefer	= "coach@ec-edi.biz";
	var emailto_addpub		= "customerservice@ec-edi.biz";
	var emailto_addlink		= "customerservice@ec-edi.biz";
	var emailto_addjob		= "customerservice@ec-edi.biz";
	var emailto_addcand		= "customerservice@ec-edi.biz";
	var sSubject_pref		= "EC-EDI: "
	var sSubject = "Form"	//* Default failsafe subject
	var sPrefix 			//confirm page file name
	
//*----------------
//* ADD a JOB	
//*----------------
	if (thefile.substring(0,"res-job-addjob".length) == "res-job-addjob" ) {
 		if (spaceTrim(document.form0.Company_Name.value) == "") errormessage=errormessage +  "Company Name\n";	
		if (spaceTrim(document.form0.Job_Title.value) == "") errormessage=errormessage +  "Job Title\n";	
		if (spaceTrim(document.form0.Location.value) == "") errormessage=errormessage +  "Location\n";	
		if (spaceTrim(document.form0.Date_Posted.value) == "") errormessage=errormessage +  "Date Posted\n";	
		if (spaceTrim(document.form0.Expiry_Date.value) == "") errormessage=errormessage +  "Expiry Date\n";	
		if (spaceTrim(document.form0.Contact_Name.value) == "") errormessage=errormessage +  "Contact Name\n";	
		
    	if (document.form0.Contact_Email.value.length ==0 || document.form0.Contact_Email.value.indexOf('@', 0) == -1 || document.form0.Contact_Email.value.indexOf('.', 0) == -1) {errormessage=errormessage+"Contact Email\n"} 
 				
		if (spaceTrim(document.form0.Contact_Telephone.value) == "") errormessage=errormessage +  "Contact Telephone\n";	
		if (spaceTrim(document.form0.Position_Description.value) == "") errormessage=errormessage +  "Position Description\n";	
	}	//*** END res-job-addjob	
	
//*----------------
//* COMMON
//*---------------- 
//* Dont do for Add a Candidate
 	if (thefile.substring(0,"res-job-addcand".length) != "res-job-addcand" ) {	
		if (window.document.form0.Name) {
			if (spaceTrim(document.form0.Name.value) == "") errormessage=errormessage + "Name\n";		
		}
		if (window.document.form0.Title) {
			if (spaceTrim(document.form0.Title.value) == "") errormessage=errormessage + "Title\n";
		}		
		if (window.document.form0.Company) {
			if (spaceTrim(document.form0.Company.value) == "") errormessage=errormessage + "Company\n";
		}			
		if (spaceTrim(document.form0.Telephone.value) == "") errormessage=errormessage + "Telephone\n";
	    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"} 
 		
 	} 	

//*----------------
//* VENDOR ENROLMENT FORM	
//*----------------
	if (thefile.substring(0,"dir-vendor-enrol-form".length) == "dir-vendor-enrol-form" ) {
		
	}
	
	if (thefile.substring(0,"dir-mediakit-form".length) == "dir-mediakit-form" ) {
		
	}	

//*--------------------
//* REF ASK an EXPERT
//*--------------------
	if (thefile.substring(0,"ref-askexpert".length) == "ref-askexpert" ) {
		if (spaceTrim(document.form0.Comments.value) == "") errormessage=errormessage + "Question\n";
	}		

//*--------------------
//* REF ASK for a REFERAAL
//*--------------------
	if (thefile.substring(0,"ref-askreferral".length) == "ref-askreferral" ) {
		if (spaceTrim(document.form0.Problem_to_Solve.value) == "") errormessage=errormessage + "Problem to Solve\n";
	}

//*--------------------
//* RES ADD a CANDIDATE
//*--------------------
	if (thefile.substring(0,"res-job-addcand".length) == "res-job-addcand" ) {
		if (spaceTrim(document.form0.Candidate_Name.value) == "") errormessage=errormessage + "Candidate Name\n";
		if (spaceTrim(document.form0.Telephone.value) == "") errormessage=errormessage + "Telephone\n";	
		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"} 
		if (spaceTrim(document.form0.Date_Posted.value) == "") errormessage=errormessage +  "Date Posted\n";
		if (spaceTrim(document.form0.Expiry_Date.value) == "") errormessage=errormessage +  "Expiry Date\n";
		if (spaceTrim(document.form0.Candidate_Qualifications.value) == "") errormessage=errormessage +  "Candidate Qualifications\n";
	}	

//*----------------
//* NEWS - SUBMIT a RELEASE	
//*---------------- 
	if (thefile.substring(0,"news-subrel".length) == "news-subrel" ) {
		if (spaceTrim(document.form0.Requested_Date.value) == "") errormessage=errormessage +  "Requested Date\n";
				//*** CHECK BOXES
		if (document.form0.Option_1.checked == 0 & document.form0.Option_2.checked == 0 & document.form0.Option_3.checked == 0 & document.form0.Option_4.checked == 0 & document.form0.Option_5.checked == 0 )
		    {errormessage=errormessage +  "Invoice Options - check at least one\n";	}
		if (spaceTrim(document.form0.attachment.value) == "") errormessage=errormessage +  "Attachment\n";	
	}		

//*----------------
//* ADD a LINK	
//*---------------- 
	if (thefile.substring(0,"res-links-addlink".length) == "res-links-addlink" ) {
		
		// Category RADIO
		if (document.form0.Category[0].checked ||
			document.form0.Category[1].checked ||
			document.form0.Category[2].checked ||
			document.form0.Category[3].checked ||
			document.form0.Category[4].checked ||
			document.form0.Category[5].checked ||
			document.form0.Category[6].checked ) {	}
	  		else {errormessage=errormessage + "Category\n"} 
	  		
		if (spaceTrim(document.form0.Organization_Name.value) == "") errormessage=errormessage +  "Organization Name\n";
		if (spaceTrim(document.form0.Website.value) == "") errormessage=errormessage +  "Website Address\n";	  		   		
		
	//* If event button checked	
		if (document.form0.Category[4].checked) {
			if (spaceTrim(document.form0.Event_Date.value) == "") errormessage=errormessage +  "Event Date\n";
			if (spaceTrim(document.form0.Event_Name.value) == "") errormessage=errormessage +  "Event Name\n";
		}				  						
		
	}	
//*----------------
//* ADD a PUBLICATION	
//*---------------- 	
	if (thefile.substring(0,"res-pub-addpub".length) == "res-pub-addpub" ) {
		
		// Section RADIO

		if (document.form0.Section[0].checked ||
			document.form0.Section[1].checked ||
			document.form0.Section[2].checked ) {	}
	  		else {errormessage=errormessage + "Section\n"}    		
	  		
		if (spaceTrim(document.form0.Publication_Date.value) == "") errormessage=errormessage +  "Publication Date\n";	
		if (spaceTrim(document.form0.Issuer_Author.value) == "") errormessage=errormessage +  "Issuer/Author\n";	
		if (spaceTrim(document.form0.Title.value) == "") errormessage=errormessage +  "Title\n";	
		if (spaceTrim(document.form0.Attachment.value) == "") errormessage=errormessage +  "Attachment\n";	
	}		
//*----------------
//* BUYERS COACH
//*---------------- 
	if (thefile.substring(0,"res-serv-coach".length) == "res-serv-coach" ) {
		//** Must be a number
 		 if (spaceTrim(document.form0.No_of_Increments.value) == "") errormessage=errormessage +  "No. of 15 min. Increments\n";	
		 if (!isInteger(spaceTrim(document.form0.No_of_Increments.value))) errormessage=errormessage +  "No. of 15 min. Increments\n";	
		 
		  if (spaceTrim(document.form0.Session_Time_1.value) == "" & spaceTrim(document.form0.Session_Time_2.value) == "" & spaceTrim(document.form0.Session_Time_3.value) == "") errormessage=errormessage +  "Preferred Session Time\n";		 
	}
		

//* if field exists on form  (Ask Expert)
	if (window.document.form0.Question) {
		if (spaceTrim(document.form0.Question.value) == "") errormessage=errormessage +  "Question\n";
	}
 	
// 	errormessage ="";  // Uncomment to deactivate validation for Testing

if (spaceTrim(document.form0.Comments.value) == "xxx") {errormessage=""; testFlag = 0;}  //*** FOR TESTING - BYPASS VALDIDATION
if (spaceTrim(document.form0.Comments.value) == "xx") {errormessage=""; testFlag = 1;}  //*** FOR TESTING - BYPASS VALDIDATION


 //  alert(testdir);
	if (errormessage !="") { alert (firstmessage + errormessage) ; return false; }
	else { 	
//***---------------------------------------
//***  Input valid - submit form 	
//***---------------------------------------
		//* Vendor Enrollment Form
		if (thefile.substring(0,"dir-vendor-enrol".length) == "dir-vendor-enrol" ) {
		//	emailto_vendorenrol = "pc@twistedpixel.com";
			sEmailto = emailto_vendorenrol;
			sFormid = "vendorenrol";
			sSubject = "Vendor Enrolment"
			sPrefix = "dir-";
		} 	
		
		if (thefile.substring(0,"dir-mediakit".length) == "dir-mediakit" ) {
		//	emailto_vendorenrol = "pc@twistedpixel.com";
			sEmailto = emailto_mediakit;
			sFormid = "vendorenrol";
			sSubject = "Media Kit"
			sPrefix = "dir-";
		} 		
		//* Affiliate Form
		if (thefile.substring(0,"dir-affiliate".length) == "dir-affiliate" ) {
		//	emailto_affil = "pc@twistedpixel.com";
			sEmailto = emailto_affil;
			sFormid = "affil";
			sSubject = "Affiliate Program"
			sPrefix = "dir-";
		} 		
//*---------------------------------------
//* NEWS
//*---------------------------------------		
		if (thefile.substring(0,"news-subrel".length) == "news-subrel" ) {
			sEmailto = emailto_subrel;
			sFormid = "subrel";
			sSubject = "Submit Release"
			sPrefix = "news-";
		} 		
//*---------------------------------------
//* REFERRAL
//*---------------------------------------		
//****** Form moved from RES-SERV to REF- section  - 2009-10-04
		if (thefile.substring(0,"ref-askexpert".length) == "ref-askexpert" ) {
			sEmailto = emailto_askexpert;
			sFormid = "askexpert";
			sSubject = "Ask an Expert"
			sPrefix = "ref-";
		} 
 
//****** OLD - Form moved to REF- section	- NOT USED AS OF 2009-10-11	
//		if (thefile.substring(0,"res-serv-rfi".length) == "res-serv-rfi" ) {
//			sEmailto = emailto_rfi;
//			sFormid = "rfi";
//			sSubject = "Vendor RFI"
//			sPrefix = "res-";
//		} 	

//****** MOVED FORM 2009-10-04
		if (thefile.substring(0,"ref-rfi".length) == "ref-rfi" ) {
			sEmailto = emailto_rfi;
			sFormid = "rfi";
			sSubject = "Vendor RFI"
			sPrefix = "ref-";
		} 	
//****** NEW FORM 2009-10-04
		if (thefile.substring(0,"ref-askreferral-form".length) == "ref-askreferral-form" ) {
			sEmailto = emailto_askrefer;
			sFormid = "askrefer";
			sSubject = "ASK FOR REFERRAL"
			sPrefix = "ref-";
			document.form0.sendemailcc.value = document.form0.Email.value; //* cc the user
		}

//*---------------------------------------
//* RESOURCES
//*---------------------------------------
		if (thefile.substring(0,"res-serv-coach".length) == "res-serv-coach" ) {
			sEmailto = emailto_coach;
			sFormid = "coach";
			sSubject = "Coaching Request"
			sPrefix = "res-";
		}											
		if (thefile.substring(0,"res-pub-addpub".length) == "res-pub-addpub" ) {
			sEmailto = emailto_addpub;
			sFormid = "addpub";
			sSubject = "Add a Publication"
			sPrefix = "res-";
		} 	
		if (thefile.substring(0,"res-links-addlink".length) == "res-links-addlink" ) {
			sEmailto = emailto_addlink;
			sFormid = "addlink";
			sSubject = "Add a Link"
			sPrefix = "res-";
		} 	
		if (thefile.substring(0,"res-job-addjob".length) == "res-job-addjob" ) {
			sEmailto = emailto_addjob;
			sFormid = "addjob";
			sSubject = "Add a Job"
			sPrefix = "res-";
		} 	
		if (thefile.substring(0,"res-job-addcand".length) == "res-job-addcand" ) {
			sEmailto = emailto_addcand;
			sFormid = "addcand";
			sSubject = "Add a Candidate"
			sPrefix = "res-";
		} 			 
//alert(thefile)
//*----------------------------------------------
//* Use /mailer/FORMMAIL.PHP for forms with attachments  		 
//*----------------------------------------------
		if (thefile.substring(0,"res-pub-addpub".length) == "res-pub-addpub" || thefile.substring(0,"news-subrel-form".length) == "news-subrel-form"  ) {
	  		document.form0.recipients.value = sEmailto;
			if (testFlag) document.form0.recipients.value = "pc@twistedpixel.com"; 	 //* TEST - cc in comments sends to me (pc)
	 		document.form0.bcc.value = bcc; //* Defined in setup.js	  	
	  		document.form0.email.value = document.form0.Email.value
	  		document.form0.subject.value = sSubject_pref + sSubject;
	  		document.form0.good_url.value = "http://www.ec-edi.biz/" + testdir + "content/en/" + sPrefix + "confirm.asp?fid=" + sFormid;
//	  		document.form0.action = "../formmail/formmail.php"; 
	  		document.form0.action = "../../mailer/formmail.php";
	  		document.form0.enctype = "multipart/form-data";
		} 		
	else {		
		//*----------------------------------------------
		//* Use /mailer/FORMSEND.ASP
		//*----------------------------------------------					
 		document.form0.sendemailto.value = sEmailto;
		if (testFlag) document.form0.sendemailto.value = "pc@twistedpixel.com"; 	 //* TEST - xx in comments sends to me
 		
 		document.form0.sendemailbcc.value = bcc;  
 		 
  		document.form0.sendemailfrom.value = document.form0.Email.value
  		document.form0.sendemailsubject.value = sSubject_pref + sSubject;
//    	testdir = "test/";  //* defined in setup.js
//    	document.form0.redirect.value = "http://www.ec-edi.biz/" + testdir + "content/en/confirm.asp?fid=" + sFormid;
    	document.form0.redirect.value = "http://www.ec-edi.biz/" + testdir + "content/en/" + sPrefix + "confirm.asp?fid=" + sFormid;
    	    
  		document.form0.action = "http://www.ec-edi.biz/" + testdir + "mailer/formsend.asp"; 
 	}
  		  
  		document.form0.method = "POST";
  		document.form0.submit()
		return(0); 	
   }  
}

function calcPromo (form, func)  {
//*******************************************************************************
//	Calculate Total of Form, then redisplay the form with the discount.
//*******************************************************************************
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage=""; 
	
	if (spaceTrim(document.form0.PromoCode.value) == "") errormessage=errormessage + "Promotion Code\n";
 	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 
		document.form0.action = "dir-prod-form.asp?func=" + func; 
  		document.form0.method = "POST";
  		document.form0.submit()
		return(0); 			
	}
}

function doFree (form, func)  {
//*******************************************************************************
//	This rtn is done just to capture the optional promo code and pass it on to the reg form.
//  func will be Free Search "fs" or Free PDF "fpdf"
//*******************************************************************************
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage=""; 
	var sPromo = spaceTrim(document.form0.PromoCode.value);
	
//* Make promo mandatory 2008-03-08	
//	if (sPromo == "") { }
//	else {
		if (isNumberString(sPromo) == false  || sPromo.length != 4) errormessage=errormessage + "Promotion Code\n";
//	}		
  	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 
			document.form0.thePromoCode.value = spaceTrim(document.form0.PromoCode.value);
			document.form0.action = "dir-prod-reg-form.asp?func=" + func; 
	  		document.form0.method = "POST";
	  		document.form0.submit()
			return(0); 			
	 	}
}

function doPaidSearch (form, func)  {
//*******************************************************************************
//	Paid Search PS
//  func = ps2 if already logged in.
//*******************************************************************************
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage=""; 
	
		// Category RADIO
	if (document.form0.Paid_Search[0].checked ||
		document.form0.Paid_Search[1].checked ||
		document.form0.Paid_Search[2].checked ) {	
			if (document.form0.Paid_Search[0].checked) {
				 document.form0.theProdCode.value = "01"; 
				 document.form0.theMonthsAccess.value = 1;
				 document.form0.theProdPrice.value = document.form0.Paid_Search[0].value;
			}	
			if (document.form0.Paid_Search[1].checked) { 
				document.form0.theProdCode.value = "02";
				document.form0.theMonthsAccess.value = 6;
				document.form0.theProdPrice.value = document.form0.Paid_Search[1].value;
				
			}
			if (document.form0.Paid_Search[2].checked) { 
				document.form0.theProdCode.value = "03"; 
				document.form0.theMonthsAccess.value = 12;
				document.form0.theProdPrice.value = document.form0.Paid_Search[2].value;
			}	
		}	
	  	else {errormessage=errormessage + "No. of months to search\n"} 		
	if (window.document.form0.PromoCode) {  	
		if (spaceTrim(document.form0.PromoCode.value) != "" && document.form0.theDiscount.value == "0") {
			errormessage=errormessage + "Code not validated... click Validate Code\n"
		}		  	  		  	  	
	}	
	  		  	  	
//alert(	document.form0.theProdPrice.value)	  	
	
 	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 
//		alert(doPaidSearch)
		document.form0.action = "dir-prod-reg-form.asp?func=" + func; 
		//* By pass the registration form
 		if (func == "ps2") {
			document.form0.action = "dir-prod-reg-data2.asp?func=" + func; 
		}		
  		document.form0.method = "POST";
 		document.form0.submit()
		return(0); 			
	}
}

function doPaidPDF (form, func)  {
//*******************************************************************************
//	Paid PDF  PPDF - Called from dir-prod-form.asp
//  func = ppdf2 if already logged in.
//*******************************************************************************
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";   

	document.form0.theProdCode.value = "10"; 
	document.form0.theProdPrice.value = document.form0.Paid_PDF.value;  		  	  	
	if (window.document.form0.PromoCode) {  
		if (spaceTrim(document.form0.PromoCode.value) != "" && document.form0.theDiscount.value == "0") {
			errormessage=errormessage + "Code not validated... click Validate Code\n"
		}	
	}		
	  		  	  	
//alert(	document.form0.theProdPrice.value)	  	
	
 	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 
		document.form0.action = "dir-prod-reg-form.asp?func=" + func; 
		//* By pass the registration form
 		if (func == "ppdf2") {
			document.form0.action = "dir-prod-reg-data2.asp?func=" + func; 
		}
  		document.form0.method = "POST";
 		document.form0.submit()
		return(0); 			
	}
}

function doPaidPRT (form, func)  {
//*******************************************************************************
//	Printed Edition PPRT - Called from dir-prod-form.asp
//  func = pprt2 if already logged in.
//*******************************************************************************
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";   	

	document.form0.theProdCode.value = "11"; 
	document.form0.theProdPrice.value = document.form0.Paid_PRT.value;  		  	  	
	
	if (window.document.form0.PromoCode) {  
		if (spaceTrim(document.form0.PromoCode.value) != "" && document.form0.theDiscount.value == "0") {
			errormessage=errormessage + "Code not validated... click Validate Code\n"
		}
	}			
	  		  	  	
//alert(	document.form0.theProdPrice.value)	  	
	
 	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 
		document.form0.action = "dir-prod-reg-form.asp?func=" + func; 
		//* By pass the registration form		
		 if (func == "pprt2") {
			document.form0.action = "dir-prod-reg-data2.asp?func=" + func; 
		}
  		document.form0.method = "POST";
 		document.form0.submit()
		return(0); 			
	}
}

function doFreeSearchRenew (form, func)  {
//*******************************************************************************
//	Free Online Search Renew - Called from dir-prod-form.asp
//  func = fs2 if already logged in.
//*******************************************************************************
 	if (func == "fs2") {
		document.form0.action = "dir-prod-reg-data2.asp?func=" + func; 
	}
	else {
		alert("Error in doFreeSearchRenew(). Invalid Func:" + func)
	}
  	document.form0.method = "POST";
 	document.form0.submit()
	return(0); 			 
}

function doPaidCoach (form)  {
//*******************************************************************************
// PAID FORM	Buyers Coach form - dir-prod-form.asp?func=pcr2
//*******************************************************************************
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";  
	
	document.form0.theProdCode.value = "12"; 
	document.form0.theProdPrice.value = document.form0.Paid_COACH.value;  	//Total calc'ed in doPaidCoachTotal()
	 	
		//** Must be a number
 	if (spaceTrim(document.form0.No_of_Increments.value) == "") errormessage=errormessage +  "No. of 15 min. Increments\n";	
	if (!isInteger(spaceTrim(document.form0.No_of_Increments.value))) errormessage=errormessage +  "No. of 15 min. Increments\n";	
		 
	 if (spaceTrim(document.form0.Session_Time_1.value) == "" & spaceTrim(document.form0.Session_Time_2.value) == "" & spaceTrim(document.form0.Session_Time_3.value) == "") errormessage=errormessage +  "Preferred Session Time\n";		


 	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else {  	 	
		document.form0.action = "dir-prod-reg-data2.asp?func=pcr2"; 		
  		document.form0.method = "POST";
 		document.form0.submit()
		return(0); 			
	}
}

function doPaidCoachTotal (form)  {
//*******************************************************************************
//	PAID FORM - Calculate Total of Form for DIR-coach-form.asp  
//*******************************************************************************
	var theTotal = 0;
 
 	var theUnitCost = document.form0.theUnitCost.value;
	
	var qty = spaceTrim(document.form0.No_of_Increments.value);
//	alert(theUnitCost);
  	if (qty == "" ||  !isInteger(qty) ) { alert("Invalid No. Increments. Cannot calculate Total Cost\n"); }
	else {
 		theTotal = theUnitCost * qty;
 //		alert(theTotal);
 	 	document.form0.Total.value = "$ " + formatDollar(theTotal,true);	
 	 	document.form0.Paid_COACH.value =  formatDollar(theTotal,true);  // Put total on form.	
 	} 
}

function calcCoachTotal (form)  {
//*******************************************************************************
//	Calculate Total of Form for RES-coach-form.asp
//*******************************************************************************
	var theTotal = 0;
	var theTotalplusGST = 0;
 	var theUnitCost = document.form0.theUnitCost.value;
 	var theGSTline = ""; 
 	var theGST = 0;
	
	var qty = spaceTrim(document.form0.No_of_Increments.value);
//	alert(theUnitCost);
  	if (qty == "" ||  !isInteger(qty) ) { alert("Invalid No. Increments. Cannot calculate Total Cost\n"); }
	else {
 		theTotal = theUnitCost * qty;
// 		theTotalplusGST  = theTotal;
 		// if GST checkbox checked, add GST to total
 //		alert(document.form0.GST.checked);
 		if (document.form0.GST.checked) { 
 			
 			theTotal =  theTotal * 1.07;
 			//round to two decimals 
 			theTotal = Math.round(theTotal*100)/100;
 		}
 //		alert(theTotal);
 	 	document.form0.Total.value = "$ " + formatDollar(theTotal,true);
 	} 
}

function doLogin (form) {	
//******************************************************************************* 
//  Validate Login form 
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n_____________________________________________\n\n ";
	var errormessage="";
	var fieldisblank=true;						

   if (document.form0.UserName.value.length ==0 || document.form0.UserName.value.indexOf('@', 0) == -1 || document.form0.UserName.value.indexOf('.', 0) == -1) 
	{errormessage=errormessage+"User Name (Your Email Address)\n"} 
	
//*** PASSWORD 
    fieldisblank=true
    for (j=0; j < document.form0.Password.value.length; j++) 
    {
      if (document.form0.Password.value.substring(j,j+1) !=" ") {fieldisblank=false}
    }
    if (document.form0.Password.value.length < 4 || fieldisblank)
      	{errormessage=errormessage+" Password\n"}	

//	errormessage = "";   // Uncomment to deactivate the validation for testing
 

   if (errormessage !="") { alert (firstmessage + errormessage); }
   else {   
  	document.form0.action = "dir-login-data.asp"; 
    document.form0.method = "POST";
  	document.form0.submit();
 	return(0);  
   }
 
}

function doSendPass ( form ) {	
//******************************************************************************* 
//  Validate Sending of Password back to user
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n_____________________________________________\n\n ";
	var errormessage="";
	var fieldisblank=true;

//*** Email (EMAIL) 

   if (document.form0.UserName.value.length ==0 || document.form0.UserName.value.indexOf('@', 0) == -1 || document.form0.UserName.value.indexOf('.', 0) == -1) 
	{errormessage=errormessage+"Userid (Your Email Address)\n"} 

//	errormessage = "";   // Uncomment to deactivate the validation for testing

   if (errormessage !="") { alert (firstmessage + errormessage); }
   else {   
  	document.form0.action = "dir-login-sendpass.asp"; 
    document.form0.method = "POST";
  	document.form0.submit();
 	return(0);  
   }   
}


function doVendorRFI ( form ) {	
//******************************************************************************* 
//  Validate and send form.  
//******************************************************************************* 
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";
	var errorcode=0; 
	var testFlag = 0;  // set to 1 if Comments = "xx" - bypass validation.
	var len;
	
	var Vendor_Email_1 = spaceTrim(document.form0.Vendor_Email_1.value);
	
	if (Vendor_Email_1.length ==0 || Vendor_Email_1.indexOf('@', 0) == -1 || Vendor_Email_1.indexOf('.', 0) == -1) 
	{errormessage=errormessage+"Vendor Email Address\n"; }

	if (window.document.form0.Name) {
		if (spaceTrim(document.form0.Name.value) == "") errormessage=errormessage + "Name\n";		
	}
	if (window.document.form0.Company) {
		if (spaceTrim(document.form0.Company.value) == "") errormessage=errormessage + "Company\n";
	}	
	if (spaceTrim(document.form0.Telephone.value) == "") errormessage=errormessage + "Telephone\n";
	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"} 
//*------------------------------------
//*** Areas_of_Interest/CATEGORY MULTIPLE SELECT LIST
//*------------------------------------
	nSelected = 0;
	 for(i = 0; i < document.form0.Areas_of_Interest.length; i++) {
	//	document.form0.Areas_of_Interest[i].selected = true;
		if (document.form0.Areas_of_Interest[i].selected == true) {
			nSelected = nSelected + 1;
		}
	}	
	//alert(nSelected)
	if (nSelected == 0 ) {errormessage=errormessage+"Area of Interest\n"} 
	if (nSelected > 3 ) {errormessage=errormessage+"More than 3 Area of Interest selected\n"} 
//*------------------------------------
//*** Industry SELECT LIST
//*------------------------------------
  	itemx = document.form0.Industry.selectedIndex;
 	itemval = document.form0.Industry.options[itemx].value
 	if (itemval == "") errormessage = errormessage + "Industry\n";

//*------------------------------------
//*** TIME FRAME RADIOS  2009-02-23
//*------------------------------------
 
//* Check of field exists, it's not on the rfi2 form, just on the rfi form.

 	if(document.getElementById('Time_Frame') != null) {	
		if (document.form0.Time_Frame[0].checked ||
			document.form0.Time_Frame[1].checked ||
			document.form0.Time_Frame[2].checked) {  }
		else errormessage=errormessage + "Time Frame\n";
  	} 
				
//   	errormessage ="";  // Uncomment to deactivate validation for Testing

	if (spaceTrim(document.form0.Comments.value) == "zz") {errormessage=""; testFlag = 1;}   
	if (spaceTrim(document.form0.Comments.value) == "xx") {errormessage=""; testFlag = 2;}  
 
   if (errormessage !="") { alert (firstmessage + errormessage) ; return false; }
   else { 
		// Default, but it's overidden in res-serv-rfi-form-mailer.asp
		document.form0.sendemailto.value = "customerservice@ec-edi.biz";  
		
//*--------------------------		
    	testdir = "test/";   //* COMMENT OUT THIS STATEMENT FOR PRODUCTION
//   	testdir = "";
//*--------------------------

		//* zz sends to email field		
		if (testFlag == 1) document.form0.Vendor_Email_1.value = document.form0.Email.value; 
		//* xx sends to me (pc)
		if (testFlag == 2) document.form0.Vendor_Email_1.value = "pc@twistedpixel.com";
 
 		document.form0.sendemailbcc.value = "leem@vantagepoint.ca, pc@twistedpixel.com"; 			 	
 		document.form0.sendemailsubject.value = "EC-EDI: Request for Information";
 
// 		document.form0.redirect.value = "http://www.ec-edi.biz/" + testdir + "content/en/res-confirm.asp?fid=" + "rfi";	
 
//*Form moved to new referral network section (ref-)  2009-10-04
 		document.form0.redirect.value = "http://www.ec-edi.biz/" + testdir + "content/en/ref-confirm.asp?fid=" + "rfi"; 			
 	
//*     Trading Partner RFI form uses different Confirm page without main site hdr and footer 	
 		if (thefile.substring(0,"res-serv-rfi3-form".length) == "res-serv-rfi3-form" )	{
 			document.form0.redirect.value = "http://www.ec-edi.biz/" + testdir + "content/en/res-serv-rfi3-confirm.asp?fid=" + "rfi";	
 		}
 	
  	 	document.form0.sendemailfrom.value = document.form0.Email.value;
  		document.form0.action = "res-serv-rfi-form-mailer.asp";; 
  		document.form0.method = "POST";
 		document.form0.submit();
		return(0);  
   }  
}

function doPayInvoice (form, func)  {
//*******************************************************************************
//	 Func = "inv"
//Your payment has been received. Thank You
//*******************************************************************************
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage="";
  	var sMerchantNumber_CA	= "7057";
  	var sMerchantNumber_US	= "7058";  	
	var sPrice				= "";
  	var sProd00				= "Price::Qty::Code::Description::Flags" ;
	var sProd01				= "";
//	var sTest				= ""; // Set to {Test} to trigger submit test transaction to IS
	var sGST				= "";
	var sQty 				= 1;
	var sDesc 				= "Payment for Invoice: ";
	var sCode 				= "98";
	var sFunc 				= "inv";
	
//	sTest = "{Test}";   // Activates Test mode on internet secure
//	sTest = "";			// Uncomment to place into production
	sGST = ""		// sGST = "{GST}"

	if (spaceTrim(document.form0.Invoiceno.value) == "") errormessage=errormessage +  " Invoice No.\n";	
	
	sAmount = document.form0.Amount.value;
	if (sAmount == "" || isDollarString(sAmount) == false || formatDollar(sAmount) == false )
	  {errormessage=errormessage + " Amount\n";}
 	
		// Currency RADIO
	if (document.form0.Currency[0].checked ||
		document.form0.Currency[1].checked ) {
			if (document.form0.Currency[0].checked) sMerchantNumber = sMerchantNumber_US;
			if (document.form0.Currency[1].checked) sMerchantNumber = sMerchantNumber_CA;
		}
	else {errormessage=errormessage + "Currency\n"} 	
 		 					

// 	errormessage ="";  // Uncomment to deactivate validation for Testing
   
   if (errormessage !="") { alert (firstmessage + errormessage) ; return false; }
   else { 
   	    if (sTest == "{Test}") {
//        	alert("NOTE: You are submitting a transaction with TEST flag ON.");
	    }   
	    
	    sDesc = sDesc + document.form0.Invoiceno.value;
	    sPrice = document.form0.Amount.value;
	    sProd01 = "|" + sPrice + "::" + sQty + "::" + sCode + "::" + sDesc + "::" + sGST + sTest;
	    document.form0.Products.value = sProd00 + sProd01;
     	
//     	alert("Products=|" + sProd00 + sProd01 + "|");
     	
 	  	document.form0.MerchantNumber.value = sMerchantNumber;
 	 	document.form0.xxxVar1.value = sFunc;  	 	
 	 	document.form0.xxxVar5.value = ""; 			//* Internet Secure Exit script (non required) 	  	
  	  	document.form0.language.value = "English";
      	document.form0.ReturnURL.value = "http://www.ec-edi.biz/" + testdir +  "content/en/dir-confirm.asp?fid=" + sFunc; 
    	
  	 	document.form0.action = "https://secure.internetsecure.com/process.cgi";  
  		document.form0.method = "POST";
 		document.form0.submit();
  		return(0);  
   }  
} 

function doLogOut ( form ) {	
//******************************************************************************* 
//   
//******************************************************************************* 
	location.href = "dir-survey-data.asp?logout=y";
}

function doSurvey ( form ) {	
//******************************************************************************* 
//   
//*******************************************************************************
	var firstmessage="Please provide the following valid information:\n\n ";
	var errormessage=""; 
	
	if (document.form0.Q1_Find_It[0].checked ||
		document.form0.Q1_Find_It[1].checked ) {	}
	else {errormessage=errormessage + "Question 1\n"} 
	
	if (document.form0.Q2_Easy_Search[0].checked ||
		document.form0.Q2_Easy_Search[1].checked ) {	}
	else {errormessage=errormessage + "Question 2\n"} 

//*** Loop through all 10 buttons	
	for (i=0, n=document.form0.Q3_Rate_Experience.length; i<n; i++) {
	   if (document.form0.Q3_Rate_Experience[i].checked) {
	      var checkvalue = document.form0.Q3_Rate_Experience[i].value;
	      break;
	   }
	}
	if (!(checkvalue)) {
		errormessage=errormessage + "Question 3\n"	
	}
	
	
	if (document.form0.Q4_Refer[0].checked ||
		document.form0.Q4_Refer[1].checked ) {	}
	else {errormessage=errormessage + "Question 4\n"} 			
	
	if (document.form0.Q5_Industry_Sector[0].checked ||
		document.form0.Q5_Industry_Sector[1].checked ) {	}
	else {errormessage=errormessage + "Question 5\n"} 	
 
	if (spaceTrim(document.form0.Email.value) != "") {
		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"} 
	}	
	
//	alert(document.form0.Name.value);
	
   if (errormessage !="") { alert (firstmessage + errormessage) ; return false; }
   else { 

  		document.form0.action = "dir-survey-data.asp";; 
  		document.form0.method = "POST";
 		document.form0.submit();
		return(0);  
   }  
}
 
function loadpc( ) {
//*******************************************************************************
// load form with test data
//*******************************************************************************
 
   document.form0.Vendor_Email_1.value =  "pc@twistedpixel.com";
   document.form0.Vendor_Email_2.value =  "twisted6@csolve.net";
   document.form0.Vendor_Email_3.value =  "paul@atlis.net";
    document.form0.Name.value = "Paul Charles";
    document.form0.Company.value = "Twisted Pixel"; 
    document.form0.Telephone.value = "705-555-1212";
    document.form0.Email.value =  "info@twistedpixel.com";
//    document.form0.Areas_of_Interest[0].checked = 1;
//    document.form0.Areas_of_Interest[1].checked = 1;
//    document.form0.Areas_of_Interest[2].checked = 1;
//    document.form0.Areas_of_Interest[3].checked = 1;
//    document.form0.Areas_of_Interest[4].checked = 1;
//    document.form0.Areas_of_Interest[5].checked = 1;
//    document.form0.Areas_of_Interest[6].checked = 1;
//    document.form0.Areas_of_Interest[7].checked = 1;
//    document.form0.Areas_of_Interest[8].checked = 1;
//    document.form0.Areas_of_Interest[9].checked = 1;
//    document.form0.Areas_of_Interest[10].checked = 1;
//    document.form0.Areas_of_Interest[11].checked = 1;
    
    document.form0.Comments.value =  "I like EDI.";
    document.form0.Submitted_by_Name.value = "Mister Twisted";
    document.form0.Submitted_by_Company.value = "Pixels R US"; 
    document.form0.Submitted_by_Telephone.value = "705-444-4444";
    document.form0.Submitted_by_Email.value =  "mistertwisted@hotmail.com";    
}

function loadlee( ) {
//*******************************************************************************
// load form with test data
//*******************************************************************************
 
   document.form0.Vendor_Email_1.value =  "customerservice@edidirectory.com";
   document.form0.Vendor_Email_2.value =  "leem@edidirectory.com";
   document.form0.Vendor_Email_3.value =  "info@edidirectory.com";
    document.form0.Name.value = "Lee M.";
    document.form0.Company.value = "Vantage Point"; 
    document.form0.Telephone.value = "416-555-1212";
    document.form0.Email.value =  "leem@vantagepoint.ca";
//    document.form0.Areas_of_Interest[0].checked = 1;
//    document.form0.Areas_of_Interest[1].checked = 1;
//    document.form0.Areas_of_Interest[2].checked = 1;
//    document.form0.Areas_of_Interest[3].checked = 1;
//    document.form0.Areas_of_Interest[4].checked = 1;
//    document.form0.Areas_of_Interest[5].checked = 1;
//    document.form0.Areas_of_Interest[6].checked = 1;
//    document.form0.Areas_of_Interest[7].checked = 1;
//    document.form0.Areas_of_Interest[8].checked = 1;
//    document.form0.Areas_of_Interest[9].checked = 1;
//    document.form0.Areas_of_Interest[10].checked = 1;
//    document.form0.Areas_of_Interest[11].checked = 1;
    
    document.form0.Comments.value =  "I like EDI.";
    document.form0.Submitted_by_Name.value = "The Leemster";
    document.form0.Submitted_by_Company.value = "Leems R Us"; 
    document.form0.Submitted_by_Telephone.value = "416-444-4444";
    document.form0.Submitted_by_Email.value =  "leem@vantagepoint.ca";    
}
	
function loadpc_login( ) {
//*******************************************************************************
// load form with test data
//*******************************************************************************
 
   document.form0.UserName.value = "pc@xxxtwistedpixel.com";
   document.form0.Password.value = "xxxx"; 
}

function load_UserName(uid ) {
   document.form0.UserName.value = uid + "@xxxtwistedpixel.com";
   document.form0.Password.value = "xxxx"; 
}

function loadpc_active_buyer( ) {
   document.form0.UserName.value = "11@xxxtwistedpixel.com";
   document.form0.Password.value = "xxxx"; 
}

function loadpc_active_vendor( ) {
   document.form0.UserName.value = "22@xxxtwistedpixel.com";
   document.form0.Password.value = "xxxx"; 
}
function loadpc_active_promo( ) {
   document.form0.UserName.value = "33@xxxtwistedpixel.com";
   document.form0.Password.value = "xxxx"; 
}
