var CURL_ID;
var uid = 0;
var grad = '';
var pol = '';
var god1 = 0;
var god2 = 0;
var uname = '';
var tuntoggle = 0;
var MSN;
var mi = 0;
var TIM = 0;
var mt = 0;
var nt = 0;
var nt2 = 0;
var info_var = 0;

$(document).ready(function(){
	cut_comments();
	getMessengerNotes();
	makeMenu();
	userMenu();
	$('#stattButt').click(function(){
		showLatestStats();
	});

	clickAway();


	//var twidth = $(document).width();
	var twidth = $('html').width();
	var ie_ver = 0;

	if (jQuery.browser.msie) {
		ie_ver = parseInt(jQuery.browser.version);
	}

	if(twidth > 1000){
		twidth = twidth - 60;

		if(ie_ver == 6 || ie_ver == 7){
			twidth = twidth - 6;
		}
		if(ie_ver == 8){
			twidth = twidth - 25;
		}
		if(ie_ver == 0){
		}

		$("#horizontal_menu_bar").css("left", "30px");
	}

	info_var = twidth;

	$("#horizontal_menu_bar").css("width", twidth+"px");

	showNotifications();
	showNotifications2();
	ajax_messenger_invitation();

	//hints for input boxes
	$('input[title!=""]').hint();

});

function clickAway(){
	$(".input_l").each(function(){
		var vall = $(this).attr('value');
		$(this).focus(function(){
			$(this).attr({ value: '' }); 
		}).blur(function(){
			if( $(this).attr('value') == '' ){
				$(this).attr({ value: vall });
			}
		});
	});
};

function trigg(obj){
	$('#menu-'+obj).slideDown("slow");
	mi = true;
};
function makeMenu(){
	$('#first_tier_navbar li').each(function(){
		$(this).hover(
			function(){
				var ie_ver = 0;
				mi = false;
				var pos = $(this).position();
				setAbsolutePosition('#menu-' + $(this).attr("id"), pos);
				var ob = $(this).attr("id");
				if(ob != 'undefined')
					TIM = setTimeout('trigg(\''+ob+'\');', 200);

			},
			function(){
				clearTimeout(TIM);
				if(mi == true){
					$('#menu-' + $(this).attr("id")).fadeOut("normal");
				}
			}
		);
		$(this).click(
			function(){
				$('#menu-' + $(this).attr("id")).fadeOut();
			}
		);
	});
	$('.myMenu a').each(function(){
		var b = $(this).css("border");
		$(this).hover(
			function(){
// 				$(this).css("border","3px ridge #000");
			},
			function(){
// 				$(this).css("border",b);
			}
		);
	});
};

function setAbsolutePosition(varname, pos){

	var pTop = parseInt(pos.top) + 1;
	var pLeft = parseInt(pos.left) - 4;

	var ie_ver = 0;

	if (jQuery.browser.msie) {
		ie_ver = parseInt(jQuery.browser.version);
	}
	if(ie_ver == 6){
		pTop = pTop + 20;
	}
	if(ie_ver == 7){
		pTop = pTop + 20;
		pLeft = pLeft - 130;
	}
	if(ie_ver == 8 || ie_ver == 0){
		pTop = pTop + 26;
		pLeft = pLeft + 4;
	}

	//var_width = parseInt( $( varname ).css("width") );
	var_width = 186;
	if(pLeft + var_width > 986){
		pLeft = pLeft - ( ( pLeft + var_width ) - 986 );
// 		$( varname ).css("left", newleft+'px');
	}

	$( varname ).css("top", pTop+'px');
	$( varname ).css("left", pLeft+'px');

};

function userMenu(){
	$('.user-menu').each(function(){
		$(this).click(function(){
			var pos = $(this).position();
			var pTop = parseInt(pos.top) + 19;
			var pLeft = parseInt(pos.left);
			var varname = '#um-'+ $(this).attr('rel');
			var ie_ver = 0;

			if( $(varname).css("display") == 'block' ){
				$(varname).css("display", "none");
				return;
			}

			$('.user-menu ul').each(function(){
				$(this).css("display", "none");
			});

			if (jQuery.browser.msie) {
				ie_ver = parseInt(jQuery.browser.version);
			}


			if(ie_ver == 6){
				pTop = pTop + 9;
			}
			if(ie_ver == 7){
				pTop = pTop + 5;
			}
			if(ie_ver == 8 || ie_ver == 0){
				pTop = pTop + 5;
				pLeft = pLeft + 4;
			}
			$( varname ).css("top", pTop+'px');
			$( varname ).css("left", pLeft+'px');
			$('#um-'+ $(this).attr('rel') + ' li a').each(function(){
				$(this).click(function(){
					location.href = $(this).attr("href");
				});
			});
			$( '#um-'+ $(this).attr('rel') ).fadeIn("normal");
		});
	});
}

