// start ajax
   var http_request = false;
   function makePOSTRequest(url, parameters) {
      http_request = false;
	  if (window.XMLHttpRequest) { // Mozilla, Safari,...
         http_request = new XMLHttpRequest();
         if (http_request.overrideMimeType) {
         	// set type accordingly to anticipated content type
            //http_request.overrideMimeType('text/xml');
            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('Cannot create XMLHTTP instance');
         return false;
      }
	  http_request.onreadystatechange = alertContents;
	  http_request.open('POST', url, true);
      http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
      http_request.setRequestHeader("Content-length", parameters.length);
      http_request.setRequestHeader("Connection", "close");
      http_request.send(parameters);
	  //alert("ddd");
   }
function alertContents() {
  //alert(http_request.readyState);
  if (http_request.readyState == 4) {
	 //alert(http_request.status);
	 if (http_request.status == 200) {
		//alert(http_request.responseText);
		result = http_request.responseText;
		if ( (result == "sessionInvalid") || (result == "noPermission") ) {
			location.href = 'http://www.listenloud.org/admin/index.php?' + result;
		} else {
			var resultArray = result.split("**%%%**");
			//alert(resultArray[0]);
			//alert(resultArray[1]);
			if ( (resultArray[0].length == 0) || (resultArray[0].toLowerCase() == "blank") ) {
				// do nothing
			} else {
				//populate
				document.getElementById(formElementIdAlert).value = resultArray[0];
			}
			document.getElementById('infoText').innerHTML = resultArray[1];
			var timeOutInfoBox = setTimeout("document.getElementById('infoBox').style.margin = '0 0 0 -999em'", 1000);
		}
		
	 } else {
		alert('There was a problem with the request.');
	 }
  }
}
function updatePost3vars(obj, theValue, theValue2, mySQLId, postPage, formElementId) {
 var poststr =  "theValue=" + escape(encodeURI(theValue))  +
				"&theValue2=" + escape(encodeURI(theValue2))  +
				"&mySQLId=" + escape(encodeURI(mySQLId))  +
				"&postPage=" + escape(encodeURI(postPage)) +
				"&formElementId=" + escape(encodeURI(formElementId));
			
  //alert(poststr);
  // define variables globally
  //theValueAlert = theValue;
  //mySQLIdAlert = mySQLId;
  //postPageAlert = postPage;
  formElementIdAlert = formElementId;
  makePOSTRequest(postPage, poststr);
  // show the dialog box with 'please wait'
  document.getElementById('infoBox').style.margin = "0 0 0 0";
  document.getElementById('infoText').innerHTML = "<p>Please Wait</p>";
}
function updatePost2vars(obj, theValue, mySQLId, postPage, formElementId) {
 var poststr =  "theValue=" + escape(encodeURI(theValue))  +
				"&mySQLId=" + escape(encodeURI(mySQLId))  +
				"&postPage=" + escape(encodeURI(postPage)) +
				"&formElementId=" + escape(encodeURI(formElementId));
			
  //alert(poststr);
  // define variables globally
  //theValueAlert = theValue;
  //mySQLIdAlert = mySQLId;
  //postPageAlert = postPage;
  formElementIdAlert = formElementId;
  makePOSTRequest(postPage, poststr);
  // show the dialog box with 'please wait'
  document.getElementById('infoBox').style.margin = "0 0 0 0";
  document.getElementById('infoText').innerHTML = "<p>Please Wait</p>";
}
var xmlHttp;
function checkAndDisplay(theValue, theFileURL, theDivId, theFieldId) {
	//if (theValue.length==0)
	  //{ 
	  //document.getElementById(theDivId).innerHTML="";
	  //return;
	  //}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url=theFileURL;
	url=url+"?q="+theValue;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	// define globally
	thisDivId = theDivId;
	thisFieldId = theFieldId;
	document.getElementById(thisDivId).style.backgroundImage = "url(\"/images/design/interface/waiting.gif\")";
	document.getElementById(thisDivId).innerHTML = "Checking...";
}
function stateChanged() { 
	if (xmlHttp.readyState==4) {
		//alert(xmlHttp.responseText );
		var cadArray = xmlHttp.responseText.split("**%%%**");
		if (cadArray[0] != "OK") {
			document.getElementById(thisDivId).style.backgroundImage = "url(\"/images/design/interface/cross.png\")";
			if (cadArray[1].length > 0) {
				document.getElementById(thisFieldId).value = cadArray[1];
			}
			document.getElementById(thisDivId).innerHTML=cadArray[0];
		} else {
			document.getElementById(thisDivId).style.backgroundImage = "url(\"/images/design/interface/tick.png\")";
			if (cadArray[1].length > 0) {
				document.getElementById(thisFieldId).value = cadArray[1];
			}
			document.getElementById(thisDivId).innerHTML=cadArray[0];
		}
	}
}
function GetXmlHttpObject() {
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  xmlHttp.overrideMimeType('text/xml; charset=utf-8');
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
		{
		xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		xmlHttp.overrideMimeType('text/xml; charset=utf-8');
		}
	  catch (e)
		{
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	  }
	return xmlHttp;
}
function simpleAJAXDisplay(theValue, theValue2, theFileURL, theDivId) {
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	var url=theFileURL;
	url=url+"?q="+theValue;
	url=url+"&r="+theValue2;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=showAJAXresult;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	// define globally
	simpleAJAXdivId = theDivId;
	document.getElementById(simpleAJAXdivId).innerHTML = "Checking...";	
}
function showAJAXresult() { 
	if (xmlHttp.readyState==4) {
		 if (xmlHttp.status == 200) {
			//alert(xmlHttp.responseText );
			var result = xmlHttp.responseText;
			document.getElementById(simpleAJAXdivId).innerHTML=result;
		 } else {
		 	alert('There was a problem with the request.');
		 }
	}
}
function getStyle(oElm, strCssRule){
  var strValue = "";
  if(document.defaultView && document.defaultView.getComputedStyle){
    strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
  }
  else if(oElm.currentStyle){
    strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
      return p1.toUpperCase();
    });
    strValue = oElm.currentStyle[strCssRule];
  }
  return strValue;
}
function checkThenSubmit(chosenStyle, searchString, formId) {
	var divArray = document.getElementsByTagName("div");
	var divLen = divArray.length;
	var formValid = 1;
	if (divLen > 0) {
		for ( var i=0; i < divLen; i++ ) {
			if ( getStyle(divArray[i], chosenStyle).indexOf(searchString) > -1)    {
				formValid = 0;
				alert(divArray[i].innerHTML);
				return false;
			}
		}
	}
	if (formValid == 1) {
		document.getElementById(formId).submit();
		return true;
	}
}
function showHideLayer(divId) {	
	var marStyle = document.getElementById(divId).style.margin;
	if ( (marStyle == "0em 0em 0em 0em") || (marStyle == "0em") || (marStyle == "0 0 0 0") || (marStyle == "0 0 0 0em") ) {
		document.getElementById(divId).style.margin = "0em 0em 0em -999em";
		
	} else {
		document.getElementById(divId).style.margin = "0em 0em 0em 0em";
	}
}
function confirmAction(warningMessage, formId, cancelMessage, confirmMesssage) {
	var theConfirm = confirm(warningMessage);
	if (theConfirm == true) {
		alert(confirmMesssage);
		if (formId.length > 0) {
			document.getElementById(formId).submit();
		}
	} else {
		alert(cancelMessage);
	}
}
function alertTandC(checkBoxId, formId, message) {
	if (document.getElementById(checkBoxId).checked == true) {
		document.getElementById(formId).submit();
	} else {
		alert(message);
	}
}
function showOneHideAll(elementId, linkSpanId, divClassId) {
	if (document.getElementById(linkSpanId).innerHTML == 'less info') {
		document.getElementById(elementId).style.margin='0 0 0 -999em';
		document.getElementById(elementId).style.height='0';
		document.getElementById(linkSpanId).innerHTML='more info';	
	} else {
		// reset everything
		var spanArray = document.getElementsByTagName("span");
		var spanLen = spanArray.length;
		if (spanLen > 0) {
			for ( var i=0; i < spanLen; i++ ) {
				if (spanArray[i].innerHTML == 'less info') {
					spanArray[i].innerHTML = 'more info';
				}
			}
		}
		var divArray = document.getElementsByTagName("div");
		var divLen = divArray.length;
		if (divLen > 0) {
			for ( var i=0; i < divLen; i++ ) {
				if (divArray[i].getAttribute('class') == divClassId)  {
					divArray[i].style.margin='0 0 0 -999em';
					divArray[i].style.height='0';
				}
			}
		}
		document.getElementById(elementId).style.margin='0 0 0 0';
		document.getElementById(elementId).style.height='auto';
		document.getElementById(linkSpanId).innerHTML='less info';				
	}
}