// -------------------------------------------------------------
// cross-browser helper functions
// -------------------------------------------------------------

// Main iitialization of util functions which need to run at startup

var browser = new browserDetect();

// return IE4+ or W3C DOM reference for an ID - Basically increases compatability between browsers to reference ID = "myName"  type tags

function getObject(obj) {
	var theObj
	if (document.getElementById) {
		if (typeof obj == 'string') {return document.getElementById(obj)}
		 else {return obj.style}
		 }
	if (document.all) {
		if (typeof obj == 'string') {return document.all(obj)}
		else {return obj.style}
		}
	return null
	}

// Detects various modern browsers else browser is "old", also detect OS, in future will detect Flash etc

function browserDetect()
{
	this.name = 'old'
	this.version = 0
	this.os = 'na'
	this.flash = 0
	
	var ua = navigator.userAgent.toLowerCase();
	this.version = parseFloat(navigator.appVersion)

	// Detect browser name and version

	
	if (detect('msie'))	
		{
		this.name = 'explorer'
		if (document.all && !document.fireEvent && !window.opera) this.version=5
		if (document.all && document.fireEvent && !document.createComment && !window.opera) this.version=5.5
		if (document.all && document.fireEvent && document.createComment && (this.version < 6)) this.version=6
		if (this.version < 5) this.name = 'old'		
		}	
	
	if (detect('safari'))
		{
		this.name = 'safari'
		this.version = parseFloat( ua.substring( ua.lastIndexOf('safari/') + 7 ) )
		}

	if (detect('netscape'))
		{
		this.name = 'netscape'
		this.version = parseFloat( ua.substring( ua.lastIndexOf('netscape/') + 9 ) )
		if (this.version < 6) this.name = 'old'
		}
	
	if (((ua.indexOf('gecko') != -1 && ua.indexOf('safari') == -1) && (ua.indexOf('gecko/') + 14 == ua.length)) && window.controllers)
		{
		this.name = 'mozilla'
		this.version = parseFloat( ua.substring( ua.indexOf('rv:') + 3 ) )
		if (this.version < 1.5) this.name = 'old'
		}
	
	if (detect('firefox'))
		{
		this.name = 'firefox'
		}
	
	if (detect('opera'))
		{
		this.name = 'opera'
		this.version = parseFloat( ua.substring( ua.indexOf('opera') + 6 ) )
		if (!document.createComment && window.opera) this.version = 6
		if (!document.createComment && window.opera && this.version < 7) this.version = 7
		if (this.version < 6) this.name = 'old'
		}
	
	// detect platform
	
	if (ua.indexOf('win') != -1) this.os = 'win'
	if ((this.os == 'win') && (( ua.indexOf('95') != -1 || ua.indexOf('98') != -1 || ua.indexOf('nt') != -1 || ua.indexOf('win32') != -1 || ua.indexOf('32bit') != -1 || ua.indexOf('xp') != -1)) ) this.os = 'win32'
	if (ua.indexOf('mac') != -1) this.os = 'mac'
	if (ua.indexOf('unix') != -1 || ua.indexOf('sunos') != -1 || ua.indexOf('bsd') != -1 || ua.indexOf('x11') != -1) this.os = 'unix'
	if (ua.indexOf('linux') != -1) this.os = 'linux'

	function detect(text)
		{
 		stringposition = ua.indexOf(text) + 1;
 		data = text;
		return stringposition;
		}


}


// Function checks for connection type either modem, lan or undefined

function Bandwidth()
{
	if( readIEVer() < 5.0 || isOpera || navigator.appVersion.toLowerCase().indexOf("win") == -1 )
	{
		return "NA";
	}
	
	document.body.addBehavior ("#default#clientCaps");
	
	if ( typeof( document.body.connectionType) != "undefined"  ) 
	{
		if ( document.body.connectionType == "modem" )
		{
			return "Modem";
		}
		return "Lan";
	}

}


// Add a BookMark

function addBookMark()
{
	if ( window.external ) 
		{
			window.external.AddFavorite( document.location.href,document.title );
		} 
		else 
		{
			alert( "Sorry, your browser doesn't support bookmarking this page...\n\nPlease try pressing Control + D instead" );
		}
}




// Find absolute position of an object

  function findPosX(obj)
  {
    var curleft = 0;
    if(obj.offsetParent)
        while(1) 
        {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.x)
        curleft += obj.x;
    return curleft;
  }

  function findPosY(obj)
  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
  }

// Draw inline image - correctly handles alpha transparent .png for IE 5.5 and up.

