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];}
}

s = "Angel Dew Farms Website - Advertising Enquiry";
b = "I would like to advertise on the Angel Dew Farms Website. Please send me advertising rates and specifications.";
c = "My details are as follows:";
d = "Name: ";
e = "E-mail: ";
f = "Contact Telephone Number: ";

function mailer() {
window.location = "mailto:info@dairygoat.co.za?subject="+s+"&body="+b+"%0A%0A"+c+"%0A%0A"+d+"%0A%0A"+e+"%0A%0A"+f;
}

function write_it(status_text) {
	window.status=status_text;
}


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 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 validateFormE(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 == '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;
    }
    }
 }    

  return true;
}

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('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 ValidDate(dateStr, e) {


var datePat = /^(\d{4})(\/)(\d{2})\2(\d{2})$/;
var DateArray = dateStr.match(datePat);

if (DateArray == null) {
alert("Date is not in a valid format.");
eval("document.all.txtDate" + e + ".value = ''");
eval("document.all.txtDate" + e + ".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+" "+hours+":"+minutes+":"+seconds+" "+dn+" " + " &nbsp;"
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=550,height=650");
}

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 removeImage(ID, Image, location) {

	if (confirm('Are you sure that you want to remove this image?')) {
		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 document?')) {
		document.location.href = location;
	}
}

function removeDoc(ID, Document, location) {

	if (confirm('Are you sure that you want to delete this document?')) {
		document.location.href = location;
	}
}


