window.name="newswindow";
window.onerror = stopError;

function stopError(){return true}
function gettopic(){return true}
function openlink(linkURL){if (linkURL == null)linkURL = "";linkwindow = window.open(linkURL,"linkwindow",'toolbar=1,location=1,menubar=1,scrollbars=1,resizable=1,width=615,height=500,status=1,top=screen.availTop,left=screen.availLeft');linkwindow.focus}
function mom(linkURL){if (linkURL == null)linkURL = "";son = window.open(linkURL,"son",'toolbar=0,location=0,menubar=0,scrollbars=1,resizable=0,width=540,height=460,status=1,top=screen.availTop,left=screen.availLeft');son.focus}
function pop(linkURL){if (linkURL == null)linkURL = "";popwindow = window.open(linkURL,"popwindow",'toolbar=0,location=0,menubar=0,scrollbars=1,resizable=1,width=540,height=550,status=1,top=screen.availTop,left=screen.availLeft');popwindow.focus}
function pixpop(linkURL){if (linkURL == null)linkURL = "";pixwindow = window.open(linkURL,"pixwindow",'toolbar=0,location=0,menubar=0,scrollbars=1,resizable=1,width=615,height=550,status=1,top=screen.availTop,left=screen.availLeft');pixwindow.focus}
function openwingsgallery(gallery) {pixpop("http://pc99.detnews.com/wingsgallery/frame.hbs?project=" + gallery)}
function openjoyridesgallery(gallery) {pixpop("http://pc99.detnews.com/joyridesgallery/frame.hbs?project=" + gallery)}
function openlionsgallery(gallery) {pixpop("http://pc99.detnews.com/lionsgallery/frame.hbs?project=" + gallery)}
function openrvmgallery(gallery) {pixpop("http://pc99.detnews.com/rvmgallery/frame.hbs?project=" + gallery)}
function opennewsgallery(gallery) {pixpop("http://pc99.detnews.com/newsgallery/frame.hbs?project=" + gallery)}
function opensportsgallery(gallery) {pixpop("http://pc99.detnews.com/sportsgallery/frame.hbs?project=" + gallery)}
function openautosgallery(gallery) {pixpop("http://pc99.detnews.com/autosgallery/frame.hbs?project=" + gallery)}
function opengallery(gallery) {pixpop("http://data.detnews.com/slideshow/frame.hbs?project=" + gallery)}
function galleryindex(){pixpop("http://data.detnews.com/slideshow/galleryindex.htm")}
function autosgalleryindex(){pixpop("http://pc99.detnews.com/autosgallery/galleryindex.htm")}
function gothere(form){if(form.pick.options[form.pick.selectedIndex].value != "")openlink(form.pick.options[form.pick.selectedIndex].value)}
function morningstar(){pop("http://poweredby.morningstar.com/CoverPages/CoBrandstocksWI.html?CN=DTN725&PC=1")}
function companybox(Ticker){pop("http://poweredby.morningstar.com/Stocks/Snapshot/_" + Ticker + ".html?CN=DTN725&PC=1")} 
function shareit() {pop("http://data.detnews.com/slideshow/linktoshare.hbs?referer=" + window.location)}
function comments(forum) {if (forum == "geartalk"){pop("http://pc99.detnews.com/geartalk/writeus.hbs?referer=" + window.location)}else{pop("http://data.detnews.com/" + forum + "/writeus.hbs?referer=" + window.location)}}
function searchform(form){var search = ((document.search.searchtext.value == "") ? mom("http://detnews.com/search/fulltext.htm") : scriptsearch(document.search.searchtext.value, "phrase"))}
function searchsection(form){var search = ((document.searchsection.sectiontext.value == "") ? mom("http://detnews.com/search/fulltext.htm") : scriptsearch(document.searchsection.sectiontext.value, document.searchsection.typeofsearch.value, document.searchsection.sectionname.value))}
tvDate = new Date();var tvThisday = tvDate.getDay();var tvFiles = "twi_sunday.html*twi_monday.html*twi_tuesday.html*twi_wednesday.html*twi_thursday.html*twi_friday.html*twi_saturday.html";var tvNames = tvFiles.split("*");
function tvToday(){window.location="http://tvlistings.zap2it.com/partners/editorial_link.asp?partner_id=det&url=http://tv.zap2it.com/shows/bestbets/tv/include/" + tvNames[tvThisday]}
function tvTomorrow(){window.location="http://tvlistings.zap2it.com/partners/editorial_link.asp?partner_id=det&url=http://tv.zap2it.com/shows/bestbets/tv/include/" + tvNames[tvThisday + 1]}
function tvSportsToday(){window.location="http://tvlistings.zap2it.com/partners/editorial_link.asp?partner_id=det&url=http://tv.zap2it.com/shows/bestbets/sports/" + tvNames[tvThisday]}
function tvSportsTomorrow(){window.location="http://tvlistings.zap2it.com/partners/editorial_link.asp?partner_id=det&url=http://tv.zap2it.com/shows/bestbets/sports/" + tvNames[tvThisday + 1]}
function findreplace(inString, removeString, replaceString) {
	var outString = "", i = 0;
	while (i <= (inString.length - 1)) {
		if ((i <= (inString.length - removeString.length)) && (inString.substring(i, i + removeString.length)) == removeString){outString += replaceString; i += removeString.length}
		else {outString += inString.charAt(i); i++}
	} 
	return outString;
}
function removeSpaces(inString) {
	var outString = "";
	for (i = 0; i < inString.length; i++ ){if (inString.charAt(i) == " " && inString.charAt(i + 1) == " "){continue}outString += inString.charAt(i)}
	if (outString.charAt(0) == " "){outString = outString.substring(1, outString.length - 1)}
	if (outString.charAt(outString.length - 1) == " "){outString = outString.substring(0, outString.length - 1)}
	return outString;
}
function scriptsearch(searchterm, searchtype, selectedsection, dateline){
	document.startsearch.getit.value = searchterm;
    var s = "\\*'*=*>*<*)*(*{*}*!*@*&*[*\"*]*.*,* and * not *;*?";
	var a = s.split("*");
	for (i = 0; i < a.length; i++) searchterm = findreplace(searchterm, a[i], "");
	if (searchtype == "phrase"){searchterm = findreplace(removeSpaces(searchterm), " ", "<SENTENCE>")}
	if (searchtype == "anywords"){searchterm = findreplace(removeSpaces(new String(searchterm.toLowerCase())), " ", "<OR>")}
	if (searchtype != "phrase" && searchtype != "anywords"){searchterm = findreplace(removeSpaces(new String(searchterm.toLowerCase())), " ", "<AND>");searchtype = "allwords"}
	if (selectedsection != "" && selectedsection != null){searchterm = "(SECTION=" + removeSpaces(new String(selectedsection.toLowerCase())) + ")<AND>" + searchterm} 
	if (dateline != "" && dateline != null){searchterm = "(DATELINE=" + removeSpaces(new String(dateline.toUpperCase())) + ")<AND>" + searchterm} 
	searchterm += "<AND>(FILEDATE>=01/01/2000)<IN>blockquote";
	document.startsearch.SearchType.value = searchtype;
	document.startsearch.QueryText.value = searchterm;
	mom(); 
	document.startsearch.submit();
}
function notiframe(alternatepage){
	if (document.all || document.getElementByID){return true}
	else {window.location=alternatepage}
} 
document.write('<form method="post" action="http://sol.bizserve.com/search97cgi/s97_cgi" name="startsearch" target="son"><INPUT TYPE="hidden" NAME="Action" VALUE="Search"><INPUT TYPE="hidden" NAME="ResultTemplate" VALUE="popupresults.hts"><INPUT TYPE="hidden" NAME="SortField" VALUE="FILEDATE"><INPUT TYPE="hidden" NAME="Collection" VALUE="detnews2"><INPUT TYPE="hidden" NAME="QueryText" VALUE=""><INPUT TYPE="hidden" NAME="getit" VALUE=""><INPUT TYPE="hidden" NAME="SearchType" VALUE=""><INPUT TYPE="hidden" NAME="SortOrder" VALUE="desc"></form>');

