
// contains functions used in calendar.asp

// check browser
var win= null;
var isMozilla = (document.all) ? 0 : 1;
var y;
var x;
if (isMozilla) {
    document.captureEvents(Event.MOUSEUP);
}
document.onmouseup = MouseUp;

function MouseUp(e) {
    if (isMozilla) {
        y = e.pageY;
        x = e.pageX - document.body.scrollLeft;
    }
    else {
        y = event.y;
        x = event.x + document.body.scrollLeft; 
    }
    if ((y - 10) < 0) {
       y = y - 100;
    }
    else {
       y = y + 10;
    }
    if ( x + 10  > screen.width ) {
        x = x - 300;
    } 
    else {
        x = x + 5;
    }
    x = x + 256;
    y = y + 146;
}

// opens the popup window
function calpopup(lnk, winHeight, winWidth) { 
    windowSpecs = "fullscreen=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,height=" + winHeight + ",width=" + winWidth + ",scrollbars=no,top=" + y + ",left=" + x
    window.open(lnk, "calendar",windowSpecs) 
} 

// opens a new window
function NewWindow(mypage,myname,w,h,scroll){
    var winl = (screen.width-w)/2;
    var wint = (screen.height-h)/2;
    var settings  ='height='+h+',';
        settings +='width='+w+',';
        settings +='top='+wint+',';
        settings +='left='+winl+',';
        settings +='scrollbars='+scroll+',';
        settings +='resizable=yes';
    win=window.open(mypage,myname,settings);
    if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

// prints page
function PrintPage() {
    alert("<%=Sub1Var1%>");
    window.print();
}

// deletes the event
function goDeleteEvent(CurrentLink){
  	if (confirm('Are you sure you want to delete the selected event? WARNING! THIS CANNOT BE UNDONE!') == true){
  	  window.location.replace(CurrentLink);
  	}else{
  	  return false;
  	}
} 

// deletes the calendar
function goDeleteCalendar(CurrentLink){
  	if (confirm('Are you sure you want to delete this calendar? ALL THE EVENTS IN THIS CALENDAR WILL BE DELETED! WARNING! THIS CANNOT BE UNDONE!') == true){
  	  window.location.replace(CurrentLink);
  	}else{
  	  return false;
  	}
}

// deletes the color scheme
function goDeleteColorScheme(CurrentLink){
  	if (confirm('Are you sure you want to delete this Color Scheme? THIS CANNOT BE UNDONE!') == true){
  	  window.location.replace(CurrentLink);
  	}else{
  	  return false;
  	}
} 

// validates the add/edit event on formsubmit
function goValidate(){
    if (document.all.adminform.colCal_EventDate.value == "") {
      alert("You must enter an EVENT DATE");
      return false;
      document.all.adminform.colCal_EventDate.focus();
    }
    date = new Date(document.all.adminform.colCal_EventDate.value);
    if (isNaN(date)) {
        alert ("You must enter a valid EVENT DATE")
        return false;
        document.all.adminform.colCal_EventDate.focus();
    }
    if (document.all.adminform.colCal_EventTitle.value == "") {
      alert("You must enter and EVENT TITLE");
      return false;
    }
    if (document.all.adminform.colCal_EventAllDay.checked == "") {
      StartTime = document.all.adminform.colCal_EventDate.value + " " + document.all.adminform.colCal_EventStartTime.value
      EndTime = document.all.adminform.colCal_EventDate.value + " " + document.all.adminform.colCal_EventEndTime.value
      StartTime = new Date(StartTime)
      EndTime = new Date(EndTime)
      if (Date.parse(StartTime) > Date.parse(EndTime)) {
        alert("You END TIME cannot be before you START TIME");
       return false;
       }
    }
    return WYSIWYG.updateTextArea('colCal_EventBody');
    
    return true;
}

function checkedAllDay(){
   if (document.all.adminform.colCal_EventAllDay.checked == true) {
    document.all.colCal_EventStartTime.disabled=true;
    document.all.colCal_EventEndTime.disabled=true;
   }
   if (document.all.adminform.colCal_EventAllDay.checked == false) {
    document.all.colCal_EventStartTime.disabled=false;
    document.all.colCal_EventEndTime.disabled=false;
   }
}