﻿

//*************************************************************************************************************

window.onload = function() {
        
        var fileName = "default.aspx"
        
        if (getFileName(location.href) != "") {fileName = getFileName(location.href);} 
        switch (fileName.toLowerCase())
        {
        case "default.aspx":
                        
            // init main flash
            var flashvars = {};
            var centerFile = "yoplait_delights_site_660x330.swf";
            var vSceneNumber = getParams("SceneNumber");
            var vEpisodeNumber = getParams("EpisodeNumber");
           
            if ((vSceneNumber != "x") && (vEpisodeNumber != "x")) { 
                var flashvars = {
                    SceneNumber: vSceneNumber,
                    EpisodeNumber: vEpisodeNumber
                };
                centerFile = "yoplait_delights_site_preloader.swf";     
                document.getElementById("flashFooter").style.display = "none"; // dont display footer flash when displaying main video       
                document.getElementById("download").style.display = "block";
                document.getElementById("downloadScript").onclick =  function() {dcsMultiTrack('DCS.dcsuri','yoplait_delights/default/upload_to_youtube','WT.ti','Download Script'); getScript(1,vSceneNumber);}
                document.getElementById("uploadVideoButton").onclick = function() {dcsMultiTrack('DCS.dcsuri','yoplait_delights/default/upload_to_youtube','WT.ti','Upload Video Button'); tb_show('','TB_inline?height=500&width=360&inlineId=uploadVideo&modal=false','');	 }
                document.getElementById("viewVideo").onclick =  function() {dcsMultiTrack('DCS.dcsuri','yoplait_delights/default/upload_to_youtube','WT.ti','View Videos'); getScript(2,vSceneNumber);}
           
            } else {
                // init footer flash 
                initFlash ("swf/yoplait_delights_carousel_466x148.swf","footerVideo","flashFooter","flashFooterError","470", "150", {});
            }
            
            // main video
            $(document).ready(function() {
                 initFlash ("swf/" + centerFile ,"mainVideo","centralFlash","centralFlashError","660", "330", flashvars);
            });
    
           document.getElementById("share").onclick = function() {tb_show('','TB_inline?height=500&width=360&inlineId=friendLetFriend&modal=false','');}
           setTimeout ('displayWait()', 3000 );
    
            break;
        case "scenes.aspx":
            // view inidiviaul profiles and scroll through
            document.getElementById("actors1").onclick = function() { profile(1); }
            document.getElementById("actors2").onclick = function() { profile(2); }
            document.getElementById("actors3").onclick = function() { profile(3); }
            document.getElementById("actors4").onclick = function() { profile(4); }
            document.getElementById("nextGroup").onclick = function() { profileScroll(); } //scroll through
            document.getElementById("button-back").onclick = function() { closeProfile(); } // close window
            rolloverStates(); // rollover for video thumnails and columns
            instruct(); // loads splash instruction screen on initial load, cookie based.
            document.getElementById("download").style.display = "block"; // display download capabilities
            getSelection(); // gets selection and records
            document.getElementById("submitButton1").style.display = "block";
            document.getElementById("submitButton2").style.display = "block";
            document.getElementById("submitButton3").style.display = "block";
            document.getElementById("site").style.visibility = "visible";
            document.getElementById("uploadVideoButton").onclick = function() {dcsMultiTrack('DCS.dcsuri','yoplait_delights/scenes/upload_to_youtube','WT.ti','Upload Video Button'); tb_show('','TB_inline?height=500&width=360&inlineId=uploadVideo&modal=false','');	 }
            document.getElementById("downloadScript").onclick =  function() {dcsMultiTrack('DCS.dcsuri','yoplait_delights/scenes/upload_to_youtube','WT.ti','Download Script'); getScript(0,0);}
            document.getElementById("viewVideo").onclick =  function() {dcsMultiTrack('DCS.dcsuri','yoplait_delights/scenes/upload_to_youtube','WT.ti','View Videos'); getScript(2,vSceneNumber);}
            document.getElementById("share").onclick = function() {dcsMultiTrack('DCS.dcsuri','yoplait_delights/scenes/share_videos','WT.ti','Share Videos'); tb_show('','TB_inline?height=500&width=360&inlineId=friendLetFriend&modal=false','');}
            
            break;
        case "products.aspx":
            // set product page display onclick or per url paramaters
            document.getElementById("product-click-1").onclick = function() {changeProduct(1);choc_rasp(); };
            document.getElementById("product-click-2").onclick = function() {changeProduct(2);caramel(); };
            document.getElementById("product-click-3").onclick = function() {changeProduct(3);triple(); };
            document.getElementById("product-click-4").onclick = function() {changeProduct(4);lemon(); };
            document.getElementById("share").onclick = function() {tb_show('','TB_inline?height=500&width=360&inlineId=friendLetFriend&modal=false','');}
            var productId = 1;
            var urlString = getParams("productid");
            if ((urlString == "1") || (urlString == "2") || (urlString == "3") || (urlString == "4")) { productId = urlString; } ;
            
            changeProduct(productId);  //display product profile
           
            
            break;
        }
        
        // indulge friend email
        
            
            
      
}

