document.write('<script type="text/javascript" src="classes/js/trim.js"></script>');

function verificarDisponibilidad(f, id)
{
  // verifica si hay disponibilidad
  var nombre = jQuery('#vNombre').val();
  var apellido = jQuery('#vApellido').val();
  
  jQuery.get
  (
    "index.php?ohaction=guardarContactos",
    { 
      vNombre: nombre, 
      vApellido: apellido,
      id: id 
    }, 
    f
  )
}


// verifica si el contacto no existe ya
// y lo guarda
function guardarContactos(id)
{
  // callback
  var f = function(data)
          {
            if (data == 'true') 
            {
              sendForm('form1');
            }
            else
            {
              alert("El contacto se encuentra registrado");
            }
          }
          
  var data = verificarDisponibilidad(f, id);
}

// para captaciones
function guardarContactosCaptaciones()
{
  var f = function(data)
  {
    if (data == 'true') 
    {
      sendForm('nuevoContacto');
    }
    else
    {
      alert("El contacto se encuentra registrado");
    }
  }
  var data = verificarDisponibilidad(f);
}

// Realiza controles periodicos
// del lado del servidor
function initHeartBeat()
{
	jQuery.jheartbeat.set({
	url: "index.php?ohaction=checkPulse",
	delay:30000
	}, checkPulse); 
}
	
// si se ha mostrado una ventana
function checkPulse()
{
	// Callback Function
	var response = document.getElementById("HeartBeatDIV").innerHTML;
	
	var arrValues = response.split('@');
	arrValues[0] = Trim(arrValues[0]);
	
	if (arrValues[0] != "false" && jQuery("#TB_window").css("display") != 'block')
	{
		// muchos usuarios
		tb_show("Alerta", "index.php?ohaction=dspAlertaMuchosUsuarios&height=200&width=500&modal=true", null);
	}
	else // esta todo bien
	{
		// mostrarlo si ya no lo ha mostrado	
		if (arrValues[1] != "" && jQuery("#TB_window").css("display") != 'block')
		{
			// los id recorrerlos y mostrarlos como alertas
			tb_show("Alerta", "index.php?ohaction=dspAlarmas&id=" + arrValues[1] + "&height=275&width=500&modal=true", null);
		}		
	}
}


/**
*
*	La función initAjax permite inicializar un objeto AJAX y luego devolverlo.
*   Esto sirve para encadenar dos llamadas a la función getMyHTML() sin tener
*   que utilizar AJAX asincronico.

*/

function initAjax(){

	

	var ajax=false;



    /*@cc_on @*/

	

    /*@if (@_jscript_version >= 5)

	

    try {

	

    ajax = new ActiveXObject("Msxml2.XMLHTTP");

	

    } catch (e) {

	

    	try {

	

    ajax = new ActiveXObject("Microsoft.XMLHTTP");

	

    } catch (E) {

	

    ajax = false;

	

    }

	

    }

	

    @end @*/

	

    if (!ajax && typeof XMLHttpRequest!='undefined') 

	{

	   	ajax = new XMLHttpRequest();

    }

    

    return ajax;

}



function getMyHTML( url , divId ) 
{
	var ajax = initAjax();    
	var obj = document.getElementById( divId );
	ajax.open("GET", url );

	ajax.onreadystatechange = function() 
	{
		if (ajax.readyState == 4 && ajax.status == 200) 
		{
			//alert(ajax.responseText);
			obj.innerHTML = ajax.responseText;
        }
	}

    ajax.send(null);
}



// Verifica si el usuario se encuentra registrado
function chequearUsuario() 
{
	// si las validaciones estan correctas
	if (checkForm('form1'))
	{
		var usuario = document.getElementById('txtUser');
		var password = document.getElementById('txtPassword');
		var obj = document.getElementById( 'divAutentificacion' );
		var divUsuario = document.getElementById( 'divNombre' );
		var ajax = initAjax();

		ajax.open("GET", 'index.php?ohaction=ajaxLogin&user=' + usuario.value + '&pass=' + password.value, true);

		ajax.onreadystatechange = function() 
		{
			if (ajax.readyState == 4 && ajax.status == 200) 
			{
				if (ajax.responseText != 'false')
				{
					respuesta = new String(ajax.responseText);
					arrRespuesta = respuesta.split('@@');
					divUsuario.innerHTML = arrRespuesta[1];
					obj.innerHTML = "Bienvenido <b>" + arrRespuesta[0];
					sendForm('form1');
				}
				else
				{
					//document.getElementById('Submit').disabled = false;
					usuario.value = '';
					password.value = '';
					usuario.focus();
					obj.innerHTML = 'Usuario inválido, por favor intente nuevamente';
				}
			}
		}

		ajax.send(null);
	}
}





