function optionvak(zoekvak) 
{
var state = zoekvak;
if(state=="1")
   {
   engine = "1";
   document.getElementById('optionsboxtwitter').style.display = 'block'			
    document.getElementById('advancedbox').style.display = 'none'			
    document.getElementById('datesbox').style.display = 'none'			
    document.getElementById('peoplebox').style.display = 'none'			
    document.getElementById('placesbox').style.display = 'none'			
    document.getElementById('trendsbox').style.display = 'block'
    document.twitsearch.twitteropt[4].checked = true		
   document.getElementById('optionsboxleeg').style.display = 'none'			
    document.getElementById('tweepzbox').style.display = 'none'
    document.getElementById('wikipediabox').style.display = 'none'
    document.getElementById('diggbox').style.display = 'none'
   }
if(state=="2")
   {
   engine = "2";
   document.getElementById('optionsboxtwitter').style.display = 'none'			
    document.getElementById('advancedbox').style.display = 'none'			
    document.getElementById('datesbox').style.display = 'none'			
    document.getElementById('peoplebox').style.display = 'none'			
    document.getElementById('placesbox').style.display = 'none'			
    document.getElementById('trendsbox').style.display = 'none'			
   document.getElementById('optionsboxleeg').style.display = 'block'
   document.getElementById('tweepzbox').style.display = 'block'
    document.getElementById('wikipediabox').style.display = 'none'
    document.getElementById('diggbox').style.display = 'none'
   }
if(state=="3")
   {
   engine = "3";
   document.getElementById('optionsboxtwitter').style.display = 'none'			
    document.getElementById('advancedbox').style.display = 'none'			
    document.getElementById('datesbox').style.display = 'none'			
    document.getElementById('peoplebox').style.display = 'none'			
    document.getElementById('placesbox').style.display = 'none'			
    document.getElementById('trendsbox').style.display = 'none'			
   document.getElementById('optionsboxleeg').style.display = 'block'			
    document.getElementById('tweepzbox').style.display = 'none'
    document.getElementById('wikipediabox').style.display = 'block'
    document.getElementById('diggbox').style.display = 'none'
   }
if(state=="4")
   {
   engine = "4";
   document.getElementById('optionsboxtwitter').style.display = 'none'			
    document.getElementById('advancedbox').style.display = 'none'			
    document.getElementById('datesbox').style.display = 'none'			
    document.getElementById('peoplebox').style.display = 'none'			
    document.getElementById('placesbox').style.display = 'none'			
    document.getElementById('trendsbox').style.display = 'none'			
   document.getElementById('optionsboxleeg').style.display = 'block'			
    document.getElementById('tweepzbox').style.display = 'none'
    document.getElementById('wikipediabox').style.display = 'none'
    document.getElementById('diggbox').style.display = 'block'
   }


document.getElementById('words').focus()			
}


function twitoption(zoekvak) 
{
var state = zoekvak;
if(state=="1")
   {
   document.getElementById('advancedbox').style.display = 'block'			
   document.getElementById('datesbox').style.display = 'none'			
   document.getElementById('peoplebox').style.display = 'none'			
   document.getElementById('placesbox').style.display = 'none'			
   document.getElementById('trendsbox').style.display = 'none'			
   }
if(state=="2")
   {
   document.getElementById('advancedbox').style.display = 'none'			
   document.getElementById('datesbox').style.display = 'block'			
   document.getElementById('peoplebox').style.display = 'none'			
   document.getElementById('placesbox').style.display = 'none'			
   document.getElementById('trendsbox').style.display = 'none'			
   }
if(state=="3")
   {
   document.getElementById('advancedbox').style.display = 'none'			
   document.getElementById('datesbox').style.display = 'none'			
   document.getElementById('peoplebox').style.display = 'block'			
   document.getElementById('placesbox').style.display = 'none'			
   document.getElementById('trendsbox').style.display = 'none'			
   document.getElementById('fromid').focus()			
   }
if(state=="4")
   {
   document.getElementById('advancedbox').style.display = 'none'			
   document.getElementById('datesbox').style.display = 'none'			
   document.getElementById('peoplebox').style.display = 'none'			
   document.getElementById('placesbox').style.display = 'block'			
   document.getElementById('trendsbox').style.display = 'none'			
   document.getElementById('nearid').focus()			
   }
if(state=="5")
   {
   document.getElementById('advancedbox').style.display = 'none'			
   document.getElementById('datesbox').style.display = 'none'			
   document.getElementById('peoplebox').style.display = 'none'			
   document.getElementById('placesbox').style.display = 'none'			
   document.getElementById('trendsbox').style.display = 'block'			
   }
}


