// JavaScript Document
var ndialog; 

function openGdalog(){
	if(ndialog) {
		ndialog.close();
		ndialog  = null;
		setTimeout(function(){
			ndialog = new GoldDialog("", {width:660, height:660, useIframe:true, url:'reg.jsp?t='+Math.random()});
		}, 10);
	}else{
		ndialog = new GoldDialog("", {width:660, height:660, useIframe:true, url:'reg.jsp?t='+Math.random()});
	}
	
	return false;
}

function openLdalog() {
    if (ndialog) {
        ndialog.close();
        ndialog = null;
        setTimeout(function () {
            ndialog = new GoldDialog("", { width: 550, height: 300, useIframe: true, url: 'login.jsp?t=' + Math.random() });
        }, 10);
    } else {
        ndialog = new GoldDialog("", { width: 550, height: 300, useIframe: true, url: 'login.jsp?t=' + Math.random() });
    }

    return false;
}

var paydialog;
var curTradeNo = "";
function clickPayBtn(){
	var meo = $("#buyTabsId");
	var t = "&t=" + new Date().getTime();
	$(".csbMenu a", meo).each(function(i){
		var selected = $(this).attr("class");
		if(selected.indexOf("on")>=0){// && i!=0
			var path = $(this).attr("href");
			if(path != "" && path != "#" && path != "javascript:void(0)"){
				var rel = $(this).attr("rel");
				var relCon = $("#"+rel);
				//$(".ifr", relCon)[0].src = "/trade/isPay.action"+t;
				$(".ifr", relCon)[0].contentWindow.location = "/trade/isPay.action?orderNoId=" + curTradeNo + t;
			}		
		}
	});
	
	paydialog.close();
	paydialog = null;
}
function openPayTip(tradeNo) {
    curTradeNo = tradeNo;
	var con = '<div class="payInfo"><p class="desc">请您在新打开的网上银行页面上完成付款。</p></div>'
				+'<div class="payTip"><b>友情提示：</b><br />1.付款完成前请不要关闭此窗口。<br />2.付款成功后，该窗口将自动关闭；如需重新付款请点击下面的按钮：<div style="text-align:center; padding-top:10px; height:30px;"><input type="button" onclick="clickPayBtn()" name="button" value=" 重新选择银行 " /></div></div>';
	paydialog = new PayDialog(con, {width:400, height:400});
}
function commonDialog(strUrl, strWidth, strHeight) {
    if (!strUrl) return;
    if (!strWidth) strWidth = 600;
    if (!strHeight) strHeight = 400;
    if (ndialog) {
        ndialog.close();
        ndialog = null;
        setTimeout(function () {
            ndialog = new GoldDialog("", { width: strWidth, height: strHeight, useIframe: true, url: strUrl });
        }, 10);
    } else {
        ndialog = new GoldDialog("", { width: strWidth, height: strHeight, useIframe: true, url: strUrl});
    }
    return false;
}
function openDalog(strUrl, strWidth, strHeight){
	if(!strUrl) return;
	if(!strWidth) strWidth = 500;
	if(!strHeight) strHeight = 400;
	if(ndialog) {
		ndialog.close();
		ndialog  = null;
		setTimeout(function(){
			ndialog = new GoldDialog("", {width:strWidth, height:strHeight, useIframe:true, url:strUrl+"?t="+Math.random()});
		}, 10);
	}else{
		ndialog = new GoldDialog("", {width:strWidth, height:strHeight, useIframe:true, url:strUrl+"?t="+Math.random()});
	}	
	return false;
}

