function openPic(url,winName,winParams)	{
    var theWindow = window.open(url,winName,winParams);
    if (theWindow)	{theWindow.focus();}
}

function resetField(fieldName, fieldDesignator) {
    document.forms['project'].elements[fieldDesignator + '[' + fieldName + ']'].value = '';
    document.forms['project'].elements[fieldDesignator + '[' + fieldName + '_display]'].value = '';
    document.forms['project'].elements[fieldDesignator + '[' + fieldName + '_comment]'].value = '';
    document.getElementById(fieldName + '_comment_label').style.display = 'none';
    document.getElementById(fieldName + '_comment').style.display = 'none';
}

var PPP = {}
PPP.Project = {}
PPP.Project.Form = {}
PPP.Project.Form.Contact = {
    init:function(){

        $('.add-contact').each(function(){
            $(this).click(function(){
                var el = $(this).parent().parent();
                var newEl = el.clone();
                newEl.insertAfter((PPP.Project.Form.Contact.currentElement && PPP.Project.Form.Contact.currentEventHandler == $(this).attr('id'))?PPP.Project.Form.Contact.currentElement:el);
                var selectField = newEl.find('.contact-select');
                selectField.attr('name', selectField.attr('name').replace('[0]', '['+newEl.index()+']'));
                var commentField = newEl.find('.contact-comment');
                commentField.attr('name', commentField.attr('name').replace('[0]', '['+newEl.index()+']'));
                newEl.find('.add-contact').html('entfernen').click(function(){
                    $(this).parent().parent().remove();
                });
                newEl.find('.contact-select').val(0);
                newEl.find('.comment').hide();
                PPP.Project.Form.Contact.currentElement = newEl;
                PPP.Project.Form.Contact.currentEventHandler = $(this).attr('id');
                PPP.Project.Form.Contact.setSelectHandler();
            });
        });

        this.setSelectHandler();
    },

    setSelectHandler:function(){
        $('.contact-select').each(function(){
            $(this).change(function(){
                if($(this).val() == 0){
                    $(this).parent().find('.comment').fadeOut();
                    $(this).parent().find('.add-contact').fadeOut();
                }else{
                    $(this).parent().find('.comment').fadeIn();
                    $(this).parent().find('.add-contact').fadeIn();
               }
            });
        });

        $('.reset-address').each(function(){
            $(this).click(function(){
               $(this).parent().find('.comment').fadeOut();
               $(this).parent().find('.contact-select').val(0);
            });
        });
    }
}
