function clearField(obj) {
    if (obj.defaultValue==obj.value) obj.value = '';
}

function writeField(obj) {
	if (obj.value=='') obj.value = obj.defaultValue;
}

var addEvent = function() { // This function sets up events for all browsers
	function w3c_event(el, evt, fn, bool) {
		bool = bool || false;
		if(typeof el == 'string') el = document.getElementById(el);
		el.addEventListener(evt, fn, bool);
	}
	function ie_event(el, evt, fn) {
		if(typeof el == 'string') el = document.getElementById(el);
		el.attachEvent('on' + evt, fn);
	}
	var rO = typeof window.addEventListener != 'undefined' ? w3c_event : typeof window.attachEvent != 'undefined' ? ie_event : false;
	return rO;
}();
function makeActive(ev) {
	ev = ev || window.event;
	var target = ev.target || ev.srcElement;
	var parent = target.parentNode.parentNode;
	var links = parent.getElementsByTagName('li');
	for(var i = 0; i < links.length; i++) {
		links[i].className = links[i].className.replace('active-search', '');
	}
	target.parentNode.className += ' active-search';
	ev.stopPropagation ? ev.stopPropagation() : ev.cancelBubble = true;
	ev.preventDefault ? ev.preventDefault() : ev.returnValue = false;
}
addEvent(window, 'load', init, false);
function init() {
	// search tabs
	if(document.getElementById('campsearchinner')) {
		var items = document.getElementById('campsearchinner').getElementsByTagName('ul')[0].getElementsByTagName('a');
		for(var i = 0; i < items.length; i++) {
			addEvent(items[i], 'click', makeActive, false);
		}
	}
	
	// featured tabs
	if(document.getElementById('featured')) {
		var items = document.getElementById('featured').getElementsByTagName('ul')[0].getElementsByTagName('a');
		for(var i = 0; i < items.length; i++) {
			//addEvent(items[i], 'click', makeActive, false);
		}
	}
	
	// general search tabs
	if(document.getElementById('searchinner')) {
		var items = document.getElementById('searchinner').getElementsByTagName('ul')[0].getElementsByTagName('a');
		for(var i = 0; i < items.length; i++) {
			addEvent(items[i], 'click', makeActive, false);
		}
	}
}

function SetMenu(element,divName,cName)
{
    var nodes=element.parentNode.childNodes;
    for(i=0;i<nodes.length;i++)
    {
    nodes[i].className="";
    }
    element.className=cName;

    //show or hide divs based on index;
    e=divName.parentNode;
    alert(e.id);
    divName.style.visibility='visible';
}


function ValidateCreditCard(source, number, cardtype) 
{
    InvalidCreditCardMessage = "The credit card number is invalid.";
    CreditCardTypeUnknownMessage = "The credit card type is not known.";
    
    if (cardtype = "Rec Rewards VISA")
    {
        return true;
    }
    else
    {
        ccValidatorId = -1;
        for(i=0;i<Page_Validators.length;i++) 
        {
            if (source.id == Page_Validators[i].id) 
            {
                ccValidatorId = i;
                break;
            }
        }

	    ccNumberChecked = StripNonDigits(number);
	    if(ccNumberChecked == 'X')
	    {
	        if (ccValidatorId >= 0) 
	        {
	            Page_Validators[ccValidatorId].errormessage = 'Please supply a credit card number.';
		    }
		    return false;
	    }
    	
	    ccType = GetType(ccNumberChecked);
	    if ( cardtype != ccType ) 
	    {
	        if (ccValidatorId >= 0) 
	        {
	            Page_Validators[ccValidatorId].errormessage = 'The card number does not match the card type. (' + cardtype + ' - ' + ccType + ')' ;
		    }
		    return false;
	    }

	    ccNumberOkay = Mod10(ccNumberChecked);
	    if(ccType.length < 2 && ccNumberOkay == 0) 
	    { 
	        if (ccValidatorId >= 0) 
	        {
	            Page_Validators[ccValidatorId].errormessage = InvalidCreditCardMessage;
		    }
		    return false; 
	    }
	    else if(ccNumberOkay == 0) 
	    { 
		    if (ccValidatorId >= 0) 
		    {
	            Page_Validators[ccValidatorId].errormessage = InvalidCreditCardMessage;
		    }
		    return false;
	    }
	    else if(ccType.length < 2) 
	    { 
		    if (ccValidatorId >= 0) 
		    {
	            Page_Validators[ccValidatorId].errormessage = CreditCardTypeUnknownMessage;
		    }
		    return false; 
	    }
	    else
	    {
		    return true;
	    }   
    }
} // ValidateCreditCard()

