/// --- dreamweaver codes --- /////////////////////////////////////////////////////////////////
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function popup(a,msg,look,x,y){ //v1.0.4
  var d=document; if (!a){var ln='pLayer';dx="";dy="";b=(d.layers)?1:0;
    nn=(b||d.getElementById &&!d.all)?1:0;l = new Object();
    l.s=b?d.layers[ln]:MM_findObj(ln).style;l.r=b?d.layers[ln].document:MM_findObj(ln);
    l.w=function (t) {if(b){l.r.write(t);l.r.close()}else l.r.innerHTML=t}
  if(b) d.captureEvents(Event.MOUSEMOVE);d.onmousemove=function(e)
  {dx=(nn)?e.pageX:event.x;dy=(nn)?e.pageY:event.y;}}if (a=='1') {l.s.visibility='hidden'}
  if (a=='2') {l.w('<span class="'+look+'">'+unescape(msg)+'</span>')
  if(d.all) dy=dy+d.body.scrollTop;x=(!x)?50:Number(x);
  y=(!y)?-20:Number(y);l.s.left=dx+x; l.s.top=dy+y;l.s.visibility='visible'}
}
/// --- web page functions --- ////////////////////////////////////////////////////////////////
function setValuesAndSubmit()
{  
  var arg=0;
  formName = setValuesAndSubmit.arguments[arg++]; 
  for(var i=arg; i<setValuesAndSubmit.arguments.length; i+=2) {
//    alert('document.' + formName + '.' + setValuesAndSubmit.arguments[i] + '.value="' + setValuesAndSubmit.arguments[i+1] + '"');
    eval('document.' + formName + '.' + setValuesAndSubmit.arguments[i] + '.value="' + setValuesAndSubmit.arguments[i+1] + '"');
  }
  eval('document.' + formName + '.submit()');
}

function setValues()
{  
  var arg=0;
  formName = setValues.arguments[arg++]; 
  for(var i=arg; i<setValues.arguments.length; i+=2) {
//    alert('document.' + formName + '.' + setValuesAndSubmit.arguments[i] + '.value="' + setValuesAndSubmit.arguments[i+1] + '"');
    eval('document.' + formName + '.' + setValues.arguments[i] + '.value="' + setValues.arguments[i+1] + '"');
  }
//  eval('document.' + formName + '.submit()');
}

function deletes(text, form, variab, value)
{
  if( confirm(text) ) {
  	setValuesAndSubmit(form, variab, value);
  }
}

/// --- email functions --- ///////////////////////////////////////////////////////////////////
function checkall(allbox)
// in the emails form makes checkboxex checked or unchecked. depends on allbox checkbox
{
  var checkstatus;
  if(allbox.checked)
    checkstatus = true;
  else
    checkstatus = false;
  for(var i=0; i<emailerform.elements.length; i++) {  
    var elem = emailerform.elements[i];
    if((elem.name!='allbox') && (elem.type=='checkbox')) {
      elem.checked = checkstatus;
    }
  }
}

function checkit()
// in the emails form checks all checkboxes. than change status on allbox checkbox
{
  var countall=0;
  var countchecked=0;
  for(var i=0; i<emailerform.elements.length; i++) {  
    var elem = emailerform.elements[i];
    if((elem.name!='allbox') && (elem.type=='checkbox') && (elem.value)){
      countall++;
      if(elem.checked)
        countchecked++;
    }
  }
  if(countall==countchecked)
    emailerform.allbox.checked=true;
  else
    emailerform.allbox.checked=false;
}

function countrec()
// counts selected checkboxes or hidden fields (all together are indexes of email recipients)
{
  var count=0;
  for(var i=0; i<emailerform.elements.length; i++) {  
    var elem = emailerform.elements[i];
    if((elem.name!='allbox') && (elem.type=='checkbox') && (elem.value) && (elem.checked))
      count++;
    if((elem.type=='hidden') && (elem.name=='sendmailArr[]'))
      count++;
  }
  return count;
}
function showrec()
{
    window.open("emails_show_rec.php","emails",'status, toolbar=0,location=0,scrollbars=1,width=500,height=200,resizable=0,top=100,left=100');
    window.parent.name="dev";
}
function showrechistory(id)
{
    window.open("emails_rec_history.php?idem="+id,"emailer",'status=0, toolbar=0,location=0,scrollbars=1,width=500,height=200,resizable=0,top=100,left=100');
    window.parent.name="dev";
}



/// --- file upload functions --- ///////////////////////////////////////////////////////////////////
function fileupload(file) {
  url="upload_file.php?type="+file;
  window.open(url,"newfile",'status=0, toolbar=0,location=0,scrollbars=0,width=400,height=200,resizable=1,top=10,left=10');
  window.parent.name="files";
}

function choosevideo() {
  url = "choose_video.php";
  window.open(url,"newfile",'status=0, toolbar=0,location=0,scrollbars=0,width=400,height=200,resizable=1,top=10,left=10');
  window.parent.name="files";
}

