// JavaScript Document
function CreateObjetoAjax() {
	var Objeto;
		var browser = navigator.appName;
		if(browser == "Microsoft Internet Explorer"){
			Objeto = new ActiveXObject("Microsoft.XMLHTTP");
		}else{
			Objeto = new XMLHttpRequest();
		}
			return Objeto
 }
 /* function transaccion(action) {
	var HTTP = CreateObjetoAjax();
	 HTTP.open("get", "server.php?action="+action);
     HTTP.onreadystatechange=function() { 
   				if (HTTP.readyState==4) { 
   						recibe(HTTP.responseText); 
   				} 
  		} 
       HTTP.send(null);
}*/
 function transaccion(sw,parametros) {
	var HTTP = CreateObjetoAjax();
	 HTTP.open("POST", "ajax/server_callcenter.php?valor=Yasser",true);
	                                                   //aparte de mandar con el Post
	                                                   //tambien mandamos en la url una 
													   //variable que puede ser tratada como get 
	 HTTP.setRequestHeader('Content-Type','application/x-www-form-urlencoded')
	 //HTTP.send('variable='+action);//asi se manda una sola variable
	 HTTP.send('sw=' + sw + '&parametros=' + parametros);//asi se manda varias variables
	 HTTP.onreadystatechange=function() { 
	            
   				if (HTTP.readyState==4) { 
   						recibe(HTTP.responseText); //aqui recibo el mensaje
						
				}
  		} 
       
}




function recibe(action){
	
		var descriminador =	action.substring(0,1);//PORQUE LA POSICION 0 TRAE EL NUMERO
		
		                                         //EN LA POSICION 1 VIENE EL MICHI
		   
	    var cadena_total =	action.substring(2,action.length); //PORQUE A PARTIR DE LA 
		                                                       //POSICION 2 TRAE LO DEMAS
	 
	    
		switch (descriminador){
			
			case "1":   
						
						document.getElementById("sp_contiene").innerHTML=cadena_total;
						break;
						
						
		   case  "2":  
					  	
						document.getElementById("sp_contiene").innerHTML=cadena_total;
						break;
						
		   case  "3": 
		                
						document.getElementById("sp_contiene").innerHTML=cadena_total;
						break;
						
		   case  "4":  
						
						document.getElementById("sp_contiene").innerHTML=cadena_total;
						break;
								
 		   case  "5":  
						var arreglo=cadena_total.split("|");
						var pie_contacto=arreglo[0];
						var idioma=arreglo[1];
						
						if(idioma=="1"){//español
							
							construye_contacto_es();
							
						}else if(idioma=="2"){//ingles
							
							construye_contacto_ing();
							
						}
						document.getElementById("td_contacto").innerHTML=pie_contacto;
						
						break;
						
 		   case  "6":  
						
						window.location='index.php';
						break;
					   
 		   case  "7":  
						
						window.location='index.php';
						break;
					   
 		   case  "8":  
						
						if(cadena_total=="ok"){
							document.getElementById("btn_contacto").disabled=false;
							limpia_contacto();
							var men="¡ Mensaje enviado con éxito !";
							document.getElementById("men_gif").innerHTML=men;
						}
						
						break;
						
						
						
					   
 		   case  "9":  
						
						
						document.getElementById("sp_contiene").innerHTML=cadena_total;
						break;
					   
		
	   }//end switch

}//end function 



function carga_sw_es(){
	
 var strhtml='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="760" height="318">'
 
strhtml+='<param name="movie" value="swf/cabecera_es_conprecarga.swf" /><param name="quality" value="high" />';
  
  strhtml+='<embed src="swf/cabecera_es_conprecarga.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="760" height="318"></embed></object>'
  
  document.getElementById("div_cabecera").innerHTML=strhtml;
	
}

function carga_sw_ing(){
	
 var strhtml='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="760" height="318">'
 
strhtml+='<param name="movie" value="swf/cabecera_ing_conprecarga.swf" /><param name="quality" value="high" />';
  
  strhtml+='<embed src="swf/cabecera_ing_conprecarga.swf" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="760" height="318"></embed></object>'
  
  document.getElementById("div_cabecera").innerHTML=strhtml;
	
}


function home(){
	
	transaccion("1","");
	gif_ajax("sp_contiene");
}

function nosotros(){
	
	transaccion("2","");
	gif_ajax("sp_contiene");
}

function servicios(){
	
	transaccion("3","");
	gif_ajax("sp_contiene");
}

function tecnologia(){
	
	transaccion("4","");
	gif_ajax("sp_contiene");
}

function contacto(){
	transaccion("5","");
	gif_ajax("sp_contiene");
}

function idioma_es(){
	transaccion("6","");
	gif_ajax("sp_contiene");
		
}


function idioma_ing(){
	transaccion("7","");
	gif_ajax("sp_contiene");
}


function banners(sw){
	
	//EN EL SW VIENE EL IDDETALLE QUE NOS VA SERVIR
	//PARA TRAER EL CONTENIDO DE CADA BANNER
	transaccion("9",sw);
	gif_ajax("sp_contiene");
	
}



