var cookieName = "tsw236VaFwQ";
var ImageNameCookee = "jhtrsfz";
var styleCookee = "sagsafr";


var buttonNames= new Array();

var selectedButtons= new Array();

buttonNames[0]='Google';
buttonNames[1]='Yahoo!';
buttonNames[2]='Msn';
buttonNames[3]='Lycos';
buttonNames[4]='Altavista';
buttonNames[5]='Hotbot';
buttonNames[6]='Ask';
buttonNames[7]='Excite';
buttonNames[8]='Google News';
buttonNames[9]='Yahoo News';
buttonNames[10]='Scholar';
buttonNames[11]='New Scientist';
buttonNames[12]='About';
buttonNames[13]='Britannica';
buttonNames[14]='Wikipedia';
buttonNames[15]='Dogpile';
buttonNames[16]='Mamma';
buttonNames[17]='Yahoo Finance';
buttonNames[18]='Msn Money';
buttonNames[19]='Jayde';
buttonNames[20]='Market Watch';
buttonNames[21]='Maps';
buttonNames[22]='Images';
buttonNames[23]='YouTube';
buttonNames[24]='Metacafe';
buttonNames[25]='Dailymotion';
buttonNames[26]='Break';
buttonNames[27]='Spike';
buttonNames[28]='Amazon';
buttonNames[29]='eBay';
buttonNames[30]='New York Times';
buttonNames[31]='Become';
buttonNames[32]='Technorati';
buttonNames[33]='Myspace';
buttonNames[34]='Flickr';
buttonNames[35]='Pixsy';
buttonNames[36]='Blinkx';
buttonNames[37]='Digg';
buttonNames[38]='Simpy';
buttonNames[39]='Topix';
buttonNames[40] = "Alltheweb";
buttonNames[41] = "IxQuick";
buttonNames[42] = "Metacrawler";
buttonNames[43] = "Search";
buttonNames[44] = "Clusty";
buttonNames[45] = "CNN";
buttonNames[46] = "Reuters";
buttonNames[47] = "BBC";
buttonNames[48] = "Newsday";
buttonNames[49] = "Usatoday";
buttonNames[50] = "Fark";
buttonNames[51] = "Reddit";
buttonNames[52] = "Shoutwire";
buttonNames[53] = "Buzz";
buttonNames[54] = "Ekudos";
buttonNames[55] = "Dzone";
buttonNames[56] = "Delicious";
buttonNames[57] = "Stumbleupon";
buttonNames[58] = "Furl";
buttonNames[59] = "Propeller";
buttonNames[60] = "Blogmarks";
buttonNames[61] = "Magnolia";
buttonNames[62] = "I am bored";
buttonNames[63] = "Netvouz";
buttonNames[64] = "Blinklist";
buttonNames[65] = "Linkarena";
buttonNames[66] = "Syncone";
buttonNames[67] = "Maple";
buttonNames[68] = "Watvindenwijover";
buttonNames[69] = "Diigo";
buttonNames[70] = "Myweb";
buttonNames[71] = "Slashdot";
buttonNames[72] = "Hotlinks";
buttonNames[73] = "Blogsearch";
buttonNames[74] = "Blog Digger";
buttonNames[75] = "icerocket";
buttonNames[76] = "BlogSearchEngine";
buttonNames[77] = "Blog Arama";
buttonNames[78] = "Blogpulse";
buttonNames[79] = "Lifehacker";
buttonNames[80] = "Tech Crunch";
buttonNames[81] = "Attuworld";
buttonNames[82] = "Lifehack";
buttonNames[83] = "Alttext";
buttonNames[84] = "Neatorama";
buttonNames[85] = "Coolhunting";
buttonNames[86] = "Beppegrillo";
buttonNames[87] = "Gawker";
buttonNames[88] = "Downloadsquad";
buttonNames[89] = "Google video";
buttonNames[90] = "Yahoo video";
buttonNames[91] = "Metacafe";
buttonNames[92] = "Dailymotion";
buttonNames[93] = "Veoh";
buttonNames[94] = "Revver";
buttonNames[95] = "Atom";
buttonNames[96] = "Myspace Videos";
buttonNames[97] = "Putfile";
buttonNames[98] = "Vidilife";
buttonNames[99] = "Zippyvideos";
buttonNames[100] = "Blip";
buttonNames[101] = "Bolt";
buttonNames[102] = "Guba";
buttonNames[103] = "Sharkle";
buttonNames[104] = "Justin";
buttonNames[105] = "Megavideo";
buttonNames[106] = "Youku";
buttonNames[107] = "Gofish";
buttonNames[108] = "Supernovatube";
buttonNames[109] = "Uncut Video";
buttonNames[110] = "Tudou";
buttonNames[111] = "Products";
buttonNames[112] = "Alibaba";
buttonNames[113] = "Shopping";
buttonNames[114] = "Sell";
buttonNames[115] = "Books";
buttonNames[116] = "Patents";
buttonNames[117] = "Code Search";
buttonNames[118] = "Koders";
buttonNames[119] = "Oreilly";
buttonNames[120] = "Facebook";
buttonNames[121] = "Orkut";


