/*/// these variables set the bar preferences ////*/

/* turns dictionary on/off */
//var bardictionary="off";
var bardictionary="off";
var doctype="";

//URL of toolbar_css including bar.css

var cssbaseurl='http://www.texticweb.com/remotetoolbars/default/';
//var cssbaseurl='http://localhost:8080/remotetoolbars/default/';

/*///////////////////////////////////////////////*/


var detect = navigator.userAgent.toLowerCase();
var OS,browser,version,total,thestring;

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
if (checkIt('msie 8')) 
  browser = "Internet Explorer 8"
else if (checkIt('safari')) 
  browser = "Safari"
else if (checkIt('omniweb')) 
  browser = "OmniWeb"
else if (checkIt('opera')) 
  browser = "Opera"
else if (checkIt('webtv')) 
  browser = "WebTV";
else if (checkIt('icab')) 
  browser = "iCab"
else if (checkIt('msie')) 
  browser = "Internet Explorer"
else if (!checkIt('compatible'))
{
	browser = "Netscape Navigator"
	version = detect.charAt(8);
}
else 
  browser = "An unknown browser";

if (!version) version = detect.charAt(place + thestring.length);

if (!OS)
{
	if (checkIt('linux')) 
    OS = "Linux";
	else if (checkIt('x11')) 
    OS = "Unix";
	else if (checkIt('mac')) 
    OS = "Mac"
	else if (checkIt('win')) 
    OS = "Windows"
	else 
    OS = "an unknown operating system";
}

