var SiteC = {

	popup				: '',
	templateSettings	: {},
	
	openWindow: function(url, parameters) {
		this.popup = window.open(url, 'SiteC_popup', parameters);
		this.popup.focus();
	},
	
	cloaseWindow: function() {
		this.popup.close();
	},
	
 	setSefValue: function(field, value, trim) {
		var char;
		var rex;
		var specialChars = {
			a 	: 'àáâãäå',
			ae	: 'æ',
			c	: 'ç',
			d	: 'Ð',
			e	: 'èéêë',
			i	: 'ìíîï',
			n	: 'ñ',
			o	: 'òóôõöø',
			ss	: 'ß',
			u	: 'ùúûü',
			x	: '×', 
			y	: 'ýÿ'
		};
		
		//lower case
		value = value.toLowerCase();
		
		//strips all leading and trailing whitespace
		if((typeof trim == 'undefined') || (trim == true)) {
			value = value.strip();
		};
		
		//convert all whitespaces to - char
		value = value.replace(/\s/g, '-');
		
		//convert all dots to - char
		value = value.replace('.', '-');
		
		//convert utf8 chars to normal chars
		for(char in specialChars) {		
			rex = new RegExp('['+specialChars[char]+']', 'g');
			value = value.replace(rex, char);
		};
		
		//only keep letters,numbers,slashes,minus and underscore
		value = value.replace(/[^a-z0-9/\-_]/g, '');
		
		//remove any multiple minus chars
		while(value.indexOf('--') != -1) {
			value = value.replace('--', '-');
		};
		
		//remove any multiple slash chars
		while(value.indexOf('//') != -1) {
			value = value.replace('//', '/');
		};
		
		$(field).value = value;	
	},

	setSectionTitles: function() {
		if($F('section_title') != '' && $F('section_title_menu') == '' && $F('section_title_browser') == '' && $F('section_title_sef') == '') {
			$('section_title_menu').value = $F('section_title');
			$('section_title_browser').value = $F('section_title');
			this.setSefValue($('section_title_sef'), $F('section_title'), true);
		};
	},
	
	setSectionImage: function(section_path_image) {
		var templateSettings 			= this.templateSettings[$F('template_id')];
		$('section_path_image').value 	= section_path_image;
		
		if(templateSettings.section_image_active) {
			$('browse').removeClassName('AdminFormButtonSubmitDisabled');
			$('browse').disabled = false;
		} else {
			$('browse').addClassName('AdminFormButtonSubmitDisabled');
			$('browse').disabled = true;
		};
		
		var ajax = new Ajax.Updater($('display_section_image'), WS_ADMIN + 'xhr/section_image.php', {method: 'get', evalScripts: true, onCreate: function(){$('display_section_image').update('<img src=\'' + WS_ADMIN + 'images/loading.gif\'>');}, parameters:{section_path_image: section_path_image}});
	}
};

//module compatibility
setSefValue = SiteC.setSefValue;

function cms_cancelEventBubbling(evt) {
	//this fuctions cancels the event you put in it
	//example: if you have buttonlink in a tr-link you have to block the tr-link
	//window.event.cancelBubble doesnt work in firefox
	//call function exactly like this: cms_cancelEventBubbling(event);
	
	Event.stop(evt);
}
