function vytvorFlash(menomovie, width, height, id)
{
    //flesh = document.getElementById(kde);
    //flesh.innerHTML +=
    document.writeln("<object type='application/x-shockwave-flash' data='"+menomovie+"' width='"+width+"' height='"+height+"' id='"+id+"'><param name='movie' value='"+menomovie+"'><param name='quality' value='high'><param name='wmode' value='transparent'></object>");
}

function vytvorFlashInElement(menomovie, width, height, id, eId)
{
    flesh = document.getElementById(eId);
    flesh.innerHTML = "<object type='application/x-shockwave-flash' data='"+menomovie+"' width='"+width+"' height='"+height+"' id='"+id+"'><param name='movie' value='"+menomovie+"' /><param name='quality' value='high' /><param name='wmode' value='transparent' /><param name='allowFullScreen' value='true' /><param name='allowScriptAccess' value='always' /></object>";
}

function showPlayer(movie, playlist, width, height)
{
  document.writeln("<object type='application/x-shockwave-flash' data='"+movie+"?playlist_url="+playlist+"&autoload=true' width='"+width+"' height='"+height+"' id='player'>");
  document.writeln("<param name='movie' value='"+movie+"?playlist_url="+playlist+"&autoload=true' />");
  document.writeln("<param name='quality' value='high' />");
  document.writeln("</object>");
}

function showVideoplayer(movie, file, img, width, height)
{
  document.writeln("<object type='application/x-shockwave-flash' data='"+movie+"?file="+file+"&image="+img+"&width="+width+"&height="+height+"' width='"+width+"' height='"+height+"' id='player'>");
  document.writeln("<param name='movie' value='"+movie+"?file="+file+"&image="+img+"&width="+width+"&height="+height+"' />");
  document.writeln("<param name='quality' value='high' />");
  document.writeln("<param name='allowfullscreen' value='true' />");
  document.writeln("</object>");
}

function showSpan(parent,e,w,h)
{
    var imageSpan = document.getElementById(parent);
    var moz = false;
    //mouse position
  	var posx = 0;
  	var posy = 0;
  	if (!e) var e = window.event;
  	if (e.pageX || e.pageY) 	{
  		posx = e.pageX;
  		posy = e.pageY;
  	}
  	else if (e.clientX || e.clientY) 	{
  		posx = e.clientX + document.body.scrollLeft
  			+ document.documentElement.scrollLeft;
  		posy = e.clientY + document.body.scrollTop
  			+ document.documentElement.scrollTop;
  	}
    if (e.layerX || e.layerY) {
      posx = e.layerX;
      posy = e.layerY;
      moz = true;
    }
    
  	// posx and posy contain the mouse position relative to the document
    if (posx > (w+20)) 
      posx = posx-(w+20);
    else
      posx = posx+20;
    if (posy > (h+20)) 
      posy = posy-(h+20);
    else
      posy = posy+20;
    
    imageSpan.style.display = "block";
    if (moz) {
      imageSpan.style.top = posy+"px";
      imageSpan.style.left = posx+"px";
    } else {
      imageSpan.style.top = posy;
      imageSpan.style.left = posx;
    }
}

function hideSpan(parent)
{
    var imageSpan = document.getElementById(parent);
    imageSpan.style.display = "none";
    //var imageSpan = parent.getElementsByTagName('span');
    //imageSpan[0].style.display = "none";
}

function hideMe(self)
{
    self.style.display = "none";
}

function showMe(parent)
{
    var imageSpan = document.getElementById(parent);
    imageSpan.style.display = "block";
}

function setValue(value, elementId) {
  var element = document.getElementById(elementId);
  element.value = value;
}

function urlencode_bad(str)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = str;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};

function urldecode(str)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = str;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
};

function createRequestObject() {
    var request_o;
    var browser = navigator.appName;
  	if(browser == "Microsoft Internet Explorer") {
  		request_o = new ActiveXObject("Microsoft.XMLHTTP");
  	} else {
  		request_o = new XMLHttpRequest();
  	}
  	return request_o;
}

function httpGET(url) {
	http.open('get', url);
	http.onreadystatechange = handleResults;
	http.send(null);
}

function handleResults() {
  var element = document.getElementById(printInto);
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4) {
		var response = http.responseText;
		element.innerHTML = response;
		var responses = response.split("\n");
		for(i=0;i<=responses.length-1;i++) {
		  if (responses[i]) {
		    if ((responses[i].search(".swf")>0) || (responses[i].indexOf("()")>0) || (responses[i].indexOf("\";")>0) || (responses[i].indexOf(");")>0))
		      eval(responses[i]);
		  }
    }
	}
}

function ukazSajtu(url,title) {
    httpGET(url);
    if (title) {
      window.location.hash = title;
      var dHead  = document.getElementsByTagName("head");
      var dTitle = dHead[0].getElementsByTagName("title");
      dTitle[0].innerHTML = "Samuel Tomeček&Free Inna Cage &bull; "+title;
    } 
}

function klikni(id) { 
    var link = document.getElementById(id);
    var index = navigator.userAgent.indexOf("Mozilla");
		if (index == -1)
		  link.click();
		else
      link.onclick();
} 

function posliForm(url, namesList) {
    var variabls = '';
    for (i=0;i<=namesList.length-1;i++) {
      if (namesList[i]) {
        if (variabls!='') variabls += '&';
        variabls += namesList[i][0]+"="+escape(namesList[i][1]);
      }
    }
    httpGET(url+'?'+variabls); 
}

function spracujForm(actionUrl, formName) {
    var formElements = document.forms[formName].elements;
    var formFields = new Array();
    for (i=0;i<=formElements.length-1;i++) {
      formFields[i] = [formElements[i].name,formElements[i].value];
    }
    //formFields[formElementName] = formElementValue;
    posliForm(actionUrl, formFields);
}

function maPresmerujNa(naHash) {
    var dHead  = document.getElementsByTagName("head");
    var dTitle = dHead[0].getElementsByTagName("title");
    var sajt   = naHash.substr(1,naHash.length);
    if (sajt!="")
      dTitle[0].innerHTML = "Samuel Tomeček&Free Inna Cage &bull; "+sajt; 
    if (sajt=="samuel" || sajt=="lucas" || sajt=="jacque")
      httpGET("bio.php?kto="+sajt);
    if (sajt=="ezo")
      httpGET("bio.php?kto=chzezo");
    if (sajt=="foto" || sajt=="video" || sajt=="audio")
      httpGET("media.php?typ="+sajt);
    if (sajt=="kontakt" || sajt=="koncerty" || sajt=="news" || sajt=="market" || sajt=="bio" || sajt=="guestbook")
      httpGET(sajt+".php");
}

