// Browser Sniffer
var doCheck = (document.all!=null);
if (doCheck == false) {
	versionNN = navigator.userAgent.toLowerCase();
	if (versionNN.search(/mozilla\/4/i) != -1) 
		browser = "NN4";
	else 
		browser = "NN6";
} else {
	var agt = navigator.userAgent.toLowerCase();
	if ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1)) 
		browser = "IE";
	else 
		browser = "OP";
}

// Image Preloader
navimgNames = new Array(
	"/images/top_nav/nav_on_business03.gif",
	"/images/top_nav/nav_on_foxfan03.gif",
	"/images/top_nav/nav_on_centralBug03.gif",
	"/images/top_nav/nav_on_foxlife03.gif",
	"/images/top_nav/nav_on_foxpolls03.gif",
	"/images/top_nav/nav_on_foxsports03.gif",
	"/images/top_nav/nav_on_politics03.gif",
	"/images/top_nav/nav_on_shows03.gif",
	"/images/top_nav/nav_on_topstories03.gif",
	"/images/top_nav/nav_on_views03.gif",
	"/images/top_nav/nav_on_weather03.gif",
	"/images/top_nav/nav_on_fea_oreillyfactor03.gif",
	"/images/top_nav/nav_on_fea_yourworld03.gif",
	"/images/top_nav/nav_on_fea_realestate03.gif",
	"/images/top_nav/nav_on_fea_jobs03.gif"
)
loadNavImgs = new Array();
for(i=0; i < navimgNames.length; i++) {
  loadNavImgs[i] = new Image;
  loadNavImgs[i].src = navimgNames[i];
}

// Rollover/out
function rollOver(name) {
	document.images[name].src = "/images/top_nav/nav_on_"+name+"03.gif";
}
function rollOut(name) {
	document.images[name].src = "/images/top_nav/nav_off_"+name+"03.gif";
}

// Hide/Show Layer Scripts for Shows Div
function getLayer(id) {        
   	if (browser == "IE" || browser == "OP")
   		return document.all[id];
	else if (browser == "NN4")
		return document.layers[id];
	else
		return document.getElementById(id);
}
function showLayer(id) {        
   var get = getLayer(id)
   if (get != null)          
     	if (browser != "NN4")
         	get.style.visibility = "visible";
      	else
         	get.visibility = "show";
}
function hideLayer(id) {
	var get = getLayer(id)        
	if (get != null)        
      if (browser != "NN4")
         get.style.visibility = "hidden";
      else
         get.visibility = "hide";
}
function closeShows() {
	hideLayer('showsDiv');
	rollOut('fncshows');
}
function openShows() {
	showLayer('showsDiv');
	rollOver('fncshows');
}

// Daughter Window Script
function pop(mypage, myname, w, h, scroll, menu) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no';
	if (menu=='yes')
		winprops += ',menubar=yes,toolbar=yes,locationbar=yes';
		
	win = window.open(mypage, myname, winprops);
	  if ((window.navigator.appName.indexOf("Microsoft")==0) &
	      (window.navigator.appVersion.substring(0,1)=="4"))
	  {
	    damnBrowser = 1;
	  }
	  else if ((window.navigator.appName.indexOf("Netscape")==0) &
	           (window.navigator.appVersion.substring(0,1)=="4"))
	  {
	    damnBrowser = 1;
	  }
	  else if (parseFloat(navigator.appVersion.substring(0,navigator.appVersion.indexOf("")))>=3.0)
	  {
	    if ((window.navigator.appName.indexOf("Microsoft")=="0") &
	        (window.navigator.userAgent.indexOf("Mac")>=0) & (parseFloat(navigator.appVersion.substring(0,navigator.appVersion.indexOf("")))<4.0))
	    { }
	    else
	    {
	      win.focus();
	    }
	}
}

