function getExpireDate(daysTilExpiry) {
     var second = 1000;
     var hour   = 3600 * second;
     var day    = 24 * hour;
     var expire = new Date((new Date()).getTime() + daysTilExpiry*day);
     return expire.toGMTString();
}

function getLastUsed(){
	if(document.cookie) {
		index = document.cookie.indexOf("lastUse");
			if (index != -1){
				namestart = (document.cookie.indexOf("=", index) + 1);
				nameend = document.cookie.indexOf(";", index);
				if (nameend == -1) {
					nameend = document.cookie.length;
				}
				lastUse = document.cookie.substring(namestart, nameend);
				return lastUse;
			}
	}
}

function isCountrySelected(country){
	var lastUsed = getLastUsed();
	//alert(lastUsed+country);
	if(lastUsed){
		if(lastUsed.substring(lastUsed.indexOf(":")+1,lastUsed.length).equals(country)){
			//alert("returning true");
			return true;
		} else {
			//alert("returning false1");
			return false;
		}
	} else {
		return false;
	}
}

function submitSearch()
{
	var searchText = document.forms[0].elements[0].value;
	var countryBox = document.forms[0].country;
	
	var radio = document.forms[0].elements;
	var whichSearch = "none checked";
	var whichCountry = "none selected";
	
	for ( counter=0; counter < radio.length; counter++ )
	{

		//alert(counter+" array no is "+radio[counter].value);
		if ( radio[counter].checked )
		{
			whichSearch = radio[counter].value;
		}
	}
	
	for ( j=0; j < countryBox.length; j++ )
	{
		if ( countryBox.options[j].selected )
		{
			if(countryBox.options[j].value != "--"){
				whichCountry = countryBox.options[j].value;
			} else {
				whichCountry = countryBox.options[0].value;
			}
		}
	}
	
	// alert("Which search: " + whichSearch + "  " + searchText + " (" +whichCountry+")"); 
	
	// cookie parameters
 	var c = "lastUse=" + whichSearch +":"+ whichCountry + "; expires=" + getExpireDate(999);
 
 	// write cookie
 	document.cookie = c;
	
	if ( whichSearch == "1" && whichCountry == "us" )
	{
		// google
		var searchform = document.forms[1];
		searchform.elements[2].value = searchText;
		searchform.submit();
	}
	else if ( whichSearch == "2"  && whichCountry == "us")
	{
		// Yahoo
		var searchform = document.forms[3];
		searchform.elements[0].value = searchText;
		searchform.submit();
	}
	else if ( whichSearch == "3"  && whichCountry == "us")
	{
		// MSN
		var searchform = document.forms[2];
		searchform.elements[0].value = searchText;
		searchform.submit();
	}
	else if ( whichSearch == "4"  && whichCountry == "us")
	{
		// Ask
		var searchform = document.forms[4];
		searchform.elements[0].value = searchText;
		searchform.submit();
	} 
	else if ( whichSearch == "1" && whichCountry == "uk" )
	{
		// google
		var searchform = document.forms[5];
		searchform.elements[2].value = searchText;
		searchform.submit();
	}
	else if ( whichSearch == "3"  && whichCountry == "uk")
	{
		// MSN
		var searchform = document.forms[6];
		searchform.elements[0].value = searchText;
		searchform.submit();
	}
	else if ( whichSearch == "2"  && whichCountry == "uk")
	{
		// Yahoo UK
		var searchform = document.forms[7];
		searchform.elements[0].value = searchText;
		searchform.submit();
	}
}

function setLink()
{
		
	
			var bname = navigator.appName;
			if (!bname.search(/netscape/i) == 0)
			   {
			   	 	document.getElementById('homelink').style.visibility='visible';
			   }
	
		
}

function shouldRolldown(){
	if(document.cookie) {
		index = document.cookie.indexOf("rolldownseen");
			if (index != -1){
				return false;
			}
	}
	
	var browser = detectBrowser();
	
	
	if(!browser){
		return false;
	}
		
	//var plugintexttag = document.getElementById("install_text");
	
	//if(browser == "FF")
	//	plugintexttag.innerHTML = "Get the Firefox Search Plugin!";
		
	//if(browser == "IE7")
	//	plugintexttag.innerHTML = "Get the Internet Explorer Search Plugin!";
		
	
	return true;	
}

function rollDownBox(){

  var divTag = document.getElementById("container");

  if(!shouldRolldown()){
	  document.write("<style type='text/css'>#rolldown {visibility: hidden;}</style>");
  }

  //preload images if possible
  //if (document.images) {
  //  pic1= new Image(35,65); 
  //  pic1.src="images/rolldown/rd_bg.jpg"; 

  //  pic2= new Image(102,65); 
  //  pic2.src="images/rolldown/rd_lhs.jpg"; 

  //  pic3= new Image(258,65); 
  //  pic3.src="images/rolldown/rd_rhs.jpg"; 
  //}




  //t1 = new Tween(divTag.style,'top',Tween.bounceEaseOut,-65,0,2,'px');
  //t1.start();
}

function rollBack(){

  var divTag = document.getElementById("container");

  t1 = new Tween(divTag.style,'top',Tween.none,0,-63,1,'px');
  t1.start();
  
  setRolldownCookie(7);
  
}

function setRolldownCookie(daysTilExpiry){

	var c = "rolldownseen=y; expires=" + getExpireDate(daysTilExpiry);
 
 	// write cookie
 	document.cookie = c;
}


function detectBrowser(){

	if(navigator.userAgent.indexOf("Firefox")!=-1){
		var versionindex=navigator.userAgent.indexOf("Firefox")+8;
		if (parseInt(navigator.userAgent.charAt(versionindex))>=1){
			return "FF";
		}
	} else {//Detect IE5.5+
		version=0
		if (navigator.appVersion.indexOf("MSIE")!=-1){
			temp=navigator.appVersion.split("MSIE");
			version=parseFloat(temp[1]);
		}
		
		if (version>=7){ //NON IE browser will return 0
			return "IE7";
		}
	}
	return false;
}

function getPlugin(){

	var browser = detectBrowser();
	
	if(browser == "FF")
		addEngine('Scandoo','png','Search',0);
	
	if(browser == "IE7"){
		window.external.AddSearchProvider('http://static.scandoo.com/scandoo/IE7/scandoogoogle.xml');

	}

	setRolldownCookie(999);
}

function addEngine(name,ext,cat,type) {

	if ((typeof window.sidebar == "object") && (typeof window.sidebar.addSearchEngine == "function")) {
		window.sidebar.addSearchEngine(
			"http://static.scandoo.com/scandoo/firefox/"+name+".src",
			"http://static.scandoo.com/scandoo/firefox/"+name+"."+ext, name, cat );

		//alert("Scandoo added!");
	}
}
