// JavaScript Document: AJAX Main Handler
var locatie = '';
var reminder = new Array();

function $(id) {
  return document.getElementById(id);
}

function fixpath(fisier) {
  return locatie+fisier;
}
/*
function req(action, location, context) {
  var url = fixpath('req.php')+'?act='+action;

  if (!(location)) {
    alert('There is no element with id: '+location);
  }
  else {
    makeRequest(url, 'innerWrite("'+location+'", xml_text)');
  }
  if (context) {
    var url = fixpath('req.php')+'?context='+action;
    location = 'context_'+location;
    if (!(location)) {
      alert('There is no element with id: '+location);
    }
    else {
      makeRequest(url, 'innerWrite("'+location+'", xml_text)');
    }
  }
}
*/
function req_post(url, variables, location) {
  var url = fixpath('req.php')+'?act='+url;
  if (!(location)) {
    alert('There is no element with id: '+location);
  }
  else {
    makePostRequest(url, variables, 'innerWrite("'+location+'", xml_text)');
  }
}
function retrieve_innerHTML(location) {
  if ((location)) {
  (location).innerHTML = reminder[location];
  }
  //alert(location);
}

// JavaScript Document: ajax kickstarter

function makeRequest(url, called_function) {
  //alert('called'+url);

  var http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
      http_request.overrideMimeType('text/html');
    }
  }
  else if (window.ActiveXObject) { // IE
    try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
      try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e) {}
    }
  }
  if (!http_request) {
    alert('Giving up :( Cannot create an XMLHTTP instance');
    return false;
  }
  http_request.onreadystatechange = function() { generalHandler(http_request, called_function); };
  http_request.open('GET', url, true);
  http_request.send(null);
}

function generalHandler(http_request, called_function) {
  if (http_request.readyState == 4) {
    if (http_request.status == 200) {
      var xml_text = http_request.responseText;
      var xml_doc = http_request.responseXML;
      //alert(xml_text + xml_doc);
      eval(called_function);
    }
    else {
      alert('There was a problem with the request.');
    }
  }
}

// http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

function makePostRequest(url, variables, called_function) {
  var http_request = false;
  if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
      http_request.overrideMimeType('text/html');
    }
  }
  else if (window.ActiveXObject) { // IE
    try {
      http_request = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
      try {
        http_request = new ActiveXObject("Microsoft.XMLHTTP");
      }
      catch (e) {}
    }
  }
  if (!http_request) {
    alert('Giving up :( Cannot create an XMLHTTP instance');
    return false;
  }
  http_request.onreadystatechange = function() { generalHandler(http_request, called_function); };
  http_request.open('POST', url, true);
  http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  http_request.send(variables);
}


// called functions:  examples
function innerWrite(location, xml_text) {
  $(location).innerHTML = xml_text;
}

// getting mouse position
var IE = document.all?true:false

if (!IE)
{
  addEventListener("mousemove", getMouseXY, false);
  //document.captureEvents(Event.MOUSEMOVE);
}

var tempX = 0
var tempY = 0

function getMouseXY(e) {
  if (IE) {
    tempX = event.clientX + document.body.scrollLeft
    tempY = event.clientY + document.body.scrollTop
  } else {
    tempX = e.pageX
    tempY = e.pageY
  }

  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}
}

function isEmail(string) {
  if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
  return true;
  else return false;
}

// called
/*
function resend_invitation(email_id, location) {
  var email = (email_id).value;
  if (!isEmail(email)) {alert('Invalid email address!'); (email_id).focus(); return false;}
  //alert("here calling " + 'resend&resend_email='+email)
  req('resend&resend_email='+email, location, 0);
}
*/
/*
function resend_invitation(email_id, location) {
req('not_received', location, 0);
}
*/
function showHide(divId) {
  if ((divId).style.display == 'none') {
  (divId).style.display = 'block';
  }
  else {
  (divId).style.display = 'none';
  }
}




