// Global and common routines for NY Metro

var browserType = (navigator.appName.substring(0,8) + parseFloat(navigator.appVersion)).toLowerCase();
var browserClass = navigator.appName.substring(0,8) + parseFloat(navigator.appVersion.substring(0,1));

// Globals for Discrete Site Sections

var gHome=0;
var gNews=1;
var gFood=2;
var gShops=3;
var gUrban=4;
var gArts=5;
var gBestOf=6;
var gRealEstate=7;
var gTravel=8;
var gDoctors=9;
var gPersonals=10;
var gMovies=11;
var gAList = 18;
var gFFF = 20;
var gTest = 21;
var gMetroTV = 22;
var gsumhot = 23;
var gPromo = 24;
var gSpringstreet = 25;
var gClassifieds = 26;


var gInSection=gHome; // section global
var gAdTag=''; // Ad tag for targeting
var gSprinksTag='id=homepage&guidesite=gonyc'; // Sprinks customization tag

function SetSection( iAsSection ) {
	gInSection=iAsSection;
	if (iAsSection==gHome) {
		gAdTag='homepage';
		gSprinksTag='id=homepage&guidesite=gonyc&type=2';
		gPixTrax.SetUC2('HomePage'); }
	else if (iAsSection==gNews) {
		gAdTag='news';
		gSprinksTag='id=news&guidesite=news'; 
		gPixTrax.SetUC2('News'); }
	else if (iAsSection==gFood) {
		gAdTag='restaurants';
		gSprinksTag='id=restaurants&guidesite=gonyc'; 
		gPixTrax.SetUC2('Restaurants'); }
	else if (iAsSection==gShops) {
		gAdTag='shopping';
		gSprinksTag='id=shopping&guidesite=onlineshopping'; 
		gPixTrax.SetUC2('Shopping'); }
	else if (iAsSection==gUrban) {
		gAdTag='living';
		gSprinksTag='id=savvy&guidesite=fashion'; 
		gPixTrax.SetUC2('UrbanStrategist'); }
	else if (iAsSection==gArts) {
		gAdTag='arts';
		gSprinksTag='id=ae&guidesite=gonyc'; 
		gPixTrax.SetUC2('Arts'); }
	else if (iAsSection==gMovies) {
		gAdTag='movies';
		gSprinksTag='id=ae&guidesite=gonyc'; 
		gPixTrax.SetUC2('Movies'); }
	else if (iAsSection==gBestOf) {
		gAdTag='bony';
		gSprinksTag='id=savvy&guidesite=fashion'; 
		gPixTrax.SetUC2('BestOfNewYork'); }
	else if (iAsSection==gRealEstate) {
		gAdTag='realestate';
		gSprinksTag='id=restaurants&guidesite=gonyc'; 
		gPixTrax.SetUC2('RealEstate'); }
	else if (iAsSection==gTravel) {
		gAdTag='travel';
		gSprinksTag='id=travel&guidesite=gonyc'; 
		gPixTrax.SetUC2('Travel'); }
	else if (iAsSection==gDoctors) {
		gAdTag='doctors';
		gSprinksTag='id=savvy&guidesite=fashion'; 
		gPixTrax.SetUC2('BestDoctors'); }
	else if (iAsSection==gPersonals) {
		gAdTag='personals'; 
		gPixTrax.SetUC2('Personals'); }
	else if (iAsSection==gAList) {
		gAdTag='alistNL'; 
		gPixTrax.SetUC2('AList'); }
	else if (iAsSection==gFFF) {
		gAdTag='FFF'; 
		gPixTrax.SetUC2('FFF'); }
	else if (iAsSection==gTest) {
		gAdTag='test';
		gSprinksTag='id=restaurants&guidesite=gonyc'; 
		gPixTrax.SetUC2('Test'); }
	else if (iAsSection==gMetroTV) {
		gAdTag='MetroTV';
		gSprinksTag='id=shopping&guidesite=onlineshopping'; 
		gPixTrax.SetUC2('MetroTV'); }
	else if (iAsSection==gsumhot) {
		gAdTag='sumhot'; 
		gPixTrax.SetUC2('sumhot'); }
else if (iAsSection==gSpringstreet) {
		gAdTag='springstreet';
		gSprinksTag='id=savvy&guidesite=fashion'; 
		gPixTrax.SetUC2('StrictlyPersonal'); }
	else if (iAsSection==gPromo) {
		gAdTag='Promo'; 
		gPixTrax.SetUC2('Promo'); }
else if (iAsSection==gClassifieds) {
		gAdTag='Classifieds';
		gSprinksTag='id=restaurants&guidesite=gonyc'; 
		gPixTrax.SetUC2('ClassifiedsGooglePage'); }
	else {
		gAdTag=''; }
}

// End of Site Sections

