// ppc 'whats this' popup window function - DO NOT REMOVE
function wtpopup(){
	wtpopupwin = window.open('/inc/wt.aspx', 'wtpopup', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=400,height=250');
}


// UX - Offermatica Install Point
function includeScript(src,id) {
	document.write('<sc' + 'ript src="' + src + '" type="text/javascript"'+(id?" id=\""+id+"\"":"")+'></sc' + 'ript>');
}
includeScript('http://www.green2s.com/ux/main.js',"UX_SCRIPT_INCLUDE");


//hornav image rollover for standard pages
function navRollOver (whichNav,imageFileType) {	
	var rollOverSuffix = "-over";
	var whichNav = whichNav.replace(/^\s+|\s+$/g,'');
	var imageFileType = imageFileType.replace(/^\s+|\s+$/g,'');
	var imagePath = "/i/hornav-";
	var navRoot = document.getElementById(whichNav);
	var args = getUrlSubString();	
	for(i=0; i<navRoot.childNodes.length; i++){
		node0 = navRoot.childNodes[i];
		if(node0.nodeName=='A'){
			for(a=0; a<node0.childNodes.length; a++){
				node1=node0.childNodes[a];
				if(node1.nodeName=="IMG"){
					node1.onmouseover=function(){
						if (
							(this.id=="getaquote" && args=="get-a-quote")||
							(this.id=="advertise" && args=="locator")||
							(this.id=="ourservices" && args=="our-services")||
							(this.id=="shippinglogistics" && args=="shipping-logistics")||
							(this.id=="freightguideinfo" && args=="freight-guide-info")||
							(this.id=="movers" && args=="movers")
							)
						{
							srcactive = imagePath+this.id+"-on"+imageFileType;
						} else {
							srcactive = imagePath+this.id+rollOverSuffix+imageFileType;
						}
						this.src = srcactive;						
					}
					node1.onmouseout=function(){						
						if (
							(this.id=="getaquote" && args=="get-a-quote")||
							(this.id=="advertise" && args=="locator")||
							(this.id=="ourservices" && args=="our-services")||
							(this.id=="shippinglogistics" && args=="shipping-logistics")||
							(this.id=="freightguideinfo" && args=="freight-guide-info")||
							(this.id=="movers" && args=="movers")
							)
						{
							src = imagePath+this.id+"-on"+imageFileType;
						} else {
							src = imagePath+this.id+imageFileType;	
						}						
						this.src = src;
					}
				}
			}
		}
	}
}

//image rollover for getaquote element
function getaquoteRollOver (whichNav,imageFileType) {	
	var rollOverSuffix = "-over";
	var whichNav = whichNav.replace(/^\s+|\s+$/g,'');
	var imageFileType = imageFileType.replace(/^\s+|\s+$/g,'');
	var imagePath = "/i/";
	var navRoot = document.getElementById(whichNav);
	var args = getUrlSubString();	
	for(i=0; i<navRoot.childNodes.length; i++){
		node0 = navRoot.childNodes[i];
		if(node0.nodeName=='A'){
			for(a=0; a<node0.childNodes.length; a++){
				node1=node0.childNodes[a];
				if(node1.nodeName=="IMG"){
					node1.onmouseover=function(){
						srcactive = imagePath+this.id+rollOverSuffix+imageFileType;
						this.src = srcactive;						
					}
					node1.onmouseout=function(){						
						src = imagePath+this.id+imageFileType;	
						this.src = src;
					}
				}
			}
		}
	}
}

//hornav image rollover for homepage
function navRollOverHome (whichNav,imageFileType) {	
	var rollOverSuffix = "-over";
	var whichNav = whichNav.replace(/^\s+|\s+$/g,'');
	var imageFileType = imageFileType.replace(/^\s+|\s+$/g,'');
	var imagePath = "/i/hornav-";
	var navRoot = document.getElementById(whichNav);
	var args = getUrlSubString();	
	for(i=0; i<navRoot.childNodes.length; i++){
		node0 = navRoot.childNodes[i];
		if(node0.nodeName=='A'){
			for(a=0; a<node0.childNodes.length; a++){
				node1=node0.childNodes[a];
				if(node1.nodeName=="IMG"){
					node1.onmouseover=function(){
						if (
							(this.id=="freightguideinfo")||
							(this.id=="movers")
							)
						{
							srcactive = imagePath+this.id+"-home-over"+imageFileType;
						} else if (this.id=="advertise") {
							srcactive = "/i/hornav-advertise-home.gif";						
						} else {
							srcactive = imagePath+this.id+rollOverSuffix+imageFileType;
						}
						this.src = srcactive;						
					}
					node1.onmouseout=function(){						
						if (
							(this.id=="freightguideinfo")||
							(this.id=="movers")
							)
						{
							src = imagePath+this.id+"-home"+imageFileType;
						} else if (this.id=="advertise") {
							src = "/i/hornav-advertise-home.gif";						
						} else {
							src = imagePath+this.id+imageFileType;
						}
						this.src = src;
					}
				}
			}
		}
	}
}

//returns first level directory string to rollover functions
function getUrlSubString() {
	var url = document.URL;
	var whichPageArray=url.split("/");	
	return whichPageArray[3];
}

//functions for directory functionality
function FindByDistance()
{ 
	if (checkform() == false)
		document.getElementById("btnSearch").href = "Javascript:void(0);";
	else
		document.getElementById("btnSearch").href = "javascript:document.getElementById('searchForm').submit();";            
}

//writes the flash object code to the homepage
function addSwfFile() {
	document.write("<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\" width=\"253\" height=\"256\" id=\"wheelscene-homepage\" align=\"middle\">");
	document.write("<param name=\"allowScriptAccess\" value=\"sameDomain\" />");
	document.write("<param name=\"movie\" value=\"/swf/freightbrokers-ads.swf\" />");
	document.write("<param name=\"quality\" value=\"high\" />");
	document.write("<embed src=\"/swf/freightbrokers-ads.swf\" quality=\"high\" bgcolor=\"#ffffff\" width=\"253\" height=\"256\" name=\"freightbrokers-ads\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" />");
	document.write("</object>");
}

function checkform()
{
	var bolSearch = false;
	var bolRight = true;
	var objZip = document.getElementsByName("zip");
	var objState = document.getElementsByName("state");
	var objCity = document.getElementsByName("city");
	var objKeyword = document.getElementById("keyword");
		
	if(objState[0].options[objState[0].selectedIndex].value != '')
		bolSearch = true;
		
	if (objCity.item(0).value != '')
	{
	   if (validateString(objCity.item(0).value) == false){
			bolSearch = false;
			bolRight = false;
			alert("The box has special characters. \nThese are not allowed.\n");
		}    
		else{
			bolSearch = true;
			bolRight = true;
		}    
	}    
	 
	if (objZip.item(0).value != '')
	{
	   if (validateZip(objZip.item(0).value) == false){
			bolSearch = false;
			bolRight = false;
			alert('Invalid Zipcode\nExample: US = 48912\nCanada = N1E7M1');
		}    
		else{
			bolSearch = true;
			bolRight = true;
		}    
	}
	
	if (objKeyword.value != '')
	{
	   if (validateString(objKeyword.value) == false){
			bolSearch = false;
			bolRight = false;
			alert("The box has special characters. \nThese are not allowed.\n");
		}    
		else{
			bolSearch = true;
			bolRight = true;
		}    
	} 
	
		if (bolRight == true && bolSearch == true)
		bolSearch = true;
	else
		bolSearch = false;
		
	return bolSearch;
}

function validateZip(strValue) {
	var objRegExpUS  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
	var objRegExpCA = /^\D{1}\d{1}\D{1}\s?\d{1}\D{1}\d{1}$/;
	var bol = true;
	
	//check for valid US Zipcode
	if (objRegExpUS.test(strValue) == false)
	{
		if (objRegExpCA.test(strValue) == true)
		{
			bol = true;
		}
		else
		{
			bol = false;
		}
	}
	else
	{
		bol = true;
	}
	
	return bol;
}

function validateString(str) {
	var iChars = "!@#$%^&*()+=-[]\\\;,./{}|\":<>?";
	for (var i = 0; i < str.length; i++) {
		if (iChars.indexOf(str.charAt(i)) != -1) {
		return false;
		}
   }
}
