// JavaScript Document

var contenido;
var refrescatxt = true;

function ensenamensajes(urlpedida){
  var urlped = "../avisos/mensaje.jsp?mensaje="+urlpedida;
  makerequest(urlped,'resajax')
}

function ensenamensaje(urlpedida){
  var urlped = urlpedida;
  makerequest(urlped,'resajax2')
  //atextos();
}

function printmensaje(){
  try{
    document.mensaje_iframe.window.focus();
    document.mensaje_iframe.window.print();
  }catch(e){
    window.mensaje_iframe.focus(); 
    window.mensaje_iframe.print(); 
  }
}

function compruebaaviso(){

}

function ensenabody(){
  document.body.style.display = "block";
  try{document.getElementById("maincontainer").style.display = "block";}catch(e){}
  try{document.getElementById("divtotus").style.display = "block";}catch(e){}
  try{document.getElementById("divprevio").style.display = "none";}catch(e){}
}

var x = -1;
var y = -1;
var x1 = 0;
var y1 = 0;
var x0 = 0;
var y0 = 0;

/*
var bloqueada = 0;

function MenuClick(j){
	alert(j);
	bloqueada = j;
	for(i=1;i<999;i++){
		capa2 = "boton"+i;
		if(document.getElementById(capa2)!=null){
			document.getElementById(capa2).className='bot-botonera';
		}else{
			i=9999;
		}
	}
	capa = "boton"+j;
	document.getElementById(capa).className='bot-botonera-press';
}
function MenuOver(j){
	if(bloqueada!=j){
		capa = "boton"+j;
		document.getElementById(capa).className='bot-botonera-over';
	}
}
function MenuOut(j){
	if(bloqueada!=j){
		capa = "boton"+j;
		document.getElementById(capa).className='bot-botonera';
	}
}
//
*/

function milisfecha_old(dia){ 
  if(dia.length==10){
    var di= dia.substring(0,2);
    var me = dia.substring(3,5);
    var ao =dia.substring(6);
    var dates =new Date();
    dates.setFullYear(ao,me,di);
    dates.setHours("00");
    dates.setMinutes("00")
    dates.setSeconds("00");
    return dates.getTime();
  }
}

function milisfecha2(dia){ 
    var di= dia.substring(0,2);
    var me = dia.substring(3,5);
    var ao = dia.substring(6);
	if( di.substring(0,1)=="0"){
		di = di.substring(1)
	}
	if( me.substring(0,1)=="0"){
		me = me.substring(1)
	}
    return ((parseInt(ao)*365)+(parseInt(me)*30)+parseInt(di));
}

function milisfecha(dia){ 
    var di= dia.substring(0,2);
    var me = dia.substring(3,5);
    var ao = dia.substring(6);
	if( di.substring(0,1)=="0"){
		di = di.substring(1)
	}
	if( me.substring(0,1)=="0"){
		me = me.substring(1)
	}
    return ((parseInt(ao)*365)+(parseInt(me)*30)+parseInt(di));
}

function milisfecha_mal(dia){ 
	 if(dia.length==10){
    //alert(dia.substring(0,2));
	  var di= parseInt(dia.substring(0,2));
    if(dia.substring(0,2)=='01'){
      di= 1;
    }
    if(dia.substring(0,2)=='02'){
      di= 2;
    }
    if(dia.substring(0,2)=='03'){
      di= 3;
    }
    if(dia.substring(0,2)=='04'){
      di= 4;
    }
    if(dia.substring(0,2)=='05'){
      di= 5;
    }
    if(dia.substring(0,2)=='06'){
      di= 6;
    }
      if(dia.substring(0,2)=='07'){
      di= 7;
    }
      if(dia.substring(0,2)=='08'){
      di= 8;
    }
      if(dia.substring(0,2)=='09'){
      di= 9;
    }
	  var me = parseInt(dia.substring(3,5));
      if(dia.substring(3,5)=='08'){
        me = 8;
      }
    var ao =parseInt(dia.substring(6));
    var milises = di + (me*30) + (ao*360*30);
    //alert(dia+".."+di+".."+me+".."+ao+"..."+milises);
    return (milises);
	 }
}

function milisfecha_mal_ocho(dia){
	 if(dia.length==10){
	  var di= parseInt(dia.substring(0,2));
	  var me = parseInt(dia.substring(3,5));
      var ao =parseInt(dia.substring(6));
	  return (di + (me*30) + (ao*360*30));
	 }
}

function  dimension(){
  //alert("--dimension-");
  if (self.innerHeight) // all except Explorer
  {
    x = self.innerWidth;
    y = self.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientHeight)
    // Explorer 6 Strict Mode
  {
    x = document.documentElement.clientWidth;
    y = document.documentElement.clientHeight;
  }
  else if (document.body) // other Explorers
  {
    x = document.body.clientWidth;
    y = document.body.clientHeight;
  }
  //alert(x+"..."+y);
}





