var sCheckURL = "http://chat.outsell.com/Media/dlls/TLMediaU.dll";
var sChatURL = "http://chat.outsell.com/Media"; 
var sTimeURL = "http://chat.outsell.com/Media/visitorchat/TimeCal.asp";
var sTrackURL = "http://chat.outsell.com/WebTrak" ;

DBSvr = "PRDNTDB004" ;
DBName = "tlWebTrak" ;

//Changes for outsell
var dealerEmail = "";

function Outsell_StartChat(custEmail)
{
	dealerEmail = custEmail;
	if(dealerEmail == null)
		dealerEmail = "nullemail@nullemail.com";
	if(dealerEmail == "")
		dealerEmail = "blankemail@blankemail.com";
	CheckBrowser()
}

var TimerInterval = 30;    // Seconds   provide -1 if do not want to check
var sContextProps = '';

var isIE = (navigator.userAgent.indexOf("MSIE") > -1) ? true : false ;
var isMac = (navigator.userAgent.indexOf("Macintosh") > -1) ? true : false ;
var isIEMac = ((navigator.userAgent.indexOf("Macintosh") > -1) && (navigator.userAgent.indexOf("MSIE") > -1))? true : false ;
isIE4 = (navigator.userAgent.indexOf("MSIE 4") > -1) ? true : false ;

var NS6Image1 = new Image();
NS6Image1.width = 0  ;
NS6Image1.height = 0 ;

var DBSvr = "" ;
var DBName = "" ;
var sContextProps = "" ;


var sUrl = window.location.href
var nIndex = sUrl.indexOf("?")
var sQueryString = "";


function Is() 
{
    var agent = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.version=parseFloat(navigator.appVersion);
    this.ns  = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
    this.ns4 = (this.ns && (this.major >= 4));
    this.ns47 = (this.ns && (this.version == 4.7));
    this.ns61=(this.ns && (agent.indexOf("netscape6/6.1") != -1));
	this.ns62 = (this.ns && (agent.indexOf("netscape6/6.2.1") != -1));
	this.ns70 = (this.ns && (agent.indexOf("netscape/7.0") != -1));
    this.ie   = (agent.indexOf("msie") != -1);
    this.ie4  = (this.ie && (this.major = 4));
	this.firefox = (this.ns && (agent.indexOf("firefox/") != -1));
	this.ie5 = (this.ie && (agent.indexOf("msie 5.") != -1));
	this.ie6 = (this.ie && (agent.indexOf("msie 6.") != -1));
	this.ie7 = (this.ie && (agent.indexOf("msie 7.") != -1));
	this.windows = (agent.indexOf("win") != -1);
	this.AOL=(agent.indexOf("aol") != -1);
	this.mac = (agent.indexOf("mac") != -1);
	this.winXP=(agent.indexOf("XP") != -1);
}


var is = new Is();

function CheckBrowser()
{
	if(self.name == "CustPage")
		return false;
	if(parent.name=="CustPage")
		return false;
	if(is.AOL)
		return window.setTimeout("form_onSubmit('False')", 20);
	if(is.windows) //check for windows 95 , 98 and NT
	{
		if(!is.winXP)
		{ 		
			if(is.ie5||is.ie6||is.ie7||is.ns47||is.ns61||is.ns62||is.ns70||is.firefox)
				return window.setTimeout("form_onSubmit('False')", 20);
			else 
			{
				//for browser not belonging to these categories
				window.open("http://chat.outsell.com/DoesnotSupport.htm",null,"left=50,top=50,width=880,height=518,location=no,menubar=no,resizable=no,scrollbars=yes,status=yes,toolbar=no,titlebar=no");	
	                        return ;
			}
		}	 
		else
		{	
			if(is.ie6)
				return window.setTimeout("form_onSubmit('False')", 20);
			else
			{
				//for browser not belonging to these categories
	            		window.open("http://chat.outsell.com/DoesnotSupport.htm",null,"left=50,top=50,width=880,height=518,location=no,menubar=no,resizable=no,scrollbars=yes,status=yes,toolbar=no,titlebar=no");		  
	        	    	return ;
		 	}
		}
	}
	else
	{
		if(is.mac)
			return window.setTimeout("form_onSubmit('False')", 20);
		else   //if OS is neither mac nor Win then chat will not be initiated.
		{
			window.open("http://chat.outsell.com/DoesnotSupport.htm",null,"left=50,top=50,width=880,height=518,location=no,menubar=no,resizable=no,scrollbars=yes,status=yes,toolbar=no,titlebar=no");	
			return ;
		}
	}
}	
	
