function addBookmark() {
	window.external.AddFavorite(location.href, document.title);
	return false;
}

function productPopup(url) {
	var width = 525;
	var height = 360;
	var left = (screen.width-width)/2;
	var top = (screen.height*0.8-height)/2;
		
	newWin = window.open(url, "popup", "width="+width+",height="+height+",toolbar=no,location=no,directories=no,resizable=no,status=no,menubar=no,screenX=100,screenY=100, left="+left+", top="+top);
	
	return false;
}

function termsPopup(url) {
	var width = 600;
	var height = 500;
	var left = (screen.width-width)/2;
	var top = (screen.height*0.8-height)/2;
		
	newWin = window.open(url, "popup", "width="+width+",height="+height+",scrollbars=yes,toolbar=no,location=no,directories=no,resizable=no,status=no,menubar=no,screenX=100,screenY=100, left="+left+", top="+top);
	
	return false;
}

function new_window(url) {
	window.open(url);
	return false;
}

function collapse_lhnav() {
	for (var i=0;i<$('lhnav').childNodes.length;i++) {
		if($('lhnav').childNodes[i].lastChild && $('lhnav').childNodes[i].lastChild.tagName == "UL") {
			 Element.toggle($('lhnav').childNodes[i].lastChild);
		}
	}
}


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;
}

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 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 rememberLoginCheck(strCheckID, strInputID) {
	if (document.getElementById(strCheckID).checked) {
		var dtExpires = new Date();
		deleteCookie('remembercplogin');
		dtExpires.setTime(dtExpires.getTime() + 2678400000); // 31 days
		//alert(dtExpires);
		setCookie('remembercplogin', document.getElementById(strInputID).value, dtExpires);
	}
	else {
		deleteCookie('remembercplogin');
	}
	
	return true;
}

function slideme(element_id) {
	if($(element_id)) {
		Effect.toggle(element_id,'blind', {afterFinish: slideIndicator, duration: 0.3});
	}
}

function hideme(element_id) {
	if($(element_id)) {
		$(element_id).style.display = "none";
		if($('hdr_' + element_id)) $('hdr_' + element_id).className = "collapsed";
	}
}

function slideIndicator(obj) {
		element_id = obj.element.id;
		
		if($('hdr_' + element_id)) {
			if($(element_id).visible()) $('hdr_' + element_id).className = "expanded";
				else $('hdr_' + element_id).className = "collapsed";
		}
}

function enabletabs() {
	var firstTab = true;
	
	tabs = document.getElementsByClassName('tab');
	for ( var i = 0; i < tabs.length; i++ ) {
		if(firstTab) {
			toggleTab(tabs[i].rel);
			firstTab = false;
		}
		
		tabs[i].onclick = function() { toggleTab(this.rel); return false;}
	}
	
}

function toggleTab(selectedTab) {
	tabs = document.getElementsByClassName('tab');
	for ( var i = 0; i < tabs.length; i++ ) {
		if(tabs[i].rel == selectedTab) {
			if($(tabs[i].rel)) $(tabs[i].rel).show();
			tabs[i].parentNode.className = "selected";
		}else{
			if($(tabs[i].rel)) $(tabs[i].rel).hide();
			tabs[i].parentNode.className = "";
		}
	}
}

function lock_n_load() {
	// Process link relations
	var external_links = new Array();
	external_links = document.getElementsByTagName('A');
	
	for ( var i = 0; i < external_links.length; i++ ) {
		if(external_links[i].rel=="external") external_links[i].onclick = function () { new_window(this.href); return false;};
			else if(external_links[i].rel=="productkb") external_links[i].onclick = function () { productPopup(this.href); return false;};
			else if(external_links[i].rel=="termspopup") external_links[i].onclick = function () { termsPopup(this.href); return false;};
	}
	
	enabletabs();
	// Fire off sIFR
}

window.onload = function () {lock_n_load()};