function  dimensioncaja(caja){
	var obj = document.getElementById(caja);
	//alert(obj);
  //alert("---");
  if (self.innerHeight) // all except Explorer
  {
    x1 = obj.innerWidth;
    y1 = obj.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientHeight)
    // Explorer 6 Strict Mode
  {
    x1 = obj.clientWidth;
    y1 = obj.clientHeight;
  }
  else if (document.body) // other Explorers
  {
    x1 = obj.clientWidth;
    y1 = obj.clientHeight;
  }
  //alert(x+"..."+y);
}

//Scrolling offset
//How much the page has scrolled.
function dimensionscroll(){
  if (self.pageYOffset) // all except Explorer
  {
    x0 = self.pageXOffset;
    y0 = self.pageYOffset;
  }
  else if (document.documentElement && document.documentElement.scrollTop)
    // Explorer 6 Strict
  {
    x0 = document.documentElement.scrollLeft;
    y0 = document.documentElement.scrollTop;
  }
  else if (document.body) // all other Explorers
  {
    x0 = document.body.scrollLeft;
    y0 = document.body.scrollTop;
  }
}

//Page height
//The height of the total page (usually the body element).
//This is a tricky one, some browsers require scrollHeight, others offsetHeight, but all browsers support both properties. Therefore I see which property has the larger value. This means the page height the script below gives is never smaller than the window height.
function dimension2(){
  var test1 = document.body.scrollHeight;
  var test2 = document.body.offsetHeight
  if (test1 > test2) // all but Explorer Mac
  {
    x = document.body.scrollWidth;
    y = document.body.scrollHeight;
  }
  else // Explorer Mac;
       //would also work in Explorer 6 Strict, Mozilla and Safari
  {
    x = document.body.offsetWidth;
    y = document.body.offsetHeight;
  }
}

function dimen(){
  dimension();
}

function enmedio(id){
  dimen();
  x1 = document.getElementById(id).offsetWidth;
  y1 = document.getElementById(id).offsetHeight;

if(id=='alertas'){
 	 //alert(x1+' '+y1);
	/*if(y1>285){
		y1 = 285;
	} */
 }	
if(id=="avisos"){
	y1 = "300";
}
  var xfinal = ((x/2)-(x1/2))+(x0);
  var yfinal = ((y/2)-(y1/2))+(y0);
  //alert((y/2)+"-"+(y1/2)+"+"+(y0)+"="+yfinal);
  document.getElementById(id).style.left = xfinal;
  if(yfinal<0){
  	yfinal = 10;
  }
  //alert(id+"..."+y+".."+y1+".."+yfinal);	
  document.getElementById(id).style.top = yfinal;
 
}

/*function enmedio(id){
  dimen();
  //dimension(id);
  x1 = document.getElementById(id).offsetWidth;
  y1 = document.getElementById(id).offsetHeight;
  //alert("x1="+x1+" y1="+y1);
  var xfinal = ((x/2)-(x1/2))+(x0);
  var yfinal = ((y/2)-(y1/2))+(y0);
  //alert((y/2)+"-"+(y1/2)+"+"+(y0)+"="+yfinal);
  document.getElementById(id).style.left = xfinal;
  document.getElementById(id).style.top = yfinal;
}*/

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
	  /*
      try{
      //alert(obj.id);
      if(empiezapor("busca",obj.id)==1){//socorro
        return curleft;
      }
      }catch(e){}
	  */
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
     /*
	 try{
      if(empiezapor("busca",obj.id)==1){
        return curleft;
      }
      }catch(e){}
		*/
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


  function posiframe(idaux){
	  document.getElementById("tapador").style.visibility ="visible";
      document.getElementById("tapador").style.left = findPosX(idaux);
      document.getElementById("tapador").style.top = findPosY(idaux);
      document.getElementById("tapador").style.width = idaux.offsetWidth;
      document.getElementById("tapador").style.height = idaux.offsetHeight;
  }
  
  function posiframeesconde(){
	  document.getElementById("tapador").style.visibility ="hidden";
      document.getElementById("tapador").style.left = 0;
      document.getElementById("tapador").style.top = 0;
      document.getElementById("tapador").style.height = 1;
      document.getElementById("tapador").style.width = 1;	  
  }


function posiframeId(cual){
   if(document.getElementById(cual).style.visibility =="visible"){
      document.getElementById("tapador").style.visibility = "visible";
      document.getElementById("tapador").style.left = findPosX(document.getElementById(cual));
      document.getElementById("tapador").style.top = findPosY(document.getElementById(cual));
      document.getElementById("tapador").style.width = document.getElementById(cual).offsetWidth;//300;
      document.getElementById("tapador").style.height = document.getElementById(cual).offsetHeight;//300;
   }else{
      //alert("me escondo");
      document.getElementById("tapador").style.left = 0;
      document.getElementById("tapador").style.top = 0;
      document.getElementById("tapador").style.height = 1;
      document.getElementById("tapador").style.width = 1;	  
  }
}

