function resize(img) {
    if (img.height > img.width) {
        var wi = eval(img.width);
        var he = eval(img.height);
        img.width = Math.round(530 * (wi / he));
        img.height = 530;
    }
}

function is_resize(img) {
    if (img.height > img.width) {
        var wi = eval(img.width);
        var he = eval(img.height);
        img.width = Math.round(93 * (he / wi));
        img.height = 93;
    }
    else {
        img.width = 128;
        img.height = 93;
    }
}

function addComment(type, id) {
    myRef = window.open('add_comment.do?type=' + type + '&id=' + id, 'AddComment', 'left=250,top=250,width=500,height=200,toolbar=0,menubar=0,scrollbars=0,statusbar=0,resizable=1');
}

function addImageComment(type, id, parentId, parentType) {
    myRef = window.open('add_comment.do?type=' + type + '&id=' + id + '&parentId=' + parentId + '&parentType=' + parentType, 'AddComment', 'left=250,top=250,width=500,height=200,toolbar=0,menubar=0,scrollbars=0,statusbar=0,resizable=1');
}

function showComments(type, id) {
    myRef = window.open('show_comments.do?type=' + type + '&id=' + id, 'ShowComments', 'left=250,top=200,width=500,height=400,toolbar=0,menubar=0,scrollbars=1,statusbar=0,resizable=1');
}

function showSubsectionComments(subsectionId, dateFrom, dateTo) {
    myRef = window.open('show_subsection_comments.do?subsectionId=' + subsectionId + '&dateFrom=' + dateFrom + '&dateTo=' + dateTo, 'ShowSubsectionComments', 'left=250,top=200,width=500,height=400,toolbar=0,menubar=0,scrollbars=1,statusbar=0,resizable=1');
}

function showItemComments(subsectionId, itemId, dateFrom, dateTo) {
    myRef = window.open('show_item_comments.do?subsectionId=' + subsectionId + '&itemId=' + itemId + '&dateFrom=' + dateFrom + '&dateTo=' + dateTo, 'ShowSubsectionComments', 'left=250,top=200,width=500,height=400,toolbar=0,menubar=0,scrollbars=1,statusbar=0,resizable=1');
}

function showUserComments(userId, dateFrom, dateTo) {
    myRef = window.open('show_user_comments.do?userId=' + userId + '&dateFrom=' + dateFrom + '&dateTo=' + dateTo, 'ShowUserComments', 'left=250,top=200,width=500,height=400,toolbar=0,menubar=0,scrollbars=1,statusbar=0,resizable=1');
}

function toggleCentralImage(link) {
    document.getElementById(link.id).style.display = 'none';
    document.getElementById('centralImgInput').style.visibility = 'visible';
}

function toggleAudioFile(link) {
    document.getElementById(link.id).style.display = 'none';
    document.getElementById('audioFileInput').style.visibility = 'visible';
    document.getElementById('audioFileInput').size = '50';
    document.getElementById('deleteAudioFile').value = 'yes';
}

function toggleVideoFile(link) {
    document.getElementById(link.id).style.display = 'none';
    document.getElementById('videoFileInput').style.visibility = 'visible';
    document.getElementById('videoFileInput').size = '50';
    document.getElementById('deleteVideoFile').value = 'yes';
}

function toggleAuthorImage(link) {
    document.getElementById(link.id).style.display = 'none';
    document.getElementById('authorImgInput').style.visibility = 'visible';
    document.getElementById('authorImgInput').size = '50';
    document.getElementById('deleteAuthorsPhoto').value = 'yes';
}
function toggleBookAuthorImage(link) {
    document.getElementById(link.id).style.display = 'none';
    document.getElementById('bookAuthorImgInput').style.visibility = 'visible';
    document.getElementById('bookAuthorImgInput').size = '50';
    document.getElementById('deleteBookAuthorsPhoto').value = 'yes';
}

function toggleBannerImage(link) {
    document.getElementById(link.id).style.display = 'none';
    document.getElementById('bannerImgInput').style.visibility = 'visible';
}

function hideControls() {
    if (document.getElementById('centralImgInput') != null) {
        document.getElementById('centralImgInput').style.visibility = 'hidden';
    }
    if (document.getElementById('audioFileInput') != null) {
        document.getElementById('audioFileInput').style.visibility = 'hidden';
    }

    if (document.getElementById('videoFileInput') != null) {
        document.getElementById('videoFileInput').style.visibility = 'hidden';
    }

    if (document.getElementById('authorImgInput') != null) {
        document.getElementById('authorImgInput').style.visibility = 'hidden';
    }
    if (document.getElementById('bookAuthorImgInput') != null) {
        document.getElementById('bookAuthorImgInput').style.visibility = 'hidden';
    }

    if (document.getElementById('bannerImgInput') != null) {
        document.getElementById('bannerImgInput').style.visibility = 'hidden';
    }
}

/*function MsgOkCancel(){
return confirm('The Selected Items will be deleted!');
}*/

