//*****************************************************************************
// Do not remove this notice.
//
// Copyright 2001 by Mike Hall.
// See http://www.brainjar.com for terms of use.
//*****************************************************************************

// Determine browser and version.

function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

/* The following function creates an XMLHttpRequest object... */

function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

/* You can get more specific with version information by using 
	parseInt(navigator.appVersion)
	Which will extract an integer value containing the version 
	of the browser being used.
*/

/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 
var http2 = createRequestObject(); 

/* Function called to get the activity categories list */
function DeleteEvent(id, mode){
        if ( confirm("Are you sure you wish to delete this event") ) {
	  /* Create the request. The first argument to the open function is the method (POST/GET),
		  and the second argument is the url... 
		  document contains references to all items on the page
		  We can reference document.form_category_select.select_category_select and we will
		  be referencing the dropdown list. The selectedIndex property will give us the 
		  index of the selected item. 
	  */
          if ( mode == 0 ) {
            url = 'my_events.html?delete=1&uid=' + id;
          } else {
            /* admin */
            url = 'events_admin.html?delete=1&id=' + id;
          }
     
       
	  http.open('get', url);
	  /* Define a function to call once a response has been received. This will be our
		  refreshEvents function that we define below. */
	  http.onreadystatechange = refreshEvents; 
	  /* Send the data. We use something other than null when we are sending using the POST
		  method. */
	  http.send(null);
        }
}



function refreshEvents(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
		document.getElementById('my_events').innerHTML = response;
	}
}


/* code to handle refresh of main list of events */

/* Function called to get the activity categories list */
function getMainEvents(startdate){
          http2.open('get', '/events/get_events.php?start_date=' + startdate);
          /* Define a function to call once a response has been received. This will be our
                  refreshMainEvents function that we define below. */
          http2.onreadystatechange = refreshMainEvents;
          /* Send the data. We use something other than null when we are sending using the POST
                  method. */
          try {
            http2.send(null);
          } catch(e) {}
}

function refreshMainEvents(){
        /* Make sure that the transaction has finished. The XMLHttpRequest object
                has a property called readyState with several states:
                0: Uninitialized
                1: Loading
                2: Loaded
                3: Interactive
                4: Finished */
        if(http2.readyState == 4){ //Finished loading the response
                /* We have got the response from the server-side script,
                        let's see just what it was. using the responseText property of
                        the XMLHttpRequest object. */
                var response = http2.responseText;
                /* And now we want to change the product_categories <div> content.
                        we do this using an ability to get/change the content of a page element
                        that we can find: innerHTML. */
                document.getElementById('events_container').innerHTML = response;
        }
}

function windowOpener(url, name, args) {
  if (typeof(popupWin) != "object"){
    popupWin = window.open(url,name,args);
  } else {
    if (!popupWin.closed){
      popupWin.location.href = url;
    } else {
      popupWin = window.open(url, name,args );
    }
  }
  popupWin.focus();
}

function showEvents(startdate,e) {
     if (browser.isIE) {
       x = window.event.clientX + document.documentElement.scrollLeft;
       y = window.event.clientY + document.documentElement.scrollTop;
     }
     if (browser.isNS) {
       x = e.clientX + window.scrollX;
       y = e.clientY + window.scrollY;
     } 
     x -=100;
     y += 10;
     document.getElementById('events_container').style.visibility = "visible";
     document.getElementById('events_container').style.left = x + "px";
     document.getElementById('events_container').style.top = y + "px";
     getMainEvents(startdate);
     //close the popup after a number of seconds 
     //window.setTimeout("hideEvents()", 10000); 

}

function hideEvents() {
    document.getElementById('events_container').style.visibility = "hidden";

}

