// config
var domain_root = "http://trueworld.truelife.com/"; //www.trueworld.net
var domain_name = "http://truemusic.truelife.com/"; //music2.trueworld.net
var domain_my = "http://my.truelife.com/"; //my.trueworld.net
var domain_webboard = "http://webboard.truelife.com/"; //webboard.trueworld.net

var return_page = window.document.location;

//alert(centralid);

function openURL(url){
    var windowprops = "height=680,width=570,location=no,"+ "scrollbars=no,menubars=no,toolbars=no,status=no,resizable=no";
    var openWindow = window.open(url,	"cart",	"");
    //openWindow.title = "cart";
}

function openURL_newWindow(url){
	var openWindow = window.open(url,"_blank");
}


function openRadioLink(){
	if (document.getElementById('radiochannel').value=="") {
		alert("กรุณาเลือกสถานี");	
	}
	
	else{
		var ob= $("radiochannel");
		window.open(ob.options[ob.selectedIndex].value);
	}
}			

function openTVLink(){
	if (document.getElementById('tvchannel').value=="") {
		alert("กรุณาเลือกสถานี");	
	}
	
	else{
		var ob= $("tvchannel");
		window.open(ob.options[ob.selectedIndex].value);
	}	
}

function popupFullsonglistening(guid)
{
	//var windowprops = "toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=no,resizable=no,width=990,height=615";
	//var openWindow = window.open("http://truemusic.truelife.com/home/player/player_song.php?guid=" + guid +"&centralid=" + centralid + "","popupFullsonglistening",windowprops );
	var openWindow = window.open("http://truemusic.truelife.com/home/player/player_song.php?songguid=" + guid ,"popupFullsonglistening","" );
}


function popupMV(guid)
{
   //var windowprops = "toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=yes,resizable=no,width=990,height=615";
   //var openWindow = window.open("http://truemusic.truelife.com/home/player/player_mv.php?centralid=" + centralid + "&guid=" + guid ,"popupMV",windowprops );   
   var openWindow = window.open("http://truemusic.truelife.com/home/player/player_mv.php?guid=" + guid ,"popupMV","" );   
}


function popupLyric(lyric_guid)
{
   var windowprops = "toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=yes,resizable=no,width=590,height=602";
   //var openWindow = window.open("http://truemusic.truelife.com/lyrics/lyrics.jsp?guid=" + lyric_guid ,"popupLyric",windowprops );   
   var openWindow = window.open("http://truemusic.truelife.com/home/player/lyrics/lyrics.php?guid=" + lyric_guid ,"popupLyric",windowprops );   
   

}


function popupNetradio(guid)
{
   var openWindow = window.open("http://truemusic.truelife.com/home/player/player_nr.php?guid=" + guid,"popupNerradio","");
}


function popupMVCrazyHit(guid)
{
   var openWindow = window.open("http://truemusic.truelife.com/home/player/player_mvcrazyhit.php?guid=" + guid,"popupMVCrazyHit","");
}


function popupJukebox(guid)
{
   var openWindow = window.open("http://truemusic.truelife.com/home/jukebox/","popupJukebox","");
}


function popupLiveRadio(location)
{
	var windowprops = "directories=no,scrollbars=no,width=500,height=370,left=200,top=50,resizable=1";
	window.open(location,"",windowprops)
}


function openArtist(guid){
	winopt = "http://truemusic.truelife.com/home/artist.php?guid=" + guid;
	window.open(winopt,"_blank");
}


function openAlbum(artistGuid,albumGuid){
	winopt = "http://truemusic.truelife.com/home/album.php?guid=" + artistGuid + "&album_guid=" + albumGuid;
	window.open(winopt,"_blank");
}


function openAllAlbum(artistGuid){
	winopt = "http://truemusic.truelife.com/home/allAlbum.php?guid=" + artistGuid;
	window.open(winopt,"_blank");
}


function AlbumPreview(guid)
{
	var windowprops = "toolbar=0,location=0,directories=0,status=0,menubar=no,scrollbars=no,resizable=no,width=400,height=150";
	var openWindow = window.open("http://truemusic.truelife.com/home/player/player_album.php?guid=" + guid ,"AlbumPreview",windowprops );
}


function AddtoJukebox_xsl(guid)
{	
	//alert("add_to_jukebox('" +guid+ "','" +centralid+ "')");
	//add_to_jukebox("'" + guid + ",'" + centralid + "'");    
	add_to_jukebox(guid,centralid);		// jukebox.js  : 1 Song
}

function AddtoJukebox_xsl_many()
{		 
	songList(centralid);    // Many Songs
}


