if ( !$j && typeof( jQuery ) != 'undefined' )
   var $j = jQuery.noConflict();

var isOpera = (navigator.userAgent.indexOf('Opera') != -1);
var isIE = (!isOpera && navigator.userAgent.indexOf('MSIE') != -1)

if (!document.getElementById && document.all) { 
	document.getElementById = function(id)	{
		return document.all[id];
	}
}

var formCheck = new Array();
function ddFormCheckAll(val) {
	var editInsert = "";
	var ret = true;
	var str = typ = pat = "";
	
	if (formCheck[0] == undefined) {
		return true;
	}

	for (var j=0;j<formCheck[val].length;j++) {
		if (ret) {
			if (formCheck[val][j][0] && formCheck[val][j][0] != "") {
				str = document.getElementById(formCheck[val][j][0]).value;
			}
			typ = formCheck[val][j][1];
			pat = formCheck[val][j][2];
			reselect = true;
			refocus = true;

			if (typ == "cnumber" && str != "" && isNaN(str)) {
				ret = false;
			}

			if (typ == "cminl" && str != "" && str.length < pat) {
				ret = false;
			}

			if (typ == "cempty") {
				str2 = str;
				while ((str2.length>0) && (str2.substring(str2.length-1, str2.length) == " ")) {
					str2 = str2.substring(0, str2.length-1);
				}
				if (str2.length==0) {
					ret = false;
				}
			}

			if (typ == "cgpass") {
				if (str.length < 6) {
					ret = false;
				}

			}
			if (typ == "cguname") {
				if (!((new RegExp('^[a-zA-Z0-9]{'+pat+',}$')).test(str))) {
					ret = false;
				}
			}

			if (typ == "crepass") {
				if (str != document.getElementById(pat).value) {
					ret = false;
				}
			}

			if (typ == "crefield") {
				if (str != document.getElementById(pat).value) {
					ret = false;
				}
			}

			if (typ == "cselect" && pat==document.getElementById(formCheck[val][j][0]).options[document.getElementById(formCheck[val][j][0]).selectedIndex].value) {
				ret = false;
				reselect = false;
			}

			if (typ == "cselected" && document.getElementById(formCheck[val][j][0]).selectedIndex == -1) {
				ret = false;
				reselect = false;
			}

			//if (typ == "cradiogroupselected" && document.getElementById(formCheck[val][j][0]) == null) {
			//	ret = false;
			//	reselect = false;
			//}

			if (typ == "cemail") {
				if (str.length > 0 && (str.indexOf("@") < 0 || str.indexOf(".", str.length-5) < 0 || str.indexOf(" ") > 0)) {
					ret = false;
				}
			}
			if (typ == "curl") {
				if (str.length > 0 && (str.substring(0, 7) != "http://" || str.indexOf(".") < 0 || str.indexOf(" ") > 0)) {
					ret = false;
				}
			}

			if (typ == "ccompempt") {
				if (document.getElementById(pat).value == "") {
					ret = false;
				}
			}

			if (typ == "ceditinsert") {
				var editInsert = substitute(pat, "PRE", "document.getElementById");
				editInsert = eval(editInsert);
			}

			if (!ret) {
				alert(formCheck[val][j][3]);
				if (refocus) {
					document.getElementById(formCheck[val][j][0]).focus();
				}
				if (reselect) {
					document.getElementById(formCheck[val][j][0]).select();
				}
			}
		}
	}

	// Call insert if everything is a-OK
	if (ret) {
		if (editInsert != "" && opener) {
			insertAtCaret(opener.document.form0.text, editInsert);
		}
	}

	return ret;
}

function ddFormConfDel(txt) {
	return confirm(txt);
}

function checkCompareEmpty(form, id, txt) {
	if (document.getElementById(""+id).value == "") {
		alert(txt);
		document.getElementById(""+id).focus();
		return false;
	}
	else {
		return true;
	}
}

function goUrl(url) {
	location.href=url;
}

function parsemenuMouseOver(id, templsrc1, templsrc2, lang, on) {
	if (lang != "") {
		lang = lang + "-";
	}
	if (document.getElementById) {
		document.getElementById(id).src = templsrc1+"/siteimage/"+lang+templsrc2+"-"+on+".gif";
	}
}

