
$(document).ready(function(){

    $('body').weCookie({

	'url': '/cookie-policy/',
	'close_icon_path' : '/images/close_icon1.gif',
	'fade_in' : '1000'
    });
 
    $("html.no-js").removeClass('no-js');

});



//David P added infographic functions for 2011 Generations TV ad
$(document).ready( function(){
    if($('.infographic').size()){
	$('#tab1').addClass('active');
	$('.info-section').hide();
	$('#info-section-1').show();
	$('.info-tabs a').bind('click', function() {
	    var thisLi = $(this).parent("li");
	    var thisContainer = $(this).parents(".infographic");
	    var theseTabs = thisContainer.find(".info-tabs li");
	    var thisIndex = theseTabs.index(thisLi);
	    theseTabs.removeClass("active");
	    thisContainer.find(".info-section").hide().eq(thisIndex).show();
	    $(".info-tabs li").animate({
		"margin-top":"18px"
	    },400);
	    thisLi.addClass("active");
	    gaTrackEvent('Smoking and Family Life', thisLi.attr("class"));
	    return false;
	});

	$('#info-section-1 .post-message a').bind('click', function() {
	    $('#tab2 a').click();
	    gaTrackEvent('Smoking and Family Life', 'Message to Money');
	    return false;
	});
	$('#info-section-2 .post-message a').bind('click', function() {
	    $('#tab3 a').click();
	    gaTrackEvent('Smoking and Family Life', 'Message to Family');
	    return false;
	});
    }

    $(".info-section .post-message span").hide();

    $("#info-section-1 .dragger").drag("start",function(ev,dd){
	$(this).parent().addClass('drag-active');
    }).drag("dragend",function(ev,dd){
	$(this).parent().removeClass('drag-active');
	if(dd.offsetX > 250){
	    if($.browser.msie && $.browser.version=="6.0"){
		gaTrackEvent('Smoking and Family Life', 'Health throw away extra');
		anim1Changeie6();
	    }else{
		if($("#info-section-1").hasClass("animated")){
		    anim1ChangeNoAnim('400');
		gaTrackEvent('Smoking and Family Life', 'Health throw away extra');
		}else{
		    $('#info-section-1').dTimeline({
			functionName:'anim1Change',
			action:'autoTrigger',
			animateSpeed:'400',
			fps:'700'
		    });
		gaTrackEvent('Smoking and Family Life', 'Health throw away first');
		}  
	    }
	}else if(dd.offsetX < 46){
	    if($.browser.msie && $.browser.version=="6.0"){      
		anim1Resetie6();
	    gaTrackEvent('Smoking and Family Life', 'Health reset');
	    }else{
		anim1Reset('400');
	    gaTrackEvent('Smoking and Family Life', 'Health reset');
	    }
	}
    }).drag(function(ev, dd){
	$(this).css({
	    left: Math.min(265,Math.max(31,dd.offsetX))
	});
	$(this).parent().find(".mask").css({
	    width: Math.min(265,Math.max(31,dd.offsetX))-31
	});
    },{
	relative:true
    });

    $("#info-section-2 .dragger").drag("start",function(ev,dd){
	$(this).parent().addClass('drag-active');
    }).drag("dragend",function(ev,dd){
	$(this).parent().removeClass('drag-active');
	if(dd.offsetX > 250){
	    if($.browser.msie && $.browser.version=="6.0"){
		anim2Changeie6();
	    gaTrackEvent('Smoking and Family Life', 'Money throw away extra');
	    }else{
		if($("#info-section-2").hasClass("animated")){
		    anim2ChangeNoAnim('400');
		gaTrackEvent('Smoking and Family Life', 'Money throw away extra');
		}else{
		    $('#info-section-2').dTimeline({
			functionName:'anim2Change',
			action:'autoTrigger'
		    });
		gaTrackEvent('Smoking and Family Life', 'Money throw away first');
		}  
	    }
	}else if(dd.offsetX < 46){
	    if($.browser.msie && $.browser.version=="6.0"){
		anim2Resetie6();
	    gaTrackEvent('Smoking and Family Life', 'Money reset');
	    }else{
		anim2Reset('400');
	    gaTrackEvent('Smoking and Family Life', 'Money reset');
	    }
	}
    }).drag(function(ev, dd){
	$(this).css({
	    left: Math.min(265,Math.max(31,dd.offsetX))
	});
	$(this).parent().find(".mask").css({
	    width: Math.min(265,Math.max(31,dd.offsetX))-31
	});
    },{
	relative:true
    });

    $("#info-section-3 .dragger").drag("start",function(ev,dd){
	$(this).parent().addClass('drag-active');
    }).drag("dragend",function(ev,dd){
	$(this).parent().removeClass('drag-active');
	if(dd.offsetX > 250){
	    if($.browser.msie && $.browser.version=="6.0"){
		anim3Changeie6();
	    gaTrackEvent('Smoking and Family Life', 'Family throw away extra');
	    }else{
		if($("#info-section-3").hasClass("animated")){
		    anim3ChangeNoAnim('400');
		gaTrackEvent('Smoking and Family Life', 'Family throw away extra');
		}else{
		    $('#info-section-3').dTimeline({
			functionName:'anim3Change',
			action:'autoTrigger'
		    });
		gaTrackEvent('Smoking and Family Life', 'Family throw away first');
		}  
	    }
	}else if(dd.offsetX < 46){
	    if($.browser.msie && $.browser.version=="6.0"){
		anim3Resetie6();
	    gaTrackEvent('Smoking and Family Life', 'Family reset');
	    }else{
		anim3Reset('400');
	    gaTrackEvent('Smoking and Family Life', 'Family reset');
	    }
	}
    }).drag(function(ev, dd){
	$(this).css({
	    left: Math.min(265,Math.max(31,dd.offsetX))
	});
	$(this).parent().find(".mask").css({
	    width: Math.min(265,Math.max(31,dd.offsetX))-31
	});
    },{
	relative:true
    });

    
});
//End of infographic docready

