/*
* Give this a URL, as long as the URL returns : pairs
* in JSON format the these values will be added to the select box
*/
jQuery.fn.loadJsonOptions = function(url) 
{
  id = "#"+jQuery(this).attr("id");
  jQuery.getJSON(url, function(data)
  {
    jQuery.each(data, function(i, item)
    {
      jQuery(id).addOption(item.value, item.name);
    });
  });
}

/*
* Add a new option to the end of a select box
*/
jQuery.fn.addOption = function(value, text) {
id = "#"+jQuery(this).attr("id");
var option = document.createElement("option");
option.value = value;
option.text = text;
jQuery(id).get(0)[jQuery(id+' option').length] = option;
}

jQuery.fn.clear = function() {
jQuery("#"+jQuery(this).attr("id")).children().remove();
}


var ie	= document.all;
var ns6	= document.getElementById && !document.all;

/*
Code taken from phpBB Project - textarea BB code editor
*/

var form_name = 'prispevek';
var text_name = 'message';

var cil;

/*
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version

var is_ie = ((clientPC.indexOf("msie") != -1) && (clientPC.indexOf("opera") == -1));
var is_nav = ((clientPC.indexOf('mozilla')!=-1) && (clientPC.indexOf('spoofer')==-1)
&& (clientPC.indexOf('compatible') == -1) && (clientPC.indexOf('opera')==-1)
&& (clientPC.indexOf('webtv')==-1) && (clientPC.indexOf('hotjava')==-1));
var is_moz = 0;

var is_win = ((clientPC.indexOf("win")!=-1) || (clientPC.indexOf("16bit") != -1));
var is_mac = (clientPC.indexOf("mac")!=-1);
*/

// Check for Browser & Platform for PC & IE specific bits
// More details from: http://www.mozilla.org/docs/web-developer/sniffer/browser_type.html
var clientPC = navigator.userAgent.toLowerCase(); // Get client info
var clientVer = parseInt(navigator.appVersion); // Get browser version

var is_ie = ((clientPC.indexOf('msie') != -1) && (clientPC.indexOf('opera') == -1));
var is_win = ((clientPC.indexOf('win') != -1) || (clientPC.indexOf('16bit') != -1));
var is_moz = 0;

var isCtrl = false;


if((!document.getElementById) && document.all)
{
	document.getElementById = function(id){return document.all[id];};
}









// Insert at Claret position. Code from
// http://www.faqts.com/knowledge_base/view.phtml/aid/1052/fid/130
function storeCaret(textEl)
{
  if (textEl.createTextRange) textEl.caretPos = document.selection.createRange().duplicate();

}





function bbstyle(pole, bbtag_begin, bbtag_end)
{
  var txtarea = document.getElementById("message");
  var theSelection = '';

  txtarea.focus();

//  alert (clientVer + ' ' + is_ie + ' ' + is_win);
  if ((clientVer >= 4) && is_ie)
  {
    theSelection = document.selection.createRange().text; // Get text selection
    if (theSelection)
    {
 //     alert('1');
      // Add tags around selection
      document.selection.createRange().text = bbtag_begin + theSelection + bbtag_end;
      txtarea.focus();
      theSelection = '';
      return;
    }
    else
    {

        mozWrap(txtarea, bbtag_begin, bbtag_end);
        return;
    }
  }
  else //if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
  {
//  alert('3');
    mozWrap(txtarea, bbtag_begin, bbtag_end);
    return;
  }
  storeCaret(txtarea);
}








// From http://www.massless.org/mozedit/
function mozWrap(txtarea, open, close)
{
  var txtArea = document.getElementById("message");
 // alert('tudy2');

  if (txtArea.selectionEnd && (txtArea.selectionEnd - txtArea.selectionStart > 0) )
  {
    var preString = (txtArea.value).substring(0,txtArea.selectionStart);
    var newString = open + (txtArea.value).substring(txtArea.selectionStart,txtArea.selectionEnd) + close;
    var postString = (txtArea.value).substring(txtArea.selectionEnd);
    txtArea.value = preString + newString + postString;
    txtArea.focus();
  }
  else
  {

    if (!isNaN(txtArea.selectionStart))
  	{
   //   alert('tudy');

  		var offset = txtArea.selectionStart;
  		var preString = (txtArea.value).substring(0,offset);
      var newString = open + close;
      var postString = (txtArea.value).substring(offset);
      txtArea.value = preString + newString + postString;
      txtArea.selectionStart = offset + open.length;
      txtArea.selectionEnd = offset + close.length;
      txtArea.focus();
  	}
    else
    {
   //   alert('tudy3');

  		txtArea.focus();
		  sel = document.selection.createRange();
		  sel.text = open + close;

  /*
      var preString = (txtArea.value).substring(0,caret_pos);
      var newString = open + close;
      var postString = (txtArea.value).substring(caret_pos);
      txtArea.value = preString + newString + postString;
  	*/

    }
  }


// modifikace na zaklade kodu http://codingforums.com/archive/index.php?t-68882.html

/*
  var selLength = txtarea.textLength;
  var selStart = txtarea.selectionStart;
  var selEnd = txtarea.selectionEnd;
  if (selEnd == 1 || selEnd == 2)
  selEnd = selLength;

  var s1 = (txtarea.value).substring(0,selStart);
  var s2 = (txtarea.value).substring(selStart, selEnd)
  var s3 = (txtarea.value).substring(selEnd, selLength);
  txtarea.value = s1 + open + s2 + close + s3;
*/
  return;

}


