// JavaScript Document

//launchpad
function iheartradioToggleOn(){
    document.getElementById("iHeart").className = "active";
    document.getElementById("RadioTunerLink").innerHTML="iHeartRadio";
    document.getElementById("RadioTunerText").className ="active";
    document.getElementById("arrow350").className = "active";
}
function iheartradioToggleOff(){
    document.getElementById("iHeart").className = "inactive";
    document.getElementById("RadioTunerLink").innerHTML="750+ free radio stations";
    document.getElementById("RadioTunerText").className = "inactive";
    document.getElementById("arrow350").className = "inactive";         
}

//Search Box
function clearText(field){
  if (field.defaultvalue == field.value) field.value = '';
  else if (field.value == '') field.value = field.defaultvalue;
}


//Photo Album
function open_photo_popup(album_id,position) {
	if(typeof(position)=="undefined"){
		//window.open('/cc-common/gallery/display.html?album_id=' + album_id, 'photo_album','width=728,height=600,resizable=no,scrollbars=no,menu=no,status=no');
		window.location.href = "/cc-common/gallery/photos.html?album_id="+ album_id;
	} else {
		//window.open('/cc-common/gallery/display.html?album_id=' + album_id + '&position='+position, 'photo_album','width=728,height=600,resizable=no,scrollbars=no,menu=no,status=no');
		window.location.href = "/cc-common/gallery/photos.html?album_id="+ album_id + '&p='+position;
	}
}

//Any Photo Album Over Any Page At Any Position
function album_over_page(album_id,pageurl,position) {
	if(typeof(position)=="undefined"){
		//window.open('/cc-common/gallery/display.html?album_id=' + album_id, 'photo_album','width=728,height=600,resizable=no,scrollbars=no,menu=no,status=no');
		//parent.location = pageurl;
		window.location.href = "/cc-common/gallery/photos.html?album_id="+ album_id;
	} else {
		//window.open('/cc-common/gallery/display.html?album_id=' + album_id + '&position='+position, 'photo_album','width=728,height=600,resizable=no,scrollbars=no,menu=no,status=no');
		//parent.location = pageurl;
		window.location.href = "/cc-common/gallery/photos.html?album_id="+ album_id + '&p='+position;
	}
}

// Any Music Video
function open_videos_on_demand_player(track_id) {
	location.href='/cc-common/ondemand/player.html?program=vod&track_id='+track_id;
}

//Any Music Video Over Any Page
function video_over_page(track_id,pageurl) {
	window.open('/cc-common/ondemand/player.html?program=vod&track_id='+track_id,'player');
	parent.location = pageurl;
}

//Any National Music On Demand Program
function open_on_demand_playerT2(APID,MID){
	location.href='/cc-common/ondemand/player.html?apid='+APID+'&mid='+MID;
}

//Any National Music On Demand Program Over Any Page
function mod_over_page(APID,MID,pageurl){
	window.open('/cc-common/ondemand/player.html?apid='+APID+'&mid='+MID,'player');
	parent.location = pageurl;
}

//Any Rich Media
function openMediaPlayer(SKIN,MEDIA) {
	day = new Date();
	id = day.getTime();
	artskin = SKIN.replace(/.php/gi, "");
	location.href='/player/?art='+artskin+'&tra=on demand&omu='+MEDIA+'';
}

//Any Rich Media Over Any Page
function richmedia_over_page(SKIN,MEDIA,pageurl) {
	day = new Date();
	id = day.getTime();
	artskin = SKIN.replace(/.php/gi, "");
	window.open('/player/?art='+artskin+'&tra=on demand&mid='+MEDIA+'','player');
	parent.location = pageurl;
}

//Any Flash On Demand Media
function playFlashMedia(media_id){
	window.location.href = '/player/?mid='+media_id;
}

//Any Flash On Demand Media Over Any Page
function flashmedia_over_page(podcastxmlname,mediaid,pageurl){
	window.open('/player/?station='+clearchannelGlobalSiteId+'&program_name=ondemand&mid='+mediaid+'&program_id='+podcastxmlname,'player');
	parent.location = pageurl;
}

//Any Flash Player Media Podcast Item
function open_media_podcast(podcastxmlname, mediaid){
	location.href = '/player/?station='+clearchannelGlobalSiteId+'&program_name=podcast&mid='+mediaid+'&program_id='+podcastxmlname;
}

//Any Flash Player Media Podcast Item Over Any Page
function open_media_podcast_over_page(podcastxmlname, mediaid,pageurl){
	window.open('/player/?station='+clearchannelGlobalSiteId+'&program_name=podcast&mid='+mediaid+'&program_id='+podcastxmlname,'player');
	parent.location = pageurl;
}

