//LN_Begin
function NoticeActive(){
	NoticeHover();	
	NoticeOptions();
	
	$('.image_massage a').lightBox();  
	
	var favoptions = { dataType: 'xml',					   
					   success: function(xml) { 					   							
					   							var new_form = document._importNode($('form', xml).get(0), true);
												var dis = new_form.id;
												var fav = dis.replace('disfavor', 'favor');
												$('form#'+fav).replaceWith(new_form);
												$('form#'+dis).ajaxForm(disoptions).each(addAjaxHidden);
											  }
					 };

	var disoptions = { dataType: 'xml',
					   success: function(xml) { var new_form = document._importNode($('form', xml).get(0), true);
												var fav = new_form.id;
												var dis = fav.replace('favor', 'disfavor');
												$('form#'+dis).replaceWith(new_form);
												$('form#'+fav).ajaxForm(favoptions).each(addAjaxHidden);
											  }
					 };
    
    var flaggedoptions = { dataType: 'xml',	
					   success: function(xml) {					   	
					   		var notice_id = $(xml).find('noticeid').text();					   		
					   		$('#notice-' + notice_id).fadeOut();
						}
					 };


//retweet					 	 

 var retweetoptions = { dataType: 'xml',	
					   success: function(xml) {					   	
							var node = $("li", xml).get(0);
							var qualifier = node.getAttribute('name');
							var qualifier_css = node.getAttribute('id');
							var content = node.text;
						   	if(!content || content.length<0){
						   		content = node.textContent || node.innerHTML;
						   	}
						   	$("#notice_data-text").val(content);
						   	getSayText(qualifier,qualifier_css);
						   	$("#notice_data-text").focus();
						}
					 };		
					 
				 
	
    $("form.form_retweet").ajaxForm(retweetoptions);
		
	$("form.form_favor").ajaxForm(favoptions);
	$("form.form_disfavor").ajaxForm(disoptions);
	$("form.form_flagged").ajaxForm(flaggedoptions);
	
	$("form.form_retweet").each(addAjaxHidden);
	
	
	$("form.form_favor").each(addAjaxHidden);
	$("form.form_disfavor").each(addAjaxHidden);
	$("form.form_flagged").each(addAjaxHidden);	
}

function NoticeOptions(){	
	//notice-option		
	$("li.hentry").mouseout(function(){		
        var id = this.id.substr(7);

        if (id[0]=='-'){
        	id = this.id.substr(8);
        }
        
        if ($("#notice_reply_"+id)){
        	$("#notice_reply_"+id).removeClass(); 
        	$("#notice_reply_"+id).addClass("notice_reply"); 
        }
        
        if ($("#retweet-"+id)){
        	$("#retweet-"+id).css("visibility", "hidden");   
        } 
        
        if ($("#notice_delete_"+id)){
        	$("#notice_delete_"+id).css("visibility", "hidden");   
        } 
        
        if ($("#notice_check_"+id)){
        	$("#notice_check_"+id).css("visibility", "hidden");   
        }  
        
        if ($("#notice_flag_"+id)){
        	$("#notice_flag_"+id).css("visibility", "hidden");   
        }     
            		 
        if($("#favor-"+id)){         		 	
        	$("#favor-"+id).css("visibility", "hidden");
        }     
        
     });        
    
    $("li.hentry").mouseover(function(){    	
        var id = this.id.substr(7);
        
        if (id[0]=='-'){
        	id = this.id.substr(8);
        }       
        
        if ($("#notice_reply_"+id)){        	
        	$("#notice_reply_"+id).addClass("notice_reply_active");   
        } 
        
        if ($("#notice_data-text").length>0 && $(".main_reply_form").length==0){         	
	        if ($("#retweet-"+id)){
	        	$("#retweet-"+id).css("visibility", "visible");   
	        } 
        }
        
        if ($("#notice_delete_"+id)){
        	$("#notice_delete_"+id).css("visibility", "visible");   
        } 
        
        if ($("#notice_check_"+id)){
        	$("#notice_check_"+id).css("visibility", "visible");   
        } 
        
        if ($("#notice_flag_"+id)){
        	$("#notice_flag_"+id).css("visibility", "visible");   
        }    
        		       		 
        if($("#favor-"+id)){
        	$("#favor-"+id).css("visibility", "visible");
        } 
        if($("#disfavor-"+id)){         		 	
        	$("#disfavor-"+id).css("visibility", "visible");
        } 
           
    });
}

function addAjaxHidden() {
		var ajax = document.createElement('input');
		ajax.setAttribute('type', 'hidden');
		ajax.setAttribute('name', 'ajax');
		ajax.setAttribute('value', 1);
		this.appendChild(ajax);
}

function NoticeHover() {
    $("#content .notice").hover(
        function () {
            $(this).addClass('hover');
        },
        function () {
            $(this).removeClass('hover');
        }
    );
}

