// for debug window:
debugmode=0;

var winW=0, winH=0;
var bgL=0, bgT=0;
var iMenuID = new Array(0,0,0);
var blMenuOpen = new Array(0,0,0);
var iSubMenuID = new Array(0,0,0,0);
var blSubMenuOpen = new Array(0,0,0,0);
var blSubMenuFxin = new Array(0,0,0,0);
var blSubMenuFxout = new Array(0,0,0,0);
var curSection="";
var curSectionLeft=0;
var curSectionTop=0;
var xmlhttp=false;
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
try {
  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
  try {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  }
  catch (E) {
      xmlhttp = false;
  }
}
@end @*/

if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
  xmlhttp = new XMLHttpRequest();
}

function getWinSize() {
  if (parseInt(navigator.appVersion)>3) {
   if (navigator.appName=="Netscape") {
    winW = window.innerWidth;
    winH = window.innerHeight;
   }
   if (navigator.appName.indexOf("Microsoft")!=-1) {
    if (document.documentElement) {
      winW = document.documentElement.offsetWidth;
      winH = document.documentElement.offsetHeight;
    } else {
      winW = document.body.offsetWidth;
      winH = document.body.offsetHeight;
    }
   }
  }
}

function getObj(name) {
  if (document.getElementById) {  // FF IE
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  } else if (document.all) {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  } else if (document.layers) {
	this.obj = getObjNN4(document,name);
	this.style = this.obj;
  }
}

function getObjNN4(obj,name) {
  var x = obj.layers;
  var foundLayer;
  for (var i=0;i<x.length;i++) {
    if (x[i].id == name)
      foundLayer = x[i];
    else if (x[i].layers.length)
      var tmp = getObjNN4(x[i],name);
    if (tmp) foundLayer = tmp;
  }
  return foundLayer;
}

function center(object) {
  var hObj = new getObj(object);
  var IpopTop = (document.documentElement.offsetHeight - hObj.obj.offsetHeight)/2;
  if (document.all) IpopTop+=document.body.scrollLeft;
  else IpopTop+=pageXOffset;
  var IpopLeft = (document.documentElement.offsetWidth - hObj.obj.offsetWidth)/2;
  if (document.all) IpopLeft+=document.body.scrollTop;
  else IpopLeft+=pageYOffset;
  if (IpopLeft<0) IpopLeft=10;
  if (IpopTop<0) IpopTop=10;
  //deb(IpopLeft+","+IpopTop+" "+document.body.scrollLeft+","+document.body.scrollTop);
  //deb(IpopLeft+","+IpopTop+" "+pageXOffset+","+pageYOffset);
  bgL=IpopLeft;
  bgT=IpopTop;
  //alert(hObj.style.left+","+hObj.style.top);
  hObj.style.left=bgL+"px";
  hObj.style.top=bgT+"px";
  deb("centered: "+object+" to: "+bgL+","+bgT);
}


function center_hor(object) {
  var hObj = new getObj(object);
  var IpopLeft = (document.documentElement.offsetWidth - hObj.obj.offsetWidth)/2;
  if (document.all) IpopLeft+=document.body.scrollTop;
  else IpopLeft+=pageYOffset;
  if (IpopLeft<0) IpopLeft=10;
  bgL=IpopLeft;
  bgT=1;
  hObj.style.left=bgL+"px";
  hObj.style.top=bgT+"px";
  deb("centered hor: "+object+" to: "+bgL+","+bgT);
}



function setpos(object,left,top) {
  var hObj = new getObj(object);
  hObj.style.left=left+"px";
  hObj.style.top=top+"px";
  deb("setpos: "+object+" to: "+left+","+top);
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

function getData( myNode, myNodeName ) {
    var subNodes = myNode.childNodes;
    for ( j=0; j < subNodes.length; j++ ) {
        var subNode = subNodes.item(j);
        if ( subNode.nodeName == myNodeName ) {
            // this is cross browser ( ie and firefox ) compatible
            return subNode.childNodes.item(0).nodeValue;
        }
    }
    return "";
}

function processXmlResponse( response ) {
  deb("processXmlResponse:"+response);
  nodes = response.getElementsByTagName('item'); // returns only nodes that are item nodes. this removes the response and xml nodes
  for (i=0;i<nodes.length; i++) {
    var node = nodes.item(i);
    document.getElementById( getData( node, 'divid' ) ).innerHTML = getData( node, 'data' );
  }
}

function sendForm(frmSend,formProc,cbDone) {

	if (frmSend=="frmContacto") Mk_validateForm();
   
	else  document.MM_returnValue=true;
	
	if (document.MM_returnValue) {

		var form = document.getElementById(frmSend);
		var elements = form.elements;
		query = "";

		for (i=0;i<elements.length-1;i++) {
			query = query + elements.item(i).name + "=" + elements.item(i).value + "&";
		}

		query = query + elements.item(i).name + "=" + elements.item(i).value;

		xmlhttp.open("POST", formProc );
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				//processXmlResponse( xmlhttp.responseXML );
			cbDone(xmlhttp.responseXML);
			}
		}
		
		xmlhttp.send(query);
	}
}

function initdebug() {
  if (debugmode) {
    new Draggable('debug',{scroll:window,zindex:99,handle:'debug'});
    setpos("debug",10,winH-110);
    deb("w:"+winW+" h:"+winH);
  }
}

function deb(str) {
  if (debugmode) {
    var hObj = new getObj("debug");
    hObj.obj.innerHTML+=str+"<br>";
    hObj.obj.scrollTop=hObj.obj.scrollHeight 
  }
}

function getHash() {
  return window.location.hash.replace("#", "");
}


function initScrollLayer() {
  // arguments: id of layer containing scrolling layers (clipped layer), id of layer to scroll, 
  // if horizontal scrolling, id of element containing scrolling content
  var wndo = new dw_scrollObj('productos1content', 'productos1slide', 'scrolltable'); 
  wndo.shiftTo( document.getElementById(wndo.lyrId), 0, 0 );
}

