function AvailToCart(ContentID, Qty, QString)
{
	var Url = "Ajax.aspx?CN=98A129E595F9" +
			"&ITEMID="+ ContentID +
			"&HLTYPE=ADD"+
			"&quantity=" + Qty +
			"&"+ QString;
	GetAjax(Url);
}

function ToolbarConsolePage(url)
{
	var Html = '<div id="tile-dialog-!tile!" style="display: none; overflow: hidden;"><div class="workspace-block"></div><input type="hidden" id="tile-url-!tile!" value="'+ url +'" /><iframe id="consoleiframe!tile!" src="Portal.aspx?CN=24662EED52C7&TILE=!tile!" scrolling="off" style="overflow: hidden;" frameborder="0" height="100%" width="100%"></iframe></div>';

	if (!ToolbarConsolePage.lastAssignedId)
		ToolbarConsolePage.lastAssignedId = 1;
	var Tile = ToolbarConsolePage.lastAssignedId;
	ToolbarConsolePage.lastAssignedId++;

	Html = Html.replace(/!tile!/g, Tile);
	$("body").prepend(Html);
}
function ToolbarLoadPage(Tile, Title, Height, Width)
{
	$("#tile-dialog-"+ Tile).dialog({
		height: parseInt(Height) + 47,
		width: parseInt(Width) + 2,
		dialogClass: 'console',
		resizable: false,
		stack: true,
		title: Title,
		dragStart: function(event, ui){ 
			$(".workspace-block").show();
		},
		dragStop: function(event, ui){
			$(".workspace-block").hide();
		}
	});
}
function GetPage()
{
	return $("#tbCN").val();
}

/*****************************************************
 *	Function: Submit(Action, Redirect)
 *****************************************************
 *
 *	Change Log
 *	----------
 *	None
 *
 *	Function Description
 *	--------------------
 *	This function submits a form and sets hidden
 *	input values for '#tbAction' and '#tbREDIRECT'
 *
 *	Function Paramaters
 *	-------------------
 *	Action - The action to perform in the database
 *		ex. ('U' to update a record)
 *	Redirect - The content number to redirect to.
 *
 *	Function Returns
 *      ----------------
 *	None
 *
 *	Dependencies
 *	------------
 *	- JQuery
 *
 *****************************************************/
function Submit(Action, Redirect)
{
	
	if(Action == undefined)
	{
		$("#tbAction").val("U");
	}//END if
	else
	{
		$("#tbAction").val(Action);
	}//END else

	if(Redirect != undefined)
	{
		$("#tbREDIRECT").val(Redirect);
	}//END if
	document.getElementById("myForm").submit();
}//END 'Submit' function


/*****************************************************
 *	Function: ItemToCart(ContentID, Quantity)
 *****************************************************
 *
 *	Change Log
 *	----------
 *	None
 *
 *	Function Description
 *	--------------------
 *	This function validates the quantity and if the
 *	quantity is valid, it is submitted to the cart.
 *
 *	Function Paramaters
 *	-------------------
 *	ContentID - The Content Number of the item to 
 *		    be added
 *	Quantity - The amount of the item to add to the
 *		   cart
 *
 *	Function Returns
 *      ----------------
 *	None
 *
 *	Dependencies
 *	------------
 *	- JQuery
 *
 *****************************************************/
function ItemToCart(ContentID, Quantity, shouldRefresh, Dimension)
{
	if(Quantity == undefined || Quantity === '')
		Quantity = "1"; //END if
	if(Dimension == undefined)
		Dimension = ""; //END if

	if (shouldRefresh === undefined || shouldRefresh !== false)
	{
		shouldRefresh = true;
	}

	if(parseInt(Quantity, 10) >= 1)
	{
		var Url = "Ajax.aspx?CN=98A129E595F9&ITEMID="+ ContentID +"&HLTYPE=ADD&QUANTITY="+ Quantity +"&DIMENSIONID="+ Dimension + UrlNoCache();
		$.get(Url, null, function(html)
		{
			if (shouldRefresh)
			{
				window.location=window.location;
			}
		});//END 'get' function
	}//END if
	else
		alert('Please enter a valid quantity'); //END else
}//END 'ItemToCart' function



