//---------------------------------------------------------------------------

// Utility routines used by various javascript functions to create new querys

// from existing urls.  If current browser url does not reflect current query,

// these functions are not useful (since they are not aware of the current

// application state.)  These functions are used sparingly in the reference

// implementation only in conjunction with modules that contain form element.

//---------------------------------------------------------------------------


	function changeSort(sortOption){
			window.location=sortOption;
	} 
	
	
var deletedSearch = false;

// added to allow for recording email links and web links
	function coxJumpPage (type,link,merchant) {

		if (type == 'email') {
		var dynamic_div = document.createElement('DIV');
		dynamic_div.innerHTML = '<iframe name="dynamic_iframe" id="dynamic_iframe" src="" width="0" height="0" border="0"></iframe>';
		dynamic_div.id = "dynamic_div2";
		document.body.appendChild(dynamic_div);

		var dynamic_div3 = document.getElementById('dynamic_div2');
			var jump = '/jump.jsp?type=email&link=' + link + '&merchantID=' + merchant;
			document.getElementById("dynamic_iframe").src=jump;
			setTimeout("closeThis()",500);
		} else {
			var jump = '/jump.jsp?type=' + type + '&link=' + encodeURIComponent(link) + '&merchantID=' + merchant;
			window.open(jump);
		}

	}
	
	function closeThis() {
		var dynamic_div3 = document.getElementById('dynamic_div2');
		dynamic_div3.style.display = 'none';
		document.body.removeChild(dynamic_div3);
	}

// If we are on the map detail page and the user changes the selected location
// we will need to reload the page
function reloadMapDetail( addressName ) {
  var removeTerms = [ "selectedLocations" ];
  var newurl = ConstructURL( window.location.href, removeTerms, "" );

  newurl += "&selectedLocations=" + addressName;
  window.location=newurl;
}


function compareProceed(url){	
	document.getElementById("url").value = url;
	document.companyCompareForm.submit();
}


function toggleHelp(whichBox) {
  if (document.getElementById(whichBox).style.display=="none"){
    document.getElementById(whichBox).style.display="block";
  }
  else {
    document.getElementById(whichBox).style.display="none";
  }
}

function ConstructURL(url,removeterms,addterms) {

        var params = BuildURLArray(url);

        var newurl = "";

        for (var i=0; i<params.length; i++) {

                val = CheckArray(removeterms,params[i][0]);

                if (val == -1)

                        newurl = newurl + "&" + params[i][0] + "=" + params[i][1];
        }

        for (var i=0; i<addterms.length; i++) {

                newurl = newurl + "&" + addterms[i];

        }

        if (newurl.length > 0) {

                newurl = newurl.substr(1);

                newurl = "?"+newurl;

        }

        else {

                newurl = "?N="+eneroot;

        }


        return newurl;

}

function BuildURLArray(oldurl) {

        var returnArray = new Array();

        var url;

        if (oldurl == "CURRENTURL") {
                url = location.search;
        }
        else if (oldurl == "BLANKURL") {

        }

        else {

                var tokens = oldurl.split("?");

                url = "?"+tokens[1];

        }

        if (url) {

                url = url.substr(1);

                var params = url.split("&");

                for (var i=0; i<params.length; i++) {

                        var param = params[i].split("=");

                        returnArray[i] = param;

                }

        }

        return returnArray;

}

function CheckArray(removeterms,checkterm) {
        for (var i=0; i<removeterms.length; i++) {
                if (removeterms[i] == checkterm) {
                        return 1;
                }
        }

        return -1;

}

