// JavaScript Document
function disableForms() {
	var combo1=document.getElementById('form-profesion');
	combo1.style.visibility='hidden';
	var forms = document.getElementsByTagName('form');
	for (var k = 0; k < forms.length; k++) {
		try {
			Form.disable(forms[k]);
		} catch(e) {;}
	}
}
function enableForms() {
	var combo1=document.getElementById('form-profesion');
	combo1.style.visibility='visible';
	var forms = document.getElementsByTagName('form');
	for (var k = 0; k < forms.length; k++) {
		try {
			Form.enable(forms[k]);
		} catch(e) {;}
	}
}

var mostrandoImagen = false;
var enMostrarImagen = false;
var enOcultarImagen= false;
function mostrarImagen(toHide, imgUrl, w, h,top) {
	if (mostrandoImagen || enMostrarImagen) return false;
	enMostrarImagen = true;
	var oBox = $('mostrarImagenBox');
	var oImg = $('mostrarImagenImg');
	var oHide = $(toHide);
	// Set image parameters
	oImg.src = imgUrl;
	oImg.width = w;
	oImg.height = h;
	document.body.appendChild(oBox);
	var bodyDims = Element.getDimensions(document.body);
	var toHideDims = Element.getDimensions(toHide);
	var boxDims = Element.getDimensions(oBox);
//	oBox.style.left = parseInt(bodyDims.width/2-boxDims.width/2+100)+"px";
	oBox.style.left = parseInt(bodyDims.width/2-boxDims.width/2+1)+"px";
	oBox.style.top = parseInt(top)+"px";
//	oBox.style.top = parseInt(400)+"px";
//	oBox.style.top = parseInt(toHideDims.height/2-boxDims.height-100)+"px";
	var fAfterFinish = function () {
		mostrandoImagen = true;
	}
	disableForms();
	new Effect.Fade(oHide, {duration: 1.0, from: 1.0, to: 0.5});
	new Effect.Appear(oBox, {duration: 1.0, afterFinish: fAfterFinish});
	enMostrarImagen = false;
	return false;
}

function ocultarImagen(toShow) {
	if (!mostrandoImagen || enOcultarImagen) return false;
	enOcultarImagen = true;
	var oBox = $('mostrarImagenBox');
	var oImg = $('mostrarImagenImg');
	var oShow = $(toShow);
	var fAfterFinish = function () {
		mostrandoImagen = false;
		enableForms();
		oBox.style.display = 'none';
	}
	new Effect.Fade(oBox, {duration: 0.5});
	new Effect.Appear(oShow, {duration: 1.0, from: 0.5, to: 1.0, afterFinish: fAfterFinish});	
	enOcultarImagen = false;
	return false;
}



/* AJAX */
/*Inicio Funciones Remotas*/
function RMT_inicializa() {
var xx=null;
 try {
  xx = new XMLHttpRequest();
 } catch (e) {
  xx=null;
  var msxmlhttp = new Array('Msxml2.XMLHTTP.5.0',
                      'Msxml2.XMLHTTP.4.0',
                      'Msxml2.XMLHTTP.3.0',
                      'Msxml2.XMLHTTP',
                      'Microsoft.XMLHTTP');
  var success = false;
  for (var i=0; i<msxmlhttp.length && !success;i++) {
   try {
    xx = new ActiveXObject(msxmlhttp[i]);
    success = true;
   } catch (e) { xx=null; }
  }
 }
 return xx;
}

var LNSR_layer='';
var LNSR_funcion='';

