function show_join_now_form(){
	$('#join_now_form').overlay({
		expose: {
			color: '#333',
			opacity: 0.7
		},
		left: 'center',
		top: '12%',
		closeOnClick: true
	}).load();
	if(!$("#join_now_form").overlay().isOpened()){
		$("#join_now_form").overlay({
			expose: {
				color: '#333',
				opacity: 0.7
			},
			left: 'center',
			top: '12%',
			closeOnClick: true
		}).load();
	}
	
	//Omniture Tracking
	var s=s_gi(omniture);
	s.linkTrackVars="events";
	s.linkTrackEvents="event7";
	s.events="event7,"
	s.tl(true,'o','Join Now');
	return false;
}

function show_email_page_form(){
	$('#email_page_form').overlay({
		expose: {
			color: '#333',
			opacity: 0.7
		},
		left: 'center',
		top: '12%',
		closeOnClick: true
	}).load();
	if(!$("#email_page_form").overlay().isOpened()){
		$("#email_page_form").overlay({
			expose: {
				color: '#333',
				opacity: 0.7
			},
			left: 'center',
			top: '12%',
			closeOnClick: true
		}).load();
	}
	
}


function openLinks(type,text){
	$.ajax({
			type: "POST",
			url: "/account/badges/",
			data: "type="+type+"&text="+text,
			success: function(msg){
				document.getElementById("badge_details").innerHTML = msg;
			}
		});
	$('#badges').overlay({
		expose: {
			color: '#333',
			opacity: 0.7
		},
		left: 'center',
		top: '12%',
		closeOnClick: true
	}).load();
	if(!$("#badges").overlay().isOpened()){
		$("#badges").overlay({
			expose: {
				color: '#333',
				opacity: 0.7
			},
			left: 'center',
			top: '12%',
			closeOnClick: true
		}).load();
	}
}


function edit_profile(omniture){
	if(jQuery.trim(document.getElementById('firstname').value)==''
	   || jQuery.trim(document.getElementById('lastname').value)==''
	   || jQuery.trim(document.getElementById('church').value)==''
	   || jQuery.trim(document.getElementById('church_location').value)==''
	   || jQuery.trim(document.getElementById('believe_statement').value)==''){
		alert('Please fill out all fields.');
	}else{
		var firstname=document.getElementById('firstname').value;
		var lastname=document.getElementById('lastname').value;
		var church=document.getElementById('church').value;
		var location=document.getElementById('church_location').value;
		var believe=document.getElementById('believe_statement').value;
		var marital_status=document.getElementById('marital_status');
		marital_status=marital_status.options[marital_status.selectedIndex].value;
		$("*").css("cursor", "progress");
		$.ajax({
			type: "POST",
			url: "/account/save/?t="+new Date().getTime(),
			data: "save_now=1&firstname="+firstname+"&lastname="+lastname+"&church="+church+"&church_location="+location+
					"&marital_status="+marital_status+"&believe_statement="+believe,
			success: function(msg){
				if(1==msg){
					window.location.reload();
				}else{
					$("*").css("cursor", "auto");
					alert(msg);
				}
			}
		});
	}
}

function join_now(){
	if(jQuery.trim(document.getElementById('action_hash').value)==''
	   || jQuery.trim(document.getElementById('username').value)==''
	   || jQuery.trim(document.getElementById('join_password').value)==''
	   || jQuery.trim(document.getElementById('email_address').value)==''
	   || jQuery.trim(document.getElementById('firstname').value)==''
	   || jQuery.trim(document.getElementById('lastname').value)==''
	   || jQuery.trim(document.getElementById('church').value)==''
	   || jQuery.trim(document.getElementById('church_location').value)==''
	   || jQuery.trim(document.getElementById('believe_statement').value)==''){
		alert('Please fill out all fields.');
	}else{
		var action_hash=document.getElementById('action_hash').value;
		var username=document.getElementById('username').value;
		var password=document.getElementById('join_password').value;
		var email=document.getElementById('email_address').value;
		var firstname=document.getElementById('firstname').value;
		var lastname=document.getElementById('lastname').value;
		var church=document.getElementById('church').value;
		var location=document.getElementById('church_location').value;
		var believe=document.getElementById('believe_statement').value;
		var marital_status=document.getElementById('marital_status');
		marital_status=marital_status.options[marital_status.selectedIndex].value;

		$("*").css("cursor", "progress");
		$('#but_join_now').hide();
		$('#but_join_now_gray').show();
		$.ajax({
			type: "POST",
			url: "/account/join_now/?t="+new Date().getTime(),
			data: "join_now=1&action_hash="+action_hash+"&username="+username+"&password="+password+"&email_address="+email+
					"&firstname="+firstname+"&lastname="+lastname+"&church="+church+"&church_location="+location+
					"&marital_status="+marital_status+"&believe_statement="+believe,
			success: function(msg){
				if(1==msg){
					$('#join_now_form').overlay().close();
					$("*").css("cursor", "auto");
					//Reload the page the user is on to show them the logged in version
					if(-1==String(window.location).indexOf('/account/')){
						window.location.reload();
					}else{
						window.location="http://www.believe.com";
					}
				}else{
					$('#but_join_now').show();
					$('#but_join_now_gray').hide();
					$("*").css("cursor", "auto");
					alert(msg);
				}
			}
		});
	}
}


