var regis=function(){};

regis.prototype.sajasVal="POST";
regis.prototype.DevuelvoValorQue=function(form, elemento){
	var e = form.elements;
	
	for(i=0;i<e.length;i++)
	{		
		if(e[i].name == "profileTipo")
		{
			if(e[i].checked){	
			//alert(e[i].value);			
				return e[i].value;
				
			}
		}
	}
}

regis.prototype.validoRegistro=function(form){
	//var sajax_request_type = this.sajasVal;
	var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	var res = /^[\w-]+{\/}$/;
	var username=$('username');
	var pass = $('password');
	var email=$('email');
	var check= $('selec');
	var sexo= $('sexo');
	//var validaImage=$('validaImage');
	var N_Pais=$('N_Pais');
	var N_Provincia=$('N_Provincia');
	var N_localidad=$('N_localidad');
	var Nombre=$('Nombre');
	var Apellido=$('Apellido');
	var FechaCumpleanio=$('FechaCumpleanio');
	var ErrorRegistro=$('ErrorRegistro');
	var efe;
	if(!username.value){
		efe =new Effect.Highlight(ErrorRegistro,{duration: 0.3});		
		ErrorRegistro.update("Debe Ingresar Su nombre De Usuario").setStyle({fontWeight: "bolder"}); username.focus(); return;
	}else if((username.value.lastIndexOf("/")!=-1 || username.value.lastIndexOf(" ")!=-1)){
		efe =new Effect.Highlight(ErrorRegistro,{duration: 0.3});
		ErrorRegistro.update("Usted esta intentado usar caracteres ilegales para el nombre de usuario, por favos use solo letras y numero e intente nuevamente").setStyle({fontWeight: "bolder"});  username.focus(); return;
	}else if(!pass.value){
		efe =new Effect.Highlight(ErrorRegistro,{duration: 0.3});
		ErrorRegistro.update("Debe Ingresar Su Password").setStyle({fontWeight: "bolder"});  pass.focus(); return;
	}else if(!email.value){
		efe =new Effect.Highlight(ErrorRegistro,{duration: 0.3});
		ErrorRegistro.update("Debe Ingresar Su Email").setStyle({fontWeight: "bolder"});  email.focus(); return;
	}else if(!email.value.match(re)){
		efe =new Effect.Highlight(ErrorRegistro,{duration: 0.3});
		ErrorRegistro.update("Debe Ingresar Un Email Valido").setStyle({fontWeight: "bolder"});  email.focus(); return;
	}else if(sexo.value==0){
		efe =new Effect.Highlight(ErrorRegistro,{duration: 0.3});
		ErrorRegistro.update("Debe Seleccionar Su Genero").setStyle({fontWeight: "bolder"});  sexo.focus(); return;
	}/*else if(!validaImage.value){
		efe =new Effect.Highlight(ErrorRegistro,{duration: 0.3});
		ErrorRegistro.update("Por Favor Debe Ingresar El Valor Que Aparece En La Imagen").setStyle({fontWeight: "bolder"});  validaImage.focus(); return;
	}*/else if(!check.checked){
		efe =new Effect.Highlight(ErrorRegistro,{duration: 0.3});
		ErrorRegistro.update("Para Registrarce Debe Aceptar Los Terminos De Uso").setStyle({fontWeight: "bolder"});  return;
	}else if(!Nombre.value){
		efe =new Effect.Highlight(ErrorRegistro,{duration: 0.3});
		ErrorRegistro.update("Por Favor Ingrese Su Nombre De Pila").setStyle({fontWeight: "bolder"});  Nombre.focus(); return;
	}else if(!Apellido.value){
		efe =new Effect.Highlight(ErrorRegistro,{duration: 0.3});
		ErrorRegistro.update("Por Favor Ingrese Su Apellido").setStyle({fontWeight: "bolder"});  Apellido.focus(); return;
	}else if(!FechaCumpleanio.value){
		efe =new Effect.Highlight(ErrorRegistro,{duration: 0.3});
		ErrorRegistro.update("Por Favor Seleecione El Calendario Para Ingresar Su Fecha De Cumpleaņo").setStyle({fontWeight: "bolder"}); 
	}else{
		var datos;
		ErrorRegistro.update(pagi.procesarLog('../'));
		datos=username.value+"##"+pass.value+"##"+email.value+"##"+sexo.value+"##"+N_Pais.value+"##"+N_Provincia.value+"##"+N_localidad.value+"##"+Nombre.value+"##"+Apellido.value+"##"+FechaCumpleanio.value;
		x_registrarNuevoUSu(datos,this.mostrarResultadoRegistros);
		//alert(datos);
	}
	
}
regis.prototype.genLoginForm=function(valor){
	
	x_GenLogiForm(valor,pagi.MOstrarAlgunRes);	
}

