function replaceText(text){
 while(text.lastIndexOf("&") > 0){
  text = text.replace('&', '[i-Stats]');
 }
 return text;
}

var web_referrer = replaceText(document.referrer);
istat = new Image(1,1);
istat.src = "http://www.bogotaflyer.com/admin/include/web/stats/counter.php?sw="+screen.width+"&sc="+screen.colorDepth+"&referer="+web_referrer+"&page="+location.href;

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

MM_preloadImages('/imagenes/loadingAnimation.gif');

var tempX = 0
var tempY = 0

// Funciones de Capas
CreateConnect = function() {
 xmlhttp = null;
 try {
	xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 } catch (e) {
	try {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	} catch (err) {
		xmlhttp = null;
	}
 }
 
 if(!xmlhttp && typeof XMLHttpRequest != "undefined")
	xmlhttp = new XMLHttpRequest();
 
 if (!xmlhttp){
	alert('No se puede conectar con el servidor');
 }
 
 return xmlhttp;
}

doLoad = function() {
 document.getElementById('DataLy').style.zIndex = 99998;
 document.getElementById('DataW').innerHTML = '';
 str = '<table align="center"><tr><td><img src="/script/thickbox/loadingAnimation.gif" border="0" /></td></tr></table>';
 document.getElementById('DataLy').style.display = 'block';
 document.getElementById('DataW').innerHTML = str;
 if(document.getElementById('_tv_player_ly')) {
  document.getElementById('_tv_player_ly').style.display = 'none';
 }
}

doUnload = function() {
 document.getElementById('DataW').innerHTML = '';
}

showRegistry = function() {
 doLoad();
 $.get("/script/int/registry.html", function(data) { 
   doUnload();
   window.scroll(0,0);
   document.body.style.overflow = 'hidden';
   document.getElementById('DataLy').style.display = 'block';
   document.getElementById('DataW').style.top = '7%';
   document.getElementById('DataW').style.zIndex = '99999';
   document.getElementById('DataW').innerHTML = data;
 });
}

ShowContact = function() {
 doLoad();
 $.get("/script/int/cnt.html", function(data) { 
   doUnload();
   window.scroll(0,0);
   document.body.style.overflow = 'hidden';
   document.getElementById('DataW').style.top = '10%';
   document.getElementById('DataLy').style.display = 'block';
   document.getElementById('DataW').style.zIndex = 99999;
   document.getElementById('DataW').innerHTML = data;
  } );
}

chkCntForm = function() { 
 var f = document.forms['FrmContact'];
 //
 if(f.name.value == '') { alert('Escribe tu Nombre!'); f.name.focus(); return false; }
 if(f.email.value == '') { alert('Escribe tu Correo Electrónico!'); f.email.focus(); return false; } 
 if(f.email.value.indexOf('@',0) == -1 || f.email.value.indexOf('.',0) == -1) {
  alert('Escribe correctamente tu Dirección de Correo Electrónico!'); f.email.focus(); f.email.select(); return false;
 }
 if(f.Message.value == '') { alert('Escribe tu Mensaje!'); f.Message.focus(); return false; }
 f.submit();
}

CheckSessionExists = function() {
 doLoad();
 
 $.ajax({
   type: "POST",
   url: "/script/CheckSession.phpx",
   data: "s=0",
   success: function(msg){
     if(msg == '1') {
	  showUpload();
	 } else {
	  showInst();
	 }
   }
 });
}

showUpload = function() {
 if(document.getElementById('_tv_player_ly')) {
  document.getElementById('_tv_player_ly').style.display = 'none';
 }

 $.get("/script/int/upload.html", function(data) {
   doUnload();
   window.scroll(0,0);
   document.body.style.overflow = 'hidden';
   document.getElementById('DataW').style.top = '7%';
   document.getElementById('DataLy').style.display = 'block';
   document.getElementById('DataW').style.zIndex = 99999;
   document.getElementById('DataW').innerHTML = data;
  });
}

