// <![CDATA[

//remove nonFlash warning
/**
 *
 * @access public
 * @return void
 **/

// AJAX vote window displayer
function vote(id){
 var win = new Window({id: "voteWindow", url: "/index.php/form/index/"+id, className: "alphacube", width:440, top: 107, minHeight: 372, destroyOnClose: true});
 win.showCenter({modal:false});
 return false;
}
// AJAX send to friend window displayer
function sendToFriend(){
 var win = new Window({id: "sendWindow", url: "/index.php/form/send_to_friend/", className: "alphacube", width:440, minHeight: 322, destroyOnClose: true});
 win.showCenter({modal:false});
 return false;
}
// send send to friend email and shows success
function sendSubmit(){

  var serialForm = Form.serialize('sendForm');
	var url = '/index.php/form/send_to_friend';
	var params = serialForm;
	var ajax = new Ajax.Updater(
		{success: 'sendResult'},
		url,
		{method: 'post', parameters: params, onFailure: reportError});
  window.document.body.removeChild(document.getElementById('formContainer'));
}

// alert box if AJAX error
function reportError(request) {
	alert("There was an error with your submission. Please try again");
}

// send to friend valid flag
var sendFriendValid;
// highlighting send to friend form validation
function sendFriendHighlight (inputField, textAlert)
{
		document.getElementById('yr_name').style.borderColor = '#fff';
		document.getElementById('yr_name').style.backgroundColor = '#ffffff';
		document.getElementById('email').style.borderColor = '#fff';
		document.getElementById('email').style.backgroundColor = '#ffffff';

		sendFriendValid = false;
		var errmsg = document.createElement('p');
		errmsg.id = 'err';
		var msg = document.createTextNode(textAlert);
		errmsg.appendChild(msg);
		// check if element with id 'err' exisits, if not then create it
		if (document.getElementById('err')) {
			document.getElementById('errDiv').removeChild(document.getElementById('err'));
		}
		document.getElementById('errDiv').appendChild(errmsg);

		var inputbox = document.getElementById(inputField);
		inputbox.style.borderColor = '#9f0369';
		inputbox.style.backgroundColor = '#efd4e5';
		inputbox.focus();
}
// check for valid send to friend form
function sendFriendValidate(pageForm) {

	sendFriendValid = true;
	if (pageForm.yr_name.value == "")
	{
		sendFriendHighlight('yr_name', 'Please enter your name');
	}
	else if (pageForm.email.value == "")
	{
		sendFriendHighlight('email', 'Please enter your friend\'s email address');
	}

	if (sendFriendValid) {
	  sendSubmit();
	}

}
// AJAX vote submit function
function voteSubmit(){

  var serialForm = Form.serialize('bntmForm');
	var url = '/index.php/form';
	var params = serialForm;
	var ajax = new Ajax.Updater(
		{success: 'voteResult'},
		url,
		{method: 'post', parameters: params, onFailure: reportError});
    window.document.body.removeChild(document.getElementById('voteForm'));
}
// vote form valid flag
var voteFormValid;
// highlighting send to friend form validation
function voteFormHighlight (inputField, textAlert)
{
		document.getElementById('username').style.borderColor = '#fff';
		document.getElementById('username').style.backgroundColor = '#ffffff';
		document.getElementById('email').style.borderColor = '#fff';
		document.getElementById('email').style.backgroundColor = '#ffffff';

		voteFormValid = false;
		var errmsg = document.createElement('p');
		errmsg.id = 'err';
		var msg = document.createTextNode(textAlert);
		errmsg.appendChild(msg);
		// check if element with id 'err' exisits, if not then create it
		if (document.getElementById('err')) {
			document.getElementById('errDiv').removeChild(document.getElementById('err'));
		}
		document.getElementById('errDiv').appendChild(errmsg);

		var inputbox = document.getElementById(inputField);
		inputbox.style.borderColor = '#9f0369';
		inputbox.style.backgroundColor = '#efd4e5';
		inputbox.focus();
}
// check for valid send to friend form
function voteFormValidate(pageForm) {

	voteFormValid = true;
  if (pageForm.email.value == "")
	{
		voteFormHighlight('email', 'Please enter your email address');
	}
	else if (pageForm.username.value == "")
	{
		voteFormHighlight('username', 'Please enter your name');
	}

	if (voteFormValid) {
	  voteSubmit();
	}

}
// ]]>