/* -----------------------------------------------
Title: Common script
Author: Jarid Love
Comment: App customized copy of /common/inc/hdr_script_2010.js
----------------------------------------------- */

/* Environment Variables
---------------------------------------------------- */
var isExternalHdr = false;
var isSSL = (window.location.protocol == "https:")?true:false;
var isStage = (window.location.hostname.indexOf("stage") > 0 || window.location.hostname == ("usabilitytest")) ? true : false;
var isTest = (window.location.hostname.indexOf("test") > 0) ? true : false;
var isDev = (window.location.hostname.indexOf("dev") > 0) ? true : false;
var allowRedirect = (window.location.href.indexOf("forceRedirect=false") > 0) ? false: true;
var buSite = "novell";

function inEMEA(){
	var countriesEMEA = new RegExp('AT|DE|LI|DZ|BJ|BF|CM|TD|CI|FR|GA|GM|GP|LR|MG|ML|MQ|MR|YT|MC|MA|NE|RE|PM|SN|SL|TG|TN|EH|AL|AD|AO|AM|AZ|BH|BY|BE|BA|BW|BG|BI|CV|CF|KM|HR|CY|CZ|DJ|EG|ER|EE|ET|FO|FI|GE|GH|GI|GR|GL|HU|IS|IQ|IL|IT|JO|KZ|KE|KW|KG|LV|LB|LS|LT|LU|MK|MW|MV|MT|MU|MD|MZ|NA|NG|OM|PL|PT|QA|RO|RU|RW|SH|SM|SA|CS|SC|SK|SI|SO|ZA|ES|SZ|TJ|TZ|TR|TM|UG|UA|AE|UZ|YE|ZM|ZW|IE|GS','i');
	return (n_cnt.search(countriesEMEA) >= 0) ? true : false;
}

function inAPAC(){
	var countriesAPAC = new RegExp('AS|AU|BD|BT|BN|CC|CK|CN|CX|FJ|FM|GU|HK|IN|IO|JP|LK|KH|KI|KR|LA|LK|MH|MM|MN|MO|MP|MY|NC|NR|NU|NZ|PF|PG|PH|PN|PW|SB|SG|TH|TK|TL|TO|TV|TW|VN|VU|WF|WS','i');
	return (n_cnt.search(countriesAPAC) >= 0) ? true : false;
}

