﻿/*======================================================================*\
|| #################################################################### ||
|| # AT TXGC MEDIA ONLINE Ltd.                                        # ||
|| # ---------------------------------------------------------------- # ||
|| # Copyright ©2008-2009 ThiXaGoCong.Com . All Rights Reserved.      # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| # ----------- AT MOVIE IS FREE SOFTWARE - OPEN SOURCE ------------ # ||
|| # http://thixagocong.com | http://www.thixagocong.com/support.html # ||
|| #################################################################### ||
\*======================================================================*/
var http = createRequestObject();
var lastUrl = '';
var current_url = '';
var field = '';
var interval = '';
var loading=0;
var str = 'Gõ tiếng Việt có dấu để tìm kiếm chính xác nhất';
function setValue(obj)
{
	if(obj.value == '')
	{
		obj.value = str;
		obj.style.color = '#ff3399';
	}
	else if(obj.value == str)
	{
		obj.value = '';
		obj.style.color = '#50a31a';
	}
}
String.prototype.trim = function() { //Trim ambas direcciones
    return this.replace(/^[ ]+|[ ]+$/g, "");
}

String.prototype.stripSpace = function() { //Trim ambas direcciones
    return this.replace(/(\s\s+)/g, "-");
}

String.prototype.stripExtra = function() { //Trim ambas direcciones
    re = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\.|\//g;
    return this.replace(re, "");
}

String.prototype.stripViet = function() {
    var replaceChr = String.prototype.stripViet.arguments[0];
    var stripped_str = this;
    var viet = [];
    i = 0;
    viet[i++] = new Array('a', "/á|à|ả|ã|ạ|ă|ắ|ằ|ẳ|ẵ|ặ|â|ấ|ầ|ẩ|ẫ|ậ/g");
    viet[i++] = new Array('o', "/ó|ò|ỏ|õ|ọ|ơ|ớ|ờ|ở|ỡ|ợ|ô|ố|ồ|ổ|ỗ|ộ/g");
    viet[i++] = new Array('e', "/é|è|ẻ|ẽ|ẹ|ê|ế|ề|ể|ễ|ệ/g");
    viet[i++] = new Array('u', "/ú|ù|ủ|ũ|ụ|ư|ứ|ừ|ử|ữ|ự/g");
    viet[i++] = new Array('i', "/í|ì|ỉ|ĩ|ị/g");
    viet[i++] = new Array('y', "/ý|ỳ|ỷ|ỹ|ỵ/g");
    viet[i++] = new Array('d', "/đ/g");
    for (var i = 0; i < viet.length; i++) {
        stripped_str = stripped_str.replace(eval(viet[i][1]), viet[i][0]);
        stripped_str = stripped_str.replace(eval(viet[i][1].toUpperCase().replace('G', 'g')), viet[i][0].toUpperCase());
    }
    if (replaceChr) {
        return stripped_str.replace(/[\W]|_/g, replaceChr).replace(/\s/g, replaceChr).replace(/^\-+|\-+$/g, replaceChr);
    } else {
        return stripped_str;
    }
};

