/*FANCY DISPLAY FUNCTION -- Centers text with asterisks around it.  Call with FancyDisplay("Your message")*/

function FancyDisplay(message){
document.write("<Center>******************************<br>");
document.write("***" + message + "***<br>");
document.write("<Center>******************************<br></center>");
}


/*INITARRAY FUNCTION -- creates one-dimensional arrays.  Call like Dave=new initArray(argument1, argument2, argument3, etc....)*/

function initArray() {
	this.length=initArray.arguments.length;
	for (var i=0; i<this.length; i++);
	this[i+1];
	}


/*GALLERY FUNCTION --This is good for gallery pages where you have a small photo and you want to be able to click on a photo and have it appear in a separate window.  This is set to a certain size window and appears in the upper left.  It works for both Netscape and IE.  The last statement makes sure the window always comes to the top of the window "stack." You can adjust location, but in order for both IE and NN to appear in the same position, you must make sure the 'left' and 'screenX' values are the same, likewise 'top' and 'screenY'*/

function gallery(URL) {
var gallerypopup = window.open(URL, 'picture', 'left=0,top=0,screenX=0,screenY=0,toolbars=0,scrollbars=0,location=0,statusbars=0,menubars=0,resizable=1,width=475,height=475');
gallerypopup.focus();
}


//E-MAIL ADDRESS VALIDATOR
function IsEmailValid(FormName,ElemName)
{
var EmailOk  = true
var Temp     = document.forms[FormName].elements[ElemName]
var AtSym    = Temp.value.indexOf('@')
var Period   = Temp.value.lastIndexOf('.')
var Space    = Temp.value.indexOf(' ')
var Length   = Temp.value.length - 1   // Array is from 0 to length-1

if ((AtSym < 1) ||                     // '@' cannot be in first position
    (Period <= AtSym+1) ||             // Must be atleast one valid char btwn '@' and '.'
    (Period == Length ) ||             // Must be atleast one valid char after '.'
    (Space  != -1))                    // No empty spaces permitted
   {  
      EmailOk = false
      alert('Please enter a valid e-mail address!')
      Temp.focus()
   }
return EmailOk
}


//*************************************************************
//*************************************************************
//*************************************************************
//DATE VALIDATION FUNCTIONS
/*To make this work put the following inside the <input> tag for any date field: onBlur="formatDate(this)" onKeyPress="testKey(event)".  The two functions together
prevent the user from inputting non numerical characters other than - or /, and highlights the text field for correction.  Does allow a null in case the field is not required.*/

function testKey(e){
   chars= "0123456789/";
   e    = window.event;
   if(chars.indexOf(String.fromCharCode(e.keyCode))==-1) window.event.keyCode=0;
};

function valDate(M, D, Y){
  Months= new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  Leap  = false;

  if((Y % 4 == 0) && ((Y % 100 != 0) || (Y %400 == 0)))
    Leap = true;
  if((D < 1) || (D > 31) || (M < 1) || (M > 12) || (Y < 0))
    return(false);
  if((D > Months[M-1]) && !((M == 2) && (D > 28)))
    return(false);
  if(!(Leap) && (M == 2) && (D > 28))
    return(false);    
  if((Leap)  && (M == 2) && (D > 29))
    return(false);    
};

function formatDate(dateForm){
   cDate = dateForm.value;
   dSize = cDate.length;
   sCount= 0;
 
   if(cDate=='') return;

   //Check ou the slashs
   for(var i=0; i < dSize; i++)
      (cDate.substr(i,1) == "/") ? sCount++ : sCount;
   if (sCount != 2){
      alert("Date must be in the format\n ''dd/mm/aaaa''");
      dateForm.select();
      return(false);
   };
   //Check if the year is a 2 or 4 digits string
   ySize = cDate.substring(cDate.lastIndexOf("/")+1,dSize).length
   if(ySize<2 || ySize>4 || ySize == 3){
     alert('Invalid Date !');
     dateForm.select();
     return false;
   };
   //Cut the date string into three parts (Month, Day & Year)
   idxBarI = cDate.indexOf("/");
   idxBarII= cDate.lastIndexOf("/");
   strM    = cDate.substring(0,idxBarI);
   strD    = cDate.substring(idxBarI+1,idxBarII);
   strY    = cDate.substring(idxBarII+1,dSize);

   strM = (strM.length < 2 ? '0'+strM : strM);   
   strD = (strD.length < 2 ? '0'+strD : strD);
   if(strY.length == 2)
      strY = (strY > 50  ? '19'+strY : '20'+strY);
   dateForm.value = strM+'/'+strD+'/'+strY;
 
   ok = valDate(strM, strD, strY);
    if(ok==false){ 
      alert("Invalid Date!");
      dateForm.select();
      return false;
   };
};



//*************************************************************
//*************************************************************
//*************************************************************



