// JavaScript Document // JavaScript Document

/** XHConn - Simple XMLHTTP Interface - bfults@gmail.com - 2005-04-08        **
 ** Code licensed under Creative Commons Attribution-ShareAlike License      **
 ** http://creativecommons.org/licenses/by-sa/2.0/                           **/
 
var tecla= window.event ? true:false;

function XHConn()
{ 
  var digital = new Date();
  var time = digital.getTime();
  var miAleatorio = time+parseInt(Math.random()*99999999);
  var xmlhttp, bComplete = false;
  try { xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); }
  catch (e) { try { xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); }
  catch (e) { try { xmlhttp = new XMLHttpRequest(); }
  catch (e) { xmlhttp = false; }}}
  if (!xmlhttp) return null;
  this.connect = function(sURL, sMethod, sVars, fnDone){
	  
    if (!xmlhttp) return false;
    bComplete = false;
    sMethod = sMethod.toUpperCase(); 

    try { 
		
      if (sMethod == "GET"){
        xmlhttp.open(sMethod, sURL+"?"+sVars+ "&rand=" + miAleatorio, true);
	    sVars = "";
		
      }else{
        xmlhttp.open(sMethod, sURL, true);
        xmlhttp.setRequestHeader("Method", "POST "+sURL+" HTTP/1.1");
        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            }//FIN ELSE
			
      xmlhttp.onreadystatechange = function(){
		  
        if (xmlhttp.readyState == 4&& !bComplete){
          bComplete = true;
          fnDone(xmlhttp);
		  
		                                         }
		  
		  };
      xmlhttp.send(sVars);
	  
         }//FIN TRY  
	
	
    catch(z) { return false; }
    return true;
  };
  return this;
}


function cargar_contenido(target,pagina){
	
	
	document.getElementById(target).innerHTML = 'Cargando..';
	var myConn = new XHConn();
		if (!myConn) alert("XMLHTTP no esta disponible. Inténtalo con un navegador más nuevo.");
		var peticion = function (oXML) {
		  
		      document.getElementById(target).innerHTML = oXML.responseText;	
			  
			};
							 
		myConn.connect(pagina, "GET", "", peticion);
}

/*function ver_documento(ID, url_busqueda){
	new Ajax.Updater( ID ,url_busqueda, {asynchronous:true, evalScripts:true, onLoading:function(request){Element.show('mini_loading');}, onComplete:function(request){Element.hide('mini_loading')}, requestHeaders:['X-Update', ID]});
}*/

/*function ver_documento(target, pagina){

	jQuery.ajax({
	  type: "POST",
          url: pagina,
          data: "",
          success: function(msg){
         	jQuery('#'+target).html(msg);
          }
        });

}*/
function ver_documento(target,page){

	jQuery.ajax({
   		type: "POST",
   		url: page,
		data: "",
		beforeSend: function(objeto){
			jQuery("#mini_loading").css("display", "block");
			//jQuery("#xss").html("<center>Cargando...</center>");
        	},
		 complete: function(objeto, exito){
           		jQuery("#mini_loading").css("display", "none");
        	},
   		success: function(msg){
			jQuery("#"+target+"").html(msg);
   		}

 	});

}



function cargar_formulario(targ,cadena,pagina){	

	target = document.getElementById(targ);

	paramdef=cadena;
	
		document.getElementById(targ).innerHTML = 'Cargando...';
	var myConn = new XHConn();
	if (!myConn) alert("XMLHTTP not available. Try a newer/better browser.");
	var submit = function (oXML) {
		
				target.innerHTML = oXML.responseText;
			 
		};
		//enviamos datos
		//usamos escape() para no tener problemas con los caracteres raros
		myConn.connect(pagina, "POST", paramdef, submit);
}







function cargar(id){
	
		
		fun_msj("ESPERE UN MOMENTO POR FAVOR...", id);	
	    cargar_contenido("principal", "contenido.php");
	
	
}//fin 


function valida_form (){
	
	var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	
if(document.getElementById("paises").value == "0"){

	fun_msj("USTED DEBE ELEGIR UNA CATEGORIA", "mensaje");	
	return false;
	
	}else if(document.getElementById("estados").value == "0"){

	fun_msj("USTED DEBE ELEGIR UNA SUB CATEGORIA", "mensaje");	
	return false;
	
	}else if(document.getElementById("nombre").value == ""){
	
	fun_msj("POR FAVOR INSERTE SU NOMBRE", "mensaje");	
	return false;
	
	}else if(document.getElementById("direccion").value == ""){

	fun_msj("POR FAVOR INSERTE SU DIRECCION", "mensaje");	
	return false;
	
	}else if(document.getElementById("telefono").value == ""){
	
	fun_msj("POR FAVOR INSERTE SU TELEFONO", "mensaje");	
	return false;
	
	}else if(document.getElementById("correo").value == ""){
	
	fun_msj("POR FAVOR INSERTE SU CORREO", "mensaje");	
	return false;
	
	}else if(!filter.test(document.getElementById('correo').value)){

			            fun_msj("El Campo Correo es Invalido", "mensaje");
					    //document.getElementById('correo').focus();
						return false;


	}else if(document.getElementById("titulo").value == ""){

	fun_msj("POR FAVOR INSERTE EL TITULO", "mensaje");	
	return false;
	
	}else if(document.getElementById("precio").value == ""){

	fun_msj("POR FAVOR INSERTE UN PRECIO", "mensaje");	
	return false;
	
	}else if(document.getElementById("anuncio").value == ""){
	
	fun_msj("POR FAVOR INSERTE SU ANUNCIO", "mensaje");	
	return false;
	
	}
	else{
		jQuery.ajax({
	  type: "POST",
          url: "includes/anuncios_clasificados/recibir_anuncio.php",
          data: jQuery("#agregar_anuncio").serialize(),
          success: function(msg){
         	jQuery('#mensaje3').html(msg);
          }
        });
        return false;
       	}
	
	}
	
	
		
function msj_none(id){document.getElementById(id).style.visibility = 'hidden';}

function fun_msj(mensaje, id){

	  document.getElementById(id).style.visibility = "visible";
	  document.getElementById(id).innerHTML = mensaje;
	  nMiliSegundos=3000;	 
	  window.setTimeout("msj_none('"+id+"');", nMiliSegundos);


}//FIN MENSAJE de ERROR


function acceptNum(evt){

  evt = (evt) ? evt : event
var key = (evt.which) ? evt.which : evt.keyCode;
if (key > 47 && key < 58 || key == 8 || key == 37 || key == 39 || key == 46 || key == 9) { return true;}
else {return false;}
}//fin function