function drawImg(sourceImg,widthImg,heightImg)
	{
	var strImg = ''
	var pngChk = sourceImg.toLowerCase()
	if (pngChk.indexOf('png') != -1)
		{
		strImg = '<span style=\"width:1px;height:1px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + sourceImg;
		strImg += '\',sizingMethod=\'scale\');\">'
		strImg += '<img style=\"filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);\" src=\"' + sourceImg;
		strImg += '\" width=\"' + widthImg + '\" height=\"' + heightImg + '\" border=\"0\" alt=\"\"></span>';

		}
	else strImg = '<img src=\"'+sourceImg+'\" width=\"'+widthImg+'\" height=\"'+heightImg+'\" border=\"0\" alt=\"\">'
	document.write (strImg)
	}
	
// Positional draw image

function posImg(sourceImg,xImg,yImg,wImg,hImg)
	{
	document.write ('<div style="position: absolute; left: '+xImg+'px; top: '+yImg+'px;">')
	drawImg (sourceImg,wImg,hImg)
	document.write ('</div>')
	}

// Draw Box

function drawBox(sourceImg,xBox,yBox,wBox,hBox)
	{
	if (wBox<25) wBox = 25
	if (hBox<25) hBox = 25
	if (browser.name != 'old' && (browser.name != 'explorer' || browser.version >= 5.5))
		{
		document.write ('<div style="position: absolute; left: '+xBox+'px; top: '+yBox+'px;">')
		drawImg(sourceImg+'01.png',11,11);drawImg(sourceImg+'02.png',wBox-24,11);drawImg(sourceImg+'04.png',13,11)
		document.write ('<div>')
		drawImg(sourceImg+'05.png',4,hBox-24);drawImg(sourceImg+'07.png',wBox-10,hBox-24);drawImg(sourceImg+'09.png',6,hBox-24)
		document.write ('<div>')
		drawImg(sourceImg+'13.png',11,13);drawImg(sourceImg+'14.png',wBox-24,13);drawImg(sourceImg+'15.png',13,13)
		document.write ('</div></div></div>')
		}
	else posImg(sourceImg+'06.png',xBox+4,yBox+4,wBox-10,hBox-10)
	}	

// Draw Inline Box

function drawInBox(sourceImg,wBox,hBox,boxHTML)
	{
	if (wBox<25) wBox = 25
	if (hBox<25) hBox = 25
//	if (browser.name != 'old' && (browser.name != 'explorer' || browser.version >= 5.5))
//		{

		drawImg(sourceImg+'01.png',11,11);drawImg(sourceImg+'02.png',wBox-24,11);drawImg(sourceImg+'04.png',13,11)
		
	if (browser.name == 'explorer')
		{
		document.write ('<div style="position: relative">')
		drawImg(sourceImg+'05.png',4,hBox-24);drawImg(sourceImg+'07.png',wBox-10,hBox-24);drawImg(sourceImg+'09.png',6,hBox-24)		
		document.write ('<div style=\"position: absolute; left:4px; top:0px; width:'+(wBox-10)+'px;\">'+boxHTML+'</div><div>')
		drawImg(sourceImg+'13.png',11,13);drawImg(sourceImg+'14.png',wBox-24,13);drawImg(sourceImg+'15.png',13,13)
		document.write ('</div>')	
		}
	else
		{

	
		document.write ('<table border="0" cellpadding="0" cellspacing="0">')
		document.write ('<tr><td width="4" style="background-image: url(../imgs/bxGlass_05.png);background-repeat: repeat-y;">&nbsp;</td><td>')
		

		
		document.write ('<div style=\"width:'+(wBox-10)+'px;\">'+boxHTML+'</div></td></tr></table>')

		document.write ('<div>')
		drawImg(sourceImg+'13.png',11,13);drawImg(sourceImg+'14.png',wBox-24,13);drawImg(sourceImg+'15.png',13,13)
		document.write ('</div>')	

		}
//	else posImg(sourceImg+'06.png',xBox+4,yBox+4,wBox-10,hBox-10)
	}	





// Reload the 'contentFrame' frame on the main (parent) page

function loadContent(srcFile)
	{
//	parent.getObject('contentFrame').src=srcFile
	parent.location.href = srcFile;
	}


// Look for change in size of browser window


function detectPageSizeInit()
{
	oldPageBot = findPosY (getObject('pageBottom'))
	setTimeout( "detectPageSize(oldPageBot)", 300)
}

function detectPageSize(oldPageBot)
{
	if (oldPageBot != findPosY (getObject('pageBottom'))) loadContent(reloadPage)
	setTimeout( "detectPageSize(oldPageBot)", 300)
}	
	

	
