function CreateCall(
	server, 
	companyName,
	countryCode, 
	areaCode, 
	phoneNumber,
	phoneHash,
	dispName, 
	logo, 
	background,
	optionalStr
	)
{
	theURL = GetURL(	
					server, 
					companyName,
					countryCode, 
					areaCode, 
					phoneNumber,
					phoneHash,
					dispName, 
					logo, 
					background
					); 
				
	// optional parameters
	if (null != optionalStr)
	{
		theURL += "OptionalStr=" + escape(optionalStr) + "&";
	}
	newWin = window.open(theURL, "CreateCall",'location=no,menubar=no,toolbar=no,hotkeys=no,resizable=no,titlebar=yes,scrollbars=no,status=yes,width=490,height=400');
	return;
}

function CreateCallRM(
	server, 
	companyName, 
	acdCountryCode, 
	acdAreaCode, 
	acdPhoneNumber, 
	phoneHash, 
	lastName, 
	firstName, 
	email, 
	callType,
	callAttributes,
	cbExtType, 
	cbCountryCode, 
	cbAreaCode, 
	cbPhoneNumber,
	cbExtension,
	dispName, 
	logo, 
	background, 
	origPage,
	optionalStr
	)
{
	theURL = GetRMURL(
				server, 
				companyName, 
				acdCountryCode, 
				acdAreaCode, 
				acdPhoneNumber, 
				phoneHash, 
				lastName, 
				firstName, 
				email, 
				callType,
				callAttributes,
				cbExtType, 
				cbCountryCode, 
				cbAreaCode, 
				cbPhoneNumber,
				cbExtension,
				dispName, 
				logo, 
				background, 
				origPage
				);
				
	// optional parameters
	if (null != optionalStr)
	{
		theURL += "OptionalStr=" + escape(optionalStr) + "&";
	}
	newWin = window.open(theURL, "CreateCall",'location=no,menubar=no,toolbar=no,hotkeys=no,resizable=no,titlebar=yes,scrollbars=no,status=yes,width=490,height=400');
}

function CreateCallRMNoWindow(
	server, 
	companyName, 
	acdCountryCode, 
	acdAreaCode, 
	acdPhoneNumber, 
	phoneHash, 
	lastName, 
	firstName, 
	email, 
	callType,
	callAttributes,
	cbExtType, 
	cbCountryCode, 
	cbAreaCode, 
	cbPhoneNumber,
	cbExtension,
	dispName, 
	logo, 
	background, 
	origPage
	)
{
	theURL = GetRMURL(
				server, 
				companyName, 
				acdCountryCode, 
				acdAreaCode, 
				acdPhoneNumber, 
				phoneHash, 
				lastName, 
				firstName, 
				email, 
				callType,
				callAttributes,
				cbExtType, 
				cbCountryCode, 
				cbAreaCode, 
				cbPhoneNumber,
				cbExtension,
				dispName, 
				logo, 
				background, 
				origPage
				);

	self.location = theURL;
}

function CreateCall2(
	server, 
	companyName,
	countryCode, 
	areaCode, 
	phoneNumber,
	phoneHash,
	dispName, 
	logo, 
	background,
    WhisperOne,
    WhisperTwo,
    IVRString,
    OptionalStr
	)
{
	var theURL = GetURL(
						server, 
						companyName,
						countryCode, 
						areaCode, 
						phoneNumber,
						phoneHash,
						dispName, 
						logo, 
						background
						);			 
	
	// new parameters
	theURL += "WhisperOne="
				+ escape(WhisperOne)
				+ "&WhisperTwo="
				+ escape(WhisperTwo)
				+ "&IVRString="
				+ escape(IVRString)
				+ "&OptionalStr="
				+ escape(OptionalStr)
				+ "&";

	newWin = window.open(theURL, "CreateCall",'location=no,menubar=no,toolbar=no,hotkeys=no,resizable=no,titlebar=yes,scrollbars=no,status=yes,width=490,height=400');
	return;
}

function CreateCall2RM(
	server, 
	companyName, 
	acdCountryCode, 
	acdAreaCode, 
	acdPhoneNumber, 
	phoneHash, 
	lastName, 
	firstName, 
	email, 
	callType,
	callAttributes,
	cbExtType, 
	cbCountryCode, 
	cbAreaCode, 
	cbPhoneNumber,
	cbExtension,
	dispName, 
	logo, 
	background, 
	origPage,
    WhisperOne,
    WhisperTwo,
    IVRString,
    OptionalStr
	)
{
	theURL = GetRMURL2(
				server, 
				companyName, 
				acdCountryCode, 
				acdAreaCode, 
				acdPhoneNumber, 
				phoneHash, 
				lastName, 
				firstName, 
				email, 
				callType,
				callAttributes,
				cbExtType, 
				cbCountryCode, 
				cbAreaCode, 
				cbPhoneNumber,
				cbExtension,
				dispName, 
				logo, 
				background, 
				origPage,
				WhisperOne,
				WhisperTwo,
				IVRString,
				OptionalStr
				);
				
	newWin = window.open(theURL, "CreateCall",'location=no,menubar=no,toolbar=no,hotkeys=no,resizable=no,titlebar=yes,scrollbars=no,status=yes,width=490,height=400');
}