function cut_comments(){
	setTimeout("delayed_cut();", 700);
};

function delayed_cut(){
	var bid = 0;
	$('.user_comment_div').each(function(){
		var c = 0;
		bid++;
		var h = $(this).height();
		if( h > 120 && h > 160 ){
			var button = '<a class="comment_reveal" id="b_' + bid + '" href="#">Toggle</a>';
			var obj = this;
			var memo = '<div class="c_memo" id="c_memo_'+bid+'">'+h+'</div>';
			$(obj).html( button + $(obj).html() + memo );
			$(obj).css("height", "120px");
			$('#b_'+bid).click(function(){
				c++;
				if(c % 2 == 0){
					animateUP(obj);
				} else {
					animateDOWN(h, obj);
				}
				return false;
			});
			$('.toggleAll').css("display", "block");
		}
	});
};

function toggleAll(){
	var c = tuntoggle;
	var bid = 0;
	c++;
	$('.user_comment_div').each(function(){
		bid++;
		var h = $(this).height();
		var memo = parseInt( $('#c_memo_' + bid).html(), 10);
		var obj = this;
		if( memo > 0 ){
			if(c % 2 == 0){
				$('.comment_reveal').css("display", "block");
				animateUP(obj);
			} else {
				$('.comment_reveal').css("display", "none");
				animateDOWN(memo, obj);
			}
		}
	});
	tuntoggle = c;
};

function animateDOWN(h, obj){
	var hg = h+'px';
	$(obj).animate({
		height: hg
	}, 500 );
};

function animateUP(obj){
	$(obj).animate({
		height: "120px"
		}, 500 );
};

/**
*DEPRECATED This function is not being used any more
*/function mood(){
	var old = $('#profile_status').html();
	var st = $('#mood').html();
	if(!st) st = '';
	$('#profile_status').html('<input id="moodInput" type="text" name="mood" value="" maxlength="100" /><input class="p_s_i" type="submit" value="Submit" onclick="moodSubmit(\'' + escape(old) + '\');" /><input class="p_s_i" type="submit" value="Cancel" onclick="moodCancel(\'' + escape(old) + '\');" />');
	$('#moodInput').val( st  );
};

/*
*DEPRECATED This function has never been used, it's here just for safekeep
*/
function moodSubmitOLD(old){
	var mood = $('#moodInput').val();
	response = $.ajax({
		url: "/ajax_user_mood.php",
		global: false,
		type: "POST",
		data: "mood="+mood,
		dataType: "html",
		success: function(msg){
			$('#mood').html( mood );
			$('#profile_status').html( unescape( old ) );
		}
	}).responseText;
};

function moodSubmit(){
	var mood = escape( $('#moodInput').val() );
	response = $.ajax({
		url: "/ajax_user_mood.php",
		global: false,
		type: "POST",
		data: "mood=" +  escape( mood ),
		dataType: "html",
		success: function(msg){
			if(msg){
				alert(msg);
			}
			$.facebox( 'Your status is updated!' );
			$("#moodInput").val( unescape( mood ) );
		}
	}).responseText;
};

/**
*DEPRECATED This function is not being used any more
*/function moodCancel(old){
	$('#profile_status').html( unescape(old) );
};

function jqmsg(){
	return;
};

function cdq(cmid){
	if(confirm('Are you sure you want to delete this comment?')) location.href = 'http://faithlight.com/deletecomment.php?comment_id='+cmid;
	return false;
};

function fpdq(cmid){
	if(confirm('Are you sure you want to delete this forum comment?')) location.href = 'http://faithlight.com/deletecomment.php?type=forum&comment_id='+cmid;
	return false;
};

function lydq(cmid){
	if(confirm('Are you sure you want to delete this lyrics comment?')) location.href = 'http://faithlight.com/deletecomment.php?type=lyrics&comment_id='+cmid;
	return false;
};

function BKdel(id){
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
 		alert ("Browser does not support AJAX!");
 		return;
 	}
	var url = "/ajax_bookmarks.php";
	var params = 'action=delete&id='+escape(id);
	xmlHttp.onreadystatechange = BKdelEnd;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
};