var prodprevfxin1=new Array(0,0,0,0,0,0,0);
var prodprevfxout1=new Array(0,0,0,0,0,0,0);
var prodprevup1=new Array(0,0,0,0,0,0,0);
var prodprevsub1=new Array(0,0,0,0,0,0,0);
var prodprevsubmain1=new Array(0,0,0,0,0,0,0);
var prodprevsubid1=new Array(0,0,0,0,0,0,0);
var prodprevfxin2=new Array(0,0,0);
var prodprevfxout2=new Array(0,0,0);
var prodprevup2=new Array(0,0,0);
var prodprevsub2=new Array(0,0,0);
var prodprevsubmain2=new Array(0,0,0);
var prodprevsubid2=new Array(0,0,0);
var prodprevfxin=new Array();
var prodprevfxout=new Array();
var prodprevup=new Array();
var prodprevsub=new Array();
var prodprevsubmain=new Array();
var prodprevsubid=new Array();
var prodprevspeed=500;
var prodprevsubspeed=2000;
var prodprevdispatch=10;
var lastpp=0;
var prodprevfxin3=new Array(0,0,0);
var prodprevfxout3=new Array(0,0,0);
var prodprevup3=new Array(0,0,0);
var prodprevsub3=new Array(0,0,0);
var prodprevsubmain3=new Array(0,0,0);
var prodprevsubid3=new Array(0,0,0);
var prodprevfxin4=new Array(0,0,0);
var prodprevfxout4=new Array(0,0,0);
var prodprevup4=new Array(0,0,0);
var prodprevsub4=new Array(0,0,0);
var prodprevsubmain4=new Array(0,0,0);
var prodprevsubid4=new Array(0,0,0);

function prodprevmaintain(section,img) {
  prodprevfxin=eval("prodprevfxin"+section);
  prodprevfxout=eval("prodprevfxout"+section);
  prodprevup=eval("prodprevup"+section);
  prodprevsub=eval("prodprevsub"+section);
  prodprevsubmain=eval("prodprevsubmain"+section);
  prodprevsubid=eval("prodprevsubid"+section);
  prodprevsub[img]=1;
  prodprevsubmain[img]=1;
  //deb("prodprevmaintain("+img+") ");
}
function prodprevmaintainoff(section,img) {
  prodprevfxin=eval("prodprevfxin"+section);
  prodprevfxout=eval("prodprevfxout"+section);
  prodprevup=eval("prodprevup"+section);
  prodprevsub=eval("prodprevsub"+section);
  prodprevsubmain=eval("prodprevsubmain"+section);
  prodprevsubid=eval("prodprevsubid"+section);
  prodprevsub[img]=0;
  prodprevsubmain[img]=0;
  //deb("prodprevmaintainoff("+img+") ");
}
function prodprev(section,img) {
  lastpp=img;
  prodprevfxin=eval("prodprevfxin"+section);
  prodprevfxout=eval("prodprevfxout"+section);
  prodprevup=eval("prodprevup"+section);
  prodprevsub=eval("prodprevsub"+section);
  prodprevsubmain=eval("prodprevsubmain"+section);
  prodprevsubid=eval("prodprevsubid"+section);
  deb("prodprev("+img+") "+prodprevfxin);
  if (!prodprevfxin[img] && !prodprevfxout[img]) {
   if (!prodprevup[img]) {
    //for (i=0;i<prodprevsub.length;i++) {
/*
    for (i=1;i<prodprevsub.length+1;i++) {
      if (prodprevsub[i]) {
        deb("loop: "+i);
        prodprevup[i]=1;
        prodprevsub[i]=0;
        prodprevsubmain[i]=0;
        //clearTimeout(prodprevsubid[img]);
        clearTimeout(prodprevsubid[i]);
        setTimeout("prodprevoff("+section+","+i+");",prodprevdispatch);
        //prodprevoff_int(i);
      }
      //else deb("no loop:"+i);
    }
*/
    prodprevfxin[img]=1;
    //new Effect.Scale(img,{scaleTo:200});
    var myEffectin = new fx.Width("prod"+section+"."+img, {duration: prodprevspeed, onComplete: function() {
      //deb('the effect is completed');
    }});
    var myEffectin2 = new fx.Height("prod"+section+"."+img, {duration: prodprevspeed, onComplete: function() {
      //deb('the effect is completed');
      //var hObj2=document.getElementById("prod"+img);
      //var hObj2 = new getObj("divprod"+img);
      //hObj2.setAttribute("width","145px");
      //hObj2.setAttribute("height","120px");
      //setTimeout('prodprevfxin=0;',prodprevdispatch);
      prodprevfxin[img]=0;
      //prodprevsub[img]=1;
      prodprevup[img]=1;
      //deb("left: "+getAnchorXPosition("aprod"+img));
      //deb("top: "+getAnchorPosition("aprod"+img));
      //deb("width: "+hObj2.style.width);
      //deb("height: "+hObj2.style.height);
      //setTimeout("prodprevsub["+img+"]=0;",1000);
      //setpos("productos"+section+"_"+img,getAnchorXPosition("aprod"+section+"."+img),getAnchorPosition("aprod"+section+"."+img)-119);
      prodprevsub[img]=1;
      setTimeout("setsub("+section+","+img+");",10);
    }});
    if (section=="2") {
      myEffectin.custom(165,256);
      myEffectin2.custom(120,186);
    } else {
      myEffectin.custom(145,224);
      myEffectin2.custom(120,186);
    }
   }
  }
  //else setTimeout('prodprev('+section+','+img+')',prodprevdispatch); 
}