//*************************************************************************************************************




function initFlash (flashFile,flashName,flashContainer,flashError,width, height,flashvars)
{
    // initialize flash

    var params = {
            wmode: "transparent",
            allowFullScreen: "true"
        };
    var attributes = {
            id:    flashName
    };
    
    if (!(swfobject.hasFlashPlayerVersion("9.0.18"))) { 
            document.getElementById("flashFooterError").style.display = "block"; 
        } 

    swfobject.embedSWF(flashFile,flashContainer,width,height, "9.0.0","expressInstall.swf",  flashvars, params, attributes);


    
}

function instruct(){

    

    var user = ReadCookie("userSession");
    document.getElementById("question-screen").onclick = function() {document.getElementById("instruct-intro").style.display = "block"; setTimeout('clearHelp()', 7000);}
    document.getElementById("closeSplash").onclick = function() {document.getElementById("instruct-intro").style.display = "none";}
    if(user.length == 0) { 
        document.getElementById("instruct-intro").style.display = "block";
        setTimeout('clearHelp()', 10000);
        SetCookie("userSession", "9999999", 0);
    } 
    
 
    
}

function getSelection () { 
    document.getElementById("selection1").onclick = function() {starClick(1,1,4,1);}
    document.getElementById("selection2").onclick = function() {starClick(2,1,4,1);}
    document.getElementById("selection3").onclick = function() {starClick(3,1,4,1);}
    document.getElementById("selection4").onclick = function() {starClick(4,1,4,1);}
    document.getElementById("selection5").onclick = function() {starClick(5,5,8,2);}
    document.getElementById("selection6").onclick = function() {starClick(6,5,8,2);}
    document.getElementById("selection7").onclick = function() {starClick(7,5,8,2);}
    document.getElementById("selection8").onclick = function() {starClick(8,5,8,2);}
    document.getElementById("selection9").onclick = function() {starClick(9,9,12,3);}
    document.getElementById("selection10").onclick = function() {starClick(10,9,12,3);}
    document.getElementById("selection11").onclick = function() {starClick(11,9,12,3);}
    document.getElementById("selection12").onclick = function() {starClick(12,9,12,3);}
    
    document.getElementById("surveySubmit1").onclick = function() {doVote(1);};
    document.getElementById("surveySubmit2").onclick = function() {doVote(2);};
    document.getElementById("surveySubmit3").onclick = function() {doVote(3);};
    
}

function checkSelection(itemId,start,end,row) {

    document.getElementById("submitButton" + row).style.display = "block";
    document.getElementById("surveySubmit" + row).src = "images/button-vote.jpg";
    document.getElementById("selection" + itemId).src = "images/star-red.gif";
    for (start;start <= end ; start++){
        if (itemId != start){
            document.getElementById("selection" + start).src = "images/star-white.gif";
         }
    }
}

function submitValue () {
    
    var videoName = "";
    for (var x=1;x < 5; x++){
    
    var star = document.getElementById("selection" + x).src;

    var filename = star.substring(star.lastIndexOf('/')+1);

        if (filename == "star-red.gif"){
            videoName  = document.getElementById("selection" + x).value;            
        } 
    }
    return videoName;
}


