var ControlToSet;
var theForm = document.theForm;
var CalWidth=200;
var StartYear = "";
var EndYear = "";
var FormatAs;
var NN4 = (navigator.appName.indexOf("Netscape")>=0 && !document.getElementById)? true : false;
var NN6 = (document.getElementById && navigator.appName.indexOf("Netscape")>=0 )? true: false;
var TOP;
var LEFT;

if(NN4)document.captureEvents(Event.MOUSEMOVE);

document.onmousemove = LogPosition;

function LogPosition(evt){

    if (NN4||NN6){
    LEFT=evt.screenX;
    TOP=evt.screenY-10;
    }
    else{
    LEFT=event.screenX;
    TOP=event.screenY-10;
    }

}


function ShowCalendar(CONTROL,START_YEAR,END_YEAR,FORMAT){

ControlToSet = eval(CONTROL);
StartYear = START_YEAR;
EndYear = END_YEAR;
FormatAs = FORMAT;

var strFeatures = "width=" + CalWidth + ",height=200" + ",left=" + LEFT + ",top=" + TOP;
var CalWindow = window.open("/Events/calendar.lasso","Calendar", strFeatures)
CalWindow.focus();
} //End Function

function SetDate(DATE){
if(ControlToSet){
ControlToSet.value = DATE; 
}
ControlToSet = null;
StartYear = null;
EndYear = null;
FormatAs = null;
}




function changecss(id, newClass) {
	identity=document.getElementById(id);
	identity.className=newClass;
}

function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
if(document.layers)    //NN4+
	{
	document.layers[szDivID].visibility = iState ? "show" : "hide";
	}
	else if(document.getElementById)      //gecko(NN6) + IE 5+
	{
	var obj = document.getElementById(szDivID);
	obj.style.visibility = iState ? "visible" : "hidden";
	obj.style.display = iState ? "block" : "none";
	}
	else if(document.all)       // IE 4
	{
	document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
	}
}


function makeToday()
{
today = new Date();
today2 = (today.getMonth() + 1) + "/" + today.getDate() + "/" + today.getFullYear();
return(today2);
}

function addSelectOption(theSelect, theValue, theText)
{
var theElement;
theElement = document.createElement("option");
theElement.value = theValue;
theElement.text = theText;
theElement.selected = true;
theSelect.add(theElement);
}


function checkURL(checkString)
{
	var newstr = "";
	var dots = 0;

	if (checkString.length > 0) {
		for (var i = 0; i < checkString.length; i++) {
			ch = checkString.substring(i, i + 1);
			if (ch == ".") {
				dots = 1;
			}
			if (ch != " ") {
				newstr += ch;
			}
		}

		if(newstr.substring(0, 7) != "http://" && newstr.substring(0, 8) != "https://") {
			newstr = "http://" + newstr;
		}

		if(newstr.length < 11 || dots == 0) {
			alert ("This doesn't look like a valid web address, please fix.");
		}

	}
	return newstr;
}


function checkPhone(checkString)
{
	var newstr = "";
	var dashes = 0;

	for (var i = 0; i < checkString.length; i++) {
		ch = checkString.substring(i, i + 1);
		if ((ch >= "0" && ch <= "9") || (ch == "x") || (ch == "-")) {
			newstr += ch;
		}
		if ((ch == "X")) {
			newstr += "x";
		}
		if ((ch == ".") || (ch == ")") || (ch == "/")) {
			newstr += "-";
			ch = "-";
		}
		if (ch == "-") {
			dashes = dashes + 1;
		}
	}
	if (((dashes == 2) && (newstr.length > 11)) || (newstr.length == 0)) {
		return newstr;
	}
	else {
		alert ("Please enter the phone number in the correct format.");
	return checkString;
	}
}