function BKdelEnd(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		if(xmlHttp.responseText != '0'){
			$('#bk_'+xmlHttp.responseText).fadeOut("slow");
		}
	}
};

function bookmarkThis(cid, ctype){
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
 		alert ("Browser does not support AJAX!");
 		return;
 	}
	var url = "/ajax_bookmarks.php";
	var params = "cid="+escape(cid)+"&ctype="+escape(ctype);
	xmlHttp.onreadystatechange = bookmarked;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
};

function bookmarked(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		if(xmlHttp.responseText != '0'){
			$('#bookmarkBTN').html(xmlHttp.responseText);
		}
	}
};

function rate_light(rate){
	for(var i = 1; i < 6; i++){
		if(rate < i){
			document.getElementById('rate_'+i).src = "/Themes/Beta/rate_imgs/off.gif";
		}
		else {
			document.getElementById('rate_'+i).src = "/Themes/Beta/rate_imgs/on.gif";
		}
	}
};

function rate_do_content(vote, id){
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
 		alert ("Browser does not support AJAX!");
 		return;
 	}
	var url = "/ajax/ajax_content_vote.php";
	var params = "sodrzina="+escape(id)+"&glas="+escape(vote);
	xmlHttp.onreadystatechange = stateChangedContent;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
};

function stateChangedContent(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		if (xmlHttp.responseText == '<b>Oooops!</b>'){
			document.getElementById('user_rate').style.display = 'none';
 			alert("<b>Oooops!</b><br />Voting is not possible at the moment,<br />please try again.");
			document.getElementById('user_rate').style.display = 'block';
		} else {
			if (xmlHttp.responseText == 'ERROR!Voted' || xmlHttp.responseText == 'ERROR!Login' || xmlHttp.responseText == 'ERROR!Owner' || xmlHttp.responseText == 'ERROR!ERROR'){
				if(xmlHttp.responseText == 'ERROR!Voted'){
					MyAlert('You can\\\'t vote twice!');
				}
				if(xmlHttp.responseText == 'ERROR!Owner'){
					MyAlert('You can\\\'t vote on your own content!');
				}
				if(xmlHttp.responseText == 'ERROR!Login'){
					MyAlert('You must be logged in to vote!');
				}
				if(xmlHttp.responseText == 'ERROR!ERROR'){
					MyAlert('ERROR! Something is wrong!');
				}
			} else {

				extraX = 'success';
				document.getElementById('user_rate').id = extraX;
				document.getElementById(extraX).style.width = '30%';
// 				pom1 = 'Your vote has been accepted!';
				pom1 = 'Voted!';
				pom = xmlHttp.responseText;
				var ttt = pom.split('+');
				ttr = ttt[1];
				ttt = ttt[0];
				if(ttr){
					pom = ttt;
					document.getElementById(extraX).style.width = 'auto';
					document.getElementById('rare').innerHTML = ttr;
				}
				document.getElementById(extraX).innerHTML = pom1;

				$('#'+extraX).effect("pulsate", { times:2 }, 1000);

				idi = 'user_rate';
				setTimeout('vrati_nazad(extraX, pom, idi)', 3000);
			}
		}
	}
};

function rate_do(vote, id){
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
 		alert ("Browser does not support AJAX!");
 		return;
 	}
	var url = "/user_vote.php";
	var params = "kandidat="+escape(id)+"&glas="+escape(vote);
	xmlHttp.onreadystatechange = stateChanged;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
};

function stateChanged(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		if (xmlHttp.responseText == '<b>Oooops!</b>'){
			document.getElementById('user_rate').style.display = 'none';
 			MyAlert("<b>Oooops!</b><br />Voting is not possible at the moment,<br />please try again.");
			document.getElementById('user_rate').style.display = 'block';
		} else {
			responded = xmlHttp.responseText;
			if (responded.length < 100)
				extraX = 'failure';
			else
				extraX = 'success';
		}
		pom = document.getElementById('user_rate').innerHTML;
		if (extraX == 'success'){
			pom = xmlHttp.responseText;
		}
		if (extraX == 'failure'){
 			MyAlert(xmlHttp.responseText);
		} else {
			document.getElementById('user_rate').id = extraX;
// 			document.getElementById(extraX).innerHTML = 'Your vote has been accepted!';
			document.getElementById(extraX).innerHTML = 'Voted!';
			$('#'+extraX).effect("pulsate", { times:2 }, 1000);
			idi = 'user_rate';
			setTimeout('vrati_nazad(extraX, pom, idi)', 3000);
		}
	}
};

