var timerTextColor;


function create_xmlhttp() {
   // Non-IE browsers
  try{req=new XMLHttpRequest();}
  catch (e) {
    // Non-IE browsers
    try {req=new ActiveXObject("Msxml2.XMLHTTP");}
    // IE
    catch (e){req=new ActiveXObject("Microsoft.XMLHTTP");}
  }
  return req;
}

function Ajax() { 
  this.xmlhttp = create_xmlhttp();
  this.get = ajax_get;
  this.post = ajax_post;
  this.response = '';
  this.callback = '';
  function ajax_get(url, callback, options) {
    this.callback = callback;
    var this_obj = this;
    this.xmlhttp.onreadystatechange = function() {
      if(this_obj.xmlhttp.readyState == 4) {
        if(this_obj.xmlhttp.status == 200) {
          this_obj.response = this_obj.xmlhttp.responseText;
          eval(this_obj.callback+'(this_obj.response,options)');
        } else {
          if(options=='alert_error') {
            alert("Грешка: Проблем с отговора на заявката. (" + this_obj.xmlhttp.status + ")\n         Оптайте да повторите операцята.");
          }
          //alert('Грешка: Проблем с отговора на заявката. ('+this_obj.xmlhttp.status+')');
        }
      }
    }
    this.xmlhttp.open("GET", url, true);
    this.xmlhttp.send(null);
    return true;
  }
  function ajax_post(url, params, callback, options) {
    this.callback = callback;
    var this_obj = this;
    this.xmlhttp.onreadystatechange = function() {
      if(this_obj.xmlhttp.readyState == 4) {
        if(this_obj.xmlhttp.status == 200) {
          this_obj.response = this_obj.xmlhttp.responseText;
          eval(this_obj.callback+'(this_obj.response,options)');
          //eval('this_obj.result(this_obj.response,options)');
        } else {
          if(options=='alert_error') {
            alert("Грешка: Проблем с отговора на заявката. (" + this_obj.xmlhttp.status + ")\n         Оптайте да повторите операцята.");
          }
        }
      }
    }
    this.xmlhttp.open("POST",url,true);
    this.xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    this.xmlhttp.setRequestHeader("Content-length", params.length);
    this.xmlhttp.setRequestHeader("Connection", "close");
    this.xmlhttp.send(params);
    return true;
  }
} 

function ajax_script(script,params) {
  var ajax2 = new Ajax();
  var url='ajax/'+script+'.php';
  ajax2.post(url,params,'ajax_result');
}

function ajax_result(r) {
  //alert(r);
}

function myTFocus() {
  setTimeout("myFocus();",0);
}

function getBrowser() {
  var sBrowser = navigator.userAgent;
  //if (sBrowser.toLowerCase().indexOf('msie 5.0') > 0)         return 'ie5';
  //if (sBrowser.toLowerCase().indexOf('msie 6.0') > 0)         return 'ie6';
  if (sBrowser.toLowerCase().indexOf('msie') > 0) return 'ie';
  if (sBrowser.toLowerCase().indexOf('firefox/2') > 0) return 'ff2';
  else return;
}

function myFocus() {
  if(getBrowser()=='ie') {
    self.focus();
  }
  else {
    document.getElementById('focus').focus();
  }
}

function SFocus() {
  if(getBrowser()=='ie') {
    self.focus();
  }
  else {
    self.blur();
  }
}










function textColor(obj,color,backcolor,timeout) {
  timeout=(timeout) ? timeout : 2000;
  tc=color; bc=backcolor;
  clearTimeout(timerTextColor);
  obj.setAttribute("id", "hintbox");
  obj.style.color=color;
  dropmenuobj=document.getElementById("hintbox");
  timerTextColor=setTimeout("dropmenuobj.style.color=bc",timeout);
  obj.onmouseout=textmout;

}

function textmout() {
  clearTimeout(timerTextColor);
  dropmenuobj.style.color=bc;
  dropmenuobj.setAttribute("id", "");
}

function getFlashMovieObject(movieName) {
  if (window.document[movieName]) 
  {
      return window.document[movieName];
  }
  if (navigator.appName.indexOf("Microsoft Internet")==-1)
  {
    if (document.embeds && document.embeds[movieName])
      return document.embeds[movieName]; 
  }
  else // if (navigator.appName.indexOf("Microsoft Internet")!=-1)
  {
    return document.getElementById(movieName);
  }
}

function SendDataToFlashMovie(){
     var flashMovie=getFlashMovieObject("myFlashMovie");
     flashMovie.SetVariable("/:message", document.controller.Data.value);
     //alert(flashMovie)
}