<!--
/*
		@Company	: LivePerson Inc.
*		@FileName	:proxy.js
*		@Description: Script file with methods for communicating Flash and LivePerson's monitor tag
*		@Author		: Uri Bahar (ubahar@liveperson.com)
*       @Legal Disclaimer: By downloading or using this software/code you expressly agree to the following: 
*        This software/code is for the limited use only in connection with the LivePerson services purchased by you. 
*        Once the LivePerson services are no longer in use, you must cease all use of the software/code and destroy all copies. 
*        The software/code is provided to you "as is" and without any warranty of any kind, express, implied or otherwise, including without limitation, 
*        any warranty of merchantability or fitness for a particular purpose.  In no event shall LivePerson or any of its affiliates be liable for 
*        any direct, indirect, special, incidental, or consequential damages or any other damages of any kind, whether LivePerson or any of its 
*       affiliates have been advised of the possibility of such loss, however caused, and on any theory of liability, arising out of or related 
*        to the possession, use or performance of this software/code.  
*       IF YOU DO NOT AGREE TO THE FOREGOING TERMS, DO NOT DOWNLOAD OR USE THE SOFTWARE/CODE

*/

//Must set this to the actual Flash object reference on the page!!!
lpMTagConfig.flashMovie = null;

/*  
LP Events: The body of these methods should be replaced with a call to the Flash object
*/

//Create a new button object overide
lpMTagConfig.db1 = new Object();
lpMTagConfig.db1.dbStart = function (btname)
{
  try{
	//init flash button only when flash is ready
   setTimeout('lpMTagConfig.initButtonWhenReady(\"' + btname + '\")', 500);
  }catch(e){}
   
   return true;
}

//override the State Change event
lpMTagConfig.db1.dbStateChange = function (btname, state)
{
    try{
       //notify the Flash button the state should change. Make sure the button is ready before doing so
       setTimeout('lpMTagConfig.setButtonStateWhenReady(\"' + btname + '\",\"' + state + '\")', 500);
   }catch(e){}
   
   return true;
}

//invitation loaded (NOT shown yet)
lpMTagConfig.inviteChatStart =  function (invitename)
{
    try{
        //set the inner HTML of the invitation to the Flash object
        var inviteObj = eval(invitename);
        if (inviteObj==null) {
            return true;
        }
        var divObj = inviteObj.GetObj(inviteObj.divID);
        if (divObj==null) {
            return true;
        }
        
	    divObj.innerHTML = "";
        divObj.style.width = "1px";     
        divObj.style.height = "1px";
	
	    //don't attempt to interact with Flash before it's ready
	    setTimeout('lpMTagConfig.showInviteWhenReady(\"' + invitename + '\")', 500);
	
	}catch(e){}
	
	return true;
}

//invitation timed out
lpMTagConfig.inviteChatTimeout =  function (invitename)
{
    try{
	    //hide the invitation
        lpMTagConfig.flashMovie.hideInvitation();
    }catch(e){}
        
    return true;
}

//Flag to check Flash is ready
lpMTagConfig.bSWFInviteReady = false;
lpMTagConfig.bSWFButtonReady = false;


lpMTagConfig.flashevent_MarkSWFInviteReady =  function (){
 lpMTagConfig.bSWFInviteReady = true;
 return true;
 }

lpMTagConfig.flashevent_MarkSWFButtonReady = function (){
 lpMTagConfig.bSWFButtonReady = true;
 return true;
}

lpMTagConfig.showInviteWhenReady = function(invitename){
 
 try{  
	if(!lpMTagConfig.bSWFInviteReady){
		setTimeout('lpMTagConfig.showInviteWhenReady(\"' + invitename + '\")', 500);
		return;
	}
	lpMTagConfig.flashMovie.createInvitation(invitename);
	lpMTagConfig.flashMovie.showInvitation();
	
 }catch(e){}	

}

lpMTagConfig.initButtonWhenReady = function(btname){
 try{
	if(!lpMTagConfig.bSWFButtonReady){
		setTimeout('lpMTagConfig.initButtonWhenReady(\"' + btname + '\")', 500);
		return;
	}

	lpMTagConfig.flashMovie.createButton(btname);
 }catch(e){}
}

lpMTagConfig.setButtonStateWhenReady = function(btname, state){
	
  try{

	if(!lpMTagConfig.bSWFButtonReady){
		setTimeout('lpMTagConfig.setButtonStateWhenReady(\"' + btname + '\",\"' + state + '\")', 500);
		return;
	}
	//flashMovie.createButton(btname);
	lpMTagConfig.flashMovie.setState(btname, state);
	
  }catch(e){}	
	
}    
/*
FLASH EVENTS: Flash should call the below methods for click events that occur in the button and invitation
*/
//Notifification from Flash button when button is clicked
lpMTagConfig.flashevent_ButtonClicked = function (btname)
{
  try{
    //try to convert the button name to the button object
    var objBt = eval(btname);
    if(objBt == null || typeof(objBt) == "undefined")
    {
       return;
    }
    
	//call the internal Monitor tag implementation
    objBt.actionHook();
    
  }catch(e){} 
}
//Notifification from Flash invitation when invitation is accepted
lpMTagConfig.flashevent_InvitationAccepted = function(invitename)
{
    try{
        //try to convert the invite name to the invite object
        var objInv = eval(invitename);
    	
        if(objInv == null || typeof(objInv) == "undefined")
        {
            return;
        }
        
	    //now call the Monitor tag implementation that will show the chat window
        objInv.AcceptInvite();
    }catch(e){}    
}

//Notifification from Flash invitation when invitation is declined
lpMTagConfig.flashevent_InvitationDeclined = function(invitename)
{
    try{
        //try to convert the invite name to the invite object
        var objInv = eval(invitename);
        if(objInv == null || typeof(objInv) == "undefined")
        {
            return;
        }
        
        //now call the Monitor tag implementation
        objInv.CloseInvite();
    }catch(e){}    
}