function tamanotapador2(cual){
	document.getElementById(cual).style.width = x+x0; 
	document.getElementById(cual).style.height = y+y0; 
}

function colocaalerta(alerta){
	if (document.getElementById(alerta).style.visibility =="visible"){
		dimensionscroll();
		document.getElementById("tapador").style.visibility = "visible";
		document.getElementById("tapador2").style.visibility = "visible";
		enmedio(alerta);
		//alert('posiframe');
		posiframeId(alerta);
		tamanotapador2("tapador2");
	}
}

function escondealerta(alerta){
	//alert('escondealerta');
   try{ 
      //alert(alerta+"..escondiendo");
      if(document.getElementById(alerta).style.visibility =="visible"){
        document.getElementById(alerta).style.visibility = "hidden";
        var todo = true;
        try{
          if(document.getElementById('divcargando').style.visibility == "visible" || document.getElementById('confi').style.visibility == "visible" || document.getElementById('alertas').style.visibility == "visible" || document.getElementById('divdetalle').style.visibility == "visible" ){
            //alert('alertaviva');
            todo = false;
          }
        }catch(e){}
        if(todo){
          document.getElementById("tapador").style.height = 1;
          document.getElementById("tapador").style.width = 1;	  
          document.getElementById("tapador2").style.height = 1;
          document.getElementById("tapador2").style.width = 1;	 
          document.getElementById("tapador").style.visibility = "hidden";
          document.getElementById("tapador2").style.visibility = "hidden";
        }
     }
    }catch(e){
      //alert('error esconde');
    }
}

function escondealerta_viejo(alerta){
 try{ 
	document.getElementById(alerta).style.visibility = "hidden";
    document.getElementById("tapador").style.height = 1;
    document.getElementById("tapador").style.width = 1;	  
    document.getElementById("tapador2").style.height = 1;
    document.getElementById("tapador2").style.width = 1;	 
    document.getElementById("tapador").style.visibility = "hidden";
    document.getElementById("tapador2").style.visibility = "hidden";
    }catch(e){
      //alert('error esconde');
    }
}
function ensenaalerta(alerta){
	//deberia borrar todas antes salvo la grande.
  try{
    document.getElementById("divprevio").style.visibility = "hidden";
    }catch(e){}
	try{
    document.getElementById(alerta).style.visibility = "visible";
    colocaalerta(alerta);
	}catch(e){}
  //reposiciona(alerta);
}

  function ensenatodo(){
    //alert("enseno");
  	//  try{document.getElementById("divtotus").style.display = "block";}catch(e){alert("1-"+e);}
    //try{document.getElementById("divprevio").style.display = "none";}catch(e){alert("2-"+e);}
    ensenabody();
  }

function repos(){
  //alert("..repos...");
  escondealerta("divcargando");
  //alert("repos...2");
  escondealerta("divdetalle");
  //alert("repos...3");
  escondealerta('alertas');
  //alert("repos...4");
  try{
    //alert("voy a repos");
    contenido = document.getElementById("diverror").innerHTML;
    anchocontenido = document.getElementById("diverror").offsetWidth;
    altocontenido = document.getElementById("diverror").offsetHeight;
	if(altocontenido >300){
		altocontenido = "300px";
	}
    //alert("contenido error "+contenido);
    if(contenido.length >0){
     pintaalerta(contenido,anchocontenido,altocontenido); 
    }
  }catch(e){
    //alert("no error"+e);
  }
  try{
    contenido = document.getElementById("divconfirm").innerHTML;
    anchocontenido = document.getElementById("divconfirm").offsetWidth;
    altocontenido = document.getElementById("divconfirm").offsetHeight;
    if(contenido.length >0){
     pintaconfirm(contenido,anchocontenido,altocontenido); 
    }
  }catch(e){}
  try{
  //alert("voy a aviso...");
  contenido = document.getElementById("divaviso").innerHTML;
  //alert("es contenido..");
  anchocontenido = document.getElementById("divaviso").style.width;//"545px";//document.getElementById("divaviso").offsetWidth;
  //altocontenido = "z345px";//
  altocontenido =document.getElementById("divaviso").style.height;//"345px";//document.getElementById("divaviso").offsetHeight;
	  if(contenido.length >0){
		//alert('esaviso');
		pintaaviso(contenido,anchocontenido,altocontenido); 
		//parent.fContenido.pintaalerta(contenido,anchocontenido,altocontenido); 
	  }
  }catch(e){
	  
	 }

  try{
    contenido = document.getElementById("divdetalle").innerHTML;
    anchocontenido = "545px";//document.getElementById("divdetalle").offsetWidth;
    altocontenido = document.getElementById("divdetalle").offsetHeight;
	 txtitulo = "";//"MADRID - SALAMANCA (BLANCOSANCHO)-14:30";
   	if(altocontenido >300){
		altocontenido = "300px";
	}
	if(contenido.length >0){
      //alert("voy a pintar");
    //alert(document.getElementById("divdetalle").offsetWidth);
	  	pintar("alertas",contenido,anchocontenido,altocontenido,txtitulo)	 
    }
  }catch(e){
    //alert(e);
  }
  //document.getElementById("resajax2").innerHTML=" ";
  //document.getElementById("resajax").innerHTML=" ";  
  //alert("actualizando textos");
  //makerequest2("../textos.jsp","resajax",document.forms["textos"]);
}