function GetValue(url, term) {

        var params = BuildURLArray(url);

        for (var i=0; i<params.length; i++) {

                if (params[i][0] == term) {

                        return params[i][1];

                }

        }

        return -1;
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function rateMerchant(imgRating){
          var activeRating = imgRating.id;
          var totalRatings = 5;
        var txtChosenRating = document.getElementById("txt_rating");

        var txtRatings = new Array(totalRatings);
        txtRatings[0] = "Poor";
        txtRatings[1] = "Below average";
        txtRatings[2] = "Average";
        txtRatings[3] = "Above average";
        txtRatings[4] = "Great";

        txtChosenRating.innerHTML = txtRatings[imgRating.id - 1];

        for (i=1; i <= totalRatings; i++){
           if(i <= activeRating){
                    document.getElementById(i.toString()).src = '/img/rating_check_yes.gif';
          }
           else{
                    document.getElementById(i.toString()).src = '/img/rating_check_no.gif';
          }
        }
}

//onmouseout, this function changes all the rating links to inactive
function rate_deselect(){
          var txtRating = document.getElementById("txt_rating");
        txtRating.innerHTML = "Rate it:";
        var totalRatings = 5;
        for (i = 1; i <= totalRatings; i++){
                 document.getElementById(i.toString()).src = '/img/rating_check_no.gif';
        }
}

function setScreenRes(){
                if(screen.width > 1024){
        document.write('<style>\n\n.bodyTable{\nwidth:955px;\n}\n</style>');

        }
        else{
                document.write('<style>\n\n.bodyTable{\nwidth:100%;\n}\n</style>');
        }
}

function policyPopup(theURL){		
		var origWidth=screen.availWidth;
		var	origHeight=screen.availHeight;
		var newWidth=600;
		var newHeight=600;
		var leftPos = (origWidth - newWidth)/2;
		var topPos = (origHeight - newHeight)/2;
		window.open(theURL,'policies','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=' + newWidth + ',height=' + newHeight + ',top=20, left=' + leftPos).focus();
}

function centerPopup(theURL){
		var origWidth=screen.availWidth;
		var	origHeight=screen.availHeight;
		var newWidth=screen.availWidth - 300;
		var newHeight=screen.availHeight - 300;
		var leftPos = (origWidth - newWidth)/2;
		var topPos = (origHeight - newHeight)/2;
		window.open(theURL,'','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=' + newWidth + ',height=' + newHeight + ',top=20, left=' + leftPos).focus();
		self.close();
}

function openPopup(theURL){
	var origWidth=screen.availWidth;
		var	origHeight=screen.availHeight;
		var newWidth=screen.availWidth - 300;
		var newHeight=screen.availHeight - 100;
		var leftPos = (650)/2;
		var topPos = (origHeight - newHeight)/2;
		window.open(theURL,'','toolbar=no,location=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width=650,height=' + newHeight + ',top=20, left=' + leftPos).focus();
}

function newsletterPopup(theURL){
		var origWidth=screen.availWidth;
		var	origHeight=screen.availHeight;
		var newWidth=750;
		var newHeight=500;
		var leftPos = (origWidth - newWidth)/2;
		var topPos = (origHeight - newHeight)/2;
		window.open(theURL,'','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=' + newWidth + ',height=' + newHeight + ',top=20, left=' + leftPos).focus();
}

function NewWindow(u,n,w,h,f,p,x,y){var	ws=window.screen?1:0,m=Math,C='center',R='random',M='custom',sw=screen.availWidth,sh=screen.availHeight,T=(p==C&&ws)?(sh-h)/2:(p==R&&ws)?(m.floor(m.random()*(sh-h))):(p==M)?y:100,L=(p==C&&ws)?(sw-w)/2:(p==R&&ws)?(m.floor(m.random()*(sw-w))):(p==M)?x:100,s='width='+w+',height='+h+',top='+T+',left='+L;s+=(!f||f=='')?'':','+f;win=window.open(u,n,s);if(win.focus)win.focus();}

// adding in new Map feature scripts

var IFrameObj; // our IFrame object
function callToServerDriving(theFormName) {
  if (!document.createElement) {return false};
  var IFrameDoc;
  var URL = '/maps/drivingDirections_directions.jsp' + buildQueryString(theFormName);

  document.getElementById( 'mapDiv' ).style.display="block";

  if (!IFrameObj && document.createElement) {
    // create the IFrame and assign a reference to the
    // object to our global variable IFrameObj.
    // this will only happen the first time 
    // callToServer() is called
   try {
      var tempIFrame=document.createElement('iframe');
      tempIFrame.setAttribute('id','RSIFrame');
      tempIFrame.style.border='0px';
      tempIFrame.style.width='0px';
      tempIFrame.style.height='0px';
      IFrameObj = document.body.appendChild(tempIFrame);
      
      if (document.frames) {
        // this is for IE5 Mac, because it will only
        // allow access to the document object
        // of the IFrame if we access it through
        // the document.frames array
        IFrameObj = document.frames['RSIFrame'];
      }
    } catch(exception) {
      // This is for IE5 PC, which does not allow dynamic creation
      // and manipulation of an iframe object. Instead, we'll fake
      // it up by creating our own objects.
      iframeHTML='\<iframe id="RSIFrame" style="';
      iframeHTML+='border:0px;';
      iframeHTML+='width:0px;';
      iframeHTML+='height:0px;';
      iframeHTML+='"><\/iframe>';
      document.body.innerHTML+=iframeHTML;
      IFrameObj = new Object();
      IFrameObj.document = new Object();
      IFrameObj.document.location = new Object();
      IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
      IFrameObj.document.location.replace = function(location) {
        this.iframe.src = location;
      }
    }
  }
  
  if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
    // we have to give NS6 a fraction of a second
    // to recognize the new IFrame
    setTimeout('callToServer()',10);
    return false;
  }
  
  if (IFrameObj.contentDocument) {
    // For NS6
    IFrameDoc = IFrameObj.contentDocument; 
  } else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj.contentWindow.document;
  } else if (IFrameObj.document) {
    // For IE5
    IFrameDoc = IFrameObj.document;
  } else {
    return true;
  }
  
  IFrameDoc.location.replace(URL);
  return false;
}

