var auto_play_timer;
var flash_radio_player;
var player_loaded = false; // this variable is used to check if the flash player is loaded or not

// the 2D arrays to hold the category data

var category_array_Erhverv = new Array();
var category_array_Politik = new Array();;
var category_array_Magasinprogrammer  = new Array();;
var category_array_Børs  = new Array();;
var category_array_Forbrug  = new Array();;
var category_array_Øvrige  = new Array();;
var category_array_Nyheder = new Array();;

// array to hold the contents of the playlist

var playlist_array = new Array();

var current_clip_id = ''; // this variable stores the currently loaded/played clip id in the flash player

////////////////////////

//var prefs = {
//
//    data: {},
//
//    load: function () {
//        var the_cookie = document.cookie.split(';');
//        if (the_cookie[0]) {
//            this.data = unescape(the_cookie[0]).parseJSON();
//        }
//        return this.data;
//    },
//
//    save: function (expires, path) {
//        var d = expires || new Date(2020, 02, 02);
//        var p = path || '/';
//        document.cookie = escape(this.data.toJSONString())
//                          + ';path=' + p
//                          + ';expires=' + d.toUTCString();
//    }
//
//}



////////////////////////


function disableKey( _key) {
	if (window.event && window.event.keyCode==_key) {
		window.event.keyCode=0;
		window.event.returnValue=false;
	}
}

var volumeLevel = 4;
var muted = false;

function AdjustVol(aNumb) {
	var VolLevel
	switch(aNumb) {
		case 0: VolLevel = 0;break
		case 1: VolLevel = 20;break
		case 2: VolLevel = 40;break
		case 3: VolLevel = 60;break
		case 4: VolLevel = 80;break
		case 5: VolLevel = 100;break
	}
	if (document.player1 != null && document.player1.settings != null) {
		document.player1.settings.volume = VolLevel;
	}
}

function updateVolume(vol) {
	volumeLevel = vol;
	AdjustVol(vol);
	muted = false;
}

function muteUnmute(prefix) {
	if (document.player1 != null) {
		
		var loc = window.location;
		loc = loc.toString();
				
		if (muted) {
			
			if(loc.indexOf("layout") != -1)
				prefix.src = "images/page/mute.gif";
			AdjustVol(volumeLevel);
			muted = false;
		} else {
			
			if(loc.indexOf("layout") != -1)
				prefix.src = "images/page/unmute.gif";
			AdjustVol(0);
			muted = true;
		}
	}
}

function play(prefix) {
	
	if (document.player1 != null && document.player1.controls != null) {
		document.player1.controls.play();
		if (muted) {
			muteUnmute();
		}
	}
}

function stop(prefix) {
	if (document.player1 != null && document.player1.controls != null) {
	
		document.player1.controls.stop();
		
	}
}

function danskState(_stateString)  {
	var stateString = _stateString;
	stateString = stateString.replace('Buffering','henter');
	stateString = stateString.replace('Playing','spiller');
	stateString = stateString.replace('Connecting','forbinder');
	stateString = stateString.replace('complete','f&aelig;rdig');
	stateString = stateString.replace('Ready','klar');
	stateString = stateString.replace('Paused','pause');
	stateString = stateString.replace('to media','');
	stateString = stateString.replace('Stopped','stoppet');
	stateString = stateString.replace('Waiting','venter');
	
	return stateString;
}

function checkstate() {
	
	if(!player_loaded) {
	
	try {
		
		// we make a check on the location 
		// if we find it, that means we are coming from the new page
		// else it is the old page
		
		var loc = window.location;
		
		loc = loc.toString();
		
		if(loc.indexOf("layout") == -1 && loc.indexOf("liveplayer") == -1)
			var divState = document.getElementById('playerState');
		else 
			var divState = document.getElementById('sangstatus');
			
		if (document.player1.playState == 3) {
						
			var bitrate = document.player1.currentMedia.getItemInfo('Bitrate');
			var kbitrate = parseInt(bitrate/1000);
			
			if(loc.indexOf("layout") == -1  && loc.indexOf("liveplayer") == -1)
				divState.innerHTML = "spiller "+kbitrate+" Kbit/s";
			else 
				divState.innerHTML = "<P>spiller "+kbitrate+" Kbit/s</P>";
				
		} else {
			
			if(loc.indexOf("layout") == -1  && loc.indexOf("liveplayer") == -1)
				divState.innerHTML = danskState( document.player1.status );
			else 
				 divState.innerHTML = "<P>"+danskState( document.player1.status )+"</P>";
				
		}
		var check_timer = setTimeout("checkstate()",1000)
	} catch (Exception) {};
	
	} else {
		
		clearTimeout(check_timer); 
	}
}


// i closed these two onload functions and would check once needed
	
var loc = window.location;

var str = loc.toString();

if(str.indexOf("layout") == -1 && str.indexOf("liveplayer") == -1) {
	
	$('#player1').ready(function() {
		if (location.href.indexOf('controls') == -1) {
			if (document.player1 != null && document.player1.controls != null) {
				location.href = location.href + "?controls=full";
			} else {
				location.href = location.href + "?controls=unavailable";
			}
		}
	}); 
	
	$(document).ready(function() {
		checkstate();
		var sliderOptions = {handle: '#volume', max: 5, startValue: 4, steps: 5, axis: 'horizontal', slide: function(evt, data) {
			updateVolume(data.value);
		}};
		$('#volume').slider(sliderOptions);
	}); 

}

// since we would be having 

// we would fetch the details of the clip which we need to set along with the clipID

