// JavaScript Document
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 = "";
/* Update made by Rene Bustamante 08/2008 **************************
*********************************************************************/
function Outsell_StartChat(custEmail)
{
	
	if (FindMatch(custEmail)) {
		var StartingURL = "";
		var strQuerystring = "";
		var startchatfile = "";
		var tscript = "TreatCode_hosted";
		//alert(TalismaID);
		StartingURL = escape(top.window.location.href);
		Posting_URL= "http://www.outsellchat.com/IS_IPanel/StartChatTalisma.php";
		Posting_URL_PAR = Posting_URL + "?" + "TalismaID=" + custEmail + "&useprechatform=0" + "&curURL=" + StartingURL + "&tscript=" + tscript;
		window.open(Posting_URL_PAR, 'custclient','location=0,width=500,height=320,scrollbars=0');		
	} else { 
		dealerEmail = custEmail;
		if(dealerEmail == null)
			dealerEmail = "nullemail@nullemail.com";
		if(dealerEmail == "")
			dealerEmail = "blankemail@blankemail.com";
		CheckBrowser()
	}
}
function FindMatch(dmail) {
	var ArrayDT = ['acurariverside@outsellchats.dl','adventureccj@outsellchats.dl','alvarezlincolnmercury@outsellchats.dl','AndersonDirectHonda@outsellchats.dl','arrow@outsellchats.dl','arrowhead@outsellchats.dl','bdkia@outsellchats.dl','BeavertonToyota@outsellchats.dl','BergstromAppletonBuick@outsellchats.dl','BergstromAppletonChevy@outsellchats.dl','BergstromCadillacMadison@outsellchats.dl','BergstromChevroletBuickCadillac@outsellchats.dl','BergstromChevroletMilwaukee@outsellchats.dl','BergstromChevyCadillacOshkosh@outsellchats.dl','BergstromFordNeenah@outsellchats.dl','BergstromGMOshkosh@outsellchats.dl','BergstromHondaOshkosh@outsellchats.dl','BergstromHummerMadison@outsellchats.dl','BergstromHummerMilwaukee@outsellchats.dl','BergstromNeenah@outsellchats.dl','BergstromNissanOshkosh@outsellchats.dl','BergstromPorsche@outsellchats.dl','BergstromSaturnEauClaire@outsellchats.dl','BergstromSaturnGreenBayc@outsellchats.dl','BergstromSaturnLaCrosse@outsellchats.dl','BergstromSaturnWausau@outsellchats.dl','BergstromSturgeonBay@outsellchats.dl','BergstromVolvo@outsellchats.dl','bfchevy@outsellchats.dl','BFfordmercury@outsellchats.dl','BMWConcord@outsellchats.dl','BobRossAuto@outsellchats.dl','bradshawauto@outsellchats.dl','bradshawinfiniti@outsellchats.dl','cameltoyota@outsellchats.dl','centennialtoyota@outsellchats.dl','ChampionAutomall@outsellchats.dl','clearlakedodge@outsellchats.dl','ContinentalHonda@outsellchats.dl','courtesychevroletAZ@outsellchats.dl','CourtesyChevroletCA@outsellchats.dl','cowboykiaconroe@outsellchats.dl','davesinclairford@outsellchats.dl','Eastwaytoyotalexus@outsellchats.dl','EdwardsArcher@outsellchats.dl','ElDoradoChrysler@outsellchats.dl','ElDoradoJeep@outsellchats.dl','ElDoradoMazda@outsellchats.dl','EnterpriseMotorcars@outsellchats.dl','flemingtonbmw@outsellchats.dl','fordcountry@outsellchats.dl','FredHaasToyota@outsellchats.dl','FredHaasToyotaCountry@outsellchats.dl','galpinford@outsellchats.dl','galpinhonda@outsellchats.dl','GarveyHyundaiNorth@outsellchats.dl','GarveyHyundaiSouth@outsellchats.dl','GarveyKia@outsellchats.dl','GarveyParts@outsellchats.dl','GarveyVW@outsellchats.dl','GradyAutomotive@outsellchats.dl','hardinhonda@outsellchats.dl','HareBuickPontiacGMC@outsellchats.dl','HareChevrolet@outsellchats.dl','hartzheimdodge@outsellchats.dl','hendrickmotors@outsellchats.dl','HerbGordon@outsellchats.dl','HeritageAutoBaltimore@outsellchats.dl','HeritageDodgeJeepOwingsMills@outsellchats.dl','HeritageMazdaOwingsMills@outsellchats.dl','hicountrychevrolet@outsellchats.dl','HondaCarsMcKinney@outsellchats.dl','HondaCarsofRockHill@outsellchats.dl','HondaofBowie@outsellchats.dl','HowdyHonda@outsellchats.dl','ImportedCarStore@outsellchats.dl','InfinitiofScottsdale@outsellchats.dl','islandhonda@outsellchats.dl','jaguarlandroverwindsor@outsellchats.dl','jensonmotorcenter@outsellchats.dl','jmnissan@outsellchats.dl','kerrybuick@outsellchats.dl','KiaofWestchester@outsellchats.dl','kingstoyota@outsellchats.dl','kmtoyota@outsellchats.dl','kmtoyotasuper@outsellchats.dl','LACarVWSantaMonica@outsellchats.dl','LandmarkHonda@outsellchats.dl','LandRoverAlexandria@outsellchats.dl','LarryHopkinsHonda@outsellchats.dl','larrymillerhyundai@outsellchats.dl','larrymillertoyota@outsellchats.dl','LexusofLasVegas@outsellchats.dl','lexusrivercenter@outsellchats.dl','lhmchevy@outsellchats.dl','lhmofhillsboro@outsellchats.dl','LombardToyota@outsellchats.dl','LustineDodge@outsellchats.dl','lustinetoyota@outsellchats.dl','MaplewoodToyota@outsellchats.dl','MarinAcura@outsellchats.dl','MercedesofAnnapolis@outsellchats.dl','MooreAutomotive@outsellchats.dl','MoritzCadillac@outsellchats.dl','MoritzDirect@outsellchats.dl','mountainviewflm@outsellchats.dl','myfchevy@outsellchats.dl','NormReevesCJD@outsellchats.dl','NormReevesHonda@outsellchats.dl','performanceford@outsellchats.dl','performancelexus@outsellchats.dl','phhonda@outsellchats.dl','PinesPontiacGMCBuick@outsellchats.dl','pinnaclecjd@outsellchats.dl','PlanetDodge@outsellchats.dl','planetford45@outsellchats.dl','planetford59@outsellchats.dl','reliablebmw@outsellchats.dl','saab@outsellchats.dl','saturnofasheville@outsellchats.dl','SaturnofBeaverton@outsellchats.dl','saturnofgreenville@outsellchats.dl','saturnofspartanburg@outsellchats.dl','saturnrt31@outsellchats.dl','saturnsyracuse@outsellchats.dl','scott@outsellchats.dl','SheehyFordAshland@outsellchats.dl','SheehyFordMH@outsellchats.dl','SheehyFordRichmond@outsellchats.dl','SheehyFordSpringfield@outsellchats.dl','sheehyhonda@outsellchats.dl','SheehyInfinitiAnnapolis@outsellchats.dl','sheehylexusannapolis@outsellchats.dl','sheehynissan@outsellchats.dl','SheehyNissanAnnapolis@outsellchats.dl','SheehyNissanGlenBurnie@outsellchats.dl','SheehyNissanManassas@outsellchats.dl','SheehyNissanWaldorf@outsellchats.dl','smhonda@outsellchats.dl','southworthchevrolet@outsellchats.dl','subriverside@outsellchats.dl','SunriseToyota@outsellchats.dl','tbautobase@mileone.com','Tischer@outsellchats.dl','TischerPorscheAudi@outsellchats.dl','ToporMotors@outsellchats.dl','TustinAcura@outsellchats.dl','VossChevrolet@outsellchats.dl','WeberChevrolet@outsellchats.dl','WestLoopAutomotive@outsellchats.dl','WhiteBearLakeSuperstore@outsellchats.dl','WilliamsAutomax@outsellchats.dl','WilliamsChevy@outsellchats.dl','WilliamsHonda@outsellchats.dl','WilliamsKia@outsellchats.dl','windsormazda@outsellchats.dl','xml.billwalsh.com@jazel.net','xml.carlchevy.com@jazel.net','xml.carlkia.com@jazel.net','xml.coxauto.com@jazel.net','xml.coxmazda.com@jazel.net','xml.DarrowChryslerJeepofMadison.com@jazel.net','xml.daytontoyota.com@jazel.net','xml.dublinbpgmc.com@jazel.net','xml.gwinnettplacehonda.com@jazel.net','xml.jupiterchevy.com@jazel.net','xml.kiaofduluth.com@jazel.net','xml.nelsonauto.com@jazel.net','xml.prestigevw.com@jazel.net','xml.rickhendrickchevy.com@jazel.net','xml.shakerlincolnmercury.com@jazel.net','xml.sheehyuppermarlboro.com@jazel.net','xml.southeasternhonda.com@jazel.net','dealersuite@outsellchats.dl','HeritageSaturnofYorkRoad@outsellchats.dl']; 
	var FoundMatch = false;
	
	for (var i=0; i<ArrayDT.length; i++) {
		if (trimchain(ArrayDT[i]) == trimchain(dmail)) {
			FoundMatch = true;	
			break;
		}
	}	
	return FoundMatch;
}
function trimchain(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}
/* End Update by Rene Bustamante 08/2008 ******************************************
***********************************************************************************/

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;