regis.prototype.login_Function=function(valor,ruta){
	var form=$('Login');
	var datos;
	var usuario=$("usuario");
	var pass=$("pass");
	var errorLog=$('errorLogin');
	var efe;
	if(!usuario.value){
		var efe =new Effect.Highlight(errorLog,{duration: 0.3});
		errorLog.update("<b>Por favor inserte su nombre de usuario</b>"); usuario.focus(); return;
		
	}else if(!pass.value){
		var efe =new Effect.Highlight(errorLog,{duration: 0.3});
		errorLog.update("<b>Por favor inserte su password</b>"); pass.focus(); return;		
	}else{
		errorLog.update(pagi.procesarLog(ruta)).setStyle({background:"#fff",color:"#000"});
		
		var url=ruta+"php_files/clases/regitros/ValidoLogin.php";
		new Ajax.Request(url, {   
			parameters: {usuario:usuario.value, pass:pass.value,valor:valor},   
			onSuccess: function(transport) {
				 var notice = $('notice');
				 if (transport.responseText=="1"){
				 	efe =new Effect.Highlight(errorLog,{duration: 0.3});
				 	errorLog.update('<b>El Usuario No Existe En La Base De Dato</b>').setStyle({ background: '#AE0000',color:"#fff" });
				 	
				 }else if(transport.responseText=="2"){
				 	efe =new Effect.Highlight(errorLog,{duration: 0.3});
				 	errorLog.update('<b>El Password Es Incorrecto</b>').setStyle({ background: '#AE0000',color:"#fff" });
				 }else if(transport.responseText=="4"){
				 	efe =new Effect.Highlight(errorLog,{duration: 0.3});
				 	errorLog.update('<b>Bienvenido Al Sistema</b>').setStyle({ background: '#dfd' });
				 	setTimeout('pagi.RefrescoPagina()',1000);				 	
				 }else{
				 	$('Join').update(transport.responseText);
				 	
				 }
		 }}); 
	}
}

regis.prototype.RecuperaFunction=function(ruta){
	var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	var res = /^[\w-]+{\/}$/;
	var datos;
	var Usuario=$('NUsuario');
	var EmailUsu=$('EmailUsu');
	var Npass=$('Npass');
	var errorLog=$('errorLogin');
	var efe;
	if(!Usuario.value){
		efe =new Effect.Highlight(errorLog,{duration: 0.3});
		errorLog.update("<b>Por Fasvor Ingrese Su Usuario</b>"); Usuario.focus(); return;
	}else if(!EmailUsu.value){
		efe =new Effect.Highlight(errorLog,{duration: 0.3});
		errorLog.update("<b>Por Favor Ingrese Su E-mail</b>"); EmailUsu.focus(); return;
	}else if(!EmailUsu.value.match(re)){
		efe =new Effect.Highlight(errorLog,{duration: 0.3});
		errorLog.update("<b>Debe Ingresar Una Direccion De E-mail Valida</b>"); EmailUsu.focus(); return;
	}else if(!Npass.value){
		efe =new Effect.Highlight(errorLog,{duration: 0.3});
		errorLog.update("<b>Por Favor Ingrese Su Nuevo Password</b>"); Npass.focus(); return;
	}else{
		errorLog.update(pagi.procesarLog(ruta)).setStyle({background:"#fff",color:"#000"});
		datos=Usuario.value+"##"+EmailUsu.value+"##"+Npass.value;
		x_SajxRecupassSystem(datos,pagi.MOstrarAlgunRes);
	}
}
regis.prototype.mostrarResultadoRegistros=function(datos){
	if(datos==2){
		$('ErrorRegistro').update("Este E-mail esta actualmente en uso, por seleccione uno diferente");
	}else if(datos==3){
		$('ErrorRegistro').update("Este Nombre De Usuario Esta Actualmente en uso");
	}else if(datos==4){
		$('ErrorRegistro').update("El Valor Que Ingreso Para Validar La Imagen Es Incorrecta");
	}else{
		//alert("llegue hast aaca");
		regi.AmpliarInfo(1,datos);
		//document.getElementById('RegistroOk').innerHTML =datos;
	}
}