function LNSR_ejecutar(lay,reg,metodo,uri,funcion, args) {
 var i, n;
 var post_data;
 var retorno=true;
 LRMT_ResultadoError='';
 LRMT_ResultadoHttp='';
 LNSR_layer=lay;
 LNSR_funcion=reg;
 if (typeof(metodo) == "undefined" || metodo== "") 	metodo = "GET";
 if (metodo == "GET") {
  if (uri.indexOf("?") == -1) uri += "?fn=" + escape(funcion);
  else uri += "&fn=" + escape(funcion);
  uri += "&fnrnd=" + new Date().getTime();
  for (i = 0; i < args.length-1; i+=2) uri += "&" + args[i] + "=" + escape(args[i+1]);
  post_data = null;
 } else if (metodo == "POST") {
  post_data = "fn=" + escape(funcion);
  post_data += "&fnrnd=" + new Date().getTime();
  for (i = 0; i < args.length-1; i+=2) {
		post_data += "&" + args[i] + "=" + escape(args[i+1]);
	}
 } else {
  alert("Tipo de Petición Ilegal: " + LRMT_tipopeticion);
  LNSR_funcion();
  return false;
 }
 if (LRMT_conector == null) {
  alert("Imposible Crear Objeto de conexión Remota al Servidor.");
  return false;
  LNSR_funcion();
 } else {
	bComplete = false;
  LRMT_conector.open(metodo, uri, true);
  if (metodo == "POST") {
   LRMT_conector.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
   LRMT_conector.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=iso-8859-1");
  }
  LRMT_conector.onreadystatechange = function(){
   if (LRMT_conector.readyState == 4 && !bComplete) {
     bComplete = true
     LNSR_ejecutar2(LRMT_conector)
   }
  };
  LRMT_conector.send(post_data);
  return retorno;
 }
}


function LNSR_ejecutar2(a) {
		var reto = false;
		try {
			switch(a.status) {
				case 200:
					document.getElementById(LNSR_layer).innerHTML=a.responseText;
					reto = true;
					break;
				case 400:
					alert('El servidor envió el código de Error: '+a.status+' (Petición errónea. Se ha introducido una URL mal formada.) a la petición solicitada');
					break;
				case 401:
					alert('El servidor envió el código de Error: '+a.status+' (No autorizado. El visitante no tiene autorización para acceder a esa página.) a la petición solicitada');
					break;
				case 403:
					alert('El servidor envió el código de Error: '+a.status+' (Prohibido. Permisos insuficientes para leer esa página o directorio.) a la petición solicitada');
					break;
				case 404:
					alert('El servidor envió el código de Error: '+a.status+' (No encontrado. La página solicitada no se ha encontrado.) a la petición solicitada');
					break;
				default:
					alert('El servidor envió el código de Error: '+a.status+' (Error interno del servidor Ocurrió un error interno mientras se intentaba mostrar la página solicitada.) a la petición solicitada');
					break;
			}
		} catch (e) {
			//alert("Unable connect to server.")
		}
	if (!reto) LNSR_funcion();
	return reto;
}

var LRMT_conector = RMT_inicializa();
var LRMT_ResultadoHttp="";
var LRMT_ResultadoError="";
/*final Funciones Remotas*/




/* TAMAÑO DE LETRA */
function FindObj(n, d) { //v4.01
	var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
	if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
	for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=FindObj(n,d.layers[i].document);
	if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function ChangeProp(objName,x,theProp,theValue){ //v6.0
	var obj = FindObj(objName);
	if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
		if (theValue == true || theValue == false)
		eval("obj."+theProp+"="+theValue);
		else eval("obj."+theProp+"='"+theValue+"'");
		var ob=document.getElementById(objName);
		ob.style.fontSize=theValue+'px';
	}
}


function LoadActualFontSize() {
	tempArray = document.cookie.split(";");
	for (tA = 0; tA < tempArray.length; tA++){
		if (tempArray[tA].indexOf('fontSize') > -1){
			fontSizeValue = tempArray[tA].split("=")
			ACTUAL_FONTSIZE = parseInt(fontSizeValue[1]);
		}
	}
}

function SaveActualFontSize() {
	var expire = new Date ();
	expire.setTime (expire.getTime() + (6000 * 24 * 3600000));
	expire = expire.toGMTString();
	//document.cookie="fontSize="+ACTUAL_FONTSIZE+"; path=/; expires="+expire;
}

function Bigger() {
	ACTUAL_FONTSIZE = ACTUAL_FONTSIZE+3;
	if (ACTUAL_FONTSIZE > LARGEST_FONTSIZE) { ACTUAL_FONTSIZE = LARGEST_FONTSIZE }
	ChangeProp('texto','','style.fontSize',ACTUAL_FONTSIZE,'p');
	SaveActualFontSize();
}

