Ajax.Responders.register({
    onCreate: function(){ Element.show('ajaxLoader')},
    onComplete: function(){Element.hide('ajaxLoader')}
});

function validateFriends(formInfo)
{
	var outTxt = "";

	if (formInfo.name.value == "")
	{ outTxt += "Please fill in the Name field.\n"; }
	if (!formInfo.email.value.match(/.+@.+\..+/))
	{ outTxt += "Your email is invalid.\n"; }
	if (formInfo.friends.value == "")
	{ outTxt += "Please fill in the Friend's email address field.\n"; }
 	
	if (outTxt != "")
	{
		alert("The following information is incorrect:\n" + outTxt);
		return false;
	}
	return true;
}

function limitText(textarea)
{
	if (textarea.value.length > 1000)
	{
		textarea.value = textarea.value.substring(0, 1000);
	}
}

function videoStep1(formInfo)
{
	var outTxt = "";
	var firstName = formInfo.firstName.value;
	var lastName = formInfo.lastName.value;
	var address = formInfo.address.value;
	var city = formInfo.city.value;
	var state = formInfo.state.value;
	var zip = formInfo.zip.value;
	var email = formInfo.email.value;
//	var sendInfo = formInfo.sendInfo.checked;

	if (firstName == "")
	{ outTxt += "Please fill in the First Name field.\n"; }
	if (lastName == "")
	{ outTxt += "Please fill in the Last Name field.\n"; }
	if (address == "")
	{ outTxt += "Please fill in the Address field.\n"; }
	if (city == "")
	{ outTxt += "Please fill in the City field.\n"; }
	if (state == "")
	{ outTxt += "Please select your State.\n"; }
	if (zip == "")
	{ outTxt += "Please fill in the Zip field.\n"; }
	if (!email.match(/.+@.+\..+/))
	{ outTxt += "Your email is invalid.\n"; }
//	if (formInfo.Rules.checked == false)
//	{ outTxt += "You must agree to the Privacy Policy, Rules and Terms of Service.\n"; }
 	
	if (outTxt != "")
	{
		alert("The following information is incorrect:\n" + outTxt);
		return false;
	}
	
	new Ajax.Request('scripts/videoStep1.php', {
		method:'get',
			parameters:"firstName=" + firstName + "&lastName=" + lastName + "&address=" + escape(address) + "&city=" + city + "&state=" + state + "&zip=" + zip + "&email=" + email/* + "&sendInfo=" + sendInfo*/,
			onSuccess: function(transport){
				document.getElementById("formDiv").innerHTML = transport.responseText;
			},
			onFailure:function(){ alert('Something went wrong...') }
		});
	return true;
}

function videoStep2(formInfo)
{
	var outTxt = "";
	var id = formInfo.id.value;
	var videoTitle = formInfo.videoTitle.value;
	var videoDescription = formInfo.videoDescription.value;

	if (videoTitle == "")
	{ outTxt += "Please fill in the Video Title field.\n"; }
	if (videoDescription == "")
	{ outTxt += "Please fill in the Video Description field.\n"; }
	if (videoTitle.match(/<|>/) || videoDescription.match(/<|>/))
	{ outTxt += "The less than and greater than symbols (< and >) are not allowed."; }
 	
	if (outTxt != "")
	{
		alert("The following information is incorrect:\n" + outTxt);
		return false;
	}
	
	new Ajax.Request('scripts/videoStep2.php', {
		method:'post',
			parameters:"id=" + id + "&videoTitle=" + videoTitle + "&videoDescription=" + videoDescription,
			onSuccess: function(transport){
				document.getElementById("formDiv").innerHTML = transport.responseText;
			},
			onFailure:function(){ alert('Something went wrong...') }
		});
	return true;
}

function videoStep3(formInfo)
{
	var outTxt = "";

	if (formInfo.file.value == "")
	{ outTxt += "Please select a file to upload.\n"; }
 	
	if (outTxt != "")
	{
		alert("The following information is incorrect:\n" + outTxt);
		return false;
	}
	
	document.getElementById("ajaxLoader").style.display = "block";
	return true;
}

function facebook_onload(already_logged_into_facebook)
{
	// user state is either: has a session, or does not.
	// if the state has changed, detect that and reload.
	FB.ensureInit(function()
	{
		FB.Facebook.get_sessionState().waitUntilReady(function(session)
		{
			var is_now_logged_into_facebook = session ? true : false;

			// if the new state is the same as the old (i.e., nothing changed)
			// then do nothing
			if (is_now_logged_into_facebook == already_logged_into_facebook)
			{ return; }

			// otherwise, refresh to pick up the state change
			window.location = window.location;
		});
	});
}

function facebookVideoUpload(fname)
{
	FB.ensureInit(function()
	{
		var attachment = {'media':[{'type':'image','src':'http://banvideos.mesorc.com/images/fb-logo.jpg','href':'http://banvideos.mesorc.com/'}]}; 
		FB.Connect.streamPublish(fname + " just entered the Ban Asbestos Now Viral Video Search for a chance to win some great prizes. http://banvideos.mesorc.com/", attachment, null, null, '', facebookCallback);
			
	});
}

function facebookVideoVote(fname)
{
	FB.ensureInit(function()
	{
		var attachment = {'media':[{'type':'image','src':'http://banvideos.mesorc.com/images/fb-logo.jpg','href':'http://banvideos.mesorc.com/'}]}; 
		FB.Connect.streamPublish("I just voted on a video at Ban Asbestos Now Viral Video Search. http://banvideos.mesorc.com/", attachment, null, null, '', facebookCallback);
			
	});
}

function facebookVideoComment(fname)
{
	FB.ensureInit(function()
	{
		var attachment = {'media':[{'type':'image','src':'http://banvideos.mesorc.com/images/fb-logo.jpg','href':'http://banvideos.mesorc.com/'}]}; 
		FB.Connect.streamPublish("I just entered a comment at the Ban Asbestos Now Viral Video contest. http://banvideos.mesorc.com/", attachment, null, null, '', facebookCallback);
			
	});
}

function facebookCallback()
{
return;
}