function reposiciona(obj){ //NO SE USA
	var elque = document.getElementById(obj);
	elque.style.left = "50%";
	elque.style.top = "50%";
	var elqueleft = elque.offsetLeft;
	var elquetop = elque.offsetTop;
	var elquewidth = elque.offsetWidth;
	var elqueheight = elque.offsetHeight;
	elque.style.left = (elqueleft - elquewidth/2)+"px";//elque.offsetWidth/2;
	elque.style.top = (elquetop - elqueheight/2)+"px";//elque.offsetHeight/2;
	//alert(elque+" "+elqueleft+" "+elquetop+" "+elquewidth+" "+elqueheight);
}

function pintaalerta(contenido,anchocontenido,altocontenido){
 	escondealerta('alertas');
  	escondealerta('confi');
	try{escondealerta('divcargando');}catch(e){}
	//document.getElementById("alertas").style.width = anchocontenido;
	//document.getElementById("alertas").style.height = altocontenido+46;
	document.getElementById("alertas-texto").innerHTML = contenido;
	ensenaalerta('alertas');
}

function pintaconfirm(contenido,anchocontenido,altocontenido){
 	escondealerta('alertas');
  	escondealerta('confi');
	try{escondealerta('divcargando');}catch(e){}
	//document.getElementById("alertas").style.width = anchocontenido;
	//document.getElementById("alertas").style.height = altocontenido+46;
	document.getElementById("confi-texto").innerHTML = contenido;
	ensenaalerta('confi');
}

function pintaaviso(contenido,anchocontenido,altocontenido){
	//alert ("pintaaviso "+anchocontenido);
	//var anchocontenido2 = "600px";
	escondealerta('avisos');
	document.getElementById("avisos").style.width = anchocontenido;
	document.getElementById("avisos").style.height = altocontenido;
	document.getElementById("avisos-texto").innerHTML = contenido;
	//document.getElementById("avisos-texto").style.background-color = "#cc3300";
	ensenaalerta('avisos');
}

function pintadetalle(contenido,anchocontenido,altocontenido){
	
	escondealerta('divdetalles');
	//alert("voy a pintar detalle");
  document.getElementById("divdetalles").style.width = anchocontenido;
	document.getElementById("divdetalles").style.height = altocontenido;
	document.getElementById("divdetalles-texto").innerHTML = contenido;
	//document.getElementById("avisos-texto").style.background-color = "#cc3300";
	ensenaalerta('divdetalles');
}

function pintar(capa,contenido,anchocontenido,altocontenido){
	txtitulo = "";
	pintar(capa,contenido,anchocontenido,altocontenido,txtitulo)
}

function pintar(capa,contenido,anchocontenido,altocontenido,txtitulo){
	escondealerta(capa);
	textocapa = capa+"-texto";
	textotitulo = capa+"-txtitulo";
	document.getElementById(capa).style.width = anchocontenido;
	document.getElementById(capa).style.height = altocontenido;
	document.getElementById(textocapa).innerHTML = contenido;
	document.getElementById(textotitulo).innerHTML = txtitulo;
	ensenaalerta(capa);
		//alert('5');
}

function cierraover(obj){
	obj.className = "x-cierra-over";
	}
function cierraout(obj){
	obj.className = "x-cierra";
}
function cierraalerta(){
	//alert("kk");
	try{accionalerta();}catch(e){}
	escondealerta("alertas");
}

function cierraconfirm(nume){
	//alert("kk");
  if(nume==0){
    try{accionalerta();}catch(e){} 
  }else{
    try{accionconfirm();}catch(e){}
  }
	escondealerta("confi");
}

function cierraaviso(){
	escondealerta("avisos");
}

function cajaover(obj){};
function cajaout(obj){};

function anadeinput(formi,name,valor) { 
  try{
    currentElement = document.createElement("input");
    currentElement.setAttribute("type","hidden");
    currentElement.setAttribute("name",name);
    currentElement.setAttribute("id",name);
    currentElement.setAttribute("value",valor);
    formi.appendChild(currentElement);
  }catch(e){}
} 

function getIframe(aID,fr){
	//alert(fr+"..."+aID);	
 var rv = null; 
 if (parent.frames[fr].document.getElementById(aID).contentDocument){ 
	rv = parent.frames[fr].document.getElementById(aID).contentDocument; 
 } else { 
	  // IE 
	rv = parent.frames[fr].document.frames[aID].document; 
 } 
 return rv; 		
}


function getIframe2(aID){
 var rv = null; 
 if (document.getElementById(aID)){ 
	rv = document.getElementById(aID); 
 } else { 
	  // IE 
	rv = document.frames[aID]; 
 } 
 return rv; 
}

