var i
var txt
function isFilled(txb) {

	txt=txb.value
	if (txt!='')
		for (i=0;i<txt.length;i++) {
			if (txt.charAt(i)!=' ') 
				return true
		}
	txb.focus()
	txb.select()
	alert(jsReq)	//This field is required.
	return false
}
function noQuotes(txb) {
	txt=txb.value
	if ((txt.indexOf("'")==-1) && (txt.indexOf('"')==-1))
		return true
	txb.focus()
	txb.select()
	alert(jsNoQuotes)		//This field must not contain quotes.
	return false
}

function isNum(txb) {
	if (txb.value=='')
		return true
	if (isNaN(Number(txb.value))) {
		txb.focus()
		txb.select()
		alert(jsNbrChk)		//This field must be a number
		return false
	}
	return true
}

var reDate= new RegExp("^(\\d+)\\W(\\d+)\\W(\\d+)(.+)?$","g")
var reNum= new RegExp("\\d+","g")
var yr,mn,dy
var tmp
	
           	
function ChkEmail(txt) {
	var i, atPos, periodPos
	
    if (txt != "") {
   
		invalidChars = " /:,;"
       
		for (i=0; i<invalidChars.length; i++)	{
			badChar = invalidChars.charAt(i)
			if (txt.indexOf(badChar,0) != -1) {
				alert(txt + " - Invalid Characters in Email field")
				return false
            }
		}

		if ( (txt.indexOf('@@',0)!=-1) || (txt.indexOf('..',0)!=-1)) {
		    alert(txt + " - Invalid Email Address")
			return false             
		}
              
		atPos = txt.indexOf("@",1)
		if (atPos == -1) {
		    alert(txt + " - Invalid Email Address")
			return false             
		}
       
		if (txt.indexOf("@",atPos+1) != -1) {
			alert(txt + " - Invalid Email Address, More Than one '@' found")
			return false
        }
		
		periodPos = txt.indexOf(".",atPos)
		if (periodPos == -1) {
			alert(txt + " - Invalid Email Address")
			return false
        }
                   
		if (periodPos+3 > txt.length) {
			alert(txt + " - Invalid Email Address")
			return false
        }                                
	}
    return true
}

function isEmail(txb)
{
  var txt = txb.value
  
  if (ChkEmail(txt))
	return true
  else {
	txb.focus()
	return false	
  }                    
}

  
 
function isSepDate (year, month, day)
{   // catch invalid years (not 2- or 4-digit) and invalid months and days.
    if (! (isMonth(month, false) && isDay(day, false))) return false;

    // Explicitly change type to integer to make code work in both
    // JavaScript 1.1 and JavaScript 1.2.
    var intYear = parseInt(year);
    var intMonth = parseInt(month);
    var intDay = parseInt(day);

    // catch invalid days, except for February
    if (intDay > daysInMonth[intMonth]) return false; 

    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;

    return true;
}


function isRemDate(txb) {
	if (isNaN(Date.parse(txb.value)))  {
		txb.focus()
		txb.select()
		alert(jsDateChk)	//"This field must be a valid date in the form of: MM/DD/YY  For example, the date June 9, 2000 would be entered as 6/9/00 or 6/9/2000.")
		return false
	}
	return true
}

//the following function are used for the date validations 12/07 satya

function isDateTemp(txb)
{
	if (isNaN(Date.parse(txb.value)))
	{
		txb.focus()
		txb.select()
		alert(jsDateChk)	//"This field must be a valid date in the form of: MM/DD/YY  For example, the date June 9, 1999 would be entered as 6/9/99 or 6/9/1999.")
		return false
	}
	else
	return true
}

function isDate(txb) 
{
	var Rawdate=dojsTrim(String(txb.value).replace(/-/gi,'/'));
	if (!isNaN(Date.parse(Rawdate)))
	{
		/*  commented by jon on 3/26/04 (shouldn't focus if not wrong...)
		txb.focus()
		txb.select()
		*/
		var array = Rawdate.split("/")
		if (isDate1 (array[2],array[0], array[1]))	return true;
	}

	txb.focus()
	txb.select()
	alert(jsDateChk)	//"This field must be a valid date in the form of: MM/DD/YY  For example, the date June 9, 1999 would be entered as 6/9/99 or 6/9/1999.")
	return false;
}

function isDate1 (year, month, day)
{   
    if (! (isYear(year, false) && isMonth(month, false) && isDay(day, false))) return false;
    //09/28/05 - parseInt stops at the first numeric val in the string!...parseInt('09') returns 0!!!
    var intYear = Number(year);		//	parseInt(year);
    var intMonth = Number(month);	//parseInt(month);
    var intDay = Number(day);		//parseInt(day);
		
    if (intDay > daysInMonth[intMonth]) return false; 
	
    if ((intMonth == 2) && (intDay > daysInFebruary(intYear))) return false;
	return true;
}

//hh:mm:ss	(hh can be 12 not 13)
function isTime1 (hh, mm, ss)
{   
    if (isNaN(hh) || isNaN(mm) || isNaN(ss)) return false
    
    var inthh = parseInt(hh);
    var intmm = parseInt(mm);
    var intss = parseInt(ss);
    
    if (inthh > 12 || inthh < 0) return false; 

    if (intmm > 59 || intmm < 0) return false;
    
    if (intss > 59 || intss < 0) return false;

    return true;
}

