﻿// JScript File

var msg="";
function emailCheck(emailStr,m,id,pop) {
msg="";
//if pop="1" or "" pop up msg
if(m=="undefined" || m=="" || m==null)
{m="";}
/* The following variable tells the rest of the function whether or not
to verify that the address ends in a two-letter country or well-known
TLD.  1 means check it, 0 means don't. */
if(emailStr.replace(/(^\s+)(\s+$)/, "").replace(" ","").length>0)
{
var checkTLD=1;

/* The following is the list of known TLDs that an e-mail address must end with. */

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;

/* The following pattern is used to check if the entered e-mail address
fits the user@domain format.  It also is used to separate the username
from the domain. */

var emailPat=/^(.+)@(.+)$/;

/* The following string represents the pattern for matching all special
characters.  We don't want to allow special characters in the address. 
These characters include ( ) < > @ , ; : \ " . [ ] */

var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";

/* The following string represents the range of characters allowed in a 
username or domainname.  It really states which chars aren't allowed.*/

var validChars="\[^\\s" + specialChars + "\]";

/* The following pattern applies if the "user" is a quoted string (in
which case, there are no rules about which characters are allowed
and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
is a legal e-mail address. */

var quotedUser="(\"[^\"]*\")";

/* The following pattern applies for domains that are IP addresses,
rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
e-mail address. NOTE: The square brackets are required. */

var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;

/* The following string represents an atom (basically a series of non-special characters.) */

var atom=validChars + '+';

/* The following string represents one word in the typical username.
For example, in john.doe@somewhere.com, john and doe are words.
Basically, a word is either an atom or quoted string. */

var word="(" + atom + "|" + quotedUser + ")";

// The following pattern describes the structure of the user

var userPat=new RegExp("^" + word + "(\\." + word + ")*$");

/* The following pattern describes the structure of a normal symbolic
domain, as opposed to ipDomainPat, shown above. */

var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");

/* Finally, let's start trying to figure out if the supplied address is valid. */

/* Begin with the coarse pattern to simply break up user@domain into
different pieces that are easy to analyze. */

var matchArray=emailStr.match(emailPat);

if (matchArray==null) {

/* Too many/few @'s or something; basically, this address doesn't
even fit the general mould of a valid e-mail address. */
msg=m+"Email address must include “@” and “.”";
addemailnote(msg,id);
if(pop!="0")
{
alert(msg);
}
return false;
}
var user=matchArray[1];
var domain=matchArray[2];

// Start by checking that only basic ASCII characters are in the strings (0-127).

for (i=0; i<user.length; i++) {
if (user.charCodeAt(i)>127) {
msg=m+"Ths username contains invalid characters.";
addemailnote(msg,id);
if(pop!="0")
{
alert(msg);
}

return false;
   }
}
for (i=0; i<domain.length; i++) {
if (domain.charCodeAt(i)>127) {
msg=m+"Ths domain name contains invalid characters.";
addemailnote(msg,id);
if(pop!="0")
{
alert(msg);
}

return false;
   }
}

// See if "user" is valid 

if (user.match(userPat)==null) {

// user is not valid
msg=m+"The username doesn't seem to be valid.";
addemailnote(msg,id);
if(pop!="0")
{
alert(msg);
}

return false;
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
host name) make sure the IP address is valid. */

var IPArray=domain.match(ipDomainPat);
if (IPArray!=null) {

// this is an IP address

for (var i=1;i<=4;i++) {
if (IPArray[i]>255) {
msg=m+"Destination IP address is invalid.";
addemailnote(msg,id);
alert(msg);
return false;
   }
}
return true;
}

// Domain is symbolic name.  Check if it's valid.
 
var atomPat=new RegExp("^" + atom + "$");
var domArr=domain.split(".");
var len=domArr.length;
for (i=0;i<len;i++) {
if (domArr[i].search(atomPat)==-1) {
msg=m+"The domain name does not seem to be valid.";
addemailnote(msg,id);
if(pop!="0")
{
alert(msg);
}

return false;
   }
}

/* domain name seems valid, but now make sure that it ends in a
known top-level domain (like com, edu, gov) or a two-letter word,
representing country (uk, nl), and that there's a hostname preceding 
the domain or country. */

if (checkTLD && domArr[domArr.length-1].length!=2 && 
domArr[domArr.length-1].search(knownDomsPat)==-1) {
msg=m+"The email address must end in a well-known domain or two letter " + "country abbreviation .";
addemailnote(msg,id);
if(pop!="0")
{
alert(msg);
}

return false;
}

// Make sure there's a host name preceding the domain.

if (len<2) {
msg=m+"This address is missing a hostname.";
addemailnote(msg,id);
if(pop!="0")
{
alert(msg);
}

return false;
}

// If we've gotten this far, everything's valid!
return true;
}
}

