<script type="text/javascript">

    $.ctrl('S', function () {
        return json_add('sources-add', 'x', '0', 'popupform');
    });

</script>


<form action="" method="post" id="popupform" onsubmit="return json_add('sources-add','x','0','popupform');">

    <div id="popupsave">
        <input type="submit" value="Save" class="save"/>
    </div>

    <h1>Sources</h1>

    <p class="highlight">
        Use this form to create a new source for tracking acquision and value of contacts and members.
    </p>

    <div class="fullForm popupbody">

        <fieldset>
            <div class="pad24t">

        <ul id="source_list" class="popup_longlist">

            <?php

            $q1 = $db->run_query("

            SELECT *

            FROM `ppSD_sources`

            WHERE `type`='custom'

            ORDER BY `source` ASC

        ");

            while ($item = $q1->fetch()) {
                ?>



                <li id="td-cell-<?php echo $item['id'] ?>">

                    <a href="null.php" onclick="return delete_item('ppSD_sources','<?php echo $item['id'] ?>');"
                       class="floatright">

                        <img src="imgs/icon-delete.png" width="16" height="16" border="0" class="option_icon hover"
                             alt="Delete" title="Delete"/>

                    </a><input type="text" name="source[<?php echo $item['id']; ?>][name]" style="width:85%;"
                               value="<?php echo $item['source'] ?>"/> <span class="weak">(<?php echo $item['id']; ?>)</span>

                    <input type="hidden" name="source[<?php echo $item['id']; ?>][id]"
                           value="<?php echo $item['id'] ?>"/>

                </li>



            <?php

            }

            ?>

        </ul>


        <div class="submit">

            <a href="null.php" onclick="return add_source();">[+] Add New Source</a>

        </div>

        </div>
    </fieldset>

    </div>


</form>


<script type="text/javascript">

    function add_source() {
        var math = Math.random().toString(36).substring(7);
        html = '<li><input type="text" name="source[new_' + math + '][name]" style="width:90%;" value="" /><input type="hidden" name="source[new_' + math + '][id]" value="new" /></li>';
        $('#source_list').append(html);
        return false;
    }

</script>