// Custom jQuery stuff for the future-ink website

$(function() {
	// Make default form text grey on page load
	$(":text, textarea").addClass("defaultformtext");

	// If form inputs have a default value, clear on focus
	$(":text, textarea").focus(function() {
		if(this.value == this.defaultValue) {
			this.value = "";
			$(this).removeClass("defaultformtext");
		}
	})
	// Restore default text
	.blur(function() {
		if( !this.value.length ) {
			this.value = this.defaultValue;
			$(this).addClass("defaultformtext");
		}
	});
});

// open/close divs based on selection. input has class "opennext"
$(function() {
	function switchyswitch() {
		var thediv =  $(this).parent().next("div");
		switch ($(this).val()) {
			case "Friend/Referral": // how did you find us
			case "Other": // how did you find us
			case "Redesign of Existing Site": // project type
			case "Updates/Changes to Existing Site": // project type
			case "Yes": // radio buttons and checkboxes
			thediv.slideDown();
			break;
			default: thediv.slideUp();
		}
	}
	$(":radio.opennext, :checkbox.opennext").click(switchyswitch); // ie will not trigger change() until the radio button or checkbox loses focus. must use click()
	$("select.opennext").change(switchyswitch); // safari doesn't do click() on a select element. must use change()
});

// sidebar blog signup validation and submit
$(function() {
	$('#sidebar_blog_signup form').validate({
		errorElement: 'div',
		submitHandler: function(form) {
			form.submit(
				window.open('', 'thanks', 'width=500,height=520,status=no,resizable=no,scrollbars=no')
			);
   		}
	});
});

// TEMPORARY SHOW/HIDE

function rowtoggleselect(selectObj, selectObjOption1, selectObjOption2, DivId) {
	if (selectObj.selectedIndex == selectObjOption1 || selectObj.selectedIndex == selectObjOption2) {
    	document.getElementById(DivId).style.display='';
	} 
	else {
      document.getElementById(DivId).style.display='none';
    }
 }
 
function rowtoggleradio(radioObjShow, radioObjHide, DivId) 
	{
	if (radioObjShow.checked) 
	{
    document.getElementById(DivId).style.display='';
	} 
	else if (radioObjHide.checked)
	{
      document.getElementById(DivId).style.display='none';
    }
 }