function ajaxRequest(myplaylist, clipID, choice) {
	
		http_request = '';

			if (window.XMLHttpRequest) { // Mozilla, Safari, ...

			    http_request = new XMLHttpRequest();

			} else if (window.ActiveXObject) { // IE

			    http_request = new ActiveXObject("Microsoft.XMLHTTP");

			}
// callback

	http_request.onreadystatechange = function() {

	if (http_request.readyState == 4) {
	
            if (http_request.status == 200) {

				response = http_request.responseXML;
				
				if(choice == "fetchClipDetails") { // if we need to fetch the clip details
				
				var id = response.getElementsByTagName("id")[0].firstChild.nodeValue;
				var title = response.getElementsByTagName("title")[0].firstChild.nodeValue;
				
				var duration = response.getElementsByTagName("duration")[0].firstChild.nodeValue;
				//var info = response.getElementsByTagName("info")[0].firstChild.nodeValue;
				var url = response.getElementsByTagName("url")[0].firstChild.nodeValue;
				
				// now we need to feed the playlist with the incoming data
				
				size = myplaylist.length;
				
				myplaylist[size] = new Array(4);
				
				// we control the size of the title and info, title is hardcoded at the moment for the playlist display
				var title_length = 15;
				
				var desc_length = document.getElementById("desc_length").value;
	
   				titley = (title.length > title_length) ? title.substring(0, title_length)+"..." : title;
   				//infoy = (info.length > desc_length) ? info.substring(0, desc_length)+"..." : info;

				myplaylist[size][0] = id;
				myplaylist[size][1] = titley;
				myplaylist[size][2] = duration;
				myplaylist[size][3] = url;
				
				// we check the page which would be there now
				
				var page_no = Math.ceil(myplaylist.length / 4);
				
				document.getElementById("playlist_page").value = page_no;
				
				// -> replace this document.getElementById("playlist").value = myplaylist;
				playlist_array = myplaylist;

				var expiration_days = document.getElementById("COOKIE_EXPIRATION").value;
							
				jar = new CookieJar({
				expires:expiration_days,   // seconds
				path: '/'
				});
				 
				cook_cookie = {playlist: playlist_array};
				 
				jar.put('cookie_playlist', cook_cookie);
				//cookie = jar.get('cookie_playlist');
				 
//				for(i = 0; i < cookie.playlist.length; i++) {
//					
//					alert(cookie.playlist[i][0]);
//					alert(cookie.playlist[i][1]);
//					alert(cookie.playlist[i][2]);
//					alert(cookie.playlist[i][3]);
//				
//				}
				
				//alert("He is " + mydog.age + " years old");
				//alert("He is an " + mydog.breed);				
				
				
				// we got a new clip added, we update the next playing clips in the player if we have something in the playlist_clip_id!
				
				updateNextPlayingClips();
			
				//var expiration_days = document.getElementById("COOKIE_EXPIRATION").value;
				
				// -> replace Set_Cookie( "playlist", document.getElementById("playlist").value, expiration_days, "/", "", "" );
				//Set_Cookie( "playlist", playlist_array, expiration_days, "/", "", "" );
								
				drawPlayList(document.getElementById("playlist_page").value);
				
				} else if(choice == "searchClips")  {
					
					//alert(http_request.responseText);
					
					var table = "";
					var box_height = 280;
					var boxed_height = 280;
					
					if(response.getElementsByTagName('clip').length > 0)  // if we have some clips in the search result
						table += "<table style='width:530px; margin-left:2px; BACKGROUND-IMAGE:none;' border=0>";
				
					for(i = 0; i < response.getElementsByTagName('clip').length; i++) { // we loop over all the clip tags to fetch the searched clips info
						
						//table+="<tr>";
						
						for(j = 0; j < response.getElementsByTagName('clip')[i].childNodes.length; ) {
							
							// check if the node is an element node 
							if(response.getElementsByTagName('clip')[i].childNodes[j].nodeType == 1) {
								
								var id;
								
								// detect the tag
								switch (response.getElementsByTagName('clip')[i].childNodes[j].nodeName) {
									
									case "id" : id = response.getElementsByTagName('clip')[i].childNodes[j].firstChild.data; break;					
									case "url" : url = response.getElementsByTagName('clip')[i].childNodes[j].firstChild.data; break;
									case "title" : 
									var title_length = document.getElementById("title_length").value;
									title = (response.getElementsByTagName('clip')[i].childNodes[j].firstChild.data.length > title_length) ? response.getElementsByTagName('clip')[i].childNodes[j].firstChild.data.substring(0, title_length)+"..." : response.getElementsByTagName('clip')[i].childNodes[j].firstChild.data;
									table+="<tr><td width='30%' class='playlist_text' id='search_clips_title' align='left'><strong>"+title+"</strong></td><td style='width:1px;' id='search_clips_add'><img src='images/page/plus.gif' onmouseover='handCursor(this);' onclick='addtoplaylist("+id+"); return false;' alt='Klik her for at tilføje klippet til din playliste' title='Klik her for at tilføje klippet til din playliste'></td><td style='width:190px;' id='search_clips_download'> <a href='filedownload.php?title="+title+"&file="+url+"'><img src='images/page/download.gif' border='0' alt='klik her for at downloade klippet som mp3' title='klik her for at downloade klippet som mp3'></a></td></tr>";
									break;
									case "duration" : table+='<tr><td class="playlist_text" colspan="3" id="search_clips_duration"><i>Længde:</i> '+response.getElementsByTagName("clip")[i].childNodes[j].firstChild.data+'</td></tr>'; break;
									case "info" : 
									
									if(response.getElementsByTagName('clip')[i].childNodes[j].firstChild != null) {
										
										var desc_length = document.getElementById("desc_length").value;
										desc = (response.getElementsByTagName('clip')[i].childNodes[j].firstChild.data.length > desc_length) ? response.getElementsByTagName('clip')[i].childNodes[j].firstChild.data.substring(0, desc_length)+"..." : response.getElementsByTagName('clip')[i].childNodes[j].firstChild.data;
										table+="<tr><td class='playlist_text' colspan='3' id='search_clips_desc'>"+desc+"</td></tr>"; 

									} else {
												
										table+="<tr><td class='playlist_text' colspan='3' id='search_clips_desc'>&nbsp;</td></tr>"; 
									}
								
									break;
									//case "url" : table+="<td><img src='images/page/megafon.gif' onclick=\"playsingleclip("+id+"); return false;\" onmouseover=\"handCursor(this);\"></td>"; break;
									
								}
							
							} 
							
							j++;
							
						}
							// based on i
							
							
							if(i > 3) { // if we go above three records, jus think on increasing the size of the table/container :)
								
								//alert("we are greater");
								
								boxed_height = box_height + (i * 58);
								
									
							}
						
							
						}
						
						//table+="</tr>";
						
					
			
					if(response.getElementsByTagName('clip').length > 0)
						table+="</table>";
					
					// set a table as innerHTML 
			
					
					///////////////////
					
					
	var onRadio = '<DIV class=conCluster_page>';
		onRadio+= '<DIV class="conContent_page t6" id="variable_height_box">';
      	onRadio+= '<H1 class="H1_page">Search Results <span class="Luk" onclick="closeSearchTable();" onmouseover="handCursor(this);">Luk</span></H1>';
      	onRadio+= '<table style="width:504px; margin-left:15px;margin-right:5px;background-image:none;">';
      							onRadio+= '<tr>';
      								onRadio+= '<td>&nbsp;</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">'+table+'</td>';
      							onRadio+= '</tr>';
  							onRadio+= '</table>';
      					onRadio+= '</DIV>';
      				onRadio+= '</DIV>';
	      				
      			
      		// we need to arrange the category boxes as well
      					
      		if(table.length > 0) {
      						
				document.getElementById("search_results").innerHTML = onRadio;
				
				document.getElementById("variable_height_box").style.height = boxed_height + "px";
				
				document.getElementById("Erhverv_table").style.top = "-5px";
					
				document.getElementById("Politik_table").style.top = "-5px";
				
				document.getElementById("Nyheder_table").style.top = "-5px";
				
				document.getElementById("Magasinprogrammer_table").style.top = "-5px";			
				
				document.getElementById("Børs og Valuta_table").style.top = "-5px";
				
				document.getElementById("Forbrug_table").style.top = "-5px";
				
				document.getElementById("Øvrige_table").style.top = "-5px";
				
				
      		} else {
      			
      			
      			
      		}
					
					
					
					////////////////////
					
					
					//document.getElementById("search_results").innerHTML = table; -> disabled
					
				} // choice = searchClips end
				else if(choice == "fetchClipCategories") {
					
					// we would request title of the clip as well
					//alert(http_request.responseText);
					
					//alert("title is :: "+response.getElementsByTagName('clipTitle')[0].firstChild.data);
					//alert("categories are :: "+response.getElementsByTagName('categories')[0].firstChild.data);
					
					var category = "";
					
					if(response.getElementsByTagName('categories')[0].firstChild.data.length > 0)
						category = " ("+response.getElementsByTagName('categories')[0].firstChild.data+")";
					
					// -> (disabled as this would be displayed in flash) document.getElementById("title_clip").innerHTML = response.getElementsByTagName('clipTitle')[0].firstChild.data+category;
					
					// we check the clipID of the clip being played and display the titles of next two clips if myplaylist is set
					
					if(myplaylist == 1) {
					
					var next_clips = "";
						
					// -> replace this playlist = document.getElementById("playlist").value;
					var playlist = playlist_array;
					
					//playlist = stringTo2DArray(playlist);
				
					for(i = 0; i < playlist.length; i++) {
						
						if(playlist[i][0] == clipID) { // if we find the clip ID in the playlist check for next clips in the playlist
							
							if(i == playlist.length - 1) {
								break;
							}
							else if(i <= playlist.length - 1) {
								
								var j = i+1;
								
								var title = playlist[j][1]; // title of the immediate next clip in the playlist
								var duration = playlist[j][2]; // duration of the immediate next clip in the playlist
								
								next_clips += title+" ("+duration+") ";
								
								j++;
								
								if(j <= playlist.length - 1) {
									
									var title = playlist[j][1]; // title of the immediate next clip in the playlist
									var duration = playlist[j][2]; // duration of the immediate next clip in the playlist
									
									next_clips += title+" ("+duration+")";
									
								}
								
								break;
								
							}
							
						} 
							
							
						}
					
						
						// -> (disabled as this would be displayed in flash) document.getElementById("next_clips").innerHTML = next_clips;	
						
						/////// we pass the values to the flash player 
						
						var FRONT_DOMAIN = document.getElementById("FRONT_DOMAIN").value;

						//var FRONT_DOMAIN = "http://10.1.0.96/apache2-default/front_jpradio/";
													
						// set the playlist clip id hidden variable
						document.getElementById("playlist_clip_id").value = clipID;
						
						obj = new Object();
						
						obj.url = FRONT_DOMAIN+"xmlgenerator.php";
						obj.id = clipID;
						obj.choice = "playlist";
						obj.title = response.getElementsByTagName('clipTitle')[0].firstChild.data+category;
						obj.next = next_clips;
												
						//var xmlurl = FRONT_DOMAIN+"xmlgenerator.php?id="+clipID+"&choice=playlist&title="+response.getElementsByTagName('clipTitle')[0].firstChild.data+category+"&next="+next_clips;
																
						sendToActionScript(obj); // set the clipID and the choice to playlist as this clip is being played from the playlist
						
						
						//////////////////////////////////////////////						
						
					} // if the call is made from the playlist
					else if(myplaylist == 0) {
						
						var FRONT_DOMAIN = document.getElementById("FRONT_DOMAIN").value;
						
						//var FRONT_DOMAIN = "http://10.1.0.96/apache2-default/front_jpradio/";
						
						//var xmlurl = FRONT_DOMAIN+"xmlgenerator.php?id="+clipID+"&choice=single&title="+response.getElementsByTagName('clipTitle')[0].firstChild.data+category;
						
						obj = new Object();
						
						obj.url = FRONT_DOMAIN+"xmlgenerator.php";
						obj.id = clipID;
						obj.choice = "single";
						obj.title = response.getElementsByTagName('clipTitle')[0].firstChild.data+category;
						
						obj.next = "";
											
						sendToActionScript(obj); // set the clipID and the choice to single as single clip is being played here 
					
						
					}
					
					
				} else if(choice == "sendToFriend") {
					
					// jus display a confirmation message 
					document.getElementById("message_confirmation").innerHTML = "Din besked er afsendt";
					
				}
							
			}

		}

	}

	http_request.open('POST', 'requesthandler.php', true);

	http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	//alert(document.getElementById('catt').value);
	
	if(choice == "fetchClipDetails")
		http_request.send('clipID='+clipID+'&choice=fetchClipDetails');
	else if(choice == "searchClips") 
		http_request.send('search='+clipID+'&choice=searchClips'); // here the clipID = search text
	else if(choice == "fetchClipCategories")	
		http_request.send('clipID='+clipID+'&choice=fetchClipCategories'); // clipID is the ID itself here :)
	else if(choice == "sendToFriend") {
		
		// we extract the values from the array <sender name, sender email, receiver email, receiver name and the message>
		// myplaylist in this case holds the posted values 
		
//	details[0] = document.getElementById("receiver_email").value;
//	details[1] = document.getElementById("receiver_name").value;
//	details[2] = document.getElementById("sender_email").value;
//	details[3] = document.getElementById("sender_name").value;
//	details[4] = document.getElementById("besked").value;
		
		var receiver_email = myplaylist[0];
		var receiver_name = myplaylist[1];
		var sender_email = myplaylist[2];
		var sender_name = myplaylist[3];
		var besked = myplaylist[4];
		var clip_id = myplaylist[5];
		
		http_request.send('receiver_email='+receiver_email+'&receiver_name='+receiver_name+'&sender_email='+sender_email+'&sender_name='+sender_name+'&besked='+besked+'&choice=sendToFriend&clip_id='+clip_id); // send a mail to friend
			
	} 
		
	return false; 
	
	
}

// this function is used to update the next playing titles in the player on adding a clip

function updateNextPlayingClips() {
	
	var next_clips = '';
	
	if(document.getElementById("playlist_clip_id").value.length > 0) {
		
		// we check where is this playlist_clip_id in the playlist
		
		// -> replace myplaylist = document.getElementById("playlist").value;
		myplaylist = playlist_array;
		
		//myplaylist = stringTo2DArray(myplaylist);
		
		for(i = 0; i < myplaylist.length; i++) {
			
			// check where we have the clipID (which is being played) in the playlist 	
			
			if(document.getElementById("playlist_clip_id").value == myplaylist[i][0]) {
				
				// we check if we have next clip in the playlist after the currently playing clip
				var j = i + 1;
				
				if(j <= myplaylist.length - 1) {
					
					var title = myplaylist[j][1]; // title of the immediate next clip in the playlist
					var duration = myplaylist[j][2]; // duration of the immediate next clip in the playlist
								
					next_clips += title+" ("+duration+") ";
					
				}
				
				j++;
				
				if(j <= myplaylist.length - 1) {
					
					var title = myplaylist[j][1]; // title of the immediate next clip in the playlist
					var duration = myplaylist[j][2]; // duration of the immediate next clip in the playlist
								
					next_clips += title+" ("+duration+") ";
					
				}
				
				break;
				
			} // we found the clip in the playlist 
			
		}

		if(next_clips.length > 0) { // if we have next clips to display
			
			thisMovie("flashradio").updateNextClips(next_clips);
			
		}
		
	}
		
}


// this function is maybe temporary to close the search table 

function closeSearchTable() {
	
	document.getElementById("search_results").innerHTML = "";
	
	document.getElementById("Erhverv_table").style.top = "-30px";
		
	document.getElementById("Politik_table").style.top = "-30px";
	
	document.getElementById("Nyheder_table").style.top = "-30px";
	
	document.getElementById("Magasinprogrammer_table").style.top = "-30px";			
	
	document.getElementById("Børs og Valuta_table").style.top = "-30px";
	
	document.getElementById("Forbrug_table").style.top = "-30px";
	
	document.getElementById("Øvrige_table").style.top = "-30px";
	
	
}


// this is a helper function which converts a string separated with commas into a 2D array

function stringTo2DArray(string) {
	
	// we split the string around , 
	
	// if the string is not empty
	
	if(string.length > 0) { 
	
	var myarray = string.split(",");
		
	// now we loop over the array to convert it into a 2D array
	var count = 0;
	
	var length_of_array = myarray.length;
	
	var size = length_of_array / 5; // since we have chunks of 5, so we divide on 5 to get the length of the 2D array to store the data
		
	if(myarray.length > 0) {
	
	var DATA = new Array();
	
	for(i = 0; i < myarray.length; ) {
		
		DATA[count] = new Array(5);
		
		DATA[count][0] = myarray[i];
		DATA[count][1] = myarray[i+1];
		DATA[count][2] = myarray[i+2];
		DATA[count][3] = myarray[i+3];
		DATA[count][4] = myarray[i+4];
		
		count++;
		
		i+=5;
		
		}
	
	}
	
	} else 
		
		var DATA = new Array(0);
	
		
		
	return DATA;
	
}

// this function is the controller for populating all the categories 

function populateAllCategories() {

	populateCategory("Erhverv", 1);
	populateCategory("Politik", 1);
	populateCategory("Forbrug", 1);
	populateCategory("Nyheder", 1);
	populateCategory("Øvrige", 1);
	//populateCategory("Sport", 1);
	populateCategory("Magasinprogrammer", 1);
	populateCategory("Børs og Valuta", 1);
	
	
}
 
// this function is responsible for populating a category with the data from the 2D array

