function initSelectBoxesForCG(locationId){
	if( locationId != null){
		//fix first level location
		for(var i=0; i<locationArray.length; i++)
			if( locationArray[i][1] == null)
				addOption('cs_location_1', locationArray[i][0], locationArray[i][2]);		
		
		//fix location to its posted value
		if( locationId != '')
			//fixParentsCG('location',locationId); //this for the (All) functionality
			fixParents('location',locationId);
		
		/*else{
			//make the (All) choice the one selected.
			document.getElementById('cs_location_1').selectedIndex=1;
			reloadOptions('cs_location_1');
		}*/
		
		
	}
}



function initSelectBoxes(locationId, activityId, experienceId, generalId){
	
	
	/*********************
	Since this js might be used by other searches that dont need  all three criteria (location activity and experience), check the parameters for null
	********************/

	
	if( locationId != null){
		//fix first level location
		for(var i=0; i<locationArray.length; i++)
			if( locationArray[i][1] == null)
				addOption('cs_location_1', locationArray[i][0], locationArray[i][2]);		
		
		//fix location to its posted value
		if( locationId != '')
			fixParents('location',locationId);
	}
		
	/*
	if( activityId != null){
		//fix first level activity
		for(var i=0; i<activityArray.length; i++)
			if( activityArray[i][1] == null)
				addOption('cs_activity_1', activityArray[i][0], activityArray[i][2]);
				
		//fix activity to its posted value
		if( activityId != '')
			fixParents('activity',activityId);
	}
	
	/
	if( experienceId != null){
		//fix first level experience
		for(var i=0; i<experienceArray.length; i++)
			if( experienceArray[i][1] == null)
				addOption('cs_experience_1', experienceArray[i][0], experienceArray[i][2]);
		
		//fix experience to its posted value
		if( experienceId != '')
			fixParents('experience',experienceId);
	}
	
	if( generalId != null){
		//fix first level general
		for(var i=0; i<generalArray.length; i++)
			if( generalArray[i][1] == null)
				addOption('cs_general_1', generalArray[i][0], generalArray[i][2]);
		
		//fix experience to its posted value
		if( generalId != '')
			fixParents('general',generalId);
	}*/	
}







function reloadOptions(selectBox){

	//first clean the next select boxes
	propagateClean(selectBox);
	
	//find target select box
	var targetSelectBox = selectBox.substring(0, selectBox.length-1) + (selectBox.substring(selectBox.length-1) - -1);	

	//get selected id
	var sb = document.getElementById(selectBox);
	var selectedId = document.getElementById(selectBox).options[sb.selectedIndex].value;
	eval( 'var currentArray = ' + selectBox.substring(3, selectBox.lastIndexOf('_')) + 'Array');
	
	if( selectedId == -1){ // then we need all prefectures
		var topLevelIds = findTopLevelIds();
		for(var i=0; i<currentArray.length; i++)	
			if( topLevelIds.indexOf(currentArray[i][1]) != -1)
				addOption(targetSelectBox, currentArray[i][0], currentArray[i][2]);	
			
	}
	else{
		for(var i=0; i<currentArray.length; i++)	
			if( currentArray[i][1] == selectedId)
				addOption(targetSelectBox, currentArray[i][0], currentArray[i][2]);	
	}
	
	
}


function findTopLevelIds(){
	if(!Array.indexOf){
		Array.prototype.indexOf = function(obj){
			for(var i=0; i<this.length; i++){
				if(this[i]==obj){
					return i;
				}
			}
			return -1;
		}
	}

	var topIds = new Array();
	for(var i=0, j=0; i<locationArray.length; i++)
		if( locationArray[i][1] == null)
			topIds[j++]= locationArray[i][0];
			
	return topIds;
}



function propagateClean(selectBox){
	
	var targetSelectBox = selectBox.substring(0, selectBox.length-1) + (selectBox.substring(selectBox.length-1) - -1);	
	
	if( document.getElementById(targetSelectBox) != null){
		document.getElementById(targetSelectBox).options.selectedIndex = 0;
		document.getElementById(targetSelectBox).options.length = 1;
		propagateClean(targetSelectBox);		
	}
	
	
}
	


function addOption(selectBox, id, name){
	var sb = document.getElementById(selectBox);
	var size = sb.options.length;
	sb.options[size] = new Option(name, id);
}