/*function songList(plowner)
{
	 var s_list = "";
	 var s_group="Thai";
	 try{
	   if(centralid.length>5){
		if(document.all.song.length !=null && document.all.song.length !="undefined" && document.all.song.length !=  0){
		  for (i=0; i<document.all.song.length; i++){
			if (document.all.song[i].checked==true)
			  s_list += document.all.song[i].value +",";
			  //alert(s_list);
		   }
	   }else{
		 if(document.all.song != null || document.all.song != "undefined"){
		  s_list = ""+document.all.song.value +",";
		  //s_list = "'"+document.all.song.value +"',";
		 }
	   }
		 s_list = s_list.substring(0,s_list.length-1);
		 //alert(s_list);
		 
			 if(confirm("Confirm to Add")){;
			   s_group="Thai";
			   if(s_group== "Thai"){				 
				 //alert("do_add_item('"+ centralid +"','" + s_list + "')");
				 do_add_item(centralid,s_list);
			   }else{
				 //alert("Inter");
				 //jk_inter_addsongList(s_list);
			   }
			   
			   
			 }else{
			   alert("ยกเลิกการเพิ่มเพลง");
			 }
				 
		  for (i=0; i<document.all.song.length; i++){
			document.all.song[i].checked=false;
		}
	
		}else{
		alert("กรุณา login");
		}
		}catch(e){
		}
}*/
function songList(centralid){
//	alert("ss");
 var s_list = "";
 var s_group="Thai";
 try{
   if(centralid.length>5){
    if(document.all.song.length !=null && document.all.song.length !="undefined" && document.all.song.length !=  0){
      for (i=0; i<document.all.song.length; i++){
	    if (document.all.song[i].checked==true)
		  s_list += ""+document.all.song[i].value +",";
		  //alert(s_list);
	   }
   }else{
     if(document.all.song != null || document.all.song != "undefined"){
  	  s_list = ""+document.all.song.value +",";
     }
   }
	 s_group=document.all.song_group.value;
	 s_list = s_list.substring(0,s_list.length-1);
         if(confirm("Confirm to Add")){
		   add_to_jukebox(s_list);
         }else{
           alert("ยกเลิกการเพิ่มเพลง");
         }
	  for (i=0; i<document.all.song.length; i++){
		document.all.song[i].checked=false;
	}

	}else{
	alert("กรุณา login");
	}
	}catch(e){
	}
}


/*function addCart(contentID,serviceID,cartTitle,priceTitle,world,mediaType,quantity,ref,cartID)   // Add to Cart  =  1 song
{
	var world = 'ms';
	var quantity = '1';
	var ref = '';
	var cartid = '3';
	var media_type = 'download';
	var centralID = centralid;	
	var cart = new clsShoppingCart();
	var itemCount = 0;
	
	  if(centralID.length<=5){
		 alert("กรุณา login");
	  }else{
		  if(cart.exists_streamguid(centralID, contentID,serviceID,"3"))
		  {
			alert("มีสินค้าชิ้นนี้อยู่ในตะกร้าแล้ว");
		  }else{
				//alert("centralID:"+centralID+"cartTitle:"+cartTitle+"contentID:"+contentID+"serviceID:"+serviceID+"priceTitle"+priceTitle+"world:"+world+"mediaType:"+mediaType+"quantity"+quantity+"ref"+ref+"cartID"+cartID)
				cart.addItem_streamguid(centralID, cartTitle, contentID, serviceID, priceTitle, world, mediaType, quantity, ref, cartID);
				itemCount = itemCount + 1;
				document.all["itemCount"].innerHTML = cart.count(centralid,"3") + " เพลง";
				alert("ได้ทำการเพิ่มสินค้าลงตะกร้าแล้ว จำนวน " + quantity + " ชิ้น\n" + "ขณะนี้คุณมีสินค้าอยู่ในตะกร้าจำนวน " + cart.count(centralID,"3") + " ชิ้น");
				var url="http://my.truelife.com/shopping/showItemList.jsp?cartId=3";
				openURL(url);
		  }
	  }
}*/