// Verifica si el usuario se encuentra registrado

function chequearUsuarioLive() 

{

	

	usuario = document.getElementById('txtUser').value;

	password = document.getElementById('txtPassword').value;

//	alert(usuario);

	

	if (usuario != '' && password != '')

	{

		var ajax = initAjax();

	

		var obj = document.getElementById( 'divAutentificacion' );

		var divUsuario = document.getElementById( 'divNombre' );

	

		ajax.open("GET", 'index.php?ohaction=ajaxLogin&user=' + usuario + '&pass=' + password);

	

		ajax.onreadystatechange = function() 

		{

	

			if (ajax.readyState == 4 && ajax.status == 200) 

			{

				//alert(ajax.responseText);

        if (ajax.responseText != 'false')

				{

					respuesta = new String(ajax.responseText);

					arrRespuesta = respuesta.split('@@');

					divUsuario.innerHTML = arrRespuesta[1];

					obj.innerHTML = "Bienvenido <b>" + arrRespuesta[0];

				}

			}

		}

	

		ajax.send(null);

	}

}



// Verifica si el usuario se encuentra registrado

function buscarContactos() 

{

	categoria = document.getElementById('iSubID');

	indice = categoria.selectedIndex;

	categoriavalor = categoria.options[indice].value;

	nombreapellido = document.getElementById('nombreapellido').value;

  idcontacto = document.getElementById('iConID').value;

  

	var ajax = initAjax();



	var obj = document.getElementById( 'divBuscarContactos' );



	ajax.open("GET", 'index.php?ohaction=ajaxBuscarContactos' + '&id=' + idcontacto + '&categoria=' + categoriavalor + '&nombreapellido=' + nombreapellido);



	ajax.onreadystatechange = function() 

	{



		if (ajax.readyState == 4 && ajax.status == 200) 

		{

			obj.innerHTML = ajax.responseText;

		}

	}



	ajax.send(null);

}



// Verifica si el usuario se encuentra registrado

function buscarContactosParaPropiedades() 

{

	categoria = document.getElementById('iSubID');

	indice = categoria.selectedIndex;

	categoriavalor = categoria.options[indice].value;

	nombreapellido = document.getElementById('nombreapellido').value;

	idpro = document.getElementById('iProID').value;



	var ajax = initAjax();



	var obj = document.getElementById( 'divBuscarContactos' );



	ajax.open("GET", 'index.php?ohaction=ajaxBuscarContactosParaPropiedades&id=' + idpro + '&categoria=' + categoriavalor + '&nombreapellido=' + nombreapellido);



	ajax.onreadystatechange = function() 

	{



		if (ajax.readyState == 4 && ajax.status == 200) 

		{

			obj.innerHTML = ajax.responseText;

		}

	}



	ajax.send(null);

}







// Busca una propiedad

function buscarPropiedades()

{

	referencia = document.getElementById('referencia').value;

	palabra = document.getElementById('palabra').value;

  idcon = document.getElementById('iConID').value;

	



	var ajax = initAjax();



	var obj = document.getElementById( 'divBuscar' );



	ajax.open("GET", 'index.php?ohaction=ajaxBuscarPropiedades&id=' + idcon + '&referencia=' + referencia + '&palabra=' + palabra);



	ajax.onreadystatechange = function() 

	{



		if (ajax.readyState == 4 && ajax.status == 200) 

		{

			obj.innerHTML = ajax.responseText;

		}

	}



	ajax.send(null);

}





