function validaFeriados(){
	var i;
	var arrItem;
	var dia=0;
	var mes=0;
	var agno=0;
	var doc=document.Form1;
	if(doc.datePicker.value=="")
		return true;
	var strCampo=doc.datePicker.value;
	var iguales=false;
	for(i=0;i<arrFec.length;i++){
		if(arrFec[i].toString()==strCampo.toString())
			iguales=true;
	}
	if(iguales){
		if (confirm("La fecha programada corresponde a un dia feriado, ¿Desea continuar?"))
			return true;
		else
			return false;
	}else
		return true;
}
function changeIdioma(valor){
	parent.frames['main'].location.href="main.aspx?ChangeIdioma="+valor
	parent.frames['contents'].location.href="left_ini.aspx";
	self.location.reload();
}
function valida_largo(largo,obj){
	var str=obj.value;
	if(str.length>(largo-1)){
		obj.value=str.substring(0,1500);
		return false;
	}else{
		return true;
	}
}
function openDocument(frm,id){
	window.open(frm+"?id="+id,"DOCS",atts)
	
}
function showHide(id_objeto){

	if(document.getElementById(id_objeto).style.display=="none"){
		document.getElementById(id_objeto).style.display="block"
		document.getElementById("img_" + id_objeto).src="../../imagenes/menos.gif"
	}else{
		document.getElementById(id_objeto).style.display="none"
		document.getElementById("img_" + id_objeto).src="../../imagenes/mas.gif"
	}
}
function DesabilitarEnter (field, event)
{
  var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : 
event.charCode;
  if (keyCode == 13)
  {
   var i;
   for (i = 0; i < field.form.elements.length; i++)
    if (field == field.form.elements[i])
     break;
   i = (i + 1) % field.form.elements.length;
   //field.form.elements[i].focus();
   return false;
  }
  else
  return true;
}
function validaResolutor(source, arguments){
	var resolutor = document.Form1.ddlAsignadoA[document.Form1.ddlAsignadoA.selectedIndex].text;
	var estado = document.Form1.ddlEstado.value;
	if(estado==2 || estado==4){
		var existe=resolutor.indexOf("COMOD");
		var existe2=resolutor.indexOf("comod");
		var existe3=resolutor.indexOf("Comod");
		if(existe == -1 && existe2 == -1 && existe3 == -1){
			arguments.IsValid=true;
			return true;
		}else{
			arguments.IsValid=false;
			return true;
		}
	}else{
		arguments.IsValid=true;
		return true;
	}
}
function checkRutField(source, arguments)
{
	var tmpstr = "";
	var rut;
	var obj=Form1.txtRut;
	rut = obj.value;
	//alert("1");
	for ( i=0; i < rut.length ; i++ )
		if ( rut.charAt(i) != ' ' && rut.charAt(i) != '.' && rut.charAt(i) != '-' )
			tmpstr = tmpstr + rut.charAt(i);
	rut = tmpstr;
	largo = rut.length;
// [VARM+]
	tmpstr = "";
	for ( i=0; rut.charAt(i) == '0' ; i++ );
		for (; i < rut.length ; i++ )
			tmpstr = tmpstr + rut.charAt(i);
	rut = tmpstr;
	largo = rut.length;
// [VARM-]
	if ( largo < 2 )
	{
		//alert("Debe ingresar el rut completo.");
		//obj.focus();
		//obj.select();
		arguments.IsValid=false;
		return false;
		//return false;
	}
	for (i=0; i < largo ; i++ )
	{
		if ( rut.charAt(i) != "0" && rut.charAt(i) != "1" && rut.charAt(i) !="2" && rut.charAt(i) != "3" && rut.charAt(i) != "4" && rut.charAt(i) !="5" && rut.charAt(i) != "6" && rut.charAt(i) != "7" && rut.charAt(i) !="8" && rut.charAt(i) != "9" && rut.charAt(i) !="k" && rut.charAt(i) != "K" )
		{
			//alert("El valor ingresado no corresponde a un R.U.T valido.");
			//obj.focus();
			//obj.select();
			arguments.IsValid=false;
			return;
			//return false;
		}
	}
	var invertido = "";
	for ( i=(largo-1),j=0; i>=0; i--,j++ )
		invertido = invertido + rut.charAt(i);
	var drut = "";
	drut = drut + invertido.charAt(0);
	drut = drut + '-';
	cnt = 0;
	for ( i=1,j=2; i<largo; i++,j++ )
	{
		if ( cnt == 3 )
		{
			drut = drut + '.';
			j++;
			drut = drut + invertido.charAt(i);
			cnt = 1;
		}
		else
		{
			drut = drut + invertido.charAt(i);
			cnt++;
		}
	}
	invertido = "";
	for ( i=(drut.length-1),j=0; i>=0; i--,j++ )
		invertido = invertido + drut.charAt(i);
	obj.value = invertido;
	if (!checkDV(rut)) {
		//alert("EL rut es incorrecto.");
		//obj.focus();
		//obj.value = "";
		arguments.IsValid=false;
		return;
		//return false;
	}
	return true;
}
function checkDV( crut )
{
	largo = crut.length;
	if ( largo < 2 )
	{
		//alert("Debe ingresar el rut completo.");
		//obj.focus();
		//obj.select();
		arguments.IsValid=false;
		return;
		//return false;
	}
	if ( largo > 2 )
		rut = crut.substring(0, largo - 1);
	else
		rut = crut.charAt(0);
	dv = crut.charAt(largo-1);
	checkCDV( dv );
	if ( rut == null || dv == null )
		return 0;
	var dvr = '0';
	suma = 0;
	mul = 2;
	for (i= rut.length -1 ; i >= 0; i--)
	{
		suma = suma + rut.charAt(i) * mul;
		if (mul == 7)
			mul = 2;
		else
			mul++;
	}
	res = suma % 11;
	if (res==1)
		dvr = 'k';
	else if (res==0)
		dvr = '0';
	else
	{
		dvi = 11-res;
		dvr = dvi + "";
	}
	if ( dvr != dv.toLowerCase() )
	{
		return false;
	}
	arguments.IsValid=true;
	return true;
	//return true;
}
function checkCDV( dvr )
{
	dv = dvr + "";
	if ( dv != '0' && dv != '1' && dv != '2' && dv != '3' && dv != '4' && dv != '5' && dv != '6' && dv != '7' && dv != '8' && dv != '9' && dv != 'k'  && dv != 'K')
	{
		//alert("Debe ingresar un digito verificador valido.");
		//obj.focus();
		//obj.select();
		arguments.IsValid=false;
		return false;
	}
	arguments.IsValid=true;
	return true;
	//return true;
}
function click() {
	if (event.button==2 || event.button==1 || event.button==3) {
		return;
	}
}
function only_number(e){
var keynum
var keychar
var numcheck
if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
if (keynum >= 48 && keynum <= 57){
	return true; 
} else{
	return false; 
}
}
function set_resolutor_from_carga(id){
	var pdoc = window.opener.document.Form1;
	
	if (Form1.txtDesde.value == "GPlan")
	{
        var combo=pdoc.ddlAgentePropuesto;
        pdoc.txtIdAgentePropuesto.value=id;
        for(i=0;i<combo.options.length;i++){
           if(combo[i].value==id){
              combo.selectedIndex=i;
              return;
           }
        }
	}
	else
	{
        var combo=pdoc.ddlAsignadoA;
        pdoc.txtIdResolutor.value=id;
        for(i=0;i<combo.options.length;i++){
           if(combo[i].value==id){
              combo.selectedIndex=i;
              return;
           }
        }
	}
}
function open_carga_trabajo(){
	var doc = document.Form1;
	if(doc.txtIdGrupoResolutor.value=='0'){
		return;
	}
	window.open('Carga_Trabajo_Grupo.aspx?id='+doc.txtIdGrupoResolutor.value,'CARGA','width=620,height=450,top=50,left=50,scrollbars=1,resizable=1');
}
function pasa_usuario(id,nom){
	window.opener.document.Form1.txtNomUsuario.value=nom;
	window.opener.document.Form1.txtIdUsuario.value=id;
}
function pasa_responsableproveedor(id,nom){
	window.opener.document.Form1.txtResponsableProveedor.value=nom;
	window.opener.document.Form1.txtIdUsuarioR.value=id;
}
function pasa_catalogo(id, descomp)
{
 window.opener.document.Form1.txtIdCatalogo.value = id;
 window.opener.document.Form1.txtCatalogo.value = descomp;
}
function pasa_mail(mail){
	window.opener.document.Form1.txtDirMail.value=mail;
}
function pasa_sitio(id,nom){
	window.opener.document.getElementById("dgPersonas__ctl2_txtSitio").value=nom;
	window.opener.document.getElementById("dgPersonas__ctl2_txtIdSitio").value=id;
}
function pasa_sitio_ot_comp(id,nom){
	window.opener.document.getElementById("dgComponentes__ctl2_txtSitio").value=nom;
	window.opener.document.getElementById("dgComponentes__ctl2_txtIdSitio").value=id;
}
function pasa_responsable(id,nom){
	window.opener.document.getElementById("dgComponentes__ctl2_txtPersona").value=nom;
	window.opener.document.getElementById("dgComponentes__ctl2_txtIdPersona").value=id;
}
function pasa_sitio_ot(id,nom,item){
	window.opener.document.getElementById("dgEventos__ctl" + item + "_lblSitioId").innerHTML=nom;
	window.opener.document.getElementById("dgEventos__ctl" + item + "_txtSitioId").value=id;
}
function pasa_sitio_inv(id,nom){
	window.opener.document.Form1.txtNomSitio.value=nom;
	window.opener.document.Form1.txtIdSitio.value=id;
}
function pasa_pcinstalacionsitio(id,nom,serie,marca,modelo,procesador,dd,ram,cd){
window.opener.document.Form1.txtIdEquipo.value=id;
window.opener.document.Form1.txtSerie.value=serie;
window.opener.document.Form1.txtIdentificacion.value=nom;
window.opener.document.Form1.txtMarca.value=marca;
window.opener.document.Form1.txtModelo.value=modelo;
window.opener.document.Form1.txtProcesador.value=procesador;
window.opener.document.Form1.txtRam.value=ram;
window.opener.document.Form1.txtDD.value=dd;
window.opener.document.Form1.txtCD.value=cd;
}
function pasa_usuarioinstalacion(id,nom,mail,idgerencia,idcargo,cargo,telefono,rut){
	window.opener.document.Form1.txtNomUsuario.value=nom;
	window.opener.document.Form1.txtIdUsuario.value=id;
	window.opener.document.Form1.txtIdCargo.value=idcargo;
	window.opener.document.Form1.txtCargo.value=cargo;
	window.opener.document.Form1.txtTelefono.value=telefono;
	window.opener.document.Form1.txtMail.value=mail;
	window.opener.document.Form1.ddlUnidad.value=idgerencia;
	window.opener.document.Form1.txtRutUsuario.value=rut;
window.opener.document.Form1.txtNomUsuario.readOnly='True';
window.opener.document.Form1.txtCargo.readOnly='True';
	
}
function pasa_cargo(id, nombre)
{
	window.opener.document.Form1.txtCargo.value=nombre;
window.opener.document.Form1.txtIdCargo.value=id;
window.opener.document.Form1.txtCargo.readOnly='True';
}
function pasa_instalador(id, nombre,rut)
{
	window.opener.document.Form1.txtInstaladorOlidata.value=nombre;
	window.opener.document.Form1.txtIdInstaladorOlidata.value=id;
	window.opener.document.Form1.txtRutOlidata.value=rut;
	window.opener.document.Form1.txtInstaladorOlidata.readOnly='True';

}
function pasa_encargado(id, nombre,rut)
{
	window.opener.document.Form1.txtEncargadoMinsal.value=nombre;
	window.opener.document.Form1.txtIdEncargadoMinsal.value=id;
	window.opener.document.Form1.txtRUTEncargadoMinsal.value=rut;
		window.opener.document.Form1.txtEncargadoMinsal.readOnly='True';
	
}

