
function filter_by_subscription(obj, id){
	if(subscriptions.indexOf(id)>-1)
		subscriptions = subscriptions.without(id);
	else
		subscriptions.push(id);
	
	if(obj.style.fontWeight=='' || obj.style.fontWeight=='bold')
		obj.style.fontWeight = 'normal';
	else
		obj.style.fontWeight = 'bold';
	
	load_locations('');
};

var map=null;var pn=null;
var filter_criterion='';var filter_value='';
var offset_locations=0;//var offset_categories=0;
var arrPoints=[];

function check_search(frm){
	if($F(frm.cauta).strip()!=''){
		if($F(frm.cauta).strip().length>=4)
			do_search(frm);
		else{
			alert('The search term should contain at least 4 characters!');
			frm.cauta.focus();
		};
	}else{
		alert('The search term is mandatory!');
		frm.cauta.value='';
		frm.cauta.focus();
	};
	return false;
};
function do_search(frm){
	do_AJAX_post('cauta=' + escape(encodeURI($F(frm.cauta).strip())) + 
		'&criteriu=' + escape(encodeURI(frm.criteriu.options[frm.criteriu.selectedIndex].value)) + 
		'&nu_are_cuvintele=' + escape(encodeURI($F(frm.nu_are_cuvintele).strip())) + 
		'&categorie=' + escape(encodeURI(frm.categorie.options[frm.categorie.selectedIndex].value)) + 
		'&sub_categorie=' + escape(encodeURI(frm.sub_categorie.options[frm.sub_categorie.selectedIndex].value)) + 
		'&judet=' + escape(encodeURI(frm.judet.options[frm.judet.selectedIndex].value)) + 
		'&localitate=' + escape(encodeURI(frm.localitate.options[frm.localitate.selectedIndex].value)), '/wp-includes/LoadMapLocations/SearchLocation.php');
	return false;
};
function clear_search(){
	document.frmSearch.cauta.value = '';
	document.frmSearch.criteriu.selectedIndex = 0;
	document.frmSearch.nu_are_cuvintele.value = '';
	document.frmSearch.categorie.selectedIndex = 0;
	get_subcategories(document.frmSearch.categorie);
	document.frmSearch.judet.selectedIndex = 0;
	get_cities(document.frmSearch.judet);
	
	do_search(document.frmSearch);
};

function unload_map(){if(map!=null){map.Dispose();};};

function load_locations(l){map.HideInfoBox();map.Clear();do_AJAX_get('/wp-includes/LoadMapLocations/LoadLocations.php?abonamente='+escape(encodeURI(subscriptions.join('|')))+'&locatie='+escape(encodeURI(l))+'&offset='+escape(encodeURI(offset_locations))+'&criteriu='+escape(encodeURI(filter_criterion))+'&valoare='+escape(encodeURI(filter_value)));};

function load_my_locations(){map.HideInfoBox();map.Clear();do_AJAX_get('/wp-includes/LoadMapLocations/LoadMyLocations.php?offset='+escape(encodeURI(offset_locations)));};

function add_point(lat,lng){var p=new VEShape(VEShapeType.Pushpin,new VELatLong(lat,lng));map.AddShape(p);return p;};
function get_point_info(lat,lng){var l=map.GetShapeLayerByIndex(0);for(i=0;i<l.GetShapeCount();i++){if(l.GetShapeByIndex(i).GetPoints()[0].Latitude==lat && l.GetShapeByIndex(i).GetPoints()[0].Longitude==lng){map.HideInfoBox();map.ShowInfoBox(l.GetShapeByIndex(i));};};};

function get_subcategories(ddl){if(ddl.options[ddl.selectedIndex].value.strip()!='')ddl.form.sub_categorie.focus();var req=cRO();req.open('get','/wp-includes/LoadMapLocations/GetSubcategories.php?categorie='+escape(encodeURI(ddl.options[ddl.selectedIndex].value)),true);req.onreadystatechange=function(){if(req.readyState==4)eval(req.responseText);};req.send(null);};

function get_cities(ddl){if(ddl.options[ddl.selectedIndex].value.strip()!='')ddl.form.localitate.focus();var req=cRO();req.open('get','/wp-includes/LoadMapLocations/GetCities.php?judet='+escape(encodeURI(ddl.options[ddl.selectedIndex].value)),true);req.onreadystatechange=function(){if(req.readyState==4)eval(req.responseText);};req.send(null);};