function vrati_nazad(pomx, pomy, idi){
	document.getElementById(pomx).id = idi;
	pomyY = pomy;
	setTimeout('document.getElementById(idi).innerHTML = pomyY', 100);
};

function sortiraj(parametar, limit){
	$('#glossy_1').removeClass();
	$('#glossy_2').removeClass();
	$('#glossy_3').removeClass();
	$('#glossy_4').removeClass();
	$('#glossy_5').removeClass();
	$('#glossy_'+parametar).addClass("current");
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
		alert ("Browser does not support AJAX!");
		return;
	}
	var url = "/ajax_user_sort_by.php";
	var params = "nacin="+escape(parametar)+"&limit="+escape(limit);
	xmlHttp.onreadystatechange = sort_after;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);	
};

function sort_after(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		if (xmlHttp.responseText != 'failure'){
			var cell = document.getElementById("menko");
			if (cell.hasChildNodes()){
				while ( cell.childNodes.length >= 1 ){
					cell.removeChild( cell.firstChild );       
				}
			}
			image_display=document.createElement('div');
			image_display.innerHTML=xmlHttp.responseText;
			document.getElementById('menko').appendChild(image_display);
			//JT_init();
		}
	}
};

function friend_action(uaction, uid){
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
		alert ("Browser does not support AJAX!");
		return;
	}
	var url = "/ajax_friends.php";
	var params = "action="+escape(uaction)+"&uid="+escape(uid);
	xmlHttp.onreadystatechange = friend_action_result;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
};

function friend_action_result(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		elmt = escape(xmlHttp.responseText);
		el = elmt.split('+');
		if(!el[1]){
			$('#vikac_'+elmt).fadeOut("slow");
			setTimeout("delayFadeOut('ajax_friend_invites', 'vikac_"+elmt+"');", 1500);
		} else {
			var w = '201px';
			MyAlert(unescape(el[0]));
			$('#link_menu_2').css("display", "none");

// 			$('#u_menu_1').css("width", w);
// 			$('#u_menu_3').css("width", w);

			$('#u_menu_1, #u_menu_3').animate({ width: w }, 1000 );

// 			$('#u_menu_1').animate({ width: w }, 500 );
// 			$('#u_menu_3').animate({ width: w }, 500 );
		}
	}
};

function poll_vote (opt_id){
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
		alert ("Browser does not support AJAX!");
		return;
	}
	var url = "/poll_vote.php";
	var params = "option=" + escape(opt_id);
	xmlHttp.onreadystatechange = poll_result_vote;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
};

function poll_result_vote(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		if (xmlHttp.responseText == 'Error')
			MyAlert('You must be logged in to vote!');
		else {
			responded = xmlHttp.responseText;
			ret_val=responded.split("+");

			if (ret_val[1] == "ERROR"){
				extraX = "failure";
				MyAlert(ret_val[0]);
			}

			if (ret_val[1] == "OK"){
				extraX = "success";
				old_ht = document.getElementById("pollBody").innerHTML;
				document.getElementById("pollBody").id = extraX;
				document.getElementById(extraX).innerHTML = ret_val[0];
				document.getElementById(extraX).style.marginLeft = "15px";
				$('#'+extraX).effect("pulsate", { times:2 }, 1000);
				idi = "pollBody";
				pom = ret_val[2];
				setTimeout('vrati_nazad(extraX, pom, idi)', 5000);
				setTimeout('document.getElementById(idi).style.marginLeft = "0px"', 5000);
			}
        	}
	}
};

function dsb(){
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
		alert ("Browser does not support AJAX!");
		return;
	}
	var url = "/ajax_dsb.php";
	var params = "paramx="+0;
	xmlHttp.onreadystatechange = dodsb;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
};

function dodsb(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		var cell = document.getElementById("menko");
		if (cell.hasChildNodes()){
			while ( cell.childNodes.length >= 1 ){
				cell.removeChild( cell.firstChild );
			}
		}
		image_display=document.createElement('div');
		image_display.innerHTML=xmlHttp.responseText;
		document.getElementById('menko').appendChild(image_display);
		//JT_init();
	}
};

