function objGet(x) {
   if (typeof x != 'string') return x;
   else if (Boolean(document.getElementById))
      return document.getElementById(x);
   else if (Boolean(document.all))
      return eval('document.all.'+x);
   else if (Boolean(document.ids))
      return eval('document.ids.'+x);
   else
      return null;
}

  function openWindow(url){
    wasOpen  = false;
    win = window.open(url);    
    return (typeof(win)=='object')?true:false;
  }
  function openWindowSize(url,popis,width,height){
    wasOpen  = false;
    win = window.open(url,popis,'width='+width+',height='+height+',resizable=1');    
    return (typeof(win)=='object')?true:false;
  }

function openWindow2(url,width,height) {
	window.open(url,'popis','width='+width+',height='+height+',scrollbars=1');
}

/*********RODOKMEN*********/
var bRodokmen = false;
s_Text1 = 'Zobrazit jednoduchý rodokmen'
s_Text2 = 'Zobrazit rozšířený rodokmen'
function vytvorOdkazRodokmen() {
  var novy_odkaz = document.createElement("a"); 
  var obsah_odkazu = document.createTextNode(s_Text1);
  novy_odkaz.setAttribute("href", "#");
  novy_odkaz.id = "id_odkazu";
  novy_odkaz.onclick  = ZmenaOdkazu;
  novy_odkaz.appendChild(obsah_odkazu);
  var body = document.getElementById("odkaz");
  body.appendChild(novy_odkaz);
} 
function ZmenaOdkazu()
{
	var oRodokmen = document.getElementsByTagName("div")
	for (var i = 0; i < oRodokmen.length; i++) {
		if(oRodokmen[i].className=='r-full')
		{
			oRodokmen[i].className='r-none'
		}
		else if(oRodokmen[i].className=='r-none')
		{
			oRodokmen[i].className='r-full'
		}

	}
	
	var oRodokmen = document.getElementsByTagName("strong")
	for (var i = 0; i < oRodokmen.length; i++) {
		if(oRodokmen[i].className=='j-full')
		{
			oRodokmen[i].className='j-none'
		}
		else if(oRodokmen[i].className=='j-none')
		{
			oRodokmen[i].className='j-full'
		}

	}
	

	if(bRodokmen)
	{
		document.getElementById('id_odkazu').firstChild.data=s_Text1;
		bRodokmen = false;
	}
	else
	{
		document.getElementById('id_odkazu').firstChild.data=s_Text2;
		bRodokmen = true;
	}
	return false;
}
/*********RODOKMEN*********/



/*KALENDAR*/

function ShowCalendar(iYear, iMonth)
{
	var element = objGet("KalendarAJAX");
	while (element.firstChild) {
		element.removeChild(element.firstChild);
	}
	var element = objGet("OpenFolder");
	while (element.firstChild) {
		element.removeChild(element.firstChild);
	}
	
	if(objGet("KalendarAJAX").style.display=="none")
	{
	objGet("KalendarAJAX").style.display="block"
	CalendarMove(iYear, iMonth)
	
	var obsah_odkazu = document.createTextNode("Zavřít kalendář");
	var span = document.createElement("span");
	span.appendChild(obsah_odkazu);
	
	objGet("OpenFolder").appendChild(span);

	
	
	}
	else
	{
	objGet("KalendarAJAX").style.display="none"
	var obsah_odkazu = document.createTextNode("Otevřít kalendář");
	var span = document.createElement("span");
	span.appendChild(obsah_odkazu);
	objGet("OpenFolder").appendChild(span);
	}
	
	
}


function CalendarMove(iYear, iMonth)
{
	url = "/kalendar.asp?Year="+iYear+"&Month="+iMonth
	if (url != 0)
    {

       	if (window.ActiveXObject)
		{
			httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
		}
		else
		{
			httpRequest = new XMLHttpRequest();
		}
		httpRequest.open("GET", url, true);
        httpRequest.onreadystatechange= function () {processRequest(); } ;
   	    httpRequest.send(null);
	}
	//timerID=setTimeout("fceScore('"+url+"')",10000);
}


function processRequest()
{
	var iReturn
	iReturn = 0

	if (httpRequest.readyState == 4)
	{
		if(httpRequest.status == 200)
		{
			s_Score = httpRequest.responseText;

			objGet("KalendarAJAX").innerHTML = s_Score;
			
			
			arrScore = s_Score.split(';');
			sDomaci = ""
			sHoste = ""
			if(arrScore.length==3){
				sDomaci = arrScore[0];
				sHoste = arrScore[1];
				iTabule = arrScore[2];
				
				var s_Domaci = document.createTextNode(sDomaci);
				var s_Hoste = document.createTextNode(sHoste);
				
				var element = objGet("Domaci");
				while (element.firstChild) {
				  element.removeChild(element.firstChild);
				}

				var element = objGet("Hoste");
				while (element.firstChild) {
				  element.removeChild(element.firstChild);
				}
				
				
				objGet("Domaci").appendChild(s_Domaci);
				objGet("Hoste").appendChild(s_Hoste);
				
				
				if(iTabule==1)
				{
//					objGet("Tabule").innerText = "";
//					var novy_odkaz = document.createElement("a"); 
//					var obsah_odkazu = document.createTextNode("»» SCOREBOARD ««");
//					novy_odkaz.setAttribute("href", "#");
//					novy_odkaz.onclick  = OpenTable;
//					novy_odkaz.appendChild(obsah_odkazu);
//					var body = document.getElementById("Tabule");
//					body.appendChild(novy_odkaz);

				}
				else
				{
//					objGet("Tabule").innerText = "»» SCOREBOARD ««"
				}
				
			}
	    }
    	else
	    {
//    	    alert("Chyba pri nacitani stanky "+ httpRequest.status +":"+ httpRequest.statusText);
	    }
	}
}


/*KALENDAR*/


function insertTag(startTag, endTag, id) {
		var myField=document.getElementById(id);
		//IE support
		if (document.selection) {
			myField.focus();
			sel = document.selection.createRange();
			sel.text = startTag+sel.text+endTag;
			myField.focus();
		}
		//MOZILLA/NETSCAPE support
		else if (myField.selectionStart || myField.selectionStart == '0') {
			var startPos = myField.selectionStart;
			var endPos = myField.selectionEnd;
			myField.value = myField.value.substring(0, startPos)
                      + startTag 
                      + myField.value.substring(startPos, endPos)
                      + endTag
                      + myField.value.substring(endPos, myField.value.length);
			myField.focus();
			myField.selectionStart = startPos + startTag.length;
			myField.selectionEnd = endPos + startTag.length;
		} else {
			myField.value += myValue;
			myField.focus();
		}
	}
