jQuery(document).ready(function() {

        jQuery("#accordion").accordion({
            autoHeight: false,
            active: false,
            change: function(event, ui) {
                activeID = ui.newHeader.find('a').attr("id");
                setPayment(activeID);
                //jQuery("#accordion").accordion( 'disable' );
            }
        });

        //if({$nActive} > -1)
        //   jQuery('#accordion').accordion('activate', {$nActive});

});


    function setPayment(strID){
        if (strID == "credit" )
            AjaxExecutePost("setPayment", "'credit'", "setCredit");
        else
            AjaxExecutePost("setPayment", "'cheque'", "setCheque");
        if("{$cart->command_id}" == "0")
        	jQuery("#ptintBtn").attr("href" , "javascript:ToPdfObject({$NewCommand_id}); this.blur();");
    }

    function setCredit(strRes){
        arrTmp = strRes.split("|");
        jQuery("#ptintBtn2").click(function () {
            ToPdfObject(arrTmp[0])
        });
    }

    function setCheque(strRes){
        arrTmp = strRes.split("|");
        jQuery("#ptintBtn").click(function () {
            ToPdfObject(arrTmp[0])
        });
    }

  	function ToPdfObject(nID)
	{
		var bScroll = false;
		strURL = "command_pdf.php?command_id="+nID;
		nWidth = 0;
		nHeight = 0;
		strName = "command";
		if (nWidth == 0) nWidth = 300;
		if (nHeight == 0) nHeight = 300;
		var bOverflowX = (nWidth > window.screen.width);
		var bOverflowY = (nHeight > window.screen.height);
		if (bOverflowX) { nWidth = window.screen.width; bScroll = true; }
		if (bOverflowY) { nHeight = window.screen.height; bScroll = true; }
		var nLeft = (window.screen.width - nWidth) / 2;
		var nTop = (window.screen.height - nHeight) / 2;
		if (bOverflowX) { nWidth -= 20; }
		if (bOverflowY) { nHeight -= 50; }
		if (bOverflowX && !bOverflowY)
			nHeight += 16;
		else if (bOverflowY && !bOverflowX)
			nWidth += 16;
		g_bIE = document.all;
		var strFeatures = "left=" + nLeft + ",top=" + nTop + ",width=" + nWidth + ",height=" + nHeight + ",resizable=yes," + (bScroll ? "scrollbars=yes," : "scrollbars=" + (g_bIE ? "auto" : "yes") + ",") + "modal=no";

		var objWin = window.open(strURL, strName, strFeatures);
		return objWin;

	}

    function setPayMethod(nID, n){
        AjaxExecutePost("setPayMethod", escape(nID+","+n), "void");
    }