function Is() {
	agent = navigator.userAgent.toLowerCase();
	this.major = parseInt(navigator.appVersion);
	this.minor = parseFloat(navigator.appVersion);
	this.ie = (agent.indexOf("msie") != -1);
	this.ie4 = (this.ie && (this.major == 4) && (agent.indexOf("msie 4.0") != -1));
	this.ie45 = (this.ie && (this.major == 4) && (agent.indexOf("msie 4.5") != -1));
}

var is = new Is();
var is_ns4mac=false;

if((navigator.appName.indexOf("Netscape") != -1) &&
  (navigator.userAgent.indexOf("Mac") != -1) &&
  (parseInt(navigator.appVersion) < 5))
	  is_ns4mac = true;

// Function to link to correct database search page
function jumpPage(newLoc) {
        newPage = newLoc.options[newLoc.selectedIndex].value
        if (newPage !="") { window.location.href = newPage }
}  

function WriteStyleSheet(AsInternal) {
	var sCSSFileName= ((AsInternal)?'/':'http://www.nymetro.com/') + 'style/style';
	if ((navigator.appVersion.toLowerCase().indexOf('mac') != -1) && ((navigator.appName == 'Netscape') || (is.ie4) || (is.ie45))) 
		sCSSFileName+='_mac';
	// LINK to correct stylesheet
    document.write('<link rel="stylesheet" href="'+sCSSFileName+'.css" type="text/css">');
}

// Nav Bar Functions
function fGo_Base(iAsSection, FullPath) {
	// Default page is home page.

	var hRef='/index.htm';

	if (iAsSection==gHome) 
		hRef='/'
	else if (iAsSection==gNews)
		hRef='/news/'
	else if (iAsSection==gFood)
		hRef='/restaurants/'
	else if (iAsSection==gShops)
		hRef='/shopping/'
	else if (iAsSection==gUrban)
		hRef='/urban/'
	else if (iAsSection==gArts)
		hRef='/arts/'
	else if (iAsSection==gBestOf)
		hRef='/urban/guides/bestofny/'
	else if (iAsSection==gRealEstate)
		hRef='/realestate/'
	else if (iAsSection==gTravel)
		hRef='/travel/'
	else if (iAsSection==gDoctors)
		hRef='/bestdoctors/'
	else if (iAsSection==gPersonals)
		hRef='/personals/';
	else if (iAsSection==gMovies)
		hRef='/movies/';

	// go to that page
	top.location.href = ((FullPath)?'http://www.newyorkmetro.com':'')+hRef;
	return false;
}

function fGo(iAsSection) {
	fGo_Base(iAsSection,false);
}
function fGoNYMag(iAsSection) {
	fGo_Base(iAsSection,true);
}

// Pixel Tracking Class (no personally identifiable data tracked)
function cPixelTracker(){
	this.xlref=function(rfr){
		var g=/google%2e/i;
		var n=/(newyorkmetro%2e|nymag%2e|nymetro%2e|newyorkmag%2e|metronewyork%2e|newyorkmagazine%2e)/i;
		var a=/about%2e/i;
		var p='http%3a%2f%2fwww%2e';
		if (g.test(rfr)) return (p+'google%2ecom%2f'); if (n.test(rfr)) return (p+'newyorkmetro%2ecom%2f'); if (a.test(rfr)) return (p+'about%2ecom%2f');
		return rfr;
	}
	this.ConsolidateUnder='metronewyork.com';
//	this.HTTP_REFERER=(arguments.length>0)?'&ref='+this.xlref(arguments[0]):'';
	this.HTTP_REFERER=(arguments.length>0)?'&ref='+arguments[0]:'';
	this.DOCUMENT_URI='&pg=' + ((arguments.length>1)?arguments[1]:(location.pathname+location.search));
	this.UC1='&uc1='+((arguments.length>2)?arguments[2]:'metronewyork.com');
	this.UC2='&uc2=Unclassified';
	this.LC1='';
	this.LC2='';
	this.pixelpath='http://prmpix.about.com/pixel.cgi';
	// Methods
	this.PixelImage=function() {
		var hostn=location.host.toLowerCase();
		var r=/(preview\.|staging\.|mny-web1)/i;
		if ( r.test(hostn) ) return ''; else {
			var s='<img src="'+this.pixelpath+'?dom='+this.ConsolidateUnder+this.DOCUMENT_URI+this.HTTP_REFERER+this.UC1+this.UC2+this.LC1+this.LC2+'" height=1 width=1>';
			return s;
		}
	}
	this.TrackIt=function(){document.write(this.PixelImage());}
	this.SetUC1=function(v){this.UC1='&uc1='+v;}
	this.SetUC2=function(v){this.UC2='&uc2='+v;}
	this.SetURI=function(v){this.DOCUMENT_URI='&pg='+v;}
	this.SetLC1=function(v){this.LC1='&lc1='+v;}
	this.SetLC2=function(v){this.LC2='&lc2='+v;}
}
