// JavaScript Document
function isEmailAddress(name){
  var s = document.getElementById(name).value;
  var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
  if (s.length == 0 ) return true;
  if (filter.test(s))
  return true;
  else
  document.getElementById(name).focus();
  return false;
}

function getValor(input){
  return document.getElementById(input).value;
}

function limpiar(){
   document.getElementById("name").value="";
   document.getElementById("address").value="";
   document.getElementById("email").value="";
   document.getElementById("comments").value="";
}

function validar(){
   var error = "";
   
   if(getValor("name")=="") error+= "Insert name\n";
   if(getValor("email")==""){
	 error+= "Insert email\n";
   }else{
	 if(!isEmailAddress('email')) error+="Insert valid email\n";
   }
   if(getValor("comments")=="") error+= "Insert message\n";
   
   if(error!="") alert(error);
   else document.frm.submit();
}

function _sel(id,tipo){
   document.location.href = 'clients.php?tipo=' + tipo + '&id=' + id;
}

function validar_login(){

	var user = document.getElementById("user").value;
	var pass = document.getElementById("pass").value;
	if(user==""){
		alert("Ingresar Usuario");
		document.getElementById("user").focus();
	}else{
	   if(pass==""){
		   alert("Ingresar Password");
		   document.getElementById("pass").focus();
	   }else{
		   document.frm.action="login.php";
		   document.frm.submit();
	   }
	}
 }
 
function validar_contra(){
 if(document.frm.contrasena.value==""){
	 alert("Ingresar contraseņa");
	 document.frm.contrasena.focus();
 }else{
   if(document.frm.contrasena.value!=document.frm.contrasena_nueva.value){
	   alert("Contraseņa Incorrecta");
	   document.frm.contrasena_nueva.focus();
   }else{
	   document.frm.action="graba_contra.php";
	   document.frm.submit();
   }
 } 
}

function validar_usu(){
 var codigo=document.frm.codigo.value;

 if(document.frm.nombre.value==""){
	alert("Ingrese Nombre");
	document.frm.nombre.focus();
 }else{
 if(document.frm.user.value==""){
	alert("Ingrese Usuario");
	document.frm.user.focus();
 }else{
 if(document.frm.pass.value==""){
	 alert("Ingresar contraseņa");
	 document.frm.pass.focus();
 }else{
   if(document.frm.pass.value!=document.frm.pass1.value){
	   alert("Contraseņa Incorrecta");
	   document.pass1.focus();
   }else{
	   document.frm.action="grabar.php?tabla=1&codigo=" + codigo;
	   document.frm.submit();
   }
 } 
 }
 }
}

function eliminar(codigo,tabla){
  if(confirm('Desea borrar el registro?')) location.href="borrar.php?codigo=" + codigo + "&tabla=" + tabla;
}

function validar_client(){
  if(document.frm.nombre.value==""){
	alert("Insert name");
	document.frm.nombre.focus();
  }
  else{
   document.frm.action="grabar.php?tabla=2";
   document.frm.submit();
  }
}

function validar_test(){
  var error = "";
  if(document.frm.client){
   if(document.frm.client.value==""){
	error+="Insert client\n";
   }
  }
  if(document.frm.name){
   if(document.frm.name.value==""){
	error+="Insert name\n";
   }
  }
  if(document.frm.comment.value==""){
	error+="Insert comment\n";
  }
  if(error!=""){
   alert(error);
  }else{
   document.frm.action="grabar.php?tabla=3";
   document.frm.submit();
  }
}

function lista_cat(valor,activo){
	sndReqGet('dvcat','lista_cat.php?gen=' + valor + '&activo=' + activo,'');
	if(activo==1){
	  var selectOrigen=document.getElementById("client");
	  selectOrigen.length=0;
	  var nuevaOpcion=document.createElement("option"); 
	  nuevaOpcion.value=0; 
	  nuevaOpcion.innerHTML="Cargando...";				
	  selectOrigen.appendChild(nuevaOpcion);	
	  listado = '<select name="client" id="client" class="campoCont">';
	  listado+='<option value="">Selection...</option>';
	  listado+='</select>';
      selectOrigen.parentNode.innerHTML=listado;
	}
}

function lista_client(valor){
	sndReqGet('dvclient','lista_client.php?cat=' + valor,'');
}

function validar_representante(){
  if(document.frm.nombre.value==""){
	alert("Insert name");
	document.frm.nombre.focus();
  }
  else{
   document.frm.action="grabar.php?tabla=4";
   document.frm.submit();
  }
}

function validar_luchador(){
  if(document.frm.nombre.value==""){
	alert("Insert name");
	document.frm.nombre.focus();
  }
  else{
   document.frm.action="grabar.php?tabla=5";
   document.frm.submit();
  }
}

function validar_about(){
  tinyMCE.triggerSave();
  tinyMCE.triggerSave();
  if(document.frm.nombre.value==""){
	alert("Insert name");
	document.frm.nombre.focus();
  }
  else{
   document.frm.action="grabar.php?tabla=6";
   document.frm.submit();
  }
}

function validar_affiliates(){
  if(document.frm.nombre.value==""){
	alert("Insert name");
	document.frm.nombre.focus();
  }
  else{
   document.frm.action="grabar.php?tabla=7";
   document.frm.submit();
  }
}

function validar_not(){
 var codigo=document.frm.codigo.value;
 
  if(document.frm.titulo.value==""){
	alert("Insert Title");
	document.frm.titulo.focus();
  }else{
   if(document.frm.fecha.value==""){
	alert("Insert Date");
	document.frm.fecha.focus();
   }else{
	var oEditor = CKEDITOR.instances.descripcion;
    if(oEditor.getData()==""){
	 alert("Insert Description");
	 document.getElementById("descripcion").focus();
    }else{  
	   document.frm.action="grabar.php?tabla=8&codigo=" + codigo;
	   document.frm.submit();
    }
   }
  }
}

function validar_img(formup){
	 var tipo = document.getElementById(formup).value.split(".");
	 if(tipo[1]!="jpg" && tipo[1]!="gif" && tipo[1]!="png"){
	  alert("Tipo de archivo no valido");
	  document.getElementById(formup).value="";
	  document.getElementById(formup).focus();
	 }
}