function redirect (url) {
	location.href = url;
}

function change_lang (lang) {
	href_add_params ("change_lang=" + lang);
}

function href_add_params (paramsStr) {
	var href = location.href;
	if (href.indexOf("?") > 0)
		href += "&" + paramsStr;
	else
		href += "?" + paramsStr;
	location.href = href;
}

function newClass(parent, prot) {
	var cls = prot.constructor ? prot.constructor : function() {};
	cls.prototype = prot;
	return cls;
}

function json(val) {
	var result = null;
	if (typeof(val) == "String") {
		result = eval('(' + val + ')');
	} else if (typeof(val) == "object" && val.responseText) {
		result = eval('(' + val.responseText + ')');
	} else {
		result = {};
	}
	return result;
}

function showErrors(result) {
	var errorsStr = "";
	for (var i = 0; i < result.errors.length; i++) {
		var text = result.errors[i].message;
		if (!text)
			text = result.errors[i].id;
		errorsStr += text + "\n";
	}	
	alert(errorsStr);
}

function showAjaxError(type, r) {
	var str = r ? r.statusText : ""; 
	alert("Ajax error: " + type + " - ");
}

function clearNode(node) {
   if(!node)
      return;
   var len = node.childNodes.length;
   for(var i = len -1 ; i >= 0; i--)
      node.removeChild(node.childNodes[i]);
}