function isEmpty(mytext) 
{
    //alert ("mytext" & mytext);
    var re = /^\s{1,}$/g; //match any white space including space, tab, form-feed, etc.
    if ((mytext.value.length==0) || (mytext.value=="") || ((mytext.value.search(re)) > -1))
    {
        return true;
    }
    else 
    {
        return false;
    }
}

function isIntegerNumber(NumberToTest) 
{
    var IsFound = /^-?\d+$/.test(NumberToTest);
    return (IsFound);
}

function isRealNumber(NumberToTest) 
{
    //var IsFound = /^[0123456789-\.]\d*$/.test(NumberToTest);
    //alert(NumberToTest);
    var IsFound = /^(\+|-)?[0-9][0-9]*(\.[0-9]*)?$/.test(NumberToTest);
    //alert(IsFound);
    return (IsFound);
}

function Validation(theForm)
{
    if (theForm.name.value == "")
    {
        alert("Please enter a value for the \"Name\" field.");
        theForm.name.focus();
        return (false);
    }

    if ((!isIntegerNumber(theForm.day.value) || theForm.day.value < 1 || theForm.day.value > 31))
    {
        alert("The value for \"Day\" should be between 1 and 31.");
        theForm.day.focus();
        return (false);
    }

    if ((!isIntegerNumber(theForm.month.value) || theForm.month.value < 1 || theForm.month.value > 12))
    {
        alert("The value for \"Month\" should be between 1 and 12.");
        theForm.month.focus();
        return (false);
    }

    if ((!isIntegerNumber(theForm.year.value) || theForm.year.value < 1 || theForm.year.value > 9999))
    {
        alert("The value for \"Year\" should be between 1 and 9999.");
        theForm.year.focus();
        return (false);
    }
    
    var checkOK = "0123456789-!";
    var checkStr = theForm.year.value;
    var allValid = true;
    var decPoints = 0;
    var allNum = "";
    
    for (i = 0;  i < checkStr.length;  i++)
    {
        ch = checkStr.charAt(i);
        for (j = 0;  j < checkOK.length;  j++)
        
        if (ch == checkOK.charAt(j))
            break;
        if (j == checkOK.length)
        {
            allValid = false;
            break;
        }
        if (ch != ",")
            allNum += ch;
    }
  
    if (!allValid)
    {
        alert("Please enter only digit characters in the Year field.");
        theForm.year.focus();
        return (false);
    }

    if ((!isIntegerNumber(theForm.hrs.value) || theForm.hrs.value < 0 || theForm.hrs.value >= 24))
    {
        alert("The value for \"Hours\" should be between 0 and 24.");
        theForm.hrs.focus();
        return (false);
    }

    if ((!isIntegerNumber(theForm.min.value) || theForm.min.value < 0 || theForm.min.value >= 60))
    {
        alert("The value for \"Minutes\" should be between 0 and 60.");
        theForm.min.focus();
        return (false);
    }

    if ((!isIntegerNumber(theForm.sec.value) || theForm.sec.value < 0 || theForm.sec.value >= 60))
    {
        alert("The value for \"Seconds\" should be between 0 and 60.");
        theForm.sec.focus();
        return (false);
    }
    
    if(theForm.place.value == "")
    {
        alert("Please enter Place.");
        theForm.place.focus();
        return (false);
    }
    if(theForm.place.value.length < 3)
    {
        alert("Please enter at least 3 starting characters of Place.");
        theForm.place.focus();
        return (false);
    }
    
    if ((!isIntegerNumber(theForm.LongDeg.value) || theForm.LongDeg.value < 0 || theForm.LongDeg.value >= 180))
    {
        alert("The value for \"Longitude Degree\" should be between 0 and 180.");
        theForm.LongDeg.focus();
        return (false);
    }

    if ((!isIntegerNumber(theForm.LongMin.value) || theForm.LongMin.value < 0 || theForm.LongMin.value >= 60))
    {
        alert("The value for \"Longitude Minute\" should be between 0 and 60.");
        theForm.LongMin.focus();
        return (false);
    }

    if ((!isIntegerNumber(theForm.LatDeg.value) || theForm.LatDeg.value < 0 || theForm.LatDeg.value >= 90))
    {
        alert("The value for \"Latitude Degree\" should be between 0 and 90.");
        theForm.LatDeg.focus();
        return (false);
    }

    if ((!isIntegerNumber(theForm.LatMin.value) || theForm.LatMin.value < 0 || theForm.LatMin.value >= 60))
    {
        alert("The value for \"Latitude Minute\" should be between 0 and 60.");
        theForm.LatMin.focus();
        return (false);
    }

    /*
    if ((!isIntegerNumber(theForm.LatSec.value) || theForm.LatSec.value < 0 || theForm.LatSec.value >= 60))
    {
        alert("The value for \"Latitude Second\" should be between 0 and 60.");
        theForm.LatSec.focus();
        return (false);
    }
    */

    if ((!isRealNumber(theForm.timeZone.value) || theForm.timeZone.value < -12.0 || theForm.timeZone.value > 13.0))
    {
        alert("The value for \"Time Zone\" should be between -12.00 and 13.00.");
        theForm.timeZone.focus();
        return (false);
    }

    var checkOK1 = "0123456789-!";
    var checkStr1 = theForm.kphn.value;
    var allValid1 = true;
    var decPoints1 = 0;
    var allNum1 = "";
    
    for (i = 0;  i < checkStr1.length;  i++)
    {
        ch = checkStr1.charAt(i);
        for (j = 0;  j < checkOK1.length;  j++)
        
        if (ch == checkOK1.charAt(j))
            break;
        if (j == checkOK1.length)
        {
            allValid1 = false;
            break;
        }
        if (ch != ",")
            allNum1 += ch;
    }
  
    if (!allValid1)
    {
        alert("Please enter only digit characters in KP Horary Field.");
        theForm.kphn.focus();
        return (false);
    }

    if(theForm.kphn.value=="")
    {
        alert("Please enter KP Horary Number.");
        theForm.kphn.focus();
        return (false);
    }
  
    if((theForm.kphn.value<0) || (theForm.kphn.value>249))
    {
        alert("Please enter KP Horary Number between '0' and '249'. Enter '0' if you want to generate 'Janma Kundali' in place of 'Prashna Kundali'.");
        theForm.kphn.focus();
        return (false);
    }
  return (true);
}
