// JavaScript Document
/* This script and many more are available free online at
The JavaScript Source :: http://javascript.internet.com
By: Christian Watson :: http://www.smileycat.com
Based on a script by Chris Nott: http://www.dithered.com/javascript/rollovers/index.html
License: http://creativecommons.org/licenses/by/1.0/
Futher info: http://www.smileycat.com/miaow/archives/000224.html */

function confirmUpdate()
{
	if (!confirm("Please confirm everything is correct."))
		return false;
	else
		return true;
}

function validateEmail()
{		
	if (confirmUpdate())
	{
		var emailStr = document.getElementById("email").value;
		apos=emailStr.indexOf("@");
		dotpos=emailStr.lastIndexOf(".");
		len=emailStr.length;
	
		if (apos<1||dotpos-apos<2||len-dotpos<2) 
		{
				alert('Please correct errors in highlighted fields.  Note that fields marked with an asterisk (*) are required');
				return false;
		}
		else
		{
			return true;
		}
	}
	else
		return false;
}

function isDefined(property) 
{
  return (typeof property != 'undefined');
}

var rolloverInitialized = false;
function rolloverInit() 
{
  if (!rolloverInitialized && isDefined(document.images)) 
  {
     var bodyId;
	 var dirPrefix = "";
	 if (document.URL.indexOf("index") != -1)
	 	bodyId = "01";
	else if (document.URL.indexOf("about") != -1)
	 	bodyId = "02";
	else if (document.URL.indexOf("live") != -1)
	 	bodyId = "03";
	else if (document.URL.indexOf("listen") != -1)
	 	bodyId = "04";
	else if (document.URL.indexOf("buycd") != -1)
	 	bodyId = "05";
	else if (document.URL.indexOf("look") != -1)
	 	bodyId = "06";
	else if (document.URL.indexOf("reviews.html") != -1)
	{
	 	bodyId = "07";
	}
	else if (document.URL.indexOf("reviews") != -1)
	{
	 	bodyId = "07";
		dirPrefix = "../";
	}
	else if (document.URL.indexOf("contact") != -1)
	 	bodyId = "08";

		
	 // get all images (including all <input type="image">s)
     // use getElementsByTagName() if supported
     var images = new Array();
     if (isDefined(document.getElementsByTagName)) 
	 {
        images = document.getElementsByTagName('img');
        var inputs = document.getElementsByTagName('input');
        for (var i = 0; i < inputs.length; i++) 
		{
           if (inputs[i].type == 'image') 
		   {
              images[images.length] = inputs[i];
           }
        }
     }

     // otherwise, use document.images and document.forms collections
     // remove if not supporting IE4, Opera 4-5
     else 
	 {
        images = document.images;
        inputs = new Array();
        for (var formIndex = 0; formIndex < document.forms.length; formIndex++) 
		{
           for (var elementIndex = 0; elementIndex < document.forms.elements.length;                                                                     elementIndex++) 
		   {
              if (isDefined(document.forms.elements[i].src)) 
			  {
                 inputs[inputs.length] = document.forms.elements[i];
              }
           }
        }
     }

     // get all images with '_off.' in src value excepting the one that is for the BODY
     for (var i = 0; i < images.length; i++) 
	 {
        if (images[i].src.indexOf('up_state') != -1) 
		{
           // check for current page, and turn image 'on' if found
           if (images[i].id == bodyId)
		   {
              images[i].src = images[i].src.replace(/up_state_/, 'current_state_');
		   }
           else 
		   {
			   var image = images[i];
	
			   // store the up state filename in a property of the image object
			   image.upImage = new Image();
			   image.upImage.src = image.src;
	
			   // store the current state filename in a property of the image object
			   // (also preloads the current state image)
			   image.curImage = new Image();
			   image.curImage.imageElement = image;
	
			   // add onmouseover and onmouseout event handlers once the on state image has loaded
			   // Safari's onload is screwed up for off-screen images; temporary fix
			   if (navigator.userAgent.toLowerCase().indexOf('safari') != - 1) 
			   {
				  image.onmouseover = function() 
				  {
					 this.src = this.curImage.src;
				  };
				  image.onmouseout = function() 
				  {
					 this.src = this.upImage.src;
				  };
			   }
			   else 
			   {
				  image.curImage.onload = function() 
				  {
					this.src = dirPrefix+"images/slices/over_state_"+this.id+".png";
					 this.imageElement.onmouseover = function() 
					 {
						this.src = dirPrefix+"images/slices/over_state_"+this.id+".png";
					 };
					 this.imageElement.onmouseout = function() 
					 {
						 if (this.id == this.curImage.id)
							this.src = dirPrefix+"images/slices/current_state_"+this.id+".png";
						else
							this.src = dirPrefix+"images/slices/up_state_"+this.id+".png";
					 };
					 this.imageElement.onmousedown = function() 
					 {
						this.src = dirPrefix+"images/slices/down_state_"+this.id+".png";
					 };
				  };
			   }
	
			   // set src of current state image after defining onload event handler
			   // so cached images (that load instantly in IE) will trigger onload
			   image.curImage.src = image.src.replace(/up_state_/, 'current_state_');

          }
        }
     }
  }
  rolloverInitialized = true;
}



// call rolloverInit when document finishes loading
if (isDefined(window.addEventListener)) {
   window.addEventListener('load', rolloverInit, false);
}
else if (isDefined(window.attachEvent)) {
   window.attachEvent('onload', rolloverInit);
}


