/* The American Bonanza Society */

//preload images
function preloadImages()
{ 
  var args = preloadImages.arguments;
  document.imageArray = new Array(args.length);
  for(var i=0; i<args.length; i++)
  {
    document.imageArray[i] = new Image;
    document.imageArray[i].src = args[i];
  }
}


//open a new window/file
function openNewWindow(file)
{
  v = window.open(file);
}


//show/hide layer
function toggleDiv(name, visible)
{
	var elem, vis;
	elem = document.getElementById(name);
	vis = elem.style;
	// if the style.display value is blank we try to figure it out here
	if(visible == true)
		vis.display = 'block';
	else
		vis.display = 'none';
}

function setCookie(name, value, expires)
{
	document.cookie = name + '=' + escape(value) + ';' + ' domain=.bonanza.org;' + ' path=/;' + ' expires=' + expires + ';' ;
}

function getCookie(name){
	var cname = name + "=";               
	var dc = document.cookie; 
		 if (dc.length > 0) {
		 	var begin = dc.indexOf(cname);       
			  if (begin != -1) {           
			  begin += cname.length;       
			  end = dc.indexOf(";", begin);
					if (end == -1) end = dc.length;
					return unescape(dc.substring(begin,end));
			  } 
		 }
	return null;
}



function delCookie(name) {
	document.cookie = name + '=;' + ' domain=.bonanza.org;' + ' path=/;' + ' expires=Thu, 01-Jan-70 00:00:01 GMT;';
}

function checkCookieSettings () {
	if (document.getElementById("saveCredentials").checked == true)
	{
		if (document.getElementById("txtUsername").value != '' && document.getElementById("txtPassword").value != '')
		{
			setCookie('webUsername', document.getElementById("txtUsername").value, 'Thu, 01 January 2020 00:00:01 GMT');
			setCookie('webPassword', document.getElementById("txtPassword").value, 'Thu, 01 January 2020 00:00:01 GMT');
		}
	}
	else
	{
		delCookie('webUsername');
		delCookie('webPassword');
	}
}

//delete this after implimentation of login()
function showLogin()
{
	toggleDiv('login', true);
	toggleDiv('guest', false);
	document.quickLogin.txtUsername.focus();
	document.quickLogin.txtUsername.select();
}

function login()
{
	toggleDiv('loginLeft1', false); toggleDiv('loginLeft2', true);
	toggleDiv('loginRight1', false); toggleDiv('loginRight2', true);
	checkCookieSettings();
	document.getElementById('loginRight2').innerHTML = 'Logging<br />into<br />ABS...';
	document.quickLogin.submit();
}
function NewBlueLogin()
{
	if(document.quickLogin && document.quickLogin.txtUsername.value.length > 0 && document.quickLogin.txtPassword.value.length > 0)
	{
		checkCookieSettings();
		toggleDiv('processing', true);
		document.quickLogin.submit();
	}
	else
	{
		window.location.href = 'http://abs-online.bonanza.org/source/Security/member-logon.cfm' + '?originalURL=' + location.href.substring(7);
	}
}
function logout()
{
	toggleDiv('member', false);
	toggleDiv('login', true);
	toggleDiv('loginLeft1', false); toggleDiv('loginLeft2', true);
	toggleDiv('loginRight1', false); toggleDiv('loginRight2', true);
	delCookie('webUsername');delCookie('webPassword');
	document.getElementById('loginRight2').innerHTML = 'Logging<br />out of<br />ABS...';
	window.location.href = 'http://www.bonanza.org/auth/_logoffUser.cfm' + '?originalURL=' + location.href.substring(7);
}
function NewBlueLogout()
{
	delCookie('RememberMe');
	window.location.href = 'http://abs-online.bonanza.org/AsiCommon/Controls/Shared/FormsAuthentication/Logout.aspx';
}

function InStr(strSearch, charSearchFor)
{
	for (i=0; i < strSearch.length; i++)
	{
		if (charSearchFor == Mid(strSearch, i, 1))
		{
			return i;
		}
	}
	return -1;
}

function fullScreen(theURL) {
	window.open(theURL, '', 'fullscreen=yes, scrollbars=auto');
}