
function Over(el, cha){
	el.className = cha;
}

function Out(el, cha){
	el.className = cha;
}

function ExtraerCookie() {
	var i = (document.cookie.indexOf("COLORES"));
	var longitud = (document.cookie.indexOf("=", i) + 1);
	if(document.cookie.substring(i, longitud) == 'COLORES='){
		return true;
	}else{
		return null;
	}
}

function ColocarCookie (name, value) {
	//document.cookie = name + "=" + escape (value) + "@";
	var context = '';
	document.cookie = name + "=" + escape (value) + "@" + context;
}

function color(el){
	var color_new = "include/style/" + el + ".css";
	document.getElementById('color').href = color_new;
	var hoy = new Date();
	var expira = new Date(hoy.getTime() + 365 * 24 * 60 * 60 * 1000).toGMTString();
	ColocarCookie("COLORES", color_new);
}

function load_color(){
	var visita = ExtraerCookie("COLORES");
	if (visita == null){
		var hoy = new Date();
		var expira = new Date(hoy.getTime() + 365 * 24 * 60 * 60 * 1000).toGMTString();
		var color_new = "include/style/grey.css";
		ColocarCookie("COLORES", color_new);
	}else{
		index = document.cookie.indexOf("COLORES");
		countbegin = (document.cookie.indexOf("=", index) + 1);
		countend = document.cookie.indexOf("@", index);
		color_new = document.cookie.substring(countend, countbegin);
		document.getElementById('color').href = color_new;
	}
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

//VERIFICAR QUE UN CAMPO NO ESTE VACIO.
function CampoVacio(campo,mensaje){
  if(campo.value == ""){
    alert(mensaje);
  	campo.focus();
  	return false;
  }else{
    return true;
  }
}


//VERIFICAR QUE TODOS LOS CAMPOS select ESTEN LLENOS
function MenuVacio(mensaje,frm_x,exc,suta){
  frm_x = (frm_x != '') ? eval(frm_x) : eval("frm");
  suta = (suta == 1) ? "==" : "!=" ;
  exc = (exc == "") ? 1 : exc ;
  if(exc != 1){
	  exc1 = exc.split(",");
		exc2 = "";
		for(i=0; i<=exc1.length-1; i++){
			exc2 += "frm_x[x].name "+ suta +" '"+exc1[i]+"' || ";
		}
		exc2 = exc2.substring(0,exc2.length-4);
		exc2 = "(" +exc2+ ")";
	}else{
		exc2 = "1==1";
	}
	var num = num1 = 0;
	for (var x=0; x < frm_x.length; x++){
    if(frm_x[x].type == 'select-one'  && eval(exc2) && frm_x[x].disabled == false){
      num1++;
		}
	}
	for(var x=0; x < frm_x.length; x++){
		if(frm_x[x].type == 'select-one'  && eval(exc2) && frm_x[x].disabled == false){
			if(frm_x[x].value == ""){
				alert(mensaje);
				frm_x[x].focus();
				return false ;
			}else{
				num++;
			}
		}
	}
	if(num  == num1) return true;
}

//VERIFICAR QUE TODOS LOS CAMPOS text ESTEN LLENOS
function TodosCamposVacios(mensaje,frm_x,exc,suta){
  frm_x = (frm_x != '') ? eval(frm_x) : eval("frm");
  suta = (suta == 1) ? "==" : "!=" ;
  exc = (exc == "") ? 1 : exc ;
  if(exc != 1){
	  exc1 = exc.split(",");
		exc2 = "";
		for(i=0; i<=exc1.length-1; i++){
			exc2 += "frm_x[x].name "+ suta +" '"+exc1[i]+"' || ";
		}
		exc2 = exc2.substring(0,exc2.length-4);
		exc2 = "(" +exc2+ ")";
	}else{
		exc2 = "1==1";
	}
	var num = num1 = 0;
	for (var x=0; x < frm_x.length; x++){
    if((frm_x[x].type == 'text' || frm_x[x].type == 'password') && eval(exc2) && frm_x[x].disabled == false){
      num1++;
		}
	}
	for(var x=0; x < frm_x.length; x++){
		if((frm_x[x].type == 'text' || frm_x[x].type == 'password') && eval(exc2) && frm_x[x].disabled == false){
			if(frm_x[x].value.length == 0){
				alert(mensaje);
				frm_x[x].focus();
				return false ;
			}else{
				num++;
			}
		}
	}
	if(num  == num1) return true;
}

//VERIFICA SI UN CAMPO checkbox ESTA SELECCIONADO
function ValidarChk(campo,mensaje){
  if (!campo.checked){
		alert(mensaje);
		campo.focus();
		return false;
	}else{
	  return true;
	}
}

//OCULTAR O VISUALIZAR UN <div>
function ocultar(id){
	var x = document.getElementById(id);
	var a = x.style.display ? '' : 'none';
	x.style.display = a;
}

// CREA UN MENU select DEPENDIENTE DE OTRO
// NewSelect('modelo',this.value,ArraySelect,'')
function NewSelect(NameSelect,IDValue,NameArray,Selected){
	var NameSelect = document.getElementById(NameSelect);
	NameSelect.options.length = 0;
	if(IDValue == ""){
	  NameSelect.options[0] = new Option(" ","",false,true);
	}else{
		var na=1;
		for(var x=0; x<= NameArray.length-1; x++){
		  if(NameArray[x][0] == IDValue){
		    var VarSelected = (Selected == NameArray[x][1])? true : false ;
		  	NameSelect.options[na] = new Option(NameArray[x][2],NameArray[x][1],false,VarSelected);
		  	na++;
		  }
		}
	}
}

// SELECCIONA UNA OPCION DE UN MENU select
function DefaultSelected(x,xx,frm_x){ //nombre del menu, valor default
	frm_x = (frm_x) ? eval(frm_x + "." + x) : eval("frm." + x) ;
  for(n=0; n<=Number(frm_x.length-1); n++){
  	if(frm_x.options[n].value == xx){
    	frm_x.options[n].selected = true;
    }
  }
}

// GENERAR UN VENTANA POPUP
// onclick="NewWindow(this.href,'name','','','360','570','yes');return false"
var win = null;
function NewWindow(mypage,myname,w,h,LeftPosition,TopPosition){
	settings = 'statusbar=0,resizable=1,menubar=0,toolbar=0,scrollbars=1,height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition;
	win = window.open(mypage,myname,settings);
}

// VALIDAR UNA EMAIL ESCRITO
function ValidarEmail(campo,mensaje){
  if(!campo.value.match(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/)){
	  alert(mensaje);
	 	campo.focus();
		campo.select();
		return false;
  }else{
    return true;
  }
}

// PERMITIR SOLO CARACTERES SELECCIONADOS
function AlphaNumerico(campo,extra,tipo,espacio,mensaje){
  var ubicacion, caracteres;
  var enter = "\n";
  if(espacio != 1) espacio = " ";
  if(tipo == 1) caracteres = "abcdefghijklmnopqrstuvwxyzñ1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZÑáéíóúÁÉÍÓÚ" + espacio + String.fromCharCode(13) + enter + extra;
  if(tipo == 2) caracteres = "abcdefghijklmnopqrstuvwxyzñ1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZÑáéíóúÁÉÍÓÚ" + espacio + String.fromCharCode(13) + enter + extra;
  if(tipo == 3) caracteres = "1234567890" + espacio + String.fromCharCode(13) + enter + extra;
  var contador = 0;

	for (var i=0; i<campo.value.length; i++){
    ubicacion = campo.value.substring(i, i + 1);
    if(caracteres.indexOf(ubicacion) != -1){
      contador++;
    }else{
      alert(mensaje+ "\n No se acepta el caracter '" + ubicacion + "'.");
      campo.focus();
      campo.select();
      return false;
    }
  }
  if(contador == campo.value.length) return true;
}


// COMPROBAR SI DOS CAMPOS SON DIFERENTES
function CompararCampos1(campo1,campo2,mensaje){
	if(campo1.value == campo2.value){
		alert(mensaje);
		campo1.focus();
		campo1.select();
		return false;
	}else{
	  return true;
	}
}

// COMPROBAR SI DOS CAMPOS SON IGUALES
function CompararCampos(campo1,campo2,mensaje){
	if(campo1.value != campo2.value){
		alert(mensaje);
		campo1.focus();
		campo1.select();
		return false;
	}else{
	  return true;
	}
}

// INCLUYE ARCHIVOS
function include(file_path){
	var j = document.createElement("script");
	j.type = "text/javascript";
	j.src = file_path;
	document.body.appendChild(j);
}

// VERIFICA EL CONTENIDO DEL CAMPO EN EL EDITOR FCKeditor
function ValidarContenidoFCK(campo_name){
  oEditor = FCKeditorAPI.__Instances[campo_name].GetHTML();
  if(oEditor == "<p>&nbsp;</p>" ||  oEditor == ""){
    alert("Introduzca una descripción de su producto");
    return false;
  }else{
   	return true;
	}
}

//CARGA LAS FUNCIONES EN JAVASCRIPT DE CADA CATEGORIA
function CargarCatJs(cat_n){
	if(frm.categoria.options[frm.categoria.options.selectedIndex].value == cat_n){
		include("contenido/categorias/cuenta/catf_" + cat_n + ".php");
	}
}

//ENVIAR A UNA DIRECCION Y HACER UNA PREGUUNTA ANTES.
function GoUrl(mensaje,url){
	var yes = window.confirm(mensaje);
   	if (yes) window.location = "?"+url;
	return(false);
}

//SELECCIONA UN VALOR DE UNNA LISTA DE OPCIONES DE radio buttom
function DefaultRadio(x,xx){ //nombre del menu, valor default
	y = eval('frm.'+x);
  for(var n=0; n<=Number(y.length-1); n++){
    if(y[n].value == xx){
      y[n].checked = true;
    }
  }
}

//CAMBIAR EL VALOR DE UN CAMPO
function CambiarNombre(mensaje,values,id,url){
	var yes = window.prompt(mensaje,values);
  if (yes) window.location = "?" + url + "&cambiar=" + id + "&cambiar1=" + yes;
	return(false);
}

function BorrarItem(item,id,url){
	var mensaje = 'Desea borrar '+item;
	var yes = window.confirm(mensaje);
   	if (yes) window.location = "?"+url+"&borrar="+id;
	return(false);
}

function WinMaximizar(x,y,w,h){
    window.moveTo(x, y);
    window.resizeTo(window.screen.width-w, window.screen.height-h);
}