/*
End of code from PHPBB Project
*/













function getObj(name)
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
  	this.style = document.getElementById(name).style;
  	this.innerHTML=document.getElementById(name).innerHTML;
  }
  else if (document.all)
  {
  	this.obj = document.all[name];
  	this.style = document.all[name].style;
  	this.innerHTML=document.all[name].innerHTML;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
	  this.innerHTML=document.layers[name].innerHTML;
  }
}









function saveMod(nomid, forumid, topicid, username)
{
	    var req = null;
	    targ = document.getElementById("modSpan_" + nomid);

      if (window.XMLHttpRequest)
      {
          req = new XMLHttpRequest();
          if (req.overrideMimeType)
          {
              req.overrideMimeType('text/xml');
          }
      }
      else if (window.ActiveXObject)
      {
          try
          {
              req = new ActiveXObject("Msxml2.XMLHTTP");
          }
          catch (e)
          {
              try
              {
                  req = new ActiveXObject("Microsoft.XMLHTTP");
              }
              catch (e)
  						{
  						}
          }
      }

      req.onreadystatechange = function()
      {
          if(req.readyState == 4)
          {
              if(req.status == 200)
              {
                  targ.innerHTML = req.responseText;

              }
              else
              {
                  alert("Error: returned status code " + req.status + " " + req.statusText);
              }
          }
      };

      req.open("POST", "http://forum.valka.cz/action/saveMod.php", true);
      req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=windows-1250");
      req.send("nomid=" + nomid + "&forumid=" + forumid + "&topicid=" + topicid + "&username=" + username);

}











function Nominuj(id)
{
		var x = new getObj('nominator');
		x.style.display = "block";

    var currentOffset = x.scrollTop || document.body.scrollTop; // body for Safari
//    alert (currentOffset);

		if (ns6)
		{
			x.style.left = (document.body.scrollLeft + 400)+'px'; //e.clientX+document.body.scrollLeft;
			x.style.top = (currentOffset + 400)+'px';
		} else
		{
			x.style.pixelLeft = (document.body.scrollLeft + 400); //event.clientX+document.body.scrollLeft;
			x.style.pixelTop = (currentOffset + 400);
		}
		document.nominatorForm.nomid.value=id;
		document.nominatorForm.nomnazev.value="";
		document.nominatorForm.nomanotace.value="";
}













function saveNominator()
{
	    var req = null;

      if (window.XMLHttpRequest)
      {
          req = new XMLHttpRequest();
          if (req.overrideMimeType)
          {
              req.overrideMimeType('text/xml');
          }
      }
      else if (window.ActiveXObject)
      {
          try
          {
              req = new ActiveXObject("Msxml2.XMLHTTP");
          }
          catch (e)
          {
              try
              {
                  req = new ActiveXObject("Microsoft.XMLHTTP");
              }
              catch (e)
  						{
  						}
          }
      }

      req.onreadystatechange = function()
      {
          if(req.readyState == 4)
          {
              if(req.status == 200)
              {
                  alert(req.responseText);

              }
              else
              {
                  alert("Error: returned status code " + req.status + " " + req.statusText);
              }
          }
      };

  req.open("POST", "http://forum.valka.cz/action/saveNominator.php", true);
  req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=windows-1250");

  req.send("nomid=" + document.getElementById("nomid").value + "&nomnazev=" + encodeURIComponent(document.getElementById("nomnazev").value) + "&nomanotace=" + encodeURIComponent(document.getElementById("nomanotace").value));
	var x = new getObj('nominator');
	x.style.display = "none";

}










function HideNominator()
{
		var x = new getObj('nominator');
		x.style.display="none";
}











function upAll(postid, topicid)
{
	    var req = null;
	    //targ = document.getElementById("modSpan_" + nomid);

      if (window.XMLHttpRequest)
      {
          req = new XMLHttpRequest();
          if (req.overrideMimeType)
          {
              req.overrideMimeType('text/xml');
          }
      }
      else if (window.ActiveXObject)
      {
          try
          {
              req = new ActiveXObject("Msxml2.XMLHTTP");
          }
          catch (e)
          {
              try
              {
                  req = new ActiveXObject("Microsoft.XMLHTTP");
              }
              catch (e)
            	{
            	}
          }
      }

      req.onreadystatechange = function()
      {
          if(req.readyState == 4)
          {
              if(req.status == 200)
              {
                  alert(req.responseText);

              }
              else
              {
                  alert("Error: returned status code " + req.status + " " + req.statusText);
              }
          }
      };

  req.open("POST", "http://forum.valka.cz/action/moveFirst.php", true);
  req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=windows-1250");
  req.send("postid=" + postid + "&topicid=" + topicid);

}









