/* 3.18.09 - 10:00 am */

function couponForm() {
	var buttontext = "Enter coupon code";
	if (document.getElementById('couponCode').value != ''){
	//DON'T DO THIS GARBAGE
	} else{
	if (document.getElementById('aspnetForm')) {
		var couponform = document.getElementById('aspnetForm');
		// set the text in the email field to our default text
		couponform.couponCode.value=buttontext;
		// if field is default text clear it out, otherwise leave it
		$('input#couponCode').focus( function(){
			if(couponform.couponCode.value==buttontext){
				couponform.couponCode.value='';
			}
		});
		// if it is empty put the default text
		$('input#couponCode').blur( function(){
			if(couponform.couponCode.value==''){
				couponform.couponCode.value=buttontext;
			}
		});
		// remove default text on submit
		$('form#jp_ecomCartForm').submit( function(){
			if(couponform.couponCode.value==buttontext){
				couponform.couponCode.value='';
			}
		});
	}
	}
}
function accountInfoForm() {
	var firstnametext = "First Name";
	var lastnametext = "Last Name";
	if (document.getElementById('firstName')) {
		var nameform = document.getElementById('jp_ecomCartForm');
		// set the text in the email field to our default text
		nameform.firstName.value=firstnametext;
		nameform.lastName.value=lastnametext;
		// if field is default text clear it out, otherwise leave it
		$('input#firstName').focus( function(){
			if(nameform.firstName.value==firstnametext){
				nameform.firstName.value='';
			}
		});
		$('input#lastName').focus( function(){
			if(nameform.lastName.value==lastnametext){
				nameform.lastName.value='';
			}
		});
		// if it is empty put the default text
		$('input#firstName').blur( function(){
			if(nameform.firstName.value==''){
				nameform.firstName.value=firstnametext;
			}
		});
		$('input#lastName').blur( function(){
			if(nameform.lastName.value==''){
				nameform.lastName.value=lastnametext;
			}
		});
		// remove default text on submit
		$('form#jp_ecomCartForm').submit( function(){
			if(nameform.firstName.value==firstnametext){
				nameform.firstName.value='';
			}
			if(nameform.lastName.value==lastnametext){
				nameform.lastName.value='';
			}
		});
	}
}
function uploadLogoForm() {
	$("#jp_picklogo").change(function () {
		$("#jp_picklogo option:selected").each(function () {
			if($(this).attr("id") == "uploadNew") {
				$("#uploadNewLogo").show();
			} else {
				$("#uploadNewLogo").hide();
			}
		});
	}).change();
}
function companyProfile() {
	var profileField = $('#companyProfile');
	if (profileField) {
		$("#companyProfile").change(function () {
			$("#companyProfile option:selected").each(function () {
				if($(this).attr("id") == "manualEntry") {
					$("#contactName").show();
					$("#companyName").show();
				} else {
					$("#contactName").hide();
					$("#companyName").hide();
				}
			});
		}).change();
	}
}
function countTextareaChars() {
	if ( $("#jobDesc").size()) {
		var startDescLength = $('#jobDesc').val().length;
		if (startDescLength == 0) {
			$('#jobDesc').keyup(function() {
				var jobcharLength = $(this).val().length;
				var jobcharRemaining = 15000 - jobcharLength;
				$('#jobletternum').html("[ You have used <strong>" + jobcharLength + "</strong> and have <strong>" + jobcharRemaining + "</strong> remaining. ]");
			})
		} else {
			var jobcharLength = startDescLength;
			var jobcharRemaining = 15000 - jobcharLength;
			$('#jobletternum').html("[ You have used <strong>" + jobcharLength + "</strong> and have <strong>" + jobcharRemaining + "</strong> remaining. ]");
		};
	}
	
	if ( $("#jobRequirements").size()) {
		var startReqsLength = $('#jobRequirements').val().length;
		if (startReqsLength == 0) {
		$('#jobRequirements').keyup(function() {
			var reqcharLength = $(this).val().length;
			var reqcharRemaining = 10000 - reqcharLength;
			$('#reqletternum').html("[ You have used <strong>" + reqcharLength + "</strong> and have <strong>" + reqcharRemaining + "</strong> remaining. ]");
		})
		} else {
			var reqcharLength = startReqsLength;
			var reqcharRemaining = 10000 - reqcharLength;
			$('#reqletternum').html("[ You have used <strong>" + reqcharLength + "</strong> and have <strong>" + reqcharRemaining + "</strong> remaining. ]");
		};
	}
}
function createModals() {
	$("#jobDescLabel").append("<a href=\"#\" id=\"showDescTips\" class=\"jp_helpfulTips jqModal\">Helpful Tips</a>");
	$("#jobReqLabel").append("<a href=\"#\" id=\"showReqTips\" class=\"jp_helpfulTips jqModal\">Helpful Tips</a>");
	$('#jobDescTips').jqm({trigger: 'a#showDescTips'});
	$('#jobRequirementTips').jqm({trigger: 'a#showReqTips'});
	$('#securityCodeInfo').jqm({trigger: 'a#showSecurityCodeInfo'});
}
function printReceipt() {
	$("h2.headingWithPrint").after("<a href=\"javascript:window.print();\" class=\"printReceipt\">Print this</a>");
}
$(document).ready(function(){
	couponForm();
	accountInfoForm();
	uploadLogoForm();
	countTextareaChars();
	companyProfile();
	createModals();
	printReceipt();
});