var searchCategory = 'all';

function setSearchCategory(category) {
	searchCategory = category;
	valueMe('categoryList', category);
}

function searchFormValidate() {
	searchCategory = getValue('categoryList');
	if (searchCategory == 'all' || searchCategory == '') {
		alert("Please select an Information type.");
		return false;
	}
	else if (getValue('publicationList') == 'frasers' && searchCategory == 'articles') {
		valueMe('publicationList','cmo');
	}
	else if (searchCategory == 'web') {
		valueMe('publicationList','frasers');
	}

	var keyword = getValue('keyword');
	if (keyword.toUpperCase() == 'ENTER SEARCH WORDS HERE' || keyword == '') {
		valueMe('keyword','*');
	}
	nameMe('keyword', searchCategory);

	return true;
}

function searchFormKeyPress(e) {
	var keyCode;

	if (window.event) { // IE
		keyCode = e.keyCode;
	}
	else if(e.which) { // Netscape/Firefox/Opera
		keyCode = e.which;
	}
	if (keyCode == 13) {
	    var searchSubmit = document.getElementById('searchSubmit');
		searchSubmit.onclick();
	    return false;
	}
	return true;
}

function searchFormSubmit(form) {
	pageTracker._trackPageview("/Site Search/?q="+getValue('keyword')+"&Cat="+getValue('categoryList'));
	form.submit();
}


function setFrasersDefaultSearchCriteria() {

  var url = location.href;

  url = url.toLowerCase();

  

  if (url.indexOf("canadianmetalworking") != -1) {

    valueMe('categoryList', "articles");

    valueMe('publicationList', "canadianmetalworking");

  } else if (url.indexOf("canadianpackaging") != -1) {

    valueMe('categoryList', "articles");

    valueMe('publicationList', "canadianpackaging");

  } else if (url.indexOf("canadianprinter") != -1) {

    valueMe('categoryList', "articles");

    valueMe('publicationList', "canadianprinter");

  } else if (url.indexOf("coatings") != -1) {

    valueMe('categoryList', "articles");

    valueMe('publicationList', "coatings");

  } else if (url.indexOf("designengineering") != -1) {

    valueMe('categoryList', "articles");

    valueMe('publicationList', "designengineering");

  } else if (url.indexOf("foodincanada") != -1) {

    valueMe('categoryList', "articles");

    valueMe('publicationList', "foodincanada");

  } else if (url.indexOf("mmd") != -1) {

    valueMe('categoryList', "articles");

    valueMe('publicationList', "mmd");

  } else if (url.indexOf("plant") != -1) {

    valueMe('categoryList', "articles");

    valueMe('publicationList', "plant");

  } else if (url.indexOf("plasticsincanada") != -1) {

    valueMe('categoryList', "articles");

    valueMe('publicationList', "plasticsincanada");

  } else if (url.indexOf("purchasingb2b") != -1) {

    valueMe('categoryList', "articles");

    valueMe('publicationList', "purchasingb2b");

  } else if (url.indexOf("frasers") != -1) {

    valueMe('categoryList', "productservices");

    valueMe('publicationList', "frasers");

  } else if (url.indexOf("canadianmanufacturing") != -1 || url.indexOf("rogers-cmo-ts") != -1) {

    valueMe('categoryList', "articles");

    valueMe('publicationList', "cmo");

  } else {

    valueMe('categoryList', "productservices");

    valueMe('publicationList', "frasers");

  }

}


function presetSearch(publication) {

                var searchURL = location.href;

 

                if (searchURL.indexOf("http", 0) == -1 || searchURL.indexOf("searchResults.jsf") == -1) {

                                setFrasersDefaultSearchCriteria();

                                return;

                } else {

 

                                 searchURL = searchURL.substring(10);

 

    var searchParams = searchURL.split("/");

    if (searchParams.length > 4) {

      var searchType = searchParams[1];

      var searchPublication = searchParams[2];

      var searchKeywords = searchParams[4];

 

      valueMe('categoryList', searchType);

      valueMe('publicationList', searchPublication);

      valueMe('keyword', searchKeywords);

   }

  }

 

                return;

}