var IFrameObj; // our IFrame object
function callToServer(theFormName) {
  if (!document.createElement) {return false};
  var IFrameDoc;
  var URL = 'map_directions.jsp' + buildQueryString(theFormName);
  if (!IFrameObj && document.createElement) {
    // create the IFrame and assign a reference to the
    // object to our global variable IFrameObj.
    // this will only happen the first time 
    // callToServer() is called
   try {
      var tempIFrame=document.createElement('iframe');
      tempIFrame.setAttribute('id','RSIFrame');
      tempIFrame.style.border='0px';
      tempIFrame.style.width='0px';
      tempIFrame.style.height='0px';
      IFrameObj = document.body.appendChild(tempIFrame);
      
      if (document.frames) {
        // this is for IE5 Mac, because it will only
        // allow access to the document object
        // of the IFrame if we access it through
        // the document.frames array
        IFrameObj = document.frames['RSIFrame'];
      }
    } catch(exception) {
      // This is for IE5 PC, which does not allow dynamic creation
      // and manipulation of an iframe object. Instead, we'll fake
      // it up by creating our own objects.
      iframeHTML='\<iframe id="RSIFrame" style="';
      iframeHTML+='border:0px;';
      iframeHTML+='width:0px;';
      iframeHTML+='height:0px;';
      iframeHTML+='"><\/iframe>';
      document.body.innerHTML+=iframeHTML;
      IFrameObj = new Object();
      IFrameObj.document = new Object();
      IFrameObj.document.location = new Object();
      IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
      IFrameObj.document.location.replace = function(location) {
        this.iframe.src = location;
      }
    }
  }
  
  if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
    // we have to give NS6 a fraction of a second
    // to recognize the new IFrame
    setTimeout('callToServer()',10);
    return false;
  }
  
  if (IFrameObj.contentDocument) {
    // For NS6
    IFrameDoc = IFrameObj.contentDocument; 
  } else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj.contentWindow.document;
  } else if (IFrameObj.document) {
    // For IE5
    IFrameDoc = IFrameObj.document;
  } else {
    return true;
  }
  
  IFrameDoc.location.replace(URL);
  return false;
}

