
/* Funkce inicializuje, registruje posluchace pro udalost */
function init(){
	document.getElementById("accountId").onkeypress = checkKey;
}

/* Obsluha reakce na udalost */
function checkKey(e) {
	if (!e) e = window.event;
	var evt = e || window.event;
	//alert(evt.type);
	//alert('keyCode is ' + evt.keyCode);
	//alert('charCode is ' + evt.charCode);
	if(evt.keyCode==100||evt.charCode==100||evt.keyCode==68||evt.charCode==68){ // stisk tlacitka d/D  (funguje u IE a Firefox)
		deleteValue();
		document.getElementById('output').style.visibility='hidden';
		return false;
	}
	if(evt.keyCode==99||evt.keyCode==67){ // stisk tlacitka c/C	(funguje pouze u IE)
		if(document.getElementById("resultId") && document.getElementById("output") && document.getElementById('output').style.visibility!='hidden'){
			copyToClipb();
		}
		return false;
	}
	document.getElementById('output').style.visibility='hidden';
}

function deleteValue() {
	document.getElementById("accountId").value='';
}


/* Zmeni Currency dle aktualniho nastaveni */
function changeCurrency(firstLoad, euro, sk ) {
	if(!firstLoad) document.getElementById('output').style.visibility='hidden';
	if (document.getElementById("directionSK").checked) {
		document.getElementById("currencyInput").innerHTML = euro;
	} else {
		document.getElementById("currencyInput").innerHTML = sk;
	}
	
	if (!window.clipboardData) {
		document.getElementById('kopirujId').style.visibility = "hidden";
	}
}

/* Funkce ulozi vyslednou hodnotu do Clipboard */
function copyToClipboard(alertCopy) {
		var resume = document.getElementById("resultStrokeId").value;
		if (document.getElementById("pointId").checked) {
			resume = document.getElementById("resultPointId").value;
		}
		window.clipboardData.setData('Text', resume );
		alert(alertCopy + resume );
}


/*	Otevre nove Popup okno */
function openWindowPopup(url,scroll,windowName,resizable) {
	 var heightWindow = 425;
	 var widthWindow = 220;
	 if (!resizable) resizable = "no"
	 if (windowName==null) {
	 	windowName = Math.random() + "";
	 	windowName = windowName.replace(".","x");
	 } else {
	  var ran = Math.random() + "";
	  ran = ran.replace(".","x");
	  /* chceme vzdy nove okno (mnozstvi n)*/
	  //windowName = windowName + ran;
	  /* chceme jen jedno okno (mnozstvi 1)*/
	  windowName = windowName;	 	
	 }
	 	/* na stred*/
	 //poziceTop = (screen.height - heightWindow)/2;
	 //poziceLeft = (screen.width - widthWindow)/2;
	 	
	 	/*vpravo nahoru*/
	 poziceTop = (0 + (50));
	 poziceLeft = (screen.width - (50+widthWindow));

	 var win = window.open(url,windowName,"location=no,scrollbars="+scroll+",resizable="+resizable+",personalbar=no,menubar=no,status=no,toolbar=no,height="+heightWindow+",width="+widthWindow+",left="+poziceLeft+",top="+poziceTop+",screenX=0,screenY=0");  
	 
	 win.focus();
	 
	 return win;
}

function copy_clip(meintext){
	var resume = document.getElementById("resultStrokeId").value;
	if (document.getElementById("pointId").checked) {
		resume = document.getElementById("resultPointId").value;
	}
	if (window.clipboardData) {
		// the IE-way
		window.clipboardData.setData("Text", resume);
		// Probabely not the best way to detect netscape/mozilla.
		// I am unsure from what version this is supported
	} else if (window.netscape) { 
		// This is importent but it's not noted anywhere
		netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
		// create interface to the clipboard
		var clip = Components.classes['@mozilla.org/widget/clipboard;[[[[1]]]]'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;
		// create a transferable
		var trans = Components.classes['@mozilla.org/widget/transferable;[[[[1]]]]'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;
		// specify the data we wish to handle. Plaintext in this case.
		trans.addDataFlavor('text/unicode');
		// To get the data from the transferable we need two new objects
		var str = new Object();
		var len = new Object();
		var str = Components.classes["@mozilla.org/supports-string;[[[[1]]]]"].createInstance(Components.interfaces.nsISupportsString);
		var copytext=resume;
		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);
	}
	alert(meintext + resume );
	return false;
}
