function roll(theimg, imgname, ext, mode){
	switch(mode){
		case 1:{
			theimg.src = basePath + imgname + "_on." + ext;
		}
		break;
		case 0:{
			theimg.src = basePath +imgname + "_off." + ext;
		}
		break;
		default:{
			theimg.src = basePath +imgname + "_off." + ext;
		}
	}
}
function startup(){
    document.getElementById('lc_sub_1').style.display = 'none';
    document.getElementById('lc_sub_2').style.display = 'none';
}
function hide_combobox(boxid){
    var thebox = document.getElementById(boxid);
    thebox.style.visibility = 'hidden';
}
function show_combobox(boxid){
    var thebox = document.getElementById(boxid);
    thebox.style.visibility = 'visible';
}
function openleftmenu(listid, imageid){
   try
   { 
		var nummenus = 4; // hardcoded number of expandable menus.  ID's have to be sequential
		var theitems
		var theimage
		var imgsrc
		var arr_fileparts
		var imgname
	    
		//before we do anything, close all the other menus
		for(i=1;i<=nummenus;i++){
			if(i != listid){ //skip the one we've clicked on for now
				theitems = document.getElementById('lc_sub_' + i);
				if (!theitems)
					continue;
					
				theimage = document.getElementById('lc_bullet_' + i); // assuming the id for the image will be the same, currently is
				imgsrc = theimage.src;
				arr_fileparts = imgsrc.split('/');
				imgname = arr_fileparts[arr_fileparts.length - 1];
				if(imgname == 'leftcol_multi_bullet_dn.gif'){                
					theimage.src = basePath + 'images/leftcol_multi_bullet_rt.gif';
					//collapse menu
					theitems.style.display = 'none';
				}
			}
		}
	    
		// now work with the menu item we actually selected
		theitems = document.getElementById('lc_sub_' + listid);
		theimage = document.getElementById(imageid);
		imgsrc = theimage.src;
		arr_fileparts = imgsrc.split('/');
		imgname = arr_fileparts[arr_fileparts.length - 1];
		if(imgname == 'leftcol_multi_bullet_dn.gif'){
			theimage.src = basePath + 'images/leftcol_multi_bullet_rt.gif';
			//collapse menu
			theitems.style.display = 'none';
		}
		else{
			theimage.src = basePath + 'images/leftcol_multi_bullet_dn.gif';
			//expand menu
			theitems.style.display = 'block';
		}
	}
	catch(e) {}    
}

function changepointer(mode){
    if(mode == '1'){
         document.body.style.cursor = 'pointer';
    }
    else{
        document.body.style.cursor = 'default';
    }
}

function change_item_bg(thediv, mode, icon){
    if(mode == '1'){
        if(icon == '1'){
            thediv.style.background = 'url(images/' + thediv.id + '_on.jpg)';
        }
        else{
            thediv.style.background = '#141414';
        }
    }
    else{
        if(icon == '1'){
            thediv.style.background = 'url(images/' + thediv.id + '_off.jpg)';
        }
        else{
            thediv.style.background = '#ffffff';
        }
    }
    
}
/** fancy combo box script START **/
function oc_combo(combo_box){
    var thelayer = document.getElementById(combo_box);
    if(thelayer.style.visibility == ''){
        thelayer.style.visibility = 'hidden';
    }
    if(thelayer.style.visibility == 'hidden'){
        thelayer.style.visibility = 'visible';
    }
    else{
        thelayer.style.visibility = 'hidden';
    }
}

function set_cbo_selection(maincboid, itemid, valueboxid, funcname){
    var mainbox = document.getElementById(maincboid);
    var item = document.getElementById(itemid);
    if(valueboxid){
        var valuebox = document.getElementById(valueboxid);
        valuebox.value = item.innerHTML;
    }
    mainbox.innerHTML = item.innerHTML;
    mainbox.style.background = 'url(images/' + itemid + '_top.jpg)';
    
    if(funcname){
        eval(funcname + ';');
    }
}