/*****************************************************
 *	Function: SearchSite(Value)
 *****************************************************
 *
 *	Change Log
 *	----------
 *	None
 *
 *	Function Description
 *	--------------------
 *	This function performs a global site search
 *
 *	Function Paramaters
 *	-------------------
 *	Value - The query string
 *
 *	Function Returns
 *      ----------------
 *	None
 *
 *	Dependencies
 *	------------
 *	None
 *
 *****************************************************/
function SearchSite(Value)
{
	//Sets the search query as a parameter in the URL
	// and then redirectes the user to the results page
	var Url = "Portal.aspx?CN=9CE97316BE98&GCONTENTID=D3954F94DBE0&SEARCH="+ encodeURIComponent(Value);
	window.location = Url;

}//END 'SearchSite' function

/*****************************************************
 *	Function: SearchSite(Value)
 *****************************************************
 *
 *	Change Log
 *	----------
 *	None
 *
 *	Function Description
 *	--------------------
 *	Returns a 'RND' URL parameter to prevent caching
 *
 *	Function Paramaters
 *	-------------------
 *	None
 *
 *	Function Returns
 *      ----------------
 *	Return
 *	- Type: String
 *	- Values: "&RND" + Any number
 *
 *	Dependencies
 *	------------
 *	None
 *
 *****************************************************/
function UrlNoCache()
{
	var t = Math.random() +'';
	var Return = '&RND='+ t.replace('0.','');
	return Return;
}//END 'UrlNoCache' function


/*****************************************************
 *	Function: GetPanel(Url, Panel, Callback)
 *****************************************************
 *
 *	Change Log
 *	----------
 *	None
 *
 *	Function Description
 *	--------------------
 *	This function pulls a code snippet from a given url
 *	and puts it into a given Panel
 *
 *	Function Paramaters
 *	-------------------
 *	Url - The location of the panel data
 *	Panel - The containing element
 *	Callback - any function call to make after
 *		   getting the new panel
 *
 *	Function Returns
 *      ----------------
 *	None
 *
 *	Dependencies
 *	------------
 *	- JQuery
 *
 *****************************************************/
function GetPanel(Url, Panel, Callback)
{
	if(Url != "")
	{
		var data = $(Panel).find("input, select, textarea").serialize();

		//sets the Panel to a loading state
		var height = $(Panel).height();
		$(Panel +" *").hide();
		$(Panel).height(height);
		$(Panel).addClass("loading");

		//recieves and displays the data for the Panel
		$.get(Url + UrlNoCache(), function(html){
			$(Panel +" *").show();
			$(Panel).css("height","auto");
			$(Panel).removeClass("loading");

			//evaluates the data if it is javascript code
			if(html.substring(0,11).toLowerCase() == "javascript:")
				eval(html.substring(11, html.length));//END if
			else if($(Panel).length > 0)			
				$(Panel).html(html);//END else if

			if (typeof Callback == "function") 
				Callback();//END if
		});//END 'get' function
	}//END if
}//END 'GetPanel' function

function ShowLoading(Panel)
{
	var height = $(Panel).height();
	$(Panel +" *").hide();
	$(Panel).height(height);
	$(Panel).addClass("loading");
}

/*****************************************************
 *	Function: RefreshPanel(Url, Panel, Replacement, Callback)
 *****************************************************
 *
 *	Change Log
 *	----------
 *	None
 *
 *	Function Description
 *	--------------------
 *	Refreshing a given panel with the data from the given
 *	url
 *
 *	Function Paramaters
 *	-------------------
 *	Url - The location of the panel data
 *	Panel - The containing element
 *	Replacement - Get-Description
 *	Callback - any function call to make after
 *		   getting the new panel
 *
 *	Function Returns
 *      ----------------
 *	None
 *
 *	Dependencies
 *	------------
 *	- JQuery
 *
 *****************************************************/
