var http = getXmlHttpObject();
var raiz;
var capasqs;
raiz="http://www.soulhospital.com/web/en/components/com_gesnot/";
function capacitador()
{
	window.open("http://www.soulhospital.com/web/en/index.php?option=com_gesnot","_self");
}
 function validarEntero(valor){
	 patron=/^[0-9.]*$/;
      if (isNaN(parseInt(valor))) {
            return "error"
      }else{
		if (patron.test(valor)==0)
		{
			return "error";
		}else{
            return valor
		}
      }
}
function validarEmail(valor)
{
	patron=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	if (patron.test(valor)==0)
	{
		return "error";
	}else{
		return valor
	}
}
function vaciar_combo(nome)
{
	var a;
	a=nome.options.length;
	for (i=a;i>=0;i--)
	{
		nome.options[i]=null;
	}
}
function validarFecha(valor,rec,imgfield,capimg,idioma)
{
	var a;
	var error=0;
	patron=/^[0-9.]*$/;
	a=valor.value;
	a=a.split("/")
	if (a[0]!=null)
	{
		if (a[0].length!=2)
		{
			rec.style.color='red';
			if (idioma=='english')
			{
				rec.value="Correct format MM/DD/YYYY";
			}else if(idioma=='castellano')
			{
				rec.value="Tamaño MM incorrecto, solo 2 números";
			}else{
				rec.value="Mida MM incorrecta, només 2 nombres";
			}
			capimg.style.visibility="visible";
			imgfield.src="images/cancel_f2.png";
			
			error=1;
		}else{
			if (patron.test(a[0])==0)
			{
				rec.style.color='red';
				if (idioma=='english')
				{
					rec.value="Correct format MM/DD/YYYY";
				}else if(idioma=='castellano')
				{
					rec.value="Formato MM incorrecto, solo números";
				}else{
					rec.value="Format MM incorrecte, només nombres";
				}
				
				error=1;
			}
			capimg.style.visibility="visible";
			imgfield.src="images/cancel_f2.png";
		}
	}
	if ((a[1]!=null)&&(error==0))
	{
		if (a[1].length!=2)
		{
			rec.style.color='red';
			if (idioma=='english')
			{
				rec.value="Correct format MM/DD/YYYY";
			}else if(idioma=='castellano')
			{
				rec.value="Tamaño DD incorrecto, solo 2 números";
			}else{
				rec.value="Mida DD incorrecta, només 2 nombres";
			}
			capimg.style.visibility="visible";
			imgfield.src="images/cancel_f2.png";
			error=1;
		}else{
			if (patron.test(a[1])==0)
			{
				rec.style.color='red';
				if (idioma=='english')
				{
					rec.value="Correct format MM/DD/YYYY";
				}else if(idioma=='castellano')
				{
					rec.value="Formato DD incorrecto, solo números";
				}else{
					rec.value="Format DD incorrecte, només nombres";
				}
				error=1;
				capimg.style.visibility="visible";
				imgfield.src="images/cancel_f2.png";
			}
		}
	}
	if ((a[2]!=null)&&(error==0))
	{
		if (a[2].length!=4)
		{
			rec.style.color='red';
			if (idioma=='english')
			{
				rec.value="Correct format MM/DD/YYYY";
			}else if(idioma=='castellano')
			{
				rec.value="Tamaño YYYY incorrecto, solo 4 números";
			}else{
				rec.value="Mida YYYY incorrecta, només 4 nombres";
			}
			capimg.style.visibility="visible";
			imgfield.src="images/cancel_f2.png";
			error=1;
		}else{
			if (patron.test(a[2])==0)
			{
				rec.style.color='red';
				if (idioma=='english')
				{
					rec.value="Correct format MM/DD/YYYY";
				}else if(idioma=='castellano')
				{
					rec.value="Formato YYYY incorrecto, solo números";
				}else{
					rec.value="Format YYYY incorrecte, només nombres";
				}
				capimg.style.visibility="visible";
				imgfield.src="images/cancel_f2.png";
				error=1;
			}
		}
	}
	if (error==0)
	{
		rec.style.color="green";
		rec.value="OK";
		capimg.style.visibility="visible";
		imgfield.src="images/apply_f2.png";
	}
	
}
function ws(f1,f2,idioma)
{
	window.open(f1+'?fichero='+document.getElementById(f2).value+'&idioma='+idioma,'GesNOT','width=250,height=100,toolbar=no,status=yes,menubar=no,location=no');
}
function ws2(f1,idioma)
{
	window.open(f1+'?idioma='+idioma,'GesNOT','width=400,height=400,toolbar=no,status=yes,menubar=no,location=no,scrollbar=yes');
}
function textCounter(field, countfield,imgfield,capimg,minlimit, maxlimit,idioma) 
{
	var queda;
	patron=/^[aAbBcCdDeEfFgGhHiIjJkKlLmMnNñÑoOpPqQrRsStTuUvVwWxXyYzZ123456789_-]*$/;
	if (patron.test(field.value)==0)
	{
		countfield.style.color='red';
		if (idioma=='english')
		{
			countfield.value='The username must be written without spaces';
		}else if (idioma=='castellano')
		{	
			countfield.value='No se admiten espacios';
		}else{
			countfield.value='No hi pot haver espais';
		}
		capimg.style.visibility="visible";
		imgfield.src="images/cancel_f2.png";
	}else{
		if (maxlimit!='')
		{
			if ((field.value.length > maxlimit)&&(field.value.length>=minlimit))
			{
				countfield.style.color='red';
				if (idioma=='english')
				{
					countfield.value='Maximum '+maxlimit+' characters';
				}else if (idioma=='castellano')
				{	
					countfield.value='El número máximo de carácteres es '+maxlimit;
				}else{
					countfield.value='El nombre màxim de caràcters es '+maxlimit;
				}
				field.value = field.value.substring(0, maxlimit);
				capimg.style.visibility="visible";
				imgfield.src="images/cancel_f2.png";
			}else if(field.value.length<minlimit)
			{
				queda=minlimit-field.value.length;
				countfield.style.color='red';
				if (idioma=='english')
				{
					countfield.value='Minimum '+queda+' characters';
				}else if (idioma=='castellano')
				{	
					countfield.value='El número mínimo de carácteres es '+queda;
				}else{
					countfield.value='El nombre mínim de caràcters és '+queda;
				}
				capimg.style.visibility="visible";
				imgfield.src="images/cancel_f2.png";
			}
			else{
				countfield.style.color='green';
				queda = maxlimit - field.value.length;
				if (idioma=='english')
				{
					countfield.value='Maximum '+queda+' characters';
				}else if (idioma=='castellano')
				{	
					countfield.value='El número máximo de carácteres es '+queda;
				}else{
					countfield.value='El nombre màxim de caràcters és '+queda;
				}
				capimg.style.visibility="visible";
				imgfield.src="images/apply_f2.png";
			}
		}else{
			if(field.value.length<minlimit)
			{
				queda=minlimit-field.value.length;
				countfield.style.color='red';
				if (idioma=='english')
				{
					countfield.value='Minimum '+queda+' characters';
				}else if (idioma=='castellano')
				{	
					countfield.value='El número mínimo de carácteres es '+queda;
				}else{
					countfield.value='El nombre mínim de caràcters és '+queda;
				}
				capimg.style.visibility="visible";
				imgfield.src="images/cancel_f2.png";
			}else{
				countfield.style.color='green';
				countfield.value='OK';
				capimg.style.visibility="visible";
				imgfield.src="images/apply_f2.png";
			}
		}
	}
}
function textCounter2(field, countfield,imgfield,capimg,minlimit, maxlimit,idioma) 
{
	var queda;
	if (maxlimit!='')
	{
		if ((field.value.length > maxlimit)&&(field.value.length>=minlimit))
		{
			countfield.style.color='red';
			if (idioma=='english')
			{
				countfield.value='Maximum '+maxlimit+' characters';
			}else if (idioma=='castellano')
			{	
				countfield.value='El número máximo de carácteres es '+maxlimit;
			}else{
				countfield.value='El nombre màxim de caràcters es '+maxlimit;
			}
			field.value = field.value.substring(0, maxlimit);
			capimg.style.visibility="visible";
			imgfield.src="images/cancel_f2.png";
		}else if(field.value.length<minlimit)
		{
			queda=minlimit-field.value.length;
			countfield.style.color='red';
			if (idioma=='english')
			{
				countfield.value='Minimum '+queda+' characters';
			}else if (idioma=='castellano')
			{	
				countfield.value='El número mínimo de carácteres es '+queda;
			}else{
				countfield.value='El nombre mínim de caràcters és '+queda;
			}
			capimg.style.visibility="visible";
			imgfield.src="images/cancel_f2.png";
		}
		else{
			countfield.style.color='green';
			queda = maxlimit - field.value.length;
			if (idioma=='english')
			{
				countfield.value='Maximum '+queda+' characters';
			}else if (idioma=='castellano')
			{	
				countfield.value='El número máximo de carácteres es '+queda;
			}else{
				countfield.value='El nombre màxim de caràcters és '+queda;
			}
			capimg.style.visibility="visible";
			imgfield.src="images/apply_f2.png";
		}
	}else{
		if(field.value.length<minlimit)
		{
			queda=minlimit-field.value.length;
			countfield.style.color='red';
			if (idioma=='english')
			{
				countfield.value='Minimum '+queda+' characters';
			}else if (idioma=='castellano')
			{	
				countfield.value='El número mínimo de carácteres es '+queda;
			}else{
				countfield.value='El nombre mínim de caràcters és '+queda;
			}
			capimg.style.visibility="visible";
			imgfield.src="images/cancel_f2.png";
		}else{
			countfield.style.color='green';
			countfield.value='OK';
			capimg.style.visibility="visible";
			imgfield.src="images/apply_f2.png";
		}
	}
}

