
//var DHTML = (document.getElementById || document.all || document.layers);
//*-------------------------------------------------------------------------
//*  Flip visibility for a div name.
//*  invi(0, "ans1");   	// 0 = make visible  1=make invisible	
//*-------------------------------------------------------------------------
function invi(flag, obj)
{
//	if (!DHTML) return;
	var x = new getObj(obj);
	x.style.visibility = (flag) ? 'hidden' : 'visible'
	x.style.display = (flag) ? 'none' : 'block'
}

function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}
//*-------------------------------------------------------------------------
//* General functions for the site.
//*-------------------------------------------------------------------------

//* get out of frames, just in case.
if (top.frames.length!=0) {
    if (window.location.href.replace)
        top.location.replace(self.location.href);
    else
        top.location.href=self.document.href;
}

//*-------------------------------------------------------------------------
//* Get page url.
//*-------------------------------------------------------------------------
function getFileName(){
  var temp = window.location.href;
  alert(temp.substring(temp.lastIndexOf('/') + 1));
}
 
function flipImg(imgNam,imgTyp,onoff){
//*******************************************************************************
//	Do the mouse over image flipping.
//******************************************************************************* 		
  	if(document.images){ 	
 		document.images[imgNam].src=eval(imgTyp+onoff+'.src');
  	}
}

function doClear ( form ) {	
//*******************************************************************************
// Clear Form  - pagelan is defined in setup-e.js (or -f).
//*******************************************************************************	
//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 doSearch ( form ) {	
//*******************************************************************************
// Validate Form
//*******************************************************************************	
	var firstmessage="Please provide the following valid information:\n____________________________________\n ";
	var errormessage="";
	var len;
	
//	alert("Search Function not yet implemented");
		document.form1.action = "search-" + pagelang + ".asp";  //* Search
  		document.form1.method = "POST";
  		 document.form1.submit();
		return(0); 
}

