
function showAnswer(id){ 
    if($("#question_"+id).hasClass('answer-question')){
            $(".answer").hide();
            var elem1 = $(".answer-question");
            elem1.removeClass("answer-question");
            elem1.addClass("question");
            return;
        
    }
    
    var div = "answer_"+id;
    $(".answer").hide();
    var elem = $(".answer-question");
    elem.removeClass("answer-question");
    elem.addClass("question");
    $("#question_"+id).removeClass("question");
    $("#question_"+id).addClass("answer-question");
    $("#"+div).slideDown();
    
}
function submitQuestion(form){
    var question = form.myname.value;
    if(question =='' || trim(question)=='Ask a question here.'){
        alert("Please enter your question.");
        return false;
    }
    $.ajax({
          type: "POST",
          url: '/home/addQuestion',
          data: "question="+form.myname.value+"",
          success: function(msg) {
            $('#ask-id').html(msg);
          }
        });
        return false;
}

function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function numDaysLeft(){
    var startDate = new Date();
    var endDate = new Date("2010/08/27");
    var daysApart = Math.abs(Math.round((startDate-endDate)/86400000));


    document.write(daysApart);
}
function getHighFiveNumber(){
    var nocache = Math.random();

    $.ajax({
          type: "GET",
          url: '/home/highfive?nocache='+nocache,
          success: function(msg) {
            $('#high-five-number-id').html(msg);
          }
        });

}
function setupCountdown(){
    var theyear=2010;
    var themonth=8;
    var theday=18;
    var thehour=16;
    var themins=15;
    var thesecs=0;




    var before="24:00:00";
    var current="00:00:00";
    var montharray=new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

    var newDateSplit = countDown.split("-");
    theyear = parseInt(newDateSplit[0]);
    themonth = parseInt(newDateSplit[1]);
    theday = parseInt(newDateSplit[2]);
    thehour = parseInt(newDateSplit[3]) - 3;
    themins = parseInt(newDateSplit[4]);
    thesecs = parseInt(newDateSplit[5]);

    var today=new Date();
    var todayy=today.getYear();
    if (todayy < 1000)
            todayy+=1900;
    var todaym=today.getMonth();
    var todayd=today.getDate();
    var todayh=today.getHours();
    var todaymin=today.getMinutes();
    var todaysec=today.getSeconds();
    var todaystring=montharray[todaym]+" "+todayd+", "+todayy+" "+todayh+":"+todaymin+":"+todaysec;
    futurestring=montharray[themonth-1]+" "+theday+", "+theyear+" "+thehour+":"+themins+":"+thesecs;
    dd=Date.parse(futurestring)-Date.parse(todaystring);
    dday=Math.floor(dd/(60*60*1000*24)*1);

    var dhour=Math.floor((dd%(60*60*1000*24))/(60*60*1000)*1);
    var dmin=Math.floor(((dd%(60*60*1000*24))%(60*60*1000))/(60*1000)*1);
    var dsec=Math.floor((((dd%(60*60*1000*24))%(60*60*1000))%(60*1000))/1000*1);

    if (dday>=1) {

            document.getElementById("timeRemaining").innerHTML=before;

    } else  if(dday==0&&dhour==0&&dmin==0&&dsec==0){
            document.getElementById("timeRemaining").innerHTML=current;
            return;
    } else if (dday<0) {
            document.getElementById("timeRemaining").innerHTML=current;
    } else {
            document.getElementById("timeRemaining").innerHTML= (dhour < 10? '0' + dhour: dhour) +":"+(dmin < 10? '0' + dmin: dmin) +":"+ (dsec< 10? '0' + dsec: dsec);
            setTimeout("setupCountdown()",1000);
    }


}
