/*------------------------------------------------------------------
 2010-06-30 Div Hide toggle div
-------------------------------------------------------------------*/
 
//* This handles running script locally, on TEST, and in production without changes.
  	var thesite		= "http://www.sellmorestuff.ca";
	var test = "";  //* Defaults to production
	var dirx = location.href.substring(0,location.href.lastIndexOf('/')+1);	
	if (dirx.indexOf("/test/") > -1) {
		sMode = "TEST"	
//		thesite = "";
		test = "/test";			
	}
	if (dirx.indexOf("localhost") > -1) {
		sMode = "LOCAL"
		thesite = "";
		test = "/SellMoreStuff";	
	}
 
//******************************************************************************* 
//  Toggle show/hide div   http://www.randomsnippets.com/2008/02/12/how-to-hide-and-show-your-div/
//******************************************************************************* 
function toggle5 (showHideDiv, switchImgTag) {
        var ele = document.getElementById(showHideDiv);
        var imageEle = document.getElementById(switchImgTag);
        if(ele.style.display == "block") {
                ele.style.display = "none";
		imageEle.innerHTML = '<img src="../images/icon-plus.gif">';
        }
        else {
                ele.style.display = "block";
                imageEle.innerHTML = '<img src="../images/icon-minus.gif">';
        }
}


function doContact ( form ) {	
//******************************************************************************* 
//  CONTACT US 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 = "xx", 2 if "test" - bypass validation.
//***  
	var sEmailto = "wolfgang@wordsatwork.ca";			// Default receipient 
 
 	if (spaceTrim(document.form0.Name.value) == "") errormessage=errormessage + "Name\n";
 	if (spaceTrim(document.form0.Company.value) == "") errormessage=errormessage + "Company\n";
 	if (spaceTrim(document.form0.Job_Title.value) == "") errormessage=errormessage + "Job Title\n";
// 	if (spaceTrim(document.form0.Address1.value) == "") errormessage=errormessage + "Address\n";
// 	if (spaceTrim(document.form0.City.value) == "") errormessage=errormessage + "City\n";
// 	if (spaceTrim(document.form0.Province.value) == "") errormessage=errormessage + "Province\n";
// 	if (spaceTrim(document.form0.Postal_Code.value) == "") errormessage=errormessage + "Postal Code\n";
 	if (spaceTrim(document.form0.Telephone.value) == "") errormessage=errormessage + "Telephone\n";
	
	sEmail = spaceTrim(document.form0.Email.value);
//* if email not blank, it must be valid.
//	if (sEmail != "") {
		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"} 
//	}
 
//  	errormessage ="";  // Uncomment to deactivate validation for Testing

//* If comments start with xx, set testFlag on - for developer testing 
	var sComments = spaceTrim(document.form0.Comments.value);
	if (sComments.substring(0,2) == "xx") {errormessage=""; testFlag = 1;}
	if (sComments.substring(0,4) == "test") {errormessage=""; testFlag = 2;} 	

	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 	
 		
 	  	document.form0.recipients.value = sEmailto;
		
		if (testFlag == 1) {
			document.form0.recipients.value = "pc@twistedpixel.com";
			document.form0.Email.value 		= "pc@twistedpixel.com"; 
		}
		if (testFlag == 2) {
			document.form0.recipients.value = document.form0.Email.value;
		}		
		
 		document.form0.bcc.value = "pc@twistedpixel.com";			 	 	

		document.form0.email.value = document.form0.Email.value;
		//* Email field is blank so set from email (formmail "from" var) to default recipient
		if (spaceTrim(document.form0.Email.value) == "") {
			document.form0.email.value = sEmailto;
		} 
 	  		  	
 	  	sSubject = "SMS - CONTACT US";
 	  	
	  	document.form0.subject.value = sSubject;
 	
		document.form0.good_url.value = thesite + test + "/en/contact-confirm.asp";
 		document.form0.action = thesite + "/mailer/formmail.php";  	
 		
//	  	document.form0.enctype = "multipart/form-data";      //* For attachments
  		document.form0.method = "POST";
	  	document.form0.submit()
 		return(0); 	
   }  
}

