function CallBackObject()
{
  this.XmlHttp = this.GetHttpObject();
}
 
CallBackObject.prototype.GetHttpObject = 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;
}
 
function WebForm_EncodeCallback(parameter) {
    if (encodeURIComponent) {
        return encodeURIComponent(parameter);
    }
    else {
        return escape(parameter);
    }
}
 
 
CallBackObject.prototype.DoCallBack = function(eventTarget, eventArgument, pagepath, sendViewState)
{
  var theData = '';
  var theform = document.forms[0];
  var thePage = pagepath + window.location.search; //window.location.pathname + window.location.search;
  var eName = '';

  theData  = '__EVENTTARGET='  + escape(eventTarget.split("$").join(":")) + '&';
  theData += '__EVENTARGUMENT=' + escape(eventArgument) + '&';
  if (sendViewState==true) {
  if (theform.__VIEWSTATE)
  theData += '__VIEWSTATE='    + escape(theform.__VIEWSTATE.value).replace(new RegExp('\\+', 'g'), '%2b') + '&';
  }
  theData += 'IsAJCallBack=true';

  
  if (theform) {
  for( var i=0; i<theform.elements.length; i++ )
  {
    eName = theform.elements[i].name;
    if( eName && eName != '')
    {
      if( eName == '__EVENTTARGET' || eName == '__EVENTARGUMENT' || eName == '__VIEWSTATE' || eName == '__LASTFOCUS' ||   eName == '__LASTFOCUS' || eName == '__EVENTVALIDATION')
      {
        // Do Nothing
      }
      else
     {
        theData = theData + '&' + escape(eName.split("$").join(":")) + '=' + theform.elements[i].value;
      }
    }
  }

  if (theform.__EVENTVALIDATION)
  theData += '&__EVENTVALIDATION=' + WebForm_EncodeCallback(theform.__EVENTVALIDATION.value);

}

  
 
  if( this.XmlHttp )
  {
    if( this.XmlHttp.readyState == 4 || this.XmlHttp.readyState == 0 )
    {
      var oThis = this;
      this.XmlHttp.open('POST', thePage, true);
      this.XmlHttp.onreadystatechange = function(){ oThis.ReadyStateChange(); };
      this.XmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      this.XmlHttp.send(theData);
    }
  }
}



