function fbFetch(album_id, div){
	//Set Url of JSON data from the facebook graph api. make sure callback is set with a '?' to overcome the cross domain problems with JSON
	var album_url = "http://graph.facebook.com/"+album_id+"/photos&callback=?";
	
	//Use jQuery getJSON method to fetch the data from the url and then create our unordered list with the relevant data.
	$.getJSON(album_url,function(json){
		var html = "<ul>";
		var max_count = 4;
		var count = 0;
		
		//loop through and within data array's retrieve the message variable.
		$.each(json.data,function(i,fb){
			count++;
			
			var photo_url = fb.picture;
			var photo_link = fb.link;
			
			if(count == max_count) class_val = "class='last' ";
			else class_val = "";
			
			if(count <= max_count) html += "<li "+class_val+"><a href=\""+photo_link+"\" target=\"_blank\"><img src=\""+photo_url+"\"></a></li>";
		});
		html += "<li class='clear'></li></ul>";		
		
		//A little animation once fetched
		$('#'+div).html(html);

	});
};

function fbShowFetch(album_id, div){
	//Set Url of JSON data from the facebook graph api. make sure callback is set with a '?' to overcome the cross domain problems with JSON
	var album_url = "http://graph.facebook.com/"+album_id+"/photos&callback=?";
	
	//Use jQuery getJSON method to fetch the data from the url and then create our unordered list with the relevant data.
	$.getJSON(album_url,function(json){
		var html = "";
		var max_count = 4;
		var count = 0;
		
		//loop through and within data array's retrieve the message variable.
		$.each(json.data,function(i,fb){
			count++;
			
			var photo_url = fb.picture;
			var photo_link = fb.link;
			
			var photo_txt = fb.images[3]['source'];
			
			if(count == max_count) class_val = "class='last' ";
			else class_val = "";
			
			if(count <= 1) html += "<a href=\""+photo_link+"\" target=\"_blank\"><img src=\""+photo_txt+"\"></a>";
		});
			
		
		//A little animation once fetched
		$('#'+div).html(html);

	});
};

function buyTickets(event_title, price) {
	
	var paypal_form = document.createElement("form");
  paypal_form.method="post" ;
  paypal_form.action = "https://www.paypal.com/cgi-bin/webscr";
  paypal_form.target = "_blank";
  
  var input_form = document.createElement("input");
  
  input_form.setAttribute("name", "add");
  input_form.setAttribute("value", "1");
  input_form.setAttribute("type", "hidden");
  paypal_form.appendChild(input_form) ;
  
  var input_form = document.createElement("input");
  input_form.setAttribute("name", "cmd");
  input_form.setAttribute("value", "_cart");
  input_form.setAttribute("type", "hidden");
  paypal_form.appendChild(input_form) ;
  
  var input_form = document.createElement("input");
  input_form.setAttribute("name", "business");
  input_form.setAttribute("value", "chs@packageofprevention.com");
  input_form.setAttribute("type", "hidden");
  paypal_form.appendChild(input_form) ;
  
  var input_form = document.createElement("input");
  input_form.setAttribute("name", "item_name");
  input_form.setAttribute("value", event_title);
  input_form.setAttribute("type", "hidden");
  paypal_form.appendChild(input_form) ;
  
  var input_form = document.createElement("input");
  input_form.setAttribute("name", "item_number");
  input_form.setAttribute("value", "#RSVP");
  input_form.setAttribute("type", "hidden");
  paypal_form.appendChild(input_form) ;
  
  var input_form = document.createElement("input");
  input_form.setAttribute("name", "amount");
  input_form.setAttribute("value", price);
  input_form.setAttribute("type", "hidden");
  paypal_form.appendChild(input_form) ;
  
  var input_form = document.createElement("input");
  input_form.setAttribute("name", "no_shipping");
  input_form.setAttribute("value", "0");
  input_form.setAttribute("type", "hidden");
  paypal_form.appendChild(input_form) ;
  
  var input_form = document.createElement("input");
  input_form.setAttribute("name", "no_note");
  input_form.setAttribute("value", "1");
  input_form.setAttribute("type", "hidden");
  paypal_form.appendChild(input_form) ;
  
  var input_form = document.createElement("input");
  input_form.setAttribute("name", "currency_code");
  input_form.setAttribute("value", "USD");
  input_form.setAttribute("type", "hidden");
  paypal_form.appendChild(input_form) ;
  
  var input_form = document.createElement("input");
  input_form.setAttribute("name", "lc");
  input_form.setAttribute("value", "US");
  input_form.setAttribute("type", "hidden");
  paypal_form.appendChild(input_form) ;
  
  var input_form = document.createElement("input");
  input_form.setAttribute("name", "bn");
  input_form.setAttribute("value", "PP-ShopCartBF");
  input_form.setAttribute("type", "hidden");
  paypal_form.appendChild(input_form) ;
  
  document.body.appendChild(paypal_form) ;
  paypal_form.submit() ;
  document.body.removeChild(paypal_form) ;
	
}