function set_cbo_selection2(maincboid, bgimg, item, valueboxid, funcname){
    var mainbox = document.getElementById(maincboid);
    
    if(valueboxid){
        var valuebox = document.getElementById(valueboxid);
        valuebox.value = item.innerHTML;
    }
    mainbox.innerHTML = item.innerHTML;
    
    if(bgimg){
        mainbox.style.background = 'url(images/' + bgimg + '_top.jpg)';
    }
	else{
		mainbox.style.background = 'none';
	}
    
    if(funcname){
        eval(funcname + ';');
    }
}

function fancy_cbo_object(hiddenTextId)
{
    this.SelectedValue = function () {
		return document.getElementById(hiddenTextId).value;
	}
}

/** fancy combo box script END **/

var IE = document.all?true:false

// hack from Prototype.removeClassName
// remove multiple css classes from element
function removeClassNames (element, classNames) {
    if (!(element = $(element))) return;
    
    $w(classNames).each(function(c) {
        element.className = element.className.replace(
            new RegExp("(^|\\s+)" + c + "(\\s+|$)"), ' ').strip();
    });
    
    return element;
}
  
function tooltip_flyout(flyoutid, contentPane, mode){
    var flyoutPane = $(flyoutid);
    
	if(mode == 1){	    
	    removeClassNames (flyoutPane, "top bottom left right");
	    
		flyoutPane._on = true;
		
		setTimeout(function() {
		    //alert("*** tooltip_flyout: flyoutPane._on = " + flyoutPane._on);
		    //console.debug("*** tooltip_flyout (mode=1): flyoutPane._on = " + flyoutPane._on);
			if (!flyoutPane._on)
				return;
			
			var height_viewport = document.viewport.getHeight();
            var width_viewport = document.viewport.getWidth();
            
            var top_offset = BrowserDetect.browser == "MSIE" && BrowserDetect.version <= 6 ? 0 : 30;
			var left_offset = BrowserDetect.browser == "MSIE" /*&& BrowserDetect.version <= 6*/ ? 40 : 0;
            
            var left_base = Element.viewportOffset($("container")).left;
            
            var height_contentpane = Element.getHeight(contentPane);
            var width_contentpane = Element.getWidth(contentPane);
                        
            var left_contentpane_viewport_offset = Element.viewportOffset(contentPane).left;            
            var top_contentpane_viewport_offset = Element.viewportOffset(contentPane).top;
            //var contentpane_cumulative_offset = contentPane.cumulativeScrollOffset();
                        
            var height_flyoutpane = flyoutPane.getHeight();
            var width_flyoutpane = flyoutPane.getWidth();
            
			// top coordinate
			var top_coord = top_contentpane_viewport_offset - top_offset;

            /*
            ** if the content pane (target) is at or above (i.e. off) the viewport, display the flyout
            ** at the bottom of the target
            */
            if (top_coord <= 0)
            {
                top_coord = top_contentpane_viewport_offset + height_contentpane - 10;
                flyoutPane.addClassName("top");
            }           
            /*
            ** if the content pane (target) is at or below the viewport, display the flyout
            ** above the top of the target.             
            */
            else if (height_flyoutpane + top_coord > height_viewport)
            {
				top_coord = height_viewport - height_flyoutpane - (height_viewport - top_contentpane_viewport_offset) - 10;
				flyoutPane.addClassName("bottom");
            }
            
            // left coordinate
            // determines whether the content pane is to the left or right of the viewport
            var display_left = (left_contentpane_viewport_offset << 1) > width_viewport;
            var left_coord = left_contentpane_viewport_offset /* absolute left */ - left_base;

            if (display_left) {
                left_coord -= 323; // (300 /* flyout square */ + 20 /* flyout pointer */ +3 /* offset */);
                flyoutPane.addClassName("left");
            }
            else {                
                left_coord += width_contentpane + left_offset + 3;
                flyoutPane.addClassName("right");
            }
            /*
			if (width_flyoutpane + left_coord > width_viewport)
				left_coord = width_viewport - width_flyoutpane;
			*/
			
			// set the coordinates				
			flyoutPane.style.top = (top_coord + contentPane.cumulativeScrollOffset().top) + 'px';
			flyoutPane.style.left = (left_coord + contentPane.cumulativeScrollOffset().left) + 'px';
			flyoutPane.style.display = '';
			//jQuery("div:flyout").fadeIn("slow");
		}, 200);
    }
    else{
        flyoutPane._on = false;        
        var t = setTimeout(function(){
            //console.debug("*** tooltip_flyout (mode=0): flyoutPane._on = " + flyoutPane._on);
            if (flyoutPane._on) return;
            flyoutPane.style.display = 'none';
            //jQuery("div:flyout").fadeOut("slow");
        }, 200);
    }    
}

