//-------------------------- FONCTION COOKIE ----------------------------
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

var pubactif = readCookie('mobile');


if (document.referrer == "") createCookie('mobile','passif',1);

if (pubactif !='passif' && document.referrer != "") {

	if((window.location.host.search(/onisep.fr/i) != -1) || (window.location.host.search(/integra.fr/i) != -1)) 
	{	
	createCookie('mobile_url',self.location.href,1);
	}

//-------------------------- VERIFICATION URL  ----------------------------
	
var url="";
if (/Apres-le-bac/.test(self.location.href))
	url= "/site/redirection_mobile/post-bac.html";
else
	url= "/site/redirection_mobile/";
	

//-------------------------- VERIFICATION DES VERSION DES NAVIGATEURS ----------------------------
//ios		
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/iPad/i)) )
	{ 
		document.location.href=url;
	}


//android
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1;
if(isAndroid){
	tabUA = ua.split(";");
	version = tabUA[2].split(" ");
	version = version[2];
	version = version.split(".");
	if(version[0] >= 1){	
	document.location.href=url;
	//alert(self.location.href);
	}
}


}
