/* ======================================================================

     JavaScript Source File -- Created with NetObjects ScriptBuilder

NAME: checkform2.js

AUTHOR: Bear Swamp Lumber Co., Inc.

PURPOSE: Check various profile1 fields.  Modify as needed using code between start 
        and end, modifying as needed

====================================================================== */
function checkform (profile1){
var splitArray = new Array();
  errormsg='<html><head><link rel=stylesheet href=css/style2.css><title>Warning</title></head><body><table align=center cellspacing=2 cellpadding=3 border=0><tr valign=top><td><img src=images/formwarn.png hspace=4></td><td><p class=sidebar><b>';
  errormsg +='The Following Errors Occured<br>_____________________________<br><br>';
  errcall=0;
  // ** first name **
  if (profile1.first.value == "") {
  errormsg+='Please enter your First Name.<br>';
    profile1.first.focus();
	errcall=errcall+1;
  }
  
  // ** last name **
    if (profile1.last.value == "") {
  errormsg+='Please enter your Last Name.<br>';
    profile1.last.focus();
	errcall=errcall+1;
  }

 
   // ** street **
  if (profile1.street.value == "") {
	errormsg+='Please enter your Street Address.<br>';
    profile1.street.focus();
	errcall=errcall+1;
  }
  
 
       // ** city **
  if (profile1.city.value == "") {
	errormsg+='Please enter your City.<br>';
    profile1.city.focus();
	errcall=errcall+1;
  }

          // ** state **
  if (profile1.state.value == "") {
	errormsg+='Please select a State.<br>';
    profile1.state.focus();
	errcall=errcall+1;
  }
  

 
      // ** zip **
  if (profile1.zip.value == "") {
	errormsg+='Please enter your Zip Code.<br>';
    profile1.zip.focus();
	errcall=errcall+1;
  }
  
          // ** phones **
  if (profile1.home_tele.value == "" && profile1.work_tele.value == "" && profile1.cell_tele.value == "") {
	errormsg+='Please enter a Phone Number.<br>';
    profile1.home_tele.focus();
	profile1.work_tele.focus();
	profile1.cell_tele.focus();
	errcall=errcall+1;
  }
  
  
       // ** primary phone **
  if (profile1.primary.value == "") {
	errormsg+='No Primary Phone has been selected.<br>';
    profile1.primary.focus();
	errcall=errcall+1;
  }

    // ** Email **
  if (profile1.email.value == "") {
	errormsg+='Please enter your Email Address.<br>';
    profile1.email.focus();
	errcall=errcall+1;
  }
  
  if (profile1.email.value != "") {
  		if(!check_email(profile1.email.value)){
  		errormsg+='Please enter a correct Email Address.<br>';
		errcall=errcall+1;
		}
	}
	
	       // ** date of birth **
  if (profile1.xdobmonth.value == "" || profile1.xdobday.value == "" || profile1.xdobyear.value == "") {
	errormsg+='No Date of Birth Provided.<br>';
    profile1.xdobmonth.focus();
	profile1.xdobday.focus();
	profile1.xdobyear.focus();
	errcall=errcall+1;
  }
   
      // ** marital status**
  if (profile1.marital.value == "") {
	errormsg+='Please enter your Marital Status.<br>';
    profile1.marital.focus();
	errcall=errcall+1;
  }
  
    if (profile1.marital.value == "married" || profile1.marital.value == "Married") {
	if (profile1.spouse_first.value == "") {
	errormsg+='Please enter your Spouse First Name.<br>';
    profile1.spouse_first.focus();
	errcall=errcall+1;
  }
  if (profile1.spouse_last.value == "") {
	errormsg+='Please enter your Spouse Last Name.<br>';
    profile1.spouse_last.focus();
	errcall=errcall+1;
  }
  }
  
  
  

  // ** open alert on error **
  if (errcall !=0){
  errormsg+='_____________________________<br><br>Please correct them before proceeding.<br>';
  errormsg +='</b></p></td></tr></table><br><div align=center><form><input type="button" value="Close window" onClick="window.close()"></form></div></body></html>';
errorwindow=window.open("","","width=300,height=350,screenX=100,screenY=150,left=100,top=150")
errorwindow.document.write(errormsg);
errorwindow.document.close();
errorwindow.document.bgColor="white";
  return false;
  }
  else {
  return true ;
  }
}