function populateCategory(category, page) {
	
	// when we fetch the category we need to make a lookup on the corresponding category array to fetch the data
	
	switch(category) {
		
		case "Erhverv" : arr = category_array_Erhverv; break;
		case "Politik" : arr = category_array_Politik; break;
		case "Forbrug" : arr = category_array_Forbrug; break;
		case "Øvrige"  : arr = category_array_Øvrige; break;
		case "Magasinprogrammer" : arr = category_array_Magasinprogrammer; break;
		case "Børs og Valuta" : arr = category_array_Børs; break;
		case "Nyheder" : arr = category_array_Nyheder; break;
		
	}
	
	//var arr =  document.getElementById(category).value;
	
	//arr = stringTo2DArray(arr);
			
	// we calculate the start offset depending on the page <we change the number of records for Erhverv and Politik>

	var offset_to_begin = 3;
	
	if(category == "Erhverv" || category == "Politik")
		//offset_to_begin = 7;
		offset_to_begin = 6;	
	else if(category == "Nyheder")	{
		offset_to_begin = 1;
	}
		
			
	//var offset_to_begin = (category == "Erhverv" || category == "Politik") ? 7 : 3;
	
	offset = page * offset_to_begin - offset_to_begin;

	size = arr.length; // we need to check if the offset is within the length of the array
		
	//CONTENT_DIR = "http://front1.xstream.dk/jpradio/content/"; // the path has been specified here
	
	// clear the innerHTML before loading the new data
		
	// since Nyhder is an exclusively different category so we need to manage listing lil differently in it :)
	
		document.getElementById("title_"+category+"_1").innerHTML = "&nbsp;";
		document.getElementById("buttons_"+category+"_1").innerHTML = "&nbsp;";
		document.getElementById("length_"+category+"_1").innerHTML = "&nbsp;";
		document.getElementById("desc_"+category+"_1").innerHTML = "&nbsp;";
	
		if(category != "Nyheder") { // just have 1 record to disolay at a time for news 
		
		document.getElementById("title_"+category+"_2").innerHTML = "&nbsp;";
		document.getElementById("buttons_"+category+"_2").innerHTML = "&nbsp;";
		document.getElementById("length_"+category+"_2").innerHTML = "&nbsp;";
		document.getElementById("desc_"+category+"_2").innerHTML = "&nbsp;";
	
		document.getElementById("title_"+category+"_3").innerHTML = "&nbsp;";
		document.getElementById("buttons_"+category+"_3").innerHTML = "&nbsp;";
		document.getElementById("length_"+category+"_3").innerHTML = "&nbsp;";
		document.getElementById("desc_"+category+"_3").innerHTML = "&nbsp;";
		
		}
	
		if(category == "Erhverv" || category == "Politik") {
			
			document.getElementById("title_"+category+"_4").innerHTML = "&nbsp;";
			document.getElementById("buttons_"+category+"_4").innerHTML = "&nbsp;";
			document.getElementById("length_"+category+"_4").innerHTML = "&nbsp;";
			document.getElementById("desc_"+category+"_4").innerHTML = "&nbsp;";
		
			document.getElementById("title_"+category+"_5").innerHTML = "&nbsp;";
			document.getElementById("buttons_"+category+"_5").innerHTML = "&nbsp;";
			document.getElementById("length_"+category+"_5").innerHTML = "&nbsp;";
			document.getElementById("desc_"+category+"_5").innerHTML = "&nbsp;";
		
			document.getElementById("title_"+category+"_6").innerHTML = "&nbsp;";
			document.getElementById("buttons_"+category+"_6").innerHTML = "&nbsp;";
			document.getElementById("length_"+category+"_6").innerHTML = "&nbsp;";
			document.getElementById("desc_"+category+"_6").innerHTML = "&nbsp;";

			//document.getElementById("title_"+category+"_7").innerHTML = "&nbsp;";
			//document.getElementById("buttons_"+category+"_7").innerHTML = "&nbsp;";
			//document.getElementById("length_"+category+"_7").innerHTML = "&nbsp;";
			//document.getElementById("desc_"+category+"_7").innerHTML = "&nbsp;";
			
			
		}
		
		
	///////////////////////	
	
	// we check the category and change the color of the text to display in this category box
	
	
	var playlist_text_category;
	
	switch (category) {
		
		case "Erhverv" : playlist_text_category = "playlist_text_Erhverv" ; break;
		case "Politik" : playlist_text_category = "playlist_text_Politik" ; break;
		case "Forbrug" : playlist_text_category = "playlist_text_Forbrug" ; break;
		case "Indland" : playlist_text_category = "playlist_text_Indland" ; break;
		case "Øvrige" : playlist_text_category = "playlist_text_Kultur" ; break;
		case "Sport" : playlist_text_category = "playlist_text_Sport" ; break;
		case "Magasinprogrammer" : playlist_text_category = "playlist_text_Magasinprogrammer" ; break;
		case "Børs og Valuta" : playlist_text_category = "playlist_text_Bors" ; break;
		case "Nyheder" : playlist_text_category = "playlist_text_Nyheder" ; break;

	}
	
	// we check and strip the title and info if it is greater than a certain set length
	
	var title_length = document.getElementById("title_length").value;
	var desc_length = document.getElementById("desc_length").value;
	
   	if(offset <= arr.length - 1) { 			
   			
   		title = (arr[offset][1].length > title_length) ? arr[offset][1].substring(0, title_length)+"..." : arr[offset][1];
   			
   		desc = (arr[offset][3].length > desc_length) ? arr[offset][3].substring(0, desc_length)+"..." : arr[offset][3];
	
   		// as the format is little bit different so we have a choice here 
   		
   		if(category == "Nyheder") {

   			if(desc.length == 0)
   				desc = "<br>&nbsp;";
   			
	   		document.getElementById("title_"+category+"_1").innerHTML = '<span class="'+playlist_text_category+'" onmouseover="handCursor(this);" onclick="playsingleclip('+arr[offset][0]+');"><strong>'+html_entity_decode(title)+'</strong></span>';
			document.getElementById("buttons_"+category+"_1").innerHTML = "<a href=\"#\" onclick=\"addtoplaylist("+arr[offset][0]+"); return false;\"><img src=\"images/page/plus.gif\" border=0 alt=\"Klik her for at tilføje klippet til din playliste\" title=\"Klik her for at tilføje klippet til din playliste\"></a> <a href=\"filedownload.php?title="+title+"&file="+arr[offset][4]+"\" onMouseover=\"blurURL();\"><img src=\"images/page/download.gif\" border=0 alt=\"klik her for at downloade klippet som mp3\" title=\"klik her for at downloade klippet som mp3\"></a>";
			if(arr[offset][5].indexOf("1999") == -1)
				document.getElementById("date_"+category+"_1").innerHTML = '<span class="'+playlist_text_category+'">'+arr[offset][5]+'</span>';
			else 
				document.getElementById("date_"+category+"_1").innerHTML = '<span class="'+playlist_text_category+'">&nbsp;</span>';
				
			document.getElementById("desc_"+category+"_1").innerHTML = '<span class="'+playlist_text_category+'">'+html_entity_decode(desc)+'</span>';
   			document.getElementById("length_"+category+"_1").innerHTML = '<img src="images/page/speaker_icon.png" align="absmiddle" onmouseover="handCursor(this);" onclick="playsingleclip('+arr[offset][0]+');"> &nbsp;&nbsp;&nbsp;<span class="'+playlist_text_category+'"><strong><span onmouseover="handCursor(this);" onclick="playsingleclip('+arr[offset][0]+');">Hør indslag</span></strong> ('+arr[offset][2]+')</span>';
			
   			
   		} else {
   			
	   		document.getElementById("title_"+category+"_1").innerHTML = '<span class="'+playlist_text_category+'" onmouseover="handCursor(this);" onclick="playsingleclip('+arr[offset][0]+');"><strong>'+html_entity_decode(title)+'</strong></span>';
			document.getElementById("buttons_"+category+"_1").innerHTML = "<a href=\"#\" onclick=\"addtoplaylist("+arr[offset][0]+"); return false;\"><img src=\"images/page/plus.gif\" border=0 alt=\"Klik her for at tilføje klippet til din playliste\" title=\"Klik her for at tilføje klippet til din playliste\"></a> <a href=\"filedownload.php?title="+title+"&file="+arr[offset][4]+"\" onMouseover=\"blurURL();\"><img src=\"images/page/download.gif\" border=0 alt=\"klik her for at downloade klippet som mp3\" title=\"klik her for at downloade klippet som mp3\"></a>";
			document.getElementById("length_"+category+"_1").innerHTML = '<span class="'+playlist_text_category+'">Længde '+arr[offset][2]+'</span>';
			document.getElementById("desc_"+category+"_1").innerHTML = '<span class="'+playlist_text_category+'">'+html_entity_decode(desc)+'</span>';
		
   		}
		
   	}
   	
   	// since news has 1 record  on the view
   	
   	if(category != "Nyheder") {
   	
	   	if(++offset <= arr.length - 1) { 		
	
	   		title = (arr[offset][1].length > title_length) ? arr[offset][1].substring(0, title_length)+"..." : arr[offset][1];
	   		desc = (arr[offset][3].length > desc_length) ? arr[offset][3].substring(0, desc_length)+"..." : arr[offset][3];
	   	
			document.getElementById("title_"+category+"_2").innerHTML = '<span class="'+playlist_text_category+'" onmouseover="handCursor(this);" onclick="playsingleclip('+arr[offset][0]+');"><strong>'+html_entity_decode(title)+'</strong></span>';
			document.getElementById("buttons_"+category+"_2").innerHTML = "<a href=\"#\" onclick=\"addtoplaylist("+arr[offset][0]+"); return false;\"><img src=\"images/page/plus.gif\" border=0 alt=\"Klik her for at tilføje klippet til din playliste\" title=\"Klik her for at tilføje klippet til din playliste\"></a> <a href=\"filedownload.php?title="+title+"&file="+arr[offset][4]+"\"><img src=\"images/page/download.gif\" border=0 alt=\"klik her for at downloade klippet som mp3\" title=\"klik her for at downloade klippet som mp3\"></a>";
			document.getElementById("length_"+category+"_2").innerHTML = '<span class="'+playlist_text_category+'">Længde '+arr[offset][2]+'</span>';
			document.getElementById("desc_"+category+"_2").innerHTML = '<span class="'+playlist_text_category+'">'+html_entity_decode(desc)+'</span>';
		
	   	}
	   	
	   	if(++offset <= arr.length - 1) { 		
	
	   		title = (arr[offset][1].length > title_length) ? arr[offset][1].substring(0, title_length)+"..." : arr[offset][1];
	   		desc = (arr[offset][3].length > desc_length) ? arr[offset][3].substring(0, desc_length)+"..." : arr[offset][3];
	   		
			document.getElementById("title_"+category+"_3").innerHTML = '<span class="'+playlist_text_category+'" onmouseover="handCursor(this);" onclick="playsingleclip('+arr[offset][0]+');"><strong>'+html_entity_decode(title)+'</strong></span>';
			document.getElementById("buttons_"+category+"_3").innerHTML = "<a href=\"#\" onclick=\"addtoplaylist("+arr[offset][0]+"); return false;\"><img src=\"images/page/plus.gif\" border=0 alt=\"Klik her for at tilføje klippet til din playliste\" title=\"Klik her for at tilføje klippet til din playliste\"></a> <a href=\"filedownload.php?title="+title+"&file="+arr[offset][4]+"\"><img src=\"images/page/download.gif\" border=0 alt=\"klik her for at downloade klippet som mp3\" title=\"klik her for at downloade klippet som mp3\"></a>";
			document.getElementById("length_"+category+"_3").innerHTML = '<span class="'+playlist_text_category+'">Længde '+arr[offset][2]+'</span>';
			document.getElementById("desc_"+category+"_3").innerHTML = '<span class="'+playlist_text_category+'">'+html_entity_decode(desc)+'</span>';
		
	   	}
   	
   	}
  
   	// we check if we have category Politik or Erhverv 
   	
   	if(category == "Erhverv" || category == "Politik") {
   		
	   	if(++offset <= arr.length - 1) { 		
	
	   		title = (arr[offset][1].length > title_length) ? arr[offset][1].substring(0, title_length)+"..." : arr[offset][1];
	   		desc = (arr[offset][3].length > desc_length) ? arr[offset][3].substring(0, desc_length)+"..." : arr[offset][3];

			document.getElementById("title_"+category+"_4").innerHTML = '<span class="'+playlist_text_category+'" onmouseover="handCursor(this);" onclick="playsingleclip('+arr[offset][0]+');"><strong>'+html_entity_decode(title)+'</strong></span>';
			document.getElementById("buttons_"+category+"_4").innerHTML = "<a href=\"#\" onclick=\"addtoplaylist("+arr[offset][0]+"); return false;\"><img src=\"images/page/plus.gif\" border=0 alt=\"Klik her for at tilføje klippet til din playliste\" title=\"Klik her for at tilføje klippet til din playliste\"></a> <a href=\"filedownload.php?title="+title+"&file="+arr[offset][4]+"\"><img src=\"images/page/download.gif\" border=0 alt=\"klik her for at downloade klippet som mp3\" title=\"klik her for at downloade klippet som mp3\"></a>";
			document.getElementById("length_"+category+"_4").innerHTML = '<span class="'+playlist_text_category+'">Længde '+arr[offset][2]+'</span>';
			document.getElementById("desc_"+category+"_4").innerHTML = '<span class="'+playlist_text_category+'">'+html_entity_decode(desc)+'</span>';
		
	   	}
	   	
	   	if(++offset <= arr.length - 1) { 		
	
	   		title = (arr[offset][1].length > title_length) ? arr[offset][1].substring(0, title_length)+"..." : arr[offset][1];
	   		desc = (arr[offset][3].length > desc_length) ? arr[offset][3].substring(0, desc_length)+"..." : arr[offset][3];
		
			document.getElementById("title_"+category+"_5").innerHTML = '<span class="'+playlist_text_category+'" onmouseover="handCursor(this);" onclick="playsingleclip('+arr[offset][0]+');"><strong>'+html_entity_decode(title)+'</strong></span>';
			document.getElementById("buttons_"+category+"_5").innerHTML = "<a href=\"#\" onclick=\"addtoplaylist("+arr[offset][0]+"); return false;\"><img src=\"images/page/plus.gif\" border=0 alt=\"Klik her for at tilføje klippet til din playliste\" title=\"Klik her for at tilføje klippet til din playliste\"></a> <a href=\"filedownload.php?title="+title+"&file="+arr[offset][4]+"\"><img src=\"images/page/download.gif\" border=0 alt=\"klik her for at downloade klippet som mp3\" title=\"klik her for at downloade klippet som mp3\"></a>";
			document.getElementById("length_"+category+"_5").innerHTML = '<span class="'+playlist_text_category+'">Længde '+arr[offset][2]+'</span>';
			document.getElementById("desc_"+category+"_5").innerHTML = '<span class="'+playlist_text_category+'">'+html_entity_decode(desc)+'</span>';
		
	   	}
	   	
	   	if(++offset <= arr.length - 1) { 		
	
	   		title = (arr[offset][1].length > title_length) ? arr[offset][1].substring(0, title_length)+"..." : arr[offset][1];
	   		desc = (arr[offset][3].length > desc_length) ? arr[offset][3].substring(0, desc_length)+"..." : arr[offset][3];
		
			document.getElementById("title_"+category+"_6").innerHTML = '<span class="'+playlist_text_category+'" onmouseover="handCursor(this);" onclick="playsingleclip('+arr[offset][0]+');"><strong>'+html_entity_decode(title)+'</strong></span>';
			document.getElementById("buttons_"+category+"_6").innerHTML = "<a href=\"#\" onclick=\"addtoplaylist("+arr[offset][0]+"); return false;\"><img src=\"images/page/plus.gif\" border=0 alt=\"Klik her for at tilføje klippet til din playliste\" title=\"Klik her for at tilføje klippet til din playliste\"></a> <a href=\"filedownload.php?title="+title+"&file="+arr[offset][4]+"\"><img src=\"images/page/download.gif\" border=0 alt=\"klik her for at downloade klippet som mp3\" title=\"klik her for at downloade klippet som mp3\"></a>";
			document.getElementById("length_"+category+"_6").innerHTML = '<span class="'+playlist_text_category+'">Længde '+arr[offset][2]+'</span>';
			document.getElementById("desc_"+category+"_6").innerHTML = '<span class="'+playlist_text_category+'">'+html_entity_decode(desc)+'</span>';
		
	   	}
   		
	   	/*if(++offset <= arr.length - 1) { 		
			
	   		title = (arr[offset][1].length > title_length) ? arr[offset][1].substring(0, title_length)+"..." : arr[offset][1];
	   		desc = (arr[offset][3].length > desc_length) ? arr[offset][3].substring(0, desc_length)+"..." : arr[offset][3];
			
			document.getElementById("title_"+category+"_7").innerHTML = '<span class="'+playlist_text_category+'" onmouseover="handCursor(this);" onclick="playsingleclip('+arr[offset][0]+');"><strong>'+html_entity_decode(title)+'</strong></span>';
			document.getElementById("buttons_"+category+"_7").innerHTML = "<a href=\"#\" onclick=\"addtoplaylist("+arr[offset][0]+"); return false;\"><img src=\"images/page/plus.gif\" border=0 alt=\"Klik her for at tilføje klippet til din playliste\" title=\"Klik her for at tilføje klippet til din playliste\"></a> <a href=\"filedownload.php?title="+title+"&file="+arr[offset][4]+"\"><img src=\"images/page/download.gif\" border=0 alt=\"klik her for at downloade klippet som mp3\" title=\"klik her for at downloade klippet som mp3\"></a>";
			document.getElementById("length_"+category+"_7").innerHTML = '<span class="'+playlist_text_category+'">Længde '+arr[offset][2]+'</span>';
			document.getElementById("desc_"+category+"_7").innerHTML = '<span class="'+playlist_text_category+'">'+html_entity_decode(desc)+'</span>';
		
	   	}*/
	  
   	}
   	
   	
   	
   	// we calculate side x of x here where first x is the page and the second x is the total pages
   	
   	var division_factor = 3; 
   	
   	if(category == "Erhverv" || category == "Politik")
   		//division_factor = 7;
   		division_factor = 6;
   	else if(category == "Nyheder") 
   		division_factor = 1;
   	
   	
   	//var division_factor = (category == "Erhverv" || category == "Politik") ? 7 : 3;
   	
   	total_pages = Math.ceil(arr.length / division_factor);
   	
   	total_pages = (total_pages == 0) ? 1 : total_pages;
   	
 	// display the side information
 	
 	document.getElementById("page_"+category).innerHTML = '<span class="'+playlist_text_category+'">side '+page+' / '+total_pages+'</span>';
 	
 	// we check if we have some data in the categories and then display the back button, side and forward button
 	
 	if(document.getElementById("title_"+category+"_1").innerHTML != "&nbsp;") {
 		
 		document.getElementById("navigate_"+category+"_backward").innerHTML = '<img src="images/page/backward.gif">';
 		document.getElementById("navigate_"+category+"_forward").innerHTML = '<img src="images/page/forward.gif">';
 	
 		document.getElementById(category+"_dash").style.visibility = "visible";
 		
 	} else {
 		
 		document.getElementById("navigate_"+category+"_backward").innerHTML = '';
 		document.getElementById("page_"+category).innerHTML = '';
 		document.getElementById("navigate_"+category+"_forward").innerHTML = '';
 		
 		document.getElementById(category+"_dash").style.visibility = "hidden";
 		
 	}
 	
 	
   
 	// if the page is 1 then we can go forward not backward
 	// if the page is between 1 and total_pages then we can move both ways
 	// if the page is last page which is equal to total pages then we can move backwards
 	
 	if(page == 1) {
 		
 		document.getElementById("navigate_"+category+"_backward").onclick = null;
 		
 		if(page < total_pages) {
 		
 		document.getElementById("navigate_"+category+"_forward").onclick = function() {
 			
 			populateCategory(category, 2);
 			
 			}
 		
 		} else if(page == total_pages) {
 			
 			document.getElementById("navigate_"+category+"_forward").onclick = null;
 			
 		}
 		
 	} else if(page > 1) {
 		
	 		document.getElementById("navigate_"+category+"_backward").onclick = function() {
	 			
	 			populateCategory(category, page - 1);
	 				
	 		} 	
 		
  		if(page < total_pages) { // we can go bothways
 			
	 			
 			document.getElementById("navigate_"+category+"_forward").onclick = function() {
 			
 				populateCategory(category, page + 1);
 			
 			}	
 			
 			
 		} else if(page = total_pages) { // we are on the last page
 			
	 			document.getElementById("navigate_"+category+"_forward").onclick = null;
 			
 		}
 		
 	}
 	
   	
}

