// JavaScript Document
  var xmlhttp;
  var url;
  var ACTION2;
  //function AJAX( ACTION , NUM , MAX , CT )
  function AJAX( ACTION, pas_servicio , pas_medio_transporte , pas_tipo_carga , pas_asegurada , pas_aduana )  
  {
	ACTION2	=	ACTION;

	switch(ACTION)
	{
		case	1	:	

			incio_trans('0');
			url		=	( "pcs.vmx.ven1.php?txt_empresa="+document.getElementById("txt_empresa").value+"&txt_nombre_contacto="+document.getElementById("txt_nombre_contacto").value+"&txt_puesto="+document.getElementById("txt_puesto").value+"&txt_telefono="+document.getElementById("txt_telefono").value+"&txt_mail="+document.getElementById("txt_mail").value+"&txt_origen="+document.getElementById("txt_origen").value+"&txt_destino="+document.getElementById("txt_destino").value+"&txt_numero_carga="+document.getElementById("txt_numero_carga").value+"&txt_medidas="+document.getElementById("txt_medidas").value+"&txt_peso_bruto="+document.getElementById("txt_peso_bruto").value+"&txt_volumen="+document.getElementById("txt_volumen").value+"&txt_comentarios="+document.getElementById("txt_comentarios").value+"&pas_servicio="+pas_servicio+"&pas_medio_transporte="+pas_medio_transporte+"&pas_tipo_carga="+pas_tipo_carga+"&pas_asegurada="+pas_asegurada+"&pas_aduana="+pas_aduana+"&txt_tipo_mercancia="+document.getElementById("txt_tipo_mercancia").value+"&CMD=1&"+ Math.random() );
			break;

		case	2	:	

			url		=	( "pcs.vmx.ven1.php?k="+pas_servicio+"&CMD=2&"+ Math.random() );
			break;
	}



	xmlhttp =	null;
	
	if( window.XMLHttpRequest )
	{
			xmlhttp =       new XMLHttpRequest();
	}
	else if ( window.ActiveXObject )
	{
			xmlhttp =       new ActiveXObject("Microsoft.XMLHTTP");
	}
	if ( xmlhttp != null )
	{
			xmlhttp.onreadystatechange      =       state_Change;
			xmlhttp.open( "GET" , url , true );
			xmlhttp.send( null );
	}
	else
	{
			alert("Your browser does not support XMLHTTP.");
	}

  }
  
  
function state_Change()
{
        if (xmlhttp.readyState==4)
        {
			if (xmlhttp.status==200)
        	{
				strResponse 	= xmlhttp.responseText;
				strCadena  		= strResponse.split('@');

				switch(ACTION2)
				{
					case	1	:	
							switch(strCadena[0]){
			
								case "1":

									document.getElementById('tbl_proceso').style.display = 'none';			
									document.getElementById('tbl_msj_sistema').style.display = 'block';												
									document.getElementById("div_msj").innerHTML = strCadena[2];																	
									AJAX(2,strCadena[1],0,0,0,0);		
									
									document.location.href = "vmx.ven1.php#home";

								break;

								case "2":

									incio_trans('1');		
									document.getElementById('tbl_proceso').style.display = 'none';												
									document.getElementById('tbl_msj_sistema').style.display = 'block';												
									document.getElementById("div_msj").innerHTML = strCadena[2];																	
									 
								break;
							}
					break;						
					
					case	2	:	
					break;
				}
        	}
            else
        	{
				if( xmlhttp.responseText == '')
				{
					//alert('Error A215.');
				}
				else
				{
					//alert('Error A216');
				}
        	}
        }
 }

