Type.registerNamespace('ZeccoShare.JS');
ZeccoShare.JS = 
{
    OnZeccoSharePageLoad : function ( )
    {
	  Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest);
	  Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded);
                           
	  function beginRequest(sender, args) {
	    document.body.style.cursor = 'wait';
	  }
	  function pageLoaded(sender, args) {
		document.body.style.cursor = 'default';
	  }        
    
    },
    
    //e: event, for FF compatibility
    //btnSubmit: the ID of the sumbit button to click when enter key is press
    //valFunc: validation function
    //func: is the function to call before the form is submitted
    //param: parameter to pass into the function
    CheckEnter : function (e, btnSubmit, valFunc, func, param)
    {
        if (this.IsEnter(e))
        {
            if (typeof(valFunc) == 'function')
            {
                if (!valFunc(param))
                    return false;
            }
            if (typeof(func) == 'function')
                func(param);
            if(window.event)
            {
                __doPostBack(btnSubmit, "");
                window.event.keyCode = 0;
            }
            else
            {
                e.preventDefault();  
                __doPostBack(btnSubmit, "");
            }
        }
        else
            return true;
    },
    
    GetAsciiCode : function(e)
    {
        if(window.event)
            return window.event.keyCode;
        else
        {
            return e.keyCode == 0 ? e.charCode : e.keyCode;
        }
    },
    
    IsEnter : function(e)
    {
        return this.GetAsciiCode(e) == 13;
    },
    
    //Delay the ScrollToElement after the UpdatePanel is loaded
    AyncScrollToElement : function(id)
    {
		//Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(this.ScrollToElement(id));    
    },
    
    ScrollToElement : function(id)
    {
	    var elem = document.getElementById(id);
		elem.scrollIntoView(true);	 
		//Sys.WebForms.PageRequestManager.getInstance().remove_pageLoaded(this.ScrollToElement(id));  
    },
    
    CheckZeccoShareStatus : function(chkBox)
	{	
		if(chkBox)
		{
			if(chkBox.checked)
			{
				isZeccoShareMember = true;
				hasZeccoShareProfile = true;
			}					
		}		
	}
    
    
}


ZeccoShare.JS.MemberSearch = 
{
    txtVisibleID : '',
    lnkID : '',

    ToggleAdv : function()
    {
        //$get(this.txtVisibleID).value = ($get(this.txtVisibleID).value == '0'?'1':'0');
        this.SetAdvVisibility();
    },
    
    SetAdvVisibility : function(sender, args)
    {
        var panelOptions = $get('pnlAdv');
        panelOptions.style.display = (panelOptions.style.display == 'none' ? 'block' : 'none');
        $get('lnkToggle').innerHTML = (panelOptions.style.display == 'none' ? 'More Options' : 'Less Options');
        
        //visible = $get(ZeccoShare.JS.MemberSearch.txtVisibleID).value;
        //$get(ZeccoShare.JS.MemberSearch.lnkID).innerHTML = (visible=='0'?'More Options':'Less Options');
        
            //$get('pnlAdv').style.display = (visible=='0'?'none':'block');
//        if (visible == '1')
//        {
//            //AjaxControlToolkit.Animation.FadeInAnimation.play($get('pnlAdv'));
//            //AjaxControlToolkit.Animation.ResizeAnimation.play($get('pnlAdv'), 0.2, 10, 400, 200, 'px');                
//        }
//        else
//        {
//            //AjaxControlToolkit.Animation.FadeOutAnimation.play($get('pnlAdv'));
//            //AjaxControlToolkit.Animation.ResizeAnimation.play($get('pnlAdv'), .2, 10, 400, 0, 'px');
//        }
    },
    
    CheckSharing : function(txt1, txt2, chk)
    {
        t1 = $get(txt1).value; if (t1=='Use space to separate symbols') t1 ='';
        t2 = $get(txt2).value; if (t2=='Use space to separate symbols') t2 ='';
        chk = $get(chk);
        chk.checked = !(t1=='' && t2== '');
    },
    
    CheckActivateZeccoShareProfile : function()
    {
		var chk = $get('chkShareProfile');
        if(chk)
        {
			if(chk.checked)
			{
				isGuest = false; 
				hasZeccoShareProfile = true; 
				isZeccoShareMember = true;
			}        
        }
    }        
	
}

