 var idRestaurante=0;
function formregister(tpuser,img,color)
{
	document.getElementById("formregistro").reset();
	document.getElementById("usu_tipousuario").value=tpuser;
	document.getElementById("formregerror").innerHTML='';
	YAHOO.yahooui.tiposdeuser.hide();
	document.getElementById("cabezaformreg").src=img;
	document.getElementById("skinform").style.color=color;
	document.getElementById("tipoU").innerHTML = (tpuser == 'user') ? "del usuario" : "del establecimiento";
	document.getElementById("mtto").style.display = "none";
	document.getElementById("formregerror").innerHTML="";
	document.getElementById('formuserregister').style.display='';
	document.getElementById('formregistro').style.display='';
	document.getElementById("divregistro").style.background = "#F2F2F2";
	document.getElementById("usu_estado").value = 0;	
	document.getElementById('fechasEspeciales').className = 'ocultar';
	document.getElementById('personaContacto').className = 'ocultar';
	document.getElementById('div_valuta').className = 'ocultar';
	if(tpuser == "restaurante")
	{
		document.getElementById("usu_estado").value = 1;
		document.getElementById('personaContacto').className = 'mostrar';
		document.getElementById('div_valuta').className = 'mostrar item_small';
	}
	else if(tpuser == "hotel")
	{	
		document.getElementById("mtto").style.display = "";
		document.getElementById("divregistro").style.background = "#FFF";
		document.getElementById('formregistro').style.display='none';
		document.getElementById('personaContacto').className = 'mostrar';
	}
	else
	{
		document.getElementById('fechasEspeciales').className = 'mostrar';
	}
	YAHOO.yahooui.formuserregister.show();
	initialize();
}

function checkmail(email){

	var expregmail = new RegExp('^([0-9a-z]+([\._-]{1}[0-9a-z]*)*)@([0-9a-z]+)(([\._-]{1}[a-z]+)*[\.]{1}[a-z]{2,3})$');	

	if(!expregmail.test(email)){ return false;}

	else{ return true; }

}

function verificaform(form){
//$sql_tabla(usu_nombre,usu_identificacion,usu_direccion,usu_telefono,usu_nick,usu_clave,usu_idioma,usu_tipousuario,usu_idmail,usu_domail,usu_estado) ";
	var valid=true;
	if(!validText(document.getElementById("usu_nombre"))) valid=false;
	if(!validText(document.getElementById("usu_nick"))) valid=false;
	if(!validText(document.getElementById("usu_clave"))) valid=false;
	if(!validText(document.getElementById("usu_clave2"))) valid=false;

	if(!valid) document.getElementById("formregerror").innerHTML="<center>Verifique los campos marcados con (*)</center>";
	else {
		if(document.getElementById("usu_clave").value!=document.getElementById("usu_clave2").value){ document.getElementById("formregerror").innerHTML="<center>Las claves no coinciden entre si.</center>"; }
		else{
			var vect=document.getElementById("usu_domail").value.split(".");
			if(vect.length<=1)  document.getElementById("formregerror").innerHTML="<center>Porfavor ingrese un correo valido</center>";
			else form.submit();
		}
	}
}

function verificaform2(form){
//$sql_tabla(usu_nombre,usu_identificacion,usu_direccion,usu_telefono,usu_nick,usu_clave,usu_idioma,usu_tipousuario,usu_idmail,usu_domail,usu_estado) ";
	var valid=true;
	if(!validText(document.getElementById("com_asunto"))) valid=false;

    if(document.getElementById('usu_id').value==''){
    	if(!validText(document.getElementById("com_idmail"))) valid=false;
	    if(!validText(document.getElementById("com_domail"))) valid=false;
    }

    if(!validText(document.getElementById("com_descripcion"))) valid=false;

	if(!valid) document.getElementById("formcomerror").innerHTML="<center>Verifique los campos marcados con (*)</center>";
	else {
        if(document.getElementById('usu_id').value==''){
  			var vect=document.getElementById("com_domail").value.split(".");
  			if(vect.length<=1)  document.getElementById("formcomerror").innerHTML="<center>Porfavor ingrese un correo válido</center>";
  			else insertcoment("include/insert_coment.php"); 
    	}else{
            insertcoment("include/insert_coment.php");
            //form.submit();
        }
	}
}

function verificaformPerfil(form){
    var valid=true;
	if(!validText(document.getElementById("usu_nombre"))) valid=false;
	if(!validText(document.getElementById("usu_identificacion"))) valid=false;
	if(!validText(document.getElementById("usu_direccion"))) valid=false;
	if(!validText(document.getElementById("usu_telefono"))) valid=false;
	if(!validText(document.getElementById("usu_idmail"))) valid=false;
	if(!validText(document.getElementById("usu_domail"))) valid=false;

	if(!valid) document.getElementById("formperfilrror").innerHTML="<center>Verifique los campos marcados con (*)</center>";
	else {
        	var vect=document.getElementById("usu_domail").value.split(".");
			if(vect.length<=1)  document.getElementById("formregerror").innerHTML="<center>Porfavor ingrese un correo valido</center>";
			else form.submit();
	}
}

