
function rollForm(checkbox) {
    copy = new Array ('Address', 'City', 'Zip');
    for (i=0; i<copy.length; i++) {
        shipping = document.getElementById('form' + copy[i]);
        invoice = document.getElementById('form' + copy[i] + 'Invoice');
        if (invoice.value == '') invoice.value = shipping.value;
    }
    fieldset = document.getElementById('invoice');
    if (checkbox.checked) fieldset.style.display = 'block';
    else fieldset.style.display = 'none';
}

function popup(what) {
    window.open(what, "guide", "status=0, height=400, width=325, resizable=0, left=600, top=150");
    return false;
}

function only_numeric(entry, id_span)
{
  if(document.getElementById)
    MyOut=document.getElementById(id_span);
  if(document.all)
    MyOut=document.all[id_span];
  
  if(entry.value.search(/[^0-9]/g)!= -1)
  {
    entry.value=entry.value.replace(/[^0-9]/g,'');
    if(MyOut!=null)
    	MyOut.style.display="";
  }
  else
  {
  	if(MyOut!=null)
    	MyOut.style.display="none";
  }
}

function only_digit(entry, id_span)
{
  if(document.getElementById)
    MyOut=document.getElementById(id_span);
  if(document.all)
    MyOut=document.all[id_span];
  
  if(entry.value.search(/[^0-9]/g)!= -1)
  {
    entry.value=entry.value.replace(/[^0-9]/g,'');
    if(MyOut!=null)
    	MyOut.style.display="";
  }
  else
  {
  	if(MyOut!=null)
    	MyOut.style.display="none";
  }
}

function isCzechPhoneNumber(phone)
{
    if(phone.match(/^[0-9]{9}$/)==null && phone.match(/^\+420[0-9]{9}$/)==null)
    {
        return false;
    }
    else
    {
        return true;
    }
}

function getCheckedValue(radioObj) {
  if(!radioObj)
    return "";
  var radioLength = radioObj.length;
  if(radioLength == undefined)
  if(radioObj.checked)
    return radioObj.value;
  else
    return "";
  for(var i = 0; i < radioLength; i++) {
    if(radioObj[i].checked) {
      return radioObj[i].value;
    }
  }
  return "";
}

function getSelectedValue(select) {
    var index = select.selectedIndex;
    if ((index >= 0) && (index < select.length)) {
      return select.options[index].value;
    }
    return '';
}

function getSelected(select) {
    var index = select.selectedIndex;
    if ((index >= 0) && (index < select.length)) {
      return select.options[index];
    }
    return '';
}

function setCheckedValue(radioObj, newValue) {
    if(!radioObj) return;
    var radioLength = radioObj.length;
    if(radioLength == undefined) {
        radioObj.checked = (radioObj.value == newValue.toString());
        return;
    }
    for(var i = 0; i < radioLength; i++) {
        radioObj[i].checked = false;
        if(radioObj[i].value == newValue.toString()) {
            radioObj[i].checked = true;
        }
    }
}

function setListValue(list, newValue) {
    var i=0;
    while ((i < list.options.length) && (list.options[i].value != newValue))
        {i++;}
    if (i < list.options.length)
        {list.selectedIndex = i;}
}


/**
 * Funkce nastaví zvolenou hodnotu listboxu jako "selected"
 * @tparam int id ID číslo listboxu
 * @tparam int val Hodnota, která má být nastavena jako "selected"
 */
function dropdownSet(id, val)
{
	// Nalezení hledaného listboxu
	var element=document.getElementById(id);
	if(element!=null)
	{
		// Procházení všech prvků listboxu a hledání dané hodnoty
		for( var i=0, limit=element.options.length; i < limit; ++i )
		{
			if( element.options[i].value==val )
				element.options[i].selected=true;
			else
				element.options[i].selected=false;
		}
	}
}



