
function errMsg(msg){

	   alert("Please enter valid"+" "+msg);
//	   alert("\u8BF7\u8F93\u5165\u6709\u6548"+" "+msg);

}
function isValidKeyField(chkField){
		var val=chkField.value;
		var code;
		for (i=0; i<val.length; i++) {
			code=val.charCodeAt(i);
//			if(!((code>=65 && code <=91) ||(code>=97 && code <=122) || (code>=48 && code <=57) || code==35 || code==46))
			// space = 32 , single quots 39
			if((code==32) || (code==39))
				return false;
		}//for
		return true;
} 

function isValidAlphaNumeric(chkField){
		var val=chkField.value;
		var code;
		for (i=0; i<val.length; i++) {
			code=val.charCodeAt(i);
//			if(!((code>=65 && code <=91) ||(code>=97 && code <=122) || (code>=48 && code <=57) || code==35 || code==46 || code==64 || code==45 || code==32))
			if((code==39))
				return false;
		}//for
		return true;
}

function isAlphabets(chkField){
		var val=chkField.value;
		var code;
		for (i=0; i<val.length; i++) {
			code=val.charCodeAt(i);
//			if(!((code>=65 && code <=90) ||(code>=97 && code <=122) || code==32))
			if((code==39))
				return false;
		}//for
		return true;
}

function isValidNumber(chkField){ 
		if(isNaN(chkField.value))
			return false;
		if(eval(chkField.value)<0)
			return false;
	}
function isValidPercentage(chkField){
		if(isNaN(chkField.value))
			return false;
		if(eval(chkField.value)<0 || eval(chkField.value) > 100 )
			return false;
	}

function isValidCustId(chkField){
		var val=chkField.value;
		var code;
		var firstChar=val.charCodeAt(0);
		if(!((firstChar>=65 && firstChar <=90) ||(firstChar>=97 && firstChar <=122)))		
		{
			return false;
		}
		for (i=1; i<val.length; i++) {
			code=val.charCodeAt(i);
//			if(!((code>=65 && code <=91) ||(code>=97 && code <=122) || (code>=48 && code <=57) || code==35 || code==46 || code==64 || code==45 || code==32))
			if((code==39)) 
				return false;
		}//for
		return true;
}
function DatePosition(dateString) {

/* function to check whether the passed date is < or == or >
       if -1 means behind, 0 means equal, 1 means ahead
*/

    var now = new Date();
    var today = new Date(now.getYear(),now.getMonth(),now.getDate());
    var date = new Date(parseInt(dateString.substring(0,4)),
                            parseInt(dateString.substring(5,7)-1),
                            dateString.substring(8,10));

    if (date < today)
    {
        return -1;
    }
    else if (date > today)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}

function compareDate(str1,str2){
   // var str1=chkField1.value;
	//var str2=chkField2.value;
	var bufArray = str1.split("-");
	var startDateYear = bufArray[0];
	var startDateMonth = bufArray[1];
      var startDateDay = bufArray[2];
	var startDate=new Date(startDateYear,startDateMonth,startDateDay);
      var bufArray1 = str2.split("-");
      var endDateYear = bufArray1[0];
      var endDateMonth = bufArray1[1];
      var endDateDay = bufArray1[2];
      var endDate=new Date(endDateYear,endDateMonth,endDateDay);
    if(startDate > endDate)
      return false;
    }