// Cambia de sede
function cambiarSede(id) 
{

	var ajax = initAjax();

	ajax.open("GET", 'index.php?ohaction=cambiarSede&idsed=' + id);
	
	ajax.onreadystatechange = function() 
	{
		if (ajax.readyState == 4 && ajax.status == 200) 
		{
			window.location.reload();
		}
	}

	ajax.send(null);
}


// Busca contactos para asignar una demanda
function buscarContactosParaDemandas(iddemanda) 
{
	if(document.getElementById('tipo1').checked)
	{
	 	var tipo = 0;
	}
	else
	{
		var tipo = 1;
	}

	buscarpor = document.getElementById('buscarpor').value;
	telefono = document.getElementById('telefono').value;

	var obj = document.getElementById('divBuscarContactos');

  if (iddemanda != '')
  {	
    window.open('index.php?ohaction=ajaxBuscarContactosParaDemandas&tipo=' + tipo + '&buscarpor=' + buscarpor + '&telefono=' + telefono + '&iddemanda=' + iddemanda, 'popup', 'height=400,width=650,status=no,toolbar=no,menubar=no,location=no,resizable=yes, scrollbars=yes');
  }
  else
  {
    window.open('index.php?ohaction=ajaxBuscarContactosParaDemandas&tipo=' + tipo + '&buscarpor=' + buscarpor + '&telefono=' + telefono, 'popup', 'height=400,width=650,status=no,toolbar=no,menubar=no,location=no,resizable=yes, scrollbars=yes');
    
  }
}


// Busca contactos para asignar una demanda
function buscarContactosParaCaptaciones(idcaptacion) 
{
	if(document.getElementById('tipo1').checked)
	{
	 	tipo = 0;
	}
	else
	{
		tipo = 1;
	}

	buscarpor = document.getElementById('buscarpor').value;
	telefono = document.getElementById('telefono').value;
	
	var obj = document.getElementById( 'divBuscarContactos' );

	if (idcaptacion != '')
	{
		window.open('index.php?ohaction=ajaxBuscarContactosParaCaptaciones&tipo=' + tipo + '&buscarpor=' + buscarpor + '&telefono=' + telefono + '&idcaptacion=' + idcaptacion, 'popup', 'height=600,width=650,status=no,toolbar=no,menubar=no,location=no,resizable=yes, scrollbars=yes');
	}
	else
	{
		window.open('index.php?ohaction=ajaxBuscarContactosParaCaptaciones&tipo=' + tipo + '&buscarpor=' + buscarpor + '&telefono=' + telefono, 'popup', 'height=600,width=650,status=no,toolbar=no,menubar=no,location=no,resizable=yes, scrollbars=yes');
	}
}



















/* Agregado por Victor 12-04-07 */

function buscarContactosParaDemandasTodos() 

{
	var tipo = "";
	
	
	 if(document.getElementById('tipo1').checked)
	 	tipo=document.getElementById('tipo1').value;
	else
		if (document.getElementById('tipo2').checked)
			{tipo=document.getElementById('tipo2').value;}
		else 
			{tipo=document.getElementById('tipo0').value;}
	

	buscarpor = document.getElementById('buscarpor').value;
	telefono =  document.getElementById('telefono').value;



	var ajax = initAjax();



	var obj = document.getElementById( 'divBuscarContactos' );



	ajax.open("GET", 'index.php?ohaction=ajaxBuscarContactosParaDemandas&tipo=' + tipo + '&buscarpor=' + buscarpor + '&telefono=' + telefono);



	ajax.onreadystatechange = function() 

	{



		if (ajax.readyState == 4 && ajax.status == 200) 

		{

			//obj.innerHTML = ajax.responseText;

			window.open('index.php?ohaction=ajaxBuscarContactosParaDemandas&tipo=' + tipo + '&buscarpor=' + buscarpor + '&telefono=' + telefono, 'popup', 'height=400,width=650,status=no,toolbar=no,menubar=no,location=no,resizable=yes, scrollbars=yes');

		}

	}



	ajax.send(null);

}
/* Fin agragado por Victor */




// Muestra localizaciones
function mostrarProvincias(id)

