// ----------------------------------------------------------------------------------------------
// ----------------------------  Navigation Bar Script (suckerfish) --------------------------
// ------------------------------------------------------------------------------------------------

sfHover = function() {
	var sfEls = document.getElementById("nav").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);



// -------------------------------------------------------------------------------------------------------------
// ---Slideshow Script (from http://www.cryer.co.uk/resources/javascript/script12slideshow.htm) ---
// -------------------------------------------------------------------------------------------------------------



// Browser Slide-Show script. With image cross fade effect for those browsers
// that support it.
// Script copyright (C) 2004-2008 www.cryer.co.uk.
// Script is free to use provided this copyright header is included.
var FadeDurationMS=1000;
function SetOpacity(object,opacityPct)
{
  // IE.
  object.style.filter = 'alpha(opacity=' + opacityPct + ')';
  // Old mozilla and firefox
  object.style.MozOpacity = opacityPct/100;
  // Everything else.
  object.style.opacity = opacityPct/100;
}
function ChangeOpacity(id,msDuration,msStart,fromO,toO)
{
  var element=document.getElementById(id);
  var msNow = (new Date()).getTime();
  var opacity = fromO + (toO - fromO) * (msNow - msStart) / msDuration;
  if (opacity>=100)
  {
    SetOpacity(element,100);
    element.timer = undefined;
  }
  else if (opacity<=0)
  {
    SetOpacity(element,0);
    element.timer = undefined;
  }
  else 
  {
    SetOpacity(element,opacity);
    element.timer = window.setTimeout("ChangeOpacity('" + id + "'," + msDuration + "," + msStart + "," + fromO + "," + toO + ")",10);
  }
}
function FadeInImage(foregroundID,newImage,backgroundID)
{
  var foreground=document.getElementById(foregroundID);
  if (foreground.timer) window.clearTimeout(foreground.timer);
  if (backgroundID)
  {
    var background=document.getElementById(backgroundID);
    if (background)
    {
      if (background.src)
      {
        foreground.src = background.src; 
        SetOpacity(foreground,100);
      }
      background.src = newImage;
      background.style.backgroundImage = 'url(' + newImage + ')';
      background.style.backgroundRepeat = 'no-repeat';
      var startMS = (new Date()).getTime();
      foreground.timer = window.setTimeout("ChangeOpacity('" + foregroundID + "'," + FadeDurationMS + "," + startMS + ",100,0)",10);
    }
  } else {
    foreground.src = newImage;
  }
}
var slideCache = new Array();
function RunSlideShow(pictureID,backgroundID,imageFiles,displaySecs)
{
  var imageSeparator = imageFiles.indexOf(";");
  var nextImage = imageFiles.substring(0,imageSeparator);
  FadeInImage(pictureID,nextImage,backgroundID);
  var futureImages = imageFiles.substring(imageSeparator+1,imageFiles.length)+ ';' + nextImage;
  setTimeout("RunSlideShow('"+pictureID+"','"+backgroundID+"','"+futureImages+"',"+displaySecs+")",displaySecs*1000);
  // Cache the next image to improve performance.
  imageSeparator = futureImages.indexOf(";");
  nextImage = futureImages.substring(0,imageSeparator);
  if (slideCache[nextImage] == null)
  {
    slideCache[nextImage] = new Image;
    slideCache[nextImage].src = nextImage;
  }
}

// ----------------------------------------------------------------------------------------------
// ----------------------------  Training Form Javascript Validation --------------------------
// ------------------------------------------------------------------------------------------------


