/**
 * @author billn
 */

/****
 * Shows the loading bar in the login form on the sidebar.
 * It was being called with AJAX and would be returned too slowly sometimes
 */
function showLoginLoad()
{
	document.getElementById("loadingdiv").innerHTML = '<span style="color:#fff;text-align:center;">Loading...<br /><img src="_images/ajax-loader.gif" alt="Loading..." width="180px" /></span>';
	return false;
}

/*****
 * Shows a loading animated .gif where and how you want it
 * @param {string} d - The DIV where it is going
 * @param {integer} [w] - The width of the .gif in px(default - 180)
 * @param {integer} [t] - The text above the .gif (default - "Loading...")
 */
function showLoadBar(d,w,t)
{
	if (!w) 
	{
		var w = 180;
	}
	
	if (!t) 
	{
		var t = "Loading...";
	}
		
	document.getElementById(d).innerHTML = '<span style="color:#fff;text-align:center;">'+t+'<br /><img src="_images/ajax-loader.gif" alt="'+t+'" width="'+w+'px" /></span>';
}

/****
 * This function will clear the innerHTML for a given id
 * @param {Object} divid
 */
function clearDiv(divid)
{
	document.getElementById(divid).innerHTML = '';
}

/******
 * This function is here for future usage.  This way I will not have to change every page if
 * there is something that they all need to share.
 */
function initStuff(pflag)
{
	if(!pflag) {
		var pflag = "";
	}

	showLoginLoad();
	xajax_checkIfLoginSaved(pflag);
	
	return true;
}

/*****
 * This function is used on acctmaint.php and is used to clear some fields
 * @param {Object} whatdiv
 */
function clearAndFocus(whatdiv)
{
	myForm = document.profform;
	
	switch (whatdiv)
	{
		case 'pass':
			myForm.txtnewpass.value = '';
			myForm.txtpassconf.value = '';
			myForm.txtnewpass.select();
			break;
		case 'email':
			myForm.txtnewemail.select();
			break;
	}
	
	return false;
}

function popup(url, wname) 
{
	params  = 'width='+screen.width;
	params += ', height='+screen.height;
	params += ', top=0, left=0'
	params += ', fullscreen=yes';
	
	newwin=window.open(url,wname,params);
	if (window.focus) 
	{
		newwin.focus();
	}
	
	return false;
}

function chkForEnter(e)
{
	var keynum;
	
	if(window.event) // IE
	{
		keynum = e.keyCode;
	}
	else if(e.which) // Netscape/Firefox/Opera
	{
		keynum = e.which;
	}
	
	if (keynum==13)
	{
		showLoginLoad(); 
		xajax_userlogin(xajax.getFormValues('loginform'));
		
		return false;
	}
	else
	{
		return true;
	}
}

function includeJS(jsPath){
	var js = document.createElement("script");
	js.setAttribute("type", "text/javascript");
	js.setAttribute("src", jsPath);
	document.getElementsByTagName("head")[0].appendChild(js);
}

function includeCSS(cssPath){
	var css = document.createElement("link");
	css.setAttribute("type", "text/css");
	css.setAttribute("rel", "stylesheet")
	css.setAttribute("href", cssPath);
	document.getElementsByTagName("head")[0].appendChild(css);
}

// includeJS("scripts/jquery.countdown.min.js");
// includeCSS("styles/jquery.countdown.min.css");

$(document).ready(function(){
	$('ul.sf-menu').superfish({
		animation : { 
					opacity:"show", 
					speed:"fast",
					hoverClass:"navside"
					}				
	});
	
//	var showTime = new Date(2009, 6-1, 2);
		
//	$('#cdTimer').countdown({until: showTime,  
//							 description: 'Until Turning Stone 2009!'
//	});		
});

$(document).ready( function() {
    if (typeof $(".suplogo").corner == 'function') {
        try {
            // The supplies page is currently using the corner plugin.
            //	Not all of the pages are including this in their header.
            $(".suplogo").corner("5px top");
        }
        catch (err) {
            return false;
        }
    }
});

$(document).ready( function() {
	$(".suplink").hover(
		function() {$(this).addClass("suplinkhover")},
		function() {$(this).removeClass("suplinkhover")} 
	);
});

function clickAndHover() {
	$(".nrfform").each( function() {
		$(this).click( function() {
			xajax_retrieveForm($(this).attr("id"));
		});
		
		$(this).hover(
			function() {$(this).addClass("formhover")},
			function() {$(this).removeClass("formhover")}  
		);
	});

// debug forms only visible to the programmer.  They are styled sifferently
	$(".nrfform0").each( function() {
		$(this).click( function() {
			xajax_retrieveForm($(this).attr("id"));
		});

		$(this).hover(
			function() {$(this).addClass("formhover")},
			function() {$(this).removeClass("formhover")}
		);
	});
}

function roundFormChoices() {
	$(".nrfform").corners();
}

function rtnLinkStuff() {
	$(".rtnlink").hover(
		function() {$(this).addClass("formhover")},
		function() {$(this).removeClass("formhover")}
	);
	
	$(".rtnlink").click( function() {
		if (loggedin) { 
			showLoadBar('divsts', 220, 'Loading...'); 
			xajax_showTab('slsmforms', 'content'); 
		}
	});
	
	$(".rtnlink").corners("10px top");
}

function showFNSect() {
    str = $("input[name='chkfn']:checked").val();

    if (str == 'yes') {
        // $(".fnsection").addClass("showfn").fadeIn("fast", function() {
        $(".fnsection").animate({height: "9em"}, 500).fadeIn("fast", function() {
            $(".chkdiv2").css("visibility", "visible");
        });
    }
    else {
        $(".fnsection").animate({height: "0", visibility: "hidden"}, 500,
        function() {
            $(".chkdiv2").css("visibility", "hidden");
            $(this).css("visibility", "hidden");
            $(this).css("display", "none");
        });
    }

}