function anim1Change(frame,speed){
    switch(frame) {
        
	case 1:
	    $("#info-section-1 .pre-message span").fadeOut(speed);
	    break;
	case 2:
	    $("html, body").animate({
		'scrollTop':'799'
	    },speed);
	    break;

	case 3:
	    $(".animate1-years").addClass("showborder");
	    break;
	case 4:
	    $(".animate1-years .step1").fadeOut(speed);
	    break;
	case 5:
	    $(".animate1-years .step2").fadeIn(speed-100,function(){
		$(".animate1-years .step3").fadeIn(speed-100,function(){
		    $(".animate1-years .step4").fadeIn(speed-100,function(){
			$(".animate1-years .step5").fadeIn(speed-100,function(){
			    $(".animate1-years .step6").fadeIn(speed-100);
			});
		    });
		});
	    });
	    break;
	case 8:
	    $(".animate1-years .step8").fadeIn(speed);
	    break;
	case 9:
	    $(".animate1-years").removeClass("showborder");
	    break;

	case 11:
	    $(".animate1-football").addClass("showborder");
	    break;
	case 12:
	    $(".animate1-football .step1").fadeOut(speed);
	    break;
	case 13:
	    $(".animate1-football .step2").fadeOut(speed);
	    break;
	case 14:
	    $(".animate1-football .step3").fadeIn(speed);
	    break;
	case 15:
	    $(".animate1-football .step4").fadeIn(speed);
	    break;
	case 16:
	    $(".animate1-football .step5").fadeIn(speed);
	    break;
	case 17:
	    $(".animate1-football .step6").fadeIn(speed);
	    break;
	case 18:
	    $(".animate1-football").removeClass("showborder");
	    break;

	case 19:
	    $(".animate1-hours").addClass("showborder");
	    break;
	case 20:
	    $(".animate1-hours .step1").fadeOut(speed);
	    break;
	case 21:
	    $(".animate1-hours .step2").fadeOut(speed);
	    break;
	case 22:
	    $(".animate1-hours .step3").fadeIn(speed);
	    break;
	case 23:
	    $(".animate1-hours .step4").fadeOut(speed);
	    break;
	case 24:
	    $(".animate1-hours .step5").animate({
		'height':'1'
	    },speed);
	    break;
	case 25:
	    $(".animate1-hours .step6").fadeIn(speed);
	    break;
	case 26:
	    $(".animate1-hours").removeClass("showborder");
	    break;

	case 27:
	    $(".animate1-wembley").addClass("showborder");
	    break;
	case 28:
	    $(".animate1-wembley .step1").fadeOut(speed);
	    break;
	case 29:
	    $(".animate1-wembley .step2").fadeOut(speed);
	    break;
	case 30:
	    $(".animate1-wembley .step3").fadeIn(speed);
	    break;
	case 31:
	    $(".animate1-wembley .step4").fadeIn(speed);
	    break;
	case 32:
	    $(".animate1-wembley .step5").fadeIn(speed);
	    break;
	case 33:
	    $(".animate1-wembley").removeClass("showborder");
	    break;

	case 34:
	    $(".animate1-lungs").addClass("showborder");
	    break;
	case 35:
	    $(".animate1-lungs .step1").fadeOut(speed);
	    break;
	case 36:
	    $(".animate1-lungs .step2").fadeIn(speed);
	    break;
	case 37:
	    $(".animate1-lungs .step3").fadeOut(speed);
	    break;
	case 38:
	    $(".animate1-lungs").removeClass("showborder");
	    break;

	case 39:
	    $("html, body").animate({
		'scrollTop':'554'
	    },speed);
	    break;

	case 40:
	    $("#info-section-1 .post-message span").fadeIn(speed);
	    break;
	case 41:
	    $("#tab2").animate({
		"margin-top":"0"
	    },speed);
	    break;

	case 42:
	    $("#info-section-1").addClass("animated");
	    $("#info-section-1 .dragger").addClass("dragLeft").removeClass("dragRight");
	    break;
    }
}

function anim1Reset(speed){
    $("#info-section-1 .post-message span").fadeOut(speed);
    $("#info-section-1 .pre-message span").fadeIn(speed);
    $(".animate1-years .man").fadeOut(speed);
    $("#info-section-1 .good").fadeOut(speed);
    $("#info-section-1 .bad").fadeIn(speed);
    $(".animate1-hours .step5").animate({
	'height':'260px'
    },speed);
    $("#tab2").animate({
	"margin-top":"18px"
    },speed);
    $("#info-section-1 .dragger").addClass("dragRight").removeClass("dragLeft");
}

function anim1ChangeNoAnim(speed){
    $("#info-section-1 .post-message span").fadeIn(speed);
    $("#info-section-1 .pre-message span").fadeOut(speed);
    $(".animate1-years .man").fadeIn(speed);
    $("#info-section-1 .good").fadeIn(speed);
    $("#info-section-1 .bad").fadeOut(speed);
    $(".animate1-hours .step5").animate({
	'height':'1px'
    },speed);
    $("#tab2").animate({
	"margin-top":"1px"
    },speed);
    $("#info-section-1 .swap").text("Smoking?");
    $("#info-section-1 .dragger").addClass("dragLeft").removeClass("dragRight");
}

function anim2Change(frame,speed){
    switch(frame) {
	case 1:
	    $("#info-section-2 .pre-message span").fadeOut(speed);
	    break;

	case 2:
	    $("html, body").animate({
		'scrollTop':'799'
	    },speed);
	    break;

	case 3:
	    $(".animate2-piggy").addClass("showborder");
	    break;
	case 4:
	    $(".animate2-piggy .step1").fadeOut(speed);
	    break;
	case 5:
	    $(".animate2-piggy .step2").fadeOut(speed);
	    break;
	case 6:
	    $(".animate2-piggy .step3").fadeIn(speed);
	    break;
	case 7:
	    $(".animate2-piggy .step4").fadeIn(speed);
	    break;
	case 8:
	    $(".animate2-piggy .step5").fadeIn(speed);
	    break;
	case 9:
	    $(".animate2-piggy").removeClass("showborder");
	    break;

	case 10:
	    $(".animate2-sofa").addClass("showborder");
	    break;
	case 11:
	    $(".animate2-sofa .step1").fadeOut(speed);
	    break;
	case 12:
	    $(".animate2-sofa .step2").fadeOut(speed);
	    break;
	case 13:
	    $(".animate2-sofa .step5").fadeIn(speed);
	    break;
	case 14:
	    $(".animate2-sofa").removeClass("showborder");
	    break;

	case 15:
	    $(".animate2-money").addClass("showborder");
	    break;
	case 16:
	    $(".animate2-money .step1").fadeOut(speed);
	    break;
	case 17:
	    $(".animate2-money .step2").fadeOut(speed);
	    break;
	case 18:
	    $(".animate2-money .step3").fadeOut(speed);
	    break;
	case 19:
	    $(".animate2-money .step4").fadeIn(speed);
	    break;
	case 20:
	    $(".animate2-money .step5").fadeIn(speed);
	    break;
	case 21:
	    $(".animate2-money .step6").fadeIn(speed);
	    break;
	case 22:
	    $(".animate2-money .step7").fadeIn(speed);
	    break;
	case 23:
	    $(".animate2-money").removeClass("showborder");
	    break;

	case 24:
	    $(".animate2-more").addClass("showborder");
	    break;
	case 25:
	    $(".animate2-more .step1").fadeOut(speed);
	    break;
	case 26:
	    $(".animate2-more .step3").fadeOut(speed);
	    break;
	case 27:
	    $(".animate2-more .step2").fadeOut(speed);
	    break;
	case 28:
	    $(".animate2-more .step4").fadeIn(speed);
	    break;
	case 29:
	    $(".animate2-more .step5").fadeIn(speed);
	    break;
	case 30:
	    $(".animate2-more .step6").fadeIn(speed);
	    break;
	case 31:
	    $(".animate2-more .step7").fadeIn(speed);
	    break;
	case 32:
	    $(".animate2-more .step8").fadeIn(speed);
	    break;
	case 33:
	    $(".animate2-more .step9").fadeIn(speed);
	    break;
	case 34:
	    $(".animate2-more").removeClass("showborder");
	    break;

	case 35:
	    $("html, body").animate({
		'scrollTop':'554'
	    },speed);
	    break;

	case 36:
	    $("#info-section-2 .post-message span").fadeIn(speed);
	    break;
	case 37:
	    $("#tab3").animate({
		"margin-top":"0"
	    },speed);
	    break;

	case 38:
	    $("#info-section-2").addClass("animated");
	    $("#info-section-2 .dragger").addClass("dragLeft").removeClass("dragRight");
	    break;
    }
}

