/* This is more how it should work. I'll test it later. -MJO
mHover = function() {
	var sfEls = document.getElementById("mm").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].attachEvent("onmouseover",function() { this.className+=" mhover"; });
		sfEls[i].attachEvent("onmouseout",function() { this.className=this.className.replace(new RegExp(" mhover\\b"), ""); });
	}
}
if (window.attachEvent) window.attachEvent("onload", mHover);
function setStatus(s) { // People still use this even though they shouldn't, but it's missing from some places
   status=s;
}
*/

mHover = function() {
   var mm=document.getElementById("mm");
   if(mm) {
         var countrysel = document.getElementById('countrysel');
         if(countrysel && !document.getElementById('fakeCountrySel')){
            var fakeCountrySel = document.createElement('div');
            fakeCountrySel.id = 'fakeCountrySel';
            fakeCountrySel.style.display='none';
            countrysel.parentNode.insertBefore(fakeCountrySel, countrysel);
         }
         var sfEls = mm.getElementsByTagName("LI");
         for (var i=0; i<sfEls.length; i++) {
            sfEls[i].onmouseover=function() {
               this.className+=" mhover";
               var countrysel = document.getElementById('countrysel');
               if(countrysel){
                  countrysel.blur();
                  if(this.className.indexOf('hideCountry') >= 0){
                     countrysel.style.visibility='hidden';
                     fakeCountrySel = document.getElementById('fakeCountrySel');
                     fakeCountrySel.innerHTML = '<div>'+countrysel.options[countrysel.selectedIndex].text+'</div>';
                     fakeCountrySel.style.display='block';
                  }
               }
            }
            sfEls[i].onmouseout=function() {
               this.className=this.className.replace(new RegExp(" mhover\\b"), "");
               if(this.className.indexOf('hideCountry') >= 0){
                  var countrysel = document.getElementById('countrysel');
                  if(countrysel){
                     countrysel.style.visibility='visible';
                     document.getElementById('fakeCountrySel').style.display='none';
                  }
               }
            }
         }
   }
}

if (window.attachEvent) window.attachEvent("onload", mHover);


function setStatus(s) { // People still use this, but it's missing from some places
   status=s;
}
function cf(action) {
   var f = document.createElement("FORM");
   f.method="POST";
   f.action=action;
   document.body.appendChild(f);
   return f;
}
function cfi(parentForm,name,value) {
   var i = document.createElement("INPUT");
   i.type="hidden";
   i.name=name;
   i.value=value;
   parentForm.appendChild(i);
}
var SID;
var UID;// username
function postLink(a) {
   var url = a.href;
   var f = cf(url);
   cfi(f,"SID",SID);
   cfi(f,"UID",UID);
   f.submit();
   return false;
}

//Fetchback Tracking Pixel Code //
function getCookieValue(name){
	var cookieArray = document.cookie.split(';');
	var cookieHash = new Array();
	for(var i = 0; i < cookieArray.length; i++){
		var tempArray = new Array();
		tempArray = cookieArray[i].split('=');
		cookieHash[prepareCookieString(tempArray[0])] = prepareCookieString(tempArray[1]);
	}
	return cookieHash[name];
}
function prepareCookieString(str){
	//Trim string, and replace + with " "(JavaScript does not replace + with " ") then unescape
	if(str == null || str == undefined)
		return null;
	else
		return unescape(str.replace(/^\s+|\s+$/g, "")).replace(/\+/g, " ");
}

function insertAffiliatePixel(){
	//Check to make sure this pixel is not already present
	if(document.getElementById("fetchbackTrackingPixel") == null){
		if(getCookieValue('L').substr(0, 2) == 'US' && location.host.indexOf("lawdepot.com") != -1) {
			//Create the pixel to append to the body
			var pixel = document.createElement("iframe");
			pixel.setAttribute("id", "fetchbackTrackingPixel");
			//location.protocol so that if we''re already using https we keep using it.
			pixel.setAttribute("src", location.protocol + "//pixel.fetchback.com/serve/fb/pdj?cat=&name=landing&sid=4378");
			pixel.setAttribute("scrolling", "no");
			pixel.setAttribute("width", "1");
			pixel.setAttribute("height", "1");
			pixel.setAttribute("marginheight", "0");
			pixel.setAttribute("marginwidth", "0");
			pixel.setAttribute("frameborder", "0");
			document.body.appendChild(pixel);
			return;
		}
	}
}

if (window.attachEvent) window.attachEvent("onload", insertAffiliatePixel);
if (document.addEventListener) document.addEventListener("DOMContentLoaded", insertAffiliatePixel, false);

//End Fetchback Tracking Pixel Code //
