var isNav = false;
var isN6 = false;
var isN4 = false;
var isie = false;

var applicationName = (navigator.appName);
var browserVer = parseInt(navigator.appVersion);

if (navigator.appName == "Netscape") {
	isNav = true;
	isN6 = (browserVer>=5)?1:0;
	isN4 = (browserVer >= 4 && browserVer < 5)?1:0;
} else if (navigator.appName == "Microsoft Internet Explorer") {
	isie = true;
}

var layerRef = "";
var styleRef = "";
var visibilityRef = "";
var visibleAtt = "";
var hiddenAtt = "";
var posLeft = "";
var posTop = "";
var posWidth = "";
var posHeight = "";
var posHeight2 = "";

if (document.getElementById) {

	visibilityRef = ".style.visibility";
	
	visibleAtt = "visible";
	
	hiddenAtt = "hidden";
	
	styleRef =".style";
	
	posLeft = ".style.left";
	
	posTop = ".style.top";
 
} else if (document.all) {   			//Microsoft syntax

		layerRef = "document.all";

		styleRef ="document.style";

		visibilityRef = ".style.visibility";

		visibleAtt = "visible";

		hiddenAtt = "hidden";

		posLeft = ".style.pixelLeft";

		posTop = ".style.pixelTop";

		posWidth = ".clientWidth";

		posHeight = ".style.pixelHeight";

       		posHeight2 = ".clientHeight";


} else {    				//Netscape syntax

		layerRef = "document.layers";

		styleRef ="";

		visibilityRef = ".visibility";

		visibleAtt = "show";

		hiddenAtt = "hide";

		posLeft = ".left";

		posTop = ".top";

		posWidth = ".clip.width";

		posHeight       = ".clip.height";

        	posHeight2      = ".clip.height";

}

function getObject(objectId) {
	if (document.getElementById) {
		return (document.getElementById(objectId));
	} if (document.all) {
		return (document.all[objectId]);
	} else if (isN4) {
		return (document.layers[objectId]);
	}
}


/*
   The following handles the Netscape 4 bug of loosing the CSS
   formatting that comes from an external file when the user 
   resizes the window.
 */
 var origWidth = null;
 var origHeight = null;
 
 if (isN4) {
 	origWidth = innerWidth;
	origHeight = innerHeight;
 }
 
 function reloadPage() {
 	if (isN4 && (innerWidth != origWidth || innerHeight != origHeight))
	   location.reload(); //reloading the page causes the linked CSS work as it should 
 }
 
 if (isN4) onresize = reloadPage;
 
 
 /*
  */
  function getPageHeight() {
  	if (window.innerHeight != null)
	   return window.innerHeight;   //Netscape
  	if (document.body.clientHeight != null)
	   return document.body.clientHeight;   //IE
  	return (null);
  }
  
  function getPageWidth() {
  	if (window.innerWidth != null)
	   return window.innerWidth;   //Netscape
	if (document.body.clientWidth != null)
	  return document.body.clientWidth;   //IE
  	return (null);
  }
  
  function getObjectWidth(objectId) {
  	var obj = getObject(objectId);
  	
  	if (obj.offsetWidth) {
  		return obj.offsetWidth; //IE 4/5, Net6
  	}
  	if (obj.clip.width) {
  		return obj.clip.width;  //Net4
  	}
  	return (null);
  }
  function getObjectHeight(objectId) {
    	var obj = getObject(objectId);
    	
    	if (obj.offsetHeight) {
    		return obj.offsetHeight; //IE 4/5, Net6
    	}
    	if (obj.clip.height) {
    		return obj.clip.height;  //Net4
    	}
    	return (null);
  }
  function setObjLeft(obj, leftValue) {
  	if (isN6) {
  	//if (obj.offsetLeft) {  //Net6
  		obj.offsetLeft = leftValue;
  	}
  	if (isie) {
  		obj.style.pixelLeft = leftValue;
  	}
  	if (isN4) {
  		obj.style.left = leftValue;
  	}
  }
  function setObjTop(obj, topValue) {
  	if (isN6) {
	//if (obj.offsetLeft) {  //Net6
		obj.offsetTop = topValue;
	}
	if (isie) {
		obj.style.pixelTop = topValue;
	}
	if (isN4) {
		obj.style.top = topValue;
  	}
  }
  
// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//configure tickercontents[] to set the messges you wish be displayed (HTML codes accepted)
var tickercontents=new Array()
tickercontents[0]='All business is done according to the Company&acute;s terms and conditions,'
tickercontents[1]='copies of which are available upon request.'
tickercontents[2]='Before using this site you should'
tickercontents[3]='Read the <a href="terms.php" class="bottomLink">Responsibility Statement</a>.'

//specify how many characters of a message (for each msg) to show in expanded menu:
var charslimit=150

//Below specifies the "expand text". Do not remove onClick=".." portion.
var expandtext='<a href="#" onClick="dropdownit(event);return false">Expand</a> <img src="tridown.gif" border=0>'

//configure below variables to set dimensions and main color of the ticker
var tickerwidth='450px'
var tickerheight='15px' //not including "Expand" text

//configure the below variable to determine the delay between ticking of messages (in miliseconds)
var tickdelay=2500

////Do not edit pass this line////////////////

var ie4=document.all || navigator.userAgent.search(/opera.7/i)!=-1 //lump Opera 7 with IE
var ns6=document.getElementById && !document.all && !window.opera
var ns4=document.layers

if (isN4){
	expandtext=expandtext.replace(/dropdownit\(event\); *return false/gi, "return dropdownitNS4(event,this)")
	tickerheightNS4=parseInt(tickerheight)+19
	tickerlistheightNS4=tickerheight
}

var currentmessage=0
var tickercontentstotal=''

function rotatecontent(){
	if (isN4){ //OUTPUT HTML for ticker area for NS4
		tickerobj.document.tickernssub.document.write(tickercontents[currentmessage]+'')
		tickerobj.document.tickernssub.document.close()
	} else if (ie4||ns6) {
		tickerobj.innerHTML=tickercontents[currentmessage]
		previousmessage=(currentmessage==0)? tickercontents.length-1 : currentmessage-1
		//tickerexpand_item=ns6? document.getElementById("expand"+currentmessage) : eval("expand"+currentmessage)
		//tickerexpand_previousitem=ns6? document.getElementById("expand"+previousmessage) : eval("expand"+previousmessage)
		//tickerexpand_previousitem.className=""
		//tickerexpand_item.className="expandmenu_highlight"
	}

	currentmessage=(currentmessage==tickercontents.length-1)? 0 : currentmessage+1
	rotatemsgtimer=setTimeout("rotatecontent()",tickdelay)
}

function dropdownit(e){
	if (ns6) e.stopPropagation()
	else e.cancelBubble=true
	tickerexpandobj.style.visibility=tickerexpandobj.style.visibility=="hidden"? "visible" : "hidden"
	expandbuttonLeft=ns6? e.pageX-e.layerX : document.body.scrollLeft+event.clientX-event.offsetX
	expandbuttonTop=ns6? e.pageY-e.layerY : document.body.scrollTop+event.clientY-event.offsetY
	tickerexpandobj.style.left=expandbuttonLeft+"px"
	tickerexpandobj.style.top=expandbuttonTop+expandbuttonobj.offsetHeight-3+"px"
}

function dropdownitNS4(e, currentobj){
	tickerexpandobj.left=tickerobj.pageX
	tickerexpandobj.top=tickerobj.pageY+parseInt(tickerlistheightNS4)+tickerobj.document.expandbuttonNS4.document.height
	tickerexpandobj.visibility=(tickerexpandobj.visibility=="hide")? "show" : "hide"
	return false
}

function jumptomsg(whichmsg){
	clearTimeout(rotatemsgtimer)
	if (ie4||ns6)
		tickerexpand_item.className=""
	currentmessage=whichmsg
	rotatecontent()
}

function initialize_ticker() {
	if (isN4) document.tickernsmain.visibility="show"
	tickerobj=ie4? tickerlist : ns6? document.getElementById("tickerlist") : isN4? document.tickernsmain : ""

	for (i=0;i<tickercontents.length;i++){ //get total scroller contents
		tempstringcontainer=tickercontents[i].replace(/\<[^\>]+\>/g, ''); //remove HTML tags
		tickercontentstotal+='<div id="expand'+i+'">- <a href="javascript:jumptomsg('+i+')">'+tempstringcontainer.substring(0, charslimit)+'...</a></div>'
	}

	rotatecontent()
}
