
function isNumberStartwithZero(sValue)
{
	var myregexp = /^[1-9][0-9]*$/;
	if (sValue.match(myregexp))
	{
		return true;
	}
	else
	{
		return false;
	}
}
function isNum(Num) {
        var charpos = Num.search("[^0-9]"); 
        if(Num.length > 0 &&  charpos >= 0) 
              { 
                return false; 
              }
        else
			  { 
                return true; 
              }
    }	

function isDate(strDate)
{
	var datePattern = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
	var matchArray = strDate.match(datePattern); //check the date format ok?.
	var blnIsDate = true;

	if (matchArray == null)
	{
		//alert("Please enter date as mm/dd/yyyy ");
		return false;
		blnIsDate=false;
	}

	month=matchArray[1];
	day=matchArray[3];
	year=matchArray[5];

	if (month <1 || month > 12)
	{
		//alert("Month must be between 1 and 12");
		return false;
		blnIsDate=false;
	}

	if (day <1 || day > 31)
	{
		//alert("Day must be between 1 and 31");
		return false;
		blnIsDate=false;
	}

	if ((month ==4 || month == 6 || month==9 || month==11) && day==31)
	{
		alert("Month "+month+" doesn't have 31 days!");
		return false;
		blnIsDate=false;
	}

	if (month ==2)
	{
		var isleap = (year % 4 ==0 && (year %100 !=0 || year % 400 ==0));
		if (day > 29 || (day==29 && !isleap))
		{
			alert("February " + year + " doesn't have " + day + " days!");
			return false;
			blnIsDate=false;
		}

	}

	return true;
}

function isFloat (s)
{   var i;
	var seenDecimalPoint = false;
	var decimalPointDelimiter = "."
	var defaultEmptyOK = true
	if (isEmpty(s)) 
	   if (isFloat.arguments.length == 1) return defaultEmptyOK;
	   else return (isFloat.arguments[1] == true);

	if (s == decimalPointDelimiter) return false;

	// Search through string's characters one by one
	// until we find a non-numeric character.
	// When we do, return false; if we don't, return true.

	for (i = 0; i < s.length; i++)
	{   
		// Check that current character is number.
		var c = s.charAt(i);

		if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
		else if (!isDigit(c)) return false;
	}

// All characters are numbers.
return true;
}
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isEmpty(s)
{	return ((s == null) || (s.length == 0))
}

function checkMoney(ctl,msgName){
  if(isFloat(ctl.value)==false)	
    {
      alert('"'+msgName+'"' + " is Invalid. \nPlease Enter only Numeric Data. \nDo not use any characters like ','");
      ctl.value = "";
	  ctl.focus();
      return (false);
    }
  else
    {
    	return (true);
    }
}

function checkBlank(ctl,msgName){
  if(trimme(ctl.value)=="")	
    {
      alert('"'+msgName+'"' + " Can not be blank");
      ctl.focus();
      return (false);
    }
  else
    {
    	return (true);
    }
}
function isBlank(ctl){
	if(trimme(ctl.value))	
    {		
      return (false);
    }
  else
    {
    	return (true);
    }
}
function trimme(strName)
{
  var strTemp = "";
  strTemp = strName;
  var i = 0;

  if(strName.indexOf(" ") == 0)
  {
    for(i=0;i<=strTemp.length;i++)
    {
      if(strName.indexOf(" ") == 0)
      {
       strName = strName.substr(1);
      }  
      else
        break;   
    }
  }
  if(strName == "")
	return false;
  else
	return true;
}
function checkSelect(ctl,msgName){
  if(ctl.selectedIndex<=0)	
    {
      alert('Please Select '+msgName);
      ctl.focus();
      return (false);
    }
  else
    {
    	return (true);
    }
}

function ValidateEmail(ctl){
    	var id=ctl;
	var at=id.value.indexOf('@');
	var lastat=id.value.lastIndexOf('@');
	var dot=id.value.indexOf('.');
	lastdot=id.value.lastIndexOf('.')
	space=id.value.lastIndexOf(' ')
	if(space!=-1)
		return false;
	if ( !( (0 < at) && (at < (lastdot-1)) && (lastdot < (id.value.length-1)) && (at == lastat) ) ) {
	  error = 1;
	 //alert("Email address is not formatted properly.");
	  //ctl.focus();
	  return (false);
	}

}
function ValidateAdminEmail(ctl){
    	var id=ctl;
	var at=id.value.indexOf('@');
	var lastat=id.value.lastIndexOf('@');
	var dot=id.value.indexOf('.');
	lastdot=id.value.lastIndexOf('.')
	if ( !( (0 < at) && (at < (lastdot-1)) && (lastdot < (id.value.length-1)) && (at == lastat) ) ) {
	  error = 1;
	 alert("Email address is not formatted properly.");
	 ctl.focus();
	  return (false);
	}
}

