// Javascript Lib File

//browser = "";


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

if (checkIt('konqueror'))
{
	browser = "Konqueror";
	OS = "Linux";
}
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 = "IE"
else if (!checkIt('compatible'))
{
	browser = "NN"
	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";
}

//alert(browser);

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


//this only works in IE
function getSelection (textInput) {
  content = new Object();
  if (browser == "IE") {
    var selectedRange = document.selection.createRange();
    if (selectedRange.parentElement() == textInput) {
      content.isSelected = true;
      content.selected = selectedRange.duplicate();
      content.beforeSelection = selectedRange.duplicate();
      content.beforeSelection.moveToElementText(textInput);
      content.beforeSelection.setEndPoint('EndToStart', selectedRange);
      content.afterSelection = selectedRange.duplicate();
      content.afterSelection.moveToElementText(textInput);
      content.afterSelection.setEndPoint('StartToEnd', content.selected);
    }
    else {
      content.isSelected = false;
      content.beforeSelection = textInput.createTextRange();
    }
  }
  else if(browser == "NN" || browser == "Safari")
  { // put the mozilla code here
    content = null;

  }
  return content;
}

function textEffect (textInput, tag)
{
  if(browser == "IE")
  {
    content = getSelection (textInput);
	if (content && content.isSelected)
	{
	  content.beforeSelection.text = content.beforeSelection.text + '<' + tag + '>';
	  content.afterSelection.text = '</' + tag + '>' + content.afterSelection.text;
	}
  }
  else if(browser == "NN" || browser == "Safari")
  {
    //textInput = document.getElementById(textInput.id);
    textInput.value = textInput.value.substring(0,textInput.selectionStart) + '<' + tag + '>' + textInput.value.substring(textInput.selectionStart,textInput.selectionEnd) + '</' + tag + '>' + textInput.value.substring(textInput.selectionEnd,textInput.value.length);
  }
}

function makeLink(textInput)
{
  if(browser == "IE")
  {
    content = getSelection (textInput);
	href = 'http://' + getLink();
	if (content && content.isSelected)
	{
	  content.beforeSelection.text = content.beforeSelection.text + '<a href = "' + href + '">';
	  content.afterSelection.text = '</a>' + content.afterSelection.text;
	}
  }
  else if(browser == "NN" || browser == "Safari")
  {
	href = 'http://' + getLink();
    textInput.value = textInput.value.substring(0,textInput.selectionStart) + '<a href = "' + href + '">' + textInput.value.substring(textInput.selectionStart,textInput.selectionEnd) + '</a>' + textInput.value.substring(textInput.selectionEnd,textInput.value.length);
  }
}

function getLink()
{	
  return prompt('Type in the address of your link. Do not put the http://');
}

function makeEmail(textInput)
{
  if(browser == "IE")
  {
    content = getSelection (textInput);
	href = 'mailto:' + getEmailAddress();
	if (content && content.isSelected)
	{
	  content.beforeSelection.text = content.beforeSelection.text + '<a href = "' + href + '">';
	  content.afterSelection.text = '</a>' + content.afterSelection.text;
	}
  }
  else if(browser == "NN" || browser == "Safari")
  {
	href = 'mailto:' + getEmailAddress();
    textInput.value = textInput.value.substring(0,textInput.selectionStart) + '<a href = "' + href + '">' + textInput.value.substring(textInput.selectionStart,textInput.selectionEnd) + '</a>' + textInput.value.substring(textInput.selectionEnd,textInput.value.length);
  }
}

function getEmailAddress()
{	
  return prompt('Type in the email address you want to link. Do not put the mailto');
}

currentDiv = "";

topLevel = 0;
blog = 1;
upload = 2;
divSet = new Array();
divSet[blog] = "";
divSet[upload] = "";

function showDiv(divName)
{
  divName += "";
  if(browser == "IE")
  {
	eval(divName).style.display = "block";
  }
  if(browser == "NN" || browser == "Safari")
  {
	document.getElementById(divName).style.display = 'block';
  }
}

function hideDiv(divName)
{
  divName += "";
  if(browser == "IE")
  {
	eval(divName).style.display = "none";
  }
  if(browser == "NN" || browser == "Safari")
  {
	document.getElementById(divName).style.display = 'none';
  }
}

/*
Notes on useage of toggleShowDivExt and toggleShowDiv:

If your div ID has any of the following it will break in IE -
A space. If you need to have a space for formatting purposes use the underscore ("_")
A number. Don't use numbers in your div ids.
*/

function toggleShowDivExt(divName, hideOther, divSetID)
{  
  if(browser == "IE")
  {
	if(eval(divName).style.display == "none")
   	{
	  if(hideOther && divSet[divSetID])
	  {
	    eval(divSet[divSetID]).style.display = "none";
	  }
	  eval(divName).style.display = "block";	  
	  divSet[divSetID] = divName;
      return;
	}
	else
	{
      eval(divName).style.display = "none";
	  return;
	}
  }
  if(browser == "NN" || "Safari")
  {
    if(document.getElementById(divName).style.display == 'none')
	{
	  if(hideOther && divSet[divSetID])
	  {
	    document.getElementById(divSet[divSetID]).style.display = 'none';
     }
	  document.getElementById(divName).style.display = 'block';
	  divSet[divSetID] = divName;
	  return;
	}
	document.getElementById(divName).style.display = 'none';
  }
}

function toggleShowDiv(divName, hideOther)
{  
  if(browser == "IE")
  {
    if(eval(divName).style.display == "none")
   	{
     if(currentDiv && hideOther)
     {	 
	    eval(currentDiv).style.display = "none";
	    currentDiv = "";
     }
	  eval(divName).style.display = "block";
	  if(hideOther)
	  {
       currentDiv = divName;
	  }
     return;
	}
	eval(divName).style.display = "none";
  }
  if(browser == "NN" || browser == "Safari")
  {
    if(document.getElementById(divName).style.display == 'none')
	{
	  if(currentDiv && hideOther)
	  {
	    document.getElementById(currentDiv).style.display = 'none';
	    currentDiv = "";
      }
	  document.getElementById(divName).style.display = 'block';
	  if(hideOther)
	  {
       currentDiv = divName;
	  }
	  return;
	}
	document.getElementById(divName).style.display = 'none';
  }
}
function switchImage(imgName, imgSrc) 
{
  if (document.images)
  {
    if(imgSrc != "none")
    {
      document.images[imgName].src = "../../images/blogImages/" + imgSrc;
    }
  }
}

function imgSwap(imgName, imgSrc) 
{
  if (document.images)
  {
    if(imgSrc != "none")
    {
      document.images[imgName].src = imgSrc;
    }
  }
}

// www.sean.co.uk

function pausecomp(millis)
{
date = new Date();
var curDate = null;

do { var curDate = new Date(); }
while((curDate - date) < millis);
} 