function getSecureUrl() {
	if(window.location.hostname.indexOf("netiq") > 0 ) {
		//netiq
		return (isTest)?"https://wwwtest.netiq.com":(isStage)?"https://wwwtest.netiq.com":"https://www.netiq.com";
	}
	else if(window.location.hostname.indexOf("suse") > 0 ) {
		//suse
		return (isTest)?"https://wwwtest.suse.com":(isStage)?"https://wwwtest.suse.com":"https://www.suse.com";
	}
	else if(window.location.hostname.indexOf("partnernet") > 0 ) {
		//partnernet
		return (isTest)?"https://wwwtest.partnernetprogram.com":(isStage)?"https://wwwtest.partnernetprogram.com":"https://www.partnernetprogram.com";
	}
	// novell
	return (isDev)?"https://secure-wwwdev.provo.novell.com":(isTest)?"https://secure-wwwtest.provo.novell.com":(isStage)?((location.href.indexOf("usability") > 0)?"http://usabilitytest.novell.com":"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)?((location.href.indexOf("usability") > 0)?"http://usabilitytest.novell.com":"http://wwwstage.provo.novell.com"):"http://www.novell.com";
var usrInfo = "/inc/util/secure/userInfo.php";
if(window.location.hostname.indexOf("netiq") > 0 ) {
	//netiq
	buSite = "netiq";
	s = (isTest)?"http://wwwtest.netiq.com":(isStage)?"http://wwwtest.netiq.com":"http://www.netiq.com";
	usrInfo = "/common/util/secure/userInfo.php";
}
else if(window.location.hostname.indexOf("suse") > 0 ) {
	//suse
	buSite = "suse";
	s = (isTest)?"http://wwwtest.suse.com":(isStage)?"http://wwwtest.suse.com":"http://www.suse.com";
	usrInfo = "/common/util/secure/userInfo.php";
}
else if(window.location.hostname.indexOf("partnernet") > 0 ) {
	//partnernet
	buSite = "partnernet";
	s = (isTest)?"http://wwwtest.partnernetprogram.com":(isStage)?"http://wwwtest.partnernetprogram.com":"http://www.partnernetprogram.com";
	usrInfo = "/common/util/secure/userInfo.php";
}
else {

}
var n_server = s;
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 n_root3 = (n_dirs.length>=4)?n_dirs[3]:null;
var n_root4 = (n_dirs.length>=5)?n_dirs[4]: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 is404Page = (typeof is404Page != "undefined") ? is404Page : false;

var EMEACountries = ["AT", "BE", "BG", "CH", "CZ", "DE", "DK", "ES", "FI", "FR", "GB", "HU", "IE", "IL", "IT", "LT", "LU", "LV", "NO", "PL", "PT", "RU", "SE", "TR", "UA", "ZA", "AD", "AE", "AL", "AM", "AO", "AZ", "BA", "BF", "BG", "BH", "BI", "BJ", "BV", "BW", "BY", "CD", "CF", "CG", "CI", "CM", "CS", "CV", "CY", "DJ", "DZ", "EE", "EG", "EH", "ER", "ES", "ET", "EUR", "AQ", "BM", "GL", "GU", "PM", "RE", "UM", "FO", "FX", "GA", "GE", "GH", "GI", "GM", "GQ", "GR", "GW", "HR", "IO", "IQ", "IR", "IS", "JO", "KE", "KG", "KM", "KW", "KZ", "LB", "LI", "LR", "LS", "LX", "LY", "MA", "MC", "MD", "MG", "MK", "ML", "MR", "MT", "MU", "MV", "MW", "MZ", "NA", "NE", "NG", "OM", "QA", "RO", "RW", "SA", "SC", "SD", "SH", "SI", "SJ", "SK", "SL", "SM", "SN", "SO", "ST", "SY", "SZ", "TD", "TF", "TG", "TJ", "TM", "TN", "TZ", "UG", "UK", "UZ", "VA", "YE", "YT", "YU", "ZM", "ZR", "ZW"];
var EMEAChatCountries = ["AT", "BE", "DK", "FR", "DE", "IE", "IT", "ZA", "ES", "SE", "CH", "GB"];

/* 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) {
	var expires = "";
	if(days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		expires = "; expires="+date.toGMTString();
	}
	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 "UTF-8";
}

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_cntName= (n_country!==null && n_country.length>3)?n_country.substring(3):"United States";
var n_enc = getPageCharset();

function siteSupportsLang() {
	if(isDOM) {
		var n_lang_sites = [ /* sites that support localization */
			"supporttest.provo.novell.com",
			"supportstage.provo.novell.com",
			"support.novell.com",
			"wwwdev.provo.novell.com",
			"wwwtest.provo.novell.com",
			"wwwstage.provo.novell.com",
			"www.novell.com",
			"secure-wwwdev.provo.novell.com",
			"secure-wwwtest.provo.novell.com",
			"secure-wwwstage.provo.novell.com",
			"secure-www.novell.com"
		];
		for(var i = n_lang_sites.length-1;i > -1; i--) {
			if(n_domain == n_lang_sites[i]) {
				return true;
			}
		}
	}
	return false;
}
var isLangCompatible = siteSupportsLang();
var langCompatible = isLangCompatible; // for legacy support

function isTranslationDir(dir) {
	if(dir === null) {
		return false;
	}
	var langDirs = [
		"de-de",
		"es-es",
		"fr-fr",
		"it-it",
		"nl-nl",
		"cs-cz",
		"zh-cn",
		"zh-tw",
		"ja-jp",
		"hu-hu",
		"pl-pl",
		"pt-br",
		"ru-ru",
		"sv-se",
		"fi-fi",
		"da-dk",
		"no-no",
		"tr-tr"
	];
	for(var i = langDirs.length-1; i > -1; i--) {
		if(langDirs[i] == dir) {
			return true;
		}
	}
	return false;
}

function isCountryDir(dir) {
	if(dir === null) {
		return false;
	}
	var coDirRegex = new RegExp("^[A-Z][A-Z]$");
	if(coDirRegex.test(dir)) {
		return true;
	}
	return false;
}

function isFilteredRootDir(dir) {
	switch(dir) {
		case "communities" :
		case "rc" :
		case "cgi-bin" :
		case "servlet" :
		case "global" :
		case "ICSLogin" :
		case "ICHAINLogout" :
			return true;
		default :
			return false;
	}
}

function setLang(lang) {
	createCookie("novell_language",lang,365);
	n_lang = lang;
}

