$(document).ready(function(){
	//variables that can be changed and effect code below
	var iso_link = '/'; //contact page, when you select QA and iso
	
	
	$('input[name="q"]').css({backgroundImage:"url('/images/search.jpg')",padding: '0 8px',borderLeft:'none',borderRight:'none',borderTop:'none',borderBottom:'none'});
	$('input[name="q"]').blur(function(){
		$(this).css("background","url('/images/search.jpg') no-repeat #ffffff");							   
	});
	$('.option_dropdown li').click(function(){
		$(this).children('ul').toggle();
		return false;
	});
	$('.option_dropdown li ul li a').click(function(){
		window.location = $(this).attr('href');
	});
	
	var sales_tier = '<li id="sales_tier" class="hidden_tier"><label for="sub">Sub-Topic:</label><select id="sub" name="sub">							<option value="-">Please Select...</option><option value="corporate-sales">Corporate Sales</option><option value="inside-sales">Inside Sales</option><option value="customer-solutions">Customer Solutions</option><option value="marketing">Marketing</option></select></li>';
	var finance_tier = '<li id="finance_tier" class="hidden_tier"><label for="sub">Sub-Topic:</label><select id="sub" name="sub"><option value="-">Please Select...</option><option value="accounts-payable">Accounts Payable</option><option value="accounts-receivable">Accounts Receivable</option><option value="finance-general">Finance General</option><option value="investor-relations">Investor Relations</option></select></li>';
	var hr_tier = '<li id="hr_tier" class="hidden_tier"><label for="sub">Sub-Topic:</label><select id="sub" name="sub"><option value="-">Please Select...</option><option value="employee-inquiries">HR &amp; Employee Inquiries</option><option value="record-inquiries">Employment Record Inquiries</option><option value="community-relations">Community Relations</option></select></li>';
	var quality_tier = '<li id="quality_tier" class="hidden_tier"><label for="sub">Sub-Topic:</label><select id="sub" name="sub"><option value="-">Please Select...</option><option value="supplier-survey">Supplier Survey</option><option value="iso">ISO Certificate Requests</option></select></li>';
	
	//hide contact form if topic is not disabled or if topic is disabled and sub exists meaning they used the pre-filter and a 2nd option is availabile to further filter results
	
	$('#contact_form').hide();	
	if($('#topic').is(':disabled') && $('#sub').length){
		//if #sub exists, bind the function to show contact form
		$('form').append('<input type="hidden" name="topic" value="'+$('#topic').val()+'" />');
		$('#sub').bind('change',function(event){					
			$(this).attr('disabled','disabled');
			if($(this).val() == 'iso'){
				window.location = iso_link;
			}else{
				$('#contact_form').show();
				$('form').append('<input type="hidden" name="sub" value="'+$(this).val()+'" />');
			}
		});	
	}else if($('#topic').is(':disabled')){
		$('form').append('<input type="hidden" name="topic" value="'+$('#topic').val()+'" />');	
		$('#contact_form').show();
	}
	
	//pre-filtered list (footer)	
	$('#pre_filter').change(function(){
		$(this).closest("form").submit();
	});
	
	//contact page	
	$('#topic').change(function(){
		//$(this).attr('disabled','disabled');
		$("#topic option[value='-']").remove();
		switch($(this).val()){
			case 'sales':
			case 'engineering':
			case 'careers':
			case 'finance':
			case 'investor':
			case 'corporate':
			case 'hr':
			case 'community':
			case 'legal':
			case 'quality':
				//just show form
				$('#contact_form').show();
				break;
		}
		$("#contact_us input[name=topic]").remove();
		$('form').append('<input type="hidden" name="topic" value="'+$(this).val()+'" />');
	});
});

function checkContactUsForm(thisForm) {
		$errorMsg="";
		if (thisForm.company.value == "")
		{
			$("#contact_us #companyli").addClass("error");
			$errorMsg += "Company/Division field is required.  ";
		}else
		{
			$("#contact_us #companyli").removeClass("error");
		}
		
		if (thisForm.name.value == "")
		{
			$("#contact_us #nameli").addClass("error");
			$errorMsg += "Full Name field is required.  ";
		}
		else
		{
			$("#contact_us #nameli").removeClass("error");
		}
		
		//var re = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
		//var re = /^([a-zA-Z0-9]{3,})(((\.|\-|\_)[a-zA-Z0-9]{2,})+)?@([a-z]{3,})(\-[a-z0-9]{3,})?(\.[a-z]{2,})+$/;
		var re = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.(aero|arpa|biz|com|coop|edu|gov|info|int|mil|museum|name|net|org|pro|travel|mobi|[a-z][a-z])|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i; 
		if (thisForm.email.value == "")
		{
			$("#contact_us #emailli").addClass("error");
			$errorMsg += "E-Mail field is required.  ";
		} 
		else if (!(thisForm.email.value).match(re))
		{
			$("#contact_us #emailli").addClass("error");
			$errorMsg += "E-Mail address is not valid.  ";
		}
		else
		{
			$("#contact_us #emailli").removeClass("error");
		}
		
		if ($errorMsg.length != 0)
		{
			$("#errorTxt").html($errorMsg);
			return false;
		}
		
		return true;
}

function setCancelReturn()
{
	$("#sendid").val("nosend");
	
}









