

//弹出对话框
function dialog(url, dwidth, dheight) {	
	if(dwidth == null)
     	dwidth = 500;
   	if(dheight == null)
     	dheight = 250;
     		
	var ret = showModalDialog(url, "", "dialogWidth:" + dwidth + "pt;dialogHeight:" + dheight + "pt;help:0;status:0");
	return ret;
}   
 
//删除确认
function deleteConfirm(url) {
	if(confirm("是否删除当前记录?", "确认")) {
     		window.location = url; 
    }
}

//删除确认
function deleteConfirmE(url) {
	if(confirm("Delete?", "Confirm")) {
     		window.location = url; 
    }
}


function upload(input, UploadType, rootPath){
	
	var ret, imageFlag;
	if(rootPath == null)
		rootPath = "..";
		
	if(UploadType == "" || UploadType == "Image")
		imageFlag = "1";
	else
		imageFlag = "0";	
		
	ret = dialog(rootPath + "/Pub/Upload.asp", 500, 180);
	if(ret == null || ret == "")
		return;
	
	// 返回值:保存文件名|原始文件名
  	var tmpArray, fileName
  	
  	tmpArray = ret.split("|");
  	fileName = tmpArray[0];
  	
	input.value = fileName;
}


function memberUpload(inputCtrl, rootPath){
	var ret;
	if(rootPath == null)
		rootPath = "..";
		
	ret = dialog(rootPath + "/Member/MemberUpload.asp", 500, 180);
	if(ret == null || ret == "")
		return;
	
	// 返回值:保存文件名|原始文件名
  	var tmpArray, fileName
  	
  	tmpArray = ret.split("|");
  	fileName = tmpArray[0];
  	
	inputCtrl.value = fileName;
}

//弹出窗口
function openWindow(url, width, height, scrollbars, x, y) {
	var win,x,y;
   	//
   	if(win!=null)
     		win.close();
   	if(width==null)
     		width=500;
   	if(height==null)
     		height=250;
   	if(scrollbars==null||scrollbars=='')
     		scrollbars='no'; 
   	else
     		scrollbars='yes';    
   	//
   	if(x==null||y==null)
     	{
     		x=Math.ceil((window.screen.width-width)/2);
      		y=Math.ceil((window.screen.height-height)/2);
     	}  
   //
   	win=window.open(url,"","width="+width+",height="+height+",toolbar=no,statusbar=no,menubar=no,scrollbars="+scrollbars+",resizable=no,location=no,status=no");
   	win.moveTo(x,y);
   	win.focus();
}   

function doZoom(size, lineHeight) {
	
	var obj = document.getElementById("NewsContent"); 

	obj.style.fontSize = size + 'pt';
	obj.style.lineHeight = lineHeight + 'px'; 
}


function _doPost(form) {
	ctrl.form.submit();
}

//Javascript:SuperMarquee('SuperMarquee', 1500, 30, 40);
//CSS:.SuperMarquee {height: 50px;overflow: hidden;}
function SuperMarquee(ul, delay, speed, lh) {
	var slideBox = (typeof ul == 'string') ? document.getElementById(ul) : ul;
	var delay = delay||1000, speed = speed||20, lh = lh||20;
	var tid = null, pause = false;
	
	var start = function() {
		tid = setInterval(slide, speed);
	}

	var slide = function() {
		if (pause) 
			return;
			
		slideBox.scrollTop += 2;
		if (slideBox.scrollTop % lh == 0) {
			clearInterval(tid);
			slideBox.appendChild(slideBox.getElementsByTagName('li')[0]);
			slideBox.scrollTop = 0;
			setTimeout(start, delay);
		}
	}

	slideBox.onmouseover = function(){pause = true;}
	slideBox.onmouseout = function(){pause = false;}
	setTimeout(start, delay);
}