function CreateCall2RMNoWindow(
	server, 
	companyName, 
	acdCountryCode, 
	acdAreaCode, 
	acdPhoneNumber, 
	phoneHash, 
	lastName, 
	firstName, 
	email, 
	callType,
	callAttributes,
	cbExtType, 
	cbCountryCode, 
	cbAreaCode, 
	cbPhoneNumber,
	cbExtension,
	dispName, 
	logo, 
	background, 
	origPage,
	WhisperOne,
	WhisperTwo,
	IVRString,
	OptionalStr
	)
{
	theURL = GetRMURL2(
				server, 
				companyName, 
				acdCountryCode, 
				acdAreaCode, 
				acdPhoneNumber, 
				phoneHash, 
				lastName, 
				firstName, 
				email, 
				callType,
				callAttributes,
				cbExtType, 
				cbCountryCode, 
				cbAreaCode, 
				cbPhoneNumber,
				cbExtension,
				dispName, 
				logo, 
				background, 
				origPage,
				WhisperOne,
				WhisperTwo,
				IVRString,
				OptionalStr
				);

	self.location = theURL;
}

// ------ Util functions -----

// all parameters are required.
function GetURL(
	server, 
	companyName,
	countryCode, 
	areaCode, 
	phoneNumber,
	phoneHash,
	dispName, 
	logo, 
	background,
	origPage
	)
{
	sTimer=new Date();
	uniq = sTimer.valueOf(); 

	var theURL = "http://" + server + "/w2ig/CreateCall.ASP?uniqID="
                    + uniq
					+ "&Company="
					+ companyName
					+ "&acdPhCountryCode="
					+ countryCode 
					+ "&acdPhAreaCode="
					+ areaCode
					+ "&acdPhNumber="
					+ phoneNumber
					+ "&acdPhHash="
					+ phoneHash
					+ "&dispName="
					+ escape(dispName)
					+ "&displogo="
					+ logo
					+ "&dispbg="
					+ background;
	
	// send the originating page
	theURL += "&origpage=";
	if ((null == origPage) || ('' == origPage))
	{
		theURL += escape(top.location);
	}
	else
	{
		theURL += escape(origPage);
	}
	theURL += "&";

	return (theURL);
}

function GetRMURL(
	server, 
	companyName, 
	acdCountryCode, 
	acdAreaCode, 
	acdPhoneNumber, 
	phoneHash, 
	lastName, 
	firstName, 
	email, 
	callType,
	callAttributes,
	cbExtType, 
	cbCountryCode, 
	cbAreaCode, 
	cbPhoneNumber,
	cbExtension,
	dispName, 
	logo, 
	background, 
	origPage
	)
{
	// get the basic URL
	var theURL = GetURL(
						server, 
						companyName,
						acdCountryCode, 
						acdAreaCode, 
						acdPhoneNumber,
						phoneHash,
						dispName, 
						logo, 
						background,
						origPage
						);
	
	// values for callType are "n2p", "pstn" or "h323", convert them to number
	// values for callType are "pstn" or "h323", convert them to number
	if (callType.toUpperCase() == "H323")
		callType = "1";
	else if (callType.toUpperCase() == "N2P")
		callType = "4";
	// default to PSTN
	else
		callType = "2";

	// values for extType are "operator" or "auto" or "none", convert them to number
	if (cbExtType.toUpperCase() == "OPERATOR")
		extType = "3";
	else if (cbExtType.toUpperCase() == "AUTO")
		extType = "2";
	// default to none
	else
		extType = "1";

	theURL += "lastName="
				+ lastName
				+ "&firstName="
				+ firstName
				+ "&email="
				+ email
				+ "&callType="
				+ callType
				+ "&extType="
				+ extType
				+ "&cbPhCountryCode="
				+ cbCountryCode 
				+ "&cbPhAreaCode="
				+ cbAreaCode
				+ "&cbPhNumber="
				+ cbPhoneNumber
				+ "&cbPhExtension="
				+ cbExtension
				+ "&";

	if ('singleline' == callAttributes.toLowerCase()) 
	{
		theURL += "callAttributes=1&";
	}
	
	return theURL;
}

function GetRMURL2(
	server, 
	companyName, 
	acdCountryCode, 
	acdAreaCode, 
	acdPhoneNumber, 
	phoneHash, 
	lastName, 
	firstName, 
	email, 
	callType,
	callAttributes,
	cbExtType, 
	cbCountryCode, 
	cbAreaCode, 
	cbPhoneNumber,
	cbExtension,
	dispName, 
	logo, 
	background, 
	origPage,
	WhisperOne,
	WhisperTwo,
	IVRString,
	OptionalStr
	)
{
	var theURL = GetRMURL(
						server, 
						companyName, 
						acdCountryCode, 
						acdAreaCode, 
						acdPhoneNumber, 
						phoneHash, 
						lastName, 
						firstName, 
						email, 
						callType,
						callAttributes,
						cbExtType, 
						cbCountryCode, 
						cbAreaCode, 
						cbPhoneNumber,
						cbExtension,
						dispName, 
						logo, 
						background, 
						origPage
						);

	theURL += "WhisperOne="
				+ escape(WhisperOne)
				+ "&WhisperTwo="
				+ escape(WhisperTwo)
				+ "&IVRString="
				+ escape(IVRString)
				+ "&OptionalStr="
				+ escape(OptionalStr)
				+ "&";

	return theURL;
}


