/* ====================================== */
/* mouseover stuff                        */
/* ====================================== */

/* define images to flip here */
if (document.images) { 
	groupon = new Image(); groupon.src = "images/group_on.gif";
	groupoff = new Image(); groupoff.src = "images/group.gif";
	eventon = new Image(); eventon.src = "images/signup_on.gif";
	eventoff = new Image(); eventoff.src = "images/signup.gif";
	abouton = new Image(); abouton.src = "images/about_on.gif";
	aboutoff = new Image(); aboutoff.src = "images/about.gif";
	contacton = new Image(); contacton.src = "images/contact_on.gif";
	contactoff = new Image(); contactoff.src = "images/contact.gif";
}

// image flip script (on):
function imgAct(imgName) {
    if (document.images) {
    document[imgName].src = eval(imgName + "on.src");
    }
}

// image flip script (off):
function imgInact(imgName) {
    if (document.images) {
    document[imgName].src = eval(imgName + "off.src");
    }
}


/* ====================================== */
/* slideshow stuff                        */
/* ====================================== */

// speed (milliseconds)
var ssSpeed = 5000;

// crossfade (seconds)
var cfSpeed = 3;

// images files
var ssPictures = new Array();
ssPictures[0] = "images/slideshow/1.jpg";
ssPictures[1] = "images/slideshow/2.jpg";
ssPictures[2] = "images/slideshow/3.jpg";
ssPictures[3] = "images/slideshow/4.jpg";
ssPictures[4] = "images/slideshow/5.jpg";

// main script 
var timeOut;
var j = 0;
var numPics = ssPictures.length; //(p)

// preload images
var preLoader = new Array()
for ( i=0; i<numPics; ++i )
{
   preLoader[i] = new Image();
   preLoader[i].src = ssPictures[i];
}

// run the main slideshow
function slideShow ( ) 
{
	if ( document.all )
	{
		// do filter here (IE only though... )
		document.images.slideshowpic.style.filter = "blendTrans(duration=2)";
		document.images.slideshowpic.style.filter = "blendTrans(duration=cfSpeed)";
		document.images.slideshowpic.filters.blendTrans.Apply();
	}
	document.images.slideshowpic.src = preLoader[j].src;
	if ( document.all )
	{
		document.images.slideshowpic.filters.blendTrans.Play();
	}
	j = j + 1;
	if ( j >(numPics-1) ) {
		j = 0;
	}
	timeOut = setTimeout('slideShow()',ssSpeed)
}


/* ====================================== */
/* form validation                        */
/* ====================================== */

/* validate form */
function validateForm ( )
{
	var rc = false;
	var f = document.event_signup;
	if ( isWhitespace(f.field_name.value) )
		showError(f.field_name,"name");
	else if ( isWhitespace(f.field_phone.value) )
		showError(f.field_phone,"phone");
	else if ( f.field_phone.value.length != 10 )
	{
		f.field_phone.focus();
		alert("Please enter a valid phone number");
	}
	else if ( isWhitespace(f.field_email.value) )
		showError(f.field_email,"email");
	else if ( !isEmail(f.field_email.value) )
	{
		f.field_email.focus();
		alert("Please enter a valid email address");
	}
	else if ( isWhitespace(f.field_payment.value) )
		showError(f.field_payment,"payment");
	else if ( isWhitespace(f.field_date.value) )
		showError(f.field_date,"party date");
	else if ( isWhitespace(f.field_time.value) )
		showError(f.field_time,"party time");
	else if ( isWhitespace(f.field_guests.value) )
		showError(f.field_guests,"guests");
	else
		rc = true;
	return(rc);
}

/* form validation stuff */
/* is string empty? */
function isEmpty ( s )
{   
	return (( s == null) || (s.length == 0) );
}
/* is string only whitespace? */
function isWhitespace ( s )
{   
	var i;
	// whitespace characters
	var whitespace = " \t\n\r";

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (whitespace.indexOf(c) == -1) return false;
    }
    // All characters are whitespace.
    return true;
}
/* is string a valid email address? */
function isEmail (s)
{   
	// empty?
	if ( isEmpty(s) ) 
		return false;
   
    // is s whitespace?
    if (isWhitespace(s)) return false;
    
    // there must be >= 1 character before @, so we
    // start looking at character position 1 
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
		i++;

    if ((i >= sLength) || (s.charAt(i) != "@")) 
		return false;
    else 
		i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
		i++;

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) 
		return false;
    else 
		return true;
}
/* show the error to the user */
function showError ( field, s )
{	
	// missing data prompt information
	var missingPrefix = "You did not enter a value into the ";
	var missingSuffix = " field. This is a required field. Please enter it now.";
	field.focus();
	field.value = "";
	alert(missingPrefix + s + missingSuffix);
}