





//var serverUrl = "http://localhost:8081"
var serverUrl = "http://wdfundgolf.appspot.com"

golfTourney = {

    content: function(name){
        var filename = name+".html"
        $("#content").load(filename);
    },

    photoContent: function(name){
        var filename = name+".html"
        $("#photo_content").load(filename);
    },

    submitForm: function(){
        alert("Thank you for your comment!");
    },

    showObj: function(obj){

        var out = " - "+obj.length;
        for(var n in obj)
            out+=" "+n+" \n";
        alert(out);

    },
    serverMessage: function(mess){
        alert(message);
    },

    serverError: function(err){
        alert(err);
    },

    showGallery: function(str){
        if (str !== undefined){
            if (str ==='images2010'){
                var elem ="#"+str;
                $(elem).html("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,18,0' width='560' height='400' id='divslide'><param name='movie' value='http://www.divshare.com/flash/slide?myId=14536524-535' /><param name='allowFullScreen' value='true' /><embed src='http://www.divshare.com/flash/slide?myId=14536524-535' width='560' height='400' name='divslide' allowfullscreen='true' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object>");
            }
            else if (str ==='images2009'){
                var elem2 ="#"+str;
                $(elem2).html("<object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,18,0' width='560' height='400' id='divslide'><param name='movie' value='http://www.divshare.com/flash/slide?myId=14537669-6ad' /><param name='allowFullScreen' value='true' /><embed src='http://www.divshare.com/flash/slide?myId=14537669-6ad' width='560' height='400' name='divslide' allowfullscreen='true' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer'></embed></object>");
            }
        }
    },

    submitRegister: function(){
        var inp= $("input");
        var str ="";
        for (var i=0;i<inp.length;i++){
            var name = inp[i].name;
            var value = inp[i].value;
            if (name!=null&value!=null){
                if (name.length>0 & value.length>0){
                    str+=name+"="+value;
                }
                if (i<inp.length-1){
                    str+="&";
                }
            }
            
        }
        $.getScript(serverUrl+"/register?"+str, function(data){
            eval(data);
        });

        return false;
    },

    registrationDone: function(text){
        var str ="<div> ";
        str+=text;
        str+="</div>";
        $("#registerForm").html(str);
    },


    submitSurvey: function(){
        var inp= $("input");
        var str ="";
        for (var i=0;i<inp.length;i++){
            var name = inp[i].name;
            var value = inp[i].value;
            if (name!=null&value!=null){
                if (name.length>0 & value.length>0){
                    str+=name+"="+value+"&";
                }
                if (i<inp.length-1){
                    str+="&";
                }
            }
         
        }
        $.getScript(serverUrl+"/survey?"+str, function(data){
            eval(data);
        });

        return false;
    },


    surveyDone: function(text){
        var str ="<div> ";
        str+=text;
        str+="</div>";
        $("#surveyForm").html(str);
    },


    showBids: function(bids){
        var item = null;
		if (bids !== undefined){
			if (bids[0]){
				var content = "<table>";
				item = bids[0].item;
				for (b in bids){
					content += "<tr>";
					content += "<td>"+bids[b].name+"</td><td>$"+bids[b].amount+"</td><td>"+bids[b].date+"</td>";
					content += "</tr>";
				}
				content += "</table>";
				if (item){
					$("#"+item+"bids").empty();
					$("#"+item+"bids").append(content);
				}
	   
			}
			else{
				golfTourney.noBids(bids.item);
			}
		
		}

    },

    noBids: function(item){
        this.hideLoading(item);
        $("#"+item+"bids").empty();
        $("#"+item+"bids").append("No bids yet...");
    },


    makeBid: function(biditem){
		alert("auction is closed.. see you on the course!);
		return;
        if (biditem.id)
        {
            biditem = biditem.id;
        }
        var name = $("#"+biditem+" :text")[0].value;
        var email = $("#"+biditem+" :text")[1].value;
        var amount = $("#"+biditem+" :text")[2].value;
        var desc = $("#"+biditem+" :hidden")[0].value;
        var from = $("#"+biditem+" :hidden")[1].value;
        var img = $("#"+biditem+" :hidden")[2].value;

        if (name|amount){
            golfTourney.showLoading(biditem);
            var qstr = "name="+name+"&item="+biditem+"&amount="+amount+"&from="+from+"&desc="+desc+"&img="+img+"&email="+email;

            $.getScript(serverUrl+"/auction?"+qstr, function(data){
				eval(data);
            });
        }
        else{
            golfTourney.hideLoading(biditem);
            var content = " Need a name and a bid for "+biditem;
            $("#"+biditem+"bids").append(content);
        }
    },


    checkBids: function(item){
        // alert("Auction is closed, join us on the course!");
        // return false;
        golfTourney.showLoading(item);
        item+="&date";
        var d = new Date();
        item+=d.getMilliseconds();
        $.getScript(serverUrl+"/bids?item="+item, function(data){
            eval(data);
        });
    },

    showLoading: function(item){
        var content = "<img src='images/progress.gif'/>";
        $("#"+item+"bids").append(content);
    },

    hideLoading: function(item){
        $("#"+item+"bids").empty();
    }

}













