
    function wsUserStat(fbId,name,email,oid){
        //Get the JSON string and pass it to the cb function
        $.get("http://www.godsurfer.com/AlphaProject/webservice/ws_userStatEntriesAdded.php?fbId="+fbId+"&name="+name+"&email="+email+"&oid="+oid, function(data){cb(data)});
    }

    function cb(data){
    //called from wsUserStat
    //cb = CallBack
    //converts the JSON string to a JavaScript object
    myJSONobj = eval("myJSONobj="+data);
    $("#uSEA").html(" " + myJSONobj.userStatEntriesAdded);
    $("#uSPC").html(" " + myJSONobj.userStatPopularCategory);
    $("#uSEV").html(" " + myJSONobj.userStatEntriesVoted);
    $("#uSCC").html(" " + myJSONobj.userStatCommentCount);
    SetCookie('userId',myJSONobj.userId);
    }

    function wsBibleGame(fbId,oid){
        $.get("http://www.godsurfer.com/AlphaProject/webservice/ws_bibleGame.php?fbId="+fbId+"&oid="+oid, function(data){bg(data)});
    }

    function bg(data){
        //called from usBibleGame
        //BibleGame JSON Return Data
       //document.getElementById('gameStats').style.display = "none";
       myJSONobj = eval("myJSONobj="+data);

        if(myJSONobj.testEnd == "true"){
           //document.getElementById('game').style.display = "none";
           $('#gameResult').html("Already");
           $('#gameScore').html("Your total score:" + myJSONobj.userPoints);
           //document.getElementById('gameStats').style.display = "block";
        }else{
            $('#questionText').text(myJSONobj.questionText);
            $("#bga1").attr("value", myJSONobj.questionAnswerList[0].answerText);
            $("#bga2").attr("value", myJSONobj.questionAnswerList[1].answerText);
            $("#bga3").attr("value", myJSONobj.questionAnswerList[2].answerText);
            $("#bga4").attr("value", myJSONobj.questionAnswerList[3].answerText);
            $('#A1').text(myJSONobj.questionAnswerList[0].answerText);
            $('#A2').text(myJSONobj.questionAnswerList[1].answerText);
            $('#A3').text(myJSONobj.questionAnswerList[2].answerText);
            $('#A4').text(myJSONobj.questionAnswerList[3].answerText);
            $('#bg').append('<input type="hidden" id="bgAnswerValue" value="'+ myJSONobj.questionAnswerValue +'" />');
           //document.getElementById('game').style.display = "block";
        }

    }

    function wsBiblegameResults(fbId,blnVal){
        $.get("http://www.godsurfer.com/AlphaProject/webservice/ws_bibleGameUpdate.php?fbId="+fbId+"&blnValue="+blnVal, function(data){bgResults(data)});
    }

    function bgResults(data){
        //caled from wsBibleGameResults
        myJSONobj = eval("myJSONobj="+data);
        $('#gameScore').html("Your total score:" + myJSONobj.gamePoints);
    }

    function checkOpenId(oid){
        //alert(oid);
        document.getElementById('userLogin').style.display = "none";
        //document.getElementById('preGame').style.display = "none";
        //document.getElementById('userWelcome').style.display = "inline";
        //alert('oid: ' + oid);
        $.get("http://www.godsurfer.com/AlphaProject/webservice/ws_openIdLogin.php?oId="+oid, function(data){cbOI(data)});
        //alert(oid);
       //document.getElementById('userWelcome').innerHTML = "<h2 class='mem'>Welcome " + userName + "</h2> <p class='bottom2LoggedIn'></p>";
       //document.getElementById('fbFan').style.display = "inline";
      
        wsUserStat('','','',oid);
        wsBibleGame('',oid);

        document.getElementById('pray').style.display = "block";

        //document.getElementById('tab3').style.display = "inline";
        //document.getElementById('tabs-3').style.display = "inline";
    }
    function cbOI(data){
        myJSONobj = eval("myJSONobj="+data);

        //alert('cbOI' + myJSONobj.userName);
        //$('#gameScore').html("Your total score:" + myJSONobj.gamePoints);
        document.getElementById('userWelcome').style.display = "inline";
        document.getElementById('userWelcome').innerHTML = "<h2 class='mem'>Welcome " + myJSONobj.userName + "</h2> <p class='bottom2LoggedIn'></p>";
        document.getElementById('fbFan').style.display = "inline";
    }
 $(document).ready(function(){
     $('#btn').click(function(){
        var value;

        if (undefined === $("input[name=bga]:checked").val()) {
            value = 0;
            alert('Please select an answer.');
            return;
        }else{
            value = $("input[@name=bga]:checked").val();
        }
       var answer = $("#bgAnswerValue").val();
       if(value == answer){
           $('#bgValue').html("Correct!");
           //document.getElementById('game').style.display = "none";
           document.getElementById('gameStats').style.display = "block";
           $('#gameResult').html('Correctly!<br/>');
           wsBiblegameResults(ReadCookie('fbId'),true);
       }else{
           $('#bgValue').html("Incorrect!");
           //document.getElementById('game').style.display = "none";
           document.getElementById('gameStats').style.display = "block";
           $('#gameResult').html('Incorrectly!<br/>');
           wsBiblegameResults(ReadCookie('fbId'),false);
       }

     });
   });

	$(function() {
            //This function handles the dialog popup box for the Statement of Faith
            $("#userReg").hide();
            $("#sof").click(function() {
                $("#sofDialog").dialog('open')
		$("#sofDialog").dialog({
			bgiframe: true,
			height: 600,
                        width: 800,
			modal: true
		});
            });
            $("#faq").click(function() {
                $("#faqDialog").dialog('open')
		$("#faqDialog").dialog({
			bgiframe: true,
			height: 600,
                        width: 800,
			modal: true
		});    
            });

            $("#archive").click(function() {
                $.ajaxSetup ({
                    cache: false
                });
                var ajax_load = "<img class='loading' src='images/load.gif' alt='loading...' />";
                $("#archiveDialog").html(ajax_load);
                $.get("http://www.godsurfer.com/AlphaProject/webservice/ws_getArchive.php", function(data){archive(data)});

                $("#archiveDialog").dialog('open')
		$("#archiveDialog").dialog({
			bgiframe: true,
			height: 600,
                        width: 1000,
			modal: true
		});
            });

            $("#standings").click(function() {

                $.ajaxSetup ({
                        cache: false
                });
                $.get("http://www.godsurfer.com/AlphaProject/webservice/ws_bibleGameLeaderBoard.php", function(data){bgLB(data)});

                $("#standingsDialog").dialog('open')
		$("#standingsDialog").dialog({
			bgiframe: true,
			height: 600,
                        width: 800,
			modal: true
		});
                
            });            
		$("#sofDialog").hide();
                $("#faqDialog").hide();
                $("#standingsDialog").hide();
                $("#archiveDialog").hide();
        });

        function bgLB(data){
            //caled from wsBibleGameResults
            myJSONobj = eval("myJSONobj="+data);
            var strHTML;
            strHTML = "<center><h1>Bible Trivia Leader Board:</h1><br/><br/>";
            strHTML = strHTML + "<table width=90%><tr><th width=50%><h2>Name:</th><th width=50%><h2>Points</h2></th></tr>";

            //$('#standingsDialog').append("<center><h1>Bible Trivia Leader Board:</h1></center><br/><br/>");
            //$('#standingsDialog').append("<table border=1><tr><td>Name:</td><td>Points</td></tr>");
            for (var i = 0; i < myJSONobj.length; i++) {
                 strHTML = strHTML + "<tr><td align=center>" + myJSONobj[i].userName + "</td><td align=center>" + myJSONobj[i].userPoints + "</td></tr>";
            }
            strHTML = strHTML + "</table></center>";
            //$('#standingsDialog').append("</table>");
            $('#standingsDialog').html(strHTML);
        }

        function archive(data){
            myJSONobj = eval("myJSONobj="+data);
            var strHTML;
            strHTML = "<center><h1>GODSurfer Archives:</h1></center><br/><br/>";

            for (var i = 0; i < myJSONobj.length; i++) {
                    strHTML = strHTML + "<a href='" + myJSONobj[i].URL + "' target = 'blank'>" + myJSONobj[i].title + "</a><br/>";
            }
            //alert(strHTML);
            $('#archiveDialog').html(strHTML);
        }

      $(document).ready(function(){
          if($.getQueryString({ ID:"QE"})!='undefined'){
              //alert($.getQueryString({ID:"QE"}));

               var $tabs = $('#tabs').tabs();
               $tabs.tabs('select', 2);
          }
        });
