  function funValidEmail(email)
  {
    var validEmail = true;
    
    if (email.length > 0)
    {
        if (trimString(email) != "")
        {
             var validChars = "abcdefghijklmnopqrstuvwxyz.-_0123456789@ABCDEFGHIJKLMNOPQRSTUVWXYZ"
             var firstchar
             var maillen
             var str
             var mail = trimString(email)
             firstchar = mail.substring(0,1)
             maillen = mail.length;
     
             if (firstchar == "@" || firstchar == "." || firstchar == "-")
             {
                validEmail = false;
             }
     
            for (var i=0; i < maillen; i++)
            {
               str = mail.substring(i, i+1);
               if(validChars.indexOf(str)== -1)
               {
                  validEmail = false;
               }
            }
     
            if (mail.indexOf("@",0) != -1 )
            {
                if (mail.indexOf("@",mail.indexOf("@",0)+1)!= -1 )
                {
                  validEmail = false;
                }
            } 
     
            if( (mail.indexOf("@") == -1) || (mail.indexOf(".") == -1) )
            {
                validEmail = false;
            }
        }
        else
        {
            validEmail = false;
        }
    }
    return validEmail;
  }
  
  function trimString(trimThis)
  {
     var localString = trimThis;
     var flag = true;
     var len = localString.length;
     var cnt = 0;
     while( (localString.charAt(cnt) == ' ') && (cnt++ < len) )
     {
     }
     if(cnt >= len)
      localString = "";
     else
     {
      localString = localString.substring(cnt,len);
      len = localString.length;
      cnt=len-1;
      while( (localString.charAt(cnt) == ' ') && (cnt-- < len ) )
      {
      }
      if(cnt < len-1)
       localString = localString.substring(0,cnt+1);
     }
     return(localString);
  }
  
  function PhoneNumberFormat(m)
  {
    //n=m.name;
    //p1=document.forms[0].elements[n]
    p1=document.getElementById(m)
    id = m
    ValidatePhone()
  }
  // Phone Number Format
  var n;
  var p;
  var p1;
  var id;
    
  function ValidatePhone()
	{
      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+")";
          }
          }
          document.getElementById(id).value="";
          document.getElementById(id).value=pp;
      }
      
      if(p.length>3)
      {
          d1=p.indexOf('(')
          d2=p.indexOf(')')
          if (d2==-1)
          {
              l30=p.length;
              p30=p.substring(0,4)
              strCloseBrace = p.substring(4,5)
              if(p.substring(4,5) == ')')
              {
                p30=p30
              }
              else
              {
                p30=p30+")"
              }
        
            //		p31=p.substring(4,l30);
              p31=p.substring(4,l30);
              pp=p30+p31;
              //alert(p31);
              //alert('phone ' + p)
              document.getElementById(id).value="";
              document.getElementById(id).value=pp;
          }
      }
  
      if(p.length>5)
      {
          p11=p.substring(d1+1,d2);
          if(p11.length>3)
          {
            p12=p11;
            l12=p12.length;
            l15=p.length
            //l12=l12-3
            p13=p11.substring(0,3);
            p14=p11.substring(3,l12);
            p15=p.substring(d2+1,l15);
            document.getElementById(id).value="";
            pp="("+p13+")"+p14+p15;
            document.getElementById(id).value=pp;
            //obj1.value="";
            //obj1.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);
              //alert(p19);
              pp=p19+p17+"-"+p18;
              document.getElementById(id).value="";
              document.getElementById(id).value=pp;
              //obj1.value="";
              //obj1.value=pp;
          }
          else
          {
              var temp = p.substring(4,6)
              if(temp == '))')
              {
                pp=p.substring(0,d2+1) + p.substring(d2+2,p.length)
                document.getElementById(id).value="";
                document.getElementById(id).value=pp;
              }
          }
      }
      //}
      //setTimeout(ValidatePhone,100)
    }
    
    function checkPhoneInNumberFormat(phoneNo)
    {
        var flag = false;
        var sign1 = phoneNo.substring(0,1);
        var phone1 = trimString(phoneNo.substring(1,4));
        var sign2 = trimString(phoneNo.substring(4,5));
        var phone2 = trimString(phoneNo.substring(5,8));
        var sign3 = trimString(phoneNo.substring(8,9));
        var phone3 = trimString(phoneNo.substring(9,13));

        if(phoneNo.length < 13)
            flag = true;
        if(phone1.length == 0 || phone2.length == 0 || phone3.length == 0)
          flag = true;

        if(sign1 != '(')
          flag = true;
          
        if(sign2 != ')')
          flag = true;
        
        if(sign3 != '-')
          flag = true;
        
        if(isNaN(phone1) || phone1.indexOf(".") != -1)
          flag = true;
        if(isNaN(phone2) || phone2.indexOf(".") != -1)
          flag = true;
        if(isNaN(phone3) || phone3.indexOf(".") != -1)
          flag = true;
        return flag;
	}
  
function funPrint()
{
    window.print();
}  

