// useful javascript functions // create a popup window - 21/03/09 - gavin taylor function popup(link, windowname, width, height, scrollbars, status, resizable, location, toolbar, menubar) { if(!window.focus) { return true; } //check if additional options are set if(scrollbars == null) { scrollbars = 'no'; } if(status == null) { status = 'no'; } if(resizable == null) { resizable = 'no'; } if(location == null) { location = 'no'; } if(toolbar == null) { toolbar = 'no'; } if(menubar == null) { menubar = 'no'; } var href; if(typeof(link) == 'string') { href=link; } else { href=link.href; } //window position var posleft = (screen.width - width) / 2; var postop = (screen.height - height) / 2; newwindow = window.open(href, windowname, 'width=' + width + ', height=' + height + ',left=' + posleft + ',top=' + postop + ',scrollbars=' + scrollbars + ',status=' + status + ',resizable=' + resizable + ',location=' + location + ',toolbar=' + toolbar + ',menubar=' + menubar + ''); if(window.focus) {newwindow.focus()} return false; } //creates an HTTP Request Object to be used as required function getXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } //display flash banner function show_banner(banner_src, banner_width, banner_height) { document.write(' '); document.write(' '); document.write(' '); document.write(' '); document.write(' '); document.write(' '); } function change_featured_tab(show_tab,tab_id,tab_links_id,no_of_tabs) { //loop through all tabs for(i=1;i<=no_of_tabs;i++) { var tmp_tab_id = tab_id + i; var tab_class = ''; var tab_content_visible = 'none'; var tab_content_show_status = 'hide'; // the homepage has a featured box that reacts different than usual // so we need to add a special function to switch the bg of each tab if(tab_links_id == 'featured') { $('#featured_box').removeClass('featured_box_'+i); } if(i == show_tab) { tab_class = 'active'; tab_content_visible = 'block'; tab_content_show_status = 'show'; $('ul > li#' +tmp_tab_id+ ' > a').removeClass('tab_color_'+show_tab); $('ul > li#' +tmp_tab_id+ ' > a').addClass(tab_class); $('ul > li#' +tmp_tab_id).addClass(tab_class); //just for the featured box, we add a class so it styles diferent than the other tabs if(tab_links_id == 'featured') { $('#featured_box').addClass('featured_box_'+i); } }else{ $('ul > li#' +tmp_tab_id+ ' > a').removeClass(); $('ul > li#' +tmp_tab_id).removeClass('active'); $('ul > li#' +tmp_tab_id+ ' > a').addClass('tab_color_'+show_tab); } //activate tab document.getElementById(tmp_tab_id).className = tab_class; // apply css rule so the tab content area for the selected tab is visible $content_area = $('#'+tmp_tab_id + '_content'); // this grabs the P tags of the content so we can now use this for any effects. $p_tag_content = $('#'+tmp_tab_id + '_content p'); if(tab_content_show_status == 'show') { $p_tag_content.fadeIn(300); $content_area.show(); } else { $content_area.hide(); } } //update tabs class //document.getElementById(tab_links_id).className = tab_id + show_tab + '_active'; return false; } /* $(document).ready(function() { // Add slightly faded effect to the client images on the homepage $('#long_cta_box img').css('opacity', 0.5); $('#long_cta_box img').hover(function() { $(this).animate({ opacity: 1.0 }, 500); }); // add a fade in effect when the Configure CH cta but is hovered $('.hover_button').css('opacity', 0.75); $('.hover_button').hover(function() { $(this).animate({ opacity: 1.0 }, 'fast'); }, function() { $(this).animate({ opacity: 0.75 }, 'slow'); }); }); */ function default_rating(curval,default_message) { for (i=1;i<=5;i++) { //reset image document.getElementById('rating' + i).style.backgroundPosition = '-203px -1px'; //update if required if(i <= curval) { document.getElementById('rating' + i).style.backgroundPosition = '-220px -1px'; } } document.getElementById('pre_message').innerHTML = default_message; } function update_rating(rating_value,media) { switch(rating_value) { case 1: message = 'Poor'; break; case 2: message = 'Nothing special'; break; case 3: if (media == 'video') { message = 'Worth watching'; } else { message = 'Worth reading'; } break; case 4: message = 'Pretty cool'; break; case 5: message = 'Excellent!'; break; default: message = 'unknown rating selected'; rating_value = 0; break; } //update stars for (i=1;i<=5;i++) { //reset image document.getElementById('rating' + i).style.backgroundPosition = '-203px -1px'; //update if required if(i<=rating_value) { document.getElementById('rating' + i).style.backgroundPosition = '-237px -1px'; } } //update message document.getElementById('pre_message').innerHTML = message; } function submit_rating(rating_value,user_id,session_id,media_id,media_type) { //create AJAX request variable var http = getXmlHttpObject(); //remove javascript calls from stars to prevent future submission for (i=1;i<=5;i++) { document.getElementById('rating' + i).onmouseover = null; document.getElementById('rating' + i).onmouseout = null; document.getElementById('rating' + i).onclick = null; document.getElementById('rating' + i).title = 'Thanks for rating!'; } //submit rating details http.open("POST", "/scripts/process_rating.php", true); var parameters = "user_id=" + user_id + "&session_id=" + session_id + "&media_type=" + media_type + "&media_id=" + media_id +"&media_rating=" + rating_value; http.onreadystatechange=function() { var message = 'Unable to process your request!'; if(http.readyState == 4) { if (http.status==200) { //update message message = http.responseText; //rewrite message as too long for the pre_message container if(message=='Thanks for rating!') { message = 'Thank you.'; } //update cookie update_cookie('ukfast_' + media_type + '_ratings',media_id); } } document.getElementById('pre_message').innerHTML = message; } http.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http.setRequestHeader("Content-length", parameters.length); http.send(parameters); } function update_cookie(cookie_name,cookie_value) { var data = ''; //check if cookie exists if (document.cookie.length>0) { c_start=document.cookie.indexOf(cookie_name + "="); if (c_start!=-1) { c_start=c_start + cookie_name.length+1; c_end=document.cookie.indexOf(";",c_start); if (c_end==-1) c_end=document.cookie.length; data = unescape(document.cookie.substring(c_start,c_end)) + "|"; } } //update cookie data data = data + cookie_value; //create new cookie to store data in var exdate=new Date(); exdate.setDate(exdate.getDate()+300); document.cookie = cookie_name + "=" + data + ";path=/;expires=" + exdate.toGMTString(); } function ucfirst(str) { // split string firstChar = str.substring(0,1); remainChar = str.substring(1); // convert case firstChar = firstChar.toUpperCase(); remainChar = remainChar.toLowerCase(); return firstChar + remainChar }