<script type="text/javascript">
<!-- Hide for older browsers

var isch = 0;
var isInSignup = {isInSignup};
var totalPackages = {itemNum};
var numInUse = {selectedPromotionCount};

function itemSelected(form)
{
    strAlertMessage = lang("You need to select package(s) to perform this action on");
    bolShowMessage = true;
    var subPackages = $('subpackagesList').getElementsByTagName("input");
    for (var i = 0; i < subPackages.length; i++) {
        if (subPackages[i].checked) {
             bolShowMessage=false;
             break;
        }
    }

    if (bolShowMessage){
        alert(strAlertMessage);
        return false;
    }else{
        return true;
    }
}

function submitDeletePackages(strPlan)
{
    strWorkItems = "";
    strErrorString = "";
    intItemChecked=0;
    bolError=false;

    var subPackages = $('subpackagesList').getElementsByTagName("input");
    var intCount = subPackages.length;
    for (var i = 0; i < intCount; i++) {
        if (subPackages[i].checked) {
            if (isInteger(subPackages[i].value)!="true"){
                strErrorString += "\n"+subPackages[i].value;
                bolError = true;
            }else{
                 strWorkItems += subPackages[i].value;
                 strWorkItems += " ";
                 intItemChecked++;
             }
        }
    }

    if (bolError){
        strError = lang("WARNING: The following packages are still in use") + ":\n"+strErrorString+"\n\n"+ lang("You must update the domains that list these packages as theirs before you are allowed to delete them.");
        alert(strError);
        return false;
    }

    var strMessage = lang("Click OK if you are sure you want to delete the selected packages...");
    if (intItemChecked==intCount) {
        strMessage += "\n\n" + lang("WARNING: By deleting all of the remaining packages in the ") +strPlan+ lang(" plan you will not be able to assign any new clients to it.");
    }
    var tString;
    String(tString);
    tString = (strWorkItems.substring(0,strWorkItems.length-1));

    if (confirm(strMessage)){
        document.packageTypeForm.selectedpackages.value = tString;
        document.packageTypeForm.action = 'index.php?fuse=admin&action=DeletePackage';
        document.packageTypeForm.submit();
    }
}

function importPackage(packageId)
{
    location.href = 'index.php?fuse=admin&action=ImportPackage&packageid='+0+'&importpackage='+packageId+'&packageTypeId='+{packageTypeId};
}

function ischanged(clienttype,view) {
    isch = 1;
    var url = 'index.php?fuse=admin&clienttype=' + clienttype + '&view=' + view;
    MM_goToURL('parent',url);return document.MM_returnValue;
}

function populateHiddenVars() {
    if (isch == 0) {
        var pars =  "&order=" + document.getElementsByName('categoriesListOrder')[0].value + "&" + Sortable.serialize('categories');
        new Ajax.Request('index.php?fuse=admin&action=UpdatePlanOrder',
                         {parameters: pars,
                          onComplete:function(request){setStatus('Updating',1000, 'statusContainer')}});
    return true;
    } else {
        return false;
    }
}

function ToggleDomainTable(optionval)
{
    if (optionval==1){
        $('domaintable').style.display="";
    }else{
        $('domaintable').style.display="none";
    }
}

function ToggleIsSub(optionval)
{
    if (optionval==1){
        $('subdomaintable').style.display="";
        $('domainregtable').style.display="none";
    }else{
        $('domainregtable').style.display="";
        $('subdomaintable').style.display="none";
    }
}

function DeleteSubmit()
{
    if (!confirm(lang('Are you sure you want to delete this Package Type and all the packages associated with it?'))) {
        return;
    }

    document.packageTypeForm.action = 'index.php?fuse=admin&action=DeletePlan';
    document.packageTypeForm.submit();

}

