/* This file is included by Page.class.php in all pages. Should be renamed to utility.js */
// Strings must be passed from PHP (Translation)

function reportIncorrectEntry(id,message) {
    if (confirm(message)) {
        window.location.href = 'contact.php?id=' + id + '&mode=incorrect';
    }
}

function deleteEntry(id) {
    if (confirm("Are you sure you want to delete this entry? This record will be removed from the database and this cannot be undone.")) {
        window.location.href = 'contact.php?id=' + id + '&mode=delete';
    }
}

function deleteAddress(x) {
    document.getElementsByName('address[' + x + '][type]').item(0).value = '';
    document.getElementsByName('address[' + x + '][line1]').item(0).value = '';
    document.getElementsByName('address[' + x + '][line2]').item(0).value = '';
    document.getElementsByName('address[' + x + '][city]').item(0).value = '';
    document.getElementsByName('address[' + x + '][state]').item(0).value = '';
    document.getElementsByName('address[' + x + '][zip]').item(0).value = '';
    document.getElementsByName('address[' + x + '][phone1]').item(0).value = '';
    document.getElementsByName('address[' + x + '][phone2]').item(0).value = '';
    document.getElementsByName('address[' + x + '][country]').item(0).value = '';
}

function saveEntry() {
    createCookie('save','',-1);
    document.editEntry.submit();
}

function adminsaveEntry() {
    createCookie('save','adminsave',1);
    document.editEntry.submit();
}

/* AdminPanel */

function deleteUser(id) {
    if (confirm("Are you sure you want to delete this user? This user will be removed from the database and this cannot be undone.")) {
        window.location.href = 'adminPanel.php?mode=delete&userid=' + id;
    }
}

function uninstallPlugin(name) {
    if (confirm("Are you sure you want to uninstall this plugin? This will ERASE ALL EXISTING data created by this plugin from the database and this cannot be undone.")) {
        window.location.href = 'adminPanel.php?mode=uninstall&plugin=' + name;
    }
}

/* SearchList */

function generateMailto() {
    
    checkednames = '';
    i=0;
    while(e = document.getElementById('cx'+i))
    {
        if(e.checked == true)
             checkednames = checkednames + e.name +', ';
        
        i++;
    }
    document.getElementById("mailtoSelected").setAttribute("href","mailto:"+checkednames);
}

