/*
ESTAS FUNCIONES LAS UTILIZA EL PANEL IZQUIERDO QUE INCLUYE
REGISTRO DE USUARIO
*/
//---------------------------------------------------------------------------
//var js_asientos = new Object();
var js_segs = 0;
var js_est_tiempo_session = false;
var js_est_expiracion = false;
var js_limite_session = 900;//900 15 minutos
//var js_limite_session = 10;//

cerrar_session = function(){
	if(js_view_comprar){
		cerrar_comprar_pasajes();
	}

	//$("tiempo_restante_0").value = 0;
	$("tiempo_restante_0").value = js_limite_session;											
	js_est_tiempo_session = false;
	
	var cfg_loading =  function(){
		hide_elements_forms("SELECT",true);
		msg_info("load",true);
	}
	var cfg_complete = function(){
		js_login = "failed";
		actualizar_asientos();
		carrito();
		hide_elements_forms("SELECT",false);
		datos_usuario();
		//msg_info("load",false);
		$("div_view_login").show();
	}
	var ruta = "cerrar_session.php";
	var ajx = new Ajax.Updater("div_msg_login",ruta,{
					onLoading: cfg_loading,onComplete: cfg_complete
				}
	);
	
	delete ruta,ajx;
}


datos_usuario = function(){
	var ajx = new Ajax.Updater("div_datos_usuario","datos_usuario.php");
}

cronometro = function(){
	//alert("tiempo ok...");
	if(js_est_tiempo_session){
		var valor = parseInt($F("tiempo_restante_0"));
		//alert(valor);
		//valor++;
		valor--;
		//obteniendo los minutos y ssegundos
		//-----------------------------------
		var ms = parseInt(valor/60);	
		var sgs = parseInt(valor%60);
		js_segs = valor;
		
		js_tiempo_transcurrido = ms+":"+sgs;
		if(sgs<10){
			js_tiempo_transcurrido = ms+":"+"0"+sgs;
		}
		
		//window.status = "minutos: "+ms+" segundos: "+sgs;
		window.status = js_tiempo_transcurrido;		
		if($("tiempo_restante_1")){
			$("tiempo_restante_1").value = js_tiempo_transcurrido;	
		}		
		//-----------------------------------
		//alert(valor);
		$("tiempo_restante_0").value = valor;
		//si se pasa del limite maximo se debe cerrar la session
		//if(valor > js_limite_session){//15 minutos
		if(valor <= 0){//15 minutos
			js_est_expiracion = true;
			cerrar_session();									
		}
		setTimeout("cronometro()",1000);
	}
}

msg_expiracion = function(){
	js_est_expiracion = false;
	alert("Su tiempo de session a Expirado\n"+
		  "Su COMPRA no fue completada.\n\n" + 
		  "Reinicie su session para completar su COMPRA.");	
	$("usuario").focus();
}

