//alert('start the waitbar');
var waitBarElementId = "waitBar";

function addWaitBar(src)
{
	//alert('run addwaitbar');	
	
	
	var Str="";
	Str+= "<div id=\"" + waitBarElementId  + "\" >";
	Str += "<img id='loading' />";
	Str+= "</div>"
	document.write(Str);
	
	/////////
	//create mask and loading image
	/////////
	
	var mask = document.getElementById(waitBarElementId);
	var loading =  document.getElementById("loading");
	
	///////////
	//loading icon 
	//////////
	loading.style.position = 'absolute';
	loading.style.width = '150px';
	loading.style.height = '150px';	
	
	if(src!=null&src!=""){
		loading.src = src;
	}else{
		loading.src = '../../images/common/home/time3.gif';
	}
	
	loading.id = 'loading';
	
	
	
	//////////
	//mask 
	//////////
	var Opacity = 0.6;
	mask.id = waitBarElementId;
	mask.style.top = 0;
	mask.style.left = 0 ;

	mask.style.position = 'absolute'
	mask.style.backgroundColor = 'black';
	mask.style.zIndex = 1;
	mask.style.visibility  = 'hidden';
	if(!!(window.attachEvent && navigator.userAgent.indexOf('Opera') === -1)){
		mask.style.filter = "Alpha(Opacity=" + Opacity * 100 + ")";
	}else{
		mask.style.opacity = Opacity;
	}
	
	
	
}

function showWaitBar()
{
	
    var waitBar = document.getElementById(waitBarElementId);
    var loading = document.getElementById("loading");//获得
    if (waitBar == null) {
		window.alert("WaitBar no initialized.");
		return "false";
	}
    
	if(waitBar.style.visibility == 'visible'){
		window.alert("Can't process while WaitBar is showing, please retry later.");
		return "false";
	}
	if(!!(window.attachEvent && navigator.userAgent.indexOf('Opera') === -1)){	
		waitBar.style.width = '100%';
		
		waitBar.style.height = Math.max(document.body.offsetHeight,document.body.scrollHeight) + 'px';
		loading.style.left = ( document.body.offsetWidth - loading.style.width.replace('px','') ) / 2;
		loading.style.top = ( document.body.clientHeight - loading.style.height.replace('px','')  ) / 2 ;
		

		if(window.screen.height > document.body.offsetHeight){
			loading.style.top = (  document.body.offsetHeight - loading.style.height.replace('px','')  ) / 2 + 'px'  ;
		}else {
			loading.style.top = (  window.screen.height - loading.style.height.replace('px','')  ) / 2 + 'px'  ;
		}
	}else{
		waitBar.style.width = '100%';
		waitBar.style.height =  document.body.offsetHeight + 'px';
		loading.style.left = ( document.body.offsetWidth - loading.style.width.replace('px','')  ) / 2 + 'px' ;

		if(window.screen.height > document.body.offsetHeight){
			loading.style.top = (  document.body.offsetHeight - loading.style.height.replace('px','')  ) / 2 + 'px'  ;
		}else {
			loading.style.top = (  window.screen.height - loading.style.height.replace('px','')  ) / 2 + 'px'  ;
		}
		
	}
	

	waitBar.style.visibility = 'visible';
	
	return "true";
}

function hideWaitBar() {
    var waitBar = document.getElementById(waitBarElementId);
    
    if (waitBar == null) {
		window.alert("WaitBar no initialized.");
		return "false";
	}
	
	if (waitBar.style.visibility == 'hidden'){
		//window.alert("WaitBar no showing.");
		return "false";
	}
	
	waitBar.style.visibility = 'hidden';
	
	return "true";
}
//alert('end the waitbar');