function checkTime(checkString)
{
	var newstr = "";
	var colon = 0;
	var digits = 0;
	var ampm = "";
	var hour = "";

	for (var i = 0; i < checkString.length; i++) {
		ch = checkString.substring(i, i + 1);
		if (((ch == ":") || (digits == 2)) && (colon == 0)) {
			colon = 1;
			hour = parseInt(newstr, 10);
			if(hour > 12 && hour < 24) {
			hour = (hour - 12);
			var ampm = " PM";
			}
			if(hour == 12) {
			var ampm = " PM";
			}
			if(hour == 0) {
			hour = 12;
			var ampm = " AM";
			}
			if(hour < 10) {
			newstr = ("0" + hour + ":");
			digits = 3;
			}
			else {
			newstr = (hour + ":");
			digits = 3;
			}
		}

		if ((ch == "a") || (ch == "A")) {
			var ampm = " AM";
		}
		if ((ch == "p") || (ch == "P")) {
			var ampm = " PM";
		}

		if (ch >= "0" && ch <= "9" && digits < 5) {
			newstr += ch;
			digits = digits + 1;
		}
	}

	if ((hour == "") && (newstr != "")) {
			colon = 1;
			hour = parseInt(newstr, 10);
			if(hour > 12 && hour < 24) {
			hour = (hour - 12);
			var ampm = " PM";
			}
			if((hour == 12) && (ampm == "")) {
			var ampm = " PM";
			}
			if(hour == 0) {
			hour = 12;
			var ampm = " AM";
			}
			if(hour < 10) {
			newstr = ("0" + hour + ":");
			digits = 3;
			}
			else {
			newstr = (hour + ":");
			digits = 3;
			}
	}

	if ((colon == 1) && (digits == 3)) {
		newstr += "00";
	}

	if ((colon == 1) && (digits == 4)) {
		newstr += "0";
	}

	if (ampm == "") {
		var ampm = " AM";
	}

	if (newstr != "") {
		newstr += ampm;
	}

	if (((hour < 24) && (newstr.substring(3,5) < 60)) || (newstr.length == 0)) {
		return newstr;
	}
	else {
		alert ("Please enter a correct time.");
	return checkString;
	}
}

function checkCase(checkString)
{
	var lowercheck = 0;

	for (var i = 0; i < checkString.length; i++) {
		ch = checkString.substring(i, i + 1)
		if (ch >= "a" && ch <= "z") {
			lowercheck = 1;
		}
	}
	if (lowercheck == 0 && checkString.length > 0) {
		alert ("Please use upper and lower case letters.");
	}
	return;
}

function confirmDelete()
{
	return confirm('Do you really want to delete this information?\nThis cannot be undone.');
}

