
/**
 * Date Popup
 */
function DatePopup(){
    this.button = null;
}

DatePopup.prototype.setSrcElement = function(inButton){
    this.button = inButton;
    this.button.onclick = this.doClick;
}

DatePopup.prototype.doClick = function(){
    var datePopup = event.srcElement.popup;
    popUpCalendar(event.srcElement.previousSibling,event.srcElement.previousSibling,"yyyymmdd");
}

/**
 * Party Popup
 */
function PartyPopup(){
    this.button = null;
    this.popup = document.createElement("DIV");
    this.popup.id = "_PartyPopupView";
    this.popup.handler = this;
    this.popup.style.position = "absolute";
    this.popup.style.display    = "none";
    this.popup.style.zIndex = "999";
    this.popup.style.width = 709;
    this.popup.style.height = 430;
    this.asEditor = false;

    this.popup.innerHTML = CommonPopup_genPopup("_PartyPopupView","<div><form name='partyform' method=post action='" + contextpath + "/common/partyinfo.do' target='_party_list'><input type=hidden name=currpage><input type=hidden name=partyrole>"
        + "<table cellpadding=0 cellspacing=0 border=0 width=100% height=100%>"
        + "<tr height='30%'><td><fieldset><legend>" + _SEARCH_PARTY_TITLE + "</legend>"
        + "<table cellpadding=2 cellspacing=0 border=0 width=100% height=100%  style='font-size:9pt'>"
        + "<col width=15%><col width=35%><col width=15%><col width=35%><tr><td>" + _PARTY_ID_LABEL + "</td>"
        + "<td><input type=text class='cssText' name='partyid' id='_PartyPopup_PartyId' maxlength='10' onkeypress ='UpperCaseHandler()'></td><td>" + _PARTY_NAME_LABEL + "</td><td><input type=text class='cssText' name='fullname' maxlength='70' onkeypress ='UpperCaseHandler()'>"
        + "</td></tr><tr><td>" + _PARTY_LNAME_LABEL + "</td><td><input type=text class='cssText' onkeypress ='UpperCaseHandler()' name='localname' maxlength='70'></td><td>" + _PARTY_ALIAS_LABEL + "</td>"
        + "<td><input type=text class='cssText' name='partyalias' maxlength='30' onkeypress ='UpperCaseHandler()'></td></tr><tr><td>" + _PARTY_LSNAME_LABEL + "</td><td><input type=text class='cssText' name='lshortname' maxlength='30' onkeypress ='UpperCaseHandler()'>"
        + "</td><td>" + _PARTY_CITY_LABEL + "</td><td><input type=text class='cssText'  name='city' maxlength='3' onkeypress ='UpperCaseHandler()'></td></tr><tr><td colspan=4 align=right>"
        + "<input type=submit class='button' value=" + _SEARCH_BUTTON_LABEL + "></td></tr></table></fieldset></td></tr><tr height='60%'><td>"
        + "<iframe src='about:blank' width=100% height=100% name='_party_list' scrolling='no'></iframe></td></tr><tr height=10%><td align=right>"
        + "<input type=submit value='9'  class='navBtn' style='font-family:webdings'  id='_PartyPopup_GoFirst' disabled='true'>&nbsp;"
        + "<input type=submit value='7' class='navBtn' style='font-family:webdings'  id='_PartyPopup_GoPrevious' disabled='true'>"
        + " <span id='_PartyPopup_CurrPage'>0</span> / <span id='_PartyPopup_PageCount'>0</span> "
        + "<input type=submit value='8'  class='navBtn' style='font-family:webdings'  id='_PartyPopup_GoNext' disabled='true'>&nbsp;"
        + "<input type=submit value=':'  class='navBtn' style='font-family:webdings'  id='_PartyPopup_GoLast' disabled='true'>&nbsp;&nbsp;"
        + "<input type=hidden class='button' value=" + _OK_BUTTON_LABEL + " id='_PartyPopup_OkBtn'>&nbsp;"
        + "<input type=button class='button' value=" + _CANCEL_BUTTON_LABEL + " id='_PartyPopup_CancelBtn'>&nbsp;"
        + "<input type='hidden' name='curr_page' value=1>"
        + "<input type='hidden' name='page_num' value=1>"
        + "<input type='hidden' name='party_biztype' value=1>"
        + "</td></tr></table></form>", 428);

    document.body.insertBefore(this.popup);
    this.popup.dragHandler = new DragHandler(document.all("_PartyPopupView_DragHandler"), this.popup);

    document.all('_PartyPopup_OkBtn').onclick = this.doOkClick;
    document.all('_PartyPopup_CancelBtn').onclick = this.doCancelClick;

    document.all('_PartyPopup_GoFirst').onclick = this.doGoFirst;
    document.all('_PartyPopup_GoPrevious').onclick = this.doGoPrevious;
    document.all('_PartyPopup_GoNext').onclick = this.doGoNext;
    document.all('_PartyPopup_GoLast').onclick = this.doGoLast;

    this.boundFields = null;
    this.tableBoundFields = null;
}

