/*
Project: KotexPro
Filename: util.js
Description: This file contains
- Code to handle request To Server
First created on 2010-Mar-12
*/
var buttonType = "home";
var cheeringBoardStatus = "FALSE";

/*
Function name:	ShowAlertFlash
Input:		msg : message to show
Output:		A Dialog
Return:		N/A
Description:	A wrapper of Javascript alert() function that is called in Flash Application
*/
function ShowAlertFlash(msg) {
    alert(msg);
    return true;
}

/*
Function name:	GetExpireTime
Input:		N/A
Output:		N/A
Return:		Response from server as string
Description:	Called by Flash client to determine expire time
*/
function GetExpireTime() {
    return "0";
}

/*
Function name:	GetNewlyPost
Input:		N/A	
Output:		N/A
Return:		Response from server as string
Description:	Called by Flash client to get five newly post
*/
function GetNewlyPost() {
    //    var htmlStrForum = "<p><b> Chủ đề mới</b></p>"
    //				+ "<p><img src='img/icon.jpg'><a href='/forum/'>emyeukotex: \"Hello world!\"</a> </p>"
    //				+ "<p><img src='img/icon.jpg'><a href='/forum/'>luanvk: \"Welcome to KotexPro.\"</a></p>"
    //				+ "<p><img src='img/icon.jpg'><a href='/forum/'>babylove: \"Who are you, honey?\"</a></p>"
    //				+ "<p><img src='img/icon.jpg'><a href='/forum/'>guest: \"I'm here!\"</a></p>"
    //				+ "<p><img src='img/icon.jpg'><a href='/forum/'>whoami: \"What's happen to me\"</a></p>";

    return htmlStrForum;
}

/*
Function name:	GetChallengeInfo
Input:		N/A	
Output:		N/A
Return:		Response from server as string
Description:	Called by Flash client to get information for 'Chinh Phuc Thuc Thach Pro' popup
*/
function GetChallengeInfo() {
    //var htmlStr = "<a href='/Default.aspx#tab=thongbao'><img src='/images/News/Icons/KotexPro_thongbao_box copy.png' width='422' height='248'></a>";
    return htmlStr;
}

/*
Function name:	GetSelectedButton
Input:		N/A	
Output:		N/A
Return:		Response from server as string: "home", "skill", "event"
Description:	Called by Flash client to get name of selected button
*/
function GetSelectedButton() {
    // "home", "skill", "event"

    return buttonType;
}

/*
Function name:	FocusSkillButton
Input:		N/A	
Output:		N/A
Return:		N/A
Description:	Called by Flash client when user click on '100% TU TIN VOI KY NANG PRO' popup
*/
function FocusSkillButton() {
    // Add code to focus on "Bo 3 ky nang PRO" button
    //alert("Click on \"Bo 3 ky nang PRO\"");
    buttonType = "skill";
    $(".box").show();
    $(".box .content").hide();
    $(".box .content1").hide();
    $("#gamebox").fadeIn();
    $(".footer_intro").css("top", $(document).height() - 15);
    return true;
}

function FocusChallengePopup() {
    // Add code to focus on "Bo 3 ky nang PRO" button
    //alert("Click on \"Bo 3 ky nang PRO\"");
    buttonType = "event";
    $(".box").show();
    $(".box .content").hide();
    $(".box .content1").hide();
    $("#eventbox").fadeIn();
    $(".footer_intro").css("top", $(document).height() - 15);
    return true;
}

function FocusNewCertified() {
    // Add code to focus on "New Certified " popup
    //alert("Click on \"New Certified\" popup");
    buttonType = "event";
    $(".box").show();
    $(".box .content").hide();
    $(".box .content1").hide();
    $("#beprobox").fadeIn();
    document.getElementById("ctl00_Login1_txthash").value = "tab=bepro";
    $(".footer_intro").css("top", $(document).height() - 15);
    return true;
}


/*
Function name:	WindowArea
Input:		N/A	
Output:		N/A
Return:		N/A
Description:	Called by Flash client when position of window are change
*/
function WindowArea(xMin, xMax, yMin, yMax) {
    //alert("xMin = " + xMin + "; xMax = " + xMax + "; yMin = " + yMin + "; yMax = " + yMax);
    return true;
}

function btHome() {
    //btPromotion();
    
    $(".box").show();
    $(".box .content_default").show();
    buttonType = "home";
    $(".box .content").hide();
    $(".box .content_p").hide();
    $(".box .content_small").hide();
    $(".box .content1").hide()
    //$(".box").hide();
    selectedMenu = "#menuHome";
    $(selectedMenu).parent().addClass("current");
    
    
    if ( $.browser.msie ) {
      //alert( $.browser.version );
      $(".footer_intro").css("top",1480);
    }else{
        $(".footer_intro").css("top",1350);
    }
    
    //$(".footer_intro").css("top", $(document).height() - 15);
    
   
    
    /* old 
    $(".box").show();
    buttonType = "home";
    $(".box .content").hide();
    $(".box .content_p").hide();
    $(".box .content_small").hide();
    $(".box .content1").hide()
    $(".box").hide();
    selectedMenu = "#menuHome";
    $(selectedMenu).parent().addClass("current");
    $(".footer_intro").css("top", $(document).height() - 15);*/
}

