///Objeto Ajax //// 

function Loading(on) {
try {
	var div = $('loading');
	
	if(on == 1) {
		div.style.visibility = "visible";
		div.innerHTML = "<center><img src='../img/bigrotation2.gif'><br>Cargando...<br>Espere Porfavor</center>";
	}
	else {
		div.style.visibility = "hidden";
		div.innerHTML = null;
		div.innerHTML = "";
	}
  } catch(e) {
  	alert("No esta");
  }

}
var Ajax = function(){
	this.ajax = null;
	this.crea = creaMe;
	this.send = send;
	this.funcionIN = null;
	/*
		funcionOUT = nullFunction;
	*/
	this.funcionOUT = null;
	this.vars = null;
	this.url = null;
	this.method = "POST";
	this.sendAndReturn = sendAndReturn;
	this.sendMejorado = sendMejorado;
	this.Retorno;
	this.Preloader = false;
	this.Preloader_Div = null;
	
	function creaMe() {
		var objetoAjax = false;
		try {
			objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e) {
			try {
				objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(E) {
				objetoAjax = false;				
			}
		}
		if(!objetoAjax && typeof XMLHttpRequest != 'undefined'){
			objetoAjax = new XMLHttpRequest();
		}
		this.ajax = objetoAjax;
	}
	function send(funcionIN,funcionOUT,method,url,vars,domXML,args) {
		 if(method == "GET") {
		  url = url+"?"+vars;
		  vars = null;
		 }
		this.ajax.open(method,url);
		if(method == "POST")
		  this.ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded;');
		  var ajax = this.ajax;
		  var Preloader = this.Preloader;
		ajax.onreadystatechange = function() {
			if(Preloader == 1 && ajax.readyState < 4) {
				//Loading(1);
			}
			else if(ajax.readyState == 4 && ajax.status == 200) {
			  if(!domXML) {
			  	
				if(ajax.responseText) {
					//Funciones que se hacen cuando se recibe respuesta
					//Loading(0);
				 	this.funcionIN = funcionIN;
				 	this.funcionIN(ajax.responseText,args);
				}
			  }
			  else {
			  	this.funcionIN = funcionIN;
			  	this.funcionIN(ajax.responseXML,args);
			  }
			}
			
				else {
					//Funciones que se hacen cuando no hay respuesta
					//Loading(1);
					this.funcionOUT = funcionOUT;
					this.funcionOUT();
				}
			}
		this.ajax.send(vars);
	}
	
	function sendAndReturn() {
		this.ajax.open(this.method,this.url);
		var Retorno;
		if(this.method == "POST")
		  this.ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded;');
		  var ajax = this.ajax;
		ajax.onreadystatechange = function(){
			if (ajax.readyState == 4 && ajax.status == 200) {
				if (ajax.responseText) {
					Retorno = ajax.responseText;
				}
				else 
					Retorno = "NO HAY RESPUESTA"; 	
			}
		}
		this.ajax.send(this.vars);

	}
	
	function sendMejorado(funcionIN,funcionOUT,args) {
		 if(this.method == "GET") {
		  url = url+"?"+this.vars;
		  this.vars = null;
		 }
		this.ajax.open(this.method,this.url);
		if(this.method == "POST")
		  this.ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded;');
		  var ajax = this.ajax;
		ajax.onreadystatechange = function() {
			if(ajax.readyState == 4 && ajax.status == 200) {
			 
			  	
				if(ajax.responseText) {
					//Funciones que se hacen cuando se recibe respuesta
				 	this.funcionIN = funcionIN;
				 	this.funcionIN(ajax.responseText,args);
				}
			}
				else {
					//Funciones que se hacen cuando no hay respuesta
					this.funcionOUT = funcionOUT;
					this.funcionOUT();
				}
			}
		this.ajax.send(this.vars);
	}
		
}

var valida = function() {
	this.duplicados = duplicados;
	
	function duplicados(obj1,obj2) {
		try {
			if(obj1.value == obj2.value)
			 return true
			 else 
			 return false
		}
		catch(e){
			alert("Error "+e);
		}
	}
	
}

/**
 * Objeto ToolTip tiene un "constructor" con el mensaje
 * este objeto se tiene que crear como
 * var t = new tooltip("Este Es un mensaje de ejemplo para el tooltip");
 *  
 *  Propiedades:
 *  
 * @param {String} mensaje
 */

var tooltip = function(mensaje) { 
  
  this.mensaje = mensaje;
  this.x = 0;
  this.y = 0;
  this.position = "absolute"; 
  this.show = show;
  this.close = close;
  this.color = "#CC0000";
  this.fontColor = "#FFFFFF";
  this.divToolTip = document.getElementById('ToolTip');
  this.divToolTip.style.zIndex = 10000000;
  this.divToolTip.style.width = "250px";
  this.divToolTip.style.fontSize = "12";
  
  
  /**
   *  Metodo Show sus parametros son la posicion en la que se muestra el DIV
   *  ademas se hace visible e imprime el mensaje. Una vez que esta instanciada la "clase"
   *  se muestra usando:
   *   t.show(x,y);
   * @param {int} x
   * @param {int} y
   */
  
  function show(x,y) {
  	this.divToolTip.style.top = y;
	this.divToolTip.style.left = x;
    this.divToolTip.style.backgroundColor = this.color;
	this.divToolTip.style.color = this.fontColor;
  	this.divToolTip.innerHTML = this.mensaje;
	this.divToolTip.style.visibility = "visible";
  }
  function close() {
  	this.divToolTip.innerHTML = "";
  	this.divToolTip.style.visibility = "hidden";
  }
}


