////////////////////////////////////////////////////////////////////
// xps_864FFCB2-D534-4B83-8991-957412422F6A.js SCRIPTS - CREATED ON 2/19/2008
// Copyright 2008 XenoWize LLC
////////////////////////////////////////////////////////////////////
//numericCheck
function numericCheck(sValue, sFieldName) {
	//1
        sCheck = new String(sValue);
	bError = false;
	
	//2
	iLength = sCheck.length;
	for (i=0; i<iLength; i++)
	{
	  if ( (sCheck.charCodeAt(i) > 57) || (sCheck.charCodeAt(i) < 48) )
	  {
	      bError = true;
	  }
	}
	
	if (bError) {
	  popMessage(sFieldName + ' can only contain integers.','VALIDATION');
	}
	
	return bError
}
function popMessage(sMessage, sType) {
	if (sType=='VALIDATION') {
	  alert('Validation Error:\n\n' + sMessage);
	}else{
	  alert(sMessage);
	}
}

//lengthCheck
function lengthCheck(sValue, nLength, sFieldName) {
	//1
        sCheck = new String(sValue);
	bError = false;
	
	bCheck = emptyCheck(sCheck, sFieldName, 'NO_SHOW')
	  
	if (bCheck == true ) {
	   return !bCheck
	}

	//2
	iLength = sCheck.length;
	if ( iLength != nLength )
	{
	      bError = true;
	}
	
	if (bError) {
	  popMessage(sFieldName + ' must be a length of ' + nLength,'VALIDATION');
	}
	
	return bError
}
function popMessage(sMessage, sType) {
	if (sType=='VALIDATION') {
	  alert('Validation Error:\n\n' + sMessage);
	}else{
	  alert(sMessage);
	}
}
function emptyCheck(sValue, sFieldName, sNoShow) {
	//Convert to string if nessasary - MAS 2002-12-04
	sCheck = new String(sValue);
	bError = false;
	
	//Remove spaces and then check length
	var spaceExp = new RegExp('(\\s)+', 'g');
	sCheck = sCheck.replace(spaceExp , '');
	if (sCheck.length==0) {
	  //There are still chars in the string after removing the spaces.
	  bError = true;
	}
	
	if ( (bError) && (sNoShow!='NO_SHOW') ) {
	  popMessage(sFieldName + ' must not be empty.','VALIDATION');
	}
	
	return bError;
}
function popMessage(sMessage, sType) {
	if (sType=='VALIDATION') {
	  alert('Validation Error:\n\n' + sMessage);
	}else{
	  alert(sMessage);
	}
}

//popMessage

//other scripts
function cc_emptyCheck(objValue, sFieldName) {
	//Convert to string if nessasary - MAS 2002-12-04
	bError = false;
	
	if (objValue){
		sCheck = new String(objValue.value);
		//Remove spaces and then check length
		var spaceExp = new RegExp('(\\s)+', 'g');
		sCheck = sCheck.replace(spaceExp , '');
		if (sCheck.length==0) {
		  //There are still chars in the string after removing the spaces.
		  bError = true;
		}
	} else { bError = true; }

	if (bError) {
	  popMessage(sFieldName + ' must not be empty.','VALIDATION');
	}
	
	return bError;
}

function cc_checkSelected(objRadio, sFieldName)
{
	var bError = false;
    if (objRadio[0]) {
	for (var i=0; i<objRadio.length; i++) {
	         if (objRadio[i].checked) {
	            bError = false;
	            i = objRadio.length;

	         }else{ bError = true; }
	 }
    }
	if (bError) {
	  popMessage(sFieldName + ' must not be empty.','VALIDATION');
	}
	
	return bError;
}

function cc_checkWhichSelected(objRadio,objValue, sFieldName)
{
	var bError = false;
	if (objRadio[0]) {
		for (var i=0; i<objRadio.length; i++) {
			if ((objRadio[i].checked) && (objRadio[i].value == 'yes')){
				bError = cc_emptyCheck(objValue, sFieldName);
			}
		}
	}	
	return bError;
}

function cc_checkWhichSelected_radio(objRadio,objValue, sFieldName)
{
	var bError = false;
	if (objRadio[0]) {
		for (var i=0; i<objRadio.length; i++) {
			if ((objRadio[i].checked) && (objRadio[i].value == 'yes')){
				bError = cc_checkSelected(objValue, sFieldName);
			}
		}
	}	
	return bError;
}

