
var q = new Array();
var cur;
var KEY_ENTER= 13;
var KEY_ESC  = 27;
var KEY_LEFT = 37;
var KEY_UP   = 38;
var KEY_RIGHT= 39;
var KEY_DOWN = 40;
var KEY_F1   = 112;
var KEY_PLUS = 43;
var KEY_MINUS= 45;
var KEY_DELETE = 46;
var KEY_BACKSPACE = 8;
var KEY_TAB = 9;
var KEY_DOT = 46;

var LP_Search = {
	init: function (){

		q['web'] = "http://search.freecause.com/?type=99&userid="+jsvar+"&p=";
		q['img'] = "http://images.search.yahoo.com/search/images?fr=freecause&type=lpsearch_img&ei=utf-8&p=";
		q['vid'] = "http://video.search.yahoo.com/search/video?fr=freecause&type=lpsearch_vid&ei=utf-8&p=";
		q['news'] = "http://search.news.yahoo.com/search/news?fr=freecause&type=lpsearch_news&ei=utf-8&p=";
		cur = 'web';
	},
	se: function (obj){
		this.removeClass(cur);
		cur = obj.id;
		this.appendClass(cur,"on");
		if(document.getElementById("keyword").value){
			this.sendQuery();
		}
	},
	HookEvent: function(element, eventType, actionFunction, bubble) {
		if (!bubble){
	        bubble = false;}
	    try {
	        if (element.addEventListener) {
	            return element.addEventListener(
	                eventType,
	                actionFunction,
	                bubble);
	        } 
	    } catch(e) {
	    }
	    return element.attachEvent(
	        'on'+eventType,
	        actionFunction);
	},
	removeClass: function(id){
		document.getElementById(id).className = "";
	},
	appendClass: function(id,class_name){
		var cur_class = document.getElementById(id).className;
		document.getElementById(id).className = cur_class + " " + class_name;
	},
	sendQuery: function () {
		//return true;
		//var browser;
                //var keyword = document.getElementById('keyword').value;
		var sUrl = "http://www.lookpink.com/search.php?q="+document.getElementById('keyword').value;
                //if(keyword == "aaa" && BrowserDetect.OS == "Windows" && BrowserDetect.browser == "Explorer" && BrowserDetect.version > 5.5){
                 //  alert(sUrl);
                //}        
		var request = YAHOO.util.Connect.asyncRequest('GET', sUrl, this.callback);
		
	},
	callback : {
		success:function(o){
			LP_Search.execute();
		},
		failure:function(o){
                        LP_Search.execute();
		},
		timeout: 1000
	},
	execute: function(){
		var query = document.getElementById("keyword").value;
		location.href = q[cur]+ query;
	}
};
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	],
	getToolbar: function () {
		if(BrowserDetect.browser == "Firefox"){
		   location.href="http://s31.freecause.com/PinkRibbon2.xpi";
		}
		else if(BrowserDetect.OS == "Windows" && BrowserDetect.browser == "Explorer" && BrowserDetect.version > 5.5){
		   location.href="http://s31.freecause.com/PinkRibbon.exe";
		}
		else {
			alert('Sorry, the toolbar is not supported in '+BrowserDetect.browser+' '+BrowserDetect.version+', please download the latest version of Firefox or Internet Explorer');
		}
	}
};

function catch_enter(evt){
		evt = (evt) ? evt : event;
		var code;
		if (evt.keyCode) code = evt.keyCode;
		if( code == KEY_ENTER ){
			if( document.getElementById("keyword").value.length > 0){
				LP_Search.sendQuery();
			}
		}
	}
		
function init(){
	LP_Search.init()
	BrowserDetect.init();
	document.getElementById('keyword').focus();
	LP_Search.HookEvent(document, "keypress", catch_enter);
}