function upOne(postid, topicid)
{
	    var req = null;
	    //targ = document.getElementById("modSpan_" + nomid);

      if (window.XMLHttpRequest)
      {
          req = new XMLHttpRequest();
          if (req.overrideMimeType)
          {
              req.overrideMimeType('text/xml');
          }
      }
      else if (window.ActiveXObject)
      {
          try
          {
              req = new ActiveXObject("Msxml2.XMLHTTP");
          }
          catch (e)
          {
              try
              {
                  req = new ActiveXObject("Microsoft.XMLHTTP");
              }
              catch (e)
            	{
            	}
          }
      }

      req.onreadystatechange = function()
      {
          if(req.readyState == 4)
          {
              if(req.status == 200)
              {
                  alert(req.responseText);

              }
              else
              {
                  alert("Error: returned status code " + req.status + " " + req.statusText);
              }
          }
      };

  req.open("POST", "http://forum.valka.cz/action/movePrev.php", true);
  req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=windows-1250");
  req.send("postid=" + postid + "&topicid=" + topicid);

}









function downOne(postid, topicid)
{
	    var req = null;
	    //targ = document.getElementById("modSpan_" + nomid);

      if (window.XMLHttpRequest)
      {
          req = new XMLHttpRequest();
          if (req.overrideMimeType)
          {
              req.overrideMimeType('text/xml');
          }
      }
      else if (window.ActiveXObject)
      {
          try
          {
              req = new ActiveXObject("Msxml2.XMLHTTP");
          }
          catch (e)
          {
              try
              {
                  req = new ActiveXObject("Microsoft.XMLHTTP");
              }
              catch (e)
            	{
            	}
          }
      }

      req.onreadystatechange = function()
      {
          if(req.readyState == 4)
          {
              if(req.status == 200)
              {
                  alert(req.responseText);

              }
              else
              {
                  alert("Error: returned status code " + req.status + " " + req.statusText);
              }
          }
      };

  req.open("POST", "http://forum.valka.cz/action/moveNext.php", true);
  req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=windows-1250");
  req.send("postid=" + postid + "&topicid=" + topicid);

}









function ShowDynamicLinkator()
{
    //alert(document.body.scrollTop);
    topVal = document.body.scrollTop+100;
    jQuery("#linkator1").css({left:100,top:topVal});

		var req = null;

        if (window.XMLHttpRequest)
        {
            req = new XMLHttpRequest();
            if (req.overrideMimeType)
            {
                req.overrideMimeType('text/xml');
            }
        }
        else if (window.ActiveXObject)
        {
            try
            {
                req = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e)
            {
                try
                {
                    req = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e)
				{
				}
            }
        }

        req.onreadystatechange = function()
        {
            if(req.readyState == 4)
            {
                if(req.status == 200)
                {
                    //document.getElementById('linkator').innerHTML  = req.responseText;
                    jQuery('#linkator1_content').empty();
                    jQuery('#linkator1_content').append(req.responseText);
                }
                else
                {
                    jQuery('#linkator1_content').empty();
                    jQuery('#linkator1_content').append("<P>Error: returned status code " + req.status + " " + req.statusText + "</P>");

                    //document.getElementById('linkator').innerHTML="Error: returned status code " + req.status + " " + req.statusText;
                }
            }
        };

    var txtarea = document.getElementById("message");

    if ((clientVer >= 4) && is_ie && is_win)
		{
			theSelection = document.selection.createRange().text; // Get text selection
			if (theSelection)
			{
		                req.open("GET", "http://forum.valka.cz/action/getLink.php?searchstr=" + encodeURIComponent(theSelection), true);
        				   req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        				   req.send(null);

			}
		}
		else if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
		{
			var selLength = txtarea.textLength;
			var selStart = txtarea.selectionStart;
			var selEnd = txtarea.selectionEnd;
			if (selEnd == 1 || selEnd == 2)
				selEnd = selLength;
			var s2 = (txtarea.value).substring(selStart, selEnd)

			//
	             req.open("GET", "http://forum.valka.cz/action/getLink.php?searchstr=" + encodeURIComponent(s2), true);
       				 req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		             req.send(null);

		}

		else if (window.getSelection())
		{
			theSelection = window.getSelection(); // Get text selection
			if (theSelection)
			{
					req.open("GET", "http://forum.valka.cz/action/getLink.php?searchstr=" + encodeURIComponent(theSelection), true);
       				req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		            req.send(null);
			}
		}
		else
		{

		}
        return false;
}




function PlaceFlag(vlajka)
{
    var puvodni = cil.getSelection();
    var cilovy = puvodni.text + vlajka;

    cil.replaceSelection(cilovy, true)
		jQuery("#vlajkator2").hide();
		return;
}







