//---------------------------------------------------------------------------------------------
// ROLLOVER FLASH MAP SEARCH JAVASCRIPT
// © VEBRA Plc 2003 
// Written by Richard Stephenson 29 Jan 2003
//---------------------------------------------------------------------------------------------


// PRELOAD IMAGES
searchbut = new Image(186,26); searchbut.src = "../stat/search_submit.gif";
resetbut = new Image(186,26); resetbut.src = "../stat/search_reset.gif";

num4 = new Image(186,26); num4.src = "../stat/search_num4.gif";
num3 = new Image(186,26); num3.src = "../stat/search_num3.gif";
num2 = new Image(186,26); num2.src = "../stat/search_num2.gif";
num1 = new Image(186,26); num1.src = "../stat/search_num1.gif";

backtomap = new Image(186,26); backtomap.src = "../stat/search_backtomap.gif";
newregion = new Image(186,26); newregion.src = "../stat/search_newregion.gif";
gobut = new Image(186,26); gobut.src = "../stat/search_go.gif";

selarea = new Image(186,26); selarea.src = "../stat/search_selarea.gif";
seltype = new Image(186,26); seltype.src = "../stat/search_seltype.gif";
chooprice = new Image(186,26); chooprice.src = "../stat/search_chooprice.gif";
choocurr = new Image(186,26); choocurr.src = "../stat/search_choocurr.gif";



// ARRAY OF OTHER REGIONS
Array("alpes","aquitaine","brittany","burgundy","champagne","franche","paris","languedoc","limousin","loire","nord","normandy","picardy","charentes","provence","pyrenees","rhone");



// ARRAYS OF AREAS AND CORRESSPONDING THEIR CHECKBOX ID
areanames = new Array("area1","area2","area3","area4","area5");
areaareas = new Array("checkbox1","checkbox2","checkbox3","checkbox4","checkbox5");

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 = "#990000";
			
		} 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";
		
		// 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 = "#990000";
	}
}

//---------------------------------------------------------------------------------------------

// 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 = "#990000";
		
	} 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 = "#990000";
}

//---------------------------------------------------------------------------------------------

// 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 = "#990000";
	
	// 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 = "#990000";
     		   	}
		
		} 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 = "#990000";
     		} 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 = "#990000";
	}
}

//---------------------------------------------------------------------------------------------

// FUNCTION TO SEND VARIABLE TO FLASH MOVIE
function doPassVar(variablename,thevalue){
	window.document.flashMap.SetVariable(variablename, thevalue);
}

//---------------------------------------------------------------------------------------------

// FUNCTION TO SUBMIT FORM
function SubmitForm(){
        window.document.forms.searchform.submit();
}

//---------------------------------------------------------------------------------------------

// FUNCTION TO RESET FORM
function ResetForm(){
        window.document.forms.searchform.reset();
        checkwhatson();
}

//---------------------------------------------------------------------------------------------


function SelectRegion()  {
	theRegion = document.forms.searchform.region.options[document.forms.searchform.region.selectedIndex].value;
	if (theRegion == 0) {
		alert("Please select a Region.")
	} else {
	
		URL = "search_" + theRegion + ".php" 
		window.location.href = URL;
	}
}

function Submitform() {
	var numberselected = 0;
	for (i = 0; i <= 4; i ++) {
		if(window.document.getElementById(areaareas[i]).checked == true) {
			numberselected ++;
		}
	}
	//alert(numberselected)
	
	if(numberselected == 0) {
		var locvalue = 0;
		for (i = 0; i <= 4; i ++) {
			locvalue = locvalue + "," + window.document.getElementById(areaareas[i]).value;
		}
		locstripped = locvalue.substring(2,locvalue.length);
		window.document.getElementById('hiddenloc').value = locstripped;
		
	} else {
		window.document.getElementById('hiddenloc').name = "noselect"
		window.document.getElementById('hiddenloc').value = "undefined"	
	}
	document.forms.searchform.submit();
}