var var_obj_activo;
var var_imagen_color;

var meses = new Array("enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre");

function main(){
 if (!var_obj_activo){
   var obj_aux = document.getElementById('bt_inicio');  
   //if (obj_aux){
   mostrar(obj_aux, 'images/menu_inicio_sel.jpg', obj_aux.src, 'bot'); 	
   //}
 }
}

function chequear(who) 
{
 var Result=true;
 
 if (who=='sms'){
   sendSMS(who);	 
 }
 else{
  if (who=='registro'){
   with (document.register) {
     cod_enviar.value = cod_enviar.value.replace(/^\s*|\s*$/g,"");
	 if (cod_enviar.value=="") {
       Result=false;
       alert("Debe ingrese el codigo a enviar.");
       cod_enviar.focus();
     } 
	 if (Result==true) {
	   sendRegistro(cod_enviar.value); 	  
       //submit();
     }
   }
  }
  else {
   with (document.mailform) { 
     nombre.value = nombre.value.replace(/^\s*|\s*$/g,"");
     if (nombre.value=="" && Result) {
       Result = false;
       alert("Debe ingresar el nombre.");
       nombre.focus();
     }
     apellido.value = apellido.value.replace(/^\s*|\s*$/g,"");  
   	 if (apellido.value=="" && Result) { 
       Result = false;
       alert("Debe ingresar el apellido.");
       apellido.focus();
     }
     var At = email.value.indexOf("@",0)
     if (At < 1 && Result) {
       Result = false;
       alert ("Debe ingresar un Email correcto.");
       email.focus();
     }  
     if (who!="demo"){
       comentario.value = comentario.value.replace(/^\s*|\s*$/g,"");
       if (comentario.value=="" && Result) {
         Result=false;
         alert("Debe ingrese el comentario.");
         comentario.focus();
       }
	 }
     if (Result==true) {
       sendMail(who); 	  
     //submit();
     }
   }
  }
 }
}

function poner_s(cantidad) {
  if (cantidad > 1) return 's';
  else return '';
}

function next_month(){
  res_proximo_pago = document.getElementById('proximo_pago');
  texto = "";
  mes = 0;
  xmlhttp2=nuevoXmlHttp();
  xmlhttp2.open("POST", "script/mes.php", true);
  xmlhttp2.onreadystatechange=function() {
    if (xmlhttp2.readyState==4) {
	  res_proximo_pago.innerHTML = 'Nota: el segundo mes se pagar&iacute;a en ' + xmlhttp2.responseText;
    }
  }
  xmlhttp2.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  xmlhttp2.send(texto);  
}

function calcular() {
  res_tot_men = document.getElementById('total_mensual'); 
  res_tot_men.innerHTML = "$ 39";
   
  res_hora = document.getElementById('total_horas');
  res_horas_unica = document.getElementById('total_horas_unica');
  cantidad = 0; 
  with (document.cotizar){
    if (cantidad_horas.value != ""){
     cantidad = cantidad_horas.value;	 	   	
    }
  }
  res_hora.innerHTML = "$ " + cantidad * 80;
  res_horas_unica.innerHTML = res_hora.innerHTML;
  
  res_detalle_compra = document.getElementById('detalle_compra');
  texto = "cantidad_horas="+cantidad;
  xmlhttp=nuevoXmlHttp();
  xmlhttp.open("POST", "script/detalle_compra.php", true);
  xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4) {
      res_detalle_compra.innerHTML = xmlhttp.responseText;
    }
  }
  xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  xmlhttp.send(texto);

  next_month();
}

function cotizar_ofi(who, cantidad_ext){
	   res = document.getElementById('cotizar_offilex');
	   
	   var_script = "script/compra_1.php";
	   
	   texto="";
	   
	   if (who=='compra_1'){
		 var_script = "script/compra_2.php";  
	     cantidad = 1;  
         with (document.cotizar){
           if (cantidad_horas.value != ""){
             cantidad = cantidad_horas.value;
           }
         }
     	 texto="cantidad_horas="+cantidad;
	   }

       xmlhttp=nuevoXmlHttp();
       xmlhttp.open("POST", var_script, true);
       xmlhttp.onreadystatechange=function() {
         if (xmlhttp.readyState==4) {
           res.innerHTML = xmlhttp.responseText;
		   if (who=='load' || who=='compra_2'){
		     if (who=='compra_2'){
			   with (document.cotizar){
                 cantidad_horas.value = cantidad_ext;
			   }
			 }
			 calcular();
		   }
		   else next_month();
         }
       }
       xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
       xmlhttp.send(texto);
}