function switchKey(obj)
{
	document.oncontextmenu 	= (obj.checked) ? ItemSelMenu : null;
}









function HideDynamicLinkator()
{
//		var x = new getObj('linkator');
//		x.style.display="none";
}







function MakeLink(link)
{
	var txtarea = document.prispevek.message;

	var scrollTop = txtarea.scrollTop;
  var scrollLeft = txtarea.scrollLeft;

	if ((clientVer >= 4) && is_ie && is_win)
	{
		theSelection = document.selection.createRange().text; // Get text selection
		if (theSelection)
    {
			// Add tags around selection
			document.selection.createRange().text = "[url=" + link  + "]" + theSelection + "[/url]";
			txtarea.focus();
			theSelection = '';
			HideDynamicLinkator();
      txtarea.scrollTop = scrollTop;
      txtarea.scrollLeft = scrollLeft;
			return;
		}
		else
		{
				mozWrap(txtarea, "[url=" + link  + "]", "[/url]");
		    HideDynamicLinkator();
        txtarea.scrollTop = scrollTop;
        txtarea.scrollLeft = scrollLeft;
		    return;
    }
	}
	else //if (txtarea.selectionEnd && (txtarea.selectionEnd - txtarea.selectionStart > 0))
	{
		mozWrap(txtarea, "[url=" + link  + "]", "[/url]");
		HideDynamicLinkator();
    txtarea.scrollTop = scrollTop;
    txtarea.scrollLeft = scrollLeft;
		return;
	}
}







// POP UP MENU
function	ItemSelMenu(e)
{
/*
	var	obj = ns6 ? e.target.parentNode : event.srcElement.parentElement;
    menuSelObj = obj ;
	var x = new getObj('linkator');
	x.style.display = "block";
	if (ns6)
	{
		x.style.left = 100 //e.clientX+document.body.scrollLeft;
		x.style.top = e.clientY+document.body.scrollTop+10;
	} else
	{
		x.style.pixelLeft = 100 //event.clientX+document.body.scrollLeft;
		x.style.pixelTop = event.clientY+document.body.scrollTop+10;
	}
	ShowDynamicLinkator();
*/

  jQuery("#linkator1").show();
  ShowDynamicLinkator();
	isMenu = true;
	return false ;
}







// POP UP MENU
function ItemSelMenuKey(e)
{
/*
	var	obj = ns6 ? e.target.parentNode : event.srcElement.parentElement;

    menuSelObj = obj ;
	var x = new getObj('linkator');
	x.style.display = "block";
	if (ns6)
	{
		x.style.left = 100 //e.clientX+document.body.scrollLeft;
		x.style.top = e.clientY+document.body.scrollTop+10;
	} else
	{
		x.style.pixelLeft = 100 //event.clientX+document.body.scrollLeft;
		x.style.pixelTop = event.clientY+document.body.scrollTop+10;
	}
	ShowDynamicLinkator();
*/
  jQuery("#linkator1").show();

    ShowDynamicLinkator();
	isMenu = true;
	return false;
}






function findPos(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent)
	{
	do
	{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
	}
	while (obj = obj.offsetParent);
	}
	return curtop;
}









function ItemSelMenuPause(e)
{

  jQuery("#linkator1").show();
  ShowDynamicLinkator();

/*
	var	obj = ns6 ? e.target.parentNode : event.srcElement.parentElement;

    menuSelObj = obj ;
	var x = new getObj('linkator');
	x.style.display = "block";
	if (ns6)
	{
		x.style.left = 100 //e.clientX+document.body.scrollLeft;
		x.style.top = findPos(document.getElementById("message")) +50;
	} else
	{
		x.style.pixelLeft = 100 //event.clientX+document.body.scrollLeft;
		x.style.pixelTop = findPos(document.getElementById("message"))+50;
	}
	ShowDynamicLinkator();
	*/
	isMenu = true;
	return false;
}





function ShowEdit(id)
{

	targ = document.getElementById("editSpan_" + id);

	var req = null;

	if (window.XMLHttpRequest)
	{
		req = new XMLHttpRequest();
		if (req.overrideMimeType)
		{
			req.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject)
	{
		try
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
			}
		}
	}

	req.onreadystatechange = function()
	{
		if(req.readyState == 4)
		{
			if(req.status == 200)
			{
				targ.innerHTML  = req.responseText;
			}
			else
			{
				alert("Error: returned status code " + req.status + " " + req.statusText);
		 	}
		}
	};

	editSpan = targ;
	req.open("GET", "http://forum.valka.cz/action/getEdit.php/id/" + id + "/akt/" + Math.random(), true);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(null);

}