// function to decode html entities 

function html_entity_decode(str) {
  var ta=document.createElement("textarea");
  ta.innerHTML=str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
  return ta.value;
}


// this function is used to make the hand cursor

function handCursor(element) {
	
	element.style.cursor = "pointer";
	
}


// this method is called to hide the original file URL in the status bar although the new browsers allow blockage of status bar message

function blurURL() {

	window.status='';

	return true;
	
}


// if we have a button in the flash player, then this method would be called from the flash itself!

function addtoplaylist(clipID) {
	
	// this is one of the methods to be called from the player to add a clip to the playlist
	// clipID is the id of the clip to be added to the playlist
	
	// we add the clipID in the playlist and then while drawing the playlist we make use of this hidden variable 

	// -> replace var myplaylist = document.getElementById("playlist").value;
	var myplaylist = playlist_array;
	
	// we first convert the playlist into 2D array and then check if the id exists in the array
	// if it exists, then we dont add again! obviously and if it doesnt, then we push it into the 
	// 2D array and set the playlist

	//myplaylist = stringTo2DArray(myplaylist);
	
	// check if we have the id in the array now, if we dont have then we add it into the array and set the playlist
	
	if(!IDExists(myplaylist, clipID)) {
		
		// if the id doesnt exists, then we add the id and call the drawPlayList
		ajaxRequest(myplaylist, clipID, "fetchClipDetails"); // this would result in fetching the details of the clipID and adding to the playlist
		
	} else {

		// if we find the clipID we can check on which page it is and move to that page
		
		var count = 0;
		
		for(i = 0; i < myplaylist.length; i++) {
			
			count++;
			
			if(myplaylist[i][0] == clipID) 
				break;	
			
		}
		
		var this_clip_page = Math.ceil(count / 4);
			
		drawPlayList(this_clip_page);
		
	}
	
}

// this function searches if the id exists in the 2D array

function IDExists(myplaylist, clipID) {
	
	for(i = 0; i < myplaylist.length; i++) {
		
		// as id would be on the first index, so we check the first index
		if(myplaylist[i][0] == clipID)
			return true;
		
	}
	
	return false;
	
}


// this function would be responsible for drawing the playlist
// it involves looking at the contents of the playlist and the page which is currently to be shown
// page should be passed to draw the current page of the playlist whereas playlist is global info

