function AddFavorite(linkObj,addUrl,addTitle) {
  if (document.all && !window.opera) {
    window.external.AddFavorite(addUrl,addTitle);
    return false;
  }
  else if (window.opera && window.print) {
    linkObj.title = addTitle;
    return true;
  }
  else if ((typeof window.sidebar == 'object') && (typeof window.sidebar.addPanel == 'function')) {
      window.sidebar.addPanel(addTitle,addUrl,'');
      return false;
  }
}

function SetAsHomepage() {
  if (document.all && !window.opera) {
    this.style.behavior='url(#default#homepage)'; 
    this.setHomePage(document.location.href); 
    return false;
  } 
  else {
    window.alert('Váš prohlížeč nepodporuje automatické nastavení této funkce.');
    return false;
  }
}

if (!document.getElementById && document.all) document.getElementById = document.all;

function SetDivBackground(id,image) {
  document.getElementById(id).style.background = 'url('+image+')';
}

function SetDivBackgroundPosition(id,position) {
  document.getElementById(id).style.backgroundPosition = position;
}

function to_clip(copytext) {
  //Inspirace: http://www.krikkit.net/howto_javascript_copy_clipboard.html
  if (window.clipboardData) {
    window.clipboardData.setData("Text", copytext);
  }
  else if (window.netscape) {
    try {
      netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
    }
    catch (e) {
      alert(e);
      alert("Nemáte povoleno kopírování do schránky. Do adresního řádku napište prosím 'about:config' nastavte 'signed.applets.codebase_principal_support' na 'true'");
      return false;
    }
    var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
    if (!clip)
      return;
    var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
    if (!trans)
      return;
    trans.addDataFlavor('text/unicode');
    var str = new Object();
    var  len = new Object();
    var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
    str.data=copytext;
    trans.setTransferData("text/unicode",str,copytext.length*2);
    var clipid=Components.interfaces.nsIClipboard;
    if (!clip) return
      false;
    clip.setData(trans,null,clipid.kGlobalClipboard);
  }
  return true;
}

function from_clip() {
  //Inspirace: http://www.xulplanet.com/tutorials/xultu/clipboard.html
  var pastetext;
  if (window.clipboardData) {
    pastetext = window.clipboardData.getData("Text")
  }
  else if (window.netscape) {
    try {
      netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
    }
    catch (e) {
      alert(e);
      alert("Nemáte povoleno kopírování do schránky. Do adresního řádku napište prosím 'about:config' nastavte 'signed.applets.codebase_principal_support' na 'true'");
      return false;
    }
    var clip = Components.classes["@mozilla.org/widget/clipboard;1"].getService(Components.interfaces.nsIClipboard);
    if (!clip)
      return false;
    var trans = Components.classes["@mozilla.org/widget/transferable;1"].createInstance(Components.interfaces.nsITransferable);
    if (!trans)
      return false;
    trans.addDataFlavor("text/unicode");

    clip.getData(trans,clip.kGlobalClipboard);

    var str = new Object();
    var strLength = new Object();

    trans.getTransferData("text/unicode",str,strLength);
 
    if (str)
      str = str.value.QueryInterface(Components.interfaces.nsISupportsString);
    if (str)
      pastetext = str.data.substring(0,strLength.value / 2);
  }
  return pastetext;
}
  function ajax(stranka, kam) {
    var httpRequest;
   
    if(typeof window.ActiveXObject != 'undefined') {
      httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {  
      httpRequest = new XMLHttpRequest();
    }
    httpRequest.open("GET", stranka, true);
    httpRequest.onreadystatechange= function () { processRequest(httpRequest, kam) };
    httpRequest.send(null);
  }

  function processRequest(httpRequest, kam) {
    if (httpRequest.readyState == 4) {
      if(httpRequest.status == 200) {
        if (typeof kam == 'string') {
          document.getElementById(kam).innerHTML = httpRequest.responseText;
        }
        if (typeof kam == 'function') {
          kam(httpRequest.responseText);
        }
      }
      else {
        //alert("Chyba pri nacitani stanky " + httpRequest.status +" : "+ httpRequest.statusText);
      }
    }
    else {
      if (typeof kam == 'string' && kam != '') {
        document.getElementById(kam).innerHTML = '.';
      }
    }
  } 
  function clearOrigInputValue(id,origValue) {
    if ( document.getElementById(id).value == origValue)
		  document.getElementById(id).value = "";
	}

function checkRules( souhlas,user,email,heslo,heslo2) {
	if (!souhlas.checked) {
	  souhlas.style.backgroundColor='red';
	  souhlas.focus();
		alert('Musíte souhlasit s podmínkami');
		return false;
	}
	else {
	  souhlas.style.backgroundColor='white';
  }

	if (user && user.value.length < 1) {
	  user.style.backgroundColor='red';
	  user.focus();
		alert('Uživatel je povinný');
		return false;
	}
	else {
	  user.style.backgroundColor='white';
  }

	if (email.value.length < 1) {
	  email.style.backgroundColor='red';
	  email.focus();
		alert('Email je povinný');
		return false;
	}
	else {
	  email.style.backgroundColor='white';
  }

	//Pokud jde o update (user je null), nemusi se zadavat heslo
	if (user && heslo.value.length < 1) {
	  heslo.style.backgroundColor='red';
	  heslo.focus();
		alert('Heslo je povinné');
		return false;
	}
	else {
	  heslo.style.backgroundColor='white';
  }
	
	if ( heslo.value.length > 0) {
  	if ( heslo.value.length < 5) {
  		alert('Heslo musí mít alespoň 5 znaků');
  	  heslo.style.backgroundColor='red';
	    heslo.focus();
	  	return false;
  	}
  	else {
  	  heslo.style.backgroundColor='white';
      if ( heslo.value != heslo2.value) {
    	  heslo2.style.backgroundColor='red';
	      heslo2.focus();
    		alert('Heslo a kontrola hesla se musejí shodovat');
	    	return false;
  	  }
    	else {
	      heslo2.style.backgroundColor='white';
      }
  	}
	}

	return true;
}

function streamPublish(name, message,description, hrefTitle, hrefLink, userPrompt){
  FB.ui(
  {
    method: 'stream.publish',
    message: message,
    attachment: {
      name: name,
      caption: '',
      description: (description),
      href: hrefLink
    },
    action_links: [
      { text: hrefTitle, href: hrefLink }
    ],
    user_prompt_message: userPrompt
  },
  function(response) {
  });
}

function addToStream( message,description, hrefTitle, hrefLink, userPrompt){
  FB.api('/me', function(response) {
  //console.log(response.id);
  streamPublish(response.name,
    message, 
    description, 
    hrefTitle, 
    hrefLink, 
    userPrompt);
  });
}