function smallWindow(theURL)
{
	window.open(theURL, 'detail', 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width=450,height=300');
}


//*************************************************************************
//  Date Validation Script Version 1.3
//  ----------------------------------
//
//  Release Date: 03.05.2002
//        author: Thomas Mastaleck
//         email: Thomas.Mastaleck@webhosting-berlin.de
//           www: http://www.webhosting-berlin.de
//       License: What's this? GPL I think. Please keep this comment!
//
//  Description:
//  The script combines a date validation and automated date format
//  correction.
//
//*************************************************************************

//*************************************************************************
//  name of function: boolean check_date(var textbox-object)
//        parameters: name of a textbox
//      last changes: 04.04.2002
//
//  Description:
//  This function formats the value of a given textbox to a a correct date
//  format in the form dd.mm.yyyy
//  After format the date is validated.
//*************************************************************************
function check_date_us(textbox){
  //script configuration - Please set the wanted time range
  var year_range_begin = '1930';
  var year_range_end = '2040';

  //  contains the given date-string
  var Date;

  //  contains the length of the given date-string
  var date_length;

  //  contains the number of days of the month
  var month_length;

  //  These contain the day,month and year of the given date string after
  //  format correction
  var Month,Day,Year;

  //  number of points in date-string
  var point_count = 0;

  //  positions of points in date-string
  var point_positions = new Array;

  //  the new formated date is filled in here
  var correct_date_temp = new Array;

  //  start position of the year in the date-string
  var year_start_pos = 0;

  Date = textbox.value;
  date_length = Date.length;

  if(Date != ""){
    for(var str_pos = 0;str_pos < date_length; str_pos++){
      if(Date.charAt(str_pos)<"0" || Date.charAt(str_pos)>"9"){
        if(Date.charAt(str_pos,1)=='/'){
          point_count++;
          if(point_count <= 2){
            point_positions[point_positions.length] = str_pos;
          }
        }
        else{
          alertbox(textbox);
          return false;
        }
      }
    }
    if(point_count!=2){
      alertbox(textbox);
      return false;
    }
    //case 1 month-length = 1
    if(point_positions[0] == 1){
      correct_date_temp[correct_date_temp.length] = "0";
      correct_date_temp[correct_date_temp.length] = Date.substr(0,1);
      correct_date_temp[correct_date_temp.length] = "/";
      //day-length = 1
      if(point_positions[1] == 3){
        correct_date_temp[correct_date_temp.length] = "0";
        correct_date_temp[correct_date_temp.length] = Date.substr(2,1);
        correct_date_temp[correct_date_temp.length] = "/";
        year_start_pos = 4;
      }
      //day-length = 2
      else if(point_positions[1] == 4){
        correct_date_temp[correct_date_temp.length] = Date.substr(2,2);
        correct_date_temp[correct_date_temp.length] = "/";
        year_start_pos = 5;
      }
      //point at wrong position
      else{
        alertbox(textbox);
        return false;
      }
    }
    //case 2 month-length = 2
    else if(point_positions[0] == 2){
      correct_date_temp[correct_date_temp.length] = Date.substr(0,2);
      correct_date_temp[correct_date_temp.length] = "/";
      //day-length = 1
      if(point_positions[1] == 4){
        correct_date_temp[correct_date_temp.length] = "0";
        correct_date_temp[correct_date_temp.length] = Date.substr(3,1);
        correct_date_temp[correct_date_temp.length] = "/";
        year_start_pos = 5;
      }
      //day-length = 2
      else if(point_positions[1] == 5){
        correct_date_temp[correct_date_temp.length] = Date.substr(3,2);
        correct_date_temp[correct_date_temp.length] = "/";
        year_start_pos = 6;
      }
      //point at wrong position
      else{
        alertbox(textbox);
        return false;
      }
    }
    //year-length = 1
    if(date_length - year_start_pos == 1){
      correct_date_temp[correct_date_temp.length] = "200";
      correct_date_temp[correct_date_temp.length] = Date.substr(year_start_pos,1);
    }
    //year-length = 2
    else if(date_length - year_start_pos == 2){
      if(Date.substr(year_start_pos,2)<=30){
        correct_date_temp[correct_date_temp.length] = "20";
        correct_date_temp[correct_date_temp.length] = Date.substr(year_start_pos,2);
      }
      else{
        correct_date_temp[correct_date_temp.length] = "19";
        correct_date_temp[correct_date_temp.length] = Date.substr(year_start_pos,2);
      }
    }
    //year-length must be 4
    else if(date_length - year_start_pos == 4){
      correct_date_temp[correct_date_temp.length] = Date.substr(year_start_pos,4);
    }
    else{
      alertbox(textbox);
      return false;
    }
    Date = correct_date_temp.join("");
    textbox.value = Date;

    if (Date.length==10 && Date.substring(2,3)=="/" && Date.substring(5,6)=="/"){
      Month = parseInt(Date.substr(0,2),10);
      Day = parseInt(Date.substr(3,2),10);
      Year = parseInt(Date.substr(6,4),10);
    }
    else{
      alertbox(textbox);
      return false;
    }
    if (Month==4 || Month==6 || Month==9 || Month==11){
      month_length=30;
    }
    else if (Month==1 || Month==3 || Month==5 || Month==7 || Month==8 || Month==10 || Month==12){
      month_length=31;
    }
    else if(Month==2 && Year%4==0 && Year%100!=0 || Year%400==0){
      month_length=29;
    }
    else if(Month==2 && Year%4!=0 || Year%100==0 && Year%400!=0){
      month_length=28;
    }
    if (Day>=1 && Day<=month_length && Month>=1 && Month<=12 && Year>=year_range_begin && Year<=year_range_end){
      return true;
    }
    else{
      alertbox(textbox);
      return false;
    }
  }
}



//*************************************************************************
//  name of function: alertbox(var textbox-object)
//        parameters: name of a textbox
//      last changes: 04.04.2002
//
//  Description:
//  This function is used to give an error message in case of an incorrect
//  date.
//  After printing the messagebox the textbox is cleared and focused.
//*************************************************************************
function alertbox(textbox){
  //  Printing the error message
  alert('The value ' + textbox.value + ' is not a date.');
  //  Clearing the textbox
  //textbox.value='';
  //  Sets the focus to the document
  //this.focus();
  // Sets the focus to the textbox
  //textbox.focus();
}