PartyPopup.prototype.doGoFirst = function(){
    document.all("curr_page").value = 1 ;
}

PartyPopup.prototype.doGoPrevious = function(){
    document.all("curr_page").value = parseInt(document.all("curr_page").value) - 1;
}

PartyPopup.prototype.doGoNext = function(){
    document.all("curr_page").value = 1 + parseInt(document.all("curr_page").value);
}

PartyPopup.prototype.doGoLast = function(){
    document.all("curr_page").value = document.all("page_num").value;
}

PartyPopup.prototype.getEditor = function(){
    if (typeof this.button.asEditor == "undefined"){
        return window._PartyPopup.boundFields.Item("partyid");
    } else {
        return window._PartyPopup.boundFields;
    }
}

PartyPopup.prototype.doClick = function(){
    window._PartyPopup.button = window.event.srcElement;
    window._PartyPopup.button.handler = window._PartyPopup;

    if (typeof window._PartyPopup.button.partyrole != "undefined"){
        window.document.forms["partyform"].partyrole.value = window._PartyPopup.button.partyrole;
    } else {
        window.document.forms["partyform"].partyrole.value = "";
    }

    if (typeof window._PartyPopup.button.asEditor == "undefined"){
        window._PartyPopup.bound();
    }

    var partyid = window._PartyPopup.getEditor().value;

    if (typeof window._CurrPopup != "undefined"){
        window._CurrPopup.style.display = "none";
    }

    window._PartyPopup.popup.style.top = document.body.scrollTop + (document.body.clientHeight - 390) / 2;
    window._PartyPopup.popup.style.left = (document.body.clientWidth - 709) / 2;
    window._PartyPopup.popup.style.display = "";

    document.all("_PartyPopup_PartyId").value = partyid;
    var biztype = document.all("biztype");
    if(biztype == null || biztype.value == ''){
       biztype.value = this.boundFields.item("biztype").value;
    }
    document.all("party_biztype").value = biztype.value;

    document.all("_PartyPopup_PartyId").focus();
    window._CurrPopup = window._PartyPopup.popup;

    if (partyid != null && partyid.length > 0){
        window._PartyPopup.searchDefault();
    }
}

PartyPopup.prototype.doOkClick = function(){
    var returnValue = window.frames["_party_list"].clctSlctParty();
    window._PartyPopup.exportValues(returnValue);
    window._PartyPopup.hidePopup();

    var txtEditor = window._PartyPopup.getEditor();
    txtEditor.focus();
    txtEditor.select();
}

PartyPopup.prototype.doCancelClick = function(){
    window._PartyPopup.hidePopup();

    var txtEditor = window._PartyPopup.getEditor();
    txtEditor.focus();
    txtEditor.select();
}

PartyPopup.prototype.hidePopup = function(){
    window._CurrPopup = undefined;
    this.popup.style.display = "none";
}

PartyPopup.prototype.bound = function(){
    var container = this.button.parentNode.parentNode.parentNode;
    var fields = container.getElementsByTagName("INPUT");

    this.boundFields = new ActiveXObject("Scripting.Dictionary");

    if (fields != null && fields.length > 0){
        for (var i=0; i < fields.length; i++){
            if (typeof fields[i].field != "undefined"){
                this.boundFields.Add(fields[i].field, fields[i]);
            }
        }
    }
}

PartyPopup.prototype.searchDefault = function(){
    document.all("partyform").submit();
}

PartyPopup.prototype.exportValues = function(inValue){
    if(inValue == null){
        return;
    }

    if (typeof this.button.asEditor == "undefined"){
        var fields = (new VBArray(this.boundFields.Keys())).toArray();
        for (var i=0; i < this.boundFields.Count; i++){
            var field = this.boundFields.Item(fields[i]);
            field.value = inValue.Item(fields[i]);
        }
    } else {
        this.boundFields.value = inValue.Item("partyid");
        this.boundFields.returnValue = inValue;
    }
}

/**
 * Party Infor Popup
 */
