// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   validateNameJSTag.java

package com.ptc.windchill.enterprise.doc.tags;

import com.ptc.core.components.util.RequestHelper;
import com.ptc.netmarkets.util.beans.NmCommandBean;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import wt.org.WTUser;
import wt.preference.PreferenceHelper;
import wt.preference.PreferenceService2;
import wt.session.SessionHelper;
import wt.session.SessionManager;

// Referenced classes of package com.ptc.windchill.enterprise.doc.tags:
//            WcBaseTag

public class validateNameJSTag extends WcBaseTag
{

    public validateNameJSTag()
    {
        template = false;
    }

    public void setTemplate(boolean flag)
    {
        template = flag;
    }

    public void doTag()
        throws JspException
    {
        super.doTag();
        try
        {
            out.println("<input type='hidden' id='validateName_NAME' name='validateName_NAME'>");
            if(template)
                out.println("<input type='hidden' id='validateName_IS_TEMPLATE' name='validateName_IS_TEMPLATE' value='true'>");
            else
                out.println("<input type='hidden' id='validateName_LOCATION' name='validateName_LOCATION'>");
            out.println("<script type='text/javascript' src='netmarkets/javascript/documentManagement.js'></script>");
            out.println("<script type='text/javascript'>       <!--");
            out.println("window.nameNumValuesChanged = false;");
            out.println("window.setNameLocationValues = function () {");
            out.println("   var nameInputs = getFormInputs(/^NameInputId.*[^_][^o][^l][^d]$/, 'id');");
            out.println("   if (nameInputs != null) {");
            out.println("      var i;");
            out.println("      var namesList = '';");
            out.println("      for (i = 0; i < nameInputs.length; i++) {");
            out.println("         if(valueChanged(nameInputs[i])) {");
            out.println("            nameNumValuesChanged = true;");
            out.println("         }");
            out.println("         namesList += nameInputs[i].value;");
            out.println("         namesList += ';;;vvv';");
            out.println("      }");
            out.println("      if (namesList.length > 0) {");
            out.println("         namesList = namesList.substring(0, namesList.length-(';;;vvv'.length));");
            out.println("      }");
            out.println("      document.getElementById('validateName_NAME').value = namesList;");
            out.println("      var locationInputs = getFormInputs(/overrideFolder___combobox$/, 'name');");
            out.println("      if (locationInputs.length > 0) {");
            out.println("         document.getElementById('validateName_LOCATION').value = locationInputs[0].value;");
            out.println("      }");
            out.println("   }");
            out.println("}");
            out.println("window.valueChanged = function(inputTextbox) {");
            out.println("   var oldValue = $(inputTextbox.id + '___old').value;");
            out.println("   return inputTextbox.value != oldValue;");
            out.println("}");
            out.println("window.validateDuplicateName = function () {");
            WTUser wtuser = (WTUser)SessionHelper.manager.getPrincipal();
            NmCommandBean nmcommandbean = RequestHelper.getCommandBean(request);
            wt.inf.container.WTContainerRef wtcontainerref = nmcommandbean.getContainerRef();
            String s = (String)PreferenceHelper.service.getValue(wtcontainerref, "/wt/doc/nameUniqueness", "WINDCHILL", wtuser);
            if(!template && s.equals("NON_UNIQUE"))
            {
                out.println("  return true;");
            } else
            {
                out.println("setNameLocationValues();");
                out.println("if (!nameNumValuesChanged) {");
                out.println("   return true;");
                out.println("}");
                out.println("return callAJAXValidation('DocAttStepValidator');");
            }
            out.println("}");
            out.println("//         -->");
            out.println("</script>");
        }
        catch(Exception exception)
        {
            throw new JspException(exception);
        }
    }

    private boolean template;
}
