//---------------------------------------------------------------------------------------------
// ROLLOVER FLASH MAP SEARCH JAVASCRIPT
// © VEBRA Plc 2003 
// Written by Richard Stephenson / modified for samuelmiles 21/07/03



areanames = new Array("area1","area2","area3","area4","area5");
areaareas = new Array("aloNorthofRugeley","aloEastofRugeley","aloSouthofRugeley","aloWestofRugeley","aloCentralRugeley");

function checkwhatson() {
	
	for (i = 0; i <= 4; i ++) {	
		fred = areanames[i];
		//alert(fred);
		if (window.document.getElementById(areaareas[i]).checked == true) {
			
			var areaselected = fred + "selected";
			doPassVar(areaselected,"yes")
			var movieclip = '/map/' + fred;
			document.flashMap.TGotoFrame(movieclip,1);
			window.document.getElementById(fred).style.color = "#FFCC33";
		
		} else {
			
			var areaselected = areanames[i] + "selected";
			doPassVar(areaselected,"no")
			var movieclip = '/map/' + areanames[i];
				document.flashMap.TGotoFrame(movieclip,0);
				window.document.getElementById(fred).style.color = "#003366";
		}
	}
}

//---------------------------------------------------------------------------------------------


// FUNCTION TO TURN ON/OFF CHECKBOXES AND AREAS IN MAP WHEN TEXT IS CLICKED
function clicktext(thearea) {
	
	// Loop through array
	for (i = 0; i <= 4; i ++) {	
		
		//Find coresponding checkbox id
		if (thearea == areanames[i]) {
			var whichbox = areaareas[i];
		}
	}
	
	// If checkbox is already selected
	if(window.document.getElementById(whichbox).checked == true) {
		
		// Unselect checkbox
		window.document.getElementById(whichbox).checked = false;
		
		// Build areaselected variable to send to flash
		var areaselected = thearea + "selected";
		//alert(whichbox);
		// Send areaselected to flash using doPassVar function
		doPassVar(areaselected,"no")
		
		// Build movieclip name
		var movieclip = '/map/' + thearea;
		
		// GoTo 'normal' frame in movieclip
		document.flashMap.TGotoFrame(movieclip,0);
		window.document.getElementById(thearea).style.color = "#003366";
	
	// If checkbox is not selected	
	} else {
		
		// Select checkbox
		window.document.getElementById(whichbox).checked = true;
		
		// Build areaselected variable to send to flash
		var areaselected = thearea + "selected";
		
		// Send areaselected to flash using doPassVar function
		doPassVar(areaselected,"yes")
		
		// Build movieclip name
		var movieclip = '/map/' + thearea;
		
		// GoTo 'selected' frame in movieclip
		document.flashMap.TGotoFrame(movieclip,1);
		window.document.getElementById(thearea).style.color = "#003366";
	}
}

//-------------------------------------------------------------
// Script to select All Regions
function ShowAllAreas(){
 for (i = 0; i <= 4; i++) {
 	document.searchform[i].checked =! document.searchform.AllAreas.checked; 
 }
 document.searchform.AllAreas.checked =! document.searchform.AllAreas.checked; 
}

// Script to select all Property Types
function ShowPropTypes(){
 if (document.searchform.AllPropType.checked){
  document.searchform.typ[0].checked = false;	
	document.searchform.typ[1].checked = false;
	document.searchform.typ[2].checked = false;
	document.searchform.typ[3].checked = false;
	document.searchform.typ[4].checked = false;
	document.searchform.typ[5].checked = false;
	document.searchform.typ[6].checked = false;
	document.searchform.typ[7].checked = false;
	document.searchform.typ[8].checked = false;
	document.searchform.typ[9].checked = false;
	document.searchform.typ[10].checked = false;
	document.searchform.AllPropType.checked = false;
 } else {
 	document.searchform.typ[0].checked = true;
	document.searchform.typ[1].checked = true;
	document.searchform.typ[2].checked = true;
	document.searchform.typ[3].checked = true;
	document.searchform.typ[4].checked = true;
	document.searchform.typ[5].checked = true;
	document.searchform.typ[6].checked = true;
	document.searchform.typ[7].checked = true;
	document.searchform.typ[8].checked = true;
	document.searchform.typ[9].checked = true;
	document.searchform.typ[10].checked = true;
	document.searchform.AllPropType.checked = true;
 }
}
//---------------------------------------------------------------

// FUNCTION TO TURN ON/OFF AREAS IN MAP WHEN CHECKBOX IS CLICKED
function clickcheckbox(whichbox,thearea) {
	
	// If checkbox is already selected
	if(window.document.getElementById(whichbox).checked == true) {
		
		// Build areaselected variable to send to flash
		var areaselected = thearea + "selected";
		
		// Send areaselected to flash using doPassVar function
		doPassVar(areaselected,"yes")
		
		// Build movieclip name
		var movieclip = '/map/' + thearea;
		
		// GoTo 'selected' frame in movieclip
		document.flashMap.TGotoFrame(movieclip,1);
		window.document.getElementById(thearea).style.color = "#003366";
		window.document.getElementById(thearea).style.color = "#FFCC33";
		
	} else {
		
		// Build areaselected variable to send to flash
		var fred2 = thearea + "selected";
		
		// Send areaselected to flash using doPassVar function
		doPassVar(fred2,"no")
		
		// Build movieclip name
		var movieclip = '/map/' + thearea;
		
		// GoTo 'normal' frame in movieclip
		document.flashMap.TGotoFrame(movieclip,0);
		window.document.getElementById(thearea).style.color = "#003366";
	}
}