function pasa_solicitante(id,nom){
	window.opener.document.Form1.txtSolicitante.value=nom;
	window.opener.document.Form1.txtIdSolicitante.value=id;
}

function calcula_esfuerzo_remoto(){
	var doc = document.Form1;
	var hrPrepCoord;
	if(doc.ddlHoraPrepCoord.value==""){
		hrPrepCoord=0;
	}else{
		var horaPC=doc.ddlHoraPrepCoord.value;
		if(horaPC.substring(0,1)=="0" && horaPC != "0"){
			horaPC=horaPC.substring(1,horaPC.length)
		}
		
		hrPrepCoord=parseInt(horaPC);
	}
	var minPrepCoord;
	if(doc.ddlMinPrepCoord.value==""){
		minPrepCoord=0;
	}else{
		var minPC=doc.ddlMinPrepCoord.value;
		if(minPC.substring(0,1)=="0" && minPC != "0"){
			minPC=minPC.substring(1,minPC.length)
		}
		minPrepCoord=parseInt(minPC);
	}
	var hrEjecucion;
	if(doc.ddlHoraEjecucion.value==""){
		hrEjecucion=0;
	}else{
		var horaEj=doc.ddlHoraEjecucion.value;
		if(horaEj.substring(0,1)=="0" && horaEj != "0"){
			horaEj=horaEj.substring(1,horaEj.length)
		}
		hrEjecucion=parseInt(horaEj);
	}
	var minEjecucion;
	if(doc.ddlMinEjecucion.value==""){
		minEjecucion=0;
	}else{
		var minEj=doc.ddlMinEjecucion.value;
		if(minEj.substring(0,1)=="0" && minEj != "0"){
			minEj=minEj.substring(1,minEj.length)
		}
		minEjecucion=parseInt(minEj);
	}
	//var hrTraslado=parseInt(doc.ddlHoraTraslado.value);
	//var minTraslado=parseInt(doc.ddlMinTraslado.value);
	var hrEspera;
	if(doc.ddlHoraEspera.value==""){
		hrEspera=0;
	}else{
		var horaEsp=doc.ddlHoraEspera.value;
		if(horaEsp.substring(0,1)=="0" && horaEsp != "0"){
			horaEsp=horaEsp.substring(1,horaEsp.length)
		}
		hrEspera=parseInt(horaEsp);
	}
	var minEspera;
	if(doc.ddlMinEspera.value==""){
		minEspera=0;
	}else{
		var minEsp=doc.ddlMinEspera.value;
		if(minEsp.substring(0,1)=="0" && minEsp != "0"){
			minEsp=minEsp.substring(1,minEsp.length)
		}
		minEspera=parseInt(minEsp);
	}
	

	if(hrPrepCoord > 0){
		hrPrepCoord=(hrPrepCoord * 60);
	}
	if(hrEjecucion > 0){
		hrEjecucion=(hrEjecucion * 60);
	}
	/*if(hrTraslado > 0){
		hrTraslado=(hrTraslado * 60);
	}*/
	if(hrEspera > 0){
		hrEspera=(hrEspera * 60);
	}
	//var total_minutos=hrPrepCoord + minPrepCoord + hrEjecucion + minEjecucion + hrTraslado + minTraslado + hrEspera + minEspera;
	var total_minutos=hrPrepCoord + minPrepCoord + hrEjecucion + minEjecucion + hrEspera + minEspera;
	if(total_minutos>0){
		var parte_entera=parseInt(total_minutos / 60);
		var parte_decimal=(total_minutos / 60) - parte_entera;
		var strHora = parte_entera.toString() + " h ";
		var strMins = (Math.round(parte_decimal * 60)).toString() + " m";
		doc.txtTotalReal.value=strHora + strMins;
		doc.txtMinutosEsfuerzoRemoto.value=total_minutos.toString();
	}else{
		doc.txtTotalReal.value="0 h 0 m";
		doc.txtMinutosEsfuerzoRemoto.value="0";
	}
	
	
}
function calcula_esfuerzo_terreno()
{
 var doc = document.Form1;
 var today = new Date();
 var Horas = 0;
 var Minutos = 0;
 var Total_Minutos = 0;
 doc.txtEjecucionterreno.value = "";
 doc.txtTotalRealTerr.value = "0 h 0 m";
 // ******* Minutos Preparación	
 var Total_Minutos_Preparacion = 0;
 var horaPrep = 0;
 var txt = "";
 if (Trim(doc.ddlHoraPrepCoordTerr.value) != "")
 {
    txt = doc.ddlHoraPrepCoordTerr.value;
    if (Trim(txt) == "")
    {
       txt = "0";
    }
    if (txt.substring(0, 1) == "0" && txt != "0")
    {
       txt = txt.substring(1, txt.length)
	}
    horaPrep = parseInt(txt);
 }
 var minPrep = 0;
 if (Trim(doc.ddlMinPrepCoordTerr.value) != "")
 {
    txt = doc.ddlMinPrepCoordTerr.value;
    if (Trim(txt) == "")
    {
       txt = "0";
    }
    if (txt.substring(0, 1) == "0" && txt != "0")
    {
       txt = txt.substring(1, txt.length)
	}
    minPrep = parseInt(txt);
 }
 Horas = horaPrep;
 Minutos = minPrep;
 Total_Minutos_Preparacion = (Horas * 60) + Minutos;
 // ******* Minutos Espera
 var Total_Minutos_Espera = 0;
 var horaEsp = 0;
 var minEsp = 0;
 Horas = 0;
 Minutos = 0;
 if (Trim(doc.ddlHoraEsperaTerr.value) != "")
 {
    txt = doc.ddlHoraEsperaTerr.value;
    if (Trim(txt) == "")
    {
       txt = "0";
    }
    if (txt.substring(0, 1) == "0" && txt != "0")
    {
       txt = txt.substring(1, txt.length)
	}
    horaEsp = parseInt(txt);
 }
 if (Trim(doc.ddlMinEsperaTerr.value) != "")
 {
    txt = doc.ddlMinEsperaTerr.value;
    if (Trim(txt) == "")
    {
       txt = "0";
    }
    if (txt.substring(0, 1) == "0" && txt != "0")
    {
       txt = txt.substring(1, txt.length)
	}
    minEsp = parseInt(txt);
 }
 Horas = horaEsp;
 Minutos = minEsp;
 Total_Minutos_Espera = (Horas * 60) + Minutos;
 // ******* FECHA TRASLADO IDA
 var Total_Minutos_Traslado_Ida = 0;
 if (doc.txtHrIniTrasladoIdaTerr.value != "" && doc.txtMinIniTrasladoIdaTerr.value != "" && doc.txtHrFinTrasladoIdaTerr.value != "" && doc.txtMinFinTrasladoIdaTerr.value != "")
 {
    var horaIniTrasIda = 0;
    if (Trim(doc.txtHrIniTrasladoIdaTerr.value) != "0")
    {
       txt = doc.txtHrIniTrasladoIdaTerr.value;
       if (Trim(txt) == "")
       {
          txt = "0";
       }
       if (txt.substring(0, 1) == "0" && txt != "0")
       {
          txt = txt.substring(1, txt.length)
	   }
       horaIniTrasIda = parseInt(txt);
    }
    var minIniTrasIda = 0;
    if (Trim(doc.txtMinIniTrasladoIdaTerr.value) != "0")
    {
       txt = doc.txtMinIniTrasladoIdaTerr.value;
       if (Trim(txt) == "")
       {
          txt = "0";
       }
       if (txt.substring(0, 1) == "0" && txt != "0")
       {
          txt = txt.substring(1, txt.length)
	   }
       minIniTrasIda = parseInt(txt);
    }
    var horaFinTrasIda = 0;
    if (Trim(doc.txtHrFinTrasladoIdaTerr.value) != "0")
    {
       txt = doc.txtHrFinTrasladoIdaTerr.value;
       if (Trim(txt) == "")
       {
          txt = "0";
       }
       if (txt.substring(0, 1) == "0" && txt != "0")
       {
          txt = txt.substring(1, txt.length)
	   }
       horaFinTrasIda = parseInt(txt);
    }
    var minFinTrasIda = 0;
    if (Trim(doc.txtMinFinTrasladoIdaTerr.value) != "0")
    {
       txt = doc.txtMinFinTrasladoIdaTerr.value;
       if (Trim(txt) == "")
       {
          txt = "0";
       }
       if (txt.substring(0, 1) == "0" && txt != "0")
       {
          txt = txt.substring(1, txt.length)
	   }
       minFinTrasIda = parseInt(txt);
    }
    var Fecha_Ini_Traslado_Ida = new Date(today.getFullYear(), today.getMonth(), today.getDay(), horaIniTrasIda, minIniTrasIda, "0");
    var Fecha_Fin_Traslado_Ida = new Date(today.getFullYear(), today.getMonth(), today.getDay(), horaFinTrasIda, minFinTrasIda, "0");
    if (Fecha_Fin_Traslado_Ida <= Fecha_Ini_Traslado_Ida)
    {
       return false;
    }
    Total_Minutos_Traslado_Ida = Math.ceil(((Date.parse(Fecha_Fin_Traslado_Ida) - Date.parse(Fecha_Ini_Traslado_Ida)) / 1000) / 60);
 }
 // ******* FECHA EJECUCIÓN
 var Total_Minutos_Ejecucion = 0;
 if (doc.txtHrIniEjecTerr.value != "" && doc.txtMinIniEjecTerr.value != "" && doc.txtHrFinEjecTerr.value != "" && doc.txtMinFinEjecTerr.value != "")
 {
    var horaIniEj = 0;
    if (Trim(doc.txtHrIniEjecTerr.value) != "0")
    {
       txt = doc.txtHrIniEjecTerr.value;
       if (Trim(txt) == "")
       {
          txt = "0";
       }
       if (txt.substring(0, 1) == "0" && txt != "0")
       {
          txt = txt.substring(1, txt.length)
	   }
       horaIniEj = parseInt(txt);
    }
    var minIniEj = 0;
    if (Trim(doc.txtMinIniEjecTerr.value) != "0")
    {
       txt = doc.txtMinIniEjecTerr.value;
       if (Trim(txt) == "")
       {
          txt = "0";
       }
       if (txt.substring(0, 1) == "0" && txt != "0")
       {
          txt = txt.substring(1, txt.length)
	   }
       minIniEj = parseInt(txt);
    }
    var horaFinEj = 0;
    if (Trim(doc.txtHrFinEjecTerr.value) != "0")
    {
       txt = doc.txtHrFinEjecTerr.value;
       if (Trim(txt) == "")
       {
          txt = "0";
       }
       if (txt.substring(0, 1) == "0" && txt != "0")
       {
          txt = txt.substring(1, txt.length)
	   }
       horaFinEj = parseInt(txt);
    }
    var minFinEj = 0;
    if (Trim(doc.txtMinFinEjecTerr.value) != "0")
    {
       txt = doc.txtMinFinEjecTerr.value;
       if (Trim(txt) == "")
       {
          txt = "0";
       }
       if (txt.substring(0, 1) == "0" && txt != "0")
       {
          txt = txt.substring(1, txt.length)
	   }
       minFinEj = parseInt(txt);
    }
    var Fecha_Ini_Ejecucion = new Date(today.getFullYear(), today.getMonth(), today.getDay(), horaIniEj, minIniEj, "0");
    var Fecha_Fin_Ejecucion = new Date(today.getFullYear(), today.getMonth(), today.getDay(), horaFinEj, minFinEj, "0");
    if (Fecha_Fin_Ejecucion <= Fecha_Ini_Ejecucion)
    {
       return false;
    }
    Total_Minutos_Ejecucion = Math.ceil(((Date.parse(Fecha_Fin_Ejecucion) - Date.parse(Fecha_Ini_Ejecucion)) / 1000) / 60);
    doc.txtEjecucionterreno.value = "OK";
 }
 // ******* FECHA TRASLADO VUELTA
 var Total_Minutos_Traslado_Vuelta = 0;
 if (doc.txtHrIniTrasladoVueltaTerr.value != "" && doc.txtMinIniTrasladoVueltaTerr.value != "" && doc.txtHrFinTrasladoVueltaTerr.value != "" && doc.txtMinFinTrasladoVueltaTerr.value != "")
 {
    var horaIniTr = 0;
    if (Trim(doc.txtHrIniTrasladoVueltaTerr.value) != "0")
    {
       txt = doc.txtHrIniTrasladoVueltaTerr.value;
       if (Trim(txt) == "")
       {
          txt = "0";
       }
       if (txt.substring(0, 1) == "0" && txt != "0")
       {
          txt = txt.substring(1, txt.length)
	   }
       horaIniTr = parseInt(txt);
    }
    var minIniTr = 0;
    if (Trim(doc.txtMinIniTrasladoVueltaTerr.value) != "0")
    {
       txt = doc.txtMinIniTrasladoVueltaTerr.value;
       if (Trim(txt) == "")
       {
          txt = "0";
       }
       if (txt.substring(0, 1) == "0" && txt != "0")
       {
          txt = txt.substring(1, txt.length)
	   }
       minIniTr = parseInt(txt);
    }
    var horaFinTr = 0;
    if (Trim(doc.txtHrFinTrasladoVueltaTerr.value) != "0")
    {
       txt = doc.txtHrFinTrasladoVueltaTerr.value;
       if (Trim(txt) == "")
       {
          txt = "0";
       }
       if (txt.substring(0, 1) == "0" && txt != "0")
       {
          txt = txt.substring(1, txt.length)
	   }
       horaFinTr = parseInt(txt);
    }
    var minFinTr = 0;
    if (Trim(doc.txtMinFinTrasladoVueltaTerr.value) != "0")
    {
       txt = doc.txtMinFinTrasladoVueltaTerr.value;
       if (Trim(txt) == "")
       {
          txt = "0";
       }
       if (txt.substring(0, 1) == "0" && txt != "0")
       {
          txt = txt.substring(1, txt.length)
	   }
       minFinTr = parseInt(txt);
    }
    var Fecha_Ini_Traslado_Vuelta = new Date(today.getFullYear(), today.getMonth(), today.getDay(), horaIniTr, minIniTr, "0");
    var Fecha_Fin_Traslado_Vuelta = new Date(today.getFullYear(), today.getMonth(), today.getDay(), horaFinTr, minFinTr, "0");
    if (Fecha_Fin_Traslado_Vuelta <= Fecha_Ini_Traslado_Vuelta)
    {
       return false;
    }
    Total_Minutos_Traslado_Vuelta = Math.ceil(((Date.parse(Fecha_Fin_Traslado_Vuelta) - Date.parse(Fecha_Ini_Traslado_Vuelta)) / 1000) / 60);
 }
 var Total_Minutos = 0;
 var Total_Horas = 0;
 Total_Minutos = Total_Minutos_Preparacion + Total_Minutos_Espera + Total_Minutos_Traslado_Ida + Total_Minutos_Ejecucion + Total_Minutos_Traslado_Vuelta;
 Total_Horas = Math.floor(Total_Minutos / 60);
 Total_Minutos = Total_Minutos - (Total_Horas * 60);
 doc.txtTotalRealTerr.value = String(Total_Horas) + " h " + String(Total_Minutos) + " m";
 return true;
}

