/*
	Javascri[t File for RiverCity Solutions
	Created 9.11.08
	by Jay
	copyright River City Studio
*/


//////////////////////////////////////
//  GENERIC RETURN ELEMENT FUNCTION //
//////////////////////////////////////

function getE( v ) {
  // e is for element!
  e = false;
  
	var d = window.document;
  if ( d.getElementById ) {
    e = d.getElementById( v );
  }
  else e = d[ v ];

  return e;
}

/*
	AJAX BASE FUNCTIONALITY
*/

var xmlhttp = null;
// var displayDiv = "attendeeBoxes";
var nextFunc = "";

////////////////////////////////
//	BASIC AJAX LOADER					//
////////////////////////////////

function getPage( displayDiv, url, second ) {
	
	if ( second != false ) nextFunc = second;
	else nextFunc = "";
	
	xmlhttp=null;
	if (window.XMLHttpRequest) {// code for all new browsers
  	xmlhttp=new XMLHttpRequest();
  }
	else if (window.ActiveXObject) {// code for IE5 and IE6
  	xmlhttp=new ActiveXObject( "Microsoft.XMLHTTP" );
  }
	if (xmlhttp!=null) {
		xmlhttp.onreadystatechange=function() {
			stateChange( displayDiv );
		};
		xmlhttp.open( "GET", url, true );
		xmlhttp.send( null );
  }
	else {
  	alert( "Your browser does not support XMLHTTP." );
  }
}

////////////////////////////////
//	EVENT HANDLER FOR HTTP		//
//	STATE CHANGE							//
////////////////////////////////

function stateChange( displayDiv, nextFunc ) {
	if (xmlhttp.readyState==4) {// 4 = "loaded"
		if (xmlhttp.status==200) {// 200 = OK
			e = getE( displayDiv );
			e.innerHTML = xmlhttp.responseText;
			if ( nextFunc != "" ) eval( nextFunc );
		}
		else {
			alert("Problem retrieving XML data");
		}
	}
}


function popBoxes( displayDiv, numAtt ) {
	e = getE( displayDiv );
	e.innerHTML = "<p>loading...</p>";
	getPage( displayDiv, "getAttendeeBoxes.php?numAtt="+numAtt );
}

function popAttendees( displayDiv, stringValue ) {
	e = getE( displayDiv );
	e.innerHTML = "<p>loading...</p>";
	getPage( displayDiv, "/admin/form/getFormContents.php?string=" + stringValue );
}

function saveConfirmationForm( displayDiv, id, email, calendar ) {
	
	if (email.checked) {
		email = 1;
	} else {
		email = 0;
	}
	
	if (calendar.checked) {
		calendar = 1;
	} else {
		calendar = 0;
	}

	e = getE( displayDiv );
	e.innerHTML = "<p>loading...</p>";
// 	alert( "The Value of Email is: " + email );
	getPage( displayDiv, "/admin/form/getConfirmationContents.php?id=" + id + "&emailConfirmation=" + email + "&enteredIntoCalendar=" + calendar );
}


///////////////////////////////////////
//	TERMS AND CONDITIONS VALIDATION  //
///////////////////////////////////////

function validateTerms(thisForm) {
	with(thisForm) {
		if (!terms.checked) {
			terms.focus();
			alert("Please Agree to the Terms and Conditions");
			return false;
		}
		
		return true;
	}
}

///////////////////////////////////////
//	REGISTER NOW BUTTONS FOR  LINKS  //
///////////////////////////////////////

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}