function el(elementID) {
	return document.getElementById(elementID);
}

function clearSearch() {
	if (el('s').value == 'Search...') {
		el('s').value = '';
	} else if (el('s').value == '') {
		el('s').value = 'Search...';
	}
}

function swapPhoto(numPhoto, elementID, overText) {
	
	if (elementID == 'anchor-full') {
		el(elementID).innerHTML = '<div class="overtext">'+overText+'</div><img src="/wp-content/themes/aspent/landscape/retaining-walls/full'+numPhoto+'.jpg" alt="Landscape Photo" />';
	} else if (elementID == 'pavers-full') {
		el(elementID).innerHTML = '<div class="overtext">'+overText+'</div><img src="/wp-content/themes/aspent/landscape/pavers/full'+numPhoto+'.jpg" alt="Landscape Photo" />';
	} else if (elementID == 'natural-full') {
		el(elementID).innerHTML = '<div class="overtext">'+overText+'</div><img src="/wp-content/themes/aspent/landscape/natural-stone/full'+numPhoto+'.jpg" alt="Landscape Photo" />';
	} else if (elementID == 'outdoor-full') {
		el(elementID).innerHTML = '<div class="overtext">'+overText+'</div><img src="/wp-content/themes/aspent/landscape/outdoor/full'+numPhoto+'.jpg" alt="Landscape Photo" />';
	}
	
}

$(document).ready(function () {
	
	if ($('#DoDirectPaymentForm').length) {
	
		$('#DoDirectPaymentForm').submit(function() {
			
			if ($('.process-error').length) {
				
				$('.process-error').remove();
				
			}
			
			valid = true; 
			
			$('.required').each(function () {
				
				if ($('#'+$(this).attr('id')).val() == "") {
					
					$('#'+$(this).attr('id')).css('border-color', '#f00');
					
					valid = false;
					
				} else {
				
					$('#'+$(this).attr('id')).css('border-color', '#aaa');
				
				}
								
			});
			
			vconf = false;
			
			$('.required-conference').each(function() {
				
				if ($('#'+$(this).attr('id')).is(':checked')) {

					$('.c-info').css('color', '#000');		
										
					vconf = true

				} else if (vconf == false) {
			
					$('.c-info').css('color', '#f00');
				
				}
			
			});
			
			if (valid && vconf) {
				
				$('#register').css('display', 'none');
				$('#loader').css('display', 'block');
				
				$.ajax({
					type: 'post',
					url: 'https://aspent.com/wp-content/themes/aspent/paypal/process-payment.php',
					data: $(this).serialize(),
					success: function(result) {

						obj = $.parseJSON(result);
						
						if (obj.ACK == "Failure") {

							$('#loader').css('display', 'none');
							$('#register').css('display', 'block');
							
							$('#card-info #submit-buttons').prepend('<p class="process-error">'+obj.L_LONGMESSAGE0+'</p>');
							
						} else {
						
							$('#conference-page').remove();
							$('#content').append('<p><strong>Thank you for registering for the ASP and Quick Supply  "Clean and Green" Sustainability Conference and Expo.  We appreciate your interest in our 3rd annual conference and expo.</strong></p><p>You will receive an email shortly with your receipt and conference information.</p>');
							
						}
												
					}
					
				});
				
			}

			return false;
		
		});
		
		var attendees = 2;
		
		$('#add-attendee').click(function () {
			
			addItem = "<div class=\"attendee\" id=\"attendee"+attendees+"\"> \n";
			addItem += "<a href=\"javascript:\" rel=\"attendee"+attendees+"\" id=\"remove-"+attendees+"\" class=\"remove\">Remove <span class=\"removeX\">X</span></a> \n";
			addItem += "<div class=\"row\"> \n";
			addItem += "<label for=\"aName"+attendees+"\">Name</label> \n";
			addItem += "<input type=\"text\" name=\"aName["+attendees+"]\" id=\"aName"+attendees+"\" class=\"required\" /> \n";
			addItem += "</div> \n";
			addItem += "<div class=\"row\"> \n";
			addItem += "<label for=\"aTitle"+attendees+"\">Title</label> \n";
			addItem += "<input type=\"text\" name=\"aTitle["+attendees+"]\" id=\"aTitle"+attendees+"\" class=\"required\" /> \n";
			addItem += "</div> \n";
			addItem += "<div class=\"row\"> \n";
			addItem += "<label for=\"aEmail"+attendees+"\">Email</label> \n";
			addItem += "<input type=\"text\" name=\"aEmail["+attendees+"]\" id=\"aEmail"+attendees+"\" class=\"required\"  /> \n";
			addItem += "</div> \n";
			addItem += "</div> \n";
			
			$(this).before(addItem);
			
			var total = parseFloat($('#total').html()) + 40;
			
			$('#total').html(total+".00");
			$('#amount').val(total+".00");
						
			$('#remove-'+attendees+'').click(function () {

				total = parseFloat($('#total').html()) - 40;
				$('#total').html(total+".00");
				$('#amount').val(total+".00");
				
				$('#'+$(this).attr('rel')).remove();
				
				attendees--;
				
			});
			
			attendees++;
			
		});
	
	}
				
});

