
//builds banner name from page name
function fnGetBanner(){
	try{
		var sPath = window.location.pathname;
		//past the last slash like "products.php"
		var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
		//before the last dot like "products"
		sPage = sPage.substring(0, sPage.indexOf('.'));
		document.images["bannerImg"].src = "yieldrm/images/banner_" + sPage + ".gif";
	}catch(er){
		//alert(er.description);//do nothing
	}
}





//try's to load log-in info from cookies
function fnLoadLogIn(){
	try{
		theFrm = document.forms[0];
		var theId = readCookie("1sU");
			if(theId == null || theId == "NONE") theId = "";
		var thePass = readCookie("1sP");
			if(thePass == null || thePass == "NONE") thePass = "";
		theFrm.userI.value = theId;
		theFrm.userP.value = thePass;
		if(theId != "" && thePass != ""){
			theFrm.remember.checked = true;
		}
	}catch(er){
		//do nothing
	}
}
//cookie functions
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
//end cookie's


//rotate banner. start by calling fnStartRotate(); 
var bannerDir = "yieldrm/images/"; //directory with banners
var bannerCnt = 8; //how many banners in directory
var currBannerIndex = 0;
var rotateTmr = 0;
function fnRandNum(){
	return Math.round(bannerCnt*Math.random())
}
function fnStartRotate(){
	//changes directory as needed for images
	currBannerIndex = fnRandNum();
	var sPath = window.location.pathname;
	if(sPath.indexOf('/pages') > 0){
		document.getElementById("banner").style.backgroundImage = "url('../images/banner_" + currBannerIndex + ".png')";
	}else{
		document.getElementById("banner").style.backgroundImage = "url('yieldrm/images/banner_" + currBannerIndex + ".png')";
	}
	//rotateTmr = setTimeout("fnRotateBanner()", 20000);
}
function fnEndRotate(){
	clearTimeout (rotateTmr);
}
function fnRotateBanner(){
	var sPath = window.location.pathname;
	if(sPath.indexOf('/pages') > 0){
		document.getElementById("banner").style.backgroundImage = "url('../images/banner_" + currBannerIndex + ".png')";
	}else{
		document.getElementById("banner").style.backgroundImage = "url('yieldrm/images/banner_" + currBannerIndex + ".png')";
	}
	fnStartRotate();
}
//end rotate banner

//#############################################################
//set "galleryimg="no" attribute to prevent img toolbar
try{
	var g;
	for(g = 0; g < document.images.length; g++){
		document.images[g].setAttribute("galleryimg", "no");
		document.images[g].setAttribute("tabindex", "-1");
	}
}catch(e){
	//don't handle error
	alert(e.message);
}
//#############################################################

//#############################################################
//top and left locations of elements
function getRealTop(el) {
    yPos = el.offsetTop;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        yPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }
    return yPos;
}
function getRealLeft(el) {
    xPos = el.offsetLeft;
    tempEl = el.offsetParent;
    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }
    return xPos;
}
//#############################################################

//#############################################################
//highlights tool





//#############################################################
//disables all buttons on the page
function fnDisableButtons(theDoc){
	try{
		//need to determine if we have a parent or what?
		
		var theForm = theDoc.document.forms[0];
		for(var i = 0; i < theForm.elements.length; i++){
			if(theForm.elements[i].type == "button") theForm.elements[i].disabled = true;
		}
	}catch(er){
		alert(er.description);
	}
}
//enables all buttons of the page
function fnEnableButtons(theDoc){
	try{
		var theForm = theDoc.document.forms[0];
		for(var i = 0; i < theForm.elements.length; i++){
			if(theForm.elements[i].type == "button") theForm.elements[i].disabled = false;
		}
	}catch(er){
		alert(er.description);
	}
}

//#############################################################