function focalize()
{
	document.getElementById("q").focus();
}

function excForm(frm, siteId)
{
	var val = frm.q.value;
	location.href = "search.aspx?s=" + siteId + "&q=" + val;
}

function justLoadCookie()
{
  selectedButtons=getCookie(cookieName).split(',');	
}

function LoadSearch()
{
	if(getCookie(cookieName)==null)
	{
		addDefaultButtons();
	}
	else
	{
		selectedButtons=getCookie(cookieName).split(',');
		for(var i=0;i<selectedButtons.length;i++)
		{
			writeButton(selectedButtons[i]);
		}
	}
}

function LoadSearchLogo()
{
    if (getCookie(ImageNameCookee) == null)
	{
      document.writeln("<a href='/edit' title='Edit Logo'>");
      document.writeln("<img src='images/initallogo.jpg'   alt='logo' />");
      document.writeln("</a>");
	}
	else
	{
	    document.writeln("<a href='/edit' title='Logo'>");
	    document.writeln("<img src='logo/" + getCookie(styleCookee) + "/" + getCookie(ImageNameCookee) + ".jpg'   alt='logo' />");
	    document.writeln("</a>");
	}
}

function SaveStyle(style, ImageName) {
    var expireDate = new Date("January 01, 2500 00:00:00");
    setCookie(ImageNameCookee, ImageName, expireDate);
    setCookie(styleCookee, style, expireDate);
}

function writeButton(buttonIndex)
{
	document.write("<input type=\"button\"  alt=\"" + buttonNames[buttonIndex] + " search\" onclick=\"excForm(this.form, '" + buttonIndex + "')\" value=\"" + buttonNames[buttonIndex] + "\" />");
}

