/*
	$Id: elements.js 3836 2012-01-12 14:54:10Z mrabe $
*/

//ADDRESS BEGIN 
var active_menu = 0; // toggle menu, opened/closed

selectGmapCoordiantes = function(position) {
	$("#coordinates_preview").html("Es wurde eine Position festgelegt.<br />Koordinaten(" + position.latitude + "," + position.longitude + ")");
	$("#coordinates").val(position.latitude +',' + position.longitude + ',' + position.zoomlevel + ',' + position.maptyp);
	$("#coordinates_setting").val(position.latitude +',' + position.longitude + ',' + position.zoomlevel + ',' + position.maptyp);
}

deleteGmapPosition = function() {
	$("#coordinates").val("");
	$("#coordinates_preview").html("Keine Position gewählt.");
}

checkAddressData = function(requestType) {
	var bezeichnung = $("#locationBezeichnung").val();
	var street = $("#locationStreet").val();
	var number = $("#locationNumber").val();
	var zipcode = $("#locationPlz").val();
	var city = $("#locationCity").val();
	var error = 0;
	var errorMsg = "";
	
	if (!bezeichnung.length) {
		if (requestType) errorMsg += "Bitte eine Firma eingeben.<br />";
		error++;
	}
	if (!street.length) {
		if (requestType) errorMsg += "Bitte eine Straße eingeben.<br />";
		error++;
	}
	if (!number.length) {
		if (requestType) errorMsg += "Bitte eine Hausnummer eingeben.<br />";
		error++;
	}
	if (!zipcode.length) {
		if (requestType) errorMsg += "Bitte eine Postleitzahl eingeben.<br />";
		error++;
	}
	if (!city.length) {
		if (requestType) errorMsg += "Bitte einen Ort eingeben.<br />";
		error++;
	}
	
	if (error == 0) {
		return true;
	}else if(errorMsg.length){
		actionError(errorMsg);
	}
	
	return false;
}

address_select = function(address) {
	$("#address").val(address.ID);
	$("#address_preview").html(address.bezeichnung + '<br />' + address.strasse + '<br />' + (address.plz != 0 ? address.plz : '') +' '+address.ort);
	if (address.latitude == "")
		address.latitude = 0;
	if (address.longitude == "")
		address.longitude = 0;
	$("#coordinates2").val(address.latitude + "," + address.longitude + "," + 0 + "," + 1);
}

address_delete = function() {
	$("#address").val(0);
	$("#address_preview").text("Keine Adresse ausgewählt");
	$("#coordinates2").val('');
}
//ADDRESS END

//PRODUCT BEGIN
//get product details and show it in container
getProductDetails = function(id){
	if(id == 0){
		$("#productDetailsContainer").fadeOut('slow');
	}else {
		DWREngine._execute(_ajaxConfigGlobal._cfscriptLocation, null, 'getProductDetails', id, function(data) {
			$("#productDetailsContainer").html(data);
				if ($("#productDetailsContainer").css('display') == 'none') {
					$("#productDetailsContainer").slideToggle();
				}				
			}
		);	
	}
}
//PRODUCT END

//MAP START
openGmapSelector = function() {
	if( $("#locationBezeichnung").val() != "" ||  $("#locationStreet").val() != "" || $("#locationPlz").val() != "" || $("#locationCity").val() != ""){
		if(confirm("Soll die Koordinate automatisch ermittelt werden?")){
			autoGetLocation(1);
		}else{
			popup('/city_info/admin/gmap/select.cfm?' + $("#urltoken").val() + '&position=' + $("#coordinates_setting").val(), 650, 450, 'selectGmapCoordiantes',"yes",1);
		}
	}
	else{
		popup('/city_info/admin/gmap/select.cfm?' + $("#urltoken").val() + '&position=' + $("#coordinates").val(), 650, 450, 'selectGmapCoordiantes',"yes",1);
	}}

selectGmapCoordiantes = function(position) {	
	$("#coordinates_preview").html("Es wurde eine Position festgelegt.<br />Koordinaten(" + position.latitude + "," + position.longitude + ")");
	
	// get adress over the coordinates, write the result with the function insertAdress in input fields
	if (confirm("Soll die Adresse automatisch ermittelt werden? Ihre Daten werden überschrieben!")) {
		try{
			latlng = new GLatLng(position.latitude, position.longitude);
			var geocoder = new GClientGeocoder();
			geocoder.getLocations(latlng, insertAdress);
		}catch(e){
				alert("Leider konnte keine Adresse ermittelt werden!");
		}
	}
	$("#coordinates").val(position.latitude +',' + position.longitude + ',' + position.zoomlevel + ',' + position.maptyp);
	$("#coordinates_setting").val(position.latitude +',' + position.longitude + ',' + position.zoomlevel + ',' + position.maptyp);
}

insertAdress = function(response){
	try{
		place = response.Placemark[0];
		
		$("#locationBezeichnung").val(place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName);
		$("#locationStreet").val(place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName);
		$("#locationPlz").val(place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode.PostalCodeNumber);
		$("#locationCity").val(place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName);
		// landkreis => place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.SubAdministrativeAreaName
	}catch(e){
			alert("Leider konnte keine Adresse ermittelt werden!");
	}
}

deleteGmapPosition = function() {
	$("#coordinates").val("");
	$("#coordinates_preview").html("Keine Position gewählt.");
}

autoGetLocation = function(requestType) {
	var check = checkAddressData(requestType);
	if (check) {	
		var street = $("#locationStreet").val();
		var number = $("#locationNumber").val();
		var zipcode = $("#locationPlz").val();
		var city = $("#locationCity").val();		
		var tmp = $("#autoGetCoordinates").html();		
		$("#autoGetCoordinates").html('<img src="/city_info/images/loading_xs.gif" />');		
		DWREngine._execute(_ajaxConfigGmap._cfscriptLocation, null, "getCoordinatesByAddress", street, number, zipcode, city, function(coordinates) {																
								if (coordinates.length && coordinates != 0) {
									$("#coordinates").val(coordinates + ",14,1");
									coordinates = $("#coordinates").val().split(",");
									$("#coordinates_preview").html("Es wurde eine Position festgelegt.<br />Koordinaten(" + coordinates[0] + "," + coordinates[1] + ")");
								} else {
									$("#coordinates").val("0,0,0,1");
									$("#coordinates_preview").html("Es konnten leider keine Koordinaten ermittelt werden.");
								}
								$("#autoGetCoordinates").html(tmp);
							}
		);
	}	
}
//MAP END

//CONTACT PERSON START
ansprechpartner_select = function(person) {
	var tmp;
		$("#ansprechpartner").val(person.ID);
	if (person.vorname == '') tmp = person.Anrede + ' ' + person.name + '<br />';
	else tmp = person.name + ', ' + person.vorname + '<br />';
	if (person.strasse != '' || (person.plz != '' && person.ort != '')) tmp = tmp + person.strasse + '<br />' + person.plz + ' ' + person.ort;
			$("#ansprechpartner_preview").html(tmp);

}