function Smaller() {
	ACTUAL_FONTSIZE = ACTUAL_FONTSIZE-3;
	if (ACTUAL_FONTSIZE < SMALLEST_FONTSIZE) { ACTUAL_FONTSIZE = SMALLEST_FONTSIZE }
	ChangeProp('texto','','style.fontSize',ACTUAL_FONTSIZE,'p');
	SaveActualFontSize();
}

var ACTUAL_FONTSIZE = 12;
var SMALLEST_FONTSIZE = 9;
var LARGEST_FONTSIZE = 18;
//LoadActualFontSize();

// AJAX PARA LAS NEWS
function Show_News(idn,lng){
	var valor=idn;
	if (valor!=''){
		capa=document.getElementById('contenido-novedades');
 		capa.style.visibility='hidden';
		var nn= new Array('notid',valor,'ln',lng);
		xx='includes/show_noticias.php';
		LNSR_ejecutar('contenido-novedades','','GET',xx,'', nn);
 		capa.style.visibility='visible';
	}
}

// AJAX PARA LOS CONSEJOS
function Show_Advice(idn,lng){
	var valor=idn;
	if (valor!=''){
		capa=document.getElementById('contenido-consejos');
 		capa.style.visibility='hidden';
		var nn= new Array('cid',valor,'ln',lng);
		xx='includes/show_advice.php';
		LNSR_ejecutar('contenido-consejos','','GET',xx,'', nn);
 		capa.style.visibility='visible';
	}
}
function close_plano(){
	var capa2=document.getElementById('pagina-sonlab');
	var capa=document.getElementById('mostrar-mapa-tienda');
	new Effect.Fade(capa2, {duration: 1.0, from: 0.7, to: 0.0});
	capa.style.display='none';
	var nn= new Array('a',0);
	xx='includes/loading.php';
	LNSR_ejecutar('mostrar-mapa-tienda','','GET',xx,'', nn);

}


function Show_Plano(tid,lng){
	if(window.pageYOffset){
		e=window.pageYOffset;
	}else {
		e=Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	}
	var valor=tid;
	var ancho=document.body.clientWidth;
	if (!ancho) ancho=window.innerWidth;
	var posicion=parseInt((ancho/2)-300);
	if (valor!=''){
		var capa2=document.getElementById('pagina-sonlab');
		new Effect.Appear(capa2, {duration: 1.0, from: 0.0, to: 0.7,afterfinish:0});	
		capa=document.getElementById('mostrar-mapa-tienda');
		var nn= new Array('id_tienda',valor, 'LNG',lng);
		xx='includes/show_plano.php';
		LNSR_ejecutar('mostrar-mapa-tienda','','GET',xx,'', nn);
 		capa.style.left=posicion+'px';
 		capa.style.top=(e+100)+'px';
 		capa.style.display='block';
 		capa.style.visibility='visible';
	}
}

function Show_Foto(tid,lng){
	if(window.pageYOffset){
		e=window.pageYOffset;
	}else {
		e=Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	}
	var valor=tid;
	var ancho=document.body.clientWidth;
	if (!ancho) ancho=window.innerWidth;
	var posicion=parseInt((ancho/2)-300);
	if (valor!=''){
		var capa2=document.getElementById('pagina-sonlab');
		new Effect.Appear(capa2, {duration: 1.0, from: 0.0, to: 0.7,afterfinish:0});	
		capa=document.getElementById('mostrar-mapa-tienda');
		var nn= new Array('id_tienda',valor, 'LNG',lng);
		xx='includes/show_foto_tienda.php';
		LNSR_ejecutar('mostrar-mapa-tienda','','GET',xx,'', nn);
 		capa.style.left=posicion+'px';
 		capa.style.top=(e+100)+'px';
 		capa.style.display='block';
 		capa.style.visibility='visible';
	}
}

