/* marshpublic.js */

function checkButton(mode) {
    if (mode == "ON")
        document.buttonForm.preview[0].checked = true;
    else document.buttonForm.preview[1].checked = true;
}

//MMC stock price in left menu
function winOpen(url) {
    windowName = window.open(url);
    windowName.focus();
}

//site guide
function verifySelectedValue(theValue){
    if (theValue == "void")
	return;
    top.location = theValue;	
}

//site guide
function getImage(s) { 
    i = 1000 + s;
    if (i == 1003 || i > 1004 && i < 1032 || i == 1033 || i == 1034 || i > 1038 && i < 1043  || i > 1043 && i < 1063 || i == 1065)
        document.siteguide.info.src= "./appsitelayoutres/spacer.gif";
    else 
        document.siteguide.info.src= "./appsitelayoutres/sg_" + i + ".gif";
}


//Milind.Joshi@lnt <24/08/2004> starts here 
//Detect the visitor's browser/version.
//If he is using the browser older than the recommended i.e. IE5.0.1 and Netscape 4.77 then
//inform the visitor with the appopriate message.
var detect = navigator.userAgent.toLowerCase();
var theString,count;
function getBrowserDetails()
{
	document.frmBrowserVersion.hidPopupOnce.value = "";
	var OS,browser,version;
	if(checkIt('konqueror'))
	{
		browser = "Konqueror";
		OS		= "Linux";
	}
	else if(checkIt('safari'))
	{
		browser = "Safari";
	}
	else if(checkIt('omniweb'))
	{
		browser = "OmniWeb";
	}
	else if(checkIt('opera'))
	{
		browser = "Opera";
	}
	else if(checkIt('webtv'))
	{
		browser = "WebTV";
	}
	else if(checkIt('icab'))
	{
		browser = "iCab";
	}
	else if(checkIt('msie'))
	{
		browser = "Internet Explorer";
	}
	else if(!checkIt('compatible'))
	{
		browser = "Netscape Navigator";
		version = detect.charAt(8);
	}
	else
	{
		browser = "An unknown browser";
	}

	if(!version)
	{
		version = detect.charAt(place + theString.length);
	}

	if(!OS)
	{
		if(checkIt('linux'))
		{
			OS = "Linux";
		}
		else if(checkIt('x11'))
		{
			OS = "Unix";
		}
		else if(checkIt('mac'))
		{
			OS = "Mac";
		}
		else if(checkIt('win'))
		{
			OS = "Windows";
		}
		else
		{
			OS = "an unknown operating system";
		}
	}

	if((browser == "Internet Explorer" && floatVersion(version) < floatVersion("5.0.1")) || (browser == "Netscape Navigator" && floatVersion(version) < parseFloat("4.77")))
	{
		checkCount(browser, version);
	}
}

function floatVersion(version) {
 	var str = version;
 	while (str.indexOf(".", 2) != -1)  {
 		str = str.substring(0,str.indexOf(".", 2)).concat(str.substring(str.indexOf(".", 2) + 1));
 	 }
	 return (parseFloat(str));
}


function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	theString = string;
	return place;
}

var expDays = 1; // number of days the cookie should last
function GetCookie(name)
{  
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while(i < clen)
	{    
		var j = i + alen;    
		if(document.cookie.substring(i, j) == arg)      
			return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}

function SetCookie(name, value)
{  
	var argv = SetCookie.arguments;  
	var argc = SetCookie.arguments.length;  
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape (value) + 
	((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
	((path == null) ? "" : ("; path=" + path)) +  
	((domain == null) ? "" : ("; domain=" + domain)) +    
	((secure == true) ? "; secure" : "");
}

function DeleteCookie(name)
{  
	var exp = new Date();  
	exp.setTime (exp.getTime() - 1);  
	var cval = GetCookie (name);  
	document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
function amt()
{
	var count = GetCookie('count')
	if(count == null)
	{
		SetCookie('count','1')
		return 1
	}
	else
	{
		//var newcount = parseInt(count) + 1;
		//DeleteCookie('count')
		var newcount = parseInt(count);
		SetCookie('count',newcount,exp)
		return count
	}
}

function getCookieVal(offset)
{
	var endstr = document.cookie.indexOf (";", offset);
	if(endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function checkCount(browser, version)
{
	count = GetCookie('count');
	if(isNaN(count))
	{
		count = 2;
	}

	if(count == null || count > 1)
	{
		//It opens a new window. If the user clicks on the check box then the alert will not be displayed afterwards.
		document.frmBrowserVersion.hidBrowser.value = browser;
		document.frmBrowserVersion.hidVersion.value = version;
		if(count == null || isNaN(count))
		{
			count=2;
		}
		window.open('./appsitelayoutres/only-popup-once.html?browser='+browser+"&version="+version,'','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=550,height=150,left=150,top=200');
		if(document.frmBrowserVersion.hidPopupOnce.value != "" || document.frmBrowserVersion.hidPopupOnce.value != null || document.frmBrowserVersion.hidPopupOnce.value != "undefined")
		{
			if(document.frmBrowserVersion.hidPopupOnce.value == "Y")
			{
				count = 1;
				expDays = 1;
			}
			else if(document.frmBrowserVersion.hidPopupOnce.value == "N")
			{
				count++; 
				expDays = 0;
			}
		}
		exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
		SetCookie('count', count, exp);
	}
	else
	{
		if(count == null || isNaN(count))
		{
			count = 2;
		}
		else if(count != 1)
		{
			count++;
		}
		expDays=1;
		exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
		SetCookie('count', count, exp);
	}
}

function reCheckCount()
{
	count = GetCookie('count');
	if(isNaN(count))
	{
		count = 2 ;
	}

	if(count != 1)
	{
		if(document.frmBrowserVersion.hidPopupOnce.value == "Y")
		{
			count = 1;
		}
	}
	exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
	SetCookie('count', count, exp);
}
//Milind.Joshi@lnt <24/08/2004> ends here