regis.prototype.genFormRecupero=function(){
	var datos=0;
	x_genFormRecupero(datos,pagi.MOstrarAlgunRes);
}

regis.prototype.mostrarResultadoSiguientePaso=function(datos){	
	document.getElementById('RegistroOk').innerHTML =datos;	
}
regis.prototype.AmpliarInfo=function(tipo,id){
	if(tipo==1){
		pagi.IrAlgunLado("../");
	}else{
		pagi.IrAlgunLadoConcat("&Ampliar=true&idEvent="+id);
	}
}

regis.prototype.SigueCompletandoPaso1=function(){
	//sajax_request_type = this.sajasVal;
	
	var nombre = $('nombre');
	var apellido= $('apellido');
	var pais = $('N_Pais');
	var provincia= $('N_Provincia');
	var localidad=$('N_localidad');
	var codigoPostal=$('CodigoPostal');
	var introduccion=$('introduction');
	var miSexlife=$('mySexLife');
	var imagen=$('BroImageFileImage');
	var OtroSitio=$('OtroSitio');	
	var cumple=$('FechaCumpleanios');
	if(!introduccion.value){
		alert("Tell the members something about yourself"); introduccion.focus(); return;
	}else if(!cumple.value){
		alert("Please insert youur birthday in the format year-month-day or pick the calender icon"); cumple.focus(); return; 
	}else if(cumple.value.indexOf("0000")>-1){
		alert("Pease insert youur birthday in the format year-month-day or pick the calender icon"); cumple.value=""; cumple.focus();   return;		
	}else{
		var datos;
		
		datos=nombre.value+"##"+apellido.value+"##"+pais.value+"##"+provincia.value+"##"+localidad.value+"##"+codigoPostal.value+"##"+introduccion.value+"##"+imagen.value+"##"+miSexlife.value+"##"+OtroSitio.value+"##"+cumple.value;
		//alert(datos);
		x_ActualizoProfilePaso1(datos,this.mostrarResultadoSiguientePaso);
	}
}

regis.prototype.SigueCompletandoPaso1Performer=function(){
	//sajax_request_type = this.sajasVal;
	
	var nombre = document.getElementById('nombre');
	var apellido= document.getElementById('apellido');
	var pais = document.getElementById('N_Pais');
	var provincia= document.getElementById('N_Provincia');
	var localidad=document.getElementById('N_localidad');
	var codigoPostal=document.getElementById('CodigoPostal');
	var website=document.getElementById('WebSite');
	var introduccion=document.getElementById('introduction');
	var tipoPerformer=document.getElementById('TipPerformer');
	var miSexlife=document.getElementById('mySexLife');
	var imagen=document.getElementById('BroImageFileImage');
	
	//var cumple=document.getElementById('FechaCumpleanios');
	if(!introduccion.value){
		alert("Tell the members something about yourself"); introduccion.focus(); return;
	}else{
		var datos;
		datos=nombre.value+"##"+apellido.value+"##"+pais.value+"##"+provincia.value+"##"+localidad.value+"##"+codigoPostal.value+"##"+introduccion.value+"##"+imagen.value+"##"+miSexlife.value+"##"+website.value+"##"+tipoPerformer.value;
		x_ActualizoProfilePaso1Performer(datos,this.mostrarResultadoSiguientePaso);
	}
}