function ShowEditArchive(id)
{

	targ = document.getElementById("editSpan_" + id);

	var req = null;

	if (window.XMLHttpRequest)
	{
		req = new XMLHttpRequest();
		if (req.overrideMimeType)
		{
			req.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject)
	{
		try
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
			}
		}
	}

	req.onreadystatechange = function()
	{
		if(req.readyState == 4)
		{
			if(req.status == 200)
			{
				targ.innerHTML  = req.responseText;
			}
			else
			{
				alert("Error: returned status code " + req.status + " " + req.statusText);
		 	}
		}
	};

	editSpan = targ;
	req.open("GET", "http://forum.valka.cz/action/getEditArchive.php/id/" + id + "/akt/" + Math.random(), true);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(null);

}







function saveEdit(id)
{
	var req = null;

	if (window.XMLHttpRequest)
	{
		req = new XMLHttpRequest();
		if (req.overrideMimeType)
		{
			req.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject)
	{
		try
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
			}
		}
	}

	req.onreadystatechange = function()
	{
		if(req.readyState == 4)
		{
			if(req.status == 200)
			{
				editSpan.innerHTML  = req.responseText;
//				targ = document.getElementById("editTitle_" + id);
//				starg = document.getElementById("forwardTitle_" + id);
//				targ.innerHTML = starg.innerHTML;
			}
			else
			{
				alert("Error: returned status code " + req.status + " " + req.statusText);
		 	}
		}
	};

	req.open("POST", "http://forum.valka.cz/action/saveEdit.php", true);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	//Content-Type: text/html; charset=ISO-8859-4
//	alert( replaceAmp( document.getElementById("mytextarea1").value ) );
 	//alert(Utf8.encode(document.getElementById("message").value));
 	//alert(encodeURIComponent(document.getElementById("message").value));
	req.send("eid=" + document.getElementById("eid").value + "&message=" + (encodeURIComponent(document.getElementById("message").value)));

}



function cancelEdit(id)
{
	var req = null;

	if (window.XMLHttpRequest)
	{
		req = new XMLHttpRequest();
		if (req.overrideMimeType)
		{
			req.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject)
	{
		try
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
			}
		}
	}

	req.onreadystatechange = function()
	{
		if(req.readyState == 4)
		{
			if(req.status == 200)
			{
				editSpan.innerHTML  = req.responseText;
//				targ = document.getElementById("editTitle_" + id);
//				starg = document.getElementById("forwardTitle_" + id);
//				targ.innerHTML = starg.innerHTML;
			}
			else
			{
				alert("Error: returned status code " + req.status + " " + req.statusText);
		 	}
		}
	};

	req.open("GET", "http://forum.valka.cz/action/cancelEdit.php?eid=" + id, true);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send("id=" + id);

}







function doPreview()
{
	var req = null;

  document.getElementById("nahled").innerHTML  = '';

	if (window.XMLHttpRequest)
	{
		req = new XMLHttpRequest();
		if (req.overrideMimeType)
		{
			req.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject)
	{
		try
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
			}
		}
	}

	req.onreadystatechange = function()
	{
		if(req.readyState == 4)
		{
			if(req.status == 200)
			{
				  document.getElementById("nahled").innerHTML  = req.responseText;
//				targ = document.getElementById("editTitle_" + id);
//				starg = document.getElementById("forwardTitle_" + id);
//				targ.innerHTML = starg.innerHTML;
			}
			else
			{
				alert("Error: returned status code " + req.status + " " + req.statusText);
		 	}
		}
	};

	req.open("POST", "http://forum.valka.cz/action/showPreview.php", true);
	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send("message=" + encodeURIComponent(document.getElementById("message").value));

}


function KeyCheck(e)
{

/*
  if (!e) var e = window.event;
  var targ;
  if (e.target) targ = e.target.id;
	else if (e.srcElement) targ = e.srcElement.id;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode.id;
  
  cil = jQuery('#'+targ); 
*/

  
   cil = jQuery('#message'); 

   var KeyID = (window.event) ? event.keyCode : e.keyCode;
   switch(KeyID)
   {
 	  case 19:  // zmacknuta PAUSE
	  ItemSelMenuPause(e);
	  return true;
    
    case 3:// CTRL+PAUSE


          //alert(document.body.scrollTop);
          jQuery("#vlajkator2").show();
          topVal = document.body.scrollTop+100;
          jQuery("#vlajkator2").css({left:100,top:topVal});
      
      		var req = null;
      
              if (window.XMLHttpRequest)
              {
                  req = new XMLHttpRequest();
                  if (req.overrideMimeType)
                  {
                      req.overrideMimeType('text/xml');
                  }
              }
              else if (window.ActiveXObject)
              {
                  try
                  {
                      req = new ActiveXObject("Msxml2.XMLHTTP");
                  }
                  catch (e)
                  {
                      try
                      {
                          req = new ActiveXObject("Microsoft.XMLHTTP");
                      }
                      catch (e)
      				{
      				}
                  }
              }
      
              req.onreadystatechange = function()
              {
                  if(req.readyState == 4)
                  {
                      if(req.status == 200)
                      {
                          //document.getElementById('linkator').innerHTML  = req.responseText;
                          jQuery('#vlajkator2_content').empty();
                          jQuery('#vlajkator2_content').append(req.responseText);
                      }
                      else
                      {
                          jQuery('#vlajkator2_content').empty();
                          jQuery('#vlajkator2_content').append("<P>Error: returned status code " + req.status + " " + req.statusText + "</P>");
      
                          //document.getElementById('linkator').innerHTML="Error: returned status code " + req.status + " " + req.statusText;
                      }
                  }
              };
      
            req.open("GET", "http://forum.valka.cz/action/getCountry.php", true);
            req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
            req.send(null);
            return true;

    case 77:
      if ((window.event) ? event.ctrlKey : e.ctrlKey)
      {
        showKonverzator();
      }
    return true;
    case 188:
      if ((window.event) ? event.ctrlKey : e.ctrlKey)
      {
        showKronikator();
      }
   }
   return false;
}


