﻿    
    // JScript File
    var m_DataBeforeEdit = "";
    var m_ajax_FocusedElement = null;
    function ajax_inlineHoverOn(control)
    {
        if(m_ajax_FocusedElement == control.uniqueID)
            return;
                
        control.className = "inline-hover-on";
    }

    function ajax_inlineHoverOff(control)
    {
        if(m_ajax_FocusedElement == control.uniqueID)
            return;
                
        control.className = "inline-hover-off";
    }

    function ajax_inlineFocusOn(control)
    {
        m_ajax_FocusedElement = control.uniqueID;            
        m_DataBeforeEdit = control.innerHTML;
        control.className = "inline-focus-on";
    }

    function ajax_inlineFocusOff(control)
    {
        m_ajax_FocusedElement = "";  
        control.className = "inline-focus-off";
    }

    function ajax_ProcessReturnMessage(result, source)
    {
        if(result.value == 0)
            ajax_UpdateStatus(0, source);
        else
            ajax_UpdateStatus(-1, source);
    }
    
    function ajax_UpdateStatus(status, source)
    {
        var feedback = document.getElementById("ajax_feedback")
        if(status == 0) // done
        {
            if(feedback != null)
            {
                feedback.innerHTML = "Updated successfully";
                feedback.className = "feedback-done";
            }
            source.className = "inline-hover-off";
            window.setTimeout(ajax_RemoveMessage, 3000);
        }
        else if(status == 1) // updating
        {
            if(feedback != null)
            {       
                feedback.innerHTML = "Updating data ...";
                feedback.className = "feedback-updating";
            }
            source.className = "inline-updating";
        }
        else if(status == -1) // failed
        {
            if(feedback != null)
            {               
                feedback.innerHTML = "Update failed";
                feedback.className = "feedback-failed";
            }
            source.className = "inline-failed";
        }        
        if(status == 2) // done, remove message
        {
            if(feedback != null)
            {               
                feedback.innerHTML = "";
                feedback.className = "feedback";
            }
        }
    }
    
    function ajax_RemoveMessage()
    {
        ajax_UpdateStatus(2, null);
    }


    function ajax_UpdateItemAttribute(clientid, itemid, type, name, obj)
    {
        if(m_DataBeforeEdit == obj.innerHTML)
            return;
            
        ajax_UpdateStatus(1, obj);
        Mediachase.eCF.PublicStore.SharedModules.EditorModules.SimpleEditor.UpdateItemAttribute(itemid, type, name, obj.innerHTML, function(result) {ajax_ProcessReturnMessage(result, obj);});
    }
    
    function ajax_openPop(url, width, height, scroll) {
    	var isMSIE = (navigator.appName == "Microsoft Internet Explorer");
    	var x = parseInt(screen.width / 2.0) - (width / 2.0);
    	var y = parseInt(screen.height / 2.0) - (height / 2.0);

	    if (typeof(scroll) == "undefined")
		    scroll = "no";

    	if (isMSIE) {
	    	// MSIE + XP SP2
		    width += 15;
		    height += 35;

		    //var features = "resizable:no;scroll:no;status:no;center:yes;help:no;dialogWidth:" + width + "px;dialogHeight:" + height + "px;";
		    //window.showModalDialog(url, window, features);
	    }
    	
    	var win = window.open(url, "StorePopup", "top=" + y + ",left=" + x + ",scrollbars="+ scroll +",modal=yes,width=" + width + ",height=" + height + ",resizable=yes");
	    win.focus();
    }
    
    function ajax_imageEdit(url, object, type)
    {
        ajax_openPop('../sharedmodules/editormodules/uploadimage.aspx', 100, 200, false);
    }    