function drawPlayList(page) {
	
	// we check if after deleting a clip from the playlist, we have a reduced list, then we reduce the page 
	
	// explode the playlist into an array
	
	// replace this var myplaylist = document.getElementById("playlist").value;
	var myplaylist = playlist_array;
	
	// myplaylist = stringTo2DArray(myplaylist);
		
	var page_first_index = page * 4 - 4;
	
	if(page_first_index >= myplaylist.length)
			page--;
			
	// we draw the playlist depending on the page we are at the moment
	// the page information would be set the first time the page is loaded
	// page would be 0 from as the reference point 
	
	// we check which page is loaded and accordingly fetch the records from the 2D playlist array
	
	// first up we clear the items from the playlist for some new items
	
	//$html.= "<tr><td width=\"60%\" id=\"playlist_title_1\">title</td><td><span id=\"playlist_play_1\">Afspil</span> | <span id=\"playlist_delete_1\">Slet</span></td></tr>";

	for(i = 1; i <= 4; i++) {

		
		document.getElementById("playlist_title_"+i).innerHTML = "&nbsp;";
		document.getElementById("playlist_play_"+i).innerHTML = "&nbsp;";
		document.getElementById("playlist_delete_"+i).innerHTML = "&nbsp;";
		
	}
	
	// we hide the back and next navigation 
	
	if(myplaylist.length == 0) {
		
		document.getElementById("navigate_playlist_page").innerHTML = "";
		
		document.getElementById("playlist_back_arrow").style.visibility = "hidden";
		document.getElementById("playlist_next_arrow").style.visibility = "hidden";
				
		return;
	}
	
	offset = page * 4 - 4;
	
	// we check offset, offset + 1, offset + 2, offset + 3 which gives us the 4 elements from the playlist
	
	for(i = 1; i <= 4; i++) {
		
		if(offset <= myplaylist.length - 1) {
			
			var id = myplaylist[offset][0];
			var title = myplaylist[offset][1];
			var length = "<i>Længde</i> "+myplaylist[offset][2];
			
			document.getElementById("playlist_title_"+i).innerHTML = '<span onmouseover="handCursor(this);" onclick="playclip('+id+');">'+title+'</span><br/>'+length
			document.getElementById("playlist_play_"+i).innerHTML = "<a href=\"#\" onclick=\"playclip("+id+"); return false;\" class=\"playlist_text_link\">Afspil</a> &nbsp;&nbsp;&nbsp;&nbsp;|";
			document.getElementById("playlist_delete_"+i).innerHTML = "<a href=\"#\" onclick=\"deleteclipfromplaylist("+id+"); return false;\" class=\"playlist_text_link\">Slet</a>";
			
			// we specify the ids so that later we can map the ids and get the index number of the row in the playlist

			document.getElementById("playlist_id_"+i).value = id;		
			
		}
		
		offset++;
			
	}
	
	// depending on the page we set the things
	

   	// we calculate side x of x here where first x is the page and the second x is the total pages
   	
   	total_pages = Math.ceil(myplaylist.length / 4);
   	
   	total_pages = (total_pages == 0) ? 1 : total_pages;
   	
 	// display the side information
 	
 	document.getElementById("navigate_playlist_page").innerHTML = "side "+page+" / "+total_pages;
   
 	
 	// if the page is 1 then we can go forward not backward
 	// if the page is between 1 and total_pages then we can move both ways
 	// if the page is last page which is equal to total pages then we can move backwards

 	// visible the navigation buttons
 	
 	if(document.getElementById("playlist_back_arrow").style.visibility == "hidden")
 		document.getElementById("playlist_back_arrow").style.visibility = "visible";
 	
 	if(document.getElementById("playlist_next_arrow").style.visibility == "hidden")
 		document.getElementById("playlist_next_arrow").style.visibility = "visible";
 	
 	if(page == 1) {
 		 		
 		document.getElementById("navigate_playlist_backward").onclick = null;
 		
 		if(page < total_pages) {
 		
 		document.getElementById("navigate_playlist_forward").onclick = function() {
 			
 			drawPlayList(2);
 			
 			}
 		
 		} else if(page == total_pages) {
 			
 			document.getElementById("navigate_playlist_forward").onclick = null;
 			
 		}
 		
 	} else if(page > 1) {
 		
	 		document.getElementById("navigate_playlist_backward").onclick = function() {
	 			
	 			drawPlayList(page - 1);
	 				
	 		} 	
 		
  		if(page < total_pages) { // we can go bothways
 			
	 			
 			document.getElementById("navigate_playlist_forward").onclick = function() {
 			
 				drawPlayList(page + 1);
 			
 			}	
 			
 			
 		} else if(page = total_pages) { // we are on the last page
 			
	 			document.getElementById("navigate_playlist_forward").onclick = null;
 			
 		}
 		
 	}	
	
	
	/*if(offset <= myplaylist.length - 1) {
		
		var id = myplaylist[offset][0];
		var title = myplaylist[offset][1];
		var length = "Længde "+myplaylist[offset][2];
		
		document.getElementById("playlist_title_1").innerHTML = title+"<br/>"+length;
		document.getElementById("playlist_play_1").innerHTML = "<a href=\"#\" onclick=\"playclip("+id+"); return false;\">Afspil</a>";
		document.getElementById("playlist_delete_1").innerHTML = "<a href=\"#\" onclick=\"deleteclipfromplaylist("+id+"); return false;\">Slet</a>";
	
	}
	
	if(++offset <= myplaylist.length - 1) {
		
		var id = myplaylist[offset][0];
		var title = myplaylist[offset][1];
		var length = "Længde "+myplaylist[offset][2];
		
		document.getElementById("playlist_title_2").innerHTML = title+"<br/>"+length;
		document.getElementById("playlist_play_2").innerHTML = "<a href=\"#\" onclick=\"playclip("+id+"); return false;\">Afspil</a>";
		document.getElementById("playlist_delete_2").innerHTML = "<a href=\"#\" onclick=\"deleteclipfromplaylist("+id+"); return false;\">Slet</a>";
	
	}

	if(++offset <= myplaylist.length - 1) {
		
		var id = myplaylist[offset][0];
		var title = myplaylist[offset][1];
		var length = "Længde "+myplaylist[offset][2];
		
		document.getElementById("playlist_title_3").innerHTML = title+"<br/>"+length;
		document.getElementById("playlist_play_3").innerHTML = "<a href=\"#\" onclick=\"playclip("+id+"); return false;\">Afspil</a>";
		document.getElementById("playlist_delete_3").innerHTML = "<a href=\"#\" onclick=\"deleteclipfromplaylist("+id+"); return false;\">Slet</a>";
	
	}

	if(++offset <= myplaylist.length - 1) {
		
		var id = myplaylist[offset][0];
		var title = myplaylist[offset][1];
		var length = "Længde "+myplaylist[offset][2];
		
		document.getElementById("playlist_title_4").innerHTML = title+"<br/>"+length;
		document.getElementById("playlist_play_4").innerHTML = "<a href=\"#\" onclick=\"playclip("+id+"); return false;\">Afspil</a>";
		document.getElementById("playlist_delete_4").innerHTML = "<a href=\"#\" onclick=\"deleteclipfromplaylist("+id+"); return false;\">Slet</a>";
	
	} */
	
	
	
}

// this function is called when the clip in the playlist is clicked for playing
// this function is to pass the clipID to the flash object

function playclip(clipID) {
	
	// we set the playlist_clip_id to this clip 
	
	document.getElementById("playlist_clip_id").value = clipID;
	
	
	// we check if we have the media player and its playing we stop it 
	
	if(document.player1 != null) {
		
		document.player1.controls.stop();
	
	}
	
	
	// we load the player if player_loaded is not set

	if(!player_loaded) {
		
		document.getElementById("flashradio").innerHTML = document.getElementById("flash_object").value;
		
		loadPlayer(); // load the swf player 
		
		document.getElementById("flashradio").style.position = "relative";
		document.getElementById("flashradio").style.left = "12px";
		document.getElementById("flashradio").style.top = "-26px";
		
		
	}
	
	
	// we make a request to fetch the categories of the clip given the clipID
	
	ajaxRequest('1', clipID, "fetchClipCategories"); // first field set to 1 indicates that we need to display the next clip titles to be played as well

	// we move this code to the ajaxrequest as now we need to pass the title and the next 2 titles to the flash object as well
	
	/*var FRONT_DOMAIN = document.getElementById("FRONT_DOMAIN").value;

	// set the playlist clip id hidden variable
	document.getElementById("playlist_clip_id").value = clipID;
	
	var xmlurl = FRONT_DOMAIN+"xmlgenerator.php?id="+clipID+"&choice=playlist";
	
	sendToActionScript(xmlurl); // set the clipID and the choice to playlist as this clip is being played from the playlist*/
	
}

// this function is called when the clip is to be played from somewhere else than playlist

function playsingleclip(clipID) {
	
	// we clear the playlist_clip_id 
	
	document.getElementById("playlist_clip_id").value = "";
	
	// check if we have flash player loaded 
	 
	//document.getElementById("flashradio").innerHTML = document.getElementById("flash_object").value;
	
	// we check if we have the media player and its playing we stop it 
	
	if(document.player1 != null) {
	
		document.player1.controls.stop();
	
	}
	
	
	// we load the player if player_loaded is not set
	
	if(!player_loaded) {
		
		//document.getElementById("flashradio").innerHTML = document.getElementById("flash_object").value;	
		
		loadPlayer(); // load the swf player 

		document.getElementById("flashradio").style.position = "relative";
		document.getElementById("flashradio").style.left = "12px";
		document.getElementById("flashradio").style.top = "-26px";
		
	}
	
	
	
	
	// we make a request to fetch the categories of the clip given the clipIsD
	ajaxRequest('0', clipID, "fetchClipCategories"); // first field set to 0 indicates that we do not need to display the next clip titles to be played as well
	
	// remove the next clips from the cliplist if any
	
	// -> handled in flash object document.getElementById("next_clips").innerHTML = "";	

	// we move the code below to ajaxrequest as now the title has to be displayed in the flash player itsself
	
	/*var FRONT_DOMAIN = document.getElementById("FRONT_DOMAIN").value;
	
	var xmlurl = FRONT_DOMAIN+"xmlgenerator.php?id="+clipID+"&choice=single";
	
	sendToActionScript(xmlurl); // set the clipID and the choice to single as single clip is being played here */
	
	// clear the autoplay timeout if set :) this is temp till we dont have the player 
	//clearTimeout(auto_play_timer); 
	
	// remove all the white backgrounds if any

	for(i = 1; i <= 4; i++) ;
		//document.getElementById("playlist_title_"+i).style.background = document.bgColor;
		
}

// this function is used to load flash player 

function loadPlayer() {

	var flashvars = {};
	var params = {};
	params.wmode = "window";
	params.allowfullscreen = "true";
	params.bgcolor = "#FFFFFF";
	params.allowscriptaccess = "always";
	var attributes = {};
	var so = swfobject.embedSWF("radio.swf", "flashradio", "596", "114", "9.0.28", false, flashvars, params, attributes);
	
	player_loaded = true;

}

// this is a temp method for checking if we swap from html to flash player

function swap() {
	
	//alert("i am clicked");

	document.getElementById("flashradio").innerHTML = "";
	
	loadPlayer();

	document.getElementById("flashradio").style.position = "relative";
	document.getElementById("flashradio").style.left = "12px";
	document.getElementById("flashradio").style.top = "-26px";
	
	
	
}

// this function is used to delete a clip from the playlist 
// we call another function which is used to update the next two clip titles below the player

