<SCRIPT LANGUAGE="JScript" RUNAT="Server">

function Session_OnStart()      //Runs the first time a user runs any page in your application
{
	var StatusDic = new ActiveXObject("Scripting.Dictionary");
	var ConfAttToQuery = new ActiveXObject("Scripting.Dictionary");
	var ConfElementToAtt = new ActiveXObject("Scripting.Dictionary");
	var PartyAttToQuery = new ActiveXObject("Scripting.Dictionary");
	var PartyElementToAtt = new ActiveXObject("Scripting.Dictionary");
	var LoginAttToQuery = new ActiveXObject("Scripting.Dictionary");
	var LoginElementToAtt = new ActiveXObject("Scripting.Dictionary");
	var RecordingAttToQuery = new ActiveXObject("Scripting.Dictionary");
	var RecordingElementToAtt = new ActiveXObject("Scripting.Dictionary");

	

	var domCfg=Application("domCfg");
	var root=domCfg.documentElement;
	var IpNode = root.selectSingleNode("IP");
	
	var LdapServerIP=root.selectSingleNode("IP").text;
	var LdapServerPort=root.selectSingleNode("PORT").text;
	var LdapServerRoot=root.selectSingleNode("ROOT").text;
	var strConfRestriction=root.selectSingleNode("CONF_RESTRICTION").text;  // % will be replaced by Numeric Id
	var strPartyRestriction=root.selectSingleNode("PARTY_RESTRICTION").text; // $ will be replaced by Password ,% will be replaced by Numeric Id
	var strLoginRestriction=root.selectSingleNode("LOGIN_RESTRICTION").text; // ~ will be replaced by Password , * will be replaced by User Name
	var strRecordingRestriction=root.selectSingleNode("RECORDING_RESTRICTION").text; // # will be replaced by User id 

	var ConfMapNode = root.selectSingleNode("CONF_MAP");

	if(ConfMapNode!=null)
	{
		var tempNode = ConfMapNode.selectSingleNode("NAME");
		if(tempNode!=null && tempNode.text!="")
			ConfElementToAtt.Add("NAME",tempNode.text);
		tempNode = ConfMapNode.selectSingleNode("PASSWORD");
		if(tempNode!=null && tempNode.text!="")
			ConfElementToAtt.Add("PASSWORD",tempNode.text);
		tempNode = ConfMapNode.selectSingleNode("ENTRY_PASSWORD");
		if(tempNode!=null && tempNode.text!="")
			ConfElementToAtt.Add("ENTRY_PASSWORD",tempNode.text);
		tempNode = ConfMapNode.selectSingleNode("BILLING_DATA");
		if(tempNode!=null && tempNode.text!="")
			ConfElementToAtt.Add("BILLING_DATA",tempNode.text);
		tempNode = ConfMapNode.selectSingleNode("CONTACT_INFO_1");
		if(tempNode!=null && tempNode.text!="")
			ConfElementToAtt.Add("CONTACT_INFO_1",tempNode.text);
		tempNode = ConfMapNode.selectSingleNode("CONTACT_INFO_2");
		if(tempNode!=null && tempNode.text!="")			
			ConfElementToAtt.Add("CONTACT_INFO_2",tempNode.text);
		tempNode = ConfMapNode.selectSingleNode("CONTACT_INFO_3");
		if(tempNode!=null && tempNode.text!="")
			ConfElementToAtt.Add("CONTACT_INFO_3",tempNode.text);
		tempNode = ConfMapNode.selectSingleNode("DISPLAY_NAME");
		if(tempNode!=null && tempNode.text!="")
			ConfElementToAtt.Add("DISPLAY_NAME",tempNode.text);
	}

	var PartyMapNode = root.selectSingleNode("PARTY_MAP");

	if(PartyMapNode!=null)
	{
		var tempNode = PartyMapNode.selectSingleNode("NAME");
		if(tempNode!=null && tempNode.text!="")
			PartyElementToAtt.Add("NAME",tempNode.text);
		tempNode = PartyMapNode.selectSingleNode("LEADER");
		if(tempNode!=null && tempNode.text!="")
			PartyElementToAtt.Add("LEADER",tempNode.text);
		tempNode = PartyMapNode.selectSingleNode("VIP");
		if(tempNode!=null && tempNode.text!="")
			PartyElementToAtt.Add("VIP",tempNode.text);
		tempNode = PartyMapNode.selectSingleNode("CONTACT_INFO_1");
		if(tempNode!=null && tempNode.text!="")
			PartyElementToAtt.Add("CONTACT_INFO_1",tempNode.text);
		tempNode = PartyMapNode.selectSingleNode("CONTACT_INFO_2");
		if(tempNode!=null && tempNode.text!="")			
			PartyElementToAtt.Add("CONTACT_INFO_2",tempNode.text);
		tempNode = PartyMapNode.selectSingleNode("CONTACT_INFO_3");
		if(tempNode!=null && tempNode.text!="")
			PartyElementToAtt.Add("CONTACT_INFO_3",tempNode.text);
		tempNode = PartyMapNode.selectSingleNode("CONTACT_INFO_4");
		if(tempNode!=null && tempNode.text!="")
			PartyElementToAtt.Add("CONTACT_INFO_4",tempNode.text);
	}


	var LoginMapNode = root.selectSingleNode("LOGIN_MAP");

	if(LoginMapNode!=null)
	{
		var tempNode = LoginMapNode.selectSingleNode("USER_ID");
		if(tempNode!=null && tempNode.text!="")
			LoginElementToAtt.Add("USER_ID",tempNode.text);
	}

	var RecordingMapNode = root.selectSingleNode("RECORDING_MAP");

	if(RecordingMapNode!=null)
	{
		var tempNode = RecordingMapNode.selectSingleNode("NAME");
		if(tempNode!=null && tempNode.text!="")
			RecordingElementToAtt.Add("NAME",tempNode.text);

		tempNode = RecordingMapNode.selectSingleNode("EMAIL");
		if(tempNode!=null && tempNode.text!="")
			RecordingElementToAtt.Add("EMAIL",tempNode.text);
	}


	var statusOK=0;
	var statusIllegalMcuUserPassword=1;
	var statusRequestTimeout=2;
	var statusIllegalNid=3;
	var statusIllegalCli=4;
	var statusIllegaCliNid=5;
	var statusInternalError=6;
	var statusIllegalUserId=7;
	var statusIllegalUserNamePassword=8;


		


	StatusDic.Add(statusOK.toString(10),"OK");
	StatusDic.Add(statusIllegalMcuUserPassword.toString(10),"Invalid MCU user name and/or password");
	StatusDic.Add(statusRequestTimeout.toString(10),"Request timed out");
	StatusDic.Add(statusIllegalNid.toString(10),"Invalid NID/Password");
	StatusDic.Add(statusIllegalCli.toString(10),"Invalid CLI");
	StatusDic.Add(statusIllegaCliNid.toString(10),"Invalid CLI/NID");
	StatusDic.Add(statusInternalError.toString(10),"Invalid Error");
	StatusDic.Add(statusIllegalUserId.toString(10),"Invalid UserId");
	StatusDic.Add(statusIllegalUserNamePassword.toString(10),"Invalid user name and/or password");


	
		
	Session("StatusDic")=StatusDic;
	Session("ConfAttToQuery")=ConfAttToQuery;
	Session("ConfElementToAtt")=ConfElementToAtt;	
	Session("PartyAttToQuery")=PartyAttToQuery;
	Session("PartyElementToAtt")=PartyElementToAtt;	

	Session("LoginAttToQuery")=LoginAttToQuery;
	Session("LoginElementToAtt")=LoginElementToAtt;	
	Session("RecordingAttToQuery")=RecordingAttToQuery;
	Session("RecordingElementToAtt")=RecordingElementToAtt;	

	
	Session("statusOK")=0;	
	Session("statusIllegalMcuUserPassword")=statusIllegalMcuUserPassword;
	Session("statusRequestTimeout")=statusRequestTimeout;
	Session("statusIllegalNid")=statusIllegalNid;
	Session("statusIllegalCli")=statusIllegalCli;
	Session("statusIllegaCliNid")=statusIllegaCliNid;
	Session("statusInternalError")=statusInternalError;	
	Session("statusIllegalUserId")=statusIllegalUserId;	
	Session("statusIllegalUserNamePassword")=statusIllegalUserNamePassword;	
	
	

	ArrayAtt = (new VBArray(ConfElementToAtt.Keys()));    // Get the keys.

	for (i = 0; i < ConfElementToAtt.Count; i++)
	{
		ConfAttToQuery.Add(ConfElementToAtt.Item(ArrayAtt.getItem(i)),"");
	}
	
	ArrayAtt = (new VBArray(PartyElementToAtt.Keys()));    // Get the keys.

	for (i = 0; i < PartyElementToAtt.Count; i++)
	{
		PartyAttToQuery.Add(PartyElementToAtt.Item(ArrayAtt.getItem(i)),"");
	}

	ArrayAtt = (new VBArray(LoginElementToAtt.Keys()));    // Get the keys.

	for (i = 0; i < LoginElementToAtt.Count; i++)
	{
		LoginAttToQuery.Add(LoginElementToAtt.Item(ArrayAtt.getItem(i)),"");
	}

	ArrayAtt = (new VBArray(RecordingElementToAtt.Keys()));    // Get the keys.

	for (i = 0; i < RecordingElementToAtt.Count; i++)
	{
		RecordingAttToQuery.Add(RecordingElementToAtt.Item(ArrayAtt.getItem(i)),"");
	}
	
	
	QueryAtt="";
	ArrayAtt = (new VBArray(ConfAttToQuery.Keys()));    // Get the keys.

	for (i = 0; i < ConfAttToQuery.Count; i++)
	{
		QueryAtt += ArrayAtt.getItem(i) + ",";
	}
	
	if(LdapServerRoot!=null&&LdapServerRoot!="")
		LdapServerRoot="/"+LdapServerRoot;

	var ConfLdapQuery ="<LDAP://"+LdapServerIP+":"+LdapServerPort+LdapServerRoot+">;"+strConfRestriction+";"+QueryAtt+";subtree";

	QueryAtt="";
	ArrayAtt = (new VBArray(PartyAttToQuery.Keys()));    // Get the keys.

	for (i = 0; i < PartyAttToQuery.Count; i++)
	{
		QueryAtt += ArrayAtt.getItem(i) + ",";
	}	
	var PartyLdapQuery ="<LDAP://"+LdapServerIP+":"+LdapServerPort+LdapServerRoot+">;"+strPartyRestriction+";"+QueryAtt+";subtree";

	QueryAtt="";
	ArrayAtt = (new VBArray(LoginAttToQuery.Keys()));    // Get the keys.

	for (i = 0; i < LoginAttToQuery.Count; i++)
	{
		QueryAtt += ArrayAtt.getItem(i) + ",";
	}	
	var LoginLdapQuery ="<LDAP://"+LdapServerIP+":"+LdapServerPort+LdapServerRoot+">;"+strLoginRestriction+";"+QueryAtt+";subtree";

	QueryAtt="";
	ArrayAtt = (new VBArray(RecordingAttToQuery.Keys()));    // Get the keys.

	for (i = 0; i < RecordingAttToQuery.Count; i++)
	{
		QueryAtt += ArrayAtt.getItem(i) + ",";
	}	
	var RecordingLdapQuery ="<LDAP://"+LdapServerIP+":"+LdapServerPort+LdapServerRoot+">;"+strRecordingRestriction+";"+QueryAtt+";subtree";
	
	Session("ConfLdapQuery")=ConfLdapQuery;
	Session("PartyLdapQuery")=PartyLdapQuery;

	Session("LoginLdapQuery")=LoginLdapQuery;
	Session("RecordingLdapQuery")=RecordingLdapQuery;

	
}

function  Session_OnEnd()       //Runs when a user's session times out or quits your application
{
	Session("StatusDic")=null;
	Session("ConfAttToQuery")=null;
	Session("ConfElementToAtt")=null;	
	Session("PartyAttToQuery")=null;
	Session("PartyElementToAtt")=null;	
	Session("LoginAttToQuery")=null;
	Session("LoginElementToAtt")=null;	
	Session("RecordingAttToQuery")=null;
	Session("RecordingElementToAtt")=null;	
}

function Application_OnStart()      //Runs the first time a user runs any page in your application
{
	var domCfg = new ActiveXObject("MSXML2.FreeThreadedDOMDocument");
	domCfg.async = false;
	domCfg.load(Server.mappath("DirectoryCfg.xml"));
	Application("domCfg")=domCfg;
	
}

function Application_OnEnd()       //Runs when a user's session times out or quits your application
{
	Application("domCfg")=null;
}

</SCRIPT>