//Any Streaming Player
function openStreamingPlayer(stream_id) {
	if(typeof(stream_id)=="undefined"){
	    window.open('/cc-common/listenlive/');
	} else {
	    window.open('/cc-common/listenlive/?stream_id='+stream_id);
    }
}

//Any Streaming Player Over Page
function stream_over_page(pageurl,stream_id) {
	if(typeof(stream_id)=="undefined"){
	    window.open('/cc-common/listenlive/');
		parent.location = pageurl;
	} else {
	    window.open('/cc-common/listenlive/?stream_id='+stream_id);
		parent.location = pageurl;
	}
}

//Add To Bookmark
function addbookmark(bookmarkurl,bookmarktitle){
	if (window.sidebar) {
		window.sidebar.addPanel(bookmarktitle,bookmarkurl,'');//Moz
	} else if( window.external && !(window.chrome)) {
		window.external.AddFavorite(bookmarkurl,bookmarktitle)//IE
	} else { 
		alert("This browser does not support this functionality. To add this page as a bookmark press crtl + D (cmd + D for mac users)");
	}
}

//Show Or Hide An Element By ID
function showHide(elementid){
	if (document.getElementById(elementid).style.display == 'none') {
		document.getElementById(elementid).style.display = '';
 	} else {
  		document.getElementById(elementid).style.display = 'none';
 }
}

//Select all contents of an Element by ID
function SelectAll(id) {
	document.getElementById(id).focus();
	document.getElementById(id).select();
}


/////////////////////////////////////////////////////////
///////////////////   NATIONAL   ////////////////////////
/////////////////////////////////////////////////////////



//National News Video Player
function openNewsPlayer(URL) {
	day = new Date();
	id = day.getTime();
	window.open(URL,'_blank','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=728,height=511');
}

//National News Video Over On Demand Page
function openNewsPlayerSPECIAL(URL) {
	day = new Date();
	id = day.getTime();
	window.open(URL,'_blank','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=728,height=511');
	self.location = '/cc-common/ondemand/';
}

//Ryan Seacrest Player
function openRyanPlayer(MEDIA) {
	day = new Date();
	id = day.getTime();
	window.open('/cc-common/mediaplayer/ryanseacrest/player.html?mps=onairryan.php&mid=http://a23.v18227d.c18227.g.vm.akamaistream.net/7/23/18227/v0001/cchannel.download.akamai.com/18227/auth_!/Seacrest/' + MEDIA + '','MediPlayerWindow','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=728,height=511');
}

//Video Over VOD page
function open_videos_on_demand_playerT2(track){
	window.open('/cc-common/ondemand/player.html?program=vod&track_id='+track,'player');
	self.location = '/cc-common/videos_on_demand/';
}

//Photo Album Over Photo Aggregate Page
function open_photo_under_popup(album_id) {
	//window.open('/cc-common/gallery/display.html?album_id=' + album_id, 'photo_album','width=728,height=600,resizable=no,scrollbars=no,menu=no,status=no');
	//self.location = '/cc-common/gallery/';
	window.location.href = "cc-common/gallery/photos.html?album_id="+ album_id;
}

//NEW! Discover & Uncover Program Submission
function openNewSubmission(){
	window.open('/cc-common/artist_submission/','_blank','toolbar=0,scrollbars=1,location=1,statusbar=1,menubar=1,resizable=1,width=780,height=580');
	self.location='/cc-common/new/6/';
}

//Classic Streaming Player
function openClassicStreamingPlayer(instance) {
	if(typeof(instance)=="undefined"){
		window.open('/cc-common/streaming_new/index.html','ccTuner','width=668,height=420,status=no,resizable=no,scrollbars=no');
	} else {
		window.open('/cc-common/streaming_new/index.html?player_instance=' + instance,'ccTuner','width=668,height=420,status=no,resizable=no,scrollbars=no');
	}
}

//Flash Player Main Stream
function openFlashPlayer(){
	window.open('/cc-common/listenlive/');
}

