// JavaScript Document /* Create our object to hold all functions and vars ---------------------------------------------------------*/ var objSite = {}; /* ---------------------------------------------------------*/ objSite.site_url = "http://www.bookedup.org.uk/"; objSite.reloadPage = function( data/*string*/) { window.location.reload(); } /*-------------------------------------------------------- @description submit n answer for a comp @param radioname name of radio button @param compId id of item for competition @param userId id of user submitting comment @param email email of user ---------------------------------------------------------*/ objSite.submitVote=function(radioName,voteId,userIp){ var cookieName = 'booktrustVote_'+voteId; var votedBefore = false; if( objSite.readCookie( cookieName ) == null ) document.cookie = cookieName+'=true; expires=Thu, 2 Aug 2010 20:47:11 UTC; path=/'; else votedBefore = true; radioCount = $('.vote_answers').size() + 1; for(c=1;c
'; toolHtml += '

User: '+ username +'

'; toolHtml += '

Warn this user

'; toolHtml += '

Ban this user

'; toolHtml += 'x'; toolHtml += '
'; //attach to document $('#column1').prepend(toolHtml); //set actions $('#closetools').click(function(){ $('#modtools').remove(); }); $('.warnuser').click(function(){ var newWidth = $("#modtools").width() + 125 + "px"; $("#modtools").animate({ width: newWidth, height: "80px" }, 800, function(){ objSite.confirmAlert('warn', username); } ); }); $('.banuser').click(function(){ var newWidth = $("#modtools").width() + 125 + "px"; $("#modtools").animate({ width: newWidth, height: "80px" }, 800, function(){ objSite.confirmAlert('ban', username); } ); }); } objSite.confirmAlert = function( type, username ){ var confirmHtml = '

Are you sure you want to '+ type +' this user?

'; confirmHtml += 'Yes
'; $('.toolHolder').prepend(confirmHtml); $(".alertConfirm").animate({ opacity: 1.0 }, 200 ); var baseURL = objSite.site_url; var newURL = baseURL + "alertUser"; $('#confirmAlert').click(function(){ $.ajax({ type: "POST", url: newURL, data: 'username=' + username + '&alert='+type, success: objSite.userAlerted }); }); } objSite.userAlerted = function(){ var confirmHtml = '

The users status has been updated

