cxri_main_url = window.cxri_main_url || '';
var streaming;
var cxr_name;
var pos_statemt;

function ajax_load(mydiv, myurl, param) {
  // If mydiv is not in the current doc, this request is not used, so return.
  // This has a major effect on REX performance in slow browsers. -VV
  if ($('#'+mydiv).length == 0) {
    return;
  }
  if (cxri_main_url == 'http://'+document.domain) {
    $(document).ready(function() {
      $('#'+mydiv).load(myurl);
    });
  }
  else {
    $(document).ready(function () {
      var script_object = document.createElement('SCRIPT');
      script_object.src = cxri_main_url+'/_svc/ajax.html?loc='+mydiv+'&url='+myurl+'&param='+param;
      script_object.type = 'text/javascript';
      $("head").append(script_object);
    });
  }
}

var req, music_or_nt;
function nowplaying() {
    var sleeptime;
    //var DEF_SLEEP = 30000; // default sleep time of 30 seconds
    var DEF_SLEEP = 15000; // default sleep time of 15 seconds

    // if there is no NowPlaying spot in this page, abondon. -VV 
    if ($('#artistSongTitle').length == 0) {
      return;
    }

    if (streaming < 2) {
        // no LSP data available at server.
        $('#artistSongTitle').html("<b>"+cxr_name+"</b><br/>"+pos_statemt);
        return;
    }

    if (cxri_main_url != 'http://'+document.domain || music_or_nt != 'M') {
        // on external sites, be less aggressive. Cross-domain XHR causes
        // problems. Update once, no ratings, then return before setting the
        // timer. Non-music stations won't have live updates, so they execute
        // this path too.
        ajax_load('playerDisplay','/inc/lsp/playerDisplay.html', 1);
        return;
    } else {
        // on the main site, grab the content, update the ratings widgets
        // for the current user (in case they are logged in), and set the timer.
        var failures = 1;
        $.timer(100, function(timer) {
            $("#playerDisplay")
                .load( cxri_main_url+'/inc/lsp/playerDisplay.html'
                     , function (responseText, textStatus, XMLHttpRequest) { 
                        update_ratings(1); 
                        var curtime, endtime, mystuff;
                        mystuff = $('#artistSongTitle',this);
                        curtime = parseInt( mystuff.attr('data-now'), 10);
                        endtime = ( parseInt(mystuff.attr('data-playtime'), 10)
                                  + parseInt(mystuff.attr('data-duration'), 10)
                                  );
                        sleeptime = (endtime - curtime) * 1000; //milliseconds
                        //console.log("cur:"+curtime+"; end:"+endtime+"; sleep:"+sleeptime);
                        if (sleeptime < -300000) {
                            //no updates for 5 minutes? Maybe a server problem. Back off.
                            sleeptime = sleeptime * -0.5;
                            //console.log("LSP not update for long time, backing off for:"+sleeptime);
                        } else if (sleeptime < DEF_SLEEP) {
                            sleeptime = DEF_SLEEP;
                            //console.log("Ended, sleeping for default: "+sleeptime);
                        }
                        timer.reset(sleeptime);
                    }
                );//END LOAD
            if (failures > 4) {
                timer.stop();
            }
            timer.reset(DEF_SLEEP * failures++);
        });
    }
}//END nowplaying()

function showsubNavsIE() {
  $("#nav-one > li").hover(function() {
    $(this).addClass("sfHover");
    $(this).find("ul > li").fadeIn("slow");
  },
  function() {
    $(this).removeClass("sfHover");
    $(this).find("ul > li").fadeOut();
  });
}

var player_speed = 'normal';

