function deleteAttr(id, name, type){

    var c = confirm("Are you sure you wish to delete " + name + "?");
    
    if (c) {
        window.location = "/post.php?action=delete&cat=" + type + "&id=" + id;
    }
    
}

function deleteCategory(cat, id, name){
    var c = confirm("Are you sure you wish to delete " + name + "?");
    
    if (c) {
        window.location = "/post.php?action=delete_category&cat=" + cat + "&id=" + id;
    }
}

function deleteSection(cat, id, name){
    var c = confirm("Are you sure you wish to delete " + name + "?");
    
    if (c) {
        window.location = "/post.php?action=delete_section&cat=" + cat + "&id=" + id;
    }
}

function deleteEntry(cat, id, name){
    var c = confirm("Are you sure you wish to delete " + name + "?");
    
    if (c) {
        window.location = "/post.php?action=delete&cat=" + cat + "&id=" + id;
    }
}

function deleteHomeImage(image){
    var c = confirm("Are you sure you wish to delete " + image + "?");
    
    if (c) {
        window.location = "/admin/home_images/delete?image=" + image;
    }
}

function deleteImage(img_id, name){
    var c = confirm("Are you sure you wish to delete " + name + "?");
    
    if (c) {
        window.location = "/post.php?action=delete_image&img_id=" + img_id;
    }
}

function showProfessionalForm(){
    document.getElementById('student-form').style.display = 'none';
    document.getElementById('professional-form').style.display = 'block';
    
    //Add link to Students
    var stud_elem = document.getElementById('show-student-form');
    stud_elem.removeAttribute("style");
    var stud_text = document.createTextNode(stud_elem.textContent);
    stud_elem.textContent = '';
    
    var stud_link = document.createElement('a');
    stud_link.setAttribute("href", "#");
    stud_link.setAttribute("onclick", "showStudentForm();");
    
    stud_link.appendChild(stud_text);
    stud_elem.appendChild(stud_link);
    
    //Remove Link from Professionals
    var prof_elem = document.getElementById('show-professional-form');
    prof_elem.onclick = function(){
        return false;
    };
    prof_elem.style.fontWeight = 'bold';
    
    var prof_text = document.createTextNode(prof_elem.textContent);
    prof_elem.textContent = '';
    prof_elem.appendChild(prof_text);
}

function showStudentForm(){
    document.getElementById('professional-form').style.display = 'none';
    document.getElementById('student-form').style.display = 'block';
    
    //Add link to Professionals
    var prof_elem = document.getElementById('show-professional-form');
    prof_elem.removeAttribute("style");
    var prof_text = document.createTextNode(prof_elem.textContent);
    prof_elem.textContent = '';
    
    var prof_link = document.createElement('a');
    prof_link.setAttribute("href", "#");
    prof_link.setAttribute("onclick", "showProfessionalForm();");
    
    prof_link.appendChild(prof_text);
    prof_elem.appendChild(prof_link);
    
    //Remove Link from Students
    var stud_elem = document.getElementById('show-student-form');
    stud_elem.onclick = function(){
        return false;
    };
    stud_elem.style.fontWeight = 'bold';
    
    var stud_text = document.createTextNode(stud_elem.textContent);
    stud_elem.textContent = '';
    stud_elem.appendChild(stud_text);
}

function showProfessionals(){
    document.getElementById('students').style.display = 'none';
    document.getElementById('professionals').style.display = 'block';
    
    //Add link to Students
    var stud_elem = document.getElementById('show-students');
    stud_elem.removeAttribute("style");
    var stud_text = document.createTextNode(stud_elem.textContent);
    stud_elem.textContent = '';
    
    var stud_link = document.createElement('a');
    stud_link.setAttribute("href", "/professional-student-networking/student");
    stud_link.setAttribute("onclick", "showStudents();");
    
    stud_link.appendChild(stud_text);
    stud_elem.appendChild(stud_link);
    
    //Remove Link from Professionals
    var prof_elem = document.getElementById('show-professionals');
    prof_elem.onclick = function(){
        return false;
    };
    prof_elem.style.fontWeight = 'bold';
    
    var prof_text = document.createTextNode(prof_elem.textContent);
    prof_elem.textContent = '';
    prof_elem.appendChild(prof_text);
}

