function switchVisibility(show, showValidator, hide, hideValidator, validationSummary, hiddenVal,currentSel) {
    document.getElementById(show).style.display = '';
    document.getElementById(hide).style.display = 'none';
    document.getElementById(currentSel).value = hiddenVal;
    document.getElementById(validationSummary).innerHTML = '';
}
function switchValidation(zipValidator,phoneValidator,currentSel) {
    var current = document.getElementById(currentSel).value;
    if (current == 'phone') {        
        ValidatorEnable(document.getElementById(phoneValidator), true);
        ValidatorEnable(document.getElementById(zipValidator), false);
    }
    else {        
        ValidatorEnable(document.getElementById(zipValidator), true);
        ValidatorEnable(document.getElementById(phoneValidator), false);
    }
}
function CheckZipcode(sender, args) {
    alert(args.Value);
    var zipcode = args.Value;
    if (zipcode == 'Enter Zipcode') {
        args.IsValid = false;
        return;
    }

    args.IsValid = true;
}
/*==============================================
Emails a link for a video via the clients
default email application.
===============================================*/
function emailLink() {
    var adUrl = escape(popupEmailUrl + "?id=" + document.getElementById('popupAdNo').innerHTML + "&guid=" + document.getElementById('popupGuid').value);
    var emailLink = "mailto:Enter_Email_Here?subject=" + popupSubject + "&body=" + popupBody.replace('[VIDEO_LINK]', adUrl) + "";

    var emailWindow = window.open(emailLink, "VideoEmail", "menubar=0, location=0, top=-10, left=-10, width=0, height=0");

    if (emailWindow != null) {
        emailWindow.close();
    }
}

/*==============================================
Prints the storyboard for the requested PDF.
===============================================*/
function printPdf() {
    var pdfUrl = document.getElementById('popupPdf').innerHTML;

    if (pdfUrl != '') {
        var pdfWindow = window.open(pdfUrl, "VideoPdf");
    }
    else {
        noPdf();
    }

}

function noPdf() {
    Show('noPdfPopup');
}

function Show(oObject) {
    if (typeof (oObject) == 'string') {
        oObject = document.getElementById(oObject);
    }
    oObject.style.display = 'block';
}
function Hide(oObject) {
    if (typeof (oObject) == 'string') {
        oObject = document.getElementById(oObject);
    }
    if (oObject != null)
        oObject.style.display = 'none';
}
function StopPlay(sMovieId) {
    if (typeof (document.getElementById(sMovieId).stopPlay) != 'undefined') {
        document.getElementById(sMovieId).stopPlay();
    }
}

function StopPlaying(sMovieId) {
    try {
        if (typeof (document.getElementById(sMovieId).stopPlaying) != 'undefined') {
            document.getElementById(sMovieId).stopPlaying();
        }
        else {
            document.getElementById(sMovieId).parentNode.innerHTML = '';
        }
    }
    catch (err)
    { }
}

function OpenCarrousselMovie() {
    Show('carroussellpopup');
}

function playTutorialExample(fileNameWithoutExtension, title) {
    var fvStreamURL = 'http://dl.spotzer.com/PromotionalVideos/flv/';
    var fvMovieURL = fileNameWithoutExtension;

    document.getElementById('popupTitle').innerHTML = title;

    if (title.length > 40) {
        document.getElementById('popupTitle').innerHTML = title.substring(0, 40) + "...";
    }
    document.getElementById('popupTitle').title = title;

    // create the SWFObject
    //	var so = new SWFObject('http://dl.spotzer.com/PromotionalVideos/swf/HearstOnlinePlayer.swf', 'flashreadytoair', 382, 259, '8.0.0', '#FFFFFF');
    //	so.addParam('scale', 'noScale');
    //	so.addParam('wmode', 'Transparent');
    //	so.addParam("allowScriptAccess", "always");
    //	so.addVariable('fvConfigXmlUrl', 'config.xml');
    //	so.addVariable('fvStreamURL', fvStreamURL);
    //	so.addVariable('fvMovieURL', fvMovieURL);
    //	so.addVariable('fvPlayOnLoad', true);
    //	so.write('flashreadytoair');

    var flashVars = "fvConfigXmlUrl=http://dl.spotzer.com/Resources/xml/config.xml&fvMovieURL=" + fvMovieURL + "&fvStreamURL=" + fvStreamURL + "&fvPlayOnLoad=true";

    /*
    Notes:
    fvStreamURL : The main RTMP URL of the streaming server. 
    fvMovieURL: the name of the movie on the streaming server.
    */
    document.getElementById('flashreadytoair').innerHTML = AC_FL_RunContentPopup(
           'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0',
           'width', '382',
           'height', '259',
           'src', 'http://dl.spotzer.com/PromotionalVideos/swf/HearstOnlinePlayer',
           'quality', 'high',
           'pluginspage', 'http://www.adobe.com/go/getflashplayer',
           'align', 'middle',
           'play', 'true',
           'loop', 'false',
           'scale', 'noScale',
           'wmode', 'Transparent',
           'devicefont', 'false',
           'FlashVars', flashVars,
           'id', 'flvplayer',
           'bgcolor', '#FFFFFF',
           'name', 'flvplayer',
           'menu', 'false',
           'allowScriptAccess', 'always',
           'allowFullScreen', 'false',
           'movie', 'http://dl.spotzer.com/PromotionalVideos/swf/HearstOnlinePlayer',
           'salign', '',
           'fvPlayOnLoad', 'true',
           'fvMovieUrl', fvMovieURL,
           'fvStreamUrl', fvStreamURL,
           'id', 'readytoair'
           );

    // Show and start the video
    OpenCarrousselMovie();
}