iniciar_cronometro = function(){
	js_est_tiempo_session = true;
	//alert("cronometro...-- js_login"+js_login);
	//if(js_login == "ok"){
		//alert("cronometro... iniciando...");
		cronometro();
	//}
}
<!-- servicios -->
ver_servicios = function(){   
	$("frm_login").disable();
	var cfg_result = function(){
		//alert("1");
		hide_elements_forms("SELECT",true);
		//alert("2");
		//alert(screen.height+" - "+screen.availHeight);
		var args = new Object();
		args["left"] = "0px";
		args["top"] = "0px";
		//args["width"] = screen.width+"px";
		//args["height"] = screen.height+"px";		
		
		//alert("3");
		ocultar_elemento("div_back",false,null);
		ocultar_elemento("div_servicios",false,args);
	//	var txt_correo = $("frm_recordar").getInputs("text","correo");
		//alert(txt_correo);		
		txt_correo.invoke("focus");		
		//alert("4");
		//$("div_usuario").show();
		//msg_info("load",false);		
		//alert("123");
		setTimeout('$("div_msg_info").hide();',1000);
		delete args;
		//delete txt_correo;
	}
	var ruta = "servicios.php?codcliente="+js_cod_cliente;
	var ajx = new Ajax.Updater("div_servicios",ruta,{
							evalScripts: true,
							onLoading: function(){ msg_info("load",true); },
							onComplete: function(){ 
								msg_info("load",false);
								//alert("ayumi");
								cfg_result();
							}
						}
			  );
			  
	delete ruta,ajx;
}
<!-- fin servicios -->
<!-- Politicas -->
ver_politicas = function(){   
	$("frm_login").disable();
	var cfg_result = function(){
		//alert("1");
		hide_elements_forms("SELECT",true);
		//alert("2");
		//alert(screen.height+" - "+screen.availHeight);
		var args = new Object();
		args["left"] = "0px";
		args["top"] = "0px";
		//args["width"] = screen.width+"px";
		//args["height"] = screen.height+"px";		
		
		//alert("3");
		ocultar_elemento("div_back",false,null);
		ocultar_elemento("div_politicas",false,args);
	//	var txt_correo = $("frm_recordar").getInputs("text","correo");
		//alert(txt_correo);		
		txt_correo.invoke("focus");		
		//alert("4");
		//$("div_usuario").show();
		//msg_info("load",false);		
		//alert("123");
		setTimeout('$("div_msg_info").hide();',1000);
		delete args;
		//delete txt_correo;
	}
	var ruta = "politicas.php?codcliente="+js_cod_cliente;
	var ajx = new Ajax.Updater("div_politicas",ruta,{
							evalScripts: true,
							onLoading: function(){ msg_info("load",true); },
							onComplete: function(){ 
								msg_info("load",false);
								//alert("ayumi");
								cfg_result();
							}
						}
			  );
			  
	delete ruta,ajx;
}
<!-- Politicas -->
<!-- Politicas -->
ayuda = function(){   
	$("frm_login").disable();
	var cfg_result = function(){
		//alert("1");
		hide_elements_forms("SELECT",true);
		//alert("2");
		//alert(screen.height+" - "+screen.availHeight);
		var args = new Object();
		args["left"] = "0px";
		args["top"] = "0px";
		//args["width"] = screen.width+"px";
		//args["height"] = screen.height+"px";		
		
		//alert("3");
		ocultar_elemento("div_back",false,null);
		ocultar_elemento("div_ayuda",false,args);
	//	var txt_correo = $("frm_recordar").getInputs("text","correo");
		//alert(txt_correo);		
		txt_correo.invoke("focus");		
		//alert("4");
		//$("div_usuario").show();
		//msg_info("load",false);		
		//alert("123");
		setTimeout('$("div_msg_info").hide();',1000);
		delete args;
		//delete txt_correo;
	}
	var ruta = "ayuda.php?codcliente="+js_cod_cliente;
	var ajx = new Ajax.Updater("div_ayuda",ruta,{
							evalScripts: true,
							onLoading: function(){ msg_info("load",true); },
							onComplete: function(){ 
								msg_info("load",false);
								//alert("ayumi");
								cfg_result();
							}
						}
			  );
			  
	delete ruta,ajx;
}
<!-- Oliticas -->
registro_usuario = function(){   

	$("frm_login").disable();
	var cfg_result = function(){
		hide_elements_forms("SELECT",true);
		//alert(screen.height+" - "+screen.availHeight);
		var args = new Object();
		args["left"] = "0px";
		args["top"] = "0px";
		//args["width"] = screen.width+"px";
		//args["height"] = screen.height+"px";			
		
		ocultar_elemento("div_back",false,null);
		ocultar_elemento("div_usuario",false,args);
		/*
		Effect.Appear('div_usuario');
		Effect.Appear('div_back');	
		*/
		//$("div_usuario").show();
		delete args;
	}
	var ruta = "registro_usuario.php?codcliente="+js_cod_cliente;
	var ajx = new Ajax.Updater("div_usuario",ruta,{
							evalScripts: true,
							onLoading: function(){ msg_info("load",true); },
							onComplete: function(){ msg_info("load",false);cfg_result();}
						}
			  );
			  
	delete ruta,ajx;
}

