 function DateCompare(startDate, endDate) 
 {
	if(startDate!="" && endDate!="")
	{
		
	 	// Variables for the current date, year and month
		var right_now = new Date();
		var the_year=right_now.getYear();
		var the_month=right_now.getMonth();
		
		var enteredDate = new Date(endDate);

		if(enteredDate >= right_now) 
		{
			return true;
		}
		else
		{
			return false;
		}
	}	
 }
 
 function isGreaterThanCurrentDate(date) {
 	var d = new Date();
	var curr_date = d.getDate();
	var curr_month = d.getMonth()+1;
	var curr_year = d.getFullYear(); 
	var strDate = curr_month+"/"+curr_date +"/"+curr_year;	
 	var currentDate = new Date(strDate);
 	var givenDate = new Date(date);
 	if(givenDate > currentDate)
	{
		return true;
	}
	else
	{
		return false;
	}
	
 }

	function IsPassword(parm) 
	{
		var iChars = "!@#$%^&*()+=-[]\\\';,/{}|\":<>?";
	
	  	for (var i = 0; i < parm.length; i++) 
	  	{
	  		if (iChars.indexOf(parm.charAt(i)) != -1)
	  		return false;
	  	}
	  	return true;
	}
	
	function isSpecial(parm) 
	{
		var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
		for (var i = 0; i < parm.length; i++) 
		{
	  		if (iChars.indexOf(parm.charAt(i)) != -1)  
	  		return false;
	  	}
  		return true;
	}	
function isEmailSpecial(parm) 
	{
		var iChars = "!#$%^&*()+=-[]\\\';,/{}|\":<>?";
		for (var i = 0; i < parm.length; i++) 
		{
	  		if (iChars.indexOf(parm.charAt(i)) != -1)  
	  		return false;
	  	}
  		return true;
	}	
	
	function isEmail(parm) 
	{
		var iChars = "!#$%^&*()+=-[]\\\';,/{}|\":<>?";
		for (var i = 0; i < parm.length; i++) 
		{
	  		if (iChars.indexOf(parm.charAt(i)) != -1)  
	  		return false;
	  	}
  		return true;
	}	
function isEmailSpecialForUser(parm) 
	{
		var iChars = "!#$%^&*()+=[]\\\';,/{}|\":<>?";
		for (var i = 0; i < parm.length; i++) 
		{
	  		if (iChars.indexOf(parm.charAt(i)) != -1)  
	  		return false;
	  	}
  		return true;
	}	


function IsNumeric(strString) {
  var strValidChars = "()0123-456789";
  var strChar;
  var blnResult = true;
  if (strString.length == 0) return false;
  for (i = 0; i < strString.length && blnResult == true; i++) {
    strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1) {
        blnResult = false;
      }
  }
  return blnResult;
}