var diggsearch = "";
var wikisearch = "";
var wikihelp = "";
var waarde = "";
var tin = "";
var box1 = "";
var box1twit = "";
var box1wiki = "";
var box1tweepz = "";
var box1array = "";

var box2 = "";
var box2twit = "";
var box2tweepz = "";
var orbox2tweepz = "";
var notbox2tweepz = "";
var box2array = "";
var twitsearch = "";
var vak= "";
var twitzin = "";
var engine = "1";

function init(){
document.twitsearch.words.focus();
cvak = "1";
}

function focvak(kijk){
cvak = kijk;
}


function zin(){
tabel1()
var test = box1twit;
if(test.substring(0,1)=='"')
   test = test.substring(1,test.length-1)
   else
   test = '"' + test + '"';
document.twitsearch.words.value = test;
document.twitsearch.words2.focus();
}

function tabel1(){
box1 = document.twitsearch.words.value;
box1twit = "";
box1wiki = "";
box1tweepz = "";
var box1array=box1.split(" ");
var tel=0;
while (tel < box1array.length)
 {
  box1twit = box1twit + " " + box1array[tel];
  box1wiki = box1wiki + "_" + box1array[tel];
  tel+=1;
  }
box1twit = box1twit.substring(1,box1twit.length);
box1wiki = box1wiki.substring(1,box1wiki.length);

}

function tabel2(){
box2 = document.twitsearch.words2.value;
box2twit = "";
box2tweepz = "";
orbox2tweepz = "";
notbox2tweepz = "";
var box2array=box2.split(" ");
var tel=0;
while (tel < box2array.length)
 {
  box2twit = box2twit + " " + box2array[tel];
  box2tweepz = box2tweepz + " " + tin + box2array[tel];
  orbox2tweepz = orbox2tweepz + "+OR+" + tin + box2array[tel];
  notbox2tweepz = notbox2tweepz + "+NOT+" + tin + box2array[tel];
  tel+=1;
  }
box2twit = box2twit.substring(1,box2twit.length);
box2tweepz = box2tweepz.substring(1,box2tweepz.length);
orbox2tweepz = orbox2tweepz.substring(4,orbox2tweepz.length);
notbox2tweepz = notbox2tweepz.substring(1,notbox2tweepz.length);
}


