﻿// returns true if the string is empty
function isEmpty(s) {
	return (s == null || s.length == 0); //false isnot empty
}
// returns true if the string only contains characters A-Z or a-z
function isAlpha(str) {
	var re = /[^a-zA-Z]/g
	if (re.test(str)) return false;
	return true;
}
// returns true if the string only contains characters 0-9
function isNumber(s) {
	var r = /^\d+$/; return r.test(s);
}
// returns true if the string only contains characters A-Z, a-z or 0-9
function isAlphanumeric(s) {
	var r = /^[a-zA-Z0-9]+$/; return r.test(s);
}

// returns true if the string's length equals "len"
function isLength(str, len) {
	return str.length == len;
}
// returns true if the string's length is between "min" and "max"
function isLengthBetween(str, min, max) {
	return (str.length >= min) && (str.length <= max);
}
// returns true if "str1" is the same as the "str2"
function isMatch(str1, str2) {
	return str1 == str2;
}
// returns true if the string contains only whitespace
// cannot check a password type input for whitespace
function isWhitespace(str) { // NOT USED IN FORM VALIDATION
	var re = /[\S]/g
	if (re.test(str)) return false;
	return true;
}
// removes any whitespace from the string and returns the result
// the value of "replacement" will be used to replace the whitespace (optional)
function stripWhitespace(str, replacement) {// NOT USED IN FORM VALIDATION
	if (replacement == null) replacement = '';
	var result = str;
	var re = /\s/g
	if (str.search(re) != -1) {
		result = str.replace(re, replacement);
	}
	return result;
}

// Trả về giá trị True nếu địa chỉ Email hợp lệ
function isValidEmail(str) {
	return str.match(/^([a-zA-Z0-9_\-\.]+)@([a-zA-Z0-9_\-\.]+)\.([a-zA-Z]{2,5})$/)
}

// Hàm cắt khoảng trắng 2 ở đầu chuỗi
function sTrim(s) {
	while (s.charCodeAt(0) <= 32) {
		s = s.substr(1)
	}
	while (s.charCodeAt(s.length - 1) <= 32) {
		s = s.substr(0, s.length - 1)
	}
	return s
}

// Hàm kiểm tra ngày hợp lệ
function isDate(day, month, year) {
	if ((month < 1) || (month > 12)) return false
	var dt = new Date(year, month - 1, day)
	if (dt.getDay() != day)
		return false
	else
		return true
}
function ReplaceAll(iStr, v1, v2) {
	var i = 0, oStr = '', j = v1.length;
	while (i < iStr.length) {
		if (iStr.substr(i, j) == v1) {
			oStr += v2;
			i += j
		}
		else {
			oStr += iStr.charAt(i);
			i++;
		}
	}
	return oStr;
}

function isContains(str,substr){
	return (str.indexOf(substr) >= 0) ? true:false;
}

function loadXMLFile(dname) {
    try //Internet Explorer
        {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    }
    catch (e) {
        try //Firefox, Mozilla, Opera, etc.
            {
            xmlDoc = document.implementation.createDocument("", "", null);
        }
        catch (e) { alert(e.message) }
    }
    try {
        xmlDoc.async = false;
        xmlDoc.load(dname);
        return (xmlDoc);
    }
    catch (e) { 
		//Google Chrome
		try{
			var xmlhttp = new window.XMLHttpRequest();
			xmlhttp.open("GET",dname,false);
			xmlhttp.send(null);
			xmlDoc = xmlhttp.responseXML.documentElement;
			return (xmlDoc);
		}
		catch(e){
			alert(e.message);
		}
	}
    return (null);
}

// Format number by using 1000 seperator
function FormatN(num) {
	var n = ReplaceAll(num, ',', '');
	if (n == '') return '0';
	var no = FormatNumber(parseInt(n), false, false, false, true);
	return no;
}

//Resize Images
function ResizeImages(img) {
	if (img.width > 500) {
		img.height = parseInt(img.height * 500 / img.width);
		img.width = 500;
	}
}
// validation PIN
    function CheckSerialPIN(oSrc, args) {
	if (sTrim(args.Value).length != 10) {
		args.IsValid = false;
	} else {
		args.IsValid = true;
	}
	return args.IsValid;
}

