function writeDate() {
	document.write(new Date().getFullYear());
}

function writeUpdate() {
	var d = new Date();
	if (d.toLocaleDateString) { 
	  document.writeln(d.toLocaleDateString(document.lastModified));
	} else { 
	  document.writeln(document.lastModified);   
	}
}

function popup(page) {
	popUpWin = window.open(page,"PopWin","scrollbars=yes,resizable=yes,top=0,left=0,width=270,height=400");
}

function popupSurvey(page) {
	popUpWin = window.open(page,"PopWin","scrollbars=yes,resizable=yes,top=0,left=0,width=800,height=500");
}


function bookmark() {
  if (document.all) {
	window.external.AddFavorite(location.href, document.title);
  } else {
	alert("Your web browser does not support this feature.");
  }
}

function email() {
	page = "/email.cfm?refer=" + location.href;
	emailWin = window.open(page,"EmailWin","location=no,menubar=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no,width=520,height=650");
}

function printPage() {
    window.print();
}

function convertSpaces(str) {
  var out = "", flag = 0;
  for (i = 0; i < str.length; i++) {
    if (str.charAt(i) != "_") {
      out += str.charAt(i);
      flag = 0;
    } else {
      if (flag == 0) {
        out += " ";
        flag = 1;
      }
    }
  }
  return out;
}

function checkrequired(which) {
  var pass=true;
  if (document.images) {
    for (i=0; i < which.length; i++) {
      var tempobj=which.elements[i];
      if (tempobj.name.substring(0,9)=="required_") {
        if (((tempobj.type=="text"||tempobj.type=="textarea")&&
          tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
          tempobj.selectedIndex==0)) {
          pass=false;
          break;
        }
      }
    }
  }
  if (!pass) {
    shortFieldName = tempobj.name.substring(9,tempobj.name.length).toUpperCase();
    alert("The "+convertSpaces(shortFieldName)+" field is required. Please enter the "
		+convertSpaces(shortFieldName.toLowerCase())+" and try again.");
    return false;
  } else {
    return true;
  }
}

// Place cursor (focus) into the 1st appropriate form field
// - does not include checkboxes or radio buttons
function placeFocus() {
	if (document.forms.length > 0) {
		var field = document.forms[0];
		for (i = 0; i < field.length; i++) {
			if ((field.elements[i].type == "text") 
				|| (field.elements[i].type == "textarea") 
				|| (field.elements[i].type == "password") 
				|| (field.elements[i].type.toString().charAt(0) == "s")
				&& (field.elements[i].type != "submit")) {
				document.forms[0].elements[i].focus();
				break;
			}//if
		}//for
	}//if
}//placeFocus

function winOpen(theURL,winName,features) 
{ 
winName = window.open(theURL,winName,features); 
if(winName == null || winName.closed){window.open(theURL,winName,features);} 
else{winName.location.href = theURL;} 
if (!winName.closed) 
winName.focus(); 
}

$(document).ready(function(){
  var storiesTotal = $("#didyouknow").children();
  var storiesCurrent = Math.round(Math.random() * storiesTotal.length);
  $("#didyouknow li:eq(" + storiesCurrent + ")").addClass("shown");
});

