/**
 * 
 * @param All rights are reserved. Coping functions from this file is forbidden!
 * @copyright MyTibia.eu
 * @author Podwika Robert
 * 
 */

function $_(obj)
{
	return document.getElementById(obj);
}
function playerPvpSkills(obj,play)
{
	ajaxGET("content1","playerPvp.php?player=" + play, "pvpTable");
}
function playerHighscores(obj,world)
{	
	ajaxGET("content1","highscores.php?world=" + world, "tableExpierenceHighscores");
}
function playerHighscoresSkills(obj,world,skill)
{	
	ajaxGET("content1","highscoresSkills.php?world=" + world + "&skill=" + skill,"skillTable");
}
function getGuilds(obj,world)
{
	ajaxGET("content1","guilds.php?world=" + world) ;
}
function getGuildsToSelect(obj,world)
{
	ajaxGET("content1","guilds.php?world=" + world) ;
}
function getGuildDetails(guildName)
{
	ajaxGET("content1","guildDetails.php?guildName=" + guildName);
}
function getPlayer(playerName)
{
	ajaxGET("content1","playerDetails.php?playerName=" + playerName);
}
function whoIsOnline(world)
{
	ajaxGET("content1","whoisonline.php?world=" + world,"listaGraczy");
}
function whoIsOnlineGuild(guild)
{
	ajaxGET("content1","guildOnline.php?guild=" + guild, "listaGraczy");
}
function calcExp(lev)
{
	if(lev<0)	
	{
		alert('Too low level');
		return;
	}
	if(lev>1200)
	{
		alert('Level should be lower than 1200');
		return;
	}
	$.ajax(
			{
				type: "GET",
				url: "calc_expierence.php?level=" + lev,
				datatype: "text",
				success: function(html)
				{
					$("#content1").html(html);
				}
			}
			);
}
function calcMlv(lev,voc)
{
	ajaxGET("content1","calc_mlv.php?mlv=" + lev + "&voc=" + voc);
}
function calcMagicPower(level,mlv)
{
	ajaxGET("content1","calc_magicpower.php?mlv=" + mlv + "&level=" + level);
}
function calcFishing(skillFrom, skillTo)
{
	ajaxGET("content1","calc_fishing.php?skillFrom=" + skillFrom + "&skillTo=" + skillTo);
}
function calcPlayerInfo(level,mlevel,skill,arm,weaponattack,distance,vocation,attackType,speed)
{
	ajaxGET("content1","calc_playerinfo.php?level=" + level + "&skill=" + skill + "&mlevel=" + mlevel + "&arm=" + arm + "&weaponAttack=" + weaponattack + "&distance=" + distance + "&vocation=" + vocation + "&attackType=" + attackType + "&speed=" + speed);
}
function mainDiv(a)
{
		//if($_("content1").innerHTML.length==0)
		ajaxGET("content1","mainframe.php");
	
}
function imagesDiv()
{
		ajaxGET("content1","pictures.php");
	
}
function showDiv(t)
{
	ajaxGET("content1","showTemp.php?t=" + t);
}
function getSpeedCheckbox()
{
	sum=0;
	if($_('boh').checked==true) sum = sum | 1;
	if($_('timeRing').checked==true) sum = sum | 2;
	if($_('haste').checked==true) sum = sum | 4;
	if($_('strongHaste').checked==true) sum = sum | 8;
	if($_('swiftFoot').checked==true) sum = sum | 16;
	if($_('charge').checked==true) sum = sum | 32;
	return sum;
}
function fragCount(dane)
{
	//alert(dane);
	ajaxPOST("count_res","fragCounterAjax.php","frags=" + dane);
}
function expInfo(player)
{
	ajaxGET("content1","expHistory.php?player=" + player);
}
function blessingCount(lev, count, isPromoted, inq)
{	
	ajaxGET("content1", "calc_blessings.php?level=" + lev + "&count=" + count + "&isPromoted=" + isPromoted + "&inq=" + inq);
}