//opens window
var myWindow; //tracks open window
function fnNewWin(thePageToLoad, iLeft, iTop, theHeight, theWidth, showStatusYesOrNo, resizableYesOrNo){
	try{
		iLeft = typeof(iLeft) != 'undefined' ? iLeft : 25;   
  		iTop = typeof(iTop) != 'undefined' ? iTop : 25; 
  		theHeight = typeof(theHeight) != 'undefined' ? theHeight : getWindowHeight() - 50; 
  		theWidth = typeof(theWidth) != 'undefined' ? theWidth : getWindowWidth() - 50; 
  		showStatusYesOrNo = typeof(showStatusYesOrNo) != 'undefined' ? showStatusYesOrNo : 'yes'; 
  		resizableYesOrNo = typeof(resizableYesOrNo) != 'undefined' ? resizableYesOrNo : 'yes'; 

		//center the window
		iLeft = (getWindowWidth() / 2) - (theWidth / 2);
		iTop = (getWindowHeight() / 2) - (theHeight / 2);
  

		var d = new Date();
		var uid = d.getSeconds();
		var append = "";
		var pos = thePageToLoad.indexOf("?");
		if(pos < 0){
			append = "?";
		}else{
			append = "&";
		}
	if(thePageToLoad != ""){
		//if window was already opened..set it to null
		myWindow = window.open(thePageToLoad + append + "u4565677445611=" + uid, 'myWindow', 'directories=no, left=' + iLeft + ', top=' + iTop +', height=' + theHeight + ', width=' + theWidth + ', location=no, menubar=no, resizable=' + resizableYesOrNo + ', scrollbars=yes, status=' + showStatusYesOrNo + ', toolbar=no');
		myWindow.focus();
	}	
	}catch(er){
		alert(er.description);
	}
}

//isEven, isOdd
function isEven(x){return (x%2)?false:true;}
function isOdd(x){return !isEven(x);}

// gets mouse position.
function getMouseX(e){
    return event.clientX + document.body.scrollLeft
}
function getMouseY(e){
    return event.clientY + document.body.scrollTop
}

/* SHOW TIMER STUFF
################################################################## */
var	timerID = null
var	timerRunning = false
var	startDate
var	startSecs
function stopClock(){
	if(timerRunning)
		clearTimeout(timerID)
		timerRunning = false
}
function startClock(){
	startDate = new Date()
	startSecs = (startDate.getHours()*60*60) + (startDate.getMinutes()*60) 
						+ startDate.getSeconds()
	stopClock()
	showTime()

}
function showTime(){
	// this doesn't work correctly at midnight...
	var now = new Date()
	var nowSecs = (now.getHours()*60*60) + (now.getMinutes()*60) + now.getSeconds()
	var elapsedSecs = nowSecs - startSecs;
	var hours = Math.floor( elapsedSecs / 3600 )
	elapsedSecs = elapsedSecs - (hours*3600)
	var minutes = 	Math.floor( elapsedSecs / 60 )
	elapsedSecs = elapsedSecs - (minutes*60)
	var seconds = elapsedSecs
	var timeValue = "" + hours
	timeValue  += ((minutes < 10) ? ":0" : ":") + minutes
	timeValue  += ((seconds < 10) ? ":0" : ":") + seconds
	// Update display
	document.getElementById('timerSpan').innerHTML = timeValue 
	timerID = setTimeout("showTime()",1000)
	timerRunning = true
}
/* END SHOW TIMER
/#####################################################################################*/


//check all
function fnCheckAll(theDocument){
	var frm = null; 
	frm = theDocument.document.forms[0];
	var onOff = frm.checkAll.checked;
	for(i=0;i<frm.elements.length;i++){
		if(frm.elements[i].type == 'checkbox'){
			frm.elements[i].checked = onOff;
		}
	}
}



//determines available height
function getWindowHeight(){
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return myHeight;
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
}

//determines available width
function getWindowWidth(){
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement &&
      ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return myWidth;
  //window.alert( 'Width = ' + myWidth );
  //window.alert( 'Height = ' + myHeight );
}

//#####################################################################################*/
//embeds flash
function fnWriteFlash(id, width, height, url){
	document.write("<OBJECT classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' ");
	document.write("WIDTH='" + width + "' HEIGHT='" + height + "' id='" + id + "'>");
	document.write("<PARAM NAME=movie VALUE='" + url + "')>");
	document.write("<PARAM NAME=quality VALUE=high>");
	document.write("<PARAM NAME=bgcolor VALUE=#FFFFFF>");
	document.write("<EMBED src='" + url + "'");
	document.write("quality=high bgcolor=#FFFFFF WIDTH='" + width + "' HEIGHT='" + height + "' NAME='" + id + "'");
	document.write("TYPE='application/x-shockwave-flash' PLUGINSPAGE='http://www.macromedia.com/go/getflashplayer'>");
	document.write("</EMBED>");
	document.write("</OBJECT>");					
}
//#####################################################################################*/








