// JScript File
var CROWCODER;
if(!CROWCODER) CROWCODER = {};
if(!CROWCODER.ajax) CROWCODER.ajax = {};

/***
 * @memberOf CROWCODER.ajax The standard wait image
 * to display during ajax transactions
 */
CROWCODER.ajax.waitImg = buildWaitImg();
CROWCODER.ajax.mapId = 
    "9uD09BTV34Hepx4B2WP_v7tT6DRr4fOdHXd0dj1iRKYVOjMffzxJA_l4F4o-";

function buildWaitImg(){
    var waitImg = document.createElement("IMG");
    waitImg.src = "../images/ajax-loader.gif";
    waitImg.alt = "Please Wait...";
    //waitImg.className = "wait_img";
    return waitImg;
}

/***
 * @method showWait Shows the wait image at the xy coords
 * for the passed element
 * @param {Object} p_elem a string or dom reference of the
 * element where the wait image is to be displayed.
 */
CROWCODER.ajax.showWait = function(p_elem){    
    p_elem.appendChild(this.waitImg);    
}

CROWCODER.ajax.hideWait = function(p_elem){
    p_elem.removeChild(this.waitImg);
}

/***
 * @constructor
 * @classDescription A wrapper around the YUI connection
 * object to facilitate ajax calls
 */
CROWCODER.ajax.YuiConxn = function()
{
    this.sUrl;
    this.postdata;
    this.transaction;
    this.requestType = 'POST';
    this.callback =
    {
        success: "undefined",
        failure: "undefined"
    };
}

CROWCODER.ajax.YuiConxn.prototype.makeCall = function()
{ 
    this.transaction = 
        YAHOO.util.Connect.asyncRequest("POST", this.sUrl, this.callback, this.postdata);

}  
    
// CROWCODER.ajax.AjaxRequest = function()
//  {
//    this.xhr = CROWCODER.ajax.getXhr();
//    this.xhr.onReadyStateChange = function(){
//    
//    };
//    
//    this.sUrl = "services/YsService.asmx";
//    this.ns = "http://localhost/ws/";
//    this.methodName = "undefined"; 
//    this.soapAction = this.ns + this.methodName;
//    this.params = {};
//    this.setSoapenv = function(){
//		var param = "";
//		for(var name in this.params)
//		{
//		    param = "<" + this.methodName + " xmlns='" + this.ns + "'><" + 
//		        name + ">" + this.params[name] + "</" + name + "></" + 
//		        this.methodName + ">";
//		}
//		return "<?xml version='1.0' encoding='utf-8'?>" +
//	                  "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" +
//		                  "<soap:Body>" + param +
//		                  "</soap:Body>" +
//		                  "</soap:Envelope>";
//	    };	                
//       
//    this.xhr.setRequestHeader("Content-Type", "text/xml");
//	this.xhr.setRequestHeader("SOAPAction", soapAction);
//	
//	this.sendReq = function(){
//	    this.xhr.send(this.soapenv);
//	};
//  }
  
  CROWCODER.ajax.getXhr = function()
  {
    try
        {
        // Firefox, Opera 8.0+, Safari
        return new XMLHttpRequest();
        }
      catch (e)
        {
        // Internet Explorer
        try
          {
          return new ActiveXObject("Msxml2.XMLHTTP");
          }
        catch (e)
          {
          try
            {
            return new ActiveXObject("Microsoft.XMLHTTP");
            }
          catch (e)
            {
            alert("Your browser does not support AJAX!");
            return false;
            }
          }
        }
  }