var allow_keyboard_control = true;
var disable_comments = false;

function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function removeCookie(name) {
	createCookie(name,"",-1);
}

  
function addEmoticon(emo) {
	if (disable_comments) return;
	$('.post_comm').val($('.post_comm').val()+emo);
	$('.post_comm').focus();
	 
}   

function addEmoticon_to_field(emo, field) {
	$('#'+field).val($('#'+field).val()+emo);
	$('#'+field).focus();
	 
}   

function addEmoticon_to_tmce(emo) {
	text = emo;
 	tinyMCE.execCommand('mceInsertContent', false, '');// focus hack;
 	tinyMCE.execCommand('mceInsertContent', false, text);	 
}   

function returnEmos(arr, type, arr2, width) {
	emoticons = '';
	for ( i=0; i<arr.length; i++ ) {
		 
		emoticons +="<a href='javascript:;' onclick='AddEmo(\""+arr2[i]+"\", "+type+")'><img src='/images/emov3/"+arr[i]+"' border='0'  /></a>";
	}
	
	return emoticons;
}

function hideName(id){
	document.getElementById("usr["+id+"]").style.display = 'none';
}
function showName(id){
	document.getElementById("usr["+id+"]").style.display = '';
}


/**
*	Function to check a group of checkboxes
*
*	@param string formElement - Target form name
*	@param boolean checkState - True/false for checked state
**/
function checkAll(formElement, checkState) {
	if (typeof document.forms[formElement] != 'undefined') {
		var myForm = document.forms[formElement];
		for (i=0; i < myForm.elements.length; i++) {
			if (myForm.elements[i].type == 'checkbox') {
				myForm.elements[i].checked = checkState;
			}
		}
	}else{
		alert("Invalid form element provided!");
	}
}

function showPanel(obj) {
	var el = document.getElementById(obj);
	el.style.display = el.style.display ? '':'none';
}


function submitParentForm(elem, elemname, value) {
	if (typeof elem.parentNode != 'undefined') {
		if (elem.parentNode.tagName == 'FORM') {
			if (typeof elemname != 'undefined') { //we need to create an element and append it
				var input 	= document.createElement('INPUT');
				input.type 	= 'hidden';
				input.name 	= elemname;
				input.value = (typeof value != 'undefined') ? value : elemname;

				elem.parentNode.appendChild(input);
				//appendToLog("");
			}

			if (elem.parentNode.submit()) {
				//
			}
		}else{
			submitParentForm(elem.parentNode, elemname, value);
		}
	}
}


function addToFriend(obj, id) {
	obj.src = '/images/icons/addfriend_done.jpg';
	//exec_ajax('/friends/add_friend/'+id+'/ajax', 'GET');
	ajax_eval('/friends/add_friend/' + parseInt(id) + '/L2FqYXg=', null, 'fr_txt', 'GET');
}

function countMsgCharacters(obj,chars) {
	msg= obj.value;
	len = msg.length;
	if (len >chars){
		obj.value=msg.substr(0,charscount);
	}else{
		charscount=len;
	}

	document.getElementById('remaining_chars').innerHTML=chars-charscount;
}

function set_other_menu() {
	$("#more_menu").hover(
			function() { 
				$(this).removeClass('more_menu');
				$(this).addClass('more_ov');
				
			},
			function() { 
 				$(this).addClass('more_menu');
				$(this).removeClass('more_ov');
			}
		);
		
		
	$("#more_tab").hover(
			function() { 
				$(this).removeClass('more_menu');
				$(this).addClass('more_ov');
				
			},
			function() { 
 				$(this).addClass('more_menu');
				$(this).removeClass('more_ov');
			}
		);

}
 