// Only safari detection is needed because this needs special handling for forms
var agt=navigator.userAgent.toLowerCase();
var is_safari = ((agt.indexOf('safari')!=-1)&&(agt.indexOf('mac')!=-1))?true:false;

function cleanAndCapitalize(text){
	text = text.toLowerCase(); 
	//êéèë 
	text = text.replace(/[\xEA\xE9\xE8\xEB]/g, "e"); 
	//âáäà 
	text = text.replace(/[\xE2\xE1\xE4\xE0]/g, "a"); 
	//îï 
	text = text.replace(/[\xEE\xEF]/g, "i"); 
	//ô 
	text = text.replace(/[\xF4]/g, "o"); 
	//ç 
	text = text.replace(/[\xE7]/g, "c"); 
	//ùûúü 
	text = text.replace(/[\xF9\xFB\xFA\xFC]/g, "u"); 
	return text.toUpperCase(); 
}

function showStatus(sMsg) {
    window.status = sMsg ;
    return true ;
}

function putaction(window, element){
	if ( is_safari ) {
		var ref = unescape(window.location.href);
		//if ( ref.indexOf("?") > 0 ) {
		//	ref = ref.substring(0,ref.indexOf("?"));
		//}
		document.getElementById(element).action = ref;
	}
}

function submitFormByHiddenField(formfield,hiddenfield,name){
	var fieldObj = document.getElementById(hiddenfield);
	fieldObj.name = name;
	fieldObj.value = 'true';
	document.getElementById(formfield).submit();
}

function submitFormByHiddenField(formfield,hiddenfield,name,value){
	var fieldObj = document.getElementById(hiddenfield);
	fieldObj.name = name;
	fieldObj.value = value;
	document.getElementById(formfield).submit();
}

function checkBrowser(){
	if ( is_safari ) {
		alert("Please choose another browser. The administration pages are not designed to work with Safari.");
		return false;
	}else{
		return true;
	}
}

function onEnter(event, form){
	if (event && ( event.keyCode == 13 || event.which == 13) ){
    	form.submit();
  	}else{
    	return true;
    }
}

function beforeDeleteCategory(message){
	return confirm(message);
}

function beforeDelete(message){
	return confirm(message);
}

function beforeDeletePublication(message){
	return confirm(message);
}

function postAgendaForm(action,actionid, suffix){
/*	fixPostalCode(suffix);*/
	document.agendaForm.action.value = action;
	document.agendaForm.actionid.value = actionid;
	document.agendaForm.submit();
}
/*function fixPostalCode(suffix){
	var select;
	if(MM_findObj("isPostalCodeDropDown_"+suffix).value == "true"){
		select = MM_findObj("orderByPostalcode_"+suffix);
	}
	else{
		select = MM_findObj("orderByName_"+suffix);
	}
	if(select.selectedIndex != -1){
		document.agendaForm.townId.value = select.options[select.selectedIndex].value;
	}
}*/
function postAgendaDetailForm(action,actionid){
	document.agendaForm.goto.value = "detail";
	document.agendaForm.detailActionId.value = actionid;
	document.agendaForm.submit();
}

function postTarifficationForm(action,actioncode){
	document.tarifficationForm.action.value = action;
	document.tarifficationForm.actionCode.value = actioncode;
	document.tarifficationForm.submit();
}

function postAdminTarafficationForm(action,actionid){
	document.adminTarifficationForm.action.value = action;
	document.adminTarifficationForm.rootid.value = actionid;
	document.adminTarifficationForm.submit();
}

function postAgendaPager(page, suffix){
/*	fixPostalCode(suffix);*/
	document.agendaForm.goto.value="list";
	document.agendaForm._action.value="search";
	document.agendaForm.currentPage.value = page;
	document.agendaForm.submit();
}

function postAgendaSortOrder(sortOrderColumn,asc, suffix){
/*	fixPostalCode(suffix);*/
	document.agendaForm.sortOrderColumn.value = sortOrderColumn;
	document.agendaForm.asc.value = asc;
	document.agendaForm.goto.value = "list";
	document.agendaForm._action.value = "sort";
	document.agendaForm.submit();
}

function postAdminAgendaSortOrder(sortOrderColumn,asc){
	document.adminEventForm.changeSortOrder.value = true;
	document.adminEventForm.sortOrderColumn.value = sortOrderColumn;
	document.adminEventForm.asc.value = asc;
	document.adminEventForm.submit();
}

function postPublicationForm(action,actionid){
	document.publicationForm.action.value = action;
	document.publicationForm.actionid.value = actionid;
	document.publicationForm.submit();
}

function postPublicationPager(page){
	document.publicationForm.currentPage.value = page;
	document.publicationForm.submit();
}

function selectTown(townID){
	document.regionSelectionForm.townID.value = townID;
	document.regionSelectionForm._action.value = "false";
	document.regionSelectionForm.submit();
}

/**
  * Makes the layer with id 'layerId' visible according to 'isVisible'.
  */
function setVisible(element,isVisible) {
	if (element != null) {
		if (isVisible) {
			element.style.display = "block";
		} else {
			element.style.display = "none";
		}
	}
}

/**
  * Disables the element with id "id" if "isDisabled" is 
  * true, otherwise enables the element.
  */
function setDisabled(id, isDisabled) {
	document.getElementById(id).disabled=isDisabled;
}

/**
  * Checks the elements with id "id" if "isChecked" is
  * true, otherwise uncheckes the element.
  */
function setChecked(id, isChecked) {
	if (isChecked){
		document.getElementById(id).checked='checked';
	} else {
		document.getElementById(id).checked='';
	}
}