function PartyInforPopup(){
    this.button = null;
    this.popup = document.createElement("DIV");
    this.popup.id = "_PartyInforPopupView";
    this.popup.handler = this;
    this.popup.style.position = "absolute";
    this.popup.style.display = "none";
    this.popup.style.zIndex = "999";
    this.popup.style.width = 400;
    this.popup.style.height = 340;

    this.popup.innerHTML = CommonPopup_genPopup("_PartyInforPopupView","<div style='pading:2px;'><table cellpadding=0 cellspacing=0 border=0 width=100% height=100%>"
        + "<tr height='90%'><td><iframe frameborder=0 src='" + contextpath + "/common/partyinfor.jsp' width=100% height=100% name='_party_infor'></iframe></td></tr>"
        + "<tr><td align='center'><input type='button' class='button' id='_PartyInforPopup_OkBtn' value='OK'></td></tr>"
        +"</table></div>", 338);

    document.body.insertBefore(this.popup);
    this.popup.dragHandler = new DragHandler(document.all("_PartyInforPopupView_DragHandler"), this.popup);

    document.all('_PartyInforPopup_OkBtn').onclick = this.doOkClick;
    this.boundFields = null;
}

PartyInforPopup.prototype.doClick = function(){
    window._PartyInforPopup.button = window.event.srcElement;
    window._PartyInforPopup.button.handler = window._PartyInforPopup;
    window._PartyInforPopup.bound();

    if (typeof window._CurrPopup != "undefined"){
        window._CurrPopup.style.display = "none";
    }

    window._PartyInforPopup.popup.style.top = (document.body.clientHeight - 400) / 2;
    window._PartyInforPopup.popup.style.left = (document.body.clientWidth - 512) / 2;
    window._PartyInforPopup.popup.style.display = "";

    window.frames["_party_infor"]._party_infors = window._PartyInforPopup.importValues();
    window.frames["_party_infor"].importValues();

    window._CurrPopup = window._PartyInforPopup.popup;
}

PartyInforPopup.prototype.doOkClick = function(){
    var returnValue = window._PartyInforPopup.collectValues();

    window._PartyInforPopup.exportValues(returnValue);
    window._PartyInforPopup.hidePopup();
}

PartyInforPopup.prototype.hidePopup = function(){
    window._CurrPopup = undefined;
    this.popup.style.display = "none";
}

PartyInforPopup.prototype.bound = function(){
    var container = this.button.parentNode.parentNode.parentNode;
    var fields = container.getElementsByTagName("INPUT");

    this.boundFields = new ActiveXObject("Scripting.Dictionary");
    if (fields != null && fields.length > 0){
        for (var i=0; i < fields.length; i++){
            if (typeof fields[i].field != "undefined"){
                this.boundFields.Add(fields[i].field, fields[i]);
            }
        }
    }
}

PartyInforPopup.prototype.exportValues = function(inValue){
    var fields = (new VBArray(inValue.Keys())).toArray();

    for (var i=0; i < inValue.Count; i++){
        var field = this.boundFields.Item(fields[i]);
        field.value = inValue.Item(fields[i]);
    }
}

PartyInforPopup.prototype.importValues = function(){
    var returnValue = new ActiveXObject("Scripting.Dictionary");
    var fields = (new VBArray(this.boundFields.Keys())).toArray();

    for (var i=0; i < this.boundFields.Count; i++){
        returnValue.Add(fields[i], this.boundFields.Item(fields[i]).value);
        returnValue.Add(fields[i] + "|editable", this.boundFields.Item(fields[i]).editable);
    }

    return returnValue;
}

PartyInforPopup.prototype.collectValues = function(){
    return window.frames["_party_infor"].collectValues();
}

// Common Popup, Use iframe
function CommonPopup(){
}