var user_urlRatingArray = new Array();
var user_urlRatings;
function update_ratings(get_member_ratings) {
  var uRArray = new Array();
  $(".rating").each(function() {
    var $this = $(this);

    combinedRating = $this.find("input.ratingBox").attr("value");
    urlRating = $this.find("input.ratingBox").attr("name");
    if (get_member_ratings == 1) {
      uRArray.push(urlRating);
    }

    if (combinedRating == undefined) {
      combinedRating = '0:0';
    }

    var ratingArray = combinedRating.split(':');
    var avgRating = ratingArray[0];
    var usrRating = ratingArray[1];

    // pull usrRatings from user_urlRatings;
    if ((usrRating == 0) && (user_urlRatings != undefined)) {
      usrRating = user_urlRatings[urlRating];
    }

    if(avgRating != undefined && usrRating != undefined) {
      $this.rating(urlRating, {maxvalue:7,increment:1, curvalue:avgRating, usrvalue: usrRating, ratingid: urlRating });
    }
    else {
      $this.rating(urlRating, {maxvalue:7,increment:1, curvalue:3, usrvalue:0, ratingid: urlRating});
    }
  });
  user_urlRatingArray = uRArray;

  if (get_member_ratings == 1) {
    var site_auth = $.cookie('site_auth');
    if (site_auth != undefined) {
      // GET user_urlRatingArray to server and get JSON hash of track_ids => userRatings.
      $.getJSON(cxri_main_url+'/_svc/usrRatings.txt?tracks='+user_urlRatingArray.join(), function(data) {
        user_urlRatings = data;
        update_ratings(0);
      });
    }
  }
}

function replacements(jsonData){
    var id,replacement;
    for (var i in jsonData.replaceids) {
        replacement = null;
        id = jsonData.replaceids[i];
        if (jsonData[id]) { replacement = $(jsonData[id]); }
        if (replacement) {
            $('#'+id).html(replacement); 
            //console.log("Got replacement for "+id); console.log(replacement.html());
        }
    }
    if (jsonData['ratings']) { user_urlRatings = jsonData['ratings']; update_ratings(0); }
    if (jsonData['nav']) {
        showsubNavsIE(); 
    }
    /* HACK: set default nav hilite for CXR */
    if (cxri_main_url.match(/coxradio\./) ) {
        var here,there;
        here = $('#nav #currentPage');
        if ( here.size() == 0 ) {
            $('#nav .navlist li').eq(1).attr('id','currentPage');
        }
    }
}

$(document).ready(function(){
		/* Player for On Demand player links*/
		$("#SiteContent a[href*='/Player/']").click(function(){
			var url = $(this).attr('href');															
			window.open(url, 'playerpopup','width=800,height=440,resizable=1,toolbar=0,status=0,location=0,scrollbars=0');		
			return false;
		});
		
		/* Player for live stream links*/
		$("#pageWrapper a[href*='/player.streamtheworld.com/']").click(function(){
			var url = $(this).attr('href');															
			window.open(url, 'playerlivepopup','width=800,height=440,resizable=1,toolbar=0,status=0,location=0,scrollbars=0');		
			return false;
		});
		
		$("#pageWrapper a[href*='/streaming.']").click(function(){
			var url = $(this).attr('href');															
			window.open(url, 'playerlivepopup','width=800,height=440,resizable=1,toolbar=0,status=0,location=0,scrollbars=0');		
			return false;
		});
		
		$("#pageWrapper a[href*='/player.streamtheworld.com/']").livequery('click', function(event) { 
			var url = $(this).attr('href');															
			window.open(url, 'playerlivepopup','width=800,height=440,resizable=1,toolbar=0,status=0,location=0,scrollbars=0');		
			return false;
		});
		
		$("#pageWrapper a[href*='/streaming.']").livequery('click', function(event) { 
			var url = $(this).attr('href');															
			window.open(url, 'playerlivepopup','width=800,height=440,resizable=1,toolbar=0,status=0,location=0,scrollbars=0');		
			return false;
		});
						   
});




