


function inet_open_win() {
	if (ua["dom"]) {
		var url = "";
		var target = "";

		var attributes = "";


		if (arguments.length > 0) {
			url = arguments[0];
		}

		//Target attribute:
		if (arguments.length > 1) {
			target = arguments[1];
		}
			
		//Optional attributes:
		if (arguments.length > 2) {
			width = 0;
			height = 0;
			center = false;

			tmp = arguments[2];
			tmp_a = tmp.split(",");
			tmp = ""
			for (i = 0; i < tmp_a.length; i++) {
				val_a = tmp_a[i].split("=");
				if (val_a.length == 2) {
					if (i > 0) tmp += ",";

					if (val_a[0] == "width") width = val_a[1]
					else if (val_a[0] == "height") height = val_a[1]

					tmp += val_a[0]+"="+val_a[1];
				
				}
				else if (val_a.length > 0) {
					switch(val_a[0]) {
						case "center" :
							center = true;
							break;
					}
				}
			}
			if (center) {
				x_pos = (screen.width - width) / 2;
				y_pos = (screen.height - height) / 2;

				if (tmp.length > 0) tmp += ",";
				tmp += "left="+x_pos+",top="+y_pos
			}
			attributes = tmp;
		}
	
		win = window.open(url, target, attributes);
		win.focus();
		return false;
	}
}

	
function inet_pop_win(pageToLoad, winName, width, height, center, ramme) {
	xposition=0; yposition=0;
	if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
		xposition = (screen.width - width) / 2;
		yposition = (screen.height - height) / 2;
		}
	width = width + ramme * 2
	args = "width=" + width + "," 
	+ "height=" + height + "," 
	+ "location=0," 
	+ "menubar=0,"
	+ "resizable=0,"
	+ "scrollbars=0,"
	+ "status=0," 
	+ "titlebar=0,"
	+ "toolbar=0,"
	+ "hotkeys=0,"
	+ "left=" + xposition + ","
	+ "top=" + yposition;

	window.open(pageToLoad, winName, args);
}

function inet_print() {
	if (!ua["iemac"]){// && !ua["safari"]) {
		window.print();
	}
	return false;
}

/* Does the element <elm> have the className <cname>? */
function hasClassName(elm, cname) {
	if (ua["dom"]) {
		if (elm != null) {
			if (elm.className != null) {
				aCname = elm.className.split(" ");
				for (j=0; j<aCname.length; j++) {
					if (aCname[j] == cname) return true;
				}
			}
		}
	}
	return false;
}


/* Add the className <cname> to element <obj> */
function addClassName(obj, cname) {
	if (obj) {
		if (!hasClassName(obj, cname)) {
			obj.className += (obj.className.length > 0 ? " "+cname : cname);
		}
	}
}

/* Remove the className <cname> from element <obj> */
function removeClassName(obj, cname) {
	if (obj) {
		var res = "";
		var aCname = obj.className.split(" ");

		for (var i = 0; i < aCname.length; i++) {
			res += (aCname[i] == cname ? "" : " "+aCname[i]);
		}
		res = res.trim();
		obj.className = res;
	}					
}


/* Extends String objects with a trim function */
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g, "");
}

/* Check if the string is an email address - simple, incomplete test */
function isEmail(s) {
	var rx = /^[a-z0-9\-_\.]*[a-z0-9\-_]@([a-z0-9\-\.])+\.[a-z]{2,4}$/i;
	return s.match(rx);
}


/* Add a function to run when document is loaded */
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != "function") {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}




/**************************/
/**** COOKIE FUNCTIONS ****/

var cookie_domain = window.location.hostname;

