

function addslashes(str) {
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\0/g,'\\0');
	return str.replace(/\n/g,"<br>");
}

function contactProcess(url, vars){
jQuery.noConflict();
(function($){
	$.post(
		url, 
		vars,
		function(xmlResponse){
    		var root = xmlResponse.getElementsByTagName('root');
			var error = xmlResponse.getElementsByTagName('error')[0].childNodes[0].nodeValue;
			var dl_link = xmlResponse.getElementsByTagName('dl_link')[0].childNodes[0].nodeValue;
			
			$('#process').html('');
			$('#submitForm').attr('disabled', false);
			
			if(error == 'true'){
				$('#process').html('Error - Please try again later');
			}
			else{
				$('#contactForm')[0].reset();
				$('#contactForm').css('display', 'none');
				$('#confirm').html('Thank You!<br/> Your message has been sent successfully.<br/><br/>' + dl_link);
			}
		}, 
		"xml"
	);
})(jQuery);
}

jQuery.noConflict();
(function($){
		
$(document).ready(function(){
	if($('#download').attr('checked') != true){
		$('#download_fields').css('display', 'none');
	}
	else{
		$('#download_fields').css('display', 'block');
	}
	
	$('#download').click(function(){
		if($(this).attr('checked') != true){
			$('#download_fields').css('display', 'none');
		}
		else{
			$('#download_fields').css('display', 'block');
		}
	});
	
	$('#submitForm').click(function(){
		var regexp = /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/;
		
		if($('#firstname').val().replace(/\s+/g,'').length == 0){
			alert('Please enter your first name!');
			$('#firstname').focus();
		}
		else if($('#lastname').val().replace(/\s+/g,'').length == 0){
			alert('Please enter your last name!');
			$('#lastname').focus();
		}
		else if($('#email').val().replace(/\s+/g,'').length == 0){
			alert('Please enter your email!');
			$('#email').focus();
		}
		else if($('#email').val().search(regexp) == -1)
		{
			alert('Please enter valid email!');
			$('#email').focus();
		}
		else if($('#phone').val().replace(/\s+/g,'').length == 0){
			alert('Please enter your phone!');
			$('#phone').focus();
		}
		else if($('#company').val().replace(/\s+/g,'').length == 0){
			alert('Please enter your company!');
			$('#phone').focus();
		}
		else if($('#position').val().replace(/\s+/g,'').length == 0){
			alert('Please enter your position!');
			$('#phone').focus();
		}
		else if($('#download').attr('checked') == true && $('#company').val().replace(/\s+/g,'').length == 0){
			alert('Please enter your company name!');
			$('#company').focus();
		}
		else if($('#download').attr('checked') == true && $('#position').val().replace(/\s+/g,'').length == 0){
			alert('Please enter your position!');
			$('#position').focus();
		}
		else{
			var vars = '';
			var url = 'ajax.php';
			
			var firstname = encodeURIComponent($('#firstname').val());
			var lastname = encodeURIComponent($('#lastname').val());
			var email = encodeURIComponent($('#email').val());
			var phone = encodeURIComponent($('#phone').val());
			var address1 = encodeURIComponent($('#address1').val());
			var address2 = encodeURIComponent($('#address2').val());
			var city = encodeURIComponent($('#city').val());
			var state = encodeURIComponent($('#state').val());
			var zip = encodeURIComponent($('#zip').val());
			var how = encodeURIComponent($('#how').val());
			var comments = encodeURIComponent($('#comments').val());
			
			var company = encodeURIComponent($('#company').val());
			var position = encodeURIComponent($('#position').val());
			if($('#download').attr('checked') == true){
				var download = encodeURIComponent('y');
			}
			else{
				var download = encodeURIComponent('n');
				company = position = encodeURIComponent('');;
			}
			
			vars = addslashes('firstname=' + firstname + '&lastname=' + lastname + '&email=' + email + '&phone=' + phone + '&address1=' + address1 + '&address2=' + address2 + '&city=' + city + '&state=' + state + '&zip=' + zip + '&how=' + how + '&body=' + comments + '&position=' + position + '&company=' + company + '&download=' + download);
			
			$('#process').html('Please wait - processing...');
			$('#submitForm').attr('disabled', true);
			
			setTimeout("contactProcess('" + url + "', '" + vars + "')", 1000);
		}
	});
});

})(jQuery);