function addOrRemoveFromSignup(clienttype, itemnum){

    if(!isInSignup){
        var answer=confirm(lang('Select OK to make this type available in the signup script'));
        if (answer){
            new Ajax.Request('index.php?fuse=admin&action=AddTypeToSignup&clienttype='+clienttype+'&itemnum='+itemnum,
                {onLoading     : function(request) {resetStatus(lang('Loading'))},
                 onSuccess     : onSuccessWithSignup}
            );
            
        }        
    }else{
        var answer=confirm (lang('Select OK to remove this type from the signup script'));
        if (answer){
            new Ajax.Request('index.php?fuse=admin&action=RemoveTypeToSignup&clienttype='+clienttype+'&itemnum='+itemnum,
                {onLoading     : function(request) {resetStatus(lang('Loading'))},
                 onSuccess     : onSuccessWithSignup}
            );
           
        }
    }  
}

function onSuccessWithSignup(t){

    var packageType = t.responseText.split('|')[0];
    
    var addedOrRemovedFromSignup = packageType.split('-')[0];
    var selectedPackage = packageType.split('-')[1];
    var clientType = packageType.split('-')[2];
    
    if(totalPackages > 0){
        if(addedOrRemovedFromSignup == 0){
            $('signupButtom').value = lang("Add to Signup");
            $('signupVisible_'+selectedPackage).value = "";
        }else{
            $('signupButtom').value = lang("Remove from Signup");
            $('signupVisible_'+selectedPackage).value = "*";
        }        
    }else if(totalPackages == 0){
        if(addedOrRemovedFromSignup == 0){
            $('signupButtom').value = lang("Add to Signup");
            $('signupVisibleAlone').value = "";
        }else{
            $('signupButtom').value = lang("Remove from Signup");
            $('signupVisibleAlone').value = "*";
        }
    }
    
    if(isInSignup){
        isInSignup = false;
    }else{
        isInSignup = true;
    }
    
    unsetStatus(lang('Loaded'), 1000);
}


//-->
</script>

