
function testAlert()
{
alert("ok");
}




var isWorking = false;
var http = getHTTPObject();
var currentSelectedChar = '1';

function getHTTPObject() {
 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 handleHttpResponse() {

  if (http.readyState == 4) {

    isWorking = false;
    ajaxResponse=http.responseText;
  }
  else
  {
	ajaxResponse="Error performing AJAX HttpRequest";
  }

}

function httpRequest(url, method, syncMethod ) {
    if (!isWorking) {
    http.open(method, url, syncMethod);  

    isWorking = true;
    
    ajaxResponse=null;

    http.onreadystatechange = function (){handleHttpResponse();}

    http.send(null);
  }
}
   
function httpRequestWithParams(url, method, syncMethod, params) {
  if (!isWorking) {
    http.open(method, url, syncMethod);  

    isWorking = true;
    
    ajaxResponse=null;

    http.onreadystatechange = function (){handleHttpResponse();}
    
 
    http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');


    /*
    http.setRequestHeader("aHref", aHref);
    http.setRequestHeader("addressName", addressName);
    http.setRequestHeader("addressMail", addressMail);
    http.setRequestHeader("senderName", senderName);
    http.setRequestHeader("senderMail", senderMail);
    http.setRequestHeader("comments", comments);
    */
    http.send(params);
  }
}
    
function getAtmosphere(ddlObj, firstUrlPosting)
{	
	var url;
	if(ddlObj=="-1")
		url = firstUrlPosting;
	else
    // get the selectedIndex value
		url = ddlObj.options[ddlObj.selectedIndex].value;
	// get the file content
	if(url=="")
		return;
	var fileContent = sendPostAjax2(url, "contentOnly=0");
	
	// write the content to the page
	var spanItem = document.getElementById("contentItem");
	//alert(fileContent);
	spanItem.innerHTML = fileContent;
}

function sendPostAjax2(url, paramsString)
{
	http.open('POST', url, false);  
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	http.send(paramsString);
	var ResponseString=http.responseText;
	return ResponseString;
}
function selectMovies(selectType, selectedValue, CurrentCultureString,regionChannel, mode )
{	
	// reset the other drop downs
	//var container = document.getElementById("selMoviesContainer");
	var container = document.getElementById("divContainer");
	var arrSel = container.getElementsByTagName("select");

	arrSel[(selectType+1)%3].selectedIndex = 0;
	arrSel[(selectType+2)%3].selectedIndex = 0;
	   
	var ResponseString;


	if(selectedValue=="0")
		ResponseString="";
	else
	{
		// get the data from the Web Service GetMovies,
		// the function getMoviesFunc
		var url = appPath+"/WebServices/GetMovies.asmx/getMoviesFunc";
		   
		var paramString = "selectType="+selectType+"&selectedValue="+selectedValue+
			"&CurrentCultureString="+CurrentCultureString+"&regionChannel="+regionChannel+
			"&mode="+mode+"&appPath="+appPath;
		///////////	
		ResponseString=sendPostAjaxXml(url,paramString);
		///////////////////
		if(ResponseString == "-1")
			ResponseString="";
		ResponseString=HtmlDecode(ResponseString);
		ResponseString = ResponseString.replace('<![CDATA[','').replace(']]>','');
	}
	var dvMovies = document.getElementById("divMovies");
	dvMovies.innerHTML = ResponseString;
		
}

function selectTerms(selectedChar, CurrentCultureString, regionChannel, mode )
{
	//alert(selectedChar+","+ CurrentCultureString+","+ regionChannel+","+ mode )
	var ResponseString;
	var url = appPath+"/WebServices/GetMovies.asmx/getTermsFunc";
	var paramString = "selectedChar="+selectedChar+
		"&CurrentCultureString="+CurrentCultureString+"&regionChannel="+regionChannel+
		"&mode="+mode;
	ResponseString=sendPostAjaxXml(url,paramString);
	
	ResponseString=HtmlDecode(ResponseString);
	ResponseString = ResponseString.replace('<![CDATA[','').replace(']]>','');
	var dvTerms = document.getElementById("divTerms");
	if(ResponseString=="-1")
		ResponseString="";
	dvTerms.innerHTML = ResponseString;	
	// object of the selected char
	var curChar = document.getElementById("letter" + currentSelectedChar + "Box");
    if (curChar)
	{
	    curChar.className = "tdLetter";
	}
	currentSelectedChar = selectedChar;
	curChar = document.getElementById("letter" + currentSelectedChar + "Box");
    if (curChar)
	{
	    curChar.className = "tdLetterBoxed";
	}
}
function sendPostAjaxXml(url, paramsString)
{
	var domParser, ResponseString, xmlResponse;
	
    http.open('POST', url, false);  
	http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	http.send(paramsString);

	try
	{
	
		if (window.XMLHttpRequest && getBrowserType() != 'IE')// code for Mozilla, etc.
		{
			domParser = new DOMParser();
			xmlResponse = domParser.parseFromString(http.responseText, 'application/xml');
			ResponseString = xmlResponse.documentElement.textContent;
			
		}
		else// code for IE
		{
		  
			xmlResponse = new ActiveXObject("Msxml2.DOMDocument");
			xmlResponse.loadXML(http.responseText);
			ResponseString=xmlResponse.documentElement.childNodes.item(0).xml;
			
		}
	}
	catch(e)
	{
		ResponseString="-1";//"Xml Parse Failure";
	}
	
	return ResponseString;
}


var http_request = false;
function getRecordsForMozilla(requestURL, isXML)
{		
        if (isXML==null)
        {
            isXML=true;
        }
		http_request = false;
		if (window.XMLHttpRequest)
		{ // Mozilla, Safari,...
			http_request = new XMLHttpRequest();                     
				if (http_request.overrideMimeType)
				{
				    http_request.overrideMimeType("text/xml");                            
				    // some mozilla browser might complain here about this line
				}
		} 
		if (!http_request)
		{
			alert('Giving up :( Cannot create an XMLHTTP instance');
			return false;
		}
        
		try
		{	http_request.onreadystatechange = alertContents();
		    http_request.open('GET', requestURL, false);   
		      
		    http_request.send(null);
		    
		    if (isXML)
		        return http_request.responseXML;
		    else
		        return http_request.responseText;
		}
		catch (e)
		{
		}
		
}

// function to check if connection went ok		
//use it in mozilla
function alertContents()
{
    if (http_request.readyState == 4)
     {
     
        if (http_request.status == 200) 
        {            
        //if connection went ok then start activex object
        if (moz == true) {
       
            DoXmlObject();
            moz = false;
        }
        } 
        else 
        {
            alert('There was a problem with the request.');
        }
     }
}       
       

//FireFox [Mozilla] by default doesn't have selectNodes or selectSingleNode methods that Internet Explorer (IE) XMLDOM has.
//Parsing an XPath Expression to these methods will return a collection of Nodes or a single Node that match the XPath Expression.
// The following simple script will expand the XMLDocument and Element objects for Mozilla to enable these functions. 

try
{   //of TRY Mozilla Case
    //***** OverRide selectNodes() *****//
    // prototying the XMLDocument 
    XMLDocument.prototype.selectNodes = function(cXPathString, xNode) 
    { 
        if( !xNode ) { xNode = this; }
        var oNSResolver = this.createNSResolver(this.documentElement) 
        var aItems = this.evaluate(cXPathString, xNode, oNSResolver,
        XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null) 
        var aResult = [];
        for( var i = 0; i < aItems.snapshotLength; i++) 
        { 
        aResult[i] = aItems.snapshotItem(i);
        } 
        return aResult;
    } 

    // prototying the Element 
    Element.prototype.selectNodes = function(cXPathString) 
    { 
        if(this.ownerDocument.selectNodes) 
        { 
        return this.ownerDocument.selectNodes(cXPathString, this);
        } 
        else{throw "For XML Elements Only";} 
        
        
    } 
    //***** END OverRide selectNodes() *****//

    //***** OverRide selectSingleNode() *****//
    // prototying the XMLDocument 
    XMLDocument.prototype.selectSingleNode = function(cXPathString, xNode) 
    { 
        if( !xNode ) { xNode = this; }
        var xItems = this.selectNodes(cXPathString, xNode);
        if( xItems.length > 0 ) 
        { 
        return xItems[0];
        } 
        else 
        { 
        return null;
        } 
    } 

    // prototying the Element 
    Element.prototype.selectSingleNode = function(cXPathString) 
    {
        if(this.ownerDocument.selectSingleNode) 
        { 
            return this.ownerDocument.selectSingleNode(cXPathString, this);
        } 
        else{throw "For XML Elements Only";} 
    } 
}//end of TRY Mozilla Case
catch (e)
{
    //alert(e.message);
}
//***** END OverRide selectSingleNode() *****//
/******* New function for Ajax *********/
function attach_event(obj, eventX, funcName)
{

	if (typeof(funcName) == "string") 
	{
		funObj = eval(funcName);
	} 
	else 
	{
	    funObj = funcName;
	}
	//var funObj = eval(funcName);
	if(funObj == null)
		return;
		
   if(navigator.appName.toLowerCase().indexOf("explorer") > -1)
        obj.attachEvent(eventX, funObj);
   else
       obj.addEventListener(eventX, funObj, false);

}

var inIdebugMode = true;

var loadingImg = new Image();	

//loadingImg.src = "/Style Library/Images/Asakim/Icons/ajax-loader.gif";

loadingImg.src = "/WebResources/Images/Icon/ajax-loader.gif";

var objContent;

var AJAX = {
    replaceContent: function(obj, url, params, showLoading, debug, callback) {
        if (showLoading) {
            if (obj.attributes["LoadingText"] != null &&
                obj.attributes["LoadingText"] != '') {
                obj.innerHTML = "<table width='100%' height='100%' class='Loading'><tr><td valign='middle' align='center' class='RegularText'><img src='" + loadingImg.src + "' style='' alt=''><br/><br/>" + obj.attributes["LoadingText"].value + "</td></tr></table>"
            }
            else {
                obj.innerHTML = "<table width='100%' height='100%' class='Loading'><tr><td valign='middle' align='center' class='RegularText'><img src='" + loadingImg.src + "' style='' alt=''><br/><br/>Loading...</td></tr></table>"
            }
        }

        if (debug != false)
            debug = false;

        ajaxHandler = new cpaint();
        ajaxHandler.set_transfer_mode('post');
        ajaxHandler.set_debug(debug);
        ajaxHandler.set_response_type('text');
        objContent = obj;
        if (callback) objContent.callback = callback;

        idebug.write("replaceContent:", 0, "");
        idebug.write(url + "?" + params, 0, "url");

        ajaxHandler.call(url, "", "replaceContentCallBack", params);
    },

    asyncWithCallback: function(url, params, callbackFunc, showLoading, debug, obj) {
      
        if (debug != false)
            debug = false;

        if (obj != null) {
            if (showLoading) {
                if (obj.attributes["LoadingText"] != null &&
                    obj.attributes["LoadingText"] != '') {
                    obj.innerHTML = "<table width='100%' height='100%' class='Loading'><tr><td valign='middle' align='center' class='RegularText'><img src='" + loadingImg.src + "' style='' alt=''><br/><br/>" + obj.attributes["LoadingText"].value + "</td></tr></table>"
                }
                else {
                    obj.innerHTML = "<table width='100%' height='100%' class='Loading'><tr><td valign='middle' align='center' class='RegularText'><img src='" + loadingImg.src + "' style='' alt=''><br/><br/>Loading...</td></tr></table>"
                }
            }
        }

        ajaxHandler = new cpaint();
        ajaxHandler.set_transfer_mode('post');
        ajaxHandler.set_debug(debug);
        ajaxHandler.set_response_type('text');

        idebug.write("asyncWithCallback:", 0, "");
        idebug.write(url + "?" + params, 0, "url");
        ajaxHandler.call(url, "", callbackFunc, params);
    },
    syncWithCallback: function(url, params, callbackFunc, showLoading, debug) {
        if (debug != false)
            debug = false;

        ajaxHandler = new cpaint();
        ajaxHandler.set_transfer_mode('post');
        ajaxHandler.set_debug(debug);
        ajaxHandler.set_async(false);
        ajaxHandler.set_response_type('text');

        idebug.write("asyncWithCallback:", 0, "");
        idebug.write(url + "?" + params, 0, "url");
        ajaxHandler.call(url, "", callbackFunc, params);
    }
}
function xxx()
   {
	alert('success')
   }
function replaceContentCallBack(response)
{
   // alert(response);
	objContent.innerHTML = response;
	if (objContent.callback) objContent.callback(response);
    //a.innerHTML = response;
}


/*
function asyncWithCallback(url, params, callbackFunc, showLoading, debug)
{
    //TODO: handle showLoading... 
    
    if (debug != false)
        debug = false;

    ajaxHandler = new cpaint();
    ajaxHandler.set_transfer_mode('post');
    ajaxHandler.set_debug(debug);
    ajaxHandler.set_response_type('text');
    ajaxHandler.call(url, "", callbackFunc, params);
}
*/

function cpaint() {
  /**
  * CPAINT version
  * 
  * @access     protected
  * @var        string      version
  */
  this.version = '2.0.3';
  
  /**
  * configuration options both for this class but also for  the cpaint_call() objects.
  *
  * @access     protected
  * @var        array       config
  */
  var config                      = new Array();
  config['debugging']             = -1;
  config['proxy_url']             = '';
  config['transfer_mode']         = 'TRUE';
  config['async']                 = true;
  config['response_type']         = 'TEXT';
  config['persistent_connection'] = false;
  config['use_cpaint_api']        = false;
  
  /**
  * maintains the next free index in the stack
  *
  * @access   protected
  * @var      integer   stack_count
  */
  var stack_count = 0;

  /**
  * property returns whether or not the browser is AJAX capable
  * 
  * @access		public
  * @return		boolean
  */
  this.capable = test_ajax_capability();
  
  /**
  * switches debug mode on/off.
  *
  * @access   public
  * @param    boolean    debug    debug flag
  * @return   void
  */
  this.set_debug = function() {
    
    if (typeof arguments[0] == 'boolean') {
      if (arguments[0] === true) {
        config['debugging'] = 1;

      } else {
        config['debugging'] = 0;
      }
      
    } else if (typeof arguments[0] == 'number') {
      config['debugging'] = Math.round(arguments[0]);
    }
  }

  /**
  * defines the URL of the proxy script.
  *
  * @access   public
  * @param    string    proxy_url    URL of the proxyscript to connect
  * @return   void
  */
  this.set_proxy_url = function() {
    
    if (typeof arguments[0] == 'string') {

      config['proxy_url'] = arguments[0];
    }
  }

  /**
  * sets the transfer_mode (GET|POST).
  *
  * @access   public
  * @param    string    transfer_mode    transfer_mode
  * @return   void
  */
  this.set_transfer_mode = function() {
    
    if (arguments[0].toUpperCase() == 'GET'
      || arguments[0].toUpperCase() == 'POST') {

      config['transfer_mode'] = arguments[0].toUpperCase();
    }
  }

  /**
  * sets the flag whether or not to use asynchronous calls.
  *
  * @access   public
  * @param    boolean    async    syncronization flag
  * @return   void
  */
  this.set_async = function() {
    
    if (typeof arguments[0] == 'boolean') {
      config['async'] = arguments[0];
    }
  }

  /**
  * defines the response type.
  *
  * allowed values are:
  *   TEXT    = raw text response
  *   XML     = raw XMLHttpObject
  *   OBJECT  = parsed JavaScript object structure from XMLHttpObject
  *
  * the default is OBJECT.
  *
  * @access   public
  * @param    string    response_type    response type
  * @return   void
  */
  this.set_response_type = function() {
    
    if (arguments[0].toUpperCase() == 'TEXT'
      || arguments[0].toUpperCase() == 'XML'
      || arguments[0].toUpperCase() == 'OBJECT'
      || arguments[0].toUpperCase() == 'E4X'
      || arguments[0].toUpperCase() == 'JSON') {

      config['response_type'] = arguments[0].toUpperCase();
    }
  }

  /**
  * sets the flag whether or not to use a persistent connection.
  *
  * @access   public
  * @param    boolean    persistent_connection    persistance flag
  * @return   void
  */
  this.set_persistent_connection = function() {
    
    if (typeof arguments[0] == 'boolean') {
      config['persistent_connection'] = arguments[0];
    }
  }
  
  
  /**
  * sets the flag whether or not to use the cpaint api on the backend.
  *
  * @access    public
  * @param     boolean    cpaint_api      api_flag
  * @return    void
  */
  this.set_use_cpaint_api = function() {
    if (typeof arguments[0] == 'boolean') {
      config['use_cpaint_api'] = arguments[0];
    }
  }
  
  /**
  * tests whether one of the necessary implementations
  * of the XMLHttpRequest class are available
  *
  * @access     protected
  * @return     boolean
  */
  function test_ajax_capability() {
    var cpc = new cpaint_call(0, config, this.version);
    return cpc.test_ajax_capability();
  }

  /**
  * takes the arguments supplied and triggers a call to the CPAINT backend
  * based on the settings.
  *
  * upon response cpaint_call.callback() will automatically be called
  * to perform post-processing operations.
  *
  * @access   public
  * @param    string    url                 remote URL to call
  * @param    string    remote_method       remote method to call
  * @param    object    client_callback     client side callback method to deliver the remote response to. do NOT supply a string!
  * @param    mixed     argN                remote parameters from now on
  * @return   void
  */
  this.call = function() {
    var use_stack = -1;
    
    if (config['persistent_connection'] == true
      && __cpaint_stack[0] != null) {

      switch (__cpaint_stack[0].get_http_state()) {
        case -1:
          // no XMLHttpObject object has already been instanciated
          // create new object and configure it
          use_stack = 0;
          debug('no XMLHttpObject object to re-use for persistence, creating new one later', 2);
          break;
          
        case 4:
          // object is ready for a new request, no need to do anything
          use_stack = 0
          debug('re-using the persistent connection', 2);
          break;
          
        default:
          // connection is currently in use, don't do anything
          debug('the persistent connection is in use - skipping this request', 2);
      }
      
    } else if (config['persistent_connection'] == true) {
      // persistent connection is active, but no object has been instanciated
      use_stack = 0;
      __cpaint_stack[use_stack] = new cpaint_call(use_stack, config, this.version);
      debug('no cpaint_call object available for re-use, created new one', 2);
    
    } else {
      // no connection persistance
      use_stack = stack_count;
      __cpaint_stack[use_stack] = new cpaint_call(use_stack, config, this.version);
      debug('no cpaint_call object created new one', 2);
    }

    // configure cpaint_call if allowed to
    if (use_stack != -1) {
      __cpaint_stack[use_stack].set_client_callback(arguments[2]);
      __cpaint_stack[use_stack].set_client_container(arguments[1]);

	
      // distribute according to proxy use
      if (config['proxy_url'] != '') {
        __cpaint_stack[use_stack].call_proxy(arguments);
      
      } else {
        __cpaint_stack[use_stack].call_direct(arguments);
      }

      // increase stack counter
      stack_count++;
      debug('stack size: ' + __cpaint_stack.length, 2);
    }
  }

  /**
  * debug method
  *
  * @access  protected
  * @param   string       message         the message to debug
  * @param   integer      debug_level     debug level at which the message appears
  * @return  void
  */
  var debug  = function(message, debug_level) {
    var prefix = '[CPAINT Debug] ';
    
    if (debug_level < 1) {
      prefix = '[CPAINT Error] ';
    }
    
    if (config['debugging'] >= debug_level) {
      //alert(prefix + message);
      ERROR.publish(prefix + message.replace(/&/g, "__"));
    }
  }
}

var idebug = {
    state:0,
    debugwindow:false,
    messages:new Array(),
    write:function(message, debug_level, type) {
        this.messages[this.messages.length] = {d:this.formatTime(new Date()), m:message, t:type};
        if (this.state == 1) this.print(this.messages[this.messages.length-1]);
    },
    open:function() {
        if (this.state == 1) return;
        this.debugwindow = document.body.appendChild(document.createElement("div"));
	    this.debugwindow.style.cssText = "position:absolute;display:none; top:0; left:0; width:400px; height:400px; background:#FFFFCC; overflow-y:auto;"; /*hushay */
        this.debugwindow.align = "left";
        this.state = 1;
        for (var i=0;i<this.messages.length;i++) this.print(this.messages[i]);
    },
    formatTime:function(d) {
        function lpad(value) {
            value = value+"";
            return (value.length == 1) ? "0"+value : value;
        }
        return lpad(d.getHours())+":"+lpad(d.getMinutes())+":"+lpad(d.getSeconds())+"."+d.getMilliseconds();
    },
    print:function(message) {
        var rs = message.d+": ";
        switch (message.t) {
            case "url":
                rs += "<a href='"+message.m+"' target='_blank'>"+message.m+"</a>";
                break;
            case "xml":
                rs += "<textarea style='width:100%; height:50px;'>"+message.m+"</textarea>";
                break;
            default:
                rs += message.m;
        }
        rs += "<br />";
        this.debugwindow.innerHTML += rs;
    }
}   
if (inIdebugMode) 
{
    
    //document.attachEvent("onkeydown", chooseAction);
    attach_event(document, "onkeydown", "chooseAction");
}
	

function chooseAction()
{
    if (event.shiftKey && event.ctrlKey) 
        {
            switch (event.keyCode) 
            {
                case 123:
                    idebug.open();
                    break;
                case 40:
                    event.returnValue = false;
                    if (idebug.state == 0) idebug.open();
                    idebug.debugwindow.style.top = parseInt(idebug.debugwindow.style.top, 10) + 100;
                    break;
                case 38:
                    event.returnValue = false;
                    if (idebug.state == 0) idebug.open();
                    idebug.debugwindow.style.top = parseInt(idebug.debugwindow.style.top, 10) - 100;
                    break;
                case 37:
                    event.returnValue = false;
                    if (idebug.state == 0) idebug.open();
                    idebug.debugwindow.style.left = parseInt(idebug.debugwindow.style.left, 10) - 100;
                    break;
                case 39:
                    event.returnValue = false;
                    if (idebug.state == 0) idebug.open();
                    idebug.debugwindow.style.left = parseInt(idebug.debugwindow.style.left, 10) + 100;
                    break;
            }
        }
}
/**
* internal FIFO stack of cpaint_call() objects.
*
* @access   protected
* @var      array    __cpaint_stack
*/
var __cpaint_stack = new Array();

/**
* local instance of cpaint_transformer
* MSIE is unable to handle static classes... sheesh.
*
* @access   public
* @var      object    __cpaint_transformer
*/
var __cpaint_transformer = new cpaint_transformer();

/**
* transport agent class
*
* creates the request object, takes care of the response, handles the 
* client callback. Is configured by the cpaint() object.
*
* @package      CPAINT
* @access       public
* @copyright    Copyright (c) 2005-2006 Paul Sullivan, Dominique Stender - http://sf.net/projects/cpaint
* @author       Dominique Stender <dstender@st-webdevelopment.de>
* @author       Paul Sullivan <wiley14@gmail.com>
* @param        integer     stack_id      stack Id in cpaint
* @param        array       config        configuration array for this call
* @param        string      version       CPAINT API version
*/
function cpaint_call() {
  /**
  * CPAINT version
  * 
  * @access     protected
  * @var        string      version
  */
  var version = arguments[2];
  
  /**
  * configuration options both for this class objects.
  *
  * @access     protected
  * @var        array       config
  */
  var config                      = new Array();
  config['debugging']             = arguments[1]['debugging'];
  config['proxy_url']             = arguments[1]['proxy_url'];
  config['transfer_mode']         = arguments[1]['transfer_mode'];
  config['async']                 = arguments[1]['async'];
  config['response_type']         = arguments[1]['response_type'];
  config['persistent_connection'] = arguments[1]['persistent_connection'];
  config['use_cpaint_api']        = arguments[1]['use_cpaint_api'];

  /**
  * XMLHttpObject used for this request.
  *
  * @access   protected
  * @var      object     httpobj
  */
  var httpobj    = false;

  /**
  * client callback function.
  *
  * @access   public
  * @var      function    client_callback
  */
  var client_callback;

  /**
  * client container object.
  *
  * @access   public
  * @var      function    client_container
  */
  var client_container;

  /**
  * stores the stack Id within the cpaint object
  *
  * @access   protected
  * @var      stack_id
  */
  var stack_id = arguments[0];
  
  /**
  * sets the client callback function.
  *
  * @access   public
  * @param    function    client_callback     the client callback function
  * @return   void
  */
  this.set_client_callback = function() {
    if (typeof arguments[0] == 'string') {
      client_callback = arguments[0];
    }
  }

  this.set_client_container = function() {
    if (typeof arguments[0] == 'object') {
      client_container = arguments[0];
    }
  }

  /**
  * returns the ready state of the internal XMLHttpObject
  *
  * if no such object was set up already, -1 is returned
  * 
  * @access     public
  * @return     integer
  */
  this.get_http_state = function() {
    var return_value = -1;
    
    if (typeof httpobj == 'object') {
      return_value = httpobj.readyState;
    }
    
    return return_value;
  }
  
  this.makeEncodedArgument=function(arg)
  {
	var rtn=arg.split("=");
	var key=rtn[0];
	var value="";
		
	if (rtn.length>1)
	{
		for (itr=1; itr<rtn.length; ++itr)
		{
			value+=(itr>1? "=" : "")+rtn[itr];
		}
		//return key+"="+encodeURIComponent(value);	
		return arg
	}
	else
		return arg
		//return encodeURIComponent(key);
  }
  
  /**
  * internal method for remote calls to the local server without use of the proxy script.
  *
  * @access   public
  * @param    array    call_arguments    array of arguments initially passed to cpaint.call()
  * @return   void
  */
  this.call_direct = function(call_arguments) {
    var url             = call_arguments[0];
    var remote_method   = call_arguments[1];
    var querystring     = '';
    var i               = 0;

    // correct link to self
    if (url == 'SELF') {
      url = document.location.href;
    }
  
    if (config['use_cpaint_api'] == true) {
      // backend uses cpaint api
      // pass parameters to remote method
      for (i = 3; i < call_arguments.length; i++) {

        if ((typeof call_arguments[i] == 'string'
              && call_arguments[i] != ''
              && call_arguments[i].search(/^\s+$/g) == -1)
          && !isNaN(call_arguments[i])
          && isFinite(call_arguments[i])) {
          // numerical value, convert it first
          querystring += '&cpaint_argument[]=' + encodeURIComponent(JSON.stringify(Number(call_arguments[i])));
        
        } else {
          querystring += '&cpaint_argument[]=' + encodeURIComponent(JSON.stringify(call_arguments[i]));
        }
      }
    
      // add response type to querystring
      querystring += '&cpaint_response_type=' + config['response_type'];
    
      // build header
      if (config['transfer_mode'] == 'GET') {
				
        if(url.indexOf('?') != -1) {
					url = url + '&cpaint_function=' + remote_method +	querystring;
				
        } else {
					url = url + '?cpaint_function=' + remote_method +	querystring; 
				}
      
      } else {
        querystring = 'cpaint_function=' + remote_method + querystring;
      }
      
    } else {
      // backend does not use cpaint api
      // pass parameters to remote method
      for (i = 3; i < call_arguments.length; i++) {
        if (i == 3) {
          querystring += this.makeEncodedArgument(call_arguments[i]);
        
        } else {
          querystring += '&' + this.makeEncodedArgument(call_arguments[i]);
        }
      }
    
      // build header
      if (config['transfer_mode'] == 'GET') {
        url = url + querystring;
      } 
    }
  
    // open connection 
    get_connection_object();

    // open connection to remote target
    debug('opening connection to "' + url + '"', 1);
    httpobj.open(config['transfer_mode'], url, config['async']);

    // send "urlencoded" header if necessary (if POST)
    if (config['transfer_mode'] == 'POST') {

      try {
        httpobj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

      } catch (cp_err) {
        debug('POST cannot be completed due to incompatible browser.  Use GET as your request method.', 0);
      }
    }

    // make ourselves known
    httpobj.setRequestHeader('X-Powered-By', 'CPAINT v' + version + ' :: http://sf.net/projects/cpaint');

    // callback handling for asynchronous calls
    httpobj.onreadystatechange = callback;

    // send content
    if (config['transfer_mode'] == 'GET') {
      httpobj.send(null);

    } else {
      debug('sending query: ' + querystring, 1);
      httpobj.send(querystring);
    }
    if (config['async'] == false) {
        
      // manual callback handling for synchronized calls
      callback();
    }
  }
    
  /**
  * internal method for calls to remote servers through the proxy script.
  *
  * @access   public
  * @param    array    call_arguments    array of arguments passed to cpaint.call()
  * @return   void
  */
  this.call_proxy = function(call_arguments) {
    var proxyscript     = config['proxy_url'];
    var url             = call_arguments[0];
    var remote_method   = call_arguments[1];
    var querystring     = '';
    var i               = 0;
    
    var querystring_argument_prefix = 'cpaint_argument[]=';

    // pass parameters to remote method
    if (config['use_cpaint_api'] == false) {
      // when not talking to a CPAINT backend, don't prefix arguments
      querystring_argument_prefix = '';
    }

    for (i = 3; i < call_arguments.length; i++) {

      if (config['use_cpaint_api'] == true) {
      
        if ((typeof call_arguments[i] == 'string'
              && call_arguments[i] != ''
              && call_arguments[i].search(/^\s+$/g) == -1)
          && !isNaN(call_arguments[i])
          && isFinite(call_arguments[i])) {
          // numerical value, convert it first
          querystring += encodeURIComponent(querystring_argument_prefix + JSON.stringify(Number(call_arguments[i])) + '&');

        } else {
          querystring += encodeURIComponent(querystring_argument_prefix + JSON.stringify(call_arguments[i]) + '&');
        }
        
      } else {
        // no CPAINT in the backend
        querystring += encodeURIComponent(querystring_argument_prefix + call_arguments[i] + '&');
      }
    }

    if (config['use_cpaint_api'] == true) {
      // add remote function name to querystring
      querystring += encodeURIComponent('&cpaint_function=' + remote_method);
  
      // add response type to querystring
      querystring += encodeURIComponent('&cpaint_responsetype=' + config['response_type']);
    }
    
    // build header
    if (config['transfer_mode'] == 'GET') {
      proxyscript += '?cpaint_remote_url=' + encodeURIComponent(url) 
        + '&cpaint_remote_query=' + querystring
        + '&cpaint_remote_method=' + config['transfer_mode'] 
        + '&cpaint_response_type=' + config['response_type'];

    } else {
      querystring = 'cpaint_remote_url=' + encodeURIComponent(url)
        + '&cpaint_remote_query=' + querystring
        + '&cpaint_remote_method=' + config['transfer_mode'] 
        + '&cpaint_response_type=' + config['response_type'];
    }

    // open connection
    get_connection_object();

    // open connection to remote target
    debug('opening connection to proxy "' + proxyscript + '"', 1);
    httpobj.open(config['transfer_mode'], proxyscript, config['async']);

    // send "urlencoded" header if necessary (if POST)
    if (config['transfer_mode'] == 'POST') {

      try {
        httpobj.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

      } catch (cp_err) {
        debug('POST cannot be completed due to incompatible browser.  Use GET as your request method.', 0);
      }
    }

    httpobj.setRequestHeader('X-Powered-By', 'CPAINT v' + version);

    // callback handling for asynchronous calls
    httpobj.onreadystatechange = callback;

    // send content
    if (config['transfer_mode'] == 'GET') {
      httpobj.send(null);

    } else {
      debug('sending query: ' + querystring, 1);
      httpobj.send(querystring);
    }

    if (config['async'] == false) {
      // manual callback handling for synchronized calls
      callback();
    }
  }

  this.test_ajax_capability = function() {
    return get_connection_object();
  }
  
  /**
  * creates a new connection object.
  *
  * @access   protected
  * @return   boolean
  */
  var get_connection_object = function() {
    var return_value    = false;
    var new_connection  = false;

    // open new connection only if necessary
    if (config['persistent_connection'] == false) {
      // no persistance, create a new object every time
      debug('Using new connection object', 1);
      new_connection = true;

    } else {
      // persistent connection object, only open one if no object exists
      debug('Using shared connection object.', 1);

      if (typeof httpobj != 'object') {
        debug('Getting new persistent connection object.', 1);
        new_connection = true;
      }
    }

    if (new_connection == true) {
		
	 try {
        httpobj = new XMLHttpRequest();
      } catch (e1) {

		  try {
			httpobj = new ActiveXObject('Msxml2.XMLHTTP');
	  
		  } catch (e) {
			
			try {  
			  httpobj = new ActiveXObject('Microsoft.XMLHTTP');
 
			} catch (oc) {
			  httpobj = null;
			} 
		 }
	  }
     
  
      if (!httpobj) {
        debug('Could not create connection object', 0);
      
      } else {
        return_value = true;
      }
    }

    if (httpobj.readyState != 4) {
      httpobj.abort();
    }

    return return_value;
  }

  /**
  * internal callback function.
  *
  * will perform some consistency checks (response code, NULL value testing)
  * and if response_type = 'OBJECT' it will automatically call
  * cpaint_call.parse_ajax_xml() to have a JavaScript object structure generated.
  *
  * after all that is done the client side callback function will be called 
  * with the generated response as single value.
  *
  * @access   protected
  * @return   void
  */
  var callback = function() {
      var response = null;

    if (httpobj.readyState == 4
      && httpobj.status == 200) {

      idebug.write(httpobj.responseText, 0, "xml");
      idebug.write('using response type ' + config['response_type'], 0, "");
      
      debug(httpobj.responseText, 1);
      debug('using response type ' + config['response_type'], 2);
      // fetch correct response
      switch (config['response_type']) {
        case 'XML':
          debug(httpobj.responseXML, 2);
          response = __cpaint_transformer.xml_conversion(httpobj.responseXML);
          break;
          
        case 'OBJECT':
          response = __cpaint_transformer.object_conversion(httpobj.responseXML);
          break;
        
        case 'TEXT':
          response = __cpaint_transformer.text_conversion(httpobj.responseText);
          break;
          
        case 'ENCODETEXT':
          response = __cpaint_transformer.encodetext_conversion(httpobj.responseText);
          break;
          
        case 'E4X':
          response = __cpaint_transformer.e4x_conversion(httpobj.responseText);
          break;
          
        case 'JSON':
          response = __cpaint_transformer.json_conversion(httpobj.responseText);
          break;
          
        default:
          debug('invalid response type \'' + response_type + '\'', 0);
      }
      // call client side callback
      if (response != null 
        && typeof client_callback == 'string') {
        eval(client_callback+"(response)");
      }
      
      // remove ourselves from the stack
      remove_from_stack();
    
    } else if (httpobj.readyState == 4
      && httpobj.status != 200) {
      // HTTP error of some kind
      debug('invalid HTTP response code \'' + Number(httpobj.status) + '\': \n'+httpobj.responseText, 0);
    //  alert(httpobj.responseText);
    }
  }

  /**
  * removes an entry from the stack
  *
  * @access     protected
  * @return     void
  */
  var remove_from_stack = function() {
    // remove only if everything is okay and we're not configured as persistent connection
    if (typeof stack_id == 'number'
      && __cpaint_stack[stack_id]
      && config['persistent_connection'] == false) {
      
      __cpaint_stack[stack_id] = null;
    }
  }

  /**
  * debug method
  *
  * @access  protected
  * @param   string       message         the message to debug
  * @param   integer      debug_level     debug level at which the message appears
  * @return  void
  */
  var debug  = function(message, debug_level) {
    var prefix = '[CPAINT Debug] ';
    
    if (config['debugging'] < 1) {
      prefix = '[CPAINT Error] ';
    }
    
    if (config['debugging'] >= debug_level) {
      //alert(prefix + message);
      ERROR.publish(prefix + message.replace(/&/g, "__"));
    }
  }
}

/**
* CPAINT transformation object
*
* @package      CPAINT
* @access       public
* @copyright    Copyright (c) 2005-2006 Paul Sullivan, Dominique Stender - http://sf.net/projects/cpaint
* @author       Paul Sullivan <wiley14@gmail.com>
* @author       Dominique Stender <dstender@st-webdevelopment.de>
*/
function cpaint_transformer() {

  /**
  * will take a XMLHttpObject and generate a JavaScript
  * object structure from it.
  *
  * is internally called by cpaint_call.callback() if necessary.
  * will call cpaint_call.create_object_structure() to create nested object structures.
  *
  * @access   public
  * @param    object    xml_document  a XMLHttpObject
  * @return   object
  */
  this.object_conversion = function(xml_document) {
    var return_value  = new cpaint_result_object();
    var i             = 0;
    var firstNodeName = '';
    
    if (typeof xml_document == 'object'
      && xml_document != null) {

      // find the first element node - for MSIE the <?xml?> node is the very first...
      for (i = 0; i < xml_document.childNodes.length; i++) {

        if (xml_document.childNodes[i].nodeType == 1) {
          firstNodeName = xml_document.childNodes[i].nodeName;
          break;
        }
      }
      
      var ajax_response = xml_document.getElementsByTagName(firstNodeName);

      return_value[firstNodeName] = new Array();
    
      for (i = 0; i < ajax_response.length; i++) {
        var tmp_node = create_object_structure(ajax_response[i]);
        tmp_node.id  = ajax_response[i].getAttribute('id')
        return_value[firstNodeName].push(tmp_node);
      }

    } else {
      debug('received invalid XML response', 0);
    }

    return return_value;
  }

  /**
  * performs the necessary conversions for the XML response type
  *
  * @access   public
  * @param    object    xml_document  a XMLHttpObject
  * @return   object
  */
  this.xml_conversion = function(xml_document) {
    return xml_document;
  }
  
  /**
  * performs the necessary conversions for the TEXT response type
  *
  * @access   public
  * @param    string    text  the response text
  * @return   string
  */
  this.text_conversion = function(text) {
    return text;
  }
  
  /**
  * performs the necessary conversions for the ENCODETEXT response type
  *
  * @access   public
  * @param    string    text  the response text
  * @return   string
  */
  this.encodetext_conversion = function(text) {
    return decode(text);
  }
  
  /**
  * performs the necessary conversions for the E4X response type
  *
  * @access   public
  * @param    string    text  the response text
  * @return   string
  */
  this.e4x_conversion = function(text) {
    // remove <?xml ?>tag
    text = text.replace(/^\<\?xml[^>]+\>/, '');
    return new XML(text);
  }
  
  /**
  * performs the necessary conversions for the JSON response type
  *
  * @access   public
  * @param    string    text  the response text
  * @return   string
  */
  this.json_conversion = function(text) {
    return JSON.parse(text);
  }
  
  /**
  * this method takes a HTML / XML node object and creates a
  * JavaScript object structure from it.
  *
  * @access   public
  * @param    object    stream    a node in the XML structure
  * @return   object
  */
  var create_object_structure = function(stream) {
    var return_value = new cpaint_result_object();
    var node_name = '';
    var i         = 0;
    var attrib    = 0;
    
    if (stream.hasChildNodes() == true) {
      for (i = 0; i < stream.childNodes.length; i++) {
  
        node_name = stream.childNodes[i].nodeName;
        node_name = node_name.replace(/[^a-zA-Z0-9_]*/g, '');
        
        // reset / create subnode
        if (typeof return_value[node_name] != 'object') {
          return_value[node_name] = new Array();
        }
        
        if (stream.childNodes[i].nodeType == 1) {
          var tmp_node  = create_object_structure(stream.childNodes[i]);

          for (attrib = 0; attrib < stream.childNodes[i].attributes.length; attrib++) {
            tmp_node.set_attribute(stream.childNodes[i].attributes[attrib].nodeName, stream.childNodes[i].attributes[attrib].nodeValue);
          }
          
          return_value[node_name].push(tmp_node);
        
        } else if (stream.childNodes[i].nodeType == 3) {
          return_value.data  = decode(String(stream.firstChild.data));
        }
      }
    }
    
    return return_value;
  }

  /**
  * converts an encoded text back to viewable characters.
  *
  * @access     public
  * @param      string      rawtext     raw text as provided by the backend
  * @return     mixed
  */
  var decode = function(rawtext) {
    var plaintext = ''; 
    var i         = 0; 
    var c1        = 0;
    var c2        = 0;
    var c3        = 0;
    var u         = 0;
    var t         = 0;

    // remove special JavaScript encoded non-printable characters
    while (i < rawtext.length) {
      if (rawtext.charAt(i) == '\\'
        && rawtext.charAt(i + 1) == 'u') {
        
        u = 0;
        
        for (j = 2; j < 6; j += 1) {
          t = parseInt(rawtext.charAt(i + j), 16);
          
          if (!isFinite(t)) {
            break;
          }
          u = u * 16 + t;
        }

        plaintext += String.fromCharCode(u);
        i       += 6;
      
      } else {
        plaintext += rawtext.charAt(i);
        i++;
      }
    }

    // convert numeric data to number type
    if (plaintext != ''
      && plaintext.search(/^\s+$/g) == -1
      && !isNaN(plaintext) 
      && isFinite(plaintext)) {
      
      plaintext = Number(plaintext);
    }
  
    return plaintext;
  }
}

/**
* this is the basic prototype for a cpaint node object
* as used in cpaint_call.parse_ajax_xml()
*
* @package      CPAINT
* @access       public
* @copyright    Copyright (c) 2005-2006 Paul Sullivan, Dominique Stender - http://sf.net/projects/cpaint
* @author       Paul Sullivan <wiley14@gmail.com>
* @author       Dominique Stender <dstender@st-webdevelopment.de>
*/
function cpaint_result_object() {
  this.id           = 0;
  this.data         = '';
  var __attributes  = new Array();
  
  /**
  * Returns a subnode with the given type and id.
  *
  * @access     public
  * @param      string    type    The type of the subnode. Equivalent to the XML tag name.
  * @param      string    id      The id of the subnode. Equivalent to the XML tag names id attribute.
  * @return     object
  */
  this.find_item_by_id = function() {
    var return_value  = null;
    var type    = arguments[0];
    var id      = arguments[1];
    var i       = 0;
    
    if (this[type]) {

      for (i = 0; i < this[type].length; i++) {

        if (this[type][i].get_attribute('id') == id) {
          return_value = this[type][i];
          break;
        }
      }
    }

    return return_value;
  }
  
  /**
  * retrieves the value of an attribute.
  *
  * @access   public
  * @param    string    name    name of the attribute
  * @return   mixed
  */
  this.get_attribute = function() {
    var return_value  = null;
    var id            = arguments[0];
    
    if (typeof __attributes[id] != 'undefined') {
      return_value = __attributes[id];
    }
    
    return return_value;
  }
  
  /**
  * assigns a value to an attribute.
  *
  * if that attribute does not exist it will be created.
  *
  * @access     public
  * @param      string    name    name of the attribute
  * @param      string    value   value of the attribute
  * @return     void
  */
  this.set_attribute = function() {
    __attributes[arguments[0]] = arguments[1];
  }
}

/***********************************************************/

Array.prototype.______array = '______array';

var JSON = {
  org: 'http://www.JSON.org',
  copyright: '(c)2005 JSON.org',
  license: 'http://www.crockford.com/JSON/license.html',

  stringify: function (arg) {
    var c, i, l, s = '', v;
    var numeric = true;
    
    switch (typeof arg) {
    case 'object':
      if (arg) {
        if (arg.______array == '______array') {
          // do a test whether all array keys are numeric
          for (i in arg) {
            if (i != '______array'
              && (isNaN(i) 
                || !isFinite(i))) {
              numeric = false;
              break;
            }
          }
          
          if (numeric == true) {
            for (i = 0; i < arg.length; ++i) {
              if (typeof arg[i] != 'undefined') {
                v = this.stringify(arg[i]);
                if (s) {
                  s += ',';
                }
                s += v;
              } else {
                s += ',null';
              }
            }
            return '[' + s + ']';
          } else {
            for (i in arg) {
              if (i != '______array') {
                v = arg[i];
                if (typeof v != 'undefined' && typeof v != 'function') {
                  v = this.stringify(v);
                  if (s) {
                    s += ',';
                  }
                  s += this.stringify(i) + ':' + v;
                }
              }
            }
            // return as object
            return '{' + s + '}';
          }
        } else if (typeof arg.toString != 'undefined') {
          for (i in arg) {
            v = arg[i];
            if (typeof v != 'undefined' && typeof v != 'function') {
              v = this.stringify(v);
              if (s) {
                s += ',';
              }
              s += this.stringify(i) + ':' + v;
            }
          }
          return '{' + s + '}';
        }
      }
      return 'null';
    case 'number':
      return isFinite(arg) ? String(arg) : 'null';
    case 'string':
      l = arg.length;
      s = '"';
      for (i = 0; i < l; i += 1) {
        c = arg.charAt(i);
        if (c >= ' ') {
          if (c == '\\' || c == '"') {
            s += '\\';
          }
          s += c;
        } else {
          switch (c) {
            case '\b':
              s += '\\b';
              break;
            case '\f':
              s += '\\f';
              break;
            case '\n':
              s += '\\n';
              break;
            case '\r':
              s += '\\r';
              break;
            case '\t':
              s += '\\t';
              break;
            default:
              c = c.charCodeAt();
              s += '\\u00' + Math.floor(c / 16).toString(16) +
                (c % 16).toString(16);
          }
        }
      }
      return s + '"';
    case 'boolean':
      return String(arg);
    default:
      return 'null';
    }
  },
  parse: function (text) {
    var at = 0;
    var ch = ' ';

    function error(m) {
      throw {
        name: 'JSONError',
        message: m,
        at: at - 1,
        text: text
      };
    }

    function next() {
      ch = text.charAt(at);
      at += 1;
      return ch;
    }

    function white() {
      while (ch != '' && ch <= ' ') {
        next();
      }
    }

    function str() {
      var i, s = '', t, u;

      if (ch == '"') {
outer:      while (next()) {
          if (ch == '"') {
            next();
            return s;
          } else if (ch == '\\') {
            switch (next()) {
            case 'b':
              s += '\b';
              break;
            case 'f':
              s += '\f';
              break;
            case 'n':
              s += '\n';
              break;
            case 'r':
              s += '\r';
              break;
            case 't':
              s += '\t';
              break;
            case 'u':
              u = 0;
              for (i = 0; i < 4; i += 1) {
                t = parseInt(next(), 16);
                if (!isFinite(t)) {
                  break outer;
                }
                u = u * 16 + t;
              }
              s += String.fromCharCode(u);
              break;
            default:
              s += ch;
            }
          } else {
            s += ch;
          }
        }
      }
      error("Bad string");
    }

    function arr() {
      var a = [];

      if (ch == '[') {
        next();
        white();
        if (ch == ']') {
          next();
          return a;
        }
        while (ch) {
          a.push(val());
          white();
          if (ch == ']') {
            next();
            return a;
          } else if (ch != ',') {
            break;
          }
          next();
          white();
        }
      }
      error("Bad array");
    }

    function obj() {
      var k, o = {};

      if (ch == '{') {
        next();
        white();
        if (ch == '}') {
          next();
          return o;
        }
        while (ch) {
          k = str();
          white();
          if (ch != ':') {
            break;
          }
          next();
          o[k] = val();
          white();
          if (ch == '}') {
            next();
            return o;
          } else if (ch != ',') {
            break;
          }
          next();
          white();
        }
      }
      error("Bad object");
    }

    function assoc() {
      var k, a = [];

      if (ch == '<') {
        next();
        white();
        if (ch == '>') {
          next();
          return a;
        }
        while (ch) {
          k = str();
          white();
          if (ch != ':') {
            break;
          }
          next();
          a[k] = val();
          white();
          if (ch == '>') {
            next();
            return a;
          } else if (ch != ',') {
            break;
          }
          next();
          white();
        }
      }
      error("Bad associative array");
    }

    function num() {
      var n = '', v;
      if (ch == '-') {
        n = '-';
        next();
      }
      while (ch >= '0' && ch <= '9') {
        n += ch;
        next();
      }
      if (ch == '.') {
        n += '.';
        while (next() && ch >= '0' && ch <= '9') {
          n += ch;
        }
      }
      if (ch == 'e' || ch == 'E') {
        n += 'e';
        next();
        if (ch == '-' || ch == '+') {
          n += ch;
          next();
        }
        while (ch >= '0' && ch <= '9') {
          n += ch;
          next();
        }
      }
      v = +n;
      if (!isFinite(v)) {
        error("Bad number");
      } else {
        return v;
      }
    }

    function word() {
      switch (ch) {
        case 't':
          if (next() == 'r' && next() == 'u' && next() == 'e') {
            next();
            return true;
          }
          break;
        case 'f':
          if (next() == 'a' && next() == 'l' && next() == 's' &&
              next() == 'e') {
            next();
            return false;
          }
          break;
        case 'n':
          if (next() == 'u' && next() == 'l' && next() == 'l') {
            next();
            return null;
          }
          break;
      }
      error("Syntax error");
    }

    function val() {
      white();
      switch (ch) {
        case '{':
          return obj();
        case '[':
          return arr();
        case '<':
          return assoc();
        case '"':
          return str();
        case '-':
          return num();
        default:
          return ch >= '0' && ch <= '9' ? num() : word();
      }
    }

    return val();
  }
};

attach_event(window, "onload", handleLeftNav);
function handleLeftNav()
{	
	var slider = document.getElementById('slider');	
	if (slider) {
		//alert(slider.scrollHeight +">"+ slider.offsetHeight);
		if (slider.scrollHeight > slider.offsetHeight) {
			document.getElementById('sliderUp').style.display = '';
			document.getElementById('sliderDown').style.display = '';
		}
	}
}

//function xxx()
//{
//	try
//	{
//		if(koo)
//		{}
//		
//		//alert()
//	}catch(exp){ERROR.publish(exp.message,true)}
//}

var ERROR = {

	publish : function(exp, isErr, withHref) {
	
		if (withHref == null || typeof(withHref) == "undefined")
			withHref = true;
			
		if (isErr == null || typeof(isErr) == "undefined")
			isErr = true;
		
		
		var url = "/Pages/application/GeneralPages/JSErrService.aspx";
		var errHref = '';
		if(withHref)
		{
			errHref = location.href;
		}
		var params = "e="+exp + "&iserr=" + isErr.toString() + "&eH=" + errHref;
		/*if (Constants.mode == "debug")
			alert(exp)
		else -- YUVAL*/
			AJAX.asyncWithCallback(url, params, "", true, false) ;
			
	}
}

/******* END New function for Ajax *********/

//added by linoy
function GoToPage(url) {
 
    location.href=url;
}