function email_page(){
	if(jQuery.trim(document.getElementById('email_address').value)==''
		|| jQuery.trim(document.getElementById('email_url').value)==''
		|| jQuery.trim(document.getElementById('email_username').value)==''
		|| jQuery.trim(document.getElementById('email_title').value)==''
		|| jQuery.trim(document.getElementById('email_summary').value)==''
		|| jQuery.trim(document.getElementById('email_comment').value)==''){
		alert('Please fill out all fields.');
	}else{
		var email=document.getElementById('email_address').value;
		var url=encodeURI(document.getElementById('email_url').value);
		var title=encodeURI(document.getElementById('email_title').value);
		var username=encodeURI(document.getElementById('email_username').value);
		var author=encodeURI(document.getElementById('email_author').value);
		var ymdt=encodeURI(document.getElementById('email_ymdt').value);
		var summary=encodeURI(document.getElementById('email_summary').value);
		var comment=encodeURI(document.getElementById('email_comment').value);

		$("*").css("cursor", "progress");
		$.ajax({
			type: "POST",
			url: "/account/email_page/",
			data: "send=1&email_address="+email
				+"&url="+url
				+"&title="+title
				+"&comment="+comment
				+"&username="+username
				+"&author="+author
				+"&ymdt="+ymdt
				+"&summary="+summary,
			success: function(msg){
				if(1==msg){
					$('#email_page_form').overlay().close();
					$("*").css("cursor", "auto");
				}else{
					$("*").css("cursor", "auto");
					alert(msg);
				}
			}
		});
	}
}


function clickPassword(){
	document.getElementById("fake_login_password").style.display = 'none';
	document.getElementById("login_password").style.display = 'inline';
	document.getElementById("login_password").focus();
}
function blurPassword(){
	if(document.getElementById("login_password").value == ''){
		document.getElementById("login_password").style.display = 'none';
		document.getElementById("fake_login_password").style.display = 'inline';
	}
}

function clickUsername(){
	if(document.getElementById("login_user").value=="email"){
		document.getElementById("login_user").value="";
	}
	document.getElementById("login_user").className = 'login-clicked';
}
function blurUsername(){
	if(document.getElementById("login_user").value == '' || document.getElementById("login_user").value == 'email' ){
		document.getElementById("login_user").value = 'email';
		document.getElementById("login_user").className = 'login';
	}
}

function submit_login_form(omniture,event){
	if(jQuery.trim(document.getElementById('login_user').value)==''
	   || jQuery.trim(document.getElementById('login_password').value)==''){
		return true;
	}
	if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)){
		return login(omniture);
	}else{
		return true;
	}
}

function login(omniture){
	if(jQuery.trim(document.getElementById('login_user').value)==''
	   || jQuery.trim(document.getElementById('login_password').value)==''){
		alert('Please fill out your username and password.');
		return false;
	}
	var email=document.getElementById('login_user').value;
	var password=document.getElementById('login_password').value;
	$("*").css("cursor", "progress");
	$.ajax({
		type: "POST",
		url: "/account/login/?t="+new Date().getTime(),
		data: "login=1&email="+email+"&password="+password,
		success: function(msg){
			if(1==msg){
				//Reload the page the user is on to show them the logged in version
				window.location.reload();
			}else{
				$("*").css("cursor", "auto");
				if(-1==msg){
					alert('The system couldn\'t log you in.  Please check your email and password.');
				}else{
					alert(msg);
				}
			}
		}
	});
	return false;
}

function load_posts_comments(catid,subcatid,type,change_cursor){
	if(1==change_cursor){
		jQuery("body").css("cursor", "progress");
	}
	jQuery.ajax({
		type: "GET",
		url: "/comments/get_popular_posts_comments/",
		data: "catid="+catid+"&subcatid="+subcatid+"&type="+type,
		success: function(msg){
			jQuery('div#posts_comments').empty();
			jQuery('div#posts_comments').append(msg);
			jQuery("body").css("cursor", "auto");
		}
	});
	return false;
}

