/* 
================================================================================================================================ CREDITS
Copyright 	: Copyright (c) 2009 JPL & The Hershey Company. All Rights Reserved.
Author(s) 	: Larry Daughenbaugh - ldaugh@jplcreative.com
Date      	: 10/22/2009
Notes     	: JavaScript file for handling various events ... onLoad, onClick, etc
================================================================================================================================ CHANGE LOG
Date		Name			Desc
---			---				---
================================================================================================================================ BEGIN JAVASCRIPT
*/
/* ============================================================================================================================= MULTIPLE ONLOAD HANDLER */

var onLoadFunctions = new Array();
var iloadFunction = 0;

// Pass each function that needs to load
function addOnLoad(func) {
    onLoadFunctions[iloadFunction] = func;
    iloadFunction++;
}
// Loops through all of the functions that were added
function loadAllFunctions() {
    for(i=0; i < onLoadFunctions.length; i++) {
        eval(onLoadFunctions[i]+"()");
    }
}
// Load all of the functions that you've set
window.onload = loadAllFunctions;

/* ============================================================================================================================= CALL FUNCTIONS TO BE LOADED */

addOnLoad("load_modals");
addOnLoad("share_video_validation");

/* ============================================================================================================================= LOAD FLASH FILES */

function share() {
	new_modal0 = new modal("modal0",true,true,"");
	new_modal0.activate();
}
	
/* ============================================================================================================================= LOAD MODALS */

function load_modals() {
	init_modal();
}

/* ============================================================================================================================= SHARE VIDEO FORM VALIDATION */

function share_video_validation() {
	var share_video = document.getElementById("share_video");
	if (share_video != null) {
		share_video.onsubmit = function() {
			if (share_video.name.value == '') {
				alert("Please enter your Name.");
				share_video.name.focus();
				return false;
			}
			if (share_video.email.value == '') {
				alert("Please enter your Email.");
				share_video.email.focus();
				return false;
			}
			sEmail = share_video.email.value;
			if (sEmail != "" && sEmail.search(/^[\w-_.]*[\w-_.]@[\w].+[\w]+[\w]$/) == -1) {
				alert("Please enter a VALID Email Address.");
				share_video.email.focus();
				return false;
			}
			invalidChars = " /:,;";
			for (i = 0; i < invalidChars.length; i++) {
				badChar = invalidChars.charAt(i);
				if (sEmail.indexOf(badChar,0) > -1) {
					alert("Please enter a VALID Email Address.");
					share_video.email.focus();
					return false;
				}
			}
			if (share_video.recipient_name.value == '') {
				alert("Please enter the Recipient's Name.");
				share_video.recipient_name.focus();
				return false;
			}
			if (share_video.recipient_email.value == '') {
				alert("Please enter the Recipient's Email.");
				share_video.recipient_email.focus();
				return false;
			}
			sEmail = share_video.recipient_email.value;
			if (sEmail != "" && sEmail.search(/^[\w-_.]*[\w-_.]@[\w].+[\w]+[\w]$/) == -1) {
				alert("Please enter a VALID Recipient Email Address.");
				share_video.recipient_email.focus();
				return false;
			}
			invalidChars = " /:,;";
			for (i = 0; i < invalidChars.length; i++) {
				badChar = invalidChars.charAt(i);
				if (sEmail.indexOf(badChar,0) > -1) {
					alert("Please enter a VALID Recipient Email Address.");
					share_video.recipient_email.focus();
					return false;
				}
			}
			return true;
		}
	}
}
