﻿/* Ajax methods */
function ajaxReplace(href, containerId, isAjaxParamName, onsuccess){
	isAjaxParamName = isAjaxParamName ? isAjaxParamName : "isajaxrequest";
	$j.ajax({
		url: href + "&" + isAjaxParamName + "=true",
		dataType: "html",
		success: function(response){
			$j(containerId).html(response);
			if (typeof onsuccess == "function"){
				onsuccess();
			}
		}
	});
}

function onPageLinkClick(){
	$j("div.page-links a").click(function(){
		ajaxReplace(this.href, "#Column0", "isajaxrequest", initEvents);
		return false;
	});
}

function onCurrentUploadClick(){
	$j("a.current-upload").click(function(){
		window.open(this.href);
		return false;
	});
}

function onHeaderClick(){
	$j("a", "th").click(function(){
		ajaxReplace(this.href, "#Column0", "isajaxrequest", initEvents);
		return false;
	});
}

function onExportClick(){
	$j("a", "div.excel").click(function(){
		window.open(this.href);
		return false;
	});
}

function setVAlign(){
	$j("td").attr("valign", "top");
	$j("th").attr("valign", "top");
}

function initEvents(){
	onPageLinkClick();
	onCurrentUploadClick();
	onHeaderClick();
	onExportClick();
	setVAlign();
}

function styleUserInterface()
{
	$j(".datagrid tr").addClass("row");
	var $alternateDataRows = $j(".row:odd");
	$alternateDataRows.addClass("row-alt");
	var $allDataRows = $j(".row");
	$allDataRows.hover(
		function() { $j(this).addClass("row-hover");},
		function() { $j(this).removeClass("row-hover");} 
	);
}

// Fire off page specific init method
$j(document).ready(function() {

	// Image replace header1
	/*
	$j("h1").each(function(){
		var text = $j(this).text();
		$j(this).html("<img src=\"" + appPath + "_Handlers/H1Image.ashx?text=" + escape(text) + "\" />");
	});
	*/

	// styleUserInterface();
	
	initEvents();
	if (typeof initPage == "function"){
		initPage();
	}
});


