//start browser detection
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
//end browser detection

//stuff for setting IEMac styles
function addIEMacStyle(){
	var file="/researchnet/cov_uni_iemac.css";
	var fileref = "";
	fileref=document.createElement("link")
	fileref.setAttribute("rel", "stylesheet");
	fileref.setAttribute("type", "text/css");
	fileref.setAttribute("href", file);

	var headTags = document.getElementsByTagName("head");
	headTags.item(0).appendChild(fileref);
	alert(headTags.item(0).lastChild);


}

function setClassName(objId, className) {
    	document.getElementById(objId).className = className;
}

function ieMacStyle(x){
	if (BrowserDetect.browser == "Explorer" && BrowserDetect.OS == "Mac"){
		//change the various style setting for IE MAC
		return " iemacpage"+x;
	}else{
		return "";
	}

}

function switchPage(pageNumber){
	for(var x=1;x<=3;x++){
		if (x==pageNumber){
			//make this page visible
			//select the tab
			setClassName("page" + x + "tablink","selected");
			setClassName("page" + x,"page"+x+" pageVisible"+ieMacStyle(x));
		}else{
			//hide the others
			setClassName("page" + x + "tablink","");
			setClassName("page" + x,"page"+x+" pagehidden"+ieMacStyle(x));
		}
	}
}

function ieMacStyleInit(){

	//if the the browser is IE on the mac set the class values so the size of the column is correct for
	//IE on the mac
	if (BrowserDetect.browser == "Explorer" && BrowserDetect.OS == "Mac"){
		switchPage(1);
	}
}
//end stuff for IEMAC style

//debug window
// Show the debug window
function showDebug() {
  window.top.debugWindow =
      window.open("",
                  "Debug",
                  "left=0,top=0,width=300,height=700,scrollbars=yes,"
                  +"status=yes,resizable=yes");
  window.top.debugWindow.opener = self;
  // open the document for writing
  window.top.debugWindow.document.open();
  window.top.debugWindow.document.write(
      "<html><head><title>Debug Window</title></head><body><pre>\n");
}

function debug(text) {
  if (window.top.debugWindow && ! window.top.debugWindow.closed) {
    window.top.debugWindow.document.write(text+"\n");
  }
}

// If the debug window exists, then close it
function hideDebug() {
  if (window.top.debugWindow && ! window.top.debugWindow.closed) {
    window.top.debugWindow.close();
    window.top.debugWindow = null;
  }
}
//end debug window

function ajaxFunction()
  {
  var xmlHttp;
  try
    {
    // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
    }
  catch (e)
    {
    // Internet Explorer
    try
      {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
      }
    catch (e)
      {
      try
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      catch (e)
        {
        alert("Your browser does not support AJAX!");
        return false;
        }
      }
    }
    
    return xmlHttp;
  }
  
  function logSkypeUser(userName){
		xmlHttp = ajaxFunction();
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
	        {
    		    if (xmlHttp.status == 200) {
//    		    	alert(xmlHttp.responseText);
					var response = xmlHttp.responseText;
                } else {
  //                  alert('There was a problem with the request.');
  					var response = "no response";
                }
        	}
      	}
	    xmlHttp.open("GET","/jsp/logSkype.jsp?userName=" + userName,true);
    	xmlHttp.send(null);
		
	}
	
	function setTimeoutLogSkypeUser(userName){
		setTimeout("logSkypeUser(\""+userName+"\")",0);
	}