// JavaScript Document

function hideSelect () {
	sels = document.getElementsByTagName('select')
	for (i=0;i<sels.length;i++) {
		sels[i].style.visibility='hidden';
	}
}

function seeSelect () {
	sels = document.getElementsByTagName('select')
	for (i=0;i<sels.length;i++) {
		sels[i].style.visibility='visible';
	}
}

function RemPass() {
	parent.window.frames[1].location = "contacto.asp?rem=1";
}

function opacity(id, opacStart, opacEnd, millisec) { 
    //speed for each frame 
    var speed = Math.round(millisec / 100); 
    var timer = 0; 

    //determine the direction for the blending, if start and end are the same nothing happens 
    if(opacStart > opacEnd) { 
        for(i = opacStart; i >= opacEnd; i--) { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } else if(opacStart < opacEnd) { 
        for(i = opacStart; i <= opacEnd; i++) 
            { 
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            timer++; 
        } 
    } 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 

function shiftOpacity(id, millisec) { 
    //if an element is invisible, make it visible, else make it ivisible 
    if(document.getElementById(id).style.opacity == 0) { 
        opacity(id, 0, 100, millisec); 
    } else { 
        opacity(id, 100, 0, millisec); 
    } 
} 

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 P7_getWD(tDim){ //v2.6 by PVII
 var sh=0,sw=0,rt=0;if(window.innerWidth){sh=window.innerHeight;sw=window.innerWidth;
 }else if(document.body){sh=document.body.clientHeight;sw=document.body.clientWidth;
 if(document.body.offsetHeight==sh&&document.documentElement&&document.documentElement.clientHeight){
  sh=document.documentElement.clientHeight;}
 if(document.body.offsetWidth==sw&&document.documentElement&&document.documentElement.clientWidth) {
 sw=document.documentElement.clientWidth;}}rt=(tDim=="width")?sw:sh;return rt;
}

function P7_getLDims(el) { //v2.6 by PVII
 var x,ll=0,tl=0,hh=0,ww=0,wx,g,gg;
 if((g=MM_findObj(el))!=null){gg=(document.layers)?g:g.style;ll=parseInt(gg.left);
 tt=parseInt(gg.top);if(isNaN(ll)){if(g.currentStyle){ll=parseInt(g.currentStyle.left);
 }else if(document.defaultView&&document.defaultView.getComputedStyle){
 ll=parseInt(document.defaultView.getComputedStyle(g,"").getPropertyValue("left"));
 }if(isNaN(ll)){ll=0;}}if(isNaN(tt)){if(g.currentStyle){tt=parseInt(g.currentStyle.top);
 }else if(document.defaultView&&document.defaultView.getComputedStyle){
 tt=parseInt(document.defaultView.getComputedStyle(g,"").getPropertyValue("top"));}if(isNaN(tt)){tt=0;}}
 if(document.all||document.getElementById){ww=parseInt(g.offsetWidth);hh=parseInt(g.offsetHeight);
 if(!ww){ww=parseInt(g.style.pixelWidth);if(!ww){ww=parseInt(g.style.width);}}if(!hh){
 hh=parseInt(g.style.pixelHeight);}if(g.hasChildNodes&&g.childNodes){for(x=0;x<g.childNodes.length;x++){
 wx=parseInt(g.childNodes[x].offsetWidth);if(wx>ww){ww=wx;}}}}else if(document.layers){
 ww=parseInt(g.clip.width);hh=parseInt(g.clip.height);}}var aR=[ll,tt,hh,ww];return aR;
}

function P7_alignRR() { //v2.6 by PVII
 var i;if(!document.p7alignRR) {return;}if(document.layers){
 if(innerWidth!=document.p7RRiw || innerHeight!=document.p7RRih){location.reload();}
 }else{document.p7RR=1;for(i=0;i<p7aRR.length;i++){eval(p7aRR[i]);}document.p7RR=0;}
}

function P7_alignWD2() { //v2.6 by PVII
 var g,gg,lp=0,tp=0,aL,lh,lw,ww,wh,pa='px',args=P7_alignWD2.arguments;if(document.layers||window.opera){pa='';}
 for(var i=0;i<args.length;i+=4){if((g=MM_findObj(args[i]))!=null){gg=(document.layers)?g:g.style;
 mm=parseInt(args[i+1]);mr=parseInt(args[i+2]);ml=parseInt(args[i+3]);ww=parseInt(P7_getWD('width'));
 wh=parseInt(P7_getWD('height'));aL=P7_getLDims(args[i]);lh=aL[2];lw=aL[3];tp=aL[1];lp=aL[0];
 if(mm==1){lp=mr;}if(mm==2){lp=parseInt((ww-lw-mr)/2);if(lp<0){lp=0;}}if(mm==3){lp=ww-lw-mr;if(lp<ml){lp=ml;}}
 if(mm==4){tp=parseInt((wh-lh-mr)/2);if(tp<0){tp=0;}}if(mm==5){tp=parseInt((wh-lh)/2);lp=parseInt((ww-lw)/2);
 if((lp-mr)<=0){lp=mr;}if((tp-ml)<=0){tp=ml;}}if(mm==6){tp=wh-lh-mr;}gg.top=tp+pa;gg.left=lp+pa;
 if(!document.p7alignRR){p7aRR=new Array();document.p7alignRR=true;document.p7RR=0;
 if(document.layers){document.p7RRiw=innerWidth;document.p7RRih=innerHeight;}onresize=P7_alignRR;}
 if(document.p7RR==0){p7aRR[p7aRR.length]="P7_alignWD2('"+args[i]+"',"+mm+","+mr+","+ml+")";}}}
}
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 MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
function pviiClassNew(obj, new_style) {
    obj.className = new_style;
}
function PNG_loader() { 
   for(var i=0; i<document.images.length; i++) { 
      var img = document.images[i]; 
      var imgName = img.src.toUpperCase(); 
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG") { 
         var imgID = (img.id) ? "id='" + img.id + "' " : ""; 
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""; 
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "; 
         var imgStyle = "display:inline-block;" + img.style.cssText; 
         if (img.align == "left") imgStyle += "float:left;"; 
         if (img.align == "right") imgStyle += "float:right;"; 
         if (img.parentElement.href) imgStyle += "cursor:hand;"; 
         var strNewHTML = "<span " + imgID + imgClass + imgTitle 
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" 
            + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" 
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"; 
         img.outerHTML = strNewHTML; 
         i--; 
      } 
   } 
} 

function navDet(){
	var browsertype=navigator.userAgent;
	browsertype = browsertype.toUpperCase();
		if (browsertype.indexOf("MSIE")==-1)
			return false;
		else
			return true;
}

if (navDet()) {
	window.attachEvent("onload", PNG_loader); 
}

var WindowObjectReference = null; // global variable
var WindowObjectReference2 = null; // global variable

function winOpen(win)
{
  if(WindowObjectReference == null || WindowObjectReference.closed)
  /* if the pointer to the window object in memory does not exist
     or if such pointer exists but the window was closed */

  {
    WindowObjectReference = window.open(win,
           "footer", "width=700,height=500,resizable=no,scrollbars=yes,status=no,toolbar=no");
    /* then create it. The new window will be created and
       will be brought on top of any other window. */
  }
  else
  {	
  	WindowObjectReference = window.open(win,
           "footer", "width=700,height=500,resizable=no,scrollbars=yes,status=no,toolbar=no");
    WindowObjectReference.focus();
    /* else the window reference must exist and the window
       is not closed; therefore, we can bring it back on top of any other
       window with the focus() method. There would be no need to re-create
       the window or to reload the referenced resource. */
  };
}

function winOpenMini(win,w,h)
{
	if(WindowObjectReference2 == null || WindowObjectReference2.closed){
		WindowObjectReference2 = window.open(win,"sugerencias","width="+w+",height="+h+",resizable=no,scrollbars=no,status=no,toolbar=no,top=150,left=150");
	}else{
		WindowObjectReference2 = window.open(win,"sugerencias","width="+w+",height="+h+",resizable=no,scrollbars=no,status=no,toolbar=no,top=150,left=150");
		WindowObjectReference2.focus();
	}
}

function clickIE(){ 
if (document.all){ 
  (message); 
  return false; 
 }
} 

function clickNS(e){ 
 if (document.layers || (document.getElementById && !document.all)){ 
  if (e.which == 2 || e.which == 3){ 
   //(message); 
   return false; 
  } 
 }

} 

if (document.layers){ 
 document.captureEvents(Event.MOUSEDOWN); 
 document.onmousedown = clickNS; 
} else { 
 document.onmouseup = clickNS; 
 document.oncontextmenu = clickIE; 
} 
document.oncontextmenu = new Function("return false") 

//ESTA FUNCION ES LA QUE SIRVE PARA CREAR EL OBJETO QUE NOS DEVOLVERA LA CONSULTA

function createRequestObject() {
    var xmlhttp;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        xmlhttp = new XMLHttpRequest();
    }
    return xmlhttp;
}

