﻿
function callBackResult(value)
{


 
  var sp = String(value).split("~/~");
   for(var i = 0; i < sp.length; i++)
   {
      if(sp[i].indexOf(":v:") > 0)
      {
         s = sp[i].split(":v:")
         if(document.getElementById(s[0]))
         {
           document.getElementById(s[0]).value = s[1];
         }
      }
      if(sp[i].indexOf(":d:") > 0)
      {
         s = sp[i].split(":d:") //displays y/n tag id
         if( document.getElementById(s[0]) )
         {
            if(s[1] == 'y' || s[1] == 'Y')
               document.getElementById(s[0]).style.display = "";
            else document.getElementById(s[0]).style.display = "none";
         }
      }
      if(sp[i].indexOf(":A:") > 0)
      {
         s = sp[i].split(":A:")
         alert(s[0] + s[1]);
      }
      if(sp[i].indexOf(":h:") > 0) //assigns tag id inner html
      {
         s = sp[i].split(":h:")
         if(document.getElementById(s[0]) )
         {
            document.getElementById(s[0]).innerHTML = s[1];
         }
      }
      if(sp[i].indexOf(":checked:") > 0) 
      {
         s = sp[i].split(":checked:")
         if(document.getElementById(s[0]) )
         {
            document.getElementById(s[0]).disabled = false;
            if(s[1] == 'y' || s[1] == 'Y')
            {
              document.getElementById(s[0]).checked = true;
            }  
            else document.getElementById(s[0]).checked = false;
         }
      }
      //mainPageRotator
      if(sp[i].indexOf(":mainPageRotator:") > 0) 
      {
         s = sp[i].split(":mainPageRotator:")
         mainPageRotator(s[1]);
     }
     
     if(sp[i].indexOf(":newLocation:") > 0)
     {
     
      if( document.getElementById('divLoadingGif') )
      {

          setLoadingGif();
      }
     
        s = sp[i].split(":newLocation:")
        
        if( document.getElementById('newLocationFlag'))
        {
           document.getElementById('newLocationFlag').value = 'set';
        }
        
        window.location = s[1];
     }
     
     
     if(sp[i].indexOf(":resultDetails:") > 0)
     {
    
        s = sp[i].split(":resultDetails:")
        

        window.location = s[0] + s[1];
     }
     
     if(sp[i].indexOf(":ot:") > 0) //lower case o
     {
         
         s = sp[i].split(":ot:")
         
         var id = '' + s[0];
           //alert('' + id);
         if(document.getElementById(id))
         {
             for( i = 0; i < document.getElementById(id).options.length; i++)
             {
                    if (String(document.getElementById(id).options[i].text) == String(s[1]) )
                    {
                       document.getElementById(id).options[i].selected = true;
                    }
                
             }
         }
     }
   }
 }



function callbackAjax(arg)
{
   callbackAjaxHttp("",arg);
}


function callbackAjaxHttp(cbHttp,arg)
{

    

    if( document.getElementById('divLoadingGif') )
    {

       setLoadingGif();
    }
    else
    {
 
       if( document.getElementById('loadingGif') ) document.getElementById('loadingGif').style.display='';
    }
  
    var xmlHttpObj;
    xmlHttpObj = CreateXmlHttpRequestObject();
       //xmlHttpObj.open("POST",httpPrefix + "calbackHandler.ashx", true);
       xmlHttpObj.open("POST", cbHttp + "calbackHandler.ashx", true);
    //xlHttpObj.open("POST",String(handlerName), false);
       
    if (xmlHttpObj)
    {
         xmlHttpObj.onreadystatechange = function() 
         { 
            if ( xmlHttpObj.readyState == READYSTATE_COMPLETE )
            {

                if (xmlHttpObj.status == HTTPSTATUS_OK)
                {
                     if( String(xmlHttpObj.responseText).length > 1)
                     {
                         var value = String(xmlHttpObj.responseText);
                      
                      if( document.getElementById('divLoadingGif') )
                      {
                         document.getElementById('divLoadingGif').style.display='none';
                      }
                      else
                      {  
                         if( document.getElementById('loadingGif') ) document.getElementById('loadingGif').style.display='none';
                      }  
                        callBackResult(value);
                         
                     }
                }
                else
                {
                   if(String(xmlHttpObj.status) == '12030' )
                   {
                      alert("Error Occurred! no connection to handler");
                   }
                   else
                   {
                      var fault = xmlHttpObj.responseText;
                      alert("Error Occurred! " + xmlHttpObj.status + ' ' + fault);
                   }
                }
            }
         }
    }    
    xmlHttpObj.setRequestHeader("Content-Type","application/x-www-form-urlencoded; charset=utf-8");
    

    xmlHttpObj.send('' + arg);
   
}
 





     
     

