function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}





function bookmarksite(url, title){
if (document.all)
window.external.AddFavorite(url, title);
else if (window.sidebar)
window.sidebar.addPanel(title, url, "")
}

function clearFields() {
	document.all.Username.focus();
	document.all.Username.value = "";
	document.all.MyPassword.value = "";
}


function write_it(status_text) {
	window.status=status_text;
}

function setFormAction(selObj){ 
	location.href = selObj.value; 
} 


function switchDivision(name)	{

	if (prev == '') {
		eval("document.all." + name + ".style.display = ''");
		prev = 'home';
		eval("document.all." + prev + ".style.display = 'none'");
		}
	
	else	{
		eval("document.all." + name + ".style.display = ''");
		eval("document.all." + prev + ".style.display = 'none'");
		}
	prev = name;

	}


function toggleDivision(name)	{

	if (navigator.appName == "Netscape")	{
		if (eval("document.layers." + name + ".display == 'none'")) {
			eval("document.layers." + name + ".display = ''");
			}
		else {
			eval("document.layers." + name + ".display = 'none'");
			}
		}

	else	{
		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 displaySubs(the_sub) {
	if (document.getElementById(the_sub).style.display=="" && document.all.Tester.value != 0) {
	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.all.Tester.value = 0;
	document.getElementById(the_sub).style.display = "";
}

function printForm()	{
	if (navigator.appName == "Netscape") {
		window.print();
	}
	else {
		document.all.print.style.display = "none";
		window.print();
	}
}

var spr = false;
function doSaveAs(){
if (document.execCommand){
if (spr){document.execCommand("SaveAs");}
}
else{}
}


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 validateFormDemo(form) {
	alert("This is a demo. The real version of this web program will send an email to the company with your request and a copy to you.")

 return false;
}

function validateFormDemoReg(form) {
	alert("This is a demo. The real version of this web program will register you as a member/update your details and send a confirmation to you via email.")

 return false;
}

function validateFormDemodeReg(form) {
	alert("This is a demo. The real version of this web program will de-register you as a member and send a confirmation to you via email.")

 return false;
}
function validateFormDemoA(form) {
	alert("This is a demo. The real version of this web program will change the database.")

 return false;
}

function validateForm(form) {
  for (var e = 0; e < form.elements.length; e++) {
    var el = form.elements[e];

    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 == '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 == 'MyPassword') {
    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 == 'password' && el.name == 'ConfirmPassword') {
    myConfirmPassword = el.value;
    if (el.value == '') {
      alert('Please confirm your password');
      el.focus();
      return false;
    }	
   } 	
    	
 }    

  return true;
}

function validateFormA(form) {
  for (var e = 0; e < form.elements.length; e++) {
    var el = form.elements[e];

    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 == '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;
    }
    }
 }    

  return true;
}



function isValidDate(dateStr, e) {
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables


var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;


var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert("Date is not in a valid format.");
eval("document.all.txtDate" + e + ".value = ''");
eval("document.all.txtDate" + e + ".focus()");
return false;
}
day = matchArray[1]; // parse date into variables
month = matchArray[3];
year = matchArray[4];

if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
return false
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("February " + year + " doesn't have " + day + " days!");
return false;
   }
}
return true;  // date is valid
}

var dayarray=new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
var montharray=new Array("January","February","March","April","May","June","July","August","September","October","November","December")

function getthedate(){
var mydate=new Date()
var year=mydate.getYear()
if (year < 1000)
year+=1900
var day=mydate.getDay()
var month=mydate.getMonth()
var daym=mydate.getDate()
if (daym<10)
daym="0"+daym
var hours=mydate.getHours()
var minutes=mydate.getMinutes()
var seconds=mydate.getSeconds()
var dn="AM"
if (hours>=12)
dn="PM"
if (hours>12){
hours=hours-12
}
if (hours==0)
hours=12
if (minutes<=9)
minutes="0"+minutes
if (seconds<=9)
seconds="0"+seconds
//change font size here
var cdate=""+dayarray[day]+", "+montharray[month]+" "+daym+", "+year+""
if (document.all)
document.all.clock.innerHTML=cdate
else if (document.getElementById)
document.getElementById("clock").innerHTML=cdate
else
document.write(cdate)
}
if (!document.all&&!document.getElementById)
getthedate()
function timeDisplay(){
if (document.all||document.getElementById)
setInterval("getthedate()",1000)
}

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=no,scrollbars=no,width=500,height=200");
}

