/* Variables Globales Javascript*/


var IdHiloConsumoTrunk="";
var IdLlamadaActual="";
var	IdHiloSaldo="";
var IdTimeOutBusqueda="";
var IdLlamadasActuales="";
var IdHiloSolicitudesCliente="";
var IdHiloSolicitudesReseller="";
var IdHiloVariosReseller="";
var IdHiloVariosAdmin="";



function substr_count (haystack, needle, offset, length) {
    // Returns the number of times a substring occurs in the string  
    // 
    // version: 1109.2015
    // discuss at: http://phpjs.org/functions/substr_count    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Onno Marsman
    // *     example 1: substr_count('Kevin van Zonneveld', 'e');
    // *     returns 1: 3
    // *     example 2: substr_count('Kevin van Zonneveld', 'K', 1);    // *     returns 2: 0
    // *     example 3: substr_count('Kevin van Zonneveld', 'Z', 0, 10);
    // *     returns 3: false
    var pos = 0,
        cnt = 0; 
    haystack += '';
    needle += '';
    if (isNaN(offset)) {
        offset = 0;    }
    if (isNaN(length)) {
        length = 0;
    }
    offset--; 
    while ((offset = haystack.indexOf(needle, offset + 1)) != -1) {
        if (length > 0 && (offset + needle.length) > length) {
            return false;
        } else {            cnt++;
        }
    }
 
    return cnt;
	
	}

function imprSelec(muestra)
{
	var ficha=document.getElementById(muestra);
	var ventimp=window.open(' ','popimpr');
	ventimp.document.write("<link rel='stylesheet' href='../../css/index.css' type='text/css' media='all' >");
	ventimp.document.write(ficha.innerHTML);
    ventimp.document.close();
    ventimp.print();
    ventimp.close();
}


function grupos_seleccionados(actual) {
var enlaces = document.getElementsByTagName("li");
var i=0;
while(document.getElementById('grp'+i)){
 if(i!=actual)
  /*document.getElementById('grp'+i).style.color='';*/
  document.getElementById('grp'+i).className='';
 else
  /* document.getElementById('grp'+i).style.color='green';*/
  document.getElementById('grp'+i).className='grupo_azul';
 i++;
 }
}


function refrescar_consumo_minutos_trunk(accion){
	switch(accion){
		case 'activar':
			window.clearInterval(IdHiloConsumoTrunk);
			IdHiloConsumoTrunk="";
			if(IdHiloConsumoTrunk==""){
				IdHiloConsumoTrunk=setInterval("consumo_minutos_trunk();",10000);
			}
			break;
		case 'desactivar':
			window.clearInterval(IdHiloConsumoTrunk);
			break;		
	}
}


function activar_qtip() {
$(function() {
$('a[title], tr[title], .mojito[title], .dolar[title] ').qtip();
});
}

function zoom(){
	  $(function(){    
        $('.zoom').zoomy();
    });
	
	}

function activar_calendario(campo,img){
$(function() {
	 $( "#"+campo).datepicker({
			showOn: "both",
			buttonImage: "../../images/img.gif",
			buttonImageOnly: true,
			showAnim:"show",
            dateFormat: 'yy-mm-dd ',
			maxDate: '+1Y', 
			changeMonth: true,
			changeYear: true,
				});
	});
	
	
}

function activar_simplemodal(){
jQuery(function ($) {
	// Load dialog on page load
	//$('#basic-modal-content').modal();

	// Load dialog on click
	$('#basic-modal .basic').click(function (e) {
		$('#basic-modal-content').modal();

		return false;
	});
});
}

function activar_imprimir(){
(function($) {
    var counter = 0;
    var modes = { iframe : "iframe", popup : "popup" };
    var defaults = { mode     : modes.iframe,
                     popHt    : 500,
                     popWd    : 400,
                     popX     : 200,
                     popY     : 200,
                     popTitle : '',
                     popClose : false };

    var settings = {};//global settings

    $.fn.printArea = function( options )
        {
            $.extend( settings, defaults, options );

            counter++;
            var idPrefix = "printArea_";
            $( "[id^=" + idPrefix + "]" ).remove();
            var ele = getFormData( $(this) );

            settings.id = idPrefix + counter;

            var writeDoc;
            var printWindow;

            switch ( settings.mode )
            {
                case modes.iframe :
                    var f = new Iframe();
                    writeDoc = f.doc;
                    printWindow = f.contentWindow || f;
                    break;
                case modes.popup :
                    printWindow = new Popup();
                    writeDoc = printWindow.doc;
            }

            writeDoc.open();
            writeDoc.write( docType() + "<html>" + getHead() + getBody(ele) + "</html>" );
            writeDoc.close();

            printWindow.focus();
            printWindow.print();

            if ( settings.mode == modes.popup && settings.popClose )
                printWindow.close();
        }

    function docType()
    {
        if ( settings.mode == modes.iframe || !settings.strict ) return "";

        var standard = settings.strict == false ? " Trasitional" : "";
        var dtd = settings.strict == false ? "loose" : "strict";

        return '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01' + standard + '//EN" "http://www.w3.org/TR/html4/' + dtd +  '.dtd">';
    }

    function getHead()
    {
        var head = "<head><title>" + settings.popTitle + "</title>";
        $(document).find("link")
            .filter(function(){
                    return $(this).attr("rel").toLowerCase() == "stylesheet";
                })
            .filter(function(){ // this filter contributed by "mindinquiring"
                    var media = $(this).attr("media");
                    return (media.toLowerCase() == "all" || media.toLowerCase() == "print")
                })
            .each(function(){
                    head += '<link type="text/css" rel="stylesheet" href="' + $(this).attr("href") + '" >';
                });
        head += "</head>";
        return head;
    }

    function getBody( printElement )
    {
        return '<body><div class="' + $(printElement).attr("class") + '">' + $(printElement).html() + '</div></body>';
    }

    function getFormData( ele )
    {
        $("input,select,textarea", ele).each(function(){
            // In cases where radio, checkboxes and select elements are selected and deselected, and the print
            // button is pressed between select/deselect, the print screen shows incorrectly selected elements.
            // To ensure that the correct inputs are selected, when eventually printed, we must inspect each dom element
            var type = $(this).attr("type");
            if ( type == "radio" || type == "checkbox" )
            {
                if ( $(this).is(":not(:checked)") ) this.removeAttribute("checked");
                else this.setAttribute( "checked", true );
            }
            else if ( type == "text" )
                this.setAttribute( "value", $(this).val() );
            else if ( type == "select-multiple" || type == "select-one" )
                $(this).find( "option" ).each( function() {
                    if ( $(this).is(":not(:selected)") ) this.removeAttribute("selected");
                    else this.setAttribute( "selected", true );
                });
            else if ( type == "textarea" )
            {
                var v = $(this).attr( "value" );
                if ($.browser.mozilla)
                {
                    if (this.firstChild) this.firstChild.textContent = v;
                    else this.textContent = v;
                }
                else this.innerHTML = v;
            }
        });
        return ele;
    }

    function Iframe()
    {
        var frameId = settings.id;
        var iframeStyle = 'border:0;position:absolute;width:0px;height:0px;left:0px;top:0px;';
        var iframe;

        try
        {
            iframe = document.createElement('iframe');
            document.body.appendChild(iframe);
            $(iframe).attr({ style: iframeStyle, id: frameId, src: "" });
            iframe.doc = null;
            iframe.doc = iframe.contentDocument ? iframe.contentDocument : ( iframe.contentWindow ? iframe.contentWindow.document : iframe.document);
        }
        catch( e ) { throw e + ". iframes may not be supported in this browser."; }

        if ( iframe.doc == null ) throw "Cannot find document.";

        return iframe;
    }

    function Popup()
    {
        var windowAttr = "location=yes,statusbar=no,directories=no,menubar=no,titlebar=no,toolbar=no,dependent=no";
        windowAttr += ",width=" + settings.popWd + ",height=" + settings.popHt;
        windowAttr += ",resizable=yes,screenX=" + settings.popX + ",screenY=" + settings.popY + ",personalbar=no,scrollbars=no";

        var newWin = window.open( "", "_blank",  windowAttr );

        newWin.doc = newWin.document;

        return newWin;
    }
})(jQuery);

}