function deleteclipfromplaylist(clipID) {
	
	// replace this var myplaylist = document.getElementById("playlist").value;
	var myplaylist = playlist_array;
	
	//myplaylist = stringTo2DArray(myplaylist);
	
		var count = 0;
		
		for(i = 0; i < myplaylist.length; i++) {
			
			count++;
			
			if(myplaylist[i][0] == clipID) 
				break;	
			
		}
		
		// we set the page which we need to draw by calculating the clipID location
		
		var this_clip_page = Math.ceil(count / 4);
	
		for(i = 0; i < myplaylist.length; i++) {
		
		if(myplaylist[i][0] == clipID) {  // if we find the clipID just  remove it from the array
			
			// if this is the same ID as in the <playlist clip id>, then we clear the hidden variable
		
			var playlist_clip_id = document.getElementById("playlist_clip_id").value; 
			
						
			//alert("playlist_clip_id :: "+playlist_clip_id);
			
			// if this is the clip which is currently being played, then we dont delete it from the playlist
			
			if(playlist_clip_id == clipID) {
				
				alert("Du kan ikke slette dette klip fra playlisten, da det i øjeblikket afspilles");
				//alert("You cannot delete currently played clip");
				return ;
				
			} 
			
			// we check if the clipID has the clip played above it and then we update the next 2 titles accordingly
			//updateNextPlayingTitles(clipID);
			
			
			////////////////////////// script to update the next two titles ///////////////////
			
			var next_clips = "";
			
				
			/*if(playlist_clip_id.length == 0) {
				
				// if we dont have anything in the playlist clip id
				myplaylist.splice(i, 1);
				document.getElementById("playlist").value = myplaylist;
				
				var expiration_days = document.getElementById("COOKIE_EXPIRATION").value;
				
				Set_Cookie( "playlist", document.getElementById("playlist").value, expiration_days, "/", "", "" );
				
				drawPlayList(this_clip_page);
				
			}*/
			
			if(((i > 0 && (myplaylist[i-1][0] == document.getElementById("playlist_clip_id").value)) || (i > 1 && myplaylist[i-2][0] == document.getElementById("playlist_clip_id").value)) && document.getElementById("playlist_clip_id").value.length > 0) { // we need to update the next two clips displayed 
				
				//alert("in this range condition");
					
				// we need to make the next 2 clips as the next to next clip and the clip after that
				// so the immediate next clip is dropped 
							//alert("within range");
						
								
						//if(playlist[i][0] == clipID) { // if we find the clip ID in the playlist check for next clips in the playlist
							if(i > myplaylist.length - 1) {
								
							}
							else if(i <= myplaylist.length - 1) {
								
	
								var j = 0;
								
								if(myplaylist[i-1][0] != null && myplaylist[i-1][0] == document.getElementById("playlist_clip_id").value) {
									//alert("clip is 1 far");
									j = i+1;
								}
								else if(myplaylist[i-2][0] != null && myplaylist[i-2][0] == document.getElementById("playlist_clip_id").value) {
									//alert("clip is 2 far");
									j = i-1;
								}
									
								//alert("j is :: "+j);
								
								if(j > myplaylist.length - 1) { // update with empty i guess :)
									
									//alert("is this now!");
									next_clips += " "; 
								}
								
								if(j <= myplaylist.length - 1) {
															
								var title = myplaylist[j][1]; // title of the immediate next clip in the playlist
								var duration = myplaylist[j][2]; // duration of the immediate next clip in the playlist
								
								next_clips += title+" ("+duration+") ";
								
								}
								
								if(myplaylist[i-1][0] != null && myplaylist[i-1][0] == document.getElementById("playlist_clip_id").value) {
									//alert("played clip is 1 far");
									j++;
								}
								else if(myplaylist[i-2][0] != null && myplaylist[i-2][0] == document.getElementById("playlist_clip_id").value)  {
									//alert("played clip is 2 far");
									j+=2;
								}
									
								
								if(j <= myplaylist.length - 1) {
									
									var title = myplaylist[j][1]; // title of the immediate next clip in the playlist
									var duration = myplaylist[j][2]; // duration of the immediate next clip in the playlist
									
									next_clips += title+" ("+duration+")";
									
								}
								
							}
							
						//}				
						
					

			}			
			
			//alert("down the cond");
		
			if(next_clips.length > 0) {
				
				// the next clips to be played 
				//alert("check this update");
			
				thisMovie("flashradio").updateNextClips(next_clips);
				
				//alert(next_clips);
			} 
			
			
			/////////////////////////////////////////////////////////
			
			//if(playlist_clip_id.length > 0) {
				
				myplaylist.splice(i, 1);
				playlist_array = myplaylist;
				
				var expiration_days = document.getElementById("COOKIE_EXPIRATION").value;
				
				//var expiration_days = document.getElem			
				//Set_Cookie( "playlist", playlist_array, expiration_days, "/", "", "" );
				
				jar = new CookieJar({
				expires:expiration_days,   // seconds
				path: '/'
				});
				 
				cook_cookie = {playlist: playlist_array};
				 
				jar.put('cookie_playlist', cook_cookie);
				
			//}
			
			if(playlist_clip_id == clipID) 
				document.getElementById("playlist_clip_id").value = "";
					
			//alert('i am here for deletion');
				
			
			
			
			break;
			
		}
			
	}

	drawPlayList(this_clip_page);

}


// this function is responsible for checking if this clip is immediately after the clip being played  
// and update the clip titles appropriately

/*function updateNextPlayingTitles(clipID) {
	
	// check if the there is a clip before this clip and if it is being played as well
	var myplaylist = document.getElementById("playlist").value;
	
	myplaylist = stringTo2DArray(myplaylist);
	
	var next_clips = "";
	
	for(k = 0; k < myplaylist.length; k++) {
		
		// check if there is a clip before this clip
		
		if(myplaylist[k][0] == clipID) {
			
			if(k > 0 && (myplaylist[k-1][0] == document.getElementById("playlist_clip_id").value)) { // we need to update the next two clips displayed 
				
				// we need to make the next 2 clips as the next to next clip and the clip after that
				// so the immediate next clip is dropped 
								
						
						//if(playlist[i][0] == clipID) { // if we find the clip ID in the playlist check for next clips in the playlist
							if(k == myplaylist.length - 1) {
								break;
							}
							else if(k <= myplaylist.length - 1) {
								
								var j = k+1;
								
								//alert("j is :: "+j);
								
								var title = myplaylist[j][1]; // title of the immediate next clip in the playlist
								var duration = myplaylist[j][2]; // duration of the immediate next clip in the playlist
								
								next_clips += title+" ("+duration+") ";
						
								j++;
								
								if(j <= myplaylist.length - 1) {
									
									var title = myplaylist[j][1]; // title of the immediate next clip in the playlist
									var duration = myplaylist[j][2]; // duration of the immediate next clip in the playlist
									
									next_clips += title+" ("+duration+")";
									
								}
								
								break;
								
							}
							
						//}				

			}  
			
		}
		
	}
	
	
	
	//alert(next_clips);
	
}*/


// this method is responsible for autoplaying the playlist
// we keep track of the id by the id of the clip being played

// this method has to be called from the flash object when the clip is played

function autoplay(clip_id_played) {

	var playlist_clip_id = document.getElementById("playlist_clip_id").value;
	
	// if the clip id is empty we start playing from start

		// check if we have some clips in the playlist
		// -> replace this var myplaylist = document.getElementById("playlist").value;
		var myplaylist = playlist_array;
		
		if(myplaylist.length == 0) 
			alert("Du skal tilføje klip til playlisten");
			//alert("Please add some clips to the playlist");
		
		else { // if we have clips in the playlist
			
			// get the 2D array of the playlist and start from the beginning of the playlist
			
			//myplaylist = stringTo2DArray(myplaylist);
			
			// if the playlist clip id is empty we start from the first clip 
			// else we match the <td #> to the clipID on it  :)
			// we get the clip id from which we need to start playing 
			
			
			
			if(playlist_clip_id.length == 0) {
				
				//document.getElementById("playlist_play_1").style.background = "#FFFFFF";
				//document.getElementById("playlist_delete_1").style.background = "#FFFFFF";
				
				//document.getElementById("playlist_title_1").style.background = "#FFFFFF";
				
				// we start from the start of the list 
				
				start_id = myplaylist[0][0];
				
			} else {
				
				// we check the ID, if we have 1, then we play the next clip
				// the ID we receive from the player would be the 1 already played
				
				// if we have the ID from the player, we play the next clip in the playlist
				
				if(clip_id_played == 0) { // this means we are coming from the click on the play playlist
					
					// we set the start id to the starting clip id on the playlist
					
					start_id = myplaylist[0][0]
						 
				} else { // if we have an ID from the player 
					
					// we get the clip id next to the ID passed in from the player
					
					for(i = 0; i < myplaylist.length; i++) {
						
						if(myplaylist[i][0] == playlist_clip_id) { // if we get the ID of the clip played from the player
							
							if(i < myplaylist.length - 1)
								start_id = myplaylist[i+1][0];
							else 
								start_id = "";
							
						}
						
					}
					
					
				}
								
			}
			
			// here we would be calculating the clips onwards
			
			document.getElementById("playlist_clip_id").value = start_id;
			
			if(start_id.length > 0) { // we have a playlist id to play
					
				// we need to check on which page is the id to be played and then move to that page
				
				// there are 4 clips per page 
				
				page = 1;
			
				for(i = 0; i < myplaylist.length; i++) {

					if(i > 0 && i % 4 == 0)  // it means page change
							page++;
						
					if(myplaylist[i][0] == start_id) 
						break;
					
				}
				
				drawPlayList(page); // draw playlist for that particular page
				
				// we remove the background color of all the clips in the current playlist
				
				//for(i = 1; i <= 4; i++) 
					//document.getElementById("playlist_title_"+i).style.background = "#CCCCCC";
					
				
				// now we check the <td #> that corresponds to this clip id and set the background color for this clip id 
				
				for(i = 1; i <= 4; i++) {
					
					if(document.getElementById("playlist_id_"+i).value == start_id) {
						
						// we got the index # to change the background of the title
						//document.getElementById("playlist_title_"+i).style.background = "#FFFFFF";
						break;
						
					}
					
					
				}
				
				//alert("start_id :: "+start_id+" playlist_clip_id :: "+document.getElementById("playlist_clip_id").value);	
				
				playclip(start_id); // this method is called with the clip id to be played
				
				//auto_play_timer = setTimeout("autoplay(1)", 4000);
				
			} else {
				
				// we clear the background of all the rows in the playlist
				
				for(i = 1; i <= 4; i++)  ;
					//document.getElementById("playlist_title_"+i).style.background = "#CCCCCC";
				
				//alert("Sorry there are no more clips to play in the playlist");
				
			}
			
		}
		
}

     function thisMovie(movieName) {
         if (navigator.appName.indexOf("Microsoft") != -1) {
             return window[movieName];
         } else {
             return document[movieName];
         }
     }
     
     var value_for_action_script;
     
     function sendToActionScript(value) { // we pass an array here which comprises of the ID and the choice
     	
		 //document.getElementById("flashradio").sendToActionScript(value);
		 //alert("element :: "+thisMovie("flashradio"));
		
		 value_for_action_script = value;
		 
		 setTimeout("sendfinally()", 500);
		  
		//if(player_loaded) 
     	 	//thisMovie("flashradio").sendToActionScript(value); // this is the place where we call the object with the clip id and choice
         
     }

     
	function sendfinally() {
		
		if(player_loaded) 
     	 	thisMovie("flashradio").sendToActionScript(value_for_action_script); // this is the place where we call the object with the clip id and choice
	
	}
     
     
     function sendToJavaScript(value) {
     	
     	// this would be the call to autoplay after the movie ends 
         alert("ActionScript sayz: " + value);
     }

// this function is called to search the clip     
     
function searchClips() {

	var clip = document.getElementById("search_jpradio").value;

	// if we do not have anything to search we return 
	if(clip.length == 0) {
	
		document.getElementById("search_results").innerHTML = "";
			
		return;
	}
	
	// if we have a clip, we fetch the values 
	ajaxRequest('', clip, 'searchClips');
	
	
}

function checkKey(evt) {
	
	var key = (window.Event) ? evt.which : evt.keyCode;
	
	if (key == 13)
		{
			searchClips();
        }
	
	
}

// this function is used to set cookie which would be used to retreive playlist information

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/

if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );

}

// this function is used to get cookie which would contain the playlist information

function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}

}		

// this function is used to delete the cookie

function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

// this method is used to initialize the playlist from the cookie if its available 

function initializePlaylist() {

	// initialize playlist from cookie
		var expiration_days = document.getElementById("COOKIE_EXPIRATION").value;
	
		jar = new CookieJar({
		expires:expiration_days,   // seconds
		path: '/'
		});
		 
		var cookie = jar.get('cookie_playlist');
	
		if(cookie != null)
			playlist_array = cookie.playlist;
	
	// simple call to drawplaylist at the moment, which would be replaced once we have the logic to convert to array
	
	drawPlayList(1);
	
	
}

// this method is used to send mail to a friend

function messageToFriend() {
	
	// we check if all the fields have been filled in by the user !
	
	//receiver_email
	// receiver_name
	// sender_email 
	// sender_name
	// besked
	var error_string = "";
	
	if(document.getElementById("receiver_email").value == "") 
		error_string += "- Din vens e-mail\n";
	if(document.getElementById("receiver_name").value == "") 
		error_string += "- Din vens navn\n";
	if(document.getElementById("sender_email").value == "") 
		error_string += "- Din e-mail\n";
	if(document.getElementById("sender_name").value == "") 
		error_string += "- Dit navn\n";
	if(document.getElementById("besked").value == "") 
		error_string += "- Besked\n";
		
	if(error_string.length > 0) {
		
		var header = "For at sende en besked til en ven skal du udfylde følgende:\n";
		
		alert(header+error_string);
		
		return false;
		
	}
		
		
	
	
	
	// we make use of ajaxRequest to send an email to the friend
	
	var details = new Array(6);
	
	details[0] = document.getElementById("receiver_email").value;
	details[1] = document.getElementById("receiver_name").value;
	details[2] = document.getElementById("sender_email").value;
	details[3] = document.getElementById("sender_name").value;
	details[4] = document.getElementById("besked").value;
	
	// check if we have an id 
	// if the player is loaded
	if(/*thisMovie("flashradio")*/ player_loaded) {
		
		// we have the player
		thisMovie("flashradio").getCurrentClipId();
	
		if(current_clip_id.length > 0) 
			details[5] = current_clip_id;
		else 
			details[5] = "XY";
		
	} else {
		
		details[5] = "XY";
		
	}
	
	ajaxRequest(details, '', 'sendToFriend');
	
	
	return false;
	
	//ajaxRequest(myplaylist, clipID, choice); 
	
}