function ajax_search(strana){
	$('#glossy_1').removeClass();
	$('#glossy_3').removeClass();
	$('#glossy_2').removeClass();
	$('#glossy_5').removeClass();
	$('#glossy_4').addClass("current");
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
		alert ("Browser does not support AJAX!");
		return;
	}
	var url = "/ajax_user_search.php";
	try{
		grad 	= document.fnd_frm.country.value;
		pol 	= document.fnd_frm.sex.value;
		god1 	= document.fnd_frm.year1.value;
		god2 	= document.fnd_frm.year2.value;
		uname	= document.fnd_frm.search_uname.value;
		fname	= document.fnd_frm.search_fname.value;
	} catch(e){}

	var params = "country=" + grad + "&sex=" + pol + "&uname=" + uname + "&fname=" + fname + "&year1=" + escape(god1) + "&year2=" + escape(god2) + "&strana=" + escape(strana);
	xmlHttp.onreadystatechange = search_after;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
};

function search_after(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		if (xmlHttp.responseText != 'failure'){
			var cell = document.getElementById("menko");
			if (cell.hasChildNodes()){
				while ( cell.childNodes.length >= 1 ){
					cell.removeChild( cell.firstChild );       
				}
			}
			image_display=document.createElement('div');
			image_display.innerHTML=xmlHttp.responseText;
			document.getElementById('menko').appendChild(image_display);
			//JT_init();
		}
	}
};

function menu_work(param){
	$('#message_menu a').css({'background':'transparent'});
	$('#message_menu a').each(function(){
		$(this).unbind();
		if( $(this).attr('id') != param )
		$(this).hover(
			function(){
				$(this).css({'background':'#DDD url(/skin/message_menu_over.gif) repeat-x center top'});
			},function(){
				$(this).css({'background':'transparent'});
			}
		);
	});

	$('#'+param).css({'background':'#DDD url(/skin/message_menu_over.gif) repeat-x center top'});
};

function liveContent(param, strana){
	menu_work('_'+param);
	if(param != 'uu'){
		$('#user_profile_div').css("display","none");
		$('#ajax_user_comments').css("display","block");
		xmlHttp = GetXmlHttpObject();
		if (xmlHttp == null){
			alert ("Browser does not support AJAX!");
			return;
		}
		var url = "/ajax_liveContent.php";
		var params = "param="+escape(param)+"&strana="+escape(strana);
		if(uid > 0){
			params += '&uid='+uid;
		}
		xmlHttp.onreadystatechange = user_comments_after;
		xmlHttp.open("POST", url, true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");
		xmlHttp.send(params);
	} else {
		$('#user_profile_div').css("display","block");
		$('#ajax_user_comments').css("display","none");
	}
};

function ajax_user_comments(strana){
	menu_work('prof_comm');
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
		alert ("Browser does not support AJAX!");
		return;
	}
	var url = "/ajax_user_comments.php";
	var params = "strana="+escape(strana);
	xmlHttp.onreadystatechange = user_comments_after;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
};

function ax_fr_comm(strana){
	menu_work('fr_comm');
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
		alert ("Browser does not support AJAX!");
		return;
	}
	var url = "/ajax_forum_comments.php";
	var params = "strana="+escape(strana);
	xmlHttp.onreadystatechange = user_comments_after;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);	
};

function ax_my_fr_comm(strana){
	menu_work('my_fr_comm');
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
		alert ("Browser does not support AJAX!");
		return;
	}
	var url = "/ajax_my_forum_comments.php";
	var params = "strana="+escape(strana);
	xmlHttp.onreadystatechange = user_comments_after;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);	
};

function user_comments_after(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		var cell = document.getElementById("ajax_user_comments");
		if (cell.hasChildNodes()){
			while (cell.childNodes.length >= 1){
				cell.removeChild( cell.firstChild );       
			}
		}
		image_display=document.createElement('div');
		image_display.innerHTML=xmlHttp.responseText;
		document.getElementById('ajax_user_comments').appendChild(image_display);
		cut_comments();
	}
};

function ajax_friend_invites(str){
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
		alert ("Browser does not support AJAX!");
		return;
	}
	var url = "/ajax_friend_invites.php";
	var params = "strana="+escape(str);
	xmlHttp.onreadystatechange = friend_invites_after;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
};

function friend_invites_after(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		var cell = document.getElementById("ajax_friend_invites");
		if(cell.hasChildNodes()){
			while (cell.childNodes.length >= 1){
				cell.removeChild( cell.firstChild );       
			}
		}
		image_display=document.createElement('div');
		image_display.innerHTML=xmlHttp.responseText;
		document.getElementById('ajax_friend_invites').appendChild(image_display);
	}
};