//For note popup, !!!!this requires a Page Method called "GetNote"!!!!!!
ZeccoShare.JS.NotePopup = 
{
    objTextBox : null,
    objNotesLink : null,
    
    ShowNote : function(tradeID, e)
    {
        try{
            var obj=$get("bubble_tooltip");
            obj.style.display = 'block';

            var e = e ? e : window.event;

            var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
            var leftPos = e.clientX - 100;
            if( leftPos<0 ) leftPos = 0;
            obj.style.left = leftPos + 'px';
            obj.style.top = e.clientY - obj.offsetHeight -1 + st + 'px';

            this.objTextBox = obj.getElementsByTagName('textarea')[0];
            this.objTextBox.value = "";


            if(e.srcElement)
                this.objNotesLink = e.srcElement;
            else
                this.objNotesLink = e.target;

            if (this.objNotesLink.tagName != "A")  //it may come from "Add" link or "Edit" image
                this.objNotesLink = this.objNotesLink.parentNode;

            iAction = 4;
            this.objTextBox.readOnly = true;
            if(this.objNotesLink.getAttribute("iAction") != null)
            {
                iAction=parseInt(this.objNotesLink.getAttribute("iAction"));
                this.SetTitle(iAction);
            }
            


            //objTextBox = obj.getElementsByTagName('textarea')[0];
            this.objTextBox.TradeID = tradeID;
            
            if(iAction != 0)
                this.GetNote(tradeID);	  
      }catch(e){   }
    },

    SetTitle : function(action)
    {
        objTitle=$get("spNoteTitleText");

        spanEdit = $get("spNoteLinkEdit");
        spanEdit.style.display='none';

        spanDelete = $get('spNoteLinkDelete');
        spanDelete.style.display = 'none';
        this.objTextBox.readOnly = false;


        switch( iAction )
        {
            case 0: /* Add */
                this.objTextBox.value="";
                objTitle.innerHTML="Add a public note to your trade";
                this.objTextBox.focus();
                spanEdit.style.display = '';
                break;
               
            case 1: /* Edit */
                objTitle.innerHTML="Edit your public trade note";
                this.objTextBox.focus();
                spanEdit.style.display = '';
                spanDelete.style.display = ''; 
                break;

            case 4: /* viewable only */		      
                objTitle.innerHTML="Trade note";		      
                this.objTextBox.readOnly = true;
                break;
               
            default:
                break;	  
        }
    },
    
    GetNote: function(tradeID) 
    {
       PageMethods.GetNote(tradeID, ZeccoShare.JS.NotePopup.SetNoteText); 
    },

    SetNoteText : function (result, response, context)
    {
        ZeccoShare.JS.NotePopup.objTextBox.value = result;
    },

    CloseNote : function()
    {
        try{
            $get("bubble_tooltip").style.display='none';
        }catch(e){ }      
    },
    
    EditNote : function()
    {
        if (this.objTextBox.value == '')
        {
            this.DeleteNote();
            return;   
        }
        
        this.CloseNote();
        PageMethods.UpdateNote(this.objTextBox.TradeID, this.objTextBox.value);
        this.SetLinkText("<img src='/themes/default/images/icons/recent_trades/editnote.gif' alt='edit' title='Edit Note' />",1);
    },

    DeleteNote : function()
    {
        this.CloseNote();
        PageMethods.DeleteNote(this.objTextBox.TradeID);
        this.SetLinkText("add",0);
    },
    
    SetLinkText : function(strText,iAction)
    {  
        try{
           this.objNotesLink.innerHTML=strText;
           this.objNotesLink.setAttribute("iAction",iAction);            
                                                
        }catch(e){}  
    }

}



	