//I've seem these used somewhere, but I forget where
function changepage(thelocation){
	window.open(thelocation,'playerWindow','toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=668,height=396');
}
function changepage2(thelocation){
	self.location = thelocation;
}
var PlayerPopups = {};
PlayerPopups.openPlayer = function(url){
    if(url.indexOf('world=st')!=-1 && !ClearChannel.Browser.WebKit){
	PlayerPopups.DoAndoSurvey(url);
    }else{
		if(url.indexOf('world=st')==-1){
			window.open(url,'player');
		}else{
			window.open(url,'player', 'location=no,menubar=no,scrollbars=yes,width=980,height=592');
		}
    }
};
PlayerPopups.openPlayer_specificpage = function(playerurl,backgroundurl){
    if(playerurl.indexOf('world=st')!=-1 && !ClearChannel.Browser.WebKit){
	PlayerPopups.DoAndoSurvey(playerurl, backgroundurl);
    }else{
		if(url.indexOf('world=st')==-1){
			window.open(url,'player');
		}else{
			window.open(url,'player', 'location=no,menubar=no,scrollbars=yes,width=980,height=592');
		}
	self.location =backgroundurl;
    }
};
PlayerPopups.DoAndoSurvey = function(url, backgroundurl){
    if(backgroundurl){
	new ClearChannel.Ajax(
	    {
	    asynchronous:false, 
	    on200:new ClearChannel.AjaxListener(
		ClearChannel.AjaxEvent.prototype.OK, 
		function(transportEvent){
		    try{
			var andoObject = transportEvent.getResponseObject().getResponseJSON();
		    }catch(e){
			var andoObject = {
			    AndoSurveyActive:false, 
			    AndoPrm:0
			};
		    }
		    if(andoObject.AndoSurveyActive){
			var Y = (function(){return (ClearChannel.getViewportHeight()/2)+ClearChannel.getVerticalScroll()-(232/2);})();
			var X = (function(){return (ClearChannel.getViewportWidth()/2)+ClearChannel.getHorizontalScroll()-(222/2)})();
			try{checkcookie({clientY:Y,clientX:X},'http://podloc.andomedia.com/dloadTrack.mp3?prm='+andoObject.AndoPrm+'xhttp://'+andoObject.host+'/cc-common/ondemand/player.html?world=st',true,592,980);
			   setTimeout(function(){try{
				    document.getElementById('popdiv').style.top=Math.round(Y)+'px';
				    document.getElementById('popdiv').style.left=Math.round(X)+'px';
				    document.getElementById('shadow').style.top=Math.round(Y)+'px';
				    document.getElementById('shadow').style.left=Math.round(X)+'px';
				}catch(e){}}, 10);
			   }catch(e){}
			var pu = window.open(backgroundurl, '_blank');
			try{
			    pu.blur();
			    window.focus();
			}catch(e){
			}
		    }else{
				if(url.indexOf('world=st')==-1){
					window.open(url,'player');
				}else{
					window.open(url,'player', 'location=no,menubar=no,scrollbars=yes,width=980,height=592');
				}
			self.location=backgroundurl;
		    }
		}
	    )
	}, 
	    '/cc-common/js/ajax_services/AndoSurveyService.php'
	);
    }else{
	new ClearChannel.Ajax(
	    {
		asynchronous:false, 
		on200:new ClearChannel.AjaxListener(
		    ClearChannel.AjaxEvent.prototype.OK, 
		    function(transportEvent){
			try{
			    var andoObject = transportEvent.getResponseObject().getResponseJSON();
			}catch(e){
			    var andoObject = {
				AndoSurveyActive:false, 
				AndoPrm:0
			    };
			}
			if(andoObject.AndoSurveyActive){
			    var Y = (function(){return (ClearChannel.getViewportHeight()/2)+ClearChannel.getVerticalScroll()-(232/2);})();
			    var X = (function(){return (ClearChannel.getViewportWidth()/2)+ClearChannel.getHorizontalScroll()-(222/2);})();
			    try{checkcookie({clientY:Y,clientX:X},'http://podloc.andomedia.com/dloadTrack.mp3?prm='+andoObject.AndoPrm+'xhttp://'+andoObject.host+'/cc-common/ondemand/player.html?world=st',true,592,980);
				setTimeout(function(){try{
				    document.getElementById('popdiv').style.top=Math.round(Y)+'px';
				    document.getElementById('popdiv').style.left=Math.round(X)+'px';
				    document.getElementById('shadow').style.top=Math.round(Y)+'px';
				    document.getElementById('shadow').style.left=Math.round(X)+'px';
				}catch(e){}}, 10);
}catch(e){}
			}else{
				if(url.indexOf('world=st')==-1){
					window.open(url,'player');
				}else{
					window.open(url,'player', 'location=no,menubar=no,scrollbars=yes,width=980,height=592');
				}
			}
		    }
		)
	    }, 
	    '/cc-common/js/ajax_services/AndoSurveyService.php');
    }
};


