function openPopup(theURL, theName, Width, Height)
{
	var strValue;
	var intLeft = parseInt((screen.width - Width) / 2);
	var intTop = parseInt((screen.height - Height) / 2);
	strValue = window.open(theURL, theName, 'help:no,width=' + Width + ',height=' + Height + ',left=' + intLeft + ',top=' + intTop);
	return strValue;
}

function openPopup1(theURL, theName, Width, Height)
{
	var intLeft = parseInt((screen.width - Width) / 2);
	var intTop = parseInt((screen.height - Height) / 2);
	window.open(theURL, theName, 'help:no,width=' + Width + ',height=' + Height + ',left=' + intLeft + ',top=' + intTop + ',scrollbars=yes');
}

function openDialog(theURL, theName, Width, Height)
{
	var strValue;
	var strAppName = navigator.appName;
	var intLeft = parseInt((screen.width - Width) / 2);
	var intTop = parseInt((screen.height - Height) / 2);
	if(strAppName == 'Microsoft Internet Explorer')
		strValue = window.showModalDialog(theURL, theName, 'help:no;dialogHeight:' + Height + 'px;dialogWidth:' + Width + 'px;dialogLeft:' + intLeft + ';dialogTop:' + intTop + ';scrollbars=no;')
	else
		window.open(theURL, theName, 'help:no,width=' + Width + ',height=' + Height + ',left=' + intLeft + ',top=' + intTop);
	return strValue;
}

function CloseWindow(theForm)
{
	if(navigator.appName == 'Microsoft Internet Explorer')
	{
		if(CloseWindow.arguments.length == 2)
			window.returnValue = CloseWindow.arguments[1];
		else
			window.returnValue = 1;
		window.close();
	}
	else
	{
		eval(theForm).target = opener.name;
		eval(theForm).submit();
		window.close();
	}
}

function replaceAll(entry, before, after)
{
	out = before; // replace this
	add = after; // with this
	temp = "" + entry; // temporary holder

	while (temp.indexOf(out)>-1)
	{
		pos= temp.indexOf(out);
		temp = "" + (temp.substring(0, pos) + add + 
		temp.substring((pos + out.length), temp.length));
	}
	return temp;
}

function countCharacter(str, chr){
	var i, count = 0;
	for(i = 0; i < str.length; i++){
		if(str.charAt(i) == chr)
			count++;
	}
	if(count == 1 || count == 0)
		return true;
	else
		return false;
}

function isCurrency(str){
	if(str.length == 0)
		return false;
	if(!isNumberCurrency(str))
		return false;
	if(!countCharacter(str, '.'))
		return false;
		
	return true;
}

function isNumberCurrency(s){
	var i, isnum = true, len = s.length
	for(i = 0; i < len; i++){
		if(!isDigitCurrency(s.charAt(i)))
			isnum = false;
	}
	return isnum;
}

function isDigitCurrency(c){
	if((c=='0')||(c=='1')||(c=='2')||(c=='3')||(c=='4')||(c=='5')||(c=='6')||(c=='7')||(c=='8')||(c=='9')||(c=='.')||(c==','))
		return true;
	else
		return false;
}

function hoursOnly(e, obj){
	//check IE or FF
	var strAppName = navigator.appName;
	var key = (strAppName=='Microsoft Internet Explorer') ? event.keyCode : e.which;
	if(key > 47 && key < 58 || key==8 || key==32 || key==0 || key==44 || key==46)
		obj.value = obj.value;
	else
	{
		if (strAppName == 'Microsoft Internet Explorer')
			window.event.returnValue = null;
		else
			e.preventDefault();
	}
}
function defaultNumber(object){
	//check IE or FF
	var strCompare;
	var iLenght;
	
	if(typeof(object)!="undefined")
	{
		strCompare = eval(object).value;
		iLenght = strCompare.indexOf(".");
		if(iLenght != -1)
		{
			if(iLenght == 0)
			{
				strCompare = "0" + strCompare;
			}
		}
		else
		{
			iLenght = strCompare.indexOf(",");
			if(iLenght != -1)
			{
				if(iLenght == 0)
				{
					strCompare = "0" + strCompare;
				}
			}
		}
	}
	
	eval(object).value = strCompare;
}
function isNumber(s){
	var i, isnum = true, len = s.length
	for(i = 0; i < len; i++){
		if(!isDigit(s.charAt(i)))
			isnum = false;
	}
	return isnum;
}

function isNumberLenZero(s){
	var i, isnum = true, len = s.length
	for(i = 0; i < len; i++){
		if(!isDigit(s.charAt(i)))
			isnum = false;
	}
	return isnum;
}
function isDigit(c){
	if((c=='0')||(c=='1')||(c=='2')||(c=='3')||(c=='4')||(c=='5')||(c=='6')||(c=='7')||(c=='8')||(c=='9'))
		return true;
	else
		return false;
}

function isWeek(s){
	var i, isnum = true, len = s.length
	for(i = 0; i < len; i++){
		if(!isDigitWeek(s.charAt(i)))
			isnum = false;
	}
	return isnum;
}

function isDigitTime(c){
	if((c=='0')||(c=='1')||(c=='2')||(c=='3')||(c=='4')||(c=='5')||(c=='6')||(c=='7')||(c=='8')||(c=='9')||(c==':'))
		return true;
	else
		return false;
}

function countTimeChar(str, chr){
	var i, count = 0;
	for(i = 0; i < str.length; i++){
		if(str.charAt(i) == chr)
			count++;
	}
	if(count == 1)
		return true;
	else
		return false;
}

