/* if (location.host.search(/newzboard.com/) != -1){
	nbsite = 'http://www.newzboard.com';
}
if (location.host.search(/planavsky.com/) != -1){
	nbsite = 'http://test.planavsky.com/newzboard';
}
if (location.host.search(/127.0/) != -1){
	nbsite = 'http://127.0.0.1:8500/newzboard';
} */

nbsite = 'http://www.newzboard.com';

var overlayHeight;
var viewportwidth;
var viewportheight;
 
initNewzboard();

function initNewzboard(){
 
 var bwin = new browserWindow();
 overlayHeight = bwin.viewportheight - 50;
 
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 if (typeof window.innerWidth != 'undefined')
 {
	  //alert(getScrollerWidth());
	  
	  viewportwidth = window.innerWidth - getScrollerWidth(),
	  viewportheight = window.innerHeight
 }
 // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
 else if (typeof document.documentElement != 'undefined'
	 && typeof document.documentElement.clientWidth !=
	 'undefined' && document.documentElement.clientWidth != 0)
 {
	   viewportwidth = document.documentElement.clientWidth,
	   viewportheight = document.documentElement.clientHeight
 }
 // older versions of IE
 else
 {
	   viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
	   viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }
}

var tempcolor_newzboardBackground = newzboardBackground.replace("#","pound");
var tempcolor_newzboardText = newzboardText.replace("#","pound");
var tempcolor_newzboardLink = newzboardLink.replace("#","pound");
var tempcolor_newzboardLinkhover = newzboardLinkhover.replace("#","pound");

document.write('<style type="text/css">DIV#newzboard_mainwindow_' + newzboardmyid + ' { position:fixed; z-index:10000; background-color:#000; height:' + overlayHeight + 'px; width:850px; top:0px; left:0px; border:2px solid #888; display:none; -moz-border-radius: 12px; border-radius: 12px; } DIV#newzboard_mainwindow_shadow { position:fixed; z-index:9000; background-color:#000000; filter:alpha(opacity=65);-moz-opacity:.65;opacity:.65; top:0px; left:0px; display:none; } DIV#newzboardIframe_' + newzboardmyid + ' A.newzboard_link_color { color:' + newzboardLink + '; font-weight:normal; text-decoration:underline; } DIV#newzboardIframe_' + newzboardmyid + ' A.newzboard_link_color:HOVER { color:' + newzboardLinkhover + '; text-decoration:underline; } DIV#newzboard_mainwindow_' + newzboardmyid + ' A { color:' + newzboardLink + '; } DIV#newzboard_mainwindow_' + newzboardmyid + ' A:HOVER { color:' + newzboardLinkhover + '; }</style>');
/*document.write('<div id="newzboard_mainwindow_shadow" style="display: none;"></div>');
document.write('<div id="newzboard_mainwindow_' + newzboardmyid + '" style="display: none;"><div onclick="newzboard_closeWindow(\'' + newzboardmyid + '\');" style="background-color:black; color:white; text-align:right; font-size:10px; padding:4px; font-weight:bold; cursor: pointer; font-family:arial;" id="newzboard_close"><span style="color:red;" id="newzboard_close_span">X</span> Close Window</div><div id="newzboard_newspost_' + newzboardmyid + '"></div></div>');*/

if (searchHTML() == true){
    document.write('<style type="text/css">DIV#newzboard_mainwindow_' + newzboardmyid + ' { position:absolute; } DIV#newzboard_mainwindow_shadow { position:absolute; }</style>');
}

var newzboard_shadow=document.createElement('div');
newzboard_shadow.setAttribute('id','newzboard_mainwindow_shadow');
document.getElementsByTagName('body')[0].appendChild(newzboard_shadow)
var newzboard_window=document.createElement('div');
newzboard_window.setAttribute('id','newzboard_mainwindow_' + newzboardmyid);
document.getElementsByTagName('body')[0].appendChild(newzboard_window);
document.getElementById('newzboard_mainwindow_' + newzboardmyid).innerHTML = '<div onclick="newzboard_closeWindow(\'' + newzboardmyid + '\');" style="background-color:black; color:white; text-align:right; font-size:10px; padding:4px; font-weight:bold; cursor: pointer; font-family:arial; -moz-border-radius: 12px; border-radius: 12px;" id="newzboard_close"><span style="color:red;" id="newzboard_close_span">X</span> Close Window</div><div id="newzboard_newspost_' + newzboardmyid + '"></div>';