function setsub(section,img) {
  prodprevsub=eval("prodprevsub"+section);
  prodprevfxin=eval("prodprevfxin"+section);
  prodprevfxout=eval("prodprevfxout"+section);
  prodprevup=eval("prodprevup"+section);
  if (prodprevsub[img] && prodprevup[img] && !prodprevfxin[img] && !prodprevfxout[img]) {
      setpos("productos"+section+"_"+img,getAnchorXPosition("aprod"+section+"."+img),getAnchorPosition("aprod"+section+"."+img)-119);
      setTimeout("setsub("+section+","+img+");",10);
  }
}

function prodprevoff(section,img) {
  prodprevfxin=eval("prodprevfxin"+section);
  prodprevfxout=eval("prodprevfxout"+section);
  prodprevup=eval("prodprevup"+section);
  prodprevsub=eval("prodprevsub"+section);
  prodprevsubmain=eval("prodprevsubmain"+section);
  prodprevsubid=eval("prodprevsubid"+section);
  //deb("prodprevoff("+img+") "+prodprevsubmain[img]);
/*
  if (lastpp==img) prodprevsubid[img]=setTimeout("prodprevoff_int("+section+","+img+")",1000);
  else prodprevsubid[img]=setTimeout("prodprevoff_int("+section+","+img+")",10);

  clearTimeout(prodprevsubid[img]);
  if (!prodprevsubmain[img]) {
    clearTimeout(prodprevsubid[img]);
    if (prodprevsub[img]) prodprevsubid[img]=setTimeout("prodprevsub["+img+"]=0;"+"prodprevoff_int("+section+","+img+")",prodprevsubspeed);
    else prodprevsubid[img]=setTimeout("prodprevoff_int("+section+","+img+")",prodprevdispatch);
  }

  prodprevoff_int(section,img);
*/
  prodprevsubid[img]=setTimeout("prodprevoff_int("+section+","+img+")",20);
}
function prodprevoff_int(section,img) {
  prodprevfxin=eval("prodprevfxin"+section);
  prodprevfxout=eval("prodprevfxout"+section);
  prodprevup=eval("prodprevup"+section);
  prodprevsub=eval("prodprevsub"+section);
  prodprevsubmain=eval("prodprevsubmain"+section);
  prodprevsubid=eval("prodprevsubid"+section);
  if (!prodprevsubmain[img]) {
    //deb("prodprevoff_int("+img+") fx:"+prodprevfxout[img]+" main:"+prodprevsubmain[img]);
    //if (!prodprevfxout[img] && !prodprevfxin[img] && !prodprevsub[img]) {
    if (!prodprevfxout[img] && !prodprevfxin[img]) {
      if (prodprevup[img]) {
        prodprevfxout[img]=1;
        setpos("productos"+section+"_"+img,-800,-800);
        //new Effect.Shrink(img);
        var myEffect = new fx.Width("prod"+section+"."+img, {duration: prodprevspeed, onComplete: function() {
          //alert('the effect is completed');
        }});
        var myEffect2 = new fx.Height("prod"+section+"."+img, {duration: prodprevspeed, onComplete: function() {
          //alert('the effect is completed');
          //setTimeout('prodprevfxout=0;',prodprevdispatch);
          prodprevfxout[img]=0;
          prodprevup[img]=0;
        }});
        if (section=="2") {
          myEffect.custom(256,165);
          myEffect2.custom(186,120);
        } else {
          myEffect.custom(224,145);
          myEffect2.custom(186,120);
        }
      }
    }
    else {
      deb("off prod"+img+" "+prodprevfxout[img]+" "+prodprevfxin[img]+" "+prodprevsub[img]+" ");
      setTimeout('prodprevoff_int('+section+','+img+')',prodprevdispatch); 

      //var hObj = new getObj("prod"+img);
      //deb("w "+hObj.style.width+" h "+hObj.style.height);
      //hObj.style.width="145px";
      //hObj.style.height="120px";
      //hObj.style.visibility="hidden";
      //hObj.style.visibility="visible";
      //deb("w "+hObj.style.width+" h "+hObj.style.height);
/*
      var hObj2=document.getElementById("prod"+img);
      hObj2.setAttribute("width","145px");
      hObj2.setAttribute("height","120px");

      var myEffect3 = new fx.Width("prod"+img, {duration: 100, onComplete: function() {
        //alert('the effect is completed');
      }});
      var myEffect4 = new fx.Height("prod"+img, {duration: 100, onComplete: function() {
        //alert('the effect is completed');
        prodprevfxout=0;
      }});
      myEffect3.custom(224,145);
      myEffect4.custom(186,120);
*/
    }
  }
}

function hideproductodivs(section) {
  prodprevsub=eval("prodprevsub"+section);
  for (j=1;j<prodprevsub.length;j++) {
    setpos("productos"+section+"_"+j,-800,-800);
  }
}


//function startSlideshow() {
//  initSlideShow($('home'), mySlideData);
//}
//addLoadEvent(startSlideshow);
 
function startbganim() {
  deb("starting background animation");
  var mySlideData = new Array();
  countArticle = 0;
  mySlideData[countArticle++] = new Array('img/home/home.3.jpg', '', 'Title', 'Description');
  mySlideData[countArticle++] = new Array('img/home/home.4.jpg', '', 'Title', 'Description');
  mySlideData[countArticle++] = new Array('img/home/home.0.jpg', '', 'Title', 'Description');
  mySlideData[countArticle++] = new Array('img/home/home.1.jpg', '', 'Title', 'Description');
  mySlideData[countArticle++] = new Array('img/home/home.2.jpg', '', 'Title', 'Description');
  initSlideShow($('home'), mySlideData);
}

function stopbganim() {
  deb("stop bganim");
  stopSlideShow();
}