function chequear_compra() 
{  var Result = true;

   with (document.enviar_compra) { 
     titular.value = titular.value.replace(/^\s*|\s*$/g,"");
     if (titular.value=="" && Result) {
       Result = false;
       alert("Debe ingresar el titular.");
       titular.focus();
     }
	 
     telefono.value = telefono.value.replace(/^\s*|\s*$/g,"");  
   	 if (telefono.value=="" && Result) { 
       Result = false;
       alert("Debe ingresar el telefono.");
       telefono.focus();
     }
	 
     var At = email.value.indexOf("@",0)
     if (At < 1 && Result) {
       Result = false;
       alert ("Debe ingresar un Email correcto.");
       email.focus();
     }  
     
     if (Result==true) {
       sendCompra(); 	  
     //submit();
     }
	 
   }
}

function sendCompra(){
       res = document.getElementById('cotizar_offilex');
   
       with (document.enviar_compra) {  
    	 texto="titular="+titular.value+"&estudio="+estudio.value+"&domicilio="+domicilio.value+"&localidad="+localidad.value+"&provincia="+provincia.value+"&telefono="+telefono.value+"&email="+email.value+"&comentario="+comentario.value+"&cantidad_horas="+cantidad_horas.value;
	   }

       xmlhttp=nuevoXmlHttp();
       res.innerHTML = '<span class="offilex">Enviando...</span>'; 
       xmlhttp.open("POST", "script/mail_compra.php",true);
       xmlhttp.onreadystatechange=function() {
         if (xmlhttp.readyState==4) {
           res.innerHTML = xmlhttp.responseText;		   
         }
       }
       xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
       xmlhttp.send(texto);
}

function KeyPress_numeros(e) {
  tecla=(document.all) ? e.keyCode : e.which;	
    
  if ((tecla != 8) && (tecla < 48 || tecla > 57)){
    return false;
  }
  
  return true;
}

function nuevoXmlHttp(){
	var xmlhttp=false;
	try{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}catch(e){
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}catch(E){
			xmlhttp = false;
		}
	}	
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}


function nuevoDOMParser(xmlText){
   var parser = false;
   var xmldoc = false;

   if (window.DOMParser) {
     parser = new DOMParser();
     xmldoc = parser.parseFromString(xmlText,"text/xml");
   }
   else { // Internet Explorer
     xmldoc = new ActiveXObject("Microsoft.XMLDOM");
     xmldoc.async = "false";
     xmldoc.loadXML(xmlText);		 
   } 
   return xmldoc;
}

function sendSMS(who){
       res = document.getElementById('result_mail');
   
       with (document.sms) {  
         nomemp=nomemp.value;
		 numdestino=numdestino.value;
		 titulo=titulo.value;
		 mensaje=mensaje.value;
		 
		 texto="nomemp="+nomemp+"&numdestino="+numdestino+"&titulo="+titulo+"&mensaje="+mensaje;
		 
	   }
   
       xmlhttp=nuevoXmlHttp();
       res.innerHTML = '<span class="offilex">Enviando...</span>'; 
       xmlhttp.open("POST", "../script/sms.php",true);
       xmlhttp.onreadystatechange=function() {
         if (xmlhttp.readyState==4) {
           res.innerHTML = xmlhttp.responseText;
         }
       }
       xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
       xmlhttp.send(texto);
}


function sendMail(who){
       res = document.getElementById('result_mail');
   
       with (document.mailform) {  
         nom=nombre.value;
         ape=apellido.value;
		 emp=empresa.value;
		 tel=telefono.value;
		 dom=domicilio.value;
		 ema=email.value;
		 
		 texto="nombre="+nom+"&apellido="+ape+"&empresa="+emp+"&telefono="+tel+"&domicilio="+dom+"&email="+ema+"&who="+who;
		 
		 if (who!="demo"){
		   com=comentario.value;
		   texto = texto+"&comentario="+com;
		 }

         if (who=="compra"){
		   pro =   "\n		Offilex Profesional";
		   lic=licencias.value;
		   texto=texto+"&producto="+pro+"&licencias="+lic;
		 }
	   }
   
       xmlhttp=nuevoXmlHttp();
       res.innerHTML = '<span class="offilex">Enviando...</span>'; 
       xmlhttp.open("POST", "script/mail.php",true);
       xmlhttp.onreadystatechange=function() {
         if (xmlhttp.readyState==4) {
           res.innerHTML = xmlhttp.responseText;
         }
         borrarCampos(who)
       }
       xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
       xmlhttp.send(texto);
}