{
	// si el id es vacio asignar 0
	if (id == '')
	{
		id = 0;
	}
	
	var ajax = initAjax();


	//var obj = document.getElementById( 'comboProvincias' );
	ajax.open("GET", 'index.php?ohaction=mostrarProvincias&idpais=' + id);

	ajax.onreadystatechange = function() 
	{
		if (ajax.readyState == 4 && ajax.status == 200) 
		{
			//obj.innerHTML = ajax.responseText;

			var cadena = ajax.responseText;

			// Borra las opciones actuales
			var elSel = document.getElementById('iProID');

			elSel.options.length=0
			var myOption = new Option('[Seleccione]', '');

	  		elSel.options[0] = myOption;
			if (cadena != '')
			{
				// Agrega las nuevas provincias
				var opciones = cadena.split(",");
				
				for (i = 1; i <= opciones.length; i++) 
				{

					var parvalores = opciones[i-1].split("-");
					var myOption = new Option(parvalores[1], parvalores[0]);
			  		elSel.options[i] = myOption;
				}
			}
			else // sino llama a mostrar ciudad para que limpie todo
			{
				mostrarCiudades(0);
			}
		}
	}

	ajax.send(null);
}



function mostrarCiudades(id)
{

	// si el id es vacio asignar 0
	if (id == '')
	{
		id = 0;
	}
	
	var ajax = initAjax();

	//var obj = document.getElementById( 'comboCiudades' );

	ajax.open("GET", 'index.php?ohaction=mostrarCiudades&idprovincia=' + id);

	ajax.onreadystatechange = function() 
	{
		if (ajax.readyState == 4 && ajax.status == 200) 
		{
			var cadena = ajax.responseText;

			// Borra las opciones actuales
			var elSel = document.getElementById('iCiuID');
			elSel.options.length=0
			var myOption = new Option('[Seleccione]', '');
	  		elSel.options[0] = myOption;

			if (cadena != '')
			{
				// Agrega las nuevas provincias
				var opciones = cadena.split(",");
				for (i = 1; i <= opciones.length; i++) 
				{
					var parvalores = opciones[i-1].split("-");
					var myOption = new Option(parvalores[1], parvalores[0]);
			  		elSel.options[i] = myOption;
				}
			}
			else
			{
				mostrarZonas(0);
			}
		}
	}

	ajax.send(null);
}



function mostrarZonas(id)
{
	// si el id es vacio asignar 0
	if (id == '')
	{
		id = 0;
	}
	
	var ajax = initAjax();

	//var obj = document.getElementById( 'comboZonas' );

	ajax.open("GET", 'index.php?ohaction=mostrarZonas&idciudad=' + id);

	ajax.onreadystatechange = function() 
	{
		if (ajax.readyState == 4 && ajax.status == 200) 
		{
			var cadena = ajax.responseText;
			
			var elSel = document.getElementById('iZonID');

			elSel.options.length=0
			var myOption = new Option('[Seleccione]', '');
	  		elSel.options[0] = myOption;

			if (cadena != '')
			{
				// Agrega las nuevas provincias
				var opciones = cadena.split(",");
				for (i = 1; i <= opciones.length; i++) 
				{
					var parvalores = opciones[i-1].split("-");
					var myOption = new Option(parvalores[1], parvalores[0]);
			  		elSel.options[i] = myOption;
				}
			}	

	}
	}

	ajax.send(null);
}




// Trae las subcategorias para la categoria seleccionada

function cambiarSubcategoriasAJAX(id) 

{

	var ajax = initAjax();



	var obj = document.getElementById( 'comboSubcategorias' );



	ajax.open("GET", 'index.php?ohaction=mostrarSubcategorias&id=' + id);

	ajax.onreadystatechange = function() 
	{
		if (ajax.readyState == 4 && ajax.status == 200) 
		{
			var cadena = ajax.responseText;

			// Borra las opciones actuales
			var elSel = document.getElementById('iTinID');
			elSel.options.length=0
			var myOption = new Option('[Seleccione]', '0');
	  		elSel.options[0] = myOption;

			if (cadena != '')
			{
				// Agrega las nuevas provincias
				var opciones = cadena.split(",");
				for (i = 1; i <= opciones.length; i++) 
				{
					var parvalores = opciones[i-1].split("-");
					var myOption = new Option(parvalores[1], parvalores[0]);
			  		elSel.options[i] = myOption;
				}
			}
		}
	}


	ajax.send(null);

}