function consumo_minutos_trunk(){
	var i=0;
	while(document.getElementById('HiddenTrunk'+i)){
		eval("IFrameTrunk"+i+".location.reload();");
		i++;
	}
}

function busqueda_keyup(archivo,titulo,gets,div){
	IdTimeOutBusqueda=setTimeout("abrir('"+archivo+"','"+titulo+"','"+gets+"','"+div+"');",200);
}

function verifica_feedback_cliente(){
			abrir('verifica_feedback_cliente.php','','','info_oculta');
			setInterval("abrir('verifica_feedback_cliente.php','','','info_oculta');",4000);
}

function verificar_varios_admin(accion){
			switch(accion){
				case 'activar':
					if(IdHiloVariosAdmin==""){
						abrir('verifica.varios.admin.php','','','info_oculta');
						IdHiloVariosAdmin=setInterval("abrir('verifica.varios.admin.php','','','info_oculta');",4000);
					}
					break;
				case 'inactivar':
					window.clearInterval(IdHiloVariosAdmin);
					IdHiloVariosAdmin="";
			}
}

function verificar_varios_reseller(accion){
			switch(accion){
				case 'activar':
					if(IdHiloVariosReseller==""){
						abrir('verifica.varios.reseller.php','','','info_oculta');
						IdHiloVariosReseller=setInterval("abrir('verifica.varios.reseller.php','','','info_oculta');",4000);
					}
					break;
				case 'inactivar':
					window.clearInterval(IdHiloVariosReseller);
					IdHiloVariosReseller="";
			}
}



function verifica_solicitudes_carga_reseller(id_admin){
			abrir('verifica_solicitud_carga_reseller.php','','&id_admin='+id_admin,'info_oculta');
			setInterval("abrir('verifica_solicitud_carga_reseller.php','','&id_admin="+id_admin+"','info_oculta');",4000);
}

function cambiar_estado_varios_cliente(){

			if(document.getElementById('div_verifica_feedback')){
				document.getElementById('a_feedback_cliente').innerHTML=document.getElementById('div_verifica_feedback').innerHTML;
			}	
					
			if(document.getElementById('input_saldo_bajo_cliente')){
				if(document.getElementById('input_saldo_bajo_cliente').value=='si'){
					
					document.title='Su saldo es bajo, recuerde recargar.';
					if(document.getElementById('div_solicitud_carga')){
						if(document.getElementById('div_solicitud_carga').innerHTML==''){
							document.getElementById('div_solicitud_carga').innerHTML="<div id='formulario002'><input  class='boton'  type='button' name='radio' id='SolicitarRecarga' value='Su saldo Es bajo. \n Solicite Su Recarga Aqui' onclick=\"abrir('../../forms/carga.solicitar.form.php','Solicitud Recarga','','contenido');\"></div>";
						}
					}
				}
				if(document.getElementById('input_saldo_bajo_cliente').value=='no'){
					if(document.getElementById('div_solicitud_carga')){					
						document.getElementById('div_solicitud_carga').innerHTML='';
						if(document.title=='Su saldo es bajo, recuerde recargar.')
							document.title='FCOVOIP, Plataforma de telefonia ip.'
					}
				}
			}
			
			if(document.getElementById('hay_llamadas_en_curso')){
				if(document.getElementById('hay_llamadas_en_curso').value=='si'){
					if(IdLlamadasActuales==""){
//						abrir('tarifador.php','','','right');
						IdLlamadasActuales=setInterval("abrirCabinas();",2000);
						window.clearInterval(IdLlamadaActual);
						IdLlamadaActual="";
					}
				}else{
					if(IdLlamadasActuales!=""){
						window.clearInterval(IdLlamadasActuales);
                        abrirCabinas();
						IdLlamadasActuales="";
					}

//					refrescar_saldo('desactivar','2000');
				}
			}
						
						
}

function cambiar_estado_solicitudes_admin(){ 
			if(document.getElementById('a_solicitudes')){
				if(document.getElementById('div_solicitudes_carga_reseller'))
				document.getElementById('a_solicitudes').innerHTML=document.getElementById('div_solicitudes_carga_reseller').innerHTML;
			}	
/*			if(document.getElementById('a_feedback')){
				if(document.getElementById('div_feebacks_reseller'))
					document.getElementById('a_feedback').innerHTML=document.getElementById('div_feebacks_reseller').innerHTML;
			}*/
			
			if(document.getElementById('session_activa'))
				if(document.getElementById('session_activa').value=='no')
					document.location.href='login.php';
}

function cambiar_estado_solicitudes(){ 
			if(document.getElementById('a_solicitudes')){
				if(document.getElementById('div_solicitudes_cargas_cliente'))
				document.getElementById('a_solicitudes').innerHTML=document.getElementById('div_solicitudes_cargas_cliente').innerHTML;
			}	
			if(document.getElementById('a_feedback')){
				if(document.getElementById('div_feebacks_reseller'))
					document.getElementById('a_feedback').innerHTML=document.getElementById('div_feebacks_reseller').innerHTML;
			}
			if(document.getElementById('session_activa'))
				if(document.getElementById('session_activa').value=='no')
					document.location.href='login.php';
}