function twitter(zoeken){
// tin bevat all, name, bio or loc
//
tin = "";
tel = 0;
while (tel < document.twitsearch.twpz.length)
 {
   if(document.twitsearch.twpz[tel].checked)
    {
     tin = document.twitsearch.twpz[tel].value;
    }
 tel+=1;
 }

//
// box1
//
tabel1()


// zinoperator verwijderen voor wikipedia
//
if(box1wiki.substring(0,1)=='"')
   box1wiki = box1wiki.substring(1,box1wiki.length-1)

// hashtagconversie en plustekenconversie voor twitter
//
box1twitr = "";
tel = 0;
while (tel < box1.length)
 {
  if(box1.substring(tel,tel+1)=="#")
  {  box1twitr = box1twitr + "%23";  }
  else
  {
     if(box1.substring(tel,tel+1)==" ")
     {  box1twitr = box1twitr + "+";  }
     else
     {  box1twitr = box1twitr + box1.substring(tel,tel+1);  }
  }
  tel+=1;
}

// zinoperatorconversie voor twitter
//
if(box1twitr.substring(0,1)=='"')
   box1twitr = "&phrase=" + box1twitr.substring(1,box1twitr.length-1)


// hashtag verwijderen voor tweepz en wikipedia en tin bijvoegen voor tweepz
//
box1wikir = "";
tel = 0;
while (tel < box1.length)
 {
  if(box1.substring(tel,tel+1)=="#")
  {  }
  else
  {
  box1tweepz = box1tweepz + box1.substring(tel,tel+1);
  box1wikir = box1wikir + box1wiki.substring(tel,tel+1);
  }
  tel+=1;
}
if(!box1tweepz=="")
box1tweepz = tin + box1tweepz;

//
// box2
//
tabel2()


// hashtagconversie en plustekenconversie voor twitter
//
box2twitr = "";
tel2 = 0;
while (tel2 < box2.length)
 {
  if(box2.substring(tel2,tel2+1)=="#")
  {  box2twitr = box2twitr + "%23";  }
  else
  {
     if(box2.substring(tel2,tel2+1)==" ")
     {  box2twitr = box2twitr + "+";  }
     else
     {  box2twitr = box2twitr + box2.substring(tel2,tel2+1);  }
  }
  tel2+=1;
}

// hashtag verwijderen voor tweepz2 
//
//box1wikir = "";
//tel = 0;
//while (tel < box2.length)
 //{
//  if(box2.substring(tel,tel+1)=="#")
//  {  }
//  else
 // {
//  box2tweepz = box2tweepz + box2.substring(tel,tel+1);
//  }
//  tel+=1;
//}


// retweet
//
var zonder ="";
if(document.twitsearch.retweet.checked)
    {
    zonder = "+rt";
    }
    else
    {
    zonder = "";
    }

// lang
//
tel = 0;
index = 0;
while (tel < document.twitsearch.rlang.length)
 {
  if(document.twitsearch.rlang.options[tel].selected==true)
    {
    index = tel;
    }
  tel+=1;
  }
var lang = "&lang=" + document.twitsearch.rlang[index].value;
//

// source
//
tel = 0;
index = 0;
while (tel < document.twitsearch.rsource.length)
 {
  if(document.twitsearch.rsource.options[tel].selected==true)
    {
    index = tel;
    }
  tel+=1;
  }
var source = "&source=" + document.twitsearch.rsource[index].value;
//

// res
//
tel = 0;
index = 0;
while (tel < document.twitsearch.rpp.length)
 {
  if(document.twitsearch.rpp.options[tel].selected==true)
    {
    index = tel;
    }
  tel+=1;
  }
var res = "&rpp=" + document.twitsearch.rpp[index].value;
//

// people
//
var from = "&from=" + document.twitsearch.nfrom.value;
var to = "&to=" + document.twitsearch.nto.value;
var ref = "&ref=" + document.twitsearch.nref.value;
//

// places
//
var near = "&near=" + document.twitsearch.pnear.value;
var within = "&within=" + document.twitsearch.pwithin.value;
if(document.twitsearch.punit[0].checked)
    {
    var units = "&units=mi";
    }
    else
    {
    var units = "&units=km";
    }
var places = near + within + units;
//

// dates
//
var date = "&since=" + document.twitsearch.date1xx.value;
var date = date + "&until=" + document.twitsearch.date2xx.value;
//


// containing links
//
var link ="";
if(document.twitsearch.conlinks.checked)
    {
link = "&filter=links";
    }
//


if(document.twitsearch.woord[0].checked)
    {
    box2twitr = "&ands=" + box2twitr + "&nots=" + zonder.substring(1,3);
    }
if(document.twitsearch.woord[1].checked)
    {
    box2twitr = "&ors=" + box2twitr + "&nots=" + zonder.substring(1,3);
    box2tweepz = orbox2tweepz;
    }
if(document.twitsearch.woord[2].checked)
    {
    box2twitr = "&nots=" + box2twitr + zonder;
    box2tweepz = notbox2tweepz;
    }



// wikilang
//
tel = 0;
index = 0;
while (tel < document.twitsearch.wikilang.length)
 {
  if(document.twitsearch.wikilang.options[tel].selected==true)
    {
    index = tel;
    }
  tel+=1;
  }
var wikilangr = document.twitsearch.wikilang[index].value;

// sorterenvolgorde
twpsort = "";
if(document.twitsearch.twps[1].checked)
    {
	if(document.twitsearch.fwers.options[1].selected)
	    {
	     twpsort = "&s=followers&sa=1";
	    }
 	else
	    {
	     twpsort = "&s=followers&sa=0";
	    }
    }
if(document.twitsearch.twps[2].checked)
    {
	if(document.twitsearch.fwing.options[1].selected)
	    {
	     twpsort = "&s=following&sa=1";
	    }
 	else
	    {
	     twpsort = "&s=following&sa=0";
	    }
    }
if(document.twitsearch.twps[3].checked)
    {
	if(document.twitsearch.fdate.options[1].selected)
	    {
	     twpsort = "&s=created&sa=1";
	    }
 	else
	    {
	     twpsort = "&s=created&sa=0";
	    }
    }
if(document.twitsearch.twps[4].checked)
    {
	if(document.twitsearch.fupdate.options[1].selected)
	    {
	     twpsort = "&s=updates&sa=1";
	    }
 	else
	    {
	     twpsort = "&s=updates&sa=0";
	    }
    }

if((box2tweepz=="bio%3A")||(box2tweepz=="name%3A")||(box2tweepz=="loc%3A"))
box2tweepz="";

//var url = twitbasis + andtot + lang + from + to + ref + places + date + link + res + source;

// diggage
//
tel = 0;
index = 0;
while (tel < document.twitsearch.age.length)
 {
  if(document.twitsearch.age.options[tel].selected==true)
    {    index = tel;    }
  tel+=1;
  }
var diggage = document.twitsearch.age[index].value;

// diggmedia
//
tel = 0;
index = 0;
while (tel < document.twitsearch.media.length)
 {
  if(document.twitsearch.media.options[tel].selected==true)
    {    index = tel;    }
  tel+=1;
  }
var diggmedia = document.twitsearch.media[index].value;

// diggtopics
//
tel = 0;
index = 0;
while (tel < document.twitsearch.topics.length)
 {
  if(document.twitsearch.topics.options[tel].selected==true)
    {    index = tel;    }
  tel+=1;
  }
var diggtopics = document.twitsearch.topics[index].value;

// diggs
//
tel = 0;
index = 0;
while (tel < document.twitsearch.diggs.length)
 {
  if(document.twitsearch.diggs.options[tel].selected==true)
    {    index = tel;    }
  tel+=1;
  }
var diggamount = document.twitsearch.diggs[index].value;

// diggextra
//
tel = 0;
index = 0;
while (tel < document.twitsearch.extra.length)
 {
  if(document.twitsearch.extra.options[tel].selected==true)
    {    index = tel;    }
  tel+=1;
  }
var diggextra = document.twitsearch.extra[index].value;

// diggs
//
tel = 0;
index = 0;
while (tel < document.twitsearch.sorted.length)
 {
  if(document.twitsearch.sorted.options[tel].selected==true)
    {    index = tel;    }
  tel+=1;
  }
var diggsorted = document.twitsearch.sorted[index].value;


diggsearch = box1twitr + diggage + diggmedia + diggtopics + diggamount + diggextra + diggsorted;
//alert(box1tweepz);


if(engine=="1")
    {
    var twitbasis="http://search.twitter.com/search?q=";
    urltwit = twitbasis + box1twitr + box2twitr + lang + from + to + ref + places + date + link + res + source;
    window.open(urltwit,"test");
    }
if(engine=="2")
    {
     var urltweepz = "http://www.tweepz.com/search?q=";
     urltweepz = urltweepz + box1tweepz + "+" + box2tweepz + twpsort;
     window.open(urltweepz,"test");
    }
if(engine=="3")
    {
     var urlwiki = "http://" + wikilangr + ".wikipedia.org/wiki/" + box1wikir;
     window.open(urlwiki,"test");
    }
if(engine=="4")
    {
     var urldigg = "http://digg.com/search?s=" + diggsearch;
     window.open(urldigg,"test");
    }
}