function setCountry(co,coname) {
	if(coname == null) {
		n_cnt = co;
		document.write('<script type="text/javascript" src="/common/util/langsetcountry.php?lang='+n_lang+'&&co='+n_cnt+'"><\/script>'); // call external script to set country cookie because we have to look up country name
	}
	else {
		createCookie("novell_country",co+"|"+coname,(co === "") ? 0 : 365);
		n_cnt = co;
		n_cntName = coname;
		n_country = readCookie("novell_country");
	}        
	 
	if(n_lang == null){
		switch(co) {
			case "IT" : 
				setLang("it-it"); 
				document.location.reload(true);
				break;
			case "JP" : 
				setLang("ja-jp");
				document.location.reload(true);
				break;
			case "CN" : 
				setLang("zh-cn");
				document.location.reload(true);
				break;
			case "SE" : 
				setLang("sv-se");
				document.location.reload(true);
				break;
			case "PL" : 
				setLang("pl-pl");
				document.location.reload(true);
				break;
			case "NO" : 
				setLang("no-no");
				document.location.reload(true);
				break;
			case "CZ" : 
				setLang("cs-cz");
				document.location.reload(true);
				break;
			case "HU" : 
				setLang("hu-hu");
				document.location.reload(true);
				break;
			case "FI" :
				setLang("fi-fi");
				document.location.reload(true);
				break;
			case "RU" :
				setLang("ru-ru");
				document.location.reload(true);
				break;
			case "TR" :
				setLang("tr-tr");
				document.location.reload(true);
				break;
		}	}

}

function setDefaultCountryForLang(lang) {
	switch(lang) {
		case "it-it" : 
			setCountry("IT","Italia");
			break;
		case "ja-jp" : 
			setCountry("JP","&#26085;&#26412;");
			break;
		case "zh-cn" : 
			setCountry("CN","&#20013;&#22269;");
			break;
		case "sv-se" : 
			setCountry("SE","Sverige");
			break;
		case "pl-pl" : 
			setCountry("PL","Polska");
			break;
		case "no-no" : 
			setCountry("NO","Norge");
			break;
		case "cs-cz" : 
			setCountry("CZ","&#268;esk&#225; republika");
			break;
		case "hu-hu" : 
			setCountry("HU","Magyarorsz&#225;g");
			break;
		case "fi-fi" :
			setCountry("FI","Suomi");
			break;
		case "ru-ru" :
			setCountry("RU","Rossiya");
			break;
		case "tr-tr" :
			setCountry("TR", "T&#252;rkiye");
			break;
	}
}

function getNovellTranslation(arry) {
	var txt = arry[n_lang];
	if(!txt) {
		txt = arry["en-us"];
	}
	return txt;
}

/* Country Check
---------------------------------------------------- */
if(n_country == null && buSite == "novell")
	document.write('<script type="text/javascript" src="'+s+'/common/util/ipcheck/index.php?v=1"><\/script>');

/* Localization Redirect
---------------------------------------------------- */
if(isLangCompatible && !is404Page) {
	if(n_lang===null) {
		// no language set
		if(typeof defaultPageLang != "undefined" && typeof defaultPageCntry != "undefined") {
			// lang/co override vars set so just show page matching override without setting cookies
			n_lang = defaultPageLang;
			n_country = defaultPageCntry;
			n_co_array = n_country.split("|");
			n_cnt = n_co_array[0];
			n_cntName = n_co_array[1];
		}
		else {
			// set language to default of target page
			setLang(isTranslationDir(n_root) ? n_root : "en-us");
			setDefaultCountryForLang(n_lang);
		}
	}
	else if(allowRedirect===true && !isFilteredRootDir(n_root) && (location.pathname.indexOf(".htm") >= 0 || location.pathname.lastIndexOf('/') == location.pathname.length-1)) {
		if(isTranslationDir(n_root) && n_root != n_lang) {
			// user navigated to different lang dir then setting so change language
			setLang(n_root);
			setDefaultCountryForLang(n_root);
		}
		if(isCountryDir(n_root2) && n_cnt != n_root2) {
			// user navigated to different non-english country dir so change country
			setCountry(n_root2);
		}
		if(n_lang == "en-us" && isCountryDir(n_root) && n_cnt != n_root) {
			// user navigated to different english country dir so change country
			setCountry(n_root);
		}
		// load redir app if one of following conditions is met
		if(
			(n_lang != "en-us" && (n_root != n_lang || n_root2 != n_cnt)) ||
			(n_lang == "en-us" && n_cnt != "US" && !isCountryDir(n_root))
		) {
			if(readCookie("novell_lang_redirect_refer")===null){ //only set value if one has not already been set
				createCookie("novell_lang_redirect_refer", document.referrer, 1);
			}
			var htmlTag = document.getElementsByTagName("html")[0];
			htmlTag.style.display = "none";
			document.write('<script type="text/javascript" src="/common/util/langredirect.php?url='+escape(location.href)+'"><\/script>'); // redir app checks the file system to see if there is a mathing page for co/lang and returns redirect if one exists
		}
	}
}
else if(n_lang == null) {
	n_lang = "en-us";
}

/* Include menu script, css, and local phone number
---------------------------------------------------- */
document.write('<script type="text/javascript" src="'+ss+'/common/util/geophone.php?co='+n_cnt+'"><\/script>');

