function Register(){
	val = ValTextLength('RegName', 1);
	if(!val)
	{
		alert("El Nombre es obligatorio");
		//document.getElementById('RegName').select();
		//document.getElementById('RegName').focus();
		return;
	}
	val = ValTextLength('RegLastName', 1);
	if(!val)
	{
		alert("El Apellido es obligatorio");
		return;
	}
	val = ValTextLength('RegNickName', 1);
	if(!val)
	{
		alert("El Usuario(NickName) es obligatorio");
		return;
	}
	val = ValTextLength('RegeMail', 1);
	if(!val)
	{
		alert("La dirección de correo es obligatoria");
		return;
	}
	else
	{
		val = ValEMail('RegeMail');
		if(!val)
		{
			alert("Esturctura de correo erronea");
			return;
		}
	}
	val = ValTextLength('RegPassW', 6);
	if(!val)
	{
		alert("La contraseña debe tener al menos 6 caracteres");
		return;
	}
	else
	{
		if (document.getElementById('RegPassW').value == document.getElementById('RegPassWII').value)
		{
			SendRegistration();
		}
		else
		{
			alert("Fallo de verificación de Contraseña");
		}
	}
}

function ValTextLength(xObject, xMinLength){
	if (document.getElementById(xObject).value.length < xMinLength)
	{
		return false;
	}
	else
	{
		return true;
	}
}

function ValEMail(xObject){
	xVer1 = document.getElementById(xObject).value.split("@");
	if (xVer1.length < 2)
	{
		return false;
	}
	else
	{
		xVer2 = xVer1[1].split(".com");
		if (xVer2.length < 2)
		{
			return false;
		}
		else
		{
			if (xVer2[0].length < 1)
			{
				return false;
			}
			else
			{
				return true;
			}
			
		}
	}	
}

function SendRegistration(){
	xString = 'op=Register&Name=' + document.getElementById('RegName').value;
	xString = xString + '&LastName=' + document.getElementById('RegLastName').value;
	xString = xString + '&NickName=' + document.getElementById('RegNickName').value;
	xString = xString + '&Mail=' + document.getElementById('RegeMail').value;
	xString = xString + '&PassW=' + document.getElementById('RegPassW').value;
	var AjaxSendRegistration = new req('AjaxSendRegistration');
	var xRegSuccess = new RegSuccess();
	AjaxSendRegistration.xmlhttpPost('ops.php', xRegSuccess,xString);
	//alert(xString);
}

function RegSuccess(){
	this.callBackFunction = function(xTxt) 
	{
		if(xTxt == 'ok')
		{
			alert("Se registro exitosamente. Muchas Gracias!");
			window.location = "index.php";
		}
		else
		{
			alert("Fallo la registración, vuela a intentarlo más tarde");
		}
	}
}

function LogIn(){
	xString = 'op=LogIn&NickLogIn=' + document.getElementById('NickLogIn').value;
	xString = xString + '&PassLogIn=' + document.getElementById('PassLogIn').value;
	var AjaxLogIn = new req('AjaxLogIn');
	var xLogInResult = new LogInResult();
	AjaxLogIn.xmlhttpPost('ops.php', xLogInResult,xString);
}

function LogInResult(){
	this.callBackFunction = function(xTxt) 
	{
		if(xTxt == 'ok')
		{
			alert("Se registro exitosamente.");
			window.location = "index.php";
		}
		else
		{
			alert("Usuario o Contraseña Incorrectas, vuelva a intentarlo");
		}
	}
}

function LogOut(){
	xString = 'op=LogOut';
	var AjaxLogOut = new req('AjaxLogOut');
	var xLogOutResult = new LogOutResult();
	AjaxLogOut.xmlhttpPost('ops.php', xLogOutResult,xString);
}

function LogOutResult(){
	this.callBackFunction = function(xTxt) 
	{
		window.location = "index.php";
	}
}
