function selectMenu(value)
{
  if (value)
  {
    document.cookie = 'menu=' + value;
  }
  return true;
}

function $(id)
{
  return document.getElementById(id);
}


function hide(id)
{
  $(id).style.display = 'none';
  return true;
}

function show(id)
{
  $(id).style.display = '';
}

function switchView()
{
  st = $('showTable');
  et = $('editTable');

  if (et.style.display == 'none')
  {
    st.style.display = 'none';
    et.style.display = '';
  }
  else
  {
    et.style.display = 'none';
    st.style.display = '';
  }
  return true;

}

function popup(url, id, w, h, scroll, resize, menubar, titlebar, status, location, toolbar, dir)
{
  win = window.open(
    url, id,
    'toolbar='+toolbar+', titlebar='+titlebar+', menubar='+menubar+', location='+location+', directories='+dir+', status='+status+', width='+w+', height='+h+', scrollbars='+scroll+', resizable='+resize+'',
    false
  );
  win.focus();
}


function authorClose(selectid, value, text, select)
{
  s = window.opener.$(selectid);
  var y=document.createElement('option');
  y.text = text;
  y.value = value;
  y.selected = select;
  s.add(y, null);
  window.opener.focus()
  window.close();
}

function sf()
{
  if (document.vorm.username.value.length == 0)
  {
    document.vorm.username.focus();
  }
  else
  {
    document.vorm.password.focus();
  }
}

window.default_on_submit = function(event)
{
  frm = event.srcElement ? event.srcElement : event.target;
  btnValue = frm.submit_button_value ? frm.submit_button_value.value : '';

  elems = document.getElementsByTagName('INPUT');
  for (i = 0; i < elems.length; i++)
  {
    el = elems[i];
    if (el.type == 'submit' || el.type == 'button')
    {
      el.style.color = 'silver';
      el.disabled = true;
    }
  }
}

window.default_on_click = function(event, ask_confirmation)
{
  if (ask_confirmation)
  {
    if(!confirm('Vajuta OK nġustumiseks')) return false;
  }

  btn = window.event ? window.event.srcElement : event.target;
  if (btn && btn.form)
  {
    el = btn.form.submit_button_value;
    el.name = btn.name;
    el.value = btn.value;
  }
  return true;
}

window.buttonConfirm = function(text)
{
  text = text ? text : 'Vajuta OK nġustumiseks';

  if(!confirm(text)) return false;
}

//--------------------------------------------------------------------------------
function windowFoto(code, title)
{
	if(!title)
	{
	  title = 'Foto';
	}
  var refFoto = window.open(sPageUrl + "picture.php?code="+ code + "&title=" + title, 'Photo', "heigth=500,width=700,top=20,left=20,resizable=yes,scrollbars=yes,status=0;" );
}

function setOrderManFields()
{
  sel = $('method');
  var val = sel.options[sel.selectedIndex].value;

  for (i = 1; i < 10; i++)
  {
    $('f' + i).innerHTML = '';
  }
  cur = $('currency').value;
  fee = parseFloat($('postfee').value);
  sum = parseFloat($('summa').value);

  if (val == 1) // postiga
  {
    $('postfeerow').style.display = '';
    var mandatory = new Array(1, 2, 4, 5, 6, 7, 9);
    sum += fee;
  }
  else
  {
    $('postfeerow').style.display = 'none';
    var mandatory = new Array(1, 2, 7, 9);
  }

  for (i in mandatory)
  {
    $('f' + mandatory[i]).innerHTML = '*';
  }

  $('tdsumma').innerHTML = fix(sum) + ' ' + cur;
}

function fix(f)
{
	f	= f.toString( );
	var re = /\,/gi;
	f	= f.replace( re, "\." );

	f = Math.round( f * 100 );
	f = f.toString( );
	var sMinus = f.slice( 0, 1 );
	if( sMinus == '-' )
	{
	 f = f.slice( 1, f.length )
	}
	else
	 sMinus = '';
	if( f.length < 3 )
	{
		while( f.length < 3 )
			f = '0' + f;
	}

	var w = sMinus + f.slice( 0, f.length-2 ) + "." + f.slice( f.length-2, f.length );

  var poprawnyFloat = /^-?[0-9]{1,}[.]{1}[0-9]{1,}$/i;
	if( w.search( poprawnyFloat ) == -1 )
	{
	  w = '0.00';
	}
	return w;

}