// JavaScript Document

//var pageTracker = _gat._getTracker("UA-3159166-2");
//pageTracker._trackPageview();
////////////////////////////// funcion para autocompletar /////////////
	//functions.js
	
	//Create a boolean variable to check for a valid IE instance.
	var xmlhttp = false;
	
	//Check if we are using IE.
	try {
		//If the javascript version is greater than 5.
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		
	} catch (e) {
		//If not, then use the older active x object.
		try {
			//If we are using IE.
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (E) {
			//Else we must be using a non-IE browser.
			xmlhttp = false;
		}
	}
	
	//If we are using a non-IE browser, create a JavaScript instance of the object.
	if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
		xmlhttp = new XMLHttpRequest();
		
	}
	
	//A variable used to distinguish whether to open or close the calendar.
	//var showCalendar = true;
	
	
	function findPosX(obj){
		var curleft = 0;
		if (obj.offsetParent){
			while (obj.offsetParent){
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		} else if (obj.x){
			curleft += obj.x;
		}
		return curleft;
	}
	
	function findPosY(obj){
		var curtop = 0;
		if (obj.offsetParent){
			while (obj.offsetParent){
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		} else if (obj.y){
			curtop += obj.y;
		}
		return curtop;
	}
/* funcion para autocompletar nombre de empresa */	
	function nom_empresacomplit (thevalue, e){
		
		theObject = document.getElementById("nom_emprediv");
		
		theObject.style.visibility = "visible";
		theObject.style.width = "200px";
		//theObject.style.position = "absolute";
		//theObject.style.index = "1000";
		//theObject.style.left = "5px";
		//theObject.style.top = "120px";
		
		var posx = 0;
		var posy = 0;
		
		posx = (findPosX (document.getElementById("buscadorempresa")) + 7 );
		posy = (findPosY (document.getElementById("buscadorempresa")) + 70 );
		
		theObject.style.left = posx + "px";
		theObject.style.top = posy + "px";
		
		var theextrachar = e.which;
		
		if (theextrachar == undefined){
			theextrachar = e.keyCode;
		}
		
		//The location we are loading the page into.
		var objID = "nom_emprediv";

		//Take into account the backspace.
		if (theextrachar == 8){
			if (thevalue.length == 1){
				var serverPage = "modulos/busqueda/empresas/nom_empre.php";
			} else {
				var serverPage = "modulos/busqueda/empresas/nom_empre.php" + "?sstring=" + thevalue.substr (0, (thevalue.length -1));
			}
		} else {
			var serverPage = "modulos/busqueda/empresas/nom_empre.php" + "?sstring=" + thevalue + String.fromCharCode (theextrachar);
		}
		
		var obj = document.getElementById(objID);
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				obj.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}
/* funcion para autocompletar la direccion de empresas */	
	function direc_emprecomplit (thevalue, e){
		
		theObject = document.getElementById("direc_emprediv");
		
		theObject.style.visibility = "visible";
		theObject.style.width = "200px";
		//theObject.style.position = "absolute";
		//theObject.style.index = "1000";
		//theObject.style.left = "5px";
		//theObject.style.top = "120px";
		
		var posx = 0;
		var posy = 0;
		
		posx = (findPosX (document.getElementById("buscadorempresa")) + 7 );
		posy = (findPosY (document.getElementById("buscadorempresa")) + 115 );
		
		theObject.style.left = posx + "px";
		theObject.style.top = posy + "px";
		
		var theextrachar = e.which;
		
		if (theextrachar == undefined){
			theextrachar = e.keyCode;
		}
		
		//The location we are loading the page into.
		var objID = "direc_emprediv";

		//Take into account the backspace.
		if (theextrachar == 8){
			if (thevalue.length == 1){
				var serverPage = "modulos/busqueda/empresas/direc_empre.php";
			} else {
				var serverPage = "modulos/busqueda/empresas/direc_empre.php" + "?sstring=" + thevalue.substr (0, (thevalue.length -1));
			}
		} else {
			var serverPage = "modulos/busqueda/empresas/direc_empre.php" + "?sstring=" + thevalue + String.fromCharCode (theextrachar);
		}
		
		var obj = document.getElementById(objID);
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				obj.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}
/* funcion para poner el nombre seleccionado en el formulario de empresa */		
	function nom_empre (thevalue){
		acObject = document.getElementById("nom_emprediv");
		
		acObject.style.visibility = "hidden";
		acObject.style.height = "0px";
		acObject.style.width = "0px";
		
		document.getElementById("nom_empresa").value = thevalue;
	}

/* funcion para poner la direccion seleccionada en el formulario de empresa */	
	function direc_empre (thevalue){
		acObject = document.getElementById("direc_emprediv");
		
		acObject.style.visibility = "hidden";
		acObject.style.height = "0px";
		acObject.style.width = "0px";
		
		document.getElementById("direc_empresa").value = thevalue;
	}
/* funcion para autocompletar nombre de particulares */	
	function nom_particomplit (thevalue, e){
		
		theObject = document.getElementById("nom_partidiv");
		
		theObject.style.visibility = "visible";
		theObject.style.width = "200px";

		
		var posx = 0;
		var posy = 0;
		
		posx = (findPosX (document.getElementById("buscadorparticular")) + 7);
		posy = (findPosY (document.getElementById("buscadorparticular")) + 68);
		
		theObject.style.left = posx + "px";
		theObject.style.top = posy + "px";
		
		var theextrachar = e.which;
		
		if (theextrachar == undefined){
			theextrachar = e.keyCode;
		}
		
		//The location we are loading the page into.
		var objID = "nom_partidiv";

		//Take into account the backspace.
		if (theextrachar == 8){
			if (thevalue.length == 1){
				var serverPage = "modulos/busqueda/particulares/nom_parti.php";
			} else {
				var serverPage = "modulos/busqueda/particulares/nom_parti.php" + "?sstring=" + thevalue.substr (0, (thevalue.length -1));
			}
		} else {
			var serverPage = "modulos/busqueda/particulares/nom_parti.php" + "?sstring=" + thevalue + String.fromCharCode (theextrachar);
		}
		
		var obj = document.getElementById(objID);
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				obj.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}
/* funcion para autocompletar la direccion de particulares */	
	function dir_particomplit (thevalue, e){
		
		theObject = document.getElementById("dir_partidiv");
		
		theObject.style.visibility = "visible";
		theObject.style.width = "200px";
		//theObject.style.position = "absolute";
		//theObject.style.index = "1000";
		//theObject.style.left = "5px";
		//theObject.style.top = "120px";
		
		var posx = 0;
		var posy = 0;
		
		posx = (findPosX (document.getElementById("buscadorparticular")) + 7 );
		posy = (findPosY (document.getElementById("buscadorparticular")) + 115 );
		
		theObject.style.left = posx + "px";
		theObject.style.top = posy + "px";
		
		var theextrachar = e.which;
		
		if (theextrachar == undefined){
			theextrachar = e.keyCode;
		}
		
		//The location we are loading the page into.
		var objID = "dir_partidiv";

		//Take into account the backspace.
		if (theextrachar == 8){
			if (thevalue.length == 1){
				var serverPage = "modulos/busqueda/particulares/direc_parti.php";
			} else {
				var serverPage = "modulos/busqueda/particulares/direc_parti.php" + "?sstring=" + thevalue.substr (0, (thevalue.length -1));
			}
		} else {
			var serverPage = "modulos/busqueda/particulares/direc_parti.php" + "?sstring=" + thevalue + String.fromCharCode (theextrachar);
		}
		
		var obj = document.getElementById(objID);
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				obj.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}
/* funcion para autocompletar la apellidos de particulares */	
	function ape_particomplit (thevalue, e){
		
		theObject = document.getElementById("ape_partidiv");
		
		theObject.style.visibility = "visible";
		theObject.style.width = "200px";
		//theObject.style.position = "absolute";
		//theObject.style.index = "1000";
		//theObject.style.left = "5px";
		//theObject.style.top = "120px";
		
		var posx = 0;
		var posy = 0;
		
		posx = (findPosX (document.getElementById("buscadorparticular")) + 180 );
		posy = (findPosY (document.getElementById("buscadorparticular")) + 70 );
		
		theObject.style.left = posx + "px";
		theObject.style.top = posy + "px";
		
		var theextrachar = e.which;
		
		if (theextrachar == undefined){
			theextrachar = e.keyCode;
		}
		
		//The location we are loading the page into.
		var objID = "ape_partidiv";

		//Take into account the backspace.
		if (theextrachar == 8){
			if (thevalue.length == 1){
				var serverPage = "modulos/busqueda/particulares/apelli_parti.php";
			} else {
				var serverPage = "modulos/busqueda/particulares/apelli_parti.php" + "?sstring=" + thevalue.substr (0, (thevalue.length -1));
			}
		} else {
			var serverPage = "modulos/busqueda/particulares/apelli_parti.php" + "?sstring=" + thevalue + String.fromCharCode (theextrachar);
		}
		
		var obj = document.getElementById(objID);
		xmlhttp.open("GET", serverPage);
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
				obj.innerHTML = xmlhttp.responseText;
			}
		}
		xmlhttp.send(null);
	}
/* funcion para poner el nombre seleccionado en el formulario de particular */		
	function nom_partis (thevalue){
		acObject = document.getElementById("nom_partidiv");
		
		acObject.style.visibility = "hidden";
		acObject.style.height = "0px";
		acObject.style.width = "0px";
		
		document.getElementById("nom_parti").value = thevalue;
	}

/* funcion para poner la direccion seleccionada en el formulario de particular */	
	function dir_partis (thevalue){
		acObject = document.getElementById("dir_partidiv");
		
		acObject.style.visibility = "hidden";
		acObject.style.height = "0px";
		acObject.style.width = "0px";
		
		document.getElementById("dir_parti").value = thevalue;
		
		}	

/* funcion para poner la apellidos seleccionada en el formulario de particular */	
	function ape_partis (thevalue){
		acObject = document.getElementById("ape_partidiv");
		
		acObject.style.visibility = "hidden";
		acObject.style.height = "0px";
		acObject.style.width = "0px";
		
		document.getElementById("ape_parti").value = thevalue;
		
		}	