function podtyp()
{
	var wybrany = $_('opcje')[$_('opcje').selectedIndex].value;
	var world = $_('world')[$_('world').selectedIndex].value;
	var ur = "returnViolation.php?type=podtype&podtyp=" + wybrany + "&world="+ world;
	//ajaxGET("podtyp","returnViolation.php?type=podtype&podtyp=" + wybrany + "&world="+ world);
	var resp=$.ajax(
			{
				type: "GET",
				url: ur,
				datatype: "text",
				success: function(html)
				{
					$("#podtyp").html(html);
				}
			}
	).responseText;
	
	
}
function opis()
{
	var wybrany = $_('opis')[$_('opis').selectedIndex].value;
	var world = $_('world')[$_('world').selectedIndex].value;
	var resp=$.ajax(
			{
				type: "GET",
				url: "returnViolation.php?type=opis&podtyp=" + wybrany + "&world="+ world,
				datatype: "text",
				success: function(html)
				{
					$("#desc").html(html);
				}
			}
	).responseText;
	var resp2=$.ajax(
			{
				type: "GET",
				url: "returnViolation.php?type=fulldesc&rule=" + wybrany + "&world="+ world,
				datatype: "text",
				success: function(html)
				{
					$("#fulldesc").html(html);
				}
			}
	).responseText;
}
function report()
{	
	ajaxGET("content1", "report.php");
}
function ajaxGET(targetDiv,url)
{
	 $.ajax({
		   type: "GET",
		   url: url,
		   success: function(msg){
		     document.getElementById(targetDiv).innerHTML = msg;
		     $("#content-loading").hide();
		   },
		   beforeSend: function (XMLHttpRequest) {
			   $("#content-loading").show();
		   }

		 });

}
function ajaxPOST(targetDiv,url,dane)
{
	 $.ajax({
		   type: "POST",
		   url: url,
		   data: dane,
		   success: function(msg){
		     document.getElementById(targetDiv).innerHTML = msg;
		     $("#content-loading").hide();
		   },
		   beforeSend: function (XMLHttpRequest) {
			   $("#content-loading").show();
		   }

		 });

}
/*
function ajaxPOST(targetDiv,url,dane,sortTable){
		 var ajax=createXMLHttpRequest();
		 if(!ajax) return 0;
		 ajax.open("POST", url);
		 var target = $_(targetDiv);
			//document.getElementById('mainContentLoading').style.visiblity="visible";
			
						ajax.onreadystatechange = function(){
				   if(ajax.readyState == 4){
				   	  switch(ajax.status){					  
					  		case 200:
							target.innerHTML = ajax.responseText;
							$_('content-loading').style.display="none";	
							if(sortTable!=undefined)
							{								
								$("#"+sortTable).tablesorter();
							}
							return true;							
							break;
							default:
							$_('content-loading').style.display="none";
							//ajax.abort();
							//throw new Exception(ajax.statusText);
					  }	
				   }
				   else if(ajax.readyState == 1)
				   {
				   	$_('content-loading').style.display="block";
				   }
				   else{ return; }			   
				}
			 ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			 ajax.setRequestHeader("Content-length", dane.length);
			 ajax.setRequestHeader("Connection", "close");				
			 ajax.send(dane);
		
}
*/
function pvpEvent()
{
		alert('ok');
}

function enterFunction(e,funkcja)
{
	  if (e.which == null)
	  char= e.keyCode;    // IE
	  else if (e.which > 0)
		 char = e.which;	  // All others	 
	 if(char==13)
	 playerPvpSkills(null,document.getElementById('playerName').value);
	
}
function enterGuildName(e,guild)
{
	  if (e.which == null)
	  char= e.keyCode;    // IE
	  else if (e.which > 0)
		 char = e.which;	  // All others	 
	 if(char==13)
	 whoIsOnlineGuild(guild);
	
}
/*----------------------------------------------*/
