$j = jQuery.noConflict();
function showOtherAmount() {
	var amount = $j('input[name=cb-amount]:checked').val(); 
	if(amount == "other") {
		$j('#cb-other').show();
	} else {
		$j('#cb-other').hide();
		$j('#cb-amount-other').val('');
	}
}

function validateContribute() {
	if($j('input[name=cb-amount]:checked').val() != "" && $j('input[name=cb-amount]:checked').val() != "other") {
		$j('#amount').val($j('input[name=cb-amount]:checked').val());
	} else if($j('#cb-amount-other').val() != "") {
		$j('#amount').val($j('#cb-amount-other').val());
	} else {
		$j('#amount').val("");
	}
	
	$j.ajax({
   		type: "POST",
   		url: "/wp-content/themes/goolsbyforsenate/ajax/validateForm.php",
   		data: $j('#donate').serialize() + "&form=contribute",
   		success: function(msg){
   			//reset
   			$j('#contribute_amt_fields').removeClass("error");
   			$j('#cb-name').removeClass("error");
   			$j('#cb-email').removeClass("error")
   			$j('#cb-occupation').removeClass("error");
   			$j('#cb-employer').removeClass("error");
     		if(msg == "") {
     			$j('#paypal_amt').val($j('#amount').val());
	     			$j('#processing').overlay().load();
     			$j('#paypal').submit();
     		} else {
     			var e = new Array();
     			e = msg.split("|");
     			for(var i in e) {
     				if(e[i] == "amount") {
     					$j('#contribute_amt_fields').addClass("error");
     				} else {
	     				$j('#' + e[i]).addClass("error");
     				}
     			}
     		}
   		}
 	});
 	return false;
}

function validateContact() {
	$j.ajax({
   		type: "POST",
   		url: "/wp-content/themes/goolsbyforsenate/ajax/validateForm.php",
   		data: $j('#cn-form').serialize() + "&form=contact",
   		success: function(msg){
   			//reset
   			$j('#cn-name').removeClass("error");
   			$j('#cn-email').removeClass("error")
   			$j('#cn-message').removeClass("error");
     		if(msg == "") {
     			//$j('#cn-form').submit();
     			$j('#contact').html("<h2>Thank you for contacting our campaign</h2>");
     		} else {
     			var e = new Array();
     			e = msg.split("|");
     			for(var i in e) {
	     			$j('#' + e[i]).addClass("error");
     			}
     		}
   		}
 	});
 	return false;
}

function formatPhone(element) {
	var allowedChars = "0123456789";
	var token = $j('#' + element).val();
	var arr = new Array();
	var x = 0;
	for(var i=0;i<token.length;i++) {
		char = token.substring(i,i+1);
		if(allowedChars.indexOf(char) != -1) {
			arr[x] = char;
			x++;
		}
			
	}
	var str = "";
	for(var j in arr) {
		if(j == 0) {
			str = "(";
		} else if(j == 3) {
			str = str + ") ";
		} else if(j == 6) {
			str = str + "-";
		}
		
		str = str + arr[j]; 
		
	}
	if(str == "")
		str = "";
	$j("#" + element).val(str);
}
