﻿// Choose search tab to display
function chooseTab(tab, prefix) {

	$('#' + prefix + 'pnlDocResults'
    + ', #' + prefix + 'pnlDldResults'
    + ', #' + prefix + 'pnlImgResults'
    + ', #' + prefix + 'pnlWebResults'
    + ', #' + prefix + 'pnlVidResults').hide();

	$('#' + prefix + 'DocTab'
    + ', #' + prefix + 'DldTab'
    + ', #' + prefix + 'ImgTab'
    + ', #' + prefix + 'WebTab'
    + ', #' + prefix + 'VidTab').removeClass('selectedTab').addClass('unselectedTab');

	switch (tab) {
		case "vid":
			$('#' + prefix + 'pnlVidResults').show();
			$('#' + prefix + 'VidTab').removeClass('unselectedTab').addClass('selectedTab');
			break;
		case "doc": //deprecated, use the download tab instead
			//$('#' + prefix + 'pnlDocResults').show();
			//$('#' + prefix + 'DldTab').removeClass('unselectedTab').addClass('selectedTab');
			//break;
		case "dld":
			$('#' + prefix + 'pnlDldResults').show();
			$('#' + prefix + 'DldTab').removeClass('unselectedTab').addClass('selectedTab');
			break;
		case "img":
			$('#' + prefix + 'pnlImgResults').show();
			$('#' + prefix + 'ImgTab').removeClass('unselectedTab').addClass('selectedTab');
			break;
		default:
			$('#' + prefix + 'pnlWebResults').show();
			$('#' + prefix + 'WebTab').removeClass('unselectedTab').addClass('selectedTab');
			break;
	}
	return false;
}
// Copy selected text to search boxes
var startSelectText;
function SearchSelection() {
	var Text = getSelected();
	if (Text && (Text = new String(Text).replace(/^\s+|\s+$/g, ''))) {
		$('input[type=text].searchbox').val(Text);
	}
}

function getSelected() {
	if (window.getSelection) { return window.getSelection(); }
	else if (document.getSelection) { return document.getSelection(); }
	else {
		var selection = document.selection && document.selection.createRange();
		if (selection.text) { return selection.text; }
		return false;
	}
	return false;
}

function clearSearchText(target, defaultText) {
	if (!startSelectText && target.value != '') {
		startSelectText = defaultText;
	}
	if (target.value == defaultText) target.value = '';
}

function setSearchText(target) {
	if (target.value == '' && startSelectText) target.value = startSelectText;
}

function popDesc(target) {
	if (jQuery.support.boxModel) {
		$(target).removeClass('imageResult_text').addClass('imageResult_text_pop');
	}
}
function unPopDesc(target) {
	if (jQuery.support.boxModel) {
		$(target).removeClass('imageResult_text_pop').addClass('imageResult_text');
	}
}