// this is the method called to clear the message send confirmation message

function clearMessageConfirmation() {
	
	document.getElementById('message_confirmation').innerHTML = '';
	
}

// this is a window pop up to send mail to a friend

function sendToFriend() {

	var onRadio = '<DIV class=conCluster_page>';
		onRadio+= '<DIV class="conContent_page t6">';
      	onRadio+= '<H1 class="H1_page">Send til en ven <span class="Luk" onclick="closeSearchTable();" onmouseover="handCursor(this);">Luk</span></H1>';
      	onRadio+= '<FORM name="sendmailtofriend" method="post" onSubmit="return messageToFriend();">'
      	onRadio+= '<table style="width:500px; margin-left:15px;margin-right:5px;background-image:none;" border=0>';
      							onRadio+= '<tr>';
      								onRadio+= '<td width="20%">&nbsp;</td><td>&nbsp;</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify" colspan="2">Du kan sende et link til en ven ved at udfylde nedenstående.</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td width="20%">&nbsp;</td><td>&nbsp;</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Din vens e-mail:</td><td><input name="receiver_email" id="receiver_email" class="text_field" onclick="clearMessageConfirmation();"></td>';
      							onRadio+= '</tr>';	
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Din vens navn:</td><td><input name="receiver_name"  id="receiver_name"  class="text_field" onclick="clearMessageConfirmation();"></td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Din e-mail:</td><td><input name="sender_email"  id="sender_email" class="text_field" onclick="clearMessageConfirmation();"></td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Dit navn:</td><td><input name="sender_name"  id="sender_name" class="text_field" onclick="clearMessageConfirmation();"></td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Besked:</td><td><textarea name="besked"  id="besked" class="text_area" onclick="clearMessageConfirmation();"></textarea></td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td colspan=2><input type="submit" value="Send" class="form_button" style="margin-left:100px;"></td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td colspan=2 id="message_confirmation" style="position:absolute;left:100px;font-weight:bold;"></td>';
      							onRadio+= '</tr>';    							
      						onRadio+= '</table>';
      						onRadio+= '</FORM>';
      					onRadio+= '</DIV>';
      				onRadio+= '</DIV>';
	
	document.getElementById("search_results").innerHTML = onRadio;
	
				document.getElementById("Erhverv_table").style.top = "-5px";
					
				document.getElementById("Politik_table").style.top = "-5px";
				
				document.getElementById("Nyheder_table").style.top = "-5px";
				
				document.getElementById("Magasinprogrammer_table").style.top = "-5px";			
				
				document.getElementById("Børs og Valuta_table").style.top = "-5px";
				
				document.getElementById("Forbrug_table").style.top = "-5px";
				
				document.getElementById("Øvrige_table").style.top = "-5px";
	
	
	
}

// this is the function used to add the player to the website :)

function addToWebsite() {

	var onRadio = '<DIV class=conCluster_page>';
		onRadio+= '<DIV class="conContent_page t6">';
      	onRadio+= '<H1 class="H1_page">Add til website <span class="Luk" onclick="closeSearchTable();" onmouseover="handCursor(this);">Luk</span></H1>';
      	onRadio+= '<table style="width:500px; margin-left:15px;margin-right:5px;background-image:none;">';
      							onRadio+= '<tr>';
      								onRadio+= '<td>&nbsp;</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Det er muligt at tilføje vores player på dit eget website for at afspille det aktuelle klip.</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Du skal kopiere nedenstående kode stump:</td>';
      							onRadio+= '</tr>';
      						
      							var front_domain = document.getElementById("FRONT_DOMAIN").value;
      							
  								if(!player_loaded) {
  									
  								onRadio+= '<tr>'
  									onRadio+= '<td><input type="text" readonly style="WIDTH:560px;" value="<iframe src='+front_domain+'liveplayer.php width=630 height=130 scrolling=No />"></td>';								
  								onRadio+= '</tr>'
  									
  								} else if(player_loaded) {

  									// check for the ID loaded in the player
  									thisMovie("flashradio").getCurrentClipId();
  								
  								onRadio+= '<tr>'
  									onRadio+= '<td><input type="text" readonly style="WIDTH:560px;" value="<iframe src='+front_domain+'flashplayer.php?id='+current_clip_id+' width=630 height=130 scrolling=No />"></td>';								
  								onRadio+= '</tr>'
  									
  									
  								}    							 
      							
 	
      							
      							
      						onRadio+= '</table>';
      					onRadio+= '</DIV>';
      				onRadio+= '</DIV>';
	
	document.getElementById("search_results").innerHTML = onRadio;
	
				document.getElementById("Erhverv_table").style.top = "-5px";
					
				document.getElementById("Politik_table").style.top = "-5px";
				
				document.getElementById("Nyheder_table").style.top = "-5px";
				
				document.getElementById("Magasinprogrammer_table").style.top = "-5px";			
				
				document.getElementById("Børs og Valuta_table").style.top = "-5px";
				
				document.getElementById("Forbrug_table").style.top = "-5px";
				
				document.getElementById("Øvrige_table").style.top = "-5px";
	
	
	
	
}

function sendCurrentClipId(value) {

	current_clip_id	= value;

}	

// this function is called when the mouse is over the play button

function play_over(element) {
	
	element.style.cursor = "pointer";
	
}

function stop_over(element) {
	
	element.style.cursor = "pointer";
	
}

function mute_over(element) {
	
	element.style.cursor = "pointer";
	
}

// this function is called initially to adjust the volume

function adjustVolume() {
	
	
}

function volume_inc(event) {
	

	pos_x = event.offsetX?(event.offsetX):event.pageX-document.getElementById("pointer_div").offsetLeft;

    pos_y = event.offsetY?(event.offsetY):event.pageY-document.getElementById("pointer_div").offsetTop;

    // we need to check the position and then adjust the volume and the volume box
   
    if(pos_x >= 0 && pos_x <=29) {
    	
    	setBox(1);
    	
    } else if(pos_x >= 30 && pos_x <= 44) {
    	
    	setBox(2);
    	
    } else if(pos_x >= 45 && pos_x <= 59) {
    	
    	setBox(3);
    	
    } else if(pos_x >= 60 && pos_x <= 74) {
    	
    	setBox(4);
    	
    } else if(pos_x >= 75 && pos_x <= 89) {
    	
    	setBox(5);
    
    } else if(pos_x >= 90) {
    	
    	setBox(6);
    }
    	
    
	//document.getElementById("level_5").innerHTML = '<img src="images/page/box.jpg">';
	
}

// this helper function adjusts the volume box location and also the volume

function setBox(level) {
		
	for(i = 1; i <= 6; i++) {
		
		if(i == level) 
			document.getElementById("level_"+i).innerHTML = '<img src="images/page/box.jpg">';
		else 
			document.getElementById("level_"+i).innerHTML = '';
	
	}
	
	updateVolume(level - 1); // update the volume as well
	
}

// this function is targeted towards setting the volume slider for live player in iframe

function volume_inc_iframe(event) {
	
	pos_x = event.offsetX?(event.offsetX):event.pageX-document.getElementById("pointer_div").offsetLeft;
	
	pos_y = event.offsetY?(event.offsetY):event.pageY-document.getElementById("pointer_div").offsetTop;
    
    if(pos_x >= 0 && pos_x <=29) {
    	
    	// align the box as well
		document.getElementById("slider_box").style.position = "relative";
		//document.getElementById("slider_box").style.top = "48px";
		document.getElementById("slider_box").style.left = "152px";
		
    	updateVolume(0);
    	
    } else if(pos_x >= 30 && pos_x <= 44) {

		document.getElementById("slider_box").style.position = "relative";
		//document.getElementById("slider_box").style.top = "48px";
		document.getElementById("slider_box").style.left = "165px";
    	    	
    	updateVolume(1);
    	
    } else if(pos_x >= 45 && pos_x <= 59) {

    	document.getElementById("slider_box").style.position = "relative";
		//document.getElementById("slider_box").style.top = "48px";
		document.getElementById("slider_box").style.left = "178px";
    	
    	updateVolume(2);
    	
    } else if(pos_x >= 60 && pos_x <= 74) {
    	
		document.getElementById("slider_box").style.position = "relative";
		//document.getElementById("slider_box").style.top = "48px";
		document.getElementById("slider_box").style.left = "191px";
		
    	updateVolume(3);
    	
    } else if(pos_x >= 75 && pos_x <= 89) {
    	
		document.getElementById("slider_box").style.position = "relative";
		//document.getElementById("slider_box").style.top = "48px";
		document.getElementById("slider_box").style.left = "204px";
		
    	updateVolume(4);
    
    } else if(pos_x >= 90) {
    	
		document.getElementById("slider_box").style.position = "relative";
		//document.getElementById("slider_box").style.top = "48px";
		document.getElementById("slider_box").style.left = "220px";
		
    	updateVolume(5);
    	
    }
    
}

// this function is used to initialize the volume for the live player included in the iframe

function initializeVolume() {
	
	document.getElementById("slider_box").style.position = "relative";
	//document.getElementById("slider_box").style.top = "48px";
	document.getElementById("slider_box").style.left = "178px";
	
	updateVolume(2);
	
}

// this function is called from the player in the iframe

function playsingleclipiframe(clipID) {
	
	player_loaded = true;
	
	ajaxRequest('0', clipID, "fetchClipCategories"); // first field set to 0 indicates that we do not need to display the next clip titles to be played as well
	
}

function pushCategoryData(category, DATA) { // this method assigns the appropriate variable with the DATA
	
	switch (category) {
		
		case "Erhverv" : 
			category_array_Erhverv = DATA;
			//alert("Erhverv :: "+category_array_Erhverv);
		break;

		case "Politik" : 
			category_array_Politik = DATA;
			//alert(category_array_Politik);
		break;
			
		case "Magasinprogrammer" : 
			category_array_Magasinprogrammer = DATA;
			//alert(category_array_Magasinprogrammer);
		break;
		
		case "Børs og Valuta" :
			category_array_Børs = DATA;
			//alert(category_array_Børs);
		break;
		
		case "Forbrug" : 
			category_array_Forbrug = DATA;
			//alert(category_array_Forbrug);
		break;
		
		case "Øvrige" : 
			category_array_Øvrige = DATA;
			//alert(category_array_Øvrige);
		break;
		
		case "Nyheder" : 
			category_array_Nyheder = DATA;
			
		break;
		
	}
	
}

// this is the function called when Om Radio is clicked

function openOnRadioBox() {
	
	var onRadio = '<DIV class=conCluster_page>';
		onRadio+= '<DIV class="conContent_page t6">';
      	onRadio+= '<H1 class="H1_page">Om JP Radio <span class="Luk" onclick="closeSearchTable();" onmouseover="handCursor(this);">Luk</span></H1>';
      	onRadio+= '<table style="width:500px; margin-left:15px;margin-right:5px;background-image:none;">';
      							onRadio+= '<tr>';
      								onRadio+= '<td>&nbsp;</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">JP Radio er radioen for dig, som vil vide mere om alt med relation til dansk erhvervsliv. Vi laver interviews, nyheder og børskommentarer dagen igennem og følger desuden de vigtigste nyheder med fokus på politik, sport og kultur.</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Vi sender nyheder alle hverdage fra 6-18 – og er i luften alle dage døgnet rundt.</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">I hverdagene fra 6.00-18.00 er vi på med 10 minutters nyheder hver halve time. Derudover kan du høre interviews, børsberetninger og aktuelle magasinprogrammer. Vi tager et kig på det danske børs- og valutamarked mandag til fredag kl. 8.45 og igen kl. 16.15. I hverdagene fra 18.00-6.00 og i weekenden genudsender vi dagens væsentligste interviews og giver dig mulighed for at lytte til vores magasinprogrammer om IT, private investeringer, politik, videnskab, innovation, forbrugerstof, EU og bøger.</td>';
      							onRadio+= '</tr>';
      							
      						onRadio+= '</table>';
      					onRadio+= '</DIV>';
      				onRadio+= '</DIV>';
	
	document.getElementById("search_results").innerHTML = onRadio;
				
				document.getElementById("Erhverv_table").style.top = "-5px";
					
				document.getElementById("Politik_table").style.top = "-5px";
				
				document.getElementById("Nyheder_table").style.top = "-5px";
				
				document.getElementById("Magasinprogrammer_table").style.top = "-5px";			
				
				document.getElementById("Børs og Valuta_table").style.top = "-5px";
				
				document.getElementById("Forbrug_table").style.top = "-5px";
				
				document.getElementById("Øvrige_table").style.top = "-5px";
		
	
}

