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 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, mode){
	var element=document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : "";
	if(mode == undefined){
		if(element.style.display == 'none'){
			element.style.display = '';
		} else {element.style.display = 'none';}
	}else{
		//if mode supplied, true = show, false = hide:
		element.style.display = (mode) ? '' : 'none';
	}
}

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


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


function addElement(_parent, _type, _childname, _content) {
	var parent = (_parent == null) ? document.body : document.getElementById(_parent);
	var newdiv = document.createElement(_type);
	newdiv.setAttribute('id', _childname);
	newdiv.innerHTML = _content;
	parent.appendChild(newdiv);
}
function removeElement(_element) {
	var element = document.getElementById(_element);
	element.parentNode.removeChild(element);
}


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(){
	var xmlHttp;
	try{
		//Firefox, Opera 8.0+, Safari
		xmlHttp = new XMLHttpRequest();
	}catch (e){
		//IE
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e){
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}

	return xmlHttp;
// 	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;
}
/* ###################### */
