// Form validation functions

function searchValid(theForm)
{
  if (document.layers == null)
  {
    var error = "";
    error += (theForm.SearchFor.value == "") ? "Vinsamlega slįšu inn leitarorš.\n" : "";
    if (error != "") {
      alert(error);
      return false;
    }
    return true;
  }
}


function contactValid(theForm)
{
  if (document.layers == null)
  {
    var error = "";
    error += (theForm.author.value == '') ? "Vinsamlega slįšu inn nafn.\n" : "";
    // error += checkEmail(theForm.email.value);
    error += (theForm.url.value == '') ? "Vinsamlega slįšu inn veffang.\n" : "";
    error += (theForm.text.value == '') ? "Žś gleymdir aš skrifa eitthvaš ķ svar reitinn.\n" : "";
    if (error != "") {
      alert(error);
      return false;
    }
    return true;
  }
}


// Form-field validation functions (only used by the form validation functions above)
function checkEmail( strng )
{
  var error = "";
  var emailFilter=/^.+@.+\..{2,3}$/;
  if (!(emailFilter.test(strng))) {
    error += "Vinsamlega slįšu inn löglegt netfang.\n";
  }
  var illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/;
  if (strng.match(illegalChars)) {
    error += "Netfangiš inniheldur ólögleg tįkn.\n";
  }
  return error;
}


function checkRadios(theForm, radioName) {
  var error = "";
  var checkvalue = false;
  for(i = 0; i < theForm.elements.length; i++) {
    if(theForm.elements[i].name == radioName) {
      if(theForm.elements[i].checked) {
        checkvalue = true;
        break;
      }
    }
  }
  if(!(checkvalue)) {
    error = "Vinsamlegast hakašu viš valkost.\n";
  }
  return error;
}


// Make sure that the pagebody block is at least equal height to
// each of the side columns
var isChanged = false;
function fixPagebodyHeight()
{
  if (document.layers == null)
  {
    var hBody = document.getElementById('pagebody').offsetHeight;
    var hExtra1 = (document.getElementById('pageextra1') != null) ? document.getElementById('pageextra1').offsetHeight : 0;
    var hExtra2 = (document.getElementById('pageextra2') != null) ? document.getElementById('pageextra2').offsetHeight : 0;
    var hExtra3 = (document.getElementById('pageextra3') != null) ? document.getElementById('pageextra3').offsetHeight : 0;
    var hExtra4 = (document.getElementById('pageextra4') != null) ? document.getElementById('pageextra4').offsetHeight : 0;
    if (hExtra1 > hBody) { hBody = hExtra1; isChanged = true; }
    if (hExtra2 > hBody) { hBody = hExtra2; isChanged = true; }
    if (hExtra3 > hBody) { hBody = hExtra3; isChanged = true; }
    if (hExtra4 > hBody) { hBody = hExtra4; isChanged = true; }
    if (isChanged == true)
    {
      document.getElementById('pagebody').style.height = hBody + "px";
    }
  }
}


// Set explicit height value to the containing blocks of images
// (Fixes various float bugs in IE5.5 and IE6 for Windows)
if (document.all && window.attachEvent && navigator.appName == "Microsoft Internet Explorer")
{
  window.attachEvent("onload", doIEStuff);
}
function doIEStuff()
{
  // styleAbbr();
  fixFloatsInWinIE();
}
function fixFloatsInWinIE()
{
  for (i = 0; i < document.images.length; i++ )
  {
    myNode = document.images[i].parentNode;
    if (
        (myNode.tagName != "P") &&
        (myNode.tagName != "H2") &&
        (myNode.tagName != "H3") &&
        (myNode.tagName != "H4") &&
        (myNode.tagName != "BLOCKQUOTE") &&
        (myNode.tagName != "A")
       )
    {
      h = myNode.offsetHeight;
      myNode.style.height = h + "px";
      dh = myNode.offsetHeight - h;
      myNode.style.height = h - dh + "px";
    }
  }
  if (isChanged == false)
  {
    h = pagebody.offsetHeight;
    pagebody.style.height = h + "px";
    dh = pagebody.offsetHeight - h;
    pagebody.style.height = h - dh + "px";
  }
}
/*
function styleAbbr()
{
  var oldBodyText, newBodyText, reg;
  oldBodyText = document.body.innerHTML;
  reg = /]*)>([^<]*)<\/ABBR>/g;
  newBodyText = oldBodyText.replace(reg, '$2');
  document.body.innerHTML = newBodyText;
}
*/



