﻿<!--

    function GetControl(controlID)
    {
        var control = document.getElementById('ctl00_' + controlID);
        
        if (control == null)
        {
            control = document.getElementById('ctl00$' + controlID);
            
            if (control == null)
                control = document.getElementById(controlID);
            
        }
        
        return control;
    }

    function GetControlAction()
    {
        var control = document.getElementById('ctl00___Action');
        
        if (control == null)
        {
            control = document.getElementById('ctl00$__Action');
            
            if (control == null)
                control = document.getElementById('__Action');
            
        }
        
        return control;
    }
    
    function GetControlValidationSkip()
    {
        var control = document.getElementById('ctl00___ValidationSkip');
        
        if (control == null)
        {
            control = document.getElementById('ctl00$__ValidationSkip');
            
            if (control == null)
                control = document.getElementById('__ValidationSkip');
            
        }

        return control;
    }
    
    function GetControlSessionGuid()
    {
        var control = document.getElementById('ctl00___SessionGuid');
        
        if (control == null)
        {
            control = document.getElementById('ctl00$__SessionGuid');
            
            if (control == null)
                control = document.getElementById('__SessionGuid');
                
        }

        return control;
    }
    
    function GetControlActionValue()
    {
        var control = document.getElementById('ctl00___ActionValue');
        
        if (control == null)
        {
            control = document.getElementById('ctl00$__ActionValue');
            
            if (control == null)
                control = document.getElementById('__ActionValue');
                
        }
        
        return control;
    }
    
    function SetAction(action)
    {
        var control = GetControlAction();
        control.value = action;
    }

    function SetActionAndValidationSkip(action, validationSkip)
    {
        var control = GetControlAction();
        control.value = action;
        control = GetControlValidationSkip();
        control.value = validationSkip;
    }

    function PopUpActionAndValidationSkip(popUpView, action, validationSkip)
    {
        var control = GetControlSessionGuid();
        var url = window.document.URL
        var queryStringIndex = url.indexOf("?", 0)

        if (queryStringIndex > 0)
            url = url.substr(0, queryStringIndex)
            
        var queryPageIndex = url.lastIndexOf("/");

        if (queryPageIndex > 0)
            url = url.substr(0, queryPageIndex + 1)
            
        window.open(url + popUpView + "?__SessionGuid=" + control.value + "&__Action=" + action + "&__ValidationSkip=" + validationSkip, window.name);
    }
    
    function SetActionAndValue(action, actionValue)
    {
        var control = GetControlAction();
        control.value = action;
        control = GetControlActionValue();
        control.value = actionValue;
    }
    
    function SetActionValueAndValidationSkip(action, actionValue, validationSkip)
    {
        var control = GetControlAction();
        control.value = action;
        control = GetControlActionValue();
        control.value = actionValue;
        control = GetControlValidationSkip();
        control.value = validationSkip;
    }
    
    function MenuItemInvoke(notused, view, workflow, newsession)
    {
        MenuItemInvokeInternal(notused, view, workflow, newsession, '__SwitchView');
    }

    function MenuItemInvokeConfirmNo(notused, view, workflow, newsession)
    {
        MenuItemInvokeInternal(notused, view, workflow, newsession, 'ConfirmNo');
    }
    
    function MenuItemInvokeInternal(notused, view, workflow, newsession, action)
    {
        var control;
    
        if (view != null && view.length > 0)
        {
            control = GetControlAction();
            control.value = action;
            control = GetControlActionValue();
            control.value = view;
        }
        
        control = GetControlValidationSkip();
        control.value = true;
        
        if (workflow != null && workflow.length > 0)
            CreateWorkflow(workflow);
        else
            CreateWorkflow('');
            
        var formMain = document.forms[0];
        var newElement = document.createElement('input');
        newElement.setAttribute('id', '__MenuItemAction');
        newElement.setAttribute('name', '__MenuItemAction');
        newElement.setAttribute('type', 'hidden');
        newElement.setAttribute('value', 'yes');
        formMain.appendChild(newElement);
            
        if (newsession != null && newsession.length > 0)
        {
            newElement = document.createElement('input');
            newElement.setAttribute('id', '__NewSession');
            newElement.setAttribute('name', '__NewSession');
            newElement.setAttribute('type', 'hidden');
            newElement.setAttribute('value', 'yes');
            formMain.appendChild(newElement);
        }
        
        CreateClearSessionFormVariables();
        FormSubmitCurrent();
    }

    function CreateNoButtonAndPanelInitCallLoad(controlID, javascript)
    {
        $(document).ready(function() {eval('CreateNoButtonAndPanelInitCall(\'' + controlID + '\', "' + javascript + '");'); });
    }
    
    function CreateNoButtonAndPanelInitCall(controlID, javascript)
    {
        //var targetControlHiddenID = 'ctl00___Panel1TargetControlHidden';
        var targetControlHiddenID = '__Panel1TargetControlHidden';
        var noButtonHiddenID = '__' + controlID + 'NoButtonHidden';
        var okControlID = '__Panel1OkControl';
        var formMain = document.forms[0];
        var newElement = document.createElement('input');
        javascript = javascript.replace('MenuItemInvoke(', 'MenuItemInvokeConfirmNo(');
        newElement.setAttribute('id', noButtonHiddenID);
        newElement.setAttribute('name', noButtonHiddenID);
        newElement.setAttribute('type', 'hidden');
        //newElement.onclick = 'javascript:' + javascript;
        newElement.onclick = javascript;
        formMain.appendChild(newElement);
        PanelOnClickInit(targetControlHiddenID, controlID, okControlID, noButtonHiddenID, '__Panel1NoButtonHidden');
    }
    
    function BackspaceKeySimulate()
    {
        history.go(-1);
    }

    function execBackspace(event)
    {
	    var retVal = true;
        var catchBackspaceKeyNonInput = true;

        if (typeof event == 'undefined')
            event = window.event;

        var srcElement = event.srcElement? event.srcElement : event.target;
        
        if (srcElement && srcElement.type && (srcElement.type == 'file' || srcElement.type == 'password' || srcElement.type == 'text' || srcElement.type == 'textarea' ))
            catchBackspaceKeyNonInput = false;
        
        if (catchBackspaceKeyNonInput && catchBackspaceKey(event) == true)
        {
    	    
            if (event.preventDefault)
                event.preventDefault();
                
	        event.returnValue=false;
	        event.cancel = true;
	        retVal = false;

            try
            {
                DisableControlsForPopup();
            }
            catch(err) {}
            
	        //document.getElementById('ctl00___PageBackspaceTargetControlHidden').click();
	        GetControl('__PageBackspaceTargetControlHidden').click();
        }
	        
	    return retVal;
    }

    function catchBackspaceKey(event)
    {
	    var retVal = false;
    	
	    if (document.all)
	    {
    	
		    if (event.keyCode == 8)
			    retVal = true;
    		
	    }
	    else if (document.getElementById)
	    {
    	
		    if (event.which == 8)
			    retVal = true;
    		
	    }
	    else if(document.layers)
	    {
    	
		    if(event.which == 8)
			    retVal = true;
    		
	    }
    	
	    return retVal;
    }

    function CreateWorkflow(workflow)
    {
        var formMain = document.forms[0];
        var newElement = document.createElement('input');
        newElement.setAttribute('id', '__Workflow');
        newElement.setAttribute('name', '__Workflow');
        newElement.setAttribute('type', 'hidden');
        newElement.setAttribute('value', workflow);
        formMain.appendChild(newElement);
    }

    function CreateClearSessionFormVariables()
    {
        var formMain = document.forms[0];
        var newElement = document.createElement('input');
        newElement.setAttribute('id', '__SessionClearFormVariables');
        newElement.setAttribute('name', '__SessionClearFormVariables');
        newElement.setAttribute('type', 'hidden');
        newElement.setAttribute('value', 'yes');
        formMain.appendChild(newElement);
    }
        
    function PopUpActionValueAndValidationSkip(popUpView, action, actionValue, validationSkip)
    {
        var control = GetControlSessionGuid();
        var url = window.document.URL
        var queryStringIndex = url.indexOf("?", 0)
        
        if (queryStringIndex > 0)
            url = url.substr(0, queryStringIndex)
            
        var queryPageIndex = url.lastIndexOf("/");

        if (queryPageIndex > 0)
            url = url.substr(0, queryPageIndex + 1)
            
        window.open(url + popUpView + "?__SessionGuid=" + control.value + "&__ViewName=" + actionValue + "&__Action=" + action + "&__ActionValue=" + actionValue + "&__ValidationSkip=" + validationSkip, window.name);
    }
    
    function PopUpActionValueAndValidationSkipWorkflow(popUpView, action, actionValue, validationSkip, workflow)
    {
        var control = GetControlSessionGuid();
        var url = window.document.URL
        var queryStringIndex = url.indexOf("?", 0)
        
        if (queryStringIndex > 0)
            url = url.substr(0, queryStringIndex)
            
        var queryPageIndex = url.lastIndexOf("/");

        if (queryPageIndex > 0)
            url = url.substr(0, queryPageIndex + 1)
            
        window.open(url + popUpView + "?__SessionGuid=" + control.value + "&__ViewName=" + actionValue + "&__Action=" + action + "&__ActionValue=" + actionValue + "&__ValidationSkip=" + validationSkip + "&__Workflow=" + workflow, window.name);
    }
    
    function submitAllIFrames()
    {
       
		var iframeList = document.getElementsByTagName("IFRAME");
		var index = 0;
        var session = GetControlSessionGuid();
        
		for (; index < iframeList.length; index++) {
		     if(iframeList[index].contentWindow.document.getElementById('__SessionGuid') != null)
		     {
		        EnableDisableElements(iframeList[index].contentWindow.document.forms[0],true);
		        iframeList[index].contentWindow.document.getElementById('__SessionGuid').value = session.value;
		        iframeList[index].contentWindow.document.getElementById('__Action').value= '__SwitchView';
		        iframeList[index].contentWindow.document.getElementById('__ActionValue').value= 'FileUpload';
		        AIM.submit(iframeList[index].contentWindow.document.forms[0], {'onStart' : startCallback, 'onComplete' : completeCallback});
		        iframeList[index].contentWindow.document.forms[0].submit();
		        
		    }
		    
		}
		
    }
    
    function SetActionValidationSkipAndSubmit(action,actionValue)
    {
        document.body.style.cursor='wait';
        SetActionValueAndValidationSkip(action,actionValue,'True');
        document.forms[0].submit();
        document.body.style.cursor='default';
    }
    
    
    function viewAndSubmit(actionValue)
    {
        document.body.style.cursor='wait';
        SetActionValueAndValidationSkip('__SwitchView',actionValue,'True');
        document.forms[0].submit();
        document.body.style.cursor='default';
    }
    
    function FormSubmitCurrent()
    {
        var formMain = document.forms[0];
        FormSubmit(formMain);
    }
    
    function FormSubmit(formToSubmit)
    {
		//submitAllIFrames();
		displayPageLocked();
		formToSubmit.submit();
    }
    
    function SetActionFormSubmit(action)
    {
        var control = GetControlAction();
        control.value = action;
        formMain = document.forms[0];
        FormSubmit(formMain);
    }

    function SetActionAndValueFormSubmit(action, actionValue)
    {
        var control = GetControlAction();
        control.value = action;
        control = GetControlActionValue();
        control.value = actionValue;
        formMain = document.forms[0];
        FormSubmit(formMain);
    }

    function SetActionAndValueFormSubmitClear(action, actionValue)
    {
        var control = GetControlAction();
        control.value = action;
        control = GetControlActionValue();
        control.value = actionValue;
        CreateClearSessionFormVariables();
        var formMain = document.forms[0];
        FormSubmit(formMain);
    }
    
    function RenewSession()
    {
        formMain = document.forms[0];
        var newElement = document.createElement('input');
        newElement.setAttribute('id', '__RenewSession');
        newElement.setAttribute('name', '__RenewSession');
        newElement.setAttribute('type', 'hidden');
        newElement.setAttribute('value', 'yes');
        formMain.appendChild(newElement);
        FormSubmit(formMain);
    }
    
    function FormSubmitMain()
    {
        FormSubmit(document.forms[0]);
    }
    
    function SetActionFormSubmitIndexOrName(action, forIndexOrName)
    {
        formMain = document.forms[forIndexOrName];
        formMain.ctl00$__Action.value = action;
        FormSubmit(formMain);
    }
    function SetActionAndValueFormSubmitIndexOrName(action, actionValue, forIndexOrName)
    {
        var control = GetControlAction();
        control.value = action;
        control = GetControlActionValue();
        control.value = actionValue;
        formMain = document.forms[forIndexOrName];
        FormSubmit(formMain);
    }
    
    function FormSubmitIndexOrName(forIndexOrName)
    {
        FormSubmit(document.forms[forIndexOrName]);
    }
    
    function GoToUrl(url)
    {
        var control = GetControlSessionGuid();
        document.location = url + control.value;
    }
    
    function removeQueryStringVariableFromAction(queryStringVariableName, action)
    {
        var index;
        var questionMarkFirst = 0;
        
        index = action.indexOf('?' + queryStringVariableName + '=');

        if (index == -1)
            index = action.indexOf('&' + queryStringVariableName + '=');
        else
        {
            questionMarkFirst = 1;
            index += 1;
        }
        
        if (index != -1)
        {
            var indexSecondAmpersand = action.substring(index + 1).indexOf('&');
            
            if (indexSecondAmpersand == -1)
                action = action.substring(0, index);
            else
            {
                var indexAmpersand = index + 1 + indexSecondAmpersand + questionMarkFirst;
                action = action.substring(0, index) + action.substring(indexAmpersand);
            }
            
        }

        return action;
    }
    
    function formatAllTextAreas()
    {
		var textAreaList = document.getElementsByTagName("textarea");
		var index;
		
		for (index = 0; index < textAreaList.length; index++)
		    if (textAreaList[index].__format == "wordwrap")
		        adjustRows(textAreaList[index]);
		
    }
    
    function adjustRows(textarea)
    {
    
        if (textarea.rows) 
        {
            var lineBreaks = countLineBreaks(textarea.value);
            var height = 20;
                       
            if (lineBreaks > textarea.rows)
            {
                while (textarea.rows  < lineBreaks)
                {
                    textarea.rows += 1;
                    height += 13;
                }
            }
            
            while (textarea.rows * (400/7) <= textarea.value.length) 
            {
                textarea.rows += 1;
                height += 13;
            }
            
            var maxHeight=height;
            var adjustedHeight = textarea.clientHeight; 

            if (maxHeight > adjustedHeight ) 
            {     
             adjustedHeight = Math.max(textarea.scrollHeight, maxHeight); 
             textarea.style.height = adjustedHeight + "px"; 
            }
            else
            {
             textarea.style.height = adjustedHeight + "px"; 
            }
        }
        
    }
   
    function countLineBreaks(str)
    {
    
        try 
        {
            return((str.match(/[^\n]*\n[^\n]*/gi).length));
        }
        catch(e)
        {
            return 0;
        }
        
    }
    
    	function startCallback() 
    	{
    	   document.body.style.cursor='wait';
    	   EnableDisableFormElements(true);
    	   EnableDisableIframeElements(true);
		}
		
		function EnableDisableIframeElements(enable)
		{
            var iframeList = document.getElementsByTagName("IFRAME");
            var index = 0;
            var session = GetControlSessionGuid();
            
            for (; index < iframeList.length; index++)
            {
            
                if(iframeList[index].contentWindow.document.getElementById('__SessionGuid') != null)
                    EnableDisableElements(iframeList[index].contentWindow.document.forms[0],enable);
                    
            }
            
		}
		
		
		function EnableDisableFormElements(enable)
		{
		
            for (var x=0;x<document.forms.length;x++) 
               EnableDisableElements(document.forms[x], enable);
               
		}
		
		function EnableDisableElements(formControl,enable)
		{
		
            for (var i=0;i<formControl.elements.length;i++) 
            {
                var e = formControl.elements[i];
                
                if (e.type=="submit" || e.type=="reset" || e.type=="button")
                    e.disabled=enable;
                    
            }
            
		}
 
		function completeCallback(response,ifr)
		{
    	   ifr.parentNode.removeChild(ifr);
    	   SetActionValueAndValidationSkip('__SwitchView','FileUploadComplete','True');
    	   document.forms[0].submit();
    	   document.body.style.cursor='default';
		}
    
        function ExecuteReviewLink(viewName, controlName)
        {
            var control = GetControlAction();
            control.value = '__SwitchView';
            control = GetControlActionValue();
            control.value = viewName;
            var formMain = document.forms[0];
            newElement = document.createElement('input');
            newElement.setAttribute('id', '__ControlSetFocus');
            newElement.setAttribute('name', '__ControlSetFocus');
            newElement.setAttribute('type', 'hidden');
            newElement.setAttribute('value', controlName);
            formMain.appendChild(newElement);
            newElement = document.createElement('input');
            newElement.setAttribute('id', '__ShowReviewButton');
            newElement.setAttribute('name', '__ShowReviewButton');
            newElement.setAttribute('type', 'hidden');
            newElement.setAttribute('value', controlName);
            formMain.appendChild(newElement);
            FormSubmit(formMain);
        }
        
        function checkboxClick(checkBoxID, textboxID, callback)    
        {
            //var checkbox = document.getElementById(checkBoxID);
            //var textbox = document.getElementById(textboxID);
            var checkbox = GetControl(checkBoxID);
            var textbox = GetControl(textboxID);
            
            if (textbox != null)
            {
                if (checkbox.checked)
                    textbox.value = "1";
                else
                    textbox.value = "0";
            }

            if (callback != null && callback.length > 0) 
            {
                eval(callback + "(" + textbox.value + ")");
            }
            
        }
         
        function VisitUrl(controlId)
        {
           //var control=document.getElementById(controlId);
           var control=GetControl(controlId);
           
            if (control != null)
            {
                var url = control.value;
              
                if (url.length > 0)
                {
                    var httpToken = url.toString().toLowerCase().substring(0,7);
                    var httpsToken = url.toString().toLowerCase().substring(0,8);
                    
                    if( httpToken != 'http://' && httpsToken != 'https://')
                       url= 'http://'+url;
                    
                    var win6 =window.open(url,'LocationURL','height=600,width=800,scrollbars=yes,resizable=yes',false);
                    
                    if (window.focus)
                        win6.focus()
                    
                }
             
            }
            
        }
        
        function ShowUrl(url)
        {
              if (url.length > 0)
              {
                var httpToken = url.toString().toLowerCase().substring(0,7);
                var httpsToken = url.toString().toLowerCase().substring(0,8);
                
                if( httpToken != 'http://' && httpsToken != 'https://')
                {
                   url= 'http://'+url;
                }
                
                var win6 =window.open(url,'LocationURL','height=600,width=800,scrollbars=yes,resizable=yes',false);
                if (window.focus) {win6.focus()}
             }
        }
        
        function BuildProductDownloadUrl(url)
        {
            var control = GetControlSessionGuid();
            alert(url);
            url = url + "&__SessionGuid=" + control.value;
            return url;
        }

    function displayPageLocked()
    {
        try{
            DisableControlsForPopup();
        } catch(e) {};
        var control = $find('ctl00___PageLockedModalPopupExtender');

        if (control != null)
            control.show();
            
        setTimeout('GetControl("procImage").src = "Images/Processing.gif"', 5); 
    }

    function hidePageLocked()
    {
        var control = $find('ctl00___PageLockedModalPopupExtender')

        if (control != null)
            control.hide();
            
        try{
            EnableControlsForPopup();
        } catch(e) {};
    }
// -->

