/*@cc_on @if (@_win32 && @_jscript_version >= 5) if (!window.XMLHttpRequest)
window.XMLHttpRequest = function() { return new ActiveXObject('Microsoft.XMLHTTP') }
@end @*/

var BCB_ajax_httpRequest;
var BCB_ajax_bg;
var BCB_ajax_form;
var BCB_ajax_formdiv;
var BCB_ajax_div;
var BCB_ajax_activepopup=false;
var BCB_ajax_activeform=false;
var BCB_ajax_popup_height=0;
var BCB_ajax_popup_toleft=0;
var BCB_ajax_popup_tobottom=0;
var BCB_ajax_popup_mousecapture=true;
var BCB_ajax_posthandlefunc=null;
var BCB_extern=false;

function BCB_ajax_showform(url,parameters){
  //if(!BCB_page_ready)
    //return false;
  BCB_ajax_bg=document.getElementById('BCB_ajax_bg');
  BCB_ajax_formdiv=document.getElementById('BCB_ajax_formdiv');
  BCB_ajax_bg.style.display="block";
  BCB_ajax_activeform=true;
  window.location.href = "#BCB_ajax_bg";
  return BCB_ajax_loadinto("BCB_ajax_form_box_content","forms/"+url,parameters);
}

function BCB_ajax_closeform(){
  BCB_ajax_activeform=false;
  BCB_ajax_formdiv=document.getElementById('BCB_ajax_formdiv');
  BCB_ajax_bg=document.getElementById('BCB_ajax_bg');
  BCB_ajax_formdiv.style.display="none";
  BCB_ajax_bg.style.display="none";
  return false;
}

function BCB_ajax_sendform(formhandler){
  BCB_ajax_form = document.getElementById('BCB_ajax_form');
  var params = '';
  for(var i=0;i<BCB_ajax_form.elements.length;i++){
    if(BCB_ajax_form.elements[i].type=="checkbox" || BCB_ajax_form.elements[i].type=="radio"){
      if(BCB_ajax_form.elements[i].checked)
        params += "&" + BCB_ajax_form.elements[i].name + "=" + encodeURIComponent(BCB_ajax_form.elements[i].value);
    }
    else
      params += "&" + BCB_ajax_form.elements[i].name + "=" + encodeURIComponent(BCB_ajax_form.elements[i].value);
  }
  params = params.substr(1);
  return BCB_ajax_loadinto("BCB_ajax_form_box_content",formhandler,params);
}

function BCB_ajax_mousemove(e,force){
  force = typeof(force) != 'undefined' ? force : false;
  if(force==false && (BCB_ajax_activepopup==false || BCB_ajax_popup_mousecapture==false)){
    return;
  }
  if(typeof(e) == "undefined")
    e=window.event;
  if(typeof(window.pageYOffset) == "undefined")
    YOff=document.documentElement.scrollTop;
  else
    YOff=window.pageYOffset;
  BCB_ajax_div.style.top=" " + parseInt(e.clientY + BCB_ajax_popup_tobottom - BCB_ajax_popup_height + YOff) + "px";
  BCB_ajax_div.style.left=" " + parseInt(e.clientX-BCB_ajax_popup_toleft) + "px";
}

function BCB_ajax_loadinto(elementid,url,parameters) {
  //alert(elementid+' '+url+' '+parameters);
  if(typeof(parameters)!="string")
    parameters='';
  BCB_ajax_httpRequest = new XMLHttpRequest();
  if(!BCB_ajax_httpRequest || typeof(BCB_ajax_httpRequest)=="undefined"){
    try{ BCB_ajax_httpRequest = new ActiveXObject("Msxml2.XMLHTTP"); } 
    catch(e){}
  }
  if(!BCB_ajax_httpRequest || typeof(BCB_ajax_httpRequest)=="undefined"){
    try{ BCB_ajax_httpRequest = new ActiveXObject("Microsoft.XMLHTTP"); }
    catch(e){}
  }
  if(!BCB_ajax_httpRequest || typeof(BCB_ajax_httpRequest)=="undefined"){
    alert('XMLHTTP Instanz nicht erstellbar.');
    return false;
  }
  if(BCB_ajax_httpRequest.overrideMimeType)
    BCB_ajax_httpRequest.overrideMimeType('text/xml');
  params = "ajaxfile=" + encodeURIComponent(url) + "&" + encodeURI(parameters);
  //alert(params);
  BCB_ajax_httpRequest.onreadystatechange = function() { BCB_ajax_handle(elementid,BCB_ajax_httpRequest); };
  if(BCB_extern)
    BCB_ajax_httpRequest.open('GET', 'www.bigcitybeats.de/ajax.php?'+params, true);
  else
    BCB_ajax_httpRequest.open('GET', 'ajax.php?'+params, true);
  BCB_ajax_httpRequest.send(null);
  /*BCB_ajax_httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=ISO-8859-1");
  BCB_ajax_httpRequest.setRequestHeader("Content-length", params.length);
  BCB_ajax_httpRequest.setRequestHeader("Connection", "close");
  BCB_ajax_httpRequest.send(params);*/
  return false;
}

function BCB_ajax_handle(eid,httpRequest) {
  e = document.getElementById(eid);
  if (BCB_ajax_httpRequest.readyState == 4) {
    if(BCB_ajax_httpRequest.status == 200){
      e.innerHTML=BCB_ajax_httpRequest.responseText;
      if(BCB_ajax_activepopup)
        BCB_ajax_div.style.visibility="visible";
      if(BCB_ajax_activeform)
        BCB_ajax_formdiv.style.display="block";
      if(BCB_ajax_posthandlefunc!=null)
        BCB_ajax_posthandlefunc.call(this);
      BCB_ajax_posthandlefunc=null;
    }
    else{
      //alert('There was a problem with the request.');
      return false;
    }
  }
}

function BCB_ajax_popup(w,h,toleft,tobottom,url,parameters,fixedx,fixedy){
  if(!BCB_page_ready)
    return;
  fixedx = typeof(fixedx) != 'undefined' ? fixedx : -1;
  fixedy = typeof(fixedy) != 'undefined' ? fixedy : -1;
  if(BCB_ajax_activepopup==true)
    BCB_ajax_killpopup();
  BCB_ajax_activepopup=true;
  // add event
  if(fixedx<0 || fixedy<0)
    BCB_ajax_popup_mousecapture=true;
  else{
    BCB_ajax_popup_mousecapture=false;
    if(typeof(window.pageYOffset) == "undefined")
      YOff=document.documentElement.scrollTop;
    else
      YOff=window.pageYOffset;
    BCB_ajax_div.style.top=" " + parseInt(fixedy + BCB_ajax_popup_tobottom - BCB_ajax_popup_height + YOff) + "px";
    BCB_ajax_div.style.left=" " + parseInt(fixedx-BCB_ajax_popup_toleft) + "px";
  }
  BCB_ajax_div.style.width="" + parseInt(w) + "px";
  BCB_ajax_div.style.height="" + parseInt(h) + "px";
  BCB_ajax_popup_height=h;
  BCB_ajax_popup_toleft=toleft;
  BCB_ajax_popup_tobottom=tobottom;
  BCB_ajax_loadinto('BCB_ajax_div',url,parameters);
}

function BCB_ajax_killpopup(){
  if(!BCB_page_ready)
    return;
  BCB_ajax_activepopup=false;
  document.onmousemove = function(){};
  BCB_ajax_div.style.visibility="hidden";
  return false;
}