document.write('<img src="/pix/folios/dot.gif" onLoad=\'Poll(); return true;\' width="1" height="1" border="0">');

// this script implements the survey strategy. After number of pages visited is equal to or
// greater than 'stickFactor' apply the 'samplePercentage' rule to determine if this visitor
// gets the survey.
// CustomerName: Detroit News Content

// ************* configuration variables - change the values, NOT THE NAMES **************
// minimum number of pages viewed before we survey the user, range: positive integer
var stickFactor = 4;

// this variable when set to 1 will prevent the trigger from performing its
// function
var disableTrigger = 0;

// percentage of visitors to randomly sample, range: 1-100
var samplePercentage = 5;

// number of minutes the persistent cookie should last - this prevents a user from
// getting multi-surveyed in this time period. This variable is ignored if we are
// not using persistent cookies. (1440 minutes per day), range: positive integer
var resampleWait = 129600; 

// this variable will override resampleWait in the event that persistent cookies
// are not allowed by the client, range 1 or 0
var noPersistentCookies = 0;

// this is the base URL to the survey engine
var popUpURL = "http://www.foreseeresults.com/survey/display";

// this is our customer's unique customer id
var customerId = "QKfTcEwBbv6Sp6XUTPCB5w";

// this is out customer's unique model instance id for this survey's model
var modelInstanceId = "p+O7H5m4aqdmM/ndJDLIJg";

// the name of the pop up window
var popUpWinName = "survey";

// if this variable is set to 1,the window pops under rather than up, range: 1 or 0
var popUnder = 0;

// these are the dimensions of the pop up window
var popUpWidth = 410;
var popUpHeight = 500;

// the name of the persistent or session cookie to prevent multi-surveying in a given time period
var ckAlreadyShown = "foreseeSurveyShown";