if(n_lang == "ja-jp"){
	document.write('<link rel="stylesheet" type="text/css" href="'+ss+'/common/inc/css/fonts_ja.css" />');
}

if(isDOM) { 
	if(window.name == "printer_friendly") {
		document.write('<link rel="stylesheet" type="text/css" href="'+ss+'/common/inc/printerfriendly.css" title="Printer Friendly" />');
		window.onload = function() {
			window.print();	
		}
	}
	document.write('<script type="text/javascript" src="'+ss+'/common/app/crossbu/js/legacynav.js"><\/script>');
	var hasHdrNav = true; 
}

function showPrinterFriendly() {
	if(document.getElementById("contentcontainer") || document.getElementById("pageContent") || (typeof jQuery != 'undefined' && ($('.pageContainer') || $('.contentContainer')))) {
		var pfwindow = window.open(location.href,"printer_friendly");
		pfwindow.focus();
	}
	else {
		window.open(s+'/inc/pf/pf.jsp?url='+escape(location.href)+'&sourceid=PrinterFriendlyFromFooter');
	}
}

/* login/out functions
---------------------------------------------------- */
function setLoginStatus() {
	var cks = document.cookie.split(';');
	for(var i=0; i < cks.length; i++) {
		var c = cks[i];
		while(c.charAt(0)===' ') {
			c = c.substring(1,c.length);
		}
		if(c.indexOf("IPC")===0 && c.indexOf("=")==16) {
			document.write('<script type="text/javascript" src="'+ss+usrInfo+'"><\/script>');
			return;
		}
	}
}
var isLoggedIn = false;
setLoginStatus();

/* Misc functions
---------------------------------------------------- */
function rgb2hex(rgb) {
	rgb = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
	function hex(x) {
		return ("0" + parseInt(x).toString(16)).slice(-2);
	}
	return hex(rgb[1]) + hex(rgb[2]) + hex(rgb[3]);
}

function getBgColor(obj) {
	var obj = $(obj);
	do {
		var bgColor = obj.css("background-color");
		if(bgColor != "transparent" && bgColor != "rgba(0, 0, 0, 0)") {
			return bgColor;	
		}
		obj = obj.parent();
	} while(obj.tagName != "BODY" && obj.tagName != "HTML");
	return "transparent";
}

function getTxtImg(txt, size, lineHeight, isBold, color, bgcolor, width) {
	var imgUrl = ss+'/common/img/txt2img/?text='+encodeURI(txt);
	if(typeof color != 'undefined' && color) imgUrl += "&color="+color;
	if(typeof bgcolor != 'undefined' && bgcolor) imgUrl += "&bg="+bgcolor;
	if(typeof size != 'undefined' && size) imgUrl += "&size="+size;
	if(typeof lineHeight != 'undefined' && lineHeight) imgUrl += "&linespacing="+lineHeight;
	if(typeof isBold != 'undefined' && isBold == true) imgUrl += "&bold=true";
	if(typeof width != 'undefined' && width != null) imgUrl += "&w="+width;
	return '<img class="txt_img" src="'+imgUrl+'" alt="'+txt+'" onload="$(this).ifixpng();">';
}

function txtToImg(obj, isFixedWidth, bgcolor) {
	var container = (obj.size) ? obj : $(obj);
	var isBold = (container.css("font-weight") == "bold" || parseInt(container.css("font-weight")) > 400) ? true : false;
	var width = (isFixedWidth) ? container.width() : null;
	var bg = (typeof bgcolor && bgcolor) ? bgcolor : getBgColor(obj);
	bg = (bg.indexOf("rgb") > -1) ? rgb2hex(bg) : bg.replace("#","");
	var color = container.css("color");
	color = (color.indexOf("rgb") > -1) ? rgb2hex(color) : color.replace("#","");
	var size = parseInt(container.css("font-size"));
	var lineHeight = (container.css("line-height") == "normal") ? 1.5 : parseInt(container.css("line-height"))/size;
	var imgHtml = getTxtImg(container.text(), size, lineHeight, isBold, color, bg, width);
	container.empty().html(imgHtml);
}

if(n_lang == "ja-jp" && typeof $ != 'undefined'){
	document.write('<script type="text/javascript" src="/common/inc/ja-jp_customize.js"><\/script>');
}

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;
}

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 [intX,intY];
	}
}

function isSupportedTouchDevice() {
	var deviceList = ["iphone","ipod","ipad","android","series60","symbian","palm"];
	var uagent = navigator.userAgent.toLowerCase();
	for(var i = 0; i < deviceList.length; i++) {
		if(uagent.search(deviceList[i]) > -1) {
			return true;
		}
	}
	return false;
}