function startmenu() {
  deb("starting menu");
  //new Element.hide("menu1");
  var hObj = new getObj("menu1");
  hObj.style.visibility="hidden"; 
  var hObj2 = new getObj("menu2");
  hObj2.style.visibility="hidden"; 
  var hObj3 = new getObj("menu3");
  hObj3.style.visibility="hidden"; 
  resetmenupos();
  setTimeout("openmenu(1)",3000);
  setTimeout("openmenu(2)",3100);
  setTimeout("openmenu(3)",3200);
}

function resetmenupos() {
  setpos("menu1",bgL+402,bgT+50);
  setpos("menu2",bgL+566,bgT+50);
  setpos("menu3",bgL+724,bgT+50);
}

function openmenu(num) {
  deb("openmenu: "+num);
  var hObj = new getObj("menu"+num);
  //hObj.style.width="0px"; 
  //var myEffect = new fx.Width("menu"+num , {duration: 2000, onComplete: function() {
  var myEffect = new fx.Opacity("menu"+num , {duration: 2000, onComplete: function() {
      //alert('the effect is completed');
  }});
  //myEffect.custom(0,147);
  myEffect.setOpacity(0);
  hObj.style.visibility="visible"; 
  myEffect.custom(0,1);

  //myEffect.toggle();
  //new Element.show("menu1");
//alert("menu"+num);
  //new Effect.Grow("menu"+num,{duration:1.4,direction:top});
  //new Effect.SlideDown("menu"+num);
  //new Effect.BlindUp("menu"+num);
  //new Effect.BlindDown("menu"+num);
  //new Effect.BlindDown(document.getElementById("menu"+num));
  //new Effect.Appear("menu1",{duration:1});
  //new Effect.toggle($('menu1'),'blind')
  //var myEffect = new fx.Width("menu"+num , {duration: 500, onComplete: function() {
/*
  var myEffect = new fx.Height("menu"+num , {duration: 500, onComplete: function() {
      //alert('the effect is completed');
    } });
  //myEffect.toggle();
  myEffect.custom(0,15);
*/
}

function hidesub(num) {
  iMenuID[num-1]=setTimeout('hidesub_int('+num+')',subtimeout);
}

function hidesub_int(num) {
  deb("hidesub: "+num);
  blMenuOpen[num-1]=0;
  var hObj = new getObj("submenu"+num);
  var myEffect = new fx.Height("submenu"+num , {duration: 500, onComplete: function() {
    //alert('the effect is completed');
    document.getElementById("amenu"+num).className="mainmenu";
  }});
  if (num==3) myEffect.custom(150,0);
  else myEffect.custom(85,0);
}

function showsub(num) {
  clearTimeout(iMenuID[num-1]);
  if (!blMenuOpen[num-1]) {
    blMenuOpen[num-1]=1;
    deb("showsub: "+num);
    document.getElementById("amenu"+num).className="mainmenuselected";
    var hObj = new getObj("submenu"+num);
    hObj.style.visibility="hidden"; 
    if (num==1) off=415;
    else if (num==2) off=579;
    else if (num==3) off=737;
    setpos("submenu"+num,bgL+off,bgT+65);
    hObj.style.height="0px"; 
    hObj.style.visibility="visible"; 
    var myEffect = new fx.Height("submenu"+num , {duration: 500, onComplete: function() {
        //alert('the effect is completed');
    }});
    if (num==3) myEffect.custom(0,150);
    else myEffect.custom(0,85);
    //new Effect.SlideDown("submenu"+num);
  }
}

function hidesub2(num) {
  iSubMenuID[num-1]=setTimeout('hidesub2_int('+num+')',sub2timeout);
}

function hidesub2_int(num) {
  deb("hidesub2: "+num);
  document.getElementById("asubmenu2_"+num).className="menu";
  if (blSubMenuOpen[num-1] && !blSubMenuFxout[num-1] && !blSubMenuFxin[num-1]) {
    blSubMenuOpen[num-1]=0;
    blSubMenuFxout[num-1]=1;
    var hObj = new getObj("submenu2_"+num);
    if (num==1) { orgw=133; }
    else if (num==2) { orgw=176; }
    else if (num==3) { orgw=166; }
    else if (num==4) { orgw=119; }
    //var myEffect = new fx.Width("submenu2_"+num , {duration: 500, onComplete: function() {
    var myEffect = new fx.Width("submenu2_"+num , {duration: 1, onComplete: function() {
      //alert('the effect is completed');
      hObj.style.visibility="hidden"; 
      blSubMenuFxout[num-1]=0;
    }});
    myEffect.custom(orgw,0);
    //myEffect.toggle();
    //myEffect.custom(85,0);
  } else hidesub2(num);
}

function setClass(elem,classname) {
  document.getElementById(elem).className=classname;
}

function showsub2(num) {
  clearTimeout(iSubMenuID[num-1]);
  if (!blSubMenuOpen[num-1] && !blSubMenuFxout[num-1] && !blSubMenuFxin[num-1]) {
    blSubMenuOpen[num-1]=1;
    blSubMenuFxin[num-1]=1;
    deb("showsub2: "+num);
    document.getElementById("asubmenu2_"+num).className="menuselected";
    var hObj = new getObj("submenu2_"+num);
    hObj.style.visibility="hidden"; 
    if (num==1) { posx=647; posy=65; orgw=133; }
    else if (num==2) { posx=647; posy=85; orgw=176; }
    else if (num==3) { posx=655; posy=107; orgw=166; }
    else if (num==4) { posx=639; posy=127; orgw=119; }
    setpos("submenu2_"+num,bgL+posx,bgT+posy);
    hObj.style.width="0px"; 
    hObj.style.visibility="visible"; 
    var myEffect = new fx.Width("submenu2_"+num , {duration: 500, onComplete: function() {
      //alert('the effect is completed');
      blSubMenuFxin[num-1]=0;
    }});
    //myEffect.toggle();
    myEffect.custom(0,orgw);
    //new Effect.SlideDown("submenu"+num);
  } else if (blSubMenuFxout[num-1]) {
    setTimeout('showsub2('+num+')',1000);
  }
}

