var iRecordingEnabled=0;
var iMessageEnabled=0;
//var iState=0; //0=paused 1= waiting 2= speaking
var iIndex=0;
var iSocketID=0;
var iCount=0;
var iConnectedDistrib=0;		//flags for socket connection
var iConnectedGateway=0;
var iConnectedSC=0;
var blank="                                                                                   ";
var part1=new Array(200);
var part2=new Array(2);
var iLogin=0;
var zCallerEmail;
var szSender;
var szBcc;
var szText;
var szPassword;

// for alert messages
var alertmessage=""
var noready=0;
var iMap=0;
var szMap;
//for scripts
var szScriptBuffer=new String;
var szContent;
var szLabels
var szColors
var aszContent=new Array(200);
var aszLabels=new Array(10);
var aszColors=new Array(10);
var aszAnswer=new Array(part1, part2);
var aszRelations=new Array(100);
var aszFields=new Array(10);


//for fields
var szFieldsBuffer=new String;
var aszResultCodes=new Array(30);
var iResultsCount;
var aszOtherCodes=new Array(30);
var szNotes2=" "

//window names
var winProperties;
var winScript;
var winWrapup;
var winRecentNotes;
var winStatistics;
var winNoCamp;
var newWindow;
var buffer=new String();

var username;
var campaign;
var iSpeaking;
var iWaiting;
var iRinging;
var szDistributor;
var scripturl;
var aszFieldEdit=new Array(20);
var aszRunningCampaigns=new Array(20);		//for director to tell us what camps are running


function isphonecharacters(theitem){
// allow ONLY phone characters
  var checkOK = "0123456789()-+ ";
  var checkStr = theitem;
	allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
return allValid;
}

function isextensioncharacters(theitem){
// allow ONLY normal extension characters
  var checkOK = "0123456789#* ,.";
  var checkStr = theitem;
	allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
return allValid;
}


function getCookie(NameOfCookie)
{ 
		if (document.cookie.length > 0) 
		{ 
			begin = document.cookie.indexOf(NameOfCookie+"="); 
			if (begin != -1) 
			{ 
				begin += NameOfCookie.length+1; 
				end = document.cookie.indexOf(";", begin);
				if (end == -1) end = document.cookie.length;
				return unescape(document.cookie.substring(begin, end));
			} 
		}
		return null; 
}