var listDialog;
function openListDalog(element, strWidth, strHeight) {
    var strUrl = '';
    if (element) {
        strUrl = $(element).attr("rel");
        if (!strUrl) return;
    } else {
        var campName = "";
        if (campVL && hasCamp) {
            campName = "&campName=" + campVL;
        }
        strUrl = "/trade/queryAllSoldGoods.action?gameOrgId=" + gameOrgId + campName;
    }
	if(!strWidth) strWidth = 600;
	if(!strHeight) strHeight = 400;
	if(listDialog) {
		listDialog.close();
		listDialog  = null;
		setTimeout(function(){
			listDialog = new GoldDialog("", {width:strWidth, height:strHeight, useIframe:true, url:strUrl+"&t="+Math.random()});
		}, 10);
	}else{
		if(jQuery.browser.msie){
			setTimeout(function(){
				listDialog = new GoldDialog("", {width:strWidth, height:strHeight, useIframe:true, url:strUrl+"&t="+Math.random()});
			}, 10);
		}else{
			listDialog = new GoldDialog("", {width:strWidth, height:strHeight, useIframe:true, url:strUrl+"&t="+Math.random()});
		}
	}	
	return false;
}
function closeListDalog(){
	listDialog.close();
	listDialog  = null;
}
function openGdalogRs(str){
	if(!str) return;
	if(ndialog) {
		ndialog.close();
		ndialog  = null;
		setTimeout(function(){
			ndialog = new GoldDialog(str, {width:600, height:600, mask:false});
		}, 10);
	}else{
		ndialog = new GoldDialog(str, {width:600, height:600, mask:false});
	}
	
	return false;
}
function gdialogClose(){
	ndialog.close();
	ndialog  = null;
}
function openLightBox(strPath){
	if(strPath){
		var libox = new LightBox({imgPath:strPath});
	}
}
var infoTipShow = false;
function infoTipDialog(info, strWidth, strHeight){
	if(!info) return;
	if(!strWidth) strWidth = 500;
	if(!strHeight) strHeight = 400;
		
	if(ndialog) {
		ndialog.close();
		ndialog  = null;
		setTimeout(function(){
			ndialog = new GoldDialog(info, {width:strWidth, height:strHeight, useIframe:false});
		}, 10);
	}else{
		ndialog = new GoldDialog(info, {width:strWidth, height:strHeight, useIframe:false});
	}
	return false;
}
jQuery(document).ready(function ($)
{
    // 当用户点击登录按钮时 
    $('.user_login').click(function ()
    {

       
        ndialog = new GoldDialog("", { width: 660, height: 600, useIframe: true, url: 'login.jsp?t=' + Math.random() });
        return false;
    });
    $('.user_reg').click(function ()
    {
       
        ndialog = new GoldDialog("", { width: 660, height: 600, useIframe: true, url: 'reg.jsp?t=' + Math.random() });
        return false;
    });
    $('#user-act-chpass').click(function ()
    {
        openDalog('user_pwd_modefiy.jsp', 560, 660);
        return false;
    });
    $('#user-act-info').click(function ()
    {
        openDalog('user/getUserInfo.action', 560, 660);
        return false;
    });

    $('#zjmxId').click(function ()
    {
        ndialog = new GoldDialog("", { width: 680, height: 660, useIframe: true, url: '/moneyDetail.action?t=' + Math.random() });
        return false;
    });

});
function initTime(){
	 var dateEl = $('.date');
     var timeEl = $('.time');
     setInterval(function (){
         var now = new Date();
         var date = (now.getMonth()+1) + '月' + now.getDate() + '日';
         var time = ('00' + now.getHours()).slice(-2) +
                 ':' + ('00' + now.getMinutes()).slice(-2) +
                 ':' + ('00' + now.getSeconds()).slice(-2);
         dateEl.text(date);
         timeEl.text(time);
     }, 500);
 }

 function refreshNav() {
     var url = "/User/GetCurrentUserName.action?t=" + new Date().getTime();
     $.getJSON(url, function (obj) {
         if (obj.UserName) {
             var html = '<a href="/">首页</a> | <a href="/Member/SupplyOnlines.action" target="_blank">用户中心</a> | <a class="none_line" id="user-act-logout" href="/j_spring_security_logout">退出</a>';
             $(".memberNav").html(html);
             $(".loginInfo").text(obj.UserName + "，欢迎您来到50洲！" + " 可用账户资金：" + obj.Balance);
         }
     });
 }
