// Documento JavaScript
// Esta función cargará las paginas
WIdDivAnt= "";

function llamarasincrono(url, id_contenedor){
var pagina_requerida = false
if (window.XMLHttpRequest) {// Si es Mozilla, Safari etc
pagina_requerida = new XMLHttpRequest()
} else if (window.ActiveXObject){ // pero si es IE
try {
pagina_requerida = new ActiveXObject("Msxml2.XMLHTTP")
} 
catch (e){ // en caso que sea una versión antigua
try{
pagina_requerida = new ActiveXObject("Microsoft.XMLHTTP")
}
catch (e){}
}
}
else
return false
pagina_requerida.onreadystatechange=function(){ // función de respuesta
cargarpagina(pagina_requerida, id_contenedor)
}
pagina_requerida.open('POST', url, true) // asignamos los métodos open y send
pagina_requerida.send(null)
}
// todo es correcto y ha llegado el momento de poner la información requerida
// en su sitio en la pagina xhtml
function cargarpagina(pagina_requerida, id_contenedor){
  if (pagina_requerida.readyState == 4 && (pagina_requerida.status==200 || window.location.href.indexOf("http")==-1)){
      document.getElementById(id_contenedor).innerHTML=pagina_requerida.responseText    
    }
  else {document.getElementById(id_contenedor).innerHTML= '<img src="images/indicator_green.gif"/> Loading...';}
}
//funcion para envio  de Datos  POST AJAX
function ExtractInfo(iPage,IsHtml,IsAsinc,pFuncToGenAsinc){
    if (!IsAsinc){IsAsinc=false;}    
    if (!IsHtml){IsHtml=true;}    
    if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc 
        xmlhttp=new XMLHttpRequest();       
    }else if (window.ActiveXObject) { //IE 
        xmlhttp=new ActiveXObject('Msxml2.XMLHTTP');   //Microsoft  o Msxml2   Msxml2.XMLHTTP.3.0      Msxml2.XMLHTTP
        if (!xmlhttp) {   //xmlhttp.onreadystatechange=ReciveOpenFileCFG;  //eval('xmlhttp.onreadystatechange='+pFunc+';');              Opcional para Explorer
           return;           
        }
    }     
    if (typeof pFuncToGenAsinc!='undefined'){ 
      eval('xmlhttp.onreadystatechange='+pFuncToGenAsinc +';'); 
    }
    //   xmlhttp.onload=ejemplo;   eventos on load 
    //xmlhttp.onprogress=ejemplo;   eventos para on progress             
    xmlhttp.open("GET",iPage, IsAsinc); // leave true for Gecko   true  asincrono  false no es asincrono  si es true  ejecuta la Funcion Arriba Mencionada           
    xmlhttp.setRequestHeader('Content-Type','text/' + (IsHtml)?'html':'plain' + ';charset=UTF-8');    //charset=ISO-8859-1  windows-1252
    xmlhttp.send(null);  
    var DataToReturn=xmlhttp.responseText;
    return DataToReturn;    
}
  
function SaveToDB(iPage,iParams,IsAsinc,iDivWait,pFuncToGenAsinc){ 
   //------------- Genera el Wait
   if(iDivWait!="" && document.getElementById(iDivWait)){
   //alert(document.getElementById(iDivWait).value);
      document.getElementById(iDivWait).innerHTML="<img border='0' src='Images/indicator_green.gif'>";
   }
   var xmlHttp = new XMLHttpRequest()   
   xmlHttp.open("POST", iPage, IsAsinc);   // False Sincrono    True Asyncrono 
   xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;  charset=UTF-8');
   if (typeof pFuncToGenAsinc!='undefined'){ 
      eval('xmlHttp.onreadystatechange='+pFuncToGenAsinc +';'); 
    }
    var wCadtoPass=iParams + "&nocache=" + Math.random();
    xmlHttp.send(wCadtoPass);
	//alert(iDivWait);
    if(iDivWait!="" && document.getElementById(iDivWait)){document.getElementById(iDivWait).innerHTML="";}    
	//alert(document.getElementById(iDivWait).value);
	return xmlHttp.responseText;
	
}
      
function RecibeIfonHttp() {        // Funcion que recibira la informacion cuando el .open = true  por supuesto esta es el prototipo ya que solo me servira como modelo de datos as
 if (xmlhttp.readyState==4) { 
    if (xmlhttp.status==200) {var wCadDev =xmlhttp.responseText;}   //responseXML  responseText           
  }        
}

function ReturnAllFields(iForm){
    var wCadRet='';
    for(var j=0;j<=iForm.elements.length-1;j++){      
        var iElement=iForm.elements[j];
         if(iElement.type=='text'|| iElement.type=='textarea' || iElement.type=='password' || iElement.type=='hidden' || iElement.type=='select-one'){
            wCadRet+=((wCadRet!='')?'&':'') + iElement.id + '=' + encodeURIComponent(iElement.value);}else if (iElement.type=='checkbox'){
            wCadRet+=((wCadRet!='')?'&':'') + iElement.id + '=' + encodeURIComponent(iElement.checked)
            }
      } 
    return wCadRet
}
//Funcion Para mostrar los menus //
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function mostrardiv(type){
div="";
var div = document.getElementById(type);
 if (div!=WIdDivAnt){
    if(WIdDivAnt!=""){
		Ocultadiv(WIdDivAnt.id)
		div.style.display = 'inline';
	    WIdDivAnt=div;
	}
     oacultarProductos()
	 div.style.display = 'inline';
	 WIdDivAnt=div;	
    }
}

function oacultarProductos(){
var div = document.getElementById('Productos');
div.style.display='none';

}
function Ocultadiv(type){
var div = document.getElementById(type);
  if (!div){
  div = document.getElementById('Productos');
  }
div.style.display='none';
}
      
function FocusOff(WObj){
    WObj.style.color="#5FB404";
    WObj.style.background="#FFFFFF";
    WObj.style.border="1px #6E6E6E solid";    
}
function FocusOn(WObj){
  WObj.style.color="#FFFFFF";
  WObj.style.background="#5FB404";
  WObj.style.border="1px #333333 solid";
}
function SendMail(){
   if(document.FRMReg.TxtEmail.value==""){ alert("Es necesario una direccion de correo ....");return;}
   var iParam=ReturnAllFields(document.FRMReg);   
   var wCad=SaveToDB("SendMail.asp",iParam,false,'');
   if (wCad!=""){ alert("Su mensaje fuen enviado con éxito \n Muy pronto un ejecutivo se pondara en contacto con usted ...\n Gracias Por su Preferencia ")}
}

function validarEmail(valor) {  
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(valor)){
return true;
} else {
   alert("La dirección de email es incorrecta")
return false;
}
} 

function OpenAcces(){
	
	
}