function clearHelp (){
    document.getElementById("instruct-intro").style.display = "none"
}

function displayWait(){
    document.getElementById("site").style.visibility = "visible";
    document.getElementById("waitScreen").style.display = "none";
}


function rolloverStates() {
    document.getElementById("thumb_1_1").onmouseover = function() { document.getElementById("thumb_1_1").src = "images/videoThumb_1_1.jpg";}
    document.getElementById("thumb_1_1").onmouseout = function() { document.getElementById("thumb_1_1").src = "images/videoThumb_1_1_off.jpg";}
    document.getElementById("thumb_1_2").onmouseover = function() { document.getElementById("thumb_1_2").src = "images/videoThumb_1_2.jpg";}
    document.getElementById("thumb_1_2").onmouseout = function() { document.getElementById("thumb_1_2").src = "images/videoThumb_1_2_off.jpg";}
    document.getElementById("thumb_1_3").onmouseover = function() { document.getElementById("thumb_1_3").src = "images/videoThumb_1_3.jpg";}
    document.getElementById("thumb_1_3").onmouseout = function() { document.getElementById("thumb_1_3").src = "images/videoThumb_1_3_off.jpg";}
    document.getElementById("thumb_1_4").onmouseover = function() { document.getElementById("thumb_1_4").src = "images/videoThumb_1_4.jpg";}
    document.getElementById("thumb_1_4").onmouseout = function() { document.getElementById("thumb_1_4").src = "images/videoThumb_1_4_off.jpg";}
    document.getElementById("thumb_2_1").onmouseover = function() { document.getElementById("thumb_2_1").src = "images/videoThumb_2_1.jpg";}
    document.getElementById("thumb_2_1").onmouseout = function() { document.getElementById("thumb_2_1").src = "images/videoThumb_2_1_off.jpg";}
    document.getElementById("thumb_2_2").onmouseover = function() { document.getElementById("thumb_2_2").src = "images/videoThumb_2_2.jpg";}
    document.getElementById("thumb_2_2").onmouseout = function() { document.getElementById("thumb_2_2").src = "images/videoThumb_2_2_off.jpg";}
    document.getElementById("thumb_2_3").onmouseover = function() { document.getElementById("thumb_2_3").src = "images/videoThumb_2_3.jpg";}
    document.getElementById("thumb_2_3").onmouseout = function() { document.getElementById("thumb_2_3").src = "images/videoThumb_2_3_off.jpg";}
    document.getElementById("thumb_2_4").onmouseover = function() { document.getElementById("thumb_2_4").src = "images/videoThumb_2_4.jpg";}
    document.getElementById("thumb_2_4").onmouseout = function() { document.getElementById("thumb_2_4").src = "images/videoThumb_2_4_off.jpg";}
    document.getElementById("thumb_3_1").onmouseover = function() { document.getElementById("thumb_3_1").src = "images/videoThumb_3_1.jpg";}
    document.getElementById("thumb_3_1").onmouseout = function() { document.getElementById("thumb_3_1").src = "images/videoThumb_3_1_off.jpg";}
    document.getElementById("thumb_3_2").onmouseover = function() { document.getElementById("thumb_3_2").src = "images/videoThumb_3_2.jpg";}
    document.getElementById("thumb_3_2").onmouseout = function() { document.getElementById("thumb_3_2").src = "images/videoThumb_3_2_off.jpg";}
    document.getElementById("thumb_3_3").onmouseover = function() { document.getElementById("thumb_3_3").src = "images/videoThumb_3_3.jpg";}
    document.getElementById("thumb_3_3").onmouseout = function() { document.getElementById("thumb_3_3").src = "images/videoThumb_3_3_off.jpg";}
    document.getElementById("thumb_3_4").onmouseover = function() { document.getElementById("thumb_3_4").src = "images/videoThumb_3_4.jpg";}
    document.getElementById("thumb_3_4").onmouseout = function() { document.getElementById("thumb_3_4").src = "images/videoThumb_3_4_off.jpg";}


    document.getElementById("actors1").onmouseover = function() { document.getElementById("actors1").src = "images/column1-on.gif";}
    document.getElementById("actors1").onmouseout = function() { document.getElementById("actors1").src = "images/column1.gif";}
    document.getElementById("actors2").onmouseover = function() { document.getElementById("actors2").src = "images/column2-on.gif";}
    document.getElementById("actors2").onmouseout = function() { document.getElementById("actors2").src = "images/column2.gif";}
    document.getElementById("actors3").onmouseover = function() { document.getElementById("actors3").src = "images/column3-on.gif";}
    document.getElementById("actors3").onmouseout = function() { document.getElementById("actors3").src = "images/column3.gif";}
    document.getElementById("actors4").onmouseover = function() { document.getElementById("actors4").src = "images/column4-on.gif";}
    document.getElementById("actors4").onmouseout = function() { document.getElementById("actors4").src = "images/column4.gif";}


}


