
// JavaScript Document

function ira() { 
	location.href = document.jumpto.select.options[document.jumpto.select.selectedIndex].value;
}

function search(f) {
	f.action = 'http://www.google.com/search';
}

// Checks that FTE value is valid. If not an alert occurs.
function validateFTE() {
	if (isNumberic(Calc.FTE.value) == false) {
		return false;
	}
	if (Calc.FTE.value > 1.0 || Calc.FTE.value < 0.01) {
		alert("Please keep the value of the Full-time equivalency between 0.01 and 1.0");
		return false;
	}
	return true;
}

// Checks that Salary value is valid. If not an alert occurs.
function validateSalary() {
	if (isNumberic(Calc.Salary.value) == false) {
		return false;
	}
	if (Calc.Salary.value < 0) {
		alert("Please keep the value of the Salary as a positive number");
		return false;
	}
	return true;
}

// Returns true if in the input is a valid number, false otherwise
function isNumberic(sText) {
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++) { 
		Char = sText.charAt(i);
		if (Char == "-" && i == 0) {
			IsNumber = true;
		} else if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	if (IsNumber == false) {
		alert('Please enter only numberic characters in the FTE and Salary fields.');
	}
	return IsNumber;
}

// Puts commas every third space on a number
function addCommas(nStr){
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(d+)(d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

// Drops all the commas in a string. Used for when math is required and commas get in the way
function dropCommas(nStr) {
	while (nStr.indexOf(",") > -1) {
		nStr = nStr.replace(",","");
	}
	return nStr;
}

// Calculates the estimate
function Calculate() {
	if (navigator.appName != "Microsoft Internet Explorer") {
		Calc = document.Calc;
	}
	Calc.Salary.value = dropCommas(Calc.Salary.value);
	// checks for validation
	if ( !validateFTE() || !validateSalary() ) {
		Calc.Salary.value = addCommas(Calc.Salary.value);
		return false;
	}
	// The math
	if (Calc.HIT.value == 'Family') {
		Calc.HITOut.value = Math.round(835.98 * Calc.FTE.value * 12);
	} else if (Calc.HIT.value == 'Individual') {
		Calc.HITOut.value = Math.round(399.26 * Calc.FTE.value * 12);
	} else {
		Calc.HITOut.value = '0';
	}
	
	if (Calc.LIT.value == 'Yes' ) {
		Calc.LITOut.value = Math.round((Calc.Salary.value / 1000) * 1.5 * 0.1208 * Calc.FTE.value * 12);
	} else {
		Calc.LITOut.value = '0';
	}
	
	if (Calc.Tuition.value == 'In-State Undergraduate') {
		Calc.TuitionOut.value = '2212';
	} else if (Calc.Tuition.value == 'In-State Graduate') {
		Calc.TuitionOut.value = '5376';
	} else {
		Calc.TuitionOut.value = '0';
	}
	
	if ((Calc.Salary.value * 0.062) > (106800 * 0.062)) {
		Calc.SSTaxOut.value = Math.round(106800 * 0.062);
	} else {
		Calc.SSTaxOut.value = Math.round(Calc.Salary.value * 0.062);
	}
		
	Calc.MedOut.value = Math.round(Calc.Salary.value * 0.0145);
	
	var pos;
	if (Calc.Position.value == 'Staff') {
		pos = 0.0985;
	} else if (Calc.Position.value == 'Law Enforcement Officer') {
		pos = 0.2092;
	} else if (Calc.Position.value == 'null') {
		pos = 0;
	} else{
		pos = 0.1043;
	}
	
	
	if (Calc.Salary.value >= 230000) {
	Calc.RetOut.value = Math.round(pos * 230000);
	} else {
	Calc.RetOut.value = Math.round(pos * Calc.Salary.value);
	}
	
		
	Calc.WorkCompOut.value = Calc.UnEmpOut.value = Math.round(0.002 * Calc.Salary.value);
	
	Calc.TotalMonComp.value = (
	parseInt(Calc.HITOut.value) + 
	parseInt(Calc.LITOut.value) + 
	parseInt(Calc.TuitionOut.value) + 
	parseInt(Calc.SSTaxOut.value) + 
	parseInt(Calc.MedOut.value) + 
	parseInt(Calc.RetOut.value) + 
	parseInt(Calc.WorkCompOut.value) + 
	parseInt(Calc.UnEmpOut.value) +
	parseInt(Calc.Salary.value)
	);
	var x;
	if (Calc.Position.value == 'Staff' || Calc.Position.value == 'Law Enforcement Officer') {
		x = 5*26.1;
	}
	else if (Calc.Position.value == 'Administrative' || Calc.Position.value == '12-Month Faculty') {
		x = 7* 26.1;
	}
	else {
		x = 0;
	}
	
	Calc.VacLeaveIn.value = Math.round(x / 8 * Calc.FTE.value);
	
	if (Calc.Position.value != 'null') {
		Calc.SickLeaveIn.value = Math.round(4 * 26.1 / 8 * Calc.FTE.value);
		Calc.HoliLeaveIn.value = Math.round(11 * Calc.FTE.value);
	} else {
		Calc.SickLeaveIn.value = 0;
		Calc.HoliLeaveIn.value = 0;
	}
	
	Calc.VacLeaveOut.value = Math.round((Calc.Salary.value / 2088) * Calc.VacLeaveIn.value *  Calc.FTE.value * 8);
	
	if (Calc.Position.value == '9-Month Faculty') {
		x = (1560 * Calc.FTE.value);
	} else {
		x = (2088 * Calc.FTE.value);
	}
	Calc.SickLeaveOut.value = Math.round(Calc.Salary.value / x * Calc.SickLeaveIn.value * 8 * Calc.FTE.value);

	Calc.HoliLeaveOut.value = Math.round(Calc.Salary.value / x * Calc.HoliLeaveIn.value * 8);
	
	Calc.TotalNonComp.value = (
	parseInt(Calc.VacLeaveOut.value) + 
	parseInt(Calc.SickLeaveOut.value) + 
	parseInt(Calc.HoliLeaveOut.value)
	);
	
	Calc.TotalComp.value = (
	parseInt(Calc.TotalNonComp.value) + 
	parseInt(Calc.TotalMonComp.value)
	);
	
	// Puts the commas on the results
	Calc.Salary.value = addCommas(Calc.Salary.value);
	Calc.HITOut.value = addCommas(Calc.HITOut.value);
	Calc.LITOut.value = addCommas(Calc.LITOut.value);
	Calc.TuitionOut.value = addCommas(Calc.TuitionOut.value);
	Calc.SSTaxOut.value = addCommas(Calc.SSTaxOut.value);
	Calc.MedOut.value = addCommas(Calc.MedOut.value);
	Calc.RetOut.value = addCommas(Calc.RetOut.value);
	Calc.UnEmpOut.value = addCommas(Calc.UnEmpOut.value);
	Calc.WorkCompOut.value = addCommas(Calc.WorkCompOut.value);
	Calc.TotalMonComp.value = addCommas(Calc.TotalMonComp.value);
	Calc.VacLeaveOut.value = addCommas(Calc.VacLeaveOut.value);
	Calc.SickLeaveOut.value = addCommas(Calc.SickLeaveOut.value);
	Calc.HoliLeaveOut.value = addCommas(Calc.HoliLeaveOut.value);
	Calc.TotalNonComp.value = addCommas(Calc.TotalNonComp.value);	
	Calc.TotalComp.value = addCommas(Calc.TotalComp.value);
	
	return true;
}

function rssfeedsetup(){
var feedpointer=new google.feeds.Feed(feedurl) //Google Feed API method
feedpointer.setNumEntries(feedlimit) //Google Feed API method
feedpointer.load(displayfeed) //Google Feed API method
}

function displayfeed(result){
if (!result.error){
var thefeeds=result.feed.entries
for (var i=0; i<thefeeds.length; i++)
rssoutput+="<li><a href='" + thefeeds[i].link + "'>" + thefeeds[i].title + "</a><br/>" + thefeeds[i].contentSnippet + "</li>"
rssoutput+="</ul>"
feedcontainer.innerHTML=rssoutput
}
else
alert("Error fetching feeds!")
}

window.onload=function(){
rssfeedsetup()
}

//Style Sheet Switcher version 1.1 Oct 10th, 2006
//Author: Dynamic Drive: http://www.dynamicdrive.com
//Usage terms: http://www.dynamicdrive.com/notice.htm

var manual_or_random="manual" //"manual" or "random"
var randomsetting="3 days" //"eachtime", "sessiononly", or "x days (replace x with desired integer)". Only applicable if mode is random.

//////No need to edit beyond here//////////////

function getCookie(Name) { 
var re=new RegExp(Name+"=[^;]+", "i"); //construct RE to search for target name/value pair
if (document.cookie.match(re)) //if cookie found
return document.cookie.match(re)[0].split("=")[1] //return its value
return null
}

function setCookie(name, value, days) {
var expireDate = new Date()
//set "expstring" to either future or past date, to set or delete cookie, respectively
var expstring=(typeof days!="undefined")? expireDate.setDate(expireDate.getDate()+parseInt(days)) : expireDate.setDate(expireDate.getDate()-5)
document.cookie = name+"="+value+"; expires="+expireDate.toGMTString()+"; path=/";
}

function deleteCookie(name){
setCookie(name, "moot")
}


function setStylesheet(title, randomize){ //Main stylesheet switcher function. Second parameter if defined causes a random alternate stylesheet (including none) to be enabled
var i, cacheobj, altsheets=[""]
for(i=0; (cacheobj=document.getElementsByTagName("link")[i]); i++) {
if(cacheobj.getAttribute("rel").toLowerCase()=="alternate stylesheet" && cacheobj.getAttribute("title")) { //if this is an alternate stylesheet with title
cacheobj.disabled = true
altsheets.push(cacheobj) //store reference to alt stylesheets inside array
if(cacheobj.getAttribute("title") == title) //enable alternate stylesheet with title that matches parameter
cacheobj.disabled = false //enable chosen style sheet
}
}
if (typeof randomize!="undefined"){ //if second paramter is defined, randomly enable an alt style sheet (includes non)
var randomnumber=Math.floor(Math.random()*altsheets.length)
altsheets[randomnumber].disabled=false
}
return (typeof randomize!="undefined" && altsheets[randomnumber]!="")? altsheets[randomnumber].getAttribute("title") : "" //if in "random" mode, return "title" of randomly enabled alt stylesheet
}

function chooseStyle(styletitle, days){ //Interface function to switch style sheets plus save "title" attr of selected stylesheet to cookie
if (document.getElementById){
setStylesheet(styletitle)
setCookie("mysheet", styletitle, days)
}
}

function indicateSelected(element){ //Optional function that shows which style sheet is currently selected within group of radio buttons or select menu
if (selectedtitle!=null && (element.type==undefined || element.type=="select-one")){ //if element is a radio button or select menu
var element=(element.type=="select-one") ? element.options : element
for (var i=0; i<element.length; i++){
if (element[i].value==selectedtitle){ //if match found between form element value and cookie value
if (element[i].tagName=="OPTION") //if this is a select menu
element[i].selected=true
else //else if it's a radio button
element[i].checked=true
break
}
}
}
}

if (manual_or_random=="manual"){ //IF MANUAL MODE
var selectedtitle=getCookie("mysheet")
if (document.getElementById && selectedtitle!=null) //load user chosen style sheet from cookie if there is one stored
setStylesheet(selectedtitle)
}
else if (manual_or_random=="random"){ //IF AUTO RANDOM MODE
if (randomsetting=="eachtime")
setStylesheet("", "random")
else if (randomsetting=="sessiononly"){ //if "sessiononly" setting
if (getCookie("mysheet_s")==null) //if "mysheet_s" session cookie is empty
document.cookie="mysheet_s="+setStylesheet("", "random")+"; path=/" //activate random alt stylesheet while remembering its "title" value
else
setStylesheet(getCookie("mysheet_s")) //just activate random alt stylesheet stored in cookie
}
else if (randomsetting.search(/^[1-9]+ days/i)!=-1){ //if "x days" setting
if (getCookie("mysheet_r")==null || parseInt(getCookie("mysheet_r_days"))!=parseInt(randomsetting)){ //if "mysheet_r" cookie is empty or admin has changed number of days to persist in "x days" variable
setCookie("mysheet_r", setStylesheet("", "random"), parseInt(randomsetting)) //activate random alt stylesheet while remembering its "title" value
setCookie("mysheet_r_days", randomsetting, parseInt(randomsetting)) //Also remember the number of days to persist per the "x days" variable
}
else
setStylesheet(getCookie("mysheet_r")) //just activate random alt stylesheet stored in cookie
} 
}

function search(f) {
	f.action = 'http://www.google.com/search';
}

	$(document).ready(function() {

		$("#make_large").click(function() {
			$('#text').removeClass('wimpy');
			$('#text').addClass('hefty');
			return false;
		});

		$("#make_medium").click(function() {
			$('#text').removeClass('hefty');
			$('#text').addClass('wimpy');
			return false;
		});

		$("#make_regular").click(function() {
			$('#text').removeClass('wimpy');
			$('#text').removeClass('hefty');
			return false;
		});

	});