regis.prototype.SigueCompletandoPaso1Seller=function(){
	//sajax_request_type = this.sajasVal;
	
	var comoconocion=document.getElementById('ComoCono');	
	var nombre = document.getElementById('nombre');	
	var apellido= document.getElementById('apellido');	
	var compania= document.getElementById('compania');	
	var telefonoCOntacto=document.getElementById('telefonoCOntacto');	
	var customerTelefono=document.getElementById('customerTelefono');	
	var CustomerEmail=document.getElementById('CustomerEmail');	
	var direccion=document.getElementById('direccion');	
	var pais = document.getElementById('N_Pais');	
	var provincia= document.getElementById('N_Provincia');	
	var localidad=document.getElementById('N_localidad');	
	var codigoPostal=document.getElementById('CodigoPostal');	
	var hubicacionfisica=document.getElementById('hubicacionfisica');	
	var WebSite=document.getElementById('WebSite');	
	var ShortDescription=document.getElementById('ShortDescrip');
	var introduccion=document.getElementById('introduction');	
	
	var Direc=document.getElementById('Direc');	
	var SubCatePrin=document.getElementById('SubCatePrin');
	var SubCate=document.getElementById('SubCate');
	var imagen=document.getElementById('BroImageFileImage');
	
	if(!nombre.value){
		alert("Please insert your real name"); nombre.focus(); return;
	}else if(!apellido.value){
		alert("Please insert your real last name"); apellido.focus(); return;
	}else if(!compania.value){
		alert("Please insert the name of your company"); compania.focus(); return;
	}else if(!direccion.value){
		alert("Please Insert your adress"); direccion.focus(); return;
	}else if(!codigoPostal.value){
		alert("Please insert your postal code"); codigoPostal.focus(); return;
	}else if(hubicacionfisica.value==0){
		alert("Please Select your Business Location"); hubicacionfisica.focus(); return;
	}else if(!ShortDescription.value){
		alert("Please Insert a Short Description for business listing"); ShortDescription.focus(); return;
	}else if(!introduccion.value){
		alert("Tell the members something about yourself"); introduccion.focus(); return;
	}else{
		var datos;
		datos=comoconocion.value+"##"+nombre.value+"##"+apellido.value+"##"+compania.value+"##"+telefonoCOntacto.value+"##"+customerTelefono.value+"##"+CustomerEmail.value+"##"+direccion.value+"##"+pais.value+"##"+provincia.value+"##"+localidad.value+"##"+codigoPostal.value+"##"+hubicacionfisica.value+"##"+WebSite.value+"##"+introduccion.value+"##"+Direc.value+"##"+SubCatePrin.value+"##"+SubCate.value+"##"+imagen.value+"##"+ShortDescription.value;
		x_ActualizoProfilePasoSeller(datos,GotoToHome);
	}
}

regis.prototype.wordCounter=function(field, maxlimit, divCuenta) {
	var countfield= document.getElementById(divCuenta)
      if (field.value.length > maxlimit){
      	field.value = field.value.substring(0, maxlimit);
      }else{
      	countfield.innerHTML ="Characters remaining "+( maxlimit - field.value.length);
      }
  //}
}

regis.prototype.ActualizoFormRePage=function(form,caso){
	form.action="?Inserta=true&caso="+caso;
	form.submit();
}
function finishLater(){
	if(confirm("Sure that you want to finish later ?")){
		pagi.IrAlgunLado('../');
	}
}

function GotoToHome(){	
	window.location='../';	
}

regi=new regis();