// JavaScript Document /* Create our object to hold all functions and vars ---------------------------------------------------------*/ var objSite = {}; /* ---------------------------------------------------------*/ objSite.site_url = "http://www.translatedfiction.org.uk/" objSite.admin_url = "http://booktrustadmin.kentlyons.com/"; 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 append to the current chat div once and ajax response has been recieved ---------------------------------------------------------*/ objSite.appendChat = function( data/*string*/) { if( data == 'ending chat' ) location.reload(true); //check for any alerts if( data.search(/warn::/)==0 ){ //show the warning and carry on objSite.alertUser( "The moderator of this site has felt the need to give you a warning for your behaviour on this chat. Please be careful!" ); } else if( data.search(/ban::/)==0 ){ var failText = "The moderator of this chat has banned you due to your innappropriate use of this chat. To reactivate your account please contact admin@booktrust.org.uk"; objSite.alertUser( failText, true ); } else if( data.search(/commentDelete::/)==0 ){ new_data = data.replace("commentDelete::",""); $("#chatTranscript").empty(); $("#chatTranscript").append(new_data); objSite.resetChatDelete(); } else if( data!='fail'){ //append a new comment $("#chatTranscript").append(data); objSite.resetChatDelete(); } var baseURL = objSite.site_url; window.setTimeout( function() { var newURL = baseURL + "getComments"; $.ajax({ type: "POST", url: newURL, data: 'itemId=' + objSite.itemId + '&typeId=' + objSite.typeId, success: objSite.appendChat }); },1000); } objSite.resetChatDelete = function(){ //Needed to avoid adding multiple js calls onto an item $('.modDisplay').unbind(); $('.modDisplay').hover(function(){ $(this).css('background-color','#f2f2f2'); objSite.deleteTool( $(this).attr('id'), 'Are you sure you want to delete this item?',objSite.itemId); }, function(){ $("#delete").remove(); $("#tooltip").remove(); $(this).css('background-color','#ffffff'); }); } objSite.alertUser = function( text, ban ){ var alertBoxHtml = '

Warning

'; alertBoxHtml += '

'; alertBoxHtml += text; alertBoxHtml += '