// Armar url para buscar eventos en el auditor de reseller
function armar_url_busqueda_auditoria_a(){
	var fecha_ini=document.getElementById('fecha_ini_txt').value;

	var hora_ini=document.getElementById('h_ini').options[document.getElementById('h_ini').selectedIndex].value;
	var min_ini=document.getElementById('m_ini').options[document.getElementById('m_ini').selectedIndex].value;
	var seg_ini=document.getElementById('s_ini').options[document.getElementById('s_ini').selectedIndex].value;

	var fecha_fin=document.getElementById('fecha_fin_txt').value;
	
	var hora_fin=document.getElementById('h_fin').options[document.getElementById('h_fin').selectedIndex].value;
	var min_fin=document.getElementById('m_fin').options[document.getElementById('m_fin').selectedIndex].value;
	var seg_fin=document.getElementById('s_fin').options[document.getElementById('s_fin').selectedIndex].value;	
	
	var url='&fecha_inicial='+fecha_ini+' '+hora_ini+':'+min_ini+':'+seg_ini+'&fecha_final='+fecha_fin+' '+hora_fin+':'+min_fin+':'+seg_fin+'&f_fecha=1';
	
	var st_afectada=document.getElementById('tabla_afectada');
	var saccion=document.getElementById('accion');
	var susuario=document.getElementById('id_admin_usuario');
	
	if(st_afectada.selectedIndex!=0)
		url+='&tabla_afectada='+st_afectada.options[st_afectada.selectedIndex].value; 
	
	if(saccion.selectedIndex!=0)
		url+='&accion='+saccion.options[saccion.selectedIndex].value;

	if(susuario.selectedIndex!=0)
		url+='&id_admin_usuario='+susuario.options[susuario.selectedIndex].value;
	
	
	document.getElementById('url_busqueda').value=url;
//	alert(url);
	
}





// Armar url para buscar eventos en el auditor de reseller
function armar_url_busqueda_auditoria_r(){
	var fecha_ini=document.getElementById('fecha_ini_txt').value;

	var hora_ini=document.getElementById('h_ini').options[document.getElementById('h_ini').selectedIndex].value;
	var min_ini=document.getElementById('m_ini').options[document.getElementById('m_ini').selectedIndex].value;
	var seg_ini=document.getElementById('s_ini').options[document.getElementById('s_ini').selectedIndex].value;

	var fecha_fin=document.getElementById('fecha_fin_txt').value;
	
	var hora_fin=document.getElementById('h_fin').options[document.getElementById('h_fin').selectedIndex].value;
	var min_fin=document.getElementById('m_fin').options[document.getElementById('m_fin').selectedIndex].value;
	var seg_fin=document.getElementById('s_fin').options[document.getElementById('s_fin').selectedIndex].value;	
	
	var url='&fecha_inicial='+fecha_ini+' '+hora_ini+':'+min_ini+':'+seg_ini+'&fecha_final='+fecha_fin+' '+hora_fin+':'+min_fin+':'+seg_fin+'&f_fecha=1';
	
	var st_afectada=document.getElementById('tabla_afectada');
	var saccion=document.getElementById('accion');
	var susuario=document.getElementById('id_distribuidor_usuario');
	
	if(st_afectada.selectedIndex!=0)
		url+='&tabla_afectada='+st_afectada.options[st_afectada.selectedIndex].value;
	
	if(saccion.selectedIndex!=0)
		url+='&accion='+saccion.options[saccion.selectedIndex].value;

	if(susuario.selectedIndex!=0)
		url+='&id_distribuidor_usuario='+susuario.options[susuario.selectedIndex].value;
	
	
	document.getElementById('url_busqueda').value=url;
//	alert(url);
	
}


function validar_contrasena(campo){
	var txt=document.getElementById(campo).value;

	var valida_may=0;
	var valida_min=0;	
	var valida_sim=0;
	var valida_num=0;	

	var Mayusculas="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var Minusculas="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var Simbolos="!|@#$\%&/=*.-+";
	var Numeros="0123456789";
	
	var tamano_may=Mayusculas.length;
	var tamano_min=Minusculas.length;
	var tamano_sim=Simbolos.length;
	var tamano_num=Numeros.length;	
	
	var tamano_txt=txt.length;
	var textos="";
	for(i=0;i<tamano_may;i++){
		for(j=0;j<tamano_txt;j++){
			if(txt[j]==Mayusculas[i]){
				valida_may=1;
				break;
			}
		}
		if(valida_may==1)
			break;		
	}
	
	for(i=0;i<tamano_min;i++){
		for(j=0;j<tamano_txt;j++){
			if(txt[j]==Minusculas[i]){
				valida_min=1;
				break;
			}
		}
		if(valida_min==1)
			break;		
		
	}	
	
	for(i=0;i<tamano_sim;i++){
		for(j=0;j<tamano_txt;j++){
			if(txt[j]==Simbolos[i]){
				valida_sim=1;
				break;
			}
		}
		if(valida_sim==1)
			break;		
		
	}		
	
	for(i=0;i<tamano_num;i++){
		for(j=0;j<tamano_txt;j++){
			if(txt[j]==Numeros[i]){
				valida_num=1;
				break;
			}
		}
		if(valida_num==1)
			break;		
		
	}			
		
	if(valida_min&&valida_sim&&valida_num){
		return true;
	}else{
		alert("Por la seguridad de sus cuentas, la clave debe tener combinacion de letras, numeros y caracteres especiales como  "+Simbolos);
		document.getElementById(campo).focus();
		return false;
	}
		
	
}


function verificar_extension(campo,ext){
	var objeto=document.getElementById(campo);
	var archivo=objeto.value;
	var tamano_cadena=archivo.length;
	var tamano_ext=ext.length;

	var extension=archivo.slice(tamano_cadena-tamano_ext,tamano_cadena);
	if(extension!=ext&&extension!=ext.toUpperCase()){
		retorno=false;
		alert('El archivo no tiene una extension valida para subir al sistema. La extension debe ser '+ext);
	}else {
		retorno=true;
	}
	
	return retorno;
}