function movieinfo_flyout(infolayerid, thelink, mode){
	var infolayer = $(infolayerid);
	var infolayer_arrow = $(infolayerid + "_arrow");
	if(mode == '1'){
		infolayer._on = true;
		
		setTimeout(function() {
			if (!infolayer._on)
				return;
				
//			var offset = BrowserDetect.browser == "MSIE" && BrowserDetect.version <= 6 ? 0 : 30;
//			var top_coord = Element.viewportOffset(thelink).top - offset;

//			if (infolayer.getHeight() + top_coord > document.viewport.getHeight())
//				top_coord = document.viewport.getHeight() - infolayer.getHeight();

			infolayer.style.top = Element.cumulativeOffset(thelink).top - infolayer.getHeight() + 30 + 'px';
			infolayer_arrow.style.top = Element.cumulativeOffset(thelink).top - Element.cumulativeOffset(infolayer).top - infolayer_arrow.getHeight()/2 - 3 + 'px';
			infolayer_arrow.style.left = infolayer.getWidth() - 17 + 'px';
			infolayer.style.visibility = 'visible';
		}, 200);
    }
    else{
		infolayer._on = false; 
        infolayer.style.visibility = 'hidden';
    }
}

function cardinfo_flyout(infolayerid, thelink, mode){
	var infolayer = $(infolayerid);

	if(mode == '1'){
		infolayer._on = true;
		
		setTimeout(function() {
			if (!infolayer._on)
				return;

			var offset = BrowserDetect.browser == "MSIE" && BrowserDetect.version <= 6 ? 0 : 0;
			var top_coord = Element.viewportOffset(thelink).top - 133;

			if (infolayer.getHeight() + top_coord > document.viewport.getHeight())
				top_coord = document.viewport.getHeight() - infolayer.getHeight();

			infolayer.style.visibility = 'visible';
			infolayer.style.top = (top_coord + thelink.cumulativeScrollOffset().top) + 'px';        
			infolayer.style.left = (thelink.positionedOffset().left + thelink.getWidth() - offset)  + 'px';
		}, 200);
	}
	else{
		infolayer._on = false; 
		infolayer.style.visibility = 'hidden';
	}
}

function flyout_visible(thelayer, mode)
{    
    if (mode == 1)
    {
        thelayer._on = true;
        setTimeout(function(){
            if (!thelayer._on) return;
            //console.debug("*** flyout_visible (mode=1): thelayer._on = " + thelayer._on);
            thelayer.style.display = '';    
            }, 200);
    }
    else
    {
        thelayer._on = true;
        setTimeout(function(){            
            //console.debug("*** flyout_visible (mode=0): thelayer._on = " + thelayer._on);
            thelayer.style.display = 'none';    
            }, 200);            
    } 
}

function movieinfo_visible(thelayer, mode){
    if(mode == '1'){
        thelayer.style.visibility = 'visible';
    }
    else{
        thelayer.style.visibility = 'hidden';
    }
}

function subdvdformat(theform){
    var optionstate = -1;
    for (i=theform.optDVDType.length-1; i > -1; i--){
        if(theform.optDVDType[i].checked){
            optionstate = i;
            i = -1;
        }
    }
    
    if(optionstate == -1){
        alert("Please select a DVD format.");
        return false;
    }
    
    theform.submit();
}

function fancycheck(theimageid, hiddenfieldid){
    theimage = document.getElementById(theimageid);
    theControl = document.getElementById(hiddenfieldid);
    if(theControl.value == '0'){
        theControl.value = '1';
        theimage.src = basePath+'images/checkbox1_on.jpg';
    }
    else{
        theControl.value = '0';
        theimage.src = basePath+'images/checkbox1_off.jpg';
    }
    
}

