
var debugError = true;
window.onerror = catchError;
function catchError(msg, url, lno) {
	try {
		if ( debugError ) {
			var msgErr = '';
			msgErr += 'Error in file: ' + url + '\n';
			msgErr += 'Line number: ' + lno + '\n';
			msgErr += 'Message: ' + msg;
			alert(msgErr);
		}
	} catch (e) { }
	return true;
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function openWindow(Url, winWidth, winHeight, winName, winFeature) {
	var winWidth=(winWidth>screen.width)?screen.width:winWidth;
	var winHeight=(winHeight>screen.height)?screen.height:winHeight;

	var winTop = (screen.height-winHeight)/2;
	var winLeft = (screen.width-winWidth)/2;

	if (winName == undefined) winName = '';
	if (winFeature == undefined) winFeature = 'top='+winTop+', left='+winLeft+', toolbar=no, location=no, directories=no, scrollbars=yes, status=no, resizable=yes, width='+winWidth+', height='+winHeight;

	newWindow = window.open(Url, winName, winFeature);
	newWindow.focus();
}

function zoomImage(imgName, imgWidth, imgHeight) {
//imgWindow = window.open(imgName, 'ZoomImage', 'top=0, left=0, toolbar=no, location=no, directories=no, scrollbars=yes, status=no, resizable=yes');
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=\""+imgName+"\" 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();

	imgWindow = window.open("", 'ZoomImage', 'top='+windowX+', left='+windowY+', toolbar=no, location=no, directories=no, status=no, resizable=no, width='+winWidth+', height='+winHeight+'');
	imgWindow.blur();
	window.focus()
	//imgWindow.resizeTo(winWidth, winHeight);
	//newWindow.moveTo(windowX, windowY);
	imgWindow.document.open();
	imgWindow.document.write(Html);
	imgWindow.document.close();
	imgWindow.focus()

}


/* Function String */
function getTextValue ( frmName, srcListName ) {
	var form = eval( 'document.' + frmName );
	var srcInput = eval( 'form.' + srcListName );
	if ( Trim(srcInput.value) != '') {
		return srcInput.value;
	} else {
		return null;
	}
}

function getSelectedOption( frmName, srcListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	i = srcList.selectedIndex;
	if (i != null && i > -1) {
		return srcList.options[i];
	} else {
		return null;
	}
}

function setSelectedValue( frmName, srcListName, value ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	var srcLen = srcList.length;

	for (var i=0; i < srcLen; i++) {
		srcList.options[i].selected = false;
		if (srcList.options[i].value == value) {
			srcList.options[i].selected = true;
		}
	}
}

function getSelectedRadio( frmName, srcGroupName ) {
	var form = eval( 'document.' + frmName );
	var srcGroup = eval( 'form.' + srcGroupName );

	if (srcGroup[0]) {
		for (var i=0, n=srcGroup.length; i < n; i++) {
			if (srcGroup[i].checked) {
				return srcGroup[i].value;
			}
		}
	} else {
		if (srcGroup.checked) {
			return srcGroup.value;
		} // if the one button is checked, return zero
	}
	// if we get to this point, no radio button is selected
	return null;
}

function getSelectedValue( frmName, srcListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	i = srcList.selectedIndex;
	if (i != null && i > -1) {
		return srcList.options[i].value;
	} else {
		return null;
	}
}

function getSelectedText( frmName, srcListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	i = srcList.selectedIndex;
	if (i != null && i > -1) {
		return srcList.options[i].text;
	} else {
		return null;
	}
}

function Trim(str){
	return str.replace(/^\s+|\s+$/g, ''); 
}

// 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))
	return true;
else
	return false;
}

function validateEmail( strValue) {
	var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
	var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;

	if (strValue == "") {
		return false;
	} else if (!emailFilter.test(strValue)) { //test email for illegal characters
		return false;
	} else if (strValue.match(illegalChars)) {
		return false;
	} else {
		return true;
	}
}

function ActionLogin( frmName ) {
	try {
		if ( getTextValue( frmName, 'Username') == null ) {
			eval( 'document.' + frmName + '.Username.focus();' );
		} else {
			return true;
		}
	} catch (e) { }
	return false;
}

function ActionUpload( frmName ) {
	try {
		if ( getTextValue( frmName, 'Filename') == null ) {
			eval( 'document.' + frmName + '.Filename.focus();' );
		} else {
			return true;
		}
	} catch (e) { }
	return false;
}

