function loadingOn()
{
	//We change submit image to sending gif
	document.getElementById("imgbutton").src = "img/sending.gif";
	document.getElementById("linksubmit").blur();
	//We block the imputs
	document.getElementById("cinema").disabled = true;
	document.getElementById("name").disabled = true;
	document.getElementById("email").disabled = true;
}
function loadingOff()
{
	//We change submit image to sending gif
	document.getElementById("imgbutton").src = "img/submit.jpg";

	//We block the imputs
	document.getElementById("cinema").disabled = false;
	document.getElementById("name").disabled = false;
	document.getElementById("email").disabled = false;
}
function openPopup (url)
{
   window.open(url,null,"width=640,height=480,scrollbars=yes");
} 
function loadMain(_id)
{
	var wrapper = document.getElementById(_id);
	
	var htmltext = '<div id="textinfo"><div id="title"><img src="img/entertowin.jpg" alt="EVERYONE WINS!" name="imgtitle" id="imgtitle" /></img></div>';
	htmltext +=	'<span class="style6">Simply enter your details in the spaces provided and we will email you an 8 digit code to claim 1 month FREE DVD RENTAL from'; 			    htmltext += 'Screenclick. You will also be automatically entered into our daily draw to win 1 of 6 pairs of Cinema tickets. ';
	htmltext +=	'<br /><br />We will also email you an 8 digit code to claim your 1 month free DVD rental from Screenclick.   </span></div>';
	htmltext += '<div id="entrypanel"><table><tr><td><input id="name" name="name" type="text"></input></td></tr><tr>';
	htmltext +=	'<td class="imgtb"><img src="img/name.jpg" alt="name"></img></td></tr><tr><td><input id="email" name="email" type="text"></input></td></tr>';
	htmltext +=	'<tr><td class="imgtb"><img src="img/email.jpg" alt="email"></img></td></tr><tr><td>';
	htmltext +=	'<select id="cinema" name="cinema" style="width: 146px;"><option value="Movies @ Dundrum" selected="selected">Movies @ Dundrum</option>';
	htmltext +=	'<option value="Movies @ Swords">Movies @ Swords</option><option value="Diamond Cinema Monaghan">Diamond Cinema Monaghan</option>';
	htmltext +=	'<option value="Eye Cinema Galway">Eye Cinema Galway</option><option value="Global Cinema Dungannon">Global Cinema Dungannon</option>';
	htmltext +=	'<option value="Carrick Cinema, Carrick-on-Shannon">Carrick Cinema, Carrick-on-Shannon</option></select></td></tr><tr>';
	htmltext +=	'<td class="imgtb"><img src="img/prefcinema.jpg" alt="preferred cinema"></img></td></tr><tr><td><div id="error"></div></td></tr><tr>';
	htmltext +=	'<td id="imgsubmit"><img src="img/submit.jpg" alt="submit" onclick="send()"></img></td></tr></table></div><div id="bottles">';
	htmltext +=	'<div id="terms">Click <a href="javascript:void(0)" onclick="openPopup (\'http://www.bignightsin.ie/terms.html\', \'Terms and Conditions\')">here</a> for Terms and conditions</div></div>';
		
	wrapper.innerHTML = htmltext;
	
}


function loadThanks(_id, _htmltext)
{
	
	// Code !!!!!! //
	
	var code = "BYGB934";
	var header = document.getElementById("header");
	while(header.hasChildNodes())
		header.removeChild(header.firstChild);
	var imagen= document.createElement('img');
	imagen.src = "./img/thankyoubanner.jpg";
	header.appendChild(imagen);
	
	document.getElementById("imgtitle").src = "img/thankyou.jpg";
	
	wrapper = document.getElementById(_id);
	wrapper.innerHTML = _htmltext;

}


function validateEmail(email) 
{
	if (!(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/.test(email)))
	{
		return(false);
		
	}
	return(true);
}


function showErrors(_id, _error)
{

	var error="";

	if(_error.length > 40)	//We receive thanks message
	{
		loadThanks("firstpanel", _error);
	}
	else
		switch (_error)
		{
			case ('Mail error'):
			{	error = "Check your mail, please";
				document.getElementById(_id).innerHTML = error;
				loadingOff();
			} break;
			case ('Database error'):
			{
				error = "Server error, try again with a new email";
				document.getElementById(_id).innerHTML = error;
				loadingOff();
			} break;
			case ('User error'):
			{
				error = "This user already exists";
				document.getElementById(_id).innerHTML = error;
				loadingOff();
			} break;
			case ('Fields error'):
			{
				error = "There're some empty fields";
				document.getElementById(_id).innerHTML = error;
				loadingOff();
			} break;
			
		}
	
}