function getIframe(aID){
 var rv = null; 
 if (document.getElementById(aID).contentDocument){ 
	rv = document.getElementById(aID).contentDocument; 
 } else { 
	  // IE 
	rv = document.frames[aID].document; 
 } 
 return rv; 
}

function enviatecla(e){	
	enviatecla(e,"login");
}
function enviatecla(e,formulario){	
	if (!e){ 
    	e = window.event;
      kk=e.keyCode;
  	}else{
      kk=e.keyCode;
	}	
	if(kk==13){
		if(document.getElementById('alertas').style.visibility =="visible"){
			escondealerta('alertas');
		}else{
			try{
				enviajax(formulario);//document.forms[formulario].submit();
			}catch(e){}
		}
	}else{
		if(document.getElementById('alertas').style.visibility =="visible"){
			escondealerta('alertas');
		}
	}
}

function enviateclasubmit(e,formulario){	
	if (!e){ 
    	e = window.event;
      kk=e.keyCode;
  	}else{
      kk=e.keyCode;
	}	
	if(kk==13){
		if(document.getElementById('alertas').style.visibility =="visible"){
			escondealerta('alertas');
		}else{
			try{
        //if(formulario = "billoc"
				enviajax(formulario);
        //document.forms[formulario].submit();
			}catch(e){}
		}
	}else{
		if(document.getElementById('alertas').style.visibility =="visible"){
			escondealerta('alertas');
		}
	}
}
//
function BotonClick(j){
	document.getElementById(j).className='userpass-boton-press';
}
function BotonOver(j){
	document.getElementById(j).className='userpass-boton-over';
}
function BotonOut(j){
	document.getElementById(j).className='userpass-boton';
}
function Boton1Click(j){
	document.getElementById(j).className='boton1-press';
}
function Boton1Over(j){
	document.getElementById(j).className='boton1-over';
}
function Boton1Out(j){
	document.getElementById(j).className='boton1';
}
function Boton2Click(j){
	document.getElementById(j).className='boton2-press';
}
function Boton2Over(j){
	document.getElementById(j).className='boton2-over';
}
function Boton2Out(j){
	document.getElementById(j).className='boton2';
}
function Boton3Click(j){
	document.getElementById(j).className='boton3-press';
}
function Boton3Over(j){
	document.getElementById(j).className='boton3-over';
}
function Boton3Out(j){
	document.getElementById(j).className='boton3';
}
function Boton4Click(j){
	document.getElementById(j).className='boton4-press';
}
function Boton4Over(j){
	document.getElementById(j).className='boton4-over';
}
function Boton4Out(j){
	document.getElementById(j).className='boton4';
}
function Boton5Click(j){
	document.getElementById(j).className='boton5-press';
}
function Boton5Over(j){
	document.getElementById(j).className='boton5-over';
}
function Boton5Out(j){
	document.getElementById(j).className='boton5';
}
function Boton6Click(j){
	document.getElementById(j).className='boton6-press';
}
function Boton6Over(j){
	document.getElementById(j).className='boton6-over';
}
function Boton6Out(j){
	document.getElementById(j).className='boton6';
}
function BotonPromoClick(j){
	document.getElementById(j).className='bot-promo';
}
function BotonPromoOver(j){
	document.getElementById(j).className='bot-promo-over';
}
function BotonPromoOut(j){
	document.getElementById(j).className='bot-promo';
}
function navega(j,i){
	contenido.location.href = i;
}
function ponfoco(donde){
	try{
	document.getElementById(donde).focus();
	}catch(e){}
}
function cambiaestilo(cual,como){
	document.getElementById(cual).className=como;
}
function ensenadiv(cual){
	//document.getElementById(cual).style.visibility='visible';
	document.getElementById(cual).style.display='block';
}
function ocultadiv(cual){
	//document.getElementById(cual).style.visibility='hidden';
	document.getElementById(cual).style.display='none';
}

function lanzatextos0(servidor){
//alert('voy a lanzar');
//try{ensenaalerta("divcargando");}catch(e){}
lanzatextos("fContenido",servidor);
} 

