var params = new Array();

function saveCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else
		expires = "";
	document.cookie = name+"="+value+expires+"; domain=google.atcomet.com; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i<ca.length;i++) {
	var c = ca[i];
	while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return parseReturn(c.substring(nameEQ.length,c.length));
	}
	return null;
}
function qs(el) {
	if (window.RegExp && window.encodeURIComponent) {
		var ue=el.getAttribute("href");
		var qe=encodeURIComponent(document.f.q.value);
		if(ue.indexOf("q=")!=-1){
			el.href=ue.replace(new RegExp("q=[^&$]*"),"q="+qe);
		}else{
			el.href=ue+"&q="+qe;
		}
	}
	return 1;
}

function sf(){
	if (query != undefined && query != null && query != "")
	{
		query=decodeURIComponent(query);
		if (window.RegExp) {
			document.f.q.value = query.replace(/\+/g, " ");
		} else {
			document.f.q.value = query
			document.f1.q.value = query
		}
	}
	if (params["fileType"] != null && params["fileType"] != "")
	{
		for(var i=0;i<document.all["fileType"].options.length;i++)
		{
			if (params["fileType"] == document.all["fileType"].options[i].value)
				document.all["fileType"].options[i].selected = true;
		}
	}
	if (params["searchType"] != null && params["searchType"] != "")
	{
		for(var i=0;i<document.all["searchType"].options.length;i++)
		{
			if (params["searchType"] == document.all["searchType"].options[i].value)
				document.all["searchType"].options[i].selected = true;
		}
	}
	document.f.q.focus();
}

function loadFunctions()
{
	document.getElementById("query").focus();
	var page = 1;
	if (params["q"] == null)
		return;
	if (params["q"] != null)
	{
		globalSearchWord = params["q"];
		document.getElementById("query").value = decodeURIComponent(params["q"]).replace(/\+/g, " ");
		document.getElementById("query1").value = decodeURIComponent(params["q"]).replace(/\+/g, " ");
	}
}
function gotoImages(search)
{
	if (!search)
		location.href = "http://www.google.com/imghp?hl=" + searchLang + "&tab=wi&q=" + encodeURIComponent(document.getElementById("query").value);
	else 
		location.href = "http://images.google.com/images?hl=" + searchLang + "&q=" + encodeURIComponent(document.getElementById("query").value);
}
function gotoNews()
{
	location.href = "http://www.mcomet.com/search_movie/?tn=bchome&q=" + document.getElementById("query").value;
}

function gotoVideos()
{
	location.href = "http://video.google.com/videosearch?hl=" + searchLang + "&q=" + encodeURIComponent(document.getElementById("query").value);
}



function gotoImages1(search)
{
	if (!search)
		location.href = "http://www.google.com/imghp?hl=" + searchLang + "&tab=wi&q=" + encodeURIComponent(document.getElementById("query1").value);
	else 
		location.href = "http://images.google.com/images?hl=" + searchLang + "&q=" + encodeURIComponent(document.getElementById("query1").value);
}
function gotoNews1()
{
	location.href = "http://www.mcomet.com/search_movie/?tn=bchome&q=" + document.getElementById("query1").value;
}

function gotoVideos1()
{
	location.href = "http://video.google.com/videosearch?hl=" + searchLang + "&q=" + encodeURIComponent(document.getElementById("query1").value);
}

function getParams() {
	var locationSearch = document.location.search.toString();
	locationSearch = (locationSearch.substring(0,1) == "?") ? locationSearch.substring(1) : locationSearch;
	var searchParamsArr = locationSearch.split("&");
	for (var i=0; i<searchParamsArr.length; i++) {
		var searchParamArr = searchParamsArr[i].split("=");
		for (var y=0; y<searchParamArr.length; y++) {
			if (y == 0) {
				params[searchParamArr[y]] = "";
			} else {
				if (searchParamArr[0] == 'useGenre') {
					params[searchParamArr[0]] = eval(searchParamArr[y]);
				} else {
					params[searchParamArr[0]] = searchParamArr[y];
				}
			}
		}
	}
}
getParams();
var query = (params['q']!= undefined)? params['q']:'';

function checkSubmit()
{
    var d = document.getElementById("query");
    if(d != null && d.value!="")
    {
        return true;
    } else {
        return false;
	}
}
function checkSubmit1()
{
    var d = document.getElementById("query1");
    if(d != null && d.value!="")
    {
        return true;
    } else {
        return false;
	}
}