function ajax_content_paging(str, tip, side){
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
		alert ("Browser does not support AJAX!");
		return;
	}
	var url = "/ajax_content_paging.php";
	var params = "strana="+escape(str)+"&type="+tip+"&side="+side;
	if (side == 'Left');
		xmlHttp.onreadystatechange = ajax_content_paging_after_leva;
	if (side == 'Right')
		xmlHttp.onreadystatechange = ajax_content_paging_after_desna;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
};

function ajax_content_paging_after_leva(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		var cell = document.getElementById("ajax_leva");
		if (cell.hasChildNodes()){
			while (cell.childNodes.length >= 1){
				cell.removeChild( cell.firstChild );
			}
		}
		image_display=document.createElement('div');
		image_display.innerHTML=xmlHttp.responseText;
		document.getElementById('ajax_leva').appendChild(image_display);
	}
};

function ajax_content_paging_after_desna(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		var cell = document.getElementById("ajax_desna");
		if (cell.hasChildNodes()){
			while (cell.childNodes.length >= 1){
				cell.removeChild(cell.firstChild);
			}
		}
		image_display=document.createElement('div');
		image_display.innerHTML=xmlHttp.responseText;
		document.getElementById('ajax_desna').appendChild(image_display);
	}
};

function ajax_comment_paging(str){
	xmlHttp = GetXmlHttpObject();
	if (xmlHttp == null){
		alert ("Browser does not support AJAX!");
		return;
	}
	var url = "/ajax_comments_paging.php";
	var params = "strana="+escape(str);
	xmlHttp.onreadystatechange = ajax_comment_paging_after;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
};

function ajax_comment_paging_after(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		responded = xmlHttp.responseText;
		ret_val=responded.split("+");
		var cell = document.getElementById('comments_front_left');
		if (cell.hasChildNodes()){
			while (cell.childNodes.length >= 1){
					cell.removeChild( cell.firstChild );
			}
		}
		image_display=document.createElement('div');
		image_display.innerHTML=ret_val[0];
		document.getElementById('comments_front_left').appendChild(image_display);
		var cell = document.getElementById('comments_front_right');
		if (cell.hasChildNodes()){
			while (cell.childNodes.length >= 1){
				cell.removeChild( cell.firstChild );
			}
		}
		image_display=document.createElement('div');
		image_display.innerHTML=ret_val[1];
		document.getElementById('comments_front_right').appendChild(image_display);
		var cell = document.getElementById('comm_paging');
		if (cell.hasChildNodes()){
			while (cell.childNodes.length >= 1){
				cell.removeChild( cell.firstChild );
			}
		}
		image_display=document.createElement('div');
		image_display.innerHTML=ret_val[2];
		document.getElementById('comm_paging').appendChild(image_display);
		cut_comments();
	}
};

function ajax_conn_comm(strana){
	menu_work('cont_comm');
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null){
		alert ("Browser does not support AJAX!");
		return;
	}
	var url = "/ajax_conn_comm.php";
	var params = "strana="+escape(strana);
	xmlHttp.onreadystatechange = ajax_conn_comm_after;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);	
};

function ajax_conn_comm_after(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		var cell = document.getElementById("ajax_user_comments");
		if (cell.hasChildNodes()){
			while (cell.childNodes.length >= 1){
				cell.removeChild( cell.firstChild );
			}
		}
		image_display=document.createElement('div');
		image_display.innerHTML=xmlHttp.responseText;
		document.getElementById('ajax_user_comments').appendChild(image_display);
		cut_comments();
	}
};

function ajax_my_comm(strana){
	menu_work('my_comm');
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null){
		alert ("Browser does not support AJAX!");
		return;
	}
	var url = "/ajax_my_comm.php";
	var params = "strana="+escape(strana);
	xmlHttp.onreadystatechange = ajax_my_comm_after;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
};

function ajax_my_comm_after(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		var cell = document.getElementById("ajax_user_comments");
		if (cell.hasChildNodes()){
			while (cell.childNodes.length >= 1){
				cell.removeChild( cell.firstChild );
			}
		}
		image_display=document.createElement('div');
		image_display.innerHTML=xmlHttp.responseText;
		document.getElementById('ajax_user_comments').appendChild(image_display);
		cut_comments();
	}
};