function isNumberTime(s){
	var i, isnum = true, len = s.length
	for(i = 0; i < len; i++){
		if(!isDigitTime(s.charAt(i)))
			isnum = false;
	}
	return isnum;
}

function isTime(s){
	var len = s.length
	
	if(len != 5 && len != 4)
		return false;
	if(!isNumberTime(s))
		return false;
	if(s.indexOf(':')==-1) 
		return false;
	if(s.indexOf(':')!=1 && s.indexOf(':')!=2)
		return false;
	if(!countTimeChar(s,':'))
		return false;
		
	return true;
}

function isDigitWeek(c){
	if((c=='1')||(c=='2')||(c=='3')||(c=='4')||(c=='5')||(c=='6')||(c=='7'))
		return true;
	else
		return false;
}

function trimLeft(s){
	var i;
	i = 0;
	var n;
	n = s.length;
	while((i<n)&&(s.charAt(i)==' ')) i++;
		s = s.substring(i);
	return(s);
} 

function trimRight(s){
	var n;
	n = s.length;
	var i;
	i = s.length-1;
	while((i>=0)&&(s.charAt(i)==' ')) i--;
		s = s.substring(0,i+1);
	return(s);
}

function trimAll(s){
	s = trimLeft(s);
	s = trimRight(s);
	return(s);
}  

//verify phone format (###) ###-#### with "#" is number digit
/*function isPhoneNumber(s){
	if(s.length != 14)	return false;
	if(parseInt(s.indexOf(' ')) != 5) return false;
	if(parseInt(s.indexOf('(')) != 0) return false;
	if(parseInt(s.indexOf(')')) != 4) return false;
	if(parseInt(s.indexOf('-')) != 9) return false;
	if(!isNumber(s.substring(1,4))) return false;
	if(!isNumber(s.substring(6,9))) return false;
	if(!isNumber(s.substring(10,14))) return false;
	return true;
}*/

//verify phone format: besides number digit or characters 
//follow: '(', ')', '-', ' '
function isPhoneNumber(s){
	var i;
	if(s.length == 0) return false;
	for(i = 0; i <= s.length-1; i++){
		if(!isDigit(s.charAt(i)) && s.charAt(i) != '(' && s.charAt(i) != ')' && s.charAt(i) != '-' && s.charAt(i) != ' ')
			return false;
	}
	return true;
}

function isEmail(emailStr){
	var emailPat = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	var matchArray = emailStr.match(emailPat);
	
	if (matchArray == null)
	{
		return (false);
	}

	return (true);
}

function isDate(dateStr) {
    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{2,4})$/;
    var matchArray = dateStr.match(datePat); // is the format ok?

    if (matchArray == null) {
        //alert("You must input date format mm/dd/yyyy"); //or dd-mm-yy
        return false;
    }

    month = matchArray[3]; // parse date into variables
    day = matchArray[1];
    year = matchArray[5];

    if (day < 1 || day > 31) {
        //alert("Day must from 1 to 31.");
        return false;
    }

    if (month < 1 || month > 12) { // check month range
        //alert("Month must from 1 to 12.");
        return false;
    }

    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
        //alert("This month have no 31 day!")
        return false;
    }

	if(year.length == 2)
		if(year < 20)
			year = parseInt('20' + year);
		else
			year = parseInt('19' + year);
	
    if (month == 2) { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day==29 && !isleap)) {
            //alert("Month 2nd " + year + " have no " + day + " day!");
            return false;
        }
    }
 
    if(year < 1900)
		return false;
    return true; // date is valid
}

function isDate2(dateStr) {
    var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{2,4})$/;
    var matchArray = dateStr.match(datePat); // is the format ok?

    if (matchArray == null) {
        //alert("You must input date format mm/dd/yyyy"); //or dd-mm-yy
        return false;
    }

    month = matchArray[1]; // parse date into variables
    day = matchArray[3];
    year = matchArray[5];

    if (day < 1 || day > 31) {
        //alert("Day must from 1 to 31.");
        return false;
    }

    if (month < 1 || month > 12) { // check month range
        //alert("Month must from 1 to 12.");
        return false;
    }

    if ((month==4 || month==6 || month==9 || month==11) && day==31) {
        //alert("This month have no 31 day!")
        return false;
    }

	if(year.length == 2)
		if(year < 20)
			year = parseInt('20' + year);
		else
			year = parseInt('19' + year);
	
    if (month == 2) { // check for february 29th
        var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
        if (day > 29 || (day==29 && !isleap)) {
            //alert("Month 2nd " + year + " have no " + day + " day!");
            return false;
        }
    }
 
    if(year < 1900)
		return false;
    return true; // date is valid
}
function isEmail(emailStr)
{
	var emailPat = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
	var matchArray = emailStr.match(emailPat);
	if (matchArray == null)
	{
		return (false);
	}

	return (true);
}

function GoPageMaster(iPage,iTotalPages)
{
    if(Number(iTotalPages) == 1)
        return false;
    if(iPage != "" && !isNaN(iPage))
    {
        if(Number(iTotalPages) == 1)
            return false;
        if(document.getElementById('hidPaging'))
        {
            if(Number(iPage) < 1)
                document.getElementById('hidPaging').value = 1;
            else if(Number(iPage) > Number(iTotalPages))
                document.getElementById('hidPaging').value = iTotalPages;
            else
                document.getElementById('hidPaging').value = iPage;
        }  
    }
    else
        return false;        
}