// array of select fields to toggle visibility for overlay ie hack
selectFields = document.getElementsByTagName('select');
fpw = false;
window.onresize = center;

function showBox(){
		setPageDims();
    center('box');
		var d = document;

		var oLay = d.getElementById('overlay');
		oLay.style.width = pageDims[0] + 'px';
		oLay.style.height = pageDims[1] + 'px';
		oLay.style.display = 'block';

		hideSelects();
}

stopPropagation = function(e){
	e.stopPropagation();
}

showBox_fpw = function(){
		fpw = true;
		showBox();
}


function showBox_stf(){
	setPageDims();
  center('box');
	var d = document;
	var oLay = d.getElementById('overlay');
	oLay.style.width = pageDims[0] + 'px';
	oLay.style.height = pageDims[1] + 'px';
	oLay.style.display = 'block';

	hideSelects();

	if (memberid != '0')	{
		d.getElementById('overlay').style.display='block';
		d.getElementById('notsignedin').style.display='none';
		d.getElementById('addemails').style.display='block';		
		d.getElementById('sent').style.display='none';				
		d.getElementById('notsignedinsave').style.display='none';			
	} else {
		d.getElementById('overlay').style.display='block';
		d.getElementById('notsignedin').style.display='block';		
		d.getElementById('addemails').style.display='none';	
		d.getElementById('sent').style.display='none';								
		d.getElementById('notsignedinsave').style.display='none';						
	}
}


function showBox_save(){
	setPageDims();
  center('box');

	var d = document;
	var oLay = d.getElementById('overlay');
	oLay.style.width = pageDims[0] + 'px';
	oLay.style.height = pageDims[1] + 'px';

	if (memberid == '0')
	{
		d.getElementById('overlay').style.display='block';
		d.getElementById('notsignedin').style.display='none';
		d.getElementById('addemails').style.display='none';	
		d.getElementById('sent').style.display='none';							
		d.getElementById('notsignedinsave').style.display='block';							
	}
		
	hideSelects();

}

hideSelects = function(){
	for(var i = 0; i < selectFields.length; i++) {
		selectFields[i].style.visibility='hidden';	
	}
}

showSelects = function(){
	for(var i = 0; i < selectFields.length; i++) {
		selectFields[i].style.visibility='visible';	
	}
}

hideBox = function(){
		var d = document;
		try{
	    d.getElementById('overlay').style.display='none';
		}catch(e){
			return;
		}
		showSelects();
}

function center(element){
	element = (typeof(element) == 'string') ? element : 'box';
	element = document.getElementById(element);
	if(!element) return;

  var my_width  = 0;
  var my_height = 0;

    if ( typeof( window.innerWidth ) == 'number' ){
        my_width  = window.innerWidth;
        my_height = window.innerHeight;

    }else if ( document.documentElement && 
             ( document.documentElement.clientWidth ||
               document.documentElement.clientHeight ) ){
        my_width  = document.documentElement.clientWidth;
        my_height = document.documentElement.clientHeight;
    }
    else if ( document.body && 
            ( document.body.clientWidth || document.body.clientHeight ) ){
        my_width  = document.body.clientWidth;
        my_height = document.body.clientHeight;
    }
	
    element.style.position = 'absolute';
    element.style.zIndex   = '5003';

    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }
    

    var total_height = document.getElementById('container_body').offsetHeight ? document.getElementById('container_body').offsetHeight+10 : my_height + scrollY;
	
	//alert($("#box").width());
    var setX = ( my_width  - 410 ) / 2;
    var setY = ( my_height - 250 ) / 2 + scrollY;

    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;
    
    element.style.left = setX + "px";
	element.style.top  = (fpw) ? '150px' : setY + "px";
}

	setPageDims = function(){
		var xScroll, yScroll;

		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
	
		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
	
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}

		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}

		pageDims = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
	}