function htmlEncode(text) {return $('<div/>').text(text).html();}
function htmlDecode(text) {return $('<div/>').html(text).text();}

function getClientWidth() {
	return document.compatMode=='CSS1Compat' && !window.opera ? document.documentElement.clientWidth : document.body.clientWidth;
}

function setSize() {
	var w = getClientWidth();
	var pad = 0;
	if (w >= 980) {
		pad = (w - 980)/2;
		w = 980;
	} else {
		w = w - 10;
		pad = 5;
	}
	$('#home, #settings, #send, #accountin, #about, #sentmessages, #feedback')
		.add('#createGroup, #createBrand, #account, .sent_messages, .sizet, .MasterPanel')
		.add('#homepage, #agree, #login, #register, #pwdReset, #planPanel, #planDescription')
		.width(w + 'px').css('margin-left', pad + 'px').css('margin-right', pad + 'px');
}

function clear_input(){
	$('#upload_area').text('no image selected');
	$('#send select[name=brandId]').attr('disabled', false);
	$.post('session_clear.php', {clear:'yes'});
}

function textCounter(a, b, c) {
	if (a.value.length > c) {
		a.value = a.value.substring(0, c);
	} else {
		b.value = a.value.length;
	}
}
function toggle(e) {e.checked = !(e.checked)}
function toggle_child(e) {toggle(e.firstChild)}

//For iOS
window.launchPhotoPicker = function() {
	setTimeout(function() {
		window.location = 'http://www.yourcompanyname.com/instruction-to-install-app.html'
	}, 500);

	window.location = 'photopicker://?source=camera&context=yourdatahere';
};

$(document).ready(function () {
	setSize();
	$('a.language-link').click(function (e) {
		e.preventDefault();
		window.location = $(this).attr('href');
		return false;
	});
});
