function DateAsMMDDYYYY() {
   var mSep = "/";
   d = new Date(); 
   nDay = d.getDate();
   nMonth = 1 + d.getMonth();
   nYear = d.getYear();
   if (nYear < 2000) {
      nYear = nYear + 1900;
   }
   return nMonth + mSep + nDay + mSep + nYear;
}
function isBlank(s,message) {
   if ((s.value.length > 0) && (s.value != null) && (s.value != "")) {
      return false;
   }
   alert(message);
   s.focus();
   return true;
}
function isDigit (c) {
   return((c >= "0") && (c <= "9"))
}
function isEmail (s,message) {
   var i,ii;
   var j;
   var k,kk;
   var jj;
   var len;
   if (isBlank(s,message)) {
      s.focus();
      return false;
   }
   if (s.value.length >0) {
      i=s.value.indexOf("@");
      ii=s.value.indexOf("@",i+1);
      j=s.value.indexOf(".",i);
      k=s.value.indexOf(",");
      kk=s.value.indexOf(" ");
      jj=s.value.lastIndexOf(".")+1;
      len=s.value.length;
      if ((i>0) && (j>(1+1)) && (k==-1) && (ii==-1) && (kk==-1) &&
          (len-jj >=2) && (len-jj<=3)) {
      } else {
         alert(message)
         s.focus();        
         return false;
      }
   }
   return true;
}
function isInteger (s,message) {
   var i;
   for (i = 0; i < s.length; i++) {
      var c = s.charAt(i);
      if (!isDigit(c)) {
         alert(message);         
         return false;
      }
   }
   return true;
}
function isPhone (s,message) {
   if (s.value.length > 10) {
      s.value = numericize(s.value);
   }
   if ((s.value.charAt(0) == '0') || (s.value.charAt(0) == '1')) {
      alert(message);
      s.focus();
      return false;
   }
   if (s.value.length == 10) {
      if (isInteger(s.value,message)) {
         return true;
      } else {
         s.focus();
         return false;
      }
   } else {
      alert(message);
      s.focus();
      return false;
   }
   return true;
}
function isSelected (s,message) {
   if (s.selectedIndex==0) {
      alert(message);
      s.focus();
      return false;
   }
   return true;
}
function isSSN (s,message) {
   var x,i;
   if (isBlank(s,message)) {
      s.focus();
      return false;
   }
   if (s.value.length == 11) {
      s.value=numericize(s.value);
   }
   if (s.value.length == 9) {
      if (isInteger(s.value,message)) {
         return true;
      } else {
         s.focus();
         return false;
      }
   }

   alert(message);
   s.focus();
   return false;
}
function isZipCode (s,message) {
   var x,i;
   if (s.value.length == 5) {
      if (isInteger(s.value,message)) {
         s.value=s.value+"0000";
         return true;
      } else {
         s.focus();
         return false;
      }
   }
   if (s.value.length == 10) {
      s.value=numericize(s.value);
   }
   if (s.value.length == 9) {
      if (isInteger(s.value,message)) {
         return true;
      } else {
         s.focus();
         return false;
      }
   }
   alert(message);
   s.focus();
   return false;
}
function MM_findObj(n, d) {
  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_openBrWindow(theURL,winName,features) {
  window.open(theURL,winName,features);
}
function MM_preloadImages() {
  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_swapImage() {
  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];}
}
function MM_swapImgRestore() {
  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 numericize(s) {
   var i,j;
   j="";
   for (i=0;i<s.length;i++) {
      if (isDigit(s.charAt(i))) {
         j=j+s.charAt(i);
      }
   }
   return j;
}
function PrinterFriendly(MyWindow) {
   var BodyObject = document.body.all;
   var count = BodyObject.length;
   var i,labels=0,counter=0;
   var d = DateAsMMDDYYYY();
   var PrinterString = "<HTML><HEAD><TITLE>Vision Management - Service Request</TITLE></HEAD><BODY><STRONG>Vision Management Service Request</STRONG><BR><HR>";
   PrinterString = PrinterString + "Thank you for your inquiry. We will be sending you a confirmation e-mail shortly.<BR><BR>Following is a summary of your service request made on "+d+".";
   for (i=0;i<count;i++) {
      var myObject = BodyObject[i];
      if (myObject.tagName == "SPAN" && myObject.id == "header") {
         PrinterString = PrinterString + "<BR><BR><STRONG>" + myObject.innerText + "</STRONG>&nbsp;&nbsp;";
         labels++;
      }
      if (myObject.tagName == "INPUT" || myObject.tagName == "TEXTAREA") {
         if (myObject.value != "" && myObject.value != " " && myObject.value != null && myObject.id !="OM") {
            if (myObject.tagName == "TEXTAREA") {
               PrinterString = PrinterString + "<PRE>";
               PrinterString = PrinterString + myObject.value + "&nbsp;&nbsp;";
               PrinterString = PrinterString + "</PRE>";
            } else {
               PrinterString = PrinterString + myObject.value + "&nbsp;&nbsp;";
            }
         }
      }
      if (myObject.tagName == "SELECT") {
         PrinterString = PrinterString + myObject.value;
      }
      if (labels==5) {
         counter++;
      }
      if (counter>=10) {
         break;
      }
   }
   PrinterString = PrinterString
   + "<BR><HR>"
   + "<BR>If you have any questions about this service request, please contact our customer service desk.<BR><BR>"
   + "<TABLE><TR><TD WIDTH='75' VALIGN=top>by phone:</TD><TD WIDTH='100' VALIGN=top>860/242-4131</TD></TR><TR><TD VALIGN=top>by e-mail:</TD><TD VALIGN=top>support@visionmgmt.com</TD></TR><TR><TD VALIGN=top>by fax:</TD><TD VALIGN=top>860/242-4166</TD></TR><TR><TD VALIGN=top>by mail:</TD><TD VALIGN=top>Vision Management, LLC<BR>PO Box 7382<BR>Bloomfield, CT  06002-7382</TD></TR></TABLE>"
   + "<BR>Thank you,<BR><BR><BR><BR>"
   + "Vision Management, LLC<BR>"
   + "<I>Focused on your property needs.</I><BR>"
   + "http://www.visionmgmt.com<BR>"
   + "</BODY></HTML>";
   msgWindow=window.open("","MyWindow","toolbar=yes,menubar=yes,status,scrollbars,resizable");
   if (msgWindow.opener == null) msgWindow.opener = self;
   msgWindow.document.write(PrinterString);
}
function RequestNew() {
   document.request.reset();
}
function RequestSend() {
   with (document.request) {
      if (!isEmail(msgFrom,'Sorry! Please enter a valid e-mail address.')) {
         return;
      }
      if (!isSelected(msgSubj,'Sorry! Please indicate an action item.')) {
         return;
      }
      if (setDescription(msgSubj,msgBody)) {
         return;
      }
   }
   document.request.submit();
}
function setDescription(Subject, Description) {
   switch (Subject.value) {
      case "Other." :
         if (Description.value.length == 0) {
            alert('Please describe the problem.');
            Description.focus();
            return true;
         } else {
            return false;
         }
      case "Please change my address." :
         if (Description.value.length < 20) {
            alert('Please tell us your previous and current addresses.');
            Description.focus();
            return true;
         } else {
            return false;
         }
      case "Did you receive my last payment?" :
         if (Description.value.length < 8) {
            alert('Please tell us the Check #, Check Date, and Check Amount.');
            Description.focus();
            return true;
         } else {
            return false;
         }
      default:
         return false;
   }
}