$(document).ready(function(){
    // Get list of tracks in page that need ratings
    var trackList = [];
    $(".rating").each(function(){trackList.push($(this).find("input.ratingBox").attr("name"))});
    // Replace most AJAX items in single request
    $.getJSON(cxri_main_url
                +'/_svc/replacement.json?callback=&this_page='
                +document.location
                +'&tracks='+trackList.join()
             , replacements
             );

    nowplaying();

	var playeropen = $.cookie('expanded'); /* open player if it was already opened */
	if(playeropen == 1) {
          update_ratings(0);
          $("#playerFull").show(player_speed);

          $("#sublinks").show();
          $("#expandable > a").toggle();
	}

	var textsize = $.cookie('textsize');
	$("#centerColumn").css("font-size", textsize);
	if(textsize == "1.2em") { $("#font_med").addClass("currentFont");}
	else if (textsize == "1.4em") { $("#font_lg").addClass("currentFont");}
	else { $("#font_sm").addClass("currentFont");}


	/* Set up events on Carousel module */
	$("div.carouselModuleNav > ul > li").click(function() {
		var theType = 'carousel';
		var obj = $(this);
		return enableTabs(theType, obj);
												
	});
	
	/* Set up events on Rotating module */
	$("div.rotatingModuleNav > ul > li").click(function() {
		var theType = 'rotating';
		var obj = $(this);
		return enableTabs(theType, obj);
												
	});	
	
	
	
	/* Enables navigation on module that can support them (rotating, carousel) */
	enableTabs = function(type, obj) {
			var num_tabs = obj.parent().children().length -2;
			var current_tab = obj.siblings(".currentTab").get(0);
			var current_tab_index = obj.parent().children().index(current_tab);
			var clicked_index = obj.parent().children().index(obj);
			var next_tab_index = current_tab_index;
			var next_tab = current_tab;
			if (clicked_index == 0) { //previous
				next_tab_index = (current_tab_index-1) || num_tabs;
				next_tab = obj.parent().children().get(next_tab_index);
			} else if ( clicked_index > num_tabs ) { //next
				next_tab_index = current_tab_index==num_tabs ? 1 : current_tab_index+1;
				next_tab = obj.parent().children().get(next_tab_index);
			} else {
				next_tab = obj;
				next_tab_index = obj.parent().children().index(obj);
			}
	
			obj.siblings().removeClass("currentTab");
			$(next_tab).addClass("currentTab");
			var tabName = $(next_tab).attr("name");
			obj.parent().parent().parent().find("div."+type+"ModuleContainer").removeClass("showTab");
			$("#"+tabName).addClass("showTab");
			return false;
			
	}


		
	var prevTitle = $(".JScarPrev").attr("title");		
	var nextTitle = $(".JScarNext").attr("title");	
		
	$(".JScarPrev > a").append(prevTitle+" ");
	$(".JScarNext > a").prepend(nextTitle+" ");
	
	$(".JScarNext > a").click(function() {
			var t = $("div.carouselModuleNav > ul").children();
			var nt = t.length -2;
			var current_tab = $("div.carouselModuleNav > ul > li").siblings(".currentTab").get(0);
			var current_tab_index = $("div.carouselModuleNav > ul > li").parent().children().index(current_tab);
			var prev_title = $("div.carouselModuleNav > ul").find("li.currentTab").attr("title");
			$(".JScarPrev").attr('title',prev_title);
			$(".JScarPrev > a").html('< '+ prev_title);
			
			if(current_tab_index == (nt-1)) {
				var next_title = $("div.carouselModuleNav > ul").find("li:eq(1)").attr("title");
			}
			else if (current_tab_index == nt) {
				var next_title = $("div.carouselModuleNav > ul").find("li:eq(2)").attr("title");
			}
			else {
				var next_title = $("div.carouselModuleNav > ul").find("li.currentTab").next().next().attr("title");
			}
			
			$(".JScarNext").attr('title',next_title);
			$(".JScarNext > a").html(next_title + ' >');
			
	});
	
	$(".JScarPrev > a").click(function() {
			var t = $("div.carouselModuleNav > ul").children();
			var nt = t.length -2;
			var current_tab = $("div.carouselModuleNav > ul > li").siblings(".currentTab").get(0);
			var current_tab_index = $("div.carouselModuleNav > ul > li").parent().children().index(current_tab);
			var next_title = $("div.carouselModuleNav > ul").find("li.currentTab").attr("title");
			$(".JScarNext").attr('title',next_title);
			$(".JScarNext > a").html(next_title + ' >');
			
			if (current_tab_index == 1){
				
				var prev_title = $("div.carouselModuleNav > ul").find("li:eq("+(nt-1)+")").attr("title");
			}
			else if (current_tab_index == 2) {
				var prev_title = $("div.carouselModuleNav > ul").find("li:eq("+(nt)+")").attr("title");
			}
			else {
				
				var prev_title = $("div.carouselModuleNav > ul").find("li.currentTab").prev().prev().attr("title");
			}
			
			$(".JScarPrev").attr('title',prev_title);
			$(".JScarPrev > a").html('< '+ prev_title);

	});

	$("div.rotatingModuleNav > ul > li").hover(
		function() {
			$("#headlineDisplay").html( $(this).attr("title") );
		},
		function() {
			var t = $("div.rotatingModuleNav > ul").children();
			var nt = t.length -2;
			var curtab = $(this).parent().find("li.currentTab").attr("name");
			var curtabnum = curtab.split("-");
			var ctn = parseInt(curtabnum[1]) + 1; /* added 1 because of zero based index */
			
			if (nt == ctn) { /* if current node is last node, show the first node title as next */
				var title = $("div.rotatingModuleNav > ul > li:eq(1)").attr("title");
				$("#headlineDisplay").html("Next: "+title);
			}
			else {
				var title = $(this).parent().find(".currentTab").next().attr("title");
				$("#headlineDisplay").html("Next: "+title);
			}
		}
	);
	
	
	$(".JSrotNext > a").click(function() {
			var t = $("div.rotatingModuleNav > ul").children();
			var nt = t.length -2;
			var current_tab = $("div.rotatingModuleNav > ul > li").siblings(".currentTab").get(0);
			var current_tab_index = $("div.rotatingModuleNav > ul > li").parent().children().index(current_tab);
			var prev_title = $("div.rotatingModuleNav > ul").find("li.currentTab").attr("title");
			$(".JSrotPrev").attr('title',prev_title);
			
			if(current_tab_index == (nt-1)) {
				var next_title = $("div.rotatingModuleNav > ul").find("li:eq(1)").attr("title");
			}
			else if (current_tab_index == nt) {
				var next_title = $("div.rotatingModuleNav > ul").find("li:eq(2)").attr("title");
			}
			else {
				var next_title = $("div.rotatingModuleNav > ul").find("li.currentTab").next().next().attr("title");
			}
			
			$(".JSrotNext").attr('title',next_title);
			
	});
	
	
	$(".JSrotPrev > a").click(function() {
			var t = $("div.rotatingModuleNav > ul").children();
			var nt = t.length -2;
			var current_tab = $("div.rotatingModuleNav > ul > li").siblings(".currentTab").get(0);
			var current_tab_index = $("div.rotatingModuleNav > ul > li").parent().children().index(current_tab);
			var next_title = $("div.rotatingModuleNav > ul").find("li.currentTab").attr("title");
			$(".JSrotNext").attr('title',next_title);
			
			if (current_tab_index == 1){
				
				var prev_title = $("div.rotatingModuleNav > ul").find("li:eq("+(nt-1)+")").attr("title");
			}
			else if (current_tab_index == 2) {
				var prev_title = $("div.rotatingModuleNav > ul").find("li:eq("+(nt)+")").attr("title");
			}
			else {
				
				var prev_title = $("div.rotatingModuleNav > ul").find("li.currentTab").prev().prev().attr("title");
			}
			
			$(".JSrotPrev").attr('title',prev_title);
			
	});


	/* Set up events on Tabbed modules */
	$("div.tabbedModuleNav > ul > li").click(function() {
		$(this).siblings().removeClass("currentTab");
		$(this).addClass("currentTab");
		var tabName = $(this).attr("name");
		$(this).parent().parent().parent().find("div.tabbedModuleContainer").removeClass('showTab');
		$("#"+tabName).addClass('showTab');
		return false;
	});

	$("div.tabbedModuleNav > ul > li").hover (
	function() {
			$(this).addClass("sfHover");
		},
		function() {
			$(this).removeClass("sfHover");
		}

	);

	$("div.rotatingModuleNav > ul > li").hover (
	function() {
			$(this).addClass("sfHover");
		},
		function() {
			$(this).removeClass("sfHover");
		}

	);


	/* Player expand button */
	$("#expandable > a").click(function() {
		var expanded = $.cookie('expanded');
		if(expanded == 0 || expanded == null){
                  $.cookie('expanded',1, {path: "/"});
                  $("#playerFull").show(player_speed);
		}
		else {
                  $.cookie('expanded',0, {path: "/"});
                  $("#playerFull").hide(player_speed);
		}

                $("#sublinks").toggle();
		$("#expandable > a").toggle();
		return false;
	});

	/* Show/hide comments */
	$("#comments > span > a").click(function() {
		$("#comments > span > a").toggle();
		$(".commentList").toggle("slow");
		return false;
	});


	/* Font size widget */
	$("#font_sm").click(function() {
		$.cookie('textsize','1em', {path: "/"});
		$("#centerColumn").css("font-size", "1em");
		$("#textSize > a").removeClass("currentFont");
		$(this).addClass("currentFont");
		return false;
	});

	$("#font_med").click(function() {
		$.cookie('textsize','1.2em', {path: "/"});
		$("#centerColumn").css("font-size", "1.2em");
		$("#textSize > a").removeClass("currentFont");
		$(this).addClass("currentFont");
		return false;
	});

	$("#font_lg").click(function() {
		$.cookie('textsize','1.4em', {path: "/"});
		$("#centerColumn").css("font-size", "1.4em");
		$("#textSize > a").removeClass("currentFont");
		$(this).addClass("currentFont");
		return false;
	});

	/* Advanced search box and initialization */
	$("#advSearchMenu").show();
	$("#advSearchMenu > fieldset > div.advSearchBoxes").nextAll().hide(); /* on initial load, hides all of the advanced search items except the first */
	$("#advSearchMenu > fieldset > div.advSearchBoxes > input").attr("disabled","true");
	$("#advSearchMenu > fieldset > div.advSearchBoxes > select").attr("disabled","true");

	/* Sets the initial action value of the advance search form */
	var advSearchId = $("#ssc option:selected").attr("value");
	var optiondiv ="#"+advSearchId;
	$(optiondiv).show();
	buildAdvSearchURL(advSearchId,"searchform_adv");
	$(optiondiv + " > input").removeAttr("disabled");
	$(optiondiv + " > select").removeAttr("disabled");
	
	
	$("#ssc").change(function() {
		/* takes the value from the option and matches it to the id of the div and show it */
		$("#ssc option:selected").each(function() {
			var theId = $(this).attr("value");
			$("#advSearchMenu > fieldset > div.advSearchBoxes > input").attr("disabled","true");
			$("#advSearchMenu > fieldset > div.advSearchBoxes > select").attr("disabled","true");
			$("#advSearchMenu > fieldset > div.advSearchBoxes").hide();
			var searchdiv ="#"+theId;
			$(searchdiv).show();
			/* Construct the url for the search query and insert it into the form */
			buildAdvSearchURL(theId,"searchform_adv");
			$(searchdiv + " > input").removeAttr("disabled");
			$(searchdiv + " > select").removeAttr("disabled");

		});
	});
	
	function buildAdvSearchURL(formtype, formid) {
	var advSearchArray = cxri_main_url.split("//");
	var advSearchUrl = "http://search."+advSearchArray[1]+"/"+formtype;
	$("#"+formid).attr("action", advSearchUrl);
	$("#submitBtnAdv").unbind("click");
	$("#storehidden").remove();
	
		if(formtype == "es") {
			$("#advSearchMenu").show();
			$("#keywordbox").attr("name", "q");
			$("#submitBtnAdv").click(function() {
				 processDate(this);
			});
			
		}
		
		if (formtype == "ms") {
			$("#advSearchMenu").show();
			$("#keywordbox").attr("name", "q");
			$("#submitBtnAdv").click(function() {
				 return submitZip(this);
			});
		}
		
		if (formtype == "as") {
			$("#advSearchMenu").show();
			$("#keywordbox").attr("name", "q");
			$("#submitBtnAdv").click(function() {
				$("#searchform_adv").submit();
			});
		}

		if (formtype == "us") {
			$("#advSearchMenu").hide();
			$("#keywordbox").attr("name", "q");
			$("#submitBtnAdv").click(function() {
				$("#searchform_adv").submit();
			});
		}
		
		if (formtype == "ls") {
			$("#keywordbox").attr("name", "string");
			$("#"+formid).attr("action", "http://"+advSearchArray[1]+"/search/lyrics.html");
			$("#advSearchMenu").hide();
			$("#submitBtnAdv").click(function() {
				$("#searchform_adv").submit();
			});
		}
		
		if (formtype == "vs") {
			$("#keywordbox").attr("name", "string");
			$("#advSearchMenu").hide();
			$("#"+formid).attr("action", "http://"+advSearchArray[1]+"/search/video.html");
			$("#submitBtnAdv").click(function() {
				$("#searchform_adv").submit();
			});
		}
		
		if (formtype == "os") {
			$("#keywordbox").attr("name", "string");
			$("#advSearchMenu").hide();
			$("#"+formid).attr("action", "http://"+advSearchArray[1]+"/lsp/ads.html");
			$("#submitBtnAdv").click(function() {
				$("#searchform_adv").submit();
			});
		}
		
		if (formtype == "ts") {
			$("#keywordbox").attr("name", "string");
			$("#advSearchMenu").show();
			$("#"+formid).attr("action", "http://"+advSearchArray[1]+"/liveweb/search/national_tours.html");
			$("#submitBtnAdv").click(function() {
				$("#searchform_adv").submit();
			});
		}
		
		if (formtype == "tsd") {
			$("#keywordbox").attr("name", "string");
			$("#advSearchMenu").show();
			$("#"+formid).attr("action", "http://"+advSearchArray[1]+"/liveweb/search/national_tours.html");
			$("#submitBtnAdv").click(function() {
				$("#searchform_adv").submit();
			});
		}
		
		if (formtype == "sms") {
			$("#keywordbox").attr("name", "string");
			var thetag = '<input type="hidden" name="type" value="store" id="storehidden" />';
			$(thetag).appendTo("#searchform_adv");
			$("#advSearchMenu").hide();
			$("#"+formid).attr("action", "http://"+advSearchArray[1]+"/liveweb/search/music.html");
			$("#submitBtnAdv").click(function() {
				$("#searchform_adv").submit();
			});
		}
		
		if (formtype == "mts") {
			$("#keywordbox").attr("name", "string");
			$("#advSearchMenu").hide();
			$("#"+formid).attr("action", "http://"+advSearchArray[1]+"/search/trailers.html");
			$("#submitBtnAdv").click(function() {
				$("#searchform_adv").submit();
			});
		}
		
		if (formtype == "sds") {
			$("#keywordbox").attr("name", "string");
			$("#advSearchMenu").hide();
			$("#"+formid).attr("action", "http://"+advSearchArray[1]+"/p/store/dvd.cgi");
			$("#submitBtnAdv").click(function() {
				$("#searchform_adv").submit();
			});
		}		

	}
	
	
	
	$("#ms > #ez-type").change(function() {
		/* takes the value from the option and matches it to show the zip sort options */
		$("#ms > #ez-type option:selected").each(function() {
			var msvalue = $(this).attr("value");	
			if (msvalue == "Movie" || msvalue == "Notes,Reviews") {
				$("#zipdisplay").hide();	
			}
			else {
				$("#zipdisplay").show();	
			}
		});
	});
	
	$("#ms > #ez-type option:selected").each(function() {
			var msvalue = $(this).attr("value");	
			if (msvalue == "Movie" || msvalue == "Notes,Reviews") {
				$("#zipdisplay").hide();	
			}
			else {
				$("#zipdisplay").show();	
			}
	});
	

	/* Clue tip box */
	$(".cluetip").cluetip({sticky: true, closePosition: 'title',splitTitle: '|'});
	
        //	var mycluetip = function() { $(".cluetip").cluetip({sticky: true, closePosition: 'title',splitTitle: '|'}); };
	//      $(".cluetip").mycluetip();
	

	/* Empties contents on focus, used in forms */
	$(".empty").focus(function() {
          $(this).attr("value","");
        });

	/* Search form attribute rewrite for business directory */
	$("#searchbtn").click(function() {
		var biz = $("#btn_biz_dir:checked").length;
		if(biz > 0) {
			var searchurl = cxri_main_url;
			var additional = $("#btn_biz_dir").attr("value");
			searchurl = searchurl + additional;
			$("#searchform").attr("action",searchurl);
			$("#searchbox").attr("name","userquery");
			$("#searchform").attr("method","get");
		}
	});

	$("#commentBtn").click(function() {
		$(this).attr("disabled", "true");
		/* add function to load comment form */
                var query_string = document.location.search;
                query_string = query_string.replace(/\?_form=1/,'?');
                query_string = query_string.replace(/&_form=1/,'');
                if (query_string == '?') {
		  query_string = '';
		}
                var url = escape(document.location.pathname + query_string);
                var title = escape($('title').text());
                $('#commentForm').load(cxri_main_url+'/inc/comments/edit_form.html?url='+url+'&title='+title)
	});


	$("#select_dates").click(function() {
		$("#dates_from_to").show();
		return false;
        });

});