function openFrekvenserBox() {
	
	var onRadio = '<DIV class=conCluster_page>';
		onRadio+= '<DIV class="conContent_page t6">';
      	onRadio+= '<H1 class="H1_page">Frekvenser <span class="Luk" onclick="closeSearchTable();" onmouseover="handCursor(this);">Luk</span></H1>';
      	onRadio+= '<table style="width:500px; margin-left:15px;margin-right:5px;background-image:none;">';
      							onRadio+= '<tr>';
      								onRadio+= '<td>&nbsp;</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Du kan altid høre JP Radio på radio.jp.dk, men JP Radio udsendes også i følgende områder på disse frekvenser:</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Frekvenser og områder:<BR>København: 92,9 FM - mandag-fredag 06-17<BR>Nordsjælland: 92,8 FM - mandag-fredag 06-18<BR>Gladsaxe: 100,9 FM - mandag-fredag 06-18<BR>Fredensborg-Humlebæk: 104,3 FM - mandag-fredag 06-18<BR>Sorø: 104,9 FM - mandag-torsdag 06-18 fredag 06-14<BR>Ringsted: 90,1 FM - mandag-fredag 06-09<BR>Hørning: 105,1 FM - mandag-fredag 06-10<BR>Odense: 107,1 FM - mandag-fredag 06-09<BR>Nordvestsjælland (Odsherred): 107,0-107,9 FM - mandag-tirsdag 00-12 + 20-00 og onsdag-fredag 00-14 + 20-00</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Sendenettet udvides løbende.</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Er du i tvivl om hvor vi sender er du velkommen til at kontakte os på radio@jp.dk</td>';
      							onRadio+= '</tr>';
      							
      						onRadio+= '</table>';
      					onRadio+= '</DIV>';
      				onRadio+= '</DIV>';
	
	document.getElementById("search_results").innerHTML = onRadio;
				
				document.getElementById("Erhverv_table").style.top = "-5px";
					
				document.getElementById("Politik_table").style.top = "-5px";
				
				document.getElementById("Nyheder_table").style.top = "-5px";
				
				document.getElementById("Magasinprogrammer_table").style.top = "-5px";			
				
				document.getElementById("Børs og Valuta_table").style.top = "-5px";
				
				document.getElementById("Forbrug_table").style.top = "-5px";
				
				document.getElementById("Øvrige_table").style.top = "-5px";
	
	
}

function fadigBox() {
	
	var onRadio = '<DIV class=conCluster_page>';
		onRadio+= '<DIV class="conContent_page t6">';
      	onRadio+= '<H1 class="H1_page">Få JP Radio hos dig <span class="Luk" onclick="closeSearchTable();" onmouseover="handCursor(this);">Luk</span></H1>';
      	onRadio+= '<table style="width:500px; margin-left:15px;margin-right:5px;background-image:none;">';
      							onRadio+= '<tr>';
      								onRadio+= '<td>&nbsp;</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Ønsker du at sende JP Radio?</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Alle lokalradioer kan kvit og frit streame JP Radio.</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Kontakt redaktør Dan Bjerring for at få de nærmere detaljer på bjerring@tune.dk eller på telefon: 23 84 80 83</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Du er i øvrigt velkommen til at downloade klippene fra radio.jp.dk og lægge ud på dit eget website.</td>';
      							onRadio+= '</tr>';
      							
      						onRadio+= '</table>';
      					onRadio+= '</DIV>';
      				onRadio+= '</DIV>';
	
	document.getElementById("search_results").innerHTML = onRadio;
				
				document.getElementById("Erhverv_table").style.top = "-5px";
					
				document.getElementById("Politik_table").style.top = "-5px";
				
				document.getElementById("Nyheder_table").style.top = "-5px";
				
				document.getElementById("Magasinprogrammer_table").style.top = "-5px";			
				
				document.getElementById("Børs og Valuta_table").style.top = "-5px";
				
				document.getElementById("Forbrug_table").style.top = "-5px";
				
				document.getElementById("Øvrige_table").style.top = "-5px";

	
	
}

function kontaktBox() {
	
	var onRadio = '<DIV class=conCluster_page>';
		onRadio+= '<DIV class="conContent_page t6">';
      	onRadio+= '<H1 class="H1_page">Kontakt os <span class="Luk" onclick="closeSearchTable();" onmouseover="handCursor(this);">Luk</span></H1>';
      	onRadio+= '<table style="width:500px; margin-left:15px;margin-right:5px;background-image:none;">';
      							onRadio+= '<tr>';
      								onRadio+= '<td>&nbsp;</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Redaktionen på JP Radio består af:</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Dan Bjerring, Redaktør - bjerring@tune.dk - telefon: 23 84 80 83</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td>&nbsp;</td>';
      							onRadio+= '</tr>';
       							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Pressemeddelelser og ris/ros sendes til: Redaktionen: radio@jp.dk</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td>&nbsp;</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Henvendelser fra pressen og henvendelser angående sponsorater:</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Direktør Jens Nicolaisen - jn@jp.dk - telefon: 20 19 41 32</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td>&nbsp;</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Redaktør: Dan Bjerring</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Ansvarhavende chefredaktør: Jørn Mikkelsen</td>';
      							onRadio+= '</tr>';
								      							
      						onRadio+= '</table>';
      					onRadio+= '</DIV>';
      				onRadio+= '</DIV>';
	
	document.getElementById("search_results").innerHTML = onRadio;

				document.getElementById("Erhverv_table").style.top = "-5px";
					
				document.getElementById("Politik_table").style.top = "-5px";
				
				document.getElementById("Nyheder_table").style.top = "-5px";
				
				document.getElementById("Magasinprogrammer_table").style.top = "-5px";			
				
				document.getElementById("Børs og Valuta_table").style.top = "-5px";
				
				document.getElementById("Forbrug_table").style.top = "-5px";
				
				document.getElementById("Øvrige_table").style.top = "-5px";
	
	
}

// this is the help box

function helpBox() {
	
	var onRadio = '<DIV class=conCluster_page>';
		onRadio+= '<DIV class="conContent_page_help t6">';
      	onRadio+= '<H1 class="H1_page">Hjælp <span class="Luk" onclick="closeSearchTable();" onmouseover="handCursor(this);">Luk</span></H1>';
      	onRadio+= '<table style="width:500px; margin-left:15px;margin-right:5px;background-image:none;">';
      							onRadio+= '<tr>';
      								onRadio+= '<td>&nbsp;</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">JP Radio er optimeret til Windows XP/Vista med enten browseren Internet Explorer 7.0 eller Firefox 3.0. Du kan også lytte til JP Radio hvis du har installeret et andet styresystem (Mac OS eller Linux), eller benytter andre og ældre browsere, men i visse tilfælde vil du opleve begrænset funktionalitet.</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">For at benytte JP Radio og lytte til enten live radio eller enkelte klip er der muligvis behov for at du installerer nogle plugins eller software.</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td>&nbsp;</td>';
      							onRadio+= '</tr>';
       							onRadio+= '<tr>';
      								onRadio+= '<td align="justify"><strong>Live JP Radio</strong></td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td>&nbsp;</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">For at lytte til live Jp Radio skal du have installeret enten Windows Media Player eller en plugin til den browser du benytter.</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Windows Media Player 11 til Windows baserede PC\'er kan hentes <a href="http://www.microsoft.com/windows/windowsmedia/player/11/default.aspx" target="_blank">her</a></td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td>Benytter du en en Mac kan du få hjælp til at installere Windows Media Player <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=1e974157-5031-4ac6-840a-6e07547b6aeb&DisplayLang=en" target="_blank">her</a></td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">Benytter du browseren Firefox kan du hente en plugin <a href="http://port25.technet.com/pages/windows-media-player-firefox-plugin-download.aspx" target="_blank">her</a></td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">&nbsp;</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify"><strong>JP Radio klip</strong></td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">&nbsp;</td>';
      							onRadio+= '</tr>';
      							onRadio+= '<tr>';
      								onRadio+= '<td align="justify">For at lytte til de enkelte klip på JP Radio siden skal du have installeret Adobe Flash Player der kan findes <a href="http://www.adobe.com/products/flashplayer/" target="_blank">her</a></td>';
      							onRadio+= '</tr>';
								      							
      						onRadio+= '</table>';
      					onRadio+= '</DIV>';
      				onRadio+= '</DIV>';
	
	document.getElementById("search_results").innerHTML = onRadio;

				document.getElementById("Erhverv_table").style.top = "-5px";
					
				document.getElementById("Politik_table").style.top = "-5px";
				
				document.getElementById("Nyheder_table").style.top = "-5px";
				
				document.getElementById("Magasinprogrammer_table").style.top = "-5px";			
				
				document.getElementById("Børs og Valuta_table").style.top = "-5px";
				
				document.getElementById("Forbrug_table").style.top = "-5px";
				
				document.getElementById("Øvrige_table").style.top = "-5px";
	
	
}



// functions for trimming spaces 

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

// this method loads the live player if the flash player has been loaded 

function loadLivePlayer() {
	
	
	
	if(player_loaded) { // if the flash player has been loaded, change to live player
				
		player_loaded = false;
		
		//alert("already we had :: "+document.getElementById("main_player_div").innerHTML);
		
		destroy();
		
		var newdiv = document.createElement("div");
	
		newdiv.innerHTML = '<DIV id="flashradio"><DIV id=radioplayer><P><B>Afspiller nu:</B> JP Radio Live</P><P><BR><IMG alt=player src="images/page/afspil.gif" border=0 onclick="play();" onmouseover="play_over(this);"> <IMG alt=player src="images/page/stop.gif" border=0 onclick="stop();" onmouseover="stop_over(this);"> <IMG alt=player src="images/page/sliderbar.gif" border=0 onclick="volume_inc(event);" id="pointer_div" style="position:inherit"> <IMG alt=player src="images/page/mute.gif" border=0 onclick="muteUnmute(this);"  onmouseover="mute_over(this);"> <IMG alt=player src="images/page/JP-Radio-B.png" border=0 style="position:absolute; left:523px; top:30px;"> <DIV id="level_1"></DIV> <DIV id="level_2"></DIV> <DIV id="level_3"></DIV> <DIV id="level_4"></DIV> <DIV id="level_5"></DIV> <DIV id="level_6"></DIV><DIV id=sangstatus><P>spiller med 728 Kbits/s</P></DIV></DIV></DIV>';
		
		//alert("content to add :: "+newdiv.innerHTML);
				
		document.getElementById("main_player_div").appendChild(newdiv);
		
		document.player1.controls.play();
		
		checkstate();
		
		setBox(3);
		
		
	}

	
}

function destroy() {
	
			var elem = document.getElementById("flashradio");
			
			elem.parentNode.removeChild(elem);
	
		}


/*function removeSWFobject() {
    
	var newdiv = document.createElement("div");
    newdiv.innerHTML = "Hello World!";
    var flashdiv = document.getElementById("flashradio");


    
    alert(document.getElementById("flashradio"));
    
    alert(newdiv);
    
    document.body.replaceChild(newdiv, flashdiv);
    
}*/

// this is the function that loads the flash player if the id is set

function loadflashplayer(clipID) {
	
	playsingleclip(clipID);
	
}

// this function plays the live stream 

function playLiveStream() {
	
	if(document.player1 != null) {
		
		document.player1.controls.play();
		
	} else {
		
		setTimeout("playLiveStream()", 1000);
		
	}
}