function validar_form_promocion(){
	var	radioMinutos=document.getElementById('tipo_minutos');
	var radioPorcentaje=document.getElementById('tipo_porcentaje');
	var nombre=document.getElementById('nombre_promocion');
	var fecha_ini=document.getElementById('fecha_ini_txt');
	var fecha_fin=document.getElementById('fecha_fin_txt');

	
	
	if(!radioMinutos.checked&&!radioPorcentaje.checked){
		alert("Debe seleccionar tipo de promocion");
		radioMinutos.focus();
		return false;
	}
	
	 var val_nombre = nombre.value;
	 val_nombre = val_nombre.replace(/^\s*|\s*$/g,"");
	
	if(val_nombre==''){
		alert('Debe escribir el nombre de la promocion');
		nombre.focus();
		return false;
	}
	
	if(fecha_ini.value==''){
		alert('Debe seleccionar una fecha de inicio de promocion');
		fecha_ini.focus();
		return false;
	}
	
	if(fecha_fin.value==''){
		alert('Debe seleccionar una fecha de fin de promocion');
		fecha_fin.focus();
		return false;
	}
	
	if(fecha_ini.value==fecha_fin.value){
		if(document.getElementById('h_ini').selectedIndex==document.getElementById('h_fin').selectedIndex){
			if(document.getElementById('m_ini').selectedIndex>=document.getElementById('m_fin').selectedIndex){
				alert('Recuerde que la fecha y hora de fin de promocion debe ser mayor a la fecha y hora de inicio');
				return false;
			}
		}else if(document.getElementById('h_ini').selectedIndex>document.getElementById('h_fin').selectedIndex){
				alert('Recuerde que la fecha y hora de fin de promocion debe ser mayor a la fecha y hora de inicio');
			return false;
		}
	}
	
	var array_fecha_ini=fecha_ini.value.split("-");
	var array_fecha_fin=fecha_fin.value.split("-");
	
	array_fecha_ini[0]=parseInt(array_fecha_ini[0]);
	array_fecha_ini[1]=parseInt(array_fecha_ini[1]);
	array_fecha_ini[2]=parseInt(array_fecha_ini[2]);
	
	array_fecha_fin[0]=parseInt(array_fecha_fin[0]);
	array_fecha_fin[1]=parseInt(array_fecha_fin[1]);
	array_fecha_fin[2]=parseInt(array_fecha_fin[2]);

/*	for(i=0;i<3;i++){
		alert(array_fecha_ini[i]);
		alert(array_fecha_fin[i]);
	}*/
		
	if(array_fecha_ini[0]==array_fecha_fin[0]){
//		alert('tro');
		if(array_fecha_ini[1]==array_fecha_fin[1]){
			if(array_fecha_ini[2]>array_fecha_fin[2]){
				alert('Recuerde que la fecha final de promocion debe ser mayor o igual a la fecha de inicio');
				return false;
			}
		}else if(array_fecha_ini[1]>array_fecha_fin[1]){
			alert('Recuerde que la fecha final de promocion debe ser mayor o igual a la fecha de inicio');
			return false;
		}
	}else if(array_fecha_ini[0]>array_fecha_fin[0]){
		alert('Recuerde que la fecha final de promocion debe ser mayor o igual a la fecha de inicio');
		return false;
	}
	
	
	
	if(!document.getElementById('lunes').checked&&!document.getElementById('martes').checked&&!document.getElementById('miercoles').checked&&!document.getElementById('jueves').checked&&!document.getElementById('viernes').checked&&!document.getElementById('sabado').checked&&!document.getElementById('domingo').checked){
		alert('Debe seleccionar al menos un dia para la promocion');
		document.getElementById('lunes').focus();
		return false;
	}
	
	if(document.getElementById('hora_inicio_dia').selectedIndex==document.getElementById('hora_fin_dia').selectedIndex){
		if(document.getElementById('m_inicio_dia').selectedIndex>=document.getElementById('m_fin_dia').selectedIndex){
			alert('Recuerde que la hora de fin de promocion en el dia debe ser mayor a la hora de inicio');
			return false;
		}
	}else if(document.getElementById('hora_inicio_dia').selectedIndex>document.getElementById('hora_fin_dia').selectedIndex){
		alert('Recuerde que la hora de fin de promocion en el dia debe ser mayor a la hora de inicio');
		return false;
	}
	
	var campo_max_min_semana = document.getElementById('max_min_semana');
	var campo_porcentaje_ultima_carga = document.getElementById('porcentaje_ultima_carga');
	
	if(campo_max_min_semana.value==''||parseInt(campo_max_min_semana.value)<=0){
		if(radioMinutos.checked){
			alert("Si la promocion es por minutos, debe escribir el numero de minutos.");
			campo_max_min_semana.focus();
			return false;
		}
	}
	
	if(campo_porcentaje_ultima_carga.value==''||parseInt(campo_porcentaje_ultima_carga.value)<=0){
		if(radioPorcentaje.checked){
			alert("Si la promocion es por porcentaje, debe escribir el porcentaje de la recarga.");
			campo_porcentaje_ultima_carga.focus();
			return false;
		}
	}
	
	var campo_monto_minimo_carga=document.getElementById('monto_minimo_carga');
	if(campo_monto_minimo_carga.value==''||parseInt(campo_monto_minimo_carga.value)<=0){
		alert("Debe escribir un monto mínimo de recarga para la promoción.");
		campo_monto_minimo_carga.focus();
	}
	
	
	
	
	
	



}




function popup(URL,ancho,alto,nombre){
   window.open(URL,nombre,"width="+ancho+",height="+alto+",scrollbars=YES");
} 

function editar_destino(id){
	document.getElementById('id_indicativo_ant').value=document.getElementById('id_indicativo_ant'+id).value;
	document.getElementById('id_indicativo').value=document.getElementById('id_indicativo'+id).value;
	document.getElementById('destino').value=document.getElementById('destino'+id).value;
	document.getElementById('precio_costo').value=document.getElementById('precio_costo'+id).value;
	
//	alert(document.getElementById('destino'+id).value);
	
	if(confirm('Desea realizar esta tarea ahora?')){
		document.getElementById('formDestino').submit();
	}
}

function MasMenos(div,botton){
	if(document.getElementById(div).style.display==''){
		document.getElementById(div).style.display='none';
		document.getElementById(botton).innerHTML='Mas+';
	}else{
		document.getElementById(div).style.display='';
		document.getElementById(botton).innerHTML='Ocultar-';
	}
}
 
function ver_ocultar(id){
	if(document.getElementById(id).style.display!='none')
		document.getElementById(id).style.display='none';
	else			
		document.getElementById(id).style.display='';
}

function desplegar(id){
	Effect.BlindDown(id);
}

function recoger(id){
	Effect.BlindUp(id);
}


function activar_lightbox() {
      $('.gallery a').lightBox();
	// Use this example, or...
	$('a[@rel*=lightbox]').lightBox(); // Select all links that contains lightbox in the attribute rel
	// This, or...
	$('#gallery a').lightBox(); // Select all links in object with gallery ID
	// This, or...
	$('a.lightbox').lightBox(); // Select all links with lightbox class
	// This, or...
	$('a').lightBox(); // Select all links in the page
	// ... The possibility are many. Use your creative or choose one in the examples above
}






