/*-------------------------- BROWSER DETECTION --------------------------*/

function dom_browser() {
	// browser identification based on dom capabilities
	this.myNav = this.navigator;
	this.version = this.navigator.appVersion;
	this.name = this.navigator.appName;
	this.userAgt = this.navigator.userAgent;
	this.ns4 = (document.layers) ? true : false;
	this.ns6 = (this.navigator.userAgent.indexOf("Netscape6") != -1) ? true : false;
	this.dom = (document.getElementById) ? true : false;
	this.ie4 = (document.all) ? true : false;
	this.mac = (this.version.indexOf("Mac") != -1) ? true : false;
	this.ie = (this.version.indexOf("MSIE") != -1) ? true : false;
	this.windows = (this.version.indexOf("Windows") != -1) ? true : false;
	this.hasPlugins = (this.navigator.plugins) ? true : false;
	this.ie6 = (this.version.indexOf("MSIE") != -1 && this.version.indexOf("6") != -1) ? true : false; 
	
	this.ie55 = (this.version.indexOf("MSIE 5.5") != -1) ? true : false;
	this.ie5 = (this.version.indexOf("MSIE 5.01") != -1) ? true : false;
	this.ns = (this.userAgt.indexOf("Netscape") != -1) ? true : false;
	this.ff = (this.userAgt.indexOf("Firefox") != -1) ? true : false;
	this.safari = (this.userAgt.indexOf("Safari") != -1) ? true : false;
}

dom_browser();


// function to set default text to input fields
function setValue(myObj) { // when users click on user and keyword fields, default text disappears
	if(myObj.value == "Enter keyword(s)" || myObj.value == "") {
		myObj.value = "";
	}
}	
function checkValue(myObj,defaultValue) { // if user has not entered any value, default value is restored
	if(myObj.value == "") {
		myObj.value = defaultValue;
	}
}


/*-------------------------- PRINT AND SEND TO FRIEND --------------------------*/

// opens up the send to friend page in a popup window...
function openPage(myPage) {
	switch (myPage) {
		case "s2fPage":
			myS2FWin = window.open('sendToFriend.aspx?Page='+ document.URL,'myS2FWin','width=550,height=600,scrollbars=yes,resizeable=no,menubar=no,statusbar=no');
			myS2FWin.focus();
			break;
		default:
			myPrintWin = window.open(myPage,'myPrintWin','width=656,height=500,scrollbars=yes,resizeable=no,menubar=no,statusbar=no');
			myPrintWin.focus();
			break;
	}
}

// brings up the print dialog box when clicking the print icon...
function printPage() {
	this.print();
}

/*-------------------------- INCREASE / DECREASE FONT SIZE --------------------------*/

// on page load... set initial font size...
function setupFontSize() {
	try
	{
		myObj = document.body;
		myCookie = getCookie("DUKEFontSize");
		if(myObj != null && typeof(myObj) != "undefined" && myCookie == null) {
		// if object exists and cookie not set then...
		myObj.style.fontSize = "0.8em";
		} else if(myObj != null && typeof(myObj) != "undefined") {
		// if object exists and cookie is set...
		myObj.style.fontSize = myCookie;
		}
	}
	catch(err){}
}

// set cookie for storing document font size...
function setCookie(cName,cValue,cExpiryDays) {
 var expDate = new Date();
 expDate.setDate(expDate.getDate()+cExpiryDays);
 document.cookie = cName + "=" + escape(cValue) + ((cExpiryDays == null) ? "" : ";expires=" + expDate);
}

// get value of cookie if it exists...
function getCookie(cName) {
 if(document.cookie.length > 0) { // if there are cookies...
  cStart = document.cookie.indexOf(cName + "="); // get index of where cookie value starts...
  if(cStart != -1) {
   cStart = cStart + cName.length + 1;
   cEnd = document.cookie.indexOf(";",cStart);
   if(cEnd == -1) cEnd = document.cookie.length;
   return unescape(document.cookie.substring(cStart,cEnd));
  }
 }
 return null;
}

// change font size.. increase or decrease font size...
function changeFont(myDir) {
 myObj = document.body;
 if(myObj != null && typeof(myObj) != "undefined") {
  tempFont = parseFloat(myObj.style.fontSize);
  if(myDir == "increase" && tempFont < 1) {
   myObj.style.fontSize = (tempFont + 0.1) + "em";
  } else if(myDir == "decrease" && tempFont > 0.5) {
   myObj.style.fontSize = (tempFont - 0.1) + "em";
  } else {
   // don't change font...
  }
  // set cookie to remember font size for 30 days..
  setCookie("DUKEFontSize",myObj.style.fontSize,30); 
 }
}


// Clear text input values
var swap_text_boxes = [];
$(document).ready(function() {
    jQuery.each($("input[type='text'].autoclear"), function() {
        swap_text_boxes[$(this).attr('id')] = $(this).attr('value');
        $(this).bind('focus', function() {
            if ($(this).val() == swap_text_boxes[$(this).attr('id')]) {
                $(this).val('');
            }
        });
        $(this).bind('blur', function() {
            if ($(this).val() == '') {
                $(this).val(swap_text_boxes[$(this).attr('id')]);
            }
        });
    });
});