function anim2Reset(speed){
    $("#info-section-2 .post-message span").fadeOut(speed);
    $("#info-section-2 .pre-message span").fadeIn(speed);
    $("#info-section-2 .good").fadeOut(speed);
    $("#info-section-2 .bad").fadeIn(speed);
    $("#tab2").animate({
	"margin-top":"18px"
    },speed);
    $("#info-section-2 .swap").text("Quitting?");
    $("#info-section-2 .dragger").addClass("dragRight").removeClass("dragLeft");
}

function anim2ChangeNoAnim(speed){
    $("#info-section-2 .post-message span").fadeIn(speed);
    $("#info-section-2 .pre-message span").fadeOut(speed);
    $("#info-section-2 .good").fadeIn(speed);
    $("#info-section-2 .bad").fadeOut(speed);
    $("#tab2").animate({
	"margin-top":"1px"
    },speed);
    $("#info-section-2 .swap").text("Smoking?");
    $("#info-section-2 .dragger").addClass("dragLeft").removeClass("dragRight");
}

function anim3Change(frame,speed){
    switch(frame) {
	case 1:
	    $("#info-section-3 .pre-message span").fadeOut(speed);
	    break;

	case 2:
	    $("html, body").animate({
		'scrollTop':'799'
	    },speed);
	    break;

	case 3:
	    $(".animate3-future").addClass("showborder");
	    break;
	case 4:
	    $(".animate3-future .step1").fadeOut(speed);
	    break;
	case 5:
	    $(".animate3-future .step2").fadeIn(speed);
	    break;
	case 6:
	    $(".animate3-future").removeClass("showborder");
	    break;

	case 7:
	    $(".animate3-doc").addClass("showborder");
	    break;
	case 8:
	    $(".animate3-doc .step1").fadeOut(speed);
	    break;
	case 9:
	    $(".animate3-doc .step2").fadeOut(speed);
	    break;
	case 10:
	    $(".animate3-doc .step3").fadeIn(speed);
	    break;
	case 11:
	    $(".animate3-doc .step4").fadeIn(speed);
	    break;
	case 12:
	    $(".animate3-doc").removeClass("showborder");
	    break;

	case 13:
	    $(".animate3-family").addClass("showborder");
	    break;
	case 14:
	    $(".animate3-family .step1").fadeOut(speed);
	    break;
	case 15:
	    $(".animate3-family .step2").fadeOut(speed);
	    break;
	case 16:
	    $(".animate3-family .step3a").fadeOut(speed);
	    $(".animate3-family .step3b").fadeIn(speed);
	    break;
	case 17:
	    $(".animate3-family .step4a").fadeOut(speed);
	    $(".animate3-family .step4b").fadeIn(speed);
	    break;
	case 18:
	    $(".animate3-family .step5").fadeIn(speed);
	    break;
	case 19:
	    $(".animate3-family .step6").fadeIn(speed);
	    break;
	case 20:
	    $(".animate3-family").removeClass("showborder");
	    break;

	case 21:
	    $(".animate3-school").addClass("showborder");
	    break;
	case 22:
	    $(".animate3-school .step1").fadeOut(speed);
	    break;
	case 23:
	    $(".animate3-school .step2").fadeOut(speed);
	    break;
	case 24:
	    $(".animate3-school .step4").fadeIn(speed);
	    break;
	case 25:
	    $(".animate3-school .step3").fadeIn(speed);
	    break;
	case 26:
	    $(".animate3-school").removeClass("showborder");
	    break;

	case 27:
	    $("html, body").animate({
		'scrollTop':'554'
	    },speed);
	    break;

	case 28:
	    $("#info-section-3").addClass("animated");
	    $("#info-section-3 .dragger").addClass("dragLeft").removeClass("dragRight");
	    break;
    }
}

function anim3Reset(speed){
    $("#info-section-3 .post-message span").fadeOut(speed);
    $("#info-section-3 .pre-message span").fadeIn(speed);
    $("#info-section-3 .good").fadeOut(speed);
    $("#info-section-3 .bad").fadeIn(speed);
    $("#info-section-3 .dragger").addClass("dragRight").removeClass("dragLeft");
}

function anim3ChangeNoAnim(speed){
    $("#info-section-3 .post-message span").fadeIn(speed);
    $("#info-section-3 .pre-message span").fadeOut(speed);
    $("#info-section-3 .good").fadeIn(speed);
    $("#info-section-3 .bad").fadeOut(speed);
    $("#info-section-3 .dragger").addClass("dragLeft").removeClass("dragRight");
}

function anim1Changeie6(){
    $("#info-section-1 .bad, #info-section-1 .pre-message span").hide();
    $("#info-section-1 .good, #info-section-1 .post-message span").show();
    $(".animate1-years .man").show();
    $(".animate1-hours .mask").addClass("on");
    $("#info-section-1 .dragger").addClass("dragLeft").removeClass("dragRight");
}

