var defaultEmptyOK = false;
var xmlHttpC = getHTTPObject();

function lgl(x)
{
    var b=document.getElementById('lgdv');
    if(b)
    {
        b.innerText=b.innerText+x+'\n';
    }
    

}

function accionForm(nom,id,msgConf)
{

    if(!msgConf||(msgConf&&confirm(msgConf)))
    {
    document.formulario['accion'].value=nom;
 if(id)document.formulario['idTemp'].value=id;
 
 if(document.formulario['envio'])document.formulario['envio'].value=1;
    document.formulario.submit();
    }
}

function rt(txt)
{
	if(!txt||txt==null)return false;
        if(window.print)
        {
	txtl=txt.toLowerCase();
	if(txtl.indexOf("falkag")!=-1||txtl.indexOf("doubleclick")!=-1)return false;
	
	fdw(txt);
        }
}

function d(x)
{
	document.write(x);
}
function sa()
{
	d('<');d('a');d(' ');d('h');d('r');d('e');d('f');d('=');d('"');d('m');d('a');d('i');d('l');d('t');d('o');d(':');
}

function dl()
{
	d('@');d('d');d('a');d('t');d('o');d('c');d('a');d('p');d('i');d('t');d('a');d('l');d('.');d('c');d('o');d('m');
	
}

function isFloat(theNum) {
	theNum=theNum.replace(',','.');
	
var dotPos = theNum.indexOf(".");
if(dotPos==-1) dotPos= theNum.indexOf(",");
if(dotPos!=-1)
{
var dTemp=theNum.substring((dotPos+1),theNum.length);
if(dTemp.length==1)theNum+="0";
}

if(dotPos==-1)
{
	theNum+=".00";
	dotPos = theNum.indexOf(".");
	if(dotPos==-1) dotPos= theNum.indexOf(",");
}
//alert(theNum);


var theLen = theNum.length;
var thePos = theLen - 3;
if(thePos!=dotPos)thePos=theLen-4;


var comaPos = theNum.indexOf(",");
var isNum = (isNaN(theNum)) ? false:true;
var isDot = ((dotPos != -1) ? true:((comaPos != -1) ? true:false));
var isAt = (dotPos == thePos) ? true:false;
var isOne = ( (theNum.indexOf(".",dotPos+1) == -1) ? true:( (theNum.indexOf(",",comaPos+1) == -1) ? true:false ) );

if((isNum) && (isDot) && (isAt) && (isOne)) {
return true;
}

else {
return false;
}
}

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

//------------------------------------------------------------------------------------------------------

function isWhitespace (s)
{   var i;
    var whitespace = " \t\n\r";
    if (isEmpty(s)) return true;
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        // si el caracter en que estoy no aparece en whitespace,
        // entonces retornar falso
        if (whitespace.indexOf(c) == -1) return false;
    }
    return true;
}

function isLetter (c)
{   return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) );
}

//------------------------------------------------------------------------------------------------------

function isDigit (c)
{   return ((c >= "0") && (c <= "9"));
}


function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}


function validarFecha(x)
{

   if (x.value != "")
   {
      var DayArray =new Array(31,28,31,30,31,30,31,31,30,31,30,31);
      var MonthArray = new Array("01","02","03","04","05","06","07","08","09","10","11","12");
      var thisYear = null;
      var thisMon = null;
      var thisDay = null;
      var today = null;
      inpDate = x.value;
      thisDay = inpDate.substr(0,2);
      thisMonth = inpDate.substr(3,2);
      thisYear = inpDate.substr(6,4);
      var filter=/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/;
      if (! filter.test(inpDate))
      {
         alert("El formato debe ser DD/MM/AAAA");
         document.Solicitud_srv.formulario_ok.value=0;
         x.focus();
         return false;
      }
      var filter=/01|02|03|04|05|06|07|08|09|10|11|12/ ;
      if (! filter.test(thisMonth))
      {
         alert("Introduzca un mes correcto");
         document.Solicitud_srv.formulario_ok.value=0;
         x.focus();
         return false;
      }
      N=Number(thisYear);
      if ( ( N%4==0 && N%100 !=0 ) || ( N%400==0 ) )
      {
         DayArray[1]=29;
      }
      for(var ctr=0; ctr<=11; ctr++)
      {
         if (MonthArray[ctr]==thisMonth)
         {
            if (!(thisDay<= DayArray[ctr] && thisDay >0))
            {
               alert("Introduzca un día correcto");
               document.Solicitud_srv.formulario_ok.value=0;
               x.focus();
               return false;
            }
         }
      }
   }

return true;
}