function valida_esfuerzos_terreno()
{
 var doc = document.Form1;
 var today = new Date();
 var Horas = 0;
 var Minutos = 0;
 var Total_Minutos = 0;
 // ******* FECHA TRASLADO IDA
 var Total_Minutos_Traslado_Ida = 0;
 if (doc.txtHrIniTrasladoIdaTerr.value != "" && doc.txtMinIniTrasladoIdaTerr.value != "" && doc.txtHrFinTrasladoIdaTerr.value != "" && doc.txtMinFinTrasladoIdaTerr.value != "")
 {
    var horaIniTrasIda = doc.txtHrIniTrasladoIdaTerr.value;
    if (horaIniTrasIda.substring(0, 1) == "0" && horaIniTrasIda != "0")
    {
       horaIniTrasIda = horaIniTrasIda.substring(1, horaIniTrasIda.length);
    }
    var minIniTrasIda = doc.txtMinIniTrasladoIdaTerr.value;
    if (minIniTrasIda.substring(0, 1) == "0" && minIniTrasIda != "0")
    {
       minIniTrasIda = minIniTrasIda.substring(1, minIniTrasIda.length);
    }
    var horaFinTrasIda = doc.txtHrFinTrasladoIdaTerr.value;
    if (horaFinTrasIda.substring(0, 1) == "0" && horaFinTrasIda != "0")
    {
       horaFinTrasIda = horaFinTrasIda.substring(1, horaFinTrasIda.length);
    }
    var minFinTrasIda = doc.txtMinFinTrasladoIdaTerr.value;
    if (minFinTrasIda.substring(0, 1) == "0" && minFinTrasIda != "0")
    {
       minFinTrasIda = minFinTrasIda.substring(1, minFinTrasIda.length);
    }
    var Fecha_Ini_Traslado_Ida = new Date(today.getFullYear(), today.getMonth(), today.getDay(), parseInt(horaIniTrasIda), parseInt(minIniTrasIda), "0");
    var Fecha_Fin_Traslado_Ida = new Date(today.getFullYear(), today.getMonth(), today.getDay(), parseInt(horaFinTrasIda), parseInt(minFinTrasIda), "0");
    if (Fecha_Fin_Traslado_Ida <= Fecha_Ini_Traslado_Ida)
    {
       alert(document.getElementById("lblErrorFecFinTrasIdaMayorInicio").innerHTML);
       doc.txtHrFinTrasladoIdaTerr.value = "";
       doc.txtMinFinTrasladoIdaTerr.value = "";
       doc.txtHrFinTrasladoIdaTerr.focus();
       return false;
    }
 }
 // ******* FECHA EJECUCIÓN
 var Total_Minutos_Ejecucion = 0;
 if (doc.txtHrIniEjecTerr.value != "" && doc.txtMinIniEjecTerr.value != "" && doc.txtHrFinEjecTerr.value != "" && doc.txtMinFinEjecTerr.value != "")
 {
    var horaIniEj = doc.txtHrIniEjecTerr.value;
    if (horaIniEj.substring(0, 1) == "0" && horaIniEj != "0")
    {
       horaIniEj = horaIniEj.substring(1, horaIniEj.length);
    }
    var minIniEj = doc.txtMinIniEjecTerr.value;
    if (minIniEj.substring(0, 1) == "0" && minIniEj != "0")
    {
       minIniEj = minIniEj.substring(1, minIniEj.length);
    }
    var horaFinEj = doc.txtHrFinEjecTerr.value;
    if (horaFinEj.substring(0,1) == "0" && horaFinEj != "0")
    {
       horaFinEj = horaFinEj.substring(1, horaFinEj.length);
    }
    var minFinEj = doc.txtMinFinEjecTerr.value;
    if (minFinEj.substring(0,1) == "0" && minFinEj != "0")
    {
       minFinEj = minFinEj.substring(1, minFinEj.length);
    }
    var Fecha_Ini_Ejecucion = new Date(today.getFullYear(), today.getMonth(), today.getDay(), parseInt(horaIniEj), parseInt(minIniEj), "0");
    var Fecha_Fin_Ejecucion = new Date(today.getFullYear(), today.getMonth(), today.getDay(), parseInt(horaFinEj), parseInt(minFinEj), "0");
    if (Fecha_Fin_Ejecucion <= Fecha_Ini_Ejecucion)
    {
       alert(document.getElementById("lblErrorFecFinEjecMayorInicio").innerHTML);
       doc.txtHrFinEjecTerr.value = "";
       doc.txtMinFinEjecTerr.value = "";
       doc.txtHrFinEjecTerr.focus();
       return false;
    }
    doc.txtEjecucionterreno.value = "OK";
 }
 // ******* FECHA TRASLADO VUELTA
 if (doc.txtHrIniTrasladoVueltaTerr.value != "" && doc.txtMinIniTrasladoVueltaTerr.value != "" && doc.txtHrFinTrasladoVueltaTerr.value != "" && doc.txtMinFinTrasladoVueltaTerr.value != "")
 {
    var horaIniTr = doc.txtHrIniTrasladoVueltaTerr.value;
    if (horaIniTr.substring(0, 1) == "0" && horaIniTr != "0")
    {
       horaIniTr = horaIniTr.substring(1, horaIniTr.length)
    }
    var minIniTr = doc.txtMinIniTrasladoVueltaTerr.value;
    if (minIniTr.substring(0, 1) == "0" && minIniTr != "0")
    {
       minIniTr = minIniTr.substring(1, minIniTr.length);
    }
    var horaFinTr = doc.txtHrFinTrasladoVueltaTerr.value;
    if (horaFinTr.substring(0, 1) == "0" && horaFinTr != "0")
    {
       horaFinTr = horaFinTr.substring(1, horaFinTr.length);
    }
    var minFinTr = doc.txtMinFinTrasladoVueltaTerr.value;
    if (minFinTr.substring(0, 1) == "0" && minFinTr != "0")
    {
       minFinTr = minFinTr.substring(1, minFinTr.length);
    }
    var Fecha_Ini_Traslado_Vuelta = new Date(today.getFullYear(), today.getMonth(), today.getDay(), parseInt(horaIniTr), parseInt(minIniTr), "0");
    var Fecha_Fin_Traslado_Vuelta = new Date(today.getFullYear(), today.getMonth(), today.getDay(), parseInt(horaFinTr), parseInt(minFinTr), "0");
    if (Fecha_Fin_Traslado_Vuelta <= Fecha_Ini_Traslado_Vuelta)
    {
       alert(document.getElementById("lblErrorFecFinTrasVueltaMayorInicio").innerHTML);
       doc.txtHrFinTrasladoVueltaTerr.value = "";
       doc.txtMinFinTrasladoVueltaTerr.value = "";
       doc.txtHrFinTrasladoVueltaTerr.focus();
       return false;
    }
 }
 // ******* Valida Fecha Fin de Traslado Ida no sea mayor a la Fecha de Inicio Ejecución
 if (doc.txtHrFinTrasladoIdaTerr.value != "" && doc.txtMinFinTrasladoIdaTerr.value != "" && doc.txtHrIniEjecTerr.value != "" && doc.txtMinIniEjecTerr.value != "")
 {
    var Fecha_Fin_Traslado_Ida = new Date(today.getFullYear(), today.getMonth(), today.getDay(), parseInt(doc.txtHrFinTrasladoIdaTerr.value), parseInt(doc.txtMinFinTrasladoIdaTerr.value), "0");
    var Fecha_Ini_Ejecucion = new Date(today.getFullYear(), today.getMonth(), today.getDay(), parseInt(doc.txtHrIniEjecTerr.value), parseInt(doc.txtMinIniEjecTerr.value), "0");
    if (Fecha_Ini_Ejecucion <= Fecha_Fin_Traslado_Ida)
    {
       alert(document.getElementById("lblErrorFecFinTrasIdaMenorEjecIni").innerHTML);
       doc.txtHrFinTrasladoIdaTerr.value = "";
       doc.txtMinFinTrasladoIdaTerr.value = "";
       doc.txtHrFinTrasladoIdaTerr.focus();
       return false;
    }
 }
 // ******* Valida Fecha Fin de Ejecución no sea mayor a la Fecha de Inicio Traslado Vuelta
 if (doc.txtHrFinEjecTerr.value != "" && doc.txtMinFinEjecTerr.value != "" && doc.txtHrIniTrasladoVueltaTerr.value != "" && doc.txtMinIniTrasladoVueltaTerr.value != "")
 {
    var Fecha_Fin_Ejecucion = new Date(today.getFullYear(), today.getMonth(), today.getDay(), parseInt(doc.txtHrFinEjecTerr.value), parseInt(doc.txtMinFinEjecTerr.value), "0");
    var Fecha_Ini_Traslado_Vuelta = new Date(today.getFullYear(), today.getMonth(), today.getDay(), parseInt(doc.txtHrIniTrasladoVueltaTerr.value), parseInt(doc.txtMinIniTrasladoVueltaTerr.value), "0");
    if (Fecha_Ini_Traslado_Vuelta <= Fecha_Fin_Ejecucion)
    {
       alert(document.getElementById("lblErrorFecFinEjecMenorTrasVueltaIni").innerHTML);
       doc.txtHrFinEjecTerr.value = "";
       doc.txtMinFinEjecTerr.value = "";
       doc.txtHrFinEjecTerr.focus();
       return false;
    }
 }
 return true;
}
function valida_remoto(source,arguments){
	var doc = document.Form1;
	var hrEjecucion=parseInt(doc.ddlHoraEjecucion.value);
	var minEjecucion=parseInt(doc.ddlMinEjecucion.value);
	if(hrEjecucion==0 && minEjecucion==0){
		arguments.IsValid=false;
		return;
	}
	arguments.IsValid=true;
	return true;
}
function setImagen(idObj,valor){	
	if (valor==""){
		document.getElementById(idObj).style.display="none";
		document.getElementById(idObj).src="";	
	}else{
		document.getElementById(idObj).style.display="block";
		document.getElementById(idObj).src="../../imagenes/mails/"+valor;	
	}
}
function setImagenMarketing(idObj,valor){	
	if (valor==""){
		document.getElementById(idObj).style.display="none";
		document.getElementById(idObj).src="";	
	}else{
		document.getElementById(idObj).style.display="block";
		document.getElementById(idObj).src="marketing/imagenes/"+valor;	
	}
}
function edita_campo_notif(id){
	location.href="campo_notificacion.aspx?ordenInt=NO&id=" +id;
}
/*function only_number(){
	if (event.keyCode >= 48 && event.keyCode <= 57){
		return true; 
	} else{
		return false; 
	}
}*/