function anim1Resetie6(){
    $("#info-section-1 .bad, #info-section-1 .pre-message span").show();
    $("#info-section-1 .good, #info-section-1 .post-message span").hide();  
    $(".animate1-years .man").hide();
    $(".animate1-hours .mask").removeClass("on");
    $("#info-section-1 .dragger").addClass("dragRight").removeClass("dragLeft");
}

function anim2Changeie6(){
    $("#info-section-2 .bad, #info-section-2 .pre-message span").hide();
    $("#info-section-2 .good, #info-section-2 .post-message span").show();
    $("#info-section-2 .dragger").addClass("dragLeft").removeClass("dragRight");
}

function anim2Resetie6(){
    $("#info-section-2 .bad, #info-section-2 .pre-message span").show();
    $("#info-section-2 .good, #info-section-2 .post-message span").hide();
    $("#info-section-2 .dragger").addClass("dragRight").removeClass("dragLeft");
}

function anim3Changeie6(){
    $("#info-section-3 .bad, #info-section-3 .pre-message span").hide();
    $("#info-section-3 .good, #info-section-3 .post-message span").show();
    $(".animate3-family .bad, .animate3-family .good, .animate3-family .speech").hide();
    $(".animate3-family .step5").show();
    $(".animate3-family .ppl").addClass("on");
    $("#info-section-3 .dragger").addClass("dragLeft").removeClass("dragRight");
}

function anim3Resetie6(){
    $("#info-section-3 .bad, #info-section-3 .pre-message span").show();
    $("#info-section-3 .good, #info-section-3 .post-message span").hide();
    $(".animate3-family .bad, .animate3-family .good, .animate3-family .speech").hide();
    $(".animate3-family .step2").show();
    $(".animate3-family .ppl").removeClass("on");
    $("#info-section-3 .dragger").addClass("dragRight").removeClass("dragLeft");
}

//Danny added calendar functionality


$(document).ready( function(){
	
    $('.noJavascriptWeeks').hide();
    $('.dropDown').show();
    $('.jsAlt').show();
	
	
    /* For changing the page with the select box */

    $('.numberOfWeeks').change( function(){
		
	var trimester = $(this).val();
		
	window.location = trimester;

    });
	
    /* ----------------------------------------- */

    //Clicking on calendar tabs used to change content in the main content area

    $('.firstTrimester a').click( function(){
	
	var theLink = $(this).attr('class');
	
	$(".stageContent").load("/smoking-and-pregnancy/calendar/ajax/" + theLink + ".html");
	$('.periods li').removeClass("on");
	$(this).parent().addClass(" on");
		 
	return false;
    });

    $('.secondTrimester a').click( function(){
	
	var theLink = $(this).attr('class');
	
	$(".stageContent").load("/smoking-and-pregnancy/calendar/ajax/" + theLink + ".html");
	$('.periods li').removeClass("on");
	$(this).parent().addClass(" on");
		 
	return false;
    });

    $('.thirdTrimester a').click( function(){
	
	var theLink = $(this).attr('class');
	
	$(".stageContent").load("/smoking-and-pregnancy/calendar/ajax/" + theLink + ".html");
	$('.periods li').removeClass("on");
	$(this).parent().addClass(" on");

	return false;
    });


    /* Dads and Smoking */

    $('ul.tabs li a').click( function(){
	
	var theLink = $(this).attr('class');
	
	$(".tabBoxInnerInner").load("/smoking-and-pregnancy/fathers-and-smoking/ajax/" + theLink + ".html");
	$('.imageContainerInnerInner').load("/smoking-and-pregnancy/fathers-and-smoking/ajax/image" + theLink + ".html");
		 
	$('.tabs li').removeClass("on");
	$(this).parent().addClass(" on");
		
	return false;
    });



	
    /* Hover pop ups on stages in Just the Facts*/

    $('map area').mouseover(

	function(){
	
	    var id = $(this).attr('id');
	
	    $('ol li.' + id).show();
	
	} );
	
    $('map area').mouseout(
	
	function(){

	    var id = $(this).attr('id');

	    $('ol li.' + id).hide();

	});
});


function setCookie(c_name,value){
    var exdate=new Date();
    exdate.setDate(exdate.getTime()+1440000); //24 minutes
    document.cookie=c_name+ "=" +escape(value)+ ";expires=" +exdate.toGMTString();
}

function getCookie(c_name){
    if (document.cookie.length>0)
    {
	c_start=document.cookie.indexOf(c_name + "=");
	if (c_start!=-1)
	{
	    c_start=c_start + c_name.length+1;
	    c_end=document.cookie.indexOf(";",c_start);
	    if (c_end==-1){
		c_end=document.cookie.length;
	    }
	    return unescape(document.cookie.substring(c_start,c_end));
	}
    }
    return "";
}


// Google Analytics wrapper functions
// There are here to make sure we dont have undefined errors on the unlikely 
// chance that the user clicks on a tracked link before ga has initialised.
function gaHasTrackedAction(action){
    var actionString = getCookie("rrGaEventActions");
    var actions = actionString.split("|");
	
    if (-1 == actions.indexOf(action)) {
	actions.push(action);
	setCookie("rrGaEventActions",  actions.join("|"));
	return false;
    }
    return true;
}

function gaTrackEvent(category, action, optional_label, optional_value){

    try {
	
	_gaq.push(['_trackEvent', category, action, optional_label]);

	
    } catch(err){}
}

function gaLink(targetUrl, useHash){
    try {
	_gaq.push(['_trackPageview', targetUrl, useHash]);
    } catch(err){}
}

function gaTrackPageview(url)
{
    try {
	_gaq.push(['_trackPageview', url]);
    } catch(err){}
}

