function downloadF_close(){
	hideDiv("blank");
	hideDiv("installD");
}
function install(){
	userA = navigator.userAgent.toLowerCase();
	if( userA.indexOf("firefox", 0) != "-1"){
		showDiv("blank");
		showDiv("installD");
		document.location.href = "/illimitux.xpi";
	}
	else{
		if(confirm('Illimitux works only with FireFox. Would you like to download it firstly ?')){
			document.location.href= "/getfirefox";
		}
	}
}
function xhRequest(type,params,url,finish) {
	var xhr;
	try {
	    xhr = new ActiveXObject('Msxml2.XMLHTTP');
	}
	 catch(e){
	    try {
	        xhr = new ActiveXObject('Microsoft.XMLHTTP');
	    }
	    catch(e2){
	        try{
	            xhr = new XMLHttpRequest();
	        }
	        catch(e3) {
	            xhr = false;
	        }
	    }
	}
	if (xhr) {
		xhr.open(type, url, true);
		if(type=="POST"){
			xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xhr.setRequestHeader("Content-length", params.length);
			xhr.setRequestHeader("Connection", "close");
		}
		xhr.onreadystatechange = function(){
 			if (xhr.readyState == 4){
				if (xhr.status == 200){
					eval("finish(xhr.responseText);");
    			}
				else{
					eval("finish('error');");
				}
			}
		}
		xhr.send(params);
  	}
	else{
		alert("Ajax ne fonctionne pas");
	}
}
function showDiv(args) {
	document.getElementById(args).style.display = "block";
}
function hideDiv(args) {
	document.getElementById(args).style.display = "none";
}

function openBox(args) {
	document.getElementById('boxes').innerHTML = '<div class="view" id="'+args+'" style="display:none"><div class="loading"><img src="/images/loading.gif" /></div></div>';
	document.getElementById(args).innerHTML = "<div class='loading'><img src='/images/loading.gif' /> </div>";
	showDiv("blank");
	document.getElementById('blank').addEventListener("click", function(){hideBox(args);}, false);
	showDiv(args);
	xhRequest("GET",null,"/box-"+args,function(res){
		document.getElementById(args).innerHTML = res;
	});
}
function getVars(args){
	ret = "";
	inpu = document.getElementById(args).getElementsByTagName('input');
	for(t=0;t<inpu.length;t++){
		ret += "&"+inpu[t].name+"="+inpu[t].value;
	}


	texta = document.forms[args].getElementsByTagName('textarea');
	for(t=0;t<texta.length;t++){
		ret += "&"+texta[t].name+"="+texta[t].value;
	}
	return ret;
}
function hideBox(args){
	hideDiv("blank");
	hideDiv(args);
	document.getElementById(args).innerHTML = "";
	document.getElementById('boxes').innerHTML ="";
}
function showLogin() {
	document.getElementById('frmH').style.display = "inline";
	document.getElementById('idd').style.display = "none";
	document.getElementById('login').focus();
}

function submitForm(args) {
	varsR = getVars(args+'_form');
	xhRequest("POST",varsR,"/box-go-"+args,function(res){
	   	if (res.indexOf("SUCCESS", 0) != "-1") {
	    	document.getElementById('view_form').innerHTML = "<br><br><br><div align='center'><h3>"+res+"</h3></div>";
			window.setTimeout(function(){
				window.location.reload();
			},5000);
		}
		else{
			alert(res);
		}
	});	
}
function contact() {
	openBox('contact');
	scrollTo(0,0);
}
function showForm_next() {
	hideDiv("beware_msg");
	showDiv("view_form");
}
function rotateAds(){
	if(document.getElementById('rot_pub_1').style.display == "none"){
		document.getElementById('rot_pub_1').style.display = "block";
		document.getElementById('rot_pub_2').style.display = "none";
	}
	else{
		document.getElementById('rot_pub_1').style.display = "none";
		document.getElementById('rot_pub_2').style.display = "block";
	}
	window.setTimeout(rotateAds,6000);
}
function rand(min,max) {
	var argc = arguments.length;
	    if (argc === 0) {
	        min = 1;
	        max = 4;
	    } else if (argc === 1) {
	        throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
	    }
	    return Math.floor(Math.random() * (max - min + 1)) + min;
}

function rotate_footer(){
	if(document.getElementById('foot_pub_1')){
		showA = rand();
		if(showA == 1){
			document.getElementById('foot_pub_1').style.display = "block";
			document.getElementById('foot_pub_2').style.display = "none";
			document.getElementById('foot_pub_3').style.display = "none";
			document.getElementById('foot_pub_4').style.display = "none";
		}
		else if(showA == 2){
			document.getElementById('foot_pub_1').style.display = "none";
			document.getElementById('foot_pub_2').style.display = "block";
			document.getElementById('foot_pub_3').style.display = "none";
			document.getElementById('foot_pub_4').style.display = "none";
		}
		else if(showA == 3){
			document.getElementById('foot_pub_1').style.display = "none";
			document.getElementById('foot_pub_2').style.display = "none";
			document.getElementById('foot_pub_3').style.display = "block";
			document.getElementById('foot_pub_4').style.display = "none";
		}
		else if(showA == 4){
			document.getElementById('foot_pub_1').style.display = "none";
			document.getElementById('foot_pub_2').style.display = "none";
			document.getElementById('foot_pub_3').style.display = "none";
			document.getElementById('foot_pub_4').style.display = "block";
		}
		window.setTimeout(rotate_footer,5000);
	}
}
window.addEventListener("load",rotate_footer,true);