


//Note:  https://collaborateextst.verizon.com/aims/encore/VZCTC.serv
// Define a text area with id = "textVAQuestion"
// exmaple: <textarea id= "textVAQuestion" onFocus="clearVAChatText(this)" onmouseout="removeVAText();" onmouseover="enablesVAcript();" style="padding:3px"></textarea>
// On click of the actual Ask or submit button, call doOnChatLinkClick , with the actual servlet URL and the app id given,

 var aims_ctcChatWindow = null; 
            var chatStarted = "N";
            var defaultText ="Enter your question here and then click Ask Now below...";
           
            if(chatStarted=="N")
              {
                
                if(document.getElementById('textVAQuestion')!= null)
                    document.getElementById('textVAQuestion').value= defaultText;
              }
            
            function clearChatText(thefield)
            {
	            if (thefield.value == defaultText)
		            thefield.value = "";
            } 
            
            function removeText()
            {
	            if( chatStarted == "Y" &&  aims_ctcChatWindow.closed ==false)
	            {
		            if(document.getElementById('textVAQuestion') != null)
		            {
		                document.getElementById('textVAQuestion').value="";
		                document.getElementById('textVAQuestion').readOnly =false; 
		            }
	            }

            }
              	
		   function enablescript()
            {
              if( chatStarted == "Y")
	            {
		            if(aims_ctcChatWindow.closed ==true)
		            {
			            chatStarted = "N"; 
			            document.getElementById('textVAQuestion').value= defaultText;
		            }
		            else 
		            {
			            document.getElementById('textVAQuestion').value="We have launched a Virtual Agent window where you may ask your questions";
			            document.getElementById('textVAQuestion').readOnly ='readonly'; 	
		            }
	            }

            }
			  
			  
			function doOnChatLinkClick(stAimsChatURl,appid) 
			{
                
			    try{_hbLink('aimsChatIcon');}catch(e){}
			    var myWidth = 320;
				var myHeight = 620;
				var padding = 12;
				window.resizeTo(window.screen.availWidth - (myWidth + padding), window.screen.availHeight);
				window.moveTo(myWidth + padding, 0);  
			  if( aims_ctcChatWindow!=null && aims_ctcChatWindow.closed==false )
			  {
                aims_ctcChatWindow.focus();
		        //document.getElementById('textVAQuestion').disabled= true;
		        //document.getElementById('aimsChatIcon').disabled= true;
		       // document.getElementById('textVAQuestion').value="We have launched a Virtual Agent window where you may ask your questions";
              }
              else
              {
				var chatWindowName = 'AIMSCTCCHATWINDOW';
				var width = screen.availWidth;
				var width = 320;
				var height =700;
				var aimsChatWindowFeatures = 'left=0,top=0,width='+width+',height='+height;
				
				var vaQuestion = "";
				if(document.getElementById('textVAQuestion') != null)
				    vaQuestion = document.getElementById('textVAQuestion').value;
				
				if(vaQuestion==defaultText)
				{  
				   vaQuestion= "";
				} 
				while(vaQuestion.indexOf("'")!=-1){ vaQuestion = vaQuestion.replace("'",""); }  
				var srcTitle =document.title
				srcTitle = srcTitle.replace("'","");	
				
				var aimsurl = stAimsChatURl + "?appid=" +appid+ "&Source Title=" + escape(srcTitle) + "&Source URL=" + escape(window.document.location) +"&initQ=" +escape(vaQuestion) ;
				
				aims_ctcChatWindow = window.open(aimsurl, chatWindowName, aimsChatWindowFeatures);
				chatStarted = "Y";
				//document.getElementById('textVAQuestion').disabled= true;
				//document.getElementById('aimsChatIcon').disabled= true;
				//document.getElementById('textVAQuestion').value="We have launched a Virtual Agent window where you may ask your questions";
			  }
			}