function validarNIF(x)
{
//	alert('NIF');	
	if(x==null)return false;
	
	var primerCaracter=x.charAt(0);
	
	if(primerCaracter=='0')x=x.substring(1,x.length);
	
	var ultimoCaracter=x.charAt(x.length-1);
	
	
	
	var codigo="";
	var letra="";
	
	if(isDigit(primerCaracter)&&isLetter(ultimoCaracter))
	{
		codigo=x.substring(0,x.length-1);
		letra=ultimoCaracter;
	}
	if(isDigit(ultimoCaracter)&&isLetter(primerCaracter))
	{
		codigo=x.substring(1,x.length);
		letra=primerCaracter;
	}	
	
	if(!isInteger(codigo))return false;
	
	
	var arrayLetras="TRWAGMYFPDXBNJZSQVHLCKE";
	var posDestino=eval(codigo)%23;
	
	
	
	var z=null;
	if(posDestino!=null)z=arrayLetras.charAt(posDestino);
	
	if(z!=null&&z==letra) return true;
	else 
	{
		return false;
		}

}

//------------------------------------------------------------------------------------------------------

function validarCIF(x)
{
	
	
	if(x==null)return false;
	var result;
	var cadena="XP";
	var suma=0;
	x=" "+x.toUpperCase();
	
	if(x.length==10)
	{
		suma=eval(x.charAt(3))+eval(x.charAt(5))+eval(x.charAt(7));
		var cont=1;
		for(cont=1;cont<=4;cont++)
		{
			//alert('Caso X(2x)='+x.charAt(2*cont));
			var temporal=2*eval(x.charAt(2*cont));
			//alert('Caso A S='+suma+' T='+temporal);
			suma=suma+ (    temporal%10        )+Math.floor( temporal/10);
		}
		
		if(cadena.indexOf(x.charAt(1))!=-1)
		{
			//alert('Caso 1 Comp '+x.charAt(9)+' / (Chr) '+64+(10-(suma%10)));
			result=( x.charAt(9)==Chr(64+(10-(suma%10))));
		}
		else
		{
			var datoComparar=(10-(suma%10));
			//alert('Caso 2 Comp eval '+x.charAt(9)+' / '+datoComparar);
			if(isDigit(x.charAt(9)))
			{
			if(eval(x.charAt(9))==0&&datoComparar==10)datoComparar=0;
			
			
			if(isDigit(x.charAt(9)))
			{
				result= eval(x.charAt(9))	== datoComparar;
				}
			}
		else result=false;
			
				
				
		}
		
		return result;
	}
	else return false;
	
}


function abrirVentana(direccion,ancho,alto)
{
 	if(ancho==null)ancho=600;
 	if(alto==null)alto=500;
 	
	var winl =(screen.width - ancho) / 2;
	winl=winl-5;
	var wint =(screen.height - alto) / 2;
	wint=wint-5;
 	
 	
 	w=window.open(direccion,"","top="+wint+",left="+winl+",width="+ancho+",height="+alto+",scrollbars=yes,resizable=yes,location=no");
 	w.focus();
}


function actualizar()
{
document.formulario.envio.value=1;
    document.formulario.submit();
}


    function borrar(txt,id,_objeto)
    {
        if(confirm('Confirme que desea borrar el elemento seleccionado ``'+txt+'´´'))
        {
        document.formulario.idTemp.value=id;
        document.formulario.accion.value='borrar';
        document.formulario.objeto.value=_objeto;
        document.formulario.submit();
        }
    }