/* RAC
---------------------------------------------------- */
var racUrl = "/common/inc/requestcall_smallform.html";
var inPageRAC = false;
function closeRAC() {
	if($("#requestcall .phonecall").length){
		$("#racpopup_content #requestcall").find("h3").remove();

		$("#racpopup_content .phonecall").show();
	}

	if(inPageRAC)
		$("#rac_filler").append($("#requestcall").detach()).find("#requestcall").unwrap();

	$("#racpopup").fadeOut("fast", function() {
		hideRACCanopy();
	}).hide();
	
	
	
}

function displayRACPopup() {
	$("#racpopup").css({  
		"display": "block",
		"visibility": "hidden"
	});
	$("#racpopup").css({  
		"top": Math.max(($(window).height()-$("#racpopup").height())/2+$(window).scrollTop(),10),  
		"left": Math.max(($(window).width()-$("#racpopup").width())/2+$(window).scrollLeft(),10)
	});
	$("#racpopup").css({  
		"display": "none",
		"visibility": "visible"
	});
	$("#racpopup").fadeIn("fast");
	$("#raccanopy img").hide();
	
	if(typeof demandbase != "undefined" && typeof Demandbase != "undefined")
		demandbase();
}

function addRACCanopy() {
	if($("#raccanopy").size() == 0) {
		$("body").append('<div id="raccanopy"><img src="'+n_server+'/common/img/racloader.gif" /></div>');
		$("#raccanopy").css("opacity","0.8").click(function() {
			closeRAC();
		});
	}
}

function showRACCanopy() {
	$("#raccanopy img").show();
	hidePlugins(true)
	$("#raccanopy").fadeIn("fast");
	if(isIE && parseInt($.browser.version) < 7) {
		$("#raccanopy").css("position", "absolute").width($(window).width()).height($(document).height());
	}
}

function hideRACCanopy() {
	$("#raccanopy").fadeOut("fast");
	showPlugins(true);
}

function addRACOverlay() {
	addRACCanopy();
	if($("#racpopup").size() == 0) {
		$("body").append('<div id="racpopup"><div id="racpopup_content"></div><div id="racpopup_ftr"><p><a href="#" onclick="closeRAC();return false;"><strong>Close</strong></a></p></div></div>');
	}
}

function switchRAC(){
	
	var rac_height = $('#requestcall').height();
	var rac_margin_bottom = $('#requestcall').css("margin-bottom");

	$('#requestcall').before("<div id='rac_filler' style='background:#e6e6e6; width:100%; height:"+rac_height+"px; margin-bottom:"+rac_margin_bottom+";'></div>");
	$("#racpopup_content").append($('#requestcall').detach());
	
}

function requestCall(url) {
	if(!location.href.indexOf(".novell.com")) {
		// open popup because not on novell.com server
		window.open(n_server+"/company/sales_call_request_popup.html", "rac", "width=600,height=650");
		return;
	}
	if($("#racpopup").size() > 0) {
		showRACCanopy();
		
		if(inPageRAC) //need to swap in the content again
			switchRAC();
		
		handleRAC();
		displayRACPopup();
	}
	else if($("#requestcall").size() > 0) {
		// rac form in page
		inPageRAC = true;

		// use extracted html
		addRACOverlay();
		showRACCanopy();
		switchRAC();
		handleRAC();
		displayRACPopup();
	}
	else {
		// rac form not in page so show overlay
		inPageRAC = false;
		addRACOverlay();
		showRACCanopy();
                if (typeof url == 'string') {
                    racUrl = url;
                }
		if(n_lang != "en-us") {
                    racUrl = "//www.novell.com/common/util/html_request_passthrough.php?url=/" + n_lang + racUrl + "&callback=?";
		} else {
                    racUrl = "//www.novell.com/common/util/html_request_passthrough.php?url=" + racUrl + "&callback=?";
                }
		document.domain = 'novell.com';
		jQuery.ajax({
			type: 'get',
			url: racUrl,
			success: function(data) {
				if (typeof data.result_html == 'string')
				$("#racpopup_content").html(data.result_html);
				displayRACPopup();
				handleRAC();
			},
			complete: function() {
				
			},
			error: function() {
				
			},
			dataType: 'jsonp'
		});
//		$.get(racUrl, function(data){
//		},"html");
	}
}

/* support.novell.com/lifecycle RAC text change
-----------------------------------------------*/
$(document).ready(function() {
    jQuery('.landing_06_popup').click(function() {
        requestCall("/common/inc/requestcall_small_landingpage_form_popup.html");
    });
    
	var lifecycle = location.href;
	if (lifecycle.indexOf('/lifecycle') > 0) {
		$('#rac_overlay a').html('Request a Sales Call');
	}
});