function checkform2 (profile2){
var splitArray = new Array();
  errormsg='<html><head><link rel=stylesheet href=css/style2.css><title>Warning</title></head><body><table align=center cellspacing=2 cellpadding=3 border=0><tr valign=top><td><img src=images/formwarn.png hspace=4></td><td><p class=sidebar><b>';
  errormsg +='The Following Errors Occured<br>_____________________________<br><br>';
  errcall=0;

  if (profile2.first.value != "" || profile2.last.value != "") {
	       // ** date of birth **
  if (profile2.xdobmonth.value == "" || profile2.xdobday.value == "" || profile2.xdobyear.value == "") {
	errormsg+='No Date of Birth Provided.<br>';
    profile2.xdobmonth.focus();
	profile2.xdobday.focus();
	profile2.xdobyear.focus();
	errcall=errcall+1;
  }
  }
  
    // ** open alert on error **
  if (errcall !=0){
  errormsg+='_____________________________<br><br>Please correct them before proceeding.<br>';
  errormsg +='</b></p></td></tr></table><br><div align=center><form><input type="button" value="Close window" onClick="window.close()"></form></div></body></html>';
errorwindow=window.open("","","width=300,height=350,screenX=100,screenY=150,left=100,top=150")
errorwindow.document.write(errormsg);
errorwindow.document.close();
errorwindow.document.bgColor="white";
  return false;
  }
  else {
  return true ;
  }
}


function check_email(e) {
ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

for(i=0; i < e.length ;i++){
if(ok.indexOf(e.charAt(i))<0){ 
return (false);
}	
} 

if (document.images) {
re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (!e.match(re) && e.match(re_two)) {
return (-1);		
} 

}

}

function Mod10(n) {
var reversed = Reverse(n);
var total = AddedTogether(reversed);
if(total % 10 > 0) { return 0; }
return 1;
} // Mod10()

function AddedTogether(number) {
var n = 0;
for(i = 0; i < number.length; i++) {
	var s = number.substr(i,1);
	var si = parseInt(s,10);
	if(i % 2 > 0) {
		var ii = si * 2;
		if(ii < 10) { n += ii; }
		else {
			var ss = ' ' + ii;
			for(xi = 1; xi < ss.length; xi++) {
				var xs = ss.substr(xi,1);
				var xsi = parseInt(xs,10);
				n += xsi;
				} // for
			} // else
		} // if
	else { n += si; }
	} // for
return n;
} // AddedTogether()

function Reverse(number) {
var n = '';
for(i = number.length; i >= 0; i--) { n += number.substr(i,1); }
return n;
} // Reverse()

function checkform3 (outrefer){
var splitArray = new Array();
  errormsg='<html><head><link rel=stylesheet href=css/style2.css><title>Warning</title></head><body><table align=center cellspacing=2 cellpadding=3 border=0><tr valign=top><td><img src=images/formwarn.png hspace=4></td><td><p class=sidebar><b>';
  errormsg +='The Following Errors Occured<br>_____________________________<br><br>';
  errcall=0;
  // ** user id **
  if (outrefer.newrefid.value == "") {
  errormsg+='Please Select A Name.<br>';
    outrefer.newrefid.focus();
	errcall=errcall+1;
  }
  
  // ** group **
    if (outrefer.newgroupref.value == "") {
  errormsg+='Please Select A Group.<br>';
    outrefer.newgroupref.focus();
	errcall=errcall+1;
  }

 
   // ** comment **
  if (outrefer.myrefcomment.value == "") {
	errormsg+='Please Enter A Referal Comment.<br>';
    outrefer.myrefcomment.focus();
	errcall=errcall+1;
  }
  
 

  // ** open alert on error **
  if (errcall !=0){
  errormsg+='_____________________________<br><br>Please correct them before proceeding.<br>';
  errormsg +='</b></p></td></tr></table><br><div align=center><form><input type="button" value="Close window" onClick="window.close()"></form></div></body></html>';
errorwindow=window.open("","","width=300,height=350,screenX=100,screenY=150,left=100,top=150")
errorwindow.document.write(errormsg);
errorwindow.document.close();
errorwindow.document.bgColor="white";
  return false;
  }
  else {
  return true ;
  }
}
