// JavaScript Document
function mouseOverPageNum(page) {
	if (navigator.appName == "Microsoft Internet Explorer")
		page.style.cursor = "hand";
	else	
		page.style.cursor = "pointer";
}

function refreshPage(activeKeyword, removeActiveKeyword) {
	var currPage = document.getElementById("hid.currPage");
	if (currPage != null && currPage.value > "") gotoPage(currPage.value, activeKeyword, removeActiveKeyword);
}

function gotoPage(pageNum, activeKeyword, removeActiveKeyword, recount) {
	var mode = document.getElementById("hid.mode");
	var rowCount = document.getElementById("hid.totalRowCount").value;
	var noCD = document.getElementById("nocd");
	var hasTIFF = document.getElementById("hasTIFF");
	
	if (mode != null && (mode.value == "lightbox" || mode.value == "lightboxcd")) {		
		var action = "lightboxes?hid.mode=" + mode.value + "&cmd=gotoPage&pageNum=" + pageNum + "&hid.totalRowCount=" + rowCount;
		
	} else if (mode != null && mode.value == "cdimages") {
		var cdID = document.getElementById("hid.cd_id");
		var pagingURL = document.getElementById("hid.pagingURL");	
		var action = varWebRoot + "/stock-photo-cd/" + pagingURL.value + "/" + cdID.value + "/" + pageNum + "/stock-photos.html";
		if (hasTIFF != null && hasTIFF.checked) action += "?hasTIFF=1";
		
	} else if (mode != null && mode.value == "listcd") {
		var cdCategory = document.getElementById("hid.category");	
		var pagingURL = document.getElementById("hid.pagingURL");	
		var action = varWebRoot + "/stock-photo-cd/" + pagingURL.value + "/" + pageNum + "/index.html";

	} else if (mode != null && mode.value == "browse") {
		var action = varWebRoot + "/new-stock-photos/" + pageNum + "/index.html";
		if (noCD != null && noCD.checked) action += "?nocd=1";
		if (hasTIFF != null && hasTIFF.checked) {
			if (noCD != null && noCD.checked) 
				action += "&hasTIFF=1";
			else
				action += "?hasTIFF=1";
		}
			
	} else if (mode != null && mode.value == "searchHist") {
		var action = "admin?cmd=viewSearch&pageNum=" + pageNum + "&hid.totalRowCount=" + rowCount;

	} else if (mode != null && mode.value == "pendingImg") {
		if (pageNum == 1)	//  do not send page num.  Server will default AND perform row count
			var action = "admin?cmd=viewPending";
		else {
			var action = "admin?cmd=viewPending&pageNum=" + pageNum;
			if (rowCount.trim() > "") action += "&hid.totalRowCount=" + rowCount;
		}
		
		var filterType = document.getElementById("sel.filter");
		if (filterType != null) action = action + "&sort=" + filterType.value;
			
		var printGrp = document.getElementById("sel.printGrp");
		if (printGrp != null) action = action + "&print_grp=" + printGrp.value;
	
	} else if (mode != null && mode.value == "declinedImg") {
		if (pageNum == 1)	//  do not send page num.  Server will default AND perform row count
			var action = "admin?cmd=viewDeclined";
		else
			var action = "admin?cmd=viewDeclined&pageNum=" + pageNum + "&hid.totalRowCount=" + rowCount;
		
	} else if (mode != null && (mode.value == "quicksearch" || mode.value == "quicksearch_category")) {
		var action = document.getElementById("hid.quicksearch").value;
		action = varWebRoot + action.replace("<pagenum>", pageNum);
		
	} else if (mode != null && mode.value == "salesInfo") {
		var id = document.getElementById("id");
		var rt = document.getElementById("royaltytype");
		var action = "admin?cmd=viewSales&id=" + id.value + "&pageNum=" + pageNum + "&hid.totalRowCount=" + rowCount + "&rt=" + rt.value;
	
	} else if (mode != null && mode.value == "myimages") {
		var action = varWebRoot + "/my-stock-photos/" + pageNum + "/index.html";
		if (rowCount > "") action += "?hid.totalRowCount=" + rowCount;
		
	} else {
		var action = "";
		var title = document.getElementById("hid.title");
	
		if (title != null && title.value > "")
			action = "stock-photos.jsp?pageNum=" + pageNum;			
		else
			action = "search.jsp?pageNum=" + pageNum;

		if (recount == null || recount == false)
			action += "&hid.totalRowCount=" + rowCount;
			
		var searchText = document.getElementById("hid.searchText");
		var searchID = document.getElementById("hid.searchID");
		var noLog = document.getElementById("nl");
		
		if (searchText != null) action = action + "&searchText=" + URLencode(searchText.value);
		if (searchID != null && searchID.value > "") action = action + "&search_id=" + searchID.value;
		if (noLog != null) action = action + "&nl=" + nl.value;
		if (activeKeyword != null && activeKeyword > "") action = action + "&active_keyword=" + activeKeyword;
		if (removeActiveKeyword != null && removeActiveKeyword > "") action = action + "&rem_active_keyword=" + removeActiveKeyword;
		if (title != null) action = action + "&t=" + URLencode(title.value);
		if (noCD != null && noCD.checked) action += "&nocd=1";
		if (hasTIFF != null && hasTIFF.checked) action += "&hasTIFF=1";
	
		var searchType = document.getElementsByName("chk_type");
		if (searchType != null && searchType.length > 0) {
			if (!(searchType[0].checked && searchType[1].checked)) {
				for (var i = 0; i < searchType.length; i++) {
					if (searchType[i].checked)
						action += "&chk_type=" + searchType[i].value;
				}
			}	
		}
		
		var searchColors = document.getElementsByName("hid.chk_color");
		if (searchColors != null && searchColors.length > 0) {
			for (var i = 0; i < searchColors.length; i++)
				action += "&chk_color=" + searchColors[i].value;
		}
		
		var searchShape = document.getElementById("hid.rad_shape");
		if (searchShape != null && searchShape.value > "")
			action += "&rad_shape=" + searchShape.value;
	}

	document.location.href = action;
}