function lanzatextos(a,b){
  //alert("lanzotexos.."+a+".."+b);
	//try{ensenaalerta("divcargando");}catch(e){}
	var esteframe=a;//"fContenido";
	var lugaframe ="fAux";
	//alert(esteframe);
	lugaframe+=esteframe.substring(1);	
	if(lugaframe.substring(0,7)=="fAuxAux"){
		lugaframe="fAuxPie";
	}
	if(esteframe=="servicios_iframe"){
		lugaframe="fAuxIframe";
	}
	//document.forms["textos"].target = lugaframe;
  //alert(lugaframe);
	document.forms["textos"].target = lugaframe;
	anadeinput(document.forms["textos"],"elframe",esteframe); 
	anadeinput(document.forms["textos"],"nompag",b); 
	var lista = document.getElementsByTagName('span');
	for(i=0;i<lista.length;i++){
	  if(document.getElementById("v100"+i)){
		 
		document.getElementById("v100"+i).value=lista[i].id;
	  }else{
		anadeinput(document.forms["textos"],("v100"+i),lista[i].id); 
	  }
	}

	var lista3 = document.getElementsByTagName('select');
	for(i=0;i<lista3.length;i++){
	  if(document.getElementById("v300"+i)){
		document.getElementById("v300"+i).value="S#"+lista3[i].id;
	  }else{
		anadeinput(document.forms["textos"],("v300"+i),"S#"+lista3[i].id); 
	  }
	}
	
	var lista2 = document.getElementsByTagName('td');
	//alert(lista2);
	for(i=0;i<lista2.length;i++){
	 if(lista2[i].id.length>0){	
		  if(document.getElementById("v20"+i)){
			document.getElementById("v20"+i).value=lista2[i].id;
			//alert(lista2[i].id);
		  }else{
			anadeinput(document.forms["textos"],("v20"+i),lista2[i].id); 
		  }
	  }
	}
	var lista4 = document.getElementsByTagName('txt');
	for(i=0;i<lista4.length;i++){
	 if(lista4[i].id.length>0){	
		  if(document.getElementById("v40"+i)){
			document.getElementById("v40"+i).value=lista4[i].id;
			//alert(lista2[i].id);
		  }else{
			anadeinput(document.forms["textos"],("v40"+i),lista4[i].id); 
		  }
	  }
	}
	document.forms["textos"].method="post";
	if(esteframe=="servicios_iframe"){
    //alert("enviando dos");
    enviajax2("textos");
  }else{
    //alert("enviando uno");
    enviajax("textos");
  }
}

function enviaform(obj){
  ensenaalerta("divcargando");
  document.forms[obj].submit();
}

function enviaform2(obj,alerta){
  ensenaalerta(alerta);
  document.forms[obj].submit();
}

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_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_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_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];}
}

//


	//Crear una variable de Bool para comprobar si existe Internet Explorer.
  var xmlhttp = false;
  function inicio_ajax(){
    //Comprobar si se está usando IE.
    //alert("incio un ajaxjagg");
    ensenaalerta("divcargando");
    document.getElementById("resajax2").innerHTML=" ";
    document.getElementById("resajax").innerHTML = "";//"xxxxxxxxxxxxxxxxxxxx";
    try {
      //Si la versión de javascript es superior a la 5.
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      //Si no, utilizar el tradicional objeto ActiveX.
      try {
        //Si se está usando Microsoft.
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        //En caso contrario no debe estar usándose IE.
        xmlhttp = false;
      }
    }
    //alert('ajax2');
    //Si no estamos usando IE, crear una versión javascript del objeto.
    if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
      xmlhttp = new XMLHttpRequest();
    }
    //alert(xmlhttp);
	}
  
 
  
  function anadeinput2(formi,name,valor) { 
  try{
    currentElement = document.createElement("input");
    currentElement.setAttribute("type","text");
    currentElement.setAttribute("name",name);
    //currentElement.setAttribute("id",name);
    currentElement.setAttribute("value",name+"..."+valor.innerHTML);
    formi.appendChild(currentElement);
    //alert("bien");
  }catch(e){
    //alert("mal.."+e);
  }
} 

function makerequest(serverPage, objID) {
    escondealerta("divcargando");
    inicio_ajax();  
    //alert(serverPage+".."+objID);
	var obj = document.getElementById(objID);
	xmlhttp.open("GET", serverPage);
    //xmlhttp.open("POST", serverPage);
	xmlhttp.onreadystatechange = function() {
		if ((xmlhttp.readyState == 4 ) && xmlhttp.status == 200) {
			var vajax = xmlhttp.responseText;   
			//alert(vajax);
			if(SetContainerHTML(objID,vajax, true)){ 
				escondealerta("divcargando");  
				//alert(serverPage);
				if(serverPage=="textos.jsp"){
			   //atextos();
				}else{	
					atextos();
				}
				//repos();
			} 
		}else if(xmlhttp.readyState == 4){
			escondealerta("divcargando");
			//alert('error');
		}
	}
	xmlhttp.send(null);
}
  