doLoginOp = function() {
 var d = document.getElementById('email_frm');
 var b = document.getElementById('doLogin_btn');
 if(d.value == '') { alert('Correo Vacio!'); return false; }
 if(d.value.indexOf('@',0) == -1 || d.value.indexOf('.',0) == -1) { alert('Correo no valido!'); return false; }
 //
 b.disabled = true;
 //
 $.ajax({
   type: "POST",
   url: "/script/doLogin.phpx",
   data: "email="+d.value,
   success: function(msg){
     if(msg == '1') {
      removeLy(); 
	  showUpload(); 
	 } else {
	  d.value = 'Email no existe'; b.disabled = false;
	 }
   }
 });
}

showInst = function() {
 $.get("/script/int/inst.html", function(data) {
   doUnload();
   window.scroll(0,0);
   document.body.style.overflow = 'hidden';
   document.getElementById('DataW').style.top = '7%';
   document.getElementById('DataLy').style.display = 'block';
   document.getElementById('DataW').style.zIndex = 99999;
   document.getElementById('DataW').innerHTML = data;
 });
}

showRec = function(theId) {
 doLoad();
 $.get("/script/int/recFlyer.html", function(data) {
   doUnload();
   window.scroll(0,0);
   document.body.style.overflow = 'hidden';
   document.getElementById('DataW').style.top = '7%';
   document.getElementById('DataLy').style.display = 'block';
   document.getElementById('DataW').style.zIndex = 99999;
   document.getElementById('DataW').innerHTML = data.replace('[Id]', theId);
 });
}

removeLy = function() {
 document.body.style.overflow = '';
 document.getElementById('DataLy').style.display = 'none';
 document.getElementById('DataW').innerHTML = '';
 if(document.getElementById('_tv_player_ly')) {
  document.getElementById('_tv_player_ly').style.display = 'block';
 }
}

removeOnlyLayer = function() {
 document.getElementById('DataW').innerHTML = '';
}

checkRegistry = function() {
 var f = document.forms['formReg'];
 //
 if(f.name.value == '') { alert('Falta tu Nombre'); f.name.focus(); return false; }
 if(f.age.selectedIndex == '') { alert('Falta tu Edad'); f.age.focus(); return false; }
 cnt=0;
 for(p=0; p<f.gender.length; p++) {
  if(f.gender[p].checked == true) { cnt++ }
 }
 if(cnt==0) { alert('Falta tu Sexo'); return false; }
 if(f.email.value == '') { alert('Falta tu correo electrónico'); f.email.focus(); return false; }
 if(f.email.value.indexOf('@',0) == -1 || f.email.value.indexOf('.',0) == -1) { alert('Escribe correctamente tu correo electrónico'); f.email.focus(); f.email.select(); return false; }
 cnt1=0;
 for(h=0; h<f.receiveInfo.length; h++) {
  if(f.receiveInfo[h].checked == true) { cnt1++; }
 }
 if(cnt1 == 0) { alert('Elige si deseas recibir información de Bogota Flyer'); return false; }
 return true;
} 

toggleBtn = function() {
 if(document.getElementById('includePolicies_frm').checked == true) {
  document.getElementById('doSend_frm').disabled = false;
 } else if(document.getElementById('includePolicies_frm').checked == false) {
  document.getElementById('doSend_frm').disabled = true;
 }
}

// Para conteo de clics
ARKCountBanner = function(TheURL) {
 $.ajax({
  type: 'GET',
  url: "/script/BannerCounter.phpx?File="+TheURL,
  success: null
  });
}

// Para cuando carga la pagina
ARKPrintBanner = function(TheURL) {
 $.ajax({
  type: 'GET',
  url: "/script/BannerPrint.phpx?File="+TheURL,
  success: null
  });
}

function handset_text_load() {
 window.status = document.readyState!="complete" ? "Cargando Bogota Flyer" : "Estás en el BogotaFlyer.com";
}
document.onreadystatechange = handset_text_load;