﻿function eliminarFileInput(divMoreUploads, fileInput, divMoreLinks){
    document.getElementById("div"+fileInput).removeChild(document.getElementById(fileInput));
    document.getElementById(divMoreUploads).removeChild(document.getElementById("div"+fileInput));
    document.getElementById(divMoreLinks).style.display = 'block';
}

function getDiv(id, width, margin, align){
    var div = document.createElement('div');
    div.id='divi'+id;
    div.style.width=width+'px';
    div.style.textAlign=align;
    div.style.marginTop=margin+'px';
    div.style.marginBottom=margin+'px';        
    return div;
}

function getInput(id, width){
    var file = document.createElement('input');
    file.type="file";
    file.id="i"+id;
    file.name="n"+id;
    file.style.width=width+"px";
    return file;
}

function getSpan(id, divMoreUp, divMoreLinks){
    var span = document.createElement('span');
    span.style.cursor='pointer';
    span.onclick=function(){eliminarFileInput(divMoreUp,'i'+id,divMoreLinks);};
    span.appendChild(document.createTextNode("Eliminar"));    
    return span;
}

function addFileInput(divMoreUp,inputFile,divMoreLinks, width) {
    files = document.getElementById(divMoreUp).getElementsByTagName("div");
    
    if (files.length<4){
        var date = new Date();
        var time = date.getTime();
        
        var file = getInput(time, width-60);        
        var div = getDiv(time, width, 1, 'left');        
        var span = getSpan(time, divMoreUp, divMoreLinks);
        span.className = 'underL';
        
        div.appendChild(file);
        div.appendChild(span);
        document.getElementById(divMoreUp).appendChild(div);

        if(files.length>=4){
            document.getElementById(divMoreLinks).style.display = 'none';
        }
    }
}

function addFileInputMovil(divMoreUp,inputFile,divMoreLinks, width) {
    files = document.getElementById(divMoreUp).getElementsByTagName("div");
    
    if (files.length<4){
        var date = new Date();
        var time = date.getTime();
        
        var file = getInput(time, width-50);
        file.className="span1_000em";        
        var div = getDiv(time, width, 1, 'left');        
        var span = getSpan(time, divMoreUp, divMoreLinks);
        span.className = 'underLHover';
        
        div.appendChild(file);
        div.appendChild(span);
        document.getElementById(divMoreUp).appendChild(div);

        if(files.length>=4){
            document.getElementById(divMoreLinks).style.display = 'none';
        }
    }
}

function blockFileInput(hidden){
    document.getElementById(hidden).style.display = "block";
}

function setBlock(divMoreLink) {                
    document.getElementById(divMoreLink).style.display = 'block';
}

/*Deshabilita botones de popup de confirmación al enviar los datos*/
/*begin*/
function deshabilitaBotones(){
    document.getElementById("ctl00_ContenidoPagina_bCAceptar").style.display='none';
    document.getElementById("ctl00_ContenidoPagina_bCCancelar").style.display='none';
    document.getElementById('divEnviandoDatos').style.display='block';
}
/*end*/

/*Contador de caracteres*/
function setMaxLength() {
	var x = document.getElementsByTagName('textarea');
	var counter = document.createElement('div');
	counter.className = 'span12';
	for (var i=0;i<x.length;i++) {
		if (x[i].getAttribute('maxlength')) {
			var counterClone = counter.cloneNode(true);
			counterClone.relatedElement = x[i];
			counterClone.innerHTML = '<span>0</span>/'+x[i].getAttribute('maxlength');
			x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
			x[i].relatedElement = counterClone.getElementsByTagName('span')[0];

			x[i].onkeyup = x[i].onchange = checkMaxLength;
			x[i].onkeyup();
		}
	}
}

function checkMaxLength(txt, cont, maxLength) {
    var currentLength = txt.value.length;

    if(txt.value.length>=maxLength){
        txt.value=txt.value.substring(0,maxLength);
    }
    document.getElementById(cont).firstChild.firstChild.nodeValue = currentLength;
}



/********** Contador para textareas de las encuestas **********/
    function creaContador(width, maxLenght){
        var array = document.getElementsByTagName("textarea");
        
        for (var i = 0; i < array.length; i++){
            var parent = array[i].parentNode;
            
            var div = document.createElement("div");
            div.style.width = width;
            div.style.textAlign = "right";
            div.className = "span12000000 paddingright20 paddingleft20";
            
            var span = document.createElement("span");
            span.appendChild(document.createTextNode(array[i].value.length));
            
            div.appendChild(span);
            div.appendChild(document.createTextNode("/"+maxLenght));
            
            parent.appendChild(div);

            array[i].relatedElement = div;
            array[i].onkeyup = array[i].onchange = actContador;
        }
    }
    
    function upCounter(obj, maxLenght){
        var currentLength = obj.value.length;
        if(obj.value.length>=maxLenght){
            obj.value=obj.value.substring(0,maxLenght);
        }
        obj.relatedElement.firstChild.firstChild.nodeValue = obj.value.length;
    }
    
/******** Fin contador para textareas de las encuestas *********/

/********** Identifica la resolución para redirigir ************/
        function redirigeInicio(){
            if (screen.width < 640){
                document.location = "Vista/Ingreso/IngresoMovil.aspx";
            }else{
                document.location = "Vista/Ingreso/Ingreso.aspx";
            }
        }
/**************************** Fin ******************************/
/***** Muestra popUp para adjuntar documentos a la solicitud en el ingreso *****/
        function showDocs(divDocs, divFondo){
            document.getElementById(divDocs).style.display = 'block';
            document.getElementById(divDocs).style.top = '40%';
            document.getElementById(divDocs).style.left = '35%';
            document.getElementById(divFondo).style.display = 'block';
            document.getElementById(divFondo).style.width = screen.width+'px';
            document.getElementById(divFondo).style.height = screen.height+'px';
        }
        function hideDocs(divDocs, divFondo){
            document.getElementById(divFondo).style.display = 'none';
            document.getElementById(divDocs).style.display = 'none';
        }
/***** Fin Muestra popUp para adjuntar documentos a la solicitud en el ingreso *****/
var count = 0;
function muestraarchivosadjuntos()
{

   var files = document.getElementById("moreUploads").getElementsByTagName("input");
    count = 0;
    for (var i=0;i<files.length;i++) 
    {    
        if (files[i].value.replace(/ /g, '') != '')
        {
            count++;    
        }    
    }   
   
   
    
   var doctxt =  document.getElementById("ctl00_ContenidoPagina_adjuntostxt");
   var doclbl = document.getElementById("ctl00_ContenidoPagina_adjuntoslbl");
   doctxt.value = count;  

   if (doclbl.firstChild != null)
    {
        doclbl.firstChild.nodeValue = count;
    
    }else{

      doclbl.appendChild(document.createTextNode(count)) ;
    }
      
}

function muestraarchivosadjuntosDerivacion()
{

   var files = document.getElementById("moreUploads").getElementsByTagName("input");
    var count = 0;
    for (var i=0;i<files.length;i++) 
    {    
        if (files[i].value.replace(/ /g, '') != '')
        {
            count++;    
        }    
    }   
   
   
    
   var doclbl = document.getElementById("ctl00_ContenidoPagina_adjuntoslbl");
   
   if (doclbl.firstChild != null)
    {
        doclbl.firstChild.nodeValue = count;
    
    }else{

      doclbl.appendChild(document.createTextNode(count)) ;
    }
      
}
