// JavaScript Document
//cargar capa con gif animado zona Asegurados

function changeCliente(varMostrar, varProductos){

mostrar = varMostrar
productos = varProductos;

	if(counter > mostrar)
          counter = 0;
	document.getElementById("clientesIndex"+counter).style.display="none";
	
	counter++;
	if (counter == mostrar)
	
	for (x = 0; x < mostrar; x++){
	document.getElementById("clientesIndex"+ x ).style.display="inline";
	counter = 0;
	}
	if(counter2 > productos)
          counter2 = 0;
	document.getElementById("nuevosProdcutos"+ (counter2)).style.display="none";
	//alert(counter);
	counter2++;
	if (counter2 == productos)
	
	for (i = 0; i < productos; i++){
	document.getElementById("nuevosProdcutos"+ i).style.display="";
	counter2 = 0;
	}
}

function Cargando(valor,url) {
	switch (valor) {
		// el valor determina la página desde la que se solicita la acción cargando
    case 1:
	//página de producto
 	//document.formProducto.submit();	
	document.getElementById('cargando').style.display='inline';
       break
	 //página de asegurados
    case 2:
     //  document.form_asegurado.submit();	
	document.getElementById('cargando').style.display='inline';
       break
	 case 3:
    parent.document.getElementById('cargando').style.display='inline';
       break
	   case 4:
	 document.getElementById('cargando').style.display='inline';
    default:
	
    document.getElementById('cargando').style.display='inline';
	//document.location.href=url;
	} 
}
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];}
}
function MM_changeProp(objId,x,theProp,theValue) { //v9.0
  var obj = null; with (document){ if (getElementById)
  obj = getElementById(objId); }
  if (obj){
    if (theValue == true || theValue == false)
      eval("obj.style."+theProp+"="+theValue);
    else eval("obj.style."+theProp+"='"+theValue+"'");
  }
}
//Control para ampliar los Textos de las págians

function AmpliarTexto(sizeRestore, nivel){
  //Si el valor del formulario es 0. El texto se expande, y pasamos su valor a 1
  //sizeRestore es el tamaño al que queremos dejar la caja_texto en px
  //nivel es el nivel de carpetas que tiene que retroceder
 switch(nivel)
{
	case "1":
		var nivelC= "../";
	break;
	case "2":
		var nivelC= "../../";
	break;
	case "3":
		var nivelC= "../../../";
	break;
	case "4":
		var nivelC= "../../../../";
	break;
	case "5":
		var nivelC= "../../../../../";
	break;
}
	if(document.form1.f_accion.value=='0')
	{
	document.getElementById('cuerpo-texto').style.height='auto';
	document.getElementById('cuerpo-texto').style.width='700px';
	document.getElementById('btn-ampliar').style.background='url('+ nivelC +'img/leer-menos.png) no-repeat center';
	document.getElementById('btn-ampliar').style.color='#FFFFFF';
	document.getElementById('suspensivos').style.display='none';
	document.getElementById('suspensivos').style.visibility='hidden';
	document.form1.f_accion.value=1;
	 if (navigator.appName == "Netscape"){   
   		document.getElementById('cuerpo-texto').style.width='385px';
		document.getElementById('btn-ampliar').textContent="leer -"
      }else{
		  document.getElementById('cuerpo-texto').style.width='385px';
		document.getElementById('btn-ampliar').innerText="leer -"
		}
		return true;
	}else{
		 //Si el valor del formulario es 1. El texto se contrae, y pasamos su valor a 0
	document.getElementById('cuerpo-texto').style.height=sizeRestore;
	document.getElementById('btn-ampliar').style.background='url('+ nivelC +'img/leer-mas.png) no-repeat center';
	document.getElementById('btn-ampliar').style.color='#8FB618';
	document.getElementById('suspensivos').style.display='';
	document.getElementById('suspensivos').style.visibility='';
	
	document.form1.f_accion.value=0;
	 if (navigator.appName == "Netscape"){   
   
		document.getElementById('btn-ampliar').textContent="leer +"
      }else{
		document.getElementById('btn-ampliar').innerText="leer +"
		}
	
	}
}
//*************************cargar reproducciones youtube
		/*function enviarReproduccion(){
		setInterval(updateytplayerInfo, 250);
          updateytplayerInfo();
		}*/
        function updateHTML(elmId, value) {
          document.getElementById(elmId).innerHTML = value;
        }

        function setytplayerState(newState) {
		
          /*updateHTML("playerstate", newState);*/
        }

        function onYouTubePlayerReady(playerId) {
         ytplayer = document.getElementById("myytplayer");
		// while (getCurrentTime() < 0)
		 //{
         setInterval(updateytplayerInfo, 250);
		 //}
          updateytplayerInfo();
	
          /*ytplayer.addEventListener("onStateChange", "onytplayerStateChange");*/
          ytplayer.addEventListener("onError", "onPlayerError");
        }

        function onPlayerError(errorCode) {
          alert("An error occured: " + errorCode);
        }

        function onytplayerStateChange(newState) {
         /* setytplayerState(newState);*/
        }

        function updateytplayerInfo() {
         /* updateHTML("bytesloaded", getBytesLoaded());
          updateHTML("bytestotal", getBytesTotal());
          updateHTML("videoduration", getDuration());*/
          updateHTML("videotime", getCurrentTime());
		  if ( getCurrentTime() == "0" )
		{
		//solo se envía el formulario si no ha pasado la función nunca por aquí
		document.freproducciones.target = "frameInvRellenar";
		if (document.freproducciones.f_r.value != "2")
		{
		document.freproducciones.f_r.value = "1";
		document.freproducciones.action = "control_reproducciones.asp";
		document.freproducciones.method = "POST";
		document.freproducciones.submit();
		}
	
	
	document.freproducciones.f_r.value = "2";
	
		}
          /*updateHTML("startbytes", getStartBytes());
          updateHTML("volume", getVolume());*/
        }

        // functions for the api calls
        function loadNewVideo(id, startSeconds) {
         /* if (ytplayer) {
            ytplayer.loadVideoById(id, parseInt(startSeconds));
          }*/
        }

        function cueNewVideo(id, startSeconds) {
         /* if (ytplayer) {
            ytplayer.cueVideoById(id, startSeconds);
          }*/
        }

        function getCurrentTime() {
          if (ytplayer) {
            return ytplayer.getCurrentTime();
          }
        }

//*******************************************************
function crearFrame(id, url, miscroll) {
    var FrameClientes = document.createElement("IFRAME");
    FrameClientes.id = "NewIframe" + id;
    FrameClientes.src = url + "="+id;
	FrameClientes.width = "590";
	FrameClientes.height = "300";
	FrameClientes.style.border="none";
	FrameClientes.scrolling = miscroll;
    var control = document.getElementById("NewIframe"+id);
	document.getElementById("ContenedorNewIframe"+id).style.display="inline";
	//var conentedor= document.getElementById("ContenedorNewIframe"+id)
    if (control==null) {
	
    document.getElementById("ContenedorNewIframe"+id).appendChild(FrameClientes);
	//El Iframe solo se crea si no ha sido creado ya. 
    
	}
}