CommonPopup.prototype.showPopup = function(name, width, height, url, params, srcObj){
    url = this.buildUrl(url, params);

    if (top.document.getElementById("_CommonPopup_" + name)==null) {
        this[name] = top.document.createElement("DIV");
        this[name].id = "_CommonPopup_" + name;

        this[name].handler = this;
        this[name].style.backgroundColor = "#DFDFDF";
        this[name].style.position = "absolute";
        this[name].style.cursor = "hand";
        this[name].style.border = "0px";
        this[name].style.zIndex = "999";
        this[name].style.padding = 0;
        this[name].style.display = "block";

        var popupWidth = width;
        var popupHeight = height;

        var winX = (top.document.body.offsetWidth - popupWidth) / 2;
        var winY = (top.document.body.offsetHeight - popupHeight) / 2;

        this[name].style.top = winY;
        this[name].style.left = winX;
        this[name].style.width = popupWidth;
        this[name].style.height = popupHeight;

        this[name].innerHTML = CommonPopup_genPopup(this[name].id, "<iframe id='" + this[name].id + "_Src' frameborder=0 style='{width:100%;height:100%}' " + " scrolling='auto'></iframe>", height);

        top.document.body.insertBefore(this[name]);
        top.setTimeout("document.getElementById('" + this[name].id + "_Src').src = '" + url + "'", 100);
        this[name].dragHandler = new DragHandler(top.document.all(this[name].id + "_DragHandler"), this[name]);
    } else {
        var currUrl = top.document.getElementById(this[name].id + "_Src").contentWindow.location.href;
        if (currUrl.length != currUrl.indexOf(url) + url.length){
            top.document.getElementById(this[name].id + "_Src").src = "about:blank";
            top.setTimeout("document.getElementById('" + this[name].id + "_src').src = '" + url + "'", 100);
        }
        this[name].style.display = "block";
    }

    this[name].srcObj = srcObj;
}

CommonPopup.prototype.buildUrl = function(url, params){
    if (params != null){
        var fields = (new VBArray(params.Keys())).toArray();

        for (var i=0; i < params.Count; i++){
            var param = params.Item(fields[i]);

            if (url.indexOf("?") != -1){
                url += "&";
            } else {
                url += "?";
            }

            url += fields[i] + "=" + param;
        }
    }

    return url;
}

function CommonPopup_close(popupName, returnValue) {
    var pop = window.top.document.getElementById(popupName);

    if (pop == null){
        pop = window.document.getElementById(popupName);
    }

    if (pop != null) {
        pop.style.display = "none";

        if (typeof pop.srcObj != "undefined" && typeof pop.srcObj.doClose != "undefined"){
            pop.srcObj.doClose(pop.srcObj, returnValue);
        }
    }
}

function CommonPopup_genPopup(popupName, innerHTML, height){
    return "<iframe style='width:100%;height:100%;position:absolute;z-index=1' src='about:blank'></iframe><table style='position:absolute;z-index=2' border='0' cellpadding='0' cellspacing='0' cols='3' width='100%' height='19'><col align='left' width='11'/><col align='center' width='100%'/><col align='right' width='20'/><tr><td valign='top' height='19'><img src='/portal/images/win01.gif' width='11' height='19'></td><td><div style='border-width:1px 0px 1px 0px;border-style:solid;border-color:#000000;width:100%;height:19px;'><div id='" + popupName + "_DragHandler' style='width:100%;height:17px;padding:1px 0px 0px 4px;font-family:Tahoma,Arial,ËÎÌå;font-size:11px;cursor:default;overflow: hidden; text-overflow:ellipsis;background:#94A9D6;border:1px solid;border-color:#B2CCFF #8094B9 #8094B9 #B2CCFF;'>&nbsp;</div></div></td><td valign='top' height='19'><img src='/portal/images/win22.gif' width='4' height='19' /><img src='/portal/images/win25.gif' width='12' height='19' onclick=\"CommonPopup_close('" + popupName + "')\"/><img src='/portal/images/win21.gif' width='4' height='19' /></td></tr></table><table style='position:absolute;z-index=2;top:19px;' border='0' cellpadding='0' cellspacing='0' cols='3' width='100%' height='" + (height - 38) + "'><col align='left' width='5'/><col align='center' width='100%'/><TR>    <TD style='background-image:url(/portal/images/win04.gif);background-repeat:repeat-y;background-position:leftt top;'></TD>    <TD style='background-image:url(/portal/images/win04.gif);background-repeat:repeat-y;background-position:right top;padding:0px 5px 0px 0px;background-color:white;'>" + innerHTML + "</TD></TR><table style='position:absolute;z-index=2;top:" + (height - 19) + "px;' border='0' cellpadding='0' cellspacing='0' cols='3' width='100%' height='19' style='background-color:#DFDFDF;'><col align='left' width='20'/><col align='left' width='100%'/><col align='right' width='20'/><tr><td valign='bottom' style='border-color:#000000;border-style:solid;border-width:1px 0px 0px 0px;'><img src='/portal/images/win05.gif' width='20' height='20' /></td><td style='border-color:#000000;border-style:solid;border-width:1px 0px 0px 0px;background-image:url(/portal/images/win07.gif);background-repeat:repeat-x;background-position:left bottom;font-size:12px;'>&nbsp;</td><td valign='bottom' style='border-color:#000000;border-style:solid;border-width:1px 0px 0px 0px;'><img src='/portal/images/win06.gif' width='20' height='20' /></td></tr></table>";
}