// Used by Live help client side

// Chat window object array
var chatWindowArray = new Array();

// Handles start live help button event.
function onStartLiveHelp()
{
    var myForm = document.frmLiveHelp;         // add by lianying 03/29/2005.
	if (isEmpty(myForm.sFirstName.value) || isEmpty(myForm.sLastName.value))
	{
		alert("Please fill in the required fields.");
	}	
	else
	{	
		checkBrowser();
	
		if(!bSafari)
			myForm.target = "NewWindow";
		
		myForm.submit();
	}
}

// Used by the page displayed on user's screen when there is no help staff online.
// Handles email help button. 
function onEmailHelp()
{
    var myForm = document.frmEmailHelp;     // add by lianying 03/29/2005.
	if (!isEmpty(myForm.sFirstName.value) && !isEmpty(myForm.sLastName.value) &&
	    !isEmpty(myForm.sEmail.value) && !isEmpty(myForm.sBody.value))
	{
		// add by linliming, 07/29/2005, bug id 5287.
		if(!isValidEmail(myForm.sEmail.value))
		{
		    alert("Please enter a valid recipient's email address.");
		}
	    else
	    {
	    	checkBrowser();
	
			if(!bSafari)
				myForm.target = "NewWindow";
	    	
	        myForm.submit();
	    }
	}
	else
		alert("Please enter the required field(s).");
}

// Handles Live help toolbar buttons' events
// Param: 	item		Toolbar bar button
/*
function onToolButtonClickLiveHelp(item)
{
	document.toolbar.setToolbarEnabled(false);
    var bRedirect = false;  //add by linliming ,03/30/2005, Be used of managing the redirection.
	
	if (item.getId()=="idSave")
		onStartLiveHelp();	
	else if (item.getId()=="idBack")
	{
		window.location.href="User0.jsp";
		bRedirect = true;
	}
	else 
		top.window.close();	
    if(!bRedirect)
	    document.toolbar.setToolbarEnabled(true);
}
*/
function onToolButtonClickLiveHelp(itemId, itemValue)
{	
	if (itemId == "idSave")
	{
		onStartLiveHelp();
	}
	else if(itemId == "idBack")
	{
		window.location.href="User0.jsp";
    }
    else if(itemId == "idClose")
	{
		top.window.close();
    }
}



// Handles email help toolbar buttons' events
// Param: 	item		Toolbar bar button
/*
function onToolButtonClickEmailHelp(item)
{
	document.toolbar.setToolbarEnabled(false);
    var bRedirect = false;  //add by linliming ,03/30/2005, Be used of managing the redirection.
		
	if (item.getId()=="idSave")
		onEmailHelp();	
	else if (item.getId()=="idBack")
	{
		window.location.href="User0.jsp";
	    bRedirect = true;
    }
	else if (item.getId()=="idSend")
		onEmailHelp();	
	else 
		top.window.close();
	
	if(!bRedirect)
	   document.toolbar.setToolbarEnabled(true);
}
*/

function onToolButtonClickEmailHelp(itemId, itemValue)
{	
	if (itemId == "idSave")
	{
		onEmailHelp();
	}
	else if(itemId == "idBack")
	{
		window.location.href="User0.jsp";
    }
    else if(itemId == "idSend")
	{
		onEmailHelp();
    }
    else if(itemId == "idClose")
	{
		top.window.close();
    }
    else if(itemId == "idReset")
	{
		document.frmEmailHelp.reset();
	}
	else if(itemId == "idHelp")
	{
		dialogArguments.top.Header.displayHelp("EmailHelp");
	}
	else if(itemId == "idSuggest")
	{
		showUserReport();
	}
}

// Get a unique chat ID
function getChatId()
{		
	var sChatId = new Date()/1 + "";
	sChatId = sChatId.substr(0,5) + sChatId.substr(9);
	
	document.frmLiveHelp.hidChatId.value = sChatId;	
}

// limit the length of the sBody textarea's value.
// add by linliming, 07/29/2005, bug id 5287.
function onEndEidting(vObj)
{
	//var current = event.srcElement;
	if (vObj.value.length >4000)
	{
		alert("The maximum length of the field is 4000 characters. The data has been truncated.");
		vObj.value = current.value.substr(0, 4000);
	}
}