function form_onSubmit() {

	return StartChatSession("False");
}




function ran()
{
	return Math.floor(10000*Math.random());
}

function getCookieVal (offset) 
{  
	var endstr = document.cookie.indexOf (";", offset);  
	if (endstr == -1)    
		endstr = document.cookie.length;  
	return unescape(document.cookie.substring(offset, endstr));
}	

function SetCookie (name, value) 
{
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;  
	var path = (argc > 3) ? argv[3] : null;  
	var domain = (argc > 4) ? argv[4] : null;  
	var secure = (argc > 5) ? argv[5] : false;  
	document.cookie = name + "=" + escape(value) +
		((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
		((path == null) ? "" : ("; path=" + path)) +  
		((domain == null) ? "" : ("; domain=" + domain)) +    
		((secure == true) ? "; secure" : "");
}	

function GetCookie(name) 
{
	var arg = name + "=";  
	var alen = arg.length;  
	var clen = document.cookie.length;  
	var i = 0;  
	while (i < clen) 
	{    
		var j = i + alen;    
		if (document.cookie.substring(i, j) == arg)   
			return getCookieVal (j);    
		i = document.cookie.indexOf(" ", i) + 1;    
		if (i == 0) break;   
	}  
	return null;
}			


function IsClientLocalizable()
{
	var nFound = 0;
	var nBrowse = 0;
	var ua = window.navigator.userAgent
	nFound = ua.toLowerCase().indexOf ( "mac" )
	nBrowse = ua.toLowerCase().indexOf ( "msie" )
	if(nFound > 0 && nBrowse >0)
	{
		return false;
	}
	nFound = ua.indexOf ( "MSIE 5" )
	if(nFound > 0)
	{
		return true;
	}
	nFound = ua.indexOf ( "MSIE 6" )
	if(nFound > 0)
	{
		return true;
	}
	nFound = ua.indexOf ( "Netscape6" )
	if(nFound > 0)
	{
		return true;
	}
	nFound = ua.indexOf ( "Netscape/7.0" )
	if(nFound > 0)
	{
		return true;
	}
	 return false;
}

function StartChatSession(sAuto)
{
	if ( isIEMac)
	{
		alert("You need Netscape browser on Macintosh to use chat.");
		return;
	}

	var strurl = "";
	if ( sAuto.toUpperCase() == "FALSE")
	{
		try
		{
			if ( top.frames.length >  0 )
				if ( top.frames[0].name  == "CustPage" )
					return false;
		}
		catch(e)
		{
		}
	}
	if ( IntervalID != 0 ) {	
		vIntervalIDExists = true;
		window.clearInterval(IntervalID);
	}	
	if ( sChatURL.length > 0 ) 
	{
		var strFolder = "/VisitorChat";
		if(!IsClientLocalizable())
		{
			strFolder = "/VisitorChatEnu";
		}
		
		var ans = true;
		if ( sAuto.toUpperCase() == "TRUE")
		{
		 	ans = confirm( "Our customer service representative will come online to assist you. Please wait...")			
		}
		if (ans) 
		{
			strurl = sChatURL + strFolder + "/StartChat.asp?" + "Auto=" + sAuto + "&CurURL=" + escape(top.window.location.href) ;
			strurl += "&CustEmail=" + dealerEmail;
			
			top.location.replace(strurl);
		}
		else
		{
			i400095 = new Image();
			i400095.src = sTrackURL + "/DenyChat.asp?ChatURL=" + sCheckURL + "&num=" + ran();
		}
	}
	
	return true;
}

if ( isIE ) 
{
	var i400094 = new Image();
	i400094.height= 0;
	i400094.width = 0;
}

var i400095 = new Image();
var IntervalID=0;
var vIntervalIDExists = true;