/*function addSongsToCart(plowner)			// Add to Cart   > 1 Song
{
	var world = 'ms';
	var quantity = 0;
	var ref = '';
	var cartid = '3';
	var media_type = 'download';
	var centralID = centralid;			
	var cart = new clsShoppingCart();
	var song_id = "";
	var song_sid = "";
	var song_price = "";
	var song_title = "";
	var song_album_title = "";
	var cartTitle = "";
	var itemCount = 0;
	
	 try
	 {
	   if(centralid.length>=5)
	   {
		if(document.all.buysong.length !=null && document.all.buysong.length !="undefined" && document.all.buysong.length !=  0)
		{
		  for (i=0; i<document.all.buysong.length; i++)
		  {
			if (document.all.buysong[i].checked == true)
				
				song_id= document.all.buysong[i].value;
				song_sid= document.all.song_sid[i].value;
				song_price= document.all.song_price[i].value;
				song_title= document.all.song_contentTitle[i].value;
				song_album_title= document.all.song_albumTitle[i].value;
				cartTitle = song_title + " - " + song_album_title;
				
				if(song_id != ""){
					
					if(cart.exists_streamguid(centralID, song_id,song_sid,"3"))
					{
						//alert("มีสินค้าชิ้นนี้อยู่ในตะกร้าแล้ว");
					}		
					else
					{
						//cart.addItem(centralID,cartTitle,song_id, song_sid, song_price, world, mediaType, quantity, ref, cartID);
						cart.addItem_streamguid(centralID,cartTitle,song_id,song_sid,song_price, world,'download', '1', '', '3');
						quantity ++;  
						itemCount = itemCount + 1;										
					}	
				}	
				
				song_id = "";
					
		  }
		  document.all["itemCount"].innerHTML = cart.count(centralid,"3") + " เพลง";
		  alert("ได้ทำการเพิ่มสินค้าลงตะกร้าแล้ว จำนวน " + quantity + " ชิ้น\n" + "ขณะนี้คุณมีสินค้าอยู่ในตะกร้าจำนวน " + cart.count(centralID,"3") + " ชิ้น");
		  var url="http://my.truelife.com/shopping/showItemList.jsp?cartId=3";
		  openURL(url);		  
	   	} // close for loop
		else
		{
		 	if(document.all.buysong != null || document.all.buysong != "undefined")
			{
		  		//alert("กรุณาเลือกเพลงที่ต้องการซื้อ");
		 	}
	  	}

	
	  }
	  else
	  {
		  alert("กรุณา login");
	  }
	}
	catch(e)
	{
	}
}*/


<!--  Radio And Live TV List
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
	d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
	if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
	obj.visibility=v; }
}
//-->


function addToFavorite()
{
	window.external.AddFavorite(location.href, document.title); 
}

function sendToFriends()
{
	var path = window.location;
	var windowprops = "directories=no,scrollbars=no,width=480,height=350,left=200,top=50,resizable=1";
	window.open(domain_root+"newsletter/send2fr/index.jsp?requestpath=" + escape(path),"",windowprops)
}





<!-- NEW : ADD CART -->
function addCart(content_guid,product_desc,price)  <!-- Add Song = 1 -->
{
	/*alert("ขออภัยค่ะ ระบบซื้อปิดปรับปรุงชั่วคราวค่ะ");
	return false;*/
	
	var cart = new clsShoppingCart();
	var centralID = centralid;
	var content_id_type = 'song';
	var content_type = 'download';
	var quantity = '1';
	var duplicate = 'no';
	var itemCount = 0;

	if(centralID.length<=5){
		alert("กรุณา login");
	}else{
		
		//alert("content_guid =" + content_guid + ", content_id_type =" + content_id_type + ", content_type = " + content_type + ", product_desc =" + product_desc +", quantity =" + quantity +", price =" + price + ", duplicate =" + duplicate + ",''");		
		//addnewtocart(content_guid,content_id_type,content_type,product_desc,quantity,price,duplicate,'')	
		//addnewtocart('20070330111205671786','song','download','ไม่เจ็บไม่ถาม - Woo!','1','30','no','')	;
		addmultitocart(content_guid + ";song;download;" + product_desc + ";1;"+ price +";no;-");
		
		itemCount = itemCount + 1;
		//alert("123");
		//document.getElementById('item_count').src = "http://enabling.truelife.com/shopping/getCartCount.jsp";
		setTimeout("loadCountCart()",2000);
		setTimeout("loadCountCart()",3000);
		setTimeout("loadCountCart()",1000);
		
		
		setTimeout("loadShoppigCartPage()",5000);
		
		//alert("ได้ทำการเพิ่มสินค้าลงตะกร้าแล้ว จำนวน " + quantity + " ชิ้น\n" + "ขณะนี้คุณมีสินค้าอยู่ในตะกร้าจำนวน " + cart.count(centralID,"3") + " ชิ้น");
	
	}

}