function GetType(number) 
{
    var len = number.length;
    var Re = /^5[1-5]/;
	    if(Re.lastIndex > 1) { Re.lastIndex = 0; }
		    var Array = Re.exec(number);
			    if(Array && len == 16) { return "Master Card"; }
    Re = /^4/;
	    if(Re.lastIndex > 1) { Re.lastIndex = 0; }
		    Array = Re.exec(number);
			    if(Array && (len == 13 || len == 16)) { return "VISA"; }
    Re = /^3[47]/;
	    if(Re.lastIndex > 1) { Re.lastIndex = 0; }
		    Array = Re.exec(number);
			    if(Array && len == 15) { return "American Express"; }
    Re = /^(30[0-5]|3[68])/;
	    if(Re.lastIndex > 1) { Re.lastIndex = 0; }
		    Array = Re.exec(number);
			    if(Array && len == 14) { return "Diner's Club"; }
    Re = /^6011/;
	    if(Re.lastIndex > 1) { Re.lastIndex = 0; }
		    Array = Re.exec(number);
			    if(Array && len == 16) { return "Discover"; }
    Re = /^(3|1800|2131)/;
	    if(Re.lastIndex > 1) { Re.lastIndex = 0; }
		    Array = Re.exec(number);
			    if(Array && (len == 15 || len == 16)) { return "JCB"; }
    return '';
} // GetType()
	
function StripNonDigits(number) 
{
    var Re = /\d+/g;
    if(Re.lastIndex > 1) { Re.lastIndex = 0; }
    var Array = Re.exec(number);
    if(Re.lastIndex < 1) { return 'X'; }
    var ss = Array.join();
    
    while(Re.lastIndex > 0 && Re.lastIndex < number.length) 
    {
	    Array = Re.exec(number);
	    if(Array) { ss += Array.join(); }
	}
    return ss;
} // StripNonDigits()

function Mod10(number) 
{
    var reversed = Reverse(number);
    var total = AddedTogether(reversed);
    if(total % 10 > 0) { return 0; }
    return 1;
} // Mod10()

function Reverse(number)
{
   var n = '';
   for(i = number.length; i >= 0; i = i-1) { n += number.substr(i,1); }
   return n;
}//Reverse() 	

function AddedTogether(number) 
{
    var n = 0;
    for(i = 0; i < number.length; i++) {
	    var s = number.substr(i,1);
	    var si = parseInt(s,10);
	    if(i % 2 > 0) {
		    var ii = si * 2;
		    if(ii < 10) { n += ii; }
		    else {
			    var ss = ' ' + ii;
			    for(xi = 1; xi < ss.length; xi++) {
				    var xs = ss.substr(xi,1);
				    var xsi = parseInt(xs,10);
				    n += xsi;
				    } // for
			    } // else
		    } // if
	    else { n += si; }
	    } // for
    return n;
} // AddedTogether()

function isEmail(str,showMsg) 
{
    var re;
    var valid = 0;
    var msg = "";
    var firstChar = str.charAt('_');
    re = /^\w+([\]?[.-]+\w+)*@\w+([\.-]?\w+)*(\.\w{1,})+$/;
    if (str != 0 && str != "") 
    {
        if (re.test(str) == true) 
	        valid = 1;
        else 
            valid = 0;
    }
    else
        valid = 1;

    if (showMsg) 
    {
        if (valid)
	        return true;
        else 
        {
	        msg = msg + "\n" + str + ": Email is entered incorrectly";
	        alert(msg);
	        return false;
        }
    }
    else
        return valid;
}




//////////////////////////////////////////////////////////////
//  Yahoo! Inc.
//if (document.location.href.indexOf("/checkout/thanks") > -1)
//{

//    window.ysm_customData = new Object();
//    window.ysm_customData.conversion = "transId=,currency=,amount=";
//    var ysm_accountid  = "1B0I6S3KS20OCOK1VJUEC5FSNH0";
//    document.write("<SCR" + "IPT language='JavaScript' type='text/javascript' " 
//    + "SRC=//" + "srv2.wa.marketingsolutions.yahoo.com" + "/script/ScriptServlet" + "?aid=" + ysm_accountid 
//    + "></SCR" + "IPT>");

//}
//////////////////////////////////////////////////////////////
// Leaving this in, but better way to do it with addEvent()
function popUp(fileName, width, height) 
{
    var page = fileName;
	var winProps = "height=" + height + ",width=" + width + ",location=no,top=0,scrollbars=yes,menubar=no,toolbar=no,resizable=yes";
	var theWin = window.open(page, "xWindow", winProps);
}