CallBackObject.prototype.DoCallBackLite = function(eventTarget, eventArgument, pagepath)
{
  var theData = '';
  var theform = document.forms[0];
  var thePage = pagepath + window.location.search; //window.location.pathname + window.location.search;
  var eName = '';

  theData  = '__EVENTTARGET='  + escape(eventTarget.split("$").join(":")) + '&';
  theData += '__EVENTARGUMENT=' + escape(eventArgument) + '&';
  theData += 'IsAJCallBack=true';

  
  if (theform) {
  if (theform.__EVENTVALIDATION)
  theData += '&__EVENTVALIDATION=' + WebForm_EncodeCallback(theform.__EVENTVALIDATION.value);
    }

 
  if( this.XmlHttp )
  {
    if( this.XmlHttp.readyState == 4 || this.XmlHttp.readyState == 0 )
    {
      var oThis = this;
      this.XmlHttp.open('POST', thePage, true);
      this.XmlHttp.onreadystatechange = function(){ oThis.ReadyStateChange(); };
      this.XmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      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()
{
  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" )
      this.OnComplete(this.XmlHttp.responseText, this.XmlHttp.responseXML);
    else
      this.OnError(this.XmlHttp.status, this.XmlHttp.statusText, this.XmlHttp.responseText);   
  }
}


var pagekeep='';

function ugcAJAX(EventName, InputData, entry, submit, done, nextFunction, box )
    {
  
    var action = "replace";
    
    if (done.indexOf('|') > -1)
    {
    action=done.split("|")[1];
    done=done.split("|")[0];
    }
     
    // var textbox = document.getElementById('txtBox').value;
    if (typeof box != 'undefined') { showBox(); document.getElementById('box').style.zIndex = 999; }
    else {if (entry!='') {document.getElementById(entry).style.display = "none";} if (submit!='') {document.getElementById(submit).style.display = "";}}
    //document.getElementById('rotatingclock').src='/i/spn.gif';
    
    //alert(sCountry);
    var Cbo = new CallBackObject();
    Cbo.OnComplete = Cbo_Complete;
    Cbo.OnError    = Cbo_Error;

    if (InputData=='') 
    {
    Cbo.DoCallBack(EventName + '|ugcControl',InputData,'/components/AJAX/AjaxHandler.aspx');
    }
    else
    {
    Cbo.DoCallBackLite(EventName + '|ugcControl',InputData,'/components/AJAX/AjaxHandler.aspx');
    }
    
        function Cbo_Complete(responseText, responseXML)
        {
              if (document.getElementById("pageback") != null) {
              document.getElementById("pageback"  ).value=responseText + 'cx$%ooo%$xc' + document.getElementById("pageback"  ).value;
              document.getElementById("doneback"  ).value=done;
              document.getElementById("actionback"  ).value=action;
              }
        var script='';
        if (submit!='') {document.getElementById(submit).style.display = "none";}

        if (responseText.indexOf('<script')>-1)
        {
        var iscript=responseText.indexOf('<script');
        script=responseText.substring(iscript);
        var ibracket=script.indexOf('>');
        script=script.substring(ibracket+1);
        var ibracket=script.indexOf('</script>');
        script=script.substring(0,ibracket);
        responseText=responseText.substring(0,iscript);
        }

  
        if (done!='')  {
            //if  (responseText != null && responseText != '')  {
                if (done.indexOf(',')>-1) {document.getElementById(done.split(',')[1]).style.display = "";center(document.getElementById(done.split(',')[1])); done=done.split(',')[0];}
            //}

            //if (done=='document' &&  responseText != null && responseText != '') {
            //    document.documentElement.innerHTML = responseText;
            //}
            //else
            //{
            if ((action=='replace' || action=='replaceslide') && responseText != null && responseText != '')  {  
                document.getElementById(done).innerHTML = responseText;  
                }
            else if (responseText != null && responseText != '' && done != '')
            {
                if (action=='insert')
                    document.getElementById(done).innerHTML = responseText + document.getElementById(done).innerHTML;
                else  // must be append
                    document.getElementById(done).innerHTML = document.getElementById(done).innerHTML + responseText;
            }
            //}
            if (action != 'slide' && action!='replaceslide') {
                document.getElementById(done).style.display = "";
            }
            else {
                if (responseText.replace(/ /g,'') != '') {
                    $('#' + done).slideDown(500)
                }
            }
        }



        if (script!=''){
                eval(script);
          //sdf
            }
            
        if (typeof(nextFunction) != 'undefined') {if(nextFunction !='') eval(nextFunction);}
        if (typeof box != 'undefined') {hideBox();}

        if (typeof($.history)!='undefined') {
        setTimeout("$.history( {'backz':'ajax'}, 12);",500);
        }
        }


        
        function Cbo_Error(status, statusText, responseText)
        {
          // alert('oops - I got an error:' + responseText);
         if (entry!='') {
        document.getElementById(entry).style.display = "none";  }
    }
}


        function dopage(responseText, done, action)
        {
        
        //alert(responseText);
        var script='';
        //document.getElementById(submit).style.display = "none";
        //document.getElementById(done).style.display = "";
        if (responseText.indexOf('<script')>-1)
        {
        var iscript=responseText.indexOf('<script');
        script=responseText.substring(iscript);
        var ibracket=script.indexOf('>');
        script=script.substring(ibracket+1);
        var ibracket=script.indexOf('</script>');
        script=script.substring(0,ibracket);
        responseText=responseText.substring(0,iscript);
        }
        if (action=='replace' && responseText != null && responseText != '')
         
            document.getElementById(done).innerHTML = responseText;
        else if (responseText != null && responseText != '')
        {
            if (action=='insert')
                document.getElementById(done).innerHTML = responseText + document.getElementById(done).innerHTML;
            else  // must be append
                document.getElementById(done).innerHTML = document.getElementById(done).innerHTML + responseText;
        }


        if (script!=''){
            //script = script.replace(/\r|\n|\r\n/g, '')
               eval(script);
            }

        if (typeof nextFunction != 'undefined') {if(nextFunction !='') eval(nextFunction);}
        if (typeof box != 'undefined') {hideBox();}
        }