function armar_url_busqueda_a_pagos(){
	var fecha_ini=document.getElementById('fecha_ini_txt').value;

	var hora_ini=document.getElementById('h_ini').options[document.getElementById('h_ini').selectedIndex].value;
	var min_ini=document.getElementById('m_ini').options[document.getElementById('m_ini').selectedIndex].value;
	var seg_ini=document.getElementById('s_ini').options[document.getElementById('s_ini').selectedIndex].value;

	var fecha_fin=document.getElementById('fecha_fin_txt').value;
	
	var hora_fin=document.getElementById('h_fin').options[document.getElementById('h_fin').selectedIndex].value;
	var min_fin=document.getElementById('m_fin').options[document.getElementById('m_fin').selectedIndex].value;
	var seg_fin=document.getElementById('s_fin').options[document.getElementById('s_fin').selectedIndex].value;	

	var url='&fecha_inicial='+fecha_ini+' '+hora_ini+':'+min_ini+':'+seg_ini+'&fecha_final='+fecha_fin+' '+hora_fin+':'+min_fin+':'+seg_fin;
	
	document.getElementById('url_busqueda').value=url;

}


function armar_url_busqueda_a_cargas(){
	var fecha_ini=document.getElementById('fecha_ini_txt').value;

	var hora_ini=document.getElementById('h_ini').options[document.getElementById('h_ini').selectedIndex].value;
	var min_ini=document.getElementById('m_ini').options[document.getElementById('m_ini').selectedIndex].value;
	var seg_ini=document.getElementById('s_ini').options[document.getElementById('s_ini').selectedIndex].value;

	var fecha_fin=document.getElementById('fecha_fin_txt').value;
	
	var hora_fin=document.getElementById('h_fin').options[document.getElementById('h_fin').selectedIndex].value;
	var min_fin=document.getElementById('m_fin').options[document.getElementById('m_fin').selectedIndex].value;
	var seg_fin=document.getElementById('s_fin').options[document.getElementById('s_fin').selectedIndex].value;	

	var url='&fecha_inicial='+fecha_ini+' '+hora_ini+':'+min_ini+':'+seg_ini+'&fecha_final='+fecha_fin+' '+hora_fin+':'+min_fin+':'+seg_fin;
	
	document.getElementById('url_busqueda').value=url;

}

function armar_url_busqueda_fecha(){
	var fecha_ini=document.getElementById('fecha_ini_txt').value;

	var hora_ini=document.getElementById('h_ini').options[document.getElementById('h_ini').selectedIndex].value;
	var min_ini=document.getElementById('m_ini').options[document.getElementById('m_ini').selectedIndex].value;
	var seg_ini=document.getElementById('s_ini').options[document.getElementById('s_ini').selectedIndex].value;

	var fecha_fin=document.getElementById('fecha_fin_txt').value;
	
	var hora_fin=document.getElementById('h_fin').options[document.getElementById('h_fin').selectedIndex].value;
	var min_fin=document.getElementById('m_fin').options[document.getElementById('m_fin').selectedIndex].value;
	var seg_fin=document.getElementById('s_fin').options[document.getElementById('s_fin').selectedIndex].value;	

	var url='&fecha_inicial='+fecha_ini+' '+hora_ini+':'+min_ini+':'+seg_ini+'&fecha_final='+fecha_fin+' '+hora_fin+':'+min_fin+':'+seg_fin;
	
	document.getElementById('url_busqueda').value=url;

}

function armar_url_busqueda_a(){
	var fecha_ini=document.getElementById('fecha_ini_txt').value;

	var hora_ini=document.getElementById('h_ini').options[document.getElementById('h_ini').selectedIndex].value;
	var min_ini=document.getElementById('m_ini').options[document.getElementById('m_ini').selectedIndex].value;
	var seg_ini=document.getElementById('s_ini').options[document.getElementById('s_ini').selectedIndex].value;

	var fecha_fin=document.getElementById('fecha_fin_txt').value;
	
	var hora_fin=document.getElementById('h_fin').options[document.getElementById('h_fin').selectedIndex].value;
	var min_fin=document.getElementById('m_fin').options[document.getElementById('m_fin').selectedIndex].value;
	var seg_fin=document.getElementById('s_fin').options[document.getElementById('s_fin').selectedIndex].value;	
	
	var id_trunk=document.getElementById('id_trunk').options[document.getElementById('id_trunk').selectedIndex].value;
	
	
	
	
		var url='&cantidad_llamadas='+document.getElementById('cantidad_llamadas').value+'&fecha_inicial='+fecha_ini+' '+hora_ini+':'+min_ini+':'+seg_ini+'&fecha_final='+fecha_fin+' '+hora_fin+':'+min_fin+':'+seg_fin+'&f_fecha=1'+'&id_trunk='+id_trunk;
	
	
	
	var indicativ=document.getElementById('indicativo').value;
	var ip=document.getElementById('ip').value;
	
	
		if(document.getElementById('otrosCampos').style.display==''){
				url+='&otrosCampos=1&ip='+ip;	
				if(document.getElementById('indicativo').value!="")
					url+='&indicativo='+indicativ;
			var plan_d=0;
			if(document.getElementById('no_plan_d').selectedIndex){
				plan_d=document.getElementById('no_plan_d').options[document.getElementById('no_plan_d').selectedIndex].value;
				var distribuidor=0;
				if(document.getElementById('id_distribuidor').selectedIndex){
					distribuidor=document.getElementById('id_distribuidor').options[document.getElementById('id_distribuidor').selectedIndex].value;					
					var plan=0;		
					if(document.getElementById('no_plan').selectedIndex){
						plan=document.getElementById('no_plan').options[document.getElementById('no_plan').selectedIndex].value;
						var cliente=0;
						if(document.getElementById('id_cliente').selectedIndex){
							cliente=document.getElementById('id_cliente').options[document.getElementById('id_cliente').selectedIndex].value;		
							var cuent=0;
							if(document.getElementById('id_cuenta').selectedIndex){
								cuent=document.getElementById('id_cuenta').options[document.getElementById('id_cuenta').selectedIndex].value;								
								url+="&no_plan_d="+plan_d+"&id_distribuidor="+distribuidor+"&no_plan="+plan+"&id_cliente="+cliente+"&id_cuenta="+cuent+"&consulta=5&ip="+ip;
							}else{
								url+="&no_plan_d="+plan_d+"&id_distribuidor="+distribuidor+"&no_plan="+plan+"&id_cliente="+cliente+"&consulta=4&ip="+ip;
							}
						}else{
							url+="&no_plan_d="+plan_d+"&id_distribuidor="+distribuidor+"&no_plan="+plan+"&consulta=3&ip="+ip;
						}
					}else{
						url+="&no_plan_d="+plan_d+"&id_distribuidor="+distribuidor+"&consulta=2&ip="+ip;
					}
				}else{
					url+="&no_plan_d="+plan_d+"&consulta=1&ip="+ip;	
				}
			}else{
			 	url+="&consulta=6&ip="+ip;					
			}
		}else{
		 	url+="&consulta=6&ip="+ip;	
		}
	document.getElementById('url_busqueda').value=url;
//	alert(url);
	
}


