<!--
//************ Start Default Commands ************
var graphic = "";   
var isNS4 = 0; var isIE4 = 0; var isNS6 = 0; var isNew = 0;
var docObj, styleObj, currObj, cstyleObj;

var bVer = (parseInt(navigator.appVersion));
var bName = navigator.appName;
var brow = ((navigator.appName) + (parseInt(navigator.appVersion)));

if (bName == "Netscape" && bVer >= 3) version = "js";
else if (bName == "Microsoft Internet Explorer" && bVer >= 4) version = "js";
else if (bName == "Netscape" && bVer == 2) version = "no";
else if (bName == "Microsoft Internet Explorer" && bVer >= 2) version = "no";

if (parseInt(navigator.appVersion >= 5)){isNew = 1}
else if (brow == "Netscape4") {isNS4 = 1;}
else if (brow == "Netscape5") {isNS6 = 1;}
else if (brow == "Microsoft Internet Explorer4") {isIE4 = 1;}
				
if (isNS4||isNS6||isIE4||isNew) {
  if(isNS4){ docObj = "document."; }
  else if(isNS6){ docObj = "document.getElementById('"; }
  else { docObj = "document.all."; }

  if(isNS4){ styleObj = ""; }
  else if(isNS6){ styleObj = "').style"; }
  else { styleObj = ".style"; }
  
  if(isNS4){ cstyleObj = ""; }
  else if(isNS6){ cstyleObj = "').currentStyle"; }
  else { cstyleObj = ".currentStyle"; }
}

function getQuery(val){
  var querystring = location.search.substring(1,location.search.length);
  var o = "";
  var tSec = querystring.indexOf(val+"=");
  var tStr = querystring.substring( (tSec+(val.length+1)),querystring.length);
  
  if(tSec != -1){
    if(tStr.indexOf('&') != -1){
      o = tStr.substring(0,tStr.indexOf('&'));
    } else {
      o = tStr;
    }
  }
  return o;
}

function replaceSubstring(s,f,w){
  rtn = "";
  flg = 0;
  
  for(i = 0; i < s.length; i++){
    if(s.substr(i,f.length) == f){
      rtn += w;
      i += (f.length - 1);
    } else {
      rtn += s.charAt(i);
    }
  }
  return (rtn);
}

function urlencode(str) {
  str = escape(str);
  str = str.replace('+', '%2B');
  str = str.replace('%20', '+');
  str = str.replace('*', '%2A');
  str = str.replace('/', '%2F');
  str = str.replace('@', '%40');
  return str;
}

function testAlphaPassword(f,d){
  if(d == ""){ d = 0; }
  var doc = document.forms[d];
  var ele = doc.elements[f];
  var str = false;

  if(ele.value == ""){
    alert("Please enter a password");
  } else {
    if(/[^a-zA-z0-9]/i.test(ele.value)){
      alert("Sorry, your password may only contain letters and numbers");
    } else {
      str = true;
    }
  }

  return str;
}

function getCookie(Name){ 
  var search = Name + "=" 
  if(document.cookie.length > 0){
    offset = document.cookie.indexOf(search);
    if(offset != -1){
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if(end == -1){ end = document.cookie.length; }
      return unescape(document.cookie.substring(offset, end)) ;
    }
  } 
} 

function setCookie(name, value) {
  var today = new Date(); 
  expires = new Date(); 
  expires.setTime(today.getTime() + 1000*60*60*24*1);
  document.cookie = name + "=" + value + ";path=/;expires=" + expires.toGMTString();
}

function openPopup(URL,id,width,height){
  window.open(URL, id, "toolbar=no,location=no,width="+width+",height="+height+",status=yes,scrollbars=yes,scrolling=yes,menubar=no,resizable=yes");
}

function openPopupLocked(URL,id,width,height){
  window.open(URL, id, "toolbar=no,location=no,width="+width+",height="+height+",status=yes,scrollbars=yes,scrolling=yes,menubar=no,resizable=no");
}

function goPage(u){
  location.href = u;
}

function displayChange(l,v) {
  if (isNS4||isNS6||isIE4||isNew) { eval(docObj + l + styleObj + '.display = "' + v + '"') }
}

function updateFieldText(f,t,s,d){
  if(d == ""){ d = 0; }
  var doc = document.forms[d];
  var ele = doc.elements[f].value;
  if(s == "c"){
    if(ele == t){ doc.elements[f].value = ""; }
  } else if(s == "a"){
    if(ele == ""){ doc.elements[f].value = t; }
  }
}

//************ End Default Commands ************

//********* Start Validation Commands **********
function setFocus(f,d){
  document.forms[d].elements[f].focus();
}

function testEmail(f,d){
  var a = document.forms[d].elements[f].value;
  var at = a.indexOf("@")
  var name = a.substring(0, at)
  var isp = a.substring(at + 1, a.length)
  var dot = a.lastIndexOf(".")

  if (at == -1 || at == 0 || name == "" || isp == "" || dot == -1 || dot == (a.length - 1)) {
    alert('You must enter a valid email address');
    setFocus(f,d);
  } else {
    return true;
  }
}

function testText(f,t,d){
  if(d == ""){ d = 0; }
  var doc = document.forms[d];

  if(doc.elements[f].value == ""){
    alert('You must enter ' + t);
    setFocus(f,d);
  } else {
    return true;
  }
}

function testSelect(f,t,d){
  var a = document.forms[d].elements[f];
  if( (a.selectedIndex >= 0) && (a.options[a.selectedIndex].value != "") ){
    return true;
  } else {
    alert('You must select a ' + t);
    setFocus(f,d);
  }
}