/// --- popup window (web) --- /////////////////////////////////////////////////////////////////////////////
function popupwin(file, type, lang)
{
  switch(type) {
    case'video':
      window.open("popup.php?idph=" + file + "&lang=" + lang, "newfile",'status=0, screenX=10, screenY=10, toolbar=0, location=0, scrollbars=1, width=400, height=200, resizable=0');
      break;    
    case'image':
      window.open("image_products2.php?image=" + file, "newfile",'status=0, screenX=10, screenY=10, toolbar=0, location=0, scrollbars=0, width=300, height=300, resizable=0');
      break;    
    case'optipen':
      window.open("popup_optipen.php?image=" + file, "newfile",'status=0, screenX=10, screenY=10, toolbar=0, location=0, scrollbars=0, width=500, height=370, resizable=0');
      break;    
  }
}

function openW(urlW, width_w, height_w, scroll_bar, name){
  center_x = Math.round((window.screen.availWidth - width_w) / 2);
  center_y = Math.round((window.screen.availHeight - height_w) / 2);
  
  window.open(urlW,name,'top=' + center_y + ',left=' + center_x + ',width=' + width_w + ',height=' + height_w + ',status=no,titlebar=no,toolbar=no,menubar=no,location=no,resizable=no,directories=no,scrollbars=' + scroll_bar);
} 
function popupImage(urlW, width_w, height_w, scroll_bar, name){
  center_x = Math.round((window.screen.availWidth - width_w) / 2);
  center_y = Math.round((window.screen.availHeight - height_w) / 2);
  
  window.open('popup_image.php?file='+urlW,name,'top=' + center_y + ',left=' + center_x + ',width=' + width_w + ',height=' + height_w + ',status=no,titlebar=no,toolbar=no,menubar=no,location=no,resizable=no,directories=no,scrollbars=' + scroll_bar);
} 
function popupImageG(urlW, titleW, width_w, height_w, scroll_bar, name){
  center_x = Math.round((window.screen.availWidth - width_w) / 2);
  center_y = Math.round((window.screen.availHeight - height_w) / 2);
  
  window.open('popup_imageG.php?file='+urlW+'&title='+titleW,name,'top=' + center_y + ',left=' + center_x + ',width=' + width_w + ',height=' + height_w + ',status=no,titlebar=no,toolbar=no,menubar=no,location=no,resizable=no,directories=no,scrollbars=' + scroll_bar);
} 
/// --- special --- /////////////////////////////////////////////////////////////////////////////////

function countbmi(formObj)
{
  var w; w = parseInt(formObj.w.value);
  var h; h = parseInt(formObj.h.value);
// alert("weight" + w + " height" + h);
  if(!w || w==0) {
    alert ("Musíte zadať Vašu váhu v kilogramoch!!!");
    formObj.w.focus();
  } else if(!h || h==0) {
    alert ("Musíte zadať Vašu výšku v centimetroch!!!");
    formObj.h.focus();
  } else {
    var bmi;
    bmi =  w/((h*h)/10000);
    bmi = Math.round(bmi*100)/100;
    var start = "Index hmotnosti je ";
    if(bmi < 18.5) {
      bmitext = start + "<b>" + bmi + "</b>.<br /><b>príliš nízka hmotnosť</b>";
    } else if(bmi < 25) {
      bmitext = start + "<b>" + bmi + "</b>.<br /><b>normálna váha</b>";
    } else if(bmi < 30) {
      bmitext = start + "<b>" + bmi + "</b>.<br /><b>nadváha</b>";
    } else if(bmi < 35) {
      bmitext = start + "<b>" + bmi + "</b>.<br /><b>obezita</b>";
    } else if(bmi < 40) {
      bmitext = start + "<b>" + bmi + "</b>.<br /><b>veľká obezita</b>";
    } else if(bmi > 40) {
      bmitext = start + "<b>" + bmi + "</b>.<br /><b>klinická obezita</b>";
    }
    bmispan.innerHTML = bmitext;
  }
}

function copyTextTo(objTo, objFrom) {
	objTo.innerHTML = nl2br(objFrom.value, 100);
}

function nl2br(text, x) {
  var i;
  for(i=0; i<x; i++) {
    text = text.replace(/\n/, "<br>");
  }
  return text;
}

function countInvoicePrice(amountObj) {
  var amount;
  var xvat;
  var xtotal;
  
  amount = amountObj.value;
  var pos = amount.indexOf(",");
  if(pos>=0) {
    amount = amount.replace(",", ".");
  }
  amount = parseFloat(amount);
  
  vatObj = amountObj.form.vat;
  xvat = Math.round(amount*19)/100;
  xvat = xvat.toString();
  vatObj.value = xvat.replace(".", ",");
  
  totalObj = amountObj.form.total;
  xtotal = Math.round(amount*119)/100;
  xtotal = xtotal.toString();
  totalObj.value = xtotal.replace(".", ",");
}