function profile(profileId) {
    var description = new Array();
    description[1] = "This mixed bag of actors honed their theatrical chops at the tiny Sweetmont Playhouse. Wildly different in their own ways, the group comes together over late-night games of charades, and by memorizing pop songs backwards. They might not be known outside of town, but the applause is all they need. Deep, delightful, and passionate in everything they do—get ready to be charmed. ";
    description[2] = "When Home Economics and Auto Shop were already filled, this quintessential subset of high schoolers: the jock, the queen bee, the wallflower, and the future valedictorian, got thrown together in a drama class elective. For 43 minutes a day, the shy girl gets to kiss the popular guy, and the queen bee doesn’t get what she wants. Due to their fearlessness and precociousness, they’re refreshingly entertaining.";
    description[3] = "This isn’t your typical retirement center. These energetic, adorable seniors thrill to water-aerobics and bake-offs by day, and audition for the Acting Troupe by night—their community’s most exclusive extracurricular group. They recite lines while swimming laps, and serenade each other during karaoke. Surrounded by a surprising amount of drama on a daily basis, their performances are always vivacious. ";
    description[4] = "Thespians and banking don't usually go together. And the last thing these power-brokers thought they’d be doing during their free evenings was rehearsing. But, when the guys were told they could get a small tax break by performing for the public, reciting lines became their passion. At first it was tough, putting their machismo aside to play an emotional role. In the end, though—their attractive and tempting ways stole the show.";
    
    document.getElementById("grid").style.display =         "none";
    document.getElementById("profile").style.display =      "block";
    document.getElementById("title-bio").src =              "images/bio-title-" + profileId + ".jpg"; 
    document.getElementById("imageprofile").src =           "images/profile" + profileId + ".jpg"; 
    document.getElementById("profiletext").innerHTML =      description[profileId]; 
    document.getElementById("nextGroup").value =            profileId; 
   
}

function closeProfile () {
    document.getElementById("grid").style.display =         "block";
    document.getElementById("profile").style.display =      "none";
}