function testRadio(f,t,d){
  var a = document.forms[d].elements[f];
  var str = "";

  for(i = 0; i < a.length; i++){
    if(a[i].checked == true){
      str = "yes";
      break;
    } else {
      str = "no";
    }
  }

  if(str == "yes"){
    return true;
  } else {
    alert('You must select ' + t);
  }
}

function testRadioValue(f,t,d){
  var a = document.forms[d].elements[f];
  var str = "";

  for(i = 0; i < a.length; i++){
    if(a[i].checked == true){
      if(a[i].value == t){
        str = "yes";
      } else {
        str = "no";
      }
      break;
    } else {
      str = "no";
    }
  }

  if(str == "yes"){
    return true;
  } else {
    return false;
  }
}

function testCheck(f,t,d){
  var a = document.forms[d].elements[f];
  var str = "";

  if(a.checked == true){
    return true;
  } else {
    alert('You must select ' + t);
  }
}

function getRadio(f,d){
  var a = document.forms[d].elements[f];
  var str = "";

  for(i = 0; i < a.length; i++){
    if(a[i].checked == true){
      str = a[i].value;
      break;
    } else {
      str = "";
    }
  }

  return str;
}

function validate_login(d){
  var doc = document.forms[d];
  if(testEmail('user_emailaddress',d) && testText('user_password','your password',d)){
    doc.action.value = "loginuser";
    doc.submit();
  }
}

function validate_comment(d){
  var doc = document.forms[d];
  if(testText('data_body','a comment',d)){
    doc.action.value = "submitcomment";
    doc.submit();
  }
}

function validate_mapsearch(d){
  var doc = document.forms[d];
  if(testText('mapkeyword','a post code, location or museum name',d)){
    var u = doc.mapkeyword.value;
    u = replaceSubstring(u,'&','~');

    location.href = "/artfund_map/" + escape(replaceSubstring(u," ","+"));
  }
}

function validate_simplesearch(d){
  var doc = document.forms[d];
  if(testText('simplekeyword','a keyword',d)){
    location.href = "/artsaved/search/" + escape(replaceSubstring(doc.simplekeyword.value," ","+"));
  }
}

function validate_advancedsearch(d){
  var doc = document.forms[d];
  var str = "/artsaved/advancedsearch/";

  if(doc.advancedkeyword.value == ""){    str += "none/"; } else { str += escape(replaceSubstring(replaceSubstring(doc.advancedkeyword.value,"/","~")," ","+")) + "/"; }
  if(doc.artist_name.value == ""){        str += "all/";  } else { str += escape(replaceSubstring(replaceSubstring(doc.artist_name.value,"/","~")," ","+")) + "/"; }
  if(doc.artist_nationality.value == ""){ str += "all/";  } else { str += escape(replaceSubstring(replaceSubstring(doc.artist_nationality.value,"/","~")," ","+")) + "/"; }
  if(doc.artwork_title.value == ""){      str += "all/";  } else { str += escape(replaceSubstring(replaceSubstring(doc.artwork_title.value,"/","~")," ","+")) + "/"; }
  if(doc.artwork_saved_from.value == "" || doc.artwork_saved_from.value == "From"){ str += "all/";  } else { str += escape(replaceSubstring(doc.artwork_saved_from.value,"/","~")) + "/"; }
  if(doc.artwork_saved_to.value == "" || doc.artwork_saved_to.value == "To"){   str += "all/";  } else { str += escape(replaceSubstring(doc.artwork_saved_to.value,"/","~")) + "/"; }
  if(doc.artwork_theme.value == ""){      str += "all/";  } else { str += escape(replaceSubstring(doc.artwork_theme.value,"/","~")) + "/"; }
  if(doc.artwork_type.value == ""){       str += "all/";  } else { str += escape(replaceSubstring(doc.artwork_type.value,"/","~")) + "/"; }
  if(doc.artwork_region.value == ""){     str += "all";   } else { str += escape(replaceSubstring(doc.artwork_region.value,"/","~")); }

  location.href = str;
}

function validate_valentines(d){
  var doc = document.forms[d];
  if(testText('data_fullname','your name',d) && testEmail('data_emailaddress',d) ){
    doc.action.value = "submitentry";
    doc.submit();
  }
}

//********* End Validation Commands **********

function openwindow(o,t){
 location.href = "mailto:" + t + "@" + o;
}

function displayMapTab(t){
  var tary = Array('details','artsaved');

  for(i=0; i < tary.length; i++){
    displayChange(tary[i],'none');
    document.getElementById('gm_'+tary[i]).className = "";
  }
  for(i=0; i < tary.length; i++){
    if(tary[i] == t){
      displayChange(t,'block');
      document.getElementById('gm_'+t).className = "sel";
    }
  }
}

function submit_course_finder(){
  var doc = document.forms['course_finder'];
  var q = doc.postcode.value;
  
  if(q.length > 8 || q.length < 2){
    alert('Please enter a valid post code.');
  } else {
    if(q.indexOf(' ') != -1){
      var oc = q.substring(0,q.indexOf(' '));
      if(oc.length < 2 || oc.length > 4){
        alert('Please enter a valid post code.');
      } else {
        doc.outcode.value = oc;
        doc.submit();
      }
    } else {
      if(q.length > 4){
        var oc = q.substring(0,q.length-3);
      } else {
        oc = q;
      }
      doc.outcode.value = oc;
      doc.submit();
    }
  }
}


//-->