//submit_form
function submit_form()
{
  var nErrors = 0;
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_pet_name'), 'Pet Name');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_lastName'), 'Last Name');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_firstName'), 'First Name');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_dateOfBirth_month'), 'Date of Birth Month');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_dateOfBirth_day'), 'Date of Birth Day');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_dateOfBirth_year'), 'Date of Birth Year');
  nErrors = nErrors + numericCheck(document.getElementById('ad_dateOfBirth_year').value, 'Date of Birth Year');
  nErrors = nErrors + lengthCheck(document.getElementById('ad_dateOfBirth_year').value, 4, 'Date of Birth Year');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_address'), 'Street address');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_city'), 'City');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_state'), 'State');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_zip'), 'Zip');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_main_phone'), 'Main Phone');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_email'), 'Email');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_landlord'), 'Landlord/Condo board name and phone');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_AdultCount'), 'Number of adults in the household');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_numbChild'), 'Number of children in the household');
  nErrors = nErrors + cc_checkSelected(document.getElementsByName('ad_allergic'), 'Is anyone in the household allergic to pets');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_whoAllergic'), 'Who is allergic');
  nErrors = nErrors + cc_checkSelected(document.getElementsByName('ad_whyAdopt'), 'Why would you like to adopt an animal from us');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_employeer'), 'Employeer');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_emp_city'), 'Employeer City');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_emp_state'), 'Employeer State');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_emp_zip'), 'Employeer Zip');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_refName'), 'Name of Reference');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_refPhone'), 'Reference phone #');
  nErrors = nErrors + cc_checkSelected(document.getElementsByName('ad_havePet'), 'Have you had or currently have a pet(s)');
  nErrors = nErrors + cc_checkWhichSelected(document.getElementsByName('ad_havePet'), document.getElementById('ad_petName'), 'Pet Name');
  nErrors = nErrors + cc_checkWhichSelected(document.getElementsByName('ad_havePet'), document.getElementById('ad_breed'), 'Pet Breed');
  nErrors = nErrors + cc_checkWhichSelected(document.getElementsByName('ad_havePet'), document.getElementById('ad_age'), 'Pet Age');
  nErrors = nErrors + cc_checkWhichSelected(document.getElementsByName('ad_havePet'), document.getElementsByName('ad_gender'), 'Pet Gender');
  nErrors = nErrors + cc_checkWhichSelected(document.getElementsByName('ad_havePet'), document.getElementsByName('ad_altered'), 'Pet Altered');
  nErrors = nErrors + cc_checkWhichSelected(document.getElementsByName('ad_havePet'), document.getElementById('ad_petAt'), 'Pet At');
  nErrors = nErrors + cc_checkSelected(document.getElementsByName('ad_awayPet'), 'Have you ever given an animal away or relinquished an animal to a shelter');
  nErrors = nErrors + cc_checkWhichSelected(document.getElementsByName('ad_awayPet'), document.getElementById('ad_reasonAway'), 'If yes, what were the circumstances');
  nErrors = nErrors + cc_checkSelected(document.getElementsByName('ad_currVet'), 'Do you currently have a Veterinarian');
  nErrors = nErrors + cc_checkWhichSelected(document.getElementsByName('ad_currVet'), document.getElementById('ad_vetName'), 'Veterinarian Name');
  nErrors = nErrors + cc_checkWhichSelected(document.getElementsByName('ad_currVet'), document.getElementById('ad_vetPhone'), 'Veterinarian Phone');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_longLooking'), 'How long have you been looking for a pet');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_feedPet'), 'What will you feed your new pet');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_timeAdjust'), 'How much time are you prepared to allow for your new pet to adjust to your home');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_affordEmerg'), 'Are you able to afford a bill of $200-$400 (or more) for emergency veterinary care');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_spendYear'), 'How much do you expect to spend on maintenance for your pet in a year');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_careGiver'), 'Who in the household will be the dogs primary care giver');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_keptDay'), 'Where will the dog be kept during the day');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_keptNight'), 'Where will the dog be kept during the night');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_longAlone'), 'How many hours per day will your dog be left alone');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_digging'), 'Digging');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_barking'), 'Barking');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_chewing'), 'Chewing');
  nErrors = nErrors + cc_emptyCheck(document.getElementById('ad_aggression'), 'Aggression');
          ////////////////////////////////////////////////////
      if (nErrors<1) {
           document.all('form1').submit();
     }
}
