/* 

START jQUERY 

*/
$(document).ready(function(){	
	
	/* INITIALIZE IE NAVMAIN FIX */
	
	$("#nav-global li").hover(
		function () {
			$(this).addClass("sfhover");
			//IE7 fix to make sure the nested UL closes
			$(this).removeClass("sfhover-off");
		}, 
		function () {
			$(this).removeClass("sfhover");
			//IE7 fix to make sure the nested UL closes
			$(this).addClass("sfhover-off");
		}
	);

	/*
	
	SHOW-HIDE TOGGLE
	 - show-hide is triggered by the "toggler" class
	 - show-hide content defaults to open
	 - show-hide collapsed trigger gets "toggler-closed" class
	 */	 
	 
	var toggleSpeed = 300;
	$(".show-hide h3").click(function(){
			$(this).toggleClass("toggler-closed").next().slideToggle(toggleSpeed);
		})
	.end();

	/*  
	
	WRITE DATE TO PAGE
	
	*/
	$("#date").html(getDate());
	
	/*
	
	INITIALIZE FIELD VALUE RESET (looks for presence of "alt" attribute in the input tag)
	
	*/
	$("input[alt!='']").focus(function(){
		setValue(this,"onfocus"); 
		return false;
	});
	$("input[alt!='']").blur(function(){
		setValue(this,"onblur"); 
		return false;
	});
	

 });
 
 
/*
 
BEGIN DATE FUNCTIONS
 
*/
 
function getDate() {
	var today = new Date();
	var Year = takeYear(today);
	var Month = leadingZero(today.getMonth()+1);
	//var DayName = Days[today.getDay()];
	var Day = leadingZero(today.getDate());	
	var Months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");	
	var Month = Months[today.getMonth()];	
	var retVal = ""	
	retVal = Month + " " + Day + ", " + Year;	
	return retVal;		
}  
function leadingZero(nr) {
	if (nr < 10) nr = "0" + nr;
	return nr;
}
function takeYear(theDate) {
	x = theDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}

/*

END DATE FUNCTIONS
 
*/
 
 /* 
 
 BEING SETVALUE
 
 setValue clear's a text input's value and resets it to the input's alt attribute if the user doesn't enter a value 
 
 */
 
function setValue(pEl,pSwitch) {	
	if (pSwitch == "onfocus") {
		if (pEl.value == pEl.alt) {
			pEl.value = "";	
		}
	}
	if (pSwitch == "onblur") {
		if (pEl.value == "") {
			pEl.value = pEl.alt;
		}
	}
}

/*

END SETVALUE

*/
 
 
 
 
 /* Copyright (c) 2006 Mathias Bank (http://www.mathias-bank.de)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) 
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * 
 * Thanks to Hinnerk Ruemenapf - http://hinnerk.ruemenapf.de/ for bug reporting and fixing.
 */
jQuery.extend({
/**
* Returns get parameters.
*
* If the desired param does not exist, null will be returned
*
* @example value = $.getURLParam("paramName");
*/ 
 getURLParam: function(strParamName){
	  var strReturn = "";
	  var strHref = window.location.href;
	  var bFound=false;
	  
	  var cmpstring = strParamName + "=";
	  var cmplen = cmpstring.length;

	  if ( strHref.indexOf("?") > -1 ){
	    var strQueryString = strHref.substr(strHref.indexOf("?")+1);
	    var aQueryString = strQueryString.split("&");
	    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
	      if (aQueryString[iParam].substr(0,cmplen)==cmpstring){
	        var aParam = aQueryString[iParam].split("=");
	        strReturn = aParam[1];
	        bFound=true;
	        break;
	      }
	      
	    }
	  }
	  if (bFound==false) return null;
	  return strReturn;
	}
});

/*

checkAll instructions: checkAll takes three arguments:

argument 1: array of elements to check (radio or checkboxes)
argument 2: array of matches
argument 3: check all flag (true or false)

EXAMPLE: Here we are turning one radio button on by passing in a value to match against
setCheck($("input[name='payment_type']"),["Third Party"],false);

EXAMPLE: Here we want to check multiple checkboxes based on multiple match values
setCheck($("input[name='payment_terms']"),["Prepaid","Collect"],false)

EXAMPLE: Here we want to check all checkboxes and not worry about matching values
setCheck($("input[name='payment_terms']"),[],true)

*/

function setCheck(aryCheck, matchVal, checkAll) {
	$.each(aryCheck, function() {		
		this.checked=checkAll;
		if ($.inArray(this.value, matchVal) != -1) {
			this.checked = true;
		}
	});
}


/* 

Method based function shell

myFunction = {

	// myFunction scope variable
	myVar: "string",
	
	// myFunction scope array
	myAry: [],
	
	method1: function(){
	
	},
	metho2: function(){
		
		
	}
}

*/