function gif_ajax(id_object){
	
	var strhtml="<br/><br/><br/><br/>";
	    strhtml+="<img src='imagenes/progress.gif'>";
	document.getElementById(id_object).innerHTML=strhtml;
	
}



function construye_contacto_es(){
 
       var strhtml="<div class='div_titulo'>CONTACTO</div>";
	   
	   strhtml+="<table width='490' class='tb_contacto' cellpadding='0' cellspacing='2'>";
	   
	   strhtml+="<tr>";
	   strhtml+="<td style='text-align:left;' colspan='2'>";
	   strhtml+="Para obtener más información sobre nuestros servicios y tarifas, ";
	   strhtml+="por favor llene el formulario y uno de nuestros representantes lo ";
	   strhtml+="contactará a la brevedad:";
	   strhtml+="</td>";
	   strhtml+="</tr>";
	   
	   strhtml+="<td  colspan='2'>";
	   strhtml+="<span class='sp_obligatorio'>&nbsp;&nbsp;(*)Campos Obligatorios</span>";
	   strhtml+="</td>";
	   strhtml+="</tr>";
	   
	   strhtml+="<tr>";
	   strhtml+="<td class='td_label_contacto' >";
	   strhtml+="Nombre:";
	   strhtml+="</td>";
	   strhtml+="<td class='td_label_campo'>";
	   strhtml+="<input type='text' id='txt_nombre' size='50' class='txt_contacto' />";
	   strhtml+="<span class='sp_obligatorio'>&nbsp;&nbsp;(*)</span>";
	   strhtml+="</td>";
	   strhtml+="</tr>";	
	   
	   strhtml+="<tr>";
	   strhtml+="<td class='td_label_contacto' >";
	   strhtml+="Correo electrónico:";
	   strhtml+="</td>";
	   strhtml+="<td class='td_label_campo'>";
	   strhtml+="<input type='text' id='txt_correo' size='50' class='txt_contacto' />";
	   strhtml+="<span class='sp_obligatorio'>&nbsp;&nbsp;(*)</span>";
	   strhtml+="</td>";
	   strhtml+="</tr>";	
	   
	   strhtml+="<tr>";
	   strhtml+="<td class='td_label_contacto' >";
	   strhtml+="Teléfono:";
	   strhtml+="</td>";
	   strhtml+="<td class='td_label_campo'>";
	   strhtml+="<input type='text' id='txt_telefono' size='30' class='txt_contacto' />";
	   strhtml+="</td>";
	   strhtml+="</tr>";
	   
	   strhtml+="<tr>";
	   strhtml+="<td class='td_label_contacto' >";
	   strhtml+="Asunto:";
	   strhtml+="</td>";
	   strhtml+="<td class='td_label_campo'>";
	   strhtml+="<input type='text' id='txt_asunto' size='50' class='txt_contacto' />";
	   strhtml+="<span class='sp_obligatorio'>&nbsp;&nbsp;(*)</span>";
	   strhtml+="</td>";
	   strhtml+="</tr>";
	   
	   strhtml+="<tr>";
	   strhtml+="<td class='td_label_contacto' >";
	   strhtml+="Mensaje:";
	   strhtml+="</td>";
	   strhtml+="<td class='td_label_campo'>";
	   strhtml+="<textarea cols='35' rows='10' class='txt_contacto' id='txt_mensaje'></textarea>";
	   strhtml+="<span class='sp_obligatorio'>&nbsp;&nbsp;(*)</span>";
	   strhtml+="</td>";
	   strhtml+="</tr>";
	   
	   strhtml+="<tr>";
	   strhtml+="<td class='td_label_campo' colspan='2' style='text-align:center;'>";
	   strhtml+="<input type='button' value='Envia' class='btn_contacto' id='btn_contacto'";
	   strhtml+="onclick='graba_contacto()'/><br/><span id='men_gif'></span>";
	   strhtml+="</td>";
	   strhtml+="</tr>";
	   
	   strhtml+="<tr>";
	   strhtml+="<td colspan='2' >&nbsp;";
	   strhtml+="</td>";
	   strhtml+="</tr>";
	   
	   strhtml+="<tr>";
	   strhtml+="<td colspan='2' id='td_contacto'>";
	   strhtml+="</td>";
	   strhtml+="</tr>"; 
	   strhtml+="</table>";
	   

	   
	 
   
   document.getElementById("sp_contiene").innerHTML=strhtml;
   

}


