// Javascript Functions

function focus_email() {
	if ($F('myemail') == 'email@yourcompany.com') {
		$('myemail').value = '';
		$('myemail').setStyle({ color: '#333' });	
	}
}

function blur_email() {
	if ($F('myemail') == '') {
		$('myemail').value = 'email@yourcompany.com';
		$('myemail').setStyle({ color: '#9F9F9F' });	
	}
}

function send_promo_email() {
	
	var errors = 0;
	email_valid = !(!$F('myemail').match(/^\w+([.\+\-]\w+)*@\w+([.\-]\w+)+$/));
	var error_text = '';

	if ($F('myemail') == 'email@yourcompany.com' || email_valid == false) {
		$('myemail').setStyle({ border: '1px solid #FF0000' }); 	errors++;
		if ($F('myemail') == 'email@yourcompany.com') error_text += '<li>Email</li>';
		else if (email_valid == false) error_text += '<li>Email invalid</li>';
	}

	if (errors > 0) {
		var txt = '<div id="warning_box">Please Enter A Valid Email Address</div>';
		txt += 'Please ensure you enter a valid email address - <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 Promo 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_promo.php?';

	new Ajax.Request(ajax_url, {
			parameters: {mode: 'promo',
						 email: $F('myemail')
			},
			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">Promo Email Sent</div>';
					txt += 'A promo email has been sent successfully to your inbox.';
					$j.prompt(txt);	
					
					$('myemail').value = 'email@yourcompany.com';
					$('myemail').setStyle({ color: '#9F9F9F' });						
				}
			}			
		});
}

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' });
		}
	}
}