// the name of the cookie that counts the minimum pages viewed with the trigger code in them
var ckStickyCount = "foreseePagesViewed";

// the name of the cookie that implements the surveying 'sample-percentage' algorithm
var ckSamplePercentage = "foreseeSamplePerc";

// this is the default value of customer passed parameters which can be overridden
// by additional JavaScript inside the selected page AFTER inclusion of this page
var customerParams = null;

// ************ don't modify below this line *************
// set persistent cookie expiration if we are using it, otherwise it is a session cookie
var expDate = new Date();
var now = new Date();
var persistentExpires = new Date();
persistentExpires.setTime(persistentExpires.getTime() + (resampleWait*60*1000));

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 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 DeleteCookie (name) {
    var exp = new Date();
    exp.setTime (exp.getTime() - 1);
    var cval = GetCookie (name);
    document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}

function getCookieVal(offset) {
    var endstr = document.cookie.indexOf (";", offset);
    if (endstr == -1)
        endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}

// check whether or not this browser supports focus() on windows
function supportsFocus() {
	// get user agent string
	var userAgent = navigator.userAgent;
	// find IE version label in user agent string if it exists
	var realMSVersionAt = userAgent.indexOf("MSIE");

	if (realMSVersionAt == -1) {
		// must be netscape
		return true;
	} else {
		// IE browser, see which one
		var nameAndVersion = userAgent.substring(realMSVersionAt, realMSVersionAt + 6);
		var realMSVersion = nameAndVersion.charAt(5);
		if(realMSVersion >= 5) {
			return true;
		} else {
			return false;
		}
	}
}

// special URL escapes for chars which don't escape using built-in
// escape() function in JavaScript. Currently these are '+', '/', '?', '='
// which are part of the Base64 character set
function specialEscape(s) {
	var encoded = "";
	
	// escape '+' characters
	var tokens = s.split('+');
	for(var i = 0; i < tokens.length; i++) {
		encoded += tokens[i];
		if(i < (tokens.length - 1)) {
			encoded += "%2B"; // %2B is the hex escape for '+'
		}
	}
	
	var t = encoded;
	encoded = "";
	// escape '/' characters
	var tokens = t.split('/');
	for(var i = 0; i < tokens.length; i++) {
		encoded += tokens[i];
		if(i < (tokens.length - 1)) {
			encoded += "%2F"; // %2F is the hex escape for '/'
		}
	}
	
	var t = encoded;
	encoded = "";
	// escape '?' characters
	var tokens = t.split('?');
	for(var i = 0; i < tokens.length; i++) {
		encoded += tokens[i];
		if(i < (tokens.length - 1)) {
			encoded += "%3F"; // %3F is the hex escape for '?'
		}
	}
	
	var t = encoded;
	encoded = "";
	// escape '=' characters
	var tokens = t.split('=');
	for(var i = 0; i < tokens.length; i++) {
		encoded += tokens[i];
		if(i < (tokens.length - 1)) {
			encoded += "%3D"; // %3D is the hex escape for '='
		}
	}
	
	return encoded;
}

function Poll() { // catch onUnload or onLoad event, set in page BODY tag

    if(disableTrigger == 1) {
        return;
    }

    var stickyCounter = GetCookie(ckStickyCount); // check counter cookie
    var alreadyShown = GetCookie(ckAlreadyShown); // check if we already have shown survey
    var pageCount;

    var randNum = Math.random();
    randNum *= 100;
    SetCookie(ckSamplePercentage, randNum); // only for diagnostics

    if (stickyCounter == null) {
        // no cookie, create a new one and set it to 1. We use this to monitor
        // stickiness
        pageCount=1;
        SetCookie(ckStickyCount, pageCount);
    } else {
        // already a cooke - see if we have reached the pages viewed requirement
        pageCount = stickyCounter;
        if(pageCount >= stickFactor) {
            // apply the samplingPercentage algorithm
            if(alreadyShown == null) {
            	// only if we haven't already served them a survey
                if(randNum <= samplePercentage) {
    	    	    var winOptions = "width=" + popUpWidth + ",height=" + popUpHeight + ",resizable=no,scrollbars=yes";
    	    	    if(customerParams != null) {
    	    	        fullURL += customerParams;
    	    	    }
    	    	    var fullURL = popUpURL + "?" + "cid=" + specialEscape(customerId) + "&mid=" + specialEscape(modelInstanceId);
 	            var myPopUp = window.open(fullURL, popUpWinName, winOptions);
		    if(supportsFocus()){
			    // handle pop-under functionality
			    if(popUnder == 1) {
				self.focus();
			    } else {
				myPopUp.focus();
			    }
		    }
	            // insure that we only pop up once during the lifetime of the cookie
	            if(noPersistentCookies == 1) {
	            	SetCookie(ckAlreadyShown, 'true',null,'/');
	            } else {
	            	SetCookie(ckAlreadyShown, 'true', persistentExpires,'/');
	            }
	        }
	    }
        }
        // increment it and set the new cookie value
        pageCount++;
        SetCookie(ckStickyCount, pageCount);
    }


}