function cbpg(x,y)
{
    var b=document.getElementById(x);
    if(b)
    {
        var xmlHttpBP = getHTTPObject();
        var u='/A?c=p&n='+y;
        var cbp=document.createElement('div');
        var fo=document.createElement('form');
        fo.id='fbp_'+y;
        var st=document.createElement('input');
        st.id='st_'+y;
        st.type='hidden';
        st.value=0;
        fo.appendChild(st);
        b.appendChild(cbp);
        b.appendChild(fo);
        var ftmp=function()
            {
                if (xmlHttpBP.readyState != 4)    return;
                var d=xmlHttpBP.responseText;
                dbpg(cbp,d);
                st.value=d;
                lgl('resftmp='+d);
            }
            
            lgl('creada funcion: ');
      //  while(st.value!=100)
     //   {
     
            var ut=u+'&w='+(new Date).getTime();
            lgl('creada url: '+ut);
            lgl('llamada uno');
            getData(xmlHttpBP,ut,ftmp);
            lgl('llamada dos timeout');
            ut=u+'&w='+(new Date).getTime();
            setTimeout('getData(xmlHttpBP,ut,ftmp)',1000);
            lgl('llamada tres timeout');
            ut=u+'&w='+(new Date).getTime();
            setTimeout('getData(xmlHttpBP,ut,ftmp)',1000);
            lgl('llamada cuatro timeout');
            ut=u+'&w='+(new Date).getTime();
            setTimeout('getData(xmlHttpBP,ut,ftmp)',1000);
     //   }
    }
    
}

function dbpg(x,y)
{
    var b=document.getElementById(x);
    if(b)
    {
        b.innerHTML='<b>'+y+'&nbsp;&#38;</b>';
    }
}


function getStyle(el,styleProp)
{
	var x = document.getElementById(el);
	if (x.currentStyle)
		var y = x.currentStyle[styleProp];
	else if (window.getComputedStyle)
		var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(styleProp);
	return y;
}

function ldempd() {
if (xmlHttpC.readyState != 4)    return;
    $('empd').fade('hide');
    
    document.getElementById('empd').innerHTML=xmlHttpC.responseText;
    var uno=document.getElementById('gads');
    var dos=document.getElementById('gads2');
    if(uno&&dos)
    {
    uno.innerHTML=dos.innerHTML;
    dos.style.display='none';
    }
    
    $('empd').fade('in');
    
    //if(window.parent)window.parent.rmcarga('pcarga');
    
    
}

function rmel(x)
{
    var e=document.getElementById(x);
    if(e)
    {
        var p=e.parentNode;
        p.removeChild(e);
    }
}
function lockc(x)
{
var w=document.createElement('div');
w.style.display='none';
w.id='wwwt';
x.appendChild(w);

}

function addic(x,ya,dbj,h,iw)
{
//lockc(x);
var ha=120;
if(h)ha=h;
var iwa=5000;
if(iw)iwa=iw;

var ui='b.jsp?n='+ya+'&iwa='+iw;
if(dbj)ui+='&dbj=true';
x.innerHTML=x.innerHTML+'<p>&nbsp;</p><iframe id="fffb" src="'+ui+'" style="width:100%;height:'+ha+'px;z-index:5;" class="brp" border="0" frameborder="0" scrolling="no" allowtransparency></iframe>';
}
function nosc(z)
{
    if(z)
    {
    var ppa=z.parentNode.parentNode;
    var dds=z.parentNode;
    ppa.insertBefore(z,dds);
    ppa.removeChild(dds);    
    }
    
}

function osc(z)
{
    //var an=z.offsetWidth;
    //var al=z.offsetHeight;
    var ca=document.createElement('div');
    ca.setAttribute('class','bbbb');
    ca.style.className='bbbb';
    ca.id='osc1';
    var ppa=z.parentNode;
    //alert(ppa.id);
    
    ppa.insertBefore(ca,z);
    ca.appendChild(z);
    
    //z.parentNode=ca;
    //ca.style.position='absolute';
    //var tl=(document.body.clientWidth-an)/2;
    //var tt=(document.body.clientHeight-al)/2;
    //z.innerHTML+="<div style='background:#FF0000;position:inherit;top:0;left:0;width:100%;height:100%;'>&nbsp;</div>";
    //ca.style.top=tt+'px';
    //ca.style.left=tl+'px';
    //ca.style.width=an+'px';
    //ca.style.height=al+'px';
    //ca.style.border='1px solid #FF0000';
    //ca.style.width='500px';
    //ca.style.height='500px';
    //ca.style.visibility='visible';
    

    //document.body.appendChild(ca);
    
    
}