// Mostrar y Ocultar Layer con empresas 
function toggleBox(szDivID, iState,idEmpresa,nomempresa) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
       document.layers[szDivID].visibility = iState ? "show" : "hide";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
    if (idEmpresa>0){
		document._ctl0.txtIdEmpresa.value=idEmpresa;
		document._ctl0.btnChangeEmpresa.click();
    }
    //cambia_logo_empresa(nomempresa);
    
}
function unperfil(){
	document._ctl0.btnUnperfil.click();
}

function Busca_Elemento_Combo(Combo, Valor)
{
 for (Contador=0; Contador < window.opener.document.Form1.ddlNivel1.length; Contador++)
 {
     if (Combo.options[Contador].value == Valor)
     {
        Combo.selectedIndex = Contador;
     }
 }
}
function validaPadreComponente(source, arguments){
	var idOld=document.Form1.txtComponenteId.value;
	var idNew=document.Form1.txtCompPadreId.value;
	if(idOld==idNew && idOld != "0"){
		arguments.IsValid=false;
		return false;		
	}else{
		arguments.IsValid=true;
		return true;
	}
}
function validaPadreHijoComponente(source, arguments){
	for(i=0;i<arrHijos.length;i++){
		if(document.Form1.txtCompPadreId.value==arrHijos[i] && (parseInt(document.Form1.txtCompPadreId.value)>0 && document.Form1.txtCompPadreId.value != "")){
			arguments.IsValid=false;
			return false;		
		}
	}
	arguments.IsValid=true;
	return true;

}

