// Many thanks to http://www.xs4all.nl/~sbpoley/webmatters/formval.html

function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '')
};

function validateEmail  (vfld)   // element to be validated
{
  var tfld = trim(vfld.value);  // value of field with whitespace trimmed off
  var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/
  if (!email.test(tfld)) {
    vfld.focus();
    return false;
  }

//  var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/
//  if (!email2.test(tfld))
//    msg (ifld, "warn", "Unusual e-mail address - check if correct");
//  else
//    msg (ifld, "warn", "");
  return true;
};

function validateOnSubmit() {
  var elem;
  var errs=0;
  if (!validateEmail  (document.getElementById('fromaddr'))) errs += 1; 
  if (errs>0) alert('Please give a valid email address so that\n Roger can reply to your enquiry.');
  return (errs==0);
};

function popup(mylink, windowname, x, y)
{
if (! window.focus)return true;
if (x <= 0 || x >1000) {
    x = 500;
}
if (y <= 0 || y >1000) {
    y = 500;
}

// Padding
x += 20;
y += 100;

var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, 'width=' + x + ',height=' + y + ',scrollbars=no');
return false;
}


function closeall()
{

    for (i=0;;i++) {
        y = document.getElementById('sec' + i);
        if (!y) break;
        y.style.display = 'none';
        z = document.getElementById('psec' + i);
        if (!z) break;
        z.className = 'sec';
    }

/*
    y = document.getElementById('sec1');
    y.style.display = 'none';
    z = document.getElementById('psec1');
    z.className = 'sec';
    y = document.getElementById('sec2');
    y.style.display = 'none';
    z = document.getElementById('psec2');
    z.className = 'sec';
    y = document.getElementById('sec3');
    y.style.display = 'none';
    z = document.getElementById('psec3');
    z.className = 'sec';
    y = document.getElementById('sec4');
    y.style.display = 'none';
    z = document.getElementById('psec4');
    z.className = 'sec';
*/
}

function showsec(id)
{

    closeall();
    x = document.getElementById(id);
    x.style.display = "block";
    y = document.getElementById("p" + id);
    y.className = "secsel";
}

function closepieces()
{
    for (i=0;;i++) {
        y = document.getElementById('i' + i);
        if (!y) break;
        y.style.display = "none";
    }
}

function showpiece(id)
{
    x = document.getElementById(id);

    if (!x) return;

    if (x.style.display != "block") {
        closepieces();
        x.style.display = "block";
    } else {
        closepieces();
    }

}