function armar_url_busqueda_r(){
	var fecha_ini=document.getElementById('fecha_ini_txt').value;

	var hora_ini=document.getElementById('h_ini').options[document.getElementById('h_ini').selectedIndex].value;
	var min_ini=document.getElementById('m_ini').options[document.getElementById('m_ini').selectedIndex].value;
	var seg_ini=document.getElementById('s_ini').options[document.getElementById('s_ini').selectedIndex].value;

	var fecha_fin=document.getElementById('fecha_fin_txt').value;
	
	var hora_fin=document.getElementById('h_fin').options[document.getElementById('h_fin').selectedIndex].value;
	var min_fin=document.getElementById('m_fin').options[document.getElementById('m_fin').selectedIndex].value;
	var seg_fin=document.getElementById('s_fin').options[document.getElementById('s_fin').selectedIndex].value;	
	
	
	
	
	var url='&cantidad_llamadas='+document.getElementById('cantidad_llamadas').value+'&fecha_inicial='+fecha_ini+' '+hora_ini+':'+min_ini+':'+seg_ini+'&fecha_final='+fecha_fin+' '+hora_fin+':'+min_fin+':'+seg_fin+'&f_fecha=1';
	
	
	
	var indicativ=document.getElementById('indicativo').value;
	var ip=document.getElementById('ip').value;

	if(document.getElementById('otrosCampos').style.display==''){
			url+='&otrosCampos=1&ip='+ip;
			if(document.getElementById('indicativo').value!=""){
				url+='&indicativo='+indicativ;
			}

			var plan=0;
			if(document.getElementById('no_plan').selectedIndex){
				plan=document.getElementById('no_plan').options[document.getElementById('no_plan').selectedIndex].value;
				var cliente=0;
				if(document.getElementById('id_cliente').selectedIndex){
					cliente=document.getElementById('id_cliente').options[document.getElementById('id_cliente').selectedIndex].value;
					var cuent=0;
					if(document.getElementById('id_cuenta').selectedIndex){
						cuent=document.getElementById('id_cuenta').options[document.getElementById('id_cuenta').selectedIndex].value;
						url+="&no_plan="+plan+"&id_cliente="+cliente+"&id_cuenta="+cuent+"&consulta=4&ip="+ip;
					}else{
						url+="&no_plan="+plan+"&id_cliente="+cliente+"&consulta=3&ip="+ip;
					}
				}else{
					url+="&no_plan="+plan+"&consulta=2&ip="+ip;
				}
			}
	}else{
			url+="&consulta=1";
	}
	
	
	

	document.getElementById('url_busqueda').value=url;
//	alert(url);
	
}


function armar_url_busqueda(){
	var fecha_ini=document.getElementById('fecha_ini_txt').value;

	var hora_ini=document.getElementById('h_ini').options[document.getElementById('h_ini').selectedIndex].value;
	var min_ini=document.getElementById('m_ini').options[document.getElementById('m_ini').selectedIndex].value;
	var seg_ini=document.getElementById('s_ini').options[document.getElementById('s_ini').selectedIndex].value;

	var fecha_fin=document.getElementById('fecha_fin_txt').value;
	
	var hora_fin=document.getElementById('h_fin').options[document.getElementById('h_fin').selectedIndex].value;
	var min_fin=document.getElementById('m_fin').options[document.getElementById('m_fin').selectedIndex].value;
	var seg_fin=document.getElementById('s_fin').options[document.getElementById('s_fin').selectedIndex].value;	
	
	
	
	
		var url='&cantidad_llamadas='+document.getElementById('cantidad_llamadas').value+'&fecha_inicial='+fecha_ini+' '+hora_ini+':'+min_ini+':'+seg_ini+'&fecha_final='+fecha_fin+' '+hora_fin+':'+min_fin+':'+seg_fin+'&f_fecha=1';
	
	
	
	var indicativ=document.getElementById('indicativo').value;
	var cuent=document.getElementById('cuenta').options[document.getElementById('cuenta').selectedIndex].value;
	var dura1=document.getElementById('duracion1').value;
	var dura2=document.getElementById('duracion2').value;	
	var val1=document.getElementById('valor1').value;
	var val2=document.getElementById('valor2').value;
	



	if(document.getElementById('otrosCampos').style.display==''){
		if(document.getElementById('indicativo').value!="")
			url+='&indicativo='+indicativ+'&f_indicativo=1';
		if(document.getElementById('duracion1').value!=""&&document.getElementById('duracion2').value!="")
			url+='&duracion1='+dura1+'&duracion2='+dura2+'&f_duracion=1';

		url+='&cuenta='+document.getElementById('cuenta').options[document.getElementById('cuenta').selectedIndex].value+'&f_cuenta=1';
		
		if(document.getElementById('valor1').value!=""&&document.getElementById('valor1').value!="")
			url+='&valor1='+val1+'&valor2='+val2+'&f_valor=1';			
	}
	
	
	

	document.getElementById('url_busqueda').value=url;
//	alert(url);
	
}



function enviar(form,txt){
//	var confirma;
//	if(confirma=confirm('¿Esta seguro que desea enviar el formulario ahora?'+txt))
		document.getElementById(form).submit();
	
//	return confirma;

}

function ver_div_edit(){
/*	document.getElementById('DivEdicion').style.display='none';
	Effect.toggle('EditBackground');
	setTimeout("desplegar('DivEdicion');",500);*/
	
	document.getElementById('EditBackground').style.display='';	
	document.getElementById('DivEdicion').style.display='';	

		
}




function buscar_dist(){
	abrir('resellers.list.php',' Mis Distribuidores','&palabra='+document.getElementById('palabra').value,'div_reseller_list');
}

function cerrar_edicion(){
document.getElementById('DivEdicion').style.display='none';
document.getElementById('EditBackground').style.display='none';
/*
Effect.toggle('DivEdicion');
Effect.toggle('EditBackground');	*/
}

function accion(txt){
	document.getElementById('acciones').innerHTML=txt;
//	setTimeout("document.getElementById('acciones').innerHTML='';",5000);
}

