var IE67=(navigator.userAgent.toLowerCase().indexOf('msie 6') != -1) || (navigator.userAgent.toLowerCase().indexOf('msie 7') != -1) 
var visible_modal=""; 
var visible_window=""; 
var visible_default=""; 
var restore_to=0;
function resizemodal(){
	if(document.getElementById(visible_modal))
		{
			document.getElementById(visible_modal).style.width="100%"
			document.getElementById(visible_modal).style.height=document.getElementById("floater").clientHeight+"px";
		//	document.getElementById(visible_modal).style.width=document.getElementById("floater").clientWidth+"px";
			
			if(document.getElementById("top").clientWidth>document.getElementById(visible_modal).clientWidth)
				{
					document.getElementById(visible_modal).style.width=document.getElementById("top").clientWidth+"px"
				}
		}
} 
 
function getScrollHeight() {
	var y;
	if (self.pageYOffset) // all except Explorer
		{
			y = self.pageYOffset;
		}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
		{
			y = document.documentElement.scrollTop;
		}
	else if (document.body) // all other Explorers
		{
			y = document.body.scrollTop;
		}
	return y;
} 

var temp_hidden_items=new Array();
function isVisible(e) {
	  //returns true is should be visible to user.
	  var item=e
	 if (typeof e == "string") {
		  e = xGetElementById(e);
	  }
	  while (e.nodeName.toLowerCase() != 'body' && e.currentStyle.display.toLowerCase() != 'none' && e.currentStyle.visibility.toLowerCase() != 'hidden') {
			e = e.parentNode;
	  }
	  if (e.nodeName.toLowerCase() == 'body') {
		  item.style.visibility='hidden';
		  temp_hidden_items.push(item)
	  }
  }


function showWindow(div_id,win_id,default_top){
visible_modal=div_id
visible_window=win_id
visible_default=default_top

	document.getElementById(div_id).style.width=document.getElementById("main_footer").clientWidth+"px"
	document.getElementById(div_id).style.height=parseInt(document.getElementById("main_footer").style.top.replace("px",""))+parseInt(document.getElementById("main_footer").clientHeight)+"px";
	
	if((default_top+getScrollHeight()+document.getElementById(win_id).clientHeight)<(parseInt(document.getElementById("main_footer").style.top.replace("px",""))+parseInt(document.getElementById("main_footer").clientHeight)))
		document.getElementById(win_id).style.top=default_top+getScrollHeight()+"px";
	else
		document.getElementById(win_id).style.top=(parseInt(document.getElementById("main_footer").style.top.replace("px",""))+parseInt(document.getElementById("main_footer").clientHeight))-document.getElementById(win_id).clientHeight+"px"
	if(IE67)
		{
			document.getElementById(win_id).style.width=document.getElementById(div_id).clientWidth+"px"
			/* i think there will not be need for this when you are using customized selectboxes
			
			var selects=document.getElementsByTagName("select")
			for(var x=5;x<selects.length;x++)
				{
					isVisible(selects[x])
				}
			*/
		}
	if(document.getElementById("inner_content").clientHeight<document.getElementById(win_id).clientHeight)
		{
			restore_to=document.getElementById("inner_content").clientHeight;
			document.getElementById("inner_content").style.height=document.getElementById(win_id).clientHeight+"px"
			deployFooter();
		}
	
	document.getElementById(div_id).style.visibility='visible';
	document.getElementById(win_id).style.visibility='visible';
	scroll(0,parseInt(document.getElementById(win_id).style.top.replace("px",""))-default_top);
	
	
	//window.scrollBy(0,-document.getElementById(win_id).clientHeight)
}

function hideWindow(div_id,win_id,default_top){
visible_modal=""
visible_window=""
visible_default=""
	document.getElementById(div_id).style.width="0px"
	document.getElementById(div_id).style.height="0px"

	/* i think there will not be need for this when you are using customized selectboxes
	if(IE67)
		{
			for(var x=0;x<temp_hidden_items.length;x++)
				{	
					temp_hidden_items[x].style.visibility="visible";
				}
			temp_hidden_items.length=0;
		}
	*/
	if(restore_to!=0)
		{
			document.getElementById(win_id).style.top=default_top+"px";
			document.getElementById("inner_content").style.height=restore_to+"px";
			restore_to=0;
			deployFooter();
		}
	document.getElementById(div_id).style.visibility='hidden';
	document.getElementById(win_id).style.visibility='hidden';
}

