
function jsonRequest(method,args,resultHandler,exceptionHandler) {
   
    
    args.method = method;
    
    var ajax = new Ajax.Request(
        '/services/json',
        {
            method: 'post',
            parameters: args,
            onComplete: function(transport) {

                data = eval("(" + transport.responseText + ")");
                if (data["status"]) {

                    resultHandler(data["result"]);

                } else {

    				if (exceptionHandler) {
    					exceptionHandler(data);
    				} else {
    					alert('Uncaught exception: ' + data["result"]);
    				}

                }
                
            }
        });

}

function SWFEmbed(location,width,height,flashvars,clss,id,embedSession, allowScriptAccess) {

    if (embedSession) {

    	if (!flashvars) flashvars = $H();
    	flashvars.SABRE_ID = Cookies.getCookie(sessionCookieName);

    }

	if(allowScriptAccess) allowScriptAttribute = 'allowScriptAccess="' + allowScriptAccess + '"';
	else allowScriptAttribute = ' ';

    var data= '<object ' + allowScriptAttribute + ' type="application/x-shockwave-flash" data="' + location + '" class="' + clss + '" id="' + id + '" style="width: ' + width + 'px; height: ' + height + 'px;"';
    if (id) data+='id="' + id + '"'
    data+='>\n';
    data+='  <param name="movie" value="' + location + '" />\n';
    data+='  <param name="wmode" value="transparent" />\n';
    data+='  <param name="allowFullScreen" value="true" />\n';
	if(allowScriptAccess) data+= ' <param name="allowScriptAccess" value="' + allowScriptAccess + '" />\n';


    var qs = flashvars.toQueryString();

    if (flashvars) {
    	data+= '  <param name="FlashVars" value="' + qs + '" />\n';

    }

    data+= '</object>';

    return data;


}

String.prototype.reverse = function() {
    var s = "";
    var i = this.length;
    while (i>0) {
        s += this.substring(i-1,i);
        i--;
    }
    return s;
}

function getBytes(no,format) {

    if (!format) format = 1;
    switch(format) {

    	case 1 :
    		var formats = [ 'bytes', 'KB', 'MB', 'GB', 'TB' ];
    		break;
    	case 2 :
    		var formats = [ 'bytes', 'KB', 'Megs', 'Gigs', 'TB' ];
    		break;

    }
    		
    var i = 0;
    while(no > 1024) {
    	i++;
    	no /= 1024;
    }

    return no.round() + ' ' + formats[i];

}

function documentWrite(str) {

    document.write(str);

}

// prototype fallback functions

if ( typeof toQueryString != 'function' )
{
    Array.prototype.toQueryString = function() {

        var oHashFromH = this;

        var sQueryString = "";

        for ( var sKey in oHashFromH )
        {
            if ( typeof oHashFromH[sKey] != "function" )
            {
                var sValue = oHashFromH[sKey];
                sQueryString += sKey + "=" + sValue + "&";
            }
        }

        var iTrimSpot = sQueryString.lastIndexOf('&'); 
        sQueryString = sQueryString.substring(0, iTrimSpot);

        return sQueryString;
    }
}

if ( typeof $H != 'function' )
{
    function $H(oRawHash) {
        
        var aProcessedHash = new Array();

        for ( var sKey in oRawHash )
        {
            if ( typeof oRawHash[sKey] != "function" )
            {
                var sValue = oRawHash[sKey] || "undefined";
                aProcessedHash[sKey] = encodeURIComponent(sValue);
            }
        }
        return aProcessedHash;
    }
}

// creating fake firebug console thing
if (!console) { 
    var console = {
    	log : function() { }
    }
}

var fm={};

fm.loadedModules = [];

fm.loader = function(filename,onLoaded,noCheck) {

    if (!noCheck) for(var i=0;i<fm.loadedModules.length;i++) {

    	if (fm.loadedModules[i]==filename) {
    		if (onLoaded) onLoaded(filename);
    		return false;
    	}

    }

    fm.loadedModules.push(filename);

    var request = new Ajax.Request(filename, {
    	method: 'get',
    	onComplete: function(data) {
    		eval(data.responseText);
    		console.log('Loaded library: ' + filename);
    		if (onLoaded) onLoaded(filename);
    	}
    });	
    return true;

}