// Creamos el objeto XMLHttpRequest
// De esta forma creamos el objeto

//var http = createRequestObject();

function creaHttpRequest(){
	http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }

    if (!http_request) { return false; }
	return http_request;
}

//Rubén 24/1/2007
// Crea un objeto httpRequest y envia la petición de datos al servidor web
// Parametros: Nombre del fex a llamar, Nombre de la función que se ejecutará cuando acabe,
//	parejas nombre variable focus y valor que queremos pasar. Las que queráis
// Retorno: Objeto httpRequest recién creado y que después necesitaremos para recoger los resultados
// Para cualquier función javascript está diponible el array arguments con todos los valores que hemos pasado
//	como parámetros. Esto nos permite gestionar un número indeterminado de parámetros
function consultaAjax () {
	// Comprobamos número de parámetros
	var numParam = arguments.length;
	if ((numParam < 2) || (numParam % 2 == 1)) {
		alert("!IBI.AMP.LITEEPARAM;");
		return;
	}

	// Creamos la url a la que llamaremos para realizar la consulta
	var random=Math.random();
	var url = "/ibi_apps/WFServlet?RANDOM="+random+"&"+"IBIF_ex="+arguments[0];
    for (i=2; i<arguments.length; i+=2) url += "&"+arguments[i]+"="+arguments[i+1];

	// Creamos el objetos httpRequest
	var httpReq = creaHttpRequest();

	// Inicializamos el objeto
	httpReq.open("GET", url, true);

	// Indicamos la función que deseamos invocar al finalizar la petición
	httpReq.onreadystatechange = arguments[1];

	// Realizamos la petición
	return httpReq;
}