// end validation PIN
function validSearch() {
	var txtSearch = document.getElementById("txtSearch").value;
	var reg = new RegExp("<[a-zA-Z0-0_]+|/[a-zA-Z0-0_>]+");
	if(reg.test(txtSearch)){
	    alert("Bạn không được nhập ký tự đặc biệt <></>.")
	    return false;
	}
	if (txtSearch == '' || txtSearch == 'Tìm kiếm') {
		alert('Bạn chưa nhập từ khóa cần tìm.');
		return false;
	}
	else if ((isContains(txtSearch,'<')) || (isContains(txtSearch,'>'))){
	    alert('Từ khóa không được có "<" hoặc ">".');
		return false;
	}
	else {
		return true;
	}
}
//
function validVerify() {
	var txtVerify = document.getElementById("txtVerify").value;
	var reg = new RegExp("<[a-zA-Z0-0_]+|/[a-zA-Z0-0_>]+");
	if(reg.test(txtSearch)){
	    alert("Bạn không được nhập ký tự đặc biệt <></>.")
	    return false;
	}
	 if ((isContains(txtVerify,'<')) || (isContains(txtVerify,'>'))){
	    alert('Từ khóa không được có "<" hoặc ">".');
		return false;
	}
	else {
		return true;
	}
}
//
function redirectURL(url) {
	window.location.href = url;
}

function redirectURLNew(url) {
	var newWindow = window.open(url,'_blank');
	newWindow.focus();
	return false;
}

function replaceCharacter(str,oldReplace,newReplace){
    var newStr = str.split(oldReplace);
    newStr = newStr.join(newReplace);
    return newStr;
}
$.extend({
    getUrlParams: function(){
        var vars = [], hash;
        var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for(var i = 0; i < hashes.length; i++){
          hash = hashes[i].split('=');
          vars.push(hash[0]);
          vars[hash[0]] = hash[1];
        }
        return vars;
    },
    getUrlParam: function(name){
        return $.getUrlParams()[name];
    }
});
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;
		expires = expires * 1000 * 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" : "");
}

function Get_CookieValue(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;
	}
}

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";
}

function Get_Cookie(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));
}

function IntroCookie(IntroURL)
{
	//Detected Cookie Browser
	var cookieEnabled=(navigator.cookieEnabled)? true : false;
	//if not IE4+ nor NS6+
	if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ 
		document.cookie="checkcookie"
		cookieEnabled=(document.cookie.indexOf("checkcookie")!=-1)? true : false 
	}

	if (cookieEnabled){
		if(!Get_Cookie('IntroLOONG')){
			//Write Cookie
			Set_Cookie('IntroLOONG','Intro Actived',5,'/','','');
			window.location.href = IntroURL;
		}
	}
}
function CheckCookie(IntroURL,Value)
{
//Detected Cookie Browser
	var cookieEnabled=(navigator.cookieEnabled)? true : false;
	//if not IE4+ nor NS6+
	if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ 
		document.cookie="checkcookie"
		cookieEnabled=(document.cookie.indexOf("checkcookie")!=-1)? true : false 
	}

	if(!Get_Cookie(Value)){
		//Write Cookie
		Set_Cookie(Value,'RegisterDR',5,'/','','');
		window.location.href = IntroURL;
	}
}

function IntroPopup(URL, ImgURL)
{
	//Detected Cookie Browser
	var cookieEnabled=(navigator.cookieEnabled)? true : false;
	//if not IE4+ nor NS6+
	if (typeof navigator.cookieEnabled=="undefined" && !cookieEnabled){ 
		document.cookie="checkcookie"
		cookieEnabled=(document.cookie.indexOf("checkcookie")!=-1)? true : false 
	}

	if (cookieEnabled){
		if(!Get_Cookie('PopupIntroTDK')){
			//Write Cookie
			var sHTML = '';
			sHTML += '<a href="' + URL + '" target="_blank" onclick="HidePopup();"><img alt="" src="' + ImgURL +'" width="450" height="300" border="0" /></a>';
			sHTML += '<div class="popupClose"><a href="javascript:void(-1);" onclick="HidePopup();">Close</a></div>';
			Set_Cookie('PopupIntroTDK','Popup Intro Actived',10,'/','','');
			$('#popupIntro').html(sHTML);
			centerPopup("popupIntro");
			loadPopup("popupIntro");
		}
	}
}