function DivWindow() {
	var xmlHttp; 
	this.Open = Open;
	this.Hide = Hide;
	
	function CreateWindowDiv() {
		// Create Div
		var divMaskWindow = document.createElement("DIV");
		divMaskWindow.id = "MaskWindow";
		document.body.appendChild(divMaskWindow);
		
		var divDivWindow = document.createElement("DIV");
		divDivWindow.id = "DivWindow";
		document.body.appendChild(divDivWindow);
		
		var divDivWindowClose = document.createElement("DIV");
		divDivWindowClose.id = "DivWindowClose";
		document.body.appendChild(divDivWindowClose);
	}
	
	function Open(url, width, height){ 	
	    var maskWin =  document.all("MaskWindow");
	    if(maskWin == null) {
	    	CreateWindowDiv();
	    	maskWin =  document.all("MaskWindow");
	    }
	    	
	    var divWin =  document.all("DivWindow");
	    var divWinClose =  document.all("DivWindowClose");
	    
	    maskWin.style.width=document.body.clientWidth;
	    maskWin.style.height=document.body.clientHeight;
	    maskWin.style.minWidth=document.body.clientWidth;
	    maskWin.style.minHeight=document.body.clientHeight;
	    maskWin.style.display = "block";
	
	    if(width > document.body.clientWidth) 
	    	width = document.body.clientWidth;
	    if(height > document.body.clientHeight) 
	    	height = document.body.clientHeight;
	    	
	    divWin.style.width = width;
	    divWin.style.height = height;
	    divWin.style.left = (document.body.offsetWidth - width)/2;
	    divWin.style.top = 50;//(document.body.offsetHeight - height)/2;
	    divWin.style.display = "block";
	    
	    divWinClose.style.left = (document.body.offsetWidth - width)/2 + width - 17;
	    divWinClose.style.top = 51;//(document.body.offsetHeight - height)/2 + 1;
	    divWinClose.style.display = "block";
	    
	    ShowSelectCtrls();
	    divWin.innerHTML = "Please wait a moment...";
	   
	    //divWin.innerHTML = "<iframe src='" + url + "' width='100%' height='100%' frameborder='0'></iframe>";
	   	ajax.SendRequest("DivWindow", url);
	    
	}
	
	function Hide(){
	    document.all("MaskWindow").style.display = 'none';
	    document.all("DivWindow").style.display = 'none';
	    document.all("DivWindowClose").style.display = 'none';
	    document.all("DivWindow").innerHTML = "";
	    ShowSelectCtrls();
	}
	
	//Hide Select controls
	function ShowSelectCtrls(){
	    var selects = document.getElementsByTagName("select");
	    for(var i = 0;i < selects.length; i ++){
	        if(selects[i].style.visibility){
	            selects[i].style.visibility = "";
	        }else{
	            selects[i].style.visibility = "hidden";
	        }
	    }
	}
}



var divWindow = new DivWindow();

function Ajax() {	
	var xmlHttp; 	
	this.SendRequest = SendRequest;
	
	function SendRequest(updateDivId, url) { 
			Ajax.updateDivId = updateDivId;  // Static Property
	        if(window.ActiveXObject) { 
	                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); 
	        } else if(window.XMLHttpRequest) { 
	                xmlHttp = new XMLHttpRequest(); 
	        } 
	        
	        xmlHttp.onreadystatechange = OnStateChanged;
	        xmlHttp.open( "GET", url, true );
	       	xmlHttp.setRequestHeader("If-Modified-Since", "0");
	        xmlHttp.send(null); 
	}  
	
	function OnStateChanged() { 
	        if(xmlHttp.readyState == 4) { 
	                if(xmlHttp.status == 200) { 
	               		document.all(Ajax.updateDivId).innerHTML = xmlHttp.responseText; 
	                } else {        
	        			document.all(Ajax.updateDivId).innerHTML = "System Busy!";
	        		}
	        } 
	}
}

var ajax = new Ajax();


// 折叠菜单
function FoldMenu(parentMenu, subMenuId) {	
	subMenu = document.getElementById(subMenuId);
 	if(subMenu == null)
 		return;
 	if (subMenu.style.display == "none") {
 		parentMenu.className = "LeftMenuOpenItem";
		subMenu.style.display = "";
 	} else {
 		parentMenu.className = "LeftMenuCloseItem";
  		subMenu.style.display = "none";
   	}   
}

function ShowSubMainMenu(parentMenuObj, subMenuId) {
	var subMenus = document.getElementById("MainMenuBar").getElementsByTagName("div");
	for (var i=0; i< subMenus.length; i++) {
		if(subMenus[i].id == subMenuId) 
			subMenus[i].style.display = "";
		else
			subMenus[i].style.display = "none";
	}
	
	var subMenu = document.getElementById(subMenuId);
	if(subMenu == null)
		return;
	
	var left = parentMenuObj.offsetParent.offsetParent.offsetParent.offsetLeft + parentMenuObj.offsetParent.offsetParent.offsetLeft + parentMenuObj.offsetParent.offsetLeft + parentMenuObj.offsetLeft;
	subMenu.style.left = left + parentMenuObj.offsetWidth / 2 - subMenu.offsetWidth / 2;
	var top = parentMenuObj.offsetParent.offsetParent.offsetParent.offsetTop + parentMenuObj.offsetParent.offsetParent.offsetTop + parentMenuObj.offsetParent.offsetTop + parentMenuObj.offsetTop;
	subMenu.style.top = top + parentMenuObj.offsetHeight;
	
}