function nuevoAjax(){
	// Crea el objeto AJAX.
	var xmlhttp=false;
	try {
		// Creacion del objeto AJAX para navegadores no IE
		xmlhttp=new ActiveXObject('Msxml2.XMLHTTP');
	}
	catch(e){
		try{
			// Creacion del objet AJAX para IE
			xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch(E){
			xmlhttp=false;
		}
	}
	if(!xmlhttp && typeof XMLHttpRequest!='undefined'){
		xmlhttp=new XMLHttpRequest();
	}
	return xmlhttp;
}

function verificaPais(selectACargar,langt){
	var selectAnterior=selectACargar-1;
	var valor=document.getElementById('CP_'+selectAnterior).options[document.getElementById('CP_'+selectAnterior).selectedIndex].value;
	var elemento;
	if(selectAnterior == 1){
		if(valor == 'MX'){
			document.form.E_Tel_Pais_1.value='52';
		}
		else{
			if(valor == 'US' || valor == 'CA'){
				document.form.E_Tel_Pais_1.value='001';
			}
			else{
				document.form.E_Tel_Pais_1.value='';
			}
		}
	}
	if (valor == 'MX'){
		y=2;
		while(y < 6){
			elemento2 = document.getElementById('codigo_postal_'+y);
			newInput = document.createElement('select');
			newInput.setAttribute('id','CP_'+y);
			newInput.setAttribute('name','CP_'+y);
			elemento2.replaceChild(newInput, elemento2.lastChild);
			y++;
		}
		cargaContenido_categorias(2,langt)
	}else{
		if(valor == 'US' || valor == 'CA'){
			y=2;
			elemento2 = document.getElementById('codigo_postal_'+y);
			newInput = document.createElement('select');
			newInput.setAttribute('id','CP_'+y);
			newInput.setAttribute('name','CP_'+y);
			if(elemento2.lastChild){
				elemento2.replaceChild(newInput, elemento2.lastChild);
			}
			y++;
			while(y < 6){
				elemento2 = document.getElementById('codigo_postal_'+y);
				newInput = document.createElement('input');
				newInput.setAttribute('type','text');
				newInput.setAttribute('id','CP_'+y);
				newInput.setAttribute('name','CP_'+y);
				newInput.onchange=function(){uppercase(this);};
				if(y!=5){newInput.setAttribute('size','30');}else{newInput.setAttribute('size','8');newInput.setAttribute('maxlength','8');}
				if(elemento2.lastChild){
					elemento2.replaceChild(newInput, elemento2.lastChild);
				}
				y++;
			}
			cargaContenido_categorias(2,langt)
		}else{
			if(valor != -1){
				y=2;
				while(y < 6){
					elemento2 = document.getElementById('codigo_postal_'+y);
					newInput = document.createElement('input');
					newInput.setAttribute('type','text');
					newInput.setAttribute('id','CP_'+y);
					newInput.setAttribute('name','CP_'+y);
					newInput.onchange=function(){uppercase(this);};
					if(y!=5){newInput.setAttribute('size',30);}else{newInput.setAttribute('size',8);newInput.setAttribute('maxLength',8);}
					if(elemento2.lastChild){
						elemento2.replaceChild(newInput, elemento2.lastChild);
					}
					y++;
				}
			}else{
				y=2;
				while(y < 6){
					elemento2 = document.getElementById('codigo_postal_'+y);
					newInput = document.createElement('input');
					newInput.setAttribute('type','text');
					newInput.setAttribute('id','CP_'+y);
					newInput.setAttribute('name','CP_'+y);
					newInput.onchange=function(){uppercase(this);};
					newInput.setAttribute('readOnly','true');
					if(y!=5){newInput.setAttribute('size',30);}else{newInput.setAttribute('size',8);newInput.setAttribute('maxLength',8);}
					if(elemento2.lastChild){
						elemento2.replaceChild(newInput, elemento2.lastChild);
					}
					y++;
				}
			}
		}
	}
}

function cargaContenido_categorias(selectACargar,langt){
	var elemento;
	var opcionCargando

	// Recibo el número correspondiente al combo que se debe llenar de datos
	var selectAnterior=selectACargar-1; // Obtengo el número del combo que activó el evento onChange
	// Extraigo el valor del combo que se ha cambiado
	var valor=document.getElementById('CP_'+selectAnterior).options[document.getElementById('CP_'+selectAnterior).selectedIndex].value;
	if(valor!=-1){
		ajax=nuevoAjax();
		// Envio al servidor el valor seleccionado y el combo al cual se le deben poner los datos
		ajax.open('GET', 'postales_slave.php?seleccionado='+valor+'&categ='+selectACargar+'&langt='+langt, true);
		//alert(selectACargar	);
		ajax.onreadystatechange=function(){
			if (ajax.readyState==1){
				elemento=document.getElementById('CP_'+selectACargar);
				elemento.length=0;
				if(selectACargar!=5){
					opcionCargando=document.createElement('option'); opcionCargando.value=-1;
					if(langt=='en'){
						opcionCargando.innerHTML='Downloading...';
					}else{
						opcionCargando.innerHTML='Cargando...';
					}
					elemento.appendChild(opcionCargando);
				}
				elemento.disabled=true;
			}
			if (ajax.readyState==4){
				document.getElementById('codigo_postal_'+selectACargar).innerHTML=ajax.responseText;

				if(selectACargar == '3' && valor=='D.F.'){
					if(langt=='en'){
						document.getElementById("t_E_Ciudad").innerHTML='<span class="requiered">*</span>Delegation:';
					}else{
						document.getElementById("t_E_Ciudad").innerHTML='<span class="requiered">*</span>Delegación:';
					}
				}else{
					if(langt=='en'){
						document.getElementById("t_E_Ciudad").innerHTML='<span class="requiered">*</span>City:';
					}else{
						document.getElementById("t_E_Ciudad").innerHTML='<span class="requiered">*</span>Ciudad/Municipio:';
					}
				}
			}
		}
		ajax.send(null);
	}
}

/***************************************************************************************************************/
/***************************************************************************************************************/
/*function cargaTable(cat,opc){

if(opc==0)
{
var texto;
var valor;
var flag2;
//posible valores vip dealer platinum asociado estudiante
	texto=categoria(cat);


	flag = document.getElementById("flag").value;
	flag2 = document.getElementById("flag2").value;
	//alert("esto tiene flag: "+flag);
 if(flag==0)
 {
	obDiv = document.getElementById("thirdParty");
	document.getElementById("thirdfeature").innerHTML="<b>Para realizar una compra adicional vuelva a dar click al carrito de compra</b>";
	obDiv.innerHTML="";
	obTab = document.createElement("table");
	obDiv.appendChild(obTab);
	obTab.cellspacing="0";
	obTab.border="1";
	obTab.bordercolor="#000000";
	obTab.width="100%";
    obTab.id="tableThird";


    /**********************************titulo***************************************************************************** /
	var tr = obTab.insertRow(-1);
	var td = document.createElement("td");
	td.align="center";
	td.width="15%";
	td.innerHTML="NOMBRE";
	tr.appendChild(td);
    /**********************************titulo***************************************************************************** /
	var td = document.createElement("td");
	td.align="center";
	td.width="15%";
	td.innerHTML="APELLIDO PATERNO";
	tr.appendChild(td);
    /**********************************titulo***************************************************************************** /
	var td = document.createElement("td");
	td.align="center";
	td.width="15%";
	td.innerHTML="APELLIDO MATERNO";
	tr.appendChild(td);
    /**********************************2***************************************************************************** /
	var td = document.createElement("td");
	td.align="center";
	td.id="correo";
	td.name="correo";
	td.width="15%";
	td.innerHTML="CORREO";
	tr.appendChild(td);
    /**********************************3***************************************************************************** /
	var td = document.createElement("td");
	td.align="center";
	td.width="15%";
	td.innerHTML="TIPO COMPRA";
	tr.appendChild(td);

    /**********************************5***************************************************************************** /
	var td = document.createElement("td");
	td.align="center";
	td.width="5%";
	td.innerHTML="BORRAR";
	tr.appendChild(td);
	/***********************************primera impresion****************************************************************** /
	var tr = obTab.insertRow(-1);
	  tr.id="tr_0";
	  tr.name="tr_0";
	tr.insertCell(0).innerHTML=document.getElementById("E_Nombre").value;
	tr.insertCell(1).innerHTML=document.getElementById("E_ApellidoPaterno").value;
	tr.insertCell(2).innerHTML=document.getElementById("E_ApellidoMaterno").value;
	tr.insertCell(3).innerHTML=document.getElementById("E_Email_1").value;
	tr.insertCell(4).innerHTML=texto+' <input type="hidden" id="oculto_'+flag+'" name="oculto_'+flag+'" value="'+cat+'" />';
	tr.insertCell(5).innerHTML='&nbsp;';

	document.getElementById("flag").value="1";
	document.getElementById("flag2").value="1";
	flag2=1;//se encarga de llevar el indice de los renglones para evitar el problema de ya no poder borrar renglones
	/*********************************************************************************************************************** /

 }
 else
 {
  obTab = document.getElementById("tableThird");
  var tr = obTab.insertRow(-1);
  tr.id="tr_"+flag2;
  tr.name="tr_"+flag2;

	/***********************************segundas impresiones****************************************************************** /
	tr.insertCell(0).innerHTML='<input id="name_'+flag2+'"   name="name_'+flag2+'"   size="15px" width="15%" type="text"   onchange="javascript:this.value=this.value.toUpperCase();" >';
	tr.insertCell(1).innerHTML='<input id="last1_'+flag2+'"  name="last1_'+flag2+'"  size="15px" width="15%" type="text"   onchange="javascript:this.value=this.value.toUpperCase();">';
	tr.insertCell(2).innerHTML='<input id="last2_'+flag2+'"  name="last2_'+flag2+'"  size="15px" width="15%" type="text"   onchange="javascript:this.value=this.value.toUpperCase();">';
	tr.insertCell(3).innerHTML='<input id="correo_'+flag2+'" name="correo_'+flag2+'" size="15px" width="15%" type="text"    onchange="javascript:this.value=this.value.toLowerCase();" onCopy="return false" onDrag="return false" onDrop="return false" onPaste="return false" autocomplete=off>';
	tr.insertCell(4).innerHTML=texto+' <input type="hidden" id="oculto_'+flag2+'" name="oculto_'+flag2+'" value="'+cat+'" />';//lleva oculto la categoria que es el renglón
	var td = document.createElement("td");
	td.align="center";
	td.width="15%";
	td.innerHTML='<IMG SRC="../img/incomplete.gif" onclick="cargaTable(this.value,'+flag2+')">';
	tr.appendChild(td);
	   flag++;
	   flag2++;
  //alert("esto tiene flag2 "+flag2);
   document.getElementById("flag").value=flag;
   document.getElementById("flag2").value=flag2;
  }
 }

else
 {
  var oculto = document.getElementById("oculto_"+opc).value;
   if(oculto=='vip')
   {valor=document.getElementById("noDealerVip").value;
  	if(valor==1)
 	{valor2=document.getElementById("noDealer").value;//obtenemos la cantidad de Dealers comprados
 	 if(valor2!=0)
 	 {
 	  alert("No puede Borrar este DealerVip, tiene un Dealer  escogido");

 	 }
 	 else
 	 {
 	  resta(oculto);
 	 var celda = document.getElementById("tr_"+opc);
	 celda.innerHTML="";

 	 document.getElementById("group2").disabled=true;
 	 }
 	}
 	else
 	{
	 resta(oculto);
   	 var celda = document.getElementById("tr_"+opc);
	 celda.innerHTML="";

 	}
   }
   else
   {
//   alert("restando"+opc);
	 resta(oculto);
   	 var celda = document.getElementById("tr_"+opc);
	 celda.innerHTML="";
   }


 }
}*/
/***************************************************************************************************************/
/***************************************************************************************************************/

function resta(cat)
{
 var valor;
 var flag;
	switch(cat)
	{
 	case 'vip':

 	valor=document.getElementById("noDealerVip").value;//obtiene el valor pasado del numero de DealerVip comprados
 	valor--;
 	if(valor==0)
 	{
 	document.getElementById("advertencia").innerHTML='<td colspan="6"><b><font size=1>No se puede escoger Un Dealer hasta que se compre un Dealer Vip</font></b></td>';
 	}
 	document.getElementById("noDealerVip").value=valor;//actualiza el numero de DealerVip
    flag=document.getElementById("flag").value;
	flag--;
    document.getElementById("flag").value=flag;
 	break;

 	case 'dealer':
 	valor=document.getElementById("noDealer").value;//obtiene el valor pasado del numero de Dealer comprados
 	valor--;
 	document.getElementById("noDealer").value=valor;//actualiza el numero de Dealer
 	flag=document.getElementById("flag").value;
	flag--;
    document.getElementById("flag").value=flag;
 	break;

 	case 'platinum':
 	valor=document.getElementById("noPlatinum").value;//obtiene el valor pasado del numero de Platinum comprados
 	valor--;
 	document.getElementById("noPlatinum").value=valor;//actualiza el numero de Platinum
    flag=document.getElementById("flag").value;
	flag--;
    document.getElementById("flag").value=flag;
  	break;

 	case 'asociado':
 	valor=document.getElementById("noAsociado").value;//obtiene el valor pasado del numero de Asociado comprados
 	valor--;
 	document.getElementById("noAsociado").value=valor;//actualiza el numero de Asociado
    flag=document.getElementById("flag").value;
	flag--;
    document.getElementById("flag").value=flag;
 	break;

 	case 'estudiante':
 	valor=document.getElementById("noEstudiante").value;//obtiene el valor pasado del numero de Estudiante comprados
 	valor--;
 	document.getElementById("noEstudiante").value=valor;//actualiza el numero de Estudiante
    flag=document.getElementById("flag").value;
	flag--;
    document.getElementById("flag").value=flag;
	 break;
	}
	return texto;
}
/***************************************************************************************************************/
/***************************************************************************************************************/
function categoria(cat)
{
 var valor;
	switch(cat)
	{
 	case 'vip':
 	valor=document.getElementById("noDealerVip").value;//obtiene el valor pasado del numero de DealerVip comprados
 	valor++;
 	document.getElementById("noDealerVip").value=valor;//actualiza el numero de DealerVip
 	document.getElementById("flagDealer").value="1";
 	document.getElementById("group2").disabled=false;
 	document.getElementById("advertencia").innerHTML="";
 	texto = "Dealer VIP";
 	break;

 	case 'dealer':
 	valor=document.getElementById("noDealer").value;//obtiene el valor pasado del numero de Dealer comprados
 	valor++;
 	document.getElementById("noDealer").value=valor;//actualiza el numero de Dealer
 	texto = "Dealer";
 	break;

 	case 'platinum':
 	valor=document.getElementById("noPlatinum").value;//obtiene el valor pasado del numero de Platinum comprados
 	valor++;
 	document.getElementById("noPlatinum").value=valor;//actualiza el numero de Platinum
 	texto = "No asociado Platinum";
 	break;

 	case 'asociado':
 	valor=document.getElementById("noAsociado").value;//obtiene el valor pasado del numero de Asociado comprados
 	valor++;
 	document.getElementById("noAsociado").value=valor;//actualiza el numero de Asociado
 	texto = "No asociado";
 	break;

 	case 'estudiante':
 	valor=document.getElementById("noEstudiante").value;//obtiene el valor pasado del numero de Estudiante comprados
 	valor++;
 	document.getElementById("noEstudiante").value=valor;//actualiza el numero de Estudiante
	 texto = "Académicos y estudiantes";
	 break;
	}
	return texto;
}

/***************************************************************************************************************/
/***************************************************************************************************************/

function cargaTercero(num,cat){

 var flag;
 var text;
 //	alert("si esta seleccionado");
	//alert(num);
	//alert(cat);
	flag = document.getElementById("flag").value;
	alert(flag);
	alert(cat);
	ajax=nuevoAjax();
	ajax.open('GET', 'thirdParty.php?seleccionado='+flag+'&categ='+cat, true);
	ajax.onreadystatechange=function(){
			if (ajax.readyState==1){
			 //document.getElementById('thirdParty').innerHTML="Cargando";
			}
			if (ajax.readyState==4){
				//document.getElementById('tipo_paquete').disabled=true;
				if(flag==0)
				{
				 document.getElementById('thirdParty').innerHTML=ajax.responseText;
				}
				else
				{
				text="div_"+flag;
				document.getElementById(text).innerHTML=ajax.responseText;
				}
				//document.getElementById('boton').innerHTML='<input name="tipo_paquete" type="button" id="tipo_paquete" value="Siguiente"  onclick="cargaClaveWeb(document.getElementById(\'Total_invitados\').value,2);"/>';
			}
		}
		ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		ajax.send(null);

}
/***************************************************************************************************************/
/***************************************************************************************************************/
function cargaClaveWeb(num,cat){
var categoria = cat;

	//detecta si el usuario a ingresado un "0" como numero de claves o quiere continuar sin poner número de claves
	if(num==0||num=='')
	{
	 alert("es cero o num");
	 //document.getElementById('thirdParty').innerHTML="";
	 return false;
    }

	if (!/^([0-9])*$/.test(num))
	{
      document.getElementById('t_label').className = 'tfvHighlight';
	  //document.getElementById('tipo_paquete').disabled=true;
      alert("El valor " + num + " no es un número");
      return false;
    }
    else
    {
     document.getElementById('t_label').className = 'tfvNormal';
     //document.getElementById('tipo_paquete').disabled=false;

    }

	var elemento;
	var opcionCargando;
	//alert(num);
	ajax=nuevoAjax();
	ajax.open('GET', 'thirdParty.php?seleccionado='+num+'&categ='+categoria, true);
	ajax.onreadystatechange=function(){
			if (ajax.readyState==1){
			 document.getElementById('thirdParty').innerHTML="Cargando";
			}
			if (ajax.readyState==4){
				//document.getElementById('tipo_paquete').disabled=true;
				document.getElementById('thirdParty').innerHTML=ajax.responseText;

			}
		}

		ajax.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
		ajax.send(null);

}
/***************************************************************************************************************/
/***************************************************************************************************************/

function cargaTercero1(num,cat){

var flag = document.getElementById("flag_third").checked;
var categoria = cat;
if(flag)
{
 //	alert("si esta seleccionado");
	//alert(num);
	//alert(cat);
	ajax=nuevoAjax();
	ajax.open('GET', 'thirdParty.php?seleccionado='+num+'&categ='+categoria, true);
	ajax.onreadystatechange=function(){
			if (ajax.readyState==1){
			 document.getElementById('thirdParty').innerHTML="Cargando";
			}
			if (ajax.readyState==4){
				//document.getElementById('tipo_paquete').disabled=true;
				document.getElementById('thirdParty').innerHTML=ajax.responseText;
				//document.getElementById('boton').innerHTML='<input name="tipo_paquete" type="button" id="tipo_paquete" value="Siguiente"  onclick="cargaClaveWeb(document.getElementById(\'Total_invitados\').value,2);"/>';
			}
		}
		ajax.send(null);
}
else
{
	//alert("no esta seleccionado");
		var elemento;
	var opcionCargando;
	//alert(num);
	ajax=nuevoAjax();
	ajax.open('GET', 'thirdParty.php?seleccionado='+num, true);
	ajax.onreadystatechange=function(){
			if (ajax.readyState==1){
			 document.getElementById('thirdParty').innerHTML="Cargando";
			}
			if (ajax.readyState==4){
				//document.getElementById('tipo_paquete').disabled=true;
				document.getElementById('thirdParty').innerHTML='<input name="tipo_paquete" type="submit" id="tipo_paquete" value="Siguiente"   disabled="false"/>';

			}
		}
		ajax.send(null);

}


}
/***************************************************************************************************************/
/***************************************************************************************************************/

function traerDatos(tipoPago,ref)
{
	// Obtengo la capa donde se muestran las respuestas del servidor
	var capa1=document.getElementById("tarjeta");
	var capa2=document.getElementById("trans");
	var capa3=document.getElementById("deposito");
	// Creo el objeto AJAX
	var ajax=nuevoAjax();
	// Coloco el mensaje "Cargando..." en la capa
	capa1.innerHTML="Cargando...";
/***************************************************************************************************************************/
	ajax.open("GET", "ajax.php?tipo="+tipoPago+"&referencia="+ref, true);
	//ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	//ajax.open('GET', 'thirdParty.php?seleccionado='+num, true);
	//ajax.send("tipo="+tipoPago+"&referencia="+ref);

	ajax.onreadystatechange=function()
	{
		if (ajax.readyState==4)
		{
			switch(tipoPago)
			{
			 // Respuesta recibida. Coloco el texto plano en la capa correspondiente

			 case 1:
 			 capa1.innerHTML=ajax.responseText;
			 capa2.innerHTML='';
			 capa3.innerHTML='';
			 break;
			 case 2:
			 capa2.innerHTML=ajax.responseText;
			 capa1.innerHTML='';
			 capa3.innerHTML='';
			 break;
			 case 3:
			 capa3.innerHTML=ajax.responseText;
			 capa1.innerHTML='';
			 capa2.innerHTML='';
			 break;
			}
		}
	}
	ajax.send(null);
}/***************************************************************************************************************/
/***************************************************************************************************************/
function salida()
{
 if(confirm("¿Desea Abandonar la Compra?"))
 {
  alert("Usted  quiere salir");
  window.location='http://www.foroautomotor.com.mx/intro.html';

 }

}

/***************************************************************************************************************/
/***************************************************************************************************************/

function traerDatos2(tipoPago,ref)
{
	// Obtengo la capa donde se muestran las respuestas del servidor
	var capa1=document.getElementById("tarjeta");
	var capa2=document.getElementById("trans");
	var capa3=document.getElementById("deposito");
	// Creo el objeto AJAX
	var ajax=nuevoAjax();
	// Coloco el mensaje "Cargando..." en la capa
	capa1.innerHTML="Cargando...";
/***************************************************************************************************************************/
	ajax.open("GET", "ajax2.php?tipo="+tipoPago+"&referencia="+ref, true);
	//ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	//ajax.open('GET', 'thirdParty.php?seleccionado='+num, true);
	//ajax.send("tipo="+tipoPago+"&referencia="+ref);

	ajax.onreadystatechange=function()
	{
		if (ajax.readyState==4)
		{
			switch(tipoPago)
			{
			 // Respuesta recibida. Coloco el texto plano en la capa correspondiente

			 case 1:
 			 capa1.innerHTML=ajax.responseText;
			 capa2.innerHTML='';
			 capa3.innerHTML='';
			 break;
			 case 2:
			 capa2.innerHTML=ajax.responseText;
			 capa1.innerHTML='';
			 capa3.innerHTML='';
			 break;
			 case 3:
			 capa3.innerHTML=ajax.responseText;
			 capa1.innerHTML='';
			 capa2.innerHTML='';
			 break;
			}
		}
	}
	ajax.send(null);
}/***************************************************************************************************************/
/***************************************************************************************************************/