function showNext(nextTab, currentTab) {
	var curr = document.getElementById(currentTab);
	var next = document.getElementById(nextTab);
	curr.style.display = "none";
	next.style.display = "block";
	return false;
}

function showPrev(prevTab, currentTab) {
	var curr = document.getElementById(currentTab);
	var prev = document.getElementById(prevTab);
	curr.style.display = "none";
	prev.style.display = "block";
	return false;
}

function openPlayer(URL) {
 var opt1 = 'width=697,height=346,top=420,left=520,screenY=420,screenX=520';
 var opt2 = 'width=697,height=346,top=250,left=300,screenY=250,screenX=300';

    if(screen.width >= 1000)
 {
 window.open(URL,'Streamaudio_Player',opt1);
 }
    if(screen.width <= 800)
 {window.open(URL,'Streamaudio_Player',opt2);
 }
}

/**** old v2 scripts ***/
function echeck(str) {
    var at="@";
    var dot=".";
    var lat=str.indexOf(at);
    var lstr=str.length;
    var ldot=str.indexOf(dot);
    if (str.indexOf(at)==-1){
        alert("Please enter your primary email address.");
        return false;
    }
    if (str.indexOf(at)==-1 || str.indexOf(at)===0 || str.indexOf(at)==lstr){
        alert("Please enter your primary email address.");
        return false;
    }
    if (str.indexOf(dot)==-1 || str.indexOf(dot)===0 || str.indexOf(dot)==lstr){
        alert("Please enter your primary email address.");
        return false;
    }
    if (str.indexOf(at,(lat+1))!=-1){
        alert("Please enter your primary email address.");
        return false;
    }
    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        alert("Please enter your primary email address.");
        return false;
    }
    if (str.indexOf(dot,(lat+2))==-1){
        alert("Please enter your primary email address.");
        return false;
    }
    if (str.indexOf(" ")!=-1){
        alert("Please enter your primary email address.");
        return false;
    }
    return true;
}