function HidePopup(){
	disablePopup("popupIntro");
}

var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(objPopup){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
						"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#" + objPopup).fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(objPopup){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#" + objPopup).fadeOut("slow");
		popupStatus = 0;
	}
}

function disablePopup2(objPopup1,objPopup2){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#" + objPopup1).fadeOut("slow");
		$("#" + objPopup2).fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(objPopup){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight;
	if ( $("#" + objPopup).height() > windowHeight){
		popupHeight = windowHeight;
	}
	else{
		popupHeight = $("#" + objPopup).height();
	}
	var popupWidth = $("#" + objPopup).width();
	//centering
	$("#" + objPopup).css({
					"position": "absolute",
					"top": windowHeight/2-popupHeight/2,
					"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
					"height": windowHeight
	});
                
}
//URL Encode / Decode
var Url = {

	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},

	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},

	// private method for UTF-8 encoding
	_utf8_encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

}
//Thông tin
function Info_GetLeftMenuName(RootID){
    var objName = '';
    if (RootID == '54'){
        objName = 'ThongTin_GioiThieu_LeftMenu';
    }
    else if (RootID == '55'){
        objName = 'ThongTin_HuongDan_LeftMenu';
    }
    else if (RootID == '56'){
        objName = 'ThongTin_DacTrung_LeftMenu';
    }
    else if (RootID == '59'){
        objName = 'ThongTin_CongDong_LeftMenu';
    }
    else if (RootID == '60'){
        objName = 'ThongTin_HoTro_LeftMenu';
    }
    return objName;
}

function Info_GetRightMenuName(RootID){
    var objName = '';
    if (RootID == '54'){
        objName = 'ThongTin_GioiThieu_RightMenu';
    }
    else if (RootID == '55'){
        objName = 'ThongTin_HuongDan_RightMenu';
    }
    else if (RootID == '56'){
        objName = 'ThongTin_DacTrung_RightMenu';
    }
    else if (RootID == '59'){
        objName = 'ThongTin_CongDong_RightMenu';
    }
    else if (RootID == '60'){
        objName = 'ThongTin_HoTro_RightMenu';
    }
    return objName;
}

function Info_GetNaviMenuName(RootID){
    var objName = '';
    if (RootID == '54'){
        objName = 'ThongTin_GioiThieu_NaviMenu';
    }
    else if (RootID == '55'){
        objName = 'ThongTin_HuongDan_NaviMenu';
    }
    else if (RootID == '56'){
        objName = 'ThongTin_DacTrung_NaviMenu';
    }
    else if (RootID == '59'){
        objName = 'ThongTin_CongDong_NaviMenu';
    }
    else if (RootID == '60'){
        objName = 'ThongTin_HoTro_NaviMenu';
    }
    return objName;
}
function Info_GetContentName(RootID){
    var objName = '';
    if (RootID == '54'){
        objName = 'ThongTin_GioiThieu_Content';
    }
    else if (RootID == '55'){
        objName = 'ThongTin_HuongDan_Content';
    }
    else if (RootID == '56'){
        objName = 'ThongTin_DacTrung_Content';
    }
    else if (RootID == '59'){
        objName = 'ThongTin_CongDong_Content';
    }
    else if (RootID == '60'){
        objName = 'ThongTin_HoTro_Content';
    }
    return objName;
}
 
function Info_GetFirstThongTin(RootID){
    try{
        Info_GetLeftMenu(RootID,Info_GetLeftMenuName(RootID), Info_GetNaviMenuName(RootID), Info_GetRightMenuName(RootID),Info_GetContentName(RootID));    
    }
    catch(e){
        alert(e);
    }
}