recordar_password = function(){   
	$("frm_login").disable();
	var cfg_result = function(){
		//alert("1");
		hide_elements_forms("SELECT",true);
		//alert("2");
		//alert(screen.height+" - "+screen.availHeight);
		var args = new Object();
		args["left"] = "0px";
		args["top"] = "0px";
		//args["width"] = screen.width+"px";
		//args["height"] = screen.height+"px";		
		ocultar_elemento("div_back",false,null);
		//alert("3");
		ocultar_elemento("div_recordar_clave",false,args);
		var txt_correo = $("frm_recordar").getInputs("text","correo");
		//alert(txt_correo);		
		txt_correo.invoke("focus");		
		//alert("4");
		//$("div_usuario").show();
		//msg_info("load",false);		
		//alert("123");
		setTimeout('$("div_msg_info").hide();',1000);
		delete args;
		//delete txt_correo;
	}
	var ruta = "recordar_password.php?codcliente="+js_cod_cliente;
	var ajx = new Ajax.Updater("div_recordar_clave",ruta,{
							evalScripts: true,
							onLoading: function(){ msg_info("load",true); },
							onComplete: function(){ 
								msg_info("load",false);
								//alert("ayumi");
								cfg_result();
							}
						}
			  );
			  
	delete ruta,ajx;
}

logear = function(){
	var R = js_verificar_form("frm_login");
	if(R){
		var Form = $("frm_login");
		var inputs = Form.getInputs("text","usuario");
		var email = $F(inputs[0]);
		//alert($F(inputs[0]));
		//alert(email);
		var R2 = emailCheck(email);
		//var R2 = true;
		if(R2){
			var ruta = "logear.php";
			var cfg_login = function(){
				//msg_info("load",false);
				//$("div_msg_info").style.display = "none";
				//alert("se ha logeado...");
				//return true;
				var ope_result = $F("txt_ope_result");
				var ope_msg = $F("txt_ope_msg");
				//alert(ope_result+" - "+ope_msg);
				if(ope_result == "failed" && ope_msg == "email"){
					alert("Esta cuenta de E-mail no esta en nuestra Base de Datos");
					$("usuario").focus();
					msg_info("load",false);
					setTimeout('hide_elements_forms("SELECT",false);',1000);
				}
				else if(ope_result == "failed" && ope_msg == "password"){
					alert("Este Password no corresponde con esta cuenta de E-mail");
					$("password").focus();
					msg_info("load",false);
					setTimeout('hide_elements_forms("SELECT",false);',1000);
				}
				else if(ope_result == "failed" && ope_msg == "bloqueado"){
					alert("Su cuenta ha sido bloqueda por el dia de hoy\n"+
						  "por ingresar 3 veces sin hacer una compra.\n\n Disculpe la molestia.");
					$("password").focus();
					msg_info("load",false);
				}
				else if(ope_result == "ok"){
					$("div_view_login").hide();
					//alert("TURISMO CIVA le da la Bienvenida.");
					datos_usuario();
					iniciar_cronometro();
					actualizar_asientos();			
					carrito();
					js_elegir_asientos = true;
					js_login = "ok";
				}
				
				delete ope_result,ope_msg;
			}
			var datos = $("frm_login").serialize();
			//alert(datos);
			var ajx = new Ajax.Updater("div_msg_login",ruta,{
									evalScripts: true,
									method: "POST",
									parameters: datos,
									onLoading: function(){ msg_info("load",true); },
									onComplete: function(){ cfg_login(); }
								}
					  );
					  
			delete ruta,ajx;
			delete datos;
		}		
		delete Form,inputs,email,R2;
	}
	delete R;
}
//---------------------------------------------------------------------------

