/* * * * * * * * * * * * * * * * * * * * * * * 
 *	File: OSInqChat.js
 *	Functions: 
 *	Instructions: Call Adapter functions,  
 * * * * * * * * * * * * * * * * * * * * * * */

// declare popup variable
var inqAlreadyDisplayedOrInSession = false;

var reactiveChatWindow = false;
function displayHelpWindow1Inq(servletURL)
{
	//Set a reactive chat flag = true, if a reactive chat window has been opened
	reactiveChatWindow =true;
	
	//Set a reactive chat cookie in session to suppress inQ chat
	//alert("Go to Set_Cookie() to set a Reactive Cookie");
	Set_Cookie_inQ();
	
	//Check the inq frameset. If the frameset is turn off, unlock the reactive chat
	if((typeof reactiveChatWindow != 'undefined') && (inqAlreadyDisplayedOrInSession != true))
	{       
		suppressInq(); 
		displayHelpWindow1(servletURL);
	}
}


/* The followings are the functions used by inQ chat */
function suppressInq() 
{
	var InqRegistry = {disableChat:true};
}
function unsuppressInq() 
{
	var InqRegistry = {disableChat:false};
}

function nxPopupWithInq(name,url,overWrite, inqParameters)
{
	//If a reactive chat cookie is not in  the session, send out an inq chat cookie to inQ 
	var inqCookie = Get_Cookie_inQ('reactive_chat');
	if ( inqCookie == null ||  inqCookie!='yes')
	{
	    //alert("No Reactive Chat Cookie");
		if((typeof reactiveChatWindow != 'undefined') && (reactiveChatWindow != true)
			&& ((typeof inq_store_allowed=="undefined")||(inq_store_allowed)))
		{
			if(nxVars.lang == 'es')
			{
				InqLauncher.getInst().launchChatNowByPageID(4652);
			}
			else
			{
				InqLauncher.getInst().launchChatNowByPageID(4615);
			}
		}
	} 
	nxPopup(name,url,overWrite);
}

function switchPhonesWithInq(name)
{
     
	//If a reactive chat cookie is not in  the session, send out an inq chat cookie to inQ 
	var inqCookie = Get_Cookie_inQ('reactive_chat');
	if ( inqCookie ==null ||  inqCookie!='yes')
	{
	//alert("No Reactive Chat Cookie");
		if((typeof reactiveChatWindow != 'undefined') && (reactiveChatWindow != true)
			&& ((typeof inq_store_allowed=="undefined")||(inq_store_allowed)))
		{
			if(nxVars.lang == 'es')
			{
				InqLauncher.getInst().launchChatNowByPageID(4576);
			}
			else
			{
				InqLauncher.getInst().launchChatNowByPageID(4575);
			}
		}
	}
}

function showCompareWithInq()
{   
	//If a reactive chat cookie is not in  the session, send out an inq chat cookie to inQ 
	var inqCookie = Get_Cookie_inQ('reactive_chat');
	if ( inqCookie ==null ||  inqCookie!='yes')
	{
	
		if((typeof reactiveChatWindow != 'undefined') && (reactiveChatWindow != true)
			&& ((typeof inq_store_allowed=="undefined")||(inq_store_allowed)))
		{
			if(nxVars.lang == 'es')
			{
				InqLauncher.getInst().launchChatNowByPageID(4576);
			}
			else
			{
				InqLauncher.getInst().launchChatNowByPageID(4575);
			}
		}
	}
}

function switchPlansWithInq(planID,inqParameters)
{           
	//If a reactive chat cookie is not in  the session, send out an inq chat cookie to inQ 
	var inqCookie = Get_Cookie_inQ('reactive_chat');
	if ( inqCookie ==null ||  inqCookie!='yes')
	{
		if((typeof reactiveChatWindow != 'undefined') && (reactiveChatWindow != true)
			&& ((typeof inq_store_allowed=="undefined")||(inq_store_allowed)))
		{
			if(nxVars.lang == 'es')
			{
				//The ID being passed to launch the chat is page and
				//language dependent Please update the id when this 
				// function needs to be used.
				InqLauncher.getInst().launchChatNowByPageID(4652);
			}
			else
			{
				//The ID being passed to launch the chat is page dependent
				//Please update the id when this function needs to be used.
				InqLauncher.getInst().launchChatNowByPageID(4615);
			}
		}
	}
}

var inqServiceCounter = 0;
function NewWindowWithInq(address,height,width, inqParameters) 
{
	inqServiceCounter++;

	//If a reactive chat cookie is not in  the session, send out an inq chat cookie to inQ 
	var inqCookie = Get_Cookie_inQ('reactive_chat');
	if ( inqCookie ==null ||  inqCookie!='yes')
	{
		if((typeof reactiveChatWindow != 'undefined') && (reactiveChatWindow != true)
			&& ((typeof inq_store_allowed=="undefined")||(inq_store_allowed)))
		{
			if (inqServiceCounter >= 3)
			{
				if(nxVars.lang == 'es')
				{
					InqLauncher.getInst().launchChatNowByPageID(4652);
				}
				else
				{
					InqLauncher.getInst().launchChatNowByPageID(4615);
				}
			}
		}
	}
	
    NewWindow(address,height,width);
}

function Set_Cookie_inQ( )
{ 
   	//alert("Set a Reactive Cookie");
	document.cookie='reactive_chat=yes; path=/';
}

function setInqAlreadyDisplayed()
{
	Set_Cookie_inQ();
	var inqAlreadyDisplayedOrInSession = true;
}

var inqChatListener = {
	onChatEvent: function(evt)
	{
    	setInqAlreadyDisplayed();
    }
 }
 
 var InqRegistry = {chatListeners:[inqChatListener]}
 

function Get_Cookie_inQ(cookie_name)
{
	if (document.cookie.length > 0) 
	{
		var start = document.cookie.indexOf(cookie_name + "="); 
		if (start != -1) 
		{
			start += cookie_name.length+1; 
			var end = document.cookie.indexOf(";", start);
			if (end == -1)
			{
				end = document.cookie.length;
			}
			return unescape(document.cookie.substring(start, end)); 
		}
	}
	return null; 
}
