/* PRIVATE Functions */
function isNN4(){
  if(!navigator.appName || !navigator.appVersion) return 0;
  return (navigator.appName=="Netscape" && navigator.appVersion.indexOf("4.")==0)
}

function isIE4(){
  if(document.all) return 1;
  return 0;
}

function isIE5(){
  return (isIE4() && document.getElementById);
}

/* PUBLIC Functions */
function checkSupportedBrowser() {
  if(isNN4()){/* location.href="/errors/unsupported.html" */ alert("Unsupported Browser");}
}

function NewWindow(mypage,myname,w,h,scroll) {
	var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	var settings = 'height='+h+',width='+w+',scrollbars='+scroll+',resizable';
	var win = window.open(mypage,myname,settings)
	if(win.window.focus) {
		win.window.focus();
	}
}

/* Avoid to receive junk-mail by catch with tools */
function getEmailAddress(server, name) {
	document.write(name + '@' + server);
}

/* ResizeImage Width or Height */
function resizeImage(sourceImg, maxWidth, maxHeight) {
	var image = new Image();   
	image.src = sourceImg.src;   
	if(image.width > 0  && image.height >0){   
		if (image.width / image.height >= maxWidth / maxHeight){   
			if (image.width >= maxWidth){     
				sourceImg.width = maxWidth;
				sourceImg.height = (image.height / image.width) * maxWidth;    
			}
		}   
		else {   
			if (image.height / image.width >= maxHeight / maxWidth) {
				sourceImg.height = maxHeight;
				sourceImg.width = (image.width / image.height) * maxHeight;
			}
		} 
	}
}

function HTMLEncode(html) { 
	var temp = document.createElement ("div"); 
	(temp.textContent != null) ? (temp.textContent = html) : (temp.innerText = html); 
	var output = temp.innerHTML; 
	temp = null; 
	return output; 
} 
function HTMLDecode(text) { 
	var temp = document.createElement("div"); 
	temp.innerHTML = text; 
	var output = temp.innerText || temp.textContent; 
	temp = null; 
	return output; 
}

String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.ltrim = function() {
	return this.replace(/(^\s*)/g, "");
}
String.prototype.rtrim = function() {
	return this.replace(/(\s*$)/g, "");
}

/* Get Parameter */
function getParameter(name){
	var paramStr = location.search;
	if (paramStr.length == 0) return null;
	if (paramStr.charAt(0) != '?') return null;
	paramStr = unescape(paramStr);
	paramStr = paramStr.substring(1);
	if (paramStr.length == 0) return null;
	var params = paramStr.split('&');
	var p = null;
	for (var i = 0; i < params.length; i++) {
		if (params[i].indexOf(name) >= 0) {          
			p = params[i].split('=');
			p = p[1];
		}
	}
	return p;
}

