//rjax_url="/ajax/kamp.php";

function set_data(data_input, element_id) {
	document.getElementById(element_id).innerHTML = data_input;
}

function setVisibility(id, visibility) {
	document.getElementById(id).style.display = visibility;
}

function get_region(country) {
	$.post("/ajax/kamp.php?action=get_region", {'country': country},  function (text) { $('#set_region').html(text); });
}

function get_city(city) {
	$.post("/ajax/kamp.php?action=get_city", {'city': city}, function (text) { $('#set_city').html(text); });
}

function show_help(show_id, help_code) {
	//dont look up in db if just closing help box
      var showid = $('#' + show_id);
      if (showid.is(":hidden")) {
            $.post("/ajax/kamp.php?action=load_help", {'help_code' : help_code}, function (help_text) { $('#'+ show_id).html(help_text);});
      }

      $('#' + show_id).toggle(300);
}

function set_rating(type, type_id, star_rating, user_id) {

	$.post("/ajax/kamp.php?action=set_rating", {'content_id': content_id,  'star_rating': star_rating, 'user_id' : user_id});

	$.post("/ajax/kamp.php?action=rating_score", {'type': type, 'type_id' : type_id,  'user_id': user_id}, function (text) { $('#rate_avg').html(text);});
}

function reload_avg_rate(type, type_id, user_id) {
	$.post("/ajax/kamp.php?action=rating_score", {'type': type, 'type_id' : type_id,  'user_id': user_id}, function (text) { $('#rate_avg').html(text);});
}

function not_logged_in() {
	alert('you must login to rate pages');
}

function save_flag(type, type_id, user_id, flag_id) {
	$.post("/ajax/kamp.php?action=save_flag", {'type': type, 'type_id': type_id,  'user_id': user_id, 'flag_id': flag_id}, function (text) { alert(text);});
}

function del_flag(type, type_id, user_id, flag_id) {
	$.post("/ajax/kamp.php?action=del_flag", {'type': type, 'type_id': type_id,  'user_id': user_id, 'flag_id': flag_id}, function (text) {
		alert(text);
		location.replace("dashboard.php");
	});
}

function check_username_avil(username) {
	$.post("/ajax/kamp.php?action=check_username_avil",
	{'username': username}, function (result){
		if(result=="Taken") {
			$('input[type=submit]').attr('disabled', 'disabled');
			$('#username_error').html("This username is " + result);
			$('#username').val("Taken");
		 } else {
			 $('input[type=submit]').removeAttr("disabled");
			 $('#username_error').html("This username is " + result);
		 }
	});
}

function show_comment_form(){
	$('#cmt_form1').show("slow");
	$('#cmt_form2').hide("slow");
}

function hide_comment_form(){
	$('#cmt_form1').hide("slow");
	$('#cmt_form2').show("slow");
}

function dream(){
	//calculating random color of dream
	var color = 'rgb('+Math.floor(Math.random()*255)+','+Math.floor(Math.random()*255)+','+Math.floor(Math.random()*255)+')';

	//calculating random X position
	var x = Math.floor(Math.random()*$("#responsecontainer").width());

	//calculating random Y position
	var y = Math.floor(Math.random()*$("#responsecontainer").height());

	//creating the dream and hide
	var drawingpix = $('<span>').attr({'class': 'drawingpix'}).hide();

	//appending it to body
	$("#responsecontainer").append(drawingpix);

	//styling dream.. filling colors.. positioning.. showing.. growing..fading
	drawingpix.css({
		'background-color':color,
		'border-radius':'100px',
		'-moz-border-radius': '100px',
		'-webkit-border-radius': '100px',
		top: y-14,    //offsets
		left: x-14 //offsets
	}).show().animate({
		height:'500px',
		width:'500px',
		'border-radius':'500px',
		'-moz-border-radius': '500px',
		'-webkit-border-radius': '500px',
		opacity: 0.05,
		top: y-250,    //offsets
		left: x-250
	}, 3000).fadeOut(800);

	//Every dream's end starts a new dream
	dream_func=window.setTimeout('dream()',2000);
}