function openurl(url,newwin){
var numPosibilidades=23.2;
aleat = Math.random() * numPosibilidades;
aleat = Math.round(aleat);
var numPosibilidades=25.33;
aleat2 = Math.random() * numPosibilidades;
aleat2 = Math.round(aleat);
aleat3=aleat+aleat2;
	if(newwin){
		window.open(url,"NEWWIN_"+aleat3.toString(),"top=10,left=10,width=900,height=650,scrollbars=1,resizable=0");
	}else{
		self.location.href=url;
	}
}
function cambia_logo_empresa(logo){
	document.getElementById("logoempresatop").src="imagenes/logosempresas/" + logo + ".jpg";
}

function openurl_ventanagrande(url,newwin){
	if(newwin){
		window.open(url,"COMP","width=800,height=800,scrollbars=1,resizable=0");
	}else{
		self.location.href=url;
	}
}
function openurlmaxresolucion(url){
	window.open(url,"WOP","width="+(screen.availWidth-25)+",height="+(screen.availHeight-40)+",top=0,left=0,scrollbars=1,resizable=0");
}
function openurl_ventanachica(url,newwin){
	if(newwin){
		window.open(url,"SCR","width=800,height=300,top=0,left=0,scrollbars=1,resizable=1");
	}else{
		self.location.href=url;
	}
}
function pasa_resolutor(id,nom){
	window.opener.document.Form1.txtNombreResolutor.value=nom;
	window.opener.document.Form1.txtIdResolutor.value=id;
}

function borrasolucion()
 {
 var doc = document.Form1;
 doc.txtReferencia.value="";
 doc.txtDescSolucion.value="";
 FTB_API['ftbDescSolucion'].SetHtml('');
 FTB_API['ftbDescSolucion'].Habilitar('');
 doc.txtSolucionCatalogoId.value="";
 doc.txtReferencia.readOnly='';
 doc.txtReferencia.focus();
 doc.btnHabilitarSolucion.style.display="none";
 }
 
 function habilitarsolucion()
 {
 var doc = document.Form1;
 FTB_API['ftbDescSolucion'].Habilitar('');
 doc.txtReferencia.readOnly='';
 doc.btnHabilitarSolucion.style.display="none";
 doc.txtSolucionCatalogoId.value="";
 }