function llamapie() {
    var xmlhttpcab = false;
    try {
      //Si la versión de javascript es superior a la 5.
      xmlhttpcab = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      //Si no, utilizar el tradicional objeto ActiveX.
      try {
        //Si se está usando Microsoft.
        xmlhttpcab = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        //En caso contrario no debe estar usándose IE.
        xmlhttpcab = false;
      }
    }
    //Si no estamos usando IE, crear una versión javascript del objeto.
    if (!xmlhttpcab && typeof XMLHttpRequest != 'undefined') {
      xmlhttpcab = new XMLHttpRequest();
    }
    //alert(xmlhttpcab);
    serverPage = "../archivos/pie.html";//"http://www.avanza.vsf.es/web/archivos/cabecera.html";
    objID= "divcabe";
		var obj = document.getElementById(objID);
		xmlhttpcab.open("GET", serverPage);
    //xmlhttp.open("POST", serverPage);
		xmlhttpcab.onreadystatechange = function() {
		if ((xmlhttpcab.readyState == 4 ) && xmlhttpcab.status == 200) {
         document.getElementById("divpie").innerHTML =  xmlhttpcab.responseText;
			}else if(xmlhttp.readyState == 4){
        //escondealerta("divcargando");
        //alert('error');
      }
		}
		xmlhttpcab.send(null);
	}

  
  function llamacabecera() {
    var xmlhttpcab = false;
    try {
      //Si la versión de javascript es superior a la 5.
      xmlhttpcab = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      //Si no, utilizar el tradicional objeto ActiveX.
      try {
        //Si se está usando Microsoft.
        xmlhttpcab = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        //En caso contrario no debe estar usándose IE.
        xmlhttpcab = false;
      }
    }
    //Si no estamos usando IE, crear una versión javascript del objeto.
    if (!xmlhttpcab && typeof XMLHttpRequest != 'undefined') {
      xmlhttpcab = new XMLHttpRequest();
    }
    //alert(xmlhttpcab);
    serverPage = "../archivos/cabecera.html";//"http://www.avanza.vsf.es/web/archivos/cabecera.html";
    objID= "divcabe";
		var obj = document.getElementById(objID);
		xmlhttpcab.open("GET", serverPage);
    //xmlhttp.open("POST", serverPage);
		xmlhttpcab.onreadystatechange = function() {
		if ((xmlhttpcab.readyState == 4 ) && xmlhttpcab.status == 200) {
         document.getElementById("divcabecera").innerHTML =  xmlhttpcab.responseText;
         llamapie();
			}else if(xmlhttp.readyState == 4){
        //escondealerta("divcargando");
        //alert('error');
      }
		}
		xmlhttpcab.send(null);
	}
 
function getForm(formID){
  var cadenas = "";
  var horita = new Date() 
  horita = horita.getTime();
  for(i=0;i<formID.length;i++){
    var tmpnombre = formID.elements[i].name;
    if(formID.elements[i].type == "radio"){     
      if(formID.elements[i].checked){
        var tmpcad = "";
        tmpcad = ""+tmpnombre+"="+formID.elements[i].value+"&";
        cadenas+=tmpcad;//formID.elements[i].value;
  
        //alert(tmpcad);
      }
    }else{
      cadenas+=""+tmpnombre+"="+formID.elements[i].value+"&";
    }    
  }
  cadenas+="h="+horita;
  return cadenas;
  
}  
 
 
	function SetContainerHTML(id,html,processScripts){
		var mydiv = document.getElementById(id);
		mydiv.innerHTML = html;
    
		if(processScripts!=false){
			if(html.indexOf("<html>")==-1 && html.indexOf("<body>")==-1){
        html = "<html><body>"+html+"</body></html>";
      }
      //alert('proceso script');
      mydiv.innerHTML = "<script>function despues(){}</script>";
      mydiv.innerHTML += html;
      var elementos = mydiv.getElementsByTagName('script');
			//alert(elementos.length);
      for(i=0;i<elementos.length;i++) {
        
				var elemento = elementos[i];
				
        nuevoScript = document.createElement('script');
        
        texto = nuevoScript.text;
        if(texto.length>0){
          //alert(nuevoScript.text);
        }
				nuevoScript.text = elemento.innerHTML;
				nuevoScript.type = 'text/javascript';
				if(elemento.src!=null && elemento.src.length>0)
          nuevoScript.src = elemento.src;
				elemento.parentNode.replaceChild(nuevoScript,elemento);
			}
		}
    
    escondealerta("divcargando");
    if(processScripts!=false){
      try{
        //alert('voy a despues');
        if(ultimoServerPage.indexOf("textos.jsp")!=true){
          despues();
          despues2();
        }

      }catch(e){}
      }
      return true;
    }
 
   function inicio_ajax2(){
    //alert("inicio jagg ajax2");
    ensenaalerta("divcargando");
    parent.document.getElementById("resajax").innerHTML = "";//"xxxxxxxxxxxxxxxxxxxx";
	parent.document.getElementById("resajax2").innerHTML = "";
    try {
       xmlhttp2 = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp2 = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp2 = false;
      }
    }
    if (!xmlhttp2 && typeof XMLHttpRequest != 'undefined') {
      xmlhttp2 = new XMLHttpRequest();
    }
	}
   
function capaenviajax(IDform,capa){
 //alert(document.getElementById(IDform).action);
  //alert(IDform);
  if(!xmlhttp){
    //alert("estamos trabajando en ello.."+IDform);
    //alert(document.getElementById(IDform).action);
    // alert(capa);
    //  alert(document.getElementById(IDform));
    
    makerequest2(document.getElementById(IDform).action,capa,document.getElementById(IDform));
  }else{
    makerequestAux(document.getElementById(IDform).action,capa,document.getElementById(IDform));
  }
} 
  