$(document).ready(function() {
    // Open all PDF and txt's in a new window
    $("a[href*='.pdf']").click(function(){
	var filename=this.href.substring(this.href.lastIndexOf('/')+1, this.href.length);
	gaTrackPageview('/downloads/' + filename);
	gaTrackEvent('artemis', 'active', 'pdf'); // ga event tracking
	gaTrackEvent('Download', 'PDF', $(this).attr('href') ); // ga event tracking
	window.open(this.href);
	return false;
    });
    $("a[href*='.txt']").click(function(){
	var filename=this.href.substring(this.href.lastIndexOf('/')+1, this.href.length);
	gaTrackPageview('/downloads/' + filename);
	gaTrackEvent('artemis', 'active', 'txt'); // ga event tracking
	gaTrackEvent('Download', 'TXT', $(this).attr('href') ); // ga event tracking
	window.open(this.href);
	return false;
    });
    // Track mpg links
    $("a[href$='.mpg'],a[href$='.mpeg']").click(function(){
	var filename=this.href.substring(this.href.lastIndexOf('/')+1, this.href.length);
	gaTrackPageview('/mpegs/' + filename);
	gaTrackEvent('artemis', 'active', 'mpg'); // ga event tracking
	gaTrackEvent('Download', 'MPG', $(this).attr('href') ); // ga event tracking
	return true;
    });
		
    // Open external links in new windows
    //Get all links with rel="external" and place them into 'external'
    var external = $('a[rel="external"]');
    if (!$(external).attr('title')) {
	$(external).attr('title', 'No title');
    }
    external.attr("title", external.attr("title") + " - Link opens in a new window..");		//Take the links current title and append it with the external link message
    external.click( function() {															//When an external link is clicked
	window.open( $(this).attr('href') );												//Open its href in a new window
	return false;																		//Cancel the links default behaviour
    });
	
    //---------------------------------------------------------------------------------
	
    $('.noScript').hide();
    $('#scrollWrapper').show();
    if (0 < $('.scrollerContent').length){
	$('.scrollerContent').jScrollPane({
	    scrollbarWidth  :133,
	    showArrows	    :true
	});
    }
    $('.jScrollArrowUp').css('width','16px');
    //$('.jScrollArrowDown').css({'width': '16px','height':'45px'});
    $('.jScrollArrowDown').css({
	'width': '16px'
    });
	
    //Homepage spotlight

    $(".primarySpotlight .section").hide(); //Hide all content
    $(".spotlightNav li:eq(0)").addClass("active").show(); //Activate first tab
    $(".primarySpotlight .section:eq(0)").show(); //Show first tab content

    //On Click Event
    $(".spotlightNav li").click(function() {
		
	if ($(this).hasClass("active")){
	    return false; // ignore if already active
	}
		
	var tabFinder = $(this).attr("class");

	$(".spotlightNav li").removeClass("active"); //Remove any "active" class
	$(this).addClass("active"); //Add "active" class to selected tab
	$(".primarySpotlight .section").hide(); //Hide all tab content
		
	var activeTab = $(this).parent().parent().find(".section").filter("." + tabFinder);//Find the href attribute value to identify the active tab + content
	$(activeTab).show(); //Fade in the active ID content
	return false;
    });

    /* -- lsss hide show -- */

    $('#rightContent').addClass('jsEnabled');
    $('.lsssSearchWrapper').addClass('jsLSSSS');
	
    if (1 < $('#lsssResultsHome tbody tr').length) {
	$('.viewAll').show();
    }

    $('.viewAll').click( function(){
		
	if($('#lsssResultsHome tbody tr').is(":hidden")){
	    $('#lsssResultsHome tbody tr:not(:first)').show();
	    $(this).children('span').children('span').text("Close");
	    $(this).addClass('close');
	} else {
	    $('#lsssResultsHome tbody tr:not(:first)').hide();
	    $(this).children('span').children('span').text("View all");
	    $(this).removeClass('close');
	}
	return false;
    });
	
    $('#lsssPostcodeChange').click( function(){
	$('#lsssResults').hide();
	$('.viewAll').hide();
	$('#lsssSearchForm').show();
	return false;
    });
	
    //feature Roll Overs

    $('#featuredLinksLanding .featureLinkWrapper, #featuredLinks .featureLinkWrapper').hover(
	function(){
	    $(this).children().children().next('p.rollOver').show();
	    $(this).addClass('active');
	},
	function(){
	    $(this).children().children().next('p.rollOver').hide();
	    $(this).removeClass('active');
	});
	
    //Generic Video Player
    $('div.rb_MediaContainer div.videoPanel').after('<div class="viewOptions"><a href="#">View options</a></div>');
    $('div.viewOptions a').toggle(
	function(){
	    $(this).addClass('open');
	    $(this).parent().parent().find('.videoToolsContainer').slideDown();
	    var tracking_reference = $(this).closest('.rb_MediaContainer').find('[name="flashvars"]').attr('value').split('&')[1].split('=')[1];
	    gaTrackEvent('Video', 'Show options', tracking_reference );
	},
	function() {
	    $(this).removeClass('open');
	    $(this).parent().parent().find('.videoToolsContainer').slideUp();
	}
	);

    //Rebrand expandable
    $('div.expandable .section').hide();
    $('div.expandable h2').addClass('expandHeader').wrapInner('<a href="#"></a>');
	
    $('div.expandable h2 a').toggle(
	function(){
	    $(this).addClass('open');
	    $(this).parent().next('.section').slideDown();
	    gaTrackEvent('Progressive Disclosure', 'open', $(this).text());
	},
	function(){
	    $(this).removeClass('open');
	    $(this).parent().next('.section').slideUp();
	    gaTrackEvent('Progressive Disclosure', 'close', $(this).text());
	}
	);
	
    //Announcement cycle
    $('.cycle').cycle({
	next: '.next',
	prev: '.prev',
	timeout: 12000
    });

    //$('.show_hide').hide();
    $('input.postcode_find_address').after('<a class="find_address"><span>Find address</span></a>');

    $('.find_address').toggle(
	function(){
	    $(this).addClass('open');
	    $(this).parent().next('.show_hide').fadeIn();
	    gaTrackEvent('Progressive Disclosure', 'open', $(this).text());
	},
	function(){
	    $(this).removeClass('open');
	    $(this).parent().next('.show_hide').fadeOut();
	    gaTrackEvent('Progressive Disclosure', 'open', $(this).text());
	}
	);


	
    //Calculator

    $('.calc_container label').hide();
    $('.calc_container').addClass('faded');

    $(".calc_1 textarea").focus(function() {
	if( $(this).val() == "Enter how much a packet of cigarettes costs you..." ) {
	    $(this).val("");
	}
	$(this).keyup(function() {
	    $(this).parent().parent().next('.calc_container').removeClass('faded');
	});
    });
	

    $(".calc_1 textarea").blur(function() {
	if( !$(this).val().length ) {
	    $(this).val("Enter how much a packet of cigarettes costs you...");
	}
    });

    $(".calc_2 textarea").focus(function() {
	if( $(this).val() == "Enter how many cigarettes you smoke a day..." ) {
	    $(this).val("");
	}
	$(this).keyup(function() {	
	    $(this).parent().parent().next('.calc_container').removeClass('faded');
	});
    });

    $(".calc_2 textarea").blur(function() {
	if( !$(this).val().length ) {
	    $(this).val("Enter how many cigarettes you smoke a day...");
	}
    });

    //My body

    $('.rb_my_body').addClass('rollover');

    $('div.rb_my_body.rollover ul').after('<div class="section rolloverHelp"><p>Reminding yourself of the damage smoking does to your body will give you extra motivation to quit smoking.</p><p>Roll over the green circles on the image to find out what damage smoking causes.</p></div>');

    $('#content div.rollover ul li a').mouseover(function(){
	$('div.rollover div.section').hide();
    });

    $('li.mouth_throat a').mouseover(function(){
	$('div.mouth_throat').fadeIn();
	gaTrackEvent('My body hotspot', 'hover', $(this).text());
    });

    $('li.skin_bones a').mouseover(function(){
	$('div.skin_bones').fadeIn();
	gaTrackEvent('My body hotspot', 'hover', $(this).text());
    });

    $('li.lungs a').mouseover(function(){
	$('div.lungs').fadeIn();
	gaTrackEvent('My body hotspot', 'hover', $(this).text());
    });

    $('li.heart a').mouseover(function(){
	$('div.heart').fadeIn();
	gaTrackEvent('My body hotspot', 'hover', $(this).text());
    });

    $('li.circulation a').mouseover(function(){
	$('div.circulation').fadeIn();
	gaTrackEvent('My body hotspot', 'hover', $(this).text());
    });

    $('li.stomach a').mouseover(function(){
	$('div.stomach').fadeIn();
	gaTrackEvent('My body hotspot', 'hover', $(this).text());
    });

    $('li.reproduction_fertility a').mouseover(function(){
	$('div.reproduction_fertility').fadeIn();
	gaTrackEvent('My body hotspot', 'hover', $(this).text());
    });

    // Quit kit

    $('.rb_quit_kit').addClass('qk_rollover');
    var region_str = '';
    if(typeof(quit_kit_region) !== 'undefined'){
	region_str = '?region=' + quit_kit_region;
    }
    $('.quit_kit_box_inner').prepend('<div class="section qk_rolloverHelp"><h2>What&#39;s in a Quit Kit?</h2><p>Take a look at what&#39;s inside this year&#39;s Quit Kit. Roll over the items to find out more.</p><a class="qk_button" href="/quit-tools/quit-kit/order/' + region_str + '"><span>Order a Quit Kit online</span></a></div>');

    $('#content div.qk_rollover ul li a').mouseover(function(){
	$('div.qk_rollover div.section').hide();
    });


    $('li.tangle a').mouseover(function(){
	$('div.tangle').fadeIn();
	gaTrackEvent('Quit Kit hotspot', 'hover', $(this).text());
    });

    $('li.better_health_more_wealth a').mouseover(function(){
	$('div.better_health_more_wealth').fadeIn();
	gaTrackEvent('Quit Kit hotspot', 'hover', $(this).text());
    });

    $('li.quit_planner a').mouseover(function(){
	$('div.quit_planner').fadeIn();
	gaTrackEvent('Quit Kit hotspot', 'hover', $(this).text());
    });

    $('li.get_expert_help  a').mouseover(function(){
	$('div.get_expert_help').fadeIn();
	gaTrackEvent('Quit Kit hotspot', 'hover', $(this).text());
    });
  
    $('li.stress_busting_downloads a').mouseover(function(){
	$('div.stress_busting_downloads').fadeIn();
	gaTrackEvent('Quit Kit hotspot', 'hover', $(this).text());
    });

    $('li.welcome_card a').mouseover(function(){
	$('div.welcome_card').fadeIn();
	gaTrackEvent('Quit Kit hotspot', 'hover', $(this).text());
    });

    $('li.willpower_assessor a').mouseover(function(){
	$('div.willpower_assessor').fadeIn();
	gaTrackEvent('Quit Kit hotspot', 'hover', $(this).text());
    });
  
    $('li.motivational_postcards a').mouseover(function(){
	$('div.motivational_postcards').fadeIn();
	gaTrackEvent('Quit Kit hotspot', 'hover', $(this).text());
    });

    $('li.myth_buster a').mouseover(function(){
	$('div.myth_buster').fadeIn();
	gaTrackEvent('Quit Kit hotspot', 'hover', $(this).text());
    });

    $('li.recommendafriend a').mouseover(function(){
	$('div.recommendafriend').fadeIn();
	gaTrackEvent('Quit Kit hotspot', 'hover', $(this).text());
    });
    $('li.disturbing_information a').mouseover(function(){
	$('div.disturbing_information').fadeIn();
	gaTrackEvent('Quit Kit hotspot', 'hover', $(this).text());
    });


    // Tabs
    //When page loads...
    $("ul.tabNav").show();
    $(".tabContent .section").hide(); //Hide all content
    $("ul.tabNav li:eq(0)").addClass("active").show(); //Activate first tab
    $(".tabContent .section:eq(0)").show(); //Show first tab content

    //On Click Event
    $("ul.tabNav li").click(function() {
	if ($(this).hasClass("active")){
	    return false; // ignore if already active
	}
	var tabFinder = $(this).attr("class");
	$("ul.tabNav li").removeClass("active"); //Remove any "active" class
	$(this).addClass("active"); //Add "active" class to selected tab
	$(".tabContent .section").hide(); //Hide all tab content
	var activeTab = $(this).parent().parent().find(".section").filter("." + tabFinder);//Find the href attribute value to identify the active tab + content
	$(activeTab).show(); //Fade in the active ID content
	return false;
    });

    //Timeline
    //When page loads...
    $("ul.timeLineNav").show();
    $(".rb_timeLine .section").hide(); //Hide all content
    $("ul.timeLineNav li:eq(0)").addClass("active").show(); //Activate first tab
    $(".rb_timeLine .section:eq(0)").show(); //Show first tab content

    //On Click Event
    $("ul.timeLineNav li").click(function() {
	if ($(this).hasClass("active")){
	    return false; // ignore if already active
	}
	var tabFinder = $(this).attr("class");
	$("ul.timeLineNav li").removeClass("active"); //Remove any "active" class
	$(this).addClass("active"); //Add "active" class to selected tab
	$(".rb_timeLine .section").hide(); //Hide all tab content
	var activeTab = $(this).parent().parent().find(".section").filter("." + tabFinder);//Find the href attribute value to identify the active tab + content
	$(activeTab).show(); //Fade in the active ID content
	gaTrackEvent('Timline Tab', 'Click', $(this).text());
	return false;
    });


    // Track retailer search

    $('#retailerSearchForm').submit(function(){

	if( $('#postcode').val() != 'Enter your postcode' ){
	    var postcode = 'Postcode: ' + $('#postcode').val();
	    gaTrackEvent('Search Form', 'Submit', postcode );
	}else{
	    gaTrackEvent('Search Form', 'Submit' );
	}

    });


    // Terms and conditions show hide

    $('.termsConditionsCopy').hide();

    $('.termsConditionsLink').click(function(){
	$(this).parent().parent().next('.termsConditionsCopy').fadeIn();
	return false;
    });

    // Search Results URL Parsing
    $('#searchResults>dt>a').each(function(){
	var resultPath = $(this).attr('href');
	$(this).parent('dt').next('dd').html('<a href="' + resultPath + '">' + resultPath + '</a>');
    });

    // Quit Tools Checklist
    $('.finalForm form').submit(function(){
	var cookieID = $('.finalForm').attr('rel');
	$.cookie( cookieID , 'true' , {
	    path: '/', 
	    expires: 7
	} );
    });
    
    var cookies = get_cookies_array(); // get cookies, dump'm in an array

    $('.test-checklist li').each(function(i,item){ // index list items
	if( undefined != cookies[item.id] && 'true' == cookies[item.id] ){ // check for li ID's in cookies array
	    $(item).addClass('done'); // it it's there, add a class
	    var testTitle = $(item).children('a').html(); // remove link
	    $(item).html(testTitle);
	}
    });

    // Testing - kill cookies
    $('#killcookies').click(function(){
	$.cookie('testAddiction',null,{
	    path: '/', 
	    expires: -10
	});
	$.cookie('testBody',null,{
	    path: '/', 
	    expires: -10
	});
	$.cookie('testPromise',null,{
	    path: '/', 
	    expires: -10
	});
	$.cookie('testCost',null,{
	    path: '/', 
	    expires: -10
	});
	window.location.href=this.href;
	return false;
    });

    // Real Life Quitters Page Doodah
    var listing = '#videolisting',
	article = '.videoArticle',
	fullArticle = '.keekaboo';

    $(listing).find('.keekaboo').hide();
    $(listing).find(article).append('<span class="more">&nbsp;</span>');
    $(listing).find('span.more').click(function(){
	if ( $(this).parent().hasClass('open') ) {
	    $(this).parent().removeClass('open').find('.keekaboo').slideUp();
	    $(this).parent().find('p.readmore').show();
	} else {
	    $(this).parent().addClass('open').find('.keekaboo').slideDown();
	    $(this).parent().find('p.readmore').hide();
	}
    });

    // Temporary fix for Mookie DoubleClick script that is manipulating the body tag on the Quit Kit thank you page
    $('#menu4').removeAttr('style').removeAttr('marginwidth').removeAttr('marginheight').removeAttr('leftmargin').removeAttr('topmargin');

    
    function setCookie(cookieID) {
	$(document).ready(function(){
	    $.cookie( cookieID , 'true' , {
		path: '/', 
		expires: 1
	    } );
	});
    }

    function get_cookies_array() {
	var cookies = [ ];
	if (document.cookie && document.cookie != '') {
	    var split = document.cookie.split(';');
	    for (var i = 0; i < split.length; i++) {
		var name_value = split[i].split("=");
		name_value[0] = name_value[0].replace(/^ /, '');
		cookies[decodeURIComponent(name_value[0])] = decodeURIComponent(name_value[1]);
	    }
	}
	return cookies;
    }

    var firstLevelOpen = null;
    var secondLevelOpen = null; 
      
    $(document).ready(function() {
	if (!isSafari2()) {
	    $(".productsList h2").toggle(
		function() { 
		    $(this).parent().parent().removeClass("on");
		    firstLevelOpen = null;
		}, 
		function() {
		    if (firstLevelOpen != null) {
			firstLevelOpen.trigger("click");
		    }
		    if (secondLevelOpen != null) {
			secondLevelOpen.trigger("click");
		    }
		    firstLevelOpen = $(this);
		    $(this).parent().parent().addClass("on");
		}
		).trigger("click");
	    $("#faqs dt").addClass("DTplus").next().addClass("hideDD");
	    $("#faqs dt").wrapInner("<a/>").find("a").attr("title", "Show/hide the answer").attr("href","#");
	    $("#faqs dt").toggle(
		function() {  
		    if (secondLevelOpen != null) {
			secondLevelOpen.trigger("click");
		    }
		    secondLevelOpen = $(this);
		    faqopen($(this));
		},
		function() {
		    faqclose($(this));
		    secondLevelOpen = null;
		}
		);
	}
      
    });

    function faqclose(dt) {
	dt.removeClass("DTminus").addClass("DTplus");
	dt.next().removeClass("showDD").addClass("hideDD");
    }

    function faqopen(dt) {
	dt.removeClass("DTplus").addClass("DTminus");
	dt.next().removeClass("hideDD").addClass("showDD");
    }


    $('.home_feature_cycle').cycle({
	autostop:1,
	speed:1000
    });

    // Init Google Maps
    googleMaps();
});





