/*
 * HSA Resources custom jQuery functions
 *
 * Copyright (c) 2009
 * Dual licensed under the MIT and GPL licenses.
 * http://docs.jquery.com/License
 *
 * Date: 2009-08-03
 * Revision: 1
 */

$(document).ready(function(){
	
	// prepare links based on "rel" attribute
	$('a[rel^="external"]').attr("target", "_blank");
	$('a[rel^="close"]').click(function() {window.close();});
	$('a[rel^="print"]').click(function() {window.print();});
	
	// add "last-child" class to all last-child nodes
	$(':last-child').addClass("last-child");
	
	// global navigation
	$('#nav li, #nav li li').mouseover(function(index){$(this).addClass("sfhover")});
	$('#nav li, #nav li li').mouseout(function(index){$(this).removeClass("sfhover")});
	
	// prepare tab navigation
	$('ul.tabs li a').click(function() {
		
		$('ul.tabs li').each(function(index) {$(this).removeClass("active");});
		$(this).parent().addClass('active');
		
		$('div.detail').each(function(index) {$(this).hide();});
		$($(this).attr("href")).show();
		
		return false;
	});
});



// add load event function
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

// popup windows
function popup(url,w,h,full) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	var popupProps = 'width='+w+',height='+h+',left='+winl+',top='+wint;
	
	if(full) {
		popupProps += 'resizable=1,status=1,menubar=1,toolbar=1,scrollbars=1,location=1,directories=1';
	}
	
	window.open(url,'popup',popupProps);
}

// email validation
function validate(email) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var address = email.value;
	
	if(reg.test(address) == false) {
		alert("You have entered an invalid email address.\n\nPlease try again.");
		email.focus();
		return false;
	} else {
		return true;
	}
}

function deleteCompany(del,company) {
	var agree=confirm("Are you sure you want to delete " + company + "?\n\nThis can not be undone.");

	if (agree) {
		document.companies.process.value = '4';
		document.companies.companyid.value = del;
		document.companies.companyname.value = company;
		document.companies.submit();		
		return true;
	} else {
		return false;
	}
}

function deleteContrib(del) {
	var agree=confirm("Are you sure you want to delete this contribution data?\n\nThis can not be undone.");

	if (agree) {
		document.contributions.process.value = '4';
		document.contributions.contribid.value = del;
		document.contributions.submit();		
		return true;
	} else {
		return false;
	}
}

function deleteAdmin(del,name) {
	var agree=confirm("Are you sure you want to delete this administrator?\n\nThis can not be undone.");

	if (agree) {
		document.removeAdmin.process.value = 'delete';
		document.removeAdmin.id.value = del;
		document.removeAdmin.name.value = name;
		document.removeAdmin.submit();		
		return true;
	} else {
		return false;
	}
}

function deleteEmp(del) {
	var agree=confirm("Are you sure you want to delete this employee?\n\nThis can not be undone.");

	if (agree) {
		document.employees.process.value = '4';
		document.employees.employeeid.value = del;
		document.employees.submit();		
		return true;
	} else {
		return false;
	}
}