// this formulates search GET variables and changes
// location to /search/view.html
// params	none
// returns nothing
function doSearch() {
	var topic = document.getElementById("topic");
	var category = document.getElementById("category");
	var subcategory = document.getElementById("subcategory");
	var query = document.getElementById("adv_query");
	var any_all = document.advanced_search.any_all;
	
	var topic_str = "";
	if (topic != null) topic_str = topic.value;
	
	var category_str = "";
	if (category != null) category_str = category.value;
	
	var subcategory_str = "";
	if (subcategory != null) subcategory_str = subcategory.value;
	
	var query_str = "";
	if (query != null) query_str = query.value;
	
	var any_all_str = "0";
	var any_all_length = any_all.length;
	for (var i = 0; i < any_all_length; i++) {
		if (any_all[i].checked) any_all_str = any_all[i].value;
	} // end for
	
	// replace spaces with '_' to prevent malformed URL
	topic_str = topic_str.replace(/\ /g, "_");
	category_str = category_str.replace(/\ /g, "_");
	subcategory_str = subcategory_str.replace(/\ /g, "_");
	
	if (topic_str == "") document.location = '/view/?query=' + query_str + '&any=' + any_all_str;
	else if (topic_str != "" && category_str == "" && subcategory_str == "") document.location = "/view/" + topic_str + "/?query=" + query_str + "&any=" + any_all_str;
	else if (topic_str != "" && category_str != "" && subcategory_str == "") document.location = "/view/" + topic_str + "/" + category_str + "/?query=" + query_str + "&any=" + any_all_str;
	else if (topic_str != "" && category_str != "" && subcategory_str != "") document.location = "/view/" + topic_str + "/" + category_str + "/" + subcategory_str + "/?query=" + query_str + "&any=" + any_all_str;
} // end doSearch


// open full size view for image
function viewFullSize(id) {
	var url = '/image/full_size.html?id='+id;
	window.open(url, 'image_fullsize_'+id, 'scrollbars=yes,resizable=yes,width=800,height=600');
} // end viewFullSize


// open forgot password dialog box
function openForgotPW() {
	var url = '/account/dialogs/forgot_pw.html';
	window.open(url, 'forgotPW', 'scrollbars=no,resizable=no,width=286,height=140');
} // end openForgotPW


// ========= CSS BUTTON =============

// action when mouseOver on category box
// params	this - object for <td> that mouse is over
//			link_name - string of name of link to also change
// returns nothing
function categoryButtonOver(td_obj, link_name) {
	td_obj.className = 'stockphoCategoryBoxOver';
	if (link_name != '') {
		var link_obj = document.getElementById(link_name);
		link_obj.className = 'whiteCopyLinkHover';
	} // end if
} // end categoryButtonOver


// action when mouseOut on category box
// params	this - object for <td> that mouse left
//			link_name - string of name of link to also change
// returns nothing
function categoryButtonOut(td_obj, link_name) {
	td_obj.className = 'stockphoCategoryBox';
	if (link_name != '') {
		var link_obj = document.getElementById(link_name);
		link_obj.className = 'whiteCopyLink';
	} // end if
} // end categoryButtonOut

// ===================================


// ========= LIGHT BOX ===========

// adds to user's lightbox
function addLightBoxItem(id) {
	var url = '/account/dialogs/lightbox_item_add.html?id='+id;
	window.open(url, 'lightbox_add_'+id, 'scrollbars=no,resizable=no,width=286,height=127');
} // end addLightBoxItem

function removeLightBoxItem(id) {
	var url = '/account/dialogs/lightbox_item_remove.html?id='+id;
	window.open(url, 'lightbox_remove', 'scrollbars=no,resizable=no,width=286,height=127');
} // end removeLightBoxItem

// empties lightbox
function emptyLightBox() {
	var url = '/account/dialogs/lightbox_empty.html';
	window.open(url, 'emptylightbox', 'scrollbars=no,resizable=no,width=286,height=127');
} // end removeCartItem

// =============================


// ========== CART ==============

// adds to user's cart
function addCartItem(id) {
	var url = '/account/dialogs/cart_item_add.html?id='+id;
	window.open(url, 'cart_add_'+id, 'scrollbars=no,resizable=no,width=286,height=127');
} // end addCartItem

function removeCartItem(id) {
	var url = '/account/dialogs/cart_item_remove.html?id='+id;
	window.open(url, 'cart_remove', 'scrollbars=no,resizable=no,width=286,height=127');
} // end removeCartItem

function howToOrder(id) {
	var url = '/account/dialogs/how_to_order.html?id='+id;
	window.open(url, 'how_to_order_'+id, 'scrollbars=no,resizable=no,width=510,height=157');
} 

// adds every lightbox item to user's cart
function lightBox2Cart() {
	var url = '/account/dialogs/lightbox_2_cart.html';
	window.open(url, 'lightbox_2_cart', 'scrollbars=no,resizable=no,width=286,height=127');
} // end addCartItem

// opens a window for the client to view recent orders
function viewOrders(){
	var url = '/account/orders/index.html';
	parent.location=url;
	window.resizeTo(800,650);
	window.moveTo(0,0);
}

// allows for downloading files in the dialog box
function download(id) {
	var url = '/account/download.html?id='+id;
	parent.location=url;
}
// ===============================


// ============ AJAX ==============

function topicChange() {
	if (document.advanced_search['topic'].options[document.advanced_search['topic'].selectedIndex].value == '')
		xajax_setSelects(0, -1, -1);
	else {
		xajax_setSelects(document.advanced_search['topic'].options[document.advanced_search['topic'].selectedIndex].value, 0, -1);
	} // end else
} // end TopicChange

function categoryChange() {
	if (document.advanced_search['category'].options[document.advanced_search['category'].selectedIndex].value == '')
		xajax_setSelects(document.advanced_search['topic'].options[document.advanced_search['topic'].selectedIndex].value, 0, -1);
	else 
		xajax_setSelects(document.advanced_search['topic'].options[document.advanced_search['topic'].selectedIndex].value, document.advanced_search['category'].options[document.advanced_search['category'].selectedIndex].value, 0);
} // end CategoryChange

function subcategoryChange() {
	// here to avoid throwing JS error
} // end subcategoryChange

// =================================
