function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

/*

function MostrarPlato(NumeroPlato){
	
	var selectoractual = $('#selector_'+PlatoActual);
	selectoractual.removeClass('ilu');
	var selectornuevo = $('#selector_'+NumeroPlato);
	selectornuevo.addClass('ilu');

	gotoslide(NumeroPlato,tabla,id);
	PlatoActual=NumeroPlato;
	
}

*/

function MostrarPlato(NumeroPlato,tabla,id){
	
	var selectoractual = $('#selector_'+PlatoActual);
	selectoractual.removeClass('ilu');
	var selectornuevo = $('#selector_'+NumeroPlato);
	selectornuevo.addClass('ilu');

	gotoslide(NumeroPlato,tabla,id);
	PlatoActual=NumeroPlato;
	
}


function XHConn(){
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone)
  {
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase();

    try {
      if (sMethod == "GET")
      {
        xmlhttp.open(sMethod, sURL+"?"+sVars, true);
        sVars = "";
      }
      else
      {
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type",
          "application/x-www-form-urlencoded");
      }
      xmlhttp.onreadystatechange = function(){
        if (xmlhttp.readyState == 4 && !bComplete)
        {
          bComplete = true;
          fnDone(xmlhttp);
        }};
      xmlhttp.send(sVars);
    }
    catch(z) { return false; }
    return true;
  };
  return this;
}

function SimpleSwap(el, which) {
    el.src = el.getAttribute(which || "origsrc");
}

function SimpleSwapSetup() {
    var x = document.getElementsByTagName("img");
    for (var i = 0; i < x.length; i++) {
        var oversrc = x[i].getAttribute("oversrc");
        if (!oversrc) {
            continue;
        }
        x[i].oversrc_img = new Image;
        x[i].oversrc_img.src = oversrc;
        x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
        x[i].onmouseout = new Function("SimpleSwap(this);");
        x[i].setAttribute("origsrc", x[i].src);
    }
}

addLoadEvent(SimpleSwapSetup);

function comprobarEmail(texto){

	var mailres = true;            
	var cadena = "abcdefghijklmnñopqrstuvwxyzABCDEFGHIJKLMNÑOPQRSTUVWXYZ1234567890@._-";
	var arroba = texto.indexOf("@",0);
	
	if ((texto.lastIndexOf("@")) != arroba) arroba = -1;
	
	var punto = texto.lastIndexOf(".");      
	for (var contador = 0 ; contador < texto.length ; contador++){
		if (cadena.indexOf(texto.substr(contador, 1),0) == -1){
			mailres = false;
			 break;
		}
	}

	if ((arroba > 1) && (arroba + 1 < punto) && (punto + 1 < (texto.length)) && (mailres == true) && (texto.indexOf("..",0) == -1))
		mailres = true;
	else
		mailres = false;

	return mailres;
}

function AjustaSlide(){
	
	if((window.document.getElementById("tablaslide")) && (window.document.getElementById("elementosmenu2"))){
		var heightM = window.document.getElementById("elementosmenu2").offsetHeight;
		window.document.getElementById("tablaslide").style.height = heightM + "px";
	}
	else if((window.document.getElementById("tablaslideMac")) && (window.document.getElementById("elementosmenu2"))){
		var heightM = window.document.getElementById("elementosmenu2").offsetHeight;
		window.document.getElementById("tablaslideMac").style.height = heightM + "px";
	}
}

function AjustaEspacio(){
		
	if((window.document.getElementById("espacio")) && (window.document.getElementById("contenido")) && (window.document.getElementById("columna"))){
		var content = window.document.getElementById("contenido").innerHTML;
		window.document.getElementById("columna").innerHTML += content;	
		window.document.getElementById("contenido").innerHTML = "&nbsp;";
	}
}

function comprobarEmail(valor) {
	if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\D{2,4})+$/.test(valor)){
		return false;
	} else {
		return true;
	}
}

function PopUp(pagina,idioma) {
	window.open("/popup.php?Pagina="+pagina+"&Idioma="+idioma, "","resizable=1,SCROLLBARS=YES,HEIGHT=600,WIDTH=626");
}
