var winDlg;

function ConfirmSubmit(msg)
{
	if ( confirm(msg) == true)
		return true;
	else
		return false;
}

function CheckReqField(txtObj, msg)
{
	if(	document.getElementById(txtObj).value == "" )
	{
		alert(msg);
		document.getElementById(txtObj).focus();
		return false;
	}
	else
		return true;
}

function CheckNumber(txtObj, msg)
{
	if( msg == "")
		msg = "Please write numeric value only";
		
	if(	isNaN(document.getElementById(txtObj).value) == true)
	{
		alert(msg);
		document.getElementById(txtObj).value = "";
		document.getElementById(txtObj).focus();
		return false;
	}
	else
		return true;
}

function EventCheckReqField(txtObj,  msg)
{
	if( !CheckReqField(txtObj, msg) ) return false;
}

function CheckMaxLength(txtObj, max, msg)
{
	if(	document.getElementById(txtObj).value.length > max )
	{
		alert(msg);
		document.getElementById(txtObj).focus();
		return false;
	}
	else
		return true;
}

function CheckMinLength(txtObj, min, msg)
{
	if(	document.getElementById(txtObj).value.length < min )
	{
		alert(msg);
		document.getElementById(txtObj).focus();
		return false;
	}
	else
		return true;
}

function CheckRegEx(txtObj, regEx, msg)
{
	if(	regEx.test(document.getElementById(txtObj).value) == false)
	{
		alert(msg);
		document.getElementById(txtObj).select();
		document.getElementById(txtObj).focus();
		return false;
	}
	else
		return true;
}

function CheckEmailEx(txtObj, msg)
{
	if( msg == "")
		msg = "Please write right email format";
	
	if( CheckRegEx(txtObj, /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/, msg) ) 
		return true;
	else
		return false;
}


function OpenWindow(w, h, url, menubar)
{
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h)/2 : 0;

	winDlg = window.open(
		url,
		"",
		"width=" + w + ", " +
		"height=" + h + ", " +
		"left=" + LeftPosition + ", " +
		"top=" + TopPosition + ", " + 
		"menubar=" + menubar + ", resizable=1, scrollbars=1"
	);
	winDlg.focus();
}

function IsAlphanumeric(txtObj) {
	txtObj = document.getElementById(txtObj);
	var alphaCount=0
	var numCount=0
	var upass_string = txtObj.value;

 	var num_valid="123456789";

	for (var i=0; i<upass_string.length; i++) {
		if (num_valid.indexOf(upass_string.charAt(i)) < 0) {
			numCount++
		}
	}

	if(numCount==upass_string.length) {
		txtObj.focus();
		alert("Your password contains only characters.\nPlease enter an alphanumeric value like 'alpha1'");
		return false;
	}

	var	alph_valid="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"

	for (var i=0; i<upass_string.length; i++) {
		if (alph_valid.indexOf(upass_string.charAt(i)) < 0) {
			alphaCount++
		}
	}

	if(alphaCount==upass_string.length) {
		txtObj.focus();
		alert("Your password contains only numbers.\nPlease enter an alphanumeric value like 'alpha1'");
		return false;
	}

	return true;
}