//Rubén 24/1/2007
// Recoge el resultado de la petición de datos de una cunsulta Ajax
// Parametros: Objeto httpRequest con el cual hicimos la petición
// Retorno: string con el resultado de la consulta
function resultadoAjax (httpReq) {
	var resultado = '';
	// Comprobamos si hemos acabado la consulta
	if (httpReq.readyState != 4) {
		return resultado;
	}
	// Comprobamos si la operación tuvo éxito
	if (httpReq.status != 200) {
		return resultado;
	}
	resultado = httpReq.responseText;
	return resultado;

}

//Rubén 13/2/2007. Aún no funciona
// Idem consultaAjax, pero le pasamos las variable y valores que le queremos pasar
//	en el formato correcto en el tercer parßmetro y llamaremos al .fex por post para
//	permitir un n·mero mayor
function consultaAjaxPost (programa,ARes_func,param) {
	// Creamos la url a la que llamaremos para realizar la consulta
	var random=Math.random();
	var url = "/ibi_apps/WFServlet?RANDOM="+random+"&"+"IBIF_ex="+programa+param;

	// Creamos el objetos httpRequest
	var httpReq = creaHttpRequest();

	// Inicializamos el objeto
	httpReq.open("POST", url, true);

	// Indicamos la función que deseamos invocar al finalizar la petición
	httpReq.onreadystatechange = ARes_func;

	// Realizamos la petición
	return httpReq;
}


