function write_it(status_text) {
	window.status=status_text;
}


function toggleDivision(name)	{

	if (eval("document.all." + name + ".style.display == 'none'")) {
		eval("document.all." + name + ".style.display = ''");
		}
	else {
		eval("document.all." + name + ".style.display = 'none'");
		}
	}


function showDivision(which_division)
	{
	if (navigator.appName == "Netscape")
		{
		document.layers[which_division].display = "";
		}
	else
		{
		document.all[which_division].style.display = "";
		}
	}


function hideDivision(which_division)
	{
	if (navigator.appName == "Netscape")
		{
		document.layers[which_division].display = "none";
		}
	else
		{
		document.all[which_division].style.display = "none";
		}
	}
	
function printForm()	{
	document.all.print.style.display = 'none';
	window.print();
}

function displayDate()	{
var today = new Date();
var year  = today.getYear();
var month = today.getMonth() + 1;
var day  = today.getDate();
if (day < 10)	{
	day = "0" + day;
	}
if (month < 10)	{
	month = "0" + month;
	}
mydate = day + "/" + month + "/" + year;
window.document.forms[0].Date.value = mydate;
}


function validateAppFormE(form) {
  for (var e = 0; e < form.elements.length; e++) {
    var el = form.elements[e];

    if (el.type == 'text' && el.name == 'Username') {
    myUsername = el.value;
    if (el.value == '') {
      alert('Please supply a username');
      el.focus();
      return false;
    }
    var pattern = /^[a-z0-9_\s]+$/i;
    var StringMatches = myUsername.match(pattern);
    if (!StringMatches) {
      alert('Please supply a username with alphanumeric characters only');
        el.focus();
      return false;
    }
    }
    
    if (el.type == 'password' && el.name == 'Password') {
    myPassword = el.value;
    if (el.value == '') {
      alert('Please supply a password');
      el.focus();
      return false;
    }
    var pattern = /^[a-z0-9_\s]+$/i;
    var StringMatches = myPassword.match(pattern);
    if (!StringMatches) {
      alert('Please supply a password with alphanumeric characters only');
        el.focus();
      return false;
    }
    }
    
    
    
    if (el.type == 'text' && el.name == 'Email') {
    email = el.value;
    if (el.value == '') {
      alert('Please supply an e-mail address');
      el.focus();
      return false;
    }
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) {
    	alert('Please supply a valid e-mail address');
        el.focus();
    	return false;
    }
    if(splitted[1] != null) {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) {
    	alert('Please supply a valid e-mail address');
        el.focus();
    	return false;
      }
    }
    if(splitted[2] != null) {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) {
      var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) {
    	    alert('Please supply a valid e-mail address');
            el.focus();
    	    return false;
            }
      }
    }
    }
    
    if (el.type == 'text' && el.name == 'EmailN' && el.value != '') {
    email = el.value;
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) {
    	alert('Please supply a valid e-mail address');
        el.focus();
    	return false;
    }
    if(splitted[1] != null) {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) {
    	alert('Please supply a valid e-mail address');
        el.focus();
    	return false;
      }
    }
    if(splitted[2] != null) {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) {
      var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) {
    	    alert('Please supply a valid e-mail address');
            el.focus();
    	    return false;
            }
      }
    }
    }
  
    if (el.type == 'text' && el.name != 'WebsiteURL' && el.name != 'EmailN') { 
      if (el.value == '') {
        alert('Please fill out all the text fields');
        el.focus();
        return false;
      }
    }
    else if (el.type == 'textarea') { 
      if (el.value == '') {
        alert('Please complete all the text areas');
        el.focus();
        return false;
      }
    }
    else if (el.type.indexOf('select') != -1) {
      if (el.selectedIndex == -1 || el.selectedIndex == 0 && el.name != 'DepositConfirm') {
        alert('Please make a selection');
        el.focus();
        return false;
      }
    }
    else if (el.type == 'radio') {
      var group = form[el.name];
      var checked = false;
      if (!group.length)
        checked = el.checked;
      else
        for (var r = 0; r < group.length; r++)
          if ((checked = group[r].checked))
            break;
      if (!checked) {
        alert('Please select a radio button');
        el.focus();
        return false;
      }
    }
    else if (el.type == 'checkbox' && el.name != 'Notes') {
      var group = form[el.name];
      if (group.length) {
        var checked = false;
        for (var r = 0; r < group.length; r++)
          if ((checked = group[r].checked))
            break;
        if (!checked) {
          alert('Please check at least one of the checkboxes');
          el.focus();
          return false;
        }
      }
    }
  }
  return true;
}


