currentEl = 'holdingImage';
alreadyCalled = false;

function toggleBlocks(el){

	// check if blocks exist, if so, flash wasn't used, so hide/show proper cells
	if(document.getElementById(el)){
		if(currentEl != el){
			hide("holdingImage");
			hide("amenitiesList");
			hide("registerForm");
			hide("sendToAgent");
			hide("thankYouForRegistering");
			hide("thankYouForSubmitting");
			
			show(el);
		
			currentEl = el;
		}
	}else{
		// swfobject overwrote these... so we send these calls to flash
		
		if(!alreadyCalled){
			createJSFCommunicatorObject(thisMovie("mymovie"));
			alreadyCalled = true;	
		}
		
		if(el == 'amenitiesList'){
			fc.callFunction("_root.target","goAmen");
		}else if(el == 'registerForm'){
			fc.callFunction("_root.target","goRegister");
		}else if(el == 'sendToAgent'){
			fc.callFunction("_root.target","goSend");
		}		else if(el == 'holdingImage'){
			fc.callFunction("_root.target","goHome");
		}
	}
}

function show(el){
	document.getElementById(el).className = 'visibleBlock'; 
}

function hide(el){ 
	document.getElementById(el).className = 'hiddenBlock'; 
}

//this function return to Flash ActiveX Object or Plugin depending upon browser
//it takes care for browser type and returns the proper reference.
//Accepts the id or name of <OBJECT> or <EMBED> tag respectively
//Taken from Colin Moock (http://www.moock.org) code base.
function thisMovie(movieName) {
  // IE and Netscape refer to the movie object differently.
  // This function returns the appropriate syntax depending on the browser.
 
  	if (navigator.appName.indexOf ("Microsoft") !=-1) {
   		return window[movieName]
	} else {
		return window.document[movieName]
	}
}

function createJSFCommunicatorObject(playerObj){
	//create an instance of JSFCommunicator, pass the flashMovie's reference
	//make sure flash object is loaded when you create this object with parameter otherwise
	//you can JSFCommunicator.setMovie(flashMovie) once flash object is loaded
	fc = new JSFCommunicator(playerObj);
}

function submitRegistration(theForm){
	myConn = new XHConn();

	if(!myConn) return false;

	var emailOrPhoneChoice;
	var representedChoice;
	
	// get radio values
	for (counter = 0; counter < theForm.emailOrPhone.length; counter++){
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (theForm.emailOrPhone[counter].checked){
			emailOrPhoneChoice = theForm.emailOrPhone[counter].value; 
		}
	}

	for (counter = 0; counter < theForm.represented.length; counter++){
		// If a radio button has been selected it will return true
		// (If not it will return false)
		if (theForm.represented[counter].checked){
			representedChoice = theForm.represented[counter].value; 
		}
	}
	
	myConn.connect('formProcessor.php', 'POST', 'typeOfForm=registration&fullName='+theForm.fullName.value+'&emailAddress='+theForm.emailAddress.value+'&phone='+theForm.phone.value+'&emailOrPhone='+emailOrPhoneChoice+'&address1='+theForm.address1.value+'&address2='+theForm.address2.value+'&zipCode='+theForm.zipCode.value+'&howDidYouHear='+theForm.howDidYouHear.value+'&represented='+representedChoice+'&agent='+theForm.agent.value+'&comments='+theForm.comments.value, registrationIsDone); 

}

function registrationIsDone(){
	hide("holdingImage");
	hide("amenitiesList");
	hide("registerForm");
	hide("sendToAgent");
	hide("thankYouForSubmitting");
	show("thankYouForRegistering");
	
	currentEl = "thankYouForRegistering";
}

function submitToAgent(theForm){
	myConn = new XHConn();

	if(!myConn) return false;

	myConn.connect('formProcessor.php', 'POST', 'typeOfForm=agent&fullName='+theForm.toAgent_fullName.value+'&emailAddress='+theForm.toAgent_emailAddress.value+'&agentName='+theForm.toAgent_agentName.value+'&agentMail='+theForm.toAgent_agentMail.value+'&message='+theForm.toAgent_message.value, agentIsDone); 
	
}

function agentIsDone(){
	hide("holdingImage");
	hide("amenitiesList");
	hide("registerForm");
	hide("sendToAgent");
	hide("thankYouForRegistering");
	show("thankYouForSubmitting");
	
	currentEl = "thankYouForSubmitting";
}