function sendRegistro(cod_env){
	   texto="user=&password=!sophia2009";
	   xmlhttp=nuevoXmlHttp();
	   xmlhttp.open("POST", "../script/get_ip.php", true);
	   xmlhttp.onreadystatechange=function() {
       if (xmlhttp.readyState == 4) {
		   var xmlText = xmlhttp.responseText;
		   
		   xmlDoc = nuevoDOMParser(xmlText);
		   		  		   
		   var datos = xmlDoc.getElementsByTagName("datos");
		   var varip = datos[0].getElementsByTagName("ip")[0].firstChild.nodeValue;
		   var varport = datos[0].getElementsByTagName("port")[0].firstChild.nodeValue;
				   
		   sendRegistro2(cod_env, varip, varport);
         }
       }
       xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	   xmlhttp.send(texto);
}

function sendRegistro2(cod_env, ip, port) {
	   res = document.getElementById('result_register');
	   
	   texto="codigo="+cod_env+"&ip="+ip+"&port="+port;
	   
	   xmlhttp=nuevoXmlHttp();
          
       innerHtml = '<table border="0" cellspacing="0" cellpadding="0"> \
                     <tr> \
                      <td valign="middle"> \
                       <span class="offilex">Conectando y enviando registro. Espere por favor...</span> \
                      </td> \
                      <td valign="middle" width="15"></td> \
                      <td valign="middle"> \
                       <img src="../images/register.gif" width="54" height="55"> \
                      </td> \
                     </tr> \
                    </table>';
 
       res.innerHTML = innerHtml; 
       xmlhttp.open("POST", "../script/register.php", true);
       xmlhttp.onreadystatechange=function() {
         if (xmlhttp.readyState==4) {
           res.innerHTML = xmlhttp.responseText;
         }
       }
       xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	   xmlhttp.send(texto);
}

function borrarCampos(who){
  if (who=='registro'){
    with (document.register) {
      cod_enviar.value = "";	 
    }
  }
  else{
	with (document.mailform) {	 
      if (who=="compra"){
        licencias.value = "0";
      }
      nombre.value = "";
      apellido.value = "";
      empresa.value = "";
      telefono.value = "";
      domicilio.value = "";
      email.value = "";
      if (who!="demo"){
		comentario.value = "";
	  }
      nombre.focus();
    }
  }
}

function abrir(pagina, alto, ancho){
  window.open(pagina, 'window', 'height=' + alto + ', resizable=no, scrollbars=yes, width=' + ancho);
}

function file_to_cuerpo(cuerpo, objeto_id, idioma){
  texto = "objeto_id="+objeto_id+"&idioma="+idioma;
        
  xmlhttp=nuevoXmlHttp();
  xmlhttp.open("POST", "script/load_file.php",true);
  xmlhttp.onreadystatechange=function() {
    if (xmlhttp.readyState==4) {
	  cuerpo.innerHTML = xmlhttp.responseText;
	  
	  if (objeto_id == 'bt_comprar'){
		cotizar_ofi('load');
	  }
    }
  }
  xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
  xmlhttp.send(texto);
}

function mostrar(objeto, imagen_color_sel, imagen_color_desel, tipo, idioma) {
 if (document.getElementById && (!var_obj_activo || (var_obj_activo != objeto))){    
  
   var cuerpo = document.getElementById('cuerpo');
   
   file_to_cuerpo(cuerpo, objeto.id, idioma);
   
   if (tipo){
     mouse(objeto, imagen_color_sel, tipo, 'texto_claro', true);
 	 
     if (var_obj_activo){
   	   mouse(var_obj_activo, var_imagen_color, var_tipo, 'texto_link', true);
     }
   
     var_obj_activo = objeto; 
     var_imagen_color = imagen_color_desel;	     
     var_tipo = tipo;
   }
 }
}

function mouse(objeto, imagen_color, tipo, style, forzar){
   if (forzar || (!var_obj_activo || (var_obj_activo != objeto))){         
   switch (tipo){
	 case 'bot': { 
	   objeto.src = imagen_color; 	   
	 }
	 break;
	 case 'tex': { 	   
	   objeto.style.backgroundColor = imagen_color;
	 }
	 break;
   }
   if (style) objeto.className = style;
  }
}

function mouse_t(objeto, style){
  if (style) objeto.className = style;
}

function getScreenShot(caja, size, id){  
   function append ( url, img ) { 
     var link = document.createElement('a'); 
	 img.style.border = 'none'; 
     link.href = url; 
     link.appendChild(img); 
	 container.innerHTML = '';  
     container.appendChild(link); 
   }
   
   var container = document.getElementById(id),  
        thumbs = Thumbnails({  
        devkey:'e5d8f1e625301344953db56a2b96adf8',  
        size:size,  
        nothumb:'noimage.gif'  
   });  

   thumbs.get(caja, append);   
}  


													