function openWin(target, name, width, height, center) {
  if (NavYes) {
      width += 10;
      height += 30;
  }

  ypos = (screen.height - height) / 2;
  xpos = (screen.width - width) / 2;

  if (OprYes || (center && screen.height <= 600)) {
      ypos = 0;
      xpos = 0;
  }
  features = 'width='+width+',height='+ height+',top='+ypos+',left='+xpos+
                 ',outerWidth='+width+',outerHeight='+height+',screenY='+ypos+',screenX='+ xpos;
  win = window.open(target, name, features);
}
    

function centerTitle() {
    elem = document.getElementById('holder'); 
    winWidth = 0;
    winHeight = 0;
    ypos = 0;
    xpos = 0;
    elemWidth = 400; 
    elemHeight =  30; 
    shiftDown = 110;
    
    if (ExpYes) {
        winWidth = parseInt(document.body.clientWidth);
        winHeight = parseInt(document.body.clientHeight);
    } else {
        winWidth = window.innerWidth;
        winHeight = window.innerHeight;
    }

    ypos = ((winHeight - elemHeight) / 2) + shiftDown;
    xpos = ((winWidth - elemWidth) / 2);
    
    elem.style.top = "" + ypos + "px";
    elem.style.left = "" + xpos + "px";
}


/* swaps image for another image */
function swapImages(imgID, newImg) {
    img1 = document.getElementById(imgID);
    img2 = eval(newImg);
    img1.src = img2.src;
}


function showSubMenu(subMenuID) {
    if (shownSubMenu != 0) {
        shownSubMenu.style.visibility = "hidden";
    }
    if (subMenuID == "") {
        document.getElementById("subEmpty").style.visibility = "visible";
        return;
    }

    document.getElementById("subEmpty").style.visibility = "hidden";
    subMenu = document.getElementById(subMenuID);
    if (OprYes) {
        subMenu.style.top = ""+10+"px";
    }
    subMenu.style.visibility = "visible";
    shownSubMenu = subMenu;
}


/* sets focus on a specific field in the form */
function setFocus() {
    if (!document.forms 
            || (document.forms.length == 0 || !document.forms[0].setFocus)) {
        return;
    }
    field = document.forms[0].setFocus.value;
    if (!document.forms[0].elements[field]) {
        return;
    }
    document.forms[0].elements[field].focus();
    if (document.forms[0].elements[field].type == "text") {
      document.forms[0].elements[field].select();
    }
}


/* splits string into array by separator char */
function split(string, separator) {
    var tokens = new Array();
    var index = 0;
    var tmp = "";

    for (i = 0; i < string.length; i++) {
        if ((i+1) == string.length) {
            tokens[index] = tmp + string.charAt(i);
        }
        
        if (string.charAt(i) == separator) {
            tokens[index++] = tmp;
            tmp = "";
        } else {
            tmp += string.charAt(i);
        }
    }
    return tokens;
}


function justNumeric(ev,dot) {

    /* Get ASCII value of key that user pressed */
    var key = (ExpYes) ? ev.keyCode : ev.which;
    
    /* 
     * Was key that was pressed a numeric character (0-9) or a dot (.) 
     * or enter?
     */
    return ((key > 47 && key < 58) || (key == 46 && dot) 
            || key == 13  
            || key == 0);
}


function checkInt(value) {
    num = value;
    return (!isNaN(parseInt((num * 1))) && value != "" && value != " ");
}

      
function toDecimal(numField) {
    numValue = numField.value;
    mask = /(^\d{1,5}$)|(^\d{1,5},{1}\d{1,2}$)/;
    
    if (numValue.search(mask) == -1) {
        alert("Chybne zadané číslo!");
        //numField.focus();
        return false;
    } else {
        numField.value = numValue.replace(/,/, ".");
    }
    return true;
}


function guestbookSubmitControl() {
    form = document.forms[0];

    if (form.name.value.length < 1 || form.name.value == " ") {
      alert(form.error1.value);
      form.name.focus();
      return false;
    }
    if (form.message.value.length < 2 || form.message.value == " ") {
      alert(form.error2.value);
      form.message.focus();
      return false;
    }

    return true;
}

