
var divIdArray = new Array(); //Guarda el id del div ejemplo id="subpage"
var httpReqs = new Array();

function InstancesAjax(type, http) {
	this.type = type;
	this.http = http;
}

function nuevoAjax(){
   var xmlHttp=false;
   try {
         xmlHttp = new XMLHttpRequest("Msxml2.XMLHTTP");
       } 
   catch (e) {
                try  {
                        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
                     }
                catch (e)  {
                              try  {
                                      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                                   }
                              catch (e) {
                                           alert("Your browser does not support AJAX!");
                                           return false;
                                        }
                           }
             }

    if (!xmlHttp && typeof XMLHttpRequest!='undefined') {
           xmlHttp = new XMLHttpRequest();
    }

    return xmlHttp;
} 

function onreadystatechange()
{
	if (typeof(window['httpReqs']) == "undefined") return;
	
    try {
		for (var i=0; i < httpReqs.length; i++) {	
	 		if(httpReqs[i].http.readyState == 1){
        		document.getElementById(divIdArray[i]).innerHTML="Cargando.......";
        	}
			else if (httpReqs[i].http.readyState == 4) {
				results = httpReqs[i].http.responseText;
				document.getElementById(divIdArray[i]).innerHTML = results;
				divIdArray.splice(i,1); 
				httpReqs.splice(i,1); i--;
			}
		}
   }
	catch (e){
	  	//alert(e);
	}
}

function selectPage(url,id,metodo,valores) {
       var http = false;
	   
       divIdArray.push(id); //agraga al vector
	   
	   http = new nuevoAjax();
       http.open(metodo, url, true);
       http.onreadystatechange = onreadystatechange; 

       switch(metodo.toUpperCase()){
            case 'GET':
               http.send(null);
               break;
               
            case 'POST':
               http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
               http.send(valores);
               break;   

            default:
               alert("Metodo invalido: " + metodo);
               break;     
       }    

	   	var httpReq = new InstancesAjax('',http);
	    httpReqs.push(httpReq);   
		
}

//"selectPage('form_cotizacion.htm','pageZone','post','capas='+ document.getElementById('capas').selectedIndex+'&largo='+ document.getElementById('largo').value'&ancho='+ document.getElementById('ancho').value+'&cantidad='+ document.getElementById('cantidad').value)+'&silkscreenLayer='+ document.getElementById('silkscreenLayer').selectedIndex+'&silkscreenColor='+ document.getElementById('silkscreenColor').selectedIndex+'&soldermaskColor='+ document.getElementById('soldermaskColor').selectedIndex" style="float: right"></td>
function sendForm(page,id,form,metodo){
var valores = "";
        
               for(i=0;i<form.elements.length;i++){
  		           x = form.elements[i].id + "=" + form.elements[i].value;
                   if(i!=0){
                       valores = valores + "&";
                   }    
                   valores = valores + x;
               }
               //alert(valores);
               if(metodo.toUpperCase()=='GET')
               {
                 page = page + "?" + valores;
               }

        selectPage(page,id,metodo,valores);
  
} 

function DeliveryTime(objeto)
{  
  //alert(objeto.selectedIndex);
  //alert(objeto.selectedIndex);
  capas = objeto.selectedIndex
  switch(capas)
  {
     case 0:
       document.getElementById('dias').value = 10;
       break;
     case 1:
       document.getElementById('dias').value = 11;
       break;
     case 2:
       document.getElementById('dias').value = 15;
       break;
  } 
}




