if(parent.frames.length > 0) {
	window.top.location.href = location.href;
}

function parseUrl(data) {
    var e=/^((http|ftp):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+\.[^(#|?)?\s]+)(\?[\w\-=&]+)?(#[\w\-]+)?$/;
    if (data.match(e)) {
        return {
			url: RegExp['$&'],
            protocol: RegExp.$2,
            host:RegExp.$3,
            path:RegExp.$4,
            file:RegExp.$6,
			params:RegExp.$7,
            hash:RegExp.$8
		};
    }
    else {
        return {
			url:"", 
			protocol:"",
			host:"",
			path:"",
			file:"",
			params:"",
			hash:""
		};
    }
}

function parseFile(data){
	var m = data.match(/(.*)[\/\\]([^\/\\]+\.\w+)$/);
	return {path: m[1], file: m[2]}
}

function fFlashMessage() {
	new mooFlashMessage($$('.flash'));
}

function fPopupImage(img) { 
	w = window.open('','image','width=400,height=400,toolbar=no,scrollbars=no,resizable=no'); 
	w.document.write("<html><head><title>B-Floor</title></head>"); 
	w.document.write("<script>function checksize() { if (document.images[0].complete) { window.resizeTo(document.images[0].width+10,document.images[0].height+30); window.focus();} else { setTimeout('checksize()',250) } }</"+"script>"); 
	w.document.write("<body onload='checksize()' onblur='window.close()' onclick='window.close()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0>");
	w.document.write("<table width='100%' border='0' cellspacing='0' cellpadding='0' height='100%'><TR>");
	w.document.write("<td valign='middle' align='center'><img src='"+img+"' border=0 alt=''>"); 
	w.document.write("</td></tr></table>");
	w.document.write("</body></html>"); 
	w.document.close();
}

function fAjaxCornerFlash(){
	new Ajax('ajax-entreprise.html' , {method: 'get', update: $('ajax'), evalScripts: true, onComplete:function(){
		new Ajax('js/getmenu.js.php' , {method: 'get', update: $('ulmenu'), onComplete:function(){fAjaxLinks();}}).request();
	}}).request();	
}

function fAjaxLinks(content) {
	var links = [];
	if (content && $('ajax')){
		links = $$('#ajax a', '#ajax area');
	} else {
		links = $$('a', 'area');
	}

	links.each(function(el){
		if (el.getProperty('href') && (el.getProperty('href').search(/\.((html)|(htm)|(php))(\?.*)?$/i) != -1 && !el.getProperty('target') && el.getProperty('target') != '_blank')) {
			el.addEvent('click', function(e){
				var regex = new RegExp("^(.*/)?([^/]+)\.(html|htm|php)$", "i");
//				var regex = /^(\w\-:\/)?([^\/]*)\.((html)|(htm)|(php))(\?.*)?$/i;
				m = el.getProperty('href').match(regex);
				//alert(m);
				if (m) {
					if (m[1]) {
						url = m[1] + 'ajax-' + m[2] + '.' + m[3]
					} else {
						url = 'ajax-' + m[2] + '.' + m[3]
					}
					var e = new Event(e).stop();
					new Ajax(url , {method: 'get', update: $('ajax'), evalScripts: true, onComplete:function(){
						new Ajax('js/getmenu.js.php' , {method: 'get', update: $('ulmenu'), onComplete:function(){fAjaxLinks();}}).request();
					}}).request();	
							
				}else {
//					alert(el.getProperty('href'));
				}
				//alert(url);
				
			});
		}
	});
}

function fAjaxInit() {
	fFlashMessage();
	fAjaxLinks(true);
	
	$$('#ajax form').each(function(form){
		// date : 20100217 
		// author : Geoffroy
		// changes : check if it's an external url
		var reg=new RegExp("http:\/\/([a-zA-Z0-9\.\_\-]+)(\/.*)?");
		var matches = document.location.href.match(reg);
		var http_host = matches[1];
		var matches = form.getProperty('action').match(reg)
		if(null==matches || matches[1]==http_host){
			form.setProperty('action', 'ajax-'+form.getProperty('action'));
			form.addEvent('submit', function(e){
				var e = new Event(e).stop();
				this.send({update: $('ajax'), evalScripts: true, onComplete:function(){
					new Ajax('js/getmenu.js.php' , {method: 'get', update: $('ulmenu'), onComplete:function(){fAjaxLinks();}}).request();
				}});
				
			});
		}
	});
}
function fGo(lien) {
	new Ajax('ajax-'+lien, {method: 'get', update: $('ajax'), evalScripts: true}).request();
}

function fGoHome() {
	fGo('home.html');
}

function fGoEntreprise() {
	fGo('entreprise.html');
}

function fSlideshow(imagesSlide){
	new Slideshow('slideshow', {type: 'zoom', duration: [1200, 5000],  width: 640, height: 480, images: imagesSlide, hu: 'content/gallery/'});
}

function fInit() {
	fAjaxLinks();
	fFlashMessage();
}
window.addEvent('domready', fInit);