/* add new for mss */
function btPromotion() {
    
    
    $(".box").show();
    buttonType = "event";
    $(".box .content").hide();
    $(".box .content_small").hide();
    $(".box .content1").hide();
    $(".box .content_default").hide();
        
    $("#ucHome").fadeIn();
    selectedMenu = "#menuPromotion";
    $(selectedMenu).parent().addClass("current");
    $(".footer_intro").css("top", $(document).height() - 15);
}


function btSkill() {
    //parent.location.hash = "?tab=game";
    document.getElementById("ctl00_Login1_txthash").value = "tab=game";
    $(".box").show();
    buttonType = "skill";
    $(".box .content").hide();
    $(".box .content_p").hide();
    $(".box .content_default").hide();
    $(".box .content_small").hide();
    $(".box .content1").hide();
    $("#gamebox").fadeIn();
    selectedMenu = "#menuGame";
    $(selectedMenu).parent().addClass("current");
    //$(".footer_intro").css("top", $(document).height() - 15);
    $(".footer_intro").css("top",700);
}
function btEvent() {
    //parent.location.hash = "?tab=thongbao";
    document.getElementById("ctl00_Login1_txthash").value = "tab=thongbao";
    $(".box").show();
    buttonType = "event";
    $(".box .content").hide();
    $(".box .content_p").hide();
    $(".box .content_default").hide();
    $(".box .content_small").hide();
    $(".box .content1").hide();
    $("#eventbox").fadeIn();
    selectedMenu = "#menuSukien";
    $(selectedMenu).parent().addClass("current");
    //$(".footer_intro").css("top", $(document).height() - 15);
    $(".footer_intro").css("top",700);
}

function btBePro() {
    //parent.location.hash = "?tab=thongbao";

    document.getElementById("ctl00_Login1_txthash").value = "tab=bepro";
    $(".box").show();
    buttonType = "event";
    $(".box .content").hide();
    $(".box .content_p").hide();
    $(".box .content_default").hide();
    $(".box .content_small").hide();
    $(".box .content1").hide()
    selectedMenu = "#menuBePRO";
    $("#beprobox").fadeIn();

    //$(".footer_intro").css("top", $(document).height() - 15);
    $(".footer_intro").css("top",700);
    
}
var selectedMenu;
$(window).resize(function() {
    $(".footer_intro").css("top", $(document).height() - 15);
});

$(document).ready(function() {
    
    //old
    //$(".box").hide();
    
    //mss adtive default
    $(".box").show();
    
    initClearDefault();
    var byName = $.getUrlVar('tab');

    if (byName == "thongbao") {

        buttonType = "event";
        $(".box .content").hide();
        $(".box .content_p").hide();
        $(".box .content_small").hide();
        $(".box .content1").hide()
        $(".box").show();
        $("#eventbox").fadeIn()
        selectedMenu = "#menuSukien";
        $(selectedMenu).parent().addClass("current");
    }

    if (byName == "bepro") {
        buttonType = "event";
        $(".box .content").hide();
        $(".box .content_p").hide();
        $(".box .content_small").hide();
        $(".box .content1").hide()
        $(".box").show();
        $(".box .content1").show();
        $("#beprobox").fadeIn()
        selectedMenu = "#menuBePRO";
        $(selectedMenu).parent().addClass("current");

    }

    if (byName == "game") {


        buttonType = "skill";
        $(".box .content").hide();
        $(".box .content_p").hide();
        $(".box .content_small").hide();
        $(".box .content1").hide()
        $(".box").show();
        $("#gamebox").fadeIn();
        selectedMenu = "#menuGame";
        $(selectedMenu).parent().addClass("current");
    }

    $(".lavaLampWithImage").lavaLamp({ fx: "backout", speed: 700 });

    if (!($.browser.msie && parseFloat($.browser.version) < 7)) {
        $(".lavaLampWithImage").width(780);
    }

    $(".footer_intro").css("top", $(document).height() - 20);

    //ShowCheeringBoard();
}
);

$.extend({ getUrlVars: 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; }, getUrlVar: function(name) { return $.getUrlVars()[name]; } });


/*
Function name:	HomePageLoadCompleted
Input:		N/A	
Output:		N/A
Return:		N/A
Description:	Called by Flash client when Home page load completed
*/
function HomePageLoadCompleted() {
    //alert("Home page load completed");
    cheeringBoardStatus = "TRUE";
}

/*
Function name:	TurnOnCheeringBoard
Input:		N/A	
Output:		N/A
Return:		Response from server as string: "TRUE", "FALSE"
Description:	Called by Flash client to get status of 'Cheering Board'
*/
function TurnOnCheeringBoard() {
    return cheeringBoardStatus;
}

/*
Function name:	ShowCheeringBoard
Input:		N/A	
Output:		N/A
Return:		N/A
Description:	Called by Flash client when user click on 'Show Cheering Board'
*/
function ShowCheeringBoard() {
    // Add code to focus on "cheering board"
    //alert("Show Cheering Board");

    tb_show("", "CheeringBoard.aspx?keepThis=true&TB_iframe=true&height=500&width=750", "");
}

function ShowCheeringBoard1() {
    //alert('aaa');
    //var p = parent.parent;
    $("#TB_window").remove();
    $("body").append("<div id='TB_window'></div>");
    //alert('s');
    tb_show("", "/CheeringBoard.aspx?keepThis=true&TB_iframe=true&height=500&width=750", "");

    //return false;
}

