var a_errorfields = new Array();
function highlight_errors(pa_errors) {
	if (pa_errors) {
		a_errorfields = pa_errors;
	}
	if (a_errorfields.length == 0) {
		return;
	}
	
	for (var i=0; i < a_errorfields.length; i++) {
		document.getElementById("c_" + a_errorfields[i]).className = "error_container";
	}	
	document.getElementById(a_errorfields[0]).focus();
}

function f_syncFields(ps_source, ps_target) {
	if (!ps_source && !ps_target) {
		return;
	}
	
	oSource = document.getElementById(ps_source);
	oTarget = document.getElementById(ps_target);
	
	if (oTarget.value == "") {	
		if (oSource && oTarget) {
			oTarget.value = oSource.value;
		}
	}
}

function c_browser() {
	var type = null;
	var os = null;
	var dom = null;
	var ie4 = null;
	var ns4 = null;
	var detect = null;
	this.check = function() {
		this.detect = navigator.userAgent.toLowerCase();
		this.dom = (document.getElementById)? true : false;
		this.ie4 = (document.all)? true : false;
		this.ns4 = (document.layers)? true : false;
		this.fnCheck();
	};
	this.fnCheck = function() {
		if (this.fnCheckIt('konqueror')) {
			this.type = "Konqueror";
			this.os = "Linux";
		}
		else if (this.fnCheckIt('safari')) this.type = "safari"
		else if (this.fnCheckIt('omniweb')) this.type = "omniweb"
		else if (this.fnCheckIt('opera')) this.type = "opera"
		else if (this.fnCheckIt('webtv')) this.type = "webtv";
		else if (this.fnCheckIt('icab')) this.type = "icab"
		else if (this.fnCheckIt('msie')) this.type = "internet_explorer"
		else if (this.fnCheckIt('firefox')) this.type = "firefox"
		else if (this.fnCheckIt('netscape')) this.type = "netscape_navigator"
		else if (!this.fnCheckIt('compatible')) {
			this.type = "netscape_navigator"
		} else 
			this.type = "unknown";
		
		if (this.fnCheckIt('linux')) this.os = "linux";
		else if (this.fnCheckIt('x11')) this.os = "unix";
		else if (this.fnCheckIt('mac')) this.os = "mac"
		else if (this.fnCheckIt('win')) this.os = "windows"
		else this.os = "unknown";
	};
	this.fnCheckIt = function(psString) {
		return this.detect.indexOf(psString) + 1;
	};
}
var browser = new c_browser();
browser.check();

function $(psId) {
	return fnGetElement(psId);
}

function fnGetElement(psId) {
	if (!psId) {
		return;
	}
	var oId = 0;
	if (browser.dom) {
		oId = document.getElementById(psId);
	} else if (browser.ie4) {
		oId = document.all[psId];
	} else if (browser.ns4) {
		oId = document.layers[psId];
	}
	return oId;
}

function fnToggleOn(psId) {
	var oId = fnGetElement(psId);
	oId.style.display = 'block';
}

function fnToggleOff(psId) {
	var oId = fnGetElement(psId);
	oId.style.display = 'none';
}

function fnToggleState(psId) {
	var oID = fnGetElement(psId);
	if (oID.style.display == 'none') {
		return 'hidden';
	} else if (oID.style.display == 'block') {
		return 'visible';
	} else {
		return 'unknown';
	}
}

function fnToggle(psEl) {
	if (fnToggleState(psEl) == 'hidden') {
		fnToggleOn(psEl);
	} else {
		fnToggleOff(psEl);
	}
}

function fnHideHidden() {
	var oEl = document.getElementsByTagName("INPUT");
	
	var el = null;
	for(var i = 0; i < oEl.length; i++) {
		el = oEl[i];
		if (el.type.toLowerCase() == 'hidden') {
			el.style.visibility = 'hidden';
			el.style.display = 'none';
		}
	}	
}

function isNum(sText) {
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
	
	
	for (i = 0; i < sText.length && IsNumber == true; i++) { 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;
}

function toggleClass(psEl, psTestEl, psClassOn, psClassOff) {
	el = $(psEl);
	if (fnToggleState(psTestEl) == 'hidden') {
		el.className = psClassOn;
	} else {
		el.className = psClassOff;
	}
}

function newwindow(psURL, pnWidth, pnHeight) {
	window.open(psURL, "_blank",'width=' + pnWidth + ',height=' + pnHeight);
}

