/* Focus Clear */

$(document).ready(function() {

	function focusclear(x) {
		if(x.value == x.defaultValue) {
			x.value = "";
		}
	};
	
	$("#subscribe-text").focus(function() {
		focusclear(this);
	});

});


/* Bookmark function */
function bookmark() { 
var pagename = "Anacostia Watershed Society"; 

if (document.all) window.external.AddFavorite(bookmarkurl,pagename);
else alert('Press CTRL-D (Command-D on a Mac) to add a bookmark to:\n"'+bookmarkurl+'".');
} 


/* Share with a friend function */
function share(page) {
window.open("http://sps.understandsurgery.com/includes/share-popup.asp?page="+page,"Share","HEIGHT=600,WIDTH=600,TOP=0,LEFT=0,resizable=false,scrollbars=false"); 
}



/* Print function */
function printpage(){
   if(window.print) window.print();
   else{
     if(agt.indexOf("mac") != -1)alert("To print this page press Command-P.")
     else alert("To print this page press Control-P.")
   }
}




/* text size change functions */
function setActiveStyleSheet(title, home) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  imageswitch(title, home);
  createCookie("style", title, 365);
}

function imageswitch(title,home) {
   var path;
   if (home=="home"){
   path="";}
   else {
   path="../";}
   
   switch(title) {
  case 'small':
  	document.images.small.src = path + "images/textsize-small-on.gif";
  	document.images.med.src = path + "images/textsize-med-off.gif";
  	document.images.large.src = path + "images/textsize-large-off.gif";
  	break
  case 'med':
    document.images.small.src = path + "images/textsize-small-off.gif";
  	document.images.med.src = path + "images/textsize-med-on.gif";
  	document.images.large.src = path + "images/textsize-large-off.gif";
  	break
  case 'large':
    document.images.small.src = path + "images/textsize-small-off.gif";
  	document.images.med.src = path + "images/textsize-med-off.gif";
  	document.images.large.src = path + "images/textsize-large-on.gif";
  	break
  }
}

function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  return null;
}

function callCookie(home) {  
  var cookie = readCookie("style");
  var title = cookie ? cookie : getPreferredStyleSheet();
  setActiveStyleSheet(title, home);
  }


function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}


var cookie = readCookie("style");
var title = cookie ? cookie : getPreferredStyleSheet();
//setActiveStyleSheet(title);