function switchToNotice(noticeUrl) {
	if($("#racpopup").size() > 0) { // form is in popup
		$("#raccanopy img").show();
		$("#racpopup").fadeOut("fast", function() {
			$("#requestcall").css({ 
				"visibility": "hidden",
				"height": "1px",
				"width" : "1px",
				"position" : "absolute"
			});
			$("#racpopup").css("visibility","hidden");
	
			$.get(noticeUrl, function(data){
				$("#racpopup_content").append('<div class="home_tip">'+data+'</div>');
				displayRACPopup();
			},"html");
		});
	}
	else { // form is in page
		addRACOverlay();
		showRACCanopy();
		$.get(noticeUrl, function(data){
			$("#racpopup_content").html('<div class="home_tip">'+data+'</div>');
			displayRACPopup();
		},"html");
	}
	return false;
}

function showRACHome() {
	switchToNotice(n_server+"/"+n_lang+"/common/inc/requestcall_smallform_home_content.html");
	return false;
}

function showRACTech() {
	switchToNotice(n_server+"/"+n_lang+"/common/inc/requestcall_smallform_tech_content.html");
	return false;
}

function homeClick() {
	document.getElementById('salescallrequest').submit();
}

/* Popup functions
---------------------------------------------------- */
function openNovellPopup(url) {
	openIframePopup(url);
}

function openIframePopup(url) {
	addRACCanopy();
	$("body").append('<div id="iframepopup"><div id="iframepopup_content"><iframe id="iframepopup_iframe" src="'+url+'" onload="setTimeout(displayIframePopup, 10)" frameborder="0" scrolling="no" /></div><div id="iframepopup_ftr"><p><a href="#" onclick="closeIframePopup();return false;"><strong>Close</strong></a></p></div></div>');
	$("#raccanopy").click(function() {
		closeIframePopup();
	});
	showRACCanopy();
}

function displayIframePopup() {
	//this function gets called anytime a new URL loads in the iframe. Since sometimes a thank you page will be loaded inside the iframe, we need to make sure the popup isn't visible before proceeding. if it's visible, then this is a "thank you" page being loaded, and so we simply return since we want the page to come up normally within the iframe.
	if($("#iframepopup").css("visibility") == "visible"){
		return false;
	}

	$("#iframepopup").css({  
		"visibility": "hidden",
		"display": "block"
	});
	
	$('#iframepopup_iframe').height(($('#iframepopup_iframe').contents().height()+1)+"px");
	$('#iframepopup_iframe').width($('#iframepopup_iframe').contents().width()+"px");

	$("#iframepopup").css({  
		"top": Math.max(($(window).height()-$("#iframepopup").height())/2+$(window).scrollTop(),10),  
		"left": Math.max(($(window).width()-$("#iframepopup").width())/2+$(window).scrollLeft(),10),
		"display": "none",
		"visibility": "visible"
	});
	$("#iframepopup").fadeIn("fast");
	$("#raccanopy img").hide();
}

function closeIframePopup() {
	$("#iframepopup").fadeOut("fast", function() {
		$("#raccanopy").fadeOut("fast", function() {
			$("#iframepopup, #raccanopy").remove();
		});
	});
}

function openPopup() {  // Function for opening links from flash; variables stored on individual pages
	if(typeof openUrl == 'undefined') {
		return false;
	}
	window.open(openUrl,'_blank',addParams);
}

function openExternal(URL, w, h, s, n, r) { // open link in new window (for external links)
	// 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);
	}
	if(URL.indexOf("play.php") != -1){
		assetClick(URL, false);
	}
	var winExt = (!n) ? window.open(URL,'_blank',attr) : window.open(URL,n,attr);
	if(winExt && winExt.blur) {
		winExt.focus();
	}
}

/* Functions to hide/show plugins (ie. flash)
---------------------------------------------------- */
function hideFlash(hideall) {
	$("object, embed").each(function(){
		var y = $(this).offset().top;
		if ((y > 0 && y < 500) || (typeof hideall != 'undefined' && hideall == 'all')) {
			$(this).css("visibility", "hidden");
		}
	});
}

function hidePlugins(hideall) {
	// hide select boxes in IE versions > 7 because they show through menus
	var agt=navigator.userAgent.toLowerCase();
	if(isIE && parseInt($.browser.version) < 7) {
		$("select").css("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(hideall);
		}
	}
	if(typeof SWFObject != "undefined") {
		var swfObj = new SWFObject();
		if((swfObj.installedVer.major < 6 && swfObj.installedVer.rev < 79) || isLinux || isOperaGoodDom){
			hideFlash(hideall);
		}
	}
	if(typeof frames != "undefined") {
		$("iframe[src*='http://www.novell.com/huddle/event/index.php']").each(function(){
			var getHeight = $(this).height();
			$("#videoembed").height(getHeight);
			$("#videoembed").css({"background-color":"#333"});
			$(this).css({"display":"none"});
		});
	}
	hiddenElmnts = true;
}

