/* -----------------------------------------------
Title: Common script
Author: Jarid Love
Last Modified: 13 Feb 2007
----------------------------------------------- */

/* Environment Variables
---------------------------------------------------- */
var isSSL = (location.protocol == "https:")?true:false;
var isStage = (location.href.indexOf("stage") > 0) ? true : false;
var isTest = (location.href.indexOf("wwwtest.provo.novell.com") > 0) ? true : false;
var isDev = (location.href.indexOf("wwwdev.provo.novell.com") > 0) ? true : false;
var redirect = (location.href.indexOf("forceRedirect=false") > 0) ? false: true;
function getSecureUrl() {
	return (isDev)?"https://secure-wwwdev.provo.novell.com":(isTest)?"https://secure-wwwtest.provo.novell.com":(isStage)?"https://secure-wwwstage.provo.novell.com":"https://secure-www.novell.com";
}

var s = (isDev)?"http://wwwdev.provo.novell.com":(isTest)?"http://wwwtest.provo.novell.com":(isStage)?"http://wwwstage.provo.novell.com":"http://www.novell.com";
var ss = (isSSL)? getSecureUrl() : s;
var n_domain = location.host; 
var n_dirs = location.pathname.split("/");
var n_root = (n_dirs.length>2)?n_dirs[1]:null;
var n_root2 = (n_dirs.length>3)?n_dirs[2]:null;

var isDOM = (document.getElementById)?true:false; // all DOM based browsers including IE
var isNS4 = (document.layers)?true:false;
var isIE = (document.all)?true:false;
var isMac = (navigator.appVersion.indexOf("Mac") != -1)?true:false;
var isWin = (navigator.appVersion.indexOf("Win") != -1)?true:false;
var isLinux = (navigator.platform.indexOf("Linux") != -1)?true:false;
var usragent = navigator.userAgent.toLowerCase();
var isOperaBadDom = (usragent.substr(usragent.indexOf("opera")+6,1)<=6)?true:false; // this detects opera 6 or below which have crappy DOM support
var isOperaGoodDom = (usragent.substr(usragent.indexOf("opera")+6,1)>6)?true:false;
var isKonqueror = (usragent.indexOf("konqueror")>=0)?true:false;
var langCompatible = (isDOM && n_domain.indexOf("novell.com") >= 0);

/* Cookie Functions
---------------------------------------------------- */
function readCookie(name) {
	var cks = document.cookie.split(';');
	for(var i=cks.length-1; i >= 0; i--) {
		var c = cks[i];
		while(c.charAt(0)==' ') c = c.substring(1,c.length);
		if(c.indexOf(name+"=")==0) return c.substring(name.length+1,c.length);
	}
	return null;
}