ansprechpartner_delete = function() {
	$("#ansprechpartner").val(0);
	$("#ansprechpartner_preview").text("Keine Person ausgewählt");
}

person_select = function(person) {
	var tmp;
	$('#selectPerson').val(person.ID);
	if (person.vorname == '') tmp = person.Anrede + ' ' + person.name + '<br />';
	else tmp = person.name + ', ' + person.vorname + '<br />';
	if (person.strasse != '' || (person.plz != '' && person.ort != '')) tmp = tmp + person.strasse + '<br />' + person.plz + ' ' + person.ort;
	$('#selectPerson_preview').html(tmp);
}
person_delete = function() {
	$('#selectPerson').val(0);
	$('#selectPerson_preview').text("Keine Person ausgewählt");
}
//CONTACT PERSON END

//RESPONSIBLE PERSON START
responsiblePerson_select = function(person) {
	var tmp;
	$("#verantwortliche_person").val(person.ID);
	if (person.vorname == '') tmp = person.Anrede + ' ' + person.name + '<br />';
	else tmp = person.name + ', ' + person.vorname + '<br />';
	if (person.strasse != '' || (person.plz != '' && person.ort != '')) tmp = tmp + person.strasse + '<br />' + person.plz + ' ' + person.ort;
	$("#responsiblePerson_preview").html(tmp);
}

responsiblePerson_delete = function() {
	$("#verantwortliche_person").val(0);
	$("#responsiblePerson_preview").text("Keine verantwortliche Person ausgewählt");
}
//RESPONSIBLE PERSON END

//TICKET SHOP START
ticketShop_select = function(person) {
	var tmp;
		$("#ticketShop").val(person.ID);
	if (person.vorname == '') tmp = person.Anrede + ' ' + person.name + '<br />';
	else tmp = person.name + ', ' + person.vorname + '<br />';
	if (person.strasse != '' || (person.plz != '' && person.ort != '')) tmp = tmp + person.strasse + '<br />' + person.plz + ' ' + person.ort;
			$("#ticketShop_preview").html(tmp);
}

ticketShop_delete = function() {
	$("#ticketShop").val(0);
	$("#ticketShop_preview").text("Keinen Ticket Shop ausgewählt");
}
//TICKET SHOP END