// Captaciones / Demandas



function buscarContactosCaptaciones() 

{

	categoria = document.getElementById('iSubID');

	indice = categoria.selectedIndex;

	categoriavalor = categoria.options[indice].value;

	nombreapellido = document.getElementById('nombreapellido').value;



	var ajax = initAjax();



	var obj = document.getElementById( 'divBuscarContactos' );



	ajax.open("GET", 'index.php?ohaction=ajaxBuscarContactosCaptaciones&categoria=' + categoriavalor + '&nombreapellido=' + nombreapellido);



	ajax.onreadystatechange = function() 

	{



		if (ajax.readyState == 4 && ajax.status == 200) 

		{

			obj.innerHTML = ajax.responseText;

		}

	}



	ajax.send(null);

}



function buscarContactosCaptacionesRel() 

{

	telefono = document.getElementById('telefono').value;



	var ajax = initAjax();



	var obj = document.getElementById( 'divBuscarContactos' );



	ajax.open("GET", 'index.php?ohaction=ajaxBuscarContactosCaptacionesRel&telefono=' + telefono);



	ajax.onreadystatechange = function() 

	{



		if (ajax.readyState == 4 && ajax.status == 200) 

		{

			obj.innerHTML = ajax.responseText;

		}

	}



	ajax.send(null);

}





function mostrarCiudadesCapDem(idprov, idciudad, idzona)

{

	var ajax = initAjax();

	mostrarZonas(idciudad, idzona);

	document.getElementById('iCiuID2').value=idciudad;



	var obj = document.getElementById( 'comboCiudades' );



	ajax.open("GET", 'index.php?ohaction=mostrarCiudades&idprovincia=' + idprov + '&idciudad=' + idciudad);



	ajax.onreadystatechange = function() 

	{

		if (ajax.readyState == 4 && ajax.status == 200) 

		{

			obj.innerHTML = ajax.responseText;

		}

	}



	ajax.send(null);

}



function mostrarZonasCapDem(idciudad, idzona)

{

	var ajax = initAjax();

	document.getElementById('iZonID2').value=idzona;



	var obj = document.getElementById( 'comboZonas' );



	ajax.open("GET", 'index.php?ohaction=mostrarZonas&idciudad=' + idciudad + '&idzona=' + idzona);



	ajax.onreadystatechange = function() 

	{

		if (ajax.readyState == 4 && ajax.status == 200) 

		{

			obj.innerHTML = ajax.responseText;

		}

	}



	ajax.send(null);

}



function mostrarTinmuebleCapDem(idcat,id)

{

	var ajax = initAjax();

	document.getElementById('iTipInmID2').value=id;



	var obj = document.getElementById( 'comboTinmueble' );



	ajax.open("GET", 'index.php?ohaction=mostrarTinmuebles&idcat=' + idcat + '&idinm=' + id);



	ajax.onreadystatechange = function() 

	{

		if (ajax.readyState == 4 && ajax.status == 200) 

		{

			obj.innerHTML = ajax.responseText;

		}

	}



	ajax.send(null);

}



// Cambia el estado

function cambiarEstado(id, estado) 

{

	var ajax = initAjax();

	//alert('index.php?ohaction=modTareasAgendaestado&id=' + id + '&estado=' + estado);

	ajax.open("GET", 'index.php?ohaction=modTareasAgendaestado&id=' + id + '&estado=' + estado, true);

	

	ajax.onreadystatechange = function() 

	{

		if (ajax.readyState == 4 && ajax.status == 200) 

		{



			// ESTADO = 3 Significa Tarea Completa

			// Si la tarea esta completada se debe eliminar el tachado cuando se cambia de estado

		if ( estado == '3')



			{

				

				//alert("no tachar");

				//alert(estado);

				var ele = document.getElementById(id);

				//alert(ele);

				ele.style.color = '#000000'; 

				ele.textDecoration = 'none';

			}

			// ESTADO != 3 Significa Tarea No completada  y se la cambia de estado, siempre debe tomar el estado = 3

			// Si la tarea no esta completada se debe generar el tachado cuando se cambia de estado	a Completado		

			else		

			{

				//alert(estado);

				document.getElementById(id).style.textDecoration = 'line-through';

				document.getElementById(id).style.color = '#CCCCCC';

						

			}		

			window.location.reload();

			//Para imprimir en un alert lo que devuelve el php que estoy llamando

			// Problema: Al cambiar el estado por primera vez, funciona correctamente, pero al cambiar el estado al mismo registro por segunda vez, no lo actualiza.

			//alert( ajax.responseText );

			

		}

	}



	ajax.send(null);

}