function changeProduct (productId) {
    var title = new Array();
    var description = new Array();
    
    title[1] = "Chocolate Raspberry";
    title[2] = "Crème Caramel";
    title[3] = "Triple Berry Crème";
    title[4] = "Lemon Torte";
    
    description[1] = "Dig into a delicious, dual-layered snack you can feel good about. Yoplait Delights Chocolate Raspberry Parfait contains a luscious layer of chocolate yogurt, with creamy raspberry yogurt on top. Sure to please your craving, you won't believe it's <strong>100 calories!</strong>"
    description[2] = "Who says 100 calories can’t be rich and delicious? Yoplait Delights Crème Caramel Parfait gives you two luscious layers of yogurt that you can feel good about. With rich caramel yogurt on the bottom, and creamy vanilla yogurt on top, the perfect pick-me-up is <strong>100-calories.</strong>"
    description[3] = "Triple the berry. Triple the delight! A delicious blend of rich strawberry, blueberry, and raspberry yogurt is topped with smooth vanilla yogurt to make the perfect parfait. It's hard to believe this berry bliss is <strong>100 calories!</strong>"
    description[4] = "A little tangy. A little sweet. Yoplait Delights Lemon Torte Parfait has what you're craving. With a scrumptious bottom layer of lemon yogurt, and a creamy top layer of vanilla yogurt, this little cup packs some serious zest—all for <strong>100 calories!</strong>"
    
    document.getElementById("product-click-" + productId).src = "images/product-" + productId + "-off.jpg";
    document.getElementById("product-pic").src = "images/product-" + productId + ".jpg";
    document.getElementById("couponId").src = "images/coupon-" + productId + ".jpg";
    document.getElementById("product-title").innerHTML = title[productId];
    document.getElementById("product-description").innerHTML = description[productId];
    
    document.getElementById("complete-nut").onclick = function() {tb_show('','TB_inline?height=600&width=406&inlineId=nutriInfo'+productId+'&modal=false','');}
    
    //display correct selection
    for (var x=1;x < 5; x++){
        if (productId != x){
            document.getElementById("product-click-" + x).src = "images/product-" + x + "-on.jpg";
         }
    }

}

function profileScroll() {
    
    var profileId = document.getElementById("nextGroup").value;
    if (profileId == 4) {
        profileId = 1; } 
    else { 
        profileId = parseInt(profileId) + 1; 
    } 
    
    profile(profileId);
    
}





//trim
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}



function getParams (variable)
{
        var query = window.location.search.substring(1);
        var vars = query.split("&");
        for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if (pair[0] == variable) {
            return pair[1];
            }
        } 
      return "x";
}



// create rotating images, display/hide functionality because DOM src can't be manipulated while png fix is active on image

function choc_rasp(){ displayRotation(1); }
function caramel (){ displayRotation(2); }
function lemon (){ displayRotation(3); }
function triple(){ displayRotation(4); }
function displayRotation (cupId) {
    for (var x=1;x < 5; x++){
        if (cupId != x){
            document.getElementById("rotate-package" + x).style.display = "none";
        }
    }
    document.getElementById("rotate-package" + cupId).style.display = "block";
    
}



function getFileName (url) {

var lastSlash = url.lastIndexOf("/");
var firstQuestionMark = url.indexOf("?");
if(firstQuestionMark == -1)
{
firstQuestionMark = url.length;
}

return fileName = url.substring(lastSlash + 1, firstQuestionMark);


}





function formValidate() {
               
    
        checkNull("RECIPIENT_EMAIL","Please enter email");
        checkNull("SENDER_EMAIL","Please enter email"); 
        checkNull("SENDER_NAME","Please enter name"); 
        validateEmail(document.getElementById("RECIPIENT_EMAIL").value,"Please enter valid email address","RECIPIENT_EMAIL") 
        validateEmail(document.getElementById("SENDER_EMAIL").value,"Please enter valid email address","SENDER_EMAIL")
        // return success if valid form
        var valid = 1;
        if (document.getElementById("RECIPIENT_EMAIL").style.color == "red") {valid=0}
        if (document.getElementById("SENDER_EMAIL").style.color == "red") {valid=0}
        if (document.getElementById("SENDER_NAME").style.color == "red") {valid=0}
        
        var emailFriendAddress = document.getElementById("RECIPIENT_EMAIL").value;
        var emailYourName = document.getElementById("SENDER_NAME").value;
        var emailYourAddress = document.getElementById("SENDER_EMAIL").value;
        if (valid) {
            send(emailYourName,emailYourAddress,emailFriendAddress,"Friends Let Friends Indulge!");
            return true;
        }
        else {
            return false
        }
       
 
    
}

