﻿//菜单上按钮操作
var bMenuState = true;
function setMenuHide(){
	var lang = $("#_localeLanguage").val();
	var hidemenu_zh = "隐藏菜单";
	var hidemenu_en = "Hide Menu";
	var openmenu_zh = "打开菜单";
	var openmenu_en = "Open Menu";
    //打开或隐藏菜单
    if (bMenuState) {
        bMenuState = false;
        if (getBrowser()!=6) {
            $("#navigation").css({ width: "0%"});
            $("#content").css({ width: "98%"}); 
        }else{
            $("#navigation").css({ width: "0px"});
            var w = ($("#content").width()+200)+"px";
            $("#content").css({ width: "98%"}); 
        }
        document.getElementById("htmlSubHeader").style.display = "none";
        document.getElementById("htmlMenuPanel").style.display = "none";
        document.getElementById("htmlMenuSelect").style.display = "none";
        var htmlstr="";
        if(lang=="zh")
        	htmlstr = "<img src=\"../../themes/images/netbusiness/application_windows_right.png\" alt=\"\" />"+openmenu_zh+"</a>";
        else
        	htmlstr = "<img src=\"../../themes/images/netbusiness/application_windows_right.png\" alt=\"\" />"+openmenu_en+"</a>";
        document.getElementById("htmlMenuHide").innerHTML = htmlstr;
    }else{
        //隐藏菜单
        //width:20%;
        bMenuState = true;
        if (getBrowser()!=6) {
            $("#navigation").css({ width: "18%"});
            $("#content").css({ width: "80%"}); 
        }else{
            $("#navigation").css({ width: "190px"});
            var w = ($("#PageForm").width()-220)+"px";
            $("#content").css({ width: w}); 
        }        
        document.getElementById("htmlSubHeader").style.display = "";
        document.getElementById("htmlMenuPanel").style.display = "";
        document.getElementById("htmlMenuSelect").style.display = "";
        var htmlstr="";
        if(lang=="zh")
        	htmlstr = "<img src=\"../../themes/images/netbusiness/application_windows_left.png\" alt=\"\" />"+hidemenu_zh+"</a>";
        else
        	htmlstr = "<img src=\"../../themes/images/netbusiness/application_windows_left.png\" alt=\"\" />"+hidemenu_en+"</a>";
        document.getElementById("htmlMenuHide").innerHTML = htmlstr;
    }
}
var vrwsCookie = new function(){
	this.get = function(Name){
		var search = Name + "=";
		if (document.cookie.length > 0) {
			offset = document.cookie.indexOf(search);
			if (offset != -1) {
				offset += search.length;
				end = document.cookie.indexOf(";", offset);
				if (end == -1) 
					end = document.cookie.length;
				return unescape(document.cookie.substring(offset, end));
			}
			else 
				return "";
		}
	}	
	this.set=function(name, value, exp,p,dm){ 
	    var expires = exp || null;
		var path = p ||null;
		var domain = dm || null;
	    if(expires!=null) { 
	        var LargeExpDate = new Date (); 
	        LargeExpDate.setTime(LargeExpDate.getTime() + (expires*1000*3600*24));         
	    } 
	    document.cookie=name+"="+escape(value)+((expires==null)?"":(";expires="+LargeExpDate.toGMTString())+((path==null)?"":(";path="+path))+
			((domain == null) ? "" : ("; domain=" + domain))
		); 
	}	
	this.del=function(name){var domain = location.hostname;domain = domain.substring(domain.indexOf("."));this.set(name, null,-1);this.set(name, null,-1,"/",domain);} 
	this.delAll = function (){var arrcookie=document.cookie;if(arrcookie.length > 0){var arr_cookie=arrcookie.split("; ");for(var i=0; i<arr_cookie.length;i++){var del_cookie_arr=arr_cookie[i].split("=");this.del(del_cookie_arr[0]);}}}
};
//登出系统
var owd = null;
function logout(src){
    if (confirm(src)) {
		if(vrwsCookie.get("owdclose")=="1"){
			
			if(owd!=null){
				try{
					owd.jQuery("#toolbar-logout .mt-left a")[0].click();
					owd.close();
				}catch(e){owd=null;}				
			}
		}
		window.location.href = "/ssocenter/cslogout?backURL=/serviceportal/application/common/jsp/netbusiness.jsp";
		var arrcookie=document.cookie;
		if(arrcookie.length > 0){
			var arr_cookie=arrcookie.split("; ");
			for(var i=0; i<arr_cookie.length;i++){
				var del_cookie_arr=arr_cookie[i].split("=");
				if(del_cookie_arr[0]=="ssoRemberMe"||del_cookie_arr[0]=="userLanguage")continue;
				if(vrwsCookie.get("ssoRemberMe").split(":")[0]=="true"&&del_cookie_arr[0]=="ssoLocalCookieUserName")continue;
				vrwsCookie.del(del_cookie_arr[0]);
			}
		}
	}
}
$(function(){	
     $("a:not([href='/']):not([href='#']):not([href*='javascript:']):not([noshow='true']):not([target='_blank'])").bind("click",function(){
         maskPage("<img src='/serviceportal/application/themes/images/loading_circle.gif' />");
         var path = this.href;
         $("#serviceHall").one("load", function() {
               $.unblockUI();
         }).attr("src", path);
     });     
});
function resizeWindow(){
    var windowHeight = getWindowHeight();    
    if (document.getElementById("content")!=null) {
        document.getElementById("content").style.height = (windowHeight - 140) + "px";
        if (getBrowser()==6) {
        	var nw = $("#navigation").width();
            var w = ($("#PageForm").width()-nw-18)+"px";
                    $("#content").css({ width: w}); 
        }
    }    
    if (document.getElementById("contentPanel")!=null) {
        document.getElementById("contentPanel").style.height = (windowHeight - 175) + "px";
        document.getElementById("serviceHall").style.height = (windowHeight - 170) + "px";
    }    
    if (document.getElementById("navigation")!=null) {
        document.getElementById("navigation").style.height = (windowHeight - 135) + "px";
    }
    if (document.getElementById("htmlMenuPanel")!=null) {
    	document.getElementById("htmlMenuPanel").style.height = (parseInt(parseFloat(document.getElementById("navigation").offsetHeight)) - 156) + "px";
    }
    /** 重新resize子页面的QueryPortal列表的高度和宽度 **/
    /** ========start======== **/
    if(window.frames["serviceHall"]){
    	var iframeDoc = $(window.frames["serviceHall"].document);
		iframeDoc.find("td[vrws-attribute='portlet-grid'] div:first").each(function(){
			if($(this).attr("usetscroll")=="true"){
				var _width = $(this).parents().find("[vrws-attribute^='container:'][attrtype='queryportal']").attr("width");
				var _bodyWidth=window.frames["serviceHall"].document.body.clientWidth;
				if(!_width||_width=="0"||_width=="")
					_width = $(this).parents().find(".template_content").width()-5;
				if(_width>_bodyWidth)
					_width = _bodyWidth-5;
				$(this).css("overflow","auto");
				$(this).css("width",_width);
				$(this).css("height",$(this).height());
			}
		});
	}
	/** ========end======== **/
}
function getWindowHeight(){
	var windowHeight=0;
	if (typeof(window.innerHeight)=='number'){
		windowHeight = window.innerHeight;
	}else {
		if (document.documentElement && document.documentElement.clientHeight){
			windowHeight = document.documentElement.clientHeight;
		}else{
			if (document.body && document.body.clientHeight){
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}

function getWindowWidth(){
	var windowWidth=0;
	if (typeof(window.innerWidth)=='number'){
		windowWidth = window.innerWidth;
	}else {
		if (document.documentElement && document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth;
		}else {
			if (document.body && document.body.clientWidth){
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}

function getBrowser(){
    var agt = navigator.userAgent.toLowerCase();
    var appVer = navigator.appVersion.toLowerCase();
   //*** Browser Version ***
   var is_minor = parseFloat(appVer);  
   var is_major = parseInt(is_minor); 
   /*
   alert(agt.toString()+" \n "+appVer.toString());
   var str = "浏览器名称: "+navigator.appName+"\n";
   str+="版本号: "+navigator.appVersion+"\n";
   str+="代码名字: "+navigator.appCodeName+"\n";
   str+="用户代理标识: "+navigator.userAgent;
   alert(str);
   */
   var iePos = appVer.indexOf("msie");
   if(iePos!=-1){
       is_minor = parseFloat(appVer.substring(iePos + 5,appVer.indexOf(";",iePos)));
       is_major = parseInt(is_minor);       
   }
   return is_major;
}