$(document).ready(function() {
	$('div#menu ul li').hover(
		function(e){
			$('#'+this.id+'Sub').show();
		}, 
		function(e){
			$('#'+this.id+'Sub').hide();
		}
	);

	$(':input').mouseover(function() {
		$('div#menu ul li ul').hide();
	});

	$('#button_login').bind('click', function() {	
			$('div#loginbar').slideToggle('fast');
			$('#loginUsername').focus();
	});

	$('#hide_login').bind('click', function() {	
		$('div#loginbar').slideUp('fast');
	});

	$('#button_close_header_ad').bind('click', function() {	
		var number = $(this).attr('alt');
		$(this).parent().hide();
		SetCookie('ad_'+number, 1, 365);
	}).css('cursor','pointer');
	
	$('#button_close_forum_input_information').bind('click', function() {
		var number = $(this).attr('rel');
		$(this).parent().hide();
		SetCookie('ad_'+number, 1, 365);
	}).css('cursor','pointer');
});

function insertcode(myValue, field) 
{
	myField = document.getElementById(field);
	//IE support
	if (document.selection) {
		myField.focus();
		sel = document.selection.createRange();
		sel.text = myValue;
	} else if (myField.selectionStart || myField.selectionStart == '0') {
		var startPos = myField.selectionStart;
		var endPos = myField.selectionEnd;
		myField.value = myField.value.substring(0, startPos)
		+ myValue
		+ myField.value.substring(endPos, myField.value.length);
	} else {
			myField.value += myValue;
	}
}

function SetCookie(cookieName, cookieValue, nDays)
{
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"a="+escape(cookieValue)+";expires="+ expire.toGMTString() + ";path=/";
}

function ReadCookie(cookieName) 
{
	cookieName = cookieName + "a";
	var theCookie = "" + document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return ""; 
	var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length; ;
	return unescape(theCookie.substring(ind+cookieName.length + 1,ind1));
}

function OpenWindow(object)
{
    return !window.open(object.href, 'windowOpen', 'scrollbars=1,menubar=0,resizable=1,location=0,status=0,toolbar=0');
}
