/*
function detectIE(ClassID,name)
function Test_acrobat(Is_IE)
function Test_browser()
function Test_cookie_return(Cookies_enabled)
function Test_cookie()
function Test_js()
function Test_screen()
function Test_spyware()
function Set_time(DateTime)
function Test_time()
function Test_compliance()
function allow_access()
*/

//var
var _Acrobat_answer=false;
var _Browser_answer=false;
var _Cookie_answer=false;
var _Cookie_ran=false;
var _Js_answer=false;
var _Screen_answer=false;
var _Spyware_answer=false;
var _Server_time=new Date(); //Loaded in server-side JS on calling page
var _Time_answer=false;
//var

document.write('<SCR' + 'IPT LANGUAGE=VBScript>\n');
document.write('function TestPDF(Version)\n');
document.write('	on error resume next\n');
document.write('	TestPDF = IsObject(CreateObject(Version))\n');
document.write('end function\n');
document.write('</SCR' + 'IPT>\n');

function detectIE(ClassID,name)
{
	result = false;
	document.write('<SCR' + 'IPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("' + ClassID + '"))</SCR' + 'IPT>\n');
	if (result)
		return name+',';
	else
		return '';
};
	
function Test_acrobat(Is_IE)
{
	//var
	var PDF=false;
	var IE_PDFtest=false;
	var Cookie_display_line="";
	//var
	
	if(navigator.mimeTypes.length>0)
	{
		if(navigator.mimeTypes["application/pdf"]!=undefined)
			PDF=true;
	}else{
		//TestPDF is a VBScript function at the top
		if(TestPDF("PDF.PdfCtrl.1")!=undefined || TestPDF("PDF.PdfCtrl.5")!=undefined || TestPDF("PDF.PdfCtrl.6")!=undefined || TestPDF("acroPDF.PDF")!=undefined)
			PDF=true;
	};

	if(PDF)
		document.getElementById('acrobat').innerHTML="Installed";
	else
		document.getElementById('acrobat').innerHTML="<b><font color=#ff0000>Not Installed</font> - <a href=http://www.adobe.com/products/acrobat/readstep2.html target=_blank>Install</a></b>";

	//document.cookie = "browser_test_pdf=" + PDF + ";";
	//document.cookie = "browser_test_pdf_value=" + document.getElementById('acrobat').innerHTML.replace(/ /g,"+") + ";";
	
	return PDF;
};