function NahrajZemi()
{
	jQuery('#zeme').clear();
  jQuery('#zeme').loadJsonOptions('http://forum.valka.cz/action/getContinent.php?c='+jQuery('#kontinent').val()+'&akt='+ Math.random());
}

function NahrajStaty()
{
   	var req = null;
    if (window.XMLHttpRequest)
    {
        req = new XMLHttpRequest();
        if (req.overrideMimeType)
        {
            req.overrideMimeType('text/xml');
        }
    }
    else if (window.ActiveXObject)
    {
        try
        {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
        		{
        		}
        }
    }

    req.onreadystatechange = function()
    {
        if(req.readyState == 4)
        {
            if(req.status == 200)
            {
                jQuery('#staty').empty();
                jQuery('#staty').append(req.responseText);
            }
            else
            {
                jQuery('#staty').empty();
                jQuery('#staty').append("<P>Error: returned status code " + req.status + " " + req.statusText + "</P>");
            }
        }
    };

    req.open('GET', 'http://forum.valka.cz/action/getCountryDetails.php?z='+jQuery('#zeme').val()+'&akt='+ Math.random(), true);
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    req.send(null);
}




function SaveLinkator(userid, stav)
{

	    var req = null;

                if (window.XMLHttpRequest)
                {
                    req = new XMLHttpRequest();
                    if (req.overrideMimeType)
                    {
                        req.overrideMimeType('text/xml');
                    }
                }
                else if (window.ActiveXObject)
                {
                    try
                    {
                        req = new ActiveXObject("Msxml2.XMLHTTP");
                    }
                    catch (e)
                    {
                        try
                        {
                            req = new ActiveXObject("Microsoft.XMLHTTP");
                        }
                        catch (e)
						{
						}
                    }
                }

                req.onreadystatechange = function()
                {
                    if(req.readyState == 4)
                    {
                        if(req.status == 200)
                        {
                            document.getElementById('linkatorSave').innerHTML  = req.responseText;
                        }
                        else
                        {
                            document.getElementById('linkatorSave').innerHTML="Error: returned status code " + req.status + " " + req.statusText;
                        }
                    }
                };


	req.open("GET", "http://forum.valka.cz/action/saveLink.php/u/" + userid + "/stav/" + stav + "/akt/" + Math.random(), true);
  req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	req.send(null);

	if (stav==1)
 	{
	 	document.getElementById('linkvolba').checked = true;
	}
   	else
	{
		document.getElementById('linkvolba').checked = false;
	}
	switchKey(document.getElementById('linkvolba'));

}


function getTemplate(templ_id)
{
  var req = null;

  if (confirm(dotaz))
  {

  	if (window.XMLHttpRequest)
  	{
  		req = new XMLHttpRequest();
  		if (req.overrideMimeType)
  		{
  			req.overrideMimeType('text/xml');
  		}
  	}
  	else if (window.ActiveXObject)
  	{
  		try
  		{
  			req = new ActiveXObject("Msxml2.XMLHTTP");
  		}
  		catch (e)
  		{
  			try
  			{
  				req = new ActiveXObject("Microsoft.XMLHTTP");
  			}
  			catch (e)
  			{
  			}
  		}
  	}


  	req.onreadystatechange = function()
  	{
  		if(req.readyState == 4)
  		{

  			if(req.status == 200)
  			{
//  				alert(req.responseText);
  				document.getElementById("message").value  = req.responseText;
  			}
  			else
  			{
  				alert("Error: returned status code " + req.status + " " + req.statusText);
  		 	}
  		}
  	};

  	req.open("GET", "http://forum.valka.cz/action/getTemplate.php/m/"+templ_id, true);
  	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  	req.send(null);
  }
  //alert("NEPotvrzeno");
}


/**
 *
 * @access public
 * @return void
 **/