function RefreshPanel(Url, Panel, Replacement, Callback)
{
	if(Url != "")
	{
		var height = $(Panel).height();

		//sets the Panel to a loading state
		$(Panel +" *").hide();
		$(Panel).height(height);
		$(Panel).addClass("loading");
		$(Panel).empty();

		$.get(Url + UrlNoCache(), function(html){
			//removes the loading state
			$(Panel +" *").show();
			$(Panel).css("height","auto");
			$(Panel).removeClass("loading");

			//evaluates the data if it is javascript code
			if(html.substring(0,11).toLowerCase() == "javascript:")
				eval(html.substring(11, html.length));//END if
			else if($(Panel).length > 0)
			{
				var replace = "REFRESH";
				if (typeof Replacement != "function" && Replacement != undefined) 
					replace = Replacement;
				html = html.substring(html.indexOf('<'+ replace +'>') + replace.length + 2, html.indexOf('</'+ replace +'>'));
				$(Panel).html(html);
			}//END else if

			if (typeof Replacement == "function") 
				Replacement();//END if
			if (typeof Callback == "function") 
				Callback();//END if
		});//END 'get' function
	}//END if
}//END 'RefreshPanel' function

/*****************************************************
 *	Function: PostPanel(Url, Panel, Callback)
 *****************************************************
 *
 *	Change Log
 *	----------
 *	None
 *
 *	Function Description
 *	--------------------
 *	Posts information from a given panel to the server
 *
 *	Function Paramaters
 *	-------------------
 *	Url - The location of the panel data
 *	Panel - The containing element
 *	Callback - any function call to make after
 *		   getting the new panel
 *
 *	Function Returns
 *      ----------------
 *	None
 *
 *	Dependencies
 *	------------
 *	- JQuery
 *
 *****************************************************/
function PostPanel(Url, Panel, Callback)
{
	if($(Panel).length > 0 && Url != "")
	{
		var data =  $(Panel).find("input, select, textarea").serialize();

		var height = $(Panel).height();

		//sets the Panel to a loading state
		$(Panel +" *").hide();
		$(Panel).height(height);
		$(Panel).addClass("loading");
		$(Panel).html("");

		$.post(Url, data, function(html){
			//removes the loading state
			$(Panel +" *").show();
			$(Panel).css("height","auto");
			$(Panel).removeClass("loading");

			//evaluates the data if it is javascript code
			if( typeof html !== 'object')
			{ 
				if(html.substring(0,11).toLowerCase() == "javascript:")
					eval(html.substring(11, html.length));//END if
				else if($(Panel).length > 0)			
					$(Panel).html(html);//END else if
			}
			if (typeof Callback == "function") 
				Callback();//END if
		});//END 'post' Event
	}//END if
}//END 'PostPanel' function

/*****************************************************
 *	Function: PostRefresh(Url, Panel, Replacement, Callback)
 *****************************************************
 *
 *	Change Log
 *	----------
 *	None
 *
 *	Function Description
 *	--------------------
 *	Refreshing the given panel after posting
 *
 *	Function Paramaters
 *	-------------------
 *	Url - The location of the panel data
 *	Panel - The containing element
 *	Replacement - The element to refresh
 *	Callback - any function call to make after
 *		   getting the new panel
 *
 *	Function Returns
 *      ----------------
 *	None
 *
 *	Dependencies
 *	------------
 *	- JQuery
 *
 *****************************************************/
function PostRefresh(Url, Panel, Replacement, Callback)
{
	if($(Panel).length > 0 && Url != "")
	{
		var data = $(Panel).find("input, select, textarea").serialize();

		var height = $(Panel).height();

		//sets the Panel to a loading state
		$(Panel +" *").hide();
		$(Panel).height(height);
		$(Panel).addClass("loading");
		$(Panel).html("");

		$.post(Url, data, function(html){
			//removes the loading state
			$(Panel +" *").show();
			$(Panel).css("height","auto");
			$(Panel).removeClass("loading");

			//evaluates the data if it is javascript code
			if(html.substring(0,11).toLowerCase() == "javascript:")
				eval(html.substring(11, html.length));//END if
			else if($(Panel).length > 0)
			{
				var replace = "POSTREFRESH";
				if (typeof Replacement != "function" && Replacement != undefined) 
					replace = Replacement;
				html = html.substring(html.indexOf('<'+ replace +'>') + replace.length + 2, html.indexOf('</'+ replace +'>'));
				$(Panel).html(html);

			}//END else if

			if (typeof Replacement == "function") 
				Replacement();//END if
			if (typeof Callback == "function") 
				Callback();//END if
		});//END 'post' function
	}//END if

}//END 'PostRefresh' function