function showStudents(){
    document.getElementById('professionals').style.display = 'none';
    document.getElementById('students').style.display = 'block';
    
    //Add link to Professionals
    var prof_elem = document.getElementById('show-professionals');
    prof_elem.removeAttribute("style");
    var prof_text = document.createTextNode(prof_elem.textContent);
    prof_elem.textContent = '';
    
    var prof_link = document.createElement('a');
    prof_link.setAttribute("href", "/professional-student-networking/professional");
    prof_link.setAttribute("onclick", "showProfessionals();");
    
    prof_link.appendChild(prof_text);
    prof_elem.appendChild(prof_link);
    
    //Remove Link from Students
    var stud_elem = document.getElementById('show-students');
    stud_elem.onclick = function(){
        return false;
    };
    stud_elem.style.fontWeight = 'bold';
    
    var stud_text = document.createTextNode(stud_elem.textContent);
    stud_elem.textContent = '';
    stud_elem.appendChild(stud_text);
}

function showSales(){
    document.getElementById('sales').style.display = 'block';
    document.getElementById('rentals').style.display = 'none';
}

function showRentals(){
    document.getElementById('rentals').style.display = 'block';
    document.getElementById('sales').style.display = 'none';
}

function showCategories(){
    document.getElementById('search-cats').style.display = "block";
    document.getElementById('show-cats-link').style.display = "none";
    document.getElementById('hide-cats-link').style.display = "inline";
}

function hideCategories(){
    document.getElementById('search-cats').style.display = "none";
    document.getElementById('show-cats-link').style.display = "inline";
    document.getElementById('hide-cats-link').style.display = "none";
}

function addImageInput(){
    var p = document.createElement('p');
    
    var label = document.createElement('label');
    label.innerHTML = "Image:";
    
    p.appendChild(label);
    
    var input = document.createElement('input');
    input.type = "file";
    input.name = "image[]";
    
    p.appendChild(input);
    
    document.getElementById('image-container').appendChild(p);
}

function addImageInput2(container){

    var image_container = document.getElementById(container);
    var totalInputs = image_container.getElementsByTagName("input").length;
    var totalImageInputs = totalInputs / 2;
    var p = document.createElement('p');
    
    var image_label = document.createElement('label');
    image_label.innerHTML = "Image " + (totalImageInputs + 1) + ":";
    var image_input = document.createElement('input');
    image_input.type = "file";
    image_input.name = "add_image[" + (totalImageInputs + 1) + "]";
    
    var br = document.createElement('br');
    
    var caption_label = document.createElement('label');
    caption_label.innerHTML = "Image Caption" + (totalImageInputs + 1) + ":";
    var caption_input = document.createElement('input');
    caption_input.type = "text";
    caption_input.name = "add_image_caption[" + (totalImageInputs + 1) + "]";
    
    p.appendChild(image_label);
    p.appendChild(image_input);
    p.appendChild(br);
    p.appendChild(caption_label);
    p.appendChild(caption_input);
    image_container.appendChild(p);
}

function showLightbox(){
    $('lightbox').style.display = 'block';
}

function closeLightbox(){
    $('lightbox').style.display = 'none';
}

function slide(dir){
    if (dir == 'next') {
        current_slide++;
        var new_image = images[current_slide % images.length];
    }
    else {
        current_slide--;
        if (current_slide == 0) {
            current_slide = images.length - 1;
        }
        var new_image = images[current_slide % images.length];
    }
    
    $('slideshow-image').src = new_image;
    $('slideshow-caption').innerHTML = captions[current_slide % images.length];
    $('current-num').innerHTML = (current_slide % images.length) + 1;
}

function initSlideShow(){
    slide('next');
    $('total-num').innerHTML = images.length;
    
    for (var i = 0; i < images.length; i++) {
        var pic = new Image(700, 525);
        pic.src = images[i];
    }
}

