// JavaScript Document
function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
	if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
		document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_openBrWindow(theURL,winName,features) { //v2.0
  return window.open(theURL,winName,features);
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_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=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_displayStatusMsg(msgStr) { //v1.0
	status=msgStr;
	document.MM_returnValue = true;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


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 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();


function go_buscar(){
	var frm=document.getElementById('form-buscar');
	frm.submit();
}

function close_plano(pat){
	var capa=document.getElementById('mostrar-mapa-tienda');
	capa.style.visible='hidden';
	var nn= new Array('fid',0, 'base',pat);
	xx=pat+'includes/loading.php';
	LNSR_ejecutar('mostrar-mapa-tienda','','GET',xx,'', nn);
	capa.style.display='none';
}

function Show_Foto(tid,pat,wi){
	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-wi)/2);
	if (valor!=''){
		laypic=document.getElementById('mostrar-mapa-tienda');
		var nn= new Array('imagen',valor, 'base',pat);
		xx=pat+'includes/show_foto_tienda.php';
		LNSR_ejecutar('mostrar-mapa-tienda','','GET',xx,'', nn);
 		laypic.style.left=posicion+'px';
 		laypic.style.top=(e+200)+'px';
 		laypic.style.display='block';
 		laypic.style.visibility='visible';
	}
}

function mostrar_ppd(){
	if(window.pageYOffset){
		e=window.pageYOffset;
	}else {
		e=Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	}
	var ancho=document.body.clientWidth;
	if (!ancho) ancho=window.innerWidth;
	var posicion=parseInt((ancho-400)/2);
	laypic=document.getElementById('ppd');
	laypic.style.left=posicion+'px';
	laypic.style.top=(e+200)+'px';
	laypic.style.display='block';
	laypic.style.visibility='visible';
}

var lastlen;
var lastcolor;
function checklength(obj, len, id) {
	var color = "";
	var count = "";
	if (obj.value.length >= len){
		color = "red";
		obj.value = obj.value.substring(0, len);
	}
	else if (len - obj.value.length < len * 0.25)
	color = "#FF0000";
	if (obj.value.length != lastlen){
		count = len - obj.value.length;
		document.getElementById(id).innerHTML = count;
	}
	if (color != lastcolor){
		lastcolor = color;
		document.getElementById(id).style.color = color;
	}
}

function close_ppd(){
	var capa=document.getElementById('ppd');
	capa.style.visible='hidden';
	capa.style.display='none';
}