/*function addSongsToCart()			<!-- Add Song > 1 -->
{
	var cart = new clsShoppingCart();
	var centralID = centralid;
	var content_id_type = 'song';
	var content_type = 'download';
	var quantity = '0';
	var duplicate = 'no';
	var itemCount = 0;	
	
	var song_id = "";
	var song_sid = "";
	var song_price = "";
	var song_title = "";
	var song_album_title = "";
	var cartTitle = "";	
	
	 try
	 {
	   if(centralid.length>=5)
	   {
		if(document.all.buysong.length !=null && document.all.buysong.length !="undefined" && document.all.buysong.length !=  0)
		{
		  for (i=0; i<document.all.buysong.length; i++)
		  {
			if (document.all.buysong[i].checked == true)
				
				song_id= document.all.buysong[i].value;
				song_sid= document.all.song_sid[i].value;
				song_price= document.all.song_price[i].value;
				song_title= document.all.song_contentTitle[i].value;
				song_album_title= document.all.song_albumTitle[i].value;
				cartTitle = song_title + " - " + song_album_title;	
				
				if(song_id != ""){
					//alert("content_guid =" + song_id + ", content_id_type =" + content_id_type + ", content_type = " + content_type + ", product_desc =" + cartTitle +", quantity = 1 , price =" + song_price + ", duplicate =" + duplicate );
					addnewtocart(song_id,content_id_type,content_type,cartTitle,'1',song_price,duplicate)	
					quantity ++;  
					itemCount = itemCount + 1;										
	
				}	
				
				song_id = "";
					
		  }
		  document.all["itemCount"].innerHTML = cart.count(centralid,"3") + " เพลง";
		  //alert("ได้ทำการเพิ่มสินค้าลงตะกร้าแล้ว จำนวน " + quantity + " ชิ้น\n" + "ขณะนี้คุณมีสินค้าอยู่ในตะกร้าจำนวน " + cart.count(centralID,"3") + " ชิ้น");
		  //var url="http://my.truelife.com/shopping/showItemList.jsp?cartId=3";
		  //openURL(url);		  
	   	} // close for loop
		else
		{
		 	if(document.all.buysong != null || document.all.buysong != "undefined")
			{
		  		alert("กรุณาเลือกเพลงที่ต้องการซื้อ");
		 	}
	  	}

	
	  }
	  else
	  {
		  alert("กรุณา login");
	  }
	}
	catch(e)
	{
	}				
}*/



function addSongsToCart()			<!-- Add Song > 1 -->
{
	/*alert("ขออภัยค่ะ ระบบซื้อปิดปรับปรุงชั่วคราวค่ะ");
	return false;*/
	
	var cart = new clsShoppingCart();
	var centralID = centralid;
	var content_id_type = 'song';
	var content_type = 'download';
	var quantity = '0';
	var duplicate = 'no';
	var itemCount = 0;	
	
	var song_id = "";
	var song_sid = "";
	var song_price = "";
	var song_title = "";
	var song_album_title = "";
	var cartTitle = "";	
	var multitocart = "";
	var cnt = 0;
	
	 try
	 {
	   if(centralid.length>=5){
		   
			if(document.all.buysong.length !=null && document.all.buysong.length !="undefined" && document.all.buysong.length !=  0){
		  		
				for (i=0; i<document.all.buysong.length; i++){
					
					cnt =   document.all.buysong.length - 1;
			
					if (document.all.buysong[i].checked == true)
				
						song_id= document.all.buysong[i].value;
						song_sid= document.all.song_sid[i].value;
						song_price= document.all.song_price[i].value;
						song_title= document.all.song_contentTitle[i].value;
						song_album_title= document.all.song_albumTitle[i].value;
						cartTitle = song_title + " - " + song_album_title;	
				
						if(song_id != ""){				
					
							multitocart = multitocart + ""+ song_id + ";" + content_id_type + ";" + content_type + ";" + cartTitle + ";1;" + song_price + ";" + duplicate +";-" ;
					
							if(i != cnt){
								multitocart = multitocart + "," ;
							}
						}	
				
						song_id = "";
						
						buysong[i].checked = false;
					
		 		 }
		  
		  		//alert(i);
			  //alert(multitocart);
			  addmultitocart(multitocart);
			 //alert("123"); 
			// document.getElementById('item_count').src = "http://enabling.truelife.com/shopping/getCartCount.jsp";
			
			setTimeout("loadCountCart()",2000);
			setTimeout("loadCountCart()",3000);
			setTimeout("loadCountCart()",1000);
			
			 
			setTimeout("loadShoppigCartPage()",5000);
			
			  
//			  document.all["itemCount"].innerHTML =  + " เพลง";
			  //alert("ได้ทำการเพิ่มสินค้าลงตะกร้าแล้ว จำนวน " + quantity + " ชิ้น\n" + "ขณะนี้คุณมีสินค้าอยู่ในตะกร้าจำนวน " + cart.count(centralID,"3") + " ชิ้น");
			 					  
			} // close for loop
			else{
		 		if(document.all.buysong != null || document.all.buysong != "undefined"){
		  			alert("กรุณาเลือกเพลงที่ต้องการซื้อ");
				}
	  		}	
	  	}
	  	else{
		  
		  alert("กรุณา login");
	  	}
	}
	catch(e)
	{
	}				
}

function loadCountCart(){
	var f = document.getElementById('item_count');
	f.src = f.src;
}


function loadShoppigCartPage()
{
	var url="http://enabling.truelife.com/shopping/showCart.jsp?cartid=3";
	openURL(url);
}


function bgOn(ob) {
	ob.className = "loadOn";
}

function bgOut(ob) {
	ob.className = "loadOut";
}