function Info_GetLeftMenu(iRootID, objLeftMenu, objNaviMenu, objRightMenu, objContent){
    var foundLeftMenu, objLeftMenu1, LeftMenuItem;
    
    $.ajax({
            type: 'GET',
            url: '/Event/Ajax/ThongTin/GetLeftMenu.aspx',
            data: {RootID: iRootID},
            cache: false,
            success: function(msg)
            {
                $('#' + objLeftMenu).html(msg);
            },
            complete: function(){
                foundLeftMenu = $('#' + objLeftMenu).find('a');
                if (foundLeftMenu.length >0){
                    objLeftMenu1 = foundLeftMenu.get(0);
                    LeftMenuItem = $(objLeftMenu1).attr('rel');
                    Info_GetContentLeftMenu(iRootID, LeftMenuItem,objNaviMenu,objRightMenu,objContent);
                }
            }
        }
    );
}

function Info_GetContentLeftMenu(RootID, LeftNodeID, objNaviMenu, objRightMenu, objContent){
    try{
        //Get NaviMenu
        Info_GetNaviMenu(RootID, LeftNodeID,objNaviMenu);
        //Get Right Menu
        Info_GetRightMenu(RootID, LeftNodeID,objRightMenu, objContent);
        //
        ActiveLeftMenu(RootID,LeftNodeID);
    }
    catch(e){}
}

function Info_GetContentRightMenu(RootID, InfoID, InfoTitleDom, Title, objContent){
    try{
        //Get NaviMenu
        $('#' + InfoTitleDom).text(Title);
        //Get Content
        Info_GetContent(RootID, InfoID,objContent);
        ActiveRightMenu(RootID,InfoID);
    }
    catch(e){}
}

function Info_GetRightMenu(iRootID, InfoID, objDom, objContent){
    var foundRightMenu, objRightMenu, RightMenuItem, sHtml;
    $.ajax({
            type: 'GET',
            url: '/Event/Ajax/ThongTin/GetRightMenu.aspx',
            data: {RootID: iRootID, ContentID: InfoID},
            cache: false,
            success: function(msg)
            {
                $('#' + objDom).html(msg);
            },
            complete: function(){
                sHtml = $('#' + objDom).html();
                if (!isEmpty(sHtml)){
                    foundRightMenu = $('#' + objDom).find('a');
                    if (foundRightMenu.length > 0){
                        objRightMenu = foundRightMenu.get(0);
                        RightMenuItem = $(objRightMenu).attr('rel');
                        Info_GetContent(iRootID, RightMenuItem,objContent);
                    }
                    else{
                        Info_GetContent(iRootID, InfoID,objContent);
                    }
                }
                else{
                    Info_GetContent(iRootID, InfoID,objContent);
                }
            }
        }
    );
}

function Info_GetNaviMenu(iRootID, InfoID, objDom){
    $.ajax({
            type: 'GET',
            url: '/Event/Ajax/ThongTin/GetNaviMenu.aspx',
            data: {RootID: iRootID, ContentID: InfoID},
            cache: false,
            success: function(msg)
            {
                $('#' + objDom).html(msg);
            }
        }
    );
}
function Info_GetContent(iRootID, InfoID, objDom){
    $.ajax({
            type: 'GET',
            url: '/Event/Ajax/ThongTin/GetContent.aspx',
            data: {RootID: iRootID, ContentID: InfoID},
            cache: false,
            success: function(msg)
            {
                $('#' + objDom).html(msg);
            }
        }
    );
}

function Info_GetParentID(InfoID){
	var result = '';
    $.ajax({
            type: 'GET',
            url: '/Event/Ajax/ThongTin/GetParentID.aspx',
            data: {ContentID: InfoID},
            cache: false,
            success: function(msg)
            {
                result = msg;
            }
        }
    );
	return result;
}

