/******************************************************************
* Copyright (c) 2008, Copernic Inc.
******************************************************************/

var qscat = new Array();
qscat[0] = 'web';
qscat[1] = 'images';
qscat[2] = 'smd';
qscat[3] = 'news';

var SelectedTab;
var SelectedTabName;
var qtypestr = get_url_param("qtype");
var query = decodeURIComponent(get_url_param("query"));

var qtype = parseInt(qtypestr, 10);
if (isNaN(qtype)) {
  qtype = 0;
}
else {
  // We support ID 48 because the old search system did use this ID.
  // This may be removed later.
  if (qtype == 48)
    qtype = 1;
}
	
if ((qtype < 0) || (qtype > 3))
  SelectedTab = "web";
else
  SelectedTab = qscat[qtype];

function doLoad()
{
  document.getElementById('qcat').value = SelectedTab;
  document.forms[0].qkw.focus();
  document.forms[0].qkw.value = query;
  changeState(SelectedTab);
}

/*  Get the value of a parameter's query string. Original code from:
http://www.mabaloo.com/Web-Development/Accessing-GET-parameters-with-Javascript.html*/
function get_url_param(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS, "i");
  var results = regex.exec( window.location.href.replace(/\+/g, ' ') );

  if (results == null)
    return "";
  else
    return results[1];
}

// Get current year
function get_year()
{
  var d = new Date();
  document.write(d.getFullYear());
}

function doSubmit(){
	document.forms[0].submit();
}

function changeState(id) {
  SelectedTab = id;

  // Reset controls
  for (keyVar in qscat){
    document.getElementById(qscat[keyVar]).style.fontWeight = 'normal';
    document.getElementById(qscat[keyVar]).className = "qcat";
  }
  
  // Set property for selected tab
  document.getElementById(id).style.fontWeight = 'bold';
  document.getElementById(id).className = "qcatselected";
  document.getElementById('qcat').value = id;
  
  document.forms[0].qkw.focus();
}


