/*
 * Common function for Yume1.0
 * Type:	file
 * Name: 	common.js
 * Date:	2008/05/20 
 * @version:1.0
 * @copyright 2008 Timnhanh.com
 * ---------------------------- /

/*
 * Ham thuc hien chuc nang "Chinh sua" box Profile
 * Type:	onload function
 * Name:	
 * Date:	2008/05/20
 * @author:	Tuyen Cao <tuyenck@von-inc.com>
 */
jQuery(document).ready(function(){		
	TNLibControlEdit();
})
function TNLibControlEdit()
{
	$("#ym_BProfile .edit_control a").click(function(){			
		$("#edit_nickname").slideDown('fast');
		return false;
	})	
	$("#edit_nickname p").click(function(){			
		$("#edit_nickname").slideUp('fast');
	})
};

/*
 * Ham thuc hien thay doi icon bo go
 * Type:	onload function
 * Name:	
 * Date:	2008/05/20
 * @author:	Hien Nguyen <hiennh@von-inc.com>
 */
var typing_icon_status = 0;
function typing_change_icon(){	
	$('.typing_icon').css('background-position', function(){
		typing_icon_status++;
		if (typing_icon_status % 2 == 0) { return 'top'; }
		else { return 'bottom'; }		
	});
}//end function


/*
 * Ham thuc hien chuc nang lay gia tri cua window va document
 * Type:	function
 * Name:	TNCom_getDocumentSize
 * Date:	2008/05/21
 * @author:	Tuyen Cao <tuyenck@von-inc.com>
 * @param int val cac gia tri:	0: pageWidth, 1: pageHeight, 2: windowWidth, 3: windowHeight
 * @return int gia tri tra ve khi thuc hien goi ham		
 */
function TNCom_getDocumentSize(val)
{
	var xScroll,yScroll,value;
	
	if(window.innerHeight&&window.scrollMaxY)
	{
		xScroll=window.innerWidth+window.scrollMaxX;
		yScroll=window.innerHeight+window.scrollMaxY;
	}
	else if(document.body.scrollHeight>document.body.offsetHeight)
	{
		xScroll=document.body.scrollWidth;
		yScroll=document.body.scrollHeight;
	}
	else{
		xScroll=document.body.offsetWidth;
		yScroll=document.body.offsetHeight;
	}
	
	var windowWidth,windowHeight;
	
	if(self.innerHeight)
	{
		if(document.documentElement.clientWidth){
			windowWidth=document.documentElement.clientWidth;
		}
		else{
			windowWidth=self.innerWidth;
		}
		windowHeight=self.innerHeight;
	}
	else if(document.documentElement&&document.documentElement.clientHeight)
	{
		windowWidth=document.documentElement.clientWidth;
		windowHeight=document.documentElement.clientHeight;
	}
	else if(document.body)
	{
		windowWidth=document.body.clientWidth;
		windowHeight=document.body.clientHeight;
	}
	
	if(yScroll<windowHeight){
		pageHeight=windowHeight;
	}
	else{
		pageHeight=yScroll
	}
	
	if(xScroll<windowWidth){
		pageWidth=xScroll
	}
	else{
		pageWidth=windowWidth
	}
	
	arrayPageSize=new Array(pageWidth,pageHeight,windowWidth,windowHeight)	
	return arrayPageSize[val]
}// end function



/*
 * Ham thuc hien chuc nang tab
 * Type:	function
 * Name:	TNProfile_activeTabFriend
 * Date:	2008/05/21
 * @author:	Thanh Bui <thanhbt@von-inc.com>
 * @param int obj la tab duoc active
 */
function TNProfile_activeTabFriend(obj){
	for (var i=1; i<4; i++){
		var content = "cont_0"+i;
		var content_header = "tab"+i;
		document.getElementById(content).style.display='none';
		document.getElementById(content_header).className='tab_title ym_border_module ym_link'
		if (content_header==obj){ 
			document.getElementById(content).style.display='block';
			document.getElementById(content_header).className='tab_title ym_border_module ym_text'
		}
	}
}