function Test_browser()
{
	//var
	var User_agent = navigator.userAgent.toLowerCase();
	//User_agent="Mozilla/4.0 (compatible; MSIE 5.23; Mac_PowerPC)".toLowerCase();
	//User_agent="mozilla/5.0 (windows; u; windows nt 5.1; en-us; rv:1.7.10) gecko/20050716 firefox/1.0";
	//User_agent="mozilla/5.0 (windows; u; windows nt 5.1; en-us; rv:1.7.10) gecko/20050716 firefox/1.0.6";
	//User_agent="Mozilla/4.0 (compatible; MSIE 6.0; AOL 9.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)".toLowerCase();
	//User_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)".toLowerCase();
	//User_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)".toLowerCase();
	//User_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Win 9x 4.90)".toLowerCase();
	//User_agent="Mozilla/4.0 (compatible; MSIE 6.0; AOL 9.0; Windows 98)".toLowerCase();
	//User_agent="Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/312.5 (KHTML, like Gecko) Safari/312.3".toLowerCase();
	//User_agent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:0.9.4.2) Gecko/20021112 CS 2000 7.0/7.0".toLowerCase();
	//User_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.1.4322)".toLowerCase();
	//User_agent="Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)".toLowerCase();
	//User_agent="Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.2) Gecko/20040804 Netscape/7.2 (ax)".toLowerCase();
	//User_agent="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.10) Gecko/20050909 Red Hat/1.0.6-1.4.2 Firefox/1.0.6".toLowerCase();
	//User_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT; Hotbar 4.4.0.0)::ELNSB50::00008115064004b002a002dc000000000507000900000000".toLowerCase();
	//User_agent="AUDIOVOX-SMT5600/1.2 Mozilla/4.0 (compatible; MSIE 4.01; Windows CE; Smartphone; 176x220)".toLowerCase();
	//User_agent="Mozilla/4.0 (compatible; MSIE 5.0; AOL 7.0; Windows 95; DigExt)".toLowerCase();
	//User_agent="Mozilla/4.0 (compatible; MSIE 5.0; WinNT Service Pack 2; ATHMWWW1.1;)".toLowerCase();
	//User_agent="Mozilla/5.0 (compatible; Konqueror/3.3; Linux) (KHTML, like Gecko)".toLowerCase();
	//User_agent="Mozilla/5.0 (compatible; Konqueror/3.4; Linux) KHTML/3.4.2 (like Gecko)".toLowerCase();
	//User_agent="Mozilla/5.0 (compatible; Konqueror/3.1-rc3; i686 Linux; 20020119)".toLowerCase();
	//User_agent="Mozilla/2.0 (compatible; MSIE 3.0B; Windows NT)".toLowerCase();
	//User_agent="Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)".toLowerCase();
	//User_agent="LocalcomBot/1.2 (+http://www.local.com/bot.htm)".toLowerCase();
	//User_agent="Mozilla/4.0 (compatible; MSIE 5.5; Windows 98; Win 9x 4.90)".toLowerCase();
        var Is_IE  = (User_agent.indexOf("msie") != -1);
        var Is_AOL = (User_agent.indexOf("aol") != -1);
        var Is_NS  = (navigator.appName.indexOf("Netscape") != -1);
        var Is_WIN = ((User_agent.indexOf("win")!=-1) || (User_agent.indexOf("32bit")!=-1));
        var Is_MAC = (User_agent.indexOf("mac")!=-1);
        var Is_NIX = (User_agent.indexOf("nux")!=-1);
        var OS_ver = "";
        var Browser_ver = "";
        var Browser_subver = "";
        var Browser = "";
        var Display_line = "";
        //var
        
        try{
	        if(Is_IE)
	        {
		        Browser_ver=User_agent.match(/msie ([\d\.]+)/)[1];
			Browser="IE " + Browser_ver;
		}else{
			if(User_agent.match(/ ([\w\.]+)\/(\d+\.\d+)\.?\d?( \(ax\))?$/)!=null)
			{
			        Browser_ver=User_agent.match(/ ([\w\.]+)\/(\d+\.\d+)\.?\d?( \(ax\))?$/)[2];
				Browser=User_agent.match(/ ([\w\.]+)\/(\d+\.\d+)\.?\d?( \(ax\))?$/)[1];
			}else{
//				alert(User_agent);
			        Browser_ver=User_agent.match(/ ([\w\.]+)\/(\d+\.\d+)\.?\d?( \(ax\))?(-[\w\d]+)?;?/)[2];
				Browser=User_agent.match(/ ([\w\.]+)\/(\d+\.\d+)\.?\d?( \(ax\))?(-[\w\d]+)?;?/)[1];
			};
			Browser=Browser.charAt(0).toUpperCase() + Browser.substring(1,Browser.length) + " " + Browser_ver;
		};
	}catch(e){
		Browser_ver=0;
		Browser="Undetectable";
	};
	if(Is_AOL)
	{
	        Browser_subver=User_agent.match(/aol ([\d\.]+)/)[1];
		Browser+=" (AOL " + Browser_subver + ")";
	};
	if(Is_WIN)
	{
		OS_ver=User_agent.match(/win(\w\w )?\w* ?\w* ([\w\.]+)/);
		if(OS_ver[1]!=undefined && OS_ver[1].substring(2,3)==" ")
			OS_ver=OS_ver[1];
		else
			OS_ver=OS_ver[2];
		if(!User_agent.match(/win 9x 4.90/))
		{
		        switch(OS_ver)
		        {
		        	case '98': OS_ver="Windows 98"; break;
		        	case '3.1': OS_ver="Windows NT 3.1"; break;
		        	case '3.5': OS_ver="Windows NT 3.5"; break;
		        	case '3.51': OS_ver="Windows NT 3.51"; break;
		        	case '4.0': OS_ver="Windows NT 4.0"; break;
		        	case '5.0': OS_ver="Windows 2000"; break;
		        	case '5.1': OS_ver="Windows XP"; break;
		        	case '5.2': OS_ver="Windows Server 2003"; break;
		        	case '6.0': OS_ver="Vista"; break;
		        	default: OS_ver="Windows " + OS_ver.toUpperCase(); break;
		        };
		}else
			OS_ver="Windows ME";
	}else if(Is_MAC){
		OS_ver="Macintosh";
	}else if(Is_NIX){
		OS_ver="Linux";
	}else{
		OS_ver="Other";
	};
	
	Display_line = OS_ver + " - " + Browser;
	
        if((Is_IE && Browser_ver>=5.5) && Is_WIN)
		document.getElementById('browser').innerHTML=Display_line;
	else
		document.getElementById('browser').innerHTML="<font color=#ff0000><b>" + Display_line + "</b></font>";

	//document.cookie = "browser_test_browser=" + ((Is_IE && Browser_ver>=5.5) && Is_WIN) + ";";
	//document.cookie = "browser_test_browser_value=" + document.getElementById('browser').innerHTML.replace(/ /g,"+") + ";";
	
	return ((Is_IE && Browser_ver>=5.5) && Is_WIN);
};

