﻿function LoadNew(playlist_url, playerId) {
    var emp = new bbc.Emp(); 
    emp.setWidth("256");
    emp.setHeight("179");
    emp.setDomId(playerId);
    emp.setPlaylist(playlist_url);
    emp.write();
}

function LoadVideoNew(id) {
    LoadNew("http://www.bbc.co.uk/sundaylife/video/playlist_clip" + id + ".xml", "clip" + id);
}

function load(playlist_url)
{
    var emp = new bbc.Emp(); 
    emp.setWidth("512");
    emp.setHeight("323");
    emp.setDomId("playercontainer");
    emp.setPlaylist(playlist_url);
    emp.write();
    SetTranscriptLink(4);
}

function loadVideo(link)
{
    var videoId = link.parentNode.id.substring(4);    
    var clipText = link.innerHTML;
    document.getElementById("cliptagline").innerHTML = "<p>" + clipText + "</p>";        
    load("http://www.bbc.co.uk/sundaylife/video/playlist_clip" + videoId + ".xml");         
    SetTranscriptLink(videoId);
    return false;
}

function SetTranscriptLink(videoId) 
{    
    var link = document.getElementById('transcriptLink');
    
    if(link != null)
    {
        link.href = "javascript:void(0);";     
        link.onclick = function () {window.open('clip' + videoId + 'transcript.shtml', 'Transcript', 'width=700,height=500,scrollbars=1');};
        
        switch (videoId)
        {
            case "1": link.innerHTML = "Read the transcript for Georgia Slowe meets Rabbi Barry Marcus in Auschwitz"; break;
            case "2": link.innerHTML = "Read the transcript for Emmerdale actress Georgia Slowe visits Auschwitz"; break;
            case "3": link.innerHTML = "Read the transcript for 7/7 survivor Gill Hicks talks about the London bombings"; break;
            case "4": link.innerHTML = "Read the transcript for Colin Jackson meets Archbishop Desmond Tutu."; break;
            case "5": link.innerHTML = "Read the transcript for Philip McTaggart talks about the Ardoyne suicides."; break;
            case "6": link.innerHTML = "Read the transcript for Helen Miller is waiting for a lung transplant."; break;
            case "7": link.innerHTML = "Read the transcript for the congregation of Britain's biggest online church."; break;
            case "8": link.innerHTML = "Read the transcript for the monks signed to the world's biggest record label."; break;
            case "9": link.innerHTML = "Read the transcript for the Goths attacked for looking different."; break;
            case "10": link.innerHTML = "Read the transcript for Kent police on a raid to free trafficked women."; break;
            case "11": link.innerHTML = "Read the transcript for the former hardman who now helps some of Britain's toughest prisoners."; break;
            case "12": link.innerHTML = "Read the transcript for Louise's chat with Gill Hicks and husband Joe about their forthcoming WALKTALK challenge."; break;
            case "13": link.innerHTML = "Read the transcript for Louise's chat with Gill Hicks and husband Joe about their forthcoming WALKTALK challenge."; break;
            case "14": link.innerHTML = "Read the transcript for the Sandersons do Buddhism.."; break;
            case "15": link.innerHTML = "Read the transcript for Colin Jackson meeting Archbishop Desmond Tutu."; break;
            case "16": link.innerHTML = "Read the transcript for Colin Jackson meeting Archbishop Desmond Tutu."; break;
            case "17": link.innerHTML = "Read the transcript for The Dalai Lama."; break;
            case "18": link.innerHTML = "Read the transcript for The Dalai Lama."; break;
            case "19": link.innerHTML = "Read the transcript for From Hymns to Hip Hop."; break;
            case "20": link.innerHTML = "Read the transcript for Parky and Mandela."; break;
            case "21": link.innerHTML = "Read the transcript for clip Mary Swinton talking about her experience of the Piper Alpha disaster."; break;
        } 
        link.style.display = "none";
    }    
}

function validateForm()
{
    var fname = document.getElementById("firstname").value;
    var lname = document.getElementById("lastname").value;
    var email = document.getElementById("email").value;
    var comments = document.getElementById("comments").value;
    var isValid = true;
    
    if(fname.length == 0)
    {
        alert("Please enter your first name");                
        return false;            
    }
    
    if(lname.length == 0)
    {
        alert("Please enter your last name");
        return false;
    }
    
    if(email.length == 0)
    {
        alert("Please enter your email address");
        return false;              
    }
    else if(!checkEmail(email))
    {
        alert("Please enter a valid email address");
        return false;
    }
    
    if(comments.length == 0)
    {
        alert("Please enter your comments");
        return false;
    }                            
    return true;  
}


function checkEmail(str) 
{
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)	
	if (str.indexOf(at)==-1)	   
	   return false;
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)	
	   return false;
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)	
	    return false;	
	 if (str.indexOf(at,(lat+1))!=-1)
	    return false;
	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)	    
	    return false;
	 if (str.indexOf(dot,(lat+2))==-1)	 
	    return false;
	 if (str.indexOf(" ")!=-1)	 
	    return false;	 

	 return true;				
}

function externalLinks() {
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
 for (var i=0; i<anchors.length; i++) {
   var anchor = anchors[i];
   if (anchor.getAttribute("href") &&
       anchor.getAttribute("rel") == "external")
     anchor.target = "_blank";
 }
}
window.onload = externalLinks;