//Rubén 1/3/2007. Nuevas funciones Ajax que permiten tener un número indeterminado de objetos corriendo
// Ejempro de uso
//
//	function miFuncionLanzaAjax (a,b) {
//		var httpRequest = crearAjax();
//		lanzarAjax(httpRequest,"proframa_fex",function () {miFuncionResuelveAjax(httpRequest);},"ACCION","VALORES","A",a,"B",b);
//	}
//
//	function miFuncionResuelveAjax (httpRequest) {
//		if (httpRequest) {
//			var resultado = resultadoAjax(httpRequest);
//			if (resultado!='') {
//				// Lo que quieras hacer con el resultado
//			}
//		}
//	}
//
//	Fíjate que la variable httpRequest que contiene el objeto ajax se crea en la misma función de llamada y se recoge como parámetro
//  en la función de respuesta, de manera que no se ha de mantener una variable global y por tanto tampoco está limitado al desarrollo
//	el número de consultas ajax que se puede realizar.

//Para que tenga un nombre más mono
function crearAjax () {
	// Creamos el objetos httpRequest
	return creaHttpRequest();
}

// Prepara un objeto httpRequest y lo lanza
// Parametros:  (los argumentos se recogen en el array arguments automáticamente
//	Objeto httpRequest préviamente creado,
//	Nombre del fex a llamar,
//	Apuntador a la función que se ejecutará cuando acabe,
//	Parejas nombre variable focus y valor que queremos pasar. Las que queráis
function lanzarAjax() {
	// Comprobamos número de parámetros
	var numParam = arguments.length;
	if ((numParam < 3) || (numParam % 2 == 0)) {
		alert("!IBI.AMP.LITEEPARAM;");
		return;
	}

	// Creamos la url a la que llamaremos para realizar la consulta
	var randoms=Math.random();
	var url = arguments[1]+"?d="+randoms;
    for (i=3; i<arguments.length; i+=2) url += "&"+arguments[i]+"="+arguments[i+1];

	// Creamos el objetos httpRequest
	var httpReq = arguments[0];

	// Inicializamos el objeto
	httpReq.open("GET", url, true);
	// Indicamos la función que deseamos invocar al finalizar la petición
	httpReq.onreadystatechange = arguments[2];

	// Realizamos la petición
	httpReq.send(null);
}

// ATENCION!!!: No funciona. Parece que no se puede llamar por POST
// Prepara un objeto httpRequest y lo lanza via POST
//  Recoge todos los elementos del form y los pasa como parametros
// Parametros:  (los argumentos se recogen en el array arguments automáticamente
//	Objeto httpRequest préviamente creado,
//	Nombre del fex a llamar,
//	Apuntador a la función que se ejecutará cuando acabe,
//	Objeto de form de donde se recogerán los elementos
function lanzarAjaxFormPost () {
	// Comprobamos número de parámetros
	var numParam = arguments.length;
	if (numParam !=4) {
		alert("!IBI.AMP.LITEEPARAM;");
		return;
	}

	// Recogemos los argumentos
	var httpReq = arguments[0];
	var random=Math.random();
	var url = "/ibi_apps/WFServlet?RANDOM="+random+"&IBIF_ex="+arguments[1];
	var variables = arguments[3].elements;
	arguments[3].IBIF_ex.value = arguments[1];
	var param = '';
	for (i=0;i<variables.length;i++) {
		if (variables[i].name != '' && variables[i].value != '') {
			param += '&'+variables[i].name+'='+variables[i].value;
		}
	}

	// Inicializamos el objeto
	httpReq.open("POST", url, true);

	// Indicamos la función que deseamos invocar al finalizar la petición
	httpReq.onreadystatechange = arguments[2];

	// Realizamos la petición
// AÑADIDO PARA VER SI USANDO UN HEADER CHUTA....
//	  http_request.setRequestHeader("Content-length", parameters.length);
//    http_request.setRequestHeader("Connection", "close");

	httpReq.send(param);
}


//FUNCIONES PARA PODER HACER TRIMS DE LOS INPUT
//--------------------------------------------------------------------------

function Trim(TRIM_VALUE){
if(TRIM_VALUE.length < 1){
return"";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function