function validText(obj){
	var vlacmp = obj.value.replace(/^\s+|\s+$/g, '');
    if( vlacmp === '' ) { return false; }else { return true; }
}

function popup(theURL,winName,w,h) { //v2.0
   var Ancho=w;
   var Alto=h;
   var Izquierdo = (screen.width/2) - Ancho/2;
   var Superior = (screen.height/2) - Alto/2;
   var Estilo = 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+Ancho+',height='+Alto+',left='+Izquierdo+',top='+Superior+',screenX='+Izquierdo+',screenY='+Superior;
   var Ventana = window.open(theURL,winName,Estilo);
   /*window.open(theURL,winName,features);*/
}

/*funcion para insertar comentarios*/
function insertcoment(_pagina){
	ajax = objetus();
	
	var descripcion=document.getElementById('com_descripcion').value.replace('"','');
	descripcion=document.getElementById('com_descripcion').value.replace(/\'/g,"***");
	descripcion=escape(descripcion);
	asunto=escape(document.getElementById('com_asunto').value.replace(/\'/g,"***"));
	var capa=document.getElementById('divcontformresult');
	
	campos="sql='"+document.getElementById('usu_id').value+"','"+asunto+"','"+document.getElementById('com_idmail').value+"','"+document.getElementById('com_domail').value+"','"+descripcion+"','"+document.getElementById('com_tipo').value+"','"+document.getElementById('com_estado').value+"',"+idRestaurante;
    	
	ajax.onreadystatechange=function() {
		if (ajax.readyState==1){
    		        document.getElementById('divfcomentario').className='ocultar';
    		        document.getElementById("divfcomentariorest").className='mostrar';
    		        capa.innerHTML = "<img src='loadingcircle.gif' align='center'>Cargando..."; }
    		if (ajax.readyState==4) {
			if(ajax.status==200){ capa.innerHTML = ajax.responseText; }
			else if(ajax.status==404){ capa.innerHTML = "La dirección no existe"; }
			else{ capa.innerHTML = "Error: ".ajax.status;}
		}
	}
	
	ajax.open("POST",_pagina+"?r="+Math.random(), true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(campos);
}

/*end*/
function comentPortal(id){
	idRestaurante=id;
	document.getElementById('formcomerror').innerHTML='';
	document.getElementById('divcomentarios').style.display='';
	YAHOO.comentario.divcomentarios.show(); 
	document.getElementById('formcomentarios').reset();
	document.getElementById("divfcomentariorest").className="ocultar";
	document.getElementById("divfcomentario").className="mostrar";
}

function masVotadosR(){
	document.getElementById('masVotados').style.display='';
	YAHOO.comentario.masVotados.show(); 
}

function buscarHotel(){
	document.getElementById('buscaHoteles').style.display='';
	YAHOO.comentario.buscaHotel.show(); 
}

function ultimosNuevosR()
{
	document.getElementById('ultimosNuevos').style.display='';
	YAHOO.comentario.ultimosNuevos.show(); 
}

function ultimasOfertasR()
{
	document.getElementById('ultimasOfertas').style.display='';
	YAHOO.comentario.ultimasOfertas.show(); 
}

function recomendarRest(){
	document.getElementById('formcomerror').innerHTML='';
	document.getElementById('divrecomendar').style.display='';
	YAHOO.recomendar.divrecomendar.show(); 
	document.getElementById('formrecomendar').reset();
}

function verificNick(obj){
	capa=document.getElementById('validnick');	
	capa.innerHTML = '';
	if(obj.value == "")
		return;
	ajax = objetus();
	campos="&nick="+obj.value;
	ajax.onreadystatechange=function() {
		if (ajax.readyState==1){ capa.innerHTML = "Verificando..."; }
		if (ajax.readyState==4) {
			if(ajax.status==200){ 
				if(ajax.responseText) capa.innerHTML ='<b>Nick de usuario aceptado</b><br /><img src="style/img/ok.png" style="display: inline;">';
				else{
					nomNick = obj.value;
					obj.value=""; obj.focus();
					capa.innerHTML = '<b>'+nomNick+'</b> es un nick de usuario no permitido.<br /><img src="style/img/cancel.png" style="display: inline;">';
				}
				//alert(ajax.responseText); capa.innerHTML = ajax.responseText; 
			}
			else if(ajax.status==404){ capa.innerHTML = "La dirección no existe"; }
				else{ capa.innerHTML = "Error: ".ajax.status;}
		}
	}
	capa.innerHTML = "<img src='style/img/indicator.gif' style=\"display: inline;\" align='center'>";
	ajax.open("POST","sesion/verific_nic.php"+"?r="+Math.random(), true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(campos);
}
