// JavaScript Document
var userInfo=navigator.userAgent;

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;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function dismiss_warning(){
	createCookie('gpmf','safari_dismiss',1)//they have chosen to dismiss the warning. Create the dismiss cookie to last for one day.
	var alert_area=document.getElementById("sys_info");
	alert_area.innerHTML="";

}


function browserCheck() {
	
	//alert(userInfo)
	if(userInfo.indexOf('Safari')!=-1){//if this is safari
		if (userInfo.indexOf('Version/')!=-1 || userInfo.indexOf('Chrome/')!=-1){//if "Version/" or "Chrome"is in the userInfo string, this is safari 3 or higher or google chrome
			if (myCookie) {//if a cookie exists
			eraseCookie('gpmf');//erase it. They have upgraded. Hooray!
			}
			
		//var version_str_loc=userInfo.lastIndexOf('Version/');//find occurance of version/
		//var start_str_loc=parseInt(version_str_loc+8)//Add 8 to the start and 1 to the end to grab major version number
		//var end_str_loc=start_str_loc+1;
		//var safari_majVer=userInfo.substring(start_str_loc, end_str_loc);//returns safari major version
	
			}//end if newer safari
			
			else{//This broswer is pre safari 3.0
				var myCookie = readCookie('gpmf');
				if (myCookie) {//if a cookie exists
						if(myCookie=='safari_dismiss'){//User has chosen to dismiss. ignore the browser and show no warning
							}//end if cookie is dismiss
						
						else{//they have been flagged but have not explicitly chose to ignore. Show the warning again.
							var alert_area=document.getElementById("sys_info");
							alert_area.innerHTML='<div id="browser_alert">'
  + '<p><strong>This site has advanced features that require Safari 3 or higher &mdash; or Firefox &mdash; and may not display properly in your browser.</strong></p>'
  + '<p>Check your Mac operating system by clicking on the Apple icon at the top left and choose &quot;About This Mac.&quot; If your operating system is 10.4 or above, '
  + 'you can download the newest version of Safari. If it is below 10.4, please use the Firefox browser to view this site properly.</p>'
  + '<div id="broswer_download"><a href="http://www.apple.com/safari" target="_blank"><img src="/images/get_safari.gif" /></a>'
  + '<a href="http://www.mozilla.com/en-US/firefox/firefox.html" target="_blank"><img src="/images/get_firefox.gif" /></a></div>'
  + '<div id="no_thanks"><a onclick="dismiss_warning()"><img src="/images/no_thanks.gif" /></a></div></div>';
 

						}//end flagged else
				}//end if cookie
				else{// if no cookie, set the cookie and show the warning
					createCookie('gpmf','safari_warning',1);
					var alert_area=document.getElementById("sys_info");
					alert_area.innerHTML='<div id="browser_alert">'
  + '<p><strong>This site has advanced features that require Safari 3 or higher &mdash; or Firefox &mdash; and may not display properly in your browser.</strong></p>'
  + '<p>Check your Mac operating system by clicking on the Apple icon at the top left and choose &quot;About This Mac.&quot; If your operating system is 10.4 or above, '
  + 'you can download the newest version of Safari. If it is below 10.4, please use the Firefox browser to view this site properly.</p>'
  + '<div id="broswer_download"><a href="http://www.apple.com/safari" target="_blank"><img src="/images/get_safari.gif" /></a>'
  + '<a href="http://www.mozilla.com/en-US/firefox/firefox.html" target="_blank"><img src="/images/get_firefox.gif" /></a></div>'
  + '<div id="no_thanks"><a onclick="dismiss_warning()"><img src="/images/no_thanks.gif" /></a></div></div>';
	
					}//end else if cookie
	
			
			
				}//end else old safari
			}//end if safari
			else{//this is a not safari
				if (myCookie) {//if a cookie exists
				eraseCookie('gpmf');//erase it. They have switched browsers. Hooray!
				}
			}
}

window.onload = browserCheck;
