var lang_pop;
var lang_l;

function replaceEntities(val) {
        val = val.replace(/&agrave;/g, "\340");
        val = val.replace(/&aacute;/g, "\341");
        val = val.replace(/&acirc;/g, "\343");

        val = val.replace(/&egrave;/g, "\350");
        val = val.replace(/&eacute;/g, "\351");
        val = val.replace(/&ecirc;/g, "\352");
        return val;
}


function onLoad() {
	lang_l 		= $('lang_link');
	lang_pop 	= $('lang_popup_mid');
	
	$A(lang_pop.getElementsByTagName('a')).each(function(a) {
		a.onclick = function() {
			lang_pop.Close();
		};
	});
	
	lang_l.href = "#";
	lang_l.onclick = function() {
		lang_pop.Open();
		if(lang_l.up().id == "lang_a") {
			lang_pop.opened = true;
		} else {
			lang_l.up().id = "lang_a";
		}
		document.body.focus();
	}
	
	lang_l.Reset = function() {
		lang_l.up().id = "lang";
	}
	
	lang_pop.Open = function() {
		$(this).show();
		this.opened = false;
	}	
	lang_pop.onclick = function() {
		this.opened = false;
	}	
	lang_pop.Close = function() {
		if(!this.opened) {
			this.opened = true;
		} else {
			this.hide();
			lang_l.Reset();
		}
	}
	
	$(document.body).onclick = function() {
		if(lang_pop.visible()) {
			lang_pop.Close();
		}
	};
	
	loadPrefilledTextFields();
}

function loadPrefilledTextFields(element) {
	if(element) {
		element = $(element);
	} else {
		element = $(document.body);
	}
	var prefilled_color = '#ff3333';
	var filled = $A(element.getElementsBySelector('input.prefilled'));
	filled.each( function (f) {
		f.normal_color = f.getStyle('color');
		f.setStyle( {color:prefilled_color} );
		f.onfocus = function() {
			if(!this.start_value || this.value.strip() == this.start_value.strip()) {
				this.start_value=this.value; 
				this.value='';
				$(this).setStyle( {color:this.normal_color} );
			}
		}
		f.onblur = function() {
			if($(this).value.strip() == '') { 
				this.value = this.start_value;
				$(this).setStyle( {color:prefilled_color} );
			}
		}
	});
}



