//functions.js
//Create a boolean variable to check for a valid IE instance.
var xmlhttp = false;

//Check if we are using IE. 
try {
//If the javascript version is greater than 5.
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
//If not, then use the older active x object.
try {
//If we are using IE.
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
//Else we must be using a non-IE browser.
xmlhttp = false;
}
}
//If we are using a non-IE browser, create a JavaScript instance of the object.
if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
xmlhttp = new XMLHttpRequest();
}

// the above sets up the xmlhttprequest function.
function getXMLHTTPRequest()
	{
		var req = false;
			try
				{
					req = new XMLHttpRequest(); /* e.g. Firefox */
				}
				catch(err1)
					{
						try
							{
								req = new ActiveXObject("Msxml2.XMLHTTP");
/* some versions IE */
							}
						catch(err2)
							{
								try
									{
										req = new ActiveXObject("Microsoft.XMLHTTP");
/* some versions IE */
									}
						catch(err3)
							{
								req = false;
							}
							}
				}
		return req;
	}
	
var myRequest = getXMLHTTPRequest();
function callAjaxC() {
// declare a variable to hold some information
// to pass to the server
// var lastname = 'Smith';
var country = document.form3.country.value;
// build the URL of the server script we wish to call
var url = "fillstates.php?country=" + country;
// generate a random number
var myRandom=parseInt(Math.random()*99999999);
// ask our XMLHTTPRequest object to open
// a server connection
myRequest.open("GET", url + "&rand=" + myRandom, true);
// prepare a function responseAjax() to run when
// the response has arrived
myRequest.onreadystatechange = responseAjaxc;
// and finally send the request
myRequest.send(null);
}
//
function ajaxlogout() {
// declare a variable to hold some information
// to pass to the server
var username = document.form1.username.value;
var state = document.form1.state.value;
// build the URL of the server script we wish to call
var url = "checklogout.php?username=" + username+ "&state=" + state;
// generate a random number
var myRandom=parseInt(Math.random()*99999999);
// ask our XMLHTTPRequest object to open
// a server connection
myRequest.open("GET", url + "&rand=" + myRandom, true);
// prepare a function responseAjax() to run when
// the response has arrived
myRequest.onreadystatechange = logoutresponseAjax;
// and finally send the request
myRequest.send(null);
	
}

//
function ajaxcheckname() {
// declare a variable to hold some information
// to pass to the server
var username = document.form1.username.value;
// build the URL of the server script we wish to call
var url = "checklogin.php?username=" + username;
// generate a random number
var myRandom=parseInt(Math.random()*99999999);
// ask our XMLHTTPRequest object to open
// a server connection
myRequest.open("GET", url + "&rand=" + myRandom, true);
// prepare a function responseAjax() to run when
// the response has arrived
 myRequest.onreadystatechange = usercheckresponseAjax;

// and finally send the request
myRequest.send(null);
	
}
//
function ajaxlogin() {
// declare a variable to hold some information
// to pass to the server
var username = document.form1.username.value;
var password = document.form1.password.value;
var state = document.form1.state.value;
// build the URL of the server script we wish to call
var url = "checklogin.php?username=" + username + "&password=" + password + "&state=" + state;
// generate a random number
var myRandom=parseInt(Math.random()*99999999);
// ask our XMLHTTPRequest object to open
// a server connection
myRequest.open("GET", url + "&rand=" + myRandom, true);
// prepare a function responseAjax() to run when
// the response has arrived
 myRequest.onreadystatechange = loginresponseAjax;

// and finally send the request
myRequest.send(null);
	
}