function MsgOkCancel() {
    array = document.forms[0].elements;
    n = document.forms[0].elements.length;
    hasChecked = false;
    for (i = 0; i < n; i++) {
        if (array[i].checked == true) {
            hasChecked = true;
        }
    }

    if (hasChecked) {
        return confirm('The Selected Items will be deleted!');
    } else {
        alert('There is nothing selected for deletion');
        return false;
    }
}


function loadCentralImage(linkElement)
{
    var imageContainer = document.getElementById("centralImage"),
            currentImage = imageContainer.src;

    imageContainer.src = linkElement.href;
    linkElement.firstChild.src = currentImage;
    linkElement.href = currentImage;

    tmpImg = new Image();
    tmpImg.src = currentImage;


    if (tmpImg.height > tmpImg.width) {
        var wi = eval(tmpImg.width);
        var he = eval(tmpImg.height);
        linkElement.firstChild.width = 93;
        linkElement.firstChild.height = Math.round(93 * (he / wi));
    }
    else {
        linkElement.firstChild.width = 128;
        linkElement.firstChild.height = 93;
    }

    tmpImg.src = imageContainer.src;


    var wi = eval(tmpImg.width);
    var he = eval(tmpImg.height);

    if (wi > he) {
        imageContainer.width = 530;
        imageContainer.height = Math.round(530 * (he / wi));
    }
    else {
        imageContainer.height = 530;
        imageContainer.width = Math.round(530 / (he / wi));
    }

    return false;
}

function copy(formName) {
    if (document.forms[formName] != null) {
        if (document.forms[formName].elements['shippingStreetAddress'] != null) {
            document.forms[formName].elements['contactStreetAddress'].value = document.forms[formName].elements['shippingStreetAddress'].value;
        }
        if (document.forms[formName].elements['shippingStreetAddress2'] != null) {
            document.forms[formName].elements['contactStreetAddress2'].value = document.forms[formName].elements['shippingStreetAddress2'].value;
        }
        if (document.forms[formName].elements['shippingStreetAddress3'] != null) {
            document.forms[formName].elements['contactStreetAddress3'].value = document.forms[formName].elements['shippingStreetAddress3'].value;
        }
        if (document.forms[formName].elements['shippingCity'] != null) {
            document.forms[formName].elements['contactCity'].value = document.forms[formName].elements['shippingCity'].value;
        }
        if (document.forms[formName].elements['shippingPostalCode'] != null) {
            document.forms[formName].elements['contactPostalCode'].value = document.forms[formName].elements['shippingPostalCode'].value;
        }
        if (document.forms[formName].elements['shippingCountry'] != null) {
            document.forms[formName].elements['contactCountry'].options[document.forms[formName].elements['shippingCountry'].selectedIndex].selected = true;
        }
    }
}

function change_image_state(in_form_name) {

    var images = document.forms[in_form_name].getElementsByTagName("img");

    for (var i = 0; i < images.length; i++) {
        if (images[i].className == "resizableImage")
        {
            if (images[i].width > images[i].height) {
                //alert(i + ": width (" + images[i].width + ") > height (" + images[i].height + ")");
                images[i].width = 128;
                images[i].height = 93;
            } else {
                //alert(i + ": width < height");
                images[i].width = 93;
                images[i].height = 128;
            }
        }
    }
}

function addFields(card, div_id) {
    var div_el = document.getElementById(div_id);

    if(card == "Maestro Card") {
//        var innerCode1 = "<table><tr><td align=\"left\" class=\"form-input-text\"> Issue Number<span class=\"form-required-text\">*</span></td><td align=\"right\"> <input property=\"issueNumber\" styleClass=\"form-input-text\" size=\"50\" maxlength=\"50\"/></td></tr>"
//        innerCode1 += "<tr><td align=\"left\" class=\"form-input-text\"> Start Date<span class=\"form-required-text\">*</span></td><td align=\"right\"> <input property=\"startDate\" styleClass=\"form-input-text\" size=\"50\" maxlength=\"50\"/></td></tr>"
//        innerCode1 += "<tr><td align=\"left\" class=\"form-input-text\"> Security Code<span class=\"form-required-text\">*</span></td><td align=\"right\"> <input property=\"securityCode\" styleClass=\"form-input-text\" size=\"50\" maxlength=\"50\"/></td></tr></table>"

          div_el.style.visibility = 'visible';
//        var innerCode = "Issue Number<span class=\"form-required-text\">*</span><img src=\"images/spacer.gif\" width=\"38\" height=\"1\" ><html:text property=\"issueNumber\" class=\"form-input-text\" size=\"50\" maxlength=\"128\"/><br>";
//        innerCode += "Start Date<span class=\"form-required-text\">*</span><img src=\"images/spacer.gif\" width=\"59\" height=\"1\" ><html:text property=\"startDate\" class=\"form-input-text\" size=\"50\" maxlength=\"128\"/><br>";
//        innerCode += "Security Code<span class=\"form-required-text\">*</span><img src=\"images/spacer.gif\" width=\"37\" height=\"1\" ><html:text property=\"securityCode\" class=\"form-input-text\" size=\"50\" maxlength=\"128\"/><br>";
//        div_el.innerHTML = innerCode;
    } else {
        div_el.style.visibility = 'hidden';
    }
}