function ActiveLeftMenu(RootID,LeftNodeID){
    var prefixName = 'ThongTin_LeftMenu_';
    var arrLeftMenu, objLeftMenu, sSRC;
    try{
        sSRC = '';
        arrLeftMenu = $('img[name="' + prefixName + RootID + '"]');
        objLeftMenu = $('#' + prefixName + LeftNodeID);
        
        for ( var i = 0; i<= arrLeftMenu.length - 1; i++){
            sSRC = $(arrLeftMenu.get(i)).attr('src');
            $(arrLeftMenu.get(i)).attr('src',replaceCharacter(sSRC,'_2',''));
        }
        sSRC = $('#' + prefixName + LeftNodeID).attr('src');
        $('#' + prefixName + LeftNodeID).attr('src',replaceCharacter(sSRC,'.gif','_2.gif'));
    }
    catch(e){}
}

function ActiveRightMenu(RootID,LeftNodeID){
    var prefixName = 'ThongTin_RightMenu_';
    var arrLeftMenu, objLeftMenu, sSRC;
    try{
        sSRC = '';
        arrLeftMenu = $('img[name="' + prefixName + RootID + '"]');
        objLeftMenu = $('#' + prefixName + LeftNodeID);
        
        for ( var i = 0; i<= arrLeftMenu.length - 1; i++){
            sSRC = $(arrLeftMenu.get(i)).attr('src');
            $(arrLeftMenu.get(i)).attr('src',replaceCharacter(sSRC,'_2',''));
        }
        sSRC = $('#' + prefixName + LeftNodeID).attr('src');
        $('#' + prefixName + LeftNodeID).attr('src',replaceCharacter(sSRC,'.png','_2.png'));
    }
    catch(e){}
}
function GameInfo_ActiveLeftMenu(){
       
	var urlReferer = window.location.href;
	var arrUrlContent1 = new Array();
	var arrUrlContent2 = new Array();
	try{
		if (isContains(urlReferer,'ThongTin')){
			//Disable Left Menu
			$('#LeftMenu_GameInfo').find('a').attr('class','');
			$('#LeftMenu_GameInfo').find('div.accor_txt').attr('style','height: auto; overflow: hidden; display: none;');
			$('#GameInfo_A_50').attr('class','hd');
			//Get URL Referer
			arrUrlContent1 = urlReferer.split('http://loong.us/');
			arrUrlContent2 = arrUrlContent1[1].split('/');
		
			//Get ID Menu
			$.ajax({
						type: 'GET',
						url: '/Event/Ajax/ThongTin/GetParentID.aspx',
						data: {ContentID: arrUrlContent2[1]},
						cache: false,
						success: function(msg)
						{
							//Enable Menu Item
							if (msg == '50'){
							    $('#GameInfo_A_' + msg).attr('class','hd selected');
							}
							else{
							    $('#GameInfo_A_' + msg).attr('class','selected');  
							}
							
							$('#GameInfo_Accor_' + msg).attr('style','height: auto; overflow: hidden;');
						}
					}
				);
		}
	}
	catch(e){}
}
//Download
function GetDownloadLink(Category, objDom){
    var _Location, _Server;
   
    try{
        
        if (Category == '1'){ //Full
            _Location = $('#ddlLocation_Full :selected').val();
            _Server = $('#ddlServer_Full :selected').val();
        }
        else if (Category == '2'){ //Patch
            _Location = $('#ddlLocation_Patch :selected').val();
            _Server = $('#ddlServer_Patch :selected').val();
        }
        else if (Category == '3'){ //Chia nho
            _Location = $('#ddlLocation_Small :selected').val();
            _Server = $('#ddlServer_Small :selected').val();
        }
    
        $.ajax({
            type: 'GET',
            url: '/Event/Ajax/Download/GetDownloadLink.aspx',
            data: {Type: Category, Location: Url.encode(sTrim(_Location)), Server: Url.encode(sTrim(_Server))},
            cache: false,
            success: function(msg)
            {
                $('#' + objDom).html(msg);
            }
        });
    }
    catch(e){}
}
function countDownload(sLink, sText, sServer){
 
    try{
        $.ajax({
            type: 'GET',
            url: '/Event/Ajax/Download/Count.aspx',
            data: {Link: sLink, Text: sText, Server:sServer},
            cache: false,
            success: function(msg)
            {
                redirectURL(msg);
            }
        });
    }
    catch(e){}
}
function countDownloadServer(sLink, sText, sServer){
 
    try{
        $.ajax({
            type: 'GET',
            url: '/Event/Ajax/Download/Count.aspx',
            data: {Link: sLink, Text: sText, Server: sServer},
            cache: false,
            success: function(msg)
            {
                //redirectURL(msg);
                redirectURLNew(msg);
            }
        });
    }
    catch(e){}
}
//Event Banner

