/*
	Share Our Strength scripts (utilizing jQuery 1.2.6)
	Developed by Saforian
*/

/* --- Initialize page --- */
$(document).ready(function(){

	// Stripe row colors
	$("table.data tr:nth-child(even)").not(".even").not(".odd").addClass("even");


	// Insert document icons
	$("a[href$=pdf]:not(:has(img))").append('<img class="icon" src="/images/icon_pdf.gif" width="14" height="14" alt=" (PDF)">');
	$("a[href$=doc]:not(:has(img)), a[href$=docx]:not(:has(img))").append('<img class="icon" src="/images/icon_word.gif" width="14" height="14" alt=" (Word Document)">');
	$("a[href$=xls]:not(:has(img)), a[href$=xlsx]:not(:has(img))").append('<img class="icon" src="/images/icon_excel.gif" width="14" height="14" alt=" (Excel Spreadsheet)">');
	$("a[href$=ppt]:not(:has(img)), a[href$=pptx]:not(:has(img))").append('<img class="icon" src="/images/icon_powerpoint.gif" width="14" height="14" alt=" (Powerpoint Presentation)">');


	// IE6 and quirks mode interface fixes
	if ($.browser.msie && ($.browser.version < 7 || document.compatMode == 'BackCompat')) {

		// CSS hover replacement
		$("#network>ul>li, #topnav>li").hover(function(){
			$(this).addClass("hover");
		},function(){
			$(this).removeClass("hover");
		});

		// PNG fix
		iepngfix();
	}

	Subscribebox.init;
});


// Toggle search widget
function toggleSearch() {
	$("#searchwidget").toggle();
	$("#searchlink").toggle();
}

// Contact form validation
function validate() {

	if (document.joinform.namefirst.value=='') {
		alert('Please enter your first name.');
		return false;
	}
	if (document.joinform.namelast.value=='') {
		alert('Please enter your last name.');
		return false;
	}
	if (document.joinform.email.value=='') {
		alert('Please enter your e-mail address.');
		return false;
	}
	if (document.joinform.zip.value=='') {
		alert('Please enter your ZIP/Postal code.');
		return false;
	}
}

// Comment form validation
function validatetwo() {
	if (document.commentform.author.value=='') {
		alert('Please enter your name.');
		return false;
	}
	if (document.commentform.email.value=='') {
		alert('Please enter your e-mail address.');
		return false;
	}
	if (document.commentform.text.value=='') {
		alert('Please enter your comments.');
		return false;
	}
}

// Toggle block visibility
function toggle(targetId) {
	if (!document.getElementById) { return false; }

	$("#" + targetId).toggle();
		return false;
}


/* --- Search box --- */

// Event handler
function addEventToObject(obj,evt,func) {
	var oldhandler = obj[evt];
	obj[evt] = (typeof obj[evt] != 'function') ? func : function(){oldhandler();func();};
}

var Subscribebox = {
	init: function() {
		var sBox = document.getElementById('search-text');
		if (sBox) {
			addEventToObject(sBox,'onclick',Subscribebox.click);
			addEventToObject(sBox,'onblur',Subscribebox.blur);
		}	
	},
	click: function() {
		var sBox = document.getElementById('search-text');
		if (sBox.value == 'Enter search text...') {
			sBox.value = '';
		}
	},
	blur: function() {
		var sBox = document.getElementById('search-text');
		if (sBox.value == '' || sBox.value == ' ') { sBox.value = 'Enter search text...'; }
	}
};


/* --- IE PNG fix --- */
function iepngfix() {

	// IE 5.5 and 6.0 PNG filter support (derived from youngpup.net)
	$("img[src$=png]").each(function(){
		var src = this.src;
		var div = document.createElement("div");

		// Set replacement div properties
		div.id = this.id;
		div.className = this.className;
		div.title = this.title || this.alt;
		div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "', sizing='scale')";
		div.style.width = this.width + "px";
		div.style.height = this.height + "px";

		// Replace image with transparent div
		this.replaceNode(div);
	});
}