//var urlPath = "http://www.auburn.edu/cosam/collections/arboretum";
var urlPath = "http://www.auburn.edu/academic/science_math/cosam/collections/arboretum";
now = new Date;
var curMonth = now.getUTCMonth();
var current_year = now.getFullYear();
curMonth++;

// Current Hack - 
curMonth = "3";
getSifrSheet();


function getFlowerTextInfo(num) {
	//descript = '<span class="randomtexttitle">'+ flowersname[num] + '</span><br><em>'+ flowersdescription[num] +'</em>';
	//descript = '<em>'+ flowersdescription[num] +'</em>'; - uses italics
	descript = flowersdescription[num];
	return descript;
}

function getFlowerImageInfo(num) {
	descript = ''+ flowersdescription[num] +'';
	return descript;
}

function getFlowerImage(num) {
	return '<img src="'+ urlPath+'/images/rotating/'+flowersimage[num]+'" width="429" height="159" alt="'+ getFlowerImageInfo(num) +'">';
}

var now = new Date();
var doAlerts=false;

function changeSheets(whichSheet){
  if (setCookie("arborstyle", whichSheet, now, "/")) {
	  if (doAlerts) alert ("Cookie set");
  } else {
	  	if (doAlerts) alert("Cookie not set");
  }
  whichSheet=whichSheet-1;
  
  if(document.styleSheets){
    var c = document.styleSheets.length;
    if (doAlerts) alert('Change to Style '+(whichSheet+1));
    for(var i=0;i<c;i++){
      if(i!=whichSheet){
        document.styleSheets[i].disabled=true;
      }else{
        document.styleSheets[i].disabled=false;
      }
    }
  }
}


function initStyle(){
	// fix the bug in Navigator 2.0, Macintosh
	fixDate(now);
	// cookie expires in one year (actually, 365 days)
	// 365 days in a year
	// 24 hours in a day
	// 60 minutes in an hour
	// 60 seconds in a minute
	// 1000 milliseconds in a second
	now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
	var style = getCookie("arborstyle");
	// if the cookie wasn't found, this is your first visit
	if (style) {
	  // increment the counter
	  changeSheets(parseInt(style));
	} else {
		changeSheets(7);
	}	
}
// name - name of the cookie
// value - value of the cookie
// [expires] - expiration date of the cookie (defaults to end of current session)
// [path] - path for which the cookie is valid (defaults to path of calling document)
// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
// * an argument defaults when it is assigned null as a placeholder
// * a null placeholder is not required for trailing omitted arguments
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  if (document.cookie = curCookie) {
	  checkvalue = getCookie(name);
	  if (checkvalue == value) {
  		  	return true;
	  }
	}
	return false;
}

// name - name of the desired cookie
// * return string containing value of specified cookie or null if cookie does not exist
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

// name - name of the cookie
// [path] - path of the cookie (must be same as path used to create cookie)
// [domain] - domain of the cookie (must be same as domain used to create cookie)
// * path and domain default if assigned null or omitted if no explicit argument proceeds
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" + 
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function getSifrSheet() {
	document.write("<style type=\"text/css\">.sIFR-flash {visibility: visible !important;margin: 0;} .sIFR-replaced {visibility: visible !important;} span.sIFR-alternate {position: absolute;left: 0;top: 0;width: 0;height: 0;display: block;overflow: hidden;letter-spacing: 0;} .sIFR-hasFlash .headline {visibility: hidden; font-size: 20px;} .sIFR-hasFlash .subheading {visibility: hidden; font-size: 15px;}</style>");
	document.write("<script language=\"javascript\" type=\"text/javascript\" src=\""+ urlPath +"/site/sifr/ss"+curMonth+".js\"></script>");
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}

function changeSelected(settle) {
	styleUse = settle.options[settle.selectedIndex].value;
	changeSheets(styleUse);
}


function emailPage() {
	var page = escape(location);
	var mailPage = urlPath+'/tools/email.php?url=' + page;
	
	var newWindow;
	newWindow=window.open(mailPage,'_vEmail','scrollbars=yes,width=500,height=450');
	newWindow.focus();
}

function printPage() {
	var page = escape(location);
	var printPage = urlPath+'/tools/print.php?url=' + page;
				
	var newWindow;
	newWindow=window.open(printPage,'_printable','scrollbars=yes,width=600,height=400');
	newWindow.focus();
}


function bookmarkPage() {
	var page = escape(location);
	var bookmarkPage = urlPath+'/tools/bookmark.php?url=' + page;
	self.location.href=bookmarkPage;
}


function selectNav(pageLoc, pageLink, noGo) {
	goLoc = pageLoc.options[pageLoc.selectedIndex].value;
	
	if (goLoc != "" && goLoc != "na" && goLoc != noGo) {
		window.location.href = pageLink + goLoc;
	}
}


// Added the following check functions for the Join Friends of the Arboretum Page
function checkvalue(formfield, message) {
	if (formfield.value == "") {
		alert (message);
		formfield.focus();
		return false;
	}
	return true;
}

function checkemailaddress(formfield, message) {
	var str = formfield.value;
	var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	if (str == "") {
		alert(message);
		formfield.focus();
		return false;
	} else if (!str.match(re)) {
		alert(message);
		formfield.focus();
		return false;
	} else {
		return true;
	}
}