function createCookie(name, value, days) {
	if (days) {
			var date = new Date();
			date.setTime(date.getTime()+(days*24*60*60*1000));
			var expires = "; expires=" + date.toGMTString();
	}
	else var expires = "";

	value = escape(value);

	document.cookie = name + "=" + value + expires + ";domain=" + cookie_domain + ";path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(";");
	for (var i=0; i<ca.length; i++) {
		var c = ca[i];
		while (c.charAt(0)==" ") c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

/**** COOKIE FUNCTIONS ****/
/**************************/


/**********************************/
/**** DYNAMIC STYLE SHEET LOAD ****/

var fontsizeCookieId = "fontsize";

function loadFontSizeCSS(obj) {
	if (ua["dom"]) {
		var loc = window.location;
		var cssTitle = "fontsize";
		var cssOn = "/site/css/inet_fontsize_on.css";
		var cssOff = "/site/css/inet_fontsize_off.css";
		var cssHref = "";
		var mode = 0;

		if (!ua["iemac"] && !ua["safari"]) {

			var aStyleSheets = document.styleSheets;
			var oStyleSheet = null;
			for (var i = 0; i < aStyleSheets.length; i++) {
				if (aStyleSheets[i].title == cssTitle) {
					oStyleSheet = aStyleSheets[i];
					i = aStyleSheets.length;
				}
			}
			
			if (oStyleSheet != null) {
				var rootUrl = loc.protocol +"//"+ loc.host;
				cssHref = oStyleSheet.href.replace(rootUrl, "");
				if (cssHref == cssOff) {
					cssHref = cssOn;
					mode = 1;
				}
				else {
					cssHref = cssOff;
					mode = 0;
				}
				
				if (ua["iewin"]) { //IE/Win only:
					oStyleSheet.href = cssHref;
				}
				else {
					var aLink = document.getElementsByTagName("link");
					var oLink = null;
					for (var i = 0; i < aLink.length; i++) {
						if (aLink[i].type == "text/css") {
							if (aLink[i].title == cssTitle) {
								oLink = aLink[i];
								i = aLink.length;
							}
						}
					}
					if (oLink != null) {
						oLink.parentNode.removeChild(oLink);
					}
	
				}

			}
			
			
			if (!ua["iewin"]) {
				var oLink = document.createElement("link");
				oLink.setAttribute("type", "text/css");
				oLink.setAttribute("rel", "stylesheet");
				oLink.setAttribute("media", "screen, projection");
				oLink.setAttribute("title", cssTitle);
				oLink.setAttribute("href", cssHref);

				var oHead = document.getElementsByTagName("head")[0];
				oHead.appendChild(oLink);				
			}

			//Change link text:
			/*
			obj.innerHTML = (mode == 1 ? "" : "");
			obj.blur();
			*/


			var cv = readCookie(fontsizeCookieId);
			if (cv) {
				eraseCookie(fontsizeCookieId);
			}
			createCookie(fontsizeCookieId, mode, 365);

			return false;
		}



		else { //IE MAC
			var mode = 0;
			var cv = readCookie(fontsizeCookieId);
			mode = ((cv == "0" || cv == null) ? 1 : 0);
			eraseCookie(fontsizeCookieId);
			createCookie(fontsizeCookieId, mode, 365);
			

			var params = loc.search;
			var paramsArr = null;
			if (params.length > 0) {
				params = params.substr(1, params.length - 1);
			}
			if (params.length > 0) {
				paramsArr = params.split("&");
			}

			var paramsStr = "";
			var txtStr = "fontsize=1";
			if (paramsArr != null) {
				for (var i = 0; i < paramsArr.length; i++) {
					if (paramsArr[i] != txtStr) {
						paramsStr += (paramsStr.length > 0 ? "&" : "") + paramsArr[i];
					}
				}				
			}

			var url = loc.protocol +"//"+ loc.host + loc.pathname + (paramsStr == "" ? "" : "?" + paramsStr);
			obj.href = url;

			return true;
		}
	}
}

/**** DYNAMIC STYLE SHEET LOAD ****/
/**********************************/



/*****************/
/**** SUBMENU ****/

function toggleMenuLink(obj) {
	if (ua["dom"]) {
		var oParent = obj.parentNode;

		if (hasClassName(oParent, "closed")) {
			addClassName(oParent, "open");
			removeClassName(oParent, "closed");
		}
		else if (hasClassName(oParent, "open")) {
			addClassName(oParent, "closed");
			removeClassName(oParent, "open");
		}
	}
	return false;
}

/**** SUBMENU ****/
/*****************/



/***********************/
/**** LANGUAGE MENU ****/

function toggleLanguageMenu() {
	if (ua["dom"]) {
		
		var oCLang = document.getElementById("currentLanguage");
		var oLbl = document.getElementById("langlbl");
		var oRoot = document.getElementById("langroot");
		var oOptions = document.getElementById("languageOptions");

		if ((oCLang != null) && (oLbl != null) && (oRoot != null) && (oOptions != null)) {

			var b = (oOptions.style.display == "block" ? "none" : "block");

			var lpos = findPos(oCLang);
			var rpos = findPos(oRoot);
			oOptions.style.width = oCLang.offsetWidth - oLbl.offsetWidth + "px";
			oOptions.style.left = rpos[0] - lpos[0] - 1 +"px";
			oOptions.style.top = oRoot.offsetHeight +"px";
			oOptions.style.display = b;
		}
	}
	return false;
}



/**** LANGUAGE MENU ****/
/***********************/




function imgThumb(src, w, h, t, aid, aw, ah) {
	this.src = src;
	this.w = w;
	this.h = h;
	this.t = t.replace(/\n/g, "<br />");
	this.aid = aid;
	this.aw = aw;
	this.ah = ah;
}



function toggleImgThumb(id) {
	var oI = imgThumbs[id];
	if (oI != null) {
		var oBigThumb = document.getElementById("bigThumb");
		var oBigThumbTxt = document.getElementById("bigThumbTxt");

		var oImg = new Image();
		oImg.src = oI.src;

		var waitObj = new waitForIt();
		waitObj.waitFor = function() {
			return oImg.complete;
		}

		waitObj.whenDone = function() {
			oBigThumb.src = oI.src;
			oBigThumb.width = oI.w;
			oBigThumb.height = oI.h;

			var oA = oBigThumb.parentNode;
			oA.href = "/site/utils/imgpop.asp?ass_id="+ oI.aid;
			oA.onclick = function() {
				return inet_open_win(this.href, 'img', 'width='+ oI.aw +',height='+ oI.ah +',center');
			}

			oBigThumbTxt.innerHTML = oI.t;
			oBigThumbTxt.style.display = (oI.t != "" ? "block" : "none");

		}
	

		waitObj.run();
	

	}
	return false;
}


function checkProjectField(val) {
	if (ua["dom"]) {
		var aInput = document.getElementsByTagName("INPUT");
		var oInput = null;
		var oDefInput = null;
		var rx = /^IDFormE\d+/;
		var v = "_PROJECT";
		for (var i = 0; i < aInput.length; i++) {
			if (aInput[i].type == "text") {
				if (aInput[i].name.match(rx)) {
					if (aInput[i].value == v) {
						oInput = aInput[i];
						break;
					}
				}
			}
		}
		if (oInput != null) {
			oInput.value = val;
			oDefInput = oInput.form.elements.namedItem(oInput.id + "Default");
			if (oDefInput) {
				oDefInput.value = val;
			}
		}
	}	
}