function validateAppFormA(form) {
  for (var e = 0; e < form.elements.length; e++) {
    var el = form.elements[e];
    
    if (el.type == 'text' && el.name == 'Username') {
    myUsername = el.value;
    if (el.value == '') {
      alert('Verskaf asb. \'n gebruikernaam');
      el.focus();
      return false;
    }
    var pattern = /^[a-z0-9_\s]+$/i;
    var StringMatches = myUsername.match(pattern);
    if (!StringMatches) {
      alert('Verskaf asb. \'n gebruikernaam met slegs alfanumeriese karakters');
        el.focus();
      return false;
    }
    }
    
    if (el.type == 'password' && el.name == 'Password') {
    myPassword = el.value;
    if (el.value == '') {
      alert('Verskaf asb. \'n wagwoord');
      el.focus();
      return false;
    }
    var pattern = /^[a-z0-9_\s]+$/i;
    var StringMatches = myPassword.match(pattern);
    if (!StringMatches) {
      alert('Verskaf asb. \'n wagwoord met slegs alfanumeriese karakters');
        el.focus();
      return false;
    }
    }
    
    
    
    if (el.type == 'text' && el.name == 'Email') {
    email = el.value;
    if (el.value == '') {
      alert('Verskaf asb. \'n e-pos adres');
      el.focus();
      return false;
    }
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) {
    	alert('Verskaf asb. \'n geldige e-pos adres');
        el.focus();
    	return false;
    }
    if(splitted[1] != null) {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) {
    	alert('Verskaf asb. \'n geldige e-pos adres');
        el.focus();
    	return false;
      }
    }
    if(splitted[2] != null) {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) {
      var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) {
    	    alert('Verskaf asb. \'n geldige e-pos adres');
            el.focus();
    	    return false;
            }
      }
    }
    }

    if (el.type == 'text' && el.name == 'EmailN' && el.value != '') {
    email = el.value;
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) {
    	alert('Verskaf asb. \'n geldige e-pos adres');
        el.focus();
    	return false;
    }
    if(splitted[1] != null) {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) {
    	alert('Verskaf asb. \'n geldige e-pos adres');
        el.focus();
    	return false;
      }
    }
    if(splitted[2] != null) {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) {
      var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) {
    	    alert('Verskaf asb. \'n geldige e-pos adres');
            el.focus();
    	    return false;
            }
      }
    }
    }

    if (el.type == 'text' && el.name != 'WebsiteURL' && el.name != 'EmailN') { 
      if (el.value == '') {
        alert('Voltooi asb. al die teksvelde');
        el.focus();
        return false;
      }
    }
    else if (el.type == 'textarea') { 
      if (el.value == '') {
        alert('Voltooi asb. al die teksareas');
        el.focus();
        return false;
      }
    }
    else if (el.type.indexOf('select') != -1) {
      if (el.selectedIndex == -1 || el.selectedIndex == 0 && el.name != 'DepositConfirm') {
        alert('Maak asb. \'n keuse');
        el.focus();
        return false;
      }
    }
    else if (el.type == 'radio') {
      var group = form[el.name];
      var checked = false;
      if (!group.length)
        checked = el.checked;
      else
        for (var r = 0; r < group.length; r++)
          if ((checked = group[r].checked))
            break;
      if (!checked) {
        alert('Maak asb. \'n keuse');
        el.focus();
        return false;
      }
    }
    else if (el.type == 'checkbox' && el.name != 'Notes') {
      var group = form[el.name];
      if (group.length) {
        var checked = false;
        for (var r = 0; r < group.length; r++)
          if ((checked = group[r].checked))
            break;
        if (!checked) {
          alert('Merk asb. ten minste een opsie');
          el.focus();
          return false;
        }
      }
    }
  }
  return true;
}




function displaySubs(the_sub){
	if (document.getElementById(the_sub).style.display==""){
	document.getElementById(the_sub).style.display = "none";return}
for (i=0;i<subs_array.length;i++){
	var my_sub = document.getElementById(subs_array[i]);
	my_sub.style.display = "none";
	}document.getElementById(the_sub).style.display = "";
}

function newWindow(href) {

	window.open(href,"","toolbar=no,status=no,menubar=no,resizable=no,scrollbars=yes,width=700,height=600");
}


function newWindow2(href) {

	window.open(href,"","toolbar=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=550,height=450");
}

function newWindow3(href) {

	window.open(href,"","toolbar=no,status=no,menubar=no,resizable=no,scrollbars=no,width=10,height=10");
}

function downloadInstructions() {
	alert("Save the zip file that will open next, to your hard drive.\n\r" + 
	"Unzip the file to a new folder.\n\r" +
	"Open the .htm file."); 

}

function aflaaiInstruksies() {
	alert("Stoor die zip lêer wat volgende gaan verskyn, op jou harde skyf.\n\r" + 
	"\"Unzip\" die lêer na 'n nuwe \"folder\".\n\r" +
	"Maak die .htm lêer oop."); 

}

function myVoid() { ; } // do nothing

function removePhoto(ID, Photo, location) {

	if (confirm('Are you sure that you want to remove this photo?')) {
		document.location.href = location;
	}
}

function deletePhoto(ID, Photo, location) {

	if (confirm('Are you sure that you want to delete this photo, together with its attributes?')) {
		document.location.href = location;
	}
}

function deleteImage(location) {

	if (confirm('Are you sure that you want to delete this image?')) {
		document.location.href = location;
	}
}

function removeAttachment(ID, Attachment, location) {

	if (confirm('Are you sure that you want to remove this attachment?')) {
		document.location.href = location;
	}
}

function deleteAttachment(ID, Attachment, location) {

	if (confirm('Are you sure that you want to delete this attachment, together with its attributes?')) {
		document.location.href = location;
	}
}

function deleteRecord(ID, location) {

	if (confirm('Are you sure that you want to delete this item?')) {
		document.location.href = location;
	}
}

function deleteDoc(ID, location) {

	if (confirm('Are you sure that you want to delete this item?')) {
		document.location.href = location;
	}
}