function comparar_password(field,field2,field3,idioma)
{
	if (field.value!=field2.value)
	{
		field3.style.color='red';
		if (idioma=='english')
		{
			field3.value="The passwords do not match";
		}else if(idioma=='castellano')
		{	
			field3.value="Las contraseñas no coinciden";
		}else{
			field3.value="Les contrassenyes no coincideixen";
		}
		document.getElementById('cappassrep').style.visibility="visible";
		document.getElementById('passrepimg').src="images/cancel_f2.png";
	}else{
		field3.style.color='green';
		field3.value="OK";
		document.getElementById('cappassrep').style.visibility="visible";
		document.getElementById('passrepimg').src="images/apply_f2.png";
	}
}
function show(capa)
{
	document.getElementById(capa).style.visibility="visible";
}
function show1(capa)
{
	document.getElementById(capa).style.visibility="visible";
}
function hide(capa)
{
	document.getElementById(capa).style.visibility="hidden";
}
function hide1(capa)
{
	document.getElementById(capa).style.visibility="hidden";
}
function hide_comment(capa)
{
	document.getElementById(capa).style.visibility="hidden";
	document.getElementById(capa).style.width="0px";
	document.getElementById(capa).style.height="0px";
}
function lanza_ventana_registro(i)
{
	var valor;
	if (detecta_navegador()==1)
	{
		valor=400+(i*180);
	}else{
		valor=400+(i*150);
	}
	document.getElementById('ventana_votacion_nr').style.top=valor+'px';
	show('ventana_votacion_nr');
}
function set_position_ventana_reporte_noticia(capa,valor)
{
	document.getElementById(capa).style.top=valor+'px';
}
function sendQuerystring(idnobjeto,estado,capa){
	url2=raiz+"contenedor.php";
	capasqs=capa;
	
    http.open("GET", url2 + "?idnobjeto="+idnobjeto+"&estado="+estado+"&capa="+capa, true);
	http.setRequestHeader('Content-Type','text/html; charset=iso-8859-1');
    http.onreadystatechange = handleHttpResponse;
    http.send(null);
}
function handleHttpResponse(){
    if (http.readyState == 1){ //muy importante tenemos que poner el resultado en la capa corresponDIENTE
     	document.getElementById(capasqs).innerHTML = "...";
    }
    if (http.readyState == 4){
       	results=unescape(http.responseText);
            txt2=results.replace(/\+/gi," ");
        document.getElementById(capasqs).innerHTML = txt2;
    }
}
function getXmlHttpObject(){
	var objXMLHttp=null
	if (window.XMLHttpRequest)
	{
		objXMLHttp=new XMLHttpRequest()
		}
	else if (window.ActiveXObject)
	{
		objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	return objXMLHttp
}
function muestra_cajas_login()
{
	if (document.getElementById('estlogin').value=="oculto")
	{
		document.getElementById('uslogin').type="text";
		document.getElementById('paslogin').type="text";
		document.getElementById('oklogin').type="button";
		document.getElementById('estlogin').value="mostrado";
	}else{
		document.getElementById('uslogin').type="hidden";
		document.getElementById('paslogin').type="hidden";
		document.getElementById('oklogin').type="hidden";
		document.getElementById('estlogin').value="oculto";
	}
}

function mueveContador(i,fecom)
{
	if ((fecom<=60))
	{
		var a=60-fecom
		fecom++;
		horaImprimible = a
		window.document.getElementById('contador'+i).value = horaImprimible
		setTimeout("mueveContador("+i+","+fecom+")",60000)
	}else{
		document.getElementById('com'+i).style.visibility="hidden";
	}
}

function detecta_navegador()
{
	var navegador = navigator.appName
	if (navegador == "Microsoft Internet Explorer")
		return 1;
	else
		return 2;
}

function showhide_campoCom()
{
	if (document.getElementById('campoCom').style.visibility=='visible')
	{
		document.getElementById('campoCom').style.visibility='hidden';
	}else{
		document.getElementById('campoCom').style.visibility='visible';
	}
}

function llamar_rutina_comentario(i,ini)
{
	var a;
	a=document.adminForm.numcomentarios.value;
	a=parseInt(a);
	a=a+ini;
	if ((i<=a)&&(i>0))
	{
		var b;
		b=document.getElementById('com'+i).value;
		show('ventana_citar_comentario');
	}else{
		window.alert('El número de comentario no existe');
	}
}

function str_replace(busca, repla, orig)
{
	str 	= new String(orig);

	rExp	= "/"+busca+"/g";
	rExp	= eval(rExp);
	newS	= String(repla);

	str = new String(str.replace(rExp, newS));

	return str;
}

/* EXTRA SPOILER */

function mostrar_ocultar_ser(ser_idn_serie,hid,numtmp)
{
         numtmp=parseInt(numtmp);
         numtmp*=35;
         var numaux;
         if (hid=='0')
         {

            document.getElementById('ct_ser'+ser_idn_serie).style.overflow='visible';
            document.getElementById('ser_hid'+ser_idn_serie).value='1';
            numaux=document.getElementById('cont'+ser_idn_serie).value;
            numaux=parseInt(numaux);
            if ((numaux==numtmp)||(numaux==0))
            {
               document.getElementById('ct_ser'+ser_idn_serie).style.height=numtmp+'px';
               document.getElementById('cont'+ser_idn_serie).value=numtmp;
            }else{
                  document.getElementById('ct_ser'+ser_idn_serie).style.height=numaux+'px';
            }
         }else{
            document.getElementById('ct_ser'+ser_idn_serie).style.overflow='hidden';
            document.getElementById('ct_ser'+ser_idn_serie).style.height='0px';
            document.getElementById('ser_hid'+ser_idn_serie).value='0';
         }
}
function mostrar_ocultar_tmp(ser_idn_serie,tmp_idn_temporada,hid,numcap)
{
         if (numcap!='0')
         {
            numcap=parseInt(numcap);
             numcap*=20;
             var numtmp;
             numtmp=document.getElementById('cont'+ser_idn_serie).value;
             numtmp=parseInt(numtmp);
             if (hid=='0')
             {
              document.getElementById('cont'+ser_idn_serie).value=numcap+numtmp;
              document.getElementById('ct_ser'+ser_idn_serie).style.height=document.getElementById('cont'+ser_idn_serie).value+'px';
              document.getElementById('ct_tmp'+tmp_idn_temporada).style.overflow='visible';
              document.getElementById('tmp_hid'+tmp_idn_temporada).value='1';
              document.getElementById('ct_tmp'+tmp_idn_temporada).style.height=numcap+'px';
             }else{
               document.getElementById('cont'+ser_idn_serie).value=numtmp-numcap;
               document.getElementById('ct_ser'+ser_idn_serie).style.height=document.getElementById('cont'+ser_idn_serie).value+'px';
               document.getElementById('ct_tmp'+tmp_idn_temporada).style.overflow='hidden';
               document.getElementById('ct_tmp'+tmp_idn_temporada).style.height='0px';
               document.getElementById('tmp_hid'+tmp_idn_temporada).value='0';
             }
         }
}

function marcar_desmarcar(idtemp,list)
{
         var r;
         var n;
         var ic;
         if (document.getElementById("tmp"+idtemp).checked==false)
         {
               r=list.split(",");
               n=r.length;
               if (n>1)
               {
                 for (i=0;i<n;i++)
                 {
                    ic=r[i];
                    document.getElementById(idtemp+"cap"+ic).checked=false;
                 }
               }
         }else{
                r=list.split(",");
               n=r.length;
               if (n>1)
               {
                  for (i=0;i<n;i++)
                  {
                    ic=r[i];
                    document.getElementById(idtemp+"cap"+ic).checked=true;
                  }
               }
         }
}
function desmarcar_sup(idtemp)
{
         if (document.getElementById("tmp"+idtemp).checked==true)
         {
            document.getElementById("tmp"+idtemp).checked=false;
         }
}
/***********************************************
* Drag and Drop Script: © Dynamic Drive (http://www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for this script and 100s more.
***********************************************/
var dragobject={
	z: 0, x: 0, y: 0, offsetx : null, offsety : null, targetobj : null, dragapproved : 0,
	initialize:function(){
	document.onmousedown=this.drag
	document.onmouseup=function(){this.dragapproved=0}
	},
	drag:function(e){
	var evtobj=window.event? window.event : e
	this.targetobj=window.event? event.srcElement : e.target
	if (this.targetobj.className=="drag"){
	this.dragapproved=1
	if (isNaN(parseInt(this.targetobj.style.left))){this.targetobj.style.left=0}
	if (isNaN(parseInt(this.targetobj.style.top))){this.targetobj.style.top=0}
	this.offsetx=parseInt(this.targetobj.style.left)
	this.offsety=parseInt(this.targetobj.style.top)
	this.x=evtobj.clientX
	this.y=evtobj.clientY
	if (evtobj.preventDefault)
	evtobj.preventDefault()
	document.onmousemove=dragobject.moveit
	}
},
	moveit:function(e){
	var evtobj=window.event? window.event : e
		if (this.dragapproved==1)
		{
			this.targetobj.style.left=this.offsetx+evtobj.clientX-this.x+"px"
			this.targetobj.style.top=this.offsety+evtobj.clientY-this.y+"px"
			return false
		}
	}
}
dragobject.initialize()