function ValidateForm() {
    var emailID=document.emailform.user_email_address;

    if (emailID.value===null || emailID.value==="") {
        alert("Please enter your primary email address.");
        emailID.focus();
        return false;
    }
    if (echeck(emailID.value)===false) {
        emailID.value="";
        emailID.focus();
        return false;
    }
    return true;
}


function quick_redir(myForm) {
    var dest = myForm.url.options[myForm.url.selectedIndex].value;
    if (dest) { document.location = dest; }
    else { alert("Please select an item before submitting"); }
    return false;
}

function displayYear() {
    var currentTime = new Date();
    document.write(currentTime.getFullYear());
}


/* Clears form fields of their default values */
function clearFormField(field) {

    switch(field.type) {

    case "radio":
        field.checked = false;
        break;

    case "checkbox":
        field.checked = false;
        break;

    case "select-one":
        field.selectedIndex = 0;
        break;

    default:
      if ((field.value == 'mm') ||
          (field.value == 'dd') ||
          (field.value == 'yyyy'))
        field.value="";
      break;
    }
} 


function populateWirelessInfo(first, second, third, theElement, formName) {
    var fullnum, wireless;
    if(theElement){
        if(theElement.value !== "") {
            /* gets the value of the three input fields */
            first = document.getElementById(first).value;
            second = document.getElementById(second).value;
            third = document.getElementById(third).value;

            /*make them one number */
            fullnum = first+second+third;
            if (checkPhone(fullnum) !== false) {
                wireless = filterNum(fullnum);
                document.forms[formName].wireless_email.value = fullnum + "@" + theElement.value;
            }
        }
    }
}