function deleteCookie(name,path,domain) {
	if(readCookie(name)) { document.cookie = name + "=" +
		((path) ? ";path=" + path : ";path=/") +
		((domain) ? ";domain=" + domain : ";domain=.novell.com") +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
}

function createCookie(name,value,days,path,domain) {
	if(days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+
	((path) ? ";path=" + path : ";path=/") +
	((domain) ? ";domain=" + domain : ";domain=.novell.com");
}

/* Localization Functions
---------------------------------------------------- */
function getPageCharset() {
	var mt = document.getElementsByTagName('meta');
	for(var i=0; i<mt.length; i++) {
		var ct = mt[i].getAttribute('content');
		if(ct != null && ct.toLowerCase().indexOf('charset=') != -1) return ct.substring(ct.toLowerCase().indexOf('charset=')+8);
	}
	return "iso-8859-1";
}

var n_lang = readCookie("novell_language");
var n_country = readCookie("novell_country");
var n_cnt=(n_country!=null && n_country.length>3)?n_country.substring(0,2):"US";
var n_enc = getPageCharset();
var n_phone = "";

function setLang(lang) {
	createCookie("novell_language",lang,365);
}

function setCountry(co,coname) {
	createCookie("novell_country",co+"|"+coname,(co == "") ? 0 : 365);
}

/* Include menu script, css, and local phone number
---------------------------------------------------- */
if(isDOM) { 
	if(window.name == "printer_friendly") {
		document.write('<link rel="stylesheet" type="text/css" href="'+ss+'/common/inc/printerfriendly.css" title="Printer Friendly" />');
		var s_prop15=location.href;
	}
	var hasHdrNav = true; 
}

function showPrinterFriendly() {
	if(document.getElementById("contentcontainer")) {
		var pfwindow = window.open(location.href,"printer_friendly");
		pfwindow.focus();
	}
}

/* Load Translated Text
---------------------------------------------------- */
function loadHdrTransltion(suffix) {
	suffix = (suffix == 'en-us' || n_lang == null) ? 'en-us' : suffix;
	document.write('<script type="text/javascript" src="'+ss+'/common/inc/local/hdr_menu_'+suffix+'.js"><\/script>');
}
if(n_domain.indexOf("novell.de") >= 0) loadHdrTransltion("de-de");
else if(n_domain.indexOf("novell.co.jp") >= 0) loadHdrTransltion("ja-jp");
else loadHdrTransltion((typeof navlang!="undefined") ? navlang : n_lang);

/* Misc get functions
---------------------------------------------------- */
function getRandomInt(min, max) {
	return (min >= max) ? max : Math.floor(((max+1 - min)*Math.random())+min);
}

function getItemWidth(obj) {
	var width = obj.clientWidth;
	return (width == 0) ? obj.offsetWidth : width;
}

function getItemHeight(obj) {
	var height = obj.clientHeight;
	return (height == 0) ? obj.offsetHeight : height;
}

function getXY(obj) {
	var intX = 0;
	var intY = 0;
	try {
		do { // Walk up our document tree until we find the body and add the distance from the parent to our counter.
			intX += obj.offsetLeft;
			intY += obj.offsetTop;
			obj = obj.offsetParent;
		} while(obj.tagName != "BODY" && obj.tagName != "HTML")
	}
	finally {
		return new Array(intX,intY);
	}
}

function getQueryParm(name) {
	var params = document.params;
	if(!params) {
		document.params = (location.search.substring(1)).split("&");
		params = document.params;
	}
	for(var i = 0; i < params.length; i++) {
		var param = params[i].split("=");
		if(param[0] == name) return param[1];
	}
	return null;
}

/* open link in new window (mainly for links to external site)
---------------------------------------------------- */
function openExternal(URL, w, h, s, n, r) {
	// It is possible to bypass w and h by passing in 'noW', 'noH'
	var attr = "";
	if(typeof w != "undefined" && w!= 'noW') attr += "width=" + w;
	if(typeof h != "undefined" && h != 'noH') attr += ",height=" + h;
	if(attr.length > 0) { // when no width or height is specified, use window core defaults, do not add any other values
		attr += (typeof s != "undefined" && s == true) ? ',scrollbars=yes' : ',scrollbars=no'; // default on sized window = no scrollbars
		attr += (typeof r != "undefined" && r == false) ? ',resizable=no' : ',resizable=yes'; // default on sized window = resizable
	}
	if(attr.charAt(0)==",") attr = attr.substring(1);
	var winExt = (!n) ? window.open(URL,'_blank',attr) : window.open(URL,n,attr);
	if(winExt && winExt.blur) winExt.focus();
}

/* tracking functions
---------------------------------------------------- */
// code to track adwords
var gAdword = getQueryParm("google_adword");
if(gAdword && gAdword != null) document.cookie = "google_adword=GooglePS:"+gAdword+";path=/;domain=.novell.com";

// code to track newsletter links
var gnews = getQueryParm("gnews");
if(gnews && gnews != null) document.cookie = "g_newsletter=GlobalNews:"+gnews+";path=/;domain=.novell.com";

/* Functions to hide/show plugins (ie. flash)
---------------------------------------------------- */
function hidePlugins() {
	// hide select boxes in IE versions > 7 because they show through menus
	var agt=navigator.userAgent.toLowerCase();
	if(isIE && (agt.indexOf("msie 4") >= 0 || agt.indexOf("msie 5") >= 0 || agt.indexOf("msie 6") >= 0)) {
		var selects = document.getElementsByTagName("select");
		for(var i = selects.length-1; i >=0 ; i--) {
			selects[i].style.visibility = "hidden";
		}
	}
	// hide flash content because it shows through navigation
	if(typeof flash != "undefined") {
		// if flash.forcehide, hide property has been manually set
		// if linux, wmode not supported, so hide flash
		// if flash version is less than 6,0,79,0 hide flash because wmode not supported widely
		if(flash.forcehide || isLinux || (flash.version <= 6 && flash.rev < 79) || isOperaGoodDom) hideFlash();
	}
	hiddenElmnts = true;
};

function hideFlash() {
	for(var i = 0; i < flash.movies.length; i++) {
		var elmt = document.getElementById("flash_"+i);
		var y = getXY(elmt)[1];
		if(y > 0 && y < 418) {
			//elmt.parentNode.style.background = "#e7e7e7";
			elmt.style.visibility = 'hidden';
		}
	}
};

function showPlugins() {
	// show select boxes in IE versions > 7 that were hidden because they show through menus
	var agt=navigator.userAgent.toLowerCase();
	if(isIE && (agt.indexOf("msie 4") >= 0 || agt.indexOf("msie 5") >= 0 || agt.indexOf("msie 6") >= 0)) {
		var selects = document.getElementsByTagName("select");
		for(var i = selects.length-1; i >=0 ; i--) {
			selects[i].style.visibility = "inherit";
		}
	}
	// show flash content that was hidden because it shows through navigation
	if(typeof flash != "undefined") {
		if(flash.forcehide || isLinux || (flash.version <= 6 && flash.rev < 79) || isOperaGoodDom) showFlash();
	}
	hiddenElmnts = false;
};

function showFlash() {
	for(var i = 0; i < flash.movies.length; i++) {
		var elmt = document.getElementById("flash_"+i);
		var y = getXY(elmt)[1];
		if(y > 0 && y < 418) {
			elmt.style.visibility = 'visible';
		}
	}
};