// FUNCION PARA MOSTRAR / OCULTAR LAYER, Y CROSSBROWSER MAS ENCIMA
//REPORTES DINAMICOS
function genera_sql(){
	try{
		document.Form1.txtWhere.value="";
		var sql ="";
		var filtro="";
		var valor="";
		var valor2="";
		var objetos = document.getElementsByTagName('input');
		var objetos2 = document.getElementsByTagName('select');
		var filtrosPDF="";
		var valorTxt="";
		for (i=0;i<objetos2.length;i++){
			if (objetos2[i].datatype=='int' && objetos2[i].fltdin=='True'){
				filtro=objetos2[i].filtro;
				valorTxt=eval("document.Form1."+filtro+"[document.Form1."+filtro+".selectedIndex].text");
				valor=eval("document.Form1."+filtro+".value");
				if (valor != ''){
					if(sql==""){
						sql = sql + " (" + filtro + " = " + valor + ") ";
						filtrosPDF=filtro+"|"+valorTxt;
					}else{
						sql = sql + " and (" + filtro + " = " + valor + ") ";	
						filtrosPDF=filtrosPDF+";"+filtro+"|"+valorTxt;
					}
				}
			}
		}
		for (i=0;i<objetos.length;i++){
			if (objetos[i].datatype=='datetime' && objetos[i].fltdin=='True' && objetos[i].tiporango=='desde'){
				filtro=objetos[i].filtro;
				valor=eval("document.Form1."+filtro+"_desde.value");
				valor2=eval("document.Form1."+filtro+"_hasta.value");
				if (valor != ''){
					if(sql==""){
						sql = sql + " (" + filtro + " between '" + formatea_fecha_db(valor) + " 00:00:00' and ";
						if(filtrosPDF==''){
							filtrosPDF=filtro+" " +document.getElementById('lblDesde').innerHTML+"|"+valor;
						}else{
							filtrosPDF=filtrosPDF+";"+filtro+" " +document.getElementById('lblDesde').innerHTML+"|"+valor;
						}
					}else{
						sql = sql + " and (" + filtro + " between '" + formatea_fecha_db(valor) + " 00:00:00' and ";
						if(filtrosPDF==''){
							filtrosPDF=filtro+" " +document.getElementById('lblDesde').innerHTML+"|"+valor;
						}else{
							filtrosPDF=filtrosPDF+";"+filtro+" " +document.getElementById('lblDesde').innerHTML+"|"+valor;
						}
					}
					
					if(valor2 != ""){
						sql = sql + "'" + formatea_fecha_db(valor2) + " 23:59:59') ";
						if(filtrosPDF==''){
							filtrosPDF=filtro+" " +document.getElementById('lblHasta').innerHTML+"|"+valor2;
						}else{
							filtrosPDF=filtrosPDF+";"+filtro+" " +document.getElementById('lblHasta').innerHTML+"|"+valor2;
						}
					}else{
						sql = sql + "'" + formatea_fecha_db(valor) + " 23:59:59') ";
						if(filtrosPDF==''){
							filtrosPDF=filtro+" " +document.getElementById('lblHasta').innerHTML+"|"+valor;
						}else{
							filtrosPDF=filtrosPDF+";"+filtro+" " +document.getElementById('lblHasta').innerHTML+"|"+valor;
						}
						var obj=eval("document.Form1."+filtro+"_hasta")
						obj.value=valor;
					}
				}
			}
			if (objetos[i].datatype=='int' && objetos[i].fltdin=='True'){
				filtro=objetos[i].filtro;
				valor=eval("document.Form1."+filtro+".value");
				try{
					valorTxt=eval("document.Form1."+filtro+"[document.Form1."+filtro+".selectedIndex].text");
				}catch(e){
					valorTxt=valor;
				}
				
				if (valor != ''){
					if(sql==""){
						sql = sql + " (" + filtro + " = " + valor + ") ";
						if(filtrosPDF==''){
							filtrosPDF=filtro+"|"+valorTxt;
						}else{
							filtrosPDF=filtrosPDF+";"+filtro+"|"+valorTxt;
						}
					}else{
						sql = sql + " and (" + filtro + " = " + valor + ") ";	
						if(filtrosPDF==''){
							filtrosPDF=filtro+"|"+valorTxt;
						}else{
							filtrosPDF=filtrosPDF+";"+filtro+"|"+valorTxt;
						}
					}
				}
			}
			if (objetos[i].datatype=='bit' && objetos[i].fltdin=='True'){
				filtro=objetos[i].filtro;
				if(eval("document.Form1."+filtro+".checked")){
					valor="1";	
				}else{
					valor="0";	
				}
				
				if (valor != ''){
					if(sql==""){
						sql = sql + " (" + filtro + " = " + valor + ") ";
						if(filtrosPDF==''){
							filtrosPDF=filtro+"|"+valor;
						}else{
							filtrosPDF=filtrosPDF+";"+filtro+"|"+valor;
						}
					}else{
						sql = sql + " and (" + filtro + " = " + valor + ") ";	
						if(filtrosPDF==''){
							filtrosPDF=filtro+"|"+valor;
						}else{
							filtrosPDF=filtrosPDF+";"+filtro+"|"+valor;
						}
					}
				}
			}
			if (objetos[i].datatype=='all' && objetos[i].fltdin=='True'){
				filtro=objetos[i].filtro;
				valor=eval("document.Form1."+filtro+".value");
				if (valor != ''){
					if(sql==""){
						sql = sql + " (" + filtro + " LIKE '%" + valor + "%') ";
						if(filtrosPDF==''){
							filtrosPDF=filtro+"|"+valor;
						}else{
							filtrosPDF=filtrosPDF+";"+filtro+"|"+valor;
						}
					}else{
						sql = sql + " and (" + filtro + " LIKE '%" + valor + "%') ";
						if(filtrosPDF==''){
							filtrosPDF=filtro+"|"+valor;
						}else{
							filtrosPDF=filtrosPDF+";"+filtro+"|"+valor;
						}
					}
					
				}
			}
		}
		if(sql!=""){
			sql=" where " + sql;
			document.Form1.txtWhere.value=sql;
		}
		document.Form1.txtFiltrosPDF.value=filtrosPDF;
		document.Form1.txtFiltrosInner.value=document.getElementById('lblFiltros').innerHTML;
	}catch(ex){
		alert(ex.description);
		return false;
	}
}
function formatea_fecha_db(fecha){
	var arr=fecha.split("/");
	var newFec=arr[2]+""+arr[1]+""+arr[0];
	return newFec;
}
function openPDF(){
	window.open("ejecuta_reporte_pdf.aspx?totales="+document.getElementById('lblTotales').innerHTML+"&filtros="+document.Form1.txtFiltrosPDF.value,"PDF","width=800,height=600,scrollbars=1,resizable=1");
}
function openXLS(){
	window.open("ejecuta_reporte_xls.aspx","PDF","width=800,height=600,scrollbars=1,resizable=1");
}
function cambio_nombre(){
	var newname= prompt(document.getElementById('lblPrompt').innerHTML, document.Form1.txtNomReporte.value);

	if ( (newname==' ') || (newname==null) ) 
	{ 
	return true; 
	} 
	document.Form1.txtNomReporte.value=newname;
	return true;
}


//*****FIN REPORTES DINAMIsCOS*********************

function Buscar_Evento(evento)
{
//self.location.href="../Catalogo/Carro_Catalogo_OT.aspx?evento="+evento;
document.getElementById("imgBuscarPersona").click();
}

function Buscar_Persona(persona)
{
self.location.href="../Personas/Carro_Personas_OT.aspx?persona="+persona;
}

//formulario personas2

function Buscar_Persona2(persona)
{
self.location.href="../Personas/Carro_Personas_OT2.aspx?persona="+persona+"&from=MANTENEDORPERSONA";
}


function Buscar_Solucion(solucion)
{
self.location.href="../Ticket/pick_solution.aspx?solucion="+solucion;
}

function Buscar_OT(OT)
{
self.location.href="../OrdenTrabajo/Consulta_Orden.aspx?ot="+OT;
}

function Ver_Documento(obj)
{
doc=obj.document.activeElement.parentElement.parentElement.lastChild.innerText;
window.open("archivos/"+doc,"Documento","width=800,height=600,scrollbars=1,resizable=1");
 
}

function mostrartablas()
{
document.getElementById("seleccionarcomponentes").style.display="block";
document.getElementById("componentesselecionados").style.display="block";
}
function ocultartablas()
{
document.getElementById("seleccionarcomponentes").style.display="none";
document.getElementById("componentesselecionados").style.display="none";
}

function limpiardatosmovimiento()
{
	document.getElementById("txtDocumento").value = "";
	document.getElementById("dtpFechaDoc").value = "";
	document.getElementById("txtPrecioCompra").value = "";
	document.getElementById("txtDescripcion").value = "";
	document.getElementById("txtObservacion").value = "";
	document.getElementById("txtConsumoaReemplazar").value = "";
	document.getElementById("txtConsumoaReemplazarid").value = "";
}