// E-mail Address Validator
function isEmail(email) {
	emailArray = new Array ();
	if (email.search(/,/g) == -1 && email.search(/ /g) == -1) {
		emailArray[0] = email;
	} else if (email.search(/,/g) != -1) {
		emailArray = email.split(',');
	} else {
		return false
	}
	for (n=0;n<emailArray.length;n++) {
		emailAdd = emailArray[n].replace(/ /, "");
		atPos = emailAdd.indexOf("@"); 
		dotPos = emailAdd.lastIndexOf(".");
		lastPos = emailAdd.length-1;
		if (atPos < 1 || dotPos-atPos < 2 || lastPos-dotPos<2 || emailAdd.search(/ /g) != -1) {
			return false;
			break;
		} else {
			emailValidate = true;
		}
	}
	return emailValidate;
}

// Map Pop Script to launch daughter win w/ image
function mapPop(imageUrl,title,w,h) {
	if (doCheck && navigator.platform == "MacPPC"){
		w = w - 16;
		h = h - 16;
	}
	var dimensions = "width="+w+",height="+h; 
	var winName = title.replace(/ /g,""); 
	var title = title+" -- FOXNews.com"; 
	var win = window.open("",winName,dimensions); 
	var d = win.document; 
	d.writeln("<html>"); 
	d.writeln("<head><title>"+title+"</title></head>"); 
	d.writeln("<body marginheight=0 marginwidth=0 topmargin=0 leftmargin=0 onLoad=window.focus();>"); 
	d.writeln("<img src="+imageUrl+" border=0>"); 
	d.writeln("</body>"); 
	d.writeln("</html>"); 
	d.close(); 
}

// Video Player Launch Scripts (old & new)
function videoPlayer(vidName,headline){
	var vidUrl = "/video/get_cookie.htm?"+vidName+"&"+headline;
	pop(vidUrl,'vidPlayer',340,480,'no','no');
}
function videoPlayerNew(vidID,headline){
	headline = escape(headline);
	var vidUrl = "http://www.foxnews.com/video2/get_cookie.htm?"+vidID+"&"+headline;
	pop(vidUrl,'vidPlayer',340,480,'no','no');
}

// Reloads NN4 onResize to fix NN4/Uber-bug conflict
function nn4Reload() {
	if (browser == "NN4") {
		location.reload();
	}
}

// E-Comp form submission scripts
var action= "none";
function seteCompAction(button) {
	if (button == "coName") {
		document.images['coName'].src = "/images/ecp/ecomp_co_name03_on.gif";
		document.images['coSymbol'].src = "/images/ecp/ecomp_co_symbol03_off.gif";
	} else {
		document.images['coSymbol'].src = "/images/ecp/ecomp_co_symbol03_on.gif";
		document.images['coName'].src = "/images/ecp/ecomp_co_name03_off.gif";
	}
	action = button;
}
function eCompSubmit() {
	submitUrl = "http://www.ecomponline.com/Ecomp/foxnews/";
	if (document.eCompForm.defaultText.value == "") {
		alert("You must enter a company name or symbol to continue.");
	} else {
		if (action == "none") {
			alert("You must select your type of search before you can continue.");
		} else if (action == "coName") {
			window.location = submitUrl+"companies.tcl?dir=foxnews&compname="+document.eCompForm.defaultText.value;
		} else if (action == "coSymbol") {
			window.location = submitUrl+"company.tcl?dir=foxnews&symbol="+document.eCompForm.defaultText.value;
		}
	}
	return false;
}

// Poll Scripts
var pollAnswer = "none";
function new_poll_answer(answerPassed,type){
	if (type == "story") {
		imageFile = "btn_radio";
	} else {
		imageFile = "btn_con_radio";
	}
	if (pollAnswer != "none") {
		document.images[imgName].src = "/images/poll/"+imageFile+"_off.gif";
	}
	pollAnswer = answerPassed;
	imgName = "answer"+answerPassed;
	document.images[imgName].src = "/images/poll/"+imageFile+"_on.gif";
}
function new_popup_results(pollID,format) {
	resultsUrl = "http://www2.foxnews.com/polls/poll_results/bg_results_"+format+".jpg__basic_"+pollID+".htm";
	pop(resultsUrl,'pollVote','550','400','no','no');
}
function new_submit_vote(pollID,format) {
	if (pollAnswer == "none") {
		alert("You must vote to submit this poll.");
	} else {
		voteUrl = "http://www2.foxnews.com/polls/view.asp?pollid="+pollID+"&format="+format+"&answer="+pollAnswer;
		pop(voteUrl,'pollVote','550','400','no','no');
	}
}