function Show_Oferta(oid,lng,minw){
	var minw=minw;
	var valor=oid;
	var ancho=document.body.clientWidth;
	if (!ancho) ancho=window.innerWidth;
	var posicion=parseInt((ancho/2)-(minw/2));
	var ref=document.getElementById('main');
	var capa2=document.getElementById('pagina-sonlab');

	if (valor!=''){
		new Effect.Appear(capa2, {duration: 1.0, from: 0.0, to: 0.7,afterfinish:0});	
		capa=document.getElementById('mostrar-mapa-tienda');
		capa2.style.heigh='200%';
		var nn= new Array('id_oferta',valor, 'LNG',lng,'w',minw);
		xx='includes/show_oferta.php';
		LNSR_ejecutar('mostrar-mapa-tienda','','GET',xx,'', nn);
 		capa.style.border='0px';
 		capa.style.left=posicion+'px';
 		capa.style.top='220px';
 		capa.style.width=minw+'px';
 		capa.style.display='block';
 		capa.style.background='#000';
 		//capa.style.border='4px solid #958e6c';
 		capa.style.visibility='visible';
	}
}

function showFotoProd(pid,fid){
	var valor=pid;
	var foto=(fid+1);
	var fotolink=document.getElementById('fotolink'+fid);
	var h=0;
	while(h<3){
		var linktohide=document.getElementById('fotolink'+h);
		if (linktohide) linktohide.style.fontWeight='normal';
		h++;
	}
	fotolink.style.fontWeight='bold';
	if (valor!=''){
		capa=document.getElementById('picture');
		var nn= new Array('id_prod',valor,'foto',foto);
		xx='includes/show_foto_prod.php';
		LNSR_ejecutar('picture','','GET',xx,'', nn);
	}
}

function avisolegal(ln){
	capa=document.getElementById('mostrar-aviso');
	capa.style.display='block';
	var nn= new Array('ln',ln);
	xx='includes/ajax.avisolegal.php';
	LNSR_ejecutar('mostrar-aviso','','GET',xx,'', nn);
	var h=document.body.clientHeight;
	if (!h) h=window.innerHeight;
	var v=document.body.clientWidth;
	if (!v) v=window.innerWidth;
	var posi_h=(h-450);
	var posi_v=((v/2)-200);
	capa.style.top=posi_h+'px';
	capa.style.left=posi_v+'px';
}

function closeaviso(){
	capa=document.getElementById('mostrar-aviso');
	capa.style.display='none';
}


function ShowProducto(idp,lng,padre,hijo){
	var p=1;
	while (p<50){
		var tohidep=document.getElementById('tipo'+p);
		if (tohidep) tohidep.style.color='#fff';
		var tohideh=document.getElementById('subtipo'+p);
		if (tohideh){
			tohideh.style.color='#DBD7CB';
			tohideh.style.fontWeight='normal';
		}
		p++;
	}


	var idpadre=padre;
	if (idpadre!=''){
		var tomark=document.getElementById('tipo'+idpadre);
		if (tomark) tomark.style.color='#ff0';
	}else{
		idpadre=0;
	}

	var subtipo=idp;
	if (subtipo!=''){
		var tomark2=document.getElementById('subtipo'+subtipo);
		if (tomark2){
			tomark2.style.fontWeight='bold';
			tomark2.style.color='#ff0';
		}
	}else{
		subtipo=0;
	}
/*
/*
	var idhijo=hijo;
	if (idhijo!=''){
		var tomark2=document.getElementById('subtipo'+idhijo);
		if (tomark2){
			tomark2.style.fontWeight='bold';
			tomark2.style.color='#fff';
		}
	}else{
		idhijo=0;
	}

	var p=1;
	while (p<20){
		if ((p!=idpadre) && (p!=subtipo)){
			var tohidep=document.getElementById('tipo'+p);
			if (tohidep) tohidep.style.color='#fff';
			var tohideh=document.getElementById('subtipo'+p);
			if (tohideh){
				tohideh.style.color='#DBD7CB';
				tohideh.style.fontWeight='normal';
			}
		}
		p++;
	}
*/
	var valor=idp;
	if (valor!=''){
		capa=document.getElementById('contenido-productos');
 		capa.style.visibility='hidden';
		var nn= new Array('pid',valor,'ln',lng);
		xx='includes/show_producto.php';
		LNSR_ejecutar('contenido-productos','','GET',xx,'', nn);
 		capa.style.visibility='visible';
	}
	
}