/* Copyright Bridgeline Software, Inc. An unpublished work created in 2009. 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. */
// Edit Mode Miscellaneous Functions
$(function(){
    if(document.getElementById('jsInclude')){
        $("div.pageBanner").addClass('editPageBanner');             
        $("div.relatedImage").addClass('editRelatedImage');  
        $("iframe.genericIFrame").addClass('editGenericIFrame');
    }
    $("a[rel='pop-up']").click(function (){
        var urlLink = this.href;
        var winName = "New Window";
        var winWidth = 800;
        var winHeight = 700;
        var screenWidth = $(window).width();
        var screenHeight = $(window).height();
        var leftPosition = (screenWidth) ? (screenWidth-winWidth)/2 : 0;
        var topPosition = (screenHeight) ? (screenHeight-winHeight)/2 : 0;
        var features = "toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,scrollbars=yes";
        features += " ,top="+topPosition+" ,left="+leftPosition+" ,width=" + winWidth + ",height=" + winHeight;
    	
        newwindow=window.open(urlLink, 'Popup', features);
        return false;
    });
});

// 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) {
    //document.getElementById('signUp').onclick = disableModal;
    //document.getElementById('signUp').href = "#";
	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.style.overflow = "hidden";
	tempIframe.allowTransparency=true;
	//document.body.appendChild(tempIframe);
	document.getElementById('modalWindowContainer').appendChild(tempIframe);
	tempIframe.src = custompagesFolder+ pageUrl;
	return false;
}

function positionModal(width,height,center,getClass){
	var elementId = "modal";
	var visibleHeight = pageHeight();
	var visibleWidth = pageWidth();
	element = document.getElementById(elementId);
	element.width = width;
	element.height = height;

	// Check if the Modal  Window have to be centered
	if(center != false){
	    if(element.height > visibleHeight){
		    element.style.top = "20px";
	    }else{
		    element.style.top = (visibleHeight-element.height)/2 + "px";
	    }
	    element.style.left = (visibleWidth-element.width)/2 + "px";
    }	
	var totalHeight = getPageHeightWithScroll();
	var totalWidth = getPageWidthWithScroll();
	var tempCoverDiv = document.createElement('div');
	tempCoverDiv.id = "coverLayer";
	tempCoverDiv.style.height=totalHeight+"px";
	tempCoverDiv.style.width=totalWidth+"px";
	document.body.appendChild(tempCoverDiv);
	element.setAttribute('class', getClass);
	element.setAttribute('className', getClass);
	getScrollXY();
	parent.window.scrollTo(0,0);
}

function closeModalWindow() {
    //document.getElementById('signUp').onclick = openModal;
	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);
}
//function openModal(){
//    showModal(document.getElementById('signUp').getAttribute("modalUrl"));
//    document.getElementById('signUp').href = document.getElementById('signUp').getAttribute("modalUrl");
//    return false;
//}

//function disableModal(){
//    return false;
//}
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;
    }
}
 
 function controlEnterButton (btnId, evt) 
{  
    btn = document.getElementById(btnId);
    if (btn)
    {
        if (evt.keyCode == 13)
        {
            evt.returnValue = false;
            evt.cancel = true;
            btn.click();
        } 
    } 
}
$(function(){
	var $box = $('#box').wrap('<div id="box-outer"></div>');
	$('#signUp').click(function() {
	
	var totalHeight = getPageHeightWithScroll();
	var totalWidth = getPageWidthWithScroll();
	var tempCoverDiv = document.createElement('div');
	tempCoverDiv.id = "coverLayer";
	tempCoverDiv.style.height=totalHeight+"px";
	tempCoverDiv.style.width=totalWidth+"px";
	document.body.appendChild(tempCoverDiv);

		$('.loginModal').show();
		var h = $box.height() + parseInt($box.css('paddingTop')) + parseInt($box.css('paddingBottom'));
		$box.animate({marginTop:0},'slow','swing');
		$('#txtUser .fieldTxt').focus();
		$('.quickNavContainer input').attr("disabled","disabled");	

	    return false;
	});
	
	$('#blind1').click(function() {
		var h = $box.height() + parseInt($box.css('paddingTop')) + parseInt($box.css('paddingBottom'));
		$box.animate({marginTop:-h},'slow','swing',function(){
		    $('.loginModal').hide();
		    var tempCoverLayer = $('#coverLayer');
            if(tempCoverLayer) tempCoverLayer.remove();
         	$('.quickNavContainer input').removeAttr("disabled");	
   
		});
		return false;
	});
});