/*  if($.getQueryString({ ID:"regError"})!='undefined')
	$(function() {
		//run the hide Login Code
		function runEffect(){
			//get effect type from
			var selectedEffect = 'blind';

			//most effect types need no options passed by default
			var options = {};
			//check if it's scale, transfer, or size - they need options explicitly set
			if(selectedEffect == 'scale'){  options = {percent: 0}; }
			else if(selectedEffect == 'transfer'){ options = { to: "#button", className: 'ui-effects-transfer' }; }
			else if(selectedEffect == 'size'){ options = { to: {width: 200,height: 60} }; }

			//run the effect
			$("#userLogin").hide(selectedEffect,options,250);
		};

		//callback function to bring a hidden box back
		function callback(){
			setTimeout(function(){
				$("#userLogin:hidden").removeAttr('style').hide().fadeIn();
			}, 1000);
		};
            
                if($.getQueryString({ ID:"regError"})!='undefined')
                    {
			runEffect();
                        //runs hide code
                        var options = {};
                        $("#userReg").show('blind',options,1500);
                        //runs show code
			return false;
                    };
            

		//set effect from select menu value
		$("#register").click(function() {
			runEffect();
                        //runs hide code
                        var options = {};
                        $("#userReg").show('blind',options,1500);
                        //runs show code
			return false;
		});

	});

	$(function() {
		//run the hide Reg Code
		function runEffect(){
			//get effect type from
			var selectedEffect = 'blind';

			//most effect types need no options passed by default
			var options = {};
			//check if it's scale, transfer, or size - they need options explicitly set
			if(selectedEffect == 'scale'){  options = {percent: 0}; }
			else if(selectedEffect == 'transfer'){ options = { to: "#userReg", className: 'ui-effects-transfer' }; }
			else if(selectedEffect == 'size'){ options = { to: {width: 200,height: 60} }; }

			//run the effect
			$("#userReg").hide(selectedEffect,options,500);
                        //$("#userReg:visible").removeAttr('style').hide().fadeOut();

		};

		//callback function to bring a hidden box back
		function callback(){
			setTimeout(function(){
				$("#userReg:hidden").removeAttr('style').hide().fadeIn();
			}, 5000);
		};

		//set effect from select menu value
		$("#alreadyUser").click(function() {
			runEffect();
                        //runs hide code
                        var options = {};
                        $("#userLogin").show('blind',options,1500);
                        //runs show code
			return false;
		});

	});
*/

        //This is a dumb title for a function.  This function handles the call to display the Question Details
        function ajaxFunction(id,title)
        {
             onCF(id,title);
        }

        //onCF is equal to onClickFunction.  Another dumb name.  I should rename these functions.
        function onCF(id,myTitle) {
            $.ajaxSetup ({
                    cache: false
            });
            var ajax_load = "<img class='loading' src='images/load.gif' alt='loading...' />";

            //	load() functions
            //var loadUrl = "functions/story.php?id=" + id;
            var loadUrl = "functions/question.php?id=" + id;
            
                    $("#readMoreDialog").dialog('open')
                    $("#readMoreDialog").dialog({
                           bgiframe: true,
                           height: 600,
                           width: 800,
                           title: myTitle
                     });
                     //alert(loadUrl);
                    $("#readMoreDialog").html(ajax_load).load(loadUrl);

                    $('#readMoreDialog').dialog({ dialogClass: 'alert' });
                    //getter
                    var dialogClass = $('#readMoreDialog').dialog('option', 'dialogClass');
                    //setter
                    $('.selector').dialog('option', dialogClass, 'alert');

                   //getter
                    var position = $("#readMoreDialog").dialog('option', 'position');
                    //setter
                    $("#readMoreDialog").dialog('option', position, 'top');
        }
        function voteFunction(id,type)
        {
            /*alert(id);
            alert(type);*/
            $.ajaxSetup ({
                    cache: false
            });
            var ajax_load = "<img class='loading' src='images/load.gif' alt='loading...' />";
            var loadUrl = "functions/functionStory.php?storyId=" + id + "&type=" + type;

            $("#readMoreDialog").html(ajax_load).load(loadUrl);

            if(type==0){
                 $("#readMoreDialog").dialog('close')
                 window.location.reload(true);
            }else{
                loadUrl = "functions/story.php?id=" + id;
                $("#readMoreDialog").html(ajax_load).load(loadUrl);
                $.get("http://www.godsurfer.com/AlphaProject/webservice/ws_getStoryInfo.php?storyId="+id+"&fbId="+ReadCookie('fbId')+"&oid="+ReadCookie('openIdLogin'), function(data){storyInfo(data)});
                $("#readMoreDialog").dialog('close')
            }

        }

        function voteFunctionQuestion(id,type)
        {
            //alert(id);
            //alert(type);
            $.ajaxSetup ({
                    cache: false
            });
            var ajax_load = "<img class='loading' src='images/load.gif' alt='loading...' />";
            var loadUrl = "functions/functionEntry.php?entryId=" + id + "&type=" + type + "&entryType=Question";

            $("#readMoreDialog").html(ajax_load).load(loadUrl);

            if(type==0){
                 $("#readMoreDialog").dialog('close')
                 window.location.reload(true);
            }else{
                //RE-LOAD Modal Form:
                $("#readMoreDialog").dialog('close')
                $.ajaxSetup ({
                    cache: false
                });
                ajax_load = "<img class='loading' src='images/load.gif' alt='loading...' />";
                loadUrl = "http://www.godsurfer.com/AlphaProject/controls/masterControlAjaxDisplay.php?ajaxDisplay=true&typeId=2&id=" + id;

                $("#readMoreDialog").dialog('open')
                $("#readMoreDialog").dialog({
                       bgiframe: true,
                       height: 600,
                       width: 800
                 });
                    $("#readMoreDialog").html(ajax_load).load(loadUrl);

                    $('#readMoreDialog').dialog({ dialogClass: 'alert' });
                    //getter
                    var dialogClass = $('#readMoreDialog').dialog('option', 'dialogClass');
                    //setter
                    $('.selector').dialog('option', dialogClass, 'alert');

                   //getter
                    var position = $("#readMoreDialog").dialog('option', 'position');
                    //setter
                    $("#readMoreDialog").dialog('option', position, 'top');
                }

        }

        function voteFunctionAnswer(id,type,entryId)
        {
            /*alert(id);
            alert(type);*/
            $.ajaxSetup ({
                    cache: false
            });
            var ajax_load = "<img class='loading' src='images/load.gif' alt='loading...' />";
            var loadUrl = "functions/functionEntry.php?entryId=" + id + "&type=" + type + "&entryType=Answer";
            //alert(loadUrl);

            $("#readMoreDialog").html(ajax_load).load(loadUrl);

            if(type==0){
                 $("#readMoreDialog").dialog('close')
                 window.location.reload(true);
            }else{
                //RE-LOAD Modal Form:
                $("#readMoreDialog").dialog('close')
                $.ajaxSetup ({
                    cache: false
                });
                ajax_load = "<img class='loading' src='images/load.gif' alt='loading...' />";
                loadUrl = "http://www.godsurfer.com/AlphaProject/controls/masterControlAjaxDisplay.php?ajaxDisplay=true&typeId=2&id=" + entryId;

                $("#readMoreDialog").dialog('open')
                $("#readMoreDialog").dialog({
                       bgiframe: true,
                       height: 600,
                       width: 800
                 });
                    $("#readMoreDialog").html(ajax_load).load(loadUrl);

                    $('#readMoreDialog').dialog({ dialogClass: 'alert' });
                    //getter
                    var dialogClass = $('#readMoreDialog').dialog('option', 'dialogClass');
                    //setter
                    $('.selector').dialog('option', dialogClass, 'alert');

                   //getter
                    var position = $("#readMoreDialog").dialog('option', 'position');
                    //setter
                    $("#readMoreDialog").dialog('option', position, 'top');

            }

        }

            function storyInfo(data){
                //called from ws_getStoryInfo
                //converts the JSON string to a JavaScript object
                //alert(data);
                myJSONobj = eval("myJSONobj="+data);
                if (myJSONobj === null || typeof myJSONobj === "undefined"){
                    return;
                }else{
                    var msg;
                    var title = myJSONobj.title;
                    var userName = myJSONobj.userName;
                        msg = title + ' was voted up! By: ' + userName;
                    //alert(msg);
                    $.get("http://www.godsurfer.com/AlphaProject/webservice/ws_facebookPublishing.php?message="+msg);
                }

            }



            function prayerCounter(txtfield, cntFld, maxlimit){
             var field = document.getElementById(txtfield);
             var countfield = document.getElementById(cntFld);

                    if (field.value.length > maxlimit) // if too long...trim it!
                    {
                            field.value = field.value.substring(0, maxlimit);
                            // otherwise, update 'characters left' counter
                    }else {
                            countfield.innerHTML = maxlimit - field.value.length;
                    }
            }
            function addPrayer(){
                    document.pFeed.action = 'http://www.godsurfer.com/AlphaProject/functions/functionPrayer.php';
                    document.pFeed.submit();
            }


            function SetCookie(cookieName,cookieValue,nDays) {
                 var today = new Date();
                 var expire = new Date();
                 if (nDays==null || nDays==0) nDays=1;
                 expire.setTime(today.getTime() + 3600000*24*nDays);
                 document.cookie = cookieName+"="+escape(cookieValue)
                                 + ";expires="+expire.toGMTString();
            }
            function ReadCookie(cookieName) {
                 var theCookie=""+document.cookie;
                 var ind=theCookie.indexOf(cookieName);
                 if (ind==-1 || cookieName=="") return "";
                 var ind1=theCookie.indexOf(';',ind);
                 if (ind1==-1) ind1=theCookie.length;
                 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
            }