function showFlash(hideall) {
	$("object, embed").each(function(){
		var y = $(this).offset().top;
		if ((y > 0 && y < 500) || (typeof hideall != 'undefined' && hideall == 'all')) {
			$(this).css("visibility", "visible");
		}
	});
}

function showPlugins(hideall) {
	// show select boxes in IE versions > 7 that were hidden because they show through menus
	var agt=navigator.userAgent.toLowerCase();
	if(isIE && parseInt($.browser.version) < 7) {
		$("select").css("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(hideall);
		}
	}
	if(typeof SWFObject != "undefined") {
		var swfObj = new SWFObject();
		if((swfObj.installedVer.major < 6 && swfObj.installedVer.rev < 79) || isLinux || isOperaGoodDom){
			showFlash(hideall);
		}
	}
	if(typeof frames != "undefined") {
		$("iframe[src*='http://www.novell.com/huddle/event/index.php']").each(function(){
			$("#videoembed").css({"background":"transparent"});
			$(this).css({"display":"block"});
		});
	}
	hiddenElmnts = false;
}

/* EMEA Chat
---------------------------------------------------- */
function chatClick(){
	var lang = ((n_lang != "en-us") && (n_lang != null)) ? "_"+n_lang : "";
	window.open("/common/inc/chat/",'LaunchChat','width=500,height=340');
}

/*
if($.inArray(n_cnt, EMEAChatCountries) > -1){ //only do chat for emea countries
	var chat_langs = new Array();
	chat_langs["en-us"] = "Chat Now";
	chat_langs["es-es"] = "Inicie un chat";
	chat_langs["de-de"] = "Chatten Sie jetzt";
	chat_langs["it-it"] = "Avvia la chat";
	chat_langs["nl-nl"] = "Chat nu";
	chat_langs["fr-fr"] = "Tchatez avec nous";

	var chat_lang = chat_langs[n_lang];
	if(chat_lang == null)
		chat_lang = chat_langs["en-us"];

	$(document).ready(function(){
		if($(".button_chat").length){
			//only do it for landing pages and product pages
			if($("#requestcall .phonecall").length || $("#products_nav").length){
				$(".button_chat").fadeIn("fast").find("span").text(chat_lang);
				$(".button_chat a").click(function(e){
					chatClick();
			        e.preventDefault();
			        return false;
				});
			}
		}

		if($("#flt_ftr").length){
			$("#flt_ftr ul").append('<li class="flt_ftr_chat"><a href="#">'+chat_lang+'</a></li>');
			$(".flt_ftr_chat a").click(function(e){
		        e.preventDefault();
				chatClick();
		        return false;
			});
		}
	});
}
*/

/* Search Autocomplete
---------------------------------------------------- */
$(document).ready(function() {
	$("#hdr-srch-frm").after('<div id="search_autocomplete"></div>');
	$("#hdr-srch-input").attr("autocomplete", "off").bind("keydown", function(event){
		if (event.which >= 48 && event.which <= 57 || event.which >= 65 && event.which <= 90){
		
			var value = $("#hdr-srch-input").val() + String.fromCharCode(event.which).toLowerCase();
			$.ajax({
				url: "/SearchUI/autoComplete.action?term=" + value,
				dataType: "json",
				type: "POST",
				success: function(data){
					var html = "";
					$.each(data.termMap, function(key, val){
						if(key != "")
							html += '<li><a href="#">'+key+'</a></li>';
					});
					if(html == ""){ //no results
						$("#search_autocomplete").hide();
					}
					else{
						html = "<ul>"+html+"</ul>";
						$("#search_autocomplete").html(html).show();
						
						$("#search_autocomplete li a").click(function(){
							$("#hdr-srch-input").val($(this).text());
							$("#hdr-srch-frm").submit();
							return false;
						});
					}
				}
			});
		}
		else if(event.which == 8){ //delete
			$("#search_autocomplete").html("").hide();
		}
		else if(event.which == 13){ //enter key
			if($("#search_autocomplete").is(":visible")){ //interrupt form submit
		        event.preventDefault();
				if($("#search_autocomplete li.active").length){ //overwrite value with selected value
					$("#hdr-srch-input").val($("#search_autocomplete li.active a").text());
				}
				$("#hdr-srch-frm").submit();
				return false;
			}
		}
		else{
			if (event.which == 38 || event.which == 40) {
				event.preventDefault();
				if(event.which == 40){ //down
					if($("#search_autocomplete ul li.active").length < 1){ //not currently highlighted, start with first
						$("#search_autocomplete ul li:first").addClass("active");
					}
					else{ //one is highlighted, so move down
						//if last one, go to top
						if(($("#search_autocomplete ul li.active").index() + 1) == $("#search_autocomplete ul li").length){
							$("#search_autocomplete ul li.active").removeClass("active");
							$("#search_autocomplete ul li:first").addClass("active");
						}
						else{
							//else go down
							var index = $("#search_autocomplete ul li.active").index();
							$("#search_autocomplete ul li.active").removeClass("active");
							$("#search_autocomplete ul li:eq("+(index+1)+")").addClass("active");
						}
					}
				}
				else{ //up
					if($("#search_autocomplete ul li.active").length < 1){ //not currently highlighted, start with last
						$("#search_autocomplete ul li:last").addClass("active");
					}
					else{ //one is highlighted, so move up
						//if first one, go to bottom
						if($("#search_autocomplete ul li.active").index() == 0){
							$("#search_autocomplete ul li.active").removeClass("active");
							$("#search_autocomplete ul li:last").addClass("active");
						}
						else{
							//else go up
							var index = $("#search_autocomplete ul li.active").index();
							$("#search_autocomplete ul li.active").removeClass("active");
							$("#search_autocomplete ul li:eq("+(index-1)+")").addClass("active");
						}
					}
				}
		    }
		}
	});
});

