function ssipc() {};

ssipc.cookie = {};

ssipc.cookie.get = function(name) {
	var cookies = [];
	var cookie = document.cookie;
	var i = 0;
	while (i >= 0 && i < cookie.length) {
		j = cookie.indexOf("=", i);
		if (j < 0) { break; }
		var n = cookie.substring(i, j);
		i = cookie.indexOf(";", j);
		j++;
		if (i > 0) {
			var value = cookie.substring(j, i);
			i += 2;
		}
		else {
			var value = cookie.substr(j);
		}
		cookies[n] = value;
	}
	return cookies[name];
};

ssipc.cookie.unset = function(name) {
	ssipc.cookie.set({ name: name, value: '.', expires: new Date() });
};

ssipc.cookie.set = function(params) {
	if (arguments.length > 1) {
		params = {
			name: arguments[0],
			value: arguments[1],
			expires: arguments[2],
			path: arguments[3],
			domain: arguments[4]
		};
	}
	var s = params.name + '=' + escape(params.value);
	if (params.expires) {
		 s += '; expires=' + params.expires.toGMTString();
	}

	if (params.domain) {
		s += '; domain=' + params.domain;
	}

	if (params.path) {
		s += '; path=' + params.path;
	}
	else {
		s += '; path=/';
	}

	document.cookie = s;
};

ssipc.date = function(format, t) {
	var date = new Date();
	if (t instanceof Date) {
		date = t;
	}
	else if (typeof t == 'number') {
		date.setTime(t * 1000);
	}
	var str = format;
	var Y = date.getFullYear();
	var m = date.getMonth() + 1;
	var d = date.getDate();
	var H = date.getHours();
	var i = date.getMinutes();
	var s = date.getSeconds();
	str = str.replace("Y", Y);
	str = str.replace("m", m >= 10 ? m : "0" +  m);
	str = str.replace("d", d >= 10 ? d : "0" +  d);
	str = str.replace("H", H >= 10 ? H : "0" +  H);
	str = str.replace("i", i >= 10 ? i : "0" +  i);
	str = str.replace("s", s >= 10 ? s : "0" +  s);
	return str;
};

ssipc.date.extract = function(str) {
	if (str.search(/(\d{4})年(\d{1,2})月(\d{1,2})日/) >= 0) {
		return new Date(RegExp.$1, RegExp.$2 - 1, RegExp.$3);
	}
	return null;
};

ssipc.array = {};
ssipc.array.bein = function(item, arr) {
	var exists = false;
	for (var i = 0; i < arr.length; i++) {
		if (item == arr[i]) {
			exists = true;
			break;
		}
	}
	return exists;
};

ssipc.array.keys = function(arr) {
	var keys = [];
	for (var i in arr) {
		keys.push(i);
	}
	return keys;
}

ssipc.array.unique = function(arr) {
	var newarr = [];
	for (var i in arr) {
		newarr[arr[i]] = 1;
	}
	return ssipc.array.keys(newarr);
};

ssipc.url = function() {};
ssipc.url.parse = function(url) {
	if (!url) { url = window.location.href; }
	var re = /^\s*(\w+):\/\/([^\/:]+)(:(\d+))?([^?#]*)?(\?([^#]*))?(#(.*))?\s*$/;
	var info = null;
	if (re.exec(url)) {
		info = {
			protocal : RegExp.$1,
			host     : RegExp.$2.concat(RegExp.$3),
			hostname : RegExp.$2,
			port     : RegExp.$4,
			pathname : RegExp.$5,
			search   : RegExp.$7,
			hash     : RegExp.$9
			};
	}
	else {
		re = /^([^?#]*)?(\?([^#]*))?(#(.*))?$/;
		if (re.exec(url)) {
			info = {
				protocal : ssipc.string.trim.right(window.location.protocol, ':'),
				host     : window.location.host,
				hostname : window.location.hostname,
				port     : window.location.port,
				pathname : RegExp.$1,
				search   : RegExp.$3,
				hash     : RegExp.$5
				};
		}
	}
	return info;
};

ssipc.string = function() {};
ssipc.string.trim = function(str, chars) {
	str = ssipc.string.trim.left(str, chars);
	str = ssipc.string.trim.right(str, chars);
	return str;
};

ssipc.string.trim.left = function(str, chars) {
	if (typeof chars == 'undefined') {
		chars = ' 	';
	}
	var c = str.charAt(0);
	while (c && chars.indexOf(c) >= 0) {
		str = str.substr(1);
		c = str.charAt(0);
	}
	return str;
};

ssipc.string.trim.right = function(str, chars) {
	if (typeof chars == 'undefined') {
		chars = ' 	';
	}
	var e = str.length - 1;
	while (e >= 0 && chars.indexOf(str.charAt(e)) >= 0) {
		str = str.substr(0, e);
		e--;
	}
	return str;
};