function save_point(frm,f){if(validate_location_form(frm))do_AJAX_post('latitudine='+escape(encodeURI($F(frm.latitudine)))+'&longitudine='+escape(encodeURI($F(frm.longitudine)))+'&titlu='+escape(encodeURI($F(frm.titlu).strip()))+'&categorie='+escape(encodeURI(frm.categorie.options[frm.categorie.selectedIndex].value.strip()))+'&sub_categorie='+escape(encodeURI(frm.sub_categorie.options[frm.sub_categorie.selectedIndex].value.strip()))+'&articol='+escape(encodeURI(frm.articol.options[frm.articol.selectedIndex].value.strip()))+'&descriere='+escape(encodeURI($F(frm.descriere).strip()))+'&judet='+escape(encodeURI(frm.judet.options[frm.judet.selectedIndex].value.strip()))+'&localitate='+escape(encodeURI(frm.localitate.options[frm.localitate.selectedIndex].value.strip()))+'&abonament='+escape(encodeURI(frm.abonament.options[frm.abonament.selectedIndex].value.strip()))+'&functie='+escape(encodeURI(f))+'&user='+escape(encodeURI($F(frm.user).strip())),'/wp-includes/LoadMapLocations/AddLocation.php');return false;};

function update_point(frm,f){if(validate_location_form(frm))do_AJAX_post('locatie='+escape(encodeURI($F(frm.locatie)))+'&titlu='+escape(encodeURI($F(frm.titlu).strip()))+'&categorie='+escape(encodeURI(frm.categorie.options[frm.categorie.selectedIndex].value.strip()))+'&sub_categorie='+escape(encodeURI(frm.sub_categorie.options[frm.sub_categorie.selectedIndex].value.strip()))+'&articol='+escape(encodeURI(frm.articol.options[frm.articol.selectedIndex].value.strip()))+'&descriere='+escape(encodeURI($F(frm.descriere).strip()))+'&judet='+escape(encodeURI(frm.judet.options[frm.judet.selectedIndex].value.strip()))+'&localitate='+escape(encodeURI(frm.localitate.options[frm.localitate.selectedIndex].value.strip()))+'&abonament='+escape(encodeURI(frm.abonament.options[frm.abonament.selectedIndex].value.strip()))+'&functie='+escape(encodeURI(f)),'/wp-includes/LoadMapLocations/UpdateLocation.php');return false;};

function validate_location_form(frm){
	if($F(frm.titlu).strip()==''){$('lblError').innerHTML='The "Title" field is mandatory!';frm.titlu.value='';frm.titlu.focus();return false;};
	if(frm.categorie.options[frm.categorie.selectedIndex].value.strip()==''){$('lblError').innerHTML='The "Category" field is mandatory!';frm.categorie.focus();return false;};
	if(frm.sub_categorie.options[frm.sub_categorie.selectedIndex].value.strip()==''){$('lblError').innerHTML='The "Subcategory" field is mandatory!';frm.sub_categorie.focus();return false;};
	if(frm.articol.options[frm.articol.selectedIndex].value.strip()==''){
		$('lblError').innerHTML='The "Linked Article" field is mandatory!';
		frm.articol.focus();
		return false;
	};
if($F(frm.descriere).strip()==''){$('lblError').innerHTML='The "Description" field is mandatory!';frm.descriere.value='';frm.descriere.focus();return false;};if(frm.judet.options[frm.judet.selectedIndex].value.strip()==''){$('lblError').innerHTML='The "County" field is mandatory!';frm.judet.focus();return false;};if(frm.localitate.options[frm.localitate.selectedIndex].value.strip()==''){$('lblError').innerHTML='The "City" field is mandatory!';frm.localitate.focus();return false;};if(frm.abonament.options[frm.abonament.selectedIndex].value.strip()==''){$('lblError').innerHTML='The "Subscription" field is mandatory!';frm.abonament.focus();return false;};return true;};

function delete_point(frm,f){if(confirm('Are you sure you want to remove the location?'))do_AJAX_post('locatie='+escape(encodeURI($F(frm.locatie)))+'&functie='+escape(encodeURI(f)),'/wp-includes/LoadMapLocations/DeleteLocation.php');return false;};

function filter_locations(c,v){offset_locations=0;filter_criterion=c;filter_value=v;do_AJAX_get('/wp-includes/LoadMapLocations/FilterLocations.php?criteriu='+escape(encodeURI(filter_criterion))+'&valoare='+escape(encodeURI(filter_value)));};

// PRELOADING THE ADVANCED SEARCH BAR IMAGES
var advanced_search_bar_raised = new Image(864, 15); advanced_search_bar_raised.src = '/wp-content/themes/unseen/images/bg_search_advanced_raised.png';
var advanced_search_bar_dropped = new Image(864, 15); advanced_search_bar_dropped.src = '/wp-content/themes/unseen/images/bg_search_advanced_dropped.png';
function load_accordion(){
	var verticalAccordion = new accordion('search_advanced', {
		defaultSize : {
			width : 840
		}
	});
	var verticalAccordions = $$('.accordion_toggle');
	verticalAccordions.each(function(accordion){
	    $(accordion.previous(0)).setStyle({
	        height: '0px'
	    });
	});
};

Event.observe(window, 'load', function(){
	if(document.frmSearch)
		load_accordion();
	load_map();
});
Event.observe(window, 'unload', unload_map);