function buildQueryString(theFormName) {
  theForm = document.forms[theFormName];
  var qs = '';
  for (a=0; a<theForm.elements.length; a++) {
  if (theForm.elements[a].name!= '') {
      qs+=(qs=='')?'?':'&';
      qs+=theForm.elements[a].name+'='+escape(theForm.elements[a].value);
      }
    }
  return qs;
}

function showReverse(){
	var reverse = document.getElementById('reverse');
	
	if(reverse.value == 'false')
		reverse.value = 'true';
	else{
		reverse.value = 'false';
		}
		
  	callToServer('MapIt');
    
  }
  
  //put in the call to server for the companyFinder
  function companyFinderCallToServer(theFormName) {
  if (!document.createElement) {return false};
  var IFrameDoc;
  var URL = 'companyFinderList.jsp' + buildQueryString(theFormName);
  if (!IFrameObj && document.createElement) {
    // create the IFrame and assign a reference to the
    // object to our global variable IFrameObj.
    // this will only happen the first time 
    // callToServer() is called
   try {
      var tempIFrame=document.createElement('iframe');
      tempIFrame.setAttribute('id','RSIFrame');
      tempIFrame.style.border='0px';
      tempIFrame.style.width='0px';
      tempIFrame.style.height='0px';
      IFrameObj = document.body.appendChild(tempIFrame);
      
      if (document.frames) {
        // this is for IE5 Mac, because it will only
        // allow access to the document object
        // of the IFrame if we access it through
        // the document.frames array
        IFrameObj = document.frames['RSIFrame'];
      }
    } catch(exception) {
      // This is for IE5 PC, which does not allow dynamic creation
      // and manipulation of an iframe object. Instead, we'll fake
      // it up by creating our own objects.
      iframeHTML='\<iframe id="RSIFrame" style="';
      iframeHTML+='border:0px;';
      iframeHTML+='width:0px;';
      iframeHTML+='height:0px;';
      iframeHTML+='"><\/iframe>';
      document.body.innerHTML+=iframeHTML;
      IFrameObj = new Object();
      IFrameObj.document = new Object();
      IFrameObj.document.location = new Object();
      IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
      IFrameObj.document.location.replace = function(location) {
        this.iframe.src = location;
      }
    }
  }
  
  if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
    // we have to give NS6 a fraction of a second
    // to recognize the new IFrame
    setTimeout('callToServer()',10);
    return false;
  }
  
  if (IFrameObj.contentDocument) {
    // For NS6
    IFrameDoc = IFrameObj.contentDocument; 
  } else if (IFrameObj.contentWindow) {
    // For IE5.5 and IE6
    IFrameDoc = IFrameObj.contentWindow.document;
  } else if (IFrameObj.document) {
    // For IE5
    IFrameDoc = IFrameObj.document;
  } else {
    return true;
  }
  
  IFrameDoc.location.replace(URL);
  return false;
}

/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}
 
  
function selection( mySelection ) {
  var locsDiv = document.getElementById("locsDiv");
		locsDiv.style.visibility = 'hidden';
		                	if(document.getElementById("sortOption")){
        					var sortOption = document.getElementById("sortOption");
        					sortOption.style.visibility = 'visible';
        				}
		var currentLocation = document.getElementById("currentLocation");
    currentLocation.value= mySelection
  }
  
function setLocsDiv(){
	var locSearchProps = document.getElementById('locations');
	var locsDivProps = document.getElementById('locsDiv');
	locsDivProps.style.width = (locSearchProps.offsetWidth - 3) + 'px';
    //locsDivProps.style.left = (locSearchProps.offsetLeft + 8) + 'px';
    //locsDivProps.style.top = (locSearchProps.offsetTop + locSearchProps.offsetHeight + 1) + 'px';
                if(locsDivProps.style.visibility == 'hidden'){
                        show_savedLocs();
                }
                else{
                        hide_savedLocs();
                }

	}
   