//if forced then validates datetime format: mm/dd/yy hh:mm:ss (am/pm)
//else also accepts mm/dd/yy
function chkDateTime(str, forced) {
	var ary = String(str).split(" ")

	if (ary.length !=3 && forced) return false
	var ary1, ary2
	var Rawdate = ary[0]
	
	ary1 = Rawdate.split("/")
	
	if (!isDate1 (ary1[2], ary1[0], ary1[1])) {
		return false
	}else if (!forced && ary.length == 1)		//simple mm/dd/yy and no time part
		return true
	
	ary2 = String(ary[1]).split(":")
	if (!isTime1(ary2[0], ary2[1], ary2[2])) {
		return false
	}
	
	if ((String(ary[2]).toLowerCase() != "am") && (String(ary[2]).toLowerCase() != "pm")) {
		return false
	}
		
	return true
}

//forced=true : datetime format is strictly checked.
//forced=false: simple mm/dd/yy will also be accepted
function isDateTime(txb, forced) {
	txb.value = dojsTrim(txb.value)

	if (!chkDateTime(txb.value, forced)) {
		txb.focus()
		txb.select()
		alert(jsDateChk)	//This field must be a valid date in the form of: MM/DD/YY hh:mm:ss (AM/PM). Example: 06/19/1999 10:55:45 AM.")
		return false
	}else
		return true
}

function dojsTrim(str) {
   var ch = str.substring(str.length-1, str.length);
   
   while (ch == " ") {			// Check for spaces at the end of the string
      str = str.substring(0, str.length-1);
      ch = str.substring(str.length-1, str.length);
   }
   return str
}


function makeArray(n) {
   for (var i = 1; i <= n; i++) {
      this[i] = 0
   } 
   return this
}

function nDaysInMonth(mo,yr) {
	return (mo==2) ? daysInFebruary(yr) : daysInMonth[mo];
}

var daysInMonth = makeArray(12);
daysInMonth[1] = 31;
daysInMonth[2] = 29;   
daysInMonth[3] = 31;
daysInMonth[4] = 30;
daysInMonth[5] = 31;
daysInMonth[6] = 30;
daysInMonth[7] = 31;
daysInMonth[8] = 31;
daysInMonth[9] = 30;
daysInMonth[10] = 31;
daysInMonth[11] = 30;
daysInMonth[12] = 31;

var defaultEmptyOK = false
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isIntegerInRange (s, a, b)
{   if (isEmpty(s)) 
       if (isIntegerInRange.arguments.length == 1) return defaultEmptyOK;
       else return (isIntegerInRange.arguments[1] == true);

    // Now, explicitly change the type to integer via parseInt
    // so that the comparison code below will work both on 
    // JavaScript 1.2 (which typechecks in equality comparisons)
    // and JavaScript 1.1 and before (which doesn't).
    if (s == "08")
		s = 8
	if (s == "09")
		s = 9
    var num = parseInt(s);
    //var num = s
    return ((num >= a) && (num <= b));
}

function daysInFebruary (year)
{   
    return (  ((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0) ) ) ? 29 : 28 );
}

function isNonnegativeInteger (s)
{   var secondArg = defaultEmptyOK;

    if (isNonnegativeInteger.arguments.length > 1)
        secondArg = isNonnegativeInteger.arguments[1];
    return (isSignedInteger(s, secondArg)
         && ( (isEmpty(s) && secondArg)  || (parseInt (s) >= 0) ) );
}

function isSignedInteger (s)
{   if (isEmpty(s)) 
       if (isSignedInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isSignedInteger.arguments[1] == true);

    else {
        var startPos = 0;
        var secondArg = defaultEmptyOK;
        if (isSignedInteger.arguments.length > 1)
            secondArg = isSignedInteger.arguments[1];
        if ( (s.charAt(0) == "-") || (s.charAt(0) == "+") )
           startPos = 1;    
        return (isInteger(s.substring(startPos, s.length), secondArg))
    }
}

function isInteger (s)
{   var i;
    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
		  if (!isDigit(c)) return false;
    }
    return true;
}

function isDigit (c)
{   
	return ((c >= "0") && (c <= "9"))
}

function isYear (s)
{   
	if (isEmpty(s)) 
       if (isYear.arguments.length == 1) return defaultEmptyOK;
       else return (isYear.arguments[1] == true);
    if (!isNonnegativeInteger(s)) return false;
    return ((s.length == 2) || (s.length == 4 && s>1950 && s<2050));
}

function isMonth (s)
{ 
	if (isEmpty(s)){
		if (isMonth.arguments.length == 1) return defaultEmptyOK;
		else return (isMonth.arguments[1] == true);  
    }
	return isIntegerInRange (s, 1, 12);
}

function isDay (s)
{   
	if (isEmpty(s)) 
       if (isDay.arguments.length == 1) return defaultEmptyOK;
       else return (isDay.arguments[1] == true);   
    return isIntegerInRange (s, 1, 31);
}


function DateCompare(dy1,mo1,yr1,dy2,mo2,yr2) {
	var d1=Number(dy1) + (mo1*100) + (yr1*10000)
	var d2=Number(dy2) + (mo2*100) + (yr2*10000)
	
	return (d1==d2) ? 0 : ((d1>d2) ? 1 : -1)
}
// the above functions are used for the date validation 12/07 satya