function confirmPassword(ctl1,ctl2){

   if(ctl1.value != ctl2.value){
   	alert("Password and Confirm Password do not match");
   	ctl1.focus();
   	return(false);
   }
}


function deleteitem(theMessage,theTarget)
{	
	var theRadio=form1.item_nbr;
	var strRadio;
	if (theRadio.length)
	{
		for (var i = 0; i < theRadio.length; i++)
		{   if (theRadio[i].checked)
			{
				strRadio=theRadio[i].value;
			}
		}
	}else
	{
		strRadio=theRadio.value;
	}
		if (strRadio > 0)
	{
		var blnConfirm;
		blnConfirm = confirm("Are you sure?");
		if (blnConfirm)
		{
			form1.action=theTarget+'?item_nbr='+strRadio
			form1.submit();
		}
	}else
	{
		alert ("Select "+ theMessage + " To Delete");
	}
}

function radio_validate(formObj) {
    var isOK = false;
    for (i=0;i<formObj.elements.length;i++) {
	currElem = formObj.elements[i]
        if (currElem.type == "radio"  &&  currElem.checked) {
            isOK=true;
	    break;
        }
    }
    if (!isOK) alert("You need to select a option !");
    
    return isOK;
}

function selectAllCheckbox(frm, chk_state)  
{
	totalElem = frm.length;

	for (i=0;i<totalElem;i++)
	{
		type = frm.elements[i].type;
		if (type == "checkbox")
		{
			frm.elements[i].checked = chk_state;
		}

	}
}   

function UnselectAllCheckbox(frm,ctl,ctlAll,chk_state)  
{
	chk_checked = false;
	c = document.getElementsByName(ctl);
	cAll = document.getElementsByName(ctlAll);

	total = c.length;

	for ( i = 0; i < total; i++)
	{
		if ( c[i].checked )
		{
			chk_checked = true;
		}
		else
		{
			chk_checked = false;
			cAll[0].checked = false;
			break;
		}
	 }
	
  if ( chk_checked )
	 {	
		 cAll[0].checked = chk_state;
		 
	 }
}  