function addField(zdroj, cislo)
{
	document.getElementById("hodnota_0_"+cislo).value = (document.getElementById("hodnota_0_"+cislo).value)*1 + 1;
	pocitadlo = document.getElementById("hodnota_0_"+cislo).value;
	hodnota = "<BR><input type=text size=2 name=hodnota_A_" + cislo + "_" + pocitadlo + " id=hodnota_A_" + cislo + "_" + pocitadlo + " value='DD'>.";
	hodnota = hodnota + "<input type=text size=2 name=hodnota_B_" + cislo + "_" + pocitadlo + " id=hodnota_B_" + cislo + "_" + pocitadlo + " value='MM'>.";
	hodnota = hodnota + "<input type=text size=4 name=hodnota_C_" + cislo + "_" + pocitadlo + " id=hodnota_C_" + cislo + "_" + pocitadlo + " value='RRRR'>";
	hodnota = hodnota + " - <input type=text size=2 name=hodnota_D_" + cislo + "_" + pocitadlo + " id=hodnota_D_" + cislo + "_" + pocitadlo + " value='DD'>.";
	hodnota = hodnota + "<input type=text size=2 name=hodnota_E_" + cislo + "_" + pocitadlo + " id=hodnota_E_" + cislo + "_" + pocitadlo + " value='MM'>.";
	hodnota = hodnota + "<input type=text size=4 name=hodnota_F_" + cislo + "_" + pocitadlo + " id=hodnota_F_" + cislo + "_" + pocitadlo + " value='RRRR'>";
	hodnota = hodnota + "<input type=text size=30 name=hodnota_G_" + cislo + "_" + pocitadlo + " id=hodnota_G_" + cislo + "_" + pocitadlo + " value='text'>";
	zdroj.append(hodnota);
	return false;
}


function getTemplate2(templ_id)
{
  var req = null;

  if (confirm(dotaz))
  {

  	if (window.XMLHttpRequest)
  	{
  		req = new XMLHttpRequest();
  		if (req.overrideMimeType)
  		{
  			req.overrideMimeType('text/xml');
  		}
  	}
  	else if (window.ActiveXObject)
  	{
  		try
  		{
  			req = new ActiveXObject("Msxml2.XMLHTTP");
  		}
  		catch (e)
  		{
  			try
  			{
  				req = new ActiveXObject("Microsoft.XMLHTTP");
  			}
  			catch (e)
  			{
  			}
  		}
  	}


  	req.onreadystatechange = function()
  	{
  		if(req.readyState == 4)
  		{

  			if(req.status == 200)
  			{
//  				alert(req.responseText);
  				document.getElementById("formular_sablona").innerHTML  = req.responseText;
  			}
  			else
  			{
  				alert("Error: returned status code " + req.status + " " + req.statusText);
  		 	}
  		}
  	};

  	req.open("GET", "http://forum.valka.cz/action/getTemplate2.php/m/"+templ_id, true);
  	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  	req.send(null);
  }
  //alert("NEPotvrzeno");
}


function getFlags()
{
  var req = null;

  	if (window.XMLHttpRequest)
  	{
  		req = new XMLHttpRequest();
  		if (req.overrideMimeType)
  		{
  			req.overrideMimeType('text/xml');
  		}
  	}
  	else if (window.ActiveXObject)
  	{
  		try
  		{
  			req = new ActiveXObject("Msxml2.XMLHTTP");
  		}
  		catch (e)
  		{
  			try
  			{
  				req = new ActiveXObject("Microsoft.XMLHTTP");
  			}
  			catch (e)
  			{
  			}
  		}
  	}


  	req.onreadystatechange = function()
  	{
  		if(req.readyState == 4)
  		{

  			if(req.status == 200)
  			{
  				document.getElementById("vlajky").innerHTML  = req.responseText;
  			}
  			else
  			{
  				alert("Error: returned status code " + req.status + " " + req.statusText);
  		 	}
  		}
  	};

  	req.open("GET", "http://forum.valka.cz/action/getFlags.php", true);
  	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  	req.send(null);
}

function getSmilies()
{
  var req = null;

  	if (window.XMLHttpRequest)
  	{
  		req = new XMLHttpRequest();
  		if (req.overrideMimeType)
  		{
  			req.overrideMimeType('text/xml');
  		}
  	}
  	else if (window.ActiveXObject)
  	{
  		try
  		{
  			req = new ActiveXObject("Msxml2.XMLHTTP");
  		}
  		catch (e)
  		{
  			try
  			{
  				req = new ActiveXObject("Microsoft.XMLHTTP");
  			}
  			catch (e)
  			{
  			}
  		}
  	}


  	req.onreadystatechange = function()
  	{
  		if(req.readyState == 4)
  		{

  			if(req.status == 200)
  			{
  				document.getElementById("smajliky").innerHTML  = req.responseText;
  			}
  			else
  			{
  				alert("Error: returned status code " + req.status + " " + req.statusText);
  		 	}
  		}
  	};

  	req.open("GET", "http://forum.valka.cz/action/getSmilies.php", true);
  	req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  	req.send(null);
}

