﻿function OpenFixedWin(address, winname, height, width, scrollbars,resizeable) {
	var iHeight = height;
	var iWidth = width;
	var iLeft = (screen.width - iWidth)/2;
	var iTop = (screen.height- iHeight)/2;
	var iScrollbars = scrollbars;
	var iResizeable = resizeable;
	if(iScrollbars == null || iScrollbars=="") iScrollbars = "yes";
	var feature = "left="+iLeft+",top="+iTop+",fullscreen=0,width= " + iWidth + ",height=" + iHeight +",toolbar=no, menubar=no, scrollbars=" + iScrollbars + ", resizable=" + iResizeable+ ", location=no, status=yes";
	var win =window.open(address,winname,feature);	
	win.focus();
	win = null;
}

//绑定首页的内容切换事件
function BindHoverEvent(objName, suffix) {
    var obj = $(objName);
    if (obj) {
        obj.hover(
        function() { obj.each(function(i) { $(this).removeClass("select"); $("#" + $(this).attr("name") + suffix).hide(); }); $(this).addClass("select"); $("#" + $(this).attr("name") + suffix).show(); },
        function() { });
    }
}

function ShowModalDialogPage(url, width, height) {
    var x = parseInt(screen.width / 2.0) - (width / 2.0);
    var y = parseInt(screen.height / 2.0) - (height / 2.0);
    var isMSIE = (navigator.appName == "Microsoft Internet Explorer");
    if (isMSIE) {
        retval = window.showModalDialog(url, window, "dialogWidth:" + width + "px; dialogHeight:" + height + "px; dialogLeft:" + x + "px; dialogTop:" + y + "px; status:no; directories:yes;scrollbars:no;Resizable=no; ");
    } else {
        var win = window.open(url, "Warehouse", "top=" + y + ",left=" + x + ",scrollbars=" + scrollbars + ",dialog=yes,modal=yes,dependance=yes,width=" + width + ",height=" + height + ",resizable=no");
        eval('try { win.resizeTo(width, height); } catch(e) { }');
        win.focus();
    }
}

function ShowModalDialogPageAndRefresh(url, width, height,commitButtonId) {
    var x = parseInt(screen.width / 2.0) - (width / 2.0);
    var y = parseInt(screen.height / 2.0) - (height / 2.0);
    var isMSIE = (navigator.appName == "Microsoft Internet Explorer");
    
    if (url.indexOf("?") > -1)
        url += "&buttonId=" + commitButtonId;
    else
        url += "?buttonId=" + commitButtonId;
        
    if (isMSIE) {
        retval = window.showModalDialog(url, window, "dialogWidth:" + width + "px; dialogHeight:" + height + "px; dialogLeft:" + x + "px; dialogTop:" + y + "px; status:no; directories:yes;scrollbars:no;Resizable=no; ");
    } else {
        var win = window.open(url, "Warehouse", "top=" + y + ",left=" + x + ",scrollbars=" + scrollbars + ",dialog=yes,modal=yes,dependance=yes,width=" + width + ",height=" + height + ",resizable=no");
        eval('try { win.resizeTo(width, height); } catch(e) { }');
        win.focus();
    }
}

function TriggerParentButtonClick(buttonId) {
    var button;

    var isMSIE = (navigator.appName == "Microsoft Internet Explorer");
    if (isMSIE) {
        button = window.dialogArguments.document.getElementById(buttonId);
    } else {
        button = window.opener.document.getElementById(buttonId);
    }
    
    if (button) {
        if (document.all) {
            button.click();
        }
        else {
            var evt = document.createEvent("MouseEvents");
            evt.initEvent("click", true, true);
            button.dispatchEvent(evt);
        }
    }
}

//订单全选
function SetCheckBox(obj) {
    var checks = document.getElementsByTagName("input");
    for (var i = 0; i < checks.length; i++) {
        if (checks[i].type == "checkbox")
            checks[i].checked = obj.checked;
    }
}

function SetCheckBoxByContainId(obj,id) {
    var checks = document.getElementsByTagName("input");
    for (var i = 0; i < checks.length; i++) {
        if (checks[i].type == "checkbox" && checks[i].id.indexOf(id) > -1)
            checks[i].checked = obj.checked;
    }
}


function CloseCurrWindow() {
    var browserName = navigator.appName;
    if (browserName == "Netscape") {
        window.open('', '_parent', ''); 
        window.close();
    } else if (browserName == "Microsoft Internet Explorer") {
        window.opener = "whoCares";
        window.opener = null;    //Close window, not hint. for IE6, IE7  
        window.open('', '_top'); //Close window, not hint. for IE7  
        window.close();
    }
}

function CloseCurrWindowAndReload() {
    var isMSIE = (navigator.appName == "Microsoft Internet Explorer");
    if (isMSIE) {
        window.dialogArguments.window.location = window.dialogArguments.window.location;
    } else {
        window.opener.location = window.opener.location;
    }
    window.close();
}


function IniProgressIFrame() {
    var dde = document.documentElement || document.body;
    var screenIFrame = document.getElementById("ProgressIFrame");
    screenIFrame.style.backgroundColor = "#ffffff";
    screenIFrame.style.position = "absolute";
    screenIFrame.style.filter = "alpha(opacity=50)";
    screenIFrame.style.opacity = 0.5;
    screenIFrame.style.mozOpacity = 0.5;
    screenIFrame.zIndex = 99;
    screenIFrame.style.width = (dde.scrollWidth > dde.clientWidth ? dde.scrollWidth : dde.clientWidth) - 5 + "px";
    screenIFrame.style.height = (dde.scrollHeight > dde.clientHeight ? dde.scrollHeight : dde.clientHeight) + 2000 + "px";
    screenIFrame.style.top = 0;
    screenIFrame.style.left = 0;
}

function SelectText(obj) {
    obj.select();
}

//全额到账
function SetFullPay(amount, obj) {
    document.getElementById(obj).value = amount;
}