<br>[l]You may only need one Package Type if all of your clients have the same packages and price<br>and you are not running any specials, otherwise you can create different Package Types<br>and their associated packages by clicking on the create package type tab.[/l]<br><br><br>
<form name="packageTypeForm" method="post" action="index.php?fuse=admin&action=AddEditPlan">
    <input type="hidden" name="planid" value="{packageTypeId}" />
    <input name="packageType" value="UpdatePlan" type="hidden">
    <input name="selectedpackages" type="hidden">
    <table border="0" width="650">
        <tr class="{primaryColor}">
            <td colspan="2">
                <!-- BEGIN DYNAMIC BLOCK: selectPackageType -->
                <b>[l]Select Package Type[/l]:</b>
                <br>[l]TIP: you can drag and drop the list items if you want to change their order. Changes will be saved automatically[/l]<br>
                <ul id="categories" class="sortableList" style="padding-left: 0pt; margin-left: 0pt;">
                    <!-- BEGIN DYNAMIC BLOCK: selectPackageTypeItemSortable -->
                    <li id="item_{itemNum}" style="cursor: move; list-style-type: none; position: relative;" onmouseup="populateHiddenVars();"><input name="selectedplan" onmousedown="ischanged('{listPackageTypeId}','PlanSettings');" {itemChecked} type="radio">{promotionCode}<input style="border:0" type="text" class="menu" id="signupVisible_{itemNum}" value="{shownInSignup}" ></li>
                    <!-- END DYNAMIC BLOCK: selectPackageTypeItemSortable -->
                    <!-- BEGIN DYNAMIC BLOCK: selectPackageTypeItemNonSortable -->
                    <!-- END DYNAMIC BLOCK: selectPackageTypeItemNonSortable -->
                </ul>
                <input name="categoriesListOrder" id="item_{itemNum}" value="{tPars}" type="hidden" />
                <input name="changed" id="changed" value="0" type="hidden" />
                <p id="progress" style="display: none;"><span class="announcement_column">[l]Updating[/l]</span></p>
                <script type="text/javascript">
                    // <![CDATA[
                    Sortable.create('categories');
                    // ]]>
                </script>
                <!-- END DYNAMIC BLOCK: selectPackageType -->
                <!-- BEGIN DYNAMIC BLOCK: justOnePackageType -->
                <div>
                    <b>{promotionCode}</b><input style="border:0" type="text" class="menu" id="signupVisibleAlone" value="{shownInSignup}" >
                </div>
                <!-- END DYNAMIC BLOCK: justOnePackageType -->
                <!-- BEGIN DYNAMIC BLOCK: showPlanCount -->
                <img src="{RELATIVE_PATH}images/sub_dot.gif">&nbsp;<b>{selectedPromotionCount}</b> [l]active packages signed up for this plan.[/l]<br>
                <img src="{RELATIVE_PATH}images/sub_dot.gif">&nbsp;<b>{inactivePromotionCount}</b> [l]inactive packages signed up for this plan.[/l]
                <!-- END DYNAMIC BLOCK: showPlanCount -->
            </td>
        </tr>
        <tr class="{secondaryColor}">
            <td valign="top">
                <br><b>[l]Friendly Name[/l]:</b><br>
                <input size="40" name="name" value="{selectedName}" class="body" type="text">
            </td>
        </tr>
        <tr class="{primaryColor}">
            <td valign="bottom">
                <b>[l]Show Domain Options[/l]:</b><br>
                <select name="regdomain" onchange="ToggleDomainTable(this.options[this.selectedIndex].value)">
                    <option value="1" {showDomainOptionsSelected}> [l]Yes - Show domain options[/l]&nbsp;&nbsp;</option>
                    <option value="0" {dontShowDomainOptionsSelected}> [l]No - Do not show domain options[/l]</option>
                </select>
            </td>
        </tr>
    </table>
    <div id="domaintable" style="display:{domainTableDisplay}">
        <table border="0" width="490">
            <tr>
                <td width="140">
                    <b>[l]Is this for a subdomain?[/l]</b>
                </td>
                <td>
                    <input name="issub" value="0" style="position: relative; top: 3px;" {selectedNo} onclick="ToggleIsSub(this.value);" ;="" type="radio"> No <input name="issub" {selectedYes} value="1" style="position: relative; top: 3px;" onclick="ToggleIsSub(this.value);" ;="" type="radio"> Yes
                </td>
            </tr>
        </table>
        <div id="subdomaintable" style="display:{subdomainTableDisplay};">
            <table border="0" width="490">
                <tr>
                    <td width="145">
                        <b>[l]Main Domain[/l]:</b>
                    </td>
                    <td>
                        <input size="30" name="maindomain" value="{selectedDomain}" type="text">&nbsp;&nbsp;
                        <a href="javascript:void(0);" onmouseover="return overlib('[ljh]Used for customers who are providing subdomain hosting.<br>Example: customer.yourdomain.com[/ljh]',FIXY,_mousePosY+5,FIXX,_mousePosX+13,DELAY,310,BGCOLOR, '#FFCC00', FGCOLOR, '#FFFFCC',BORDER,1,TEXTCOLOR,'#000000');" onmouseout="return nd();">
                            <img src="templates/images/question.gif" style="position: relative; left: 0px; top: 2px;" border="0">
                        </a>
                    </td>
                </tr>
            </table>
        </div>
        <div id="domainregtable" style="display:{domainregtableDisplay}">
            <table border="0" width="490">
                <tr>
                    <td>
                        <input name="allowreg" style="position: relative; top: 4px;" {allowregChecked} type="checkbox">
                        <b>[l]Allow Registration[/l]</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input name="allowselfmanage" style="position: relative; top: 4px;" {allowSelfmanageChecked} type="checkbox">
                        <b>[l]Allow Self Manage[/l]</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <input name="allowtransfer" style="position: relative; top: 4px;" {allowTransferChecked} type="checkbox" >
                        <b>[l]Allow Transfer[/l]</b>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <table border="0" width="650">
        <tr class="secondarycolor">
            <td colspan="2" valign="top">
                <br><b>[l]Description[/l]:</b><br />
                <textarea id="description" name="description" cols="122" rows="6">{packageTypeDescription}</textarea>
                <script type="text/javascript">
                    showRichTextEditor("oEditDescription", 650, '150px',
                                        [
                                            'Undo','Redo','|','Hyperlink','|','JustifyLeft','JustifyCenter','JustifyRight','JustifyFull','|','Numbering','Bullets','|','LTR','RTL','|','XHTMLFullSource','StyleAndFormatting','TextFormatting','ListFormatting','BoxFormatting','ParagraphFormatting','CssText','|','FontName','FontSize','|','Bold','Italic','Underline','|','ForeColor','BackColor'
                                        ],
                                        "description");
                </script>
            </td>
        </tr>
        <tr class="primarycolor">
            <td colspan="2" valign="top">
                <br>
                <table border="0" cellpadding="0" cellspacing="0" width="100%">
                    <tr>
                        <td>
                            <b>[l]Default Welcome E-mail[/l]:</b>&nbsp;&nbsp;&nbsp;(<a href="javascript:void(0);" onmousedown="oldOpenHelpWindow('1')">[l]Click to view tags[/l]</a>)
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td colspan="2" valign="top">
                <br>[l]Subject[/l] : &nbsp;&nbsp;
                <input id="welcomeemail_subject" name="welcomeemail_subject" value="{welcomeEmailSubject}" style="background-color: rgb(255, 250, 239);" size="50" type="text"><br><br>
                <ul class="shadetabs">
                    <li class="selected">
                        <a href="javascript:void(0);" onclick="selectHTMLTab(this, 'welcomeemail')">
                            [l]HTML[/l]
                        </a>
                    </li>
                    <li class="">
                        <a href="javascript:void(0);" onclick="selectPlainTextTab(this, 'welcomeemail')">
                            [l]Plain-Text[/l]
                        </a>
                    </li>
                </ul>
                <div id="richTextWrapper_welcomeemail">
                    <textarea id='welcomeemail[0]' name='welcomeemail[0]' style="width:650px; height:250px;">{welcomeEmailHTML}</textarea>
                    <script type="text/javascript">
                        showRichTextEditor("oEditWelcomeemail", 650, '250px',
                                            [
                                                'Undo','Redo','|','Hyperlink','|','JustifyLeft','JustifyCenter','JustifyRight','JustifyFull','|','Numbering','Bullets','|','LTR','RTL','|','XHTMLFullSource','StyleAndFormatting','TextFormatting','ListFormatting','BoxFormatting','ParagraphFormatting','CssText','|','FontName','FontSize','|','Bold','Italic','Underline','|','ForeColor','BackColor'
                                            ],
                                            "welcomeemail[0]");
                    </script>
                </div>
                <textarea id='welcomeemail[1]' name='welcomeemail[1]' style="width:650px; height:250px; display:none;">{welcomeEmailText}</textarea>
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <b>[l]Signup URL[/l]:&nbsp;&nbsp;</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <a href="{packageSignupURL}" target="_blank">
                    <font class="warningtext">{packageSignupURL}</font>
                </a>
            </td>
        </tr>
    </table>
    <br>
    <table border="0" cellpadding="1" cellspacing="0" width="100%">
        <tr valign="center">
          <td align="right" valign="center">
            <table border="0" cellpadding="0" cellspacing="0" width="100%">
              <tr valign="center">
                <td class="tight" colspan="2" align="left">
                    <input class="button_xlarge" onclick="check(form,form.elements.length);return false;" value="[lh]update package type[/lh]" type="button">
                    <input name="button" class="button_xlarge" onclick="DeleteSubmit();" value="[lh]delete package type[/lh]" type="button">
                    <input id="signupButtom" name="button" class="button_xlarge" onclick="addOrRemoveFromSignup({packageTypeId}, {itemCheckedValue});" value="{nameValue}" type="button">
                </td>
              </tr>
            </table>
          </td>
        </tr>
    </table>
    <img src="{RELATIVE_PATH}images/seperator.gif">
    <br>
    <br>
    <br>
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
            <td class="snapshot-header-left">
            </td>
            <td class="snapshot-header" nowrap="nowrap">
                <font class="snapshot-header-text">
                    [l]List of packages and prices for package type[/l]: <b>{selectedPromotionCode}</b>
                </font>
            </td>
            <td class="snapshot-header" align="right">
            </td>
            <td class="snapshot-header-right">
            </td>
        </tr>
    </table>
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
          <tr>
            <td bgcolor="#ffffff" valign="center" width="100%">
              <table border="0" cellpadding="4" cellspacing="1" width="100%" id="subpackagesList">
                <tr class="header">
                    <!-- BEGIN DYNAMIC BLOCK: subpackagesEditionChekboxColumnHeader -->
                    <td align="center" width="10">
                        <img src="{RELATIVE_PATH}images/spacer.gif">&nbsp;
                    </td>
                    <!-- END DYNAMIC BLOCK: subpackagesEditionChekboxColumnHeader -->
                    <!-- BEGIN DYNAMIC BLOCK: subpackagesTableHeaders -->
                    <td id="col_1" nowrap="nowrap">
                        <img alt="" src="{RELATIVE_PATH}images/spacer.gif" height="1" width="20"><br>
                        &nbsp;[l]Package Name (Click on package name to make changes)[/l]&nbsp;&nbsp;
                    </td>
                    <td id="col_1" align="right" nowrap="nowrap" width="55">
                        &nbsp;&nbsp;
                        <a href="javascript:void(0);" onmouseover="return overlib('<b>[ljh]Price[/ljh]</b>:<br>[ljh]The price does not identify which currency the amount is in.  This is handled in the customer profile of each customer.[/ljh]',FIXY,_mousePosY+5,FIXX,_mousePosX+13,DELAY,310,BGCOLOR, '#FFCC00', FGCOLOR, '#FFFFCC',BORDER,1,TEXTCOLOR,'#000000');" onmouseout="return nd();">[l]Price[/l]</a>&nbsp;
                    </td>
                    <td id="col_1" align="right" nowrap="nowrap" width="55">
                        &nbsp;&nbsp;
                        <a href="javascript:void(0);" onmouseover="return overlib('[ljh]The price does not identify which currency the amount is in.  This is handled in the customer profile of each customer.[/ljh]',FIXY,_mousePosY+5,FIXX,_mousePosX+13,DELAY,310,BGCOLOR, '#FFCC00', FGCOLOR, '#FFFFCC',BORDER,1,TEXTCOLOR,'#000000');" onmouseout="return nd();">[l]Setup[/l]</a>&nbsp;
                    </td>
                    <td id="col_1" align="center" nowrap="nowrap" width="55">
                        &nbsp;&nbsp;<a href="javascript:void(0);" onmouseover="return overlib('[ljh]Show the packages that are taxable[/ljh]',FIXY,_mousePosY+5,FIXX,_mousePosX+13,DELAY,310,BGCOLOR, '#FFCC00', FGCOLOR, '#FFFFCC',BORDER,1,TEXTCOLOR,'#000000');" onmouseout="return nd();">[l]Taxable[/l]</a>&nbsp;
                    </td>
                    <td id="col_1" align="center" nowrap="nowrap" width="55">
                        &nbsp;&nbsp;<a href="javascript:void(0);" onmouseover="return overlib('[ljh]Quantity of customers for each package[/ljh]',FIXY,_mousePosY+5,FIXX,_mousePosX+13,DELAY,310,BGCOLOR, '#FFCC00', FGCOLOR, '#FFFFCC',BORDER,1,TEXTCOLOR,'#000000');" onmouseout="return nd();">[l]Customers[/l]</a>&nbsp;
                    </td>
                    <td id="col_1" align="center" nowrap="nowrap" width="55">
                        &nbsp;&nbsp;<a href="javascript:void(0);" onmouseover="return overlib('[ljh]Show the packages that are allowed in signup[/ljh]',FIXY,_mousePosY+5,FIXX,_mousePosX+13,DELAY,310,BGCOLOR, '#FFCC00', FGCOLOR, '#FFFFCC',BORDER,1,TEXTCOLOR,'#000000');" onmouseout="return nd();">[l]Visible in signup[/l]</a>&nbsp;
                    </td>
                    <!-- END DYNAMIC BLOCK: subpackagesTableHeaders -->
                    <!-- BEGIN DYNAMIC BLOCK: subpackagesTableEmpty -->
                    <td colspan=3 noWrap align=left>
                        <font class=body7red>&nbsp;&nbsp;<b>[l]There are no packages for the current Package Type[/l]</b></font>
                    </td>
                    <!-- END DYNAMIC BLOCK: subpackagesTableEmpty -->
                </tr>
                <!-- BEGIN DYNAMIC BLOCK: subpackageItem -->
                <tr class="{rowClass}">
                    <!-- BEGIN DYNAMIC BLOCK: subpackagesEditionChekboxRow -->
                    <td align="center" width="12">
                        <input value="{checkboxValue}" name="entry" type="checkbox">
                    </td>
                    <!-- END DYNAMIC BLOCK: subpackagesEditionChekboxRow -->
                    <td nowrap="nowrap">
                        &nbsp;&nbsp;&nbsp;
                        <!-- BEGIN DYNAMIC BLOCK: editPackageLink -->
                        <a href="index.php?fuse=admin&view=EditPackage&clienttype={packageTypeId}&packageid={packageId}" onmouseover="return overlib('<b>[ id: {packageId} ]</b><Br>[ljh]Modify this package[/ljh]',FIXY,_mousePosY+5,FIXX,_mousePosX+13,DELAY,310,BGCOLOR, '#FFCC00', FGCOLOR, '#FFFFCC',BORDER,1,TEXTCOLOR,'#000000');" onmouseout="return nd();">{packageLabel}</a>
                        <!-- END DYNAMIC BLOCK: editPackageLink -->
                        <!-- BEGIN DYNAMIC BLOCK: packageLabelBlock -->
                        <b>{packageLabel}</b>
                        <!-- END DYNAMIC BLOCK: packageLabelBlock -->
                    </td>
                    <td align="right" nowrap="nowrap">
                        {monthlyPrice}
                        {quarterlyPrice}
                        {semiannualPrice}
                        {yearlyPrice}
                        {2yearPrice}
                    </td>
                    <td align="right" nowrap="nowrap">
                        &nbsp;{setupPrice}&nbsp;
                    </td>
                    <td align="center" nowrap="nowrap">
                      &nbsp;{taxable}&nbsp;
                    </td>
                     <td align="center" nowrap="nowrap">
                      &nbsp;{totalPackages}&nbsp;
                    </td>
                    <td align="center" nowrap="nowrap">
                      &nbsp;{avaliableInSignup}&nbsp;
                    </td>
                </tr>
                <!-- END DYNAMIC BLOCK: subpackageItem -->
              </table>
            </td>
          </tr>
    </table>
    <br>
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
        <tr>
            <td colspan="2">
                <table border="0" cellpadding="0" cellspacing="0" width="100%">
                    <tr class="actionfooter" valign="center">
                        <td align="left">
                            <input class="button_xlarge" value="[lh]Add new package[/lh]" type="button" onclick="location.href='index.php?fuse=admin&view=EditPackage&clienttype={packageTypeId}&packageid=0'">
                            <input class="button_xlarge" name="button" onclick="if (itemSelected()) submitDeletePackages('{selectedPromotionCode}');return false;" value="[lh]delete package(s)[/lh]" type="button">
                        </td>
                        <td align="right" nowrap="nowrap" valign="bottom" width="400">
                            <span>
                                [l]Import[/l]:
                                <select name="importpackage" onchange="importPackage(this.value);">
                                    <option value="0">[l]Select Package[/l]&nbsp;&nbsp;</option>
                                    <!-- BEGIN DYNAMIC BLOCK: importPackage -->
                                    <option value="{importPackageValue}">[l]{importPackageLabel}[/l]  &nbsp;&nbsp;</option>
                                    <!-- END DYNAMIC BLOCK: importPackage -->
                                </select>
                            </span>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
</form>
