// JavaScript Document /* Create our object to hold all functions and vars ---------------------------------------------------------*/ var objSite = {}; /* ---------------------------------------------------------*/ objSite.site_url = "http://www.childrenslaureate.org.uk/"; objSite.reloadPage = function( data/*string*/) { window.location.reload(); } /*-------------------------------------------------------- @description update the login data once a login has been submitted ---------------------------------------------------------*/ objSite.updateLogin = function( data/*string*/) { var data=data; var isloggedIn ="false"; if(data=="" ||data==null){ isLoggedIn ="true"; } //---------------------------------------------- var holder = document.getElementById("login"); var all_items = document.getElementById("loginError"); holder.removeChild(all_items); //---------------------------------------------- //---------------------------------------------- var new_all_items = document.createElement("div"); new_all_items.setAttribute("id", "loginError"); new_all_items.innerHTML = data; holder.appendChild(new_all_items); if(isLoggedIn=="true"){ objSite.reloadPage(data); } } /*-------------------------------------------------------- @description update the current div once and ajax response has been recieved ---------------------------------------------------------*/ objSite.updateAssignment = function( data/*string*/) { //---------------------------------------------- var holder = document.getElementById(objSite.holderDiv); var all_items= document.getElementById(objSite.div); holder.removeChild(all_items); //---------------------------------------------- //---------------------------------------------- var new_all_items = document.createElement("div"); new_all_items.setAttribute("id", objSite.div); new_all_items.innerHTML = data; holder.appendChild(new_all_items); } /*-------------------------------------------------------- @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 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 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 ---------------------------------------------------------*/ objSite.lookup=function(inputString,query,type,mode) { var URL = objSite.site_url + "autocomplete"; if(inputString.length == 0) { // Hide the suggestion box. $('#suggestions').hide(); } else { $.ajax({ type: "POST", url: URL, data: 'query='+query+'&var='+inputString+'&mode='+mode+'&type='+type, success: function(data){ if(data.length >0) { $('#suggestions').show(); $('#autoSuggestionsList').html(data); } } }); } } /*-------------------------------------------------------- @description ran once a page is loaded ---------------------------------------------------------*/ $(document).ready(function() { objSite.nextBook(objSite.tags); // 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); } });