function resetCookie(){
  	deleteCookie("recentSearch");
  	
  	deleteCookie("locations");
  	hide_savedLocs();
  	var recentLocsDiv = document.getElementById("recentContent");
  	var noLocsDiv = document.getElementById("noContent");
    deletedSearch = true;
    recentLocsDiv.style.display = 'none';
    noLocsDiv.style.display = 'block';
  	return false;
}

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 setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}        
        
// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"

function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}
        
        
function turnOffHistory(){
	
	setCookie("RECENT_HISTORY", "0", expdate, "", "", "");
	hideSearchDivs();
	document.getElementById("historyOn").style.display = 'block';
	document.getElementById("historyOff").style.display = 'none';
	document.getElementById("clearHistory").style.display= 'none';
	document.getElementById("txt_recentProfiles").style.display = 'none';
	document.getElementById("txt_recentSearches").style.display = 'none';
	document.getElementById("featureOff").style.display = 'block';
}
function turnOnHistory(){
	setCookie("RECENT_HISTORY", "1", expdate, "", "", "");
	showSearchDivs();
	document.getElementById("historyOff").style.display = 'block';
	document.getElementById("historyOn").style.display = 'none';
	document.getElementById("clearHistory").style.display= 'block';
	document.getElementById("txt_recentProfiles").style.display = 'block';
	document.getElementById("txt_recentSearches").style.display = 'block';
	document.getElementById("featureOff").style.display = 'none';
}

function clearHistory(){
	deleteCookie("RECENT_SEARCH");
	deleteCookie("RECENT_VIEWED");
	hideSearchDivs();
}

//---------------------------------------------------------------------------

// Function used by misc_searchbox.jsp to control form elements

//---------------------------------------------------------------------------
function setMouse(){
	document.onclick = isMouseOnLocsDiv;
} 

function ProvideLocationSearch() {
	if( document.provideLocationForm.searchterms.value == "" ) {
          alert( "Please enter a word or phrase to search for" );
          document.provideLocationForm.searchterms.focus();
          return false;
	}
	else if( document.provideLocationForm.currentLocation.value == "" ) {
          alert( "Please provide a location" );
          document.provideLocationForm.currentLocation.focus();
		return false;
	}
}

function zipHome() {
   var zip = document.zipHomeForm.zip.value;
   if (/.*\D.*/.test(zip) == true || zip.length < 5) {
    alert ("Please enter a valid zip (e.g., 30303).");
   }
   else {
    self.location = "/?currentLocation=" + zip;
   }
}

//code to hide the Choose Your Location box on the homepage
function hideChoose () {
     hideObj("chooseLoc");
}

//code to slide div's off the page
function hideObj (obj) {
     var newObj = document.getElementById(obj).cloneNode(true);
     newObj.setAttribute('id', 'hideObj');
     var container = document.getElementById(obj).parentNode;
     var objHeight = document.getElementById(obj).offsetHeight;
     document.getElementById(obj).style.display="none";
     container.insertBefore(newObj,document.getElementById(obj));
     setTimeout('hideProc("hideObj",' + objHeight + ')', 10);
}

function hideProc (obj, objHeight) {
   objHeight = objHeight - 15;
   document.getElementById(obj).style.height = objHeight + 'px';
   if (objHeight > 15) {
     setTimeout('hideProc ("' + obj + '",' + objHeight + ')', 10);
   }
   else {
     document.getElementById(obj).parentNode.removeChild(document.getElementById(obj));
   }
}

function showChoose () {
     showObj("chooseLoc");
}