function scrollprodstop() {
  //clearTimeout(scrollprodLeft_id);
  //clearTimeout(scrollprodRight_id);
}

var scrollprodLeft_id=0;
function scrollprodLeft(num) {
  //deb("scrollLeft");
  //new Effect.MoveBy("productos"+num+"slide",0,100,{duration:1000});
  new Effect.MoveBy("productos"+num+"slide",0,100);
  //scrollprodLeft_id=setTimeout('scrollprodLeft('+num+')',10);
}

var scrollprodRight_id=0;
function scrollprodRight(num) {
  //deb("scrollRight");
  //new Effect.MoveBy("productos"+num+"slide",0,-100,{duration:1000});
  new Effect.MoveBy("productos"+num+"slide",0,-100);
  //scrollprodRight_id=setTimeout('scrollprodRight('+num+')',10);
}


function sendformdone(obj) {
  deb("sendformdone");
  showsection('contactosend');
}

var getserversections_sub="";
var getserversections_section="";
function getServerSections(section,sub) {
  deb("getServerSections: "+section+" , "+sub);
  getserversections_sub=sub;
  getserversections_section=section;
  var myAjax=new Ajax.Request('prodlev2.php', {
	method: 'get',
	parameters: 'section='+section, 
	onComplete: prodlev2servcomplete
  });
}

function prodlev2servcomplete(Request) {
  deb("prodlev2servcomplete");
  //deb("prodlev2complete: "+Request.responseText);
  $('prodlev2content').innerHTML=Request.responseText;
  showsection('prodlev2');
  getServerSubSection(getserversections_section,getserversections_sub);
}


function getServerSection(section) {
  var myAjax=new Ajax.Request('prodlev2.php', {
	method: 'get',
	parameters: 'section='+section, 
	onComplete: prodlev2complete
  });
}

function prodlev2complete(Request){
  deb("prodlev2complete");
  //deb("prodlev2complete: "+Request.responseText);
  $('prodlev2content').innerHTML=Request.responseText;
  showsection('prodlev2');
}

function getServerSubSection(section,sub) {
  deb("getServerSubSection: "+section+" , "+sub);
  curHash=section; 
  //deb("->"+curHash);
  var myAjax=new Ajax.Request('prodlev2.php', {
	method: 'get',
	parameters: 'section='+section+'&sub='+sub,
	onComplete: prodlev2subcomplete
  });
}

function prodlev2subcomplete(Request){
  deb("prodlev2subcomplete");
  //deb("prodlev2subcomplete: "+Request.responseText);
  $('prodlev2contentsubmenu').innerHTML=Request.responseText;
}

function showcursection_old() {
  if (curSection!="") {
    stopbganim();
    center(curSection);
    deb("showcursection:"+curSection+" ("+curSectionLeft+","+curSectionTop+") in: "+bgL+","+bgT);
    setpos(curSection+"content",bgL+curSectionLeft,bgT+curSectionTop);
    if (curSection=="productos1") {
      setpos(curSection+"events",bgL,bgT);
      initScrollLayer();
    } else if (curSection=="productos2") {
      setpos(curSection+"events",bgL,bgT);
      initScrollLayer();
	} else if (curSection=="productos") {
      setpos(curSection+"events",bgL,bgT);
      initScrollLayer();
    } else if (curSection=="home") {
      startbganim();
    }
  }
}

function showsection_old(section,posx,posy) {
  deb("showsection:"+section+" ("+posx+","+posy+")");
  curHash=getHash(); 
  //curHash=section; 
  stopbganim();
  if (section!=curSection) {
    setpos(section,bgL,bgT);
    //var hObj = new getObj(section+"content");
    //hObj.style.height="0px";
    setpos(section+"content",bgL+posx,bgT+posy);
    if (curSection!="") {
      setpos(curSection,-800,-800);
      setpos(curSection+"content",-800,-800);
    }
   
    curSection=section;
    curSectionLeft=posx;
    curSectionTop=posy;
    if (section=="productos1") {
      setpos(curSection+"events",bgL,bgT);
      initScrollLayer();
    } else if (section=="productos2") {
      setpos(curSection+"events",bgL,bgT);
      initScrollLayer();
    } else if (section=="productos3") {
      setpos(curSection+"events",bgL,bgT);
      initScrollLayer();
    } else if (section=="home") {
      startbganim();
    }
  }
}

function showcursection() {
  deb("showcursection: "+curSection);
  if (curSection!="") {
    showsection(curSection);
  }
}

function showsection(section) {
  var posx,posy;
  if (section=="home") {
    posx=0; posy=0;
  } else if (section=="salmon" || section=="pulpo" || section=="bacalao" || section=="anguila" || section=="atun" || section=="rape" || section=="terrina_de_foie" || section=="magret_relleno" || section=="pechuga_codorniz_aceite" || section=="muslitos_de_codorniz" || section=="pechuga_codorniz" || section=="carrilera" || section=="patatas" || section=="tripas_bacalao" || section=="tosta" || section=="arroz" || section=="bombones" || section=="sal" || section=="prodlev2") {
    posx=0; posy=180;
  } else if (section=="productos1" || section=="productos2" || section=="productos3" || section=="productos4") {
    posx=0; posy=390;
  } else { posx=sectionLeft; posy=sectionTop; }  
  deb("showsection:"+section+" ("+posx+","+posy+")");
  stopbganim();
  center_hor("home");
  curHash=getHash(); 
  //curHash=section; 
  //if (section!=curSection) {
    //setpos(section,bgL,bgT);
    //setpos(section+"content",bgL+posx,bgT+posy);
    //center(section);
    setpos(section,bgL,bgT);
    setpos(section+"content",bgL+posx,bgT+posy);
	 setpos("siterelated",bgL+140,bgT+600);
    if (section!=curSection) {
      if (curSection!="") {
         setpos(curSection,-800,-800);
         setpos(curSection+"content",-800,-800);
      }
    }
	
	
/*
    if (curLang!=setLang) {
      setpos("mainmenu"+curLang,-1000,-1000);
      setpos("homesiterelated"+curLang,-1000,-1000);
      setpos("homecontentleftbot"+curLang,-1000,-1000);
      setpos(curSection+"contenttext"+curLang,-1000,-1000);
      setpos(curSection+"contenttitleleft"+curLang,-1000,-1000);
      curLang=setLang;
    }
*/
    curSection=section;
    curSectionLeft=posx;
    curSectionTop=posy;
    if (section=="productos1") {
      setpos(curSection+"events",bgL,bgT);
      initScrollLayer();
    } else if (section=="productos2") {
      setpos(curSection+"events",bgL,bgT);
      initScrollLayer();
    } else if (section=="productos3") {
      setpos(curSection+"events",bgL,bgT);
      initScrollLayer();
    } else if (section=="home") {
      startbganim();
    }
  //}
}