function isInteger(s)
{
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) 
{
	for (var i = 1; i <= n; i++)
	 {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

var dtCh= "/";
var minYear=1700;
var maxYear=2900;

function isDateCheck(dtStr)
{
	
	if(dtStr!="")
	{
		var daysInMonth = DaysArray(12)
		var pos1=dtStr.indexOf(dtCh)
		var pos2=dtStr.indexOf(dtCh,pos1+1)
		var strMonth=dtStr.substring(0,pos1)
		var strDay=dtStr.substring(pos1+1,pos2)
		var strYear=dtStr.substring(pos2+1)
		strYr=strYear
		if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
		if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
		for (var i = 1; i <= 3; i++) 
		{
			if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
		}
		month=parseInt(strMonth)
		day=parseInt(strDay)
		year=parseInt(strYr)
		
		if (pos1==-1 || pos2==-1)
		{
			return false
		}
		if (strMonth.length<1 || month<1 || month>12)
		{
			return false
		}
		if (strDay.length<1 || day<1 || day>31 || 
				(month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
		{
			return false
		}
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear)
		{
			return false
		}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
		{
			return false
		}
		return true
	}
	return true
}

/*
Copyright 2005, 4word systems
All rights reserved.

This software may not be reproduced or distributed in any form without the express 
written consent of 4word systems or it's designee.

Revision 1.1:  20050729 Added underscore to list of valid characters
*/


function isValidEmail(email) {
    
    if (email=="") {
       
        return true;
    }
    if (email.length==0) {  
        
        return true;
    }
    if (! allValidChars(email)) {  // check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) { //  must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {  // last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {  // @ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) { // two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {  // . must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}
function isValid(parm,val) 
{
	 for (i=0; i<parm.length; i++)
{
	 	if (val.indexOf(parm.charAt(i),0) == -1) return false;
}
	 return true;
}

function insertDateFromCalendar(idButton,c)
{
	
	var idInputField = "txt"+idButton;
	
	if(c===0){
	    Calendar.setup(
        {
          inputField  : idInputField,         // ID of the input field
          ifFormat    : "%m/%d/%Y",    // the date format
          button      : idButton       // ID of the button
        }
       );
  }
  else if(c==1)
  {
   Calendar.setup(
        {
          inputField  : idInputField,         // ID of the input field
          ifFormat    : "%m/%d/%Y[%I:%M %p]",    // the date format
          button      : idButton       // ID of the button
        }
       );
   }

}

var n;
var p;
var p1;

function ValidatePhone(m)
{
	p=p1.value
	if(p.length==3){
	
		pp=p;
		d4=p.indexOf('(')
		d5=p.indexOf(')')
		if(d4==-1){
			pp="("+pp;
		}
		if(d5==-1){
			pp=pp+")";
		}
		
		m.value="";
		m.value=pp;
	}
	if(p.length>3){
		d1=p.indexOf('(')
		d2=p.indexOf(')')
		if (d2==-1){
			l30=p.length;
			p30=p.substring(0,4);
			
			p30=p30+")"
			p31=p.substring(4,l30);
			pp=p30+p31;
			
			m.value="";
			m.value=pp;
		}
		}
	if(p.length>5){
		p11=p.substring(d1+1,d2);
		if(p11.length>3){
		p12=p11;
		l12=p12.length;
		l15=p.length
	
		p13=p11.substring(0,3);
		p14=p11.substring(3,l12);
		p15=p.substring(d2+1,l15);
		m.value="";
		pp="("+p13+")"+p14+p15;
		m.value=pp;
		
		}
		l16=p.length;
		p16=p.substring(d2+1,l16);
		l17=p16.length;
		if(l17>3&&p16.indexOf('-')==-1){
			p17=p.substring(d2+1,d2+4);
			p18=p.substring(d2+4,l16);
			p19=p.substring(0,d2+1);
			
		pp=p19+p17+"-"+p18;
		m.value="";
		m.value=pp;
		
		}
}

}

function getIt(m)
{

		n=m.name;
		p1=m;
		ValidatePhone(m);

}

function testphone(obj1)
{
	p=obj1.value
	
	p=p.replace("(","")
	p=p.replace(")","")
	p=p.replace("-","")
	p=p.replace("-","")

	if (isNaN(p)==true){
	alert("Check phone");
	return false;
	}
}
 
 function getzip(m)
 {
n=m.name;

p1=m
ValidateZip(m)
}

function ValidateZip(m){
p=p1.value
if(p.length==5){

	pp=p;
	d4=p.indexOf("-")
	if(d4==-1){
		pp=pp+"-";
	}
	
	
	m.value="";
	m.value=pp;
}
}

function checkbackspace(e)
{

  var keynum;
	if(window.event) // IE
  {
 	 keynum = e.keyCode;
 	}
	else if(e.which) // Netscape/Firefox/Opera
  {
  	keynum = e.which;
  }
	
	if(keynum==8)
	{
	
		return false;
	}
	else
	{
	
		return true;
	}
	}



       function showDown(evt) 
       {
      	var browserName=navigator.appName; 
				if (browserName!="Netscape")
				{ 
     
	        evt = (evt) ? evt : ((event) ? event : null);
	        if (evt)
	         {
	            //alert(evt.keyCode);
	            if (evt.keyCode == 40 || evt.keyCode == 38)
	             {
	                // When down arrow key is pressed
	                //        alert("When down arrow key is pressed")
	                cancelKey(evt);
	            }
	           
	        }
      }
    }

    function cancelKey(evt) {
    
        if (evt.preventDefault) {
            evt.preventDefault();
            return false;
        }
        else {
            evt.keyCode = 0;
            evt.returnValue = false;
        }
    }

function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places
  var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
	return newnumber;
}

function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail ID")
	   return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID")
	   return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid E-mail ID")
	    return false
	}
	if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid E-mail ID")
	    return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid E-mail ID")
	    return false
	}
	if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid E-mail ID")
	    return false
	}
	if (str.indexOf(" ")!=-1){
	    alert("Invalid E-mail ID")
	    return false
	}
	return true			
}
//This is for time in milliseconds.
var milisec=0;
var seconds=0;
function display(){ 
 if (milisec>=9 ){ 
    milisec=0; 
    seconds+=1; 
 } 
 else 
    milisec+=1; 
    document.getElementById('processingform:d2').value=seconds+"."+milisec +" ms";
    setTimeout("display()",100) ;
} 