function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function popUpWin(url, w, h, s){
	width = w; height = h;

	var str = "height=" + height + ",innerHeight=" + height;
	str += ",width=" + width + ",innerWidth=" + width;
	if(window.screen){
		var ah = screen.availHeight - 30;
		var aw = screen.availWidth - 10;

		var xc = (aw - width) / 2;
		var yc = (ah - height) / 2;

		str += ",left=" + xc + ",screenX=" + xc;
		str += ",top=" + yc + ",screenY=" + yc;
		if(s == false){
			str += ",location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no";
		}else{
			str += ",location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no";
		}
	}
	window.open(url, 'win1', str);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_reloadPage(init) {  //Updated by PVII. Reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
	//define variables; variable passed by link are dumped into array called a:
	var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
	if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function navRollOver(obj, state) {
	document.getElementById(obj).className = (state == 'on') ? 'nav-highlight' : 'nav';
}

function getObject(id){
	return document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : "";
}

function toggle(id){
	var element=document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : "";
	if(element.style.display == 'none'){
		element.style.display = '';
	} else {element.style.display = 'none';}
}

// function appear(id){
// 	var element=document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : "";
// 	element.style.display = '';
// }
function appear(){
	for(var i=0; i<arguments.length; i++){
		document.getElementById(arguments[i]).style.display = '';
	}
}

// function hide(id){
// 	var element=document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : "";
// 	element.style.display = 'none';
// }

function hide(){
	for(var i=0; i<arguments.length; i++){
		document.getElementById(arguments[i]).style.display = 'none';
	}
}

function sc_color(id, clr){
	var element=document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : "";
	element.style.backgroundColor = '#'+clr;
}

function setColor(id, clr){
	var element=document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : "";
	element.style.color = '#'+clr;
}

function changeHeight(id, h){
	var element=document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : "";
	element.style.height = h+'px';
}

// name = name of the cookie
// value = value of the cookie
function setCookie(name, value, expires) {
	var curCookie = name + "=" + escape(value);
	//expires must be a date, i.e.:
	//var today = new Date();
	//var expires = new Date(today.getTime() + (560 * 864000000));
	if(expires){curCookie = curCookie + ";expires=" + expires.toGMTString();}
	else{curCookie = curCookie + ";expires=";}
	curCookie = curCookie + ";path=/";
	document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
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));
}