function createRequestObject() {
	var xmlhttp;
	try { xmlhttp=new ActiveXObject("Msxml2.XMLHTTP"); }
	catch(e) {
    try { xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");}
	catch(f) { xmlhttp=null; }
  }
  if(!xmlhttp&&typeof XMLHttpRequest!="undefined") {
	xmlhttp=new XMLHttpRequest();
  }
	return  xmlhttp;
}
/* kiem tra do dai tu khoa */
function CheckSearch(obj)
{
	var length = obj.q.value.trim().length;
	if(length < 2) {
		jAlert('warning', 'Từ khóa phải có chiều dài từ 2 kí tự trở lên!', 'Thông Báo');
		if (length < 1) {
			obj.q.value = '';
		}
		obj.q.focus();
		return false;
	}
	return true;
}
function do_search(obj) {
	kw = document.getElementById("keyword").value;
	if (!kw) alert('Bạn chưa nhập từ khóa');
	else {
		kw = encodeURIComponent(kw);
		s_type = document.getElementById("searchType");
		type = s_type.options[s_type.selectedIndex].value;
		switch (type) {
			case 'song' : type = 'song.html'; break;
			case 'singer' : type = 'singer.html'; break;
			case 'album' : type = 'album.html'; break;
			case 'lyric' : type = 'lyric.html'; break; 
			case 'user' : type = 'user.html'; break; 
		}
		last_url = '';
		window.location.href = '/search/mp3/ybeta/'+kw+'/'+type+''; 
		/*window.location.href = '/search/mp3/ybeta/'+kw+'&type='+type+'';*/
	}
	return false;
}
function btnVietkey_onclick(id) {
    if (document.getElementById(id).src.indexOf('http://static.thixagocong.com/images/unity_footer1/listV.gif') == -1) {
        setMethod(0);
        document.getElementById(id).src = 'http://static.thixagocong.com/images/unity_footer1/list/V.gif';
    }
    else {
        setMethod(-1);
        document.getElementById(id).src = 'http://static.thixagocong.com/images/unity_footer1/list/E.gif';
    }
    return true;
}
var isIE = (navigator.userAgent.indexOf('MSIE') != -1);
if (window.parent!=window)
 { 
  alert('Bạn đang truy cập không phải website chính thức THỊ XÃ GÒ CÔNG.Chúng tôi hoàn toàn không chịu trách nhiệm thông tin của bạn truy cập\nVui lòng nhấn Ok để đến Site chính thức của THỊ XÃ GÒ CÔNG - Cám Ơn !');
  window.open("http://thixagocong.com", '_top', '');
 }	
function do_templates(folder) {
	temp_id = document.getElementById("template").value;
	window.location.href = mainURL+'index.php?template='+temp_id;
	return false;
}
/*
class get/set cookies
*/
var Os_Cookiess={$Set:function(name,value,expires,path,domain,secure)
{var today=new Date();today.setTime(today.getTime());if(expires)
expires=expires*1000*60*60;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":"");},$Get:function(name)
{var start=document.cookie.indexOf(name+"=");var len=start+name.length+1;if((!start)&&(name!=document.cookie.substring(0,name.length)))
return null;if(start==-1)
return null;var end=document.cookie.indexOf(";",len);if(end==-1)
end=document.cookie.length;return unescape(document.cookie.substring(len,end));},$Delete:function(name,path,domain)
{document.cookie=name+"="+
((path)?";path="+path:"")+
((domain)?";domain="+domain:"")+";expires=Thu, 01-Jan-1970 00:00:01 GMT";}};
// + ---------------------- +
// |        PLAYLIST        |
// + ---------------------- +

function reloadPlaylist(add_id,remove_id) {
	try{
		document.getElementById("playlist_field").innerHTML = loadingText;
		http.open('POST',  mainURL+'index.php');
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.onreadystatechange = playlist_handleResponse;
		http.send('reloadPlaylist=1&add_id='+add_id+'&remove_id='+remove_id);
	}
	catch(e){}
	finally{}
}

function playlist_handleResponse() {
	try {
		if((http.readyState == 4)&&(http.status == 200)){
			var response = http.responseText;
			document.getElementById("playlist_field").innerHTML = response;
		}
  	}
	catch(e){}
	finally{}
}

function addToPlaylist(song_id)
{
	reloadPlaylist(song_id,0);
}
function removeFromPlaylist(song_id)
{
	reloadPlaylist(0,song_id);
}

/*------------------------------------------------------*/


function trim(a) {
	return a.replace(/^s*(S*(s+S+)*)s*$/, "$1");
}

// + ------------------- +
// |        LOGIN        |
// + ------------------- +
function login_handleResponse() {
	try {
		if((http.readyState == 4)&&(http.status == 200)){
			document.getElementById("login_loading").style.display = "none";
			var response = http.responseText;
			if (response) {
				document.getElementById("login_loading").innerHTML = response;
				document.getElementById("login_loading").style.display = "block";
			}
			else 
			alert("Đăng nhập thành công");
			window.location.href = mainURL+'index.php';
		}
  	}
	catch(e){}
	finally{}
}

function login(form) {
name = encodeURIComponent(document.getElementById("name").value);
pwd = encodeURIComponent(document.getElementById("pwd").value);
	if(	trim(name) == "" ||	trim(pwd) == "")
		alert("Bạn chưa nhập đầy đủ thông tin");
	else {
		try{
			document.getElementById("login_loading").innerHTML = loadingText;
			document.getElementById("login_loading").style.display = "block";
			http.open('POST',  mainURL+'index.php');
			http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			http.onreadystatechange = login_handleResponse;
			http.send('login=1&name='+name+'&pwd='+pwd);
			
		}
		catch(e){}
		finally{}
	}
	return false;
}

// + ---------------------- +
// |        REGISTER        |
// + ---------------------- +

function reg_handleResponse() {
	try {
		if((http.readyState == 4)&&(http.status == 200)){
			document.getElementById("reg_loading").style.display = "none";
			var response = http.responseText;
			if (response) {
				document.getElementById("reg_loading").innerHTML = response;
				document.getElementById("reg_loading").style.display = "block";
			}
			else {
				alert("Bạn đã đăng kí thành công");
				window.location.href = mainURL+'index.php';
			}
		}
  	}
	catch(e){}
	finally{}
}

function reg_check_values() {
	ok = false;
	name = encodeURIComponent(document.getElementById("reg_name").value);
	pwd = encodeURIComponent(document.getElementById("reg_pwd").value);
	pwd2 = encodeURIComponent(document.getElementById("reg_pwd2").value);
	email = encodeURIComponent(document.getElementById("reg_email").value);
	agree = document.getElementById("agree").checked;
	
	s = document.getElementsByName("reg_sex");
	if (s[0].checked) sex = s[0].value;
	if (s[1].checked) sex = s[1].value;
	
	if(	trim(name) == "" ||	trim(pwd) == "" ||	trim(pwd2) == "" ||	trim(email) == "" )
		alert("Bạn chưa nhập đầy đủ thông tin");
	else
		if (pwd != pwd2) alert("Xác nhận mật khẩu không chính xác");
		else if (!agree) alert("Bạn chưa đồng ý với các quy định của trang Web");
		else {
			try{
				document.getElementById("reg_loading").innerHTML = loadingText;
				document.getElementById("reg_loading").style.display = "block";
				http.open('POST',  mainURL+'index.php');
				http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				http.onreadystatechange = reg_handleResponse;
				http.send('reg=1&name='+name+'&pwd='+pwd+'&email='+email+'&sex='+sex);
				
			}
			catch(e){}
			finally{}
		}
	return ok;
}


// + ----------------------------- +
// |        FORGOT PASSWORD        |
// + ----------------------------- +

function forgot_handleResponse() {
	try {
		if((http.readyState == 4)&&(http.status == 200)){
			document.getElementById("forgot_loading").style.display = "none";
			var response = http.responseText;
			if (response) {
				document.getElementById("forgot_loading").innerHTML = response;
				document.getElementById("forgot_loading").style.display = "block";
			}
		}
  	}
	catch(e){}
	finally{}
}

function forgot() {
	email = encodeURIComponent(document.getElementById("u_email").value);
	if(	trim(email) == "" )	alert("Bạn chưa nhập email");
	else {
		try{
			document.getElementById("forgot_loading").innerHTML = loadingText;
			document.getElementById("forgot_loading").style.display = "block";
			http.open('POST',  mainURL+'index.php');
			http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			http.onreadystatechange = forgot_handleResponse;
			http.send('forgot=1&email='+email);
		}
		catch(e){}
		finally{}
	}
	return false;
}

function popup(folder,url,wdname,width,height)
{
	if (width == null)  { width  = 200; }   // default width
	if (height == null) { height = 400; }   // default height
	newwin=window.open(url,wdname,'fullscreen=no,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+width+',height='+height);
	if (document.all)
	{
		newwin.moveTo(0,0);
		newwin.focus();
	}
}
function broken(id,folder,width,height) {
	popup(mainURL+'brokenlink.php?id='+id,'broken',width,height);
}
function receive_gift(id) {
	window.location.href = mainURL+'index.php?go=gift_receive&id='+id;
}

function showComment(media_id) {
	try {
		document.getElementById("comment_field").innerHTML = loadingText;
		document.getElementById("comment_field").style.display = "block";
		http.open('POST',  mainURL+'comment.php');
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.onreadystatechange = function() {
			if((http.readyState == 4)&&(http.status == 200)){
				document.getElementById("comment_field").innerHTML = http.responseText;
			}
		}
		http.send('showcomment=1&media_id='+media_id);
	}
	catch(e){}
	finally{}
	return false;
}

function comment_handleResponse() {
	try {
		if((http.readyState == 4)&&(http.status == 200)){
			var response = http.responseText;
			if (response == 'OK') {
				media_id = encodeURIComponent(document.getElementById("media_id").value);
				showComment(media_id);
			}
			else document.getElementById("comment_loading").innerHTML = response;

		}
  	}
	catch(e){}
	finally{}
}

function comment_check_values() {
	media_id = encodeURIComponent(document.getElementById("media_id").value);
	comment_content = encodeURIComponent(document.getElementById("comment_content").value);
	if(trim(comment_content) == "")
		alert("Bạn chưa nhập cảm nhận");
	else if (comment_content.length > 255)
		alert("Nội dung cảm nhận quá 255 ký tự.");
	else {
		try {
			document.getElementById("comment_loading").innerHTML = loadingText;
			document.getElementById("comment_loading").style.display = "block";
			http.open('POST',  mainURL+'comment.php');
			http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			http.onreadystatechange = comment_handleResponse;
			http.send('comment=1&media_id='+media_id+'&comment_content='+comment_content);
		}
		catch(e){}
		finally{}
	}
	return false;
}

function comment_delete(media_id,comment_id) {
	if (confirm("Bạn có muốn xóa cảm nhận này không ?")) {
		document.getElementById("comment_loading").innerHTML = loadingText;
		document.getElementById("comment_loading").style.display = "block";
		http.open('POST',  mainURL+'comment.php');
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.onreadystatechange = comment_handleResponse;
		http.send('delete=1&media_id='+media_id+'&comment_id='+comment_id);
	}
	return false;
}
function gift_check_values() {
	media_id = encodeURIComponent(document.getElementById("media_id").value);
	sender_name = encodeURIComponent(document.getElementById("sender_name").value);
	recip_name = encodeURIComponent(document.getElementById("recip_name").value);
	sender_email = encodeURIComponent(document.getElementById("sender_email").value);
	recip_email = encodeURIComponent(document.getElementById("recip_email").value);
	message = encodeURIComponent(document.getElementById("message").value);
	if(	trim(sender_name) == "" ||	trim(recip_name) == "" ||	trim(sender_email) == "" ||	trim(recip_email) == "" || trim(message) == "" )
		alert("Bạn chưa nhập đầy đủ thông tin");
	else {
		try {
			document.getElementById("gift_loading").innerHTML = loadingText;
			document.getElementById("gift_loading").style.display = "block";
			http.open('POST',  mainURL+'gift.php');
			http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
			http.onreadystatechange = gift_handleResponse;
			http.send('gift=1&media_id='+media_id+'&sender_name='+sender_name+'&recip_name='+recip_name+'&sender_email='+sender_email+'&recip_email='+recip_email+'&message='+message);
		}
		catch(e){}
		finally{}
	}
	return false;
}
// BEGIN RATING
function Rating(media_id,star) {
	try {
		document.getElementById("rate_s").innerHTML = loadingText;
		document.getElementById("rate_s").style.display = "block";
		hide_rating_process();
		http.open('POST',  'rating.php');
		http.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		http.onreadystatechange = function() {
			if((http.readyState == 4)&&(http.status == 200)){
				document.getElementById("rating_field").innerHTML = http.responseText;
			}
		}
	http.send('rating=1&media_id='+media_id+'&star='+star);
	}
	catch(e){}
	finally{}
	return false;
}

	// pre-fetch image
	(new Image()).src = RATE_OBJECT_IMG;
	(new Image()).src = RATE_OBJECT_IMG_HALF;
	(new Image()).src = RATE_OBJECT_IMG_BG;

	function show_star(starNum,rate_text) {
		remove_star();
		document.getElementById("rate_text_d").innerHTML = rate_text;
		full_star(starNum);
	}
	
	function full_star(starNum) {
		for (var i=0; i < starNum; i++)
			document.getElementById('star'+ (i+1)).src = RATE_OBJECT_IMG;
	}
	function remove_star() {
		for (var i=0; i < 5; i++)
			document.getElementById('star' + (i+1)).src = RATE_OBJECT_IMG_BG; // RATE_OBJECT_IMG_REMOVED;
	}
	function remove_all_star() {
		for (var i=0; i < 5; i++) document.getElementById('star' + (i+1)).src = RATE_OBJECT_IMG_BG; // RATE_OBJECT_IMG_REMOVED;
		document.getElementById("rate_text_d").innerHTML = 'Bình Chọn';
	}
	function show_rating_process() {
		if(document.getElementById("rating_process")) document.getElementById("rating_process").style.display = "block";
		if(document.getElementById("rate_s")) document.getElementById("rate_s").style.display = "none";
	}
	function hide_rating_process() {
		document.getElementById("rating_process").style.display = "none";
		if(document.getElementById("rate_s")) document.getElementById("rate_s").style.display = "block";
	}
// END RATING
function permission(){
      alert("Bạn phải đăng nhập mới có thể sử dụng chức năng này");
    return false;
}
/*#################################END######################################*/