function selectepisode(theimageid, episodeid, type){
    theimage = document.getElementById(theimageid + "_" + type);
    theControl = document.getElementById('chkEpisode' + episodeid + "_" + type);
    if(theControl != null)
    {
        if(theControl.value == '0'){
            theControl.value = '1';
            theimage.src = 'images/checkbox1_on.jpg';
        }
        else{
            theControl.value = '0';
            theimage.src = 'images/checkbox1_off.jpg';
        }
    }
}

function subepisodes(){
    var subit = false;
	var shoppingCartUrl = $F('shoppingCartUrl') + '?multiple=';
	var shoppingCartData = new Array();
	
   if ($('maincontent_withplayer_episodelist').style.display == '')
   {
       $('maincontent_withplayer_episodelist').select('div.episode_list div input.episode_checkbox_value').each(
		    function(i) {
			    if (i.value == '1')
			    {
				    subit = true;
				    shoppingCartData.push(i.up().select('input.shopping_cart_data').first().value);
			    }
		    });
    }
    else if ($('maincontent_withplayer_hd_episodelist').style.display == '')
    {
        $('maincontent_withplayer_hd_episodelist').select('div.episode_list div input.episode_checkbox_value').each(
		    function(i) {
			    if (i.value == '1')
			    {
				    subit = true;
				    shoppingCartData.push(i.up().select('input.shopping_cart_data').first().value);
			    }
		    });
    }
    
    if(!subit){
        alert("Please select an episode to download to own");
        return false;
    }
    else{
		try { 
			s_helper.TrackAddtoCart(null, shoppingCartData);
		} catch (err) { }
		 
		document.location.href = shoppingCartUrl + shoppingCartData.join('%20'); 
        return false;
    }
}

var ratingimgname = 'rating';
var totalratings = 5;

function ratingon(theimage, ratingnumber){
    //reset ratings
    for(i=1;i<=totalratings;i++){
        ratingimg = document.getElementById(ratingimgname + i);
        ratingimg.src = 'images/rating_off.gif';
    }
    
    //set new rating
    for(i=1;i<=ratingnumber;i++){
        ratingimg = document.getElementById(ratingimgname + i);
        ratingimg.src = 'images/rating_on.gif';
    }
}

function ratingoff(){
    var ratingbox = document.getElementById("txtCurrentRating");
    var ratingnumber = ratingbox.value;
    
    //reset ratings
    for(i=1;i<=totalratings;i++){
        ratingimg = document.getElementById(ratingimgname + i);
        ratingimg.src = 'images/rating_off.gif';
    }
    
    //set new rating
    for(i=1;i<=ratingnumber;i++){
        ratingimg = document.getElementById(ratingimgname + i);
        ratingimg.src = 'images/rating_on.gif';
    }
}

function setrating(rating){
    var ratingbox = document.getElementById("txtCurrentRating");
    ratingbox.value = rating;
    
    for(i=1;i<=rating;i++){
        ratingimg = document.getElementById(ratingimgname + i);
        ratingimg.src = 'images/rating_on.gif';
    }
}

function showepisodes(seriesid){
    var theepisodes = document.getElementById(seriesid);
    var arrowimg = document.getElementById('episodes_arrow_' + seriesid);
    if((theepisodes.style.display == 'none') || (theepisodes.style.display == '')){
        theepisodes.style.display = 'block';
        arrowimg.src = 'images/search_episodes_arrowdn.gif';
    }
    else{
        theepisodes.style.display = 'none';
        arrowimg.src = 'images/search_episodes_arrowrt.gif';
    }
}

function showship(imgid, divid){
    var theimg = document.getElementById(imgid);
    var thelayer = document.getElementById(divid);
    if(thelayer){
        if((thelayer.style.display == 'none') || (thelayer.style.display == '')){
            if(theimg)
                theimg.src = basePath+'images/search_episodes_arrowdn.gif';
            thelayer.style.display = 'block';
        }
        else{
            if(theimg)
                theimg.src = basePath+'images/search_episodes_arrowrt.gif';
            thelayer.style.display = 'none';
        }
        
    }
}

function delay_hide_combobox(divid){
    setTimeout("hide_combobox('" + divid + "')", 1000);
}

function blank(){
    return;
}