function construye_contacto_ing(){
 
       var strhtml="<div class='div_titulo'>CONTACTS</div>";
	   
	   strhtml+="<table width='490' class='tb_contacto' cellpadding='0' cellspacing='2'>";
	   
	   strhtml+="<tr>";
	   strhtml+="<td style='text-align:left;' colspan='2'>";
	   strhtml+="In order to obtain more data on our services and tariffs, ";
	   strhtml+="please it fills the form and one of our representatives will ";
	   strhtml+="contact it to the brevity:";
	   strhtml+="</td>";
	   strhtml+="</tr>";
	   
	     
	   
	   
	   strhtml+="<td  colspan='2'>";
	   strhtml+="<span class='sp_obligatorio'>&nbsp;&nbsp;(*)obligatory fields</span>";
	   strhtml+="</td>";
	   strhtml+="</tr>";
	   
	   strhtml+="<tr>";
	   strhtml+="<td class='td_label_contacto' >";
	   strhtml+="Fullname:";
	   strhtml+="</td>";
	   strhtml+="<td class='td_label_campo'>";
	   strhtml+="<input type='text' id='txt_nombre' size='50' class='txt_contacto' />";
	   strhtml+="<span class='sp_obligatorio'>&nbsp;&nbsp;(*)</span>";
	   strhtml+="</td>";
	   strhtml+="</tr>";	
	   
	   strhtml+="<tr>";
	   strhtml+="<td class='td_label_contacto' >";
	   strhtml+="Email:";
	   strhtml+="</td>";
	   strhtml+="<td class='td_label_campo'>";
	   strhtml+="<input type='text' id='txt_correo' size='50' class='txt_contacto' />";
	   strhtml+="<span class='sp_obligatorio'>&nbsp;&nbsp;(*)</span>";
	   strhtml+="</td>";
	   strhtml+="</tr>";	
	   
	   strhtml+="<tr>";
	   strhtml+="<td class='td_label_contacto' >";
	   strhtml+="Telephone:";
	   strhtml+="</td>";
	   strhtml+="<td class='td_label_campo'>";
	   strhtml+="<input type='text' id='txt_telefono' size='30' class='txt_contacto' />";
	   strhtml+="</td>";
	   strhtml+="</tr>";
	   
	   strhtml+="<tr>";
	   strhtml+="<td class='td_label_contacto' >";
	   strhtml+="Subject:";
	   strhtml+="</td>";
	   strhtml+="<td class='td_label_campo'>";
	   strhtml+="<input type='text' id='txt_asunto' size='50' class='txt_contacto' />";
	   strhtml+="<span class='sp_obligatorio'>&nbsp;&nbsp;(*)</span>";
	   strhtml+="</td>";
	   strhtml+="</tr>";
	   
	   strhtml+="<tr>";
	   strhtml+="<td class='td_label_contacto' >";
	   strhtml+="Message:";
	   strhtml+="</td>";
	   strhtml+="<td class='td_label_campo'>";
	   strhtml+="<textarea cols='35' rows='10' class='txt_contacto' id='txt_mensaje'></textarea>";
	   strhtml+="<span class='sp_obligatorio'>&nbsp;&nbsp;(*)</span>";
	   strhtml+="</td>";
	   strhtml+="</tr>";
	   
	   strhtml+="<tr>";
	   strhtml+="<td class='td_label_campo' colspan='2' style='text-align:center;'>";
	   strhtml+="<input type='button' value='Send' class='btn_contacto' id='btn_contacto'";
	   strhtml+="onclick='graba_contacto()'/><br/><span id='men_gif'></span>";
	   strhtml+="</td>";
	   strhtml+="</tr>";
	   
	   strhtml+="<tr>";
	   strhtml+="<td colspan='2' >&nbsp;";
	   strhtml+="</td>";
	   strhtml+="</tr>";
	   
	   strhtml+="<tr>";
	   strhtml+="<td colspan='2' id='td_contacto'>";
	   strhtml+="</td>";
	   strhtml+="</tr>"; 
	   strhtml+="</table>";
	   

	   
	 
   
   document.getElementById("sp_contiene").innerHTML=strhtml;
   

}




function graba_contacto(){
	
	var nombres=document.getElementById("txt_nombre").value;
	    nombres=trim(nombres);
		nombres=manda_transformacion(nombres);
	var correo=document.getElementById("txt_correo").value;
	var telefono=document.getElementById("txt_telefono").value;
	var asunto=document.getElementById("txt_asunto").value;
	    asunto=trim(asunto);
		asunto=manda_transformacion(asunto);
		
	var mensaje=document.getElementById("txt_mensaje").value;
	    mensaje=trim(mensaje);
		mensaje=manda_transformacion(mensaje);
		
	
	if(nombres.length==0){
		var mensaje="Ingrese su nombre por favor";
		alert(mensaje);
		return false;
	}
	
	if(correo.length==0){
		var mensaje="Ingrese su correo por favor";
		alert(mensaje);
		return false;
	}
	
	if(asunto.length==0){
		var mensaje="Ingrese el asunto por favor";
		alert(mensaje);
		return false;
	}
	
	if(mensaje.length==0){
		var mensaje="Ingrese el mensaje por favor";
		alert(mensaje);
		return false;
	}
	
	var cadena=nombres+"|"+correo+"|"+telefono+"|"+asunto+"|"+mensaje;
	transaccion("8", cadena);
	
	
	document.getElementById("btn_contacto").disabled=true;
	
    var strhtml="<img src='imagenes/progress.gif'>";
	document.getElementById("men_gif").innerHTML=strhtml;
	
	
}

function limpia_contacto(){
	document.getElementById("txt_nombre").value="";
	document.getElementById("txt_correo").value="";
	document.getElementById("txt_telefono").value="";
	document.getElementById("txt_asunto").value="";
	document.getElementById("txt_mensaje").value="";
	
}