function mediagallery(data){ 
	var link = $("a[data-media='"+data.requested+"']");

	$(link).attr("data-video_url", data.url);
	$(link).attr("data-video_width", data.width);
	$(link).attr("data-video_height", data.height);
	$(link).attr("data-video_title", data.title);
	$(link).attr("data-media_path", data.poster);
	$(link).attr("title", data.title);

	// var separator = (data.videodata.video_url.indexOf("?") > -1) ? "&" : "?";
	$(link).attr("href", "/common/util/mediagallery_overlay.php?play=1&url=" + encodeURIComponent(data.url) + "&subtitle=" + encodeURIComponent(data.title) + "&width="+data.width+"&height="+data.height+"&iframe=true");

}

function handleRAC(){
	$(".form_submit_hide").addClass("form_submit_hidden");
	$(".form_submit").show(); 
	
	$(".form_submit a").unbind("click").click(function(){
		if($(this).parent().parent().prev().find("form").length > 0){ //we use these buttons on thank you pages where we want them to link to a file/asset, and not a submit a form.
			var submit = true;
			// $(this).parent().parent().prev().find("form").submit();
			if($(this).parent().parent().prev().find("form").attr("action") == "https://now.eloqua.com/e/f2.aspx"){
				if(typeof formCheck != "undefined"){ //only call the validator function if it's available
					submit = formCheck();
					// console.log("formcheck called");
				}
				// if(typeof eloquaCheck != "undefined"){ //only call the validator function if it's available
				// 	submit = eloquaCheck();
				// 	// console.log("eloquaCheck called");
				// }
			}
			if(submit){
				// console.log("in submit");
				createCookie("novell_scr", $("input[name='email']").val(), 365);		
				$(this).parent().parent().prev().find("form").find('input[type=submit]').click();
			}
			return false;
		} else {
			//default action - prettyPhoto, simple anchor, etc.
		}
	});

	if($("#requestcall .phonecall").length){
		if($("#racpopup_content #requestcall h3").length)
			$("#racpopup_content #requestcall").find("h3").hide();
		else
			$("#racpopup_content #requestcall").prepend("<h3 style='border-top-left-radius: 5px; border-top-right-radius: 5px;'>"+$(".form_submit a").text()+"</h3>");
	}
	$("#racpopup_content .button_chat, #racpopup_content .phonecall").hide();
	$("#racpopup_content textarea").css({"margin-left":"6px", "width":"237px"});
	$("#racpopup_content fieldset").css({"padding":"0"});
	$("#racpopup_content p#disclaimer").css("overflow", "hidden");
	
}

$(document).ready(function(){
	if($("a.media_gallery").size() > 0) {
		$("a.media_gallery").each(function(){
			$.getJSON("http://www.novell.com/ContentUtilities/QueryDcr/"+$(this).attr("data-media")+".html?mediagallery=?");
		}).prettyPhoto({
			deeplinking: false,
			show_title: false,
			social_tools: '',
			changepicturecallback: function(){ 
				/* Called everytime an item is shown/changed */
			}, 
			callback: function(){ 
				/* Called when prettyPhoto is closed */
			}
		});
	}

	if(getQueryParm("video") != null){
		var video = getQueryParm("video");
		var video_selector = "";
		if(video == "true")
			video_selector = "a.media_gallery:first";
		else
			video_selector = "a[data-media='"+video+"']";
		setTimeout(function(){ $(video_selector).click(); }, 2000);	
	}
	
	handleRAC();
});
