//v1.1.0.2 by PVII-www.projectseven.com

function P7_ExpMenu() { 
	if(navigator.appVersion.indexOf("MSIE")==-1) {
		return;
	}
	var i; // UL counter
	var k; // LI counter
	var g; // UL object
	var lg; // LI object collection
	var r=/\s*p7hvr/; // regex for finding the p7hvr class
	var nn=''; // Used for nexted UL's (headernav->headernav1->headernav2)
	var c; // used in the function creation? 
	var cs='p7hvr'; // p7hvr class that gets appended to the UL
	var bv='headernav'; // UL name

	for( i=0; i<10; i++)// aparent limit of 10 nested levels
	{
		g=document.getElementById(bv+nn); //getting the UL
		if(g)// making sure we have a UL
		{
			lg = g.getElementsByTagName("LI");//get the child LIs
			if(lg) // make sure we have LIs
			{
				for( k = 0; k < lg.length; k++)// loop through the LIs
				{
					lg[k].onmouseover = function()
						{
							c = this.className;
							cl = (c)?c+' '+cs:cs; //cs = p7hvr, basicly adding onto the assigned class (classname p7hvr)
							this.className=cl;
						};
					 lg[k].onmouseout = function()
						{
							c=this.className;
							this.className=(c)?c.replace(r,''):''; // removing the p7hvr class (r is regex to match p7hvr)
						};
				  }
			}
		}
		nn=i+1; // update nn to loop through the next layer of nested ULs
	}
}

function populateFields(chkThis, frmThis, arFieldsFrom, arFieldsTo){
	var i, j;
	var fefrom;
	var feto;
	var fetorep;
	
	if (chkThis.checked){
		for (i=0; i < arFieldsFrom.length; i++){
			if(frmThis[arFieldsTo[i]]) {
				fefrom = frmThis[arFieldsFrom[i]];
				feto = frmThis[arFieldsTo[i]];
				if (fefrom.tagName.toLowerCase() == "select" && feto.tagName.toLowerCase() == "select") {
					feto.options.length = 1;
					
					for (j=1; j < fefrom.options.length; j++) {
						fetorep = feto.options.add ? feto.options : feto;
						fetorep.add(document.createElement("option"));
						feto.options[feto.options.length-1].value = fefrom.options[j].value;
						feto.options[feto.options.length-1].text = fefrom.options[j].text;
					}
					feto.selectedIndex = fefrom.selectedIndex;
				} else {
					frmThis[arFieldsTo[i]].value = frmThis[arFieldsFrom[i]].value;
				}
			}
		}
	}else{
		for (i=0; i < arFieldsFrom.length; i++){
			if(frmThis[arFieldsTo[i]])
				frmThis[arFieldsTo[i]].value = '';
		}
	}
}



//JONK's getAcuElementById------
// some browser sniffing:
document.version = parseFloat(navigator.appVersion);
document.hostApplication = navigator.appName.substring(0,3);
document.browserClass = parseInt(document.version);
			
