function show_photo(id, w, h, did) {
  if (!w) w = 680;
  if (!h) h = 500;
  obrw = w;
  obrh = h;
  w = w - 5;
  h = h - 5;
  if (screen.width < w + 20) w = screen.width - 20;
  if (screen.height < h + 100) h = screen.height - 100;

  window.open(
    './picture_detail.php?did=' + did + '&obrid=' + id + '&w=' + obrw + '&h=' + obrh,
    'picture_detail',
    'width=' + w + ',height=' + h + ',resizable,statusbar=no').focus();
}

function openwin(url, nazev, w, h) {
 window.open( url, nazev,'scrollbars=0,width=' + w + ',height=' + h + ',top=100,left=250,resizable');
}


function show(obj,name){var result="";for (var i in obj) result += name +"."+ i + " = " + obj[i] + " ";return result;}

function vypocet_vysky() { 
 if (document.getElementById && frames.prispevky) { 
  var vyska_dokum = frames.prispevky.document.body.scrollHeight; 
  vyska_dokum += 10; // přidat spodní okraj 
  if (vyska_dokum < 270) // minimální výka 
  vyska_dokum = 270; 
  document.getElementById('prispevky').style.height = vyska_dokum + 'px';
  if (document.getElementById('prispevky').scrollHeight == (frames.prispevky.document.body.scrollHeight)+10) {
   frames.prispevky.document.body.style.overflow = "hidden";
  } 
 } 
} 

function Vek(a, rok) {
 if (document.getElementById) {
  if (a == 1) {
   absolut = document.getElementById('newclass').absolut.value;
   if (absolut) {
    stari1 = document.getElementById('newclass').stari1.value;
    document.getElementById('newclass').rocnik.value= absolut - stari1; 
	document.getElementById('newclass').stari2.value = rok - document.getElementById('newclass').rocnik.value;
   }
  }
  if (a == 2) {
   datum = Dat_akt();
   stari2 = document.getElementById('newclass').stari2.value;
   document.getElementById('newclass').rocnik.value= datum.getFullYear() - stari2; 
   document.getElementById('newclass').stari1.value = rok - document.getElementById('newclass').rocnik.value;
  }
 }
}

function timeoutReminder(first_reminder) {
    datum = new Date(today_cas);

    if (first_reminder) {
        var msg = datum + msg2;
    } else {
        var msg = datum + msg3;
    }
	pom = new Date(); 
	alert(msg);
	pom2 = new Date();

	rozdil = pom2.getTime()-pom.getTime();

    today_cas += rozdil;
}

function Dat_akt() {
    datum = new Date(today_cas);
    return datum;
}

window.onresize=vypocet_vysky;

function Zavri() {
	document.getElementById('cjid').style.display='none';
}

function Invert(form1) {
	f= document.getElementById(form1);
    e= f.elements;
    st = true;
    var status = false;
    for(i= 0; i<e.length; i++) {
	  pom = e[i];
      if (pom.type=="checkbox") {
        if (st) {
          st = false;
          status = pom.checked;
        }
        if (status) pom.checked= false;
        else pom.checked= true;
      }
	}
}

