///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////// TO CHECK VALUE IN NUMBER ////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
function isNum(Num) {
        var charpos = Num.search("[^0-9]"); 
        if(Num.length > 0 &&  charpos >= 0) 
              { 
                return false; 
              }
        else
			  { 
                return true; 
              }
    }	

///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////// TO CHECK VALUE IN DATE FORMAT ////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////

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;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////// TO CHECK VALUE IN FLOAT NUMBER //////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////

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.focus();
      return (false);
    }
  else
    {
    	return (true);
    }
}

/TO CHECK VALUE IN FLOAT NUMBER //////////
function checkBlank(ctl,msgName){
  if(trimme(ctl.value)=="")	
    {
      alert('"'+msgName+'"' + " Can not be blank");
      ctl.focus();
      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('.')
	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;
}


