// JavaScript Document


/*funcion para mover las seleciones de un select al otro
    Parametros:
        org: id del select de origen
        dest: id del select de destino
    */
    function move(org, dest) {
        var origen = document.getElementById(org);
        var destino = document.getElementById(dest);
        var hijos = origen.getElementsByTagName("option");    
        for (i = 0; i < hijos.length; i++) {
            if(hijos[i].selected) {
                destino.appendChild(hijos[i]);
                i = -1;
            }
        }
        return false;
    }
	
	
	/**Funcion para cargar el calendario en el boton de fecha limite**/
    function calendario(id, buttonId) {
    Calendar.setup({
          inputField  : id,         // ID of the input field
          ifFormat: Calendar._TT["DEF_DATE_FORMAT"], 
          showsTime      :    true,
          button      : buttonId       // ID of the button
        } );
    }
function cargar() {
	if (document.getElementById('calendario') != null) {		
			calendario('fecha', 'calendario');
	}
	if (document.getElementById('calendario2') != null) {		
			calendario('fecha2', 'calendario2');
	}
}
window.onload = cargar;



 function hiddenShow(id) {

        if (window.document.getElementById(id).style.display == 'none') {
              window.document.getElementById(id).style.display = 'block';                    
        } else {
             window.document.getElementById(id).style.display = 'none';          
        }    
    }

	
function maximo(texto, maxim) {
//window.frames[0].frames[0].document.getElementsByTagName('body')[0].innerHTML
	var el = eliminarHtml(texto);
	
	if (el.length > maxim) {
		return false;
	}
	return true;

}

function eliminarHtml(texto) {
	var textosalida = texto.replace(/<(.*?)[a-z]+(.*?)>/gi, '');
	textosalida = textosalida.replace(/<img+(.*?)>/i, '');
	textosalida = textosalida.replace(/<(.*?)div+(.*?)>/i, '');
	textosalida = textosalida.replace(/<(.*?)span+(.*?)>/i, '');
	return textosalida;
}

function valid(text, maxs) {
		if (!validDate2(document.getElementById('fecha').value, 'lfecha')){
				return false;
		}
		if (!maximo(window.frames[0].frames[0].document.getElementsByTagName('body')[0].innerHTML,maxs)){
				alert(text);
				return false;
		}
}