function isValidEmail(chkField) {
	/* 1.1.4: Fixed a bug where upper ASCII characters (i.e. accented letters
	international characters) were allowed.

	1.1.3: Added the restriction to only accept addresses ending in two
	letters (interpreted to be a country code) or one of the known
	TLDs (com, net, org, edu, int, mil, gov, arpa), including the
	new ones (biz, aero, name, coop, info, pro, museum).  One can
	easily update the list (if ICANN adds even more TLDs in the
	future) by updating the knownDomsPat variable near the
	top of the function.  Also, I added a variable at the top
	of the function that determines whether or not TLDs should be
	checked at all.  This is good if you are using this function
	internally (i.e. intranet site) where hostnames don't have to
	conform to W3C standards and thus internal organization e-mail
	addresses don't have to either.
	Changed some of the logic so that the function will work properly
	with Netscape 6.

	1.1.2: Fixed a bug where trailing . in e-mail address was passing
	(the bug is actually in the weak regexp engine of the browser; I
	simplified the regexps to make it work).

	1.1.1: Removed restriction that countries must be preceded by a domain,
	so abc@host.uk is now legal.  However, there's still the
	restriction that an address must end in a two or three letter
	word.

	1.1: Rewrote most of the function to conform more closely to RFC 822.

	1.0: Original  */
	// -->

	/* The following variable tells the rest of the function whether or not
	to verify that the address ends in a two-letter country or well-known
	TLD.  1 means check it, 0 means don't. */
	var emailStr=chkField.value;
	var checkTLD=1;

	/* The following is the list of known TLDs that an e-mail address must end with. */

	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

	/* The following pattern is used to check if the entered e-mail address
	fits the user@domain format.  It also is used to separate the username
	from the domain. */

	var emailPat=/^(.+)@(.+)$/;

	/* The following string represents the pattern for matching all special
	characters.  We don't want to allow special characters in the address.
	These characters include ( ) < > @ , ; : \ " . [ ] */

	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

	/* The following string represents the range of characters allowed in a
	username or domainname.  It really states which chars aren't allowed.*/

	var validChars="\[^\\s" + specialChars + "\]";

	/* The following pattern applies if the "user" is a quoted string (in
	which case, there are no rules about which characters are allowed
	and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	is a legal e-mail address. */

	var quotedUser="(\"[^\"]*\")";

	/* The following pattern applies for domains that are IP addresses,
	rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	e-mail address. NOTE: The square brackets are required. */

	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

	/* The following string represents an atom (basically a series of non-special characters.) */

	var atom=validChars + '+';

	/* The following string represents one word in the typical username.
	For example, in john.doe@somewhere.com, john and doe are words.
	Basically, a word is either an atom or quoted string. */ 

	var word="(" + atom + "|" + quotedUser + ")";

	// The following pattern describes the structure of the user

	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

	/* The following pattern describes the structure of a normal symbolic
	domain, as opposed to ipDomainPat, shown above. */

	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

	/* Finally, let's start trying to figure out if the supplied address is valid. */

	/* Begin with the coarse pattern to simply break up user@domain into
	different pieces that are easy to analyze. */

	var matchArray=emailStr.match(emailPat);

	if (matchArray==null) {

	/* Too many/few @'s or something; basically, this address doesn't
	even fit the general mould of a valid e-mail address. */
	//alert("Please Enter Valid Email Address");
	//alert("Email address seems incorrect (check @ and .'s)");
	//alert("\u7535\u5b50\u90ae\u4ef6\u9519\u8bef (\u6838\u5bf9 '@' \u548c '.')");
	return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	// Start by checking that only basic ASCII characters are in the strings (0-127).

	for (i=0; i<user.length; i++) {
	if (user.charCodeAt(i)>127) {
	//alert("Invalid Username");
	//alert("\u65e0\u6548\u7684\u7528\u6237\u4ee3\u7801");
	return false;
	   }
	}
	for (i=0; i<domain.length; i++) {
	if (domain.charCodeAt(i)>127) {
	//alert("Ths domain name contains invalid characters.");
	//alert("\u65e0\u90ae\u4ef6\u670d\u52a1\u5668\u4e0d\u5b58\u5728.");
	return false;
	   }
	}

	// See if "user" is valid

	if (user.match(userPat)==null) {

	// user is not valid

	//alert("Invalid Username");
	//alert("\u65e0\u6548\u7684\u7528\u6237\u4ee3\u7801");
	return false;
	}

	/* if the e-mail address is at an IP address (as opposed to a symbolic
	host name) make sure the IP address is valid. */

	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {

	// this is an IP address

	for (var i=1;i<=4;i++) {
	if (IPArray[i]>255) {
	//alert("Destination IP address is invalid!");
	//alert("\u65e0\u6548\u7684\u88ab\u53eb IP \u5730\u5740!");
	return false;
	   }
	}
	return true;
	}

	// Domain is symbolic name.  Check if it's valid.

	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++) {
	if (domArr[i].search(atomPat)==-1) {
	//alert("The domain name does not seem to be valid.");
	//alert("\u65e0\u90ae\u4ef6\u670d\u52a1\u5668\u4e0d\u5b58\u5728.");
	return false;
	   }
	}

	/* domain name seems valid, but now make sure that it ends in a
	known top-level domain (like com, edu, gov) or a two-letter word,
	representing country (uk, nl), and that there's a hostname preceding
	the domain or country. */

	if (checkTLD && domArr[domArr.length-1].length!=2 &&
	domArr[domArr.length-1].search(knownDomsPat)==-1) {
	//alert("The address must end in a well-known domain or two letter " + "country.");
	//alert("\u90ae\u4ef6\u670d\u52a1\u5668\u5fc5\u987b\u662f\u516c\u5171\u57df\u540d");
	return false;
	}
	// Make sure there's a host name preceding the domain.

	if (len<2) {
	//alert("This address is missing a hostname!");
	//alert("\u6b64\u57df\u540d\u65e0\u6548!");
	return false;
	}
	// If we've gotten this far, everything's valid!
	return true;
}