function showObj (obj) {
     var newObj = document.getElementById(obj).cloneNode(true);
     newObj.setAttribute('id', 'tempObj');
     var container = document.getElementById(obj).parentNode;
     container.appendChild(newObj);
     newObj.style.display="block";
     var objHeight = newObj.offsetHeight;
     newObj.style.height="0px";
     var showObj = newObj.cloneNode(true);
     document.getElementById(obj).setAttribute('id', obj+'Old');
     showObj.setAttribute('id', obj);
     container.insertBefore(showObj, document.getElementById(obj+'Old'));
     container.removeChild(document.getElementById(obj+'Old'));
     container.removeChild(newObj);

     setTimeout('showProc("' + obj + '", 0, ' + objHeight + ')', 10);
}

function showProc (obj, currentHeight, objHeight) {
   currentHeight = currentHeight + 15;
   document.getElementById(obj).style.height = currentHeight + 'px';
   if (currentHeight + 15 < objHeight) {
     setTimeout('showProc ("' + obj + '",' + currentHeight + ',' + objHeight + ')', 10);
   }
   else {
     document.getElementById(obj).style.height = objHeight + 'px';
   }
}

function hide_savedLocs(){
        	var showrecent = document.getElementById("recentContent");
 			showrecent.style.display = 'none';
          	var showframe = document.getElementById("iframe");
 			showframe.style.display = 'none';
        				if(document.getElementById("sortOption")){
        					var sortOption = document.getElementById("sortOption");
        					sortOption.style.visibility = 'visible';
        				}
                var locsDiv = document.getElementById("locsDiv");
                locsDiv.style.visibility = 'hidden';
}

function show_savedLocs(){
 	if (!deletedSearch) {
	 	var showrecent = document.getElementById("recentContent");
 		showrecent.style.display = 'block';
 	}
	if (document.getElementById("locframe")) {
 			document.getElementById("locframe").src='/my_locationsList.jsp';
	}

	var showframe = document.getElementById("iframe");
	showframe.style.display = 'block';
   	if(document.getElementById("sortOption")){
        					var sortOption = document.getElementById("sortOption");
        					sortOption.style.visibility = 'hidden';
    }
    
    var locsDiv = document.getElementById("locsDiv");
	locsDiv.style.visibility = 'visible';
}

function isMouseOnLocsDiv(evt){
	var evt = (evt) ? evt : ((window.event) ? event : null);
	var locsDivProps2 = document.getElementById("locsDiv");
	var downButtonProps = document.getElementById("downButton");

if (navigator.appName.indexOf('Explorer') != -1) {

	if (evt.srcElement.id == 'downButton') {
	} else {
	//alert('clientX = ' + evt.clientX + 'clientY = ' + evt.clientY);
	if ((locsDivProps2.style.visibility == 'visible') && (evt.clientX > locsDivProps2.offsetLeft) && (evt.clientX < (locsDivProps2.offsetLeft + locsDivProps2.offsetWidth)) && (evt.clientY > locsDivProps2.offsetTop) && (evt.clientY < (locsDivProps2.offsetTop + locsDivProps2.offsetHeight))) {
	} else {
	hide_savedLocs();
	                	if(document.getElementById("sortOption")){
        					var sortOption = document.getElementById("sortOption");
        					sortOption.style.visibility = 'visible';
        				}
	//	alert('you hit outside');
	}
  }
  } else {
  	if (evt.target.id == 'downButton') {
	} else {
	//alert('clientX = ' + evt.clientX + 'clientY = ' + evt.clientY);
	if ((locsDivProps2.style.visibility == 'visible') && (evt.clientX > locsDivProps2.offsetLeft) && (evt.clientX < (locsDivProps2.offsetLeft + locsDivProps2.offsetWidth)) && (evt.clientY > locsDivProps2.offsetTop) && (evt.clientY < (locsDivProps2.offsetTop + locsDivProps2.offsetHeight))) {
	} else {
	hide_savedLocs();
	                	if(document.getElementById("sortOption")){
        					var sortOption = document.getElementById("sortOption");
        					sortOption.style.visibility = 'visible';
        				}
	//	alert('you hit outside');
	}
  }
  
  }
}