function obtenervalorradio()
{
var valor=0;
var radio=document.Form1.rbNota;
for(i=0;i<radio.length;i++)
{
 
  if(radio[i].checked) 
  {
   valor= radio[i].value;
   }
}
  encuesta_notas.MostrarNotas(valor,MostrarNotas_CallBack);

}

function ver_bodegas()
{
var valor=0;
var radio=document.Form1.rdTipoConsumo;
for(i=0;i<radio.length;i++)
{
 
  if(radio[i].checked) 
  {
   valor= radio[i].value;
   }
}
  if (valor == 1)
  {
  document.getElementById("trbodega").style.display="block";
   document.getElementById("trgrillaconsumos").style.display="none";
  }
  else
  {
  document.getElementById("trbodega").style.display="none";
  document.getElementById("trgrillaconsumos").style.display="none";
  }

}

function ver_bodegas2()
{
var valor=0;
var radio=document.Form1.rdTipoConsumo;
for(i=0;i<radio.length;i++)
{
 
  if(radio[i].checked) 
  {
   valor= radio[i].value;
   }
}
  if (valor == 1)
  {
  document.getElementById("trbodega").style.display="block";
   document.getElementById("trgrillaconsumos").style.display="block";
  }
  else
  {
  document.getElementById("trbodega").style.display="none";
  document.getElementById("trgrillaconsumos").style.display="block";
  }

}