function fixFloater(){
	if(IE67)	
		document.getElementById("floater").style.position="absolute";
}

function showTopUpload()
{
	//Show the background overlay and topbox...
	showWindow('uploading','upload_top_box',150);
}

function showTop()
{
	//Show the background overlay and topbox...
	showWindow('screenoverlay','topbox',150);
}

function closeTop()
{
	//Hide the overlay and tobox...
	hideWindow('screenoverlay','topbox',150);
}

function showTop2()
{
	//Show the background overlay and topbox...
	showWindow('screenoverlay2','topbox2',150);
}

function closeTop2()
{
	//Hide the overlay and tobox...
	hideWindow('screenoverlay2','topbox2',150);
}

function showTop3()
{
	//Show the background overlay and topbox...
	showWindow('screenoverlay3','topbox3',150);
}

function closeTop3()
{
	//Hide the overlay and tobox...
	hideWindow('screenoverlay3','topbox3',150);
}
function showTop4()
{
	//Show the background overlay and topbox...
	showWindow('screenoverlay4','topbox4',150);
}

function closeTop4()
{
	//Hide the overlay and tobox...
	hideWindow('screenoverlay4','topbox4',150);
}

function showTop5()
{
	//Show the background overlay and topbox...
	showWindow('screenoverlay5','topbox5',150);
}

function closeTop5()
{
	//Hide the overlay and tobox...
	hideWindow('screenoverlay5','topbox5',150);
}

function showTop6()
{
	//Show the background overlay and topbox...
	showWindow('screenoverlay6','topbox6',150);
}

function closeTop6()
{
	//Hide the overlay and tobox...
	hideWindow('screenoverlay6','topbox6',150);
}
function showTop7()
{
	//Show the background overlay and topbox...
	showWindow('screenoverlay7','topbox7',150);
}

function closeTop7()
{
	//Hide the overlay and tobox...
	hideWindow('screenoverlay7','topbox7',150);
}
function showTop8()
{
	//Show the background overlay and topbox...
	showWindow('screenoverlay8','topbox8',150);
}

function closeTop8()
{
	//Hide the overlay and tobox...
	hideWindow('screenoverlay8','topbox8',150);
}
function showTop9()
{
	//Show the background overlay and topbox...
	showWindow('screenoverlay9','topbox9',150);
}

function closeTop9()
{
	//Hide the overlay and tobox...
	hideWindow('screenoverlay9','topbox9',150);
}
function showTop10()
{
	//Show the background overlay and topbox...
	showWindow('screenoverlay10','topbox10',150);
}

function closeTop10()
{
	//Hide the overlay and tobox...
	hideWindow('screenoverlay10','topbox10',150);
}
function deployFooter(){
	document.getElementById("main_footer").style.width="100%";
	var highest=document.getElementById('main_back').clientHeight;
	if(document.getElementById('topbox'))
		{
			if(highest<document.getElementById('topbox').clientHeight)
					highest=document.getElementById('topbox').clientHeight+150
			var count=1;
			while(document.getElementById('topbox'+count))
				{
					if(highest<document.getElementById('topbox'+count).clientHeight)
						highest=document.getElementById('topbox'+count).clientHeight+150
					count++;
				}
		}
	
	if(document.body.clientHeight>highest)
		document.getElementById('main_footer').style.top=document.body.clientHeight-document.getElementById('main_footer').clientHeight+'px';
	else
		document.getElementById('main_footer').style.top=highest+'px'
		
	if(document.getElementById("inner_content").clientWidth>document.getElementById("main_footer").clientWidth)
			document.getElementById("main_footer").style.width=document.getElementById("inner_content").clientWidth+29+"px"
	if(visible_modal!="")		
		showWindow(visible_modal,visible_window,visible_default)	
}