// Photo Pop Script for Story Pages
function photoPop(photo,caption,credit,width) {
	var w = 440;
	var h = 375;
	if (doCheck && navigator.platform == "MacPPC"){
		w = w - 16;
		h = h - 16;
	}
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	var dimensions = 'height='+h+',width='+w+',top='+wint+',left='+winl+',resizable=\'no\'';
	if (width == 300) {
		var leftGut = 105;
		var topGut = 50;
		var rightCol = 335;
		var height = 200;
	} else {
		var leftGut = 160;
		var topGut = 10;
		var rightCol = 280;
		var height = 300;
	}
	if (caption.search(/%5C/g) != -1) {caption = caption.replace(/%5C/g,"");}
	if (credit.search(/%5C/g) != -1) {credit = credit.replace(/%5C/g,"");}
	var win = window.open('','foxPhoto',dimensions); 
	var d = win.document; 
	d.writeln("<html>"); 
	d.writeln("<head>");
	d.writeln("<title>FOXNews.com</title>");
	d.writeln("<LINK REL=STYLESHEET TYPE=\"text/css\" HREF=\"/basestyles2003.css\">"); 
	d.writeln("</head>"); 
	d.writeln("<body marginheight=0 marginwidth=0 topmargin=0 leftmargin=0 background=\"/images/bg_photo_popup.gif\" onLoad=\"window.focus();\">"); 
	d.writeln("<table cellpadding=0 cellspacing=0 border=0 width=440>");
	d.writeln("<tr>");
	d.writeln("<td><img src=\"/images/clear_dot.gif\" width="+leftGut+" height="+topGut+"></td>");
	d.writeln("<td><img src=\"/images/clear_dot.gif\" width="+rightCol+" height="+topGut+"></td>");
	d.writeln("</tr>");
	d.writeln("<tr>");
	d.writeln("<td><img src=\"/images/clear_dot.gif\" width="+leftGut+" height=10></td>");
	d.writeln("<td valign=\"top\">");
	d.writeln("<table cellpadding=0 cellspacing=0 border=0 width="+width+">");
	d.writeln("<tr><td><img src=\"/images/"+photo+"\" border=0 width="+width+" height="+height+"></td></tr>");
	if (credit != "") {d.writeln("<tr><td class=\"capblack\" align=\"right\">"+credit+"</td></tr>");}
	if (caption != "") {d.writeln("<tr><td class=\"capblack\">"+caption+"</td></tr>");}
	d.writeln("</table>");
	d.writeln("</td>");
	d.writeln("</tr>");
	d.writeln("</table>");
	d.writeln("</body>"); 
	d.writeln("</html>"); 
	d.close(); 
}