function doSales ( form ) {	
//******************************************************************************* 
//  SALES TRAINING ORDER 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 = "xx", 2 if "test" - bypass validation.
//***  
	var sEmailto = "wolfgang@wordsatwork.ca";			// Default receipient 
 
 	if (spaceTrim(document.form0.Name.value) == "") errormessage=errormessage + "Name\n";
 	if (spaceTrim(document.form0.Company.value) == "") errormessage=errormessage + "Company\n";
 	if (spaceTrim(document.form0.Job_Title.value) == "") errormessage=errormessage + "Job Title\n";
// 	if (spaceTrim(document.form0.Address1.value) == "") errormessage=errormessage + "Address\n";
// 	if (spaceTrim(document.form0.City.value) == "") errormessage=errormessage + "City\n";
// 	if (spaceTrim(document.form0.Province.value) == "") errormessage=errormessage + "Province\n";
// 	if (spaceTrim(document.form0.Postal_Code.value) == "") errormessage=errormessage + "Postal Code\n";
 	if (spaceTrim(document.form0.Telephone.value) == "") errormessage=errormessage + "Telephone\n";
	
	sEmail = spaceTrim(document.form0.Email.value);
//* if email not blank, it must be valid.
//	if (sEmail != "") {
		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"} 
//	}
 
//  	errormessage ="";  // Uncomment to deactivate validation for Testing

//* If comments start with xx, set testFlag on - for developer testing 
	var sComments = spaceTrim(document.form0.Comments.value);
	if (sComments.substring(0,2) == "xx") {errormessage=""; testFlag = 1;}
	if (sComments.substring(0,4) == "test") {errormessage=""; testFlag = 2;} 	

	if (errormessage !="") { alert (firstmessage + errormessage) ;}
	else { 	
 		
 	  	document.form0.recipients.value = sEmailto;
		
		if (testFlag == 1) {
			document.form0.recipients.value = "pc@twistedpixel.com";
			document.form0.Email.value 		= "pc@twistedpixel.com"; 
		}
		if (testFlag == 2) {
			document.form0.recipients.value = document.form0.Email.value;
		}		
		
 		document.form0.bcc.value = "pc@twistedpixel.com";			 	 	

		document.form0.email.value = document.form0.Email.value;
		//* Email field is blank so set from email (formmail "from" var) to default recipient
		if (spaceTrim(document.form0.Email.value) == "") {
			document.form0.email.value = sEmailto;
		} 
 	  		  	
 	  	sSubject = "SMS - SALES TRAINING ORDER";
 	  	
	  	document.form0.subject.value = sSubject;
 	
		document.form0.good_url.value = thesite + test + "/en/contact-confirm.asp";
 		document.form0.action = thesite + "/mailer/formmail.php";  	
 		
//	  	document.form0.enctype = "multipart/form-data";      //* For attachments
  		document.form0.method = "POST";
	  	document.form0.submit()
 		return(0); 	
   }  
}

function ChangeColor(tableRow, highLight, theader) {
//******************************************************************************* 
//*   Change table row background colour on mouseover for debtor list 
//*   highLight: true = change colour / false = revert colour to original
//*   theader: true = table header colour change / false or null = regular table row
//******************************************************************************* 
	sBGcolor = "#FFFF99";
	sColor = "#000000";
 	sImage =  "url(../images/spacer.gif)";
	//* Table header specified, use different mouseover colour for column header - Not used for SMS
	if (theader == 1) {
		sBGcolor = "#023666";  	// Background colour (Dark blue on mouseover)
		sColor = "#FFFF99";  	// Text colour (Yellow on mouseover)
	}
 	
    if (highLight) {
//    	window.status='on on on';
   		sColorSave = tableRow.style.backgroundColor;   //* Save original colours b4 mouseover
   		sTextColorSave = tableRow.style.color;
   		sImageSave = tableRow.style.backgroundImage;
		tableRow.style.backgroundColor = sBGcolor;
		tableRow.style.color = sColor;
		tableRow.style.cursor='pointer';
 		tableRow.style.backgroundImage = "url(../images/spacer.gif)";
//		tableRow.style.backgroundImage = "url(../images/bg-home-box-red-on.jpg)";

		
//		alert(sImageSave);
    }
    else {
      tableRow.style.backgroundColor = sColorSave;	//* Reinstate original on mouseout
      tableRow.style.color = sTextColorSave;
      tableRow.style.backgroundImage = sImageSave;
//	  window.status='off'; 
    }
   
}

function doPage (page) {		
//******************************************************************************* 
// Call page 
//*******************************************************************************  
	var thePage = page;
	document.location.href = thePage;
	return; 
}

function doWinPage (page) {		
//******************************************************************************* 
// Call page, open a new browser window
//*******************************************************************************  
	var thePage = page;
	// width=420,height=760,
	window.open(thePage, "newwin", "menubar=yes,toolbar=yes,scrollbars=yes,status=yes,resizable=yes");
	return; 
}

function flipImg(imgNam,imgTyp,onoff){
//*******************************************************************************
//	Do the mouse over image flipping.
//******************************************************************************* 		
  	if(document.images){ 	
 		document.images[imgNam].src=eval(imgTyp+onoff+'.src');
  	}
}
 
 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 setCookie(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;
}
 
function getCookie(name) {
//*******************************************************************************
// Get a cookie.
//*******************************************************************************	
       var dc = document.cookie;
       var prefix = name + "=";
       var begin = dc.indexOf("; " + prefix);
       if (begin == -1) {
         begin = dc.indexOf(prefix);
         if (begin != 0) return null;
       } else
         begin += 2;
       var end = document.cookie.indexOf(";", begin);
       if (end == -1)
         end = dc.length;
       return unescape(dc.substring(begin + prefix.length, end));
     } 
     
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();    
}    