function googleMaps(){

    if( !$('input#postcode').val() || 'Enter your postcode' === $('input#postcode').val() || $('.errorMessage').length ){
	$( '#map_canvas' ).remove();
	return false;
    }
    
    

    // Check Maps is available
    if( typeof(google) == "undefined" || typeof(google.maps.MapTypeId) == "undefined" ){
	return false;
    }
    
    
    
    
    var infoWindow = new google.maps.InfoWindow(),
	mapOptions = {
	    zoom	    : 14,
	    mapTypeId   : google.maps.MapTypeId.ROADMAP
	},
	map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions),
	
	shadow = new google.maps.MarkerImage(
	    '/images/google-map-pins/shadow.png',
	    new google.maps.Size( 40,34 ), // Size
	    new google.maps.Point( 0, 0 ), // Origin
	    new google.maps.Point( 10, 34 ) // point
	    ),
	createMarker = function( latLng, markerChar, id, title, i, infotext ){
	    // Make a marker image object
	    var image = new google.maps.MarkerImage(
		'/images/google-map-pins/blue_Marker' + markerChar + '.png',
		new google.maps.Size( 20,34 ), // Size
		new google.maps.Point( 0, 0 ), // Origin
		new google.maps.Point( 10, 34 ) // point
		),
	    marker = new google.maps.Marker({
		position: latLng,
		map: map,
		title: title,
		id: id,
		icon: image,
		shadow: shadow,
		animation: google.maps.Animation.DROP
	    }),
	    clickFunction = function(){
		infoWindow.setContent(infotext);
		infoWindow.open(map,marker);
	    };
	    
	    google.maps.event.addListener( marker, 'click', clickFunction );
	    
	    return clickFunction;
	},
	addMarkers = function(){
	    var $resultsList = $('.rb_find_gp_results').find('li'),
		count = 0;
            
	    $resultsList.each( function( i, el ){
		var 
		    $that = $(this),
		    lat = $that.data('lat'),
		    lng = $that.data('lng'),
		    markerChar = (function(){
			if( count > 25 ){
			    count = 0;
			}
			count ++;
			return String.fromCharCode( 64 + count );
		    })(),
		    title = $that.find( '.title' ).text(),
		    infotext = '<h4>' + title + '</h4>' + '<p>' + $that.find( '.address' ).html() + '<br/>' + $that.find( '.distance' ).html() + '</p>';

		if( lat && lng ){
		    var latLng = new google.maps.LatLng( lat, lng ),
			id = this.id;

		    // Make a marker and bind it to the map    
		    var clickFunction = createMarker( latLng, markerChar, id, title, i, infotext );

		    $that.click( function( event ){
			clickFunction();
			
			event.preventDefault();
		    } );
		}
	    } );
            
    };
    
    // Centre map on searched location
    var postcode = $('input#postcode').val(),
	geocoder = new google.maps.Geocoder();
    
    geocoder.geocode( {
	'address': postcode, 
	'region':'uk'
    }, function(results, status) {
	if (status == google.maps.GeocoderStatus.OK) {
	    map.setCenter(results[0].geometry.location);
	    
	    var distance = $('#distance').val();
	    
	    // Draw an awesome circle!
	    var mileRadius = new google.maps.Circle({
		strokeColor: "#0072C6",
		strokeOpacity: 0.4,
		strokeWeight: 2,
		fillColor: "#0072C6",
		fillOpacity: 0.1,
		center: results[0].geometry.location,
		radius: 1609 * distance // 1 miles in metres = 1609
	    });

	    mileRadius.setMap(map);
	    
	    // Zoom levels for radii
	    var zoomSwitch = {
		1 : 14,
		5 : 12,
		10 : 11,
		15 : 10,
		20 : 10,
		30 : 9
	    };
	    
	    // Check property exists in zoomSwitch
	    if( zoomSwitch.hasOwnProperty( distance ) ){
		map.setZoom( zoomSwitch[distance] );
	    }
	}
    });
    
    
    // Add listner to add makers when its ready
    google.maps.event.addListenerOnce( map, 'tilesloaded', function(){
	addMarkers();
    } );
    
    return true;
}



