function newWindow3(href) {

	window.open(href,"","toolbar=no,status=no,menubar=no,resizable=no,scrollbars=no,width=10,height=10");
}

function newWindow4(href) {

	window.open(href,"","toolbar=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=840,height=600");
}

function newWindow5(href) {

	window.open(href,"","toolbar=no,status=no,menubar=no,resizable=yes,scrollbars=yes,width=750,height=600");
}

function newWindow6(href) {

	window.open(href,"","toolbar=no,status=no,menubar=no,resizable=no,scrollbars=no,width=250,height=300");
}

function newWindow7(href) {

	window.open(href,"","toolbar=no,status=no,menubar=no,resizable=no,scrollbars=no,width=600,height=500");
}

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 DatePosition(dateString,dateType) {
/*
   function DatePosition 
   parameters: dateString dateType
   returns: integer (-1, 0, 1)
   
   dateString is a date passed as a string in the following
   formats:

   type 1 : 19970529
   type 2 : 970529
   type 3 : 29/05/1997
   type 4 : 29/05/97
   type 5 : 05/29/1997
   type 6 : 05291997
   type 7 : 052997
   
   dateType is a numeric integer from 1 to 7, representing
   the type of dateString passed, as defined above.

   Returns -1 if the date passed is behind todays date
   Returns 0 if the date passed is equal to todays date
   or if dateType is not 1 to 7
   Returns 1 if the date passed is ahead of todays date
   
   Added Y2K checking.  (Works for any century cross over)
*/


    var now = new Date();
    var today = new Date(now.getYear(),now.getMonth(),now.getDate());
    var century = parseInt(now.getYear()/100)*100;
        
    if (dateType == 1)
        var date = new Date(dateString.substring(0,4),
                            dateString.substring(4,6)-1,
                            dateString.substring(6,8));
    else if (dateType == 2)
    {
        if ((now.getYear()%100)>=parseInt(dateString.substring(0,2)))
        {
            var date = new Date(century+parseInt(dateString.substring(4,6)),
                            parseInt(dateString.substring(2,4)-1),
                            dateString.substring(4,6));
        }
        else
        {
            var date = new Date(century-100+parseInt(dateString.substring(0,2)),
                            parseInt(dateString.substring(2,4)-1),
                            dateString.substring(4,6));
        }
        
    }
    else if (dateType == 3)
        var date = new Date(dateString.substring(6,10),
                            dateString.substring(3,5)-1,
                            dateString.substring(0,2));
    else if (dateType == 4)
    {
        if ((now.getYear()%100)>=parseInt(dateString.substring(6,8)))
        {
            document.write(century+parseInt(dateString.substring(6,8)),'<P>');
            var date = new Date(century+parseInt(dateString.substring(4,6)),
                            parseInt(dateString.substring(3,5)-1),
                            dateString.substring(0,2));
        }
        else
        {
            document.write(century-100+parseInt(dateString.substring(6,8)),'<P>');
            var date = new Date(century-100+parseInt(dateString.substring(4,6)),
                            parseInt(dateString.substring(3,5)-1),
                            dateString.substring(0,2));
        }
        
    }
    else if (dateType == 5)
        var date = new Date(dateString.substring(6,10),
                            dateString.substring(0,2)-1,
                            dateString.substring(3,5));
    else if (dateType == 6)
        var date = new Date(dateString.substring(4,8),
                            dateString.substring(0,2)-1,
                            dateString.substring(2,4));
    else if (dateType == 7)
    {
        if ((now.getYear()%100)>=parseInt(dateString.substring(4,6)))
        {
            document.write('datestring Century:',century+parseInt(dateString.substring(4,6)),'<P>');
            var date = new Date(century+parseInt(dateString.substring(4,6)),
                            parseInt(dateString.substring(0,2)-1),
                            dateString.substring(2,4));
        }
        else
        {
            document.write('datestring Century:',century-100+parseInt(dateString.substring(4,6)),'<P>');
            var date = new Date(century-100+parseInt(dateString.substring(4,6)),
                            parseInt(dateString.substring(0,2)-1),
                            dateString.substring(2,4));
        }
        
    }
    else
        return false;

    if (date < today)
    {
        return -1;
    }
    else if (date > today)
    {
        return 1;
        
    }
    else
    {
        return 0;
    }
}

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?')) {
		document.location.href = location;
	}
}

function deleteImage(ID, Photo, 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 deleteDocument(ID, location) {

	if (confirm('Are you sure that you want to delete this document?')) {
		document.location.href = location;
	}
}