/*
 * Ham thuc hien chuc nang tab box BanBe trang Profile
 * Type:	function
 * Name:	TNPro_actTabFriend
 * Date:	2008/05/21
 * @author:	Hien Ng <hiennh@von-inc.com>
 * @param obj la ID cua tab
 */
function TNPro_actTabFriend(obj){
	for (var i=1; i<4; i++){
		var content = "ym_banbe_con"+i;
		var content_header = "ym_banbe_tab"+i;
		$('#'+content).hide();
		$('#'+content_header).removeClass('active_icon');
		if (content_header==obj){ 
			$('#'+content).fadeIn('normal');
			$('#'+content_header).addClass('active_icon');
		}
	}
}

/*
 * Ham thuc hien chuc nang them link box Blogroll
 * Type:	function
 * Name:	TNPro_blogroll
 * Date:	2008/06/02
 * @author:	Hien Ng <hiennh@von-inc.com>
 * @param obj la ID cua tab
 */
function TNPro_blogroll(obj){
	$('#'+obj).fadeIn('slow');
	if (obj=="ym_blogrollB") selfDiv = obj.replace('B','A');
	else selfDiv = obj.replace('A','B');
	$('#'+selfDiv).hide();
}

/*
 * Ham thuc hien chuc nang copylink cua cac box playlist
 * Type:	function
 * Name:	TNPro_HighlightAll
 * Date:	2008/06/02
 * @author:	Hien Ng <hiennh@von-inc.com>
 * @param obj la ID cua tab
 */
function HighlightAll(theField)
{
	var tempval=eval("document."+theField).select();
	var text = '';
	text = eval("document."+theField).value;
	$.copy(text);
}

/*
 * Ham thuc hien chuc nang back to top
 * Type:	function
 * Name:	GoToTop
 * Date:	2008/06/025
 * @author:	Hien Ng <hiennh@von-inc.com>
 * @param 
 */
jQuery(function( $ ){
	$('#gototop').click(function(){
		$.scrollTo( 0, 700);					
		return false;
	});
	$('#gotocm').click(function(){
	$.scrollTo('#ym_writebl_inner', 700);					
		return false;
	});
})

function IsNumeric(ch){
	if(ch=="0"||ch=="1"||ch=="2"||ch=="3"||ch=="4"||ch=="5"||ch=="6"||ch=="7"||ch=="8"||ch=="9"||ch=="A"||ch=="B"||ch=="C"||ch=="D"||ch=="E"||ch=="F"||ch=="a"||ch=="b"||ch=="c"||ch=="d"||ch=="e"||ch=="f")
		return 1
	else
		return 0
}

function isHex(str){
	var i,ch
	if(str.length>6)
		return false
		
	for(i=0;i<str.length;i++){
		ch=str.substring(i,i+1)
		if(!IsNumeric(ch))
			return false
	}
	return true
}

/*
 * Collapse/Expand description info
 * Type:	onload function
 * Name:	
 * Date:	2008/07/09
 * @author:	Hien Nguyen <hiennh@von-inc.com>
 */
var desInfo, desInfo_s;
var link_viewAll_f = "... <a href='#' class='ym_link' onclick='desInfo_control";
jQuery(document).ready(function(){	
	desInfo = $('#desInfo').html();
	if (desInfo){
		var desInfo_len = eval(desInfo.length);
		if (desInfo_len > 100){		
			desInfo_s = desInfo.substring(0,100);
			var link_viewAll = link_viewAll_f + "(\"all\"); return false;'>Xem thêm</a>";
			$('#desInfo').html(desInfo_s + link_viewAll);		
		}	
	}
});
function desInfo_control(opt){
	if (opt=="all"){
		$('#desInfo').html(desInfo);
		var link_viewAll = link_viewAll_f + "(); return false;'>Thu gọn</a>";
		$('#desInfo').html(desInfo + link_viewAll);
	}
	else{
		$('#desInfo').html(desInfo_s);
		var link_viewAll = link_viewAll_f + "(\"all\"); return false;'>Xem thêm</a>";
		$('#desInfo').html(desInfo_s + link_viewAll);
	}
}

function open_lyric(){
	document.getElementById("songfeature").style.height="230px";
}
function close_lyric(){
	document.getElementById("songfeature").style.height="89px";
}