function addemailnote(msg,id)
{
    if(id!="undefined" || id!="" || id!=null)
    {
        var eid=document.getElementById(id);
        if(eid!=null)
        {
         eid.value=msg;
        }
    }
}
var dterror="";   
   
function validateDate(fld,c,p) 
{
 if(fld.value.replace(/(^\s+)(\s+$)/, "").replace(" ","").length>0)
 {
 
    
    var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
    var errorMessage = 'MM-DD-YYYY or MM/DD/YYYY only.  Invalid dates will not be accepted.';
    var dateStr=fld.value;
    if ((fld.value.match(RegExPattern)) && (fld.value!=''))
    {
    var predatePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{1,2})$/;
			var prematchArray = dateStr.match(predatePat);
			
			// Check if they only entered a 2 year date.
			if (prematchArray != null) {
				month = prematchArray[1]; 
				day = prematchArray[3];
				year = prematchArray[5];
				
				if(year > 45){
					dateStr = month.toString() + '/' + day.toString() + '/' + '19' + year.toString();
				}
				else{
					dateStr = month.toString() + '/' + day.toString() + '/' + '20' + year.toString();
				}
				}
    
    var today=new Date();
     //document.getElementById('txtCName1').value=today;
     var bd=new Date(dateStr);
     fld.value=dateStr;
     //bd.setDate();
    // alert(bd);
     if (c=="1" && bd>today)
       {dterror="Birth date can not be greater than today."; 
         if(p!='0')  {  alert(dterror);}
            
            }
       if (c=="2" && bd<today)
       {dterror="Due date must be greater than today.";
       if(p!='0') {alert(dterror);}} 
    } 
    else 
    {
     dterror=errorMessage;   if(p!='0') {alert(errorMessage);}
       // fld.focus();
    } 
  }
}   
 function checkph(t,m)
 {
    if(m=="undefined" || m=="" || m==null)
    {m="";}
    var re=/(^\d+$)|(^\d+\.\d+$)/;
    if (t.replace(/(^\s+)(\s+$)/, "").replace(" ","").length>0 && !t.match(re))
    {alert(m+"Phone number must be numeric only.");}
 }
 function ctn()
 {
        if (document.getElementById('ddlMetro').value.replace(/(^\s+)(\s+$)/, "").replace("--","").length<=0)
        { check+= "\n - Metro Area is required"; }
 }
 function vzip(id,m)
 {
    if(m=="undefined" || m=="" || m==null)
    {m="";}
    var re=/(^\d+$)|(^\d+\.\d+$)/;
    var zid=document.getElementById(id);
    if (zid!=null)
    {
     if(zid.value.replace(/(^\s+)(\s+$)/, "").replace(" ","").length>0 && zid.value.replace(/(^\s+)(\s+$)/, "").replace(" ","").length!=5 || !zid.value.match(re))
     {
      alert(m+"Zip Code  must be 5 numeric digits.");
     }
    }
 }
  function v4zip(id,m)
 {
    if(m=="undefined" || m=="" || m==null)
    {m="";}
     var re=/(^\d+$)|(^\d+\.\d+$)/;
     var zid=document.getElementById(id);
    if (zid!=null)
    {
     if(zid.value.replace(/(^\s+)(\s+$)/, "").replace(" ","").length>0 && (zid.value.replace(/(^\s+)(\s+$)/, "").replace(" ","").length!=4 || !zid.value.match(re)))
     {
      alert(m+"Extended Zip Code must be 4 numeric digits. ");
     }
    }
 }
 var phmsg="";
 function vph(v,m,p)
 {
// alert(v);
//  if(v.replace(/(^\s+)(\s+$)/, "").replace(" ","").replace("-","").length>0 && !v.replace(/(^\s+)(\s+$)/, "").replace(" ","").replace("-","").match(/(^\d+$)|(^\d+\.\d+$)/))
//  {
//   alert(m+"Phone number must be numeric and '-' only."); 
//  }
 if(m=="undefined" || m=="" || m==null)
 {
 m="";
 }
   
   // if(v.replace(/(^\s+)(\s+$)/, "").replace(" ","").length>0 && (!v.match(/^\d{3}-\d{3}-\d{4}$/) && !v.replace(/(^\s+)(\s+$)/, "").replace(" ","").replace(" ","").match(/^\d{3}-\d{3}-\d{4}EXT.\d+$/)))
   /*     if(v.replace(/(^\s+)(\s+$)/, "").replace(" ","").replace("(","").replace(")","").replace("-","").replace("-","").length!=10) 
     {
         if (p!="0")
         {
             if(m=="Home Phone:" || m=="Mobile:" || m=="Home Fax:")
             {
                alert(m+"Must be contain 10 numeric.");
             }
             else
             {
              alert(m+"Must be numeric and '-' or 'Ext.' only, Example:\n without 'Ext.':123-456-7890.\n with 'Ext.':123-456-7890 EXT. 1234.");
             }
         }
         else{phmsg+='\n- '+m+XHmsg[1].toString();}
     }*/
     var stripped = v.replace(/[\(\)\.\-\ ]/g, '').replace(/(^\s+)(\s+$)/, "").replace(" ","");
     if (stripped.length>0 && !(stripped.length == 10))
     {
     if (p!="0")
      {
            alert(m+"Must contain 10 numeric digits.");  
    }
         else{phmsg+='\n- '+m+XHmsg[3].toString();} 
    } 
 }
 