var flashShow;
flashShow = false;

// Pop up window generator
function tagQuestionnaireLinks(URL) {
    // if cookie is set, user has already taken part....then don't do the below
    var x = document.getElementsByTagName('A');
    for (var i=0;i< x.length;i++)
    {
	x[i].onclick = function () {
	    return popUpSurvey(URL);
	}
    }
	
}

function popUpSurvey(URL) {
    var page = window.open(URL, 'popup', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=504,height=551,left = 490,top = 312');
    page.focus();
}

function getURLParam(strParamName){
    var strReturn = "";
    var strHref = window.location.href;
    if ( strHref.indexOf("?") > -1 ){
	var strQueryString = strHref.substr(strHref.indexOf("?"));
	var aQueryString = strQueryString.split("&");
	for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
	    if (
		aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
		var aParam = aQueryString[iParam].split("=");
		strReturn = aParam[1];
		break;
	    }
	}
    }
    return unescape(strReturn);
}


function getWindowDimensions(){
    var dims = new Object();
    dims.frameWidth = 0;
    dims.frameHeight = 0;
    if (self.innerWidth){
	dims.frameWidth = self.innerWidth;
	dims.frameHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientWidth){
	dims.frameWidth = document.documentElement.clientWidth;
	dims.frameHeight = document.documentElement.clientHeight;
    }
    else if (document.body){
	dims.frameWidth = document.body.clientWidth;
	dims.frameHeight = document.body.clientHeight;
    }
    return dims;
}
function getFlashMovieObject(movieName){
    if (navigator.appName.indexOf("Microsoft Internet")==-1){
	if (document.embeds && document.embeds[movieName]){
	    return document.embeds[movieName];
	}
    }else if (window.document[movieName]){
	return window.document[movieName];
    }else{
	return document.getElementById(movieName);
    }
}
function playFlashMovie(movieName, subVideo) {
    var flashMovie = getFlashMovieObject(movieName);
    flashMovie.SetVariable('playvideonum', subVideo);
    flashMovie.Play();
}

