var lastTab = "";
var lastStep = "";

function showChunk(chunkName) {
	if(lastTab != "" && jQuery("div#divlayer_"+lastTab) != null) {
		jQuery("div#divlayer_"+lastTab).hide();
	}
	lastTab 											= chunkName;
	if(jQuery("div#divlayer_"+chunkName) != null) {
		jQuery("div#divlayer_"+chunkName).show();
	}
	if (chunkName == "updates") {
		jQuery('img#updates').attr('src','/images/nav/updates_on.gif');
		jQuery('img#archives').attr('src','/images/nav/archives_off.gif');
		jQuery('img#doc').attr('src','/images/nav/doc_off.gif');
	}
	if (chunkName == "archives") {
		jQuery('img#updates').attr('src','/images/nav/updates_off.gif');
		jQuery('img#archives').attr('src','/images/nav/archives_on.gif');
		jQuery('img#doc').attr('src','/images/nav/doc_off.gif');
	}
	if (chunkName == "doc") {
		jQuery('img#updates').attr('src','/images/nav/updates_off.gif');
		jQuery('img#archives').attr('src','/images/nav/archives_off.gif');
		jQuery('img#doc').attr('src','/images/nav/doc_on.gif');
	}
}

function showStep(chunkName) {
	if(lastStep != "" && jQuery("div#divlayer_"+lastStep) != null) {
		jQuery("div#divlayer_"+lastStep).hide();
	}
	lastStep 											= chunkName;
	if(jQuery("div#divlayer_"+chunkName) != null) {
		jQuery("div#divlayer_"+chunkName).show();
	}
}

function callDefault(btnName) {
	showStep(btnName);
}

jQuery(document).ready(function(){
	jQuery("input#firstname").focus();
	
	jQuery("#referralSource").change(function(){
		if(jQuery(this).val() == 'Other') {
			jQuery("#referral_other").css({ 'display': 'block' });
		} else {
			jQuery("#referral_other").css({ 'display': 'none' });
		}
	});
	
	jQuery("#referralSource").keypress(function(){
		if(jQuery(this).val() == 'Other') {
			jQuery("#referral_other").css({ 'display': 'block' });
		} else {
			jQuery("#referral_other").css({ 'display': 'none' });
		}
	});
});

var checkstep1 = function() {
	var theForm = document.signup;
	
	var temp = theForm.firstname.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter first name.");
		theForm.firstname.focus();
		return false;
	}
	
	var temp = theForm.lastname.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter last name.");
		theForm.lastname.focus();
		return false;
	}
	
	var temp = theForm.jobtitle.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter job title.");
		theForm.jobtitle.focus();
		return false;
	}
	
	var temp = theForm.email.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter email.");
		theForm.email.focus();
		return false;
	}
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;

	if(((temp.search(exclude) != -1)||(temp.search(check)) == -1)||(temp.search(checkend) == -1)) {
		alert("Invalid email address.");
		theForm.email.focus();
		return false;
	}
	
	var temp = theForm.email_retype.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter email address.");
		theForm.email_retype.focus();
		return false;
	}
	
	var temp = theForm.email_retype.value;
	if (temp != theForm.email.value){
		alert("Please enter re-email address.");
		theForm.email_retype.focus();
		return false;
	}
	
	var temp = theForm.phone.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter phone number.");
		theForm.phone.focus();
		return false;
	}
}

var checkstep2 = function() {
	var theForm = document.signup;
	
	var temp = theForm.company.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter company name.");
		theForm.company.focus();
		return false;
	}
	
	var temp = theForm.address1.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter address.");
		theForm.address1.focus();
		return false;
	}
	
	var temp = theForm.city.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter city.");
		theForm.city.focus();
		return false;
	}
	
	var temp = theForm.state.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter state.");
		theForm.state.focus();
		return false;
	}
	
	var temp = theForm.zip.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter your ZIP or postal code.");
		theForm.zip.focus();
		return false;
	}
	
	var temp = theForm.country.value;
	if ((temp == '') || (temp.charAt(0) == ' ')){
		alert("Please enter country.");
		theForm.country.focus();
		return false;
	}
}

var checkstep3 = function() {
	var theForm = document.signup;
	
	var temp = theForm.referralSource.selectedIndex;
	if (temp == 0){
		alert("Please let us know how you heard about us.");
		theForm.referralSource.focus();
		return false;
	}
}

var checkall = function() {
	var step1, step2, step3 = false; 
	step1 = checkstep1();
	if (step1 != false) {
		step2 = checkstep2();
		if (step2 != false) {
			step3 = checkstep3();
		}
	}
	/*if (checkstep1() == true) {
		if (checkstep2() == true) {
			return checkstep3();
		}
	}*/
	//alert('1: '+step1+', 2: '+step2+', 3: '+step3);
	if (step1 == false || step2 == false || step3 == false) {
		return false;
	}
	//return step1 && step2;
}