//ROW START
editRow = function(el) {
	if (!$('#editItem' + el).val()) {
		buttonsBackup[el] = $('#actionBtn_' + el).html();
		var bez = $('#ele-' + el + '-content').text().replace(/["]/ig, "\'");

		$('#actionBtn_' + el).html('<img src="/city_info/images/save.png" onclick="saveRow(' + el + ');" id="saveBtn_' + el + '" class="editBtn" title="speichern" />');
		$('#ele-' + el + '-content').html('<input type="text" id="editItem_' + el + '" name="editItem_' + el + '" value="' + $('#ele-' + el + '-content').text() + '" class="input" />');
	}
}

saveRow = function(el) {
	$('#ele-' + el + '-content').text($('#editItem_' + el).val());
	$('#actionBtn_' + el).html(buttonsBackup[el]);
}

deleteRow = function(el) {
	$('#ele-' + el).remove();
}
//ROW END

//CODE PRINT SIZE START
selectRasterOptions = function(val) {
	switch (val) {
		 case '34': {
			 var op = [['ohne','0'],
					   ['A4 (36 x 3x4 cm)','A4-36x34x6'], // paper size - codes per page x codewidth x codes per line
					   ['A3 (78 x 3x4 cm)','A3-78x34x13']];
		 } break;
		
		 case '68': {
			 var op = [['ohne','0'],
					   ['A4 (9 x 6x8 cm)','A4-9x68x3'],
					   ['A3 (18 x 6x8 cm)','A3-18x68x6']];
		 } break;
		
		 case '1014': {
			 var op = [['ohne','0'],
					   ['A4 (2 x 10x14 cm)','A4-2x1014x2'],
			  		   ['A4 (4 x 10x14 cm)','A4-4x1014x2'],
					   ['A3 (4 x 10x14 cm)','A3-4x1014x2'],
					   ['A3 (6 x 10x14 cm)','A3-6x1014x3'],
					   ['A3 (8 x 10x14 cm)','A3-8x1014x4']];
		 } break;
		 
		 case '2028': {
			 var op = [['ohne','0'],
					   ['A4 (1 x 20x28 cm)','A4-1x2028x1'],
					   ['A3 (1 x 20x28 cm)','A3-1x2028x1'],
					   ['A3 (2 x 20x28 cm)','A3-2x2028x2']];
		 } break;
		 
		 default: {
			 var op = [['ohne','0']];
		 } break;
	}
	$('#raster').options(op);
}
//CODE PRINT SIZE END

//GLOBAL START

//CALCULATE MOBICENT
calculateMobicent = function(noteName, valueName){	
	
	/*if ($("#" + valueName).val().match(/[^\d]/i)) {
		$("#" + noteName).html('Bitte geben Sie einen Zahlenwert ein.');
		$("#" + noteName).css("color", "red");
	} else if($("#" + valueName).val() == "0" || $("#" + valueName).val() == ""){
		$("#" + noteName).html(''); 
	} else{
		DWREngine._execute(_ajaxConfigGlobal._cfscriptLocation, null, 'getCommissionRate', function(getCommissionRate) {
			commissionRate = (100 - getCommissionRate) / 100;
			$("#" + noteName).html('Entspricht ' + parseInt($("#" + valueName).val() * commissionRate) + ' Eurocent');
			$("#" + noteName).css("color", "green");
		});	
	}*/

}



//TRANSLATE
translate = function(id, type) {
	
	DWREngine._execute(_ajaxConfigGlobal._cfscriptLocation, null, 'showTranslate', id, type, function(data) {
		
		$("#dialog").append(
			'<div id="translate">' + data + '</div>'
		);
		
		$("#translate").dialog({			
			title: 	'<img src="/city_info/images/translate.png" title="Übersetzen" alt="Übersetzen" /> Übersetzen',						
			width:	400,
			height:	210,
			modal: false,
			draggable: true,
			resizable: false,
			buttons: {
				'OK': function() {									
					translateItem(id, type);						
					showTab($("#tabName").val(), $("#page").val(), $("#type").val(), $("#searchColumn").val(), $("#search").val(),
						$("#orderColumn").val(), $("#order").val(), region_id);
					$("#translate").remove();											
				},
				'ABBRECHEN': function() {							
					$("#translate").remove();				
				}
			},	
			close: function(){				
				$('#translate').remove();																										
			}
		});		
	});	
}
//TRANSLATE ITEM
translateItem = function(id, item) {
	
	if (errorHandling() == "error"){
		return false;
	};
	
	var lang_id = $('.lang:checked').val();
	
	DWREngine._execute(_ajaxConfigGlobal._cfscriptLocation, null, 'insertItemLanguage', id, lang_id, item, function(status) {
		if (status != 0) {
			actionSuccess('Erfolgreich übersetzt. Wechseln Sie jetzt in die übersetzte Sprache' +
				'(<img src="/city_info/language/Flags/' + lang_id + '.gif" alt="Sprache" title="Sprache" />)' + 
				' um den Datensatz zu bearbeiten.');
		} else {
			actionError("Fehler beim Übersetzen.");
		}		
	});				
}

actionDone = function(action) {	
	$("#notice").hide();
	$("#notice").html('<img src="/city_info/images/ok.png" title="ok" alt="ok" /> ' + action);
	$("#notice").show();
	setTimeout('fade()', 2000);
}

//GET SELECTED TAB NAME
getSelectedTabName = function(){
	var tab = $('#tabs').tabs('option', "selected");
	$('li.tab > a').each(function(i){
		if (tab == i) {
			selTabName = $(this).attr("title");						 
		}
	});	
	return selTabName;
}	

//SUCCESS DIALOG
actionSuccess = function(msg, timeout) {		
	$("#dialog").append(
		'<div id="successMessage">'+msg+'</div>'
	);
		
	$("#successMessage").dialog({
		title: 	'<img src="/city_info/images/ok.png" title="ok" alt="ok" /> Erfolg',
		width: 	400,			
		modal: false,
		resizable: false,
		draggable: false,
		close: function(){
			$("#successMessage").remove();
		}
	});
	
	if(timeout != 0){
		setTimeout('$("#successMessage").remove()', 2000);	
	}	
			
}

//ERROR DIALOG
actionError = function(msg){
	$("#dialog").append(
		'<div id="errorMessage">'+msg+'</div>'
	);
					
	$("#errorMessage").dialog({			
		title: 	'<img src="/city_info/images/cancel.png" title="Fehler" alt="Fehler" /> Fehler',
		modal: true,
		resizable: false,
		draggable: false,
		close: function(){
			$("#errorMessage").remove();
		}
		
	});	
	
}

//CONFIRM BOX
confirmBox = function(msg, callFunction, errorCheck){
	
	if (errorCheck == 1) {
		if (errorHandling() == "error") {
			return false;
		};
	}	

	$("#dialog").append(
		'<div id="confirmBox">'+msg+'</div>'
	);
						
	$("#confirmBox").dialog({			
		title: 	'<img src="/city_info/images/information.png" title="Hinweis" alt="Hinweis" /> Hinweis',
		modal: true,
		resizable: false,
		draggable: false,
		buttons: {
			'Ok': function() {		
				$(this).dialog('close');
				$(this).dialog('destroy');
				$(this).remove();
				eval(callFunction);
			},
			'Abbrechen': function() {		
				$(this).dialog('close');
				$(this).dialog('destroy');
				$(this).remove();
			}
		}		
	});	
	
}

//CHECK IF FILTER IS ACTIVATED
checkFilterActivation = function(region_id, filterName){	
	if (typeof($("." + filterName + ":checked").val()) != "undefined") {			
		showTab($("#tabName").val(), $("#page").val(), $("#type").val(), $("#searchColumn").val(), $("#search").val(), $("#orderColumn").val(), $("#order").val(), region_id);
	}
}

//CHECK IF FILTER IS ACTIVATED
checkboxFilter = function(region_id){					
	showTab($("#tabName").val(), $("#page").val(), $("#type").val(), $("#searchColumn").val(), $("#search").val(), $("#orderColumn").val(), $("#order").val(), region_id);	
}

//GET VALUE FROM FILTER FORM
getFilterValue = function(filterName, filterValue){	
	if (typeof($("." + filterName + ":checked").val()) != "undefined") {					
		if( $("#" + filterValue).length )
			value = $("#" + filterValue).val();
		else if( $("." + filterValue).length )
			value = $("." + filterValue).val();
		else if (filterValue == 'callType')
			value = $("input[name='callType']:checked").val();
		else
			alert('Can\'t find element!\n' + 'element: ' + filterValue);
	} else {
		 if (filterName == 'dateComplete' && filterValue == 'showDayFrom') {
			value = 1;	
		} else if (filterName == 'dateComplete' && filterValue == 'showMonthFrom') {
			value = 1;	
		} else if (filterName == 'dateComplete' && filterValue == 'showYearFrom') {
			value = new Date();
			value = value.getFullYear();
			value = value - 5;
		} else if (filterName == 'dateComplete' && filterValue == 'showDayTo') {
			value = new Date();
			value = value.getDate();			
		} else if (filterName == 'dateComplete' && filterValue == 'showMonthTo') {
			value = new Date();
			value = value.getMonth();	
			value = value + 1;
		}else if(filterName == 'datePickerFrom' && filterValue == 'showCalenderFrom'){
			value = $("#" + filterValue).val();
		}else if(filterName == 'datePickerTo' && filterValue == 'showCalenderTo'){
			value = $("#" + filterValue).val();
		} else if (filterName == 'dateComplete' && filterValue == 'showYearTo') {
			value = new Date();
			value = value.getFullYear();
		} else if (filterName == 'region') {
			value = region_id;
		} else if (filterName == 'callType') {
			value = $("input[name='callType']:checked").val();
		} else {
			value = 0;	
		}
	}
	return value;
}

//GET CONTENT FOR INSERT CONTAINER
getInsertContainerContent = function(contentName){
	if ($('#insertContainer_' + contentName).css("display") == 'none' && typeof($('#insertContent_' + contentName).val())=="undefined") {
		$("#insertLoad_" + contentName).show();
		
		DWREngine._execute(_ajaxConfig._cfscriptLocation, null, 'getInsertContainerContent', contentName, function(data){
			$("#insertContainer_" + contentName).html(data);
			$("#insertLoad_" + contentName).hide();
			$("#insertContainer_" + contentName).show();
			$('#insert_img_' + contentName).attr("src", "/city_info/images/arrow_up.png");
		});
	} else if($('#insertContainer_' + contentName).css("display") != 'none' && typeof($('#insertContent_' + contentName).val())!="undefined"){
		$("#insertContainer_" + contentName).hide();
		$('#insert_img_' + contentName).attr("src", "/city_info/images/arrow_down.png");		
	} else{
		$("#insertContainer_" + contentName).show();
		$('#insert_img_' + contentName).attr("src", "/city_info/images/arrow_up.png");		
	}					
}

//REMOVE INSERT CONTAINER
removeInsertContainer = function(contentName){	
	$(".insertLoad").hide();				
	$('#insertContainer_' + contentName).hide();
	$('#insert_img_' + contentName).attr("src", "/city_info/images/arrow_down.png");	
	$('#insertContainer_' + contentName).html('');	
}

//SELECT PAGE FOR INSERT WIZARD
insertWizardPageChooser = function(page, createItem){			
	switch (page) {				
		case 'insertPageLocation':
			$('#insertPageLocation').show();
			$('#insertPageContracts').hide();									
			break;
		case 'insertPageCodetype':
			$('#insertPageCodetype').show();
			$('#insertPageCodeuse').hide();
			$('#codeFunctionGeoIndoor').hide();						
			break;
		case 'insertPageCodeuse':
			if($('.codeType:checked').val() == 'geo') {
				$('#codeUseGeo').show();
				$('#nfcsettings').show();
				$('#codeUseMobile').hide();			
				$('#codeUse_1').attr("checked","checked"); 								
			} else {
				$('#codeUseGeo').hide();
				$('#nfcsettings').hide();
				$('#codeFunctionGeoIndoor').hide();
				$('#codeUseMobile').show();
				$('#codeUse_4').attr("checked","checked");
			}
			$('#insertPageContracts').hide();	
			$('#insertPageCodetype').hide();
			$('#insertPageCodeuse').show();					
			break;
		case 'insertPageContracts':
			if (errorHandling() == "error"){
				break;
			};
			
			if ($("#tabName").val() != 'location'){				
				if ($("#tabName").val() == 'bonus') {
					var codetype = 'geo';
					var codeuse = 'indoor';
					var codefunction = 'bonus';
				} else if($("#tabName").val() == 'praemie'){
					var codetype = 'mobile';
					var codeuse = 'praemie';
				} else{					
					var codetype = $('.codeType:checked').val();
					var codeuse = $('.codeUse:checked').val();
					
					if ($('.codeUse:checked').val() == 'indoor') {
						var codefunction = $("'.codeFunction:checked'").val();
					}
					else {
						var codefunction = '';
					}
				}		
			} else {
				var codetype = 'geo';
				var codeuse = 'indoor';										
				var	codefunction = 'location';				
			}
			DWREngine._execute(_ajaxConfigGlobal._cfscriptLocation, null, 'getC2CProductsByCodeProperties', codetype, 
				codeuse, codefunction, region_id, function(data) {												
					$("#insertPageContracts").html(data);
					$("#insertPageContracts").show();
					$('#insertPageCodeuse').hide();				
					$('#insertPageCodetype').hide();					
					$('#insertPageLocation').hide();					
					$('#codeFunctionGeoIndoor').hide();
					$('#insertPageCode').hide();
				}
			);
			break;		
		case 'createNewItem':
			if (errorHandling() == "error"){
				return false;
			};				
			$(".insertContainer").hide();	
			$(".insertLoad").show();				
			createNewItem(createItem);
			break;								
	}					
}

//TOGGLE FILTER FORM
toggleFilterForm = function() {
	$('#filterContainer').toggle();
	$('#filter_img').attr("src", "/city_info/images/arrow_down.png");
	if ($('#filterContainer').css("display") == 'none')
		$('#filter_img').attr("src", "/city_info/images/arrow_down.png");
	else
		$('#filter_img').attr("src", "/city_info/images/arrow_up.png");	
}

//TOGGLE FOOTER FORM
toggleFooterForm = function() {
	$('#footerContainer').toggle();
	$('#footer_img').attr("src", "/city_info/images/arrow_down.png");
	if ($('#footerContainer').css("display") == 'none')
		$('#footer_img').attr("src", "/city_info/images/arrow_down.png");
	else
		$('#footer_img').attr("src", "/city_info/images/arrow_up.png");	
}

//TOGGLE FORM
toggleForm = function(divName, imgName) {
	$('#' + divName).toggle();
	$('#' + imgName).attr("src", "/city_info/images/arrow_down.png");
	if ($('#' + divName).css("display") == 'none')
		$('#' + imgName).attr("src", "/city_info/images/arrow_down.png");
	else
		$('#' + imgName).attr("src", "/city_info/images/arrow_up.png");	
}

//TOGGLE CHILDS
toggleChilds = function(divName, imgName) {	
	$('#' + divName).toggle();
	$('#' + imgName).attr("src", "/city_info/images/expand.png");
	if ($('#' + divName).css("display") == 'none')
		$('#' + imgName).attr("src", "/city_info/images/expand.png");
	else
		$('#' + imgName).attr("src", "/city_info/images/collapse.png");	
}

//SHOW PAGE
showPage = function(tab, p) {
	page = p;
	showTab(tab);	
}

//EDIT SELECTED ITEM
editItem = function(id, secondLevelMenu, firstEdit) {
	
	if(typeof firstEdit == "undefined")
		var firstEdit = 0;
		
	
	var tab = $("#tabName").val();
	
	if(tab == "bonus" || tab == "praemie" || (tab == "location" && secondLevelMenu == "code")){
		var pagePath = "/city_info/admin/c2c/code/modify/modify.cfm";	
					
	} else {
		var pagePath = "../modify/modify.cfm"
	}
	
	location.href = pagePath + "?" + $("#urltoken").val() + "&tab=" + tab + "&page=" + $("#page").val() + 
					"&type=" + $("#type").val() + "&searchColumn=" + $("#searchColumn").val() + "&search=" + $("#search").val() +  
					"&orderColumn=" + $("#orderColumn").val() + "&order=" + $("#order").val() +
					"&id=" + id + "&firstEdit=" + firstEdit;
}

//ABORT FUNCTION
abortButton = function(){
	if(tab == "bonus" || tab == "praemie" || tab == "location"){
		var pagePath = "/city_info/admin/c2c/mobicent/default/default.cfm";	
	} else if (tab == 'singleCodes' || tab == 'singleNotInMultiCodes' || tab == 'codegroup' || tab == 'trash') {
		var pagePath = "/city_info/admin/c2c/code/default/default.cfm"
	} else {
		var pagePath = "../default/default.cfm"
	}
	
	location.href = pagePath + "?" + $("#urltoken").val() + "&tab=" + tab + "&page=" + page + "&type=" + type + 
	"&searchColumn=" + searchColumn + "&search=" + search +  "&orderColumn=" + orderColumn + "&order=" + order +
	"&region_id=" + region_id;
}

abortAction = function(func, file) {
	if (file == null || file == '')
		file = "../default/default.cfm";
	
	file += "?";

	var loc = file;
	
	if ($("#urltoken").val() != "" && $("#urltoken").val() != null && $("#urltoken").val() != "undefined")
		loc += $("#urltoken").val();
	else
		loc += urltoken;

	if ($("#page").val() != "" && $("#page").val() != null)
		loc += "&page=" + $("#page").val();
		
	if ($("#order").val() != "" && $("#order").val() != null)
		loc += "&order=" + $("#order").val()
		
	if ($("#search").val() != "" && $("#search").val() != null)
		loc += "&search=" + $("#search").val()
		
	if ($("#displayType").val() != "" && $("#displayType").val() != null)
		loc += "&displayType=" + $("#displayType").val()
		
	if (func != "" && func != null && func != "undefined")
		loc += "&function=" + func
	
	if ($("#category").val() != "" && $("#category").val() != null)
		loc += "&category=" + $("#category").val();
		
	if ($("#region_id").val() != "" && $("#region_id").val() != null)
		loc += "&region_id=" + $("#region_id").val()
		
	location.href = loc;
}

abortActionOneBack = function() {
	location.href = "../default/default.cfm?" + $("#urltoken").val();
}

loadEditor = function(token, style, type, special, modul_id, record_id, params, savemode, formfield) {
	activeedit=window.open('/city_info/admin/cms/aceditor/aceditor.cfm?' + token + '&style=' + style + '&type=' + type + '&special=' + special + '&modul_id=' + modul_id + '&record_id=' + record_id + '&formfield=' + formfield + '&load=1&saveMode=' + savemode + '&iswindow=1&' + params,'activeEdit','location=0,menubar=0,scrollbars=0,toolbar=0,resizable=1,status=0,width=750,height=500');
	activeedit.focus();	
}

toggleObject = function(s, el, showEl, hideEl, closeOther) {
	if (s) {
		if (closeOther != null && closeOther != "") {
			$("." + closeOther).hide();
			$(".showElement").show();
			$(".hideElement").hide();
		}
		$("#" + hideEl).show();
		$("#" + showEl).hide();
	} else {
		$("#" + hideEl).hide();
		$("#" + showEl).show();
	}
	$("#" + el).toggle();
}

//TOGGLE MENU START
getActionMenu = function(id, parent_id, tab, secondLevelMenu, codetype) {
	if ($("#options_" + id).css("display") != "none") {		
		$("#options_" + id).hide();
		$("#show_options_" + id).show();
		$("#hide_options_" + id).hide();
	} else {
		$(".options").hide();						
		DWREngine._execute(_ajaxConfigGlobal._cfscriptLocation, null, 'getActionMenu', id, parent_id, tab, secondLevelMenu, codetype, function(data) {
				$("#options_" + id).html(data);
				active_menu = id;
			}
		);
		if(active_menu > 0) {
			$("#show_options_" + active_menu).show();
			$("#hide_options_" + active_menu).hide();
		}
		$("#options_" + id).show();		
		$("#show_options_" + id).hide();
		$("#hide_options_" + id).show();
	}	
}

getPropertiesMenu = function(id) {											
	DWREngine._execute(_ajaxConfigGlobal._cfscriptLocation, null, 'getPropertiesMenu', id, function(data) {
			$("#dialog").append(
				'<div id="propertiesMenu">'+data+'</div>'
			);
				
			$("#propertiesMenu").dialog({
				title: 	'<img src="/city_info/images/ok.png" title="ok" alt="ok" /> Status',
				width: 	200,			
				modal: false,
				resizable: false,
				draggable: false,
				close: function(){
					$("#propertiesMenu").remove();
				}
			});
		}
	);
}		

updateCodeProperty = function(code_id, id, img, bezeichnung) {
	DWREngine._execute(_ajaxConfigGlobal._cfscriptLocation, null, "updateCodeProperty", code_id, id, function(status){		
		if (status == 1) {
			$("#propertiesMenu").remove();
		}
		else {
			$("#propertiesMenu").remove();
			actionError("Fehler beim Aktualisieren der Codeeigenschaft.");
		}
	});
	$("#propertyBtn_" + code_id).html('<img src="/city_info/images/'+ img + '" title="' + bezeichnung + '" alt="' + bezeichnung + '" />');
}


//--------------OLD--------------
toggleCodePropertiesMenu = function(id, action) {
	var data = new Object();
	data['type'] = 'code_properties';
	data['id'] = id;
	data['action'] = action;
	
	toggleMenu(data);	
}

toggleBlogMenu = function(id, action) {
	var data = new Object();
	data['type'] = 'blog';
	data['id'] = id;
	data['action'] = action;
	
	toggleMenu(data);
}

toggleTemplateMenu = function(id, action) {
	var data = new Object();
	data['type'] = 'template';
	data['id'] = id;
	data['action'] = action;
		
	toggleMenu(data);
}

toggleCodeItemsMenu = function(id, action) {
	var data = new Object();
	data['type'] = 'codeitems';
	data['id'] = id;
	data['action'] = action;

	toggleMenu(data);
}

toggleProductMenu = function(id, pid, region_id, _fixed, action) {
	var data = new Object();
	data['type'] = 'product';
	data['id'] = id;
	data['pid'] = pid;
	data['region_id'] = region_id;
	data['fixed'] = _fixed;
	data['action'] = action;
	
	toggleMenu(data);
}

toggleGeoMessageMenu = function(id, code_id) {
	var data = new Object();
	data['type'] = 'message';
	data['id'] = id;
	data['code_id'] = code_id;
	data['action'] = 'getMessageActionMenu';
	
	toggleMenu(data);
}

toggleResellerMenu = function(id, action) {
	var data = new Object();
	data['type'] = 'reseller';
	data['id'] = id;
	data['action'] = action;
	
	toggleMenu(data);
}

toggleContractMenu = function(id,action,parent_id,tab){
	var data = new Object();
	data['type'] = 'contract';
	data['id'] = id;
	data['action'] = action;
	data['parent_id'] = parent_id;	
	data['tab'] = tab;
	
	toggleMenu(data);
}

var toggle_menu_lock = 0;
toggleMenu = function(data) {
	if(toggle_menu_lock == 1) {
		return false;
	}
	toggle_menu_lock = 1;
	var id = data['id'];
		
	if ($("#options_" + data['id']).css("display") != "none") {
		if (data['type'] == 'code_properties') {
			$("#options_" + data['id']).hide();		
		} else {
			$("#options_" + data['id']).hide();
			$("#show_options_" + data['id']).show();
			$("#hide_options_" + data['id']).hide();
			$("#loading_" + data['id']).show();						
		}
		active_menu = 0;
		window.setTimeout("toggle_menu_lock = 0;", 200);
	} else {
		if (active_menu != 0) {
			$("#options_" + active_menu).hide();
			$("#show_options_" + active_menu).show();
			$("#hide_options_" + active_menu).hide();
		}
		switch(data['type']) {
			case 'product': {
				//var option = new Array(data['id'], data['pid'], data['region_id'], data['fixed']);				
				DWREngine._execute(_ajaxConfig._cfscriptLocation, null, data['action'], data['id'], data['pid'], data['region_id'], data['fixed'], function(data) {
						$("#options_" + id).html(data);
						active_menu = id;
						toggle_menu_lock = 0;
					}
				);
			} break;
			case 'message': {
				DWREngine._execute(_ajaxConfig._cfscriptLocation, null, data['action'], data['id'], data['code_id'], function(data) {
						$("#options_" + id).html(data);
						active_menu = id;
						toggle_menu_lock = 0;
					}
				);
			} break;
			case 'reseller': {
				DWREngine._execute(_ajaxConfig._cfscriptLocation, null, data['action'], data['id'], data['code_type'], data['func'], function(data) {
						$("#options_" + id).html(data);
						active_menu = id;
						toggle_menu_lock = 0;
					}
				);
			} break;
			case 'code': {				
				DWREngine._execute(_ajaxConfig._cfscriptLocation, null, data['action'], data['id'], data['contract'], function(data) {
						$("#options_" + id).html(data);
						active_menu = id;
						toggle_menu_lock = 0;
					}
				);
			} break;
			case 'codeitems': {
				DWREngine._execute(_ajaxConfig._cfscriptLocation, null, data['action'], data['id'], data['code_type'], data['func'], data['category'], function(data) {
						$("#options_" + id).html(data);
						active_menu = id;
						toggle_menu_lock = 0;
					}
				);
			} break;
			case 'contract':{
				DWREngine._execute(_ajaxConfig._cfscriptLocation, null, data['action'], data['id'], data['tab'], data['parent_id'], function(data) {
						$("#options_" + id).html(data);
						active_menu = id;
						toggle_menu_lock = 0;
					}
				);
			}
			case 'blog': {
				DWREngine._execute(_ajaxConfig._cfscriptLocation, null, data['action'], data['id'], function(data) {
						$("#options_" + id).html(data);
						active_menu = id;
						toggle_menu_lock = 0;
					}
				);
			} break;
			case 'template':{
				DWREngine._execute(_ajaxConfig._cfscriptLocation, null, data['action'], data['id'], function(data) {
						$("#options_" + id).html(data);
						active_menu = id;
						toggle_menu_lock = 0;
					}
				);
			}
			case 'code_properties':{						
				DWREngine._execute(_ajaxConfig._cfscriptLocation, null, data['action'], data['id'], function(data) {
						$("#options_" + id).html(data);
						active_menu = id;
						toggle_menu_lock = 0;
					}
				);
			}
		}
		
		$("#options_" + data['id']).show();
		$("#show_options_" + data['id']).hide();
		$("#hide_options_" + data['id']).show();
	}

}
//TOGGLE MENU END


toggleCategory = function(id) {
	el = document.getElementsByName("category_" + id);
	el2 = document.getElementById("categoryAll_" + id);
	for (i=0; i<el.length; i++) {
		if (el2.checked == true && el[i].disabled == false) {
			el[i].checked = true;
		} else {
			el[i].checked = false;
		}
	}
}

toggleCategoryFooter = function() {
	el = document.getElementsByName("category");
	el2 = document.getElementById("categoryAll");
	for (i=0; i<el.length; i++) {
		if (el2.checked == true && el[i].disabled == false) {
			el[i].checked = true;
		} else {
			el[i].checked = false;
		}
	}
}

toggle = function(el1, el2) {
	$("#" + el1).show();
	$("#" + el2).hide();
}

//if length of day, month, minute or hour is 1 then put 0 before   
testLeadZero = function(nr) {
	if (nr.length == 1){
		return "0" + nr;
	}
	else {
		return nr;
	}
}

untip = function() {
	tip(false);	
}

tip = function(info) {
	
	if (!info) {
		container = document.getElementById('infoContainer');
		if (container != null)
			container.parentNode.removeChild(container);
	} else {
		var w = window.event;

		var container = document.createElement("div");
		container.innerHTML = info;
		
		var id = document.createAttribute("id");
		id.nodeValue = "infoContainer";
		container.setAttributeNode(id);
		
		var styleClass = document.createAttribute("class");
		styleClass.nodeValue = "infoContainer";
		container.setAttributeNode(styleClass);
		
		var elWidth = 180;
		var elHeight = 120;
		var scrOfY = 0, scrOfX = 0;
		
		if(typeof(window.pageYOffset) == 'number') {
			//Netscape compliant
			scrOfY = window.pageYOffset;
			scrOfX = window.pageXOffset;
		} else if(document.body && (document.body.scrollLeft || document.body.scrollTop)) {
			//DOM compliant
			scrOfY = document.body.scrollTop;
			scrOfX = document.body.scrollLeft;
		} else if(document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
			//IE6 standards compliant mode
			scrOfY = document.documentElement.scrollTop;
			scrOfX = document.documentElement.scrollLeft;
		}

		var left = w.clientX + scrOfX + 10;
		var top = w.clientY + scrOfY + 10;
		
		//alert(document.body.scrollTop + ' ' + document.documentElement.scrollTop + ' ' + window.pageYOffset);

		if (parseInt(w.clientX) + parseInt(elWidth) > document.body.clientWidth) {
			left = parseInt(w.clientX) - parseInt(elWidth) - 10;
		}
		
		container.style.left = left;
		container.style.top = top;
	
		document.body.appendChild(container);
	}
}

displayInfo = function(action, t) {
	if (t == null)  ft = 2000;
	else			ft = t;	
	$("#notice").hide();
	$("#notice").html('<img src="/city_info/images/ok.png" title="ok" alt="ok" /> ' + action);
	$("#notice").show();
	if (ft != 0) {
		setTimeout('fade()', ft);
	}
}
fade = function() {
	if ($("#notice").css("display") != "none") {
		$("#notice").fadeOut("slow");
	}
}

toggleSubMenu = function(el) {
	var show;
	if ($('#' + el).css("display") == 'none')
		show = true;
	else
		show = false;
			
	$('.subSelectBox').hide();
	if (show)
		$('#' + el).show();
}

hideSubMenu = function() {
	$('.subSelectBox').hide();
}

//Codeuse Combobox
codeUseCombo = function() {
		
	if($('#codeTypeCmb').val() == "geo"){		
		$('#codeuse').html('<select size="0px" onchange="codeFunctionCombo()" id="codeUseCmb">' +									
												'<option value="indoor">Indoor</option>' + 
												'<option value="outdoor">Outdoor</option>' +
										  '</select>');		
	}
	else{		
		$('#codeuse').html('<select size="0px" onchange="codeFunctionCombo()" id="codeUseCmb">' +																																 
												'<option value="content">Inhaltsseite</option>' +
												'<option value="vcard">Visitenkarte</option>' +
												'<option value="file">Datei</option>' +
												'<option value="redirect">Weiterleitung</option>' +
												'<option value="event">Event</option>' +
												'<option value="praemie">Prämie</option>' +
		   								  '</select>');
	}
	codeFunctionCombo();
}

//Codefunction Combobox
codeFunctionCombo = function() {
	
	if ($('#codeUseCmb').val() == "indoor"){
		$('#codefunction').html('<select size="0px" id="codeFunctionCmb" name="codeFunctionCmb">' +													
													'<option value="content">Inhaltsseite</option>' + 
													'<option value="location">Standort</option>' +
													'<option value="bonus">Bonus</option>' + 
													'<option value="action">Aktion</option>' +					
											   '</select>');
	}	
	else{		
		$('#codefunction').html('<select size="0px" id="codeFunctionCmb" name="codeFunctionCmb">' +
														'<option value="">--</option>' +																		
											   '</select>');
	}
}

//SELECT RESELLER PREMIUM PARTNER
showPremiumPartner = function(){
	if ($('#resellerType').val() == 1){
		$("#trResellerPremiumPartner").hide();
	}else{
		$("#trResellerPremiumPartner").show();
	}	
}	

//Openingtimes
setAllOpeningDays = function(){
	
	var monday = new Array();
	
	// save data
	if($("#day_1_1:checked").val()){
		// 1
		monday[0] = new Object();
		monday[0]["stdFrom"] = $("#day_1_h1_1").val();	//montag von Stunde
		monday[0]["minFrom"] = $("#day_1_m1_1").val();	//montag von Minute
		
		monday[0]["stdTill"] = $("#day_1_h2_1").val();	//montag bis Stunde
		monday[0]["minTill"] = $("#day_1_m2_1").val();	//montag bis Minute
	}	
	// save data
	if($("#day_1_2:checked").val()){
		// 2
		monday[1] = new Object();
		monday[1]["stdFrom"] = $("#day_1_h1_2").val();	//montag von Stunde
		monday[1]["minFrom"] = $("#day_1_m1_2").val();	//montag von Minute
		
		monday[1]["stdTill"] = $("#day_1_h2_2").val();	//montag bis Stunde
		monday[1]["minTill"] = $("#day_1_m2_2").val();	//montag bis Minute
	}
	
	// set data to other day fields
	if ($("#day_1_1:checked").val()) {
		for(var i = 0;i <= 7;i++){
			$("#day_"+i+"_1").attr("checked","checked");
			
			$("#day_"+i+"_h1_1").val(monday[0]["stdFrom"]); //montag von Stunde
			$("#day_"+i+"_m1_1").val(monday[0]["minFrom"]); //montag von Stunde
			
			$("#day_"+i+"_h2_1").val(monday[0]["stdTill"]); //montag bis Stunde
			$("#day_"+i+"_m2_1").val(monday[0]["minTill"]); //montag bis Stunde
		}
	}
	if ($("#day_1_2:checked").val()) {
		for(var i = 0;i <= 7;i++){
			$("#day_"+i+"_2").attr("checked","checked");
			
			$("#day_"+i+"_h1_2").val(monday[1]["stdFrom"]); //montag von Stunde
			$("#day_"+i+"_m1_2").val(monday[1]["minFrom"]); //montag von Stunde
			
			$("#day_"+i+"_h2_2").val(monday[1]["stdTill"]); //montag bis Stunde
			$("#day_"+i+"_m2_2").val(monday[1]["minTill"]); //montag bis Stunde
		}
	}
	
	$("a[name='openingTime']").toggle();
}

undoAllOpeningDays = function(){
		
	// set all days to default 0 value
	for(var i = 2;i <= 7;i++){
		// 1
		$("#day_"+i+"_1").attr("checked",false);
			
		$("#day_"+i+"_h1_1").val("00"); //montag von Stunde
		$("#day_"+i+"_m1_1").val("00"); //montag von Stunde
		
		$("#day_"+i+"_h2_1").val("00"); //montag bis Stunde
		$("#day_"+i+"_m2_1").val("00"); //montag bis Stunde
		
		// 2
		$("#day_"+i+"_2").attr("checked",false);
		
		$("#day_"+i+"_h1_2").val("00"); //montag von Stunde
		$("#day_"+i+"_m1_2").val("00"); //montag von Stunde
		
		$("#day_"+i+"_h2_2").val("00"); //montag bis Stunde
		$("#day_"+i+"_m2_2").val("00"); //montag bis Stunde
	}
	
	
	$("a[name='openingTime']").toggle();
}

// get user defined fields 
getUserFields = function(category){
	DWREngine._execute(_ajaxConfig._cfscriptLocation, null, "getUserFields", category, function(data){
				$("#setUserFieldContainer").html(data);
			}
		);	
}

//E-MAIL START

//GET E-MAIL CONTENT 
tinyMceContent_change = function(){	
	$('#emailTextContainer').html($('#tinyMceContent').val());
	$('#emailTextContainer').show();		
}

//OPEN E-MAIL FORM
openMailForm = function(region_id, query, id_list){	

	if (typeof id_list == "undefined") {
    	id_list = "";
		if(query == "customer_selected" || query == "reseller_selected" || query == "contacts_selected"){
			$("input[type='checkbox']:checked").each(function(i){
				var value = parseInt($(this).val());
				var objRegExp  = /(^-?\d\d*$)/; // check integer

				if(objRegExp.test(value)){
					if(id_list!="")
						id_list += "," + value;
					else
						id_list += value;
				}
						
			});
			if (!id_list.length) {
				actionError("Bitte etwas auswählen!");
				return false;
			}
		}
	}

	DWREngine._execute(_ajaxConfigGlobal._cfscriptLocation, null, 'getMailForm', region_id, query, id_list,function(data) {
							$("#dialog").append(
								'<div id="email">' + data + '</div>'
							);
							
							$("#email").dialog({			
								title: 	'<img src="/city_info/images/email.png" title="E-Mail" alt="E-Mail" /> E-Mail',						
								width:	800,
								height:	'auto',
								modal: false,
								draggable: true,
								resizable: true,
								close: function(){
									$('#mailContainer').remove();									
									$('#mailTabs').remove();
									$('#mailLoad').remove();
									$('#email').remove();																										
								}
							});
							
							$('#mailTabs').tabs({});
			
							//set selected tab								
							$('#mailTabs').tabs('select', 'writeMail');
							writeMail(region_id, query, id_list);	
																	
							//function for selected tab
							$('#mailTabs').bind('tabsselect', function(event, ui) {		
								switch (ui.tab.title) {
									case "writeMail":								
										writeMail(region_id, query, id_list);
										break;
									case "transmittedMail":										
										showTransmittedMail('transmittedMail', 1, '', '', '', 'datum', 'desc', region_id);
										break;										
								}		
							});	
																																	
						}
	);	
}

//OPEN TRANSMITTED MAIL
openTransmittedMail = function(mailFrom, mailTo, mailSubject, mailTextId){	
	
	mailText = $('#mailText_' + mailTextId).val();
	
	DWREngine._execute(_ajaxConfigGlobal._cfscriptLocation, null, 'openTransmittedMail', mailFrom, mailTo, mailSubject, mailText, function(data) {
							$("#dialog").append(
								'<div id="transmittedEmail">' + data + '</div>'
							);
							
							$("#dialog").dialog({			
								title: 	'<img src="/city_info/images/email_open.png" title="Gesendete E-Mail" alt="Gesendete E-Mail" /> ' + mailSubject,						
								width:	800,
								height:	0,
								modal: false,
								draggable: true,
								resizable: true,
								close: function(){
									$('#transmittedMailContainer').remove();									
									$('#transmittedMailLoad').remove();
									$('#transmittedEmail').remove();																		
								}		
							});
							$('#emailTextContainer').show();
						}
	);	
}


//TRANSMITTED E-MAIL LIST
showTransmittedMail = function(tab, page, type, searchColumn, search, orderColumn, order, region_id) {
	
	$("#mailContainer").hide();	
	$("#mailLoad").show();
		
	DWREngine._execute(_ajaxConfigGlobal._cfscriptLocation, null, 'transmittedMailForm', tab, page, type, searchColumn, search, orderColumn, order, region_id, function(data) {
							$("#mailContainer").html(data);							
							$("#mailLoad").hide();
							$("#mailContainer").show();																	
						}
	);	
}

//WRITE E-MAIL
writeMail = function(region_id, query, id_list){
	 if (typeof id_list == "undefined") {
    	id_list = "";
	  }
	
	$("#mailContainer").hide();	
	$("#mailLoad").show();
	DWREngine._execute(_ajaxConfigGlobal._cfscriptLocation, null, 'sendMailForm', region_id, query, id_list, function(data) {
							$("#mailContainer").html(data);							
							$("#mailLoad").hide();
							$("#mailContainer").show();
						}
	);	
};

//SEND E-MAIL
sendMail = function(emailToList){	
	
	if (errorHandling() == "error"){
		return false;
	};
	
	var tinyMceContent = $('#tinyMceContent').val();
	var emailSubject = $('#emailSubject').val();
	var newsletter = ($('#newsletter:checked').val() == 1) ? 1 : 0;

	DWREngine._execute(_ajaxConfigGlobal._cfscriptLocation, null, "sendMail", tinyMceContent, emailSubject, emailToList, newsletter,function(status) {
			if (status == 1) {
				actionSuccess("E-Mail erfolgreich versendet.");
				$('#mailTabs').tabs('select', 'transmittedMail');				
				showTransmittedMail('transmittedMail', 1, '', '', '', 'datum', 'desc', region_id);				
			} else {				
				actionError("Fehler beim Versenden der E-Mail.");
			}
		});		
}


sendMailCustom = function(emailToList, subject, content, callback) {
	
	if(typeof(callback) == "undefined"){
		callback = function(){}
	}

	DWREngine._execute(_ajaxConfigGlobal._cfscriptLocation, null, "sendMail", content, subject, emailToList, function(status) {
		callback(status);	
	})
}

//TOGGLE E-MAIL TO FORM
toggleEmailToForm = function() {
	$('#emailToContainer').toggle();
	$('#emailTo_img').attr("src", "/city_info/images/arrow_down.png");
	if ($('#emailToContainer').css("display") == 'none')
		$('#emailTo_img').attr("src", "/city_info/images/arrow_down.png");
	else
		$('#emailTo_img').attr("src", "/city_info/images/arrow_up.png");	
}

// REMOVE Recipient
removeRecipient = function(mailAdress) {
	
	// decrease the count of recipient
	var cnt = parseInt($('#recipientCount').text());
	if(cnt <= 1) {
		actionError('Es muss mindestens ein Empfänger vorhanden sein!');
		return false;
	}
	cnt--;
	$('#recipientCount').text(cnt);
	
	// remove from display
	if($('.mailDesc[title="'+mailAdress+'"]').attr('title') == $('.mailDesc:last').attr('title')) {
		// if the last element clicked, we will remove the comma before the clicked element
		
		// get the text of the next to last element and remove the comma
		var el = $('.mailDesc:nth-child('+ ($('.mailDesc').length - 1) +')');
		var text = el.text();
		text = text.replace(' ,', '');
		el.text(text);
	}
	$('.mailDesc[title="'+mailAdress+'"]').remove();
		
	var recipients = $('#emailToList').val();
	recipients = recipients.replace(mailAdress+",", ""); // all items
	recipients = recipients.replace(","+mailAdress, ""); // last item with comma before the adress
	$('#emailToList').val(recipients);
}

//E-MAIL END

// toggle submenu class
toggleSubmenu = function(el){
	$("ul.subMenuBox li").each(
		function(i){
			$(this).removeClass("selectedSubMenu");
		}
	);
	
	$(el).addClass("selectedSubMenu");
}

getCommaListByCheckboxElement = function(selector) {
	var list = "";
	$(selector + ":checked").each(function(i){
		if(!list.length){
			list += $(this).val();  
		}else{
			list += "," + $(this).val();
		}
	});	
	return list;
}

//Editor
agb_change = function() {}
tos_change = function() {}
top_change = function() {}
beschreibung_l_change = function() {}
c2c_footer_content_change = function() {}

//GLOBAL END
$(document.body).click(function () {
	$("#options_" + active_menu).fadeOut("fast");
	$("#show_options_" + active_menu).show();
	$("#hide_options_" + active_menu).hide();
	$("#loading_" + active_menu).show();
	active_menu = 0;
});

$().ready(function(){	
	// set the datepicker in german format
	if (typeof($.datepicker) != "undefined") {
		jQuery(function($){
			$.datepicker.regional['de'] = {
				clearText: 'löschen',
				clearStatus: 'aktuelles Datum löschen',
				closeText: 'schließen',
				closeStatus: 'ohne Änderungen schließen',
				prevText: '&#x3c;zurück',
				prevStatus: 'letzten Monat zeigen',
				nextText: 'Vor&#x3e;',
				nextStatus: 'nächsten Monat zeigen',
				currentText: 'heute',
				currentStatus: '',
				monthNames: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
				monthNamesShort: ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'],
				monthStatus: 'anderen Monat anzeigen',
				yearStatus: 'anderes Jahr anzeigen',
				weekHeader: 'Wo',
				weekStatus: 'Woche des Monats',
				dayNames: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'],
				dayNamesShort: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
				dayNamesMin: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
				dayStatus: 'Setze DD als ersten Wochentag',
				dateStatus: 'Wähle D, M d',
				dateFormat: 'dd.mm.yy',
				firstDay: 1,
				initStatus: 'Wähle ein Datum',
				isRTL: false
			};
			$.datepicker.setDefaults($.datepicker.regional['de']);
		});
	}	
	
	// bind toggle function to all submenu items
	$("ul.subMenuBox li").each(function(i){
		$(this).bind("click",function(){
			toggleSubmenu($(this));
		})
	});
});