function search(forLocation, forActivity, forExperience, forGeneral){

	var newLocation = BASE_URL;

	if( forLocation){
	
		var locationId = (document.getElementById('cs_location_4').selectedIndex == 0) ? 
					(document.getElementById('cs_location_3').selectedIndex == 0) ? 
						(document.getElementById('cs_location_2').selectedIndex == 0) ? 
							(
								(document.getElementById('cs_location_1').selectedIndex == 0) ||
								(document.getElementById('cs_location_1').selectedIndex == 1) 
							) 
							? null 							
							: document.getElementById('cs_location_1').options[document.getElementById('cs_location_1').selectedIndex].value
						: document.getElementById('cs_location_2').options[document.getElementById('cs_location_2').selectedIndex].value
					: document.getElementById('cs_location_3').options[document.getElementById('cs_location_3').selectedIndex].value
				: document.getElementById('cs_location_4').options[document.getElementById('cs_location_4').selectedIndex].value;
				
		if( locationId != null){
			newLocation += '&location=' + locationId;
			window.location.href = newLocation + "&doSearch=true";	
		}			
		
	}
		
		/*
	if( forActivity){
	
		var activityId = (document.getElementById('cs_activity_3').selectedIndex == 0) ? 
					(document.getElementById('cs_activity_2').selectedIndex == 0) ? 
						(document.getElementById('cs_activity_1').selectedIndex == 0) ? null
						: document.getElementById('cs_activity_1').options[document.getElementById('cs_activity_1').selectedIndex].value
					: document.getElementById('cs_activity_2').options[document.getElementById('cs_activity_2').selectedIndex].value
				: document.getElementById('cs_activity_3').options[document.getElementById('cs_activity_3').selectedIndex].value;
				
		if( activityId != null)
			newLocation += '&activity=' + activityId;
	}
	
	
	if( forExperience){
	
		var experienceId = (document.getElementById('cs_experience_3').selectedIndex == 0) ? 
					(document.getElementById('cs_experience_2').selectedIndex == 0) ? 
						(document.getElementById('cs_experience_1').selectedIndex == 0) 	? null
						: document.getElementById('cs_experience_1').options[document.getElementById('cs_experience_1').selectedIndex].value
					: document.getElementById('cs_experience_2').options[document.getElementById('cs_experience_2').selectedIndex].value
				: document.getElementById('cs_experience_3').options[document.getElementById('cs_experience_3').selectedIndex].value;
				
		if( experienceId != null)
			newLocation += '&experience=' + experienceId;
	}
	
	if( forGeneral){
		var generalId = document.getElementById('cs_general_1').selectedIndex == 0 ? null : document.getElementById('cs_general_1').options[document.getElementById('cs_general_1').selectedIndex].value;
		
		if( generalId != null)
			newLocation += '&general=' + generalId;
	}*/
		
	
	
}


/*********************************************************************************************/
//these are used to populate the selects after the post...

function fixParentsCG(categoryName, value){
	var selectedValues = new Array();
	var parent = null;
		
	selectedValues[0] = value;	
	for(var j=0;  (parent = findParent(categoryName, selectedValues[j])) != null ; selectedValues[++j] = parent);	
	
	for(var ii=selectedValues.length-1; ii>=0; ii--){		
		var currentSelectBoxName = 'cs_'+categoryName+'_' + (selectedValues.length -ii);		
		fixSelectedIndexCG(currentSelectBoxName, selectedValues[ii]);		
	}		
}

function fixSelectedIndexCG(selectBoxName, selectedValue){
	var sb = document.getElementById(selectBoxName);	
	
	if( selectBoxName == 'cs_location_1')
		sb.selectedIndex = 1;
	else
		for(var jj=0; jj<sb.options.length; jj++)
			if( sb.options[jj].value == selectedValue){
				sb.selectedIndex = jj;
				break;
			}		
			
	reloadOptions(selectBoxName);
}





function fixSelectedIndex(selectBoxName, selectedValue){
	var sb = document.getElementById(selectBoxName);	
	for(var jj=0; jj<sb.options.length; jj++)
		if( sb.options[jj].value == selectedValue){
			sb.selectedIndex = jj;
			break;
		}		
	reloadOptions(selectBoxName);
}


function findParent(categoryName, value){

	eval('var currentArray='+categoryName+'Array;');
	for(var i=0; i<currentArray.length; i++)
		if( currentArray[i][0] == value)
			return currentArray[i][1];
	
		
}

function fixParents(categoryName, value){
	var selectedValues = new Array();
	var parent = null;
		
	selectedValues[0] = value;	
	for(var j=0;  (parent = findParent(categoryName, selectedValues[j])) != null ; selectedValues[++j] = parent);	
	
	for(var ii=selectedValues.length-1; ii>=0; ii--){		
		var currentSelectBoxName = 'cs_'+categoryName+'_' + (selectedValues.length -ii);		
		fixSelectedIndex(currentSelectBoxName, selectedValues[ii]);		
	}		
}
	
/****************************************************************************************//*

FUNCTIONS FOR THE FLASH MAP OF GREECE */

function geoSearch(locationId){
	window.location.href = BASE_URL + '&location=' + locationId+ "&doSearch=true";
}


function embedFlashMap(containerElementId, vcmId, langId){

	if (AC_FL_RunContent == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} 
	else {
	
		AC_FL_RunContent(
			'containerElementId', containerElementId,
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0',
			'width', '100%',
			'height', '280',
			'src', '/eot/flash/cs/map?xmlName=/eot/flash/cs/countries&langid='+langId+'&vcmId='+vcmId,
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'play', 'true',
			'loop', 'true',
			'scale', 'exactfit',
			'wmode', 'normal',
			'devicefont', 'false',
			'id', 'map',
			'bgcolor', 'red',
			'name', 'map',
			'menu', 'true',
			'allowFullScreen', 'false',
			'allowScriptAccess','sameDomain',
			'movie', '/eot/flash/cs/map?xmlName=/eot/flash/cs/countries&langid='+langId+'&vcmId='+vcmId,
			'salign', ''); 
	} 
}		

/*************** This for the category search 16-03-2010 ******/
function showResults(){
	HrefMgr = new HrefManager(document.location.href);
	var new_href = HrefMgr.appendOrReplace({'doSearch':'true'});
	document.location.href = new_href;	
}