function sad()
{
var was=document.getElementById('wwwt');

if(was)return;

        var dos=document.getElementById('gads');
        if(!dos)dos=document.getElementById('gads2');
        if(dos)
        {
        dos.style.display='block';
        dos.style.visibility='visible';
        }
        /*
        var sc=document.createElement('script');
        sc.type='text/javascript';
        sc.src='http://pagead2.googlesyndication.com/pagead/show_ads.js';
        dos.appendChild(sc);
        
        dos.innerHTML+='<script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>';
        */
}


function cpmn(x)
{
       document.formulario.action='https://www.datocapital.com/PreOrder.jsp';
       document.formulario.sectorId.value=x;
       document.formulario.submit();
    
}

function rmtag(x)
{
var strInputCode=x;
strInputCode = strInputCode.replace(/&(lt|gt);/g, function (strMatch, p1){
 		 	return (p1 == "lt")? "<" : ">";
 		});
 		var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
                
                return strTagStrippedText;
}



function dumpProps(obj, parent) {
   // Go through all the properties of the passed-in object
   for (var i in obj) {
      // if a parent (2nd parameter) was passed in, then use that to
      // build the message. Message includes i (the object's property name)
      // then the object's property value on a new line
      if (parent) { var msg = parent + "." + i + "\n" + obj[i]; } else { var msg = i + "\n" + obj[i]; }
      // Display the message. If the user clicks "OK", then continue. If they
      // click "CANCEL" then quit this level of recursion
      if (!confirm(msg)) { return; }
      // If this property (i) is an object, then recursively process the object
      if (typeof obj[i] == "object") {
         if (parent) { dumpProps(obj[i], parent + "." + i); } else { dumpProps(obj[i], i); }
      }
   }
}


function getLog(obj, nivel) {
   var resultado='';
   var nvl=0;
   if(nivel)nvl=nivel;
   for (var i in obj) {
        for(j=0;j<nvl;j++)
        {
            resultado=resultado+'  ';
        }
        resultado=i+'='+obj[i];
        resultado=resultado+'\n';
        if(typeof obj[i] == "object")
        {
            resultado=resultado+getLog(obj[i],nvl+1);
        }
   }
   return resultado;
}

function odump(object, depth, max){
  depth = depth || 0;
  max = max || 2;

  if (depth > max)
    return false;

  var indent = "";
  for (var i = 0; i < depth; i++)
    indent += "  ";

  var output = "";  
  for (var key in object){
    output += "\n" + indent + key + ": ";
    switch (typeof object[key]){
      case "object": output += odump(object[key], depth + 1, max); break;
      case "function": output += "function"; break;
      case "array": output += arrayToString(object[key]);break;
      default: output += object[key]; break;        
    }
  }
  return output;
}

function arrayToString(x)
{
    var res='[';
    for(i=0;i<x.length;i++)
    {
        if(i>0)res+=',';
        res+=x[i];
    }
    res+=']';
}

function addcc(x,y)
{
    var res=''
    if(y&&y.length>0)
    {
    if(x&&x.length>0)res=x+", "+y;
    else res=y;
    }
    else res=x;
    //alert('adcc('+x+','+y+')='+res);
    return res;
}




function resizeIframe(id)
{

	var height=window.innerWidth;//Firefox
	if (document.body.clientHeight)
	{
		height=document.body.clientHeight;//IE
	}
	//resize the iframe according to the size of the
	//window (all these should be on the same line)
        if(document.getElementById(id))
        {
	document.getElementById(id).style.height=parseInt(height-document.getElementById(id).offsetTop-8)+"px";
        }
}


