// Browser Detection Javascript
// copyright 1 February 2003, by Stephen Chapman, Felgall Pty Ltd
// Modified By: 	Ángel Díaz
//					Barcelona Media
//					May 2011

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function whichBrs() {
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1) return 'Opera';
	if (agt.indexOf("staroffice") != -1) return 'Star Office';
	if (agt.indexOf("webtv") != -1) return 'WebTV';
	if (agt.indexOf("beonex") != -1) return 'Beonex';
	if (agt.indexOf("chimera") != -1) return 'Chimera';
	if (agt.indexOf("netpositive") != -1) return 'NetPositive';
	if (agt.indexOf("phoenix") != -1) return 'Phoenix';
	if (agt.indexOf("firefox") != -1) return 'Firefox';
	if (agt.indexOf("safari") != -1) return 'Safari';
	if (agt.indexOf("skipstone") != -1) return 'SkipStone';
	if (agt.indexOf("msie") != -1) return 'Internet Explorer';
	if (agt.indexOf("netscape") != -1) return 'Netscape';
	if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
	if (agt.indexOf('\/') != -1) {
		if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
			return navigator.userAgent.substr(0,agt.indexOf('\/'));
		}
		else {
			return 'Netscape';
		}
	} 
	else if (agt.indexOf(' ') != -1) {
		return navigator.userAgent.substr(0,agt.indexOf(' '));
	}
	else return navigator.userAgent;
}
function whichDevice() {
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("iphone")!= -1) return 'iPhone';
	if (agt.indexOf("ipad")!= -1) return 'iPad';
	if (agt.indexOf("ipod")!= -1) return 'iPod';
	if (agt.indexOf("android")!= -1) return 'Android';
	if (agt.indexOf("blackberry")!= -1) return 'Blackberry';
	return 'Desktop';
}
function showIOSContent(content,path) {
	content.innerHTML  = "";
	content.innerHTML = "<h4>Benvingut a la web d'elCorrector</h4>\n" +
	"Hem detectat que estàs accedint al web d'elCorrector a través d'un dispositiu iPhone/iPad/iPod Touch.<br/><br/>\n" +
	"Si estàs interessat en fer correccions a través del teu dispositiu de textos escrits en català, t'informem de  disposes de les següents aplicacions per a iPhone/iPad/iPod Touch:<br/>\n" +
	"<div class='ioscontent'>" +
		"<h4>elCorrector</h4>" +
		"<img src='"+path+"/images/IconiPad.png' class='icon' />" +
		"<span>Corregeix textos de fins a 300 caràcters. <strong>Preu:</strong> 1,59&euro;.</span>" +
		"<a class='linkstore' href='http://itunes.apple.com/es/app/elcorrector/id422271139?mt=8&ls=1'>" +
			"<img src='"+path+"/images/AppStoreBadge.png' class='appstore' />" +
		"</a>" +
	"</div>\n" +
	"<div class='ioscontent'>" +
		"<h4>elCorrectorPro</h4>" +
		"<img src='"+path+"/images/IconiPadPro.png' class='icon' />" +
		"<span>Corregeix textos de fins a 1000 caràcters. <strong>Preu:</strong> 2,99&euro;.</span>" +
		"<a class='linkstore' href='http://itunes.apple.com/es/app/elcorrectorpro/id431817961?mt=8&ls=1'>" +
			"<img src='"+path+"/images/AppStoreBadge.png' class='appstore' />" +
		"</a>" +
	"</div>\n" +
	"<div class='ioscontent'>" +
		"<h4>elCorrectorLite</h4>" +
		"<img src='"+path+"/images/IconiPadLite.png' class='icon' />" +
		"<span>Corregeix textos de fins a 150 caràcters i màxim 2 correccions al dia. <strong>Preu:</strong> Gratuït.</span>" +
		"<a class='linkstore' href='http://itunes.apple.com/es/app/elcorrectorlite/id435068060?mt=8&ls=1'>" +
			"<img src='"+path+"/images/AppStoreBadge.png' class='appstore' />" +
		"</a>" +
		"</div>\n" +
	"</div>";
	
}
function showSoonAvailableContent(content,path) {
	content.innerHTML = "";
	content.innerHTML += "<h4>Benvingut a la web d'elCorrector</h4>\n" +
	"Hem detectat que accedeixes al web d'elCorrector a través d'un dispositiu/terminal smartphone/tablet per al qual encara no tenim aplicació nadiva.<br/><br/>\n" +
	"Si us plau, si et sembla que et seria d'utilitat tenir-la, demana'ns que fem una versió d'elCorrectorMobile per al teu dispositiu a través de la secció de <a href='suport/' title='Suport'>Suport</a>.<br/><br/>";
}
function browserDetect(path) {
	var browserName = whichBrs();
	//alert(browserName);
	var deviceName = whichDevice();
	//alert(deviceName);
	var content = document.getElementById('post-4');
	if (content != null) { 
		if (deviceName == "iPhone" || deviceName == "iPad" || deviceName == "iPod") {
			showIOSContent(content,path);
		}
		else if (deviceName != "Desktop") {
			showSoonAvailableContent(content,path);
		}
		else {
			//do nothing if is Desktop Client
			//showIOSContent(content,path);
			//showSoonAvailableContent(content,path);
		}
	}
	
}
