// JavaScript Document

//var question = confirm("Voulez-vous consulter la version mobile de ce site ?");
var myreferrer = window.document.referrer.toString();
var tailleurl = window.document.location.toString().length;
var cnturl = window.document.location.toString();

//alert (window.document.location+" "+tailleurl);


if ((/appip3/i.test(myreferrer))||(/appip4/i.test(myreferrer))||(/appans/i.test(myreferrer))||(/appanb/i.test(myreferrer)));

else if ((tailleurl <= 23)||(/mobile/i.test(cnturl)))
{
//	alert("début de détection");
//	alert(navigator.userAgent);

	if (/iphone/i.test(navigator.userAgent))
		{

//			alert("I");
			if (window.devicePixelRatio >= 2) window.location.href ="http://www.bcv.ch/static/mobile/appip3.html";
			else window.location.href ="http://www.bcv.ch/static/mobile/appip3.html";
		}
	if (/android/i.test(navigator.userAgent))
		{
//			alert("A");
	 		if(screen.width <= 440)	window.location.href ="http://www.bcv.ch/static/mobile/appans.html";
			if((screen.width > 440)&&(screen.width <= 800)) window.location.href ="http://www.bcv.ch/static/mobile/appanb.html";
		}
		
}


function SiteDisplay()
{
//alert (document.cookie);
if (document.cookie.search("bcvmobileonce1") == -1)
{
	//alert("Y");
	if ((/ipad/i.test(navigator.userAgent))||(/android/i.test(navigator.userAgent)))
	{

	//alert("yy")
		if ((screen.width > 800)||(/ipad/i.test(navigator.userAgent)))
		{
		//alert(Devicename);
		//alert(Devicename+""+screen.width);			

	
		    var myoverlay = document.getElementById("overlay-display");
			myoverlay.style.backgroundColor = "#515151";
			myoverlay.style.position = "absolute";
			myoverlay.style.top = "0px";
			myoverlay.style.left = "0px";
			myoverlay.style.zIndex = "90";	
			myoverlay.style.height = "1280px";
			myoverlay.style.width = "100%";
		    myoverlay.style["-moz-opacity"] = 0.9;
		    myoverlay.style["-khtml-opacity"] = 0.9;
		    myoverlay.style["opacity"] = 0.9;




	var myelement = document.getElementById("site-display");

	myelement.innerHTML = "";
	myelement.style.backgroundColor ="#515151";
	myelement.style.position = "absolute";
//	myelement.style.height = "480px";
	myelement.style.width = "320px";
	myelement.style.top = "160px";
	myelement.style.left = "330px";
	myelement.style.zIndex = "100";	
    myelement.style["-moz-opacity"] = 1;
    myelement.style["-khtml-opacity"] = 1;
    myelement.style["opacity"] = 1;

	
	myelement.innerHTML = "<p>L'application "
	+"<div id='Mcontent' style='text-align: center;'>"
	+"<div id='ele1' class='mblocintro' style='width:320px;'>"
    +"<p class='mtexte mtexteblanc mtextetitre '>Bienvenue sur le site de la BCV</p>"
	+"<p class='mtexte mtexteblanc'>&nbsp;</p>"
	+"<p class='mtexte mtexteblanc'>Désormais, vous pouvez  utiliser votre site<br />"
    +"bancaire préféré aussi sur votre tablette</p>"
    +"</div>"
    +"<div id='ele2' class='mbloccontenu' style='width:320px;' onclick='window.location.href=\"http://itunes.apple.com/us/app/bcv-hd/id483424082?l=fr&ls=1&mt=8\"'>"
	+"<img src='http://www.bcv.ch/static/mobile/images/icon-app-store.jpg' alt='App Store' width='117' height='41' border='0' class='mimage' />"
	+"<p class='mtexte mtexte140 plus10'>BCV Mobile</p>"
    +"<img src='http://www.bcv.ch/static/mobile/images/fleche-verte.png' alt='Télécharger BCV-Mobile' width='11' height='16' border='0' class='mchevron'/>"
	+"</div>"
    +"<div id='ele3' class='mbloccontenu' style='width:320px;' onclick='setcook();window.location.href=cnturl;'>"
    +"<img src='http://www.bcv.ch/static/mobile/images/icon-site-bcv.jpg' alt='www.bcv.ch - Site internet principal' width='117' height='41' border='0' class='mimage' />"
    +"<p class='mtexte mtexte140'>Aller sur le site internet</p>"
	+"<img src='http://www.bcv.ch/static/mobile/images/fleche-verte.png' alt='Télécharger BCV-Mobile' width='11' height='16' border='0' class='mchevron' />"
    +"</div>"
    +"</div>";
		}
	}
//alert("x");
}
}

function setcook()
{
	document.cookie = "bcvmobile='bcvmobileonce1'; expires=Mon, 31 Dec 2012 23:59:59 UTC;";

}

