  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)
  {
    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);
              pp=p30+p31;
              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
            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;
          }
      
          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;
              document.getElementById(id).value="";
              document.getElementById(id).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;
              }
          }
      }
    }
    
    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);

    var cnt = 0;
    var selectedDay = objHiddenDay.value; //document.getElementById('hiddenEffectiveDay').value;
                    
    
    objDay.selectedIndex= -1;
    objDay.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;

        if(selectedDay==0)
        {
          if(currDay==i)
          {
            objDay.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;          

}

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;
    
    // 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;

    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";
    }
    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;
    
    // Getting the selected values
    var selMon = objMonth.value;
    var selDay = objDay.value;
    var selYear = objYear.value;

    if(selMon*selDay*selYear !=0)
    {
        // if year are not same then no need to check
        if (parseFloat(curYear) > parseFloat(selYear))
        {
            flag = false;
        }
        else if (parseFloat(selYear) == parseFloat(curYear))
        {
            if ((parseFloat(selMon) == parseFloat(curMonth)) && (parseFloat(selDay) > parseFloat(curDay)))
                flag = true;
    
            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";
    }
    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 popup(coverageid,carrierid)
{
    //alert("coverageid : "+coverageid)
    alert('carrierid = ' + carrierid + ", coverageid " + coverageid);
   if(carrierid == 1)
   {
        // for Scottsdale carrier
        if(coverageid == 'CG2186')
        {
           var coverage =  window.open("../coverageForm/EIFS.html","","width=625,toolbar=no,scrollbars=yes");
        }
        else if(coverageid == 'UTS318g')
        {
           var coverage =  window.open("../coverageForm/ContractDefination.html","","width=625,toolbar=no,scrollbars=yes");
        }
        else if(coverageid == 'UTS301g')
        {
           var coverage =  window.open("../coverageForm/SilicaDustExclusion.html","","width=625,toolbar=no,scrollbars=yes");
        }
        else if(coverageid == 'CG2279')
        {
           var coverage =  window.open("../coverageForm/SilicaExclusion.html","","width=625,toolbar=no,scrollbars=yes");
        }
        
   }
   else if(carrierid == 2)
   {
       // Nautilus carrier
       
        if(coverageid == 'S289')
        {
           var coverage =  window.open("../coverageForm/ConstructionsOperation.html","","width=625,toolbar=no,scrollbars=yes");
        }
        else if(coverageid == 'S062')
        {
           var coverage =  window.open("../coverageForm/ProfessionalServices.html","","width=625,toolbar=no,scrollbars=yes");
        }
        else if(coverageid == 'S008')
        {
           var coverage =  window.open("../coverageForm/BuildingWrecking.html","","width=625,toolbar=no,scrollbars=yes");
        }
        else if(coverageid == 'S029')
        {
           var coverage =  window.open("../coverageForm/OverSpreySpillage.html","","width=625,toolbar=no,scrollbars=yes");
        }
        
        else if(coverageid == 'S075')
        {
           var coverage =  window.open("../coverageForm/SubsidenceOfLand.html","","width=625,toolbar=no,scrollbars=yes");
        }
        else if(coverageid == 'L238')
        {
           var coverage =  window.open("../coverageForm/ToxicMetals.html","","width=625,toolbar=no,scrollbars=yes");
        }
        else if(coverageid == 'L201')
        {
           var coverage =  window.open("../coverageForm/Eelse ifS.html","","width=625,toolbar=no,scrollbars=yes");
        }
        else if(coverageid == 'S156')
        {
           var coverage =  window.open("../coverageForm/MobileEquipment.html","","width=625,toolbar=no,scrollbars=yes");
        }
        
        else if(coverageid == 'S274')
        {
           var coverage =  window.open("../coverageForm/RoofingOperations.html","","width=625,toolbar=no,scrollbars=yes");
        }
        else if(coverageid == 'S277')
        {
           var coverage =  window.open("../coverageForm/SubcontractorWork.html","","width=625,toolbar=no,scrollbars=yes");
        }
   }
   else if(carrierid == 6)
   {
       // PenAmerica or PenStar carrier
        if(coverageid == 'S2107')
        {
           var coverage =  window.open("../coverageForm/LimitedExclusion.html","","width=625,toolbar=no,scrollbars=yes");
        }
        else if(coverageid == 'S2006')
        {
       // alert("coverageid : "+coverageid)
           var coverage =  window.open("../coverageForm/IndependentContractors.html","","width=625,toolbar=no,scrollbars=yes");
        }
        else if(coverageid == 'S2041')
        {
           var coverage =  window.open("../coverageForm/DesignatedClass.html","","width=625,toolbar=no,scrollbars=yes");
        }
        else if(coverageid == 'S2108')
        {
           var coverage =  window.open("../coverageForm/DefectExclusion.html","","width=625,toolbar=no,scrollbars=yes");
        }
        
        else if(coverageid == 'S2066')
        {
           var coverage =  window.open("../coverageForm/InjuryIndependantContractors.html","","width=625,toolbar=no,scrollbars=yes");
        }
        else if(coverageid == 'CG2186')
        {
           var coverage =  window.open("../coverageForm/EIFS.html","","width=625,toolbar=no,scrollbars=yes");
        }
   }
   return false;
//   else if(carrierid == 2)
//   {
//   }
    
}

function extractNumber(obj, decimalPlaces, allowNegative)
{
    var temp = obj.value;
    
    // avoid changing things if already formatted correctly
    var reg0Str = '[0-9]*';
    
    if (decimalPlaces > 0) 
    {
        reg0Str += '\\.?[0-9]{0,' + decimalPlaces + '}';
    } 
    else if (decimalPlaces < 0) 
    {
        reg0Str += '\\.?[0-9]*';
    }
    reg0Str = allowNegative ? '^-?' + reg0Str : '^' + reg0Str;
    reg0Str = reg0Str + '$';
    
    var reg0 = new RegExp(reg0Str);
    if (reg0.test(temp)) return true;
    
       // First replace all non numbers
    var reg1Str = '[^0-9' + (decimalPlaces != 0 ? '.' : '') + (allowNegative ? '-' : '') + ']';
    var reg1 = new RegExp(reg1Str, 'g');
    
    temp = temp.replace(reg1, '');
    
    if (allowNegative) 
    {
        // replace extra negative
        var hasNegative = temp.length > 0 && temp.charAt(0) == '-';
        var reg2 = /-/g;
        
        temp = temp.replace(reg2, '');
        if (hasNegative) 
            temp = '-' + temp;
    }
	
    if (decimalPlaces != 0) 
    {
        var reg3 = /\./g;
        var reg3Array = reg3.exec(temp);
        
        if (reg3Array != null) 
        {
            // keep only first occurrence of .
            //  and the number of places specified by decimalPlaces or the entire string if decimalPlaces < 0
            var reg3Right = temp.substring(reg3Array.index + reg3Array[0].length);
            reg3Right = reg3Right.replace(reg3, '');
            reg3Right = decimalPlaces > 0 ? reg3Right.substring(0, decimalPlaces) : reg3Right;
            temp = temp.substring(0,reg3Array.index) + '.' + reg3Right;
        }
    }
	
    obj.value = temp;
}

//for blokno other then "numbers"
function blockNonNumbers(obj, e, allowDecimal, allowNegative, allowDollar)
{
    var key;
    var isCtrl = false;
    var keychar;
    var reg;
    var allowCommas = false;
    
    if(allowDollar)
        allowCommas = true;

    if(window.event) 
    {
        key = e.keyCode;
        isCtrl = window.event.ctrlKey
    }
    else if(e.which) 
    {
        key = e.which;
        isCtrl = e.ctrlKey;
    }
	
    if (key != '$' && key != ',' && isNaN(key))
        return true;
    
    keychar = String.fromCharCode(key);
    
    // check for backspace or delete, or if Ctrl was pressed
    //alert(key + ', isCtrl = ' + isCtrl + ',key = ' + key)
    if (key == 8 || isCtrl)
    {
        return true;
    }
    
    reg = /\d/;
    
    var isFirstN = allowNegative ? keychar == '-' && obj.value.indexOf('-') == -1 : false;
    var isFirstD = allowDecimal ? keychar == '.' && obj.value.indexOf('.') == -1 : false;
    var isFirst$ = allowDollar ? keychar == '$' && obj.value.indexOf('$') == -1 : false;
    var isCommas = allowCommas ? keychar == ',' : false;
    
    //var isFirst$ = allowDollar ? keychar == ',' : false;
    
    return isFirstN || isFirstD || isFirst$ || isCommas || reg.test(keychar);
}