function NoticeReply() {
    if ($('#notice_data-text').length > 0) {
        $('#content .notice').each(function() {
            var notice = $(this);
            $('.notice_reply', $(this)).click(function() {
                var nickname = ($('.author .nickname', notice).length > 0) ? $('.author .nickname', notice) : $('.author .nickname');
                NoticeReplySet(nickname.text(), $('.notice_id', notice).text());
                return false;
            });
        });
    }
}

function NoticeReplySet(nick,id) {
	rgx_username = /^[0-9a-zA-Z\-_.]*$/;
	if (nick.match(rgx_username)) {
		replyto = "@" + nick + " ";
		if ($("#notice_data-text").length) {
			$("#notice_data-text").val(replyto);
			$("#form_notice input#notice_in-reply-to").val(id);
			$("#notice_data-text").focus();
			return false;
		}
	}
	return true;
}

var WindowPopup = {
	launch: function(url){			
		var left = 0;
		var top = 0;		
		var width = screen.availWidth;
		var height = (screen.availHeight*7)/9;		
		this.open(url, left, top, width, height);
	}
	,
	
	popupCenter: function(url) {
		var width = (screen.width*4)/5;
		var height = (screen.height*2)/3;	
		var left = parseInt((screen.width/2) - (width/2));
    	var top = parseInt((screen.height/2) - (height/2));
    	var windowFeatures = "left=" + left + ", top=" + top + ", width=" + width + ", height=" +height +", resizable=1";
    	window.open(url, "",  windowFeatures);
	}	
	,
	open: function(url, left, top, width, height){
		var windowFeatures = "width=" + width + ",height=" + height + 
			",status,resizable,left=" + left + ",top=" + top + 
			",screenX=" + left + ",screenY=" + top + ",alwaysRaised, scrollbars";
	
		var searchStr = "(Suite)? #?[0-9]+,";
		var replaceStr = ",";
		var re = new RegExp(searchStr , "ig");
		var result = url.replace(re, replaceStr);
	
		window.open(result, "", windowFeatures);
	}

}
//LN_End

//TP_Begin
var musicPopupview = new PopupWindow("musicPopup");		
musicPopupview.offsetX=30;
musicPopupview.offsetY=0;
musicPopupview.autoHide();

function musicPopupactivate(anchor) {
	musicPopupview.showPopup(anchor);
}

