/*
@source: http://drop.by/WebOsCmd-0.02.js
@licstart
Copyright (C) 2010  Richard H. Tingstad

The JavaScript code in this page is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version.  The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE.  See the GNU GPL for more details.
See <http://www.gnu.org/licenses/>.

As additional permission under GNU GPL version 3 section 7, you
may distribute non-source (e.g., minimized or compacted) forms of
that code without the copy of the GNU GPL normally required by
section 4, provided you include this license notice and a URL
through which recipients can access the Corresponding Source.
@licend
Version 0.02 Beta
See bottom of file for init/client script.
*/
var c=new Object();
c['a']=['http://www.amazon.com/s/?field-keywords=%s','Amazon search'];
c['ask']=['http://ask.com/web?q=%s','Ask.com search'];
c['c']=[calc,'Calculate (eval)'];
c['d']=['http://www.google.com/search?q=define:%s','Define word (Google)'];
c['del']=['http://delicious.com/save?url=%r&title=%t&v=5&jump=yes&notes=%s','Post to delicious'];
c['e']=['mailto:?subject=%t&body=%s%0A%0A%09%r%0A%0A','Email link'];
c['f']=['http://flickr.com/search/?q=%s','Flickr search'];
c['fb']=['http://www.facebook.com/sharer.php?u=%r&t=%t','Share page on Facebook'];
c['g']=['http://www.google.com/search?q=%s','Google search'];
c['gc']=['http://google.com/search?strip=1&q=cache:%r%20%s','Google cache'];
c['gs']=['http://google.com/search?q=%s%20site:%d','Search site with Google'];
c['h']=[h,'Help'];
c['i']=['http://www.imdb.com/find?s=all&q=%s','Imdb search'];
c['l']=[len,'String length'];
c['ln']=['script:http://drop.by/files/direct-link.0.32.user.js','Link all in-URL URLs'];
c['m']=['http://maps.google.com/maps?q=%s','Google maps'];
c['num']=[num,'Eng. standard gematria (a=1,..,z=26)'];
c['nvm']=[nvm,'Eng. simple gematria (i=j,u=v)'];
c['p']=['http://www.google.com/images?q=%s','Google image search'];
c['q']=['http://quixapp.com/go/?c=%s&t=%t&s=&v=080&u=%r&mode=direct','Quix'];
c['r']=['script:http://drop.by/regexp-find.user.js','Regular expression find'];
c['tw']=['http://search.twitter.com/search?q=%s','Twitter search'];
c['yt']=['http://www.youtube.com/results.php?search_query=%s','YouTube search'];
c['yub']=['http://yubnub.org/parser/parse?command=%s','YubNub'];
c['w']=['http://wikipedia.org/wiki/Special:Search/%s','Wikipedia search'];

function tingstad(u,title,url){
 var p=u.indexOf(' ');
 var n=false;
 if(p==0){
  u=u.substr(1);
  p=u.indexOf(' ');
  n=true;
 }
 var t='';
 if(p>-1){
  t=u.substr(p+1);
  u=u.substr(0,p);
 }
 if(typeof c[u]=='undefined')return '';
 var f=c[u][0];
 if(typeof f=='function') f(t,title,url);
 else if(f.indexOf('script:')==0)sc(f.substr(7));
 else if(n) return fix(f,t,title,url);
 else r(f,t,title,url);
 return '';
}
function fix(cmd,txt,title,url){
 var i=url.indexOf('://')+3;
 var d=url.substring(i,url.indexOf('/',i));
 var e=encodeURIComponent;
 return cmd.replace('%s',e(txt)).replace('%t',title).replace('%r',e(url)).replace('%d',d);
}
function r(cmd,txt,title,url){
 window.location=fix(cmd,txt,title,url);
}
function sc(u){
 var n=u.replace(/[^a-zA-Z0-9]/,'');
 var s=document.getElementById(n);
 if(s)s.parentNode.removeChild(s);
 s=document.createElement('script');
 s.src=u;
 s.id=n;
 s.type='text/javascript';
 document.getElementsByTagName('HEAD')[0].appendChild(s);
}
function h(){
 var s='';
 for(var i in c){
  s+=i+' '+c[i][1]+'\n';
 }
 s+='\nIf you start a command with space, it will open in a new tab or window.';
 alert(s);
 WebOsCmd();
}
function len(t){
 alert(t.length);
}
function calc(t){
 alert(eval(t));
}
function num(t){
 gematria(t,false);
}
function nvm(t){
 gematria(t,true);
}
function gematria(t,e){
 var s=0;
 t=t.toUpperCase();
 for(var i=0;i<t.length;i++){
  var j=t.charCodeAt(i);
  if(j>90) j=0;
  else if(j>64){
   if(e){
    if(j>85) j-=2;
    else if(j>73) j--;
   }
   j-=64;
  }
  else if(j>47 && j<58) j-=48;
  else j=0;
  s+=j;
 }
 alert(s);
}
/*
javascript:WebOsCmd();function WebOsCmd(){var b=false;var h=document.getElementsByTagName('head');if(h.length==0){alert('Error');return;}var s=document.getElementById('weboscmd');if(s)s.parentNode.removeChild(s);s=document.createElement('script');s.src='http://drop.by/WebOsCmd-0.02.min.js';s.id='weboscmd';s.type='text/javascript';s.onload=function(){b=true;};s.onreadystatechange=function(){if(s.readyState=='complete'||s.readyState=='loaded')b=true;};h[0].appendChild(s);var t=window.getSelection?window.getSelection():(document.getSelection?document.getSelection():(document.selection?document.selection.createRange().text:''));var c=window.prompt('Type \'h\' for a list of commands:','');if(c){if(t!=''&&c.indexOf(' ',1)<0)c+=' '+t;var o=function(){if(b){s=tingstad(c,document.title?encodeURIComponent(document.title):'',''+document.location);if(s!=''){s=window.open(s);s.focus();}}else setTimeout(o,99);};o();}}

javascript:WebOsCmd();
function WebOsCmd(){
	var b=false; //Is script file loaded?
	var h=document.getElementsByTagName('head');
	if(h.length==0){
		alert('Error');
		return;
	}
	var s=document.getElementById('weboscmd');
	if(s)s.parentNode.removeChild(s);
	s=document.createElement('script');
	s.src='http://drop.by/WebOsCmd-0.02.min.js';
	s.id='weboscmd';
	s.type='text/javascript';
	s.onload=function(){b=true;};
	s.onreadystatechange=function(){if(s.readyState=='complete'||s.readyState=='loaded')b=true;};
	h[0].appendChild(s);
	var t=window.getSelection?window.getSelection():(document.getSelection?document.getSelection():(document.selection?document.selection.createRange().text:''));
	var c=window.prompt('Type \'h\' for a list of commands:','');
	if(c){
		if(t!=''&&c.indexOf(' ',1)<0)c+=' '+t; //Append selected text only if user has not entered text after command manually.
		var o=function(){
			if(b){
				s=tingstad(c,document.title?encodeURIComponent(document.title):'',''+document.location);
				if(s!=''){ //Open new window here so IE doesn't block.
					s=window.open(s);
					s.focus();
				}
			} //Do not send command until script file has loaded.
			else setTimeout(o,99);
		};
		o();
	}
}
*/