/*****************************************************
 *	Function: GetAjax(Url, Panel, Callback)
 *****************************************************
 *
 *	Change Log
 *	----------
 *	None
 *
 *	Function Description
 *	--------------------
 *	This function pulls a code snippet from a given url
 *	and puts it into a given Panel
 *
 *	Function Paramaters
 *	-------------------
 *	Url - The location of the panel data
 *	Panel - The containing element
 *	Callback - any function call to make after
 *		   getting the new panel
 *
 *	Function Returns
 *      ----------------
 *	None
 *
 *	Dependencies
 *	------------
 *	- JQuery
 *
 *****************************************************/
function GetAjax(Url, Panel, Callback)
{
	if(Url != "")
	{
		$.get(Url + UrlNoCache(), function(html){

			//evaluates the data if it is javascript code
			if(html.substring(0,11).toLowerCase() == "javascript:")
				eval(html.substring(11, html.length));//END if
			else if(Panel != undefined && $(Panel).length > 0)			
				$(Panel).html(html);//END else if

			if (typeof Callback == "function") 
				Callback();//END if
		});//END 'get' function
	}//END if
}//END 'GetAjax' function

/*****************************************************
 *	Function: PostAjax(Url, Panel, Callback)
 *****************************************************
 *
 *	Change Log
 *	----------
 *	None
 *
 *	Function Description
 *	--------------------
 *	Posts information from a given panel to the server
 *
 *	Function Paramaters
 *	-------------------
 *	Url - The location of the panel data
 *	Panel - The containing element
 *	Callback - any function call to make after
 *		   getting the new panel
 *
 *	Function Returns
 *      ----------------
 *	None
 *
 *	Dependencies
 *	------------
 *	- JQuery
 *
 *****************************************************/
function PostAjax(Url, Panel, Callback)
{
	if($(Panel).length > 0 && Url != "")
	{
		var data = $(Panel).find("input, select, textarea").serialize();
		$.post(Url, data, function(html){

			if(html.substring(0,11).toLowerCase() == "javascript:")
				eval(html.substring(11, html.length));

			if (typeof Callback == "function") 
				Callback();
		});
	}
}

/*****************************************************
 *	Function: ChangeCountry(CountryCode, StateOptionsID, StateLabelID, ZipLabelID)
 *****************************************************
 *
 *	Change Log
 *	----------
 *	None
 *
 *	Function Description
 *	--------------------
 *	Changes labels and state selection depending on a
 *	given country code.
 *
 *	Function Paramaters
 *	-------------------
 *	CountryCode - The Value of the country selection
 *	StateOptionsID - The ID of the state dropdown
 *	StateLabelID - The ID of the State Label
 *	ZipLabelID - The ID of the Zip Code Label
 *
 *	Function Returns
 *      ----------------
 *	None
 *
 *	Dependencies
 *	------------
 *	- JQuery
 *
 *****************************************************/
function ChangeCountry(CountryCode, StateOptionsID, StateLabelID, ZipLabelID)
{
	var Url = "Ajax.aspx?CN=2EF841540163&COUNTRYCODE="+ CountryCode;
	Url = Url.replace(/&amp;/g, '&');
	$.ajax({
  		url: Url,
		dataType: "html",
  		cache: false,
  		success: function(html) {
			//replaces the State Options dropdown with the corresponding values
			var Options = html.substring(html.indexOf('<STATEOPTIONLIST>') + 17, html.indexOf('</STATEOPTIONLIST>'));

    			StateOptionsID.html(Options);
			StateOptionsID.val("");

			//replaces the State label with the proper corresponding label
			if(StateLabelID.length > 0 )
			{
				var StateLabel = html.substring(html.indexOf('<STATELABEL>') + 12, html.indexOf('</STATELABEL>'));
    				StateLabelID.html(StateLabel);
			}//END if

			//replaces the Zip Code label with the proper corresponding label
			if(ZipLabelID != undefined)
			{
				var ZipLabel = html.substring(html.indexOf('<ZIPCODELABEL>') + 14, html.indexOf('</ZIPCODELABEL>'));
    				ZipLabelID.html(ZipLabel);
			}//END if
  		}//END 'success' function
	});//END 'ajax' function
}//END 'ChangeCountry' function