function showKonverzator()
{
  window.open("http://forum.valka.cz/action/konverzator.html", "_blank", "width=300,height=150,menubar=no,location=no,resizable=no,toolbar=no,top=200,left=200");
  return true;
}


function showKronikator()
{
  window.open("http://forum.valka.cz/posting_chronicle.php", "_blank", "width=1000,height=500,scrollbars=yes,menubar=no,location=no,resizable=no,toolbar=no,top=200,left=200");
  return true;
}




function convertLat(vstup_neosetreno)
{
  //horizontalni
  //57°26'42.25"N
  //var vysledek = vstup_neosetreno.substr(4,4);
  //alert(vysledek);
  vstup = vstup_neosetreno.replace("'", "'");
  vstup_neosetreno = vstup.replace("’", "'");
  vstup = vstup_neosetreno.replace("”", "\"");

  if ((vstup.indexOf("°") >= 0) && (vstup.indexOf("'") >= 0) && (vstup.indexOf('"') >= 0))
  {
  
    var pomocna1 = vstup.split("°");
    var stupne = pomocna1[0];
    var pomocna2 = pomocna1[1].split("'");
    var minuty = pomocna2[0];
    var pomocna3 = pomocna2[1].split("\"");
    var vteriny = pomocna3[0];
    var severjih = pomocna3[1];
   
    var sekundy_celkem = (minuty*60) + (vteriny*1);
    var zlomek = (sekundy_celkem / 3600);
    var vysledek = (stupne*1) + zlomek;
    if (severjih=="S")
    {
      vysledek = -1 * vysledek;
    }
    return vysledek;

  }
  else if ((vstup.indexOf("°") >= 0) && (vstup.indexOf(".") >= 0) && (vstup.indexOf('"') <= 0) && (vstup.indexOf("'") <= 0))
  {
    vysledek = vstup.replace("°", "");
    return vysledek;  
  }  
  else if ((vstup.indexOf("°") <= 0) && (vstup.indexOf(".") >= 0) && (vstup.indexOf('"') <= 0) && (vstup.indexOf("'") <= 0))
  {
    vysledek = vstup;
    return vysledek;  
  }  
  
}


function convertLon(vstup_neosetreno)
{
  //vertikalni
  //17°05'23.52"E

    vstup = vstup_neosetreno.replace("'", "'");
    vstup_neosetreno = vstup.replace("’", "'");
    vstup = vstup_neosetreno.replace("”", "\"");

  if ((vstup.indexOf("°") >= 0) && (vstup.indexOf("'") >= 0) && (vstup.indexOf('"') >= 0))
  {
 
    var pomocna1 = vstup.split("°");
    var stupne = pomocna1[0];
    var pomocna2 = pomocna1[1].split("'");
    var minuty = pomocna2[0];
    var pomocna3 = pomocna2[1].split("\"");
    var vteriny = pomocna3[0];
    var vychodzapad = pomocna3[1];
    
    var sekundy_celkem = (minuty*60) + (vteriny*1);
    //alert(sekundy_celkem);
    var zlomek = (sekundy_celkem / 3600);
    var vysledek = (stupne*1) + zlomek;
    if (vychodzapad=="W")
    {
      vysledek = -1 * vysledek;
    }
    return vysledek;      
  }
  else if ((vstup.indexOf("°") >= 0) && (vstup.indexOf(".") >= 0) && (vstup.indexOf('"') <= 0) && (vstup.indexOf("'") <= 0))
  {
    vysledek = vstup.replace("°", "");
    return vysledek;  
  }  
  else if ((vstup.indexOf("°") <= 0) && (vstup.indexOf(".") >= 0) && (vstup.indexOf('"') <= 0) && (vstup.indexOf("'") <= 0))
  {
    vysledek = vstup;
    return vysledek;  
  }  


  
}


var vstupni = '';



function mapsLoaded() {
  //alert(hodnota);
  var koordinaty = jQuery(vstupni).html();
  var rozdeleni = koordinaty.split(" ");
  var coordinat_x = rozdeleni[0];
  var coordinat_y = rozdeleni[1];


  var map = new google.maps.Map2(document.getElementById("map"));
  map.setMapType(G_HYBRID_MAP);
  map.setCenter(new google.maps.LatLng(convertLat(coordinat_x), convertLon(coordinat_y)), 8);
  map.addControl(new GSmallMapControl());
  map.addControl(new GMapTypeControl());
  var point = new GLatLng(convertLat(coordinat_x), convertLon(coordinat_y));
  marker = new GMarker(point);
  map.addOverlay(marker);
}

function ShowMap(vstup) 
{

  jQuery("#map1").show();
  topVal = document.body.scrollTop+100;
  jQuery("#map1").css({left:100,top:topVal});

  vstupni = "#" + vstup; // 
  google.load("maps", "2", {"callback" : mapsLoaded});
}

function isEmpty( inputStr ) 
{ 
  return !(inputStr&&inputStr.length) 
}




document.onkeyup = KeyCheck;

switchKey(document.getElementById('linkvolba'));