function Delete(ctl,messagestring)          //******************Function call on button action  
{
  /*-----Code to check if any of the checkbox is selected else the form will not be submitted-------*/
		chk_checked = false;
		c = document.getElementsByName(ctl);
		total = c.length;

		for ( i = 0; i < total; i++)
		{
			if ( c[i].checked )
			{	
				chk_checked = true;
				break;
			}
		}
		//---------------End of code to check if any of the checkbox is selected-----------*/

		if ( chk_checked )
		{
			if ( confirm("Are you sure you wish to delete this " + messagestring + "?") )
			{
				return true;
			}
		}
		else 
		{
			alert("Please select the " + messagestring + " to be deleted");
			return false;
		}
	
}			
function dailyGreeting()
{
	var Today=new Date();
	var ThisDay=Today.getDay();
	var ThisDate=Today.getDate();
	var ThisMonth=Today.getMonth()+1;
	var ThisYear=Today.getFullYear();  //included if you wish to insert the year
	function DayTxt (DayNumber) {
	var Day=new Array();
	Day[0]="Sunday";
	Day[1]="Monday";
	Day[2]="Tuesday";
	Day[3]="Wednesday";
	Day[4]="Thursday";
	Day[5]="Friday";
	Day[6]="Saturday";
	return Day[DayNumber];
	}
	var DayName=DayTxt(ThisDay);
	function MonthTxt (MonthNumber) {
	var Month=new Array();
	Month[1]="January";
	Month[2]="February";
	Month[3]="March";
	Month[4]="April";
	Month[5]="May";
	Month[6]="June";
	Month[7]="July";
	Month[8]="August";
	Month[9]="September";
	Month[10]="October";
	Month[11]="November";
	Month[12]="December";
	return Month[MonthNumber];
	}
	var MonthName=MonthTxt(ThisMonth);
	var d = new Date();
	var h = d.getHours();
	document.write("<p style='margin-right:0;'><TABLE BORDER=3 BGCOLOR=WHITE  WIDTH=75 HEIGHT=85 align=right>"+"<TD>"+"<p align=center>"+"<font size=-1 color=#3A549D>"+DayName+"<br>"+"<font color=orangered size=+3 >"+ThisDate+"</font>"+"<br>"+MonthName+"<br>"+"</b>"+"</font>"+"</p>"+"</TD>"+"</TR>"+"</TABLE></p>");
	
}
/*---------------  For top Hide and show Div link------------------*/
function findObj(n, d)
{ 
  var p,i,x;  
  if(!d) d=document; 
  if((p=n.indexOf("?"))>0&&parent.frames.length)
{
  d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function showHideLayers()
{ 
  var i,p,v,obj,args=showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  if ((obj=findObj(args[i]))!=null) 
	{ 
	  v=args[i+2];
		if (obj.style) 
		{ 
			obj=obj.style; 
			v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
		}
		obj.visibility=v;
	}
}
function jumpMenu(targ,selObj,restore)
{ 
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function isEmail(emailStr) 
{
	
/* 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)

// Check for the Email start with number.
//if ('0123456789'.indexOf(emailStr.charAt(0)) >= 0) 
//{
//return false; 	
//}
if ('!%&\\(\\)<>@,;:\\\\\\\"\\.\\[\\]'.indexOf(emailStr.charAt(0)) >= 0) 
{
   return false; 	
}

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("Email address seems incorrect (check @ and .'s)")
	return false
}
var user=matchArray[1]
var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
    //alert("The username doesn't seem to be valid.")
    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!")
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	//alert("The domain name doesn't seem to be valid.")
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   //alert("The address must end in a three-letter domain, or two letter country.")
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   //var errStr="This address is missing a hostname!"
   //alert(errStr)
   return false
}

// If we've gotten this far, everything's valid!
return true;
}

function checkURLNew(sUrl)
	{
		var url = false ;
		var isNot = "`!@$^*()[{]}\|;'',<> " ;
		if (sUrl.length != 0 )
		{
			if (sUrl.indexOf('://') != -1)
			{
				if (sUrl.indexOf('"') == -1)
				{
					url = true ;
					if (sUrl.length <= 7 )
					{
						url = false ;	
					}
					for (i=0;i!=sUrl.length;++i)
					{
						if (isNot.indexOf(sUrl.substring(i,i+1)) != -1)
						{
							url = false ;	
						}
					}
					//Checking for .com, .co, .net, .org	in the URL	
					if (sUrl.indexOf('.com') != -1)
					{
						url = true ;						
					}
					else
					{
						if (sUrl.indexOf('.co') != -1)
						{
							url = true ;						
						}
						else
						{	
							if (sUrl.indexOf('.net') != -1)
							{
								url = true ;
							}
							else
							{
								if(sUrl.indexOf('.org') != -1)
								{
									url = true ;
								}
								else
								{
									url = false ;
								}
							}
						}
					}
					
				}
			}
		}
		else{
			url=true;
		}	
		if (url == false )
		{
			//alert('In valid URL') ;
			return false;
		}
		else
		{
			//checkURLNew = true ;
			return true ;
		}	
	}
	function isNum1(argvalue) {
	argvalue = argvalue.toString();
	
	for(i=0 ; i<=argvalue.length ; i++)
	{
		var str1 = argvalue.substring(0,1);
		
		if ((str1>="a") &&  (str1<="z") || (str1>="A") && (str1<="Z"))
		{
			//(c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")));
			return false;
		}
		
	}
	var isNot = "`~-`!@$^*()[{]}\|;''?/|#{&},<> " ;
	for (i=0;i<=argvalue.length;i++)
				{
					var number1 = argvalue.substring(i,i+1);
					var Position1=isNot.indexOf(number1);
					
					
				}
	var  isNot1 = ".";
	var  isNot2 = "0123456789";
	for(i=0 ; i<=argvalue.length ; i++)
	{
		if (isNot1.indexOf(argvalue.substring(i,i+1)) == -1)
		{
			
			var pos = argvalue.indexOf(isNot1);
			if(pos != -1)
			{
				for(i=1 ; i<=argvalue.length;i++)
				{
					num_ber = argvalue.substring(pos+i,pos+i+1);
					num_ber = num_ber.toString();
					var Position=isNot2.indexOf(num_ber);
					
					if(Position == -1)
					{
						return false;
					}
				}
			}
			
			//return true;
		}
		
	}
}
function isAlphabetic(s)
  {
  var i;
	
  if (isBlank(s)) 
     return false;

  // Search through string's chars one by one until we find a 
  // non-alphabetic char, then return false; if we don't, return true

  for (i = 0; i < s.length; i++)
  {   
  // Check that current character is letter
  var c = s.charAt(i);

  if (!isLetter(c))
    return false;
  }

  // All characters are letters
  return true;
  }

 function isAlphanumeric(s, AllowSpace, AllowUnderscore)
  {
  var i;

  // Search through string's chars one by one until we find a 
  // non-alphanumeric char, then return false; if we don't, return true

  for (i = 0; i < s.length; i++)
    {   
    // Check that current character is number or letter
    var c = s.charAt(i);
		if (!(isLetter(c) || isDigit(c) )){
			switch(c){
				case "_" :
					if(!AllowUnderscore) {
						return false;
					}
					break ;
				case " " :
					if(!AllowSpace){
						return false;
					}
					break ;
				case "-" :
					break;
				default :
					return false;
			}	
		}
    }
	// All characters are numbers or letters
	return true;
  }

  function isLetter(c)
  {
  return (((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")));
  }

  function isDigit(c)
  {
  return ((c >= "0") && (c <= "9"));
  }