function getState(formName,objZipCode)
{

    var zip=trimString(objZipCode.value);
    var zipCodeErrText="";

    if(isNaN(zip))
    {
      zipCodeErrText= "Zip Code should be Numeric";
    }    
    else if(parseFloat(zip) == 0)
    {
      zipCodeErrText= "Zip Code should not be zero";
    }    
    else if(zip.length < 5 || zip.indexOf(".") != -1)
    {
      zipCodeErrText= "Zip Code should be Numeric and 5 Digits";
    }
    else
    {
      for(i=0;i<zip.length;i++)
      {
        var chr=zip.substring(i,i+1);
        if ( chr<"0" || chr>"9" )
        {
          zipCodeErrText= "Invalid Zip Code";
        }
      }
    }  
    if(zipCodeErrText.length > 0)
    {
        alert(zipCodeErrText);
        objZipCode.focus();
        return false;
    }
    else
    {
        document.getElementById(formName).submit();    
        return true;
    }
}

function getZipCodeValidation(formName,objZipCode)
{
    var zip=trimString(objZipCode.value);
    var zipCodeErrText="";

    if(isNaN(zip))
    {
      zipCodeErrText= "Zip Code should be Numeric";
    }    
    else if(parseFloat(zip) == 0)
    {
      zipCodeErrText= "Zip Code should not be zero";
    }    
    else if(zip.length < 5 || zip.indexOf(".") != -1)
    {
      zipCodeErrText= "Zip Code should be Numeric and 5 Digits";
    }
    else
    {
      for(i=0;i<zip.length;i++)
      {
        var chr=zip.substring(i,i+1);
        if ( chr<"0" || chr>"9" )
        {
          zipCodeErrText= "Invalid Zip Code";
        }
      }
    }  
    return zipCodeErrText;
}



// This function changes populates the date combo box according to the month selection
function setValues_Date(objMonth, objDay, objYear, objHiddenDay)
{
  
    var isLeapYear = false;
    var mm = objMonth.value; //document.frmQualification.effectiveMonth.value;
    var dd = objDay.value; //document.frmQualification.effectiveDay;
    var yy = parseFloat(objYear.value);//parseFloat(document.frmQualification.effectiveYear.options[document.frmQualification.effectiveYear.selectedIndex].value);
    //alert('mm-dd-yy = ' + mm + "-"+dd+"-"+yy);

    var cnt = 0;
    var selectedDay = objHiddenDay.value; //document.getElementById('hiddenEffectiveDay').value;
                    
    //alert('selectedDay = ' + selectedDay);    
    
    objDay.selectedIndex= -1;
    objDay.options.length= 1;
    //document.frmQualification.effectiveDay.selectedIndex= -1;
    //document.frmQualification.effectiveDay.options.length= 1;
    
    if (mm==1 || mm==3 || mm==5 || mm==7 || mm==8 || mm==10 || mm==12)
    {
        cnt=31;
    }
    
    if (mm==4 || mm==6 || mm==9 || mm==11)
    {
        cnt=30;
    }
    
    if (mm==2)
    {
      if(yy!=0 && yy % 4==0)
        cnt=29;
      else
        cnt=28;
    }
    
    var currDay = 1;
    for (var i=1; i<=cnt; i++)
    {
        objDay.options.length= objDay.options.length+1;
        objDay.options[i].text=i;
        objDay.options[i].value = i;
        /*document.frmQualification.effectiveDay.options.length= document.frmQualification.effectiveDay.options.length+1;
        document.frmQualification.effectiveDay.options[i].text=i;
        document.frmQualification.effectiveDay.options[i].value = i;*/
        if(selectedDay==0)
        {
          if(currDay==i)
          {
            objDay.options[i].selected=true;
            //document.frmQualification.effectiveDay.options[i].selected=true;
            selectedDay=i;
          }
        }
    }
    if (selectedDay > 0 && selectedDay < objDay.options.length) 
        objDay.options[selectedDay].selected = true;      
    else
        objDay.options[objDay.options.length-1].selected = true;          
    /*if (selectedDay > 0 && selectedDay < document.frmQualification.effectiveDay.options.length) 
        document.frmQualification.effectiveDay.options[selectedDay].selected = true;      
    else
        document.frmQualification.effectiveDay.options[document.frmQualification.effectiveDay.options.length-1].selected = true;      
    */
}