/*
 * Checks whether the current user agent is Safari 2 or less.
 */
function isSafari2() {
    browserInfoComponents = navigator.appVersion.split(' ');
    browserInfo = browserInfoComponents[browserInfoComponents.length - 1].split('/');
    return ((browserInfo[0] == 'Safari') && (parseInt(browserInfo[1]) < 500));
}

function validate_name(fld,alerttxt)
{
    var error="";
    if (fld.value.length == 0) {
	fld.style.background = 'Yellow';
	error='Please enter your name\n';
	if(alerttxt=='Surname')
	    error='Please enter your surname\n';
    } else {
	fld.style.background = 'White';
    }
    return error;  
}

function validate_story(fld,alerttxt)
{
    var error="";
    if (fld.value.length == 0) {
	fld.style.background = 'Yellow';
	error='Please enter your story\n';
    } else {
	fld.style.background = 'White';
    }
    return error;  
}

function trim(s)
{
    return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
	fld.style.background = 'Yellow';
	error = "Please enter your email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
	fld.style.background = 'Yellow';
	error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
	fld.style.background = 'Yellow';
	error = "The email address contains illegal characters.\n";
    } else {
	fld.style.background = 'White';
    }
    return error;
}

function isFlashEnabled() {
    try {
	try {
	    var axo = new ActiveXObject('ShockwaveFlash.ShockwaveFlash.6');
	    try {
		axo.AllowScriptAccess = 'always';
	    }
	    catch(e) {
		return '6,0,0';
	    }
	} catch(e) {}
	return new ActiveXObject('ShockwaveFlash.ShockwaveFlash').GetVariable('$version').replace(/\D+/g, ',').match(/^,?(.+),?$/)[1];
    } catch(e) {
	try {
	    if(navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin){
		return (navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]).description.replace(/\D+/g, ",").match(/^,?(.+),?$/)[1];
	    }
	} catch(e) {}
    }
    return "true";
};
