<!--
$(document).ready(function () { initPage(); });

function initPage() {

	// All Pages
	$('a').click(function() { this.blur(); }); // remove link outlines
	
	// All Forms
	$('input, select, textarea').focus(function () { $(this).css('backgroundColor', '#fffedb').css('cursor', 'text'); }); // highlight fields
	$('input, select, textarea').blur(function () { validateField(this); $(this).css('backgroundColor', '#fff').css('cursor', 'pointer'); }); // validate and de-highlight on blur
	$('.formControls a').click(function () { var returnValue = validateForm($(this).closest('form')); if (returnValue) { submitForm(this); } return false; }); // validation
	
	// Home Page
	$('#testimonialBin img').css('display', 'none'); // fade out all images in pool
	if ($('#testimonialBin img').length > 0 ) { setTimeout("runFadeShow()", 12000); } // give the page time to load before running
	
	// About Us - Bios
	$('a[name][href*=#]').addClass('anchorLink').click(function() { return false });
	
	// Testimonials
	$("p.testy:odd").addClass("odd"); // add testimonials zebra striping
	
	// Tour
	$(".tourPoints li").mouseover( function() { 
		// link manipulation
		$(".tourPoints li").css("color", '#02425d'); // change all links back to blue
		this.style.color = '#FB890E'; // change current link to orange
		$("#tourContent div").fadeOut('fast'); // fade out any visible blocks
		
		// get index, get matching content obj, fade in
		var index = $(".tourPoints li").index(this);
		var obj = $("#tourContent div").get(index);
		$(obj).fadeIn('fast');
	});
	
	// Enroll - Step 1
	$('#step1 #referral').change( function() {
		if ($(this).val() == "OTHER") { $('#step1 #other').css('display', 'inline'); }
		else { $('#step1 #other').css('display', 'none'); }
	});
	
	// Forms - Overrides
	$('.formControls.domain a').unbind('click').click(function () { checkDomain(this); return false; }); // domain checker
	$('.formControls.selectedOpt a').unbind('click').click(function () { selectDomain($(this).closest('form')); return false; }); // selected domain

}
function submitForm(aObj) {
	var myForm = $(aObj).closest('form');
	$(aObj).css('display', 'none'); // hide submit form link
	$(".formControls").html("Saving . . ."); // replace with message
	myForm.submit(); // submit form
	return true;
}
function validateForm(formObj) {
	var returnValue = true;
	$(formObj+':input').each(function() {
		if (!validateField(this)) { returnValue = false; }
	});
	if (!returnValue) { $(".formMessages").html("Fields outlined in red are required.").fadeIn(1200); }
	return returnValue;
}
function validateField(fieldObj) {

	var required = new Array("test", "test2");
	switch ($(fieldObj).closest('form').attr('id')) {
		case "step1":
			var required = new Array("name_first", "name_last", "company_id", "phone_work", "address", "city_id", "state_id", "zipcode_id", "user_email", "eagain", "user_pass", "pagain", "referral", "other");
			break;
			
		case "step2":
			var required = new Array("test");
			break;
			
		case "step3":
			var required = new Array("card_type", "card_number", "month", "year", "cvv2", "cc_name", "address", "city", "state", "zipcode");
			break;
			
		case "step4":
			var required = new Array("test");
			break;			
		
		case "contact":
			var required = new Array("name", "email", "subject", "msg");
			break;
			
		case "domains":
			var required = new Array("name", "company", "email", "phone");	
			break;
	}
	
	// for any required fields
	if (searchArray(fieldObj.name, required) && $(fieldObj).length > 0) { 
		if (!isFilled(fieldObj)) { $(fieldObj).addClass('required'); return false; } // if empty, class and return false
		else { $(fieldObj).removeClass('required'); } // else unclass
	}	
	return true;
}
function checkDomain(aObj) {

	// get form and correct domain value
	var form = $(aObj).closest('form');
	if (aObj.innerHTML == 'Go To Step 3') { var field = $('#transfer').get(0); $('#choice').val('transfer'); } // user entered transfer domain
	else { var field = $('#domain').get(0); $('#choice').val('new'); } // user is searching for new domain

	if (!isFilled(field)) {
		alert("Please enter the domain name.");
		field.focus();
		return false;
	}
	var pattern = /^[\d\w\-_\.]+$/;
	if (!pattern.test(field.value)) {
		alert("A domain name can only contain alphanueric characters (no spaces) including hyphens(-) and underscores(_).");
		field.focus();
		return false;
	}
	form.submit();
	return true;
}
function selectDomain(formObj) {
	var form   = formObj.get(0);
	var domain = $('input[name=final_domain]:checked'); // get checked radio 
	if (domain.length == 0) { alert("You must select a domain from the list."); return false; }
	form.choice.value = 'final_domain'; // set choice for step 3
	form.submit(); 
	return true;
}
function fadeOutAndSwap() {
	var img1 = $('#testimonials img').get(0);
	var img2 = $('#testimonials img').get(1);
	var img3 = $('#testimonials img').get(2);
	
	$(img1).fadeOut(600, function() { // animate image off
		var parentA = $(img1).parent(); // save parent
		var stackImg = $('#testimonialBin img').get(0); // grab next image in the hidden stack, always the first
		$(parentA).prepend(stackImg); // move it to the current anchor
		$('#testimonialBin').append(img1); // then move the faded image to the end of the stack
		var tmp = $('#testimonials img').get(0);
		$(tmp).fadeIn(800);
		
		$(img2).fadeOut(600, function() { // animate image off
			var parentA = $(img2).parent(); // save parent
			var stackImg = $('#testimonialBin img').get(0); // grab next image in the hidden stack, always the first
			$(parentA).prepend(stackImg); // move it to the current anchor
			$('#testimonialBin').append(img2); // then move the faded image to the end of the stack
			var tmp = $('#testimonials img').get(1);
			$(tmp).fadeIn(800);
			
			$(img3).fadeOut(600, function() { // animate image off
				var parentA = $(img3).parent(); // save parent
				var stackImg = $('#testimonialBin img').get(0); // grab next image in the hidden stack, always the first
				$(parentA).prepend(stackImg); // move it to the current anchor
				$('#testimonialBin').append(img3); // then move the faded image to the end of the stack
				var tmp = $('#testimonials img').get(2);
				$(tmp).fadeIn(800);
			}); 
		}); 
	}); 
	return true;
}
function runFadeShow() {
	fadeOutAndSwap();
	setTimeout("runFadeShow()", 13000);
}
// checks to see if a form field is selected or filled
function isFilled(obj) {
	if (obj.nodeName == "SELECT") { if (obj.selectedIndex <= 0) { return false; } } // selects
	else {
		var pattern = /^\s+$/;
		if (obj.value == "" || obj.value == null) { return false; }
		if (pattern.test(obj.value)) { return false; }
	}
	return true;
}
// searches for a value in an array, returns true on match
function searchArray(match, array) {
	for (var x = 0; x < array.length; x++) {
		if (array[x] == match) { return true; }
	}
	return false;
}
//-->