//not http://digg.com/search?s=twitter+-digg
//phrase http://digg.com/search?s=%22twitter+search%22
//Put terms in "quotes" for an exact search 
//Add -term to exclude a term from your query (e.g. apple -iphone) 




function erasewords(id){
   document.getElementById(id).value = "";
   document.getElementById(id).focus();
}

function tag(id){
   var test = document.getElementById(id).value;
   test = test + '#';
   document.getElementById(id).value = test;
   document.getElementById(id).focus();
}

function aon(){
   document.twitsearch.words2.focus();
}

function trend(code){
if(cvak=="1")
 {
 document.twitsearch.words.focus();
 document.twitsearch.words.value = document.twitsearch.words.value  + code;
 }
 else
 {
 document.twitsearch.words2.focus();
 document.twitsearch.words2.value = document.twitsearch.words2.value + code;
 }
}

  $(document).ready(function(){
    $.sanitize = function(string){
      string = string.replace("#","");
      string = string.replace(/ /g, "+");
      string = string.toLowerCase();
      return encodeURI(string);
    };

    $.idize = function(string){
      string = string.replace(/ /g, "-");
      string = string.replace("#", "hash-");
      string = string.replace("&", "amp-");
      return string;
    };
    $.getJSON("http://search.twitter.com/trends.json?callback=?", function(data){
      $.each(data.trends, function(i,trend){
        waarde = $.idize(trend.name);
        if(i>4)
	{
        $("<div><a name='jan' id='"+trend.name+"' onclick='trend(this.id)'>" + trend.name + "</a></div>").appendTo("#trendsbox2");     
        }
	else
	{
        $("<div><a name='jan' id='"+trend.name+"' onclick='trend(this.id)'>" + trend.name + "</a></div>").appendTo("#trendsbox1");     
        }
        if ( i == 9 ) return false;
      });
    });



  });















