// set uniqueWin to false initially -- function will check it again when called
//   uniqueWin must be set to true **AFTER** this script is included in the page calling the function
var uniqueWin = false;

var page;

function popup(path,w,h,wresizeable,wtop,wleft,wmenubar,wtoolbar,wlocation,wscrollbars,wstatus) {
	// setup defaults for everything but path, w, h
	if (wresizeable != "no") wresizeable = "yes";
	if (!wtop) wtop = 20;
	if (!wleft) wleft = 20;
	if (wmenubar != "yes") wmenubar = "no";
	if (wtoolbar != "yes") wtoolbar = "no";
	if (wlocation != "yes") wlocation = "no";
	if (wscrollbars == "yes") {
		w += 16; 
		h += 16;
	}
	if (wstatus != "yes") wstatus = "no";
	
	// Set window name
	var windowName = "newWin";
	// check flag for unique windows
	if ((uniqueWin != 'undefined') && (uniqueWin)) {
		winIndex = parseInt(Math.random() * 100000);
		windowName = 'window' + winIndex;
		// alert(windowName); // left in for testing purposes
	}
	
	// Open the window and set the parameters
	newWin = window.open(path,windowName,"width=" + w + ",innerwidth="+ w + ",height=" + h + ",innerHeight="+ h + ",resizable=" + wresizeable + ",top=" + wtop + ",pixelTop=" + wtop + ",left=" + wleft + ",pixelLeft=" + wleft + ",menubar=" + wmenubar + ",toolbar=" + wtoolbar + ",location=" + wlocation + ",scrollbars=" + wscrollbars + ",status=" + wstatus);
	
	// focus the window
	newWin.focus();
}

var nn4x = false; var ie = false; var w3c = false; // some browser varialbes
if (document.all) { ie = true; } // browser is ie4+
else if (document.layers) { nn4x = true; } // browser is ns4.x 
else if (document.getElementById) { w3c = true; } // browser is ns6, ns7, mozilla, or other w3c standard browser
// browser NS6+ code (ie5+ also supports this syntax, but we already took care of IE)
else { w3c = true; }// last/default case to w3c standards
    
function LTrim(str) { // trim space from the lhs
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(0)) != -1) {
    var j=0, i = s.length;
    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
      j++;
      s = s.substring(j, i);
  }
  return s;
}
function RTrim(str) { // trim space from the rhs
  var whitespace = new String(" \t\n\r");
  var s = new String(str);
  if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
    var i = s.length - 1;
    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
      i--;
      s = s.substring(0, i+1);
  }
  return s;
}
function Trim(str) { // trim space from both sides
  return RTrim(LTrim(str));
}
    
function over(name) { // onmouseover of an image
  if (document.images) { document[name].src = eval(name + '_r.src'); }
}

function out(name) { // onmouseout of an image
  if (document.images) { document[name].src = eval(name + '_n.src'); }
}

function which_css() { // which ccs file to use
  // nn4.x font has to be one px bigger, plus any positioning can be different
  if (nn4x) { return '<link rel="stylesheet" type="text/css" href="/css/nn4x.css">' }
  else { return '<link rel="stylesheet" type="text/css" href="/css/brow.css">' }
}

function visitor() {
  if (w3c || ie) { vis = '<div id="vis" style="position:absolute; top:462px; left:42px;"><table width="100" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF"><tr><td valign="top" align="center"><span class="hotlist2">v i s i t o r s</span><br /><br /></td></tr></table></div>'; }
  else { vis = '<span class="hotlist2">v i s i t o r s</span>'; }
  return vis;
}

function air(where) { /* popup window to advertise the airfare for nationals */
  var ref = document.referrer;
  var tmp = document.location.href;
  if ( (ref.indexOf('njdancesportclassic.com') == -1) || (tmp.indexOf('air') != -1) ){
    var windowName = 'airWin';
    tp = 100; lft = 100; /* top and left position */
    var agt = navigator.userAgent.toLowerCase(); var is_aol = (agt.indexOf("aol") != -1);
    if (is_aol) { tp = 0; lft = 0; /* positioning doesn't work well in aol */ }
    airWin = window.open('air.html?wh=' + where,windowName,'width=300,height=160,top=' + tp + ',left=' + lft + ',status=yes,location=yes');
    airWin.focus();
  }
}

function pre(where) { /* popup window to advertise the pre-bronze events */
  var ref = document.referrer;
  var tmp = document.location.href;
  if ( (ref.indexOf('njdancesportclassic.com') == -1) || (tmp.indexOf('pre') != -1) ){
    var windowName = 'preWin';
    tp = 100; lft = 100; /* top and left position */
    var agt = navigator.userAgent.toLowerCase(); var is_aol = (agt.indexOf("aol") != -1);
    if (is_aol) { tp = 0; lft = 0; /* positioning doesn't work well in aol */ }
    airWin = window.open('pre.html?wh=' + where,windowName,'width=300,height=200,top=' + tp + ',left=' + lft);
    airWin.focus();
  }
}