function validar(){

	if( document.getElementById('txt_empresa').value != ''	){
		if( document.getElementById('txt_nombre_contacto').value != ''	){
			if( document.getElementById('txt_puesto').value != ''	){
				if( document.getElementById('txt_telefono').value != ''	){
					if( document.getElementById('txt_mail').value != ''	){
						if( document.getElementById('txt_origen').value != ''	){
							if( document.getElementById('txt_destino').value != ''	){
								if( document.getElementById('txt_numero_carga').value != ''	){
									if( document.getElementById('txt_tipo_mercancia').value != ''	){									
										if( document.getElementById('txt_medidas').value != ''	){
											if( document.getElementById('txt_peso_bruto').value != ''	){
												if( document.getElementById('txt_volumen').value != ''	){
														var tipo_servicio = '';
														if( document.frm_datos.rdo_tipo_servicio[0].checked == true ){
															tipo_servicio = document.frm_datos.rdo_tipo_servicio[0].value;
														}else{
															if( document.frm_datos.rdo_tipo_servicio[1].checked == true ){
																tipo_servicio = document.frm_datos.rdo_tipo_servicio[1].value;
															}else{
																if( document.frm_datos.rdo_tipo_servicio[2].checked == true ){
																	tipo_servicio = document.frm_datos.rdo_tipo_servicio[2].value;
																}else{
																	alert('Debe seleccionar un tipo de servicio.');		
																	exit();
																}
															}
														}
														
														var medio_transporte = '';
														if( document.frm_datos.rdo_medio_transporte[0].checked == true ){
															medio_transporte = document.frm_datos.rdo_medio_transporte[0].value;
														}else{
															if( document.frm_datos.rdo_medio_transporte[1].checked == true ){
																medio_transporte = document.frm_datos.rdo_medio_transporte[1].value;
															}else{
																if( document.frm_datos.rdo_medio_transporte[2].checked == true ){
																	medio_transporte = document.frm_datos.rdo_medio_transporte[2].value;
																}else{
																	alert('Debe seleccionar un medio de transporte.');		
																	exit();
																}
															}
														}
														
														var tipo_carga = '';
														if( document.frm_datos.rdo_tipo_carga[0].checked == true ){
															tipo_carga = document.frm_datos.rdo_tipo_carga[0].value;
														}else{
															if( document.frm_datos.rdo_tipo_carga[1].checked == true ){
																tipo_carga = document.frm_datos.rdo_tipo_carga[1].value;
															}else{
																alert('Debe seleccionar un tipo de carga.');		
																exit();
															}
														}	
														
														var asegurada = '';
														if( document.frm_datos.rdo_asegurada[0].checked == true ){
															asegurada = document.frm_datos.rdo_asegurada[0].value;
														}else{
															if( document.frm_datos.rdo_asegurada[1].checked == true ){
																asegurada = document.frm_datos.rdo_asegurada[1].value;
															}else{
																alert('Debe seleccionar si la mercancia esta asegurada.');		
																exit();
															}
														}	
													
														var aduana = '';
														if( document.frm_datos.rdo_aduana[0].checked == true ){
															aduana = document.frm_datos.rdo_aduana[0].value;
														}else{
															if( document.frm_datos.rdo_aduana[1].checked == true ){
																aduana = document.frm_datos.rdo_aduana[1].value;
															}else{
																alert('Debe seleccionar si cuenta con despacho aduanal.');		
																exit();
															}
														}
														
														AJAX(1,tipo_servicio,medio_transporte,tipo_carga,asegurada,aduana);													
													
												}else{
													alert('Debe proporcionar el volumen.');		
												}
											}else{
												alert('Debe proporcionar el peso bruto.');		
											}
										}else{
											alert('Debe proporcionar las medidas de la carga.');		
										}
									}else{
										alert('Debe proporcionar el tipo de mercancía.');		
									}
								}else{
									alert('Debe proporcionar el número de bultos o cargas.');		
								}
							}else{
								alert('Debe proporcionar el destino del envío.');		
							}
						}else{
							alert('Debe proporcionar el origen del envío.');		
						}
					}else{
						alert('Debe proporcionar el e-mail.');		
					}
				}else{
					alert('Debe proporcionar el número de teléfono');		
				}
			}else{
				alert('Debe proporcionar el puesto.');		
			}
		}else{
			alert('Debe proporcionar el nombre del contacto.');		
		}
	}else{
		alert('Debe proporcionar el nombre de la empresa.');		
	}

}

function incio_trans(VARS){
	switch(VARS){
		case "0":

			document.getElementById('tbl_seccion_contacto').style.display = 'none';
			document.getElementById('tbl_terrestre_nac_campos').style.display = 'none';
			document.getElementById('tbl_mensaje').style.display = 'none';
			document.getElementById('tbl_cmd').style.display = 'none';
			document.getElementById('tbl_proceso').style.display = 'block';			
			 
		break;

		case "1":

			document.getElementById('tbl_seccion_contacto').style.display = 'block';
			document.getElementById('tbl_terrestre_nac_campos').style.display = 'block';
			document.getElementById('tbl_mensaje').style.display = 'block';
			document.getElementById('tbl_cmd').style.display = 'block';
			document.getElementById('tbl_proceso').style.display = 'none';			


		break;
	}
}


 function wg(){
	if(	document.getElementById('tbl_widget').style.display == 'none'){
		document.getElementById('tbl_widget').style.display = 'block'
	}else{
		document.getElementById('tbl_widget').style.display = 'none'		
	}
 }

 function tc(){
	if(	document.getElementById('tbl_tc_disel').style.display == 'none'){
		document.getElementById('tbl_tc_disel').style.display = 'block'
	}else{
		document.getElementById('tbl_tc_disel').style.display = 'none'		
	}	 
 }
 
 function tipo_cambio(){
	window.open("http://tipodecambiohoy.com")
 }
 
 function precio_combustible(){
	window.open("http://www.cpac.com.mx")
 }
 
