function showLawInfo() {
	var pars = 'act=get_law_info';
	var search_node_Ajax = new Ajax.Request(ajax_path+'cms.php', {method: 'post', parameters: pars, onComplete: _showLawInfo});
}

function _showLawInfo(RequestFromServer) {
	if (RequestFromServer.responseText) {
		$('code_area').innerHTML = RequestFromServer.responseText;
		$('code_window').style.display = 'block';
		new xModalDialog('code_window',0);
		xModalDialog.instances['code_window'].show();
	}
}

function setNavigatorSize(size, nav) {
	var pars = 'act=setNavigatorSize&size='+size+'&nav='+nav;
	var search_node_Ajax = new Ajax.Request(ajax_path+'admin.php', {method: 'post', parameters: pars, onComplete: _setNavigatorSize});
}

function _setNavigatorSize() {
	this.location.reload();
}

function setNavigatorFilter(text, filter, nav) {
	var pars = 'act=setNavigatorFilter&text='+text+'&filter='+filter+'&nav='+nav;
	var search_node_Ajax = new Ajax.Request(ajax_path+'admin.php', {method: 'post', parameters: pars, onComplete: _setNavigatorFilter});	
}

function _setNavigatorFilter() {
	this.location.reload();
}

function showClientClassForm(id) {
	var pars = 'act=showClientClassForm&client_id='+id;
	var search_node_Ajax = new Ajax.Request(ajax_path+'admin.php', {method: 'post', parameters: pars, onComplete: _showClientClassForm});
}

function votePoll(poll_var_id) {
	var pars = 'act=vote_poll&poll_id=' + poll_var_id;
	var search_node_Ajax = new Ajax.Request(ajax_path+'poll.php', {method: 'post', parameters: pars, onComplete: _votePoll});
}

function _votePoll(response) {
	if (response.responseText) {
		obj = response.responseText.split('^##^');
		if (obj[0]) {
			$('poll_'+obj[0]).innerHTML = obj[1];
		}
	}
}

function getPollResults(poll_id) {
	var pars = 'act=get_results&poll_id=' + poll_id;
	var search_node_Ajax = new Ajax.Request(ajax_path+'poll.php', {method: 'post', parameters: pars, onComplete: _getPollResults});
}

function _getPollResults(response) {
	if (response.responseText) {
		obj = response.responseText.split('^##^');
		if (obj[0]) {
			$('poll_'+obj[0]).innerHTML = obj[1];
		}
	}
}

function _showClientClassForm(RequestFromServer) {
	if (RequestFromServer.responseText) {
		$('code_area').innerHTML = RequestFromServer.responseText;
		$('code_window').style.display = 'block';
		new xModalDialog('code_window',0);
		xModalDialog.instances['code_window'].show();
	}
}

function saveClientClass(client_id, class_id, checked) {
	var ch = checked?1:0;
	var pars = 'act=saveClientClass&client_id='+client_id+'&class_id='+class_id+'&status='+ch;
	var search_node_Ajax = new Ajax.Request(ajax_path+'admin.php', {method: 'post', parameters: pars, onComplete: _saveClientClass});
}

function _saveClientClass(response) {
	if (response.responseText) {
		obj = response.responseText.split('^##^');
		var container = $('client_class_ul_'+obj[1]);
		if (obj[0] == 1) {
				var new_element = document.createElement('li');
				new_element.innerHTML = obj[3];
				new_element.setAttribute('id','client_class_li_'+obj[2]);
				container.appendChild(new_element);
		}else {
			container.removeChild($('client_class_li_'+obj[2]));
		}
	}

}