function dateValidationForGTCurrDate(objMonth, objDay, objYear)
{
   
    
    
    var flag = false;
    var errorText = "";
    
    // Getting all the current date values
    var curDay = document.getElementById('currDay').value;
    var curMonth = document.getElementById('currMonth').value;
    var curYear = document.getElementById('currYear').value;
  //  alert('current date (mm-dd-yyyy) = ' + curMonth + '-' + curDay + '-' + curYear);
    
    // Getting the selected values
    var selMon = objMonth //document.frmQualification.effectiveMonth.options[document.frmQualification.effectiveMonth.selectedIndex].value;
    var selDay = objDay //document.frmQualification.effectiveDay.options[document.frmQualification.effectiveDay.selectedIndex].value;
    var selYear = objYear //document.frmQualification.effectiveYear.options[document.frmQualification.effectiveYear.selectedIndex].value;
 // alert('selected date (mm-dd-yyyy) = ' + selMon + '-' + selDay + '-' + selYear);

    if(selMon*selDay*selYear !=0)
    {
        // if year are not same then no need to check
        if (parseFloat(selYear) > parseFloat(curYear))
        {
            flag = false;
        }
        else if (parseFloat(curYear) == parseFloat(selYear))
        {
            if ((parseFloat(curMonth) == parseFloat(selMon)) && (parseFloat(curDay) > parseFloat(selDay)))
                flag = true;
    
            if (parseFloat(curMonth) > parseFloat(selMon))
                flag = true;
        }
    
        if (flag == true)
        {
            errorText = " Date cannot be less than Current Date.\n";
        }
    }
    else
    {
        errorText = "";//"Proposed Effective "; 
        flag  = true;                    
        var error = "";
        
        if (parseFloat(selMon) == 0)
        {
            error = error + " Month";
        }
    
        if (parseFloat(selDay) == 0)
        {
            if(error.length == 0)
            {
                error = error + " Day";
            }
            else
            {
                error = error + ", Day";    
            }
        }
    
        if (selYear == 0)
        {
            if(error.length == 0)
            {
                error = error + " Year";
            }
            else
            {
                error =error +  ", Year";    
            }
        }
        errorText = errorText +  error + " value should be selected.\n";
    }
    //alert('errorText - ' + errorText);
    return errorText;//return flag;
}


function dateValidationForLTCurrDate(objMonth, objDay, objYear)
{
    // Date is manadatory and equal or less than current date
    
    var flag = false;
    var errorText = "";
    
    // Getting all the current date values
    var curDay = document.getElementById('currDay').value;
    var curMonth = document.getElementById('currMonth').value;
    var curYear = document.getElementById('currYear').value;
    //alert('current date (mm-dd-yyyy) = ' + curMonth + '-' + curDay + '-' + curYear);
    
    // Getting the selected values
    var selMon = objMonth.value;
    var selDay = objDay.value;
    var selYear = objYear.value;
    //alert('selected date (mm-dd-yyyy) = ' + selMon + '-' + selDay + '-' + selYear);

    if(selMon*selDay*selYear !=0)
    {
        // if year are not same then no need to check
        //if (parseFloat(selYear) > parseFloat(curYear))
        if (parseFloat(curYear) > parseFloat(selYear))
        {
            flag = false;
        }
        //else if (parseFloat(curYear) == parseFloat(selYear))
        else if (parseFloat(selYear) == parseFloat(curYear))
        {
            //if (parseFloat(curMonth) == parseFloat(selMon) && parseFloat(curDay) > parseFloat(selDay))
            if ((parseFloat(selMon) == parseFloat(curMonth)) && (parseFloat(selDay) > parseFloat(curDay)))
                flag = true;
    
            //if (parseFloat(curMonth) > parseFloat(selMon))
            if (parseFloat(selMon) > parseFloat(curMonth))
                flag = true;
        }
    
        if (flag == true)
        {
            errorText = " Date cannot be greater than Current Date.\n";
        }
    }
    else
    {
        errorText = "";
        flag  = true;                    
        var error = "";
        
        if (parseFloat(selMon) == 0)
        {
            error = error + " Month";
        }
    
        if (parseFloat(selDay) == 0)
        {
            if(error.length == 0)
            {
                error = error + " Day";
            }
            else
            {
                error = error + ", Day";    
            }
        }
    
        if (selYear == 0)
        {
            if(error.length == 0)
            {
                error = error + " Year";
            }
            else
            {
                error =error +  ", Year";    
            }
        }
        errorText = errorText +  error + " value should be selected.\n";
    }
    //alert('errorText - ' + errorText);
    return errorText;//return flag;
}

function ReferToUnderwriter(formName)
{
    document.getElementById(formName).action = "../common/ReferUnderwriter.jsp";
    document.getElementById(formName).submit();
}
function checkIntegerValue(value)
{
    var errorText = "";
    if (isNaN(value))
    {
        errorText = " should be numeric";
    }  
    else if (parseFloat(value) == 0)
    {
        errorText = " cannot be equal to 0";
    }
    else if (parseFloat(value) < 0)
    {
        errorText = " cannot be less than 0";
    }
    else if (value.indexOf(".") != -1)
    {
        errorText = " cannot be in decimal format";
    }
    return errorText;
}
  
function checkNumericValue(value)
{
    var errorText = "";
    if (isNaN(value))
    {
        errorText = " should be numeric";
    }  
    else if ((parseFloat(value) == 0))
    {
        errorText = " cannot be equal to 0";
    }
    else if (parseFloat(value) < 0)
    {
        errorText = " cannot be less than 0";
    }
    return errorText;
}

function checkNumericValueWithoutZero(value)
{
    var errorText = "";
    if (isNaN(value))
    {
        errorText = " should be numeric";
    }  
    else if (parseFloat(value) < 0)
    {
        errorText = " cannot be less than 0";
    }
    return errorText;
}