// JavaScript Document

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) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); 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];}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function MM_showHideLayers() { //v9.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) 
  with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
function totalPayments() {
	var payment = document.donations.pay_amount.value;
	var number = document.donations.number_payments.value;
	var totalAmt = payment * number;
	document.donations.amount.value = totalAmt;
}

function calcHeight()
{
  //find the height of the internal page
  var the_height=document.getElementById('the_iframe').contentWindow.document.body.scrollHeight;

  //change the height of the iframe
  document.getElementById('the_iframe').height=the_height;
}

function isZip(s) {
	// Check for correct zip code
	var reZip = new RegExp(/(^\d{5}$)|(^\d{5}-\d{4}$)/);

	if (!reZip.test(s)) {
		return false;
	}
	return true;
}
function isValidEmail(email){ 
    var RegExp = /^((([a-z]|[A-Z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+(\.([a-z]|[A-Z]|[0-9]|!|#|$|%|&|'|\*|\+|\-|\/|=|\?|\^|_|`|\{|\||\}|~)+)*)@((((([a-z]|[A-Z]|[0-9])([a-z]|[A-Z]|[0-9]|\-){0,61}([a-z]|[A-Z]|[0-9])\.))*([a-z]|[A-Z]|[0-9])([a-z]|[A-Z]|[0-9]|\-){0,61}([a-z]|[A-Z]|[0-9])*\.)[\w]{2,4}|(((([0-9]){1,3}\.){3}([0-9]){1,3}))|(\[((([0-9]){1,3}\.){3}([0-9]){1,3})\])))$/ 
    if(RegExp.test(email)){ 
        return true; 
    }else{ 
        return false; 
    } 
} 

function donorValidate(step) {
	var test = 0;
	var i;
	
	
	if(step == 1) {
		var checked = 0;
		var radios = document.donations.donation_type;
		for(i=0; i<radios.length; i++){
        	if(radios[i].checked) { var checked = 1; }
    	}
		if(checked == 1) {
			return true;
		}
		else {
			alert('Please select a donation type.');
			return false;
		}
	}
	else if(step == 2) {
		var checked = 0;
		var radios = document.donations.gift;
		for(i=0; i<radios.length; i++){
        	if(radios[i].checked) { var checked = 1; }
    	}
		if(checked == 1) {
			return true;
		}
		else {
			alert('Please indicate whether this gift is in memory or honor of a person or pet.');
			return false;
		}
	}
	else if(step == 3) {
		var donationType, gift;
		donationType = document.donations.donation_type;
		gift = document.donations.gift;
		if(donationType.value == 'one' && gift.value == 'yes') {
			var radios, errors='', checked=0;
			radios = document.donations.gift_type;
			for(i=0; i<radios.length; i++){
				if(radios[i].checked) { var checked = 1; }
			}
			if(checked != 1) {
				errors += '\n  - Gift Type';
			}
			if(document.donations.amount.value.length < 1 || isNaN(document.donations.amount.value)) {
				errors += '\n  - Gift Amount';
			}
			if(document.donations.honoree.value.length < 2) {
				errors += '\n  - Honoree(s)';
			}
			if(document.donations.ack_name.value.length < 3) {
				errors += '\n  - Acknowledgement Name';
			}
			if(document.donations.ack_address.value.length < 5) {
				errors += '\n  - Acknowledgement Address';
			}
			if(document.donations.ack_city.value.length < 2) {
				errors += '\n  - Acknowledgement City';
			}
			if(document.donations.ack_state.value == 'NULL') {
				errors += '\n  - Acknowledgement State';
			}
			if(!isZip(document.donations.ack_zip.value)) {
				errors += '\n  - Acknowledgement Zip';
			}
			if(errors == '') { return true; }
			else {
				var error = 'The following items are required before continuing,\n';
				error += 'please take a moment to verify their accuracy:\n'+errors;
				alert(error);
				return false;
			}
		}
		else if(donationType.value == 'one' && gift.value == 'no') {
			if(document.donations.amount.value.length < 1) {
				alert('Please input your donation amount.');
				return false;
			}
			else if(isNaN(document.donations.amount.value)) {
				alert('Please make sure that your donation amount is a number.');
				return false;
			}
			else { return true; }
		}
		else if(donationType.value == 'monthly') {
			if(document.donations.amount.value.length < 1) {
				alert('Please input your donation amount.');
				return false;
			}
			else if(isNaN(document.donations.amount.value)) {
				alert('Please make sure that your donation amount is a number.');
				return false;
			}
			else { return true; }
		}
		
	}
	else if(step == 4) {
		var radios, errors='', checked=0;
		radios = document.donations.cc_type;
		var currDate = new Date();
		var currYear = currDate.getFullYear();
		var currMonth = currDate.getMonth();
		var compYear = '20'+document.donations.cc_year.value;
		for(i=0; i<radios.length; i++){
			if(radios[i].checked) { var checked = 1; }
		}
		if(document.donations.first_name.value.length < 2) {
			errors += '\n  - First Name';
		}
		if(document.donations.last_name.value.length < 2) {
			errors += '\n  - Last Name';
		}
		if(checked != 1) {
			errors += '\n  - Card Type';
		}
		if(document.donations.cc_number.value.length < 16) {
			errors += '\n  - Credit Card Number';
		}
		if(document.donations.cc_month.value.length != 2 || isNaN(document.donations.cc_month.value)) {
			errors += '\n  - Expiration: Month (2 digits)';
		}
		if(document.donations.cc_year.value.length != 2 || isNaN(document.donations.cc_year.value)) {
			errors += '\n  - Expiration: Year (2 digits)';
		}
		if(document.donations.cc_year.value.length == 2 && !isNaN(document.donations.cc_year.value) && document.donations.cc_month.value.length == 2 && !isNaN(document.donations.cc_month.value)) {
			if(compYear < currYear) {
				errors += '\n  - Expired Card';
			}
			else if(document.donations.cc_month.value < currMonth && compYear == currYear) {
				errors += '\n  - Expired Card';
			}
		}
		if(document.donations.cc_cvm.value.length != 3 || isNaN(document.donations.cc_cvm.value)) {
			errors += '\n  - Card CVM code';
		}
		if(document.donations.bill_address.value.length < 5 ) {
			errors += '\n  - Billing Address';
		}
		if(document.donations.bill_city.value.length < 2 ) {
			errors += '\n  - Billing City';
		}
		if(document.donations.bill_state.value == 'NULL' ) {
			errors += '\n  - Billing State';
		}
		if(!isZip(document.donations.bill_zip.value)) {
			errors += '\n  - Billing Zip';
		}
		if(!isValidEmail(document.donations.bill_email.value)) {
			errors += '\n  - Email Address';
		}
		if(errors == '') { return true; }
		else {
			var error = 'The following items are required before continuing,\n';
			error += 'please take a moment to verify their accuracy:\n'+errors;
			alert(error);
			return false;
		}
	}
	else if(step == 5) {
	}
	else {
	}
}

function evRegValidate(regCost) {
	var errors='';
	if(document.class_registration.owner_name.value.length < 2) {
		errors += "\n  - Owner's Name";
	}
	if(document.class_registration.street_address.value.length < 5) {
		errors += "\n  - Street Address";
	}
	if(document.class_registration.city.value.length < 2) {
		errors += "\n  - City";
	}
	if(document.class_registration.state.value == "NULL") {
		errors += "\n  - State";
	}
	if(!isZip(document.class_registration.zip.value)) {
		errors += "\n  - Zip";
	}
	if(document.class_registration.phone.value.length < 7) {
		errors += "\n  - Phone";
	}
	if(!isValidEmail(document.class_registration.email.value)) {
		errors += "\n  - Email";
	}
	if(document.class_registration.dog_name.value.length < 2) {
		errors += "\n  - Dog's Name";
	}
	if(document.class_registration.breed.value.length < 2) {
		errors += "\n  - Breed";
	}
	var checked = 0;
	var radios = document.class_registration.sex;
	for(i=0; i<radios.length; i++){
  	if(radios[i].checked) { var checked = 1; }
  }
	if(checked == 1) {
	}
	else {
		errors += "\n  - Gender";
	}
	var checked = 0;
	var radios = document.class_registration.spay_neuter;
	for(i=0; i<radios.length; i++){
  	if(radios[i].checked) { var checked = 1; }
  }
	if(checked == 1) {
	}
	else {
		errors += "\n  - Is your pet Spayed/Neutered?";
	}
	if(document.class_registration.dob_month.value == "NULL" || isNaN(document.class_registration.dob_year.value) || document.class_registration.dob_year.value.length < 4 || document.class_registration.dob_year.value == "    " ) {
		errors += "\n  - Date of Birth (Month, YYYY)";
	}
	var checked = 0;
	var radios = document.class_registration.ahnm_adopter;
	for(i=0; i<radios.length; i++){
  	if(radios[i].checked) { var checked = 1; }
  }
	if(checked == 1) {
	}
	else {
		errors += "\n  - Are you an Animal Humane Adopter?";
	}
	if(document.class_registration.ahnm_adopter[0].checked) {
		if(document.class_registration.shelter_id.value.length < 2) {
			errors += "\n  - Shelter ID #";
		}
		if(document.class_registration.adopt_month.value == "NULL" || isNaN(document.class_registration.adopt_year.value) || document.class_registration.adopt_year.value.length < 4 || document.class_registration.adopt_year.value == "    " ) {
			errors += "\n  - Adoption Date (Month, YYYY)";
		}
	}
	if(!document.class_registration.behavior1a.checked && !document.class_registration.behavior1b.checked && !document.class_registration.behavior1c.checked && !document.class_registration.behavior1d.checked && !document.class_registration.behavior1e.checked && !document.class_registration.behavior1f.checked && !document.class_registration.behavior1g.checked && !document.class_registration.behavior1h.checked && !document.class_registration.behavior1i.checked && document.class_registration.behavior1o.value.length < 2) {
		errors += "\n  - Select/describe your dogs behavior around other dogs";
	}
	if(!document.class_registration.behavior2a.checked && !document.class_registration.behavior2b.checked && !document.class_registration.behavior2c.checked && !document.class_registration.behavior2d.checked && !document.class_registration.behavior2e.checked && !document.class_registration.behavior2f.checked && !document.class_registration.behavior2g.checked && !document.class_registration.behavior2h.checked && !document.class_registration.behavior2i.checked && document.class_registration.behavior2o.value.length < 2) {
		errors += "\n  - Select/describe your dogs behavior around people";
	}
	var checked = 0;
	var radios = document.class_registration.behavior3;
	for(i=0; i<radios.length; i++){
  	if(radios[i].checked) { var checked = 1; }
  }
	if(checked == 1) {
	}
	else {
		errors += "\n  - Has your dog bitten another dog?";
	}
	if(document.class_registration.behavior3[1].checked) {
		if(document.class_registration.behavior3o.value.length < 5) {
			errors += "\n  - Please describe when your dog bit another dog";
		}
	}
	var checked = 0;
	var radios = document.class_registration.behavior4;
	for(i=0; i<radios.length; i++){
  	if(radios[i].checked) { var checked = 1; }
  }
	if(checked == 1) {
	}
	else {
		errors += "\n  - Has your dog bitten a person?";
	}
	if(document.class_registration.behavior4[1].checked) {
		if(document.class_registration.behavior4o.value.length < 5) {
			errors += "\n  - Please describe when your dog bit a person";
		}
	}
	if(document.class_registration.how_hear.value.length < 2) {
		errors += "\n  - Please tell us how you heard about our training";
	}
	if(document.class_registration.bill_name.value.length < 2) {
		errors += "\n  - Billing Name";
	}
	if(document.class_registration.bill_address.value.length < 5) {
		errors += "\n  - Billing Address";
	}
	if(document.class_registration.bill_city.value.length < 2) {
		errors += "\n  - Billing City";
	}
	if(document.class_registration.bill_state.value == "NULL") {
		errors += "\n  - Billing State";
	}
	if(!isZip(document.class_registration.bill_zip.value)) {
		errors += "\n  - Billing Zip";
	}
	var checked = 0;
	var radios = document.class_registration.cc_type;
	for(i=0; i<radios.length; i++){
  	if(radios[i].checked) { var checked = 1; }
  }
	if(checked == 1) {
	}
	else {
		errors += "\n  - Credit Card Type";
	}
	if(document.class_registration.cc_number.value.length < 16) {
		errors += '\n  - Credit Card Number';
	}
	var currDate = new Date();
	var currYear = currDate.getFullYear();
	var currMonth = currDate.getMonth()+1;
	var compYear = '20'+document.class_registration.cc_year.value;
	if(document.class_registration.cc_month.value.length != 2 || isNaN(document.class_registration.cc_month.value)) {
		errors += '\n  - Expiration: Month (2 digits)';
	}
	if(document.class_registration.cc_year.value.length != 2 || isNaN(document.class_registration.cc_year.value)) {
		errors += '\n  - Expiration: Year (2 digits)';
	}
	if(document.class_registration.cc_year.value.length == 2 && !isNaN(document.class_registration.cc_year.value) && document.class_registration.cc_month.value.length == 2 && !isNaN(document.class_registration.cc_month.value)) {
		if(compYear < currYear) {
			errors += '\n  - Expired Card';
		}
		else if(document.class_registration.cc_month.value < currMonth && compYear == currYear) {
			errors += '\n  - Expired Card';
		}
	}
	if(document.class_registration.cc_cvm.value.length != 3 || isNaN(document.class_registration.cc_cvm.value)) {
		errors += '\n  - Card CVM code';
	}
	
	if(!document.class_registration.informed_consent.checked) {
		errors += '\n  - You must read and agree to the Informed Consent Waiver';
	}


	if(errors == '') {
		if(document.class_registration.ahnm_adopter[0].checked) {
			document.class_registration.amount.value = regCost;
		}
		return true;
	}
	else {
		var error = 'The following items are required before continuing,\n';
		error += 'please take a moment to verify their accuracy:\n'+errors;
		alert(error);
		return false;
	}
}


function evRegValidateSpec() {
	var errors='';
	if(document.class_registration.owner_name.value.length < 2) {
		errors += "\n  - Owner's Name";
	}
	if(document.class_registration.street_address.value.length < 5) {
		errors += "\n  - Street Address";
	}
	if(document.class_registration.city.value.length < 2) {
		errors += "\n  - City";
	}
	if(document.class_registration.state.value == "NULL") {
		errors += "\n  - State";
	}
	if(!isZip(document.class_registration.zip.value)) {
		errors += "\n  - Zip";
	}
	if(document.class_registration.phone.value.length < 7) {
		errors += "\n  - Phone";
	}
	if(!isValidEmail(document.class_registration.email.value)) {
		errors += "\n  - Email";
	}
	if(document.class_registration.dog_name.value.length < 2) {
		errors += "\n  - Dog's Name";
	}
	if(document.class_registration.breed.value.length < 2) {
		errors += "\n  - Breed";
	}
	var checked = 0;
	var radios = document.class_registration.sex;
	for(i=0; i<radios.length; i++){
  	if(radios[i].checked) { var checked = 1; }
  }
	if(checked == 1) {
	}
	else {
		errors += "\n  - Gender";
	}
	var checked = 0;
	var radios = document.class_registration.spay_neuter;
	for(i=0; i<radios.length; i++){
  	if(radios[i].checked) { var checked = 1; }
  }
	if(checked == 1) {
	}
	else {
		errors += "\n  - Is your pet Spayed/Neutered?";
	}
	if(document.class_registration.dob_month.value == "NULL" || isNaN(document.class_registration.dob_year.value) || document.class_registration.dob_year.value.length < 4 || document.class_registration.dob_year.value == "    " )
	{
		errors += "\n  - Date of Birth (Month, YYYY)";
	}
	var checked = 0;
	var radios = document.class_registration.ahnm_adopter;
	for(i=0; i<radios.length; i++){
  	if(radios[i].checked) { var checked = 1; }
  }
	if(checked == 1) {
	}
	else {
		errors += "\n  - Is this an Animal Humane Adopter?";
	}
	if(document.class_registration.ahnm_adopter[0].checked) {
		if(document.class_registration.shelter_id.value.length < 2) {
			errors += "\n  - Shelter ID #";
		}
		if(document.class_registration.adopt_month.value == "NULL" || isNaN(document.class_registration.adopt_year.value) || document.class_registration.adopt_year.value.length < 4 || document.class_registration.adopt_year.value == "    " ) {
			errors += "\n  - Adoption Date (Month, YYYY)";
		}
	}
	if(!document.class_registration.behavior1a.checked && !document.class_registration.behavior1b.checked && !document.class_registration.behavior1c.checked && !document.class_registration.behavior1d.checked && !document.class_registration.behavior1e.checked && !document.class_registration.behavior1f.checked && !document.class_registration.behavior1g.checked && !document.class_registration.behavior1h.checked && !document.class_registration.behavior1i.checked && document.class_registration.behavior1o.value.length < 2) {
		errors += "\n  - Select/describe the dogs behavior around other dogs";
	}
	if(!document.class_registration.behavior2a.checked && !document.class_registration.behavior2b.checked && !document.class_registration.behavior2c.checked && !document.class_registration.behavior2d.checked && !document.class_registration.behavior2e.checked && !document.class_registration.behavior2f.checked && !document.class_registration.behavior2g.checked && !document.class_registration.behavior2h.checked && !document.class_registration.behavior2i.checked && document.class_registration.behavior2o.value.length < 2) {
		errors += "\n  - Select/describe the dogs behavior around people";
	}
	var checked = 0;
	var radios = document.class_registration.behavior3;
	for(i=0; i<radios.length; i++){
  	if(radios[i].checked) { var checked = 1; }
  }
	if(checked == 1) {
	}
	else {
		errors += "\n  - Has this dog bitten another dog?";
	}
	if(document.class_registration.behavior3[1].checked) {
		if(document.class_registration.behavior3o.value.length < 5) {
			errors += "\n  - Please describe when this dog bit another dog";
		}
	}
	var checked = 0;
	var radios = document.class_registration.behavior4;
	for(i=0; i<radios.length; i++){
  	if(radios[i].checked) { var checked = 1; }
  }
	if(checked == 1) {
	}
	else {
		errors += "\n  - Has this dog bitten a person?";
	}
	if(document.class_registration.behavior4[1].checked) {
		if(document.class_registration.behavior4o.value.length < 5) {
			errors += "\n  - Please describe when this dog bit a person";
		}
	}
	
	if(!document.class_registration.informed_consent.checked) {
		errors += '\n  - You must read and agree to the Informed Consent Waiver';
	}

	if(errors == '') {
		return true;
	}
	else {
		var error = 'The following items are required before continuing,\n';
		error += 'please take a moment to verify their accuracy:\n'+errors;
		alert(error);
		return false;
	}
}

function volRegValidate() {
	var errors='';
	if(document.class_registration.name.value.length < 2) {
		errors += "\n  - Name";
	}
	if(!isValidEmail(document.class_registration.email.value)) {
		errors += "\n  - Email";
	}

	if(errors == '') {
		return true;
	}
	else {
		var error = 'The following items are required before continuing,\n';
		error += 'please take a moment to verify their accuracy:\n'+errors;
		alert(error);
		return false;
	}
}


function informedConsent() {
  var conTop = 0, topStart;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    conTop = window.pageYOffset;
    //conLeft = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    conTop = document.body.scrollTop;
    //conLeft = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    conTop = document.documentElement.scrollTop;
    //conLeft = document.documentElement.scrollLeft;
  }
	topStart = 20 + conTop;
	document.getElementById('iConsent').scrollTop = 0;
	document.getElementById('iConsent').style.top = topStart + 'px';
	MM_showHideLayers('iConsent','','show','iCover','','show');
}

function moveInformedConsent() {
  var conTop = 0, topStart;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    conTop = window.pageYOffset;
    //conLeft = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    conTop = document.body.scrollTop;
    //conLeft = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    conTop = document.documentElement.scrollTop;
    //conLeft = document.documentElement.scrollLeft;
  }
	topStart = 20 + conTop;
	document.getElementById('iConsent').scrollTop = 0;
	document.getElementById('iConsent').style.top = topStart + 'px';
}