'; $("#modtools").empty(); $("#modtools").append(confirmHtml); window.setTimeout( function() { $("#modtools").animate({ opacity: 0 }, 400, function(){ $("#modtools").remove() }); },2000); } objSite.deleteTool = function( chatCommentId, confirm, chatId ){ $("#" + chatCommentId).append('
'); //create a tooltip $('#delete').hover(function(e){ var x = 297; var y = e.pageY - 377; var toolPosition = 'style="top: '+ y +'px; left: '+ x +'px"'; $( "#commentsHolder" ).append('
Delete this comment?
'); },function(){ $("#tooltip").remove(); }); $("#delete").mousedown(function(){ var baseURL = objSite.site_url; var newURL = baseURL + "deleteChatComment"; newId = chatCommentId.replace("chatId_",""); $.ajax({ type: "POST", url: newURL, data: 'commentId=' + newId +'&chatId=' + chatId, success: function(data){ } }); }); } /*-------------------------------------------------------- @description submit a comment for an item @param textboxId id of text box containing comment data @param itemId id of item for comment @param typeId id of type @param div div to replace @param live whether the comment wil go live @param userId id of user submitting comment ---------------------------------------------------------*/ objSite.submitComment=function( textboxId,itemId,typeId,type,div,live,userId){ var textbox=document.getElementById(textboxId); var comment=textbox.value; // --------------------------------------------------------- var baseURL = objSite.site_url; var newURL = baseURL + "addComment"; objSite.div=div; objSite.holderDiv="commentsHolder"; $.ajax({ type: "POST", url: newURL, data: 'itemId=' + itemId + '&typeId=' + typeId+'&comment='+comment+'&live='+live+'&type='+type+'&userId='+userId, success: objSite.updateAssignment }); } /*-------------------------------------------------------- @description submit a comment for an item @param textboxId id of text box containing comment data @param itemId id of item for comment @param typeId id of type @param div div to replace @param live whether the comment wil go live @param userId id of user submitting comment ---------------------------------------------------------*/ objSite.submitBookedUpComment = function( itemId, typeId, type, div, live, userId){ /// get values ------------------------------------------------------------------------------------------- var name = $('#bkcomment_name').val(); var age = $('#bkcomment_age').val(); var school = $('#bkcomment_school').val(); var rating = $('#bkcomment_rating').val(); var title = $('#bkcomment_title').val(); var comment = $('#bkcomment_comment').val(); // --------------------------------------------------------- var base_str = 'itemId=' + itemId + '&typeId=' + typeId+'&live='+live+'&type='+type+'&userId='+userId; var data_str = '&name='+name; data_str += '&age='+age; data_str += '&school='+school; data_str += '&rating='+rating; data_str += '&title='+title; data_str += '&comment='+comment; var rtn_str = base_str+data_str; // alert(rtn_str); var baseURL = objSite.site_url; var newURL = baseURL + "addBookedUpComment"; objSite.div = div; objSite.holderDiv = "commentsFormHolder"; $.ajax({ type: "POST", url: newURL, data: rtn_str, success: objSite.updateAssignment }); } /*-------------------------------------------------------- @description submit n answer for a comp @param radioname name of radio button @param compId id of item for competition @param userId id of user submitting comment @param email email of user ---------------------------------------------------------*/ objSite.submitBookedupAnswer = function( typeId, itemId, type ){ // alert("submitting :: " + radioName + " : " + compId + " : "+ itemId + " : " + type ); // get answer form radios ------------------------------------------------------------------------------------------- var answer = null; $("input:radio").each(function(){ if( $(this).attr('checked') == 1 ) { answer = $(this).val(); } }); /// get values ------------------------------------------------------------------------------------------- var first_name = $('#comp_name').val(); var surname = $('#comp_surname').val(); var email = $('#comp_email').val(); var town = $('#comp_town').val(); var school = $('#comp_school').val(); var base_str = 'itemId=' + itemId +'&typeId='+typeId; var data_str = '&answer='+answer; data_str += '&firstname='+first_name; data_str += '&surname='+surname; data_str += '&school='+school; data_str += '&email='+email; data_str += '&town='+town; var rtn_str = base_str+data_str; // alert(rtn_str); // --------------------------------------------------------- var baseURL = objSite.site_url; var newURL = baseURL + "submit_competition"; objSite.div = "compAnswers"; objSite.holderDiv = "compHolder"; $.ajax({ type: "POST", url: newURL, data: rtn_str, success: objSite.updateAssignment }); } /*-------------------------------------------------------- @description submit n answer for a comp @param radioname name of radio button @param compId id of item for competition @param userId id of user submitting comment @param email email of user ---------------------------------------------------------*/ objSite.submitBookedupTextAnswer = function( inputName, typeId, itemId, type ){ // get answer form radios ------------------------------------------------------------------------------------------- var answer = null; var input=document.getElementById(inputName); if(input.value!=""){ var answer= input.value; } /// get values ------------------------------------------------------------------------------------------- var first_name = $('#comp_name').val(); var surname = $('#comp_surname').val(); var day = $('#comp_day').val(); var month = $('#comp_month').val(); var year = $('#comp_year').val(); var add_1 = $('#comp_add1').val(); var add_2 = $('#comp_add2').val(); var add_3 = $('#comp_add3').val(); var email = $('#comp_email').val(); var postcode = $('#comp_postcode').val(); var base_str = 'itemId=' + itemId +'&typeId='+typeId; var data_str = '&answer='+answer; data_str += '&firstname='+first_name; data_str += '&surname='+surname; data_str += '&day='+day; data_str += '&month='+month; data_str += '&year='+year; data_str += '&add_1='+add_1; data_str += '&add_2='+add_2; data_str += '&add_3='+add_3; data_str += '&email='+email; data_str += '&postcode='+postcode; var rtn_str = base_str+data_str; // alert(rtn_str); // --------------------------------------------------------- var baseURL = objSite.site_url; var newURL = baseURL + "submitTextAnswer"; objSite.div = "compAnswers"; objSite.holderDiv = "compHolder"; $.ajax({ type: "POST", url: newURL, data: rtn_str, success: objSite.updateAssignment }); } objSite.submitTextAnswer = function( inputName, textareaName, typeId, itemId, type ){ // get answer form radios ------------------------------------------------------------------------------------------- var answer1 = null; var answer2 = null; /// get values ------------------------------------------------------------------------------------------- var answer1 = $('#answer1').val(); var answer2 = $('#answer2').val(); var first_name = $('#comp_name').val(); var surname = $('#comp_surname').val(); var school = $('#comp_school').val(); var email = $('#comp_email').val(); var town = $('#comp_town').val(); var base_str = 'itemId=' + itemId +'&typeId='+typeId; var data_str = '&firstname='+first_name; data_str += '&surname='+surname; data_str += '&school='+school; data_str += '&town='+town; data_str += '&email='+email; data_str += '&answer1='+answer1; data_str += '&answer2='+answer2; var rtn_str = base_str+data_str; objSite.div="compAnswers"; objSite.holderDiv="compHolder"; // --------------------------------------------------------- var baseURL = objSite.site_url; var newURL = baseURL + "submitTextComp"; $.ajax({ type: "POST", url: newURL, data: rtn_str, success: objSite.updateAssignment }); } /*-------------------------------------------------------- @description submit n answer for a comp @param radioname name of radio button @param compId id of item for competition @param userId id of user submitting comment @param email email of user ---------------------------------------------------------*/ objSite.submitAnswer=function(radioName,compId,userId,email){ for(c=1;c<4;c++){ var radioBtn=document.getElementById(radioName+c); if(radioBtn.checked){ var answer= radioBtn.value; } } // --------------------------------------------------------- var baseURL = objSite.site_url; var newURL = baseURL + "submitAnswer"; objSite.div="compAnswers"; objSite.holderDiv="compHolder"; $.ajax({ type: "POST", url: newURL, data: 'compId='+compId+'&userId='+userId+'&email='+email+'&answer='+answer, success: objSite.updateAssignment }); } /*-------------------------------------------------------- @description login to the system @param user username @param pass password ---------------------------------------------------------*/ objSite.login = function (user,pass){ var userTextbox = document.getElementById(user); var passTextbox = document.getElementById(pass); var username = userTextbox.value; var password = passTextbox.value; //-------------------------------------------------------- var baseURL = objSite.site_url; var newURL = baseURL + "login"; $.ajax({ type: "POST", url: newURL, data: 'username=' + username + '&password=' + password ,success: objSite.updateLogin }); } /*-------------------------------------------------------- @description logout of the system ---------------------------------------------------------*/ objSite.logout=function (){ var baseURL = objSite.site_url; var newURL = baseURL + "logout"; $.ajax({ type: "POST", url: newURL, success: objSite.reloadPage }); } function rate() { var rateImg = document.getElementById("rateImg"); if(typeof document.body.style.maxHeight == "undefined"){ rateImg.style.marginTop = "-21px"; } else{ rateImg.style.marginTop = "-18px"; } var holder = document.getElementById("ratingFeedback"); var child = document.getElementById("feedback"); holder.removeChild(child); //---------------------------------------------- //---------------------------------------------- var new_all_items = document.createElement("div"); new_all_items.setAttribute("id", "feedback"); new_all_items.innerHTML = "

