/***************************************/
/*		Declare Global Variables	   */
/***************************************/
// doDOMDetect() variables.
var documentall = null;
var macIEDetect = null;
var domDetect = null;

// showFlash() variables.
var objlist = new Array();
var target = null;
var timer = null;

/***************************************/
/*		Image Rollover Functions	   */
/***************************************/
function MM_preloadImages() { //v3.0
	var d=document;
	if( d.images ) {
		if(!d.MM_p) d.MM_p = new Array();
		var i, j = d.MM_p.length, a = MM_preloadImages.arguments;
		for( i=0; i<a.length; i++ ) {
			if( a[i].indexOf("#") != 0 ) {
				d.MM_p[j] = new Image;
				d.MM_p[j++].src = a[i];
			}
		}
	}
}

function MM_swapImgRestore() { //v3.0
	var i, x, a = document.MM_sr;
	for( i=0; a&&i<a.length&&(x=a[i])&&x.oSrc; i++ ) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
	var p, i, x;
	if(!d) d=document;
	if( (p=n.indexOf("?") ) > 0 && parent.frames.length) {
		d=parent.frames[n.substring(p+1)].document;
		n=n.substring(0,p);
	}
	if( !(x=d[n]) && d.all ) x = d.all[n];
	for( i=0; !x && i<d.forms.length; i++ ) x = d.forms[i][n];
	for( i=0; !x && d.layers && i<d.layers.length; i++ ) x = MM_findObj(n,d.layers[i].document);
	if( !x && d.getElementById ) x = d.getElementById(n);
	return x;
}

function MM_swapImage() { //v3.0
	var i, j = 0, x, a = MM_swapImage.arguments;
	document.MM_sr = new Array;
	for( i=0; i<(a.length-2); i+=3) {
		if( (x=MM_findObj(a[i])) != null ) {
			document.MM_sr[j++] = x;
			if( !x.oSrc ) x.oSrc = x.src;
			x.src = a[i+2];
		}
	}
}

/***************************************/
/*			Misc Functions			   */
/***************************************/
function doDOMDetect( obj ) {	// Detect the DOM.
	if ( document.all ) {
		documentall = true;
	} else {
		documentall = false;
	}
	
	if ( navigator.appVersion.indexOf('Mac') != -1 &&
		(document.all) ) {
		macIEDetect = true;
	}
	
	if ( obj ) {
		if ( typeof( window.opera ) == 'undefined' &&
			typeof( obj.getAttribute ) != 'undefined') {
			domDetect = true;
		} else {
			domDetect = false;
		}
	}
}

function findElement( id ) {	// Locate an element by ID based on type of DOM.
	if ( domDetect == true ) {
		obj = document.getElementById( id );
	} else {
		if ( documentall ) {
			obj = eval( 'document.all.' + id );
		} else {
			obj = eval( 'document.' + id );
		}
	}
	
	return obj;
}

// Returns the width and height of the client browser.
function getClientDims() {
	var width = 0, height = 0;
	if( document.all ) {
		width = document.body.clientWidth
		height = document.body.clientHeight
	} else {
		width = window.innerWidth
		height = window.innerHeight
	}
	return [ width, height ]
}

// Returns the X and Y position of the viewport on a page.
function getScrollXY() {
	var scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
	return [ scrOfX, scrOfY ];
}

// Open a popup window.
function popup( url, name, width, height, extras ) {
	var options = "width=" + width + ",height=" + height + ",innerWidth=" + width + ",innerHeight=" + height;
	
	if( window.screen ) {
		var aw = screen.availWidth - 10;
		var ah = screen.availHeight - 30;
		
		var xc = (aw - width) / 2;
		var yc = (ah - height) / 2;
		
		options += ",left=" + xc + ",screenX=" + xc;
		options += ",top=" + yc + ",screenY=" + yc;
	}
	
	options += "," + extras;
	
	myWin = window.open(url, name, options);
	myWin.focus();
}

// Round a number to a precision.
function rounder( iNumber, iPrecision ) {
	//iNumber = parseFloat( iNumber );
	iPrecision = Math.pow( 10, Math.abs(iPrecision) );
	
	iNumber = Math.round(iNumber * iPrecision) / iPrecision;
	
	return iNumber;
}

// Add zeros to the end of a string/number so that it has 2 digits after the decimal point.
function setCurrency( sValue ) {
	// sValue: 	the value to adjust.
	sValue = sValue.toString();
	
	sBits = sValue.split( "." );
	
	if( sBits.length == 1 ) {
		sValue += ".00";
	} else {
		sValue = sBits[0] + "." + (sBits[1] + "00").substring(0, 2);
	}
	
	return sValue;
}

// Make sure preceeding zeros are in place.
function setFrontZeros( str, num ) {
	str = "zx00000000000000000000000000000000000000" + str;
	
	return str.substr( str.length - num, num )
	//return ( "zx00000000000000000000000000000000000000" + str ).substr( -num )
}
function setZerosFront( sValue, iLength ) {
	var sZeros = "";
	
	iLength -= sValue.toString().length;
	
	for( i=1; i<=iLength; i++ ) {
		sZeros += "0";
	}
	
	return sZeros + sValue;
}

// Display and flash text in a target element.
function showFlash( obj, targetid, text ) {
		if ( domDetect == null ) {
			doDOMDetect( obj );
		}
		
		skip = false;
		for( i=0; i<objlist.length; i++ ) {
			if( objlist[i] == targetid ) skip = true;
		}
		
		if( !skip ) {
			objlist[objlist.length] = targetid;
			
			target = findElement( targetid );
			
			if (target.tagName == 'INPUT') {
				var original_classname = target.className;
				target.className = original_classname + ' Flash1';
				timer = setInterval( "( findElement( '"+targetid+"' ).className ==  '" + original_classname + " Flash1' ) ? findElement( '"+targetid+"' ).className =  '" + original_classname + " Flash2' : findElement( '"+targetid+"' ).className =  '" + original_classname + " Flash1'", 750 );
			} else {
				if( text.replace(" ","") != "" ) target.innerHTML = text;
				timer = setInterval( "( findElement( '"+targetid+"' ).className == 'Flash1' ) ? findElement( '"+targetid+"' ).className = 'Flash2' : findElement( '"+targetid+"' ).className = 'Flash1'", 750 );
			}
		}
}




