﻿/* 
    JBC is short for Javascript Base Components 
    JBC is created by binary(dai.pf) at 2008.03.27
    Email:  dzcouple@gmail.com
    MSN:    dz999n999@hotmail.com
    TM/OICQ:380430030
    All right reversed, Any modification and use must be permitted by author
*/
var $w = window;
var $d = document;
var $l = location;
function $i(s){return "string" == typeof s? $d.getElementById(s) : s;}
function $t(s){return $d.getElementsByTagName(s);}
function $n(s){return $d.getElementsByName(s);}

String.prototype.trim= function()  
{
    return this.replace(/(^\s*)|(\s*$)/g, "");  
}

String.prototype.replaceall = function(source,destination)
{
    return this.replace(new RegExp(source,"gm"),destination);
}


String.prototype.bytescount = function()
{
	txt = this.replace(/(<.*?>)/ig,'');
	txt = txt.replace(/([\u0391-\uFFE5])/ig, 'dz');
	var count = txt.length;
	return count;
}

Date.prototype.format   =   function(format)
{   
      var   o   =   {   
          "M+"   :   this.getMonth()+1,   //month   
          "d+"   :   this.getDate(),         //day   
          "h+"   :   this.getHours(),       //hour   
          "m+"   :   this.getMinutes(),   //minute   
          "s+"   :   this.getSeconds(),   //second   
          "q+"   :   Math.floor((this.getMonth()+3)/3),     //quarter   
          "S"   :   this.getMilliseconds()   //millisecond   
      }   
      if(/(y+)/.test(format))   format=format.replace(RegExp.$1,   
          (this.getFullYear()+"").substr(4   -   RegExp.$1.length));   
      for(var   k   in   o)if(new   RegExp("("+   k   +")").test(format))   
          format   =   format.replace(RegExp.$1,   
              RegExp.$1.length==1   ?   o[k]   :     
                  ("00"+   o[k]).substr((""+   o[k]).length));   
      return   format;
}

Array.prototype.indexOf=function(obj){
  var result=-1;
  for (var i=0;i<this.length;i++){
    if (this[i]==obj){
      result=i;
      break;
    }
  }
  return result;
}

Array.prototype.contains=function(obj){
  return (this.indexOf(obj)>=0);
}

function Hashtable()
{
     this._hash = new Object();
     this.add = function(key,value)
     {
          if(typeof(key)!="undefined")
          {
               if(this.contains(key)==false)
               {
                    this._hash[key]=typeof(value)=="undefined"?null:value;
                    return true;
               }
               else
               {
                    return false;
               }
          }
          else 
          {
               return false;
          }
     }
     this.remove = function(key){delete this._hash[key];}
     this.count = function(){var i=0;for(var k in this._hash){i++;} return i;}
     this.items = function(key){return this._hash[key];}
     this.contains = function(key){ return typeof(this._hash[key])!="undefined";}
     this.clear = function(){for(var k in this._hash){delete this._hash[k];}}
}

function XmlHttpEx()
{
	this.xmlhttp = Utils.CreateXmlHttp();
	this.context = null;
	this.callback = null;
	var self = this;
	this.xmlhttp.onreadystatechange = function()
	{
	    if (self.xmlhttp.readyState == 4 && (self.xmlhttp.status==200 || window.location.href.indexOf("http")==-1))
        {
            if(self.context.type != "css" && self.context.type != "js")
            		self.context.uri = self.xmlhttp.responseXML;
            else
                self.context.uri = self.xmlhttp.responseText;
                        
		    if(self.callback && typeof self.callback == "function")
		    {
			    self.callback(self.context);
		    }
		}
	}
	
	this.exec = function()
	{
	    if(this.context && typeof this.context != "undefined")
	    {
	        this.xmlhttp.open("GET",this.context.uri,true);
            this.xmlhttp.send(null);
        }
	}
}

/*      Start of Cookie Manager      */
function CookieManager()
{
    this.Set = function(name,value,days)
	{
		if(days)
		{
	  	    var exp  = new Date(); 
	  	    exp.setTime(exp.getTime() + days*24*60*60*1000);
	  	    document.cookie = name + "="+ escape(value) +";expires="+ exp.toGMTString();
		}else{
			document.cookie = name + "="+ escape(value);
		}
	};
	
	this.Get = function(name)
	{
        var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
        if(arr != null && arr.length>2) return unescape(arr[2]); return null;
	};
	
	this.Del = function(name)
	{
        var exp = new Date();
        exp.setTime(exp.getTime() - 1);
        var cval=getCookie(name);
        if(cval!=null) document.cookie=name +"="+cval+";expires="+exp.toGMTString();
	};
}

var cookie = new CookieManager();
