// JavaScript Documentfunction 
var loadingHasFinished = true;

// App Functions

var updateTimes = function(t)
{
		var times = t.responseText;
		var slots = times.split("|");
		
		var thisOption = $('contactTime');
		
		thisOption.options.length=0;
		thisOption.options[0] = new Option('[Select a Time]', "");
		for(var i=0; i < slots.length-1; i++) { 
			var thisTime = slots[i].split(",");
			thisOption.options[i+1]= new Option(thisTime[0], thisTime[1]);
	    }	
};

function startCallback() {
	return true;
}

function completeCallback(response) {
	$('uploadStatus').innerHTML = response;
}

function removeTN(tni)
{
	var tn = $("tn" + tni);
	var fs = $("fs" + tni);
	delThumb(fs.value, tn.value);
	$("tn" + tni + "tool").style.display='none';
	$("photo" + tni).src = '/images/photoplaceholder.gif';
	fs.value="";
	tn.value="";
	return false;
}

function uploadFile()
{
	var aForm = $("theForm");
	var tn1 = $("tn1");
	var tn2 = $("tn2");	
	var tn3 = $("tn3");
	var curTN = $("curTN");
		
	if (tn1.value == "")
		curTN.value = "1";
	else if (tn2.value == "")
		curTN.value = "2";
	else if (tn3.value == "")
		curTN.value = "3";
	else
		curTN.value = "1";
				
	$("uploadStatus").innerHTML = "Uploading Image... Please Wait...";
	$("btnUpload").disabled=true;
	aForm.action="fileUpload.php";
	aForm.enctype="multipart/form-data";
	aForm.target="f123";
	aForm.submit();
}

function checkContactTimeZone() 
{
	if ($('contactTimeZone').selectedIndex == 0)
	{
		$('contactTime').selectedIndex=0;
		$('contactTime').disabled=true;
	}
	doTimes();
}

function checkContactDate() 
{
	if ($('contactDate').selectedIndex > 0)
	{
		$('contactTimeZone').disabled=false; 
	} 
	else 
	{
		$('contactTimeZone').selectedIndex=0;
		$('contactTimeZone').disabled=true;
		$('contactTime').selectedIndex=0;
		$('contactTime').disabled=true;
	}
	doTimes();
}

function doTimes()
{
	if ($('contactDate').selectedIndex > 0 && $('contactTimeZone').selectedIndex > 0) 
	{ 
		var contactDate = $('contactDate').options[$('contactDate').selectedIndex].value;
		var contactTimeZone = $('contactTimeZone').options[$('contactTimeZone').selectedIndex].value;

		$('contactTime').disabled=true;
		showLoading();
		new Ajax.Request('/getTimes.php?TZ=' + contactTimeZone + "&Date="+contactDate, {onSuccess:updateTimes, onComplete: function() { $('contactTime').disabled=false; hideLoading();}});
	}
}

function showLoading()
{
	new Effect.Appear('loading', {duration:0.2});
	loadingHasFinished = false;
	setTimeout("loadingTimeout()", 10000);
}
function hideLoading()
{
	Effect.Fade('loading', {duration:0.2});
	loadingHasFinished = true;
}

function loadingTimeout()
{
	if (!loadingHasFinished)
		{
			hideLoading();
			alert("The requested action did not complete in a timely fashion. Please try your request again.");
			loadingHasFinished=true;
			
		}
}

	function formValidation(){
		var errMsg = "";
		var aForm = document.getElementById("theForm");
		aForm.enctype="application/x-www-form-urlencoded";
		aForm.target="_self";
		aForm.action="/signup_submit.php";
		
		with (document.forms.theForm)
		{
			if (talentID.selectedIndex == 0)
				errMsg += " - Talent Type (Actor, Model, etc...)\n";
			if (fname.value == "")
				errMsg += " - First Name\n";
			if (lname.value == "")
				errMsg += " - Last Name\n";
			if (city.value == "")
				errMsg += " - City\n";
			if (state.value == "")
				errMsg += " - State\n";
			if (zip.value == "")
				errMsg += " - Zip Code\n";
			var filter1 = /^\d{3}$/
			var filter2 = /^d{4}$/
			if (areacode1.value == "" || phonepre1.value == "" || phonepost1.value == "" || areacode1.value.length < 3 || phonepre1.value.length < 3 || phonepost1.value.length < 4 || !filter1.test(areacode1.value) || !filter1.test(phonepre1.value) || filter2.test(phonepost1.value))
				errMsg += " - Phone Number 1\n";
			if (areacode2.value != "" || phonepre2.value != "" || phonepost2.value != "")
				if (areacode2.value.length < 3 || phonepre2.value.length < 3 || phonepost2.value.length < 4 || !filter1.test(areacode2.value) || !filter1.test(phonepre2.value) || filter2.test(phonepost2.value))
				errMsg += " - Phone Number 2\n";
			var filter=/^[A-Za-z0-9_\-.]+@+[A-Za-z_0-9\-.]+\.[A-Za-z][^\.]+$/
			if (email.value == "")
				errMsg += " - Email Address\n";
			if (email.value != "" && !filter.test(email.value))
				errMsg += " - Enter a valid email address\n";
			if (DOBMonth.selectedIndex == 0 || DOBDay.selectedIndex == 0 || DOBYear.selectedIndex == 0)
				errMsg += " - Date of birth\n";
			if (contactDate.selectedIndex == 0)
				errMsg += " - Select a date to be contacted\n";
			if (contactTimeZone.selectedIndex == 0)
				errMsg += " - Select a time zone\n";			
			if (contactTime.selectedIndex == 0)
				errMsg += " - Select a time to be contacted\n";		
			if (!termAgree.checked)
				errMsg += " - You must read and agree to the terms and conditions\n";		
		 }
		if (errMsg ==""){
			return true;
		} else {
			alert("The following errors occured:\n\n" + errMsg);
			return false;
		}
	}	

// End App Functions


function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}

function swap(container)
{
var ag = $('agenda_content');
var lo = $('location_content');
var pa = $('package_content');
var div = $(container);
if (Element.visible(pa))
{
	Effect.toggle('package_content','appear');
}
if (Element.visible(ag))
{
	Effect.toggle('agenda_content','appear');
}

if (Element.visible(lo))
{
	Effect.toggle('location_content','appear');
}
showLoading();
new Ajax.Updater(container, container + '.php', {asynchronous:true, onComplete:function() {Effect.Appear (container); setTimeout('hideLoading()', 1000);}});


}

function closeContent(container)
{
	Effect.toggle(container,'appear');
}
function showGallery()
{
showLoading();
	new Ajax.Updater('gallery_sub_content', 'gallery_portal.php', {asynchronous:true, evalScripts:true, onComplete:function() {new Effect.Appear('gallery_content');  setTimeout('hideLoading()', 1000);}});
}
function showSignup()
{
showLoading();
	new Ajax.Updater('app_sub_content', 'signup_portal.php', {asynchronous:true, evalScripts:true, onComplete:function() {new Effect.Appear('app_content'); setTimeout('hideLoading()', 1000);}});
}
function moveSlider1()
		{
			s2.setValue(600);
			setTimeout('moveSlider2()', 1000);
		}
		function moveSlider2()
		{
			s2.setValue(0);
		}	