function checkPhone(str) {
    var phone2 = /^[0-9]{10,10}$/;
    if (str.match(phone2)) {
        return true;
    } else {
        alert("Please enter a valid 10 digit phone number.");
        this.focus();
        return false;
    }
} 

function filterNum(str) {
    var re = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|}|{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g;
    // remove special characters like "$" and "," etc...
    return str.replace(re, "");
} 


/* mouseover and hover functions */
function sfHoverList(theId) {
  IEmouseOver(theId);
} 

function IEmouseOver( navID ) {
  var sfEls = document.getElementById(navID).getElementsByTagName("LI");

  for (var i=0; i<sfEls.length; i++) {
    sfEls[i].onmouseover=function() {
      this.className+=" sfhover";
    };
    sfEls[i].onmouseout=function() {
      this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
    };
  }
} 


/* gets passed a container object and looks through all form field elements inside the container and enables or disables them */
function disableEnableElements( elem, value ) {
    var i;
    var inputs = elem.getElementsByTagName('input');
    for (i=0; i<inputs.length; i++){
        inputs[i].disabled = value;
    }

    var selects = elem.getElementsByTagName('select');
    for (i=0; i<selects.length; i++){
        selects[i].disabled = value;
    }

    var textareas = elem.getElementsByTagName('textarea');
    for (i=0; i<textareas.length; i++){
        textareas[i].disabled = value;
    }

} 