function curl_show_child(c_id){
	if(document.getElementById('skriena_'+c_id).style.display == 'block'){
		document.getElementById('skriena_'+c_id).style.display = 'none';
		return;
	}
	if(document.getElementById('skriena_'+c_id).innerHTML != '&nbsp;'){
		document.getElementById('skriena_'+c_id).style.display = 'block';
		return;
	}
	CURL_ID = c_id;
	xmlHttp = GetXmlHttpObject()
	if (xmlHttp == null){
		alert ("Browser does not support AJAX!");
		return;
	}
	var url = "/superadmin/curl_stats.php";
	var params = "curl_id="+escape(c_id);
	xmlHttp.onreadystatechange = curl_show_child_after;
	xmlHttp.open("POST", url, true);
	xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHttp.setRequestHeader("Content-length", params.length);
	xmlHttp.setRequestHeader("Connection", "close");
	xmlHttp.send(params);
};

function curl_show_child_after(){
	if (xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){
		var cell = document.getElementById('skriena_'+CURL_ID);
		cell.style.display = 'block';
		if (cell.hasChildNodes()){
			while (cell.childNodes.length >= 1){
				cell.removeChild( cell.firstChild );
			}
		}
		image_display=document.createElement('div');
		image_display.innerHTML=xmlHttp.responseText;
		document.getElementById('skriena_'+CURL_ID).appendChild(image_display);
	}
};

