
function CallBackObject(method){
var m = String(method).toLowerCase();
this.XmlHttp = this.GetHttpObject();
if(m == "post") this.Method = false;
else this.Method = true;
return this;
}
 
CallBackObject.prototype.GetHttpObject1 = function()
{ 
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}
 
CallBackObject.prototype.GetHttpObject = function()
{
    if (window.XMLHttpRequest) {
        try {
            return new XMLHttpRequest();
        } catch (e){}
    } else if (window.ActiveXObject) {
        try {
            return new ActiveXObject('Msxml2.XMLHTTP');
        } catch (e){}
        try {
            return new ActiveXObject('Microsoft.XMLHTTP');
        } catch (e){}
    }
    return null;
} 
 
CallBackObject.prototype.DoCallBack = function(URL,Query,Cache)
{
  var theData = Query;
  var theform = document.forms[0];
  var thePage = URL; 
  var eName = '';
 
  if(Cache==null){
    var curDate		= new Date();
    theData += '&time='+curDate.getTime().toString();
  }
  if( this.XmlHttp )
  {
    if( this.XmlHttp.readyState == 4 || this.XmlHttp.readyState == 0 )
    {
//alert("DoCallBack: " + thePage+'?'+theData);    
      var oThis = this;
      if(this.Method){
		this.XmlHttp.open('GET', thePage+'?'+theData, true);
		this.XmlHttp.onreadystatechange = function(){ oThis.ReadyStateChange(); };
		this.XmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		this.XmlHttp.setRequestHeader('Accept-Language','ru, en');
		this.XmlHttp.setRequestHeader('Accept-Charset','Windows-1251');
		this.XmlHttp.send(null);
	  }
	  else{
		this.XmlHttp.open("POST", thePage, true);
		this.XmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		this.XmlHttp.setRequestHeader("Content-length", theData.length);
		this.XmlHttp.setRequestHeader("Connection", "close");
		this.XmlHttp.onreadystatechange = function(){ oThis.ReadyStateChange(); };
		this.XmlHttp.send(theData);
	  }		
    }
  }
}
 
CallBackObject.prototype.AbortCallBack = function()
{
  if( this.XmlHttp )
    this.XmlHttp.abort();
}
 
CallBackObject.prototype.OnLoading = function()
{
  // Loading
}
 
CallBackObject.prototype.OnLoaded = function()
{
  // Loaded
}
 
CallBackObject.prototype.OnInteractive = function()
{
  // Interactive
}
 
CallBackObject.prototype.OnComplete = function(responseText, responseXml)
{
  // Complete
}
 
CallBackObject.prototype.OnAbort = function()
{
  // Abort
}
 
CallBackObject.prototype.OnError = function(status, statusText)
{
  // Error
}
 
CallBackObject.prototype.ReadyStateChange = function()
{
// alert("ReadyStateChange: " + this.XmlHttp.readyState + " " + this.XmlHttp.status);
  if( this.XmlHttp.readyState == 1 )
  {
    this.OnLoading();
  }
  else if( this.XmlHttp.readyState == 2 )
  {
    this.OnLoaded();
  }
  else if( this.XmlHttp.readyState == 3 )
  {
    this.OnInteractive();
  }
  else if( this.XmlHttp.readyState == 4 )
  {
    if( this.XmlHttp.status == 0 )
      this.OnAbort();
    else if( this.XmlHttp.status == 200 && this.XmlHttp.statusText == "OK" )
    {
//		alert("this.OnComplete:\n\r" + this.OnComplete);
      this.OnComplete(this.XmlHttp.responseText, this.XmlHttp.responseXML);
    }
    else
      this.OnError(this.XmlHttp.status, this.XmlHttp.statusText, this.XmlHttp.responseText);   
  }
}


function _Cbo_Complete(responseText, responseXML)
{
	var divAdv = document.getElementById("DIV_advertisment");
//alert("Cbo_Complete: " + divAdv.id);
	var res = String(responseText).trim();
	// divAdv.innerHTML = responseText;
    if (res.length > 0)
	  divAdv.innerHTML = res; 
//alert("Cbo_Complete:\n"+res);	
}

function _Cbo_OnError(status, statusText, responseText)
{
//	alert("OnError: " + status + "\r"+ statusText+"\r"+responseText);
}

function clickSponsor(Id)
{
	var ClickSponsor = new CallBackObject();
	var URL = "/AdvSys/AdvPanel/AddClick.aspx"; 
	var Query = 'id='+Id; 
	ClickSponsor.DoCallBack(URL,Query);
	return true;
}

String.prototype.trimLeft = function() 
{
	return this.replace(/^\s*/,"");
}

String.prototype.trimRight = function() 
{
	return this.replace(/\s*$/,"");
}

String.prototype.trim = function() 
{
	return this.trimRight().trimLeft();
}

String.prototype.endsWith = function(s) 
{
	if(this.length == 0 || this.length < s.length) { return false; }
	return (this.substr(this.length - s.length) == s);
}

String.prototype.startsWith = function(s) 
{
	if(this.length == 0 || this.length < s.length) { return false; }
	return (this.substr(0, s.length) == s);
}

