function menu_open(el) {
 if (!document.getElementById && document.all) document.getElementById = document.all;
 if (document.getElementById(el).style.display == 'none') {
  document.getElementById(el).style.display = 'block';
 } else { document.getElementById(el).style.display = 'none'; }
}

function windowopensimple(object, width, height) {
 new_window = window.open(object,'',
                          'width=' + width + ',height=' + height + ',toolbar=no,location=no,' +
                          'directories=no,status=no,menubar=no,scrollbars=yes,resizable=no');
}

function windowopensimple_s(object, width, height) {
 new_window = window.open(object,'new',
                          'width=' + width + ',height=' + height + ',toolbar=yes,location=no,' +
                          'directories=no,status=no,menubar=no,scrollbars=yes,resizable=no');
}

function windowopensimple_n(object, width, height) {
 new_window = window.open(object,'new',
                          'width=' + width + ',height=' + height + ',toolbar=no,location=no,' +
                          'directories=no,status=no,menubar=no,scrollbars=no,resizable=no');
}

function windowopensimple_sr(object, width, height) {
 new_window = window.open(object,'new',
                          'width=' + width + ',height=' + height + ',toolbar=yes,location=no,' +
                          'directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes');
}

function windowopen(object, width, height) {
 new_window = window.open('','new',
                          'width=' + width + ',height=' + height + ',toolbar=no,location=no,' +
                          'directories=no,status=no,menubar=no,scrollbars=no,resizable=no');
                         
 new_window.document.write('<html>');                         
 new_window.document.write(' <body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">'); 
 new_window.document.write(' <a href="javascript:this.window.close();"><img src="' + object + '" border="0" alt="kliknutím okno zavøete"></a>'); 
 new_window.document.write(' </body>'); 
 new_window.document.write('</html>'); 
}

function reloadAclose() {
 opener.location.reload();
 this.window.close();
}

function make_tag(tag) {
   
 var SelectedString = document.selection.createRange().text;
     
 if (SelectedString.length != 0) {
  var ReplaceString = "&+" + tag + SelectedString + "&-" + tag;
  document.selection.createRange().text = ReplaceString;
 } 
}

// funkce prevzata z http://www.breakingpar.com/bkp/home.nsf/Doc?OpenNavigator&U=45A5696524D222C387256AFB0013D850
function replaceSubstring(inputString, fromString, toString) {
   // Goes through the inputString and replaces every occurrence of fromString with toString
   var temp = inputString;
   if (fromString == "") {
      return inputString;
   }
   if (toString.indexOf(fromString) == -1) { // If the string being replaced is not a part of the replacement string (normal situation)
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } else { // String being replaced is part of replacement string (like "+" being replaced with "++") - prevent an infinite loop
      var midStrings = new Array("~", "`", "_", "^", "#");
      var midStringLen = 1;
      var midString = "";
      // Find a string that doesn't exist in the inputString to be used
      // as an "inbetween" string
      while (midString == "") {
         for (var i=0; i < midStrings.length; i++) {
            var tempMidString = "";
            for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
            if (fromString.indexOf(tempMidString) == -1) {
               midString = tempMidString;
               i = midStrings.length + 1;
            }
         }
      } // Keep on going until we build an "inbetween" string that doesn't exist
      // Now go through and do two replaces - first, replace the "fromString" with the "inbetween" string
      while (temp.indexOf(fromString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(fromString));
         var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
         temp = toTheLeft + midString + toTheRight;
      }
      // Next, replace the "inbetween" string with the "toString"
      while (temp.indexOf(midString) != -1) {
         var toTheLeft = temp.substring(0, temp.indexOf(midString));
         var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
         temp = toTheLeft + toString + toTheRight;
      }
   } // Ends the check to see if the string being replaced is part of the replacement string or not
   return temp; // Send the updated string back to the user
} // Ends the "replaceSubstring" function

function make_p() {
   
 var SelectedString = document.selection.createRange().text;
     
 if (SelectedString.length != 0) {

  var SelectedStringNew = "";
  var Addon = "";

  for (i = 0; i < SelectedString.length; i++) {
  
   if (SelectedString.charCodeAt(i) != 10) {
    if (SelectedString.charCodeAt(i) == 13) { Addon = "&+l";
    } else { Addon = ""; }
   
    SelectedStringNew  +=  SelectedString.charAt(i) + Addon;
   }
  } 
 
  var ReplaceString = "&+p&+l" + SelectedStringNew + "&-p";
  document.selection.createRange().text = ReplaceString;
 } 
}

function make_n() {
   
 var SelectedString = document.selection.createRange().text;
     
 if (SelectedString.length != 0) {

  var SelectedStringNew = "";
  var Addon = "";

  for (i = 0; i < SelectedString.length; i++) {
  
   if (SelectedString.charCodeAt(i) != 10) {
    if (SelectedString.charCodeAt(i) == 13) { Addon = "&+l";
    } else { Addon = ""; }
   
    SelectedStringNew  +=  SelectedString.charAt(i) + Addon;
   }
  } 
 
  var ReplaceString = "&+n&+l" + SelectedStringNew + "&-n";
  document.selection.createRange().text = ReplaceString;
 } 
}

function clear_format(input) {
   
 if (input == "opentime") {
	 var SelectedString = document.form.user_opentime.value;
 }
 else if (input == "text") {
	var SelectedString = document.form.page_ptext_b.value; 
 }

 if (SelectedString.length != 0) {
 
	 SelectedString = replaceSubstring(SelectedString, "&+p", "");
	 SelectedString = replaceSubstring(SelectedString, "&-p", "");
	 SelectedString = replaceSubstring(SelectedString, "&+n", "");
	 SelectedString = replaceSubstring(SelectedString, "&-n", "");
	 SelectedString = replaceSubstring(SelectedString, "&+l", "");
	 SelectedString = replaceSubstring(SelectedString, "&+b", "");
	 SelectedString = replaceSubstring(SelectedString, "&-b", "");

	 if (input == "opentime") {
		 document.form.user_opentime.value = SelectedString;
	 }	 
	 else if (input == "text") {
		 document.form.page_ptext_b.value = SelectedString;
	 }
 } 
 
}

function setCookie(name, value, expire) {
	document.cookie = name + "=" + escape(value)   + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}

function getCookie(Name) {
	var search = Name + "="
	if (document.cookie.length > 0)
	{ // if there are any cookies
    	offset = document.cookie.indexOf(search)
		if (offset != -1) { 
			offset += search.length 
			end = document.cookie.indexOf(";", offset)
			if (end == -1)
				end = document.cookie.length
			return unescape(document.cookie.substring(offset, end))
		}
	}
}

function pop_up(url,w,h,cookie)
{
var today = new Date();
var expires = new Date();

if (getCookie(cookie)!="seen"){
window.open(url,'pop_up','width='+w+',height='+h+',scrollbars=no,resizable=no,top=100,left=200');
}
expires.setTime(today.getTime() + 1000*60*30);
setCookie(cookie, "seen", expires);

} 

function pop_up_n(url,w,h)
{
window.open(url,'pop_up','width='+w+',height='+h+',scrollbars=no,resizable=no,top=100,left=200');
} 

function set_mainwindow_name(wnd, name)
{
	wnd.name = name;
}



