//==============================================================================
// http://www.scottandrew.com/js/js_util.js
// addEvent and removeEvent
// cross-browser event handling for IE5+,  NS6 and Mozilla
//==============================================================================

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 {
		//alert("Handler could not be added");
	}
} 

function removeEvent(elm, evType, fn, useCapture) {
	if (elm.removeEventListener) {
		elm.removeEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.detachEvent) {
		var r = elm.detachEvent("on"+evType, fn);
		return r;
	}
	else {
	    //alert("Handler could not be removed");
	}
}

//==============================================================================
// This function is built specifically for IE. IE doesn't recognize CSS
// :first-child and :last-child psuedo elements, but the IE JavaScript engine
// does. So in the CSS there is a style using the psuedo class, and a duplicate
// for IE (.iefirst-child and .ielast-child).
//
// ID is the wrapper around the TAG you want to get the first and last
// child for. This way you don't have to have an ID for the element you want
// children for and you can hit multiple objects.
//==============================================================================

function NA_ieChildren(id,tag) {
	if(document.getElementById(id))	{
		var els = document.getElementById(id).getElementsByTagName(tag);
		for (var i=els.length-1; i>=0; i--) {
			els[i].firstChild.className+=" iefirst-child";
			els[i].lastChild.className+=" ielast-child";
		}
	}
}

function NA_ieChildren_init() {
	NA_ieChildren('content-main','tr');
	NA_ieChildren('content-main','tbody');
	NA_ieChildren('nav-main','ul');
	NA_ieChildren('nav-global','ul');
	NA_ieChildren('nav-section','ul');
	NA_ieChildren('siteinfo-legal','ul');
	NA_ieChildren('content-main','ul');
}

// IE only
if (window.attachEvent) window.attachEvent("onload", NA_ieChildren_init);

//==============================================================================
// This function is built specifically for browsers that are not mozilla or IE.
// It applies a class to a PARAGRAPH so that the custom formfield background image
// will appear. Safari, Opera - they will not allow for an INPUT field to be
// styled enough to effectily hide it.
//==============================================================================

function NA_login_init() {
	NA_login('content-login','p');
	NA_login('content-promo-ne','p');
	NA_login('form_promotion','p');
}

function NA_login(id,tag) {
	if(document.getElementById(id))	{
		if(navigator.userAgent.toLowerCase().indexOf('mozilla') != -1 &&
		   navigator.userAgent.toLowerCase().indexOf('safari') == -1) {
			var els = document.getElementById(id).getElementsByTagName(tag);
			for (var i=els.length-1; i>=0; i--) {
					els[i].className += " withbg";
			}
		}
	}
}

addEvent(window, "load", NA_login_init);


//==============================================================================
// General Site Funtions below
//==============================================================================


// Functions to conceal email addresses from spiders and crawlers

function makeEmail(name,domain,styleClass){
    document.write('<a class=\"' + styleClass + '\" href=\"mailto:' + name + '@' + domain + '\">' + name + '@' + domain + '</a>')
}

function makeEmailSun(name,styleClass){
    makeEmail(name,'dextermo.net',styleClass)
}

//this opens a small window for the IM member services chat 2/18/05 ED
function chat_window(){
    window.open('https://admin.instantservice.com/links/5865','custclient','width=600,height=160,scrollbars=0');
}

// Function to retrieve parameters from the url
function getparamurl(param) {
    var location = window.location.href;
    var end = location.length;
    var tester = location.indexOf("?");
    if (tester < 0) return null;
    paraloc = location.indexOf(param,tester+1);
    if (paraloc < 0) return null;  
    start = location.indexOf("=",paraloc);
    if (start < 0) return null;  
    finish = location.indexOf("&",start);
    if (finish < 0) {
	finish = location.indexOf("#",start);
        if (finish < 0) {
	    var string = unescape(location.substring(start+1,end));
	}
    }
    else {
	var string = unescape(location.substring(start+1,finish));
    }
    return string;
}

function flash_window(){
window.open('/how/install/installguide.html','flash','directories=no,toolbar=no,resizable=yes,menubar=no,scrollbars=no,width=574,height=550');
}
