/*Copyright Bridgeline Software, Inc. An unpublished work created in 2007. All rights reserved. 
This software contains the confidential and trade secret information of Bridgeline Software, Inc. 
("Bridgeline").  Copying, distribution or disclosure without Bridgeline's express written permission is prohibited.*/
// Find Browser Dimention
// Copyright Stephen Chapman, 3rd Jan 2005, 8th Dec 2005

function pageWidth(){
	return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}
   
function pageHeight(){
	return window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
} 

function posLeft(){
	return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
} 

function posTop(){
    return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
} 

function posRight(){
    return posLeft()+pageWidth();
}

function posBottom(){
    return posTop()+pageHeight();
}

//Scroll Height and Width
function getPageHeightWithScroll(){
	if (window.innerHeight && window.scrollMaxY) {// Firefox
		yWithScroll = window.innerHeight + window.scrollMaxY;
	}else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		yWithScroll = document.body.scrollHeight;
	}else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		yWithScroll = document.body.offsetHeight + document.body.offsetTop;
  	}
	return yWithScroll;
}

function getPageWidthWithScroll(){
	if (window.innerWidth && window.scrollMaxX) {// Firefox
		xWithScroll = window.innerWidth + window.scrollMaxX;
	} else if (document.body.scrollWidth > document.body.offsetWidth){ // all but Explorer Mac
		xWithScroll = document.body.scrollWidth;
	} else { // works in Explorer 6 Strict, Mozilla (not FF) and Safari
		xWithScroll = document.body.offsetWidth + document.body.offsetLeft;
  	}
	return xWithScroll;
}

//Modal Window
function showModal(pageUrl) {
	var custompagesFolder="";
	
	// for IE
	var browser=navigator.appName;
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	var version=parseFloat(b_version);

	    var tempIframe = document.createElement('iframe');
	    tempIframe.id = "modal";
	    tempIframe.name = "modal";
	    tempIframe.frameBorder = "0";
	    tempIframe.scrolling="no";
	    tempIframe.height = "1";
	    tempIframe.width = "1";
	    tempIframe.style.overflow = "hidden";
	    tempIframe.allowTransparency=true;
	    document.body.appendChild(tempIframe);
	    tempIframe.src = custompagesFolder+ pageUrl;

		return false;
}

function CenterModal(width,height){

	var elementId = "modal";
	var visibleHeight = pageHeight();
	var visibleWidth = pageWidth();
	element = document.getElementById(elementId);
	element.width = width;
//	element.height = height+20;
	element.height = height;
	if(element.height > visibleHeight){
		element.style.top = "20px";
	}else{
		element.style.top = (visibleHeight-element.height)/2 + "px";
		//element.style.top = "100px";
	}
	element.style.left = (visibleWidth-element.width)/2 + "px";
	
	var totalHeight = getPageHeightWithScroll();
	var totalWidth = getPageWidthWithScroll();
    if(!document.getElementById('coverLayer')){
	    var tempCoverDiv = document.createElement('div');
	    tempCoverDiv.id = "coverLayer";
	    tempCoverDiv.style.height=totalHeight+"px";
	    tempCoverDiv.style.width=totalWidth+"px";
	    document.body.appendChild(tempCoverDiv);
	}
	var wrapper = document.getElementById('wrapper');
//	if(wrapper){
//        setTimeout(function(){     
//        element.height=(wrapper.offsetHeight) + "px";},50);
//    }

	getScrollXY();
	parent.window.scrollTo(0,0);
}

function closeModalWindow() {
	var tempIframe = document.getElementById('modal');
	var tempCoverDiv = document.getElementById('coverLayer');
	if(tempIframe) tempIframe.parentNode.removeChild(tempIframe);
	if(tempCoverDiv){tempCoverDiv.parentNode.removeChild(tempCoverDiv); }
	parent.window.scrollTo(xPos,yPos);
}

var xPos = 0, yPos = 0;
function getScrollXY() {
    if( typeof( window.pageYOffset ) == 'number' ) {
        // Netscape
        xPos = window.pageXOffset;
        yPos = window.pageYOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        // DOM
        xPos = document.body.scrollLeft;
        yPos = document.body.scrollTop;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        // IE6 standards compliant mode
        xPos = document.documentElement.scrollLeft;
        yPos = document.documentElement.scrollTop;
    }
}

//Generic PopUp window Code
var isGecko = (navigator.userAgent.indexOf("Gecko") != -1)?true:false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1)?true:false;

var wincount = 0;
var NewWindowRef;

function openPopup(url,winTitle,winWidth,winHeight){
	var winName = "NewWindow";
	var leftPosition = (screen.width) ? (screen.width-winWidth)/2 : 0;
	var topPosition = (screen.height) ? (screen.height-winHeight)/2 : 0;
	var features = "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=no";
	features += " ,top="+topPosition+" ,left="+leftPosition+" ,width=" + winWidth + ",height=" + winHeight;
	
	var urlLink = url;

	if (!eval(winName + 'Ref')) {
		eval(winName + 'Ref = window.open("' + urlLink + '","' + winName + '","' + features + '")');
	}
	else{
		//Opera doesn't give access to the .closed property, but if window has been closed .location will be undefined
		if ((isOpera && !eval(winName + 'Ref').location) || eval(winName + 'Ref').closed) {
			eval(winName + 'Ref = window.open("' + urlLink + '","' + winName + '","' + features + '")');
		}
		else {
			eval(winName + 'Ref').close();
			eval(winName + 'Ref = window.open("' + urlLink + '","' + winName + wincount + '","' + features + '")');
			wincount++;
		}
	}
}