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 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 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 == '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 == 'password' && el.name == 'ConfirmPassword') {
    myConfirm = el.value;
    if (el.value == '') {
      alert('Please confirm your password');
      el.focus();
      return false;
    }
    else if (myPassword != myConfirm) {
      alert("Please ensure that you confirm your password correctly.");
      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 myVoid() { ; } // do nothing


function newWindow3(href) {

	window.open(href,"","toolbar=no,status=no,menubar=no,resizable=no,scrollbars=no,width=10,height=10");
}

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) {
// 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.value.match(datePat); // is the format ok?
if (matchArray == null) {
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 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 deletePart(ID, WhichPart, location) {

	if (confirm('Are you sure that you want to delete this part?')) {
		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 record?')) {
		document.location.href = location;
	}
}


