function parseGetData(string){
   var aPairs = string.split("&");
   var aRes = new Array();
   var tmpPair = new Array();

   for (key in aPairs){
      if (aPairs[key] != ''){
         tmpPair = aPairs[key].split("=");
         aRes[tmpPair[0]] = tmpPair[1];
      }
   }

   return aRes;
}

function showElement(sElemId){
   var iYCoord=200;
   document.getElementById(sElemId).style.visibility = 'hidden';
   document.getElementById(sElemId).style.display = "block";
   document.getElementById(sElemId).style.left = ((document.body.clientWidth - document.getElementById(sElemId).offsetWidth)/2)+"px";
   document.getElementById(sElemId).style.visibility = 'visible';

   if (navigator.appName == "Microsoft Internet Explorer") {
      document.getElementById(sElemId).style.top = (document.documentElement.scrollTop+iYCoord)+"px";
   } else {
      document.getElementById(sElemId).style.top = (window.pageYOffset+iYCoord)+"px";
   }
}
function hideElement(sElemId){
   document.getElementById(sElemId).style.display = "none";
}

function showMessage(sText, iTimeout, sElemId) {
   if (!sElemId) { sElemId='ajax_message'; }
   if (!iTimeout && iTimeout !== 0) { iTimeout=2000; }
   document.getElementById(sElemId).innerHTML=sText;

   showElement(sElemId);

   if (iTimeout){
      setTimeout('hideMessage("'+sElemId+'")',iTimeout);
   }
}
function hideMessage(sElemId) {
   if (!sElemId) { sElemId='ajax_message'; }
   hideElement(sElemId);
}

function showPreloadPic(sElemId) {
   if (!sElemId) { sElemId='preloadPic'; }

   showElement(sElemId);

}
function hidePreloadPic(sElemId) {
   if (!sElemId) { sElemId='preloadPic'; }
   hideElement(sElemId);
}
function elemVis(elem_id,vis){
   if (document.getElementById(elem_id)){
      if (!vis) { vis='visible'; }
      document.getElementById(elem_id).style.visibility=vis;
   }
}

function toJSON (x){
   if (x == null)
      return null;

   if(typeof x != "object"){
      return '"'+x.toString().replace(/\"/gi,'\\\"')+'"';
   }

   var s = [];
   for (var i in x) s.push ('"'+i+'":'+toJSON(x[i]));
   return "{"+s.join (',')+"}";
}

function char_ajaxFillDiv(func,div_name,aFuncParams,aParams){
   if (!typeof(aParams) || typeof(aParams) == 'undefined'){
      aParams = new Array();
      aParams['script'] = '';
   }


   var decolorize_div_name = (aParams['decolorize_div_name'] != null) ? aParams['decolorize_div_name'] : div_name;

   if (decolorize_div_name != ''){
      aParams['script'] += '$("#'+decolorize_div_name+'").animate({opacity: 1},50);';
   }
   //     		aParams['script'] += '$("#'+div_name+'").css("opacity",1);';

   try {
      $("#"+decolorize_div_name).animate({opacity: 0.4},200);
   } catch (e) { }

   xajax_char_fillDiv(func, div_name, aFuncParams, aParams);

   if (decolorize_div_name != ''){
      $("#"+decolorize_div_name).attr("opacity",1);
   }
}

function char_addToOnload(fn){
   //      	alert(fn);
   try{
      if (!window.aSiteOnload){
         window.aSiteOnload = new Array();
      }
   } catch (e) {
      window.aSiteOnload = new Array();
   }
   iLen = window.aSiteOnload.length;
   window.aSiteOnload[iLen] = fn;
}

function char_executeOnload(){
   try {
      if (window.aSiteOnload && window.aSiteOnload.length > 0){
         for (key in window.aSiteOnload){
            //               	alert("!!" + window.aSiteOnload[key]);
            window.aSiteOnload[key]();
         }
      }
   } catch(e) {}
}

function char_delItem(iId){
   sCode = ""
   + "<form id='tmp_char_del_form' method=post>"
   + "	<input type=hidden name=_ai_mode value='del_item'>"
   + "	<input type=hidden name=item_id value='" + iId + "'>"
   + "</form>";
   jQuery("body").append(sCode);
   jQuery("#tmp_char_del_form").submit();
}

function char_getDocumentWidth(){
   var de = document.documentElement;
   var w = self.innerWidth || (de&&de.clientWidth) || document.body.clientWidth;
   return w;
}


//-- jquery extensions

jQuery.extend({
   count: function (arrayA) {
      cnt = 0;
      for (key in arrayA){ 
         cnt++; 
      }
      return cnt;
   }
});

jQuery.extend({
   compareObj: function (arrayA, arrayB) {
      if (jQuery.count(arrayA) != jQuery.count(arrayB)) { return false; }

      for (key in arrayA) {
         //alert(key + ": a=" + arrayA[key] + " b=" + arrayB[key]);
         if (arrayA[key] !== arrayB[key]) { 
            return false;
         }
      }

      /*
      * Нужно проверять и для второго массива тоже, т.к. если, например, будет такая ссылка:
      * http://site.com?sdf#param=value
      * то первый цикл не вернет false, т.к. arrayA.sdf == undefined, arrayB.sdf == undefined.
      * Нужно проверять для второго цикла тоже.
      */

      for (key in arrayB) {
         //alert(key + ": a=" + arrayA[key] + " b=" + arrayB[key]);
         if (arrayA[key] !== arrayB[key]) { 
            return false;
         }
      }

      return true;
   }
});



