/***************************************************************************                                                                                                       
 *   Copyright (C) 2009 by Vitaly Gnidenko                                 *                                                                                                       
 *   lart@rambler.ru                                                       *                                                                                                       
 ***************************************************************************/  
/*$Id: core.js 72 2009-02-25 01:26:21Z root $*/

Object.extend = function(destination, source) {
  for (var property in source)
    destination[property] = source[property];
  return destination;
};

function clearInner(obj){
	while(obj.firstChild){
		obj.removeChild(obj.firstChild);
	}
}

function cr(name){
		return document.createElement(name);
	}

function setCookie(value, parameters) {
    document.cookie= parameters[0] + "=" + escape(value) +
      ((parameters[1]) ? "; expires=" + parameters[1].toGMTString() : "") +
      ((parameters[2]) ? "; path=" + parameters[2] : "") +
      ((parameters[3]) ? "; domain=" + parameters[3] : "") +
      ((parameters[4]) ? "; secure" : "");
  };

	function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
      begin = dc.indexOf(prefix);
      if (begin != 0) return null;
    } else {
      begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
      end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
  }

	
	// Array Remove - By John Resig (MIT Licensed)
	/*
	 * // Remove the second item from the array
	array.remove(1);
	// Remove the second-to-last item from the array
	array.remove(-2);
	// Remove the second and third items from the array
	array.remove(1,2);
	// Remove the last and second-to-last items from the array
	array.remove(-2,-1);
	 * 
	 */
	Array.prototype.remove = function(from, to) {
	  var rest = this.slice((to || from) + 1 || this.length);
	  this.length = from < 0 ? this.length + from : from;
	  return this.push.apply(this, rest);
	};

	Array.prototype.search =function(val) {
			for (var i = 0; i < this.length; i++) {
				if (typeof(this[i])=='object'&&(this[i] instanceof Array)){
					var ret=this.search(this[i],val);
					if (ret!==false)return ret;
				}else
					if (this[i] == val) {
						return i;
					}
			}
			return false;
	};

	Array.prototype.map=function(callback,scope){
		for(var i=0;i<this.length;i++){
			if (scope)
				this[i]=callback.apply(scope,new Array(this[i]));
			else
				this[i]=callback(this[i]);
		}
		return this;
	};	

	function extractScripts(src) {
			var scriptExp='<script[^>]*>([\\S\\s]*?)<\/script>';
		    var matchAll = new RegExp(scriptExp, 'img');
		    var matchOne = new RegExp(scriptExp, 'im');
		    var t=((src.match(matchAll) || []).map(function(scriptTag) {
		      return (scriptTag.match(matchOne) || ['', ''])[1];
		    }));
		    return t;
  	}
  	function addToLocation(text){
  		var l=window.location.href;
  		var href=l.replace(/#.*/,'');
  		window.location.href=href+text;
  	}
  	function getFromLocation(){
  		var l=window.location.href;
  		var href=l.match(/#(.*)\//);
  		if (href!=null)
  			return href[1];
  		else
  			return '';
  	}
  	
function trim(string)
{
return string.replace(/(^\s+)|(\s+$)/g, "");
}
  	
  	
  	var Url = {
 
	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},
 
	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},
 
	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";
 
		for (var n = 0; n < string.length; n++) {
 
			var c = string.charCodeAt(n);
 
			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}
 
		}
 
		return utftext;
	},
 
	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;
 
		while ( i < utftext.length ) {
 
			c = utftext.charCodeAt(i);
 
			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}
 
		}
 
		return string;
	}
 
}
  	