function formValidate2() {
               
    
        checkNull("REMail","Please enter email");
        checkNull("SEMail","Please enter email"); 
        checkNull("SName","Please enter name"); 
        validateEmail(document.getElementById("REMail").value,"Please enter valid email address","REMail") 
        validateEmail(document.getElementById("SEMail").value,"Please enter valid email address","SEMail")
        // return success if valid form
        var valid = 1;
        if (document.getElementById("REMail").style.color == "red") {valid=0}
        if (document.getElementById("SEMail").style.color == "red") {valid=0}
        if (document.getElementById("SName").style.color == "red") {valid=0}
        
        var emailFriendAddress = document.getElementById("REMail").value;
        var emailYourName = document.getElementById("SName").value;
        var emailYourAddress = document.getElementById("SEMail").value;
        if (valid) {
            send(emailYourName,emailYourAddress,emailFriendAddress,"Friends Let Friends Indulge!");
            return true;
        }
        else {
            return false
        }
       
 
    
}


function formValidate3() {
               
    
        checkNull("uploadTitle","Please enter title");
        checkNull("uploadInfo","Please enter description"); 
       
        // return success if valid form
        var valid = 1;
        if (document.getElementById("uploadTitle").style.color == "red") {valid=0}
        if (document.getElementById("uploadInfo").style.color == "red") {valid=0}

        if (valid) {
            send(emailYourName,emailYourAddress,emailFriendAddress,"Friends Let Friends Indulge!");
            return true;
        }
        else {
            return false
        }
       
 
    
}

function formValidate4() {
               
    
        checkNull("Title","Please enter title");
        checkNull("Description","Please enter description"); 
       
        // return success if valid form
        var valid = 1;
        if (document.getElementById("Title").style.color == "red") {valid=0}
        if (document.getElementById("Description").style.color == "red") {valid=0}

        if (valid) {
            return true;
        }
        else {
            return false
        }
       
 
    
}





function SetCookie() {
if(arguments.length < 2) { return; }
var n = arguments[0];
var v = arguments[1];
var d = 0;
if(arguments.length > 2) { d = parseInt(arguments[2]); }
var exp = '';
if(d > 0) {
	var now = new Date();
	then = now.getTime() + (d * 24 * 60 * 60 * 1000);
	now.setTime(then);
	exp = '; expires=' + now.toGMTString();
	}
document.cookie = n + "=" + escape(String(v)) + '; path=/' + exp;
} // function SetCookie()

function ReadCookie(n) {
var cookiecontent = new String();
if(document.cookie.length > 0) {
	var cookiename = n+ '=';
	var cookiebegin = document.cookie.indexOf(cookiename);
	var cookieend = 0;
	if(cookiebegin > -1) {
		cookiebegin += cookiename.length;
		cookieend = document.cookie.indexOf(";",cookiebegin);
		if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
		cookiecontent = document.cookie.substring(cookiebegin,cookieend);
		}
	}
return unescape(cookiecontent);
} // function ReadCookie()




function sendMail(){
    //init
        document.getElementById("RECIPIENT_EMAIL").style.color == "black";
        document.getElementById("SENDER_EMAIL").style.color == "black";
        document.getElementById("SENDER_NAME").style.color == "black";
        document.getElementById("SENDER_EMAIL").value = "" ;
        document.getElementById("RECIPIENT_EMAIL").value = "" ;
        document.getElementById("SENDER_NAME").value = "" ;


	$("a.SendToFriend").click(function(){
		$("#errorBox").html("");									   
		$(".SendMailForm label").removeClass("Required");
		$("#txtYourEmail").val("");
		$("#txtFriendEmail").val("");
		$("#txtYourName").val("");
		
		tb_show('','TB_inline?height=500&width=360&inlineId=friendLetFriend&modal=false','');						   
	})
}



function formValidate() {
               
    
        checkNull("RECIPIENT_EMAIL","Please enter email");
        checkNull("SENDER_EMAIL","Please enter email"); 
        checkNull("SENDER_NAME","Please enter name"); 
        validateEmail(document.getElementById("RECIPIENT_EMAIL").value,"Please enter valid email address","RECIPIENT_EMAIL") 
        validateEmail(document.getElementById("SENDER_EMAIL").value,"Please enter valid email address","SENDER_EMAIL")
        // return success if valid form
        var valid = 1;
        if (document.getElementById("RECIPIENT_EMAIL").style.color == "red") {valid=0}
        if (document.getElementById("SENDER_EMAIL").style.color == "red") {valid=0}
        if (document.getElementById("SENDER_NAME").style.color == "red") {valid=0}
        
        var emailFriendAddress = document.getElementById("RECIPIENT_EMAIL").value;
        var emailYourName = document.getElementById("SENDER_NAME").value;
        var emailYourAddress = document.getElementById("SENDER_EMAIL").value;
        if (valid) {
            send(emailYourName,emailYourAddress,emailFriendAddress,"Friends Let Friends Indulge!");
            return true;
        }
        else {
            return false
        }
       
 
    
}