function GetEventBanner(){
    var pathxml ="/WSFile/FlashXML/SuKien/SuKien.xml";
    var xmlDoc = loadXMLFile(pathxml);
    var img = xmlDoc.getElementsByTagName("image");
    var link = xmlDoc.getElementsByTagName("link");
    var sHTML='';
    for (var i = 0; i < img.length; i++){
       // sHTML += '<a href="' + imgs[i].attributes["link"].value + '"><img id="slide-img-' + (i + 1) + '" src="' +  imgs[i].attributes["image"].value + '" class="slide"  alt="" /></a>';
        sHTML += '<a href="' + link[i].childNodes[0].nodeValue + '"><img id="slide-img-' + (i + 1) + '" src="' +  img[i].childNodes[0].nodeValue + '" class="slide"  alt="" /></a>';
    } 
   $('#slide-runner').append(sHTML);
   
   
}

function redirectLogin(){
    var url = window.location.href;
    var returnURL = $.getUrlParam('ReturnURL');
    if ((url.toLowerCase() == 'https://pay.loong.us/signin/')
            ||(url.toLowerCase() == 'https://pay.loong.us/signin/default.aspx')
            ||(url.toLowerCase() == 'https://pay.loong.us/register/')
            ||(url.toLowerCase() == 'https://pay.loong.us/register/default.aspx')
            ||(url.toLowerCase() == 'http://pay.loong.us/register/')
            ||(url.toLowerCase() == 'http://pay.loong.us/signin/default.aspx')
            ||(url.toLowerCase() == 'http://pay.loong.us/signin/')
            ||(url.toLowerCase() == 'http://pay.loong.us/register/default.aspx')){
        redirectURL('http://pay.loong.us/SignIn/');
    }
    else{
        if (isEmpty(returnURL)){
            redirectURL('http://pay.loong.us/SignIn/?ReturnURL=' + url);
        }
        else{
            redirectURL('http://pay.loong.us/SignIn/?ReturnURL=' + returnURL);
        }
    }
}

function redirectRegister(){
    redirectURL('http://pay.loong.us/Register/');
}
function loadToolBar() {
    $.ajax(
        {
         type: "GET",
            url: "/Event/Ajax/ToolBar/GetToolBar.aspx",
            cache: false,
            success: function(msg)  //show the result
            {
                $('#DivToolbar').html(msg);
            }
        }
    );
}
// Images Load

function ReloadImage(id, srcname) {
    var elm = document.getElementById(id);
    var dt = new Date();
    elm.src = srcname + '?t=' + dt;
    return false;
}
//Tracking
function Tracking(nameTracking){
    utm_source = $.getUrlParam('utm_source');
    utm_medium = $.getUrlParam('utm_medium');
    utm_campaign = $.getUrlParam('utm_campaign');
    event_name = nameTracking;
    
    if ((utm_source != null) && (utm_medium != null) && (utm_campaign != null)) {
        $.ajax(
            {
                type: 'GET',
                url: '/Event/Ajax/Tracking/Default.aspx',
                data: { utm_source: utm_source, utm_medium: utm_medium, utm_campaign: utm_campaign, event_name: event_name },
                cache: false,
                success: function(msg) {}
            }
        );
    }
}

//Get Top Cao Thu
function GetTopup(serverid){
    $.ajax(
        {
            type: "GET",
            url: "/Event/Ajax/Top/Default.aspx",
            data: {ServerID: serverid},
            cache: false,
            success: function(msg)  //show the result
            {
                $('#topcaothu').html(msg);
            }
        }
    );
}