function donateNow() {
	
	var paypal_form = document.createElement("form");
  paypal_form.method="post" ;
  paypal_form.action = "https://www.paypal.com/cgi-bin/webscr";
  paypal_form.target = "_blank";
  
  var input_form = document.createElement("input");
  
  input_form.setAttribute("name", "add");
  input_form.setAttribute("value", "1");
  input_form.setAttribute("type", "hidden");
  paypal_form.appendChild(input_form) ;
  
  var input_form = document.createElement("input");
  input_form.setAttribute("name", "cmd");
  input_form.setAttribute("value", "_donations");
  input_form.setAttribute("type", "hidden");
  paypal_form.appendChild(input_form) ;
  
  var input_form = document.createElement("input");
  input_form.setAttribute("name", "business");
  input_form.setAttribute("value", "chs@packageofprevention.com");
  input_form.setAttribute("type", "hidden");
  paypal_form.appendChild(input_form) ;
  
  var input_form = document.createElement("input");
  input_form.setAttribute("name", "item_name");
  input_form.setAttribute("value", "Package of Prevention Donation");
  input_form.setAttribute("type", "hidden");
  paypal_form.appendChild(input_form) ;
  
  var input_form = document.createElement("input");
  input_form.setAttribute("name", "item_number");
  input_form.setAttribute("value", "chs@packageofprevention.com");
  input_form.setAttribute("type", "hidden");
  paypal_form.appendChild(input_form) ;
  
  var input_form = document.createElement("input");
  input_form.setAttribute("name", "currency_code");
  input_form.setAttribute("value", "USD");
  input_form.setAttribute("type", "hidden");
  paypal_form.appendChild(input_form) ;
  
  var input_form = document.createElement("input");
  input_form.setAttribute("name", "lc");
  input_form.setAttribute("value", "US");
  input_form.setAttribute("type", "hidden");
  paypal_form.appendChild(input_form) ;
  
  var input_form = document.createElement("input");
  input_form.setAttribute("name", "bn");
  input_form.setAttribute("value", "PP-DonationsBF:btn_donate_SM.gif:NonHostedGuest");
  input_form.setAttribute("type", "hidden");
  paypal_form.appendChild(input_form) ;
  
  document.body.appendChild(paypal_form) ;
  paypal_form.submit() ;
  document.body.removeChild(paypal_form) ;
	
}

function validateAdd2Count() {
	
	$("#error_first_name").empty().hide();
	//$("#error_last_name").empty().hide(); 
	$("#error_city").empty().hide(); 
	$("#error_email_address").empty().hide();
	$("#error_screen_type").empty().hide(); 
	$("#error_validate").empty().hide();  
  
	var addcount_first_name	= $("#addcount_first_name").val();
	//var addcount_last_name	= $("#addcount_last_name").val();
	var addcount_city				= $("#addcount_city").val();
	var addcount_email			= $("#addcount_email_address").val();
	var addcount_screen			= $("#addcount_screen_type").val();
	var addcount_validate		= $("#addcount_validate_captcha").val();
	
	var errors = 0;
	
	if (addcount_first_name == null || addcount_first_name == '') {
		$("#error_first_name").show()
		.append("First Name is required");
		errors++; 
	}
	/*if (addcount_last_name == null || addcount_last_name == '') {
		$("#error_last_name").show()
		.append("Last Name is required");
		errors++; 
	}*/
	if (addcount_city == null || addcount_city == '') {
		$("#error_city").show()
		.append("City is required");
		errors++; 
	}
	if (addcount_email == null || addcount_email == '') {
		$("#error_email_address").show()
		.append("Email is required");
		errors++; 
	}
	if (addcount_screen == null || addcount_screen == '') {
		$("#error_screen_type").show()
		.append("Select Screen Type");
		errors++; 
	}
	if (addcount_validate == null || addcount_validate == '') {
		$("#error_validate").show()
		.append("Validate your submission");
		errors++; 
	}	
	
	if (errors > 0) {
		//alert (errors+" Errors were found on the form");
		return false;
	} 
}   

function validateContact() {

	$("#error_first_name").empty().hide();
	$("#error_email_address").empty().hide(); 
	$("#error_city").empty().hide(); 
	$("#error_state").empty().hide();
	$("#error_screen_type").empty().hide(); 
	$("#error_validate").empty().hide();  
	
	var contact_first_name= $("#contact_first_name").val();
	var contact_city			= $("#contact_city").val();
	var contact_state			= $("#contact_state").val();
	var contact_email			= $("#contact_email_address").val();
	var contact_validate	= $("#contact_validate_captcha").val();
	
	var errors = 0;
	
	if (contact_first_name == null || contact_first_name == '') {
		$("#error_first_name").show()
		.append("First Name is required");
		errors++; 
	}
	if (contact_city == null || contact_city == '') {
		$("#error_city").show()
		.append("City is required");
		errors++; 
	}
	if (contact_state == null || contact_state == '') {
		$("#error_state").show()
		.append("State is required");
		errors++; 
	}
	if (contact_email == null || contact_email == '') {
		$("#error_email_address").show()
		.append("Email is required");
		errors++; 
	}
	if (contact_validate == null || contact_validate == '') {
		$("#error_validate").show()
		.append("Validate your submission");
		errors++; 
	}	
	
	if (errors > 0) {
		//alert (errors+" Errors were found on the form");
		return false;
	} 
}      
 
function isNumeric(form_value) {
	if (form_value.match(/^\d+$/) == null)
		return false;
	else 
		return true; 
} 