/* begin main training javascript form validation */	
function isAlphabet(elem, helperMsg){ // This javascript form validation is from http://www.tizag.com/javascriptT/javascriptform.php
	var alphaExp = /^[a-zA-Z-\s]+$/;
	if((elem.value.match(alphaExp))&&(elem.value.length > 0)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function emailValidator(elem, helperMsg){ // This javascript form validation is from http://www.tizag.com/javascriptT/javascriptform.php
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAddress(elem, helperMsg){ // This javascript form validation is from http://www.tizag.com/javascriptT/javascriptform.php
	var alphaExp = /^[a-zA-Z\s0-9.#]+$/;
	if((elem.value.match(alphaExp))&&(elem.value.length > 0)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isZip(elem, helperMsg){ // This javascript form validation is from http://www.tizag.com/javascriptT/javascriptform.php
	var alphaExp = /^[0-9-]+$/;
	if((elem.value.match(alphaExp))&&(elem.value.length > 0)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isPhone(elem, helperMsg){ // This javascript form validation is from http://www.tizag.com/javascriptT/javascriptform.php
	var alphaExp = /^[0-9-\s()]+$/;
	if((elem.value.match(alphaExp))&&(elem.value.length > 0)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}


// If the length of the element's string is 0 then display helper message. This javascript form validation is a modified version from http://www.tizag.com/javascriptT/javascriptform.php
function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function messageValidator(elem, helperMsg){ // This javascript form validation is a modified version from http://www.tizag.com/javascriptT/javascriptform.php
	var messageExp = /^[a-zA-Z0-9.!?(),\'$\s ]+$/; // modified version of code from http://blog.techsaints.com/2007/04/30/javascript-phone-number-validation/
	if(elem.value.match(messageExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function formTrainingValidator(){
	// This javascript form validation is a modified version from http://www.tizag.com/javascriptT/javascriptform.php
	// Make quick references to our fields
	var ownerName = document.getElementById('ownerName');
	var petName = document.getElementById('petName');
	var streetAddress = document.getElementById('streetAddress');
	var city = document.getElementById('city');
	var zip = document.getElementById('zip');
	var homephone = document.getElementById('homePhone');
	var cellPhone = document.getElementById('cellPhone');
	var userEmail = document.getElementById('email');
	var userMessage = document.getElementById('message');
	
	// Check each input in the order that it appears in the form!
	if(isAlphabet(ownerName, "Please enter your name (letters and spaces only)")){
		if(isAlphabet(petName, "Please enter your pets name (letters and spaces only)")){
			if(isAddress(streetAddress, "Please enter your street address (no special characters)")){
				if(isAlphabet(city, "Please enter your city (letters and spaces only)")){
					if(isZip(zip, "Please enter your zip code (numbers only)")){
						if(isPhone(homephone, "Please enter your phone number (numbers only)")){
							if(emailValidator(userEmail, "Please enter a valid email address. Example: something@somethingelse.xyz")){
								return true;
							}
						}
					}
				}
			}
		}
	}
	return false;
}
/* end training javascript form validation */


// ----------------------------------------------------------------------------------------------
// ----------------------------  Spay/Neuter Notification Form Javascript Validation --------------------------
// ------------------------------------------------------------------------------------------------


/* begin main training javascript form validation */	
function isAlphabet(elem, helperMsg){ // This javascript form validation is from http://www.tizag.com/javascriptT/javascriptform.php
	var alphaExp = /^[a-zA-Z-\s]+$/;
	if((elem.value.match(alphaExp))&&(elem.value.length > 0)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function emailValidator(elem, helperMsg){ // This javascript form validation is from http://www.tizag.com/javascriptT/javascriptform.php
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if(elem.value.match(emailExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAddress(elem, helperMsg){ // This javascript form validation is from http://www.tizag.com/javascriptT/javascriptform.php
	var alphaExp = /^[a-zA-Z\s0-9.#]+$/;
	if((elem.value.match(alphaExp))&&(elem.value.length > 0)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isZip(elem, helperMsg){ // This javascript form validation is from http://www.tizag.com/javascriptT/javascriptform.php
	var alphaExp = /^[0-9-]+$/;
	if((elem.value.match(alphaExp))&&(elem.value.length > 0)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isPhone(elem, helperMsg){ // This javascript form validation is from http://www.tizag.com/javascriptT/javascriptform.php
	var alphaExp = /^[0-9-\s()]+$/;
	if((elem.value.match(alphaExp))&&(elem.value.length > 0)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isCodeNumber(elem, helperMsg){ // This javascript form validation is from http://www.tizag.com/javascriptT/javascriptform.php
	var alphaExp = /^[a-zA-Z0-9-\s()!@#$%&*_+=|;'"]+$/;
	if((elem.value.match(alphaExp))&&(elem.value.length > 0)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}


// If the length of the element's string is 0 then display helper message. This javascript form validation is a modified version from http://www.tizag.com/javascriptT/javascriptform.php
function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function messageValidator(elem, helperMsg){ // This javascript form validation is a modified version from http://www.tizag.com/javascriptT/javascriptform.php
	var messageExp = /^[a-zA-Z0-9.!?(),\'$\s ]+$/; // modified version of code from http://blog.techsaints.com/2007/04/30/javascript-phone-number-validation/
	if(elem.value.match(messageExp)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function formSpayValidator(){
	// This javascript form validation is a modified version from http://www.tizag.com/javascriptT/javascriptform.php
	// Make quick references to our fields
	var ownerName = document.getElementById('ownerName');
	var petName = document.getElementById('petName');
	var petDescription = document.getElementById('petDescription');
	var codeNumber = document.getElementById('codeNumber');
	
	// Check each input in the order that it appears in the form!
	if(isAlphabet(ownerName, "Please enter your name (letters and spaces only)")){
		if(isAlphabet(petName, "Please enter your pets name (letters and spaces only)")){
			if(isAlphabet(petDescription, "Please enter pet description (letters and spaces only)")){
				if(isCodeNumber(codeNumber, "Please enter your code number (letters and spaces only)")){
					return true;
				}
			}
		}
	}
	return false;
}
/* end training javascript form validation */





// ----------------------------------------------------------------------------------------------
// ----------------------------  Volunteer Form Javascript Validation --------------------------
// ------------------------------------------------------------------------------------------------


/* begin main volunteer javascript form validation */	
function isAlphabet(elem, helperMsg){ // This javascript form validation is from http://www.tizag.com/javascriptT/javascriptform.php
	var alphaExp = /^[a-zA-Z-\s]+$/;
	if((elem.value.match(alphaExp))&&(elem.value.length > 0)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function emailValidator(elem, helperMsg){ // This javascript form validation is from http://www.tizag.com/javascriptT/javascriptform.php
	var emailExp = /^[\w\/\-\.\+\\_]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if((elem.value.match(emailExp))&&(elem.value.length > 0)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAge(elem, helperMsg){ // This javascript form validation is from http://www.tizag.com/javascriptT/javascriptform.php
	var alphaExp = /^[0-9]+$/;
	if((elem.value.match(alphaExp))&&(elem.value.length > 0)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAlphabet(elem, helperMsg){ // This javascript form validation is from http://www.tizag.com/javascriptT/javascriptform.php
	var alphaExp = /^[a-zA-Z-\s]+$/;
	if((elem.value.match(alphaExp))&&(elem.value.length > 0)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isAddress(elem, helperMsg){ // This javascript form validation is from http://www.tizag.com/javascriptT/javascriptform.php
	var alphaExp = /^[0-9a-zA-Z-.#\s]+$/;
	if((elem.value.match(alphaExp))&&(elem.value.length > 0)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function isPhone(elem, helperMsg){ // This javascript form validation is from http://www.tizag.com/javascriptT/javascriptform.php
	var alphaExp = /^[0-9-().\s]+$/;
	if((elem.value.match(alphaExp))&&(elem.value.length > 0)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function eitherPhone(phone1, phone2, helperMsg){
	if ((phone1.value.length > 0)||(phone2.value.length > 0)) {
		if (phone1.value.length > 0) {
			if (isPhone(phone1, "Please enter a proper home phone number.  example (512) 555-1212.")) {
				return true;
			}
		}
		if (phone2.value.length > 0) {
			if (isPhone(phone2, "Please enter a proper cell phone number.  example (512) 555-1212.")) {
				return true;
			}
		}
		
	}else{
		alert(helperMsg);
		elem = phone1;
		elem.focus();
		return false;
	}
}

function isZip(elem, helperMsg){ // This javascript form validation is from http://www.tizag.com/javascriptT/javascriptform.php
	var alphaExp = /^[0-9-]+$/;
	if((elem.value.match(alphaExp))&&(elem.value.length > 0)){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function noSpecialCharacters(elem, helperMsg){ // This javascript form validation is from http://www.tizag.com/javascriptT/javascriptform.php
	var alphaExp = /^[^<>{}\[\]|]+$/;
	if((elem.value.match(alphaExp))&&(elem.value.length > 0)){
		return true;
	}
	else if (elem.value.length == 0 ) {
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}


// If the length of the element's string is 0 then display helper message. This javascript form validation is a modified version from http://www.tizag.com/javascriptT/javascriptform.php
function notEmpty(elem, helperMsg){
	if(elem.value.length == 0){
		alert(helperMsg);
		elem.focus(); // set the focus to this input
		return false;
	}
	return true;
}

function checkLength(elem, maxLength, helperMsg){ // This javascript form validation is a modified version from http://www.tizag.com/javascriptT/javascriptform.php
	if(elem.value.length <= maxLength){
		return true;
	}else{
		alert(helperMsg);
		elem.focus();
		return false;
	}
}

function formVolunteerValidator(){
	// This javascript form validation is a modified version from http://www.tizag.com/javascriptT/javascriptform.php
	// Make quick references to our fields
	var name = document.getElementById('name');
	var age = document.getElementById('age');
	var email = document.getElementById('email');
	var address = document.getElementById('address');
	var city = document.getElementById('city');
	var state = document.getElementById('state');
	var zip = document.getElementById('zip');
	var homePhone = document.getElementById('homePhone');
	var cellPhone = document.getElementById('cellPhone');
	var emergency_name = document.getElementById('emergency_name');
	var emergency_phone = document.getElementById('emergency_phone');
	var hear_about = document.getElementById('hear_about');
	var want_vol = document.getElementById('want_vol');
	var pet_exp = document.getElementById('pet_exp');
	var skills = document.getElementById('skills');
	
	// Check each input in the order that it appears in the form!
	if(isAlphabet(name, "Please enter your name (letters and spaces only)")){
		if(isAge(age, "Please enter your age (numbers only)")){
			if(isAge(age, "Please enter your street address (no special characters)")){
				if(emailValidator(email, "Please enter your email (example: something@somethingelse.com)")){
					if(isAddress(address, "Please enter your address (no special characters)")){
						if(isAlphabet(city, "Please enter your city (letters and spaces only)")){
							if(isAlphabet(state, "Please enter your state (letters only)")){
								if(isZip(zip, "Please enter your zip code (numbers and hypen only)")){
									if(eitherPhone(homePhone, cellPhone, "Please enter either a cell phone number or a home phone number")){										
										if(isAlphabet(emergency_name, "Please enter your emergency contact name (letters and spaces only)")){
											if(isPhone(emergency_phone, "Please enter your emergency contact phone number")){
												if(noSpecialCharacters(hear_about, "Please no special characters in how you heard about us.")){
													if(noSpecialCharacters(want_vol, "Please no special characters in why you want to volunteer with us.")){
														if(noSpecialCharacters(pet_exp, "Please no special characters in pets you've had in the past.")){
															if(noSpecialCharacters(skills, "Please no special characters in skills or experience.")){
																return true;
															}
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}
	return false;
}
/* end volunteer javascript form validation */