var chkHash="";
var curHash="";
function hashChecker() {
  chkHash=getHash();
  if (curHash!=chkHash) {
    deb("hashChecker cur:"+curHash+"  chk:"+chkHash);
    //setdivs("load");
    //setTimeout("hashChecker()",1000);
  } else {
    //setTimeout("hashChecker()",1000);
  }
}

function gohome() {
  center("home");
  startbganim();
  startmenu();
  curSection="home";
  curHash="";
}

function setdivs(mode) {
  var reqSection="";
  var fnd=0;
  getWinSize();
  if (mode=="load") {
    if (debugmode) initdebug();
    reqSection=getHash();
    if (reqSection=="") {
      showsection("home");
    } else {
      curSection=reqSection;
      //if (curSection=="lomos_de_salmon") { fnd=1; curSection=""; curSectionLeft=0; curSectionTop=180; }
      //if (curSection=="artenbuff") { fnd=1; curSectionLeft=sectionLeft; curSectionTop=sectionTop; }
      //if (curSection!="" && fnd) {
/*
      if (curSection!="") {
        showcursection();
        resetmenupos();
      }
*/
      if (reqSection=="lomos_de_salmon") { fnd=1; center('prodlev2'); getServerSection('lomos_de_salmon'); }
      if (reqSection=="lomos_de_salmon_var") { fnd=1; center('prodlev2'); getServerSection('lomos_de_salmon_var'); }
      if (reqSection=="lomos_de_salmon_foto") { fnd=1; center('prodlev2'); getServerSection('lomos_de_salmon_foto'); }
      if (reqSection=="penca_de_salmon") { fnd=1; center('prodlev2'); getServerSection('penca_de_salmon'); }
      if (reqSection=="pencas_de_salmon_var") { fnd=1; center('prodlev2'); getServerSection('pencas_de_salmon_var'); }
      if (reqSection=="penca_de_salmon_var") { fnd=1; center('prodlev2'); getServerSection('penca_de_salmon_var'); }
      if (reqSection=="penca_de_salmon_foto") { fnd=1; center('prodlev2'); getServerSection('penca_de_salmon_foto'); }
      if (reqSection=="corazon_de_salmon") { fnd=1; center('prodlev2'); getServerSection('corazon_de_salmon'); }
      if (reqSection=="corazon_de_salmon_var") { fnd=1; center('prodlev2'); getServerSection('corazon_de_salmon_var'); }
      if (reqSection=="corazon_de_salmon_foto") { fnd=1; center('prodlev2'); getServerSection('corazon_de_salmon_foto'); }
      if (reqSection=="tacos_de_salmon") { fnd=1; center('prodlev2'); getServerSection('tacos_de_salmon'); }
      if (reqSection=="tacos_de_salmon_foto") { fnd=1; center('prodlev2'); getServerSection('tacos_de_salmon_foto'); }
      if (reqSection=="toro_de_salmon") { fnd=1; center('prodlev2'); getServerSection('toro_de_salmon'); }
      if (reqSection=="toro_de_salmon_foto") { fnd=1; center('prodlev2'); getServerSection('toro_de_salmon_foto'); }
      if (reqSection=="penca_bacalao") { fnd=1; center('prodlev2'); getServerSection('penca_bacalao'); }
      if (reqSection=="penca_bacalao_foto") { fnd=1; center('prodlev2'); getServerSection('penca_bacalao_foto'); }
      if (reqSection=="lomo_bacalao") { fnd=1; center('prodlev2'); getServerSection('lomo_bacalao'); }
      if (reqSection=="lomo_bacalao_foto") { fnd=1; center('prodlev2'); getServerSection('lomo_bacalao_foto'); }
      if (reqSection=="corazon_bacalao") { fnd=1; center('prodlev2'); getServerSection('corazon_bacalao'); }
      if (reqSection=="corazon_bacalao_foto") { fnd=1; center('prodlev2'); getServerSection('corazon_bacalao_foto'); }
      if (reqSection=="tacos_bacalao") { fnd=1; center('prodlev2'); getServerSection('tacos_bacalao'); }
      if (reqSection=="tacos_bacalao_foto") { fnd=1; center('prodlev2'); getServerSection('tacos_bacalao_foto'); }
      if (reqSection=="anguila") { fnd=1; center('prodlev2'); getServerSection('anguila'); }
      if (reqSection=="anguila_foto") { fnd=1; center('prodlev2'); getServerSection('anguila_foto'); }
      if (reqSection=="atun") { fnd=1; center('prodlev2'); getServerSection('atun'); }
      if (reqSection=="atun_foto") { fnd=1; center('prodlev2'); getServerSection('atun_foto'); }
      if (reqSection=="caballa") { fnd=1; center('prodlev2'); getServerSection('caballa'); }
      if (reqSection=="pulpo") { fnd=1; center('prodlev2'); getServerSection('pulpo'); }
      if (reqSection=="pulpo_foto") { fnd=1; center('prodlev2'); getServerSection('pulpo_foto'); }
      if (reqSection=="rape") { fnd=1; center('prodlev2'); getServerSection('rape'); }
      if (reqSection=="rape_foto") { fnd=1; center('prodlev2'); getServerSection('rape_foto'); }
      if (reqSection=="terrina_de_foie") { fnd=1; center('prodlev2'); getServerSection('terrina_de_foie'); }
      if (reqSection=="terrina_de_foie_foto") { fnd=1; center('prodlev2'); getServerSection('terrina_de_foie_foto'); }
      if (reqSection=="magret_relleno") { fnd=1; center('prodlev2'); getServerSection('magret_relleno'); }
      if (reqSection=="magret_relleno_foto") { fnd=1; center('prodlev2'); getServerSection('magret_relleno_foto'); }
      if (reqSection=="pate") { fnd=1; center('prodlev2'); getServerSection('pate'); }
      if (reqSection=="pate_foto") { fnd=1; center('prodlev2'); getServerSection('pate_foto'); }
      if (reqSection=="pechuga_codorniz_aceite") { fnd=1; center('prodlev2'); getServerSection('pechuga_codorniz_aceite'); }
      if (reqSection=="pechuga_codorniz_aceite_foto") { fnd=1; center('prodlev2'); getServerSection('pechuga_codorniz_aceite_foto'); }
      if (reqSection=="muslitos_de_codorniz") { fnd=1; center('prodlev2'); getServerSection('muslitos_de_codorniz'); }
      if (reqSection=="muslitos_de_codorniz_foto") { fnd=1; center('prodlev2'); getServerSection('muslitos_de_codorniz_foto'); }
      if (reqSection=="pechuga_codorniz") { fnd=1; center('prodlev2'); getServerSection('pechuga_codorniz'); }
      if (reqSection=="pechuga_codorniz_foto") { fnd=1; center('prodlev2'); getServerSection('pechuga_codorniz_foto'); }
      if (reqSection=="carrilera") { fnd=1; center('prodlev2'); getServerSection('carrilera'); }
      if (reqSection=="carrilera_foto") { fnd=1; center('prodlev2'); getServerSection('carrilera_foto'); }
      if (reqSection=="patatas") { fnd=1; center('prodlev2'); getServerSection('patatas'); }
      if (reqSection=="patatas_foto") { fnd=1; center('prodlev2'); getServerSection('patatas_foto'); }
      if (reqSection=="tripas_bacalao") { fnd=1; center('prodlev2'); getServerSection('tripas_bacalao'); }
      if (reqSection=="tripas_bacalao_foto") { fnd=1; center('prodlev2'); getServerSection('tripas_bacalao_foto'); }
      if (reqSection=="tosta") { fnd=1; center('prodlev2'); getServerSection('tosta'); }
      if (reqSection=="tosta_foto") { fnd=1; center('prodlev2'); getServerSection('tosta_foto'); }
      if (reqSection=="arroz") { fnd=1; center('prodlev2'); getServerSection('arroz'); }
      if (reqSection=="arroz_foto") { fnd=1; center('prodlev2'); getServerSection('arroz_foto'); }
      if (reqSection=="sal") { fnd=1; center('prodlev2'); getServerSection('sal'); }
      if (reqSection=="sal_foto") { fnd=1; center('prodlev2'); getServerSection('sal_foto'); }
      if (reqSection=="bombones") { fnd=1; center('prodlev2'); getServerSection('bombones'); }
      if (reqSection=="bombones_foto") { fnd=1; center('prodlev2'); getServerSection('bombones_foto'); }
      if (reqSection=="noticias") { fnd=1; center('prodlev2'); getServerSection('noticias'); }
      if (reqSection=="ultima_noticia") { fnd=1; center('prodlev2'); getServerSection('ultima_noticia'); }
      if (!fnd) showsection(reqSection);
    }
    startmenu();
    curHash=reqSection;
    setTimeout("hashChecker()",1000);
  } else if (mode=="resize") {
    showcursection();
    resetmenupos();
  }
}