function Test_cookie_return(Cookies_enabled)
{
	//This function is ran from the postback of the "Test_cookie()" JS function
        if(Cookies_enabled)
        {
		document.getElementById('cookie').innerHTML="Enabled";
		_Cookie_answer=true;
	}else{
		document.getElementById('cookie').innerHTML="<font color=#ff0000><b>Disabled</b></font>";
		_Cookie_answer=false;
	};

	_Cookie_ran=true;
	//document.cookie = "browser_test_cookie=" + Cookies_enabled + ";";
	//document.cookie = "browser_test_cookie_value=" + document.getElementById('cookie').innerHTML.replace(/ /g,"+") + ";";

	allow_access();
};

function Test_cookie()
{
	//var
	var Js_post=new postback("/includes/test_cookies_enabled.asp");
	//var

	Js_post.Retrieve();

	return false;
};

function Test_js()
{
	document.getElementById('js').innerHTML="Enabled";
	//document.cookie = "browser_test_js=true;";
	//document.cookie = "browser_test_js_value=Enabled;";

	return true;
};

function Test_screen()
{
	if(screen.width >= 1024 && screen.height >= 768)
		document.getElementById('screen').innerHTML=screen.width + "x" + screen.height;
	else
		document.getElementById('screen').innerHTML="<font color=#ff0000><b>" + screen.width + "x" + screen.height + "</b></font>";

	//document.cookie = "browser_test_screen=" + (screen.width >= 1024 && screen.height >= 768) + ";";
	//document.cookie = "browser_test_screen_value=" + document.getElementById('screen').innerHTML.replace(/ /g,"+") + ";";

	return (screen.width >= 1024 && screen.height >= 768);
};

function Test_spyware()
{
	//var
	var User_agent = navigator.userAgent.toLowerCase();
	//User_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; FunWebProducts; .NET CLR 1.1.4322)".toLowerCase();
	//User_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705; Alexa Toolbar; .NET CLR 1.1.4322)".toLowerCase();
	//User_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Hotbar 4.5.0.0; .NET CLR 1.1.4322)".toLowerCase();
	//User_agent="Mozilla/4.0 (compatible; MSIE 6.0; AOL 9.0; Windows NT 5.1; acc=ventura5; acc=none; .NET CLR 1.1.4322)".toLowerCase();
	//User_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SpamBlockerUtility 4.7.1)".toLowerCase();
	//User_agent="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; iebar; acc=)".toLowerCase();
	var Is_spyware = (User_agent.indexOf("funwebproducts") != -1) || 
		(User_agent.indexOf("alexa") != -1) || 
		(User_agent.indexOf("hotbar") != -1) || 
		(User_agent.indexOf("hbtools") != -1) || 
		(User_agent.indexOf("askbar") != -1) || 
		(User_agent.indexOf("crazy") != -1) || 
		(User_agent.indexOf("coolsearch") != -1) || 
		(User_agent.indexOf("isearch") != -1) || 
		(User_agent.indexOf("websearch") != -1) || 
		(User_agent.indexOf("peoplepal") != -1) || 
		(User_agent.indexOf("total Search") != -1);
        //var

        if(Is_spyware)
		document.getElementById('spyware').innerHTML="Spyware:&nbsp;&nbsp;<font color=#ff0000><b>Detected</b></font>&nbsp;&nbsp;<a href=http://www.microsoft.com/athome/security/protect/windowsxpsp2/antispy.mspx target=_blank style='color:#0054A6;'><b>Info</b></a></br>";
	else
		document.getElementById('spyware').innerHTML="";

	//document.cookie = "browser_test_spyware=" + Is_spyware + ";";
	//document.cookie = "browser_test_spyware_value=" + document.getElementById('spyware').innerHTML.replace(/ /g,"+").replace(/&nbsp;/g,"+") + ";";
	
        return Is_spyware;
};

