$(document).ready(function(){
	maketitles("showtitles");

    $("#murl").keyup(function () {
      var value = $(this).val();
      $("#url_preview").text(value);
    }).keyup();

	$(".faq-questions").toggle(function() {
	$(this).next().slideDown(200);
	$(this).removeClass("faq-questions").addClass("faq-questions_active");
	},
	function() {
	$(this).next().slideUp(200);
	$(this).removeClass("faq-questions_active").addClass("faq-questions");
	});
	
	
	$('#head-inform-text').innerfade({
		animationtype: 'fade',
		speed: 600,
		timeout: 6000,
		type: 'sequence',
		containerheight: '1em'
	});

	jQuery('#back-to-top').click(function(){
		jQuery('html, body').animate({scrollTop:0}, 'slow');
	});	
});
function maketitles(classname) {
	$(".showtitles").each( function() {
		$(this).tooltip({
			position: "top right",
			opacity: 0.7,
			tipClass: "tooltip",
			effect: "slide",
			offset: [10, 2]
		}).dynamic({
			bottom: {
				direction: "down",
				bounce: true
			}
		});
	});
};

function showcode(conid) {
	$("#cod_"+conid).colorbox({width:"50%", height:"32%", scrolling:true, inline:true, href:"#code_"+conid});
	$("#click").click(function(){ 
	$('#click').css({"background-color":"#f00", "color":"#fff", "cursor":"inherit"}).text("Open this window again and this message will still be here.");
	return false;
});
};

function Steam_Validation(type, id) {

var id = new LiveValidation(id);
id.add( Validate.Presence );

if(type == steamid) { id.add( Validate.Format, { pattern: /STEAM_/i } ); }
if(type == email) { id.add( Validate.Email ); id.add( Validate.Length, { minimum: 10, maximum: 20 } ); }
}

function SendMessage(type, id) {
	var message = $("#ctext").val();
	if (message == "undefined" || message == undefined || message == "") return;
	$("#loading_process").show();
	
	var jqxhr = $.ajax({
            type: "POST",
            url: "/inc/include_sendmessage.php",
            data: "IN_MYSTEAM=true&id="+id+"&type="+type+"&message="+message
	});
	
	jqxhr.complete(function(){
		document.getElementById('ctext').value = "";
		CommentsUpdate(type, id);
	});
	
	return false;
}


function SendLockMessage(locktype, id)
{
	var message = prompt("Введите причину блокировки:","");
	if (message != null && message != "")
	{
		$("#loading_process").show();
	$.ajax({
            type: "POST",
            url: "/inc/include_sendmessage.php",
            data: "IN_MYSTEAM=true&id="+id+"&type=lockMessage&locktype="+locktype+"&message="+message
			});
	}
}

function SendtoMail(type)
{
	$("#loading").height($("#result").height());
	$("#result").html("");
	$("#loading").css("display", "block");
	
var username = $('#username').val();
var pageurl = $('#pageurl').val();
var email = $('#email').val();
var subject = $('#subject').val();
var text = $('#text').val();

if (email == "undefined" || email == undefined) return;
if (subject == "undefined" || subject == undefined) return;
if (text == "undefined" || text == undefined) return;

if(type == "bugreport") {

if (pageurl == "undefined" || pageurl == undefined) return;

	var jqxhr = $.ajax({
            type: "POST",
            url: "/inc/include_sendmessage.php",
            data: "IN_MYSTEAM=true&type="+type+"&username="+username+"&pageurl="+pageurl+"&email="+email+"&subject="+subject+"&text="+text,
			success: function(html) {
			$("#result").empty();
			$("#result").append(html);
                }
			});
} else {

if (username == "undefined" || username == undefined) return;

	var jqxhr = $.ajax({
            type: "POST",
            url: "/inc/include_sendmessage.php",
            data: "IN_MYSTEAM=true&type="+type+"&username="+username+"&email="+email+"&subject="+subject+"&text="+text,
			success: function(html) {
			$("#result").empty();
			$("#result").append(html);
                }
			});
}
	jqxhr.complete(function(){
	$("#loading").css("display", "none");
	document.getElementById('text').value = "";
	});
}

function DeleteMessage(type, id, cid) {
	var result = confirm("Вы действительно хотите удалить сообщение ?");
	if (result) {
	
	$("#loading_process").css("display", "block");

		$.ajax({
			type: "POST",
			url: "/inc/include_deletemessage.php",
			data: "IN_MYSTEAM=true&type="+type+"&url="+id+"&cid="+cid
		});
	}

}

function LockMessage(type, parameters, id, cid){
if(parameters == 'lock')
var result = confirm("Вы действительно хотите заблокировать сообщение ?");
else
var result = confirm("Вы действительно хотите разблокировать сообщение ?");

	if (result) {
	
	$("#loading_process").css("display", "block");
	
		$.ajax({
			type: "POST",
			url: "/inc/include_lockmessage.php",
			data: "IN_MYSTEAM=true&type="+type+"&parameters="+parameters+"&url="+id+"&cid="+cid
		});
	}
}

function ServerInfo() {
	
	$("#loading_text").css("display", "none");
	$("#loading").show();
		
	var jqxhr = $.ajax({
		type: "POST",
		url: "/inc/include_updateservers.php",
		data: "IN_MYSTEAM=true"
	});

	jqxhr.success(function(){
		$("#server-list").html(jqxhr.responseText);
	});

	jqxhr.complete(function(){
		$("#loading").css("display", "none");
		$("#loading_text").show();
	});
}