document.getElementById('newzboard_mainwindow_shadow').style.height = viewportheight + 'px';
document.getElementById('newzboard_mainwindow_shadow').style.width = viewportwidth + 'px';

var newzboardHeight = newzboardHeight - 14;
document.write('<div style=\"padding:0px; float:none; margin:0px auto 0px auto; width:' + newzboardWidth + 'px;\"><div id=\"newzboardIframe_' + newzboardmyid + '\" style=\"position:relative; float:none; height:' + newzboardHeight + 'px; width:' + newzboardWidth + 'px; background-color:' + newzboardBackground +'; text-align:left;\"></div>');
document.write('<iframe width=\"' + newzboardWidth + 'px\" height=\"14px\" style=\"border:0px;\" src =\"' + nbsite + '/newsfooter.cfm?id=' + newzboardmyid + '&backgroundcolor=' + tempcolor_newzboardBackground + '&textcolor=' + tempcolor_newzboardText + '&linkcolor=' + tempcolor_newzboardLink + '&linkhovercolor=' + tempcolor_newzboardLinkhover + '\" frameborder=\"0\" scrolling=\"no\" id=\"newzboardIframeFooter\"></iframe></div>');

function sendRequest(id){
    // create <script> element
    var js=document.createElement('script');
    // assign <script> attributes
    js.setAttribute('language','javascript');
    //js.setAttribute('src','http://test.planavsky.com/newzboard/convertdata.cfm?id=' + id + '&textcolor=' + newzboardText + '&linkcolor=' + newzboardLink + '&linkhovercolor=' + newzboardLinkhover + '&numberOfPosts=' + newzboardNumberOfPosts + '&backgroundcolor=' + newzboardBackground);
	js.setAttribute('src',nbsite + '/convertdata.cfm?id=' + id + '&textcolor=' + tempcolor_newzboardText + '&numberOfPosts=' + newzboardNumberOfPosts + '&backgroundcolor=' + tempcolor_newzboardBackground);
    // append element to document tree & send GET request
    document.getElementsByTagName('head')[0].appendChild(js);
}

sendRequest(newzboardmyid);

function newzboard_positionWindow(postnewzid){
			       
	userScreenWidth = viewportwidth;
	userScreenHeight = viewportheight;
	
	//alert(userScreenWidth + '    ' + userScreenHeight);
	
	/* setTop = ((userScreenHeight - 600)/2) - 100; */
	//setTop = ((userScreenHeight - 505)/2);
	setTop = 22;
	setLeft = ((userScreenWidth - 850)/2);
	
	//alert(setTop);
	//alert(setLeft);
	
	top.document.getElementById('newzboard_mainwindow_' + postnewzid).style.top = setTop + 'px';
	top.document.getElementById('newzboard_mainwindow_' + postnewzid).style.left = setLeft + 'px';
	
}

function newzboard_positionWindow_shadow(){

	userScreenWidth = viewportwidth;
	userScreenHeight = viewportheight;
	
	//alert(userScreenWidth + '    ' + userScreenHeight);
	
	setTop = ((userScreenHeight - 575)/2) - 100;
	setLeft = ((userScreenWidth - 850)/2);
	
	setTop = setTop + 7;
	setLeft = setLeft - 7;
	
	//alert(setTop);
	//alert(setLeft);
	
	top.document.getElementById('newzboard_mainwindow_shadow').style.top = setTop + 'px';
	top.document.getElementById('newzboard_mainwindow_shadow').style.left = setLeft + 'px';
	
}

function newzboard_closeWindow(postnewzid){
	//turnOffBg('show');
	top.document.getElementById('newzboard_mainwindow_' + postnewzid).style.display = 'none';
	top.document.getElementById('newzboard_mainwindow_shadow').style.display = 'none';
}