if(document.browserClass < 4) 
{
 // redirect -- no CSS support
 // if you used &lt;script language=javascript1.2&gt; 
 // this won't be necessary
 // ALL this code will be ignored!
}
else      // isolate this setup from "modern" browsers!!
if(document.browserClass == 4) // might need to check NN5 browsers as well
{

	if(document.hostApplication == "Net") // got netscape?
	{
		  // need to "fake" the style attribute
		  // so we add a little misdirection
		  // by creating an object that will
		  // intercept the property setting.
		  // we make NN think it's setting properties 
		  // in A style object, when it is actually
		  // redirected to set the property to the actual layer
		   // and you might have thought it couldn't be done...
		 function _style()
		 {
		  this.layerRef = null;    // this will be set when <B style="COLOR: black; BACKGROUND-COLOR: #ffff66">getElementByID</B> is called

		  /* we don't actually need these -- it's just pseudocode
		  this.visibility = "";
		  this.top = 0;
		  this.left = 0;
		  */
						   
		   // very cool method in NN (only) -- 
		   // since these aren't "real" object properties
		   // it's more like a watchdog
		   // for more info -- check Netscape's docs
		  this.watch("visibility", 
		     function(id, old, nval) 
		      {  // set the "real" property of the layer here
		       eval("this.layerRef." + id + " = '" + nval + "'");
		       return nval; });
		        // you must return either old or nval
		  this.watch("top",
		     function(id, old, nval) {
		       eval("this.layerRef." + id + " = '" + nval + "'");
		      return nval;});
		  this.watch("left",
		     function(id, old, nval) {
		       eval("this.layerRef." + id + " = '" + nval + "'");
		      return nval;});
						  
		   // note: all the inline functions are exactly the same
		   //  you can cut'n'paste for each property you need to watch!
		}

	 // here we set up the "appearance" of a style property

	 Layer.prototype.style = new _style();
	  // each time a new layer is created, a new _style() object
	  // is attached to it
				    
	} // end if NN

	 // here, getElementById is getting declared by BOTH IE4 and NN4 browsers
	document.getAcuElementById = function(name)
	{
		if(document.hostApplication == "Net") // netscape 4
		{
			if (document.browserClass == 4){
				var lyr = eval("document." + name);
						   
			 // only need to do this once, but
			 // what the hey...
			 if(lyr.style != null) lyr.style.layerRef = lyr;
								    
			return lyr;
			}else{
				return document.layers('" + name + "');
			}
		}
		  else // IE
		  {
			return eval("document.all." + name);
		  }
  }
}else // end browserClass == 4
	{
	if(document.hostApplication == "Net"){
		document.getAcuElementById = function(name){
				if(!eval("document." + name)){
					return document.getElementById(name);
				}else{
					return eval("document." + name);
				}
			}
	}else
	{
		document.getAcuElementById = function(name){
				return document.getElementById(name);
			}
	}
}
//END JONK's getAcuElementById---------

function showHideDisplay(obj) {
	if (typeof(obj) == "string") obj = $(obj);
	if (obj) 
	{
	  if (getStyleByObj(obj, "display") == "none") 
	  {
	       obj.style.display = "block";
	  } else if (getStyleByObj(obj, "display") == "block") 
	  {
	       obj.style.display = "none";
	  }
		
	}
}

//get the value of a parameters from the query string
function getQueryParam(name)
{
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

/*
replaceQueryParam finds and replaces a query string parameter in a url
*/
function replaceQueryParam(url,param,value) {
	var delim = '&'; if(url.indexOf('?') == -1) delim = '?'; 
	var re = new RegExp("([?|&])" + param + "=.*?(&|$)","i");
	
	if (url.match(re))
		return url.replace(re,'$1' + param + "=" + value + '$2');
	else
		return url + delim + param + "=" + value;
}

//get the value of a cookie by name
function getCookieValue(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

/*
get the value of a cookie by 
 name - cookie name
 value - value to set
 expire days - number of days after which this should expire
*/
function setCookieValue(name,value,expiredays)
{
    var exdate=new Date();
    exdate.setDate(exdate.getDate()+expiredays);
    document.cookie=name + "=" +escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString() + '; path=/');
}

//set a test cookie
setCookieValue('testcookie','y',30);

/*
check to see if the client supports cookes
    returns true/false
*/
function cookiesSupported()
{
    if(getCookieValue('testcookie')!=null)
        return true;
        
    return false;
}

/*
check to see if we need to redirect to the choose country page
*/
function tlfCountryCheck()
{
    var redirectUrl = '/choosecountry/choosecountry.aspx';
    var countryID = getCookieValue('countryID');
    
    if(document.domain.indexOf('tandyleatherfactory') == -1)
        return;
        
    if(window.location.toString().indexOf(redirectUrl) != -1)
        return;
        
    if(cookiesSupported() && (countryID == null))
    {
        setCookieValue('countryURL',window.location.toString(),1);
        window.location = redirectUrl;
    }    
}

tlfCountryCheck();