// Example: rel="popup console 800 600"
function addEvent(elm, evType, fn, useCapture){if(elm.addEventListener){elm.addEventListener(evType, fn, useCapture);return true;}else if (elm.attachEvent){var r = elm.attachEvent('on' + evType, fn);return r;}else{elm['on' + evType] = fn;}}
			var newWindow = null;

			function closeWin(){
				if (newWindow != null){
					if(!newWindow.closed)
						newWindow.close();
				}
			}

			function popUpWin(url, type, strWidth, strHeight){

				closeWin();

				type = type.toLowerCase();

				if (type == "fullscreen"){
					strWidth = screen.availWidth;
					strHeight = screen.availHeight;
				}
				var tools="";
				if (type == "standard") tools = "resizable,toolbar=yes,location=yes,scrollbars=yes,menubar=yes,width="+strWidth+",height="+strHeight+",top=0,left=0";
				if (type == "email") tools = "resizable,toolbar=no,location=no,scrollbars=yes,menubar=no,width="+strWidth+",height="+strHeight+",top=0,left=0";
				if (type == "console" || type == "fullscreen") tools = "resizable,toolbar=no,location=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=0,top=0";
				newWindow = window.open(url, "newWin", tools);
				newWindow.focus();
			}

			function doPopUp(e)
			{
			//set defaults - if nothing in rel attrib, these will be used
			var t = "standard";
			var w = "780";
			var h = "580";
			//look for parameters
			attribs = this.rel.split(" ");
			if (attribs[1]!=null) {t = attribs[1];}
			if (attribs[2]!=null) {w = attribs[2];}
			if (attribs[3]!=null) {h = attribs[3];}
			//call the popup script
			popUpWin(this.href,t,w,h);
			//cancel the default link action if pop-up activated
			if (window.event) 
				{
				window.event.returnValue = false;
				window.event.cancelBubble = true;
				} 
			else if (e) 
				{
				e.stopPropagation();
				e.preventDefault();
				}
			}

			function findPopUps()
			{
			var popups = document.getElementsByTagName("a");
			for (i=0;i<popups.length;i++)
				{
				if (popups[i].rel.indexOf("popup")!=-1)
					{
					// attach popup behaviour
					popups[i].onclick = doPopUp;
					// add popup indicator
					if (popups[i].rel.indexOf("noicon")==-1)
						{
						popups[i].style.backgroundImage = "url(pop-up.gif)";
						popups[i].style.backgroundPosition = "0 center";
						popups[i].style.backgroundRepeat = "no-repeat";
						popups[i].style.paddingLeft = "15px";
						}
					// add info to title attribute to alert fact that it's a pop-up window
					popups[i].title = popups[i].title + " [Opens in pop-up window]";
					}
				}
			}

			addEvent(window, "load", findPopUps, false);

function addEvent(elm, evType, fn, useCapture){if(elm.addEventListener){elm.addEventListener(evType, fn, useCapture);return true;}else if (elm.attachEvent){var r = elm.attachEvent('on' + evType, fn);return r;}else{elm['on' + evType] = fn;}}

// seo control 'read more/less' link
function SeoShowHideText(moreorless)
{
    if (moreorless == 1)
    {
        document.getElementById('seoboxarticlelink').innerHTML = '<a href="javascript: SeoShowHideText(0);">Show Less</a>';
        document.getElementById('seobottomdivart').style.display = 'inline';

    }
    else
    {
        document.getElementById('seoboxarticlelink').innerHTML = '<a href="javascript: SeoShowHideText(1);">Show More</a>';
        document.getElementById('seobottomdivart').style.display = 'none';
    }

}
// for newsletter popup
function toggleLayer( whichLayer )
    {
      var elem, vis;
      if( document.getElementById ) // this is the way the standards work
        elem = document.getElementById( whichLayer );
      else if( document.all ) // this is the way old msie versions work
          elem = document.all[whichLayer];
      else if( document.layers ) // this is the way nn4 works
        elem = document.layers[whichLayer];
      vis = elem.style;
      // if the style.display value is blank we try to figure it out here
      if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
        vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';
      vis.display = (vis.display==''||vis.display=='block')?'none':'block';
    }
    // for newsletter popup
    function CallInit()
    {
        // if init() function exists in the page, the call it otherwise don't
        if( typeof init == 'function' )
            init();      
         
    }
    // for newsletter popup
    function Open_PopUp (page) 
    {
        var options="toolbar=no,  location=no,  scrollbars=no, resizable=no, width=550, height=785, top=85, left=140";
        window.open(page,"",options);
    }
	