//---------------------------------------------------------------------------------------------

// FUNCTION TO ACTIVATE ROLLOVERS IN MAP WHEN MOUSE IS OVER TEXT
function spanhover(thearea) {
	
	// Loop through array
	for (i = 0; i <= 4; i ++) {	
		
		//Find coresponding checkbox id
		if (thearea == areanames[i]) {
			var whichbox = areaareas[i];
		}
	}
	
	// If checkbox is already selected
	if(window.document.getElementById(whichbox).checked != true) {
	
	// Build movieclip name
	var movieclip = '/map/' + thearea;
	
	// GoTo 'rollover' frame in movieclip
	document.flashMap.TGotoFrame(movieclip,2);
	
	}
	
	// Change text syle
	window.document.getElementById(thearea).style.color = "#FFCC33";
}

//---------------------------------------------------------------------------------------------

// FUNCTION TO DEACTIVATE ROLLOVERS IN MAP WHEN MOUSE MOVES OFF TEXT
function spanhoveroff(thearea) {
	
	// Loop through array
	for (i = 0; i <= 4; i ++) {	
		
		//Find coresponding checkbox id
		if (thearea == areanames[i]) {
			var whichbox = areaareas[i];
		}
	}
	
	// Build movieclip name
	var movieclip = '/map/' + thearea;
	
	// If Area is selected 
	if (window.document.getElementById(whichbox).checked == true) {
		
		// GoTo 'selected' frame in movieclip
		document.flashMap.TGotoFrame(movieclip,1);
		
		// Change text syle back to normal
		window.document.getElementById(thearea).style.color = "#FFCC33";
	
	// If Area is not selected 		
        } else {
        
        	// GoTo 'normal' frame in movieclip
		document.flashMap.TGotoFrame(movieclip,0);
		
		// Change text syle back to normal
		window.document.getElementById(thearea).style.color = "#003366";
        }
}

//---------------------------------------------------------------------------------------------

// FUNCTION TO ACTIVATE TEXT CHANGES WHEN AREA IS ROLLED OVER IN FLASH
function maphover(thearea) {
	
	// Loop through array
	for (i = 0; i <= 4; i ++) {	
		
		// Active text change on rolled over area
		if (thearea == areanames[i]) {
			var whichbox = areaareas[i]
			if (window.document.getElementById(whichbox).checked != true) {
				window.document.getElementById(thearea).style.color = "#FFCC33";
     		   	}
		
		} else {
			//alert(areanames[i]);
			var whichbox = areaareas[i]
			if (window.document.getElementById(whichbox).checked != true) {
				window.document.getElementById(areanames[i]).style.color = "#003366";
     		   	}
		}
	}
}

//---------------------------------------------------------------------------------------------

// FUNCTION TO DEACTIVATE TEXT CHANGES WHEN AREA IS ROLLED OFF IN FLASH
function maphoveroff(thearea) {	
	// Loop through array
	for (i = 0; i <= 4; i ++) {	
		var whichbox = areaareas[i]
		if (window.document.getElementById(whichbox).checked == true) {
			window.document.getElementById(areanames[i]).style.color = "#FFCC33";
     		} else {
     			window.document.getElementById(areanames[i]).style.color = "#003366";
     		}
		
	}
}

//---------------------------------------------------------------------------------------------

// FUNCTION TO TURN CHECKBOXES ON/OFF WHEN FLASH MAP IS CLICKED ON
function swapSearch(thearea) {
	
	// Loop through array
	for (i = 0; i <= 4; i ++) {
		
		//Find coresponding checkbox id
		if (thearea == areanames[i]) {
			var whichbox = areaareas[i];
		}
	}
	
	// If checkbox is selected
	if(window.document.getElementById(whichbox).checked == true) {
	
		// Unselect checkbox
		window.document.getElementById(whichbox).checked = false;
		window.document.getElementById(thearea).style.color = "#003366";
	
	// If checkbox is not selected	
	} else {
		
		// Select checkbox
		window.document.getElementById(whichbox).checked = true;
		window.document.getElementById(thearea).style.color = "#FFCC33";
	}
}

//---------------------------------------------------------------------------------------------

// FUNCTION TO SEND VARIABLE TO FLASH MOVIE
function doPassVar(variablename,thevalue){
	window.document.flashMap.SetVariable(variablename, thevalue);
}

//---------------------------------------------------------------------------------------------

// FUNCTION TO RESET FORM
function ResetForm(){
        window.document.forms.searchform.reset();
        checkwhatson();
}

//---------------------------------------------------------------------------------------------

function SubmitForm() {
	var numberselected = 0;
	for (i = 0; i <= 4; i ++) {
		if(window.document.getElementById(areaareas[i]).checked == true) {
			numberselected ++;
		}
	}
	if(numberselected == 0) {
		for (i = 0; i <= 4; i ++) {
			window.document.getElementById(areaareas[i]).checked = true;
		}
		
		
	}
	window.document.forms.searchform.submit();
}