'; $('#maincontainer').append(alertBoxHtml); if (window.innerWidth || window.innerHeight) var width = window.innerWidth; else if (document.body.clientWidth || document.body.clientHeight) var width = document.body.clientWidth; var window_width = $('#userAlert').width(); var pos_left = (width/2)-(window_width/2); if( typeof( window.pageYOffset ) == 'number' ) { var pos_top = window.pageYOffset + 200; }else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ){ var pos_top = document.documentElement.scrollTop + 150; } $('#userAlert').css({'left': pos_left,'top':pos_top}); if( !ban ){ window.setTimeout( function() { $("#userAlert").animate({ opacity: 0 }, 800, function(){ $("#userAlert").remove() } ); },5000); } else{ window.setTimeout( function() { $("#userAlert").animate({ opacity: 0 }, 800, function(){ objSite.logout(); } ); },5000); } } /*-------------------------------------------------------- @description append to the current chat div once and ajax response has been recieved ---------------------------------------------------------*/ objSite.updateUsers = function( data/*string*/) { var all_users= document.getElementById('all_users'); if( all_users.innerHTML != data){ all_users.innerHTML = data; $('.active_user').click(function(e){ var username = $(this).attr('id'); var username = username.replace('userid_',''); var x = this.offsetLeft; var y = this.offsetTop; objSite.modTool( x, y, username ); }); } var baseURL = objSite.site_url; window.setTimeout( function() { var newURL = baseURL + "getUsers"; $.ajax({ type: "POST", url: newURL, data: 'itemId=' + objSite.itemId, success: objSite.updateUsers }); },4000); } /*-------------------------------------------------------- @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"; chat=false; $.ajax({ type: "POST", url: newURL, data: 'itemId=' + itemId + '&typeId=' + typeId+'&comment='+comment+'&live='+live+'&type='+type+'&userId='+userId, success: objSite.updateAssignment }); } /*-------------------------------------------------------- @description submit a chat comment for a chat @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.submitChat=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 + "addChat"; objSite.holderDiv="commentsHolder"; chat=false; $.ajax({ type: "POST", url: newURL, data: 'itemId=' + itemId + '&typeId=' + typeId+'&comment='+comment+'&live='+live+'&type='+type+'&userId='+userId, success: function(data){ $('#commentsText').attr('value','');} }); } objSite.updateChat = function( itemId, typeId, div ){ objSite.holderDiv="#chatTranscriptHolder"; objSite.itemId = itemId; objSite.typeId = typeId; var baseURL = objSite.site_url; var newURL = baseURL + "getComments"; $.ajax({ type: "POST", url: newURL, data: 'itemId=' + itemId + '&typeId=' + typeId, success: objSite.appendChat }); var newURL = baseURL + "getUsers"; $.ajax({ type: "POST", url: newURL, data: 'itemId=' + itemId, success: objSite.updateUsers }); } /*-------------------------------------------------------- @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 submit n answer for a text comp @param radioname name input box @param compId id of item for competition @param userId id of user submitting comment @param email email of user ---------------------------------------------------------*/ objSite.submitTextAnswer = function( inputName, textareaName, typeId, itemId, type ){ // get answer form radios ------------------------------------------------------------------------------------------- var answer1 = null; var answer2 = null; var input1=document.getElementById(inputName); if(input1.value!=""){ var answer1= input1.value; } var input2=document.getElementById(textareaName); if(input2.value!=""){ var answer2= input2.value; } /// get values ------------------------------------------------------------------------------------------- var first_name = $('#comp_name').val(); var surname = $('#comp_surname').val(); var age = $('#comp_age').val(); var add_1 = $('#comp_add1').val(); var add_2 = $('#comp_add2').val(); var add_3 = $('#comp_add3').val(); var phone = $('#comp_phone').val(); var email = $('#comp_email').val(); var postcode = $('#comp_postcode').val(); var base_str = 'itemId=' + itemId +'&typeId='+typeId; var data_str = '&firstname='+first_name; data_str += '&surname='+surname; data_str += '&age='+age; data_str += '&add_1='+add_1; data_str += '&add_2='+add_2; data_str += '&add_3='+add_3; data_str += '&phone='+phone; data_str += '&email='+email; data_str += '&postcode='+postcode; 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.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 $('#sub').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"'; $("#" + chatCommentId).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){ } }); }); } objSite.setRandomImage = function( ){ var imageNames = new Array( 'Bird_withbooks', 'Croc_Kid', 'Cutout_Monster', 'Dino', 'Emu', 'Girl_Jumping', 'Hogs', 'Small_Bear', 'Spider' ); //pos 1 pos_1_images = new Array( '2','3','4','5','7','8'); pos_2_images = new Array( '4','5','8'); pos_3_images = new Array( '3','5','7'); pos_4_images = new Array( '0','1','2','5','6','7','8'); var usedImages = new Array(); var pos_1 = pos_1_images[Math.floor(Math.random()*pos_1_images.length)]; $('#top-char-1').css( { "background":"url(../images/site_chars/top/"+imageNames[pos_1]+".png) no-repeat top left", "width":"100px", "height": "100px" } ) usedImages.push( pos_1 ); pos_2_images = objSite.inArray( pos_2_images, usedImages); var pos_2 = pos_2_images[Math.floor(Math.random()*pos_2_images.length)]; usedImages.push( pos_2 ); pos_3_images = objSite.inArray( pos_3_images, usedImages); var pos_3 = pos_3_images[Math.floor(Math.random()*pos_3_images.length)]; usedImages.push( pos_3 ); pos_4_images = objSite.inArray( pos_4_images, usedImages); var pos_4 = pos_4_images[Math.floor(Math.random()*pos_4_images.length)]; } objSite.inArray = function(newImages, usedImages){ for(var i = 0; i < newImages.length; i++){ for( var j=0; jTo "+toName+"

"); $(".ecard-content").append(message); $(".ecard-content").append("

From "+fromName+"

"); } objSite.submitEcard = function( ecardID ){ //get values var input_values = objSite.get_form_values( 'ecard_form' ); var rtnString = "ecardID="+ecardID +"&theMessage=" + escape( tinyMCE.get( 'form_ecardMessage' ).getContent() ) + input_values; var baseURL = objSite.site_url; var newURL = baseURL + "validate_ecard"; objSite.div="ecard_form"; objSite.holderDiv = "ecardHolder"; tinyMCE.execCommand('mceRemoveControl',false,'form_ecardMessage'); $.ajax({ type: "POST", url: newURL, data: rtnString, success: function(data){ objSite.updateAssignment( data ); tinyMCE.execCommand("mceAddControl", true, 'form_ecardMessage'); } }); } objSite.getEventInfo = function( infoItem, event ){ var top = event.pageY - 55; var left = event.pageX + 25; $("#eventInfo").remove( ); switch( infoItem ){ case 'event_name_info': var title = "

