
function xmlhttpGet(strURL, strQuery) {
	agt = navigator.userAgent.toLowerCase();
	if(agt.indexOf("msie 6")==-1)
	{
		topPos = (getScrollXY() + 20) + 'px';
		document.getElementById("ajaxDiv").style.top = topPos;
	}
	else
	{
		topPos = (getScrollXY() - 170) + 'px';
		document.getElementById("ajaxDiv").style.top = topPos;
	}
	if(document.getElementById("TB_overlay"))
		document.getElementById("TB_overlay").style.display = 'inline';
	document.getElementById("ajaxDiv").style.display = 'inline';
	document.getElementById("ajaxDiv").innerHTML = '<img src="/js/loadingAnimationv3.gif" />';
    var xmlHttpReq = false;
    var self = this;
    if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = function() {
        if (self.xmlHttpReq.readyState == 4) {
            updateDiv(self.xmlHttpReq.responseText);
        }
    }
    self.xmlHttpReq.send(strQuery);
}

function updateDiv(str){
	document.getElementById("ajaxDiv").innerHTML = str;
}

function getScrollXY() {
  var scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
  } else if( document.body && document.body.scrollTop ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
  } else if( document.documentElement && document.documentElement.scrollTop ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
  }
  return scrOfY;
}


// This is the function to get the tutor from the dropdown and submit through Ajax
function submitTutor(tutorVal)
{
	tutorVal = escape(document.getElementById("ajaxTutorSelect").options[document.getElementById("ajaxTutorSelect").selectedIndex].value);
	url = 'action=email_joining&delegate_id=' + document.ajaxTutorForm.delegate_id.value + '&course_dates_id=';
	url+=  document.ajaxTutorForm.course_dates_id.value + '&selected_tutor=' + tutorVal;
	xmlhttpGet('ajax.php', url);
}


// This is the search box function with delay
function apply_add_ajax_search() {
	var theElement = document.getElementById('ajaxDelName');
	theElement.onkeyup = function(){ search_delay(this); };
}

function search_delay(element) {
	var func = function() { get_live_tabledata( element.value ); };
	if ( element.zid ) {
		clearTimeout(element.zid);
	}
	element.zid = setTimeout(func,500);
}

function get_live_tabledata(searchData)
{
	if(searchData != "")
	{
		xmlhttpGet('/admin/ajax.php', 'action=search&delName=' + searchData);
	}
	else
	{
		document.getElementById('ajaxDiv').style.display = 'none'; 
		document.getElementById('TB_overlay').style.display = 'none';
	}
}

// User Search for mailing list
function apply_mailing_ajax_search() {
	var theElement = document.getElementById('ajaxFindName');
	theElement.onkeyup = function(){ mailing_delay(this); };
}

function mailing_delay(element) {
	var func = function() { get_mailing_tabledata( element.value ); };
	if ( element.zid ) {
		clearTimeout(element.zid);
	}
	element.zid = setTimeout(func,500);
}

function get_mailing_tabledata(searchData)
{
	if(searchData != "")
	{
		xmlhttpGet('/admin/ajax.php', 'action=mailing_user_search&delName=' + searchData);
	}
	else
	{
		document.getElementById('ajaxDiv').style.display = 'none'; 
		document.getElementById('TB_overlay').style.display = 'none';
	}
}

// User Search for mailing organisation
function apply_mailing_org_ajax_search() {
	var theElement = document.getElementById('ajaxOrgName');
	theElement.onkeyup = function(){ mailing_org_delay(this); };
}

function mailing_org_delay(element) {
	var func = function() { get_mailing_org_tabledata( element.value ); };
	if ( element.zid ) {
		clearTimeout(element.zid);
	}
	element.zid = setTimeout(func,500);
}

function get_mailing_org_tabledata(searchData)
{
	if(searchData != "")
	{
		xmlhttpGet('/admin/ajax.php', 'action=mailing_org_search&delName=' + searchData);
	}
	else
	{
		document.getElementById('ajaxDiv').style.display = 'none'; 
		document.getElementById('TB_overlay').style.display = 'none';
	}
}


