//Get element by id 
if (!document.getElementById) {
	if (document.all)
		document.getElementById=function() {
			if ( typeof(document.all[arguments[0]]) != "undefined")
				return document.all[arguments[0]];
			else
				return null;
		}
	else if (document.layers)
		document.getElementById=function() {
			if ( typeof(document[arguments[0]]) != "undefined")
				return document[arguments[0]];
			else
				return null;
		}
}

//Get element
function $$() { 
    var elements = new Array(); 
    for (var i=0,len=arguments.length;i<len;i++) { 
        var element = arguments[i]; 
        if (typeof element == 'string') { 
            var matched = document.getElementById(element); 
            if (matched) { 
                elements.push(matched); 
            } else { 
                var allels = (document.all) ? document.all : document.getElementsByTagName('*'); 
                var regexp = new RegExp('(^| )'+element+'( |$$)'); 
                for (var i=0,len=allels.length;i<len;i++) if (regexp.test(allels[i].className)) elements.push(allels[i]); 
            } 
            if (!elements.length) elements = document.getElementsByTagName(element); 
            if (!elements.length) { 
                elements = new Array(); 
                var allels = (document.all) ? document.all : document.getElementsByTagName('*'); 
                for (var i=0,len=allels.length;i<len;i++) if (allels[i].getAttribute(element)) elements.push(allels[i]); 
            } 
            if (!elements.length) { 
                var allels = (document.all) ? document.all : document.getElementsByTagName('*'); 
                for (var i=0,len=allels.length;i<len;i++) if (allels[i].attributes) for (var j=0,lenn=allels[i].attributes.length;j<lenn;j++) if (allels[i].attributes[j].specified) if (allels[i].attributes[j].nodeValue == element) elements.push(allels[i]); 
            } 
        } else { 
            elements.push(element); 
        } 
    } 
    if (elements.length == 1) { 
        return elements[0]; 
    } else { 
        return elements; 
    } 
}

function getHttpRequest(){
	httpRequest = null;
	if (window.XMLHttpRequest) {
		httpRequest = new XMLHttpRequest();
		if (httpRequest.overrideMimeType) {
			httpRequest.overrideMimeType('text/xml');
		}
	}
	else if (window.ActiveXObject) {
		try {
			httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e) {}
		}
	}
	return httpRequest;
}

//Declenche evenements
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			if (oldonload) {
				oldonload();
			}
			func();
		}
	}
}

function fenetreCent(url,nom,largeur,hauteur,options) {
	var haut=(screen.height-hauteur)/2;
	var Gauche=(screen.width-largeur)/2;
	fencent=window.open(url,nom,"top="+haut+",left="+Gauche+",width="+largeur+",height="+hauteur+","+options);
	fencent.focus();
}

// fonctions pour flash
function viewBookmarks(etat1, etat2, flag){
	try{
		$$('bookmarkcrimexpo').style.display = etat1;
		$$('linkVersion').style.display = etat2;
		$$('flag').style.left = flag;
	}catch(e){
	}
}

function moveBookmarks(etat){
	try{
		if (etat == 'large') {
			$$('bookmarkcrimexpo').style.marginLeft = '240px';
		} else {
			$$('bookmarkcrimexpo').style.marginLeft = '66px';
		}
		var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;

		if (!isWin) {
			$$('bookmarkcrimexpo').style.bottom = '7px';
		}
	}catch(e){
	}
}

function addActionOnLinks(){
	var links = document.getElementsByTagName("a");
	for(var i=0, len = links.length; i < len; i++){
		if(links[i].className == "popuplink_extern")
			links[i].onclick = function(){
				fenetreCent(this.href, "crimexpo", 800, 600, "resizable=yes,location=yes,menubar=yes,status=yes,scrollbars=yes,toolbar=yes");
				return false;
			}
			
		if(links[i].className == "popuplink_intern")
			links[i].onclick = function(){
				try{
					$$('layer').style.display = "block";
					$$('layer_close').onclick = function(){
						try{
							$$('layer').style.display = "none";
						}catch(e){}
					}
					$$('layer_content').innerHTML = "";
					$$('layer_title').innerHTML = "<h1>"+this.title+"</h1>";
					var HttpRequest_page = getHttpRequest();
					if(HttpRequest_page){
						HttpRequest_page.onreadystatechange = function() {
							if (HttpRequest_page.readyState == 4) {
								if (HttpRequest_page.status == 200) {
									$$('layer_content').innerHTML = HttpRequest_page.responseText;
									addActionOnLinks();
									correctPNG();
								}
							}
						};
						HttpRequest_page.open('POST','popup_html.php?p='+this.href,true);
						//HttpRequest_page.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
						HttpRequest_page.send('');
					}
				}catch(e){
					alert(e);
				}
				return false;
			}
			if(links[i].className == 'popup_photos')
				links[i].onclick = function(){
					try{
						$$('layer_content').innerHTML = "";
						$$('layer').style.display = "block";
						$$('layer_close').onclick = function(){
							try{
								$$('layer').style.display = "none";
								viewGalerie('none');
							}catch(e){}
						}
						$$('layer_title').innerHTML = "<h1>"+this.title+"</h1>";
						viewGalerie('block');
					}catch(e){
						alert(e);
					}
					return false;
				}
	}
}

function SetCookie (name, value) { 
    var argv = SetCookie.arguments; 
    var argc = SetCookie.arguments.length; 
    var expires = (argc > 2) ? argv[2] : null; 
    var path = (argc > 3) ? argv[3] : null; 
    var domain = (argc > 4) ? argv[4] : null; 
    var secure = (argc > 5) ? argv[5] : false; 
  
    document.cookie = name + "=" + escape (value) + 
    ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
    ((path == null) ? "" : ("; path=" + path)) + 
    ((domain == null) ? "" : ("; domain=" + domain)) + 
    ((secure == true) ? "; secure" : ""); 
} 

function linkVersionFunc() {
	$$("linkVersion").onclick = function() {
		SetCookie('version', $$("version").innerHTML);
		if ($$("version").innerHTML == "version flash") {
			window.location = "index.html";
		} else {
			window.location = "index_html.php";
		}
	}
}

addLoadEvent(linkVersionFunc);

addLoadEvent(function(){
	try{
		addActionOnLinks();
		
		//Overlay pour ie6
		var tds = $$('content').getElementsByTagName('td');
		for(var i=0, len = tds.length; i < len; i++){
			if(tds[i].className == "text")
				$$('overlay').style.height = (tds[i].offsetHeight +20 )+"px";
		}
	}catch(e){}
});