function addDefaultButtons()
{
	writeButton(0);
	writeButton(1);
	//writeButton(8);
	//writeButton(14);
	//writeButton(21);
	//writeButton(22);
	//writeButton(23);
	//writeButton(29);
	//writeButton(34);	
}

		function addButtons()
		{
			selectedButtons=new Array();
			var counter=0;
			var chks = document.getElementsByName('chkengines[]');
			for (var i = 0; i < chks.length; i++)
			{
			   if (chks[i].checked)
			   {
				  selectedButtons[counter]=chks[i].value;
				  counter++;
			   }
			}
			var expireDate = new Date("January 01, 2500 00:00:00");
			setCookie(cookieName,selectedButtons,expireDate); 
			location.href="index.html";
		}

		function ListSearchEngines(captionText,buttonsToAdd)
		{
		    var caption = document.createElement('h2');
		    caption.innerHTML=captionText;
		    document.getElementById("searchenginelistDiv").appendChild(caption);
		    var ul = document.createElement('ul');
		    //li.innerHTML='<h5>'+caption+'</h5>';
		    if(getCookie(cookieName)==null)
			{
				selectedButtons=['0','1']; //,'8','14','21','22','23','29','34'
			}
			else
			{
				selectedButtons=getCookie(cookieName).split(',');
			}
			for(var j=0;j<buttonsToAdd.length;j++)
			{ 
			    var i=parseInt(buttonsToAdd[j]);
				var checkedText="";
				if(checkInSelected(i))
				{
					//checkedText='checked="checked"';
				}
				var li = document.createElement('li');
				li.innerHTML='<label><input id="chkengines' + i + '" name="chkengines[]" type="checkbox" value="' + i + '" '  + checkedText + '> ' + buttonNames[i] + '</label>';
				ul.appendChild(li);
			}
			document.getElementById("searchenginelistDiv").appendChild(ul);
		
		}
		
		function checkInSelected(val)
		{
		  var returnValue=false;
		  for(var i=0;i<selectedButtons.length;i++)
			{
				if(selectedButtons[i]==val)
				{
				   returnValue=true;
				}
			}
		  return returnValue;
		}
		
		function UpdateSelected()
		{
		    for(i=0;i<buttonNames.length;i++)
            {
                 if(checkInSelected(i))
                 {
                   document.getElementById("chkengines"+i).checked=true;
                 }
            }		   
		}

                 // Sets cookie values. Expiration date is optional
                 function setCookie(name, value, expire) 
                 {
                     strCookie = name + "=" + escape(value);
                     if (expire)
                         strCookie += "; expires=" + expire.toGMTString();

                     document.cookie = strCookie;
                 }

                 function getCookie(Name) 
                 {
                     var search = Name + "="
                     if (document.cookie.length > 0) { 
                         // if there are any cookies
                         offset = document.cookie.indexOf(search)
                         if (offset != -1) { 
                             // if cookie exists
                             offset += search.length

                             // set index of beginning of value
                             end = document.cookie.indexOf(";", offset)

                             // set index of end of cookie value
                             if (end == -1)
                                 end = document.cookie.length

                             return unescape(document.cookie.substring(offset, end))
                         }
                     }
                 }

           // End hiding -->
		   
 function CreateBookmarkLink(){
	title = "HAlf - All in one Personal Search Engine";
	url = "http://halftitle.com";
if (window.sidebar) // firefox
    window.sidebar.addPanel(title, url, "");
else if(window.opera && window.print)
{ // opera
    var elem = document.createElement('a');
    elem.setAttribute('href',url);
    elem.setAttribute('title',title);
    elem.setAttribute('rel','sidebar');
    elem.click();
}
else if(document.all)// ie
    window.external.AddFavorite(url, title);
}

function writeBookmark()
{
	if (window.sidebar)
	{
	    document.write('<a href = "javascript:CreateBookmarkLink();">Add to Favorites</a>  | '); 
	}
	else if(window.opera && window.print)
	{ // opera
	    document.write('<a href = "javascript:CreateBookmarkLink();">Add Bookmark</a>  | ');
	}
	else if(document.all)// ie
	{
	    document.write('<a href = "javascript:CreateBookmarkLink();">Bookmark Page</a>   | '); 
	}
}

function gotostep(step) {
    if ((step == 2) && (document.getElementById("txttitle").value == "")) {
        alert("Please enter a title");
        return ;
    }
    for (i = 1; i < 3; i++) {
        document.getElementById("menu" + i).removeAttribute("class");
        document.getElementById("step" + i).style.display = "none";
    }
    document.getElementById("menu" + step).setAttribute("class", "activeStep");
    document.getElementById("step" + step).style.display = "block";
}


function showpage(type) {
    window.location ="/create/"+ type + "/" + document.getElementById("txttitle").value
}
function SetEditText() {
    if (getCookie(ImageNameCookee) != null) {
        document.getElementById("txttitle").value = getCookie(ImageNameCookee);
    }
    else {
        document.getElementById("txttitle").value = "Your Name";
    }
}