var http;
var myApplicationPath="ajax/";

function CheckEMail(frm) {
	if (!SomethingEntered(frm.email,"Please enter your E-Mail Address")) return false;
	if (!echeck(frm.email.value)) {
		alert("The E-Mail address entered is not in the proper format.");
		frm.email.focus();
		return false;
	}
	return true;
}

function MainScreenContent(id) {
	http=initAjax();
    showStatus("Loading...");
	http.onreadystatechange = MainScreenContentResult;
	http.open("GET", myApplicationPath + "LoadMainContent.php?id=" + id, true);
    http.send(null);	
}
function MainScreenContentResult() {
	if (http.readyState == 4) {
        var newHTML = http.responseText;
		http = null;
		document.getElementById("welcome").innerHTML = newHTML;
		showStatus("");
	}
}

function ViewStaffProfile(id) {
	http=initAjax();
    showStatus("Loading...");
	http.onreadystatechange = ViewStaffProfileResult;
	http.open("GET", myApplicationPath + "ViewStaffProfile.php?id=" + id, true);
    http.send(null);	
}
function ViewStaffProfileResult() {
	if (http.readyState == 4) {
        var newHTML = http.responseText;
		http = null;
		document.getElementById("staffmember").innerHTML = newHTML;
		showStatus("");
	}
}

// Show Current Status
function showStatus(statusText){
	if (statusText == "") {
		document.getElementById("StatusArea").style.padding = "0px";
		document.getElementById("StatusArea").style.visibility = "hidden";
	} else {    
		document.getElementById("StatusArea").style.padding = "2px";
		document.getElementById("StatusArea").style.visibility = "visible";
		document.getElementById("StatusArea").innerHTML = statusText;
	}
}
//this function initializes the http object
function initAjax(){
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
	  xmlhttp.overrideMimeType("text/xml");	  
    } catch (e) {
      xmlhttp = false;
    }
  }
  return xmlhttp;
}

function SomethingEntered(formField, fieldMessage) {
	var result = true;
	if (formField.value == "") {
		alert(fieldMessage);
		formField.focus();
		result = false;
	}
	return result;
}

function Trim(STRING){
	STRING = LTrim(STRING);
	return RTrim(STRING);
}

function RTrim(STRING){
	while(STRING.charAt((STRING.length -1))==" "){
		STRING = STRING.substring(0,STRING.length-1);
	}
	return STRING;
}

function LTrim(STRING){
	while(STRING.charAt(0)==" "){
		STRING = STRING.replace(STRING.charAt(0),"");
	}
	return STRING;
}

function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}
	if ( str.charAt(lstr-4) != "." ) {
		if ( str.charAt(lstr-3) != "." ) {
			return false;
		}
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		return false
	 }

	 return true					
}
