
// Get client size
function getClientSize() {
	var w = 0;
	var h = 0;

	if (!window.innerWidth) {
		if (!(document.documentElement.clientWidth == 0)) {
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
		} else {
			w = document.body.clientWidth;
			h = document.body.clientHeight;
		}
	} else {
		w = window.innerWidth;
		h = window.innerHeight;
	}

	return {"width": w, "height": h};
}

// Change user's face after load from face plugin
function changeFaceImage() {
	var obj_image = document.getElementById("social_avatar_image");
	var rand = Math.round(Math.random() * 100);
	if (obj_image.src.match(/(\?\d+)$/))
		obj_image.src = obj_image.src.replace(/\d+$/, rand);
	else
		obj_image.src = obj_image.src + "?" + rand;
}

function sendLs(userId) {
    window.open("http://ls.meta.ua/reply.php?user_id="+userId,null,"top=200, left=300, height=485,width=600,status=no,toolbar=no,menubar=no,location=no");
}

function htmlSpecialChars(string, quote_style) {
	string = string.toString();
	
	// Always encode
	string = string.replace(/&/g, '&amp;');
	string = string.replace(/</g, '&lt;');
	string = string.replace(/>/g, '&gt;');
	
	// Encode depending on quote_style
	if (quote_style == 'ENT_QUOTES') {
		string = string.replace(/"/g, '&quot;');
		string = string.replace(/'/g, '&#039;');
	} else if (quote_style != 'ENT_NOQUOTES') {
		// All other cases (ENT_COMPAT, default, but not ENT_NOQUOTES)
		string = string.replace(/"/g, '&quot;');
	}
	
	return string;
}

function htmlSpecialCharsDecode(string, quote_style) {
	string = string.toString();
	
	// Always encode
	string = string.replace(/&amp;/g, '&');
	string = string.replace(/&lt;/g, '<');
	string = string.replace(/&gt;/g, '>');
	
	// Encode depending on quote_style
	if (quote_style == 'ENT_QUOTES') {
		string = string.replace(/&quot;/g, '"');
		string = string.replace(/&#039;/g, '\'');
	} else if (quote_style != 'ENT_NOQUOTES') {
		// All other cases (ENT_COMPAT, default, but not ENT_NOQUOTES)
		string = string.replace(/&quot;/g, '"');
	}
	
	return string;
}

var current_last_chars_content = new Array();
var current_last_chars_length = new Array();

function countLastChars(text_object, counter_object, limit) {
	var text_object_content = text_object.val();
	var text_object_length = text_object_content.length;

	if (text_object_length <= limit) {
		current_last_chars_content[text_object] = text_object_content;
		current_last_chars_length[counter_object] = text_object_length;
	} else {
		text_object.val(current_last_chars_content[text_object]);
	}

	counter_object.text(limit - current_last_chars_length[counter_object]);

	return true;
}

// Resize boxes of community info
function resizeCommunityBox(id){
	var div = document.getElementById(id);

	if (div.offsetWidth < 400) {
		div.style.width = "100%"
		var needle_block = div.getElementsByTagName("div")[0];
		needle_block.style.margin = "0px 0px 4px 0px";
	}

	if (div.offsetWidth > 810) {
		div.style.width = (navigator.appName == "Microsoft Internet Explorer" ? "49.9%":"50%");
		var left_table = document.getElementById("margin-left");
		left_table.style.margin = "0px 0px 0px 4px";
	}
}