// browserwarn.js
// Check browser details
// and alert user to issues

function checkBrowser(){
var appName = BrowserDetect.browser;
var appVersion = BrowserDetect.version;
var width = screen.width;
var height = screen.height;
var maxWidth =screen.availWidth;
var maxHeight = screen.availHeight;
var codename = navigator.appCodeName;
var platform = BrowserDetect.OS;

var result = "App Name: "+appName+"\nApp Version: "+appVersion+"\n\nWidth: "+width+"\nHeight: "+height+"\nmaxWidth: "+maxWidth+"\nmaxHeight: "+maxHeight+"\n\nCodename: "+codename+"\n\nPlatform: "+platform+"";

//alert(result);
var wcookie=getCookie("nowarning");

if ((wcookie == null)||(wcookie == '')||(wcookie == undefined)){
    

if((!DetectAndroid())&&(!DetectIphoneOrIpod())){
if (appName == 'Explorer' && appVersion < 7){
    addCSS();
    $('#alertB').append('<h2><img src="/images/warn.png" align="absmiddle"/>Something\'s not right here...</h2>The web browser you are using is too old to utilize the features of this site.<br/><br/>For instructions on how to upgrade your browser <a href="http://browsehappy.com/" target="_blank">Click Here</a>.<br/><br/><input type="checkbox" id="notagain" onclick="notAgain()"/><label for="notagain"> Don\'t show this again</label>');
   $("#alertB").dialog({ title: "Unsupported Web Browser",modal: true, width: 640,height:350 });
   return false;
}
if (width < 1024 || height < 768){
    addCSS();
    $('#alertB').append('<h2><img src="/images/warn.png" align="absmiddle"/>Something\'s not right here...</h2>This site is designed to work at a minimum screen resolution of 1024x768. <br/> Because your computer is set to a resolution of '+width+'x'+height+' this site may not work properly.<br/><br/>For instructions on adjusting your screen resolution <a href="http://windows.microsoft.com/en-US/windows-xp/help/change-screen-resolution" target="_blank">Click Here</a>.<br/><br/><input type="checkbox" id="notagain" onclick="notAgain()"/><label for="notagain"> Don\'t show this again</label>');
    $("#alertB").dialog({ title: "Screen Resolution Too Low!",modal: true,width: 640,height:350 });
    return false;
}
else {
    return true;
}
}
}

}

function notAgain(){
    // Set a cookie that the user does not want to see any more warnings
    setCookie("nowarning",'1',18250);
    $('#alertB').dialog('close');
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

function addCSS(){

var cssId = 'myCss';  // you could encode the css path itself to generate id..
if (!document.getElementById(cssId))
{
    var head  = document.getElementsByTagName('head')[0];
    var link  = document.createElement('link');
    link.id   = cssId;
    link.rel  = 'stylesheet';
    link.type = 'text/css';
    link.href = 'http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/themes/blitzer/jquery-ui.css';
    link.media = 'all';
    head.appendChild(link);
}

}

function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
  x=x.replace(/^\s+|\s+$/g,"");
  if (x==c_name)
    {
    return unescape(y);
    }
  }
}


var deviceAndroid = "android";

//**************************
// Detects if the current device is an Android OS-based device.
function DetectAndroid()
{
   if (uagent.search(deviceAndroid) > -1)
      return true;
   else
      return false;
}

var deviceIphone = "iphone";
var deviceIpod = "ipod";

//Initialize our user agent string to lower case.
var uagent = navigator.userAgent.toLowerCase();

//**************************
// Detects if the current device is an iPhone.
function DetectIphone()
{
   if (uagent.search(deviceIphone) > -1)
      return true;
   else
      return false;
}

//**************************
// Detects if the current device is an iPod Touch.
function DetectIpod()
{
   if (uagent.search(deviceIpod) > -1)
      return true;
   else
      return false;
}

//**************************
// Detects if the current device is an iPhone or iPod Touch.
function DetectIphoneOrIpod()
{
    if (DetectIphone())
       return true;
    else if (DetectIpod())
       return true;
    else
       return false;
}