function checkNull(formField,errMessage) {
    if ((document.getElementById(formField).value).trim() == "") {
        document.getElementById(formField).value = errMessage;
        document.getElementById(formField).style.color = "red";
        document.getElementById(formField).onfocus = function() {
            if (document.getElementById(formField).style.color == "red"){
                document.getElementById(formField).value = "";
                document.getElementById(formField).style.color = "black";
            }
        }
    };
}




function validateEmail(elementValue,errMessage,formField){      
   var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
   if  (!(emailPattern.test(elementValue))) { 
        document.getElementById(formField).value = errMessage;
        document.getElementById(formField).style.color = "red";
        document.getElementById(formField).onfocus = function() {
            if (document.getElementById(formField).style.color == "red"){
                document.getElementById(formField).value = "";
                document.getElementById(formField).style.color = "black";
            }
        }
   }; 
 }






function send(emailYourName,emailYourAddress,emailFriendAddress,subject) {

    
    //send out emai, multiples if supplied
    var vSceneNumber = getParams("SceneNumber");
    var vEpisodeNumber = getParams("EpisodeNumber");
            
    var i=0;
    var tempemailFriendAddress = emailFriendAddress + ";";
    var singleEmail = tempemailFriendAddress.split(";");

    
    for(i = 0; i < singleEmail.length -1 ; i++)
    {
        if ((vSceneNumber != "x") && (vEpisodeNumber != "x")) { 
            parseEmailVideo (emailYourName,emailYourAddress,singleEmail[i],vSceneNumber,vEpisodeNumber)
        }
        else
        {
            parseEmail (emailYourName,emailYourAddress,singleEmail[i],subject)
        }
        
       
    }
    


}