function selAllCheckBox(id,subI1,cantidad){
	for(i=0;i<cantidad;i++){
		if(document.getElementById(id+subI1+i).checked==true)
			document.getElementById(id+subI1+i).checked=false;
		else
			document.getElementById(id+subI1+i).checked=true;
	}
}

function sincronizar(id,subI1,cantidad){
	var primero=0;
	var val=document.getElementById(id+subI1+primero).value;
		for(i=0;i<=cantidad;i++){
			if(document.getElementById(id+subI1+i))
				document.getElementById(id+subI1+i).value=val;
		}
}


function val_num_prefijo(e) {
  tecla = (document.all) ? e.keyCode : e.which;
  if((tecla<48||tecla>57||tecla==35||tecla==42)&&(tecla!=13&&tecla!=46&&tecla!=0&&tecla!=8))
  	alert('unicamente se pueden escribir numeros');

  return ((tecla != 13)&&(tecla>=48)&&(tecla<=57)||tecla==0||tecla==8||tecla==46);
}

function val_num(e) {
  tecla = (document.all) ? e.keyCode : e.which;
  if((tecla<48||tecla>57)&&(tecla!=13&&tecla!=46&&tecla!=0&&tecla!=8))
  	alert('unicamente se pueden escribir numeros');

  return ((tecla != 13)&&(tecla>=48)&&(tecla<=57)||tecla==0||tecla==8||tecla==46);
}

function val_num_entero(e) {
  tecla = (document.all) ? e.keyCode : e.which;
  if((tecla<48||tecla>57)&&(tecla!=13&&tecla!=0&&tecla!=8))
  	alert('unicamente se pueden escribir numeros');

  return ((tecla != 13)&&(tecla>=48)&&(tecla<=57)||tecla==0||tecla==8);
}


function saldo(){
setInterval("abrir('consulta_saldo.php','','','info_usuario');",10000);
}

function listar_destinos(){
	if(document.getElementById('palabra').value!='')
		{
			abrir('/voip/forms/list_destinos.form.php',' Listado de destinos','&palabra='+document.getElementById('palabra').value,'destinos');
	}	
}



function ver_promocion(){
	
	abrir('promocion.php','','','promocion');
}

function eliminar(){
	var confirma;
	confirma=confirm("Esta seguro que desea eliminar el registro");
	if(confirma)
		document.getElementById('FormElimina').submit();
}

function comprueba_eliminar1(){
	var i=0;
	while(document.getElementById('confirma'+i)){
		i++;
	}	

	var j=0;
	var	bandera=1;
	for(j=0;j<i;j++){
		if(document.getElementById('confirma'+j).checked!=true)
			bandera=0;
	}
	
	if(bandera)
		document.getElementById('BotonEliminar').disabled=false;
	else
		document.getElementById('BotonEliminar').disabled=true;
}


function llamada_actual_cliente(accion){	
	switch(accion){
		case 'activar':
			IdLlamadaActual="";
	        abrir('verifica_llamadas_servidor.php','','','info_oculta');
			if(IdLlamadaActual==""){
				IdLlamadaActual=setInterval("abrir('verifica_llamadas_servidor.php','','','info_oculta');",2000);
			}
			break;
		case 'desactivar':
			window.clearInterval(IdLlamadaActual);
			window.clearInterval(IdLlamadasActuales);						
			break;		
	}
}

function refrescar_saldo(accion,intervalo_refresco_saldo){
	switch(accion){
		case 'activar':
			IdHiloSaldo="";
			abrir('saldo.php','','','saldo');
			if(IdHiloSaldo==""){
				IdHiloSaldo=setInterval("abrir('saldo.php','','','saldo');",intervalo_refresco_saldo);
			}
			break;
		case 'desactivar':
			window.clearInterval(IdHiloSaldo);
			break;		
	}
}

function llamada_actual_admin(accion){	
	switch(accion){
		case 'activar':
			IdLlamadaActual="";
			abrir('llamada_en_curso_admin.php','','','contenido');
			if(IdLlamadaActual=="")
				IdLlamadaActual=setInterval("abrir_llamada_actual_admin();",2000);
			break;
		case 'desactivar':
			window.clearInterval(IdLlamadaActual);
			if(document.getElementById('div_graficos'))
				document.getElementById('div_graficos').style.display='none';
			break;		
	}
}

function abrir_llamada_actual_admin(){
	var url='';
	if(document.getElementById('no_plan_distribuidor')){
		

			var plan_distribuidor=document.getElementById('no_plan_distribuidor');
			if(document.getElementById('id_distribuidor'))
				var distribuidor=document.getElementById('id_distribuidor');
			if(document.getElementById('no_plan'))
				var plan_cliente=document.getElementById('no_plan');
			if(document.getElementById('id_cliente'))
				var cliente=document.getElementById('id_cliente');
			if(document.getElementById('id_cuenta'))
				var cuenta=document.getElementById('id_cuenta');
			if(document.getElementById('indicativo'))
				var num=document.getElementById('indicativo');
			if(document.getElementById('id_trunk')){
				var nom_trunk=document.getElementById('id_trunk');
			}


			if(document.getElementById('campo_plan_distribuidor'))
				var chk_plan_distribuidor=document.getElementById('campo_plan_distribuidor');
			if(document.getElementById('campo_distribuidor'))
				var chk_distribuidor=document.getElementById('campo_distribuidor');
			if(document.getElementById('campo_plan_cliente'))
				var chk_plan_cliente=document.getElementById('campo_plan_cliente');
			if(document.getElementById('campo_cliente'))
				var chk_cliente=document.getElementById('campo_cliente');
			if(document.getElementById('campo_cuenta'))
				var chk_cuenta=document.getElementById('campo_cuenta');
			if(document.getElementById('campo_telefono'))
				var chk_telefono=document.getElementById('campo_telefono');
			if(document.getElementById('campo_trunk')){
				var chk_trunk=document.getElementById('campo_trunk');
				if(chk_trunk.checked==true)
					url+="&campo_trunk=1";				
			}
			

			
			if(document.getElementById('campo_todo'))
				var chk_todo=document.getElementById('campo_todo');

			if(plan_distribuidor.selectedIndex!=0)
				url+="&no_plan_distribuidor="+plan_distribuidor.options[plan_distribuidor.selectedIndex].value;
			if(distribuidor.selectedIndex!=0)
				url+="&id_distribuidor="+distribuidor.options[distribuidor.selectedIndex].value;				
			if(plan_cliente.selectedIndex!=0)
				url+="&no_plan="+plan_cliente.options[plan_cliente.selectedIndex].value;
			if(cliente.selectedIndex!=0)
				url+="&id_cliente="+cliente.options[cliente.selectedIndex].value;
			if(cuenta.selectedIndex!=0)
				url+="&id_cuenta="+cuenta.options[cuenta.selectedIndex].value;
			if(num.value!='')
				url+="&id_indicativo="+num.value;
			if(nom_trunk.selectedIndex!=0)
				url+="&id_trunk="+nom_trunk.options[nom_trunk.selectedIndex].value;

				
			if(chk_plan_distribuidor.checked==true)
				url+="&campo_plan_distribuidor=1";
			if(chk_distribuidor.checked==true)
				url+="&campo_distribuidor=1";
			if(chk_plan_cliente.checked==true)
				url+="&campo_plan_cliente=1";
			if(chk_cliente.checked==true)
				url+="&campo_cliente=1";
			if(chk_cuenta.checked==true)
				url+="&campo_cuenta=1";
			if(chk_telefono.checked==true)
				url+="&campo_telefono=1";
			if(chk_todo.checked==true)
				url+="&campo_todo=1";

			
		}
		abrir('llamadas_en_curso_admin.php','',url,'div_llamada_en_curso');
	
}

