// AUTHOR: VALENTIN MALINOV - INTERPROGRAM, INC.
// COMPANY: Century National Insurance
// DESCRIPTION: Custom Validation Routines

function isInt(strThisInt) {
  var objIntRE = /^([0-9])*$/;
  return objIntRE.test(strThisInt);
}

function isValidZip(strThisZip) {
  var objZipRE = /^([0-9]{5})$/;
  return objZipRE.test(strThisZip);
}

function isBlankOrWhiteSpace(strThisTxt) {
  var objZipBlank = /^\s*$/;
  return objZipBlank.test(strThisTxt);
}

function isValidPersonName(strThisName) {
  var objPersonRE = /\w/;
  return objPersonRE.test(objPersonRE);
}

function isValidPhone(strThisPhone) {
  strThisPhone = strThisPhone.replace(/[(). -]/g, "");
  var objPhoneRE = /^([0-9]{10,}([ext. ]*([0-9]{1,5})?))$/;
  return objPhoneRE.test(strThisPhone);
}

function isValidEmail(strEmail) {
 var objEmailRE = /^[_\.0-9a-z-]+\@([0-9a-z][0-9a-z-]*\.)+([a-z]{2,4})+$/i;
 if (strEmail.match(objEmailRE)) return true;
 return false;
}

function isValidYearYYYY(strThisYear,intMinYear,intMaxYear,objFieldRef) {
  var objYearYYYRE = /^([0-9]{4})$/;
  var blnIsValidYear = objYearYYYRE.test(strThisYear);
  if(!blnIsValidYear)
    return false;
  if(arguments.length > 3) {
    if(strThisYear < intMinYear)
      objFieldRef.value = intMinYear;
    else if(strThisYear > intMaxYear)
      objFieldRef.value = intMaxYear;
    strThisYear = objFieldRef.value;
  }
  return !(strThisYear < intMinYear || strThisYear > intMaxYear);
}

function isAdobeInstalled()  {
  if((navigator.appName == "Microsoft Internet Explorer" &&
      navigator.appVersion.indexOf("Mac") == -1 &&
      navigator.appVersion.indexOf("3.1") == -1) ||
      (navigator.plugins && navigator.plugins["Adobe Acrobat"])
                         || navigator.plugins["Adobe Acrobat"])
      return true;
      return false;
}

function isValidSquareFootage(strThisSquareFootage,intMinSquareFootage,intMaxSquareFootage,objFieldRef) {
  var objSquareFootageRE = /^([0-9]+)$/;
  var blnIsValidSquareFootage = objSquareFootageRE.test(strThisSquareFootage);
  if(!blnIsValidSquareFootage)
    return false;
  if(arguments.length > 3) {
    if(strThisSquareFootage < intMinSquareFootage)
      objFieldRef.value = intMinSquareFootage;
    else if(strThisSquareFootage > intMaxSquareFootage)
      objFieldRef.value = intMaxSquareFootage;
    strThisSquareFootage = objFieldRef.value;
  }
  return !(strThisSquareFootage < intMinSquareFootage || strThisSquareFootage > intMaxSquareFootage);
}

function isValidInsuranceAmount(strThisInsAmount,objFieldRef,blnRoundToThousand) {
  var strThisInsAmount = strThisInsAmount.replace(/[., ]/g, "");
  objFieldRef.value = strThisInsAmount;
  var objInsAmountRE = /^([0-9]+)$/;
  var blnIsValidInsAmount = objInsAmountRE.test(strThisInsAmount);
  if(!blnIsValidInsAmount) 
    return false;
  if(arguments.length > 2 && blnRoundToThousand) {
    if(strThisInsAmount.length > 3) { // atleast thousand
      intThousandPos = strThisInsAmount.length - 3;
      strAnyNums = strThisInsAmount.substring((intThousandPos));
      objThousandsRE = /[1-9]+/;
      if(strAnyNums.match(objThousandsRE)) {
       strThisInsAmount = (((strThisInsAmount.substring(0, intThousandPos) + "000") * 1) + 1000);
       objFieldRef.value = strThisInsAmount;
      }
    }
  }
  return true;
}

function isValidEarthquakeDate(dtmObjThisDate,dtmDateNow) { 
  blnObjValidDate = CheckDate(dtmObjThisDate);
  if(blnObjValidDate != null) {
    dtmPassedDate = blnObjValidDate;    
    dtmNow = getDateFromFormat(dtmDateNow,"MM/dd/yyyy");
    dtmDateNow = new Date(dtmNow.getYear(),dtmNow.getMonth(),dtmNow.getDate());
    if(dtmPassedDate > dtmDateNow)
      return false;
    return true;
  }
}

// VMalinov - Custom Validation Routines

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
  var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
  if(a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_findObj(n, d) { //v3.0
  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=MM_findObj(n,d.layers[i].document); return x;
}
function MM_swapImage() { //v3.0
 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
 if((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}