function GetXmlHttpObject(){
  var xmlHttp=null;

  try{
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  }
  catch(e){
    // Internet Explorer
    try{
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch(e){
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  return xmlHttp;
}

var ajaxide = "";
var ajaxtyp = "";

function stateChanged_x(){
  if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){ 
    var retext = xmlHttp.responseText;
    var ide = ajaxide;
    var typ = ajaxtyp;

    if(document.getElementById(ide)){
      if(typ == "inner") document.getElementById(ide).innerHTML = retext;
      else if(typ == "value") document.getElementById(ide).value = retext;
    }
  }
}

function stateChanged(){
  if(xmlHttp.readyState == 4 || xmlHttp.readyState == "complete"){ 
    var retext = xmlHttp.responseText;
    var ide = ajaxide;
    var typ = ajaxtyp;

    var poletext = retext.split("|");

    if (poletext[0]=="check") {
	  window.location.reload();
    }

	if (poletext.length>2) {
	  pom = "";
	  for(i=1;i<poletext.length;i++){
        pom += poletext[i];
	  }
	  poletext[1] = pom;
	}

    if(document.getElementById(ide)){
      if(typ == "inner") document.getElementById(ide).innerHTML = poletext[1];
      else if(typ == "value") document.getElementById(ide).value = poletext[1];
    }
  }
}

function predej_url(url){
  if(url){
    xmlHttp = GetXmlHttpObject();
    if(xmlHttp==null){
      window.alert("Va prohlížeč nepodporuje HTTP požadavky!");
      return
    } 
    xmlHttp.onreadystatechange = stateChanged;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
  }
}

function predej_url_x(url){
  if(url){
    xmlHttp = GetXmlHttpObject();
    if(xmlHttp==null){
      window.alert("Va prohlížeč nepodporuje HTTP požadavky!");
      return
    } 
    xmlHttp.onreadystatechange = stateChanged_x;
    xmlHttp.open("GET",url,true);
    xmlHttp.send(null);
  }
}

function forum(thisobj,urldid2,clss,ukonceni,skola,runda,vypis,refresh){
    if(document.getElementById(thisobj)){

	  if (urldid2 != "") var url = "ajax-"+thisobj+".php?"+urldid2+"clss="+clss+"&ukonceni="+ukonceni+"&skola="+skola+"&runda="+runda+"&vypis="+vypis+"&"+Date();
	  else var url = "ajax-"+thisobj+".php?clss="+clss+"&ukonceni="+ukonceni+"&skola="+skola+"&runda="+runda+"&vypis="+vypis+"&"+Date();
      var ide = thisobj;
      var typ = "inner";

      ajaxide = ide;
      ajaxtyp = typ;
      predej_url(url);
    }
    else{
      document.getElementById(thisobj).innerHTML = "";
    }
    if (refresh>0) timf = setTimeout("forum('"+thisobj+"','"+urldid2+"','"+clss+"','"+ukonceni+"','"+skola+"','"+runda+"','"+vypis+"','"+refresh+"')",refresh*1000);
}

//forum mimo tridu
function forum_hl(thisobj,urldid2,clss,runda,vypis,refresh){
    if(document.getElementById(thisobj)){

	  if (urldid2 != "") var url = "ajax-"+thisobj+".php?"+urldid2+"clss="+clss+"&runda="+runda+"&vypis="+vypis+"&"+Date();
	  else  var url = "ajax-"+thisobj+".php?clss="+clss+"&runda="+runda+"&vypis="+vypis+"&"+Date();
      var ide = thisobj;
      var typ = "inner";

      ajaxide = ide;
      ajaxtyp = typ;
      predej_url(url);
    }
    else{
      document.getElementById(thisobj).innerHTML = "";
    }
    if (refresh>0) timfhl = setTimeout("forum_hl('"+thisobj+"','"+urldid2+"','"+clss+"','"+runda+"','"+vypis+"','"+refresh+"')",refresh*1000);
}

//vypis lidi ve foru
function forum_vypis(thisobj,urldid2,clss,ukonceni,skola,typ_fora,scrfora){
    if(document.getElementById(thisobj)){

	  if (urldid2 != "") var url = "ajax-"+thisobj+".php?"+urldid2+"clss="+clss+"&ukonceni="+ukonceni+"&skola="+skola+"&typ_fora="+typ_fora+"&scrfora="+scrfora+"&"+Date();
	  else  var url = "ajax-"+thisobj+".php?clss="+clss+"&ukonceni="+ukonceni+"&skola="+skola+"&typ_fora="+typ_fora+"&scrfora="+scrfora+"&"+Date();
      var ide = thisobj;
      var typ = "inner";

      ajaxide = ide;
      ajaxtyp = typ;
      predej_url_x(url);
    }
    else{
      document.getElementById(thisobj).innerHTML = "";
    }
    timv = setTimeout("forum_vypis('"+thisobj+"','"+urldid2+"','"+clss+"','"+ukonceni+"','"+skola+"','"+typ_fora+"','"+scrfora+"')",30*1000);
}

function online(thisobj,urldid2,clss,refresh){
    if(document.getElementById(thisobj)){

	  if (urldid2 != "") var url = "ajax-"+thisobj+".php?"+urldid2+"clss="+clss+"&"+Date();
	  else var url = "ajax-"+thisobj+".php?clss="+clss+"&"+Date();
      var ide = thisobj;
      var typ = "inner";

      ajaxide = ide;
      ajaxtyp = typ;
      predej_url(url);
    }
    else{
      document.getElementById(thisobj).innerHTML = "";
    }
    if (refresh>0) setTimeout("online('"+thisobj+"','"+urldid2+"','"+clss+"','"+refresh+"')",refresh*1000);
}

function Zavrionline() {
	document.getElementById('privateblock').style.display='none';
}


/*
 * Adjust the behavior of the dataProcessor to avoid styles
 * and make it look like FCKeditor HTML output.
 */
function configureHtmlOutput( ev )
{
	var editor = ev.editor,
		dataProcessor = editor.dataProcessor,
		htmlFilter = dataProcessor && dataProcessor.htmlFilter;

	// Out self closing tags the HTML4 way, like <br>.
	dataProcessor.writer.selfClosingEnd = '>';

	// Make output formatting behave similar to FCKeditor
	var dtd = CKEDITOR.dtd;
	for ( var e in CKEDITOR.tools.extend( {}, dtd.$nonBodyContent, dtd.$block, dtd.$listItem, dtd.$tableContent ) )
	{
		dataProcessor.writer.setRules( e,
			{
				indent : true,
				breakBeforeOpen : true,
				breakAfterOpen : false,
				breakBeforeClose : !dtd[ e ][ '#' ],
				breakAfterClose : true
			});
	}

	// Output properties as attributes, not styles.
	htmlFilter.addRules(
		{
			elements :
			{
				$ : function( element )
				{
					// Output dimensions of images as width and height
					if ( element.name == 'img' )
					{
						var style = element.attributes.style;

						if ( style )
						{
							// Get the width from the style.
							var match = /(?:^|\s)width\s*:\s*(\d+)px/i.exec( style ),
								width = match && match[1];

							// Get the height from the style.
							match = /(?:^|\s)height\s*:\s*(\d+)px/i.exec( style );
							var height = match && match[1];

							if ( width )
							{
								element.attributes.style = element.attributes.style.replace( /(?:^|\s)width\s*:\s*(\d+)px;?/i , '' );
								element.attributes.width = width;
							}

							if ( height )
							{
								element.attributes.style = element.attributes.style.replace( /(?:^|\s)height\s*:\s*(\d+)px;?/i , '' );
								element.attributes.height = height;
							}
						}
					}

					// Output alignment of paragraphs using align
					if ( element.name == 'p' )
					{
						style = element.attributes.style;

						if ( style )
						{
							// Get the align from the style.
							match = /(?:^|\s)text-align\s*:\s*(\w*);/i.exec( style );
							var align = match && match[1];

							if ( align )
							{
								element.attributes.style = element.attributes.style.replace( /(?:^|\s)text-align\s*:\s*(\w*);?/i , '' );
								element.attributes.align = align;
							}
						}
					}

					if ( !element.attributes.style )
						delete element.attributes.style;

					return element;
				}
			},

			attributes :
				{
					style : function( value, element )
					{
						// Return #RGB for background and border colors
						return convertRGBToHex( value );
					}
				}
		} );
}


/**
* Convert a CSS rgb(R, G, B) color back to #RRGGBB format.
* @param Css style string (can include more than one color
* @return Converted css style.
*/
function convertRGBToHex( cssStyle )
{
	return cssStyle.replace( /(?:rgb\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*\))/gi, function( match, red, green, blue )
		{
			red = parseInt( red, 10 ).toString( 16 );
			green = parseInt( green, 10 ).toString( 16 );
			blue = parseInt( blue, 10 ).toString( 16 );
			var color = [red, green, blue] ;

			// Add padding zeros if the hex value is less than 0x10.
			for ( var i = 0 ; i < color.length ; i++ )
				color[i] = String( '0' + color[i] ).slice( -2 ) ;

			return '#' + color.join( '' ) ;
		 });
}