function callAjax() {
// declare a variable to hold some information
// to pass to the server
// var lastname = 'Smith';
var lastname = document.form3.username.value;
// build the URL of the server script we wish to call
var url = "verifyname.php?surname=" + lastname;
// generate a random number
var myRandom=parseInt(Math.random()*99999999);
// ask our XMLHTTPRequest object to open
// a server connection
myRequest.open("GET", url + "&rand=" + myRandom, true);
// prepare a function responseAjax() to run when
// the response has arrived
myRequest.onreadystatechange = responseAjax;
// and finally send the request
myRequest.send(null);
}
//
function filladd() {
// declare a variable to hold some information
// to pass to the server
// var lastname = 'Smith';
//var pid = document.viewadd.pid.value;
// build the URL of the server script we wish to call
var url = "checklogin.php";
// generate a random number
var myRandom=parseInt(Math.random()*99999999);
// ask our XMLHTTPRequest object to open
// a server connection
myRequest.open("GET", url + "&rand=" + myRandom, true);
// prepare a function responseAjax() to run when
// the response has arrived
myRequest.onreadystatechange = returnaddtable;
// and finally send the request
myRequest.send(null);
}
//
function viewadd() {
// declare a variable to hold some information
// to pass to the server
// var lastname = 'Smith';
var pid = document.viewadd.pid.value;
// build the URL of the server script we wish to call
var url = "getadd.php?pid=" +pid;
// generate a random number
var myRandom=parseInt(Math.random()*99999999);
// ask our XMLHTTPRequest object to open
// a server connection
myRequest.open("GET", url + "&rand=" + myRandom, true);
// prepare a function responseAjax() to run when
// the response has arrived
myRequest.onreadystatechange = viewaddreturn;
// and finally send the request
myRequest.send(null);
}
//  ******************************** Beginning of callback functions.
//
// return add table

// function to return viewed add

function returnaddtable() {
// we are only interested in readyState of 4,
// i.e. "completed"
if(myRequest.readyState == 4) {
// if server HTTP response is "OK"
if(myRequest.status == 200) {

 var result = myRequest.responseText;
 var reply = '';
 alert("The server said: "+ myRequest.responseText);

   				 document.getElementById('addspace').innerHTML = ''+result;	
														 					 
				} else {
// issue an error message for
// any other HTTP response
alert("An error has occurred: Could not load "+ myRequest.statusText);
}
}
}



// function to return viewed add

function viewaddreturn() {
// we are only interested in readyState of 4,
// i.e. "completed"
if(myRequest.readyState == 4) {
// if server HTTP response is "OK"
if(myRequest.status == 200) {

 var result = myRequest.responseText;
 var reply = '';
 alert("The server said: "+ myRequest.responseText);

   				 document.getElementById('manage').innerHTML = ''+reply;	
														 					 
				} else {
// issue an error message for
// any other HTTP response
alert("An error has occurred: Logout didnt happen "+ myRequest.statusText);
}
}
}


//
// Logout response ajax
function logoutresponseAjax() {
// we are only interested in readyState of 4,
// i.e. "completed"
if(myRequest.readyState == 4) {
// if server HTTP response is "OK"
if(myRequest.status == 200) {

 var result = myRequest.responseText;
 var reply = '';
// alert("The server said: "+ myRequest.responseText);
 reply = '<form name="form1" method="POST"  class="content"><input type="text" name="username" id="username" size="8"><input name="password" type="password" value="password" id="password" size="6"><a href="javascript://" onclick="ajaxlogin()">Login</a><input name="state" type="hidden" value="in" ></form>';
			 
		
			 
			  var txt=document.getElementById("loginDiv") 
			   txt.innerHTML=reply;
						//	 document.getElementById('stateDiv').innerHTML = document.write(reply);
										 					 
				} else {
// issue an error message for
// any other HTTP response
alert("An error has occurred: Logout didnt happen "+ myRequest.statusText);
}
}
}

 function usercheckresponseAjax() {
// we are only interested in readyState of 4,
// i.e. "completed"
if(myRequest.readyState == 4) {
// if server HTTP response is "OK"
if(myRequest.status == 200) {

 var result = myRequest.responseText;
 var reply = '';
 var username = '';
alert("The server said: "+ myRequest.responseText);
				 if (result == 'success') {
  
	
	
		  var txt=document.getElementById("checknamediv") 
			   txt.innerHTML=result;
	 					} else {
// issue an error message for
// any other HTTP response
alert("An error has occurred: "+ myRequest.statusText);
}
}
}}

// Login response ajax
function loginresponseAjax() {
// we are only interested in readyState of 4,
// i.e. "completed"
if(myRequest.readyState == 4) {
// if server HTTP response is "OK"
if(myRequest.status == 200) {

 var result = myRequest.responseText;
 var reply = '';
 var username = '';
 //alert("The server said: "+ myRequest.responseText);
				//	 if (result == 'success') {
    reply='<form name="form1" method="POST"><input name="state" type="hidden" value="out" ><input name="username" type="hidden" value="<? echo $MM_Username; ?> "><a href="javascript://" onclick="ajaxlogout()">Log Out</a> User: <? echo $MM_Username; ?> State = <? echo $state; ?></form>';
	
	
		  var txt=document.getElementById("loginDiv") 
			   txt.innerHTML=reply+result;
	 					} else {
// issue an error message for
// any other HTTP response
alert("An error has occurred: "+ myRequest.statusText);
}
}
}