function showHelp(hid, spid, tid, uid) {
	window.open("help.php?hid="+hid+"&spid="+spid+"&tid="+tid+"&uid="+uid+"&nbc=1", "Help", "resizable=no, scrollbars=yes, toolbar=no, location=no, directories=no, status=no, menubar=no, width=450, height=400, top=5, left=5")
}

function closeWindow() {
	window.close();
}

// Open window for choosing data
function openChoiceWindow(pid) {
	open(pid, "choicewindow","resizable=yes, toolbar=no, location=no, directories=no, menubar=no, scrollbar=yes, status=yes, width=450,height=400,top=20,left=20");
}

// Text edit; store caret for later insert. From Martin Honnen (Martin.Honnen@t-online.de)
function storeCaret(id) {
	if (id.createTextRange) {
		id.currRange = document.selection.createRange().duplicate();
	}
}
// Text edit
function setCaretToEnd(id) {
	if (id.createTextRange) {
		var v = id.value;
		var r = id.createTextRange();
		r.moveStart('character', v.length);
		r.select();
	}
}
// Insert at end of text if UA doesnt support inserting at arbitrary position
function insertAtEnd(id, str) {
	id.value += str;
	setCaretToEnd(id);
}
// Insert text at caret position and close window
function insertAtCaret(id, str) {
	if (id.currRange) {
		id.currRange.text =
			id.currRange.text.charAt(id.currRange.text.length - 1) != ' ' ? str : str + ' ';
		id.currRange.select();
	}
	else {
		insertAtEnd(id, str);
	}
	window.close();
}


// Substitute text. From Daniel LaLiberte (liberte@ncsa.uiuc.edu)
function substitute(string, match, replacement) {
	// Within STRING, replace any MATCHing string with the REPLACEMENT.
	var result = '';
	var index = 0;
	var lastIndex = index;
	while (string.length > lastIndex) {
		index = string.indexOf(match, lastIndex);
		if (index == -1) {
			break;
		}
		result += string.substring(lastIndex, index) + replacement;
		lastIndex = index + match.length;
	}
	result += string.substring(lastIndex, string.length);
	return result;
}

// Open window for displaying zoomed image
function openZoomImage(lnk,w,h) {
	// Add these values to the image size to get window size
	var wAdder = 30;
	var hAdder = 40;
	var windowparam = "resizable=no,toolbar=no,location=no,directories=no,menubar=no,scrollbar=no,status=no,width="+(w+wAdder)+",height="+(h+hAdder)+",top=20,left=20";
	var zoomwinvar = window.open(lnk, "zoomwin", windowparam);
   zoomwinvar.focus();
}

// Open window for displaying stripped popupped pages 
function openStrippedPopup(lnk,w,h) {
	//var pTop = event.screenY;
	//alert(pTop);
	// Add these values to the image size to get window size
	var wAdder = 20;
	var hAdder = 40;
	var windowparam = "resizable=yes,toolbar=no,location=no,scrollbars=yes,menubar=no,status=no,directories=no,width="+(w+wAdder)+",height="+(h+hAdder)+",top=20,left=20";
	var imwin = window.open(lnk, "popwin", windowparam);
   imwin.focus();
}

// Open window for prining
function openPrint(lnk) {
	open(lnk, "printwindow");
}

// Toggle block
function toggleBlockDisplay(idgroup, idnum) {
	var tab = document.getElementById(idgroup+idnum);
	var dStyle = "block";
	if (tab.style.display == dStyle || tab.style.display == "") {
		tab.style.display = "none";		
	}
	else {
		tab.style.display = dStyle;
	}
}

// Toggle block group
function toggleBlockGroup(idgroup, idnum, idheadgroup) {
	var saveclasson = saveclassoff = null;
	for (var i=0;i<20;i++) {
		cur = document.getElementById(idgroup+i);
		if (cur) {
			curhead = document.getElementById(idheadgroup+i);
			if (cur.style.display == "block") {
				saveclasson = curhead.className;
			}
			else {
				saveclassoff = curhead.className;
			}
		}
	}
	for (var i=0;i<20;i++) {
		if (document.getElementById(idgroup+i)) {
			cur = document.getElementById(idgroup+i);
			curhead = document.getElementById(idheadgroup+i);
			cur.style.display = "none";
			curhead.className = saveclassoff;
		}
	}
	document.getElementById(idgroup+idnum).style.display = "block";
	document.getElementById(idheadgroup+idnum).className = saveclasson;
}