// name - name of the cookie
function deleteCookie(name) {
	if (getCookie(name)) {
		document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
} 

function setTxt(id, content){
	var tipobj=document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : "";
	tipobj.innerHTML = content;
}
//to avoid confusion:
function setText(id, content){
	setTxt(id, content);
}

function hiLite(id, color){
	var element=document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : "";
	element.style.color = color;
}

function hiLiteBG(id, color){
	var element=document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : "";
	element.style.backgroundColor = color;
}
function hiLiteRow(id, className){
	var element=document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : "";
	element.className = className;
}

function taLimit(obj) {
	var maxlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : "";
	if(obj.value.length > maxlength){
		return false;
	}
}
function taCount(obj, visCnt) {
	var maxlength = obj.getAttribute ? parseInt(obj.getAttribute("maxlength")) : "";
	if(obj.value.length > maxlength){
		obj.value = obj.value.substring(0, maxlength);
	}
	document.getElementById(visCnt).innerHTML = maxlength - obj.value.length;
}

/*
string trim ( string str [, string charlist] )
This function returns a string with whitespace stripped from the end of string.
Without the second parameter, trim() will strip these characters:

" " an ordinary space.

"\t" a tab.

"\n" a new line (line feed).

"\r" a carriage return.

You can also specify the characters you want to strip, by means of the charlist parameter. Simply list all characters that you want to be stripped.

var text = "\t\tThese are a few words :) ...  ";
trimmed = trim(text);
// trimmed = "\t\tThese are a few words :) ..."
var trimmed = trim(text, " \t.");
// trimmed = "\t\tThese are a few words :)"
*/
function trim(string, chars) {
	if (typeof (string) != 'string') {
		return ('');
	}
	if (typeof (chars) != 'string') {
		var stripArray = new Array(" ", "\t", "\n", "\r");
	} else {
		var stripArray = chars.split("");
	}
	var sArray = string.split('');
	//function to cycle through characters to be stripped:
	var cycle = function () {
		for (var i = 0; i<sArray.length; i++) {
			for (var j = 0; j<stripArray.length; j++) {
				if (sArray[i] == stripArray[j]) {
					sArray[i] = '';
				}
			}
			if (sArray[i]) {
				break;
			}
		}
	};
	cycle();
	sArray.reverse();
	cycle();
	sArray.reverse();
	return (sArray.join(''));
}

//remove duplicate data from an array:
Array.prototype.removeDuplicate = function(){
	var array4 = new Array;
	for(var i=0; i<this.length; i++){
		var xx = true;
		for(var j=i+1; j<this.length; j++){
			if(this[i] == this[j]){
				xx = false;
			}
		}	
		if(xx == true){
			array4.push(this[i]);
		}
	}
	return array4;
}

function urldecode( str ) {
    // Decodes URL-encoded string
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_urldecode/
    // +       version: 809.1713
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urldecode('Kevin+van+Zonneveld%21');
    // *     returns 1: 'Kevin van Zonneveld!'
    // *     example 2: urldecode('http%3A%2F%2Fkevin.vanzonneveld.net%2F');
    // *     returns 2: 'http://kevin.vanzonneveld.net/'
    // *     example 3: urldecode('http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a');
    // *     returns 3: 'http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a'
    
    var histogram = {}, histogram_r = {}, code = 0, str_tmp = [];
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urlencode.
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    
    for (replace in histogram) {
        search = histogram[replace]; // Switch order when decoding
        ret = replacer(search, replace, ret) // Custom replace. No regexing   
    }
    
    // End with decodeURIComponent, which most resembles PHP's encoding functions
    ret = decodeURIComponent(ret);

    return ret;
}

function urlencode( str ) {
    // URL-encodes string
    // 
    // +    discuss at: http://kevin.vanzonneveld.net/techblog/article/javascript_equivalent_for_phps_urlencode/
    // +       version: 809.1713
    // +   original by: Philip Peterson
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: AJ
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // %          note: info on what encoding functions to use from: http://xkr.us/articles/javascript/encode-compare/
    // *     example 1: urlencode('Kevin van Zonneveld!');
    // *     returns 1: 'Kevin+van+Zonneveld%21'
    // *     example 2: urlencode('http://kevin.vanzonneveld.net/');
    // *     returns 2: 'http%3A%2F%2Fkevin.vanzonneveld.net%2F'
    // *     example 3: urlencode('http://www.google.nl/search?q=php.js&ie=utf-8&oe=utf-8&aq=t&rls=com.ubuntu:en-US:unofficial&client=firefox-a');
    // *     returns 3: 'http%3A%2F%2Fwww.google.nl%2Fsearch%3Fq%3Dphp.js%26ie%3Dutf-8%26oe%3Dutf-8%26aq%3Dt%26rls%3Dcom.ubuntu%3Aen-US%3Aunofficial%26client%3Dfirefox-a'
                                     
    var histogram = {}, histogram_r = {}, code = 0, tmp_arr = [];
    var ret = str.toString();
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The histogram is identical to the one in urldecode.
    histogram['!']   = '%21';
    histogram['%20'] = '+';
    
    // Begin with encodeURIComponent, which most resembles PHP's encoding functions
    ret = encodeURIComponent(ret);
    
    for (search in histogram) {
        replace = histogram[search];
        ret = replacer(search, replace, ret) // Custom replace. No regexing
    }
    
    // Uppercase for full PHP compatibility
    return ret.replace(/(\%([a-z0-9]{2}))/g, function(full, m1, m2) {
        return "%"+m2.toUpperCase();
    });
    
    return ret;
}

function textCounter(field, cntfield, maxlimit) {
	if (field.value.length > maxlimit){
		//if too long, trim it:
		field.value = field.value.substring(0, maxlimit);
	}else{
		//otherwise, update 'characters left' counter:
		cntfield.value = maxlimit - field.value.length;
	}
}

function setTextCounter(field, cntfield, maxlimit){
	field.onkeyup = field.onkeydown = function(){
		textCounter(field, cntfield, maxlimit);
	}
	textCounter(field, cntfield, maxlimit);
}

function toggleAlertBox(windowname, overlayname) {
	var alertbox = document.getElementById(windowname);
	var overlay = document.getElementById(overlayname);
	var viewportwidth;
	var viewportheight;
	var window_width;
	var window_height;
	var overlay_height;

	alertbox.style.display = ( alertbox.style.display == 'none' ) ? 'block' :'none';
	overlay.style.display = ( overlay.style.display == 'none' ) ? 'block' :'none';

	if(alertbox.style.display == 'none'){
		return;
	}

	if (typeof window.innerWidth != 'undefined') {
		viewportwidth = window.innerWidth;
		viewportheight = window.innerHeight;
	} else {
		viewportwidth = document.documentElement.clientWidth;
		viewportheight = document.documentElement.clientHeight;
	}

	if ((viewportheight > document.body.parentNode.scrollHeight) && (viewportheight > document.body.parentNode.clientHeight)) {
		overlay_height = viewportheight;
		window_width = viewportwidth;
		window_height = viewportheight;
	} else {
		if (document.body.parentNode.clientHeight > document.body.parentNode.scrollHeight) {
			overlay_height = document.body.parentNode.clientHeight;
			window_width = document.body.parentNode.clientWidth;
			window_height = document.body.parentNode.clientHeight;
		} else {
			overlay_height = document.body.parentNode.scrollHeight;
			window_width = document.body.parentNode.scrollWidth;
			window_height = document.body.parentNode.clientHeight;
		}
	}
	overlay.style.height = overlay_height + 'px';

	alertbox.style.left = (window_width/2 - alertbox.offsetWidth/2) + 'px';
	alertbox.style.top = (window_height/2 - alertbox.offsetHeight/2) + 'px';
}

/* AJAX HELPER FUNCTIONS */
function GetXmlHttpObject(){
	if (window.XMLHttpRequest){
		// code for IE7+, Firefox, Chrome, Opera, Safari
		return new XMLHttpRequest();
	}
	if (window.ActiveXObject){
		// code for IE6, IE5
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	return null;
}

function DisplayError(){
	alert ("Your browser does not support AJAX!");
}
/* ###################### */