function eliminarTarea(id) 

{

	//alert (id);

	var ajax = initAjax();

	ajax.open("GET", 'index.php?ohaction=delTareasAgenda&id=' + id );

	

	ajax.onreadystatechange = function() 

	{

		if (ajax.readyState == 4 && ajax.status == 200) 

		{

			//alert( ajax.responseText );

			window.location.reload();

		}

		

	}		

	ajax.send(null);

}

function guardarNuevoContacto(iddemanda)
{
	
	nombre = document.getElementById('vNombre').value;
	apellido = document.getElementById('vApellido').value;
	numero = document.getElementById('nTelefono').value;
	email = document.getElementById('eMail').value;
	nDocumento = document.getElementById('nNumero').value;	
	tDoc = document.getElementById('iTdoID').value;		
	
	var ajax = initAjax();
	
	ajax.open("GET", 'index.php?ohaction=nuevoUsuarioAjax&vNombre='+nombre+'&vApellido='+apellido+'&nTelefono='+numero+'&eMail='+email+'&nDocumento='+nDocumento+'&tDoc='+tDoc);
	
	ajax.onreadystatechange = function() 

	{

		if (ajax.readyState == 4 && ajax.status == 200) 

		{
			var respuesta = ajax.responseText;

			if (respuesta != "")
			{
				res =respuesta.split("|");
				
                document.getElementById('iConID').value = res[0]; 
                document.getElementById('iDemID').value = iddemanda; 
			
				document.getElementById('resultadoNuevoContacto').innerHTML = "El contacto " + res[1] + " fue guardado satisfactoriamente";
				
				// asigna el contacto a la demanda desde la visita
				window.opener.location.href='index.php?ohaction=dspPropriedadesDemandaDesdeVisita&iConID=' + res[0] + '&iDemID=' + iddemanda;
				//window.opener.location.href='index.php?ohaction=frmModDemandas&idcon=' + res[0] + '&id=' + iddemanda;
				//dspPropriedadesDemanda&id=101&ver=true#
			}

		}

		

	}		
	showDivWithOutImage('nuevoUsuario');

	ajax.send(null);
	
	mostrarDiv('nuevoUsuario','hide');
}



// Crea un nuevo contacto estan en demandas
function guardarNuevoContactoNoTocar()
{
  var f = function(data)
  {
    if (data == 'true') 
    {
      nombre = document.getElementById('vNombre').value;
      apellido = document.getElementById('vApellido').value;
      numero = document.getElementById('nTelefono').value;
      email = document.getElementById('eMail').value;
      nDocumento = document.getElementById('nNumero').value;	
      tDoc = document.getElementById('iTdoID').value;
      
      if (nombre == '')
      {
        alert("Ingrese el nombre");
        return false;
      }		
      
      var ajax = initAjax();
      
      ajax.open("GET", 'index.php?ohaction=nuevoUsuarioAjax&vNombre='+nombre+'&vApellido='+apellido+'&nTelefono='+numero+'&eMail='+email+'&nDocumento='+nDocumento+'&tDoc='+tDoc);
      
      ajax.onreadystatechange = function() 
      {
      	if (ajax.readyState == 4 && ajax.status == 200)
      	{
      		var respuesta = ajax.responseText;
      
      		if (respuesta != "")
      		{
      			res = respuesta.split("|");
            //document.getElementById('iConID').value = res[0]; 
            window.opener.location.href='index.php?ohaction=frmModDemandas&idcon=' + res[0]; 
            window.close();
      		}
      
      	}
      }		
      
      ajax.send(null);
    }
    else
    {
      alert("El contacto se encuentra registrado");
    }
  }
  var data = verificarDisponibilidad(f);
}


