﻿/****************************************** 
** Title........: Animated Equity 
** Filename.....: XMLHTTPJSClass.js
** Author.......: Uwe Nausner 
** Version......: 3.2
** Notes........: www_seestokrun Ajax JS Class
** File Created.: 04/21/2008
** Last changed.: 08/13/2008
********************************************/


// JScript File
//var request;

function AjaxClass()
{
this.JSONArray = {  "Method" : "GET", //Method type; For webservice user GET method only.
                    "Async"  : true, //Call type
                    "CallPage" : "", //Calling page or webservice
                    "Querystring" : "", //Query string
                    "dependentType" : null,//[0,1,2,3] for isEdit 
                    "isEdit": [
                                {
                                "textBoxId" : null, //0 then this data
                                "dropDownId" : null, //1 then this data
                                "tagId" : null, //2 then this data
                                "misc":null //3 then this data
                                }
                              ]

                    };
 
this.Method = this.JSONArray.Method;//"POST";
//this.url = "http://localhost:2849/XMLHTTPJSClassExt"; 
this.url = ""; 
this.Async = this.JSONArray.Async//"true";
this.textBox = this.JSONArray.textBox;//true;
this.request = null;
var self = this; // To handle lose of focus
this.handleResponse = function()
        {
                if(self.request.readyState == 4 && self.request.status == 200)
                {
                    if (window.ActiveXObject) // for IE
                        {
                        var doc=new ActiveXObject("Microsoft.XMLDOM");
                        doc.async="false";
                        doc.loadXML(self.request.responseText);
                        }
                          // code for Mozilla, Firefox, Opera, etc.
                    else
                        {
                       // var parser=new DOMParser();
                       // var doc=parser.parseFromString(self.request.responseText,"text/xml");
                       }
                       try
                       {
                       //  var data  = "";
                       // if(doc.documentElement) data = doc.documentElement.childNodes[0].nodeValue;
                       // else 
                        
                        data = self.request.responseText;
                        
                        window.document.getElementById(self.JSONArray.isEdit[0].tagId).innerHTML = data;
                        
                        //Logic for Poputating the HtmlControl
                           // switch(self.JSONArray.dependentType)
                          //  {
                           //     case 0:
                            //        PopulateControls(self.JSONArray.isEdit[0].textBoxId,data);
                            //    break;
                            //    case 1:
                            //    break;
                            //    case 2:
                                //window.document.getElementById(self.JSONArray.isEdit[0].tagId).innerHTML = data;
                            //    window.document.getElementById(self.JSONArray.isEdit[0].tagId).innerHTML = data;
                            //    break;
                            //}
                        }
                        catch(e) {}
                }
        }  

this.init = function() {
                   this.url = this.url + this.JSONArray.CallPage + this.JSONArray.Querystring ; //WebService.asmx/HelloWorld";
                  if (window.XMLHttpRequest) // if Mozilla, Safari etc
                    this.request = new XMLHttpRequest();
                else if (window.ActiveXObject)
                   { // if IE
                    try 
                        {
                         this.request = new ActiveXObject("Msxml2.XMLHTTP");
                        } 
                    catch (e)
                        {
                            try
                            { 
                             this.request = new ActiveXObject("Microsoft.XMLHTTP");
                            }
                            catch (e){}
                        }
                    }

                 if(this.request)
                    {   
                        this.request.onreadystatechange=this.handleResponse;
                        this.request.open(this.Method, this.url , this.Async);
                        this.request.send(null);
                    } 
                 }   
}


function PopulateControls(ids,values)
    {
    // Split ids and Split values on $ for multiple Fillins
    var idArr = ids.split('$');
    var dataArr = values.split('$');
    if(idArr.length == dataArr.length)
        {
        for(var i = 0 ; i < idArr.length ; i++)
            {
            window.document.getElementById(idArr[i]).value = dataArr[i];   
            }
        }
    }
    
    
//    function testClass()
//    {
//    this.Msg = "Hello";
//    this.showMsg = function()
//                    {
//                    alert(this.Msg);
//                    }
//    }
//    
//    var a = new testClass();
//    a.Msg = "HI";
//    a.showMsg();