/*****************************************************
 *	Function: parseNum(Value)
 *****************************************************
 *
 *	Change Log
 *	----------
 *	None
 *
 *	Function Description
 *	--------------------
 *	Returns the number result from a string
 *
 *	Function Paramaters
 *	-------------------
 *	Value - An input string
 *
 *	Function Returns
 *      ----------------
 *	Return
 *	- Type: Integer
 *	- Values: Any number or an empty string
 *
 *	Dependencies
 *	------------
 *	- JQuery
 *
 *****************************************************/
function parseNum(Value)
{
	var Return = "";
	for(var i = 0; i < Value.length; i++)
	{
		var char = Value.substr(i,1);
		if(parseInt(char, 10) >= 0)
			Return += char;//END if
	}//END 'for' loop
	if(Return != "")
		parseInt(Return);//END if

	return Return;//Returns either "" or a number
}//END 'parseNum' function


//Created by Dawid Kasperowicz
//Used for password validation on Webfoot2010 Portal
$.fn.validatePassword = function ()
{
	$.elements = 
	{
		currentElement: $(this[0]),
		hasCapitalLetter: /[A-Z]/,
		hasLowerCaseLetter: /[a-z]/,
		hasNumber: /[0-9]/,
		hasNonAlphaNumericCharacter: /[^a-zA-Z0-9]/,
		passedValidation: true,
		errorMessage: 'Your password must: <ul>'
	}
	
	if ($.elements.hasCapitalLetter.test($.elements.currentElement.val()) === false)
	{
		$.elements.passedValidation = false;
		$.elements.errorMessage = $.elements.errorMessage + '<li style="color: #DD0000; font-size: smaller;">Have at least one capital letter</li>';
	}
	
	if ($.elements.hasLowerCaseLetter.test($.elements.currentElement.val()) === false)
	{
		$.elements.passedValidation = false;
		$.elements.errorMessage = $.elements.errorMessage + '<li style="color: #DD0000; font-size: smaller;">Have at least one lower case letter</li>';
	}
	
	if ($.elements.hasNumber.test($.elements.currentElement.val()) === false)
	{
		$.elements.passedValidation = false;
		$.elements.errorMessage = $.elements.errorMessage + '<li style="color: #DD0000; font-size: smaller;">Have at least one number</li>';
	}
	if ($.elements.hasNonAlphaNumericCharacter.test($.elements.currentElement.val()) === false)
	{
		$.elements.passedValidation = false;
		$.elements.errorMessage = $.elements.errorMessage + '<li style="color: #DD0000; font-size: smaller;">Have at least one non-alphanumeric character</li>';
	}
	if ($.elements.currentElement.val().length < 8)
	{
		$.elements.passedValidation = false;
		$.elements.errorMessage = $.elements.errorMessage + '<li style="color: #DD0000; font-size: smaller;">Be at least 8 characters in length</li>';
	}
	
	if ($.elements.passedValidation === false)
	{
		$.elements.currentElement.siblings('div.passworderror').remove();
		$.elements.currentElement.after('<div class="passworderror" style="color: #DD0000; width: 100%;">' + $.elements.errorMessage + '</ul></div>');
	}
	else
	{
		$.elements.currentElement.siblings('div.passworderror').remove();
	}
	
	return $.elements.passedValidation;
};

//Created By Dawid Kasperowicz
$(function ()
{
	$('.toggle').each(function ()
	{
		if ($(this).next('div').css('display') === 'block')
		{
			$(this).html('<img src="assets/media/img/collapse.gif" alt="Collapse" style="vertical-align: middle; padding-bottom: 3px; _padding-bottom: 0px;" /> ' + $(this).text());
		}
		else
		{
			$(this).html('<img src="assets/media/img/expand.gif" alt="Expand" style="vertical-align: middle; padding-bottom: 3px; _padding-bottom: 0px;" /> ' + $(this).text());
		}
	}).live('click', function ()
	{
		if ($(this).children('img').attr('alt') === 'Collapse')
		{
			$(this).children('img').attr('src', 'assets/media/img/expand.gif')
						.attr('alt', 'Expand');
		}
		else if ($(this).children('img').attr('alt') === 'Expand')
		{
			$(this).children('img').attr('src', 'assets/media/img/collapse.gif')
						.attr('alt', 'Collapse');
		}
	});
});
