// Jscript library by cORe



window.onload = function() {
 	// hack opravující rozdílnou interpretaci mezi centrováním backgrnd obrázku na absolute elementech 
	// a margin 0px auto centrováním relative elementů při liché šířce obrazovky
	if (document.body.clientWidth || document.body.clientHeight){ 
		docwidth = document.body.clientWidth; 
		docheight = document.body.clientHeight; 
		
		var oMain = document.getElementById("main");
		var oHeader = document.getElementById("header");
		var oFooter = document.getElementById("footer");			
		
		if (docwidth%2 > 0) { 
			if (navigator.appName != "Microsoft Internet Explorer") {		
				oHeader.style.marginLeft='-1px';
				oFooter.style.marginLeft='-1px';
				oMain.style.marginLeft='-1px';	
			}
		} else {
			if (navigator.appName != "Microsoft Internet Explorer") {		
				oHeader.style.marginLeft='0px';
				oFooter.style.marginLeft='0px';
				oMain.style.marginLeft='0px';	
			}
		}
	} 
  
}

window.onresize = function() {
	if (document.body.clientWidth || document.body.clientHeight){ 
		docwidth = document.body.clientWidth; 
		docheight = document.body.clientHeight; 
		
		var oMain = document.getElementById("main");
		var oHeader = document.getElementById("header");
		var oFooter = document.getElementById("footer");			
		
		if (docwidth%2 > 0) { 
			if (navigator.appName != "Microsoft Internet Explorer") {		
				oHeader.style.marginLeft='-1px';
				oFooter.style.marginLeft='-1px';
				oMain.style.marginLeft='-1px';	
			}
		} else {
			if (navigator.appName != "Microsoft Internet Explorer") {		
				oHeader.style.marginLeft='0px';
				oFooter.style.marginLeft='0px';
				oMain.style.marginLeft='0px';	
			}
		}
	} 
}

function submitDialog() { 				
	oCheck = window.confirm("Uložit změny ?");
	if (oCheck) {
		return true;		
	} else {
		return false;
	}
} 
function submitClick() { 				
	oCheck = window.confirm("Opravdu chcete tuto položku smazat ?");
	if (oCheck) {
		return true;		
	} else {
		return false;
	}
} 
function submitClickGroup() { 				
	oCheck = window.confirm("Obsah této kategorie bude navždy smazán. Opravdu chcete tuto položku smazat ? ");
	if (oCheck) {
		return true;		
	} else {
		return false;
	}
} 

function jumpMenu(targ,selObj){
	eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
}
function jumpRadio(targ,selObj){
	eval(targ+".location='"+selObj.value+"'");
}
function jumpImg(targ, url){
	eval(targ+".location='"+url+"'");
}

function enableArea(Id) {
	var oArea = document.getElementById(Id);
		if (oArea.getAttribute("disabled") == "disabled") { 
			oArea.removeAttribute("disabled");	
		} else {
			oArea.setAttribute("disabled", "disabled");	
		}
}

function attachFile() 
{ 		
		var oVyber = document.getElementById("soubory");
		var oNewFile = document.createElement("input"); 
			oNewFile.setAttribute("type", "file");
			oNewFile.setAttribute("size", "30");			
			oNewFile.setAttribute("name", "soubor[]");			
			oVyber.appendChild(oNewFile);	
} 

function showSeznam() { 				
var oFoto = document.getElementById("seznam-galerie");
     if (oFoto.style.display=='none'){
	     oFoto.style.display='';
     } else {
     	 oFoto.style.display='none';
     }			
			
} 
function hide() {
	var element = document.getElementById("vyhledej");
	if (element.style.display == 'none') {
		element.style.display = 'block';
	} else {
		element.style.display = 'none';
	} 
}

function getRandomNum() {

    // between 0 - 1
    var rndNum = Math.random()

    // rndNum from 0 - 1000
    rndNum = parseInt(rndNum * 1000);

    // rndNum from 33 - 127
    rndNum = (rndNum % 94) + 33;

    return rndNum;
}

function checkPunc(num) {

    if ((num >=33) && (num <=47)) { return true; }
    if ((num >=58) && (num <=64)) { return true; }
    if ((num >=91) && (num <=96)) { return true; }
    if ((num >=123) && (num <=126)) { return true; }

    return false;
}

function GeneratePassword() {

    var length= 8;
    var sPassword = "";
    var noPunction = true;

   for (i=0; i < length; i++) {
        numI = getRandomNum();
		if (noPunction) { while (checkPunc(numI)) { numI = getRandomNum(); } }
        sPassword = sPassword + String.fromCharCode(numI);
    }

    var input = document.getElementById("uzpassword");
		input.value = sPassword

    return true;
}