function setValue(videoID) {

    //alert(video_itemlist);
    // get current object by ID
    var selectedAd = '';
    for (var i = 0; i < video_itemlist.length; i++) {
        if (video_itemlist[i].id == videoID) {
            selectedAd = video_itemlist[i];
            break;
        }
    }

    if (selectedAd != null && selectedAd != '') {
        // set the properties
        document.getElementById('popupAdNo').innerHTML = selectedAd.id;
        document.getElementById('popupGuid').value = selectedAd.guid;

        if (selectedAd.bc != null) {
            // Make certain the bc text doesn't exceed the maximum widtt we set, and then add a 
            //  tooltip so the user can see the entire value.
            document.getElementById('popupBc').innerHTML = selectedAd.bc;

            if (selectedAd.bc.length > 35) {
                document.getElementById('popupBc').innerHTML = selectedAd.bc.substring(0, 35) + "...";
                document.getElementById('popupBc').title = selectedAd.bc;
            }
        }

        if (selectedAd.title.length > 0)
            document.getElementById('popupTitle').innerHTML = '/ ' + selectedAd.title;
        else
            document.getElementById('popupTitle').innerHTML = '';

        if (selectedAd.title.length > 40) {
            document.getElementById('popupTitle').innerHTML = selectedAd.title.substring(0, 40) + "...";
            document.getElementById('popupTitle').title = selectedAd.title;
        }

        if (selectedAd.bn != null && document.getElementById('popupBusinessName') != null)
            document.getElementById('popupBusinessName').innerHTML = selectedAd.bn;

        document.getElementById('popupBusinessCategory').innerHTML = selectedAd.bc;
        document.getElementById('popupPdf').innerHTML = selectedAd.pdf;

        // Ensure we hide/show items based on the Sample Setting
        document.getElementById('DivSampleDetails').style.display = "none";
        document.getElementById('DivPersonalization').style.display = "none";
        if (typeof (selectedAd.isSample) == "boolean") {
            if (selectedAd.isSample) {
                document.getElementById('popupSampleTitle').style.display = "inline";
                document.getElementById('DivSampleDetails').style.display = "block";

                document.getElementById('popupStandardTitle').style.display = "none";
                document.getElementById('DivPersonalization').style.display = "none";
                document.getElementById('popupPrintButton').style.display = "none";
            }
            else {
                document.getElementById('popupSampleTitle').style.display = "none";
                document.getElementById('DivSampleDetails').style.display = "none";

                document.getElementById('popupStandardTitle').style.display = "inline";
                document.getElementById('DivPersonalization').style.display = "block";
                document.getElementById('popupPrintButton').style.display = "inline";
            }
        }

        // Hide buttons if directed to do so
        if (typeof (selectedAd.hideButtons) == "boolean") {
            if (selectedAd.hideButtons) { document.getElementById('DivPopupButtons').style.display = "none"; }
        }

        // create the SWFObject
        //	    var so = new SWFObject('http://dl.spotzer.com/PromotionalVideos/swf/HearstOnlinePlayer.swf', 'readytoair', 382, 259, '8.0.0', '#FFFFFF');
        //	    so.addParam('scale', 'noScale');
        //	    so.addParam('wmode', 'Transparent');
        //	    so.addParam("allowScriptAccess", "always");
        //	    so.addVariable('fvConfigXmlUrl', 'config.xml');
        //	    so.addVariable('fvStreamURL', selectedAd.fvStreamURL);
        //	    so.addVariable('fvMovieURL', selectedAd.fvMovieURL);
        //	    so.addVariable('fvPlayOnLoad', true);
        //	    so.write('flashreadytoair');

        var flashVars = "fvConfigXmlUrl=http://dl.spotzer.com/Resources/xml/config.xml&fvMovieURL=" + selectedAd.fvMovieURL + "&fvStreamURL=" + selectedAd.fvStreamURL + "&fvPlayOnLoad=true";


        // embed the flash movie
        document.getElementById('flashreadytoair').innerHTML = AC_FL_RunContentPopup(
           'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,45,0',
           'width', '382',
           'height', '259',
           'src', 'http://dl.spotzer.com/PromotionalVideos/swf/HearstOnlinePlayer',
           'quality', 'high',
           'pluginspage', 'http://www.adobe.com/go/getflashplayer',
           'align', 'middle',
           'play', 'true',
           'loop', 'false',
           'scale', 'noScale',
           'wmode', 'Transparent',
           'devicefont', 'false',
           'FlashVars', flashVars,
           'id', 'flvplayer',
           'bgcolor', '#FFFFFF',
           'name', 'flvplayer',
           'menu', 'false',
           'allowScriptAccess', 'always',
           'allowFullScreen', 'false',
           'movie', 'http://dl.spotzer.com/PromotionalVideos/swf/HearstOnlinePlayer',
           'salign', '',
           'fvPlayOnLoad', 'true',
           'fvMovieUrl', selectedAd.fvMovieUrl,
           'fvStreamUrl', selectedAd.fvStreamUrl,
           'id', 'readytoair'
           );

        /*
        Notes:
        fvStreamURL : The main RTMP URL of the streaming server. 
        fvMovieURL: the name of the movie on the streaming server.
        */

        // Show and start the video
        OpenCarrousselMovie();
    }
    else {
        document.getElementById('popupContentDiv').style.display = 'none';
    }


};