// Crea un nuevo contacto estando en captaciones
function guardarNuevoContactoCaptaciones()
{
/*	nombre 		= document.getElementById('vNombre').value;
	apellido 	= document.getElementById('vApellido').value;
	numero 		= document.getElementById('nTelefono').value;
	email 		= document.getElementById('eMail').value;
	nDocumento 	= document.getElementById('nNumero').value;	
	tDoc 		= document.getElementById('iTdoID').value;	
//	iSedID 		= document.getElementById('iSedID').value;
//	idusers		= document.getElementById('idusers').value;		
	
	
	var ajax = initAjax();
	
	ajax.open("GET", 'index.php?ohaction=nuevoUsuarioAjaxCaptaciones&vNombre='+nombre+'&vApellido='+apellido+'&nTelefono='+numero+'&eMail='+email+'&nDocumento='+nDocumento+'&tDoc='+tDoc);
	
	ajax.onreadystatechange = function() 
	{
		if (ajax.readyState == 4 && ajax.status == 200) 
		{
			var respuesta = ajax.responseText;

			if (respuesta != "")
			{
				res =respuesta.split("|");
				
                //document.getElementById('iConID').value = res[0]; 
                window.opener.location.href='index.php?ohaction=frmModCaptaciones&iConID=' + res[0]; 
                window.close();
			}

		}
	}		

	ajax.send(null);*/
}


// Crea un nuevo contacto estando en captaciones
function guardarNuevaPropiedadCaptaciones()
{
	/*sReferencia = document.getElementById('sReferencia').value;
	iCaptador 	= document.getElementById('iCaptador').value;
	iCatProID	= document.getElementById('iCatProID').value;
	iTinID 		= document.getElementById('iTinID').value;
	bActivo 	= document.getElementById('bActivo').value;	
	bPublicar 	= document.getElementById('bPublicar').value;
//	iSedID 		= document.getElementById('iSedID').value;
//	idusers		= document.getElementById('idusers').value;	
	
	
	var ajax = initAjax();
	
	ajax.open("GET", 'index.php?ohaction=nuevaPropiedadAjax&sReferencia='+sReferencia+'&iCaptador='+iCaptador+'&iCatProID='+iCatProID+'&iTinID='+iTinID+'&bActivo='+bActivo+'&bPublicar='+bPublicar);
	
	ajax.onreadystatechange = function() 
	{
		if (ajax.readyState == 4 && ajax.status == 200) 
		{
			var respuesta = ajax.responseText;

			if (respuesta != "")
			{
				res =respuesta.split("|");
				
				alert(ajax.responseText);				
				
				// Devuelve como parametro la referencia de la propiedad agregada
                window.opener.location.href='index.php?ohaction=frmModCaptaciones&iProID=' + res[0] + '&sReferencia=' + res[1]; 
                window.close();
			}

		}
	}		

	ajax.send(null);*/
}


// valida que la referencia no exista
function validar(referencia)
{
	var ajax = initAjax();
	
	ajax.open("GET", 'index.php?ohaction=validarPropiedad&referencia='+referencia);
	
	ajax.onreadystatechange = function() 
	{
		if (ajax.readyState == 4 && ajax.status == 200) 
		{
			var respuesta = ajax.responseText;

			if (respuesta == "false")
			{
				alert("La referencia ingresada esta disponible");
			}
			else
			{
				alert("La referencia ingresada ya existe");
			}
		}
	}		
	
	ajax.send(null);
}

// Busca contactos para asignar una demanda
function ajaxBuscarContactosParaVendedores(iddemanda) 
{
	if(document.getElementById('tipo1').checked)
	{
	 	var tipo = 0;
	}
	else
	{
		var tipo = 1;
	}

	buscarpor = document.getElementById('buscarpor').value;
	telefono = document.getElementById('telefono').value;

	var obj = document.getElementById('divBuscarContactos');

	window.open('index.php?ohaction=ajaxBuscarContactosParaVendedores&tipo=' + tipo + '&buscarpor=' + buscarpor + '&telefono=' + telefono + '&idventa=' + iddemanda, 'popup', 'height=400,width=650,status=no,toolbar=no,menubar=no,location=no,resizable=yes, scrollbars=yes');
}