Rollover above and click the appropriate button to submit your rating.

"; holder.appendChild(new_all_items); } /*-------------------------------------------------------- @description submit search form ---------------------------------------------------------*/ function submitSearchForm(form){ eval('document.' + form + '.submit()'); } /*-------------------------------------------------------- @description clear the default value of form item @param el form item ---------------------------------------------------------*/ function clearDefault(el) { if (el.defaultValue==el.value) el.value = "" } /*-------------------------------------------------------- @description @param ---------------------------------------------------------*/ objSite.setSearchObject=function(){ var x = objSite.readCookie('swf_search_visible') if (x == "false") { $("#main_ufo").height( 0 ); $("#ufo_object").height( 0 ); $("#main_swf").height( 0 ); } } /*-------------------------------------------------------- @description @param ---------------------------------------------------------*/ objSite.openFlashSearch=function (string) { var speed = 1000; // get height to check if we are closed/closing var height =$('#main_ufo').height(); // if less than full height the manimate to full height if( height < 360){ $("#main_ufo").animate({ height: "360" }, speed ); // $("#ufo_object").animate({ height: "360" }, speed ); // set swf height $("#main_swf").animate({ height: "360" }, speed ); objSite.createCookie( "swf_search_visible", "true", 30); // else close this div }else{ $("#main_ufo").animate({ height: "0" }, speed ); // $("#ufo_object").animate({ height: "0" }, speed ); // set swf height $("#main_swf").animate({ height: "0" }, speed ); objSite.createCookie( "swf_search_visible", "false", 30); } // toggle button to display the toggled version $("#ufo_button a").toggleClass("closed"); } /*-------------------------------------------------------- @description links to a new site from dropdown ---------------------------------------------------------*/ function goToSite(selector){ var link = document.getElementById(selector).value; alert(link); window.location=link; } /*-------------------------------------------------------- @description show the next book in the auto suggestion list ---------------------------------------------------------*/ objSite.nextBook=function (string) { if(!objSite.animating){ var element=$('#suggestions').find('li').eq(0); if(objSite.firstRun==true){ $(element).animate({style: 'margin-left:-200'},500); } objSite.animating=true; var baseURL = objSite.site_url; var newURL = baseURL + "getRelatedData"; $.ajax({ type: "POST", url: newURL, data: 'string=' + string, success:objSite.showBook }); } } /*-------------------------------------------------------- @description moves the old book out @param data data sent from server ---------------------------------------------------------*/ objSite.showBook=function (data) { if(data!=""){ var element=$('#suggestions').find('li').eq(0); element.html(data); $(element).animate({style: 'margin-left:0'},500); objSite.animating=false; objSite.firstRun=true; } else{ $('#suggestions').css("display","none"); $('#nextbook').css("display","none"); } } /*------------------------------------------------------- @description replace div with loading animation @param div id of div to replace @param holderDivId id of div holder --------------------------------------------------------- */ objSite.showLoading=function(divId,holderDivId){ var holder = document.getElementById(holderDivId); var div = document.getElementById(divId); var data = "
"; holder.removeChild(div); //---------------------------------------------- // add elements var new_div = document.createElement("div"); new_div.setAttribute("id", divId); new_div.innerHTML = data; holder.appendChild(new_div); } /*-------------------------------------------------------- @description submit a form @param formid id of the form to submit ---------------------------------------------------------*/ objSite.submitForm=function(formId){ var form=document.getElementById(formId); form.submit(); } /*-------------------------------------------------------- @description get content from combobox and visit specified site @param comboId id of the combobox ---------------------------------------------------------*/ objSite.goToSite=function(comboId){ var combo=document.getElementById(comboId); var address=combo.value; location.href=address; } /* ------------------------------------------------------ @description setup auto complete text box functionality @param inputString string from text field @param type type that search is for @param field field that search is on @param id int used to identify which element is used ---------------------------------------------------------*/ objSite.lookup=function(inputString,query,type,mode,id) { var URL = objSite.site_url + "autocomplete"; if(inputString.length == 0) { // Hide the suggestion box. $('#prompts'+id).hide(); } else { $.ajax({ type: "POST", url: URL, data: 'query='+query+'&var='+inputString+'&mode='+mode+'&type='+type+'&id='+id, success: function(data){ if(data.length >0) { $('#prompts'+id).show(); $('#autoSuggestionsList'+id).html(data); } else{ $('#prompts'+id).hide(); } } }); } } /* ------------------------------------------------------ @description setup auto complete text box functionality @param prompt the prompt to place in the textfield @param id int to identify the box to populate */ objSite.populateInput=function(prompt,id) { $('#contentsearch'+id).attr('value',prompt); $('#prompts'+id).hide(); } /*-------------------------------------------------------- @description ran once a page is loaded ---------------------------------------------------------*/ $(document).ready(function() { objSite.nextBook(objSite.tags); /* objSite.setSearchObject(); // ensure minimum height of column 2 var height =$('#column2.columnmajor').height(); if(height<550){ $('#column2.columnmajor').height(550); } var height =$('#column2.columnsearch_wide').height(); if(height<550){ $('#column2.columnsearch_wide').height(550); } */ }); /*-------------------------------------------------------- @description create a cookie @param string name name of cookie to be created @param string value value of cookie to be created @param number [optional] days days of cookie to be created ---------------------------------------------------------*/ objSite.createCookie = function(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } /*-------------------------------------------------------- @description reads a cookie by name and returns its value ---------------------------------------------------------*/ objSite.readCookie = function(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } /*-------------------------------------------------------- @description erases a cookie by name ---------------------------------------------------------*/ objSite.eraseCookie = function(name) { objSite.createCookie(name,"",-1); } /*** EVENT FUNCTIONS ***/ objSite.setupAdvancedOptions = function ( ){ $('#recurring_type').change( function(){ var type = $('#recurring_type').val(); $('#advanced-options span').empty(); $('#option-specific').empty(); $('#recurring_type span').append( type+'s' ); switch (type){ case "day": $('#month_advanced').hide(); $('#year_advanced').hide(); $('#week_advanced').hide(); break; case "week": $('#month_advanced').hide(); $('#year_advanced').hide(); $('#week_advanced').show(); break; case "month": $('#week_advanced').hide(); $('#year_advanced').hide(); $('#month_advanced').show(); break; case "year": $('#month_advanced').hide(); $('#week_advanced').hide(); $('#year_advanced').show(); break; } }); } objSite.updateFormDates = function( dateVal ){ var dates = dateVal.split("/"); chosenDate = new Date( dates[2], dates[1]-1, dates[0] ); arrDays = new Array( 'Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'); arrMonths = new Array( 'January','February','March','April','May','June','July','August','September','October','November','December'); arrOccur = new Array( 'First', 'Second','Third','Fourth','Last' ); intDay = chosenDate.getDay(); intMonth = chosenDate.getMonth(); intDate = chosenDate.getDate(); intDayOccur = Math.round( (intDate/7)+0.49 ); strDay = arrDays[ intDay ]; strMonth = arrMonths[ intMonth ]; strDayOccur = arrOccur[ intDayOccur-1 ]; //Find all the form values and select them - day inputs $('input.advancedOpt').removeAttr('checked'); $('input.'+strDay).attr({checked: 'checked'}); //day options $('option.advancedOpt').removeAttr('selected'); $('option.'+strDay).attr({selected: 'selected'}); $('input.'+strMonth).attr({checked: 'checked'}); $('input.day_'+intDate).attr({checked: 'checked'}); $('option.'+strDayOccur).attr({selected: 'selected'}); } objSite.get_form_values = function(form_id){ var inputs=''; $('#'+form_id+' :input').each(function(i,n){ switch (n.type){ case "checkbox": if(n.checked){ inputs += '&'+n.name+'=y'; } else{ inputs += '&'+n.name+'=n'; } break; case "radio": if( n.checked ) inputs += '&'+n.name+'='+n.value; break; case "select-multiple": //get selected values var selected_values =new Array(); var selected_indexes =new Array(); while(n.selectedIndex!=-1){ selected_indexes.push(n.selectedIndex); selected_values.push(n.options[n.selectedIndex].value); n.options[n.selectedIndex].selected = false; } //reset indexes for(var c=0;c