function serialize( mixed_value ) {
	// %          note: We feel the main purpose of this function should be to ease the transport of data between php & js
	// %          note: Aiming for PHP-compatibility, we have to translate objects to arrays
	// *     example 1: serialize(['Kevin', 'van', 'Zonneveld']);
	// *     returns 1: 'a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}'
	// *     example 2: serialize({firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'});
	// *     returns 2: 'a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}'

	var _getType = function( inp ) {
		var type = typeof inp, match;
		var key;
		if (type == 'object' && !inp) {
			return 'null';
		}
		if (type == "object") {
			if (!inp.constructor) {
				return 'object';
			}
			var cons = inp.constructor.toString();
			if (match = cons.match(/(\w+)\(/)) {
				cons = match[1].toLowerCase();
			}
			var types = ["boolean", "number", "string", "array"];
			for (key in types) {
				if (cons == types[key]) {
					type = types[key];
					break;
				}
			}
		}
		return type;
	};
	var type = _getType(mixed_value);
	var val, ktype = '';

	switch (type) {
		case "function":
		val = "";
		break;
		case "undefined":
		val = "N";
		break;
		case "boolean":
		val = "b:" + (mixed_value ? "1" : "0");
		break;
		case "number":
		val = (Math.round(mixed_value) == mixed_value ? "i" : "d") + ":" + mixed_value;
		break;
		case "string":
		val = "s:" + mixed_value.length + ":\"" + mixed_value + "\"";
		break;
		case "array":
		case "object":
		val = "a";
		/*
		if (type == "object") {
		var objname = mixed_value.constructor.toString().match(/(\w+)\(\)/);
		if (objname == undefined) {
		return;
		}
		objname[1] = serialize(objname[1]);
		val = "O" + objname[1].substring(1, objname[1].length - 1);
		}
		*/
		var count = 0;
		var vals = "";
		var okey;
		var key;
		for (key in mixed_value) {
			ktype = _getType(mixed_value[key]);
			if (ktype == "function") {
				continue;
			}

			okey = (key.match(/^[0-9]+$/) ? parseInt(key) : key);
			vals += serialize(okey) +
			serialize(mixed_value[key]);
			count++;
		}
		val += ":" + count + ":{" + vals + "}";
		break;
	}
	if (type != "object" && type != "array") val += ";";
	return val;
}
function isValidURL(url){
	var tomatch = /http:\/\/[A-Za-z0-9\.-]{3,}\.[A-Za-z]{3}/

	//if (tomatch.test(url))

	return true;

	//return false;

}

function writeFlash(p) {
	writeEmbed(
	'D27CDB6E-AE6D-11cf-96B8-444553540000',
	'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0',
	'application/x-shockwave-flash',
	p
	);
}

function writeEmbed(cls, cb, mt, p) {
	var h = '', n;

	h += '<object classid="clsid:' + cls + '" codebase="' + cb + '"';
	h += typeof(p.id) != "undefined" ? 'id="' + p.id + '"' : '';
	h += typeof(p.name) != "undefined" ? 'name="' + p.name + '"' : '';
	h += typeof(p.width) != "undefined" ? 'width="' + p.width + '"' : '';
	h += typeof(p.height) != "undefined" ? 'height="' + p.height + '"' : '';
	h += typeof(p.align) != "undefined" ? 'align="' + p.align + '"' : '';
	h += '>';

	for (n in p)
	h += '<param name="' + n + '" value="' + p[n] + '">';

	h += '<embed type="' + mt + '"';

	for (n in p)
	h += n + '="' + p[n] + '" ';

	h += '></embed></object>';

	document.write(h);
}

function unserialize(data){
	// %            note: We feel the main purpose of this function should be to ease the transport of data between php & js
	// %            note: Aiming for PHP-compatibility, we have to translate objects to arrays
	// *       example 1: unserialize('a:3:{i:0;s:5:"Kevin";i:1;s:3:"van";i:2;s:9:"Zonneveld";}');
	// *       returns 1: ['Kevin', 'van', 'Zonneveld']
	// *       example 2: unserialize('a:3:{s:9:"firstName";s:5:"Kevin";s:7:"midName";s:3:"van";s:7:"surName";s:9:"Zonneveld";}');
	// *       returns 2: {firstName: 'Kevin', midName: 'van', surName: 'Zonneveld'}

	var error = function (type, msg, filename, line){throw new window[type](msg, filename, line);};
	var read_until = function (data, offset, stopchr){
		var buf = [];
		var chr = data.slice(offset, offset + 1);
		var i = 2;
		while (chr != stopchr) {
			if ((i+offset) > data.length) {
				error('Error', 'Invalid');
			}
			buf.push(chr);
			chr = data.slice(offset + (i - 1),offset + i);
			i += 1;
		}
		return [buf.length, buf.join('')];
	};
	var read_chrs = function (data, offset, length){
		var buf;

		buf = [];
		for(var i = 0;i < length;i++){
			var chr = data.slice(offset + (i - 1),offset + i);
			buf.push(chr);
		}
		return [buf.length, buf.join('')];
	};
	var _unserialize = function (data, offset){
		var readdata;
		var readData;
		var chrs = 0;
		var ccount;
		var stringlength;
		var keyandchrs;
		var keys;

		if(!offset) offset = 0;
		var dtype = (data.slice(offset, offset + 1)).toLowerCase();

		var dataoffset = offset + 2;
		var typeconvert = new Function('x', 'return x');

		switch(dtype){
			case "i":
			typeconvert = new Function('x', 'return parseInt(x)');
			readData = read_until(data, dataoffset, ';');
			chrs = readData[0];
			readdata = readData[1];
			dataoffset += chrs + 1;
			break;
			case "b":
			typeconvert = new Function('x', 'return (parseInt(x) == 1)');
			readData = read_until(data, dataoffset, ';');
			chrs = readData[0];
			readdata = readData[1];
			dataoffset += chrs + 1;
			break;
			case "d":
			typeconvert = new Function('x', 'return parseFloat(x)');
			readData = read_until(data, dataoffset, ';');
			chrs = readData[0];
			readdata = readData[1];
			dataoffset += chrs + 1;
			break;
			case "n":
			readdata = null;
			break;
			case "s":
			ccount = read_until(data, dataoffset, ':');
			chrs = ccount[0];
			stringlength = ccount[1];
			dataoffset += chrs + 2;

			readData = read_chrs(data, dataoffset+1, parseInt(stringlength));
			chrs = readData[0];
			readdata = readData[1];
			dataoffset += chrs + 2;
			if(chrs != parseInt(stringlength) && chrs != readdata.length){
				error('SyntaxError', 'String length mismatch');
			}
			break;
			case "a":
			readdata = {};

			keyandchrs = read_until(data, dataoffset, ':');
			chrs = keyandchrs[0];
			keys = keyandchrs[1];
			dataoffset += chrs + 2;

			for(var i = 0;i < parseInt(keys);i++){
				var kprops = _unserialize(data, dataoffset);
				var kchrs = kprops[1];
				var key = kprops[2];
				dataoffset += kchrs;

				var vprops = _unserialize(data, dataoffset);
				var vchrs = vprops[1];
				var value = vprops[2];
				dataoffset += vchrs;

				readdata[key] = value;
			}

			dataoffset += 1;
			break;
			default:
			error('SyntaxError', 'Unknown / Unhandled data type(s): ' + dtype);
			break;
		}
		return [dtype, dataoffset - offset, typeconvert(readdata)];
	};
	return _unserialize(data, 0)[2];
}