// Forms JavaScript Document for Smiggle
// For validation see jquery.validate.js


//jquery
$(function() {
	
	//fix alignment for Firefox
	if( jQuery.browser.mozilla ) {
		$( 'form label' ).css( "display", "-moz-inline-box" );
		//$( 'form label' ).css( "display", "inline-block" );
	}

	//field focus styles
	$("input[type='text'], input[type='password'], textarea").addClass( "box" );
	$("input[type='text'], input[type='password'], textarea").focus(function(){ $(this).addClass( "focus" ); });
	$("input[type='text'], input[type='password'], textarea").blur(function(){ $(this).removeClass( "focus" ); });
	$("fieldset input[type!='hidden'][type!='submit']:first").focus();
	
	//a link.button in form to change to button tag
	$("form a.button").each(function (i) {
		var value = $(this).text();
		var href = $(this).attr("href");
		var classes = $(this).attr("class");
		var styles = $(this).attr("style");
		var onclick;
		if( $(this).hasClass("popup") ) {
			// This gets real messy when the a tag is supposed to be a popup
			var Width = Number($(this).attr("popupwidth"));
			var Height = Number($(this).attr("popupheight"));
			var WinTop = (screen.height - Height)/2;	//Auto position popup in center of screen
			var WinLeft = (screen.width - Width)/2;  	//Auto position popup in center of screen
			onclick = "window.open( \""+href+"\", \"Popup\", \"width="+Width+", height="+Height+", resizable=yes, scrollbars=yes, menubar=no, status=yes, top="+WinTop+", left="+WinLeft+"\" )";
		} else {
			onclick = "location.href=\""+href+"\"";
		}
		$(this).replaceWith( "<input type='button' value='"+value+"' class='"+classes+"' style='"+styles+"' onclick='"+onclick+"'/>" );
	});

});