﻿// JScript File
// SET VARIABLES
var stoaf = ".sendToAFriendForm";
var fontSize = 1;

// set currentSize to either 1, or whatever is in the cookie
var currentSize = $.cookie('fontSize');  
var currentSize = parseFloat(currentSize, 12);

if (isNaN(currentSize) == true) { 
    currentSize = 1;
}

// Country page height
var cpih = 0;
var ch = 240;

// DOCUMENT READY 
$(document).ready(function (){
    
    // turn on js dependent features, and turn off their noscript alternatives
    $('.script').css("display","block");
    $('.noscript').css("display","none");
    $('div.comments, #wrapper div.resourceListItem ul.moreDetails').css('display','none');
    //$("div.comments").after('<p class="commentsButton"><a href="#" title="View / hide comments" class="commentsToggle">View comments</a></p>');
    //$("div.resourceDetailsBar").append('<a href="#" title="View / hide more details" class="detailsToggle">View resource details</a>');    
    


    
    // search clicks
    $(".search .searchBtn").bind("click", function(event){
        search();
        event.preventDefault();
    });
    
    $(".search .search_input").bind("keypress", function(event){
        if (event.keyCode == 13) { search(); }
    });
    
    // add print page button
	$('p.controls a.printPage').click(function() {
		window.print();
		return false;
	});
	
	$(".lightbox").lightbox({fitToScreen: true});
    
});

$('fieldset.search a.search_button').bind('click', function(){
    fireSearch();
});

$('fieldset.search input').bind('keypress', function(e) {
    if(e.keyCode==13){
        fireSearch();
    }
});

// SEND TO A FRIEND ----------------------------------------------------------------------------------------------------------------
function stoafSlide () {
    // on click of either the stoaf button or the close button slideToggle the panel
    //$("#accessibilityPanel .controls a.stoaf, .sendToAFriendForm .closeBtn a").unbind("click");
    //$("#accessibilityPanel .controls a.stoaf, .sendToAFriendForm .closeBtn a").bind("click", function(event){
        $(stoaf).slideToggle(600);
        //event.preventDefault();
    //});
}

// display, change and hide stoaf form
function stoafMsgSent() {
    // after two seconds change to message sent, swap image, swap text, change color
    $(stoaf).delay(2000,function(){
        $(stoaf + ' .stoafSent img').attr("src","/images/shd/loaded.gif");
        $(stoaf + ' .stoafSent p').css("color","#A5C718");
        $(stoaf + ' .stoafSent p').text("Message sent");
        
        // after 3 seconds hide the panel    
        $(stoaf).delay(3000,function(){
            $(stoaf).slideToggle(600);   
            
            // once the panel is hidden change the message back to loading
            $(stoaf).delay(700,function(){
                $(stoaf + ' .stoafSent img').attr("src","/images/shd/loading.gif");
                $(stoaf + ' .stoafSent p').css("color","#666666");
                $(stoaf + ' .stoafSent p').text("Sending message...");
                $('#pnlMain').attr("style","display:block;");
                $('#pnlThanks').attr("style","display:none;");
            });
        });
    });
}

function validateForm(element) {
    var bOK 
    bOK = true;
    $(element).each(
        function() {
            
            var textBox = this;
            var boxValue = $(this).val();
            
            if (boxValue == "") {
                $(this).css("background-color","#EDFFA4");
                bOK = false;
            }
        }
    );
    return bOK;
}

// SEARCH FUNCTION -------------------------------------------------------------------------------------------------
function search() {
    searchTerm = $('.search .search_input').attr('value');
    window.location.href = "/pages/home/search.aspx?s=" + searchTerm;
}