function checkIt(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

//can change stylesheets depending on browser
if(browser=="Internet Explorer")
  cssurl=cssbaseurl+'toolbar_css/';
else
  cssurl=cssbaseurl+'toolbar_css/';

window.onbeforeprint=beforeprint
window.onafterprint=afterprint

function beforeprint(){ 
  document.getElementById('fixbottom').style.display='none';
}

function afterprint(){ 
  document.getElementById('fixbottom').style.display='inline';
}  



//write bar html (escape single quotes \')
document.write(''+
'<!--TEXTIC Toolbar. Copyright Textic Ltd. 2005. Unauthorised use is prohibited-->'+
'<form action="" id="toolbarform" onsubmit="">'+
'<div id="fixbottom" style="width: 100%;height: 30px;">'+

'<div id="toolbar-left" style="float: left;background: #002d5f;width: 49%;height: 30px;margin: auto auto -30px auto;">'+
    
'</div>'+

'<div id="toolbar-right" style="float: right;background: #0098d5;width: 49%;height: 30px;margin: auto auto -30px auto;">'+
    
'</div>'+


'<div id="toolbar"  >'+



'		<div class="logotool"><img onclick="window.open(\'http://www.textic.com\',\'textic\',\'width=850,height=650,scrollbars=yes,resizable=yes,status=yes,directories=yes,menubar=yes,location=yes,toolbar=yes\');" class="tool" src="'  + cssbaseurl + 'toolbar_css/lib/rok_logo.gif" alt="TEXTIC Toolbar" /></div>'+


'<!-- zoom -->'+
'		<div class="tool" style="width: 63px;">'+
'		<input type="hidden" name="sizeselect" value="1" />'+

'		<a style="float: left;margin: 0px 5px 0px 0px;" href="javascript:zoom(1.2, browser);"><img class="tool" src="'  + cssbaseurl + 'toolbar_css/lib/icon_fsize.gif" alt="Zoom in"  /></a>'+
'		<a style="float: left;border: 0px red solid;" href="javascript:zoom(1/1.2, browser);"><img class="tool" src="'  + cssbaseurl + 'toolbar_css/lib/icon_minus.gif" alt="Zoom out"  /></a> '+

'    </div>'+

'		'+
'		<!-- font face -->'+
'		<div class="tool"  ><img class="tool" src="'  + cssbaseurl + 'toolbar_css/lib/icon_fchoice.gif"  alt="Font choice"  />'+
'		<select style="width: 90px !important;" id="faceselectid" name="faceselect" class="tool" onchange="setChoice(\'face\',this.options[this.selectedIndex].value)">'+
'		<option class="tool" value="">Font choice</option>'+
'		<option class="tool" value="">---------</option>'+
'		<option class="tool" value="arial">Arial</option>'+
'		<option class="tool" value="verdana">Verdana</option>'+
'		<option class="tool" value="times">Times</option>'+
'		<option class="tool" value="comic">Comic</option>'+
'			</select></div>'+

'		'+
'		<!-- design scheme -->'+
'		<div class="tool"><img class="tool" src="'  + cssbaseurl + 'toolbar_css/lib/icon_design.gif" alt="Design scheme"  />'+
'		<select style="width: 70px !important;" id="designselectid" name="designselect" class="tool" onchange="setChoice(\'design\',this.options[this.selectedIndex].value)">'+
'		<option value="">Design</option>'+
'		<option value="">---------</option>'+
'		<option value="">Default</option>'+
'		<option value="styleb">Reverse</option>'+
'		<option value="stylec">Slate</option>'+
'		<option value="styled">Simple</option>'+
'		<option value="stylee">Soft</option>'+
'		<option value="stylef">Red</option>'+
'		<option value="styleg">Orange</option>'+
'		<option value="styleh">Yellow</option>'+
'		<option value="stylei">Green</option>'+
'		<option value="stylej">Blue</option>'+
'		<option value="stylek">Violet</option>'+
'		</select></div>'+
'		'+

'<!-- font colour -->'+
'		<div class="tool"><img class="tool" src="'  + cssbaseurl + 'toolbar_css/lib/icon_fcolour.gif"  alt="Font colour" />'+
'		<select style="width: 90px !important;" id="colorselectid" name="colourselect" class="tool" onchange="setChoice(\'colour\',this.options[this.selectedIndex].value)">'+
'		<option value="">Font colour</option>'+
'		<option value="">---------</option>'+
'		<option value="black">Black</option>'+
'		<option value="red">Red</option>'+
'		<option value="orange">Orange</option>'+
'		<option value="yellow">Yellow</option>'+
'		<option value="green">Green</option>'+
'		<option value="blue">Blue</option>'+
'		<option value="violet">Violet</option>'+
'		</select></div>'+
''+




'<div class="resettool"><input class="tool" type="button" value="Reset" onclick="resetall();" style="font-size: 8pt;" /></div>');

/*

if(bardictionary=="on")
{
  document.write(''+
'   <div class="tool"><table id="dictionary_table" cellpadding="0px" cellspacing="0px"><tr><td rowspan="2"><input style="float:left;" class="tool" name="word" size="8" /></td>'+
'   <td><a class="tool" style="font-size:9px;margin: 0px 0px 0px 2px;" href="javascript:dictionary();" title="type or drag a word into the box to access the Dictionary">&gt;&nbsp;Dictionary</a></td></tr>'+
'   <tr><td><a class="tool" style="font-size:9px;margin: 0px 0px 0px 2px;" href="javascript:thesaurus();"  title="type or drag a word into the box to access the Thesaurus">&gt;&nbsp;Thesaurus</a></td></tr></table>'+
'   </div>');
}

*/

document.write(''+
//'<!-- help -->'+
//'		<div class="helptool"><a href="http://www.textic.com/textic_toolbar_help.html"><img class="tool" src="'  + cssbaseurl + 'toolbar_css/lib/icon_help.gif" alt="Help"  /></a></div>'+
//'<!-- copyright -->'+

/*
'		<div class="tool" ><a href="#" class="tool" title="&copy; 2005 TEXTIC Ltd.">&copy;</a></div>'+
''+
''+

*/

'</div>'+
'</div>'+
''+
'</form>'+
'<!--End toolbar-->');


//Add stylesheet bar.css
if(browser=="Internet Explorer")
{ 
  if( document.compatMode == 'backCompat' )
    setstyleRB('quirks_ie_bar/bar');
  else
    setstyleRB('ie_bar/bar');
  
}
else if(browser=="Internet Explorer 8")
{
  setstyleRB('ie8_bar/bar');
}
else
{ 
  setstyleRB('other_bar/bar');
}



/*/////////////FUNCTIONS////////////////*/





function dictionary()
{
  theword=document.getElementById('toolbarform').word.value
  thestring="http://dictionary.reference.com/search?q=" + theword;
  open(thestring,"dictionary");void(0);
}


function thesaurus()
{
  theword=document.getElementById('toolbarform').word.value
  thestring="http://thesaurus.reference.com/search?q=" + theword;
  open(thestring,"thesaurus");void(0);
}


function setBarWidth()
{
  //set width of bar depending on whats in it
  if(bardictionary=="off" )
    document.getElementById('toolbar').style.width="672px";
  if(bardictionary=="on" )
    document.getElementById('toolbar').style.width="799px";
}


function gotourl(url) 
{
  location=url;
}


// Add stylesheet to head
function setstyleRB(value)
{
  
  if (value)
  {
    var csshref = cssurl+value+'.css';
    
    try 
    {
      if(document.createStyleSheet) 
      {
        document.createStyleSheet(csshref);
        
      } 
      else 
      {
        var objHead = document.getElementsByTagName('head');
        var objCSS = document.createElement('link');
        objCSS.rel = 'stylesheet'; 
        objCSS.href = csshref;
        objCSS.type = 'text/css';
        objHead[0].appendChild(objCSS);
        
      }
    }
    catch(e)
    {
	    alert (e+'could not add stylesheet')	
    }

  }
  
}


function setChoices()
{
  designc=getCookie('design'); 
  setstyleRB(designc);
  setchoice(document.getElementById('toolbarform').designselect,designc);

  sizec=getCookie('size');
  setzoom(sizec);

  colourc=getCookie('colour');
  setstyleRB(colourc);
  setchoice(document.getElementById('toolbarform').colourselect,colourc);
  
  facec=getCookie('face');
  setstyleRB(facec);
  setchoice(document.getElementById('toolbarform').faceselect,facec);

}


function clearStyles()
{ 
  
  for(i=0;i<(document.styleSheets.length);i++)
    {
      
      thesheet=document.styleSheets[i];
      //reset the stylesheet without reloading the page so we dont lose the zoom value
      if( (thesheet.href.indexOf(cssurl)!=-1) && (thesheet.href.indexOf(cssurl+'ie_bar')) && (thesheet.href.indexOf(cssurl+'other_bar')))
      {
        document.styleSheets[i].href="";
      }
    
    }
    

    if(doctype=='quirks')
      setstyleRB('quirks_ie_bar/bar');
    else
      setstyleRB('ie_bar/bar');    
}


//set choice for dropdown
function setchoice(cobj,cvalue)
{

  for (var i=0;i<cobj.options.length;i++)
  {
    //alert(cobj.options[i].value)
    //alert(cvalue)
    if(cobj.options[i].value==cvalue) 
      cobj.selectedIndex=i;break;
  }
  
}

function setChoice(name,value)
{
  
  setCookie(name,value);
  if (value)
    setstyleRB(value);
  else 
  { 
    if(browser=="Internet Explorer")
      clearStyles();
    else
      location.reload(); 
  }

}

function setzoom(z)
{
  
  var agent=navigator.userAgent.toLowerCase();
  
  if (agent.indexOf("msie")==-1 || agent.indexOf("mac")!=-1 )
  {
  
    //alert(z)
  
    if (z=='2') setstyleRB('medium','size');
    else if (z=='3') setstyleRB('large','size');
    else if (z=='4') setstyleRB('largest','size');
  } 
  else 
  {
    var zp;
    zp=Math.round(z*100);
    document.body.style.zoom=zp+'%';

    //reduce toolbar zoom by whatever percentage it is increased by
    var stay;
    stay=(100/zp)*100+1;
    
    
    //stop js error in ie
    if(stay!='Infinity' && reducebar=="on")
    {
    
      stay=stay+'%'
      document.getElementById('fixbottom').style.height=10;
      //alert(stay)
      document.getElementById('toolbar').style.zoom=stay;
      
      //makes bar 100% width of screen
      //document.getElementById('fixbottom').style.width=zp+'%';
      
      //stops bluring on zoom
      document.getElementById('fixbottom').style.filter = "none";
      
      //alert(zp)
      //make 100% of screen for ie when at 100% zoom!?
      if(zp==100)
      {
        document.getElementById('fixbottom').style.width=document.documentElement.clientWidth;
        document.getElementById('fixbottom').style.width=document.body.clientWidth;
        //document.getElementById('fixbottom').style.width='100%';
      }

    }

  }

}


function zoom(f, browser)
{
  
  var z;
  z=document.getElementById('toolbarform').sizeselect.value;

  var agent=navigator.userAgent.toLowerCase();
  
  if(browser!="Opera")
  {
  
    //if (agent.indexOf("msie")==-1 || agent.indexOf("mac")!=-1 )
    if (agent.indexOf("msie")==-1 || agent.indexOf("mac")!=-1 )
    {
      if (f>1 && z<4) 
        z++;
    
      else if (f<1 && z>1) 
      {
        z--;
        if (z==1) 
          location.reload();
      }
  
    } 
    else z*=f;
    
    //stop zoom below 100%
    if(z>=1)
    {
     
     document.getElementById('toolbarform').sizeselect.value=z;
     setCookie('size',z);
     setzoom(z);
    }

  }
  
}


function resetall()
{

  deleteCookieRB('design');
  setchoice(document.getElementById('toolbarform').designselect,'');
  
  deleteCookieRB('size');
  
  deleteCookieRB('face');
  setchoice(document.getElementById('toolbarform').faceselect,'');
  
  deleteCookieRB('colour');
  setchoice(document.getElementById('toolbarform').colourselect,'');
  
  if(browser=="Internet Explorer")
  {
    document.getElementById('toolbarform').sizeselect.value="1";
    document.body.style.zoom="100%";
    document.getElementById('toolbar').style.zoom="100%";
    clearStyles();
  }
  else
  { 
    document.getElementById('toolbarform').sizeselect.value="1";
    location.reload();
  }
  
}


function setCookie(name, value, expires, path, domain, secure)
{

  //cookie is valid throughout dir's
  path='/';

  if (expires) 
  {
  var expireDate = new Date();
  expireDate.setTime(expireDate.getTime() + 3600000*24*expires);
  }
    
  document.cookie= name + "=" + escape(value) +
  ((expires) ? "; expires=" + expireDate.toGMTString() : "") +
  ((path) ? "; path=" + path : "") +
  ((domain) ? "; domain=" + domain : "") +
  ((secure) ? "; secure" : "");

}


function getCookie(name)
{

  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);

  if (begin == -1)
  {
    begin = dc.indexOf(prefix);
    
    if (begin != 0) 
      return null;
  }
  else
  {
    begin += 2;
  }
  
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
  {
    end = dc.length;
  }
  
  return unescape(dc.substring(begin + prefix.length, end));

}


function deleteCookieRB(name, path, domain)
{
  
  //cookie is valid throughout dir's
  path='/';
  
  if (getCookie(name))
  {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
  
}

//keep toolbar 100% of screen width when resized
function resize(){
  document.getElementById('fixbottom').style.width='100%';
}



function adjustMargin()
{
    bodybottommargin=window.document.body.style.getAttribute('marginBottom');
    bodybottommargin+=35;
    window.document.body.style.setAttribute('marginBottom', bodybottommargin);
}


//Add stylesheets and set dropdown selections stored in cookies

setChoices();

//adjustMargin();

//setBarWidth();

/*
function displayToolbar(cssbaseurl)
{
  try
  {
    toolHTML(cssbaseurl)
  }
  catch(e)
  {
    alert(e)
    setTimeout("displayToolbar(cssbaseurl)", 200)
  }
  
}

toolbarHTML(cssbaseurl)
*/

//window.onload=function init(){
//  document.getElementById('fixbottom').style.filter = "none";
//}

//keep toolbar 100% of screen width
document.getElementById('fixbottom').width='100%';