function setdivs_old(mode) {
  var reqSection="";
  var fnd=0;
  getWinSize();
  if (mode=="load") {
    if (debugmode) initdebug();
    reqSection=getHash();
    if (reqSection=="") {
      gohome();
    } else {
      curSection=reqSection;
      if (curSection=="lomos_de_salmon") { fnd=1; curSection=""; curSectionLeft=0; curSectionTop=180; }
      if (curSection=="lomos_de_salmon_var") { fnd=1; curSection=""; curSectionLeft=0; curSectionTop=180; }
      if (curSection=="lomos_de_salmon_foto") { fnd=1; curSection=""; curSectionLeft=0; curSectionTop=180; }
      if (curSection=="salmon") { fnd=1; curSectionLeft=0; curSectionTop=180; }
	  if (curSection=="pulpo") { fnd=1; curSectionLeft=0; curSectionTop=180; }
	   if (curSection=="muslitos_de_codorniz") { fnd=1; curSectionLeft=0; curSectionTop=180; }
	 /*  if (curSection=="bacalao") { fnd=1; curSectionLeft=0; curSectionTop=180; }
	  if (curSection=="penca_bacalao") { fnd=1; curSectionLeft=0; curSectionTop=180; }
	  if (curSection=="penca_bacalao_var") { fnd=1; curSectionLeft=0; curSectionTop=180; }
	  if (curSection=="penca_bacalao_foto") { fnd=1; curSectionLeft=0; curSectionTop=180; }
		
	  if (curSection=="lomo_bacalao") { fnd=1; curSectionLeft=0; curSectionTop=180; }
	  if (curSection=="lomo_bacalao_var") { fnd=1; curSectionLeft=0; curSectionTop=180; }
	  if (curSection=="lomo_bacalao_foto") { fnd=1; curSectionLeft=0; curSectionTop=180; }
	  
	  if (curSection=="corazon_bacalao") { fnd=1; curSectionLeft=0; curSectionTop=180; }
	  if (curSection=="corazon_bacalao_var") { fnd=1; curSectionLeft=0; curSectionTop=180; }
	  if (curSection=="corazon_bacalao_foto") { fnd=1; curSectionLeft=0; curSectionTop=180; }
	  
	  if (curSection=="tacos_bacalao") { fnd=1; curSectionLeft=0; curSectionTop=180; }
	  if (curSection=="tacos_bacalao_var") { fnd=1; curSectionLeft=0; curSectionTop=180; }
	  if (curSection=="tacos_bacalao_foto") { fnd=1; curSectionLeft=0; curSectionTop=180; }*/
	  
	  if (curSection=="anguila") { fnd=1; curSectionLeft=0; curSectionTop=180; }
	  if (curSection=="atun") { fnd=1; curSectionLeft=0; curSectionTop=180; }
	  if (curSection=="caballa") { fnd=1; curSectionLeft=0; curSectionTop=180; }
	  if (curSection=="rape") { fnd=1; curSectionLeft=0; curSectionTop=180; }
      if (curSection=="carpier") { fnd=1; curSectionLeft=sectionLeft; curSectionTop=sectionTop; }
      if (curSection=="como_llegar") { fnd=1; curSectionLeft=sectionLeft; curSectionTop=sectionTop; }
      if (curSection=="contacto") { fnd=1; curSectionLeft=sectionLeft; curSectionTop=sectionTop; }
	    if (curSection=="mapaweb") { fnd=1; curSectionLeft=sectionLeft; curSectionTop=sectionTop; }
	  if (curSection=="avisolegal") { fnd=1; curSectionLeft=sectionLeft; curSectionTop=sectionTop; }
      if (curSection=="artenbuff") { fnd=1; curSectionLeft=sectionLeft; curSectionTop=sectionTop; }
      if (curSection=="productos1") { fnd=1; curSectionLeft=0; curSectionTop=390; }
      if (curSection=="productos2") { fnd=1; curSectionLeft=0; curSectionTop=390; }
	  if (curSection=="productos3") { fnd=1; curSectionLeft=0; curSectionTop=390; }
      if (curSection!="" && fnd) {
        showcursection();
        resetmenupos();
      }
      if (reqSection=="lomos_de_salmon") { fnd=1; center('prodlev2'); getServerSection('lomos_de_salmon'); }
      if (reqSection=="lomos_de_salmon_var") { fnd=1; center('prodlev2'); getServerSection('lomos_de_salmon_var'); }
      if (reqSection=="lomos_de_salmon_foto") { fnd=1; center('prodlev2'); getServerSection('lomos_de_salmon_foto'); }
	  
	  
	 /*if (reqSection=="lomo_bacalao") { fnd=1; center('prodlev2'); getServerSection('lomo_bacalao'); }
	  if (reqSection=="lomo_bacalao_var") { fnd=1; center('prodlev2'); getServerSection('lomo_bacalao_var'); }
	   if (reqSection=="lomo_bacalao_fotos") { fnd=1; center('prodlev2'); getServerSection('lomo_bacalao_foto'); }
	   
      if (reqSection=="corazon_bacalao") { fnd=1; center('prodlev2'); getServerSection('corazon_bacalao'); }
	    if (reqSection=="corazon_bacalao_var") { fnd=1; center('prodlev2'); getServerSection('corazon_bacalao_var'); }
		  if (reqSection=="corazon_bacalao_foto") { fnd=1; center('prodlev2'); getServerSection('corazon_bacalao_foto'); }
		  
      if (reqSection=="tacos_bacalao") { fnd=1; center('prodlev2'); getServerSection('tacos_bacalao'); }
	  if (reqSection=="tacos_bacalao_var") { fnd=1; center('prodlev2'); getServerSection('tacos_bacalao_var'); }
	  if (reqSection=="tacos_bacalao_foto") { fnd=1; center('prodlev2'); getServerSection('tacos_bacalao_foto'); }*/
      if (!fnd) gohome();
      startmenu();
    }
    curHash=reqSection;
    setTimeout("hashChecker()",1000);
  } else if (mode=="resize") {
    showcursection();
    resetmenupos();
  }
}