function GetXmlHttpObject(){
	var xmlHttp = null;
	try{
		xmlHttp = new XMLHttpRequest();
	} catch (e) {
		try{
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
};

function messenger(url){
	var w = $('html').width();
	var levo = (w / 2) - 115;
	MSN = window.open(url,'name', 'height=500, width=255, left=' + levo + ', top=250, toolbar=no, menubar=no, directories=no, location=no, scrollbars=yes, status=no, resizable=no, fullscreen=no');
	if (window.focus) { MSN.focus(); }
};

function getMessengerNotes(){
	var hmb = $('#horizontal_menu_bar');
	if(!hmb){
		$.ajax({
			url: "/ajax/ajax_messenger_info.php",
			global: false,
			type: "POST",
			dataType: "html",
			success: function(msg){
				if(msg){
					$('#menu_holder').append('<div id="boubble">' + msg + '</div>');
					$('#boubble').css('display', 'block');
				}
			}
		});
	}
};

function cancelChatInvite(){
	$.ajax({
		url: "/ajax/ajax_messenger_action.php",
		global: false,
		type: "POST",
		dataType: "html",
		success: function(msg){
			$('#boubble').css('display', 'none');
		}
	});
};

function denyGINV(token){
	$.ajax({
		url: "/ajax/ajax_group_invite.php",
		global: false,
		type: "POST",
		data: "token="+token,
		dataType: "html",
		success: function(msg){
			$('#vikac_'+token).fadeOut("slow");
			setTimeout("delayFadeOut('group_invites', 'vikac_"+token+"');", 1500);
		}
	});
};

function delayFadeOut(tag, token){
	$('#'+token).remove;
	if( $('#'+tag).html().length < 15 ){
		$('#O'+tag).fadeOut("slow");
	}
};

function showLatestStats(){
// 	$.ajax({
// 		url: "/ajax/latest-stats.php",
// 		global: false,
// 		type: "POST",
// 		dataType: "html",
// 		success: function(msg){
// 			$('#latestStats').html(msg).toggle();
// 		}
// 	});
};

function checkState(){
	var state = $('#country').val();
	if( state == 'United States'){
		$('#state-sbox').css("display", "block");
	} else {
		$('#state-sbox').css("display", "none");
		$('#state').val('Other');
	}
};

function ajaxLogin(tURL, tType, tData){
	var username = document.ajax_login_form.aluname.value;
	var password = document.ajax_login_form.alpass.value;

	tURL = 'http://' + tURL;

	if(username != '' && password != ''){
		$.ajax({
			url: "/ajax/ajax_login.php",
			global: false,
			type: "POST",
			data: "username="+username+"&password="+password,
			dataType: "html",
			success: function(msg){
				if(msg == '1'){
					if(tType == 'script'){
						messenger(tURL);
						location.href ='/';
						jQuery(document).trigger('close.facebox');
					} else {
						location.href = tURL;
					}
				} else {
					location.href = '/';
				}
			}
		});
	}
};

function prayForThis(prayer_id){
	if(prayer_id > 0){
		$.ajax({
			url: "/ajax/ajax_pray.php",
			global: false,
			type: "POST",
			data: "prayer_id="+prayer_id,
			dataType: "html",
			success: function(msg){
				if(msg == 'OK'){
					$('#prayingBTN').html("You are praying!");
				} else {
					MyAlert(msg);
				}
			}
		});
	}
};

function notificationsShow(){
	var th = $('#live_info_box').css("display");
	if(th == 'none' || th == ''){
		$('.h_menu_bar_sub_item').css("display", "none");
		$('#live_info_box').css("display", "block");
	} else {
		$('#live_info_box').css("display", "none");
	}
};

function showNotifications(){
	$.ajax({
		url: "/ajax/ajax_check_chats.php",
		global: false,
		type: "POST",
		data: "info=1", 
		dataType: "html",
		success: function(msg){
			$('#live_info_box').html('<div class="live_info_box_title"><span onclick="javascript:notificationsShow(); return false;">x</span>Notifications</div>'+msg);
//			$('.h_menu_bar_sub_item').css("display", "none");
		}
	});
};

function showNotifications2(){
	var reload_time = 5000; //5 seconds
	clearTimeout(nt2);
	$.ajax({
		url: "/ajax/ajax_check_chats.php", 
		global: false, 
		type: "POST", 
		data: "info=2", 
		dataType: "html", 
		success: function(msg){
			if(msg != ''){
				$('#live_info_box').html( $('#live_info_box').html() + msg ).css("display", "block");
				$('.h_menu_bar_sub_item').css("display", "block");
				clearTimeout(nt2);
			} else {
				nt2 = setTimeout('showNotifications2();', reload_time);
			}
		}
	});
};

function ajax_messenger_invitation(){
	$.ajax({
		url: "/ajax/ajax_messenger_invitation.php",
		global: false,
		type: "POST",
		dataType: "html",
		success: function(msg){
			var param = '<div class="h_menu_bar_item" id="chat_invite_">Chat Invitation<div class="h_menu_bar_sub_item">'
			+'<div class="live_info_box_title"><span onclick="javascript:cancelChatInvite();clearChatInvitations();return false;">x</span>Chat Invitation</div>'
			+ '<div id="chat_invitation_body">' + msg + '</div>'
			+'</div></div>';
			if(msg){
				$('#horizontal_menu_bar').append(param);
				h_menu_items_reload();
				$('#chat_invite_').click();
				clearTimeout(mt);
			} else {
				mt = setTimeout('ajax_messenger_invitation();', 5000);
			}
		}
	});
};

function clearChatInvitations(){
	$('#chat_invite_').remove();
	mt = setTimeout('ajax_messenger_invitation();', 5000);
};

function h_menu_items_reload(){
	var br = 1;

	$('.h_menu_bar_item').each(function(){
		var idd = $(this).attr("id");
		if( idd != 'live_info_button'){
			if(!idd){
				$(this).attr("id", "h_menu_item_" + br);
				br++;
			}
			$(this).click(function(){
				var tft = $( '#' + $(this).attr('id') + ' .h_menu_bar_sub_item').css("display");
				if( tft != 'block'){
					$('.h_menu_bar_item').css("background-image", "");
					$('.h_menu_bar_sub_item').css("display", "none");
					$( '#' + $(this).attr('id') + ' .h_menu_bar_sub_item').css("display", "block");
					$( '#' + $(this).attr('id') ).css("background", "transparent url(/skin/message_menu_over.gif) repeat-x center bottom");
					$('#live_info_box').css("display", "none");
				} else {
					$( '#' + $(this).attr('id') + ' .h_menu_bar_sub_item').css("display", "none");
					$( '#' + $(this).attr('id') ).css("background-image", "");
				}
			});
		}
	});
};



/**
* @author Remy Sharp
* @url http://remysharp.com/2007/01/25/jquery-tutorial-text-box-hints/
*/

(function ($) {

$.fn.hint = function (blurClass) {
  if (!blurClass) { 
    blurClass = 'blur';
  }
    
  return this.each(function () {
    // get jQuery version of 'this'
    var $input = $(this),
    
    // capture the rest of the variable to allow for reuse
      title = $input.attr('title'),
      $form = $(this.form),
      $win = $(window);

    function remove() {
      if ($input.val() === title && $input.hasClass(blurClass)) {
        $input.val('').removeClass(blurClass);
      }
    }

    // only apply logic if the element has the attribute
    if (title) { 
      // on blur, set value to title attr if text is blank
      $input.blur(function () {
        if (this.value === '') {
          $input.val(title).addClass(blurClass);
        }
      }).focus(remove).blur(); // now change all inputs to title
      
      // clear the pre-defined text when form is submitted
      $form.submit(remove);
      $win.unload(remove); // handles Firefox's autocomplete
    }
  });
};

})(jQuery);