function setCookie(NameOfCookie, value, expiredays) 
{ 
		var ExpireDate = new Date ();
		ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
		if ((value == null) || (value.length < 1))
			value=" ";
		document.cookie = NameOfCookie + "=" + escape(value) + 
		((expiredays == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}



function setCookieMins(NameOfCookie, value, expireminutes) 
{ 
		var ExpireDate = new Date ();
		ExpireDate.setTime(ExpireDate.getTime() + (expireminutes * 60 * 1000));
		document.cookie = NameOfCookie + "=" + escape(value) + 
		((expireminutes == null) ? "" : "; expires=" + ExpireDate.toGMTString());
}



 
function MM_openBrWindow(theURL,winName,features) 
{ 
		//v.2.0
		var newWindow = window.open(theURL,winName,features);
		newWindow.focus();
		return newWindow;
} 



function MM_callJS(jsStr) 
{ 
		//v2.0
		return eval(jsStr);
}



function MM_goToURL() 
{ 
		//v3.0
		var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
		for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}



function webinar_func() 
{
		MM_goToURL('parent','http://209.225.30.147/GCC/conferencing/partaccess.asp?ba=300000007');
}




function properties_func() 
{
	
		//parent.document.getElementById("bodyframe").cols="0%,0%,0%,0%,0%,100%,0%,0%,0%,0%" ;
		if (top.iProperties==0)   //is showing
		{
	//		parent.document.getElementById("bodyframe").cols="0%,0%,0%,100%,0%,0%,0%,0%,0%,0%" ;
			parent.document.getElementById("bodyframe").rows="48%,0%,52%,0%,0%,0%,0%,0%,0%,0%" ;

			top.iProperties=1;
		}
		else
		{				//pop is showing
//			parent.document.getElementById("bodyframe").cols="100%,0%,0%,0%,0%,0%,0%,0%,0%,0%" ;
//				parent.document.getElementById("bodyframe").cols="40%,0%,60%,0%,0%,0%,0%,0%,0%,0%" ;
			parent.document.getElementById("bodyframe").rows="0%,0%,0%,0%,0%,40%,0%,0%,0%,0%,60%" ;

			
			top.iProperties=0;
		}		
		
}



function script_func() 
{
		winScript=MM_openBrWindow('script.htm','script','dependent=yes,directories=no,alwaysRaised=yes,height=250,width=530,menubar=no,scrollbars=no,left=200,top=200');
}



function prop_load_func() 
{
		//check for cookies
		if (!(document.cookie.length > 0)) 
		{
			alert("No cookies found. \n This may be your first login but check to make sure cookies are enabled");
			return;
		}
		else if (getCookie("phone")!=null)
		{
			document.forms.form1.phone.value=getCookie("phone");
			top.szPhone=getCookie("phone")
			 if ((getCookie("ext")!=null) && (getCookie("ext") != "") && (getCookie("ext") != " "))
			{
				document.forms.form1.ext.value=getCookie("ext");
				top.szExtension=getCookie("ext")
				//alert (getCookie('ext'))
			}
			else
			{
				top.szExtension=" "
			}
		}
		else if (getCookie("gateway")!=null)
			document.forms.form1.gateway.value=getCookie("gateway");
		else if (getCookie("gateway2")!=null)
			document.forms.form1.gateway2.value=getCookie("gateway2");
}



function prop_ok_func() 
{
		top.phone=document.forms.form1.phone.value;
		setCookie("phone", top.phone, 30);
		top.szExtension=document.forms.form1.phone.value;
		ext=document.forms.form1.ext.value;
		if ((ext=="") || (ext==" "))
			ext=" ";
		setCookie("ext", ext, 30);
		gateway=document.forms.form1.gateway.value;
		setCookie("gateway", gateway, 30);

		gateway2=document.forms.form1.gateway2.value;
		setCookie("gateway2", gateway2, 30);
}



function wrapupnotes_func() {
		if (top.iLogin==0)
		{
			//alert("You are not logged in")
			alertmessage="You are not logged in"
			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
		}
		else
			parent.document.getElementById("bodyframe").cols="0%,0%,0%,0%,0%,0%,0%,100%,0%,0%" ;
}


function properties_preload() {
		parent.document.getElementById("bodyframe").cols="0%,0%,0%,0%,0%,100%,0%,0%,0%,0%" ;
}



function write_to_server(szState1,szAction1, szChannel, szNameString1, szCampaign)
{
		var szOutBuffer;
		blank="                     ";
		var szBlankBuffer;

//		if (szState1=="94")		
//			alert(szNameString1);
		for (i=0;i<=501;i++)
			szBlankBuffer+=" "
		
	//rnb	if (top.iLogin==0)   //not loged in anyway
	//		{
	//		alert(top.iLogin);
	//		return;
	//		}
		//buffer must be 518 bytes	rest of buffer is 18 bytes
	//	alert("into");
		szOutBuffer=top.szUserID.substr(0,12)+blank.substr(0,12-top.szUserID.length)+szChannel.substr(0,2)+blank.substr(0,2-szChannel.length)+szState1.substr(0,2)+blank.substr(0,2-szState1.length)+szAction1.substr(0,2)+blank.substr(0,2-szAction1.length)+szNameString1.substr(0,499)+szBlankBuffer.substr(0,500-szNameString1.length);
		top.leftFrame.supervisor.SendLen = szOutBuffer.length; 
		//top.leftFrame.supervisor.SendLen = 518; 
	//	alert("out of");
	//	alert("szOutBuffer="+szOutBuffer);
		try
		{
			top.leftFrame.supervisor.SendData = szOutBuffer; 
		}
		catch(e)
		{
			//JTT 5-20-03
			if (top.noready == 0) // only displays alert a maximum of every 10 seconds
			{
				alertmessage="Please wait. Not Ready."
				showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
				top.notready = 1;
			}
			return;
//			alert("Please wait. Not Ready. A");
		}
}





function record_mess_func() 
{
		//alertmessage="feature not enabled"
		//showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
		if (top.iLogin==0)
		{
			alertmessage="not logged in"
			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
			return;
		}
		if (top.iLogin==1)
		{
			// send "JT" code to initiate recording of message
			top.szCampaign=getCookie("campaign");
			top.szPhone=getCookie("phone");
			top.szUserID=getCookie("userid");
			top.szExtension=getCookie("ext");
			if (top.szExtension.length < 1)
				top.szExtension=" "
			alertmessage="You will receive a call right away. \n On the phone you hear \"Dialer Online\". \n You must press \"11\" to begin recording your message."
//			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
			strlen=top.szPhone.length;
			p1=blank.substr(0,15)+"000"+top.szPhone+blank.substr(0,15-strlen);
			strlen=top.szUserID.length
			p2=blank.substr(0,10)+top.szUserID+blank.substr(0,12-strlen);
			strlen=top.szExtension.length
			p3=blank.substr(0,10)+top.szExtension+blank.substr(0, 10-strlen);
			buffer="JT"+top.szCampaign+blank.substr(0,20-top.szCampaign.length)+p1+p2+p3;
			top.leftFrame.gateway.SendLen = buffer.length;
			try
			{
				top.leftFrame.gateway.SendData = buffer; 
			}
			catch(e)
			{
				alertmessage="system's not ready. please wait."
				showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
			}
			top.iLogin=0 
			top.leftFrame.form1.searchingImage.src = '/images/x.gif';
			top.leftFrame.form1.pausedImage.src = '/images/check.gif';
			top.leftFrame.form1.dataconnImage.src = '/images/check.gif';
			top.leftFrame.form1.calleeconnImage.src = '/images/x.gif';
			top.leftFrame.form1.voiceconnImage.src = '/images/x.gif';
			top.leftFrame.form1.wrapImage.src = '/images/x.gif';
			top.leftFrame.form1.recordImage.src = '/images/check.gif';

			//set login to zero just so they can't go online until the message setting is done - Get TJ
		}
		else
		{
			alertmessage="recording is not enabled"
			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
			// alert("recording is not enabled");	
		}
}


function play_mess_func() 
{
		if (top.iLogin==0)
		{
			alert("not logged in");
			return;
		}
		else if (top.iLogin==1)
		{
			alertmessage="you do not have an audio connection"
			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
			//alert("you do not have an audio connection")
			return
		}
		else if (top.iLogin==3)
		{
			if (top.iMessageEnabled==1)					
			{
				szPlayPound=top.iPlayPound+"    ";
				buffer="8D"+top.szCampaign+blank.substr(0,15-top.szCampaign.length)+szPlayPound;
				top.leftFrame.gateway.SendLen = buffer.length; 
				try
				{
					top.leftFrame.gateway.SendData = buffer; 
				}
				catch(e)
				{
					alertmessage="system's not ready. please wait."
					showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
					//alert("system's not ready. please wait.");
					return;
				}	
				write_to_server("8D","8D","8D"," ","Campaign");
				top.iLogin=1;   //rnb 5/15/03 no longer connected.
				alertmessage="message play triggered"
				//showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
				//alert("message play triggered");
				top.leftFrame.form1.searchingImage.src = '/images/check.gif';
				top.leftFrame.form1.pausedImage.src = '/images/x.gif';
				top.leftFrame.form1.dataconnImage.src = '/images/check.gif';
				top.leftFrame.form1.calleeconnImage.src = '/images/x.gif';
				top.leftFrame.form1.voiceconnImage.src = '/images/check.gif';
				top.leftFrame.form1.wrapImage.src = '/images/x.gif';
				top.leftFrame.form1.recordImage.src = '/images/x.gif';
				

				//rnb 4/1/03 disconnect_func() 
			}
			else
			{
				// login = 2
				alertmessage="messages are not enabled"
				showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
				//alert("messages are not enabled");	
			}	
		}
		else
		{
				alertmessage="not speaking so can't leave message"
				showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
				//alert("not speaking so can't leave message");
			return;
		}

}



function do_not_call_func() 
{
		if (top.iLogin==0)
		{
			alert("not logged in");
			return;
		}
		if (top.iLogin==1)
		{
			alertmessage="you do not have an audio connection"
			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
			//alert("you do not have an audio connection")
			return
		}
		if (top.iLogin==3)	// means is online and talking
		{
			szDataBuffer="DCB "+top.phonen+blank.substr(0,20-top.phonen.length)+top.szRecno+blank.substr(0,20-top.szRecno.length)+top.szUserID+blank.substr(0,20-top.szUserID.length)+top.szCampaign+blank.substr(0,20-top.szCampaign.length);
			write_to_server("70","70","70",szDataBuffer,"0");
//rnb 4/23/03			alertmessage="a DoNotCall was registered"
//rnb 4/23/03			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
			//alert("a DoNotCall was registered");
			top.leftFrame.form1.searchingImage.src = '/images/check.gif';
			top.leftFrame.form1.pausedImage.src = '/images/x.gif';
			top.leftFrame.form1.dataconnImage.src = '/images/check.gif';
			top.leftFrame.form1.calleeconnImage.src = '/images/x.gif';
			top.leftFrame.form1.voiceconnImage.src = '/images/check.gif';
			top.leftFrame.form1.wrapImage.src = '/images/x.gif';
			top.leftFrame.form1.recordImage.src = '/images/x.gif';
			
			
			disconnect_func() 
		}
		else
		{
			alertmessage="no callee connected"
			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
			//alert("no callee connected");
			//if iLogin==2
		}
		
}






function login_func() {
		//validate the userid
		//changeValue(document.getElementById("wow"),"richard");
		var szPassEn="        ";
	
		if (top.iLogon==1)
		{
			alert("already logged on");
			return;
		}
		if (top.iLogon==2)
		{
			alert("already logged on");
			return;
		}
		if (top.iLogon==3)
		{
			alert("already logged on");
			return;
		}
			
		//test to see of enabled
		if (getCookie("cookiesEnabled")!="yes")
		{
			alert("Cookies must be enabled");
			return;
		}
		top.szFieldsBuffer="";
		if (getCookie("badpassword")=="true")
		{
			top.location.href="badpassword.html";
			return;
		}
		if (document.form1.userid.value == "")
		{
			alert("You cannot leave userid empty");
			document.form1.userid.focus();
			return;
		}
		if (document.form1.password.value == "")
		{
			alert("You cannot leave password empty");
			document.form1.password.focus();
			return;
		}
		if (document.form1.campaign.value == "")
		{
			alert("You cannot leave campaign empty");
			document.form1.campaign.focus();
			return;
		}
			
		top.szUserID=document.form1.userid.value;
		if (top.szUserID=="UserID")
		{
			alert("You must use the UserID assigned to you by your Supervisor. See 'How to Order Time' in Help.");
			document.form1.userid.select();
			return;
		}
		top.szCampaign=document.forms.form1.campaign.value;
		if (top.szCampaign=="Campaign Name")
		{
			alert("You must use the Campaign Name assigned to you by your Supervisor.");
			document.form1.campaign.select();
			return;
		}
		top.str="log in!";
		setMessage();
		top.szPhone=getCookie("phone");
		top.szExtension=getCookie("ext");
			
		if ((top.szPhone==null) || (top.szPhone.substr(0,3)=="XXX"))
		{
			top.szPhone=window.prompt("What phone number should the system dial you back at?"," ");
			//alert(top.szPhone)
			if ((top.szPhone!=null) && (isphonecharacters(top.szPhone)) && (top.szPhone.length < 14) && (top.szPhone.length > 7))
			{
				setCookie("phone", top.szPhone, 30);
				top.propertiesFrame.form1.phone.value=top.szPhone;
				top.szExtension=window.prompt("What extension should the system dial you at? LEAVE BLANK AND CLICK OK IF NO EXTENSION."," ");
				if (top.szExtension=="")
				{	
					alert("changed to space")
					top.szExtension=" "
				}
				if ((isextensioncharacters(top.szExtension)) && (top.szExtension.length < 10))
				{
					setCookie("ext", top.szExtension, 30);
					top.propertiesFrame.form1.ext.value=top.szExtension;				
				}
				else
				{
					alert("You must enter a valid extension number in the Properties window. \n Can only contain numbers \"*\" \",\" \".\" and \"#\".");
					parent.document.getElementById("bodyframe").cols="0%,0%,0%,0%,0%,100%,0%,0%,0%,0%" ;
					top.propertiesFrame.form1.ext.select();
					return;
				}
			}
			else	
			{
				alert("You must enter a valid phone number in the Properties pop-up. \n Can only contain numbers, ( ) and -.");
				parent.document.getElementById("bodyframe").cols="0%,0%,0%,0%,0%,100%,0%,0%,0%,0%" ;
				top.propertiesFrame.form1.phone.select();
				return;
			}
		}
		if (top.szPhone.substr(0,3)=="800")
		{
			alert("You must enter a valid phone number in the Properties pop-up. Toll-free numbers are not valid.");
			return;
		}
		if (top.szPhone.substr(0,3)=="900")
		{
			alert("You must enter a valid phone number in the Properties pop-up. 900 numbers are not valid.");
			return;
		}
		if (top.szCampaign=="Campaign Name")
		{
			document.form1.password.value = ""
			alert("You must enter a campaign assigned by your Supervisor.");
			return;
		}
		if (top.iLogin==1)	//already logged in
		{
			document.form1.password.value="";	//clear the password
			alert("you are already logged in");
			return;
		}
		if ((document.form1.password.length==0)||(document.form1.password.length>=9))
		{
			document.form1.password="";	//clear the password
			alert("invalid password");
			return;
		}
		top.iLoginTimer=setTimeout('login_timer()',15000); //wait for 15 seconds to login
	
		parent.leftFrame.distributor.HostName=top.szDistributor;
		parent.leftFrame.distributor.AddressFamily=2;
		parent.leftFrame.distributor.RemotePort=15707;
		parent.leftFrame.distributor.Trace=1;
		parent.leftFrame.distributor.TraceFlags=4;
		parent.leftFrame.distributor.TraceFile="socket_trace_dist.txt";
		parent.leftFrame.distributor.Open();
		parent.leftFrame.distributor.Connect();
	
		top.szUserID=document.forms.form1.userid.value;
		if (top.szUserID=="UserID")     //don't save the defaults
			return;
		setCookie("userid", top.szUserID, 30);
		top.szCampaign=document.form1.campaign.value;
		setCookie("campaign", top.szCampaign, 30);
		top.szCampaign=document.form1.campaign.value;
		top.szPassword=document.form1.password.value;
		setCookie("password", top.szPassword, 30);
		top.schedule=0;
		top.duration=10;	//seconds for progress
		parent.mainFrame.Demo();
}



function logoff_func() {
		StopTheClock();	
	//	if (top.iLogin==0)	//already logged off
	//	{
	//		alert("already logged off");
	//		return;
	//	}
		//back to screenpop screen
		//clear all of the arrows
		top.iLogon=4;  //just temparary

		top.leftFrame.form1.searchingImage.src = '/images/x.gif';
		top.leftFrame.form1.pausedImage.src = '/images/x.gif';
		top.leftFrame.form1.dataconnImage.src = '/images/x.gif';
		top.leftFrame.form1.calleeconnImage.src = '/images/x.gif';
		top.leftFrame.form1.voiceconnImage.src = '/images/x.gif';
		top.leftFrame.form1.wrapImage.src = '/images/x.gif';
		top.leftFrame.form1.recordImage.src = '/images/x.gif';
		
	
		parent.document.getElementById("bodyframe").cols="100%,0%,0%,0%,0%,0%,0%,0%,0%,0%" ;
		top.iScriptToggle=0;
		write_to_server("76","76","76",top.szPhone,"Campaign");
		top.szUserID=document.forms.form1.userid.value;
		//alert("about to send 09");
		write_to_server("00","09","00",top.szPhone,"Campaign");
//		szNameString=top.szCampaign.substr(0,15)+blank.substr(0,15-top.szCampaign.length)+szPassEn+blank.substr(0,10-szPassEn.length)+top.szUserID+blank.substr(0,12-top.szUserID.length)+blank.substr(0,15)+blank.substr(0,15);
//		write_to_server("00","09","00",szNameString,"Campaign");
		write_to_server("98","98","98",top.szPhone,"Campaign");
		//not used
		if (top.iLogin==99)
		{
			write_to_server("98","98","98",top.szPhone,"Campaign");
		
			//clear all of the arrows
			buffer="DCM"+top.szCampaign+blank.substr(0,20-top.szCampaign.length)+top.szUserID+blank.substr(0,20-top.szUserID.length);
			gateway.SendLen = buffer.length; 
			gateway.SendData = buffer; 
			top.iLogon=0;
			alert("You are logged off. Hangup your phone.");
			top.location.reload(0);
			return;
		}
	
		buffer="DC*"+top.szCampaign+blank.substr(0,20-top.szCampaign.length)+top.szUserID+blank.substr(0,20-top.szUserID.length);
		top.leftFrame.gateway.SendLen = buffer.length; 
		top.leftFrame.gateway.close;
		try
		{
			top.leftFrame.gateway.SendData = buffer; 
		}
		catch(e)
		{
			alertmessage="system's not ready. please wait."
			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
			//alert("system's not ready. please wait.");
		}

		if ((top.iLogon==3)||(top.iLogon==2))
			alert("You are logged off. Hangup up your phone");
		else
			alert("You are logged off.")
		top.iLogon=0;  //just temparary
			
		top.location.reload(0);

		document.forms.form1.userid.value=getCookie("userid");
		document.form1.campaign.value=getCookie("campaign");
	
		reset_screenpop();
		top.scriptFrame.document.form1.answers.options.length=1;
		top.scriptFrame.document.form1.textfield.value="";
}




function online_func() 
{
		var p1;
		var p2;
		var p3;
	
		if (top.iLogin==0)
		{
			alert("you must login first");
			return;
		}
		if ((top.iLogin==2)||(top.iLogin==3))
		{
			alertmessage="you are already online"
			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
			//alert("you are already online");
			return;
		}
		top.leftFrame.form1.pausedImage.src = '/images/x.gif';
		//top.iLogin=2
		//only change state when we get a 90	
//		top.topFrame.document.getElementById("connecting").innerText="connecting...";
		top.szCampaign=getCookie("campaign");
		top.szPhone=getCookie("phone");
		top.szUserID=getCookie("userid");
		top.szExtension=getCookie("ext");
		if (top.szExtension.length < 1)
			top.szExtension=" "
		alertmessage="You will receive a call right away. \n On the phone you hear \"Dialer Online\". \n You must press \"11\" to begin searching for calls."
	//	showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
		//alert("You will receive a call right away. \n On the phone you hear \"Dialer Online\". \n You must press \"11\" to begin searching for calls.")
		strlen=top.szPhone.length;
		p1=blank.substr(0,15)+"000"+top.szPhone+blank.substr(0,15-strlen);
		strlen=top.szUserID.length
		p2=blank.substr(0,10)+top.szUserID+blank.substr(0,12-strlen);
		strlen=top.szExtension.length
		p3=blank.substr(0,10)+top.szExtension+blank.substr(0, 10-strlen);
		buffer="99"+top.szCampaign+blank.substr(0,20-top.szCampaign.length)+p1+p2+p3;
		top.leftFrame.gateway.SendLen = buffer.length;
		try
		{
			top.leftFrame.gateway.SendData = buffer; 
		}
		catch(e)
		{
			alertmessage="system's not ready. please wait."
			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
			//alert("system's not ready. please wait.");
		}
		//alert("got a 99. setting iLogin=1");		
		//top.iLogin=1;
		//iState=1;
		// automatically get dataconnection
}


function pause_func() {
		if (top.iLogin==0)
		{
			alert("You must be logged in inorder to Pause.");
			return;
		}
//		if (top.iLogin==1)  //already paused
	//	{
		//	alert("You are already Paused.");
			//return;
		//}
		if (top.iLogin==3)
		{
			alertmessage="You must not be TALKING in in order to Pause. Press Disconnect Callee first."
			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
			//alert("You must not be TALKING in in order to Pause. Press Disconnect Callee first.");
			return;
		}
		alertmessage="You can hang up your phoneset."
		showModelessDialog("alertmessage.asp?agent_id=" + top.szUserID + "&campaign=" + top.szCampaign + "&sup_user_id=" + top.szSupUserID + "&event=pause", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
	
		//must be iLogin==2
		buffer="98"+blank.substr(0,15)+top.szCampaign+blank.substr(0,20-top.szCampaign.length)+top.szUserID+blank.substr(0,20-top.szUserID.length);
		top.leftFrame.gateway.SendLen = buffer.length; 
		top.leftFrame.gateway.SendData = buffer; 
		//alert("You can hang up your phoneset.");
		write_to_server("98","98", "00", "", "Campaign");
		top.iLogin=1;   //on pause
		top.iBlinkNow=0;		//turn off the blink
	
		top.leftFrame.form1.searchingImage.src = '/images/x.gif';
		top.leftFrame.form1.pausedImage.src = '/images/check.gif';
		top.leftFrame.form1.dataconnImage.src = '/images/check.gif';
		top.leftFrame.form1.calleeconnImage.src = '/images/x.gif';
		top.leftFrame.form1.voiceconnImage.src = '/images/x.gif';
		top.leftFrame.form1.wrapImage.src = '/images/x.gif';
		top.leftFrame.form1.recordImage.src = '/images/x.gif';
		

}

function confer_func() {
		if (top.iLogin==0)
		{
			alert("You must be logged in inorder to Confer.");
			return;
		}

//		if (top.iLogin==3)
//		{
//			alertmessage="You must not be TALKING in in order to Confer. Press Disconnect Callee first."
//			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
			//alert("You must not be TALKING in in order to Pause. Press Disconnect Callee first.");
//			return;
//		}

//		alertmessage="ConnectingYou can hang up your phoneset."
//		showModelessDialog("alertmessage.asp?agent_id=" + top.szUserID + "&campaign=" + top.szCampaign + "&sup_user_id=" + top.szSupUserID + "&event=pause", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
	
		//must be iLogin==2
		buffer="CC"+blank.substr(0,15)+top.szCampaign+blank.substr(0,20-top.szCampaign.length)+top.szUserID+blank.substr(0,20-top.szUserID.length);
		top.leftFrame.gateway.SendLen = buffer.length; 
		top.leftFrame.gateway.SendData = buffer; 
		//alert("You can hang up your phoneset.");
//		write_to_server("98","98", "00", "", "Campaign");
		top.iLogin=1;   //on pause
		top.iBlinkNow=0;		//turn off the blink
	
//		top.leftFrame.form1.searchingImage.src = '/images/x.gif';
//		top.leftFrame.form1.pausedImage.src = '/images/check.gif';
//		top.leftFrame.form1.dataconnImage.src = '/images/check.gif';
//		top.leftFrame.form1.calleeconnImage.src = '/images/x.gif';
	//	top.leftFrame.form1.voiceconnImage.src = '/images/x.gif';
//		top.leftFrame.form1.wrapImage.src = '/images/x.gif';
//		top.leftFrame.form1.recordImage.src = '/images/x.gif';

}
function release_func() {
		if (top.iLogin==0)
		{
			alert("You must be logged in inorder to Confer.");
			return;
		}

//		if (top.iLogin==3)
//		{
//			alertmessage="You must not be TALKING in in order to Confer. Press Disconnect Callee first."
//			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
			//alert("You must not be TALKING in in order to Pause. Press Disconnect Callee first.");
//			return;
//		}

//		alertmessage="ConnectingYou can hang up your phoneset."
//		showModelessDialog("alertmessage.asp?agent_id=" + top.szUserID + "&campaign=" + top.szCampaign + "&sup_user_id=" + top.szSupUserID + "&event=pause", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
	
		//must be iLogin==2
		buffer="CR"+blank.substr(0,15)+top.szCampaign+blank.substr(0,20-top.szCampaign.length)+top.szUserID+blank.substr(0,20-top.szUserID.length);
		top.leftFrame.gateway.SendLen = buffer.length; 
		top.leftFrame.gateway.SendData = buffer; 
		//alert("You can hang up your phoneset.");
//		write_to_server("98","98", "00", "", "Campaign");
		top.iLogin=1;   //on pause
		top.iBlinkNow=0;		//turn off the blink
	
//		top.leftFrame.form1.searchingImage.src = '/images/x.gif';
//		top.leftFrame.form1.pausedImage.src = '/images/check.gif';
//		top.leftFrame.form1.dataconnImage.src = '/images/check.gif';
//		top.leftFrame.form1.calleeconnImage.src = '/images/x.gif';
	//	top.leftFrame.form1.voiceconnImage.src = '/images/x.gif';
//		top.leftFrame.form1.wrapImage.src = '/images/x.gif';
//		top.leftFrame.form1.recordImage.src = '/images/x.gif';

}

function flashdr_func() {
		if (top.iLogin==0)
		{
			alert("You must be logged in inorder to Confer.");
			return;
		}

//		if (top.iLogin==3)
//		{
//			alertmessage="You must not be TALKING in in order to Confer. Press Disconnect Callee first."
//			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
			//alert("You must not be TALKING in in order to Pause. Press Disconnect Callee first.");
//			return;
//		}

//		alertmessage="ConnectingYou can hang up your phoneset."
//		showModelessDialog("alertmessage.asp?agent_id=" + top.szUserID + "&campaign=" + top.szCampaign + "&sup_user_id=" + top.szSupUserID + "&event=pause", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
	
		//must be iLogin==2
		buffer="CO"+blank.substr(0,15)+top.szCampaign+blank.substr(0,20-top.szCampaign.length)+top.szUserID+blank.substr(0,20-top.szUserID.length);
		top.leftFrame.gateway.SendLen = buffer.length; 
		top.leftFrame.gateway.SendData = buffer; 
		//alert("You can hang up your phoneset.");
//		write_to_server("98","98", "00", "", "Campaign");
		top.iLogin=1;   //on pause
		top.iBlinkNow=0;		//turn off the blink
	
//		top.leftFrame.form1.searchingImage.src = '/images/x.gif';
//		top.leftFrame.form1.pausedImage.src = '/images/check.gif';
//		top.leftFrame.form1.dataconnImage.src = '/images/check.gif';
//		top.leftFrame.form1.calleeconnImage.src = '/images/x.gif';
	//	top.leftFrame.form1.voiceconnImage.src = '/images/x.gif';
//		top.leftFrame.form1.wrapImage.src = '/images/x.gif';
//		top.leftFrame.form1.recordImage.src = '/images/x.gif';

}

function flashcallee_func() {
		if (top.iLogin==0)
		{
			alert("You must be logged in inorder to Confer.");
			return;
		}

//		if (top.iLogin==3)
//		{
//			alertmessage="You must not be TALKING in in order to Confer. Press Disconnect Callee first."
//			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
			//alert("You must not be TALKING in in order to Pause. Press Disconnect Callee first.");
//			return;
//		}

//		alertmessage="ConnectingYou can hang up your phoneset."
//		showModelessDialog("alertmessage.asp?agent_id=" + top.szUserID + "&campaign=" + top.szCampaign + "&sup_user_id=" + top.szSupUserID + "&event=pause", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
	
		//must be iLogin==2
		buffer="C2"+blank.substr(0,15)+top.szCampaign+blank.substr(0,20-top.szCampaign.length)+top.szUserID+blank.substr(0,20-top.szUserID.length);
		top.leftFrame.gateway.SendLen = buffer.length; 
		top.leftFrame.gateway.SendData = buffer; 
		//alert("You can hang up your phoneset.");
//		write_to_server("98","98", "00", "", "Campaign");
		top.iLogin=1;   //on pause
		top.iBlinkNow=0;		//turn off the blink
	
//		top.leftFrame.form1.searchingImage.src = '/images/x.gif';
//		top.leftFrame.form1.pausedImage.src = '/images/check.gif';
//		top.leftFrame.form1.dataconnImage.src = '/images/check.gif';
//		top.leftFrame.form1.calleeconnImage.src = '/images/x.gif';
	//	top.leftFrame.form1.voiceconnImage.src = '/images/x.gif';
//		top.leftFrame.form1.wrapImage.src = '/images/x.gif';
//		top.leftFrame.form1.recordImage.src = '/images/x.gif';

}




function disconnect_func() 
{
		if (top.iLogin==4)  //already disconnected
			{
			return;
			}
		if (top.iLogin==0)	//not logged on
			{
			alert("you must login first");
			return;
			}
		if (top.iLogin==1)    //already on not speaking
			{
			alertmessage="This button disconnects callees. To Disconnect your own phone press Pause or Logoff."
			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
			//alert("This button disconnects callees. To Disconnect your own phone press Pause or Logoff.");
			return;
			}
		if (top.iLogin==2)    //already waiting
			{
			alertmessage="There is no callee connected to Disconnect from."
			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
			//alert("There is no callee connected to Disconnect from.");
			return;
			}
			
		top.topFrame.document.getElementById("connecting").innerText=" ";
		//back on waiting

		//agent_confirmed();  //this will stop blink timer

		//top.iBlinkNow=1;
		//top.iBlink=setTimeout('blink()',500);   //set to 1 second
		top.leftFrame.form1.calleeconnImage.src = '/images/x.gif';
		top.leftFrame.form1.searchingImage.src = '/images/check.gif';
		top.leftFrame.form1.pausedImage.src = '/images/x.gif';
		top.leftFrame.form1.dataconnImage.src = '/images/check.gif';
		top.leftFrame.form1.voiceconnImage.src = '/images/check.gif';
		top.leftFrame.form1.wrapImage.src = '/images/x.gif';
		top.leftFrame.form1.recordImage.src = '/images/x.gif';
		
		

		//buffer="DCM"+top.szCampaign+blank.substr(0,20-top.szCampaign.length)+top.UserID+blank.substr(0,20-top.UserID.length);
		//top.leftFrame.gateway.SendLen = buffer.length; 
		//top.leftFrame.gateway.SendData = buffer; 
		//buffer="98"+blank.substr(0,15)+top.szCampaign+blank.substr(0,20-top.szCampaign.length)+top.UserID+blank.substr(0,20-top.UserID.length);
		//top.leftFrame.gateway.SendLen = buffer.length; 
		//top.leftFrame.gateway.SendData = buffer; 
		//write_to_server("98","98","00"," ","Campaign");

		write_to_server("14","14", "14", "", "Campaign");  //done talking
		buffer="DC "+top.szCampaign+blank.substr(0,20-top.szCampaign.length)+top.UserID+blank.substr(0,20-top.UserID.length);
		top.leftFrame.gateway.SendLen = buffer.length; 
		top.leftFrame.gateway.SendData = buffer; 
		write_to_server("03","03", "03", " ", "Campaign");  //I've disconnected

		//iState=0;
		top.iLogin=2;  //done speaking and back to waiting
}
//rnb 6/11/03
//this function pauses the agent
function wrapup_func() 
{
		if (top.iLogin==0)	//not logged on
			{
			alert("you must login first");
			return;
			}
		if (top.iLogin==1)    //already on not speaking
			{
			alertmessage="There is no callee connected to Wrap"
			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
			//alert("This button disconnects callees. To Disconnect your own phone press Pause or Logoff.");
			return;
			}
		if (top.iLogin==2)    //already waiting
			{
			alertmessage="There is no callee connected to Wrap."
			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
			//alert("There is no callee connected to Disconnect from.");
			return;
			}
			
//		if (top.iLogin==3)    //logging off
//			{
////			alertmessage="There is no callee connected to Wrap."
//			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
			//alert("There is no callee connected to Disconnect from.");
//			return;
//			}
			
			
		top.topFrame.document.getElementById("connecting").innerText=" ";
		//back on waiting

		//agent_confirmed();  //this will stop blink timer

		//top.iBlinkNow=1;
		//top.iBlink=setTimeout('blink()',500);   //set to 1 second
		top.leftFrame.form1.searchingImage.src = '/images/check.gif';
		top.leftFrame.form1.pausedImage.src = '/images/x.gif';
		top.leftFrame.form1.dataconnImage.src = '/images/check.gif';
		top.leftFrame.form1.calleeconnImage.src = '/images/x.gif';
		top.leftFrame.form1.voiceconnImage.src = '/images/check.gif';
		top.leftFrame.form1.wrapImage.src = '/images/check.gif';
		top.leftFrame.form1.recordImage.src = '/images/x.gif';
		



//		write_to_server("14","14", "14", "", "Campaign");  //done talking
		buffer="DCW"+top.szCampaign+blank.substr(0,20-top.szCampaign.length)+top.UserID+blank.substr(0,20-top.UserID.length);
		top.leftFrame.gateway.SendLen = buffer.length; 
		top.leftFrame.gateway.SendData = buffer; 
//		write_to_server("03","03", "03", " ", "Campaign");  //I've disconnected

//rnb		top.iLogin=2;  //done speaking and back to waiting
}







function help_func() 
{
		window.open("help_frameset.html","help","");
}


function wrap_load_func() 
{
		if (!(getCookie("localNotes")=="null"))
			document.forms.form1.recentnotes.value=getCookie("localNotes");
		else
			top.szNotes2=" ";

}



function recent_notes_func() 
{
		if (!(getCookie("localNotes")=="null"))
			document.forms.form1.recentnotes.value=getCookie("localNotes");
		parent.document.getElementById("bodyframe").cols="0%,0%,0%,0%,0%,0%,100%,0%,0%,0%" ;

}



		//this function toggles the script page
function script_preload()
{
		//alert("in script preload");

		if (top.iScriptToggle==0)   //screenpop is showing
		{
			screenpop_showing();
			top.iScriptToggle=1;
		}
		else
		{				//script is showing
			parent.document.getElementById("bodyframe").rows="48%,0%,52%,0%,0%,0%,0%,0%,0%,0%" ;
//			parent.document.getElementById("bodyframe").cols="100%,0%,0%,0%,0%,0%,0%,0%,0%,0%" ;
			top.iScriptToggle=0;
		}
}



function screenpop_showing()
{
		
		if (top.iScriptType==2)		//index cards or telem script
		{
			//	initialize_tabs();  //do this when downloading script
			parent.document.getElementById("bodyframe").rows="0%,0%,100%,0%,0%,0%,0%,0%,0%,0%" ;
//			parent.document.getElementById("bodyframe").cols="1%,0%,99%,0%,0%,0%,0%,0%,0%,0%" ;
			
//			parent.document.getElementById("bodyframe").cols="50%,0%,50%,0%,0%,0%,0%,0%,0%,0%" ;
			
		}
		else
		{
			
			load_question(0);   //initialize script
			load_answers(0);
			iCurrentQuestion=0;
			parent.document.getElementById("bodyframe").cols="0%,100%,0%,0%,0%,0%,0%,0%,0%,0%" ;
		}
}




	//this function toggles the stats page
function stats_preload()
{
		if (top.iStats==0)   //stats is showing
		{
	//		parent.document.getElementById("bodyframe").cols="0%,0%,0%,100%,0%,0%,0%,0%,0%,0%" ;
			parent.document.getElementById("bodyframe").rows="48%,0%,52%,0%,0%,0%,0%,0%,0%,0%" ;

			top.iStats=1;
		}
		else
		{				//pop is showing
//			parent.document.getElementById("bodyframe").cols="100%,0%,0%,0%,0%,0%,0%,0%,0%,0%" ;
//				parent.document.getElementById("bodyframe").cols="40%,0%,60%,0%,0%,0%,0%,0%,0%,0%" ;
			parent.document.getElementById("bodyframe").rows="0%,0%,0%,100%,0%,0%,0%,0%,0%,0%" ;

			
			top.iStats=0;
		}
}



function script_ok_func()
{

}

function script_load_func()
{
		//alert("script load");
		//szScriptBuffer=getCookie("script");
		//alert(szScriptBuffer);
		//alert(szScriptBuffer.indexOf("[Answers]",1));
}




function changeValue(field,text)
{
		field.innerHTML=text;
}



function set_fieldnames_func()
{
		changeValue(top.mainFrame.document.getElementById("f1"),aszFields[1].substr(0,aszFields[1].indexOf("\"")));
		//setCookie("f1l",aszFields[1].substr(0,20),30); //for appointment
		changeValue(top.mainFrame.document.getElementById("f2"),aszFields[2].substr(0,aszFields[2].indexOf("\"")));
		//setCookie("f2l",aszFields[2].substr(0,20),30); //for appointment
		changeValue(top.mainFrame.document.getElementById("f3"),aszFields[3].substr(0,aszFields[3].indexOf("\"")));
		//setCookie("f3l",aszFields[3].substr(0,20),30); //for appointment
		changeValue(top.mainFrame.document.getElementById("f4"),aszFields[4].substr(0,aszFields[4].indexOf("\"")));
		//setCookie("f4l",aszFields[4].substr(0,20),30); //for appointment
		changeValue(top.mainFrame.document.getElementById("f5"),aszFields[5].substr(0,aszFields[5].indexOf("\"")));
		//setCookie("f5l",aszFields[5].substr(0,20),30); //for appointment
		changeValue(top.mainFrame.document.getElementById("f6"),aszFields[6].substr(0,aszFields[6].indexOf("\"")));
		//setCookie("f6l",aszFields[6].substr(0,20),30); //for appointment
		changeValue(top.mainFrame.document.getElementById("f7"),aszFields[7].substr(0,aszFields[7].indexOf("\"")));
		//setCookie("f7l",aszFields[7].substr(0,20),30); //for appointment
		changeValue(top.mainFrame.document.getElementById("f8"),aszFields[8].substr(0,aszFields[8].indexOf("\"")));
		//setCookie("f8l",aszFields[8].substr(0,20),30); //for appointment
		changeValue(top.mainFrame.document.getElementById("f9"),aszFields[9].substr(0,aszFields[9].indexOf("\"")));
		//setCookie("f9l",aszFields[9].substr(0,20),30); //for appointment
		//setCookie("f9v",aszFields[9].substr(0,aszFields[9].indexOf("\"")),30);
		//changeValue(top.mainFrame.document.getElementById("f10"),aszFields[10].substr(0,aszFields[10].indexOf("\"")));
		if (aszFieldEdit[1]!=-1)
		{
			top.mainFrame.form2.textfield.readOnly=false;
			top.mainFrame.document.getElementById("f1").innerHTML="<u>"+top.mainFrame.document.getElementById("f1").innerHTML+"</u>";
		}
		if (aszFieldEdit[2]!=-1)
		{
			top.mainFrame.document.form2.textfield2.readOnly=false;
			top.mainFrame.document.getElementById("f2").innerHTML="<u>"+top.mainFrame.document.getElementById("f2").innerHTML+"</u>";
		}
		if (aszFieldEdit[3]!=-1)
		{
			top.mainFrame.document.form2.textfield3.readOnly=false;
			top.mainFrame.document.getElementById("f3").innerHTML="<u>"+top.mainFrame.document.getElementById("f3").innerHTML+"</u>";
		}
		if (aszFieldEdit[4]!=-1)
		{
			top.mainFrame.document.form2.textfield4.readOnly=false;
			top.mainFrame.document.getElementById("f4").innerHTML="<u>"+top.mainFrame.document.getElementById("f4").innerHTML+"</u>";
		}
		if (aszFieldEdit[5]!=-1)
		{
			top.mainFrame.document.form2.textfield5.readOnly=false;
			top.mainFrame.document.getElementById("f5").innerHTML="<u>"+top.mainFrame.document.getElementById("f5").innerHTML+"</u>";
		}
		if (aszFieldEdit[6]!=-1)
		{
			top.mainFrame.document.form2.textfield6.readOnly=false;
			top.mainFrame.document.getElementById("f6").innerHTML="<u>"+top.mainFrame.document.getElementById("f6").innerHTML+"</u>";
		}
		if (aszFieldEdit[7]!=-1)
		{
			top.mainFrame.document.form2.textfield7.readOnly=false;
			top.mainFrame.document.getElementById("f7").innerHTML="<u>"+top.mainFrame.document.getElementById("f7").innerHTML+"</u>";
		}
		if (aszFieldEdit[8]!=-1)
		{
			top.mainFrame.document.form2.textfield8.readOnly=false;
			top.mainFrame.document.getElementById("f8").innerHTML="<u>"+top.mainFrame.document.getElementById("f8").innerHTML+"</u>";
		}
		if (aszFieldEdit[9]!=-1)
		{
			top.mainFrame.document.form2.textfield9.readOnly=false;
			top.mainFrame.document.getElementById("f9").innerHTML="<u>"+top.mainFrame.document.getElementById("f9").innerHTML+"</u>";
		}
}

function write_buffer_distributor( abuffer)
{
		//alert(abuffer);
		//alert("here");
		distributor.Write(abuffer,10); 
		}

		var win = null;
		function NewWindow(mypage,myname,w,h,scroll){
		LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
		TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
		settings =
		'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
		return window.open(mypage,myname,settings);
}


function cancel_func()
{
		window.close(winNoCamp);
}



function populate()
{
		//populate the list
		for (i=0;i<20;i++)
		{
			aszRunningCampaigns[i]=buffer.substring(i*20+4,14);  //get all of the running camp names
			//alert(buffer); 
			if (aszRunningCampaigns[0]=="              ")
				{
				winNoCamp.document.form1.select.options[0]="no campaigns";
				break;
				}
			if (aszRunningCampaigns[i]=="              ")
				break;
			winNoCamp.document.form1.select.options[i]=buffer.substring(i*20+4,14);
		}
}

function AddToOptionList(OptionList,OptionValue, OptionText)
{
		OptionList[OptionList.length]=new Option(OptionText,OptionValue);
		//OptionList[OptionList.length]=new Option(OptionText,OptionValue,,);
		//OptionList[OptionList.length]=new Option(OptionText,OptionValue);

		//top.mainFrame.document.form2.othercodes.options[0].text="test"
}



function  ClearOptions(OptionList)
{
		//for (x=OptionList.length; x>=0;x--)
		//	{
		//	OptionList[x]=null;
		//	}
}


function ResetOptionList(OptionList)
{
		//OptionList.options[0]selected;
}






	//call was finished so write it out
function completed()
{
//		if ((top.iLogin==0)||(top.iLogin==1)||(top.iLogin==2))    //if not speaking can't complete
//		{
//			parent.document.getElementById("bodyframe").rows="48%,0%,52%,0%,0%,0%,0%,0%,0%,0%" ;
//			top.iScriptToggle=0;
//			alertmessage="Cannot complete because not speaking"
//			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
//			alert("cannot complete because not speaking");
//			return;
//		}

		//set back to screen pop
//		parent.document.getElementById("bodyframe").cols="100%,0%,0%,0%,0%,0%,0%,0%,0%,0%" ;
//		parent.document.getElementById("bodyframe").rows="50%,0%,50%,0%,0%,0%,0%,0%,0%,0%" ; 
		parent.document.getElementById("bodyframe").rows="48%,0%,52%,0%,0%,0%,0%,0%,0%,0%" ;
		if (top.iScriptType==1    )		
			write_script_answers();
		else
			wrap_up_call();
		top.iLogin=2;		//go back on waiting
		//	alert("setting iLogin=2");
		//	alert("got a completed event so write");
}


function load_question(iQues)
{
		var szZeros="0000000";
		var szQ;
		var szTotalQuestion="";
		var i,j;
		var szQuester;

//		HERE
		szQ=iQues.toString();
		szQuester=szZeros.substr(0,3-szQ.length)+szQ;
//		alert(top.aszQuestions.length);
//		alert("in load_question for ques="+szQuester);
//		alert("top.iScriptLoaded="+top.iScriptLoaded);

		if (top.iScriptLoaded==0)   //see if we loaded the script
			return;
		for (i=0;i<top.aszQuestions.length;i++)
		{
			if (top.aszQuestions[i].substr(0,3)==szQuester)
			{
				//got it
				iStart=top.aszQuestions[i].indexOf("\"");
				iEnd=top.aszQuestions[i].lastIndexOf("\"");

				szTotalQuestion+=top.aszQuestions[i].substring(iStart+1,iEnd);
				i++;
				while(top.aszQuestions[i].substr(0,3)==szQuester)
				{
					iStart=top.aszQuestions[i].indexOf("\"");
					iEnd=top.aszQuestions[i].lastIndexOf("\"");
					szTotalQuestion+=top.aszQuestions[i].substring(iStart+1,iEnd);
					i++;
				}
				//now check for ...
				iRc=szTotalQuestion.indexOf("...");
				if (iRc!=-1)
				{
					for (j=1;j<top.aszText.length;j++)
					{
							//	alert("szQuester="+szQuester+"index="+top.aszText[j]);
							if (top.aszText[j].substr(0,3)==szQuester)   //found the text
							{
								//	alert("got one here->"+top.aszText[j]);
								szNewString=top.aszText[j];
								iStart=szNewString.indexOf("\"");
								iEnd=szNewString.indexOf("\"",iStart+1);
								szTotalQuestion+=szNewString.substring(iStart+1,iEnd);
								//alert("iStart="+iStart+",iEnd="+iEnd+",total="+szNewString);
							}
					}
					//alert(szTotalQuestion);
				}
				//check for N/A value and strip it
				iRc=szTotalQuestion.indexOf("N/A->");	
				if (iRc!=-1)  //means we found one
				{
					szVal=szTotalQuestion.substr(iRc+5,3);
					top.iNA_val=parseInt(szVal,10)
					szTotalQuestion=szTotalQuestion.substring(0,iRc)+szTotalQuestion.substr(iRc+10);
				}
				else	
				{
					top.iNA_val=-1;			//no NA so goto done
				}
				top.scriptFrame.document.form1.textfield.value=szTotalQuestion;
				return;
			}
			
		}
}

function load_answers(iQues)
{
		var szZeros="0000000";
		var szQ;
		var szAns;

		var aszAnsu;
		if (top.iScriptLoaded==0)   //see if we loaded the script
			return;
		//get the relation
		szQ=iQues.toString()
		top.szQuestion=szZeros.substr(0,3-szQ.length)+szQ;

		//top.scriptFrame.document.form1.answers.options.length=0;  //clear the pulldown
		for (i=0;i<top.aszRelations.length;i++)
		{
			if (top.aszRelations[i].substr(0,3)==top.szQuestion)
			{	
				//got the relation
				//split the questions
				iStart=top.aszRelations[i].indexOf(",");
				iEnd=top.aszRelations[i].lastIndexOf("\"");
				aszAnsu=top.aszRelations[i].substring(iStart,iEnd);
				top.aszAns=aszAnsu.split(",");	//each index has one answer in it
				//now assign it to the answers

				top.scriptFrame.document.form1.answers.options.length=top.aszAns.length-1;
				//	alert("aszAns.length="+top.aszAns.length);
				if (top.aszAns.length==1)
				{
					alertmessage=top.aszAns
					showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
					//alert(top.aszAns);
				}
				for (j=0;j<top.aszAns.length-1;j++)
				{
					szAnsIndex=top.aszAns[j+1].substr(0,3);   
					//this is the start of the question
					iStart=top.szAnswerstring.indexOf("\""+szAnsIndex);			//build the search criteria of the answer
					iEnd=top.szAnswerstring.indexOf("\"",iStart+3);			//build the search criteria of the answer

					top.scriptFrame.document.form1.answers.options[j].text=top.szAnswerstring.substring(iStart+1,iEnd);
					top.scriptFrame.document.form1.answers.options[j].value=j;
				}
			}
		}
}


function next_func()
{
		var iIndex;  //selected answer
		var szChosen;  //chosen answer
		var szNext;
		var iNextPoint;
		if (top.iScriptLoaded==0)    //if not loaded
		{
			parent.document.getElementById("bodyframe").cols="100%,0%,0%,0%,0%,0%,0%,0%,0%,0%" ;
			return;
		}
		iIndex=top.scriptFrame.document.form1.answers.options.selectedIndex;
		szChosen=top.scriptFrame.document.form1.answers.options[iIndex].text.substr(0,3);
		iNextPoint=top.scriptFrame.document.form1.answers.options[iIndex].text.lastIndexOf("->");
		szNext=top.scriptFrame.document.form1.answers.options[iIndex].text.substr(iNextPoint+3);

		top.szScriptResults+="Q"+top.szQuestion+":A"+szChosen+"->"+szNext+",";
		alertmessage=top.szScriptResults
		showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
		//alert(top.szScriptResults);
		if (szNext=="done")
		{
			//	alert(top.iScriptLoaded);
			if (top.iScriptLoaded==0)    //if not loaded
			{
				parent.document.getElementById("bodyframe").cols="100%,0%,0%,0%,0%,0%,0%,0%,0%,0%" ;
				return;
			}
			iRc=confirm("You have completed the script. Do you want to COMPLETE/disconnect the call too?");
			if (iRc==1)
			{
				completed();
				//	alert("got a done"+top.szScriptResults);
				return;
			}
		}
		load_question(parseInt(szNext,10));  //must use radix!
		load_answers(parseInt(szNext,10));
}



function na_func()
{
		var iIndex;  //selected answer
		var szChosen;  //chosen answer
		var szNext;
		var iNextPoint;

		if (top.iScriptLoaded==0)    //if not loaded
		{
			parent.document.getElementById("bodyframe").cols="100%,0%,0%,0%,0%,0%,0%,0%,0%,0%" ;
			return;
		}
		szChosen="N/A";
		if (top.iNA_val==-1)
		{
			szNext="done";
		}
		else
		{
			szNext=top.iNA_val;   //value of not applic default	
		}
		top.szScriptResults+="Q"+top.szQuestion+":A"+szChosen+"->"+szNext+",";
		if (szNext=="done")
		{
			iRc=confirm("You've chosen n/a but there is no default next question. The script will end. Do you want to COMPLETE/disconnect the call too?");
			if (iRc==1)
			{
				completed();
				//	alert("got a done"+top.szScriptResults);
				return;
			}
		}
		load_question(parseInt(szNext,10));  //must use radix!
		load_answers(parseInt(szNext,10));
}



function back_func()
{
		if (top.iScriptLoaded==0)    //if not loaded
				{
				parent.document.getElementById("bodyframe").cols="100%,0%,0%,0%,0%,0%,0%,0%,0%,0%" ;
				return;
				}

		//find last question and reload it
		iRc=top.szScriptResults.lastIndexOf("Q");
		szQues=top.szScriptResults.substr(iRc);
		szNext=szQues.substr(1,3);
		top.szScriptResults=top.szScriptResults.substring(0,iRc);
		alertmessage=top.szScriptResults
		showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
		//alert(top.szScriptResults);
		if (szNext=="done")
			{
			iRc=confirm("You chosen n/a but there is no default next question. The script will end. Do you want to COMPLETE/disconnect the call too?");
			if (iRc==1)
				{
				completed();
		//		alert("got a done"+top.szScriptResults);
				return;
				}
			}
		load_question(parseInt(szNext,10));  //must use radix!
		load_answers(parseInt(szNext,10));
}



function done_func()
{
		var szNext="done";
		if ((top.iLogin==0)||(top.iLogin==1))    //if not loaded
		{
			parent.document.getElementById("bodyframe").cols="100%,0%,0%,0%,0%,0%,0%,0%,0%,0%" ;
			top.iScriptToggle=0;
			return;
		}
		//top.szScriptResults+="Q"+top.szQuestion+":A"+szChosen+"->"+szNext+",";
		top.szScriptResults+="->"+szNext;
		if (szNext=="done")
		{
			if (top.iLogon==0)
			{
				alertmessage="This is not valid at this point."
				showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
				//alert("This is not valid at this point.");
			}
			iRc=confirm("You've chosen 'done'. The script will end. Do you want to COMPLETE/disconnect the call too?");
			if (iRc==1)
			{
				completed();
				//	alert("got a done"+top.szScriptResults);
				return;
			}
		}
}


function public_Labels(label1, label2, label3, label4, label5)
{
		top.tabsFrame.document.getElementById("t1").innerText = label1;
		top.tabsFrame.document.getElementById("t2").innerText = label2;
		top.tabsFrame.document.getElementById("t3").innerText = label3;
		top.tabsFrame.document.getElementById("t4").innerText = label4;
		top.tabsFrame.document.getElementById("t5").innerText = label5;
}



	//a public function that the container uses to pass in values for the card containers
function public_Contents(contents1, contents2, contents3, contents4, contents5){
		top.tabsFrame.document.getElementById("t1Contents").innerText= contents1;
		top.tabsFrame.document.getElementById("t2Contents").innerText= contents2;
		top.tabsFrame.document.getElementById("t3Contents").innerText= contents3;
		top.tabsFrame.document.getElementById("t4Contents").innerText= contents4;
		top.tabsFrame.document.getElementById("t5Contents").innerText= contents5;
		init();
}


	//a public function that the container uses to pass in colors for the cards
function public_Colors(color1, color2, color3, color4, color5)
{
		top.tabsFrame.document.getElementById("t1").style.backgroundColor = color1; //color1; //top.aszColors[parseInt(tab)];
		top.tabsFrame.document.getElementById("t2").style.backgroundColor = color2; 
		top.tabsFrame.document.getElementById("t3").style.backgroundColor = color3; 
		top.tabsFrame.document.getElementById("t4").style.backgroundColor = color4; 
		top.tabsFrame.document.getElementById("t5").style.backgroundColor = color5; 
	
}

 

	//sets the default display to tab 1
function init(){
		top.tabsFrame.document.getElementById("tabContents").innerHTML = top.tabsFrame.document.getElementById("t1Contents").innerHTML;
}



	//intialize the easy tabs
function initialize_tabs()
{
		public_Contents(top.aszContent[1],top.aszContent[2],top.aszContent[3],top.aszContent[4],top.aszContent[5]);
		public_Colors(top.aszColors[1],top.aszColors[2],top.aszColors[3],top.aszColors[4],top.aszColors[5]);
		public_Labels(top.aszLabels[1],top.aszLabels[2],top.aszLabels[3],top.aszLabels[4],top.aszLabels[5]);
}



var currentTab;
var tabBase;
var firstFlag = true;



function changeTabs()
{
		if(firstFlag == true){
			currentTab = t1;
			tabBase = t1base;
			firstFlag = false;
		}
		//alert("here");
		if(window.event.srcElement.className == "tab"){
			currentTab.className = "tab";
		//	tabBase.style.backgroundColor = "white";
			currentTab = window.event.srcElement;
			//alert("currentTab="+currentTab);
			tabBaseID = currentTab.id + "base";
			//alert("tabBaseID="+tabBaseID);
			
			tabContentID = currentTab.id + "Contents";
			tab=currentTab.id.substr(1,1);
			tabBase = document.all(tabBaseID);
			//alert("tabBase="+tabBase);
			
		//	tabContent = document.all(tabContentID);
			currentTab.className = "selTab";
		//	alert("color="+top.aszColors[parseInt(tab)]);
		//	tabBase.style.backgroundColor = 'red' //top.aszColors[parseInt(tab)];
		//	currentTab.style.backgroundColor = 'red' //top.aszColors[parseInt(tab)];

			tabContents.innerHTML = top.aszContent[parseInt(tab)];
		}
}



function changeTabs2()
{
	if(firstFlag == true){
		currentTab = t1;
		tabBase = t1base;
		firstFlag = false;
	}
	if(window.event.srcElement.className == "tab")
	{
		currentTab.className = "tab";
		tabBase.style.backgroundColor = "white";
		currentTab = window.event.srcElement;
		tabBaseID = currentTab.id + "base";
		tabContentID = currentTab.id + "Contents";
		tabBase = document.all(tabBaseID);
		tabContent = document.all(tabContentID);
		currentTab.className = "selTab";
		
		tabBase.style.backgroundColor = "";
		tabContents.innerHTML = tabContent.innerHTML;
	}
}

function no_response()
{
		logoff_func();
		alertmessage="Logging off. You must press Agent Confirmation within 10 seconds of a call."
		showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
		//alert("Logging off. You must press Agent Confirmation within 10 seconds of a call.");
		clearTimeout(top.iTimer);
}




function no_response_login()
{
		alert("There was no response. Please Try later.");
		//clearTimeout(top.iTimer);
}



function reset_screenpop()
{
		changeValue(top.mainFrame.document.getElementById("f1"),"field1");
		changeValue(top.mainFrame.document.getElementById("f2"),"field2");
		changeValue(top.mainFrame.document.getElementById("f3"),"field3");
		changeValue(top.mainFrame.document.getElementById("f4"),"field4");
		changeValue(top.mainFrame.document.getElementById("f5"),"field5");
		changeValue(top.mainFrame.document.getElementById("f6"),"field6");
		changeValue(top.mainFrame.document.getElementById("f7"),"field7");
		changeValue(top.mainFrame.document.getElementById("f8"),"field8");
		changeValue(top.mainFrame.document.getElementById("f9"),"field9");
}



function load_stats()
{
		var cDate=new Date();
		top.statsFrame.document.forms.form1.textfield.value = cDate.toLocaleString();

		if (top.iNumCalls==0)
			top.statsFrame.document.forms.form1.textfield2.value = top.iNumCalls;
		else	
			top.statsFrame.document.forms.form1.textfield2.value = 0;
			
		if (top.iNumConnectedSecs==0)
			top.statsFrame.document.forms.form1.textfield3.value = 0;
		else
			top.statsFrame.document.forms.form1.textfield3.value = top.iNumConnectedSecs;
			
		if (top.iNumConnectedSecs==0)
			top.statsFrame.document.forms.form1.textfield4.value = 0;
		else
			top.statsFrame.document.forms.form1.textfield4.value = top.iNumCalls/top.iNumConnectedSecs;
}


function wrap_up_call()
{
		top.szNotes2=getCookie("localNotes");
		szFieldsBack=top.szRecno+blank.substr(0,5-top.szRecno.length);
		var fieldlength
		var bob
		var fieldvalue, bob, q
		bob = "                              "
	// goes through all field to insert them in the buffer
		alert("into wrap_up_call");
		fieldvalue = top.mainFrame.document.form2.textfield.value
		if (top.mainFrame.document.form2.textfield.readOnly==true)
		{	
			szFieldsBack+=bob
		}
		else
		{
			if (fieldvalue.length > 30)
				top.mainFrame.document.form2.textfield.value=fieldvalue.substr(0,30)
			fieldlength = 30-top.mainFrame.document.form2.textfield.value.length;
			if (fieldlength > 0)
				szFieldsBack+=top.mainFrame.document.form2.textfield.value + bob.substr(0,fieldlength)
			else
				szFieldsBack+=top.mainFrame.document.form2.textfield.value
		}
		fieldvalue = top.mainFrame.document.form2.textfield2.value
		if (top.mainFrame.document.form2.textfield2.readOnly==true)
		{	
			szFieldsBack+=bob
		}
		else
		{
			if (fieldvalue.length > 30)
				top.mainFrame.document.form2.textfield2.value=fieldvalue.substr(0,30)
			fieldlength = 30-top.mainFrame.document.form2.textfield2.value.length;
			if (fieldlength > 0)
				szFieldsBack+=top.mainFrame.document.form2.textfield2.value + bob.substr(0,fieldlength)
			else
				szFieldsBack+=top.mainFrame.document.form2.textfield2.value
		}
		fieldvalue = top.mainFrame.document.form2.textfield3.value
		if (top.mainFrame.document.form2.textfield3.readOnly==true)
		{	
			szFieldsBack+=bob
		}
		else
		{
			if (fieldvalue.length > 30)
				top.mainFrame.document.form2.textfield3.value=fieldvalue.substr(0,30)
			fieldlength = 30-top.mainFrame.document.form2.textfield3.value.length;
			if (fieldlength > 0)
				szFieldsBack+=top.mainFrame.document.form2.textfield3.value + bob.substr(0,fieldlength)
			else
				szFieldsBack+=top.mainFrame.document.form2.textfield3.value
		}
		fieldvalue = top.mainFrame.document.form2.textfield4.value
		if (top.mainFrame.document.form2.textfield4.readOnly==true)
		{	
			szFieldsBack+=bob
		}
		else
		{
			if (fieldvalue.length > 30)
				top.mainFrame.document.form2.textfield4.value=fieldvalue.substr(0,30)
			fieldlength = 30-top.mainFrame.document.form2.textfield4.value.length;
			if (fieldlength > 0)
				szFieldsBack+=top.mainFrame.document.form2.textfield4.value + bob.substr(0,fieldlength)
			else
				szFieldsBack+=top.mainFrame.document.form2.textfield4.value
		}
		fieldvalue = top.mainFrame.document.form2.textfield5.value
		if (top.mainFrame.document.form2.textfield5.readOnly==true)
		{	
			szFieldsBack+=bob
		}
		else
		{
			if (fieldvalue.length > 30)
				top.mainFrame.document.form2.textfield5.value=fieldvalue.substr(0,30)
			fieldlength = 30-top.mainFrame.document.form2.textfield5.value.length;
			if (fieldlength > 0)
				szFieldsBack+=top.mainFrame.document.form2.textfield5.value + bob.substr(0,fieldlength)
			else
				szFieldsBack+=top.mainFrame.document.form2.textfield5.value
		}
		fieldvalue = top.mainFrame.document.form2.textfield6.value
		if (top.mainFrame.document.form2.textfield6.readOnly==true)
		{	
			szFieldsBack+=bob
		}
		else
		{
			if (fieldvalue.length > 30)
				top.mainFrame.document.form2.textfield6.value=fieldvalue.substr(0,30)
			fieldlength = 30-top.mainFrame.document.form2.textfield6.value.length;
			if (fieldlength > 0)
				szFieldsBack+=top.mainFrame.document.form2.textfield6.value + bob.substr(0,fieldlength)
			else
				szFieldsBack+=top.mainFrame.document.form2.textfield6.value
		}
		fieldvalue = top.mainFrame.document.form2.textfield7.value
		if (top.mainFrame.document.form2.textfield7.readOnly==true)
		{	
			szFieldsBack+=bob
		}
		else
		{
			if (fieldvalue.length > 30)
				top.mainFrame.document.form2.textfield7.value=fieldvalue.substr(0,30)
			fieldlength = 30-top.mainFrame.document.form2.textfield7.value.length;
			if (fieldlength > 0)
				szFieldsBack+=top.mainFrame.document.form2.textfield7.value + bob.substr(0,fieldlength)
			else
				szFieldsBack+=top.mainFrame.document.form2.textfield7.value
		}
		fieldvalue = top.mainFrame.document.form2.textfield8.value
		if (top.mainFrame.document.form2.textfield8.readOnly==true)
		{	
			szFieldsBack+=bob
		}
		else
		{
			if (fieldvalue.length > 30)
				top.mainFrame.document.form2.textfield8.value=fieldvalue.substr(0,30)
			fieldlength = 30-top.mainFrame.document.form2.textfield8.value.length;
			if (fieldlength > 0)
				szFieldsBack+=top.mainFrame.document.form2.textfield8.value + bob.substr(0,fieldlength)
			else
				szFieldsBack+=top.mainFrame.document.form2.textfield8.value
		}
		fieldvalue = top.mainFrame.document.form2.textfield9.value
		if (top.mainFrame.document.form2.textfield9.readOnly==true)
		{	
			szFieldsBack+=bob
		}
		else
		{
			if (fieldvalue.length > 30)
				top.mainFrame.document.form2.textfield9.value=fieldvalue.substr(0,30)
			fieldlength = 30-top.mainFrame.document.form2.textfield9.value.length;
			if (fieldlength > 0)
				szFieldsBack+=top.mainFrame.document.form2.textfield9.value + bob.substr(0,fieldlength)
			else
				szFieldsBack+=top.mainFrame.document.form2.textfield9.value
		}
		
		//alert(szFieldsBack.length)
		write_script_answers();
		for (i=0;i<top.mainFrame.document.form2.resultcodes.options.length;i++)
			{
			if (top.mainFrame.document.form2.resultcodes.options[i].selected==true)
				{
				top.szLabel=top.mainFrame.document.form2.resultcodes.options[i].text;		
				}
			}	
		for (i=0;i<top.mainFrame.document.form2.othercodes.options.length;i++)
			{
			if (top.mainFrame.document.form2.othercodes.options[i].selected==true)
				{
				top.szOthercodes=top.mainFrame.document.form2.othercodes.options[i].text;		
				}
			}
		if (top.szNotes2==null)
			top.szNotes2=" ";
		szDataBuffer=top.szPhone+blank.substr(0,20-top.szPhone.length)+top.szRecno+blank.substr(0,20-top.szRecno.length)+top.szUserID+blank.substr(0,20-top.szUserID.length)+top.szLabel+blank.substr(0,20-top.szLabel.length)+top.szOthercodes+blank.substr(0,20-top.szOthercodes.length)+top.szNotes2+blank.substr(0,80-top.szNotes2.length);
		write_to_server("69","69","69",szDataBuffer,"Campaign");
		var completelength
		write_to_server("21","21","21",szFieldsBack,"Campaign");
		//alert(szOutBuffer.length)
		szBuffer="DC "+top.szCampaign+blank.substr(0,20-top.szCampaign.length)+top.szUserID+blank.substr(0,20-top.szUserID.length);

		top.leftFrame.gateway.SendLen = szBuffer.length; 
		top.leftFrame.gateway.SendData = szBuffer; 

		write_to_server("03","03","03"," ","Campaign");
		//back to first question
		if (top.iScriptType==1)  //only do it for branching script
			{
			load_question(0);   //initialize script
			load_answers(0);
			iCurrentQuestion=0;
			}
//		parent.document.getElementById("bodyframe").cols="100%,0%,0%,0%,0%,0%,0%,0%,0%,0%" ;
//		parent.document.getElementById("bodyframe").rows="50%,0%,50%,0%,0%,0%,0%,0%,0%,0%" ; 
		parent.document.getElementById("bodyframe").rows="48%,0%,52%,0%,0%,0%,0%,0%,0%,0%" ;
		
		
		top.iScriptToggle=0;
		top.iLogin=2;   //back to waiting

		top.leftFrame.form1.searchingImage.src = '/images/check.gif';
		top.leftFrame.form1.pausedImage.src = '/images/x.gif';
		top.leftFrame.form1.dataconnImage.src = '/images/check.gif';
		top.leftFrame.form1.calleeconnImage.src = '/images/x.gif';
		top.leftFrame.form1.voiceconnImage.src = '/images/check.gif';
		top.leftFrame.form1.wrapImage.src = '/images/x.gif';
		top.leftFrame.form1.recordImage.src = '/images/x.gif';
		

}



function write_script_answers()
{
		var szSendBuf;
		iLen=top.szScriptResults.length;
		iNumWrites=iLen/180+1;
		
		for (k=0;k<iNumWrites;k++)
		{
			alert("in write_script_answers.k="+k);
			szSendBuf=top.szScriptResults.substr(k*180,180);
			write_to_server("71","71","71",szSendBuf,top.szCampaign);
		}
		alert("sending a 72");
		write_to_server("72","72","72","",top.szCampaign);

}





function error_func()
{
		alertmessage="got an error"
		showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
		//alert("got an error");
}
	
	
		
function setMessage()
{
		if (top.str == "")
		{
		    for (var ii = 0; ii < 120; ii += 10) {top.str = top.str + "          "}
		    
		    
		}
		else
		{
		   top.str = top.str.substring(2, top.str.length)
		}
		window.status = top.str
		STBTimeOutID = window.setTimeout('setMessage()',100)
}




function script_timer()
{
	alert("script timer");
	//	script.cancel();
		top.iScriptLoaded=1;		//flgag to show that we have loaded a script
		iRc=top.szScriptBuffer.indexOf("[Answers]");
		if (iRc!=-1)   //means we found it so telemarketing script
				{
	//			alert("telemark script");
				top.szAnswerstring=top.szScriptBuffer.substring(top.szScriptBuffer.indexOf("[Answers]"),top.szScriptBuffer.indexOf("[Questions]"));
				top.aszAnswers=top.szAnswerstring.split("~");
				//alert("answers="+top.aszAnswers[3]);
				questions=top.szScriptBuffer.substring(top.szScriptBuffer.indexOf("[Questions]"),top.szScriptBuffer.indexOf("[Relations]"));
				top.aszQuestions=questions.split("~");
				//alert("questions"+top.aszQuestions);
				relations=top.szScriptBuffer.substring(top.szScriptBuffer.indexOf("[Relations]"),top.szScriptBuffer.indexOf("[Text]"));
				top.aszRelations=relations.split("~");
				
				iStartOfText=top.szScriptBuffer.indexOf("[Text]");
	//			alert("size="+top.szScriptBuffer.length+" start="+iStartOfText+" endoftext="+top.szScriptBuffer.indexOf("zzz"));
				top.szText=top.szScriptBuffer.substring(iStartOfText,top.szScriptBuffer.indexOf("zzz"));
	//			alert("text="+top.szText);
				top.aszText=top.szText.split("~");
				
				//alert("text"+top.aszText);
				top.iScriptType=1;
				}
			else
				{							//not found so index cards
	//			alert("index cards");
				szContent=top.szScriptBuffer.substring(top.szScriptBuffer.indexOf("[content]"),top.szScriptBuffer.indexOf("[labels]"));
				top.aszContent=szContent.split("~");
				for (i=1;i<6;i++)
					{
					iStart=top.aszContent[i].indexOf("\"");
					iEnd=top.aszContent[i].lastIndexOf("\"");
					top.aszContent[i]=top.aszContent[i].substring(iStart+1,iEnd-1);
					}
				szLabels=top.szScriptBuffer.substring(top.szScriptBuffer.indexOf("[labels]"),top.szScriptBuffer.indexOf("[colors]"));
				top.aszLabels=szLabels.split("~");
				for (i=1;i<6;i++)
					{
					iStart=top.aszLabels[i].indexOf("\"");
					iEnd=top.aszLabels[i].lastIndexOf("\"");
					top.aszLabels[i]=top.aszLabels[i].substring(iStart+1,iEnd);
					}
				szColors=top.szScriptBuffer.substring(top.szScriptBuffer.indexOf("[colors]"),top.szScriptBuffer.indexOf("zzz"));
	//			alert(szColors);
				top.aszColors=szColors.split("~");
				for (i=1;i<6;i++)
					{
					iStart=top.aszColors[i].indexOf("\"");
					iEnd=top.aszColors[i].lastIndexOf("\"");
					top.aszColors[i]=top.aszColors[i].substring(iStart+1,iEnd-1);
					}
				top.iScriptType=2;   //means index catrds
				}  //end of answers else
}			





	//after 5 seconds if we can't login then pop this up
function login_timer()
{
	alert("Connection timed out. \n Cannot connect to the Dialer Online Network. Please try again."); 
	top.location.reload(0);
}





	//after 5 seconds if we can't connect to supervisor then pop this up
function supervisor_timer()
{
		alert("Connection timed out. \nCannot connect to your Supervisor Console. Please try again."); 
		top.location.reload(0);
}






function add_favs()
{
		window.external.AddFavorite('http://www.dialeronline.net/agent_work_frame.asp?company=0','DialerOnline Agent Workstation');
}



	//creates the top.aszContent from top.szContent
function build_the_text()
{
		//alert(top.szScriptBuffer);
		
		top.szContent=top.szScriptBuffer.substring(top.szScriptBuffer.indexOf("[content]"),top.szScriptBuffer.indexOf("[labels]"));
		var iStart=0;
		//do tab1
		if ((top.szContent.indexOf("tab1 Line"))!=(-1))			
			{
			for (a=0;a<50;a++)
				{
				iStart=top.szContent.indexOf("tab1 Line",iStart)
				if (iStart==-1)
						break;				//no more tab1's
				iEnd=top.szContent.indexOf("\"",iStart+17);		
				if (a > 0)
					top.aszContent[1]+=top.szContent.substring(iStart+17,iEnd);
				else
					top.aszContent[1]=top.szContent.substring(iStart+17,iEnd);
				top.aszContent[1]=top.aszContent[1].replace(/&&/gi,"\n");
				iStart=iEnd+1;
				}
			}
		else
			{											//only one line exists
				iStart=top.szContent.indexOf("tab1 =",iStart);											//only one line exists
				iEnd=top.szContent.indexOf("\"",iStart+8);
				top.aszContent[1]=top.szContent.substring(iStart+8,iEnd-1);	
				top.aszContent[1]=top.aszContent[1].replace(/\n/gi,"<BR>"); 
				iStart=iEnd+1;
			}
		// do tab2
		if ((top.szContent.indexOf("tab2 Line"))!=(-1))			
			{
			for (a=0;a<50;a++)
				{
				iStart=top.szContent.indexOf("tab2 Line",iStart)
				if (iStart==-1)
						break;				//no more tab1's
				iEnd=top.szContent.indexOf("\"",iStart+17);		
				if (a > 0)
					top.aszContent[2]+=top.szContent.substring(iStart+17,iEnd);
				else
					top.aszContent[2]=top.szContent.substring(iStart+17,iEnd);
				top.aszContent[2]=top.aszContent[2].replace(/&&/gi,"\n");
				iStart=iEnd+1;
				}
			}
		else
			{											//only one line exists
				iStart=top.szContent.indexOf("tab2 =",iStart);											//only one line exists
				iEnd=top.szContent.indexOf("\"",iStart+8);
				top.aszContent[2]=top.szContent.substring(iStart+8,iEnd-1);	
				top.aszContent[2]=top.aszContent[2].replace(/\n/gi,"<BR>"); 
				iStart=iEnd+1;
			}
		//do tab3
		if ((top.szContent.indexOf("tab3 Line"))!=(-1))			
			{
			for (a=0;a<50;a++)
				{
				iStart=top.szContent.indexOf("tab3 Line",iStart)
				if (iStart==-1)
						break;				//no more tab1's
				iEnd=top.szContent.indexOf("\"",iStart+17);		
				if (a > 0)
					top.aszContent[3]+=top.szContent.substring(iStart+17,iEnd);
				else
					top.aszContent[3]=top.szContent.substring(iStart+17,iEnd);
				top.aszContent[3]=top.aszContent[3].replace(/&&/gi,"\n");
				iStart=iEnd+1;
				}
			}
		else
			{											//only one line exists
				iStart=top.szContent.indexOf("tab3 =",iStart);											//only one line exists
				iEnd=top.szContent.indexOf("\"",iStart+8);
				top.aszContent[3]=top.szContent.substring(iStart+8,iEnd-1);	
				top.aszContent[3]=top.aszContent[3].replace(/\n/gi,"<BR>"); 
				iStart=iEnd+1;
			}
		//do tab4
		if ((top.szContent.indexOf("tab4 Line"))!=(-1))			
			{
			for (a=0;a<50;a++)
				{
				iStart=top.szContent.indexOf("tab4 Line",iStart)
				if (iStart==-1)
						break;				//no more tab1's
				iEnd=top.szContent.indexOf("\"",iStart+17);		
				if (a > 0)
					top.aszContent[4]+=top.szContent.substring(iStart+17,iEnd);
				else
					top.aszContent[4]=top.szContent.substring(iStart+17,iEnd);
				top.aszContent[4]=top.aszContent[4].replace(/&&/gi,"\n");
				iStart=iEnd+1;
				}
			}
		else
			{											//only one line exists
				iStart=top.szContent.indexOf("tab4 =",iStart);											//only one line exists
				iEnd=top.szContent.indexOf("\"",iStart+8);
				top.aszContent[4]=top.szContent.substring(iStart+8,iEnd-1);	
				top.aszContent[4]=top.aszContent[4].replace(/\n/gi,"<BR>"); 
				iStart=iEnd+1;
			}
		//do tab5
		if ((top.szContent.indexOf("tab5 Line"))!=(-1))			
			{
			for (a=0;a<50;a++)
				{
				iStart=top.szContent.indexOf("tab5 Line",iStart)
				if (iStart==-1)
						break;				//no more tab1's
				iEnd=top.szContent.indexOf("\"",iStart+17);		
				if (a > 0)
					top.aszContent[5]+=top.szContent.substring(iStart+17,iEnd);
				else
					top.aszContent[5]=top.szContent.substring(iStart+17,iEnd);
				top.aszContent[5]=top.aszContent[5].replace(/&&/gi,"\n");
				iStart=iEnd+1;
				}
			}
		else
			{											//only one line exists
				iStart=top.szContent.indexOf("tab5 =",iStart);											//only one line exists
				iEnd=top.szContent.indexOf("\"",iStart+8);
				top.aszContent[5]=top.szContent.substring(iStart+8,iEnd-1);	
				top.aszContent[5]=top.aszContent[5].replace(/\n/gi,"<BR>"); 
				iStart=iEnd+1;
			}
}


function build_labelsandcolors()
{
				// do labels
					top.szLabels=top.szScriptBuffer.substring(top.szScriptBuffer.indexOf("[labels]"),top.szScriptBuffer.indexOf("[colors]"));
					//do tab5
					iStart=0;
					if ((top.szLabels.indexOf("tab1"))!=(-1))			
					{
						iStart=top.szLabels.indexOf("tab1",iStart);
						iEnd=top.szLabels.indexOf("\"",iStart+8);
						top.aszLabels[1]=top.szLabels.substring(iStart+8,iEnd);
						iStart=iEnd+1;
					}
					if ((top.szLabels.indexOf("tab2"))!=(-1))
					{
						iStart=top.szLabels.indexOf("tab2",iStart);
						iEnd=top.szLabels.indexOf("\"",iStart+8);
						top.aszLabels[2]=top.szLabels.substring(iStart+8,iEnd);
						iStart=iEnd+1;
					}
					if ((top.szLabels.indexOf("tab3"))!=(-1))
					{
						iStart=top.szLabels.indexOf("tab3",iStart);
						iEnd=top.szLabels.indexOf("\"",iStart+8);
						top.aszLabels[3]=top.szLabels.substring(iStart+8,iEnd);
						iStart=iEnd+1;
					}
					if ((top.szLabels.indexOf("tab4"))!=(-1))
					{
						iStart=top.szLabels.indexOf("tab4",iStart);
						iEnd=top.szLabels.indexOf("\"",iStart+8);
						top.aszLabels[4]=top.szLabels.substring(iStart+8,iEnd);
						iStart=iEnd+1;
					}
					if ((top.szLabels.indexOf("tab5"))!=(-1))
					{
						iStart=top.szLabels.indexOf("tab5",iStart);
						iEnd=top.szLabels.indexOf("\"",iStart+8);
						top.aszLabels[5]=top.szLabels.substring(iStart+8,iEnd);
						iStart=iEnd+1;
					}

				// do colors
					top.szColors=top.szScriptBuffer.substring(top.szScriptBuffer.indexOf("[colorsH]"),top.szScriptBuffer.indexOf("zzz"));
					iStart=0;
					if ((top.szColors.indexOf("tab1"))!=(-1))
					{
						iStart=top.szColors.indexOf("tab1",iStart);
						iEnd=top.szColors.indexOf("\"",iStart+8);
						top.aszColors[1]=top.szColors.substring(iStart+8,iEnd);
						iStart=iEnd+1;
					}
					if ((top.szColors.indexOf("tab2"))!=(-1))
					{
						iStart=top.szColors.indexOf("tab2",iStart);
						iEnd=top.szColors.indexOf("\"",iStart+8);
						top.aszColors[2]=top.szColors.substring(iStart+8,iEnd);
						iStart=iEnd+1;
					}
					if ((top.szColors.indexOf("tab3"))!=(-1))
					{
						iStart=top.szColors.indexOf("tab3",iStart);
						iEnd=top.szColors.indexOf("\"",iStart+8);
						top.aszColors[3]=top.szColors.substring(iStart+8,iEnd);
						iStart=iEnd+1;
					}
					if ((top.szColors.indexOf("tab4"))!=(-1))
					{
						iStart=top.szColors.indexOf("tab4",iStart);
						iEnd=top.szColors.indexOf("\"",iStart+8);
						top.aszColors[4]=top.szColors.substring(iStart+8,iEnd);
						iStart=iEnd+1;
					}
					if ((top.szColors.indexOf("tab5"))!=(-1))
					{
						iStart=top.szColors.indexOf("tab5",iStart);
						iEnd=top.szColors.indexOf("\"",iStart+8);
						top.aszColors[5]=top.szColors.substring(iStart+8,iEnd);
						iStart=iEnd+1;
					}
}


function appointment()
{
		//	window.document.getElementById('searchingImage').src = '/images/check.gif';
		//if (top.iLogin==0)
//		alert("*"+top.szCampaign+"*");
		//huh?
		if (top.iLogin==0)
		{
			alertmessage="You are not logged in."
			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
		}
		else
		{
			if (top.appointment==0)
				{
				parent.document.getElementById("bodyframe").cols="0%,0%,0%,0%,100%,0%,0%,0%,0%,0%" ;
				top.appointment=1;
				}
			else
				{
//				parent.document.getElementById("bodyframe").cols="100%,0%,0%,0%,0%,0%,0%,0%,0%,0%" ;
				parent.document.getElementById("bodyframe").cols="40%,0%,60%,0%,0%,0%,0%,0%,0%,0%" ;
				
				top.appointment=0;
				}	
		}	
}

function backtomain()
{
//				parent.document.getElementById("bodyframe").cols="100%,0%,0%,0%,0%,0%,0%,0%" ;
				parent.document.getElementById("bodyframe").cols="0%,100%,0%,0%,0%,0%,0%,0%,0%,0%" ;

				top.appointment=0;

}

function refresh_func()
{
		if (top.iLogin==0)	//not logged on
			{
			alert("you must login first");
			return;
			}
		
		buffer="RF"+blank.substr(0,15)+top.szCampaign+blank.substr(0,20-top.szCampaign.length)+top.szUserID+blank.substr(0,20-top.szUserID.length);
		top.leftFrame.gateway.SendLen = buffer.length; 
		top.leftFrame.gateway.SendData = buffer; 

}

function sched_appoint()
{
//	top.iLogin=1;
//	top.schedule=0;
//		alert("top.iLogin=" & top.iLogin);
//		alert("top.schedule=" & top.schedule);

		//this will be moved to call from Add:
//		szDataBuffer=top.szPhone+blank.substr(0,20-top.szPhone.length)+top.szRecno+blank.substr(0,20-top.szRecno.length)+top.szUserID+blank.substr(0,20-top.szUserID.length)+top.szLabel+blank.substr(0,20-top.szLabel.length)+top.szOthercodes+blank.substr(0,20-top.szOthercodes.length)+top.szNotes2+blank.substr(0,80-top.szNotes2.length);
//		write_to_server("91","91","91",szDataBuffer,"Campaign");
//		alert("out of");

		if (top.iLogin==0)
		{
			alertmessage="You are not logged in."
			showModelessDialog("alertmessage.htm", alertmessage, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
		}
		else
		{
			if (top.schedule==0)
				{
				//alert("here");
				if (top.iLogin==3)  //only write out if audio connect
					{
					//setting appointment
//					szDataBuffer=top.szPhone+blank.substr(0,20-top.szPhone.length)+top.szRecno+blank.substr(0,20-top.szRecno.length)+top.szUserID+blank.substr(0,20-top.szUserID.length)+top.szLabel+blank.substr(0,20-top.szLabel.length)+top.szOthercodes+blank.substr(0,20-top.szOthercodes.length)+top.szNotes2+blank.substr(0,80-top.szNotes2.length);
//					write_to_server("94","94","94",szDataBuffer,"Campaign");
					
					}
					
					
				parent.document.getElementById("bodyframe").rows="0%,0%,0%,0%,0%,0%,0%,0%,100%,0%" ;
				parent.document.getElementById("bodyframe").cols="100%" ;
				
				top.schedule=3;
				return;
				}

			//was a 3,3	
			if (top.schedule==3) // map or weekly schedule
				{
				//alert ("there");
				//parent.document.getElementById("bodyframe").cols="100%,0%,0%,0%,0%,0%,0%,0%,0%,0%" ;
				parent.document.getElementById("bodyframe").rows="100%";
				//alert (top.szMap);
				if (top.szMap=="01")
					parent.document.getElementById("bodyframe").cols="0%,0%,0%,0%,0%,0%,0%,0%,0%,0%,0%,100%" ; 
				else
					parent.document.getElementById("bodyframe").cols="0%,0%,0%,0%,0%,0%,0%,0%,100%,60%,0%,0%,0%" ;

//				szDataBuffer=top.szPhone+blank.substr(0,20-top.szPhone.length)+top.szRecno+blank.substr(0,20-top.szRecno.length)+top.szUserID+blank.substr(0,20-top.szUserID.length)+top.szLabel+blank.substr(0,20-top.szLabel.length)+top.szOthercodes+blank.substr(0,20-top.szOthercodes.length)+top.szNotes2+blank.substr(0,80-top.szNotes2.length);
//				write_to_server("91","91","91",szDataBuffer,"Campaign");
					
	
				top.schedule=0;
				return;
				}				
	
		}
}

function modeless(alertmess)
	{
	showModelessDialog("alertmessage.htm", alertmess, "dialogHeight:215px; dialogWidth:400px; help:no resizable:no status:no");
	}

function added_appointment()
{

			//		top.szDataBuffer=top.phonen+blank.substr(0,20-top.phonen.length)+top.szRecno+blank.substr(0,20-top.szRecno.length)+top.szUserID+blank.substr(0,20-top.szUserID.length)+top.szLabel+blank.substr(0,20-top.szLabel.length)+top.szOthercodes+blank.substr(0,20-top.szOthercodes.length)+top.szNotes2+blank.substr(0,80-top.szNotes2.length);
			//		alert("len=" & top.szDataBuffer.length );
					write_to_server("94","94","94"," ","Campaign");
			//		alert("done");


}

function portchecker_func()
{
	alertmess="port check";
	showModelessDialog("port_checker.asp", alertmess, "dialogHeight:515px; dialogWidth:800px; help:no resizable:yes status:no");
}