// function helpmsg(m)
// {
//  var lbh=document.getElementById('lblHelp');
//  if(lbh!=null)
//  {
////alert('t');
//   document.getElementById('tbhelp').style.display='block';
//   var br=navigator.appName;
// if(br=='Netscape')
// {
//   document.getElementById('hmsg').textContent=m;
// }
//  else{ document.getElementById('hmsg').innerText=m;}
//  
//   lbh.Text="801-897-8521";
//  }
// }
 function dishpmsg()
 {
  document.getElementById('tbhelp').style.display='none';
 }
function chklen(v,l,r,id)
{
//id='r'+id;
   
    if (v.length>l-r)
    {
     if(l-v.length<0)
     {document.getElementById('r'+id).style.color='red';document.getElementById('r'+id).value=v.length-l+' over limit';}
     else
     {
     document.getElementById('r'+id).style.color='black';document.getElementById('r'+id).value=l-v.length+' remaining';}
     document.getElementById('r'+id).style.display='block';
//    var obj = document.getElementById(id);
//    var wd=obj.style.width;
//    var posX = obj.offsetLeft;var posY = obj.offsetTop;
//    while(obj.offsetParent){
//    posX=posX+obj.offsetParent.offsetLeft;
//    posY=posY+obj.offsetParent.offsetTop;
//    if(obj==document.getElementsByTagName('body')[0]){break}
//    else{obj=obj.offsetParent;}
    //}
//     var setobj=document.getElementById('rtxtHA');
//     setobj.style.top=posY-10;
//     setobj.style.left=posX-100;
//  alert(posY);
    }
    else {document.getElementById('r'+id).value="";document.getElementById('r'+id).style.display='none';}
    
}
//var ol;
function dislmsg(id)
{
var svalue=document.getElementById(id).value;
chklen(svalue,250,50,id);
if(svalue.length<251)
{document.getElementById('r'+id).style.display='none';
//document.getElementById('ol').value=document.getElementById('ol').value.replace(id+';','');
}
else{document.getElementById('r'+id).style.display='block';
//document.getElementById('ol').value=document.getElementById('ol').value+id+';';
//document.getElementById(id).value=svalue.substring(0,250);alert(id+': Max length is 250.');
}
}
var existPH="";
var existEM="";
function getdata(m,f,pop)
{
existEM="";  
existPH="";
if(m.replace(/(^\s+)(\s+$)/, '').replace(' ','').replace('-','').length>0)
{
var fnn='';
var HttpRequest=false;
if(window.XMLHttpRequest)
{HttpRequest = new XMLHttpRequest();}
  else  // Other browsers  
  {HttpRequest = new ActiveXObject("Microsoft.XMLHTTP");}
      if (!HttpRequest) return;
      var url = "checkd.aspx?EM=" +m+"&f="+f;
      //alert(url);
      HttpRequest.open("GET",url);
      HttpRequest.onreadystatechange = function()
      {
          if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
          {
              var xml = HttpRequest.responseXML;
             fnn = xml.getElementsByTagName("header");
              //alert(fnn.length);  
              if(fnn.length>0)
              { 
              //document.getElementById('hexist').value="exist";
              //alert(fnn[0].firstChild.nodeValue);
              
                   if(f=="EM")
                   {
                     existEM='It appears you have already created a login with us please contact our office at 1-888-287-2471.' ;
                    if(pop!="0")
                        {
                           alert(existEM);
                        }
                   }
                   else {
                   existPH='It appears you have already created a login with us please contact our office at 1-888-287-2471.';
                   if(pop!="0")
                        {alert(existPH);
                      }
                  }
              } 
              else {document.getElementById('hexist').value="";} 
          }
      }  
      HttpRequest.send(null);
 }     
}
function PWshowError(m,f,pop)
{
existEM="";
existPH="";
if(m.replace(/(^\s+)(\s+$)/, '').replace(' ','').replace('-','').length>0 && msg.length<=0)
{
var fnn='';
var HttpRequest=false;
if(window.XMLHttpRequest)
{HttpRequest = new XMLHttpRequest();}
  else  // Other browsers  
  {HttpRequest = new ActiveXObject("Microsoft.XMLHTTP");}
      if (!HttpRequest) return;
      var url = "checkd.aspx?EM=" +m+"&f="+f;
      //alert(url);
      HttpRequest.open("GET",url);
      HttpRequest.onreadystatechange = function()
      {
          if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
          {
              var xml = HttpRequest.responseXML;
             fnn = xml.getElementsByTagName("header");
              //alert(fnn.length);  
              if(fnn.length<=0)
              { 
              //document.getElementById('hexist').value="exist";
              //alert(fnn[0].firstChild.nodeValue);
              
                   if(f=="EM")
                   {
                    existEM='The email address provided does not match our records.  Please enter the email address used for the Online Application.' ;
                    if(pop!="0")
                        {
                           alert(existEM);
                        }
                   }
                   else {
                   existPH='The email address provided does not match our records.  Please enter the email address used for the Online Application.';
                   if(pop!="0")
                        {alert(existPH);
                      }
                  }
              } 
              else {document.getElementById('hexist').value="";} 
          }
      }  
      HttpRequest.send(null);
 }     
}
var XHmsg=new Array();
function getHelpMsg()
{
var HttpRequest=false;

if(window.XMLHttpRequest)
{   HttpRequest = new XMLHttpRequest();

}
  else  // Other browsers  

  {
    HttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
 }

      if (!HttpRequest) return;

     // if (courseId < 1) return;

  var dgrtest=document.getElementById('dgrtest');

      var url = "getHelpmsg.aspx";
      HttpRequest.open("GET",url);
      HttpRequest.onreadystatechange = function()

      {
          if (HttpRequest.readyState == 4 && HttpRequest.status == 200)
          {
//alert('t');
              var xml = HttpRequest.responseXML;
              //dgrtest.datasorce=xml;

              var Msgs = xml.getElementsByTagName("header");
              var ids=xml.getElementsByTagName("new_id");
              for (i = 0; i < Msgs.length; i++)
              {
              
              var value  = Msgs[i].firstChild.nodeValue;
              var id = Msgs[i].attributes[0].value;
              XHmsg[id]=value;
              //alert(XHmsg[id]);  
              }
           }

      }  

      HttpRequest.send(null);

}
getHelpMsg();
function setHelpMsg(n)
{
 // var lbh=document.getElementById('lblHelp');
//  if(lbh!=null)
//  {
//alert(XHmsg);
//if (XHmsg=null || XHmsg.length<=0)
//{
// getHelpMsg();
//}
//alert(Hmsg[n]);
   document.getElementById('tbhelp').style.display='block';
   var br=navigator.appName;
 if(br=='Netscape')
 {
   document.getElementById('hmsg').textContent=XHmsg[n].toString();
 }
  else{ document.getElementById('hmsg').innerText=XHmsg[n].toString();}
  
//   lbh.Text="801-897-8521";
//  }
}
function disHelpMsg()
{document.getElementById('tbhelp').style.display='none';
}
function checkpw(v,m,p)
 {
 document.getElementById('hpwa').value='';
 if(m=="undefined" || m=="" || m==null)
{m="";}
     if(v.replace(/(^\s+)(\s+$)/, "").replace(" ","").length>0)
     {
          var pwa='';
          var re = /[0-9]/;
          if(!v.match(re)) 
          {
            pwa+= " one number (0-9)";
          }
          re = /[a-z]|[A-Z]/;
          if(!v.match(re)) 
          {
            pwa+=" one letter (a-z,A-Z)";
          }
         /* re = /[A-Z]/;
          if(!v.match(re)) {
            pwa+=" one uppercase letter (A-Z)";
          }*/
          if(v.length<8)
          {
          pwa+=" a minimum 8 characters";
          }
          if (pwa.length>1)
          {
            pwa=m+"Must be at least 8 characters, contain at least one letter and one digit.";
            if(p!='0')
            {
             alert(pwa);
            }
            document.getElementById('hpwa').value=pwa;
            return false;
          }
      }

 }