/*
 * SimpleModal Basic Modal Dialog
 * http://www.ericmmartin.com/projects/simplemodal/
 * http://code.google.com/p/simplemodal/
 *
 * Copyright (c) 2009 Eric Martin - http://ericmmartin.com
 *
 * Licensed under the MIT license:
 *   http://www.opensource.org/licenses/mit-license.php
 *
 * Revision: $Id: basic.js 185 2009-02-09 21:51:12Z emartin24 $
 *
 */

$(document).ready(function () {
	$('#basicModal input.basic, #basicModal a.basic').click(function (e) {
		e.preventDefault();
		$('#basicModalContent').modal();
	});
});

function ajaxFunction() {
var xmlHttp;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
return xmlHttp;
} catch (e) {
// Internet Explorer
try {
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
return xmlHttp;
} catch (e) {
try {
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
return xmlHttp;
} catch (e) {
alert("Tu navegador no soporta AJAX!");
return false;
}}}
}
var control = false;
function tecla(e,valor,campo,contenedor,letra){
	parent.scroll(1,1);
	if(valor.length >= 1 && control)
		{
		var myDiv2 = document.getElementById('div_asesorar');
		if(valor != '')
			{
			myDiv2.style.display='block';
			}
		else
			{
			control = false;
			myDiv2.style.display='none';
			}
		var myDiv = document.getElementById('div_asesor');
		myDiv2.style.left=(getDimensions(myDiv).x + 124)+'px';
		myDiv2.style.top=(getDimensions(myDiv).y + 25)+'px';
		var divcontenedor=document.getElementById(contenedor);
		var campotexto=	document.getElementById(campo);
		}
	else
		{
		if(e == letra.charCodeAt(0) && valor.length <=1)
			{
			control = true;
			var myDiv2 = document.getElementById('div_asesorar');
			if(valor != '')
				{
				myDiv2.style.display='block';
				}
			else
				{
				control = false;
				myDiv2.style.display='none';
				}
			var myDiv = document.getElementById('div_asesor');
			myDiv2.style.left=(getDimensions(myDiv).x +124)+'px';
			myDiv2.style.top=(getDimensions(myDiv).y + 25)+'px';
			var divcontenedor=document.getElementById(contenedor);
			var campotexto=	document.getElementById(campo);
			}
		else
			{
			control = false;
			var myDiv2 = document.getElementById('div_asesorar');
			myDiv2.style.display='none';
			}
		}
	if(e == 9)
		{	
		cerrar_asesores();
		}
	if(e == 13)
		{	
		document.divcontenedor.innerHTML = '';
		document.campotexto.focus();
		}
	else
		{
		if(e == 40)
			{
			document.getElementById('lista').focus();
			obj=document.getElementById('lista');
			obj.selectedIndex = 0
			}
		else
			{
			MostrarConsulta(valor,campo,contenedor);
			}
		}
}
function MostrarConsulta(valor,campo,contenedor)
	{
	var ajax;
	ajax = ajaxFunction();
	var divcontenedor=document.getElementById(contenedor);
	var campotexto=	document.getElementById(campo);	
	ajax.open("POST", "../includes/asesorar/asesor.php",true);
	ajax.onreadystatechange=function() 
		{
		if (ajax.readyState==4) 
			{

			divcontenedor.innerHTML = ajax.responseText

			}
		}
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send("prod="+valor+"&campo="+campo+"&contenedor="+contenedor)
	}
function verificar(e,valor,campo,contenedor)
{
	var divcontenedor=document.getElementById(contenedor);
	var campotexto=	document.getElementById(campo);	
if(e==27)
	{
	campotexto.focus();
	divcontenedor.innerHTML = '';
	}
if(e==13)
	{
	campotexto.value = valor;
	campotexto.focus();
	divcontenedor.innerHTML = '';
	document.location.href="http://www.portaldelaindustria.com/rubro/"+valor;	
	}
}	
function cargar(valor,campo,contenedor)
	{
	var divcontenedor=document.getElementById(contenedor);
	var campotexto=	document.getElementById(campo);	
	campotexto.value = valor;
	campotexto.focus();
	divcontenedor.innerHTML = '';
	document.location.href="http://www.portaldelaindustria.com/rubro/"+valor;	
	}
///////////////////////////////////////////////////////////////////
getDimensions = function(oElement) {
  var x, y, w, h;
  x = y = w = h = 0;
  if (document.getBoxObjectFor) { // Mozilla
     var oBox = document.getBoxObjectFor(oElement);
     x = oBox.x-1;
     w = oBox.width;
     y = oBox.y-1;
     h = oBox.height;
   }
   else if (oElement.getBoundingClientRect) { // IE
     var oRect = oElement.getBoundingClientRect();
     x = oRect.left-2;
     w = oElement.clientWidth;
     y = oRect.top-2;
     h = oElement.clientHeight;
   }
   return {x: x, y: y, w: w, h: h};
 }