function searchHTML(){
   var absolute = false;
   for (i=0;i<document.getElementsByTagName('*').length;i++){
       if (document.getElementsByTagName('*')[i].style.position == 'absolute'){
          var absolute = true;
          break;
       }
   }
   return absolute;
}

function turnOffBg(action){
	for (i=0;i<document.getElementsByTagName('*').length;i++){
		if (document.getElementsByTagName('*')[i].id.search(/newzboard/) != -1){
			if (action == 'hide'){
				document.getElementsByTagName('*')[i].style.visibility = 'visible';
			}
		}else{
			if (action == 'hide'){
				document.getElementsByTagName('*')[i].style.visibility = 'hidden';
			}else{
				document.getElementsByTagName('*')[i].style.visibility = 'visible';
			}
		}
	}
}

function newzboard_openWindow(myid, newspostid, site, posttextcolor, postbackgroundcolor, postnewzid){
	newzboard_positionWindow(postnewzid);         
	//newzboard_positionWindow_shadow();
	
	//turnOffBg('hide');
	
//document.getElementById('newzboard_newspost').innerHTML = '<iframe src =\"' + site + '/newspost.cfm?id=' + myid + '&newspostid=' + newspostid + '&textcolor=' + newzboardText + '&linkcolor=' + newzboardLink + '&linkhovercolor=' + newzboardLinkhover + '&numberOfPosts=' + newzboardNumberOfPosts + '&backgroundcolor=' + newzboardBackground + '\" width=\"100%\" height=\"480px\"  frameborder=\"0\"></iframe>';
	 // create <script> element
    var js=document.createElement('script');
    // assign <script> attributes
   js.setAttribute('language','javascript');
    //js.setAttribute('src',site + '/newspost.cfm?id=' + myid + '&newspostid=' + newspostid + '&textcolor=' + newzboardText + '&linkcolor=' + newzboardLink + '&linkhovercolor=' + newzboardLinkhover + '&numberOfPosts=' + newzboardNumberOfPosts + '&backgroundcolor=' + newzboardBackground);
	js.setAttribute('src',site + '/newspost.cfm?id=' + myid + '&newspostid=' + newspostid + '&textcolor=' + posttextcolor + '&numberOfPosts=' + newzboardNumberOfPosts + '&backgroundcolor=' + postbackgroundcolor + '&overlayHeight=' + overlayHeight);
    // append element to document tree & send GET request
    document.getElementsByTagName('head')[0].appendChild(js);
	

	window.scrollTo(0,0);

	document.getElementById('newzboard_mainwindow_' + postnewzid).style.display = 'block';
	document.getElementById('newzboard_mainwindow_shadow').style.display = 'block';

} 

function newzboard_openShareWindow(myid, site, posttextcolor, postbackgroundcolor, postnewzid){
	newzboard_positionWindow(postnewzid);
    var js=document.createElement('script');
    js.setAttribute('language','javascript');
	js.setAttribute('src',site + '/newspost.cfm?id=' + myid + '&textcolor=' + posttextcolor + '&numberOfPosts=' + newzboardNumberOfPosts + '&backgroundcolor=' + postbackgroundcolor + '&shareview&postnewzid=' + postnewzid + '&overlayHeight=' + overlayHeight);
    // append element to document tree & send GET request
    document.getElementsByTagName('head')[0].appendChild(js);
	
	window.scrollTo(0,0);

	document.getElementById('newzboard_mainwindow_' + postnewzid).style.display = 'block';
	document.getElementById('newzboard_mainwindow_shadow').style.display = 'block';
} 

function openBrWindow(theURL,winName,width,height,features) { //v2.0
  
 // Fudge factors for window decoration space.
  // In my tests these work well on all platforms & browsers.
  w = width + 32;
  h = height + 96;

  wleft = (screen.width - w) / 2;
  wtop = (screen.height - h) / 2;
  // IE5 and other old browsers might allow a window that is
  // partially offscreen or wider than the screen. Fix that.
  // (Newer browsers fix this for us, but let's be thorough.)
  if (wleft < 0) {
    w = screen.width;
    wleft = 0;
  }
  if (wtop < 0) {
    h = screen.height;
    wtop = 0;
  }
  var win = window.open(theURL,
    winName,
    'width=' + w + ', height=' + h + ', ' +
    'left=' + wleft + ', top=' + wtop + ', ' +
    features);


  // Just in case width and height are ignored
  win.resizeTo(w, h);
  // Just in case left and top are ignored
  win.moveTo(wleft, wtop);
  win.focus();
  
}

