/************************************************************************************************************
(C) www.dhtmlgoodies.com, March 2006

This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.

Terms of use:
You are free to use this script as long as the copyright message is kept intact. However, you may not
redistribute, sell or repost it without our permission.

Thank you!

www.dhtmlgoodies.com
Alf Magne Kalleland

************************************************************************************************************/

var enableCache = true;
var jsCache = new Array();


var dynamicContent_ajaxObjects = new Array();

function ajax_showContent(divId,ajaxIndex,url)
{
	document.getElementById(divId).innerHTML = dynamicContent_ajaxObjects[ajaxIndex].response;
	if(enableCache){
		jsCache[url] = 	dynamicContent_ajaxObjects[ajaxIndex].response;
	}
	dynamicContent_ajaxObjects[ajaxIndex] = false;
}
function ajax_show_msg() {
   obj=document.getElementById("ajax_loading");
   if(obj) obj.innerHTML="<div id=\"ajax_hp_note\" style=\"position:fixed;z-index:2;bottom:0;right:0;width:20em;margin:1em;padding: 7px 5px 7px 10px;font:12px/1.2em Lucida Console,Courier New,monospace;text-align:left;color:#111;background-color:#FFFFB4;border:1px solid #111;\">Идёт загрузка данных... <a href=\"javascript: document.getElementById('ajax_hp_note').style.display='none';\">X</a></div>";
}
function ajax_hide_msg() {
	obj=document.getElementById("ajax_loading");
	if(obj) obj.innerHTML="";
}
function ajax_loadContent(divId,url,no_msg)
{
	if(enableCache && jsCache[url]){
		document.getElementById(divId).innerHTML = jsCache[url];
		return;
	}

	var ajaxIndex = dynamicContent_ajaxObjects.length;
	if (no_msg!=1) ajax_show_msg();

	dynamicContent_ajaxObjects[ajaxIndex] = new sack();
	dynamicContent_ajaxObjects[ajaxIndex].requestFile = url;	// Specifying which file to get
	dynamicContent_ajaxObjects[ajaxIndex].onCompletion = function(){ ajax_showContent(divId,ajaxIndex,url); };	// Specify function that will be executed after file has been found
	dynamicContent_ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function
}

String.prototype.urlencode = function()
{
    var ret = '';
    var chr = '';
    var chr_from=Array('%','\'','"','&','=','?');
    var chr_to=  Array('%25','%27','%22','%26','%3D','%3F');
    for (i=0; i<this.length; i++)
    {
        chr=this.substring(i,i+1);
        var skip=0;
        for(var j=0;j<chr_from.length;j++) {
           if(chr_from[j]==chr) {
           	  ret=ret+chr_to[j];
           	  skip=1;
           	  break;
	        }
	     }
	     if(skip==0) {
	        ret=ret+chr;
	     }
    }
    return ret;
}