function getHTTPObject()
{
        var xmlhttp;

        /** Special IE only code ... */
        /*@cc_on
          @if (@_jscript_version >= 5)
              try
              {
                  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
              }
              catch (e)
              {
                  try
                  {
                      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                  }
                  catch (E)
                  {
                      xmlhttp = false;
                  }
             }
          @else
             xmlhttp = false;
        @end @*/

        /** Every other browser on the planet */
        if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
        {
            try
            {
                xmlhttp = new XMLHttpRequest();
            }
            catch (e)
            {
                xmlhttp = false;
            }
        }

        return xmlhttp;
}




function getData(xmlHttp,url,cbf)
{
lgl('getData(xmlHttp,'+url+')');
//var xmlHttp = getHTTPObject();
  //var url = "http://url/that/returns/dynamic/content";

  xmlHttp.open('GET', url, true);
  xmlHttp.onreadystatechange = cbf;
  //xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  xmlHttp.setRequestHeader('Pragma', 'no-cache');
  xmlHttp.setRequestHeader('Cache-Control', 'no-cache');

  xmlHttp.send(null);
  //return xmlHttp;
}
function gstd(x,y)
{
	new Image().src = 'https://www.datocapital.com/_std.jsp?fsx='+(new Date()).getTime()+'&did='+x+'&tpz=7&dtxt='+escape(y);
}
function gstch(y,z)
{
	new Image().src = 'https://www.datocapital.com/_std.jsp?fsx='+(new Date()).getTime()+'&did='+(z.checked?10:5)+'&tpz=13&dtxt='+escape(y);
}

function fencs(fsss,dsss,fsg,fem,msgx)
{
	var shf=$("#ifenccc");
	
  

	

	var shii=document.getElementById('_shii_fenc');
	if(!shii)
	{
		var shi=document.createElement('input');
		shi.type='hidden';
		shi.name='_shii_fenc';
		shi.value=(new Date()).getTime();
		var ssd=jQuery.trim(document.getElementById("ifenc_s").value).length;
		var vem=document.getElementById("ifenc_em").value;
		var sse=jQuery.trim(vem).length;
		//alert('ssd='+ssd+' sse='+sse+" "+$('#ifenc_s').value);
		if(fsg&&ssd==0)
		{
			alert(msgx);
			return;
		}
		if(fem&&(sse==0||vem.indexOf('@')==-1))
		{
			alert(msgx);
			return;
		}
				

		var stv=$('input[name="fenc_v"]:checked', '#ifenccc');
		var ssv=stv.val()
		if(ssv&&typeof(ssv)!='undefined'||!document.getElementById('ff_fenc_v'))
		{
		
		$('#ifenccc').append(shi);
	var srz=$('#ifenccc').serialize();
	$.post("_poll.jsp", srz,
   function(data){
     $('#enccc').html('<b style="font-size:12px;">'+fsss+'</b>');
   });	
   
  }
  else
  	{
  		if(document.getElementById('ff_fenc_v')&&(!ssv||typeof(ssv)=='undefined'))
  		{
  			alert(dsss);
  		}
  	}
		
	}
}

function ldvals(sel,nm,lla,_xval,_iz,fnc,v1,v2){
	
    $.getJSON("/lval.jsp",{fName: nm, lang:lla, xval:_xval,iz:_iz,ajax: 'true',val1:v1,val2:v2}, function(j){
      var options = '';
  		var res=new Array();    
      for (var i = 0; i < j.length; i++) {
      	var sl='';
      	
      	if(j[i].optionSelected=='true')
      	{
      		sl='selected';
      		res[res.length]=j[i].optionValue;
      	}
        options += '<option '+sl+' value="' + j[i].optionValue + '">' + j[i].optionDisplay + '</option>';
      }
      $(sel).html(options);
      if(fnc)fnc(res);
    })
    
    
  }
  
function ldvalext_s(nm,lla,fnc){
	
    $.getJSON("/lval.jsp",{fName: nm, lang:lla, ajax: 'true',w:(new Date).getTime()}, function(j){
  
      if(fnc)fnc(j);
    })
    
    
  }  
  function sss2(x)
  {
  	var z= $( window );
		z[0].location='https://www.datocapital.com/'+x;
	}