function isValidSearch(){
	if((window.event && window.event.keyCode == 13) || window.event.keyCode==0 ){
		if(document.form1.sItem.value==0){
			alert("Please select the Search Item ");
			return false;
		}
		if((document.form1.sVal.value == null) || (document.form1.sVal.value.length==0) || (document.form1.sVal.value=='MM-DD-YYYY')){
			alert(" Please enter Search value ");
			return false;
		}
		return true;
	}
}

function confirmSubmit(){
	var agree=confirm("Are you sure you wish to continue?");
	if (agree)
		return true ;
	else
		return false ;
}
function confirmDelete(){
	var agree=confirm("Are you sure you wish to delete?");
	if (agree)
		return true ;
	else
		return false ;
}

function daysBetween(str1, str2) {

	var bufArray = str1.split("-");
	var startDateYear = bufArray[0];
	var startDateMonth = bufArray[1];
    var startDateDay = bufArray[2];
	var startDate=new Date(startDateYear,startDateMonth,startDateDay);
    var bufArray1 = str2.split("-");
    var endDateYear = bufArray1[0];
    var endDateMonth = bufArray1[1];
    var endDateDay = bufArray1[2];
    var endDate=new Date(endDateYear,endDateMonth,endDateDay);

    // The number of milliseconds in one day
    var ONE_DAY = 1000 * 60 * 60 * 24

    // Convert both dates to milliseconds
    var date1_ms = startDate.getTime()
    var date2_ms = endDate.getTime()

    // Calculate the difference in milliseconds
    var difference_ms = Math.abs(date1_ms - date2_ms)

    // Convert back to days and return
    return Math.round(difference_ms/ONE_DAY)

}
function isValidIP(ip) {
    if (ip.search(/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) != -1) {
        var myArray = ip.split(/\./);
        if (myArray[0] > 255 || myArray[1] > 255 || myArray[2] > 255 || myArray[3] > 255)
            return false;
        if (myArray[0] == 0 && myArray[1] == 0 && myArray[2] == 0 && myArray[3] == 0)
            return false;
        return true;
    }
    else
        return false;
}

// new function for lookup
function showLookup(obj,value) //v3.0
{
	var url=path+"CommonLookup.jsp?id="+value+"&obj="+obj;
	WinObj = window.open(url,"lookup","width=670,height=300,toolbar=no,status=no,scrollbars=yes");
}