// site specific
function setProdImg(cat,section,img) {
	var imgProd=new getObj("prodimg");
	imgProd.obj.src="img/productos/"+cat+"."+section+"/fotos/page."+img+".jpg";
}
// validate the contact form
function Mk_validateForm()
{
	var errors = "";
	nombre = document.frmContacto.Nombre.value;
	telefono = document.frmContacto.Telefono.value;
	email = document.frmContacto.Email.value;
	consulta = document.frmContacto.Consulta.value;
	aceptock = document.frmContacto.agreecheck.checked;
	
	if (nombre!="" && telefono != ""  && consulta != "") 
	{
		if(isNaN(telefono)) errors += '- revise el número de teléfono.\n';
		//p = email.indexOf('@');
		//if (p<1 || p==(email.length-1)) errors += '- revise su email.\n';
	}
	else
	{
		if(nombre =="" )errors += '- Nombre: Campo obligatorio\n';
		if(telefono =="" )errors += '- Telefono: Campo obligatorio\n';
		//if(email =="" )errors += '- Email: Campo obligatorio\n';
		if(consulta =="") errors += '- Escriba su consulta\n';
	}
	
	if(!aceptock) errors += '- Acepte la Politica de privacidad\n';
		
	if (errors) alert('Por favor compruebe los datos:\n'+errors);
    document.MM_returnValue = (errors == '');
}