// FOX Fan Recognition Scripts
function getNameFromCookie() {
	var name = ""; 
    var crumb=unescape(document.cookie);
    if (crumb.indexOf("foxnews=") != -1) { 
		var start = crumb.indexOf("foxnews=") + 8;
		var end = crumb.indexOf(";", start);
		if (end == -1)
			var end = crumb.length;
		var thisCookie = crumb.substring(start,end);
		var cookAry = thisCookie.split("|");
		if (cookAry.length > 4) {
			var name = cookAry[4];
		}
	}
	return name;
}
function regWinHeight() {
	macPlat = false;
	if (navigator.platform == "MacPPC") {macPlat = true;}
	if (browser == "NN6") {
		ht = 385;
	} else if (browser == "NN4" && !macPlat) {
		ht = 405;
	} else if (browser == "NN4" && macPlat) {
		ht = 355;
	} else if (browser == "OP") {
		ht = 375;
	} else {
		ht = 395;
	}
	return ht;
}
function ffRegister(page) {
	ht = regWinHeight();
	if (page == "register") {
		regUrl = "http://www3.foxnews.com/foxfanv3/reg_screen1.asp";
	} else {
		regUrl = "http://www3.foxnews.com/foxfanv3/reg_screen1.asp?type=modify";
	}
	pop(regUrl,'foxfanReg',730,ht,'no','no');
}
function ffImage() {
	if (getNameFromCookie() != "") {
		document.writeln("<td><a href=\"/foxfan/index.html\" onMouseover=\"rollOver('centralBug');\" onMouseout=\"rollOut('centralBug');\"><img src=\"/images/top_nav/nav_off_centralBug03.gif\" name=\"centralBug\" border=0 width=85 height=72></a></td>");
	} else {
		document.writeln("<td><a href=\"/foxfan/index.html\" onMouseover=\"rollOver('foxfan');\" onMouseout=\"rollOut('foxfan');\"><img src=\"/images/top_nav/nav_off_foxfan03.gif\" name=\"foxfan\" border=0 width=85 height=72></a></td>");
	}
}
function ffMember() {
	if (getNameFromCookie() != "") {
		document.writeln("<div class=\"uberRed\" style=\"width:159px;\"><b>Welcome "+getNameFromCookie()+"</b></div><div class=\"capblack\" style=\"line-height: 10px;\"><a href=\"javascript:ffRegister('register');\">Not You? Click Here.</a></div>");
	} else {
		document.writeln("<div class=\"uberRed\" style=\"width:159px;\"><a href=\"/foxfan/\"><b>FOX Fans Log on Here</b></a></div><div class=\"capblack\" style=\"line-height: 10px;\"><a href=\"/foxfan/\">or Register Now.</a></div>");
	}
}
// FoxFan Video Player for Non-FoxFan Pages
function foxfanVideoPlayer(vidID,headline) {
	if (getNameFromCookie() != "") {
		videoPlayerNew(vidID,headline);
	} else {
		ht = regWinHeight();
		headline = headline.replace(/ /g,"_");
		regUrl = "http://www3.foxnews.com/foxfanv3/reg_screen1.asp?type=video&videoId="+vidID+"&vidHead="+headline;
		pop(regUrl,'foxfanReg',730,ht,'no','no');
	}
}

function emailFriend()
{
    if (document.emailFriend.byline.value == "none")
    {
        document.emailFriend.byline.value = "FOXNews";
    }
    if (window.location == "http://www.foxnews.com/story/0,2933,18502,00.html" || window.location == "http://www.foxnews.com/story/0,2933,20055,00.html")
    {
        document.emailFriend.date.value = "";
    }
    document.emailFriend.url.value = window.location;
    document.emailFriend.submit();
}

function foxnews_setHomePage() {
	if (browser == 'IE') {
		version = navigator.appVersion.toLowerCase();
		if (( version.search (/macintosh/) == -1)
		&& (version.search (/msie 4/) == -1))
		{
			makehome.style.behavior='url(#default#homepage)';makehome.setHomePage("http://www.foxnews.com");
		}
		else {
			window.location = "/story/0,2933,80231,00.html";
		}
	}
	else {
		window.location = "/story/0,2933,80231,00.html";
	}
}

// Scroll Function for Search Text Box
searchInt = -1;
scrolling = true;
function searchScroll(state) {
	if (scrolling) {
		if (state == 'ongoing') {
			textBox = document.searchForm.ext_qkw.value;
			newBox = textBox.slice(1,(textBox.length));
			document.searchForm.ext_qkw.value = newBox+textBox.charAt(0);
			searchInt = setTimeout("searchScroll('ongoing')", 400);
		} else {
			//document.searchForm.ext_qkw.value = " FOX News and Web: sources include Google, Ask Jeeves, WebCrawler. . .";
			searchInt = setTimeout("searchScroll('ongoing')", 3000);
		}
	}
}
// Search Validation Script Below
function searchSub() {
	if (scrolling || document.searchForm.ext_qkw.value.length == 0) {
		alert("Please enter text into the text field.");
		return false;
	} else {
		return true;
	}
}
function searchFocus() {
	if (scrolling) {
		document.searchForm.ext_qkw.value='';
		scrolling = false;
		if (searchInt!=-1) {
			clearTimeout(searchInt);
		}
	}
}