function load_other_bible_study_topics(catid,subcatid,type){
	var query_string="catid="+catid+"&subcatid="+subcatid+"&type="+type;
	jQuery.ajax({
		type: "GET",
		url: "/bible_study/get_other_bible_study_topics/",
		data: query_string,
		success: function(msg){
			jQuery('div#posts_comments').empty();
			jQuery('div#posts_comments').append(msg);
			jQuery("body").css("cursor", "auto");
		}
	});
	return false;
}


function homepage_next_article(){
	jQuery('div#article'+featured_article).hide();
	featured_article=featured_article+1;
	if(featured_article>featured_article_count){
		featured_article=1;
	}
	jQuery('div#article'+featured_article).show();
	
}
function homepage_prev_article(){
	jQuery('div#article'+featured_article).hide();
	featured_article=featured_article-1;
	if(featured_article<1){
		featured_article=featured_article_count;
	}
	jQuery('div#article'+featured_article).show();
	
}


function load_comments(allow_comments,tid){
	if(1==allow_comments){
		$.ajax({
			type: "GET",
			url: "/comments/get_topic_comments/",
			data: "tid="+tid,
			success: function(msg){
				$('#comments').empty();
				$('#comments').append(msg);
			}
		});
	}
}

function show_add_comment(parent_cid){
	document.getElementById('parent_cid').value=parent_cid;
	$('#add_comment').overlay({
		expose: {
			color: '#333',
			opacity: 0.7
		},
		left: 'center',
		top: '30%',
		closeOnClick: false
	}).load();
	if(!$("#add_comment").overlay().isOpened()){
		$("#add_comment").overlay({
			expose: {
				color: '#333',
				opacity: 0.7
			},
			left: 'center',
			top: '30%',
			closeOnClick: false
		}).load();
	}
}


function delete_photo(num){
	if(confirm("Are you sure you want to delete this picture?")){
		$.ajax({
			type: "GET",
			url: "/account/my_pictures/",
			data: "delete="+num,
			success: function(msg){
				if('1'==msg){
					window.location.reload();
				}else{
					alert('There was an problem deleting your picture.  Please try again later.');
				}
			}
		});
		
	}
}

function show_this_photo(num){
	if(confirm("Are you sure you want to show this picture on your profile?")){
		$.ajax({
			type: "GET",
			url: "/account/my_pictures/",
			data: "default="+num,
			success: function(msg){
				if('1'==msg){
					window.location.reload();
				}else{
					alert('There was an problem changing your default picture.  Please try again later.');
				}
			}
		});
		
	}
}

function joinChurch(tid){
	$.ajax({
			type: "GET",
			url: "/church/join/",
			data: "tid="+tid,
			success: function(msg){
				if('1'==msg){
					window.location.reload();
				}else{
					alert('There was an problem joining this church.  Please try again later.');
				}
			}
		});
}

function removeChurch(tid){
	$.ajax({
			type: "GET",
			url: "/church/remove/",
			data: "tid="+tid,
			success: function(msg){
				if('1'==msg){
					window.location.reload();
				}else{
					alert('There was an problem removing this church.  Please try again later.');
				}
			}
		});
}

function daily_widget_tab_change(show_tab_sel, hide_tab_sel) {
	$(hide_tab_sel).addClass('non_selected');
	$(hide_tab_sel).removeClass('selected');
	$(hide_tab_sel+'_content').addClass('hidden');
	
	$(show_tab_sel).addClass('selected');
	$(show_tab_sel).removeClass('non_selected');
	$(show_tab_sel+'_content').removeClass('hidden');
}

function fullWindowDiv() {
	var pageHeight = 800;
	var pageWidth = 100;
	
	if ( window.innerHeight && window.scrollMaxY ) {
		pageHeight = window.innerHeight + window.scrollMaxY;
	}
	else if ( document.body.scrollHeight > document.body.offsetHeight ) { // all but Explorer Mac
		pageHeight = document.body.scrollHeight;
	}
	else {
		pageHeight = document.body.offsetHeight + document.body.offsetTop;
	}
	
	var full_div = document.getElementById('blockUI');
	
	if(full_div != null)
	{
		full_div.style.height = pageHeight+"px";
		full_div.style.visibility = "visible";
	}
	
	var content_div = document.getElementById('blockUI_adunit');
	if(content_div != null) {
		content_div.style.display = "block";
	}
}
