function goLogin(pw){
	var pwmd5 = MD5.hex_md5(pw);
	document.getElementById('password').value = pwmd5;
	document.getElementById('loginForm').submit();
}
function add_resource(data){
	opt = {
		OnSuccess: function(t){
			
		}
	}
	new Ajax.Request(data, opt);
	alert('This E-Guide has been added to My Resources. Go to My Resources to visit your selection. You must be logged to save the selection.');
}
function goDownload(id){
	form = document.getElementById('download_form');
	var padre = $('tabla_download');
	if(padre){
		padre.style.cursor = 'wait';
		id.style.cursor = 'wait';
		
	}
	
	var opt = {
			onSuccess: function(t){
				//alert(t.responseText);
				if(t.responseText != '0') {
					
					window.open('/pdf/'+t.responseText);
					window.location = 'index.php?seccion=2'
					if(padre){
						padre.style.cursor = 'default';
						id.style.cursor = 'default';
						
						
					}
				}else {
					alert("There has been an error, please contact technical support");
				}
			}
		}
	
	var pars = 'item='+form.item.value;
	
	new Ajax.Request('download.do.php?'+pars,opt);
	}
	

function check_pass(form)
{
	var clave = document.getElementById("newpassword").value;
	var claver = document.getElementById("confirmpassword").value;
	var claveViejaReal = document.getElementById("pwd").value;
	var claveViejaIngresada = document.getElementById("oldpassword").value;
	//alert(claveViejaReal)
	
	if(claveViejaReal != claveViejaIngresada)
	{
		alert("Your current password doesn't match with the one in our database, please re-type it");
		return 1;
	}
	else
	{
		if( clave != claver)
		{
			alert("Password must be the same");
			return 1;
		}
		else
		{
			if(clave.length < 1)
			{
				alert("Password cannot be empty");	
			}
			else
			{
				form.submit();
			}
		}
	}
}

function esa(){
	alert("esa");
}

function voidPass(form){
	form.password.value =  MD5.hex_md5(form.password.value);
	form.submit();
}
function checkMd5(form){
	//alert(form.oldpassword.value)
	form.oldpassword.value =  MD5.hex_md5(form.oldpassword.value);
	//alert( form.oldpassword.value)
	check_pass(form);
}
function goSubmit(form){
	var complete = true;
	complete =complete && form.firstname.value.length > 0;
	
	if(! form.firstname.value.length > 0 ) alert('Firstname cannot be null');
	
/*	var combo = 'position';
	if( $F(combo) == 'unselected' )
	{
		alert('You must select an option on ' + combo);
		return false;
	}
	var combo2 = 'country';
	if( $F(combo) == 'unselected' )
	{
		alert('You must select an option on ' + combo2);
		return false;
	}*/
	
	
	complete = complete && form.comments.value.length > 0;
	if(! form.comments.value.length >0 ) alert('Comments cannot be null');
	
	if(complete){
		alert('Thanks, we have received your feedback!');
		form.submit();
	}
}

function goSubmitContact(form){
	var complete = true;
	complete =complete && form.firstname.value.length > 0;
	
	if(! form.firstname.value.length > 0 ) alert('Firstname cannot be null');
	
	complete = complete && form.email.value.length > 0;
	if(! form.email.value.length >0 ) alert('Email cannot be null');
	
	complete = complete && form.email.value.match(/^(.+)@([^();:,<>]+.[a-zA-Z]{2,4})/);
	if(!form.email.value.match(/^(.+)@([^();:,<>]+.[a-zA-Z]{2,4})/) ) alert('The e-mail you provided is invalid');
/*	var combo = 'position';
	if( $F(combo) == 'unselected' )
	{
		alert('You must select an option on ' + combo);
		return false
	}*/
	
	
	complete = complete && form.comments.value.length > 0;
	if(! form.comments.value.length >0 ) alert('Comments cannot be null');
	
	if(complete){
		alert('Thanks, we have received your message!');
		form.submit();
	}
}
function count_click(counter, path){
	var pars = {
		file: "Contenidos",
		method: "count_click",
		type: "ContenidosManager",
		pars: "1",
		p1: "'" + counter + "'"
		}
	var opt = {
		OnSuccess: function(t){
			alert(t.responseText);
		}
	}
		pars = new $H(pars);
		new Ajax.Request(path+"counter.php?"+pars.toQueryString(),opt);
		
	//TODO: HARCODEADO. Hay que agregar una seccion en el panel para indicar el link deseado
	window.location = "http://www.challenge-education.com/site/resources/index.php?seccion=1&cat=32";
}

function goSubmit_newsletter(form){
	var complete = true;
	complete =complete && form.firstname.value.length > 0;
	
	if(! form.firstname.value.length > 0 ) alert('Firstname cannot be null');
	
	complete = complete && form.email.value.length > 0;
	if(! form.email.value.length >0 ) alert('Email cannot be null');
	
	complete = complete && form.email.value.match(/^(.+)@([^();:,<>]+.[a-zA-Z]{2,4})/);
	if(!form.email.value.match(/^(.+)@([^();:,<>]+.[a-zA-Z]{2,4})/) ) alert('The e-mail you provided is invalid');

	if(complete){
		alert('Thanks, you will receive our Newsletter soon!');
		form.submit();
	}
}

function openLegalPopup (_link)
{
	openCenteredWindow(_link, 'Legal', 400, 580, 'scrollbars=yes, resizable=no');
}

function validate_only_number(id){
	if($(id).value.match(/[a-z|A-Z]/g)){
		alert('Solo se permiten valores numericos');
		$(id).value = $(id).value.match(/\d+/g);
	}
}

function confirm_subscription(item, user){
	var bill_code = $F('bill_code');
	var pay_mode = $F('pay_mode');
	var opt = {
		onSuccess: function(t) {
			alert(t.responseText);
			window.location='index.php?seccion=6';			
		 }
	}
	
	var pars = {
		id_user: user,
		id_item : item,
		bill_code: bill_code,
		pay_mode: pay_mode
	}
	new Ajax.Request('confirm.php?'+ $H(pars).toQueryString(),opt); 
	
}