var musiclink = null;
var previousSlider = null;
var Audio = {
	musicview: function (musicid,musiclink,musicname){
		//var domainname='psg-prep.anhone.vn:8080';
		var musiclink = musiclink;
		var h=80;
		if(musiclink.length>0){
		var music='';
		var embed='';	
		if(musiclink.indexOf("http://media.imeem.com")>-1){
			if(musiclink.indexOf("/pl/")>-1){
			   h=280;
			}
			music="imeem";
			embed='<embed style="position: absolute;" class="aptureEmbed" type="application/x-shockwave-flash" src="'+ musiclink +'" id="apture_embedPlayer6" name="apture_embedPlayer6" bgcolor="#ffffff" quality="high" allowscriptaccess="never" width="361" height="'+h+'"/>\n';
		}else if(musiclink.indexOf("http://amnhac.timnhanh.com")>-1){
			if(musiclink.indexOf("/1/")>-1){
			   h=320;
			}
			music="Yume.com";
			embed='<embed src="http://static.timnhanh.com/yumemusic/flashplayer/'+musicname+'.swf?xmlPath='+ musiclink +'&getLyric=http://amnhac.timnhanh.com/player/getLyric/&amp;colorAux=0x9A9A8E&amp;colorMain=0xfefef2" type="application/x-shockwave-flash" width="361" height="'+h+'" wmode="transparent" allowscriptaccess="always"/>\n';
			musicname='';
		}else {
			music="chacha.vn";
			embed='<embed flashvars="blogmode=1&file=http://chacha.vn/embedded/v1.0/getMedia.php?songId='+ musiclink +'" type="application/x-shockwave-flash" src="http://chacha.vn/embedded/v1.0/mp3player.swf" wmode="transparent" allowscriptaccess="none" height="78" width="361"/>\n';
		}
		
		var tablecontent ='<table style="left: 0px; top: 0px;"><tbody>\n'
	          +'<tr><td style="background: transparent url(http://static.apture.com/media/imgs/pop_corners.png?2) no-repeat scroll left top; width: 15px; height: 31px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"></td>\n'
			  +'<td style="background: transparent url(http://static.apture.com/media/imgs/pop_tb.png?2) repeat-x scroll center top; height: 31px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 353px;"></td>\n'
			  +'<td style="background: transparent url(http://static.apture.com/media/imgs/pop_corners.png?2) no-repeat scroll right top; width: 15px; height: 31px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"></td>\n'
			  +'</tr>\n'
	        +'<tr>\n'
	        +'<td style="background: transparent url(http://static.apture.com/media/imgs/pop_lr.png) repeat-y scroll left center; width: 15px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; height: 70px;"></td>\n'
            +'<td style="background-color: white;"></td>\n'
			+'<td style="background: transparent url(http://static.apture.com/media/imgs/pop_lr.png) repeat-y scroll right center; width: 15px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; height:70px;"></td>\n'
			+'</tr>\n'
	        
			+'<tr>\n'
	        +'<td style="background: transparent url(http://static.apture.com/media/imgs/pop_corners.png?2) no-repeat scroll left bottom; width: 15px; height: 26px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"></td> \n'
	        +'<td style="background: transparent url(http://static.apture.com/media/imgs/pop_tb.png?2) repeat-x scroll center bottom; height: 26px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial; width: 353px;"></td> \n'
	        +'<td style="background: transparent url(http://static.apture.com/media/imgs/pop_corners.png?2) no-repeat scroll right bottom; width: 15px; height: 26px; -moz-background-clip: -moz-initial; -moz-background-origin: -moz-initial; -moz-background-inline-policy: -moz-initial;"></td> \n'
	        +'</tr>\n'
	 +'</tbody></table>\n'
	 +'<div style="color: rgb(34, 34, 34); cursor: default; text-align: left; position: absolute; left: 13px; right: 13px; top: 9px; height: 18px;">\n'
	+'<a href="javascript:;" onclick="musicPopupview.hidePopup();"><div style="background-position: 0px top;" title="Close Window (click to close the  window)" class="apturePopupButton"></div></a>\n'
	+'<div style="background-position: -54px top; display: none;" title="View Fullscreen" class="apturePopupButton"></div>\n'
	+'<img src="images/sound.png" style="display: inline; float: left;" class="apturePopupIcon">\n'
	+'<div style="overflow: hidden; height: 14px;">\n'
	+'<a href="'+musiclink+'" target="_blank" style="color: black; text-shadow: 0px 1px 1px white; padding-left: 3px; font-weight: bold; cursor: pointer;" class="aptureTitleText">'+musicname+'</a> \n'
+'	<span style="color: rgb(109, 109, 109); cursor: default; text-shadow: 0px 1px 1px white;" class="aptureTitleText">'+music+'</span>\n'
	+'</div>\n'
	+'</div>\n'
	+'<div style="position: absolute;  left: 11px; width: 100px;">\n'
	+'</div>\n'
	+'<div class="aptureEmbed" style="position: absolute; left: 11px; top: 30px; width: 300px; height: '+h+'px;"><div style="position: absolute; width: 300px; height: '+h+'px;" class="aptureEmbed">\n'
	+embed+'\n'
	+'</div><div style="display: none; width: 300px; height: '+h+'px;"><img style="width: 100%; height: 100%;" src="http://icons.imeem.com/FaFojYp_.jpg"></div></div>\n';
	/*
	+'<embed flashvars="blogmode=1&file=http://chacha.vn/embedded/v1.0/getMedia.php?songId=2319" type="application/x-shockwave-flash" src="http://chacha.vn/embedded/v1.0/mp3player.swf" wmode="transparent" allowscriptaccess="none" height="78" width="300">\n'
	
	+'</div><div style="display: none; width: 300px; height: 80px;"><img style="width: 100%; height: 100%;" src="http://icons.imeem.com/FaFojYp_.jpg"></div></div>\n';
	*/
	}			
		//	loading.hide(previousSlider);
		
		musicPopupview.populate(tablecontent);
		//alert(tablecontent);
		musicPopupactivate(musicid);
 },

 
 musicdetach: function (musicid,musiclink,musicname){
		//var musiclink = musiclink;
		var h=140;
		if(musiclink.length>0){
		if(musiclink.indexOf("http://media.imeem.com")>-1){
			if(musiclink.indexOf("/pl/")>-1){
			   h=330;
			}
		}else if(musiclink.indexOf("http://amnhac.timnhanh.com")>-1){
			if(musiclink.indexOf("/1/")>-1){
			   h=230;
			}
			
		}
		
		var url=server+'index.php?action=musicpopup&musicname='+musicname+'&link='+musiclink;
		window.open(url,"window_"+musicid,"width=400,height="+h+"");//,screenX="+this.x+",left="+this.x+",screenY="+this.y+",top="+this.y+"");
		}
  }		
};

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function deletecook(c_name)
{
    
   // document.cookie = "ajaxcontent="++";expires=" + d.toGMTString() + ";" + ";";

   setCookie(c_name,'',0);
}

function search_data(keyword, type){
	if(type == 1)
		document.getElementById("searchBox").value = "\"" + keyword + "\"";
	else
		document.getElementById("searchBox").value = keyword ;
	document.searchForm.submit();
}

function view_next_paging(paging, page_old, table_index){
	document.getElementById("paging").value = paging;
	document.getElementById("page_old").value = page_old;
	document.getElementById("table_index").value = table_index;
	document.getElementById("paging_status").value = 1;
	document.searchForm.submit();
}

function view_prev_paging(paging, page_old, table_index){
	document.getElementById("paging").value = paging;
	document.getElementById("page_old").value = page_old;
	document.getElementById("table_index").value = table_index;
	document.getElementById("paging_status").value = 2;
	document.searchForm.submit();
}

//TP_End