function getScrollerWidth() {
    var scr = null;
    var inn = null;
    var wNoScroll = 0;
    var wScroll = 0;

    // Outer scrolling div
    scr = document.createElement('div');
    scr.style.position = 'absolute';
    scr.style.top = '-1000px';
    scr.style.left = '-1000px';
    scr.style.width = '100px';
    scr.style.height = '50px';
    // Start with no scrollbar
    scr.style.overflow = 'hidden';

    // Inner content div
    inn = document.createElement('div');
    inn.style.width = '100%';
    inn.style.height = '200px';

    // Put the inner div in the scrolling div
    scr.appendChild(inn);
    // Append the scrolling div to the doc
    document.body.appendChild(scr);

    // Width of the inner div sans scrollbar
    wNoScroll = inn.offsetWidth;
    // Add the scrollbar
    scr.style.overflow = 'auto';
    // Width of the inner div width scrollbar
    wScroll = inn.offsetWidth;

    // Remove the scrolling div from the doc
    document.body.removeChild(
        document.body.lastChild);

    // Pixel width of the scroller
    return (wNoScroll - wScroll);
}


function browserWindow(){
	this.viewportwidth;
	this.viewportheight;
	this.scrollheight;
	this.browsertype;
	
	// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
	if (typeof window.innerWidth != 'undefined')
	{
	  this.viewportwidth = window.innerWidth,
	  this.viewportheight = window.innerHeight
	  this.scrollheight = document.getElementsByTagName('html')[0].offsetHeight;
	  this.browsertype = 1;
	}
	// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
	else if (typeof document.documentElement != 'undefined'
	 && typeof document.documentElement.clientWidth !=
	 'undefined' && document.documentElement.clientWidth != 0)
	{
	   this.viewportwidth = document.documentElement.clientWidth,
	   this.viewportheight = document.documentElement.clientHeight
	   this.scrollheight = document.getElementsByTagName('html')[0].offsetHeight;
	   this.browsertype = 2;
	}
	// older versions of IE
	else
	{
	   this.viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
	   this.viewportheight = document.getElementsByTagName('body')[0].clientHeight
	   this.scrollheight = document.getElementsByTagName('body')[0].offsetHeight;
	   this.browsertype = 3;
	}
	
	if (this.scrollheight < this.viewportheight){
		this.scrollheight = this.viewportheight;
	}

}

//document.body.setAttribute('onresize', 'reinitNewzboard();newzboard_positionWindow("' + newzboardmyid + '");');
var currheight;
window.onresize = function(){
	if(currheight != document.documentElement.clientHeight)
	{
		//alert('resized');	
		reinitNewzboard();
		newzboard_positionWindow(newzboardmyid);
	}
	currheight = document.documentElement.clientHeight;
}

function reinitNewzboard(){
	initNewzboard();
	document.getElementById('newzboard_mainwindow_shadow').style.height = viewportheight + 'px';
	document.getElementById('newzboard_mainwindow_shadow').style.width = viewportwidth + 'px';
	document.getElementById('newzboard_mainwindow_' + newzboardmyid).style.height = overlayHeight + 'px';
	document.getElementById('newzboard_newspost_' + newzboardmyid).getElementsByTagName("div")[0].style.height = overlayHeight - 88 + 'px';
	document.getElementById('newzboard_newspost_' + newzboardmyid).getElementsByTagName("div")[2].style.height = overlayHeight - 135 + 'px';
}

var js=document.createElement('script');
js.setAttribute('language','javascript');
js.setAttribute('src',nbsite + '/stats/log.cfm?siteurl=' + location.protocol + '//' + location.host + location.pathname);
document.getElementsByTagName('body')[0].appendChild(js); 

