
function openWindow(Url, winWidth, winHeight, winName) { 
var winl = (screen.width-winWidth)/2;
var wint = (screen.height-winHeight)/2;

	newWindow = window.open(Url, winName, 'top='+wint+', left='+winl+', toolbar=no, location=no, directories=no, scrollbars=yes, status=no, resizable=yes, width='+winWidth+', height='+winHeight+'');
	newWindow.focus();

}

function openImage(Url, imgWidth, imgHeight, winName) {
var winWidth=(imgWidth>screen.width)?screen.width:imgWidth;
var winHeight=(imgHeight>screen.height)?screen.height:imgHeight;

var windowX = (screen.height-winHeight)/2;
var windowY = (screen.width-winWidth)/2;
var Html=""+
"<html>"+
"<head>"+
"<title>Zoom Image</title>"+
"</head>"+
"<body style=\"margin: 0px 0px 0px 0px; overflow:auto;\">"+
"<img src=\""+Url+"\" width=\""+imgWidth+"\" height=\""+imgHeight+"\" border=\"0\" alt=\"\">"+
"</body>"+
"</html>"
	//newWindow = window.open(Url, winName, 'top='+wint+', left='+winl+', toolbar=no, location=no, directories=no, scrollbars=yes, status=no, resizable=yes, width='+winWidth+', height='+winHeight+'');
	//newWindow.focus();

	newWindow = window.open("", winName, 'top='+windowX+', left='+windowY+', menubar=no, toolbar=no, location=no, directories=yes, status=yes, resizable=yes, scrollbars=yes, width='+winWidth+', height='+winHeight+'');
	newWindow.blur();
	window.focus()
	newWindow.resizeTo(winWidth, winHeight);
	//newWindow.moveTo(windowX, windowY);
	newWindow.document.open();
	newWindow.document.write(Html);
	newWindow.document.close();
	newWindow.focus()
}

function ChangeClass(Mode, ElementName){
	var css=(Mode=='on')?'postFocus':'post';
	document.getElementById(ElementName).className=css;
}

function Trim(str){
	return RTrim(LTrim(str));
}

function LTrim(str) {
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(0)) != -1) {
		var j=0, i = s.length;
		while (j < i && whitespace.indexOf(s.charAt(j)) != -1) j++;
		s = s.substring(j, i);
	}
	return s;
}


function RTrim(str) {
	var whitespace = new String(" \t\n\r");
	var s = new String(str);
	if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
		var i = s.length - 1; // Get length of string
		while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1) i--;
		s = s.substring(0, i+1);
	}
	return s;
}

// onKeyPress="return KeyDigit(this.value, event);"
function KeyDigit(str, e) {
var keycode;
if (window.event)
	keycode = window.event.keyCode;
else if (e)
	keycode = e.which;
else
	return true;

if (((keycode>47) && (keycode<58) )  || (keycode==8) || (str.length>=9)) 
	return true;
else
	return false;

}

function replace(string, text, by) {
// Replaces text with by in string
	var strLength = string.length, txtLength = text.length;
	if ((strLength == 0) || (txtLength == 0)) return string;

	var i = string.indexOf(text);
	if ((!i) && (text != string.substring(0,txtLength))) return string;
	if (i == -1) return string;

	var newstr = string.substring(0,i) + by;

	if (i+txtLength < strLength)
		newstr += replace(string.substring(i+txtLength,strLength),text,by);

	return newstr;
}

function EmailValid(Email) {

var goodEmail = Email.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);

	if (goodEmail){
		return true;
	} else {
		return false
	}
}

function checkSelect(objName, Total) {
	for(i=0; i< Total; i++) {
		if(document.getElementById(objName+i)) {
			if(document.getElementById(objName+i).checked == true) return true;
		}
	}
	return false;

}

function winOpenAdj(url, widthb, heightb, toolb, menub, scrollb, resizeb, statusb){
	var h = heightb;
	var w = widthb;
	var t = toolb
	var m = menub
	var sc = scrollb
	var r = resizeb
	var st= statusb
	
	
		
	var LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	var TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
	var settings = 'height=' + h + ',width=' + w + ',top=' + (TopPosition-50) + ',left=' + LeftPosition + ',toolbar=' + t + ', menubar=' + m + ', scrollbars=' + sc + ', resizable=' + r + ', status=' + st + ''
			
	var rtnVal = window.open(url, '', settings)

}