// Javascript Functions

function send_email() {
	
	var errors = 0;
	email_valid = !(!$F('email').match(/^\w+([.\+\-]\w+)*@\w+([.\-]\w+)+$/));
	var error_text = '';
	
	if ($F('name') == '') {
		$('name').setStyle({ border: '1px solid #FF0000' });	errors++;
		error_text += '<li>Your name</li>';		
	}
	
	if ($F('company') == '') {
		$('company').setStyle({ border: '1px solid #FF0000' }); errors++;
		error_text += '<li>Company / label</li>';		
	}

	if ($F('email') == '' || email_valid == false) {
		$('email').setStyle({ border: '1px solid #FF0000' }); 	errors++;
		if ($F('email') == '') error_text += '<li>Email</li>';
		else if (email_valid == false) error_text += '<li>Email invalid</li>';
	}

	if ($F('message') == '') {
		$('message').setStyle({ border: '1px solid #FF0000' }); errors++;
		error_text += '<li>Message</li>';
	}

	if (errors > 0) {
		var txt = '<div id="warning_box">Contact Us Form Not Completed Correctly</div>';
		txt += 'Please ensure you complete all required fields - <br /><br /><ul id="warning_list">' + error_text + '</ul><br />Please try again.';
		$j.prompt(txt);		
		return false;
	}
	
	var txt = '<div class=\"info_box_single\"><p>Sending Email. Please Wait....<p></div>';
	txt += '<div align="center" style="padding-top:10px"><img src="images/ajax-loader.gif" /></div>';
	txt += '<div align="center" style="padding-top:10px; font-size:10px;">Please Wait...</div>';
	
	$j.prompt(txt,{					  
		buttons: {}
	});		
	
	var ajax_url = 'ajax/ajax_contact.php?';

	new Ajax.Request(ajax_url, {
			parameters: {mode: 'send_email',
						 name: $F('name'),
 						 company: $F('company'), 
						 email: $F('email'), 
 						 message: $F('message'),
						 promo: $F('promo'),
						 distribution: $F('distribution'),
						 web: $F('web'),
						 mastering: $F('mastering'),
						 general: $F('general')
			},
			onSuccess: function(transport){
				var response = transport.responseText || "success";
				
				$j.prompt.close();

				if (response != 'success') {
					var txt = '<div id="warning_box">The Email Failed To Send</div>';
					txt += 'Please ensure you complete all required fields - <br /><br />' + response + '<br /><br />Please try again.';
					$j.prompt(txt);	
				} else {
					var txt = '<div id="yes_box">Email Sent</div>';
					txt += 'Your email has been sent successfully. A representative from Label Worx will contact you shortly.';
					$j.prompt(txt);	
					
					$('myform').reset();
				}
			}			
		});
}

function remove_border(field) {
	$(field).setStyle({ border: '1px solid #F4F4F4' });	
}

function resetred(field, link_field) {
	if (link_field == null) {
	
		if ($F(field) != '') {
			if (field == 'contact_email') {
				email_valid = !(!$F('contact_email').match(/^\w+([.\+\-]\w+)*@\w+([.\-]\w+)+$/));
			} else {
				email_valid = true;
			}
			
			if (email_valid) $(field).setStyle({ border: '1px solid #CCC' });
		}

	} else {
		if ($F(field) != '' || $F(link_field) != '') {
			$(field).setStyle({ border: '1px solid #CCC' });
			$(link_field).setStyle({ border: '1px solid #CCC' });
		}
	}
}