//
function responseAjax() {
// we are only interested in readyState of 4,
// i.e. "completed"
if(myRequest.readyState == 4) {
// if server HTTP response is "OK"
if(myRequest.status == 200) {

 var result = myRequest.responseText;

// alert("The server said: "+ myRequest.responseText);
 if (result == 'Available') {
	// alert("This name is available to use");
	 document.getElementById('myDiv').innerHTML = 'Username is Available';	 
	  } else {
		 document.getElementById('myDiv').innerHTML = 'Username is NOT Available. Please try another name!';	  
		  }
} else {
// issue an error message for
// any other HTTP response
alert("An error has occurred: "+ myRequest.statusText);
}
}
}


// return states depending on country
function responseAjaxc() {
// we are only interested in readyState of 4,
// i.e. "completed"
if(myRequest.readyState == 4) {
// if server HTTP response is "OK"
if(myRequest.status == 200) {

 var result = myRequest.responseText;

// alert("The server said: "+ myRequest.responseText);
 
	// alert("This name is available to use");
	 document.getElementById('states').innerHTML = result;	 
	
} else {
// issue an error message for
// any other HTTP response
alert("An error has occurred: in States "+ myRequest.statusText);
}
}
}
//A variable used to distinguish whether to open or close the calendar.
var showCalendar = true;
function showHideCalendar() {
	
//The location we are loading the page into.
var objID = "calendar";
//Change the current image of the minus or plus.
if (showCalendar == true){
//Show the calendar.

 document.getElementById("opencloseimg").src = "images/tick.gif";
 
//The page we are loading.
var serverPage = "calendar.php";
//Set the open close tracker variable.
showCalendar = false;
var obj = document.getElementById(objID);
xmlhttp.open("GET", serverPage);
xmlhttp.onreadystatechange = function() {

if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
} else {
//Hide the calendar.
document.getElementById("opencloseimg").src = "images/loading.gif";
showCalendar = true;
document.getElementById(objID).innerHTML = "";
}
}

function createform (e){

theObject = document.getElementById("createtask");
theObject.style.visibility = "visible";
theObject.style.height = "200px";
theObject.style.width = "200px";
var posx = 0;
var posy = 0;
posx = e.clientX + document.body.scrollLeft;
posy = e.clientY + document.body.scrollTop;
theObject.style.left = posx + "px";
theObject.style.top = posy + "px";
//The location we are loading the page into.
document.write("Inside createform");
var objID = "createtask";
var serverPage = "theform.php";
var obj = document.getElementById(objID);
xmlhttp.open("GET", serverPage);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}
function closetask (){
theObject = document.getElementById("createtask");
theObject.style.visibility = "hidden";
theObject.style.height = "0px";
theObject.style.width = "0px";
acObject = document.getElementById("autocompletediv");
acObject.style.visibility = "hidden";
acObject.style.height = "0px";
acObject.style.width = "0px";
}
function findPosX(obj){
var curleft = 0;
if (obj.offsetParent){
while (obj.offsetParent){
curleft += obj.offsetLeft
obj = obj.offsetParent;
}
} else if (obj.x){
curleft += obj.x;
}
return curleft;
}
function findPosY(obj){
var curtop = 0;
if (obj.offsetParent){
while (obj.offsetParent){
curtop += obj.offsetTop
obj = obj.offsetParent;
}
} else if (obj.y){
curtop += obj.y;
}
return curtop;
}
function autocomplete (thevalue, e){
theObject = document.getElementById("autocompletediv");
theObject.style.visibility = "visible";
theObject.style.width = "152px";
var posx = 0;
var posy = 0;
posx = (findPosX (document.getElementById("yourname")) + 1);
posy = (findPosY (document.getElementById("yourname")) + 23);
theObject.style.left = posx + "px";
theObject.style.top = posy + "px";
var theextrachar = e.which;
if (theextrachar == undefined){
theextrachar = e.keyCode;
}
//The location we are loading the page into.
var objID = "autocompletediv";
//Take into account the backspace.
if (theextrachar == 8){
if (thevalue.length == 1){
var serverPage = "autocomp.php";
} else {
var serverPage = "autocomp.php" + "?sstring=" + thevalue.substr (0, (thevalue.length -1));
}
} else {
var serverPage = "autocomp.php" + "?sstring=" + thevalue + String.fromCharCode (theextrachar);
}
var obj = document.getElementById(objID);
xmlhttp.open("GET", serverPage);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(null);
}
function setvalue (thevalue){
acObject = document.getElementById("autocompletediv");
acObject.style.visibility = "hidden";
acObject.style.height = "0px";
acObject.style.width = "0px";
document.getElementById("yourname").value = thevalue;
}

function showDiv(divID_as_a_string) {
  //get a reference as above ...
  myReference = getRefToDiv(divID_as_a_string);
  if( !myReference ) {
    window.alert('Nothing works in this browser');
    return; //don't go any further
  }
  //now we have a reference to it
  if( myReference.style ) {
    //DOM & proprietary DOM
    myReference.style.visibility = 'visible';
  } else {
    //layers syntax
    myReference.visibility = 'show';
  }
}
function changeDisplay( elementId, setTo ) {
  var theElement;
  if( document.getElementById ) {
    //DOM
    theElement = document.getElementById( elementId );
  } else if( document.all ) {
    //Proprietary DOM
    theElement = document.all[ elementId ];
  }
  if( !theElement ) {
    /* The page has not loaded, or the browser claims to
    support document.getElementById or document.all but
    cannot actually use either */
    return;
  }
  //Reference the style ...
  if( theElement.style ) { theElement = theElement.style; }
  if( typeof( theElement.display ) == 'undefined' ) {
    //The browser does not allow us to change the display style
    //Alert something sensible (not what I have here ...)
    window.alert( 'Your browser does not support this' );
    return;
  }
  //Change the display style
  theElement.display = setTo;
}


function formValidator(){
	// Make quick references to our fields
	var firstname = document.getElementById('firstname');
	var addr = document.getElementById('addr');
	var zip = document.getElementById('zip');
	var state = document.getElementById('state');
	var username = document.getElementById('username');
	var email = document.getElementById('email');
	
	// Check each input in the order that it appears in the form!
	if(isAlphabet(firstname, "Please enter only letters for your name")){
		if(isAlphanumeric(addr, "Numbers and Letters Only for Address")){
			if(isNumeric(zip, "Please enter a valid zip code")){
				if(madeSelection(state, "Please Choose a State")){
					if(lengthRestriction(username, 6, 8)){
						if(emailValidator(email, "Please enter a valid email address")){
							return true;
						}
					}
				}
			}
		}
	}
	
	
	return false;
	
}

function loadManageNav() {
    var el = document.getElementById("loginDiv");
    if(el) {   var xmlhttp = getXmlHttpObject();
        if(xmlhttp) {
            el.innerHTML = 'Loading...';
            function abort(){
                xmlhttp.abort();
                el.innerHTML = 'Timeout';
            }
            var t = setTimeout(function(){ abort(); }, 20000);//eg 20 seconds
            xmlhttp.open("GET", "checklogin.php", true);
            xmlhttp.onreadystatechange=function() {
                if (xmlhttp.readyState==4) {
                    clearTimeout(t);
                    if (xmlhttp.status==200) { el.innerHTML = xmlhttp.responseText; }
                    else { el.innerHTML = 'Error serving data'; }
                }
            }
            xmlhttp.send(null);
        }
        else {
            el.innerHTML = 'Error requesting data.';
        }
    }
}



<!--
var time = 3000;
var numofitems = 8;

//menu constructor
function menu(allitems,thisitem,startstate){ 
  callname= "gl"+thisitem;
  divname="subglobal"+thisitem;  
  this.numberofmenuitems = allitems;
  this.caller = document.getElementById(callname);
  this.thediv = document.getElementById(divname);
  this.thediv.style.visibility = startstate;
}

//menu methods
function ehandler(event,theobj){
  for (var i=1; i<= theobj.numberofmenuitems; i++){
    var shutdiv =eval( "menuitem"+i+".thediv");
    shutdiv.style.visibility="hidden";
  }
  theobj.thediv.style.visibility="visible";
}
				
function closesubnav(event){
  if ((event.clientY <48)||(event.clientY > 107)){
    for (var i=1; i<= numofitems; i++){
      var shutdiv =eval('menuitem'+i+'.thediv');
      shutdiv.style.visibility='hidden';
    }
  }
}

 

// -->


<!-- // BannerAD

   var bannerAD=new Array();
   var bannerADlink=new Array();
   var adNum=0;

   bannerAD[0]="images/2flagboul2.gif";
   bannerADlink[0]="";
   bannerAD[1]="images/2flagrocket.gif";
   bannerADlink[1]="";
   bannerAD[2]="images/2flags.jpg";
   bannerADlink[2]="";
   bannerAD[3]="images/lighteningayresrock.gif";
   bannerADlink[3]="";
   bannerAD[4]="images/choices2.gif";
   bannerADlink[4]="";
   bannerAD[5]="images/meandmyshadowvtx1300.gif";
   bannerADlink[5]="";
   bannerAD[6]="images/ruvtx1300.gif";
   bannerADlink[6]="";
   bannerAD[7]="images/therapyboul.gif";
   bannerADlink[7]="";
   bannerAD[8]="images/whiskey.gif";
   bannerADlink[8]="";

   var preloadedimages=new Array();
   for (i=1;i<bannerAD.length;i++){
      preloadedimages[i]=new Image();
      preloadedimages[i].src=bannerAD[i];
   }

function setTransition(){
   if (document.all){
      bannerADrotator.filters.revealTrans.Transition=Math.floor(Math.random()*23);
      bannerADrotator.filters.revealTrans.apply();
   }
}

function playTransition(){
   if (document.all)
      bannerADrotator.filters.revealTrans.play()
}

function nextAd(){
   if(adNum<bannerAD.length-1)adNum++ ;
      else adNum=0;
   setTransition();
   document.images.bannerADrotator.src=bannerAD[adNum];
   playTransition();
   theTimer=setTimeout("nextAd()", 5000);
}

function jump2url(){
   jumpUrl=bannerADlink[adNum];
   jumpTarget='';
   if (jumpUrl != ''){
      if (jumpTarget != '')window.open(jumpUrl,jumpTarget);
      else location.href=jumpUrl;
   }
}
function displayStatusMsg() { 
   status=bannerADlink[adNum];
   document.returnValue = true;
}

<!-- // BannerAD

   var bannerAD=new Array();
   var bannerADlink=new Array();
   var adNum=0;

   bannerAD[0]="images/events/AB4D-033.jpg";
   bannerADlink[0]="";
   bannerAD[1]="images/events/AB4D-035mjpg";
   bannerADlink[1]="";
   bannerAD[2]="images/events/twinflags.jpg";
   bannerADlink[2]="";
   bannerAD[3]="images/events/k1845461.jpg";
   bannerADlink[3]="";
   bannerAD[4]="images/events/sunday-morning.jpg";
   bannerADlink[4]="";
   bannerAD[5]="images/events/SunriseRunFeb08019.jpg";
   bannerADlink[5]="";
   bannerAD[6]="images/events/k0408631.jpg";
   bannerADlink[6]="";
   bannerAD[7]="images/events/SunriseRunFeb08005.jpg";
   bannerADlink[7]="";
   bannerAD[8]="images/events/SunriseRunFeb08019.jpg";
   bannerADlink[8]="";

   var preloadedimages=new Array();
   for (i=1;i<bannerAD.length;i++){
      preloadedimages[i]=new Image();
      preloadedimages[i].src=bannerAD[i];
   }

function setTransition(){
   if (document.all){
      bannerADrotator.filters.revealTrans.Transition=Math.floor(Math.random()*23);
      bannerADrotator.filters.revealTrans.apply();
   }
}

function playTransition(){
   if (document.all)
      bannerADrotator.filters.revealTrans.play()
}

function nextAd(){
   if(adNum<bannerAD.length-1)adNum++ ;
      else adNum=0;
   setTransition();
   document.images.bannerADrotator.src=bannerAD[adNum];
   playTransition();
   theTimer=setTimeout("nextAd()", 5000);
}

function jump2url(){
   jumpUrl=bannerADlink[adNum];
   jumpTarget='';
   if (jumpUrl != ''){
      if (jumpTarget != '')window.open(jumpUrl,jumpTarget);
      else location.href=jumpUrl;
   }
}
function displayStatusMsg() { 
   status=bannerADlink[adNum];
   document.returnValue = true;
}


//-->