function llamada_actual_reseller(accion){	

	switch(accion){
		case 'activar':
			IdLlamadaActual="";
			abrir('llamada_en_curso.php','','','contenido');
			if(IdLlamadaActual==""){		
				IdLlamadaActual=setInterval("abrir_llamada_actual_reseller();",2000);
			}
			break;
		case 'desactivar':
			window.clearInterval(IdLlamadaActual);
			break;		
	}
}

function abrir_llamada_actual_reseller(){
	var url='';
	if(document.getElementById('id_cliente')){
		var plan_cliente=document.getElementById('no_plan');
		if(document.getElementById('id_cliente'))
			var cliente=document.getElementById('id_cliente');
			if(document.getElementById('id_cuenta'))
				var cuenta=document.getElementById('id_cuenta');
			if(document.getElementById('indicativo'))
				var num=document.getElementById('indicativo');

			if(document.getElementById('id_trunk')){
				var nom_trunk=document.getElementById('id_trunk');
				if(nom_trunk.selectedIndex!=0)
					url+="&id_trunk="+nom_trunk.options[nom_trunk.selectedIndex].value;
			}


			if(document.getElementById('campo_plan_cliente'))
				var chk_plan_cliente=document.getElementById('campo_plan_cliente');
			if(document.getElementById('campo_cliente'))
				var chk_cliente=document.getElementById('campo_cliente');
			if(document.getElementById('campo_cuenta'))
				var chk_cuenta=document.getElementById('campo_cuenta');
			if(document.getElementById('campo_telefono'))
				var chk_telefono=document.getElementById('campo_telefono');
			if(document.getElementById('campo_trunk')){
				var chk_trunk=document.getElementById('campo_trunk');				
				if(chk_trunk.checked==true)
					url+="&campo_trunk=1";				
			}
			

			
			if(document.getElementById('campo_todo'))
				var chk_todo=document.getElementById('campo_todo');



			if(plan_cliente.selectedIndex!=0)
				url="&no_plan="+plan_cliente.options[plan_cliente.selectedIndex].value;
			if(cliente.selectedIndex!=0)
				url+="&id_cliente="+cliente.options[cliente.selectedIndex].value;
			if(cuenta.selectedIndex!=0)
				url+="&id_cuenta="+cuenta.options[cuenta.selectedIndex].value;
			if(num.value!='')
				url+="&id_indicativo="+num.value;


				
			if(chk_plan_cliente.checked==true)
				url+="&campo_plan_cliente=1";
			if(chk_cliente.checked==true)
				url+="&campo_cliente=1";
			if(chk_cuenta.checked==true)
				url+="&campo_cuenta=1";
			if(chk_telefono.checked==true)
				url+="&campo_telefono=1";
			if(chk_todo.checked==true)
				url+="&campo_todo=1";

			
		}
		abrir('llamadas_en_curso_reseller.php','',url,'div_llamada_en_curso');
	
}

function validar_formulario(form,campos){
	var	ids=campos.split('-');
	var campo,indice,salir=0;
	for(i=0;i<ids.length;i++){

		campo=document.getElementById(ids[i]);
		switch(document.getElementById(ids[i]).type){
				case 'text':
								if(campo.value==''){
									alert('El campo '+ids[i]+' debe llenarse');
									campo.focus();
									salir=1;
								}
								break;
				case 'password':
								if(campo.value==''){
									alert('El campo '+ids[i]+' debe llenarse');
									campo.focus();
									salir=1;
								}
								break;								
				case 'textarea':
								if(campo.value==''){
									alert('El campo '+ids[i]+' debe llenarse');
									campo.focus();
									salir=1;									
								}
								break;
				case 'select-one':
								indice=campo.selectedIndex;
								indice=parseInt(indice);
								if(indice==0&&!campo.disabled){
									alert('Debe escoger un valor en el campo '+	ids[i]);
									campo.focus();
									salir=1;									
								}
								break;
		}
		if(salir==1){
				break;
		}
	}
	if(salir!=1){
		return true;
	}else{
		return false;
	}
}


function validar_form(form,campos){
	var	ids=campos.split('-');
	var campo,indice,salir=0;
	for(i=0;i<ids.length;i++){

		campo=document.getElementById(ids[i]);
		switch(document.getElementById(ids[i]).type){
				case 'text':
								if(campo.value==''){
									alert('El campo '+ids[i]+' debe llenarse');
									campo.focus();
									salir=1;
								}
								break;
				case 'password':
								if(campo.value==''){
									alert('El campo '+ids[i]+' debe llenarse');
									campo.focus();
									salir=1;
								}
								break;								
				case 'textarea':
								if(campo.value==''){
									alert('El campo '+ids[i]+' debe llenarse');
									campo.focus();
									salir=1;									
								}
								break;
				case 'select-one':
								indice=campo.selectedIndex;
								indice=parseInt(indice);
								if(indice==0&&!campo.disabled){
									alert('Debe escoger un valor en el campo '+	ids[i]);
									campo.focus();
									salir=1;									
								}
								break;
		}
		if(salir==1){
				break;
		}
	}
	if(salir!=1){
		return 1;
	}else{
		return 0;
	}
}


function imprimir(nombre)
{
  var ficha = document.getElementById(nombre);
  var ventimp = window.open(' ', 'popimpr');
  var estilo="<link rel='stylesheet' href='../../css/imprimir.css' type='text/css' media='screen' />";
  ventimp.document.write(estilo);
  ventimp.document.write( ficha.innerHTML );
  ventimp.document.close();
  ventimp.print( );
  ventimp.close();
}

function trim (myString){
	return myString.replace(/^\s+/g,'').replace(/\s+$/g,'');
}