Event Name

"; var mainText = "

Give your event a name eg 'Bookstart Rhymetimes'.

"; break; case 'event_location_info': var title = "

Event Location

"; var mainText = "

What is the full address of the venue where your event is taking place? Separate each line with a comma. Eg Booktrust, Book House, 45 East Hill, London

"; break; case 'event_location_name_info': var title = "

Event Location Name

"; var mainText = "

What is the name of the venue where your event taking place? Eg 'British Library'

"; break; case 'event_postcode_info': var title = "

Event Postcode

"; var mainText = "

What is the full postcode for your venue? The more accurate you are, the easier it will be to find on the Google Map. Eg SW18 2QZ.

"; break; case 'event_region_info': var title = "

Event Region

"; var mainText = "

Please select the region your event is taking place in. This will help people searching for local events

"; break; case 'event_description_info': var title = "

Event Description

"; var mainText = "

Add any details here to help promote your event. What is happening? Who should attend? What will attendees get out of attending? Also highlight any special details people may need to know.

"; break; case 'event_email_info': var title = "

Contact Email

"; var mainText = "

Add the event organiser’s full email address. This is so Booktrust or any attendee can contact you with any queries regarding your event.

"; break; case 'event_cost_info': var title = "

Event Cost

"; var mainText = "

Enter the cost of your event in pounds and pence. Eg £2.50. If the event is free, leave it as £0.00. If you are advertising a Bookstart event, it should be free.

"; break; case 'event_date_info': var title = "

Event Start Date

"; var mainText = "

Enter start date of your event. Enter in the format DD-MM-YYYY.

"; break; case 'event_until_info': var title = "

Event End Date

"; var mainText = "

If your event has an end date, enter here. Enter in the format DD-MM-YYYY.

"; break; case 'event_time_info': var title = "

Event Time

"; var mainText = "

Enter the time your event starts using the 24 hour clock. Eg 14:00

"; break; case 'event_recurring_info': var title = "

Recurring Event

"; var mainText = "

If your event is weekly, monthly or annually, tick this box and then select how often you wish the event to recur.

"; break; case 'event_type_info': var title = "

Event Type

"; var mainText = "

Select which age range this event will appeal to most. You can select more than one if need be.

"; break; } $("#maincontainer").append('
'+title+mainText+'
'); $("#delete").click( function(){ $("#eventInfo").remove( ); }); } objSite.fillDetails = function( itemId, strInputs, query_func ){ $('#auto_container').slideUp( 'normal' ); var baseURL = objSite.site_url; var newURL = baseURL + "ajax/get_auto_complete_inputs"; $.ajax({ type: "POST", url: newURL, data: 'itemId=' + itemId +'&strInputs=' + strInputs +'&query_func=' + query_func, success: function(data){ var arrInputs = strInputs.split("#"); var arrResults = data.split("#"); for( var i=0; i intMax){ var strVal = strVal.slice( 0, intMax ); $(this).val( strVal ); } $("#"+fieldId+"_count").html( strVal.length ); }); } else{ tinyMCE.get(fieldId).onKeyUp.add(function(ed, e) { var strVal = (tinyMCE.activeEditor.getContent()).replace(/(<([^>]+)>)/ig,""); var intMax = $("#"+fieldId+"_max").html(); if( strVal.length > intMax ){ //replace text with most recent buffer tinyMCE.activeEditor.setContent( recentBuffer ); }else{ recentBuffer = tinyMCE.activeEditor.getContent(); } $("#"+fieldId+"_count").html( strVal.length ); }); } } objSite.autofill = function( value, query_func, query_func_data, autofill_array ){ if( value.length > 1 ){ var baseURL = objSite.site_url; var newURL = baseURL + "ajax/get_auto_complete_results"; $.ajax({ type: "POST", url: newURL, data: 'value=' + value +'&query_func=' + query_func + '&query_func_data=' + query_func_data + '&autofill_array=' + autofill_array , success: function(data){ $('#autofill_results').html( data ); $('#auto_container').slideDown( 'normal' ); } }); } else $('#auto_container').slideUp( 'normal' ); } /*-------------------------------------------------------- @description ran once a page is loaded ---------------------------------------------------------*/ $(document).ready(function() { // 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); } });