function DetailsServerInfo(type, id) {

		$("#loading_text").css("display", "none");
		$("#loading").show();
		
	var jqxhr = $.ajax({
		type: "POST",
		url: "/inc/include_updateservers.php",
		data: "IN_MYSTEAM=true&type="+type+"&id="+id
	});

	jqxhr.success(function(){
	
		if (type == 'srvinfo') {
			$("#servers-info").html(jqxhr.responseText);
		} else if (type == 'players-list') {
			$("#players-list").html(jqxhr.responseText);
		} else if (type == 'server-cvars') {
			$("#servers-cvars").html(jqxhr.responseText);
		}
	});

	jqxhr.complete(function(){
		$("#loading").css("display", "none");
		$("#loading_text").show();
	});
}

function UpdateMessage(type, id) {
	var jqxhr = $.ajax({
		type: "POST",
		url: "/inc/include_updatemessage.php",
		data: "IN_MYSTEAM=true&type="+type+"&id="+id
	});

	jqxhr.success(function(){
		$("#comments").html(jqxhr.responseText);
	});
	
	jqxhr.complete(function(){
		$("#loading_process").fadeOut();
	});
}

function CommentsUpdate(type, id) {
	$("#loading_process").show();
	
	var jqxhr = $.ajax({
		type: "POST",
		url: "/inc/include_updatemessage.php",
		data: "IN_MYSTEAM=true&type="+type+"&id="+id
	});

	jqxhr.success(function(){
		$("#comments").html(jqxhr.responseText);
	});
	
	jqxhr.complete(function(){
		$("#loading_process").fadeOut();
	});
}

function SwitchPage(type, page) {
	$("#loading").height($("#content").height());
	$("#content").html("");
	$("#loading").css("display", "block");
	
	var jqxhr = $.ajax({
		type: "POST",
		url: "/inc/include_arbitrage.php",
		data: "IN_MYSTEAM=true&type="+type+"&st="+page
	});
	
	jqxhr.complete(function(){
		$("#loading").css("display", "none");
		$("#content").html(jqxhr.responseText);
	});
}

function checkSteamId(type) {
	var SteamId = $('#SteamId').val();
	var skins = $('#skins').val();
	$("#content").html("");
	$("#loading").css("display", "block");
	
	if (type == 'checker') {
	
	var jqxhr = $.ajax({
		type: "POST",
		url: "/inc/include_checker.php",
		data: "IN_MYSTEAM=true&type="+type+"&SteamId="+SteamId
	});
	
	} else if (type == 'steam_status') {
	
	var jqxhr = $.ajax({
		type: "POST",
		url: "/inc/include_checker.php",
		data: "IN_MYSTEAM=true&type="+type+"&SteamId="+SteamId+"&skins="+skins
	});
	
	}
	jqxhr.complete(function(){
		$("#loading").css("display", "none");
		$("#content").html(jqxhr.responseText);
	});
	
	return false;
}

function ShowNotification(id) {
  var features, w = 650, h = 225;
  var top = (screen.height - h)/2, left = (screen.width - w)/2;
  if(top < 0) top = 0;
  if(left < 0) left = 0;
  features = 'top=' + top + ',left=' +left;
  features += ',height=' + h + ',width=' + w + ',resizable=no';
  myWin = open('/inc/notification-views.php?IN_MYSTEAM=true&notification_ID='+id, 'displayWindow', features);
}


function DeleteShowMessage(){var result	= confirm("Вы действительно хотите удалить это ?");if (result) return true; else return false;}

function doClear(theText) { if (theText.value == theText.defaultValue) { theText.value = "" } }
function doDefault(theText) { if (theText.value == "") { theText.value = theText.defaultValue } }


/* PLUGIN PAGE SCRIPTS */

function plugin_page(type, mod, id) {
	
	$.ajaxSetup ({cache: false});
	
	var ajax_load = '<br><table width="100%" cellspacing="8" cellpadding="8"><tr><td align="center">Выполняется запрос. Пожалуйста, подождите...<br><br><div id="loader"></div></td></tr></table><br>';
	
	if (type == "edit") {var page_edit = "/plugin/" + type + "/" + mod + "/" + id + ".html";}
	if (type == "cancel") {var page_edit = "/plugin/" + type + "/" + mod + "/" + id + ".html";}
	
	$("#plugin-edit_" + mod).html(ajax_load).load(page_edit);
}

function plugin_page_save(type, id) {

	var ajax_load = '<br><table width="100%" cellspacing="8" cellpadding="8"><tr><td align="center">Выполняется запрос. Пожалуйста, подождите...<br><br><div id="loader"></div></td></tr></table><br>';

	var message = $("#" + type).val();
	var page_edit = "/plugin/cancel/" + type + "/" + id + ".html";
	if (message == "undefined" || message == undefined || message == "") return;
	
	var jqxhr = $.ajax({
            type: "POST",
            url: "/inc/include_plugin_information.php",
            data: "IN_MYSTEAM=true&game="+id+"&type="+type+"&message="+message
	});
	
	jqxhr.complete(function(){
	$("#plugin-edit_" + type).html(ajax_load).load(page_edit);
	});
	
	return false;
}

/* END PLUGIN PAGE SCRIPTS */