function enviajax(IDform){
  capaenviajax(IDform,"resajax");
}  

function notxt(){
  refrescatxt = false;
}


function sitxt(){
  refrescatxt = true;
}

var bloquea = false;

var ultimoServerPage = "";

function makerequest2(serverPage,objID,formID){	// envio de formulario por ajax
  //alert(serverPage);
  if(1==2){//if(serverPage == ultimoServerPage){
  
  }else{
  ultimoServerPage = serverPage;
  refrescatxt = true;
  //escondealerta("divcargando");
  inicio_ajax();
	var obj = document.getElementById(objID);
	xmlhttp.open("POST", serverPage);//,false);
	xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
  //xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=iso-8859-9");charset=ISO-8859-1'); 
  //alert(formID);
  var cadenas = getForm(formID);
	xmlhttp.onreadystatechange = function() {
		 try{escondealerta("divcargando");}catch(e){alert(e);}
    if ((xmlhttp.readyState == 4 ) && xmlhttp.status == 200) {
      var vajax = xmlhttp.responseText; 
      if(SetContainerHTML(objID,vajax, true)){ //metodo para ejecutar scripts de la pagina llamada con ajax
      xmlhttp = false;
      if(serverPage.indexOf("textos")>-1 || serverPage.indexOf("zona")>-1 || serverPage.indexOf("mataplaza")>-1 || serverPage.indexOf("pisaplaza")>-1 || serverPage.indexOf("muestraOperacionesTBA")>-1){
        refrescatxt = false;
        	//setInterval(verida(),15000);
      }
      if(serverPage.indexOf("detalles")>-1){
        //referescatxt = true;
      }
        if(serverPage.indexOf("textos.jsp")>-1){
          //alert('es texto me corto');
		    try{newdespues();}catch(e){}
        }else{
          if(refrescatxt){
            //alert("atextosvoy");
            if(bloquea){
            }else{
            //alert("llamatextos");
			atextos();
            }
          }else{
            escondealerta("divcargando");
		    
          }
        }
      }//if para esperar a que se ejecute setcontainerhtml
    }else if(xmlhttp.readyState == 4){
			if (xmlhttp.status != 0)
        	//alert("error..."+xmlhttp.status+".."+serverPage);
          if(xmlhttp.status == 12030 ){
			 alert("error..."+xmlhttp.status+"..reintentar");
			xmlhttp = null;  
            makerequest2(serverPage,objID,formID);
          }else{
			 alert("error..."+xmlhttp.status+".."+serverPage);
			 xmlhttp = null;
            repos();
          }        
    }else{
		//alert(xmlhttp.readyState);
		}
	}
	xmlhttp.send(cadenas);
}
}

function enviajax2(IDform){
  //alert(document.getElementById(IDform).action);
  makerequestAux(document.getElementById(IDform).action,"resajax2",document.getElementById(IDform));
}  

function makerequestAux(serverPage,objID,formID){	// envio de formulario por ajax
  parent.escondealerta("divcargando");
  inicio_ajax2();
	var obj = document.getElementById(objID);
  //alert("la que usamos es..."+xmlhttp2);
	xmlhttp2.open("POST", serverPage);//,false);
	xmlhttp2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  var cadenas = getForm(formID);
	xmlhttp2.onreadystatechange = function() {
    if ((xmlhttp2.readyState == 4 ) && xmlhttp2.status == 200) {
      var vajax = xmlhttp2.responseText; 
      if(SetContainerHTML2(objID,vajax, true)){ //metodo para ejecutar scripts de la pagina llamada con ajax
      //parent.ensenatodo();
      if(serverPage.indexOf("booki")>-1){
          atextos();
        }
      }
    }else if(xmlhttp2.readyState == 4){
        	alert("error.aux.."+xmlhttp2.status);
          xmlhttp2 = null;
          parent.repos();        
    }
	}
	xmlhttp2.send(cadenas);
}

function SetContainerHTML2(id,html,processScripts){
		var mydiv = parent.document.getElementById(id);
		mydiv.innerHTML = html;
		if(processScripts!=false){
			var elementos = mydiv.getElementsByTagName('script');
			for(i=0;i<elementos.length;i++) {
				var elemento = elementos[i];
				nuevoScript = document.createElement('script');
        texto = nuevoScript.text;
        if(texto.length>0){
          //alert(nuevoScript.text);
        }
				nuevoScript.text = elemento.innerHTML;
				nuevoScript.type = 'text/javascript';
				if(elemento.src!=null && elemento.src.length>0)
          nuevoScript.src = elemento.src;
				elemento.parentNode.replaceChild(nuevoScript,elemento);
			}
		}
    parent.document.getElementById("resajax").innerHTML="  ";
    parent.escondealerta("divcargando");
    return true;
    }
	/**/
	
  function replace(texto,s1,s2){
    return texto.split(s1).join(s2);
  } 
  

  
	