function clearText(thefield){
//*******************************************************************************
//	Clear default form value on mouse focus
//******************************************************************************* 	
	if (thefield.defaultValue==thefield.value) thefield.value = "";
} 

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) {
       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 makeArray(){
    this.length = makeArray.arguments.length 
        for (var i = 0; i < this.length; i++)
        this[i + 1] = makeArray.arguments[i]
}

function showStatus(text) {
//*******************************************************************************
// Show text on status bar. Use this to get around IE5 bug.
// onMouseOver="showStatus('text to display');return true" onMouseOut="window.status='';return true"
//*******************************************************************************	
    window.setTimeout('window.status="' + text + '"', 1);
}

function countChar(searchString, theChar) {
//*******************************************************************************
// string for a specific character and stops its search when it finds it or runs out of characters to look for
//*******************************************************************************
	var found = false
	n = 0;
	count = 0;
//	alert(searchString)
 //alert("test".charAt(1))
		for (i=0; i <= searchString.length; i++) {
	//		alert(searchString.charAt[i])
			if (searchString.charAt(i) == theChar){
				found = true;
				count++;
//				alert("count=" + count)
			}			
			else {
				n++;
			}	
		} 
//	alert(count + " n=" + n)
	return(count);
	
}

function xcountChar(searchString, theChar) {
//*******************************************************************************
// string for a specific character and stops its search when it finds it or runs out of characters to look for
//*******************************************************************************
	var found = false
	n = 0;
		while (n <= searchString.length || !found) {
		if (searchString.charAt(n) == theChar){
			found = true;
		}			
		else {
			n++;
		}	
	} 
	return(n);
}
 
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 isNumberString2 (InString)  {
//***********************************************************
// Just numbers
//***********************************************************
	if(InString.length==0) 
		return (false);
	RefString="1234567890";
	for (Count=0; Count < InString.length; Count++)  {
		TempChar= InString.substring (Count, Count+1);
		if (RefString.indexOf (TempChar, 0)==-1)  
			return (false);
	}
	return (true);
}

function rightString (InString, num)  {
	OutString=InString.substring (InString.length-num, InString.length);
	return (OutString);
}
 
/*------------------------------------------------
  Print the file or selection.
-------------------------------------------------*/
function printit(){  
	
//	onclick="javascript:window.print();
	window.print() 
}


/*------------------------------------------------
Mail the url using users email client software
-------------------------------------------------*/
function mailThisUrl() {
	var msg = "You may find this link useful: ";
	var u = window.location;
	var theTitle = document.title;
	var theURL = window.location.href;
	var whereAnchor = theURL.indexOf("#");
	
	//* Remove #abc anchor suffixes, if present.
	if (whereAnchor > 0) {	
		theURL = theURL.substring(0, whereAnchor);		
	}		
	
   //* Remove #abc from title, if it's there.
	whereAnchor = theTitle.indexOf("#");
	if (whereAnchor > 0) {	
		theTitle = theTitle.substring(0, whereAnchor);		
	}
	
 	window.location = "mailto:" + "" + "?subject=" + theTitle + "&body=" + msg + "  " + theURL;
// 	window.location = "mailto:" + "" + "?subject=" + theTitle + "&body=" + document.title + "   " + theURL;
} 


/*------------------------------------------------
OPT OUT - Unsubscribe to the newsletter
-------------------------------------------------*/
function optOut() {
	var msg = "Please remove me from the mailing list for the Route newsletter.";
	var theTitle = "Route Newsletter: UNSUBSCRIBE";	
  	window.location = "mailto:" + "bscharnberg@universallogistics.ca" + "?subject=" + theTitle + "&body=" + msg;
} 

function mailFormWindow() {
//*******************************************************************************
//	Display a window with form - NOT USED
//*******************************************************************************
 
	window.open("emailurl-form.asp", "newwin", "width=300,height=300,scrollbars=yes,status=yes,resizable=yes");
}

function doEmailForm ( form ) {	
//******************************************************************************* 
//  Do 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  
 
	    if (document.form0.Email.value.length ==0 || document.form0.Email.value.indexOf('@', 0) == -1 || document.form0.Email.value.indexOf('.', 0) == -1) {errormessage=errormessage+"Your Email address\n"} 
	    
	    if (document.form0.toEmail.value.length ==0 || document.form0.toEmail.value.indexOf('@', 0) == -1 || document.form0.toEmail.value.indexOf('.', 0) == -1) {errormessage=errormessage+"Your Friend's address\n"};      	 
 //  alert(testdir);
	if (errormessage !="") { alert (firstmessage + errormessage) ; return false; }
	else { 	
//***---------------------------------------
//***  Input valid - submit form 	
//***---------------------------------------	
		var sSubject = document.title;
		var theURL = window.location.href;
		var whereAnchor = theURL.indexOf("#");
		//* Remove #abc anchor suffixes, if present.
		if (whereAnchor > 0) {	
			theURL = theURL.substring(0, whereAnchor);		
		}	 
 
		//*----------------------------------------------
		//* Use /mailer/FORMSEND.ASP
		//*----------------------------------------------					
 		document.form0.sendemailto.value = document.form0.toEmail.value;
		if (testFlag) document.form0.sendemailto.value = "pc@twistedpixel.com"; 	 //* TEST - cc in comments sends to me (pc)
 		
// 		document.form0.sendemailbcc.value = "pc@twistedpixel.com"; 	 //* TEST
 		 
  		document.form0.sendemailfrom.value = document.form0.Email.value
  		document.form0.sendemailsubject.value = sSubject;    	
    	document.form0.redirect.value = "http://www.universallogistics.ca/route/emailurl-confirm.asp";    	    
  		document.form0.action = "http://www.universallogistics.ca/mailer/formsend.asp"; 
  		document.form0.method = "POST";
  		document.form0.submit()
		return(0); 	
   }  
}