function Set_time(DateTime)
{
	_Server_time=new Date(DateTime);
};

function Test_time()
{
	//var
	var Client_time = new Date();
	var Answer = (Math.abs(Client_time.getTime()-_Server_time.getTime())>4000000);
	//var
	
	if(Answer)
		document.getElementById('datetime').innerHTML="System Date/Time:&nbsp;&nbsp;<font color=#ff0000><b>Incorrect</b></font>&nbsp;&nbsp;<a href='moreinfo.asp?info=datetime' target=_blank style='color: 0054A6; font-weight: bold'>Info</a></br>";
	else
		document.getElementById('datetime').innerHTML="";
	
	return !Answer;
};

function Test_compliance()
{
	//Don't crash on older browser like Netscape 4 or so.
	if(document.getElementById!=undefined)
	{
		//The "testing..." basically IS the JS test. Otherwise it's default HTML is "failed".
		if(document.getElementById('acrobat')!=null)
			document.getElementById('acrobat').innerHTML="testing...";
		if(document.getElementById('browser')!=null)
			document.getElementById('browser').innerHTML="testing...";
		if(document.getElementById('cookie')!=null)
			document.getElementById('cookie').innerHTML="testing...";
		if(document.getElementById('js')!=null)
			document.getElementById('js').innerHTML="testing...";
		if(document.getElementById('screen')!=null)
			document.getElementById('screen').innerHTML="testing...";
//		if(document.getElementById('spyware')!=null)
//			document.getElementById('spyware').innerHTML="testing...";
//		if(document.getElementById('datetime')!=null)
//			document.getElementById('datetime').innerHTML="testing...";
	
		//I normally init the vars in the decarations, but wanted to specifically
		//show the "testing..." incase something was taking longer.
		if(document.getElementById('acrobat')!=null)
			_Acrobat_answer=Test_acrobat();
		if(document.getElementById('browser')!=null)
			_Browser_answer=Test_browser();
		if(document.getElementById('cookie')!=null)
			_Cookie_answer=Test_cookie();
		if(document.getElementById('js')!=null)
			_Js_answer=Test_js();
		if(document.getElementById('screen')!=null)
			_Screen_answer=Test_screen();
		if(document.getElementById('spyware')!=null)
			_Spyware_answer=Test_spyware();
		if(document.getElementById('datetime')!=null)
			_Time_answer=Test_time();
	
		allow_access();
	};
};

function allow_access()
{
	if(_Cookie_ran)
	{
		if(_Browser_answer && _Cookie_answer && _Js_answer && _Time_answer)
		{
			if(document.systemlogin!=undefined)
			{
//				document.systemlogin.szLoginName.disabled=false;
//				document.systemlogin.szLoginPassword.disabled=false;
//				document.getElementById("image1").disabled=false;
				if(document.getElementById('loginmessage')!=null)
					document.getElementById('loginmessage').innerHTML='Welcome to SunshineMLS.com, a collaborative project put together by the REALTOR&reg; Boards of Southwest Florida. To login, supply your login name and password. If you are not a participant of the Bonita-Estero or Naples Multiple Listing Services, you will not be able to access this system.';
			if(document.getElementById('loginarea')!=null)
				document.getElementById('loginarea').style.visibility='visible';
				Set_load_focus();
			};
		}else{
//			alert(document.getElementById('loginarea').style.visibility);
			if(document.getElementById('loginarea')!=null)
				document.getElementById('loginarea').style.visibility='hidden';
			if(document.getElementById('loginmessage')!=null)
				document.getElementById('loginmessage').innerHTML='<b>We are sorry, but your system does not meet the minimum requirements set by the SunshineMLS System Operations and Design Committee. Please take a look at the Browser Test results in the left panel and click on the "Info" link next to the red text. Follow the instructions and you will be able to access the system.</b>';
		};
	};
};