function emailArticle(articleID){
		window.open('/emailArticle.do?articleID=' + articleID,'emailwindow','width=500,height=600,toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes,left=0,top=100');		

}

//comment code
	var userFlag = function(data){
		alert('You have flagged this comment for review by a site administrator.');
		}
		
		function hideFlag(commentID){
			var flagLinkID = "flag_" + commentID;
			var flagLink = document.getElementById(flagLinkID);
			flagLink.style.display = 'none';
		}

var isNN = ( navigator.appName.indexOf( "Netscape" ) != -1 ); 
 
function autoTab( input,len, e ) { 
	var keyCode	= ( isNN ) ? e.which : e.keyCode; 
	var filter	= ( isNN ) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46]; 
	if( input.value.length >= len && !containsElement( filter, keyCode )) { 
	input.value = input.value.slice( 0, len );
	if (input.form[( getIndex( input ) + 1 ) % input.form.length].value == '') {
	input.form[( getIndex( input ) + 1 ) % input.form.length].focus();
	} else {
	input.form[( getIndex( input ) + 1 ) % input.form.length].select();
	}
	}
	return true; 
} 

function containsElement( arr, ele ) { 
	var found = false, index = 0; 
	while( !found && index < arr.length ) 
	if( arr[index] == ele ) { 
		found = true; 
	} else { 
		index++; 
	} 
	return found; 
} 
 
function getIndex( input ) { 
	var index = -1, i = 0, found = false; 
	while ( i < input.form.length && index == -1 ) 
	if ( input.form[i] == input ) { 
		index = i; 
	} else { 
		i++; 
	} 
	return index; 
} 

function showToolTip ( name, display ) {
  clearTimeout(window.timer);
  document.getElementById(name).style.filter="alpha(opacity:0)";
  document.getElementById(name).style.opacity="0";
  if (display) {
     document.getElementById(name).style.display=display;
  }
  else {
     document.getElementById(name).style.display='block';
  }
  
  var amount = 0;
  while (amount<90) {
     window.timer = setTimeout ("opacityToolTip ('" +  name + "', " + amount + " )", 20+2*amount);
     amount = amount + 20;
  }
  window.timer = setTimeout ("opacityToolTip ('" +  name + "', 90 )", 200);
}

function hideToolTip ( name ) {
  clearTimeout(window.timer);
  document.getElementById(name).style.display='none';
}

function opacityToolTip ( name, amount ) {
  document.getElementById(name).style.filter="alpha(opacity:" + amount + ")";
  document.getElementById(name).style.opacity="0." + amount;
}

	function videoPopup(companyId) {
	        displayWindow('<img src="/img/videopopup-header.gif" alt="Video" />', "/videoPopup.do?companyId="+companyId, 700, 530);
	}

	function reloadAdFrames() {
		for ( i = 0; i < window.frames.length; i++ ) {
		    try {
				if (window.frames[i].location.href.match("ClickFrame") == "ClickFrame") {
					window.frames[i].location.reload();
				}
			} catch (e) {}
		}
	}
	
function logoutCheck() {
	if (FB.Facebook.apiClient.get_session() != null) {
	   FB.Connect.logoutAndRedirect("/logout.do");
	}
	else {
		window.location='/logout.do';
	}
}

function sendPictureData () {
document.forms['sendPicture'].picImage.value = 'Get Directions';
}

	function showList (whichBox) {
	  document.getElementById(whichBox+'Expand').style.display="none";
	  document.getElementById(whichBox+'Hide').style.display="block";
	  document.getElementById(whichBox+'List').style.display="block";
	}
	function hideList (whichBox) {
	  document.getElementById(whichBox+'Expand').style.display="block";
	  document.getElementById(whichBox+'Hide').style.display="none";
	  document.getElementById(whichBox+'List').style.display="none";
	}