


//Note:
// 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...";


//var stAimsChatURl = "https://collaborateextst.verizon.com/aims/encore/VZCTC.serv"; // for sit.
//var aimsAppid = 144;

//SIT: https://collaborateextst.verizon.com/aims/encore/VZCTC.serv
//STG: https://collaborateextstg.verizon.com/aims/encore/VZCTC.serv
//PRD: https://collaborateextstg.verizon.com/aims/encore/VZCTC.serv


var isLoopQulified= "Y"; //N if not.

if(chatStarted=="N")
{
	document.getElementById('textVAQuestion').value= defaultText;
}

function clearVAChatText(thefield)
{
	if (thefield.value == defaultText)
	thefield.value = "";
}

function removeVAText()
{
	if( chatStarted == "Y" &&  aims_ctcChatWindow.closed ==false)
	{
		document.getElementById('textVAQuestion').value="";
		document.getElementById('textVAQuestion').readOnly =false;
	}
}

function enablesVAcript()
{
	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(url,appid,isLQ) 
{

       
	var myWidth = 320;
	var myHeight = 620;
	var padding = 12;
	top.resizeTo(top.screen.availWidth - (myWidth + padding), top.screen.availHeight);
	top.moveTo(myWidth + padding, 0);
	var stAimsChatURl =url;
	var aimsAppid =appid;

    if( aims_ctcChatWindow!=null && aims_ctcChatWindow.closed==false )
    {
		aims_ctcChatWindow.focus();
	}
    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 = 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=" +aimsAppid+ "&Source Title=" + escape(srcTitle) + "&Source URL=" + escape(window.document.location) +"&initQ=" +escape(vaQuestion) +"&isLoopQ=" + isLQ;
		
		aims_ctcChatWindow = window.open(aimsurl, chatWindowName, aimsChatWindowFeatures);
		chatStarted = "Y";
	}
}