function parseEmailVideo (emailYourName,emailYourAddress,singleEmail,vSceneNumber,vEpisodeNumber) {

    var xmlhttp;
    if (window.XMLHttpRequest)
      {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else if (window.ActiveXObject)
      {
      // code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    else
      {
      alert("Your browser does not support XMLHTTP!");
      }
    xmlhttp.onreadystatechange=function()
    {
    if(xmlhttp.readyState==4)
      {
        
     
      }
    }
                                
      xmlhttp.open("GET","scenes/TAF.aspx?SName=" + emailYourName + "&SEMail=" + emailYourAddress + "&REMail=" + singleEmail + "&SN=" + vSceneNumber + "&EN=" + vEpisodeNumber,true);
      xmlhttp.send(null);
   
    


}




function parseEmail (emailYourName,emailYourAddress,singleEmail,subject) {

    var xmlhttp;
    if (window.XMLHttpRequest)
      {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else if (window.ActiveXObject)
      {
      // code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    else
      {
      alert("Your browser does not support XMLHTTP!");
      }
    xmlhttp.onreadystatechange=function()
    {
    if(xmlhttp.readyState==4)
      {
        
     
      }
    }
    

      xmlhttp.open("GET","taf.aspx?SENDER_NAME=" + emailYourName + "&SENDER_EMAIL=" + emailYourAddress + "&RECIPIENT_EMAIL=" + singleEmail + "&SUBJECT=" + subject,true);
      xmlhttp.send(null);
   
    


}


//trim
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}



function shareVideo() {
        var axel = Math.random() + "";
        var num = axel * 1000000000000000000;
        var spotpix3 = new Image();
        spotpix3.src = "http://ad.doubleclick.net/activity;src=1869704;type=yopla867;cat=yopde396;ord=" + num;
        
    var vName = [];
    vName[1] = "“Riches or Richard?” <i>(Back from the Dead)</i>";
    vName[2] = "“Memory Loss or High-Risk Medical Technique?” <i>(Hero with Amnesia)</i>";
    vName[3] = "“Tina or Gina?” <i>(Evil Twin Wedding)</i>";
    
     var vSceneNumber = getParams("SceneNumber");
     var vEpisodeNumber = getParams("EpisodeNumber");
     if ((vSceneNumber != "x") && (vEpisodeNumber != "x")) { 
        if (vSceneNumber == 0) {vSceneNumber = 3} // hack for bad flash coding
        document.getElementById("videoName").innerHTML = vName[vSceneNumber];
     }
     tb_show('','TB_inline?height=500&width=360&inlineId=shareThisVideo&modal=false','');	
}


function getScript(choose,vSceneNumber) {
 if (choose === 1)  { 
    window.open("Script-" + vSceneNumber + ".pdf","testwindow");
    }
    else {
        if (choose === 2) {
            window.open("http://www.youtube.com/user/yoplaitdelights","testwindow");
        }
        else{
            window.open("AllScripts.pdf","testwindow");
        }
    }
}
















// TIMS JS ------------------------------------------------------------------------------------
    function setVote(videoID, Row){
      VoteAndUpdateElement('video' + videoID,videoID, Row);
    }
    
    function VoteAndUpdateElement(VideoName, VideoId, Row)
    {
        // Record Ajax Vote
        log("Begin VoteAndUpdateElement(" + VideoName + ", " + VideoId + ")");
        $.get("AjaxServer.aspx?task=vote&v=" + VideoName, function(data){
                     log("resposne = " + data);
                     //alert(data);// RESPONSE data
                     updateAllVoteCountsByRow(Row, VideoId);
        });    
    } 
    
    function updateAllVoteCounts() {      
       log('updateAllVoteCounts');
       var divs = document.getElementsByTagName('div');
        for (var i = 0; i < divs.length; i++){                      
         
              var divid = divs[i].id; 
              if(divid.indexOf("star") == 0) {                                     
                  // This div has the word 'star' in it
                  // SET ALL ELEMETS TO ANIMATION
                  videoid = right(divid,String(divid).length - 4);
                  document.getElementById(divid).innerHTML =  '<img src="images/ajaxLoader.gif">'; 
                  getVoteAndUpdateElement('video' + videoid,divid);
              }
        }
       
       
    }
    
    function updateAllVoteCountsByRow(row, videoid) {      
      // log('updateAllVoteCounts');
       var divs = document.getElementsByTagName('div');
        for (var i = 0; i < divs.length; i++){                      
         
              var divid = divs[i].id; 
              if(divid.indexOf("star-" + row) == 0) {                                     
                  // This div has the word 'star' in it
                  // SET ALL ELEMETS TO ANIMATION
                  videoid = right(divid,String(divid).length - 4);                  
                  videoid = videoid.replace("-" + row + "-", "");                 
                  document.getElementById(divid).innerHTML =  '<img src="images/ajaxLoader.gif">'; 
                  getVoteAndUpdateElement('video' + videoid,divid);                   
              }
        }
       
       
    }
    
    function starClick(videoID,start,end,row)
    {     
       document.getElementById("selectedVideo" + row).value = videoID;    
       checkSelection(videoID,start,end,row);
    }
    
    function doVote(row)
    {
      var videoID = document.getElementById("selectedVideo" + row).value;
      setVote(videoID, row);
      $('#submitButton' + row).hide()
      //document.getElementById("submitButton")
    }
    
    function getVoteAndUpdateElement(videoName, elementID)
    {
        $.get("AjaxServer.aspx?task=getcount&v=" + videoName, function(data){
                     log("resposne2 = " + data);
                     document.getElementById(elementID).innerHTML = '<span style="font-size:10px;color:white;font-weight:bold;font-family:verdana,arial">' + data + '<br />votes</span>';
                     
        });        
    }

    function log(str){
      //document.getElementById("debug").innerHTML += str + '\n\n';    
    }
    
    function right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
// TIMS JS END ------------------------------------------------------------------------------------