function valida_detalle(){
var str=document.getElementById('ftbDetalle').value.replace(/<[^>]+>/g," ");
var arr=str.split("&nbsp;");
var newStr="";
for(i=0;i<arr.length;i++){
	newStr += arr[i].replace("&nbsp;"," ");
}
	if(trim(newStr)== "")
	{
		document.getElementById('ftbDetalle').value=trim(newStr);
	}
}
function valida_detalle_ticket(source, arguments){
var str=document.getElementById('ftbDetalle').value.replace(/<[^>]+>/g," ");
var arr=str.split("&nbsp;");
var newStr="";
for(i=0;i<arr.length;i++){
	newStr += arr[i].replace("&nbsp;"," ");
}
	if(trim(newStr)== "")
	{
		document.getElementById('ftbDetalle').value=trim(newStr);
		arguments.IsValid=false;
			return false;		
	}
	document.getElementById('ftbDetalle').value=trim(newStr);
	arguments.IsValid=true;
	return true;

}
function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
// CSS HACK PARA IEXPLORER POR CAMBIO DE COLOR DE FONDO DE INPUTS //
sfFocus = function() {
	var sfEls = document.getElementsByTagName("INPUT");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onfocus=function() {
			this.className+=" sffocus";
		}
		sfEls[i].onblur=function() {
			this.className=this.className.replace(new RegExp(" sffocus\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfFocus);

// Valida el largo para campo descripcion de 255 caracteres solo para textarea con nombre txtDescripcion
function ValidaLargoDescripcion(source, arguments)
{
 if (Form1.txtDescripcion.value.length > 255)
 {
    arguments.IsValid = false;
 }
 else
 {
     arguments.IsValid = true;
 }
 return;
}
//ENCUESTAS CRM
function readOpcionesPregunta(){
	var doc=document.Form1;
	var objOpc=doc.rbTipoCampo;
	var campo=doc.txtConfigCampo;
	var tabla=document.getElementById("tbAlternativas");
	var strCampo="";
	if(objOpc[0].checked){
		strCampo="Text";
	}else{
		if(objOpc[1].checked){
			strCampo = doc.txtOpc1.value;
			strCampo += "~" + doc.txtOpc2.value;
		}else{
			if(objOpc[2].checked){
				if(tabla.rows.length>1){
					for(i=0;i<tabla.rows.length-1;i++){
						if(strCampo==""){
							strCampo = tabla.rows[i+1].cells[0].innerText;
						}else{
							strCampo += "~" + tabla.rows[i+1].cells[0].innerText;
						}
					}
				}
			}
		}
	}
	campo.value=strCampo;
}
function agregaFila(){
	var doc=document.Form1;
	if (doc.txtAlternativa.value!=""){
		var tabla=document.getElementById("tbAlternativas");
		for(i=0;i<tabla.rows.length-1;i++){
			if(doc.txtAlternativa.value==tabla.rows[i+1].cells[0].innerText){
				alert("ya existe");
				return;
			}
		}
		var row=tabla.insertRow(tabla.rows.length);
		var cell;
		row.className="LABELnorm"
		cell=row.insertCell(0);
		cell.innerText=doc.txtAlternativa.value;
		cell=row.insertCell(1);
		cell.innerHTML="<img src='../../imagenes/grilla_eliminar.gif' onclick='deleteRow(this)' style='cursor:hand;'>";
		doc.txtAlternativa.value="";
		doc.txtAlternativa.focus();
	}
}
function deleteRow(r){
	var i=r.parentNode.parentNode.rowIndex
	var tabla=document.getElementById("tbAlternativas");
	tabla.deleteRow(i)
}
function agregaFilaEncuesta(mail){
	var doc=document.Form1;
	var existe=false;
	if (mail!=""){
		var tabla=document.getElementById("tbAlternativas");
		for(i=0;i<tabla.rows.length-1;i++){
			if(mail==tabla.rows[i+1].cells[0].innerText){
				existe=true;
			}
		}
		if(!existe){
			var row=tabla.insertRow(tabla.rows.length);
			var cell;
			row.className="LABELnorm"
			cell=row.insertCell(0);
			cell.innerText=mail;
			cell=row.insertCell(1);
			cell.innerHTML="<img src='../../imagenes/grilla_eliminar.gif' onclick='deleteRow(this)' style='cursor:hand;'>";
		}
	}
}
function agregaFilaOtrosDestinatarios(mail){
	var doc=document.Form1;
	var existe=false;
	if (mail!=""){
		var tabla=document.getElementById("tbDestMails");
		for(i=0;i<tabla.rows.length-1;i++){
			if(mail==tabla.rows[i+1].cells[0].innerText){
				existe=true;
			}
		}
		if(!existe){
			var row=tabla.insertRow(tabla.rows.length);
			var cell;
			row.className="LABELnorm"
			cell=row.insertCell(0);
			cell.innerText=mail;
			cell=row.insertCell(1);
			cell.innerHTML="<img src='../../imagenes/grilla_eliminar.gif' onclick='deleteRow(this)' style='cursor:hand;'>";
		}
	}
}
function saveDestinatariosPorCuenta(){
	var doc=document.Form1;
	var campo=doc.txtDestinatariosPorCuenta;
	var tabla=document.getElementById("tbAlternativas");
	var strCampo="";
	if(tabla.rows.length>1){
		for(i=0;i<tabla.rows.length-1;i++){
			if(strCampo==""){
				strCampo = tabla.rows[i+1].cells[0].innerText;
			}else{
				strCampo += ";" + tabla.rows[i+1].cells[0].innerText;
			}
		}
	}
	campo.value=strCampo;
}
function saveDestinatariosLibre(){
	var doc=document.Form1;
	var campo=doc.txtDestinatariosLibre;
	var strCampo="";
	var tabla=document.getElementById("tbDestMails");
	if(tabla.rows.length>1){
		for(i=0;i<tabla.rows.length-1;i++){
			if(strCampo==""){
				strCampo = tabla.rows[i+1].cells[0].innerText;
			}else{
				strCampo += ";" + tabla.rows[i+1].cells[0].innerText;
			}
		}
	}
	campo.value=strCampo;
}
function save_encuesta(){
	var ids=new Array();
	var campos=new Array();
	var esta=false;
	var soloId;
	var strIni="";
	var strFinal="";
	for(i=0;i<fields.length;i++){
		strIni=""
		soloId=fields[i].split("|");
		var idSearch=soloId[0];
		var tipo=soloId[1];
		if(tipo=="CHECK"){
			var obj=document.getElementsByName("CHK"+idSearch);
			for(p=0;p<obj.length;p++){
				var valor="0";
				if(obj[p].checked){
					valor="1"
				}
				if(strIni==""){
					strIni=idSearch+"|"+valor;
				}else{
					strIni+="~"+valor;
				}
			}
		}else{
			if(tipo=="TEXTO"){
				var obj=document.getElementsByName("TXT"+idSearch);
				strIni=idSearch+"|"+obj[0].value;
			}else{
				var obj=document.getElementsByName("RB"+idSearch);
				for(z=0;z<obj.length;z++){
					var valor="0";
					if(obj[z].checked){
						valor="1"
					}
					if(strIni==""){
						strIni=idSearch+"|"+valor;
					}else{
						strIni+="~"+valor;
					}
				}
			}
		}
		
		if(strFinal==""){
			strFinal=strIni;
		}else{
			strFinal += "*"+strIni;
		}
	}
	document.Form1.txtResultado.value=strFinal;
}
function Trim(cadena)
{
 for (i = 0; i < cadena.length; )
 {
     if (cadena.charAt(i) == " ")
     {
        cadena = cadena.substring(i+1, cadena.length);
     }
     else
     {
         break;
     }
 }
 for (i = cadena.length-1; i>=0; i=cadena.length-1)
 {
     if (cadena.charAt(i) == " ")
     {
        cadena = cadena.substring(0, i);
     }
     else
     {
         break;
     }
 }
 return cadena;
}
//*****************************
function clickBoton(valor){
	if(valor==3){
		document.Form1.botonLBox.click();	
	}	
}
function pasa_responsable_ot_comp(Responsable_Id, Responsable, Sitio_Id, Sitio, Item)
{
 window.opener.document.getElementById("dgCompsTickets__ctl" + Item + "_txtResponsableIdEditGrid").value = Responsable_Id;
 window.opener.document.getElementById("dgCompsTickets__ctl" + Item + "_lblResponsableEditGrid").innerHTML = Responsable;
 window.opener.document.getElementById("dgCompsTickets__ctl" + Item + "_txtSitioIdEditGrid").value = Sitio_Id;
 window.opener.document.getElementById("dgCompsTickets__ctl" + Item + "_lblSitioEditGrid").innerHTML = Sitio;
}
function pasa_responsable_ot_comp2(Id_Persona, Nombre_Persona, Id_Sitio, Nombre_Sitio){
	window.opener.document.getElementById("dgComponentes__ctl2_txtIdPersonaComp").value = Id_Persona;
	window.opener.document.getElementById("dgComponentes__ctl2_txtPersona").value = Nombre_Persona;
	window.opener.document.getElementById("dgComponentes__ctl2_txtIdSitio").value = Id_Sitio;
	window.opener.document.getElementById("dgComponentes__ctl2_txtSitio").value = Nombre_Sitio;
}

function setCatalogoId_Doctos_Sols(Id)
{
 Form1.txtIdCatalogo.value = Id;
 Form1.btnMuestraDoctosSols.click();
}

function pasa_componente(id,nom){

window.opener.document.Form1.txtIdComponente.value=id;

window.opener.document.Form1.txtComponente.value=nom;

}

//**********************************************************************
// 11-10-2007 JLobosF
// Cambio para CTI (Grupos-Acciones-Resolutores) Sol. JCruz
//**********************************************************************

/*
function selcomp(Id_Componente)
{
 Form1.txtIdComponente.value = Id_Componente;
 Form1.btnSeleccionar.click();
}
*/

function selcomp(Id_Componente)
{
 window.opener.document.getElementById('txtIdComponente').value = Id_Componente;
 window.opener.document.getElementById('btnSeleccionar').click();
 window.close();
}

/*
function SelDistribuidor(Datos_Distribuidor)
{
 var arrDatos = Datos_Distribuidor.split("%%");
 if (Form1.txtDesde.value == "Carro_Personas_OT_Edit")
 {
    window.opener.document.getElementById('txtIdDistribuidorMod').value = arrDatos[0];
    window.opener.document.getElementById('btnBuscarDistMod').click();
 }
 if (Form1.txtDesde.value == "Carro_Personas_OT_New")
 {
    window.opener.document.getElementById('txtIdDistribuidor').value = arrDatos[0];
    window.opener.document.getElementById('btnBuscarDist').click();
 }
 if (Form1.txtDesde.value == "cti_intermediario.aspx")
 {
    window.opener.document.getElementById('txtIdDistribuidor').value = arrDatos[0];
    window.opener.document.getElementById('btnBuscarDist').click();
 }
 window.close();
}
*/

function SelDistribuidor(Id_Distribuidor)
{
 if (Form1.txtDesde.value == "Carro_Personas_OT_Edit")
 {
    window.opener.document.getElementById('txtIdDistribuidorMod').value = Id_Distribuidor;
    window.opener.document.getElementById('btnBuscarDistMod').click();
 }
 if (Form1.txtDesde.value == "Carro_Personas_OT_New")
 {
    window.opener.document.getElementById('txtIdDistribuidor').value = Id_Distribuidor;
    window.opener.document.getElementById('btnBuscarDist').click();
 }
 if (Form1.txtDesde.value == "cti_intermediario.aspx")
 {
    window.opener.document.getElementById('txtIdDistribuidor').value = Id_Distribuidor;
    window.opener.document.getElementById('btnBuscarDist').click();
 }
 window.close();
}

function Busca_Elemento_Combo(Combo, Valor)
{
 for (Contador=0; Contador<Combo.length;Contador++)
 {
     if (Trim(Combo.options[Contador].value) == Trim(Valor))
     {
        Combo.selectedIndex=Contador;
     }
 }
}

function pasa_organismo_externo(id)
{
 window.opener.document.getElementById('txtIdOrgExt').value = id;
 window.opener.document.getElementById('btnBuscarOrgExt').click();
 window.close();
}
function pasa_consumo(id,nombre)
{
 window.opener.document.getElementById('txtConsumoaReemplazarid').value = id;
 window.opener.document.getElementById('txtConsumoaReemplazar').value = nombre;
 window.close();
}
function pasa_consumo2(id,nombre)
{
 window.opener.document.getElementById('txtConsumo').value = id;
 window.opener.document.getElementById('txtConsumoR').value = nombre;
 window.opener.document.getElementById('txtDocumento').value = "";
 window.opener.document.getElementById("dtpFechaDoc").value = "";
 window.opener.document.getElementById("txtPrecioCompra").value = "";
 window.opener.document.getElementById("txtDescripcion").value = "";
 window.opener.document.getElementById("txtObservacion").value = "";
 window.opener.document.getElementById("txtConsumoaReemplazar").value = "";
 window.opener.document.getElementById("txtConsumoaReemplazarid").value = "";
 
window.opener.document.getElementById("imgGuardar").style.display="none";
window.opener.document.getElementById("imgGuardarNoInv").style.display="none";	
	window.opener.document.getElementById("trconsumo").style.display="none";
    window.opener.document.getElementById("trtablamovimiento").style.display="none";
      window.opener.document.getElementById("trtablamovimiento2").style.display="none";
    window.opener.document.getElementById("trtablabodega").style.display="none";
 
 window.close();
}

function Buscar_Persona_CTI(persona)
{
self.location.href="../Personas/Carro_Personas_OT_cti.aspx?persona="+persona;
}

function Open_Buscar_Componente_CTI(Ruta, Desde)
{
 window.open(Ruta + "pick_componentes_ot_cti_sel.aspx?Desde=" + Desde, "Buscar_Componente", "width=620,height=500,top=50,left=50,scrollbars=1,resizable=1");
}

//**********************************************************************
// 11-10-2007 JLobosF - FIN
//**********************************************************************
function validaRecatalogacion(source, arguments)
{
	if(document.Form1.txtIdCatalogo.value=="0"){
		arguments.IsValid=false;
		return false;
	}
	if(document.Form1.txtDescCambio.value==""){
		arguments.IsValid=false;
		return false;
	}
	if(document.Form1.txtIds.value==""){
		arguments.IsValid=false;
		return false;
	}
}
function showHideRG(id_objeto){

	if(document.getElementById(id_objeto).style.display=="none"){
		document.getElementById(id_objeto).style.display="block"
		document.getElementById("img_" + id_objeto).src="../../../imagenes/menos.gif"
	}else{
		document.getElementById(id_objeto).style.display="none"
		document.getElementById("img_" + id_objeto).src="../../../imagenes/mas.gif"
	}
}

function logReporte(Reporte)
{
 window.opener.Form1.txtReporte.value = Reporte;
 window.opener.Form1.Button1.click();
 window.close();
}


function mostrar(que){ 
for(i=0;i<result.length;i++){ 
if(que==result[i]){ 
if(document.getElementById(que).style.display=='none'){document.getElementById(que).style.display='block';}else{document.getElementById(que).style.display='none';} 
}else{ 
eval("document.getElementById('"+result[i]+"').style.display='none'"); 
} 
} 
}


