

/**
 * doplnkove metody k inlinepopups
 */ 
Dalen.expandIframe = function(iframeObj, additionalHeight) {
   var additivum = additionalHeight > 0 ? additionalHeight : 0; 
   iframeObj.height = iframeObj.contentWindow.document.body.offsetHeight + additivum;
}

Dalen.getIframeContentHeight = function(iframeObj, additionalHeight) {
   var additivum = additionalHeight > 0 ? additionalHeight : 0; 
   return iframeObj.contentWindow.document.body.offsetHeight + additivum;
}

/**
 * applets hide/show
 */ 
function hideApplets()
{
   if ($('Scribbler')) {
      $('Scribbler').setStyle({display:'none'});
   }
   if ($('Signer')) {
      $('Signer').setStyle({display:'none'});
   }
}

function showApplets()
{
   if ($('Scribbler')) {
      $('Scribbler').show();
   }
   if ($('Signer')) {
      $('Signer').show();
   }
}

/**
 * veci tykajici se stavu registrace
 */ 
function checkStavRegId(regNumEl)
{
   var regNum = regNumEl.value;
   var exp = "^[0-9\+]{0,10}$";
   if (regNum.match(exp)) {
      oldRegNum = regNum;
   } else {
      regNumEl.value = oldRegNum;
   }
   
   if (10 == regNumEl.value.length) {
      stavRegFirma(regNumEl.value);
   } else {
      $('ajaxFirma').innerHTML = '';
   }
}

function stavRegFirma(regNum)
{
   url = startUrl+'public-ajax/showstavregfirma/';
   params = 'regNum='+regNum;
   stavRegFirmaAjaxUpdater(url, params);
}

function stavRegFirmaAjaxUpdater(url, params)
{
   var opt = {
      method: 'post',
      postBody: params,
      onSuccess: function(t) {
      },
      onCreate: function(t) {
          showloading();
      },
      on404: function(t) {
          alert('Error 404: location "' + t.statusText + '" was not found.');
      },
      onFailure: function(t) {
          alert('Error ' + t.status + ' -- ' + t.statusText);
      }
   }
   new Ajax.Updater('ajaxFirma', url, opt);
}

function showloading()
{
   $('ajaxFirma').innerHTML = 'loading...';
}

/**
 * --------------------------
 * kontrola formularu - nemelo by se uz pouzivat
 * -------------------------- 
 */
var req = new Array();
var reqnames = new Array();
var cReg = 0;
var not = new Array();
var notnames = new Array();
var cNot = 0;
 
function addRequiredField(field, fieldText)
{
   req[cReg] = $(field);
   reqnames[cReg] = fieldText;
   cReg++;
}

function addNotedField(field, fieldText)
{
   not[cNot] = $(field);
   notnames[cNot] = fieldText;
   cNot++;
}

function checkForm(formEl)
{
   alert('fu');
   var valid = false;
   for (var i=0,length = req.length; i < length; i++) {
      if ('' == req[i].value) {
         req[i].style.border = '1px solid red';
         req[i].style.background = '#ffafaf';
         alert(translate.mitonform.required + ' ' + reqnames[i] + '!');
         req[i].focus();
         return false;
      } else {
         valid = true;
      }
   }
   for (var ino=0,length = not.length; ino < length; ino++) {
      if ('' == not[ino].value) {
         not[ino].style.border = '1px solid green';
         not[ino].style.background = '#afffaf';
         if (confirm(translate.mitonform.recommend_start + ' ' + notnames[ino] + translate.mitonform.recommend_end)) {
            valid = true;
         } else {
            not[ino].focus();
            valid = false;
         }
      }
   }
   if (valid) {
      if (validFormHTML()) {
         formEl.submit();
      }
   }
}

/**
 * korekce ciselneho vstupu
 */
var oldCorrectText = '';

function setFirstCorrectText(inputElement)
{
   oldCorrectText = $(inputElement).value;
}

function correctNumberInput(inputElement, type)
{
   var text = $(inputElement).value;
   if ('rc' == type) {
      var exp = "^[0-9\+]{0,10}$";
   } else {
      var exp = "^[0-9]*$";
   }
   if (text.match(exp)) {
      oldCorrectText = text;
   } else {
      $(inputElement).value = oldCorrectText;
   }
}

function numberToMoney(num)
{
   return new Number(num).numberFormat('### ### ### ### ###').strip();
}

function moneyToNumber(num)
{
   return num.replace(' ', '');
}

