﻿var jsGuidePath="http://www.invest-nb.gov.cn/";
// JScript 文件
function WindowOpen(UrlPath,mwidth,mheight,isScrollbars){
	var S = "scrollbars=" + isScrollbars + ",";
	S += "toolbar=no,resizable=yes,status=yes,"+
			"top="  + (screen.availHeight - mheight)/2 + ",height=" + mheight +
			",left="+ (screen.availWidth- mwidth)/2 + ",width=" + mwidth;
	window.open(UrlPath,"_blank",S);
}

function ShowMyDialog(url,mWidth,mHeight)  {   
  if(document.all)  {   
    window.showModalDialog(url,null,"dialogWidth:"+mWidth+";dialogHeight:"+mHeight+";status:no;help:no");   
  } else {   
    window.open(url,null,"width="+mWidth+",height="+mHeight+",menubar=no,toolbar=no,location=no,scrollbars=no,status=no,modal=yes");   
  }   
}   

function GetTagPosition(aTag,obj){
	var leftPos = aTag.offsetLeft;
	var topPos = aTag.offsetTop ;
	do {
		aTag = aTag.offsetParent;
		leftPos	+= aTag.offsetLeft;
		topPos += aTag.offsetTop;
	} 
	while(aTag.tagName!="BODY"&&aTag.tagName!="HTML");
	obj.x=leftPos;
	obj.y=topPos;
	return obj
}
function expandIt(el) {
	$(".MenuLeft").find(".MenuChild").each(function(){
	  $(this).hide();
	});
	$("#"+el+"Child").show();
}

function changeTab(tabList,aTag,selectId,className){
	$("."+className).find("li").each(function(){
	  $(this).removeClass();
	});
	$(aTag).addClass("On");
	var arrTab = tabList.split(",");
	for (var j=0;j<arrTab.length;j++){
	  $("#" + arrTab[j]).hide();
	}
	$("#" + selectId).show();
}
function ChangeTabVisible(tabList,selectTabId,preName,onClassName,noneClassName){
	var arrTab = tabList.split(",");
	if (selectTabId=="") selectTabId = arrTab[0];
	if (selectTabId=="all"){
		for (var j=0;j<arrTab.length;j++)
		{
			if (selectTabId==arrTab[j]) continue;
			if (document.getElementById(preName + arrTab[j])!=null) 
			  document.getElementById(preName + arrTab[j]).style.display = "";
			if (document.getElementById(arrTab[j])!=null) 
				document.getElementById(arrTab[j]).className = noneClassName;
		}
		if (document.getElementById(selectTabId)!=null) 
			document.getElementById(selectTabId).className = onClassName;
		return;
	}
	for (var j=0;j<arrTab.length;j++){
		findobj = null;
		findobj = document.getElementById(preName+ arrTab[j]);
		if (findobj!=null){
			findobj.style.display = "none";}
		if (document.getElementById(arrTab[j])!=null) 
			document.getElementById(arrTab[j]).className = noneClassName;
	}
	if (document.getElementById(preName+ selectTabId)!=null) 
	  document.getElementById(preName+ selectTabId).style.display = "";
	if (document.getElementById(selectTabId)!=null) 
		document.getElementById(selectTabId).className = onClassName;
}

var nowTreeNodeChecked = false;
function ChangeTreeNodeCheck(a){
  nowTreeNodeChecked = a.checked;
  var m_Li = document.getElementById('li_'+ a.id.replace('chk_',''));
  for (var j=0;j<m_Li.childNodes.length;j++){
    if (m_Li.childNodes[j].tagName=="UL"){
      CheckChildTreeNodes(m_Li.childNodes[j]);
    }
  }
  if (nowTreeNodeChecked==false)
    CheckParentTreeNodes(a);
}

function CheckChildTreeNodes(a){
  for (var j=0;j<a.childNodes.length;j++){
    if (a.childNodes[j].tagName=="LI"){
      var m_Li = a.childNodes[j];
      for (var k=0;k<m_Li.childNodes.length;k++){
        if (m_Li.childNodes[k].tagName=="INPUT")
          m_Li.childNodes[k].checked = nowTreeNodeChecked;
        if (m_Li.childNodes[k].tagName=="UL"){
          CheckChildTreeNodes(m_Li.childNodes[k]);
        }
      }
    }
  }
}

function CheckParentTreeNodes(a){
  var aTag = a.parentNode;
  if (aTag==null||aTag.tagName=="DIV") return;
  if (aTag.id!=null&&aTag.tagName=="LI"){
    var m_chk = document.getElementById('chk_'+ aTag.id.replace('li_',''));
    if (m_chk!=null)
      m_chk.checked = nowTreeNodeChecked;
  }
  CheckParentTreeNodes(aTag);
}

function ChangeTreeNodeStatus(m_Id) {	
  var li_father = document.getElementById("li_" + m_Id);
	if (li_father.className == "Closed"||li_father.className == "Opened")	
	  li_father.className = (li_father.className == "Closed")? "Opened":"Closed";				
	else		
	  li_father.className = (li_father.className == "MenClosed")? "MenOpened":"MenClosed";				
}

function SwitchTreeNodeNote(m_Id, show)	{
	var li_father = document.getElementById("li_" + m_Id);
	if (show)	{
		var ul = $("<ul id='ul_note_" + m_Id+"'></ul>").appendTo(li_father);
		var note = $("<li></li>").addClass("Child").appendTo(ul);
		$("<img />").addClass("s").attr("src",jsGuidePath + "/Images/TreeNo.gif").appendTo(note);
		$("<span>数据获取中，请稍候...</span>").appendTo(note);
	}	else	{$("#ul_note_" + m_Id).remove();}
}

 var request = {
  QueryString : function(val) {
  var uri = self.location.search;
  var re = new RegExp("" +val+ "\=([^\&\?]*)", "ig");
  return ((uri.match(re))?(uri.match(re)[0].substr(val.length+1)):null);
 },
 QueryStrings : function() {
 var uri = window.location.search;
 var re = /\w*\=([^\&\?]*)/ig;
 var retval=[];
 while ((arr = re.exec(uri)) != null) retval.push(arr[0]);
 return retval;
 },
 setQuery : function(val1, val2) {
 var a = this.QueryStrings();
 var retval = "";
 var seted = false;
 var re = new RegExp("^" +val1+ "\=([^\&\?]*)$", "ig");
 for(var i=0; i<a.length; i++) { if (re.test(a[i])) { seted = true; a[i] = val1 +"="+ val2; } }
 retval = a.join("&");
 return "?" +retval+ (seted ? "" : (retval ? "&" : "") +val1+ "=" +val2);
 }};

function MenuLeftClose(aTag){
  if (aTag!=null){//hide
    $("#LeftMain").hide();
    $("#midMain").height($(".bodyWrap").eq(0).height()).show();
    $(".bodyWrap").eq(0).css("background-position","-180px");      
    $("#RightMain").width('99%');
    $("#Print_Main").width('974');
    $.cookie('IsClosedLeft',"0",{path:'/'});
  } else {//show
    $("#LeftMain").show();
    $("#midMain").hide();
    $(".bodyWrap").eq(0).css("background-position","0");          
    $("#RightMain").width(814);
    $("#Print_Main").width('804');
    $.cookie('IsClosedLeft',"1",{path:'/'});
  }  
}

var guide ={
  DrawDivWating : function(mDivName,mAlign,mHeight,cssClass) {
    var m_div = document.getElementById(mDivName);
    if (cssClass!=null&cssClass!="") cssClass = "class='" + cssClass + "'";
    if (m_div!=null) m_div.innerHTML = "<div style='line-height:"+mHeight+";text-align:"+mAlign+";' " + cssClass+">&nbsp;<img src='"+jsGuidePath+"/Images/Loading.gif' align='absmiddle' border='0' /> 正在获取数据...</div>";
  },
  
  ChangeTextHeight : function(aTag){
    aTag.style.posHeight=aTag.scrollHeight+15;
  },
  
  SelectDept : function (id,name,moid){
    var m_Id = document.getElementById(id);
	  var date = escape(new Date());
    var arr = showModalDialog(jsGuidePath + '/dlg/DeptSelect.aspx?key=' + date + '&MoId='+moid+'&List=' + m_Id.value,'', 
		    'dialogWidth:550px; dialogHeight:420px; status:no;resizable:yes;');
    if (arr != null) {
      var arr_list = arr.split('*');
      m_Id.value = arr_list[0];
      if (name!=''){
        var m_Name = document.getElementById(name);
        if (m_Name!=null) m_Name.value = arr_list[1];
      }
    }
  },
  SelectUser : function (id,name,deptId,onlyOne){
    var m_Id = document.getElementById(id);
	  var date = escape(new Date());
		if (deptId==null) deptId='';
		if (onlyOne==null) onlyOne='';
    var arr = showModalDialog(jsGuidePath+'/dlg/UserSelect.aspx?key=' + date + '&DeptId='+deptId+
        '&OnlyOne='+onlyOne+'&List=' + m_Id.value,'', 
		    'dialogWidth:500px; dialogHeight:440px; status:no;resizable:yes;');
    if (arr != null) {
      var arr_list = arr.split('*');
      m_Id.value = arr_list[0];
      if (name!=''){
        var m_Name = document.getElementById(name);
        if (m_Name!=null) m_Name.value = arr_list[1];
      }
    }
  },
  SelectCheck : function (id,name,dmName,KeyValueId){
    var m_Id = document.getElementById(id);
    var m_FatherId = document.getElementById(KeyValueId);
    var keyValue = '';
    if (m_FatherId!=null) keyValue=m_FatherId.value;
	  var date = escape(new Date());
    var arr = showModalDialog(jsGuidePath+'/dlg/CheckSelect.aspx?key=' + date + '&DmName='+dmName+'&List=' + m_Id.value +
        '&FatherKey=' + keyValue ,'', 
		    'dialogWidth:550px; dialogHeight:500px; status:no;resizable:yes;');
    if (arr != null) {
      var arr_list = arr.split('*');
      m_Id.value = arr_list[0];
      if (name!=''){
        var m_Name = document.getElementById(name);
        if (m_Name!=null) m_Name.value = arr_list[1];
      }
    }
  },
  SelectDm : function (id,name,dmName,keySign,IsLastSelect){
    var m_Id = document.getElementById(id);
	  var date = escape(new Date());
    var arr = showModalDialog(jsGuidePath+'/dlg/DmSelect.aspx?key=' + date + '&Name=' + dmName + 
        '&KeySign=' + keySign + '&IsLastSelect=' + IsLastSelect,'', 
		    'dialogWidth:360px; dialogHeight:420px; status:no;resizable:yes;');
    if (arr != null) {
      var arr_list = arr.split('*');
      m_Id.value = arr_list[0];
      if (name!=''){
        var m_Name = document.getElementById(name);
        if (m_Name!=null) m_Name.value = arr_list[1];
      }
    }
  },
  SelectFlowUser: function (id,name,stationId,deptId)
  {
    var m_Id = document.getElementById(id);
	  var date = escape(new Date());
    switch (stationId) {
      case "010": 
      case "180": 
        this.SelectUser(id,name,deptId);
        return;
    }
	  var arr = showModalDialog(jsGuidePath+"/dlg/StationSelect.aspx?key=" +date+ "&Station="+stationId+"&deptid="+deptId+"&List=" + m_Id.value,
	    "","dialogWidth:400px; dialogHeight:360px; status:no;resizable:yes;");
	  if (arr != null) {
      var arr_list = arr.split('*');
      m_Id.value = arr_list[0];
      if (name!=''){
        var m_Name = document.getElementById(name);
        if (m_Name!=null) m_Name.value = arr_list[1];
      }
    }
  },
  
  CheckForm : function(){
    var b=true;
    $("select").each(function(){
      if ($(this).attr("check")!=undefined){
        if($(this).val()==""){
          b=false; 
　　　　  alert($(this).attr("warning"));
          return false;
        }
      }
    });
    if (!b) return false;
    $("input,textarea").each(function(){
      if ($(this).attr("check")!=undefined){
        if (!CheckFormValue(this)){ b=false; return false;}
      }
    });
    return b;
　　function CheckFormValue(el){
　　  var sReg = guide.GetReg($(el).attr("check").toString());
　　　var reg = new RegExp(sReg,"i");//不区分大小写
　　　if(!reg.test($(el).val())){
　　　　alert($(el).attr("warning"));
　　　　GoBack(el);  
　　　　return false;
　　　}
　　　return true;
　　}
　  function GoBack(el){
　　  var sType = el.type;
　　  switch(sType){
　　　  case "text":case "password":case "file":
　　　  case "textarea": if (el.style.display=="") el.focus();break;
　　　  case "checkbox":case "radio": var els = document.getElementsByName(el.name);els[0].focus();break;
　　　  case "select-one":case "select-multiple":el.focus();break;
　　  }
　  }
　},
　initCheckForm:function(){
    $("input,textarea,select,table").each(function(){
      if (this.title || this.alt) $(this).ToolTip();
    });
    $("input,textarea").each(function(){
      if ($(this).attr("check")!=undefined){
			  $(this).blur(function(){   
　　      var sReg = guide.GetReg($(this).attr("check").toString());
　　　    var reg = new RegExp(sReg,"i");//不区分大小写
　　　    if(!reg.test($(this).val()))
　　　      ShowError(this);
　　　    else
　　　      $("#"+this.id+"_tip").remove();
			  });
      }
    });
    $("select").each(function(){
      if ($(this).attr("check")!=undefined){
 			  $(this).bind("change",function(){
          if($(this).val()=="") ShowError(this); else $("#"+this.id+"_tip").remove();
        });
       if($(this).val()=="") ShowError(this);
      }
    });
    function ShowError(el){
      if (!$("#"+el.id+"_tip").get(0)){
        var w=$(el).attr("warning")?$(el).attr("warning"):"";
        $("<span id='"+el.id+"_tip'></span>").addClass("hintError")
        .mouseover(function(){$(this).html(w)})
        .mouseout(function(){$(this).html("")})
        .appendTo($(el).parent());
      }
    }
　},
  GetReg:function(el){
　  switch(el){
　　  case "string":return "^[\\s|\\S]{1,}$";
　　  case "date":return "^\\d{4}\\-\\d{1,2}\\-\\d{1,2}$";
　　  case "datetime":return "^\\d{4}\\-\\d{1,2}-\\d{1,2} \\d{1,2}:\\d{1,2}$";
　　  case "int":return "[0-9]+$";
　　  case "decimal":return "[0-9.]+$";
　　  case "select":return "^0$";
　　  case "email":return "^w+[-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*";
　　  default:return el;
　  }
  }
}

$.fn.ToolTip = function(){
	this.mouseover(function(e){
		if((!this.title && !this.alt) && !this.tooltipset) return;
		var leftPos = this.offsetLeft+2;//+ document.body.scrollLeft;
		var topPos = this.offsetTop;// + document.body.scrollTop;
		var aTag=this;
		while (aTag.offsetParent!=null){
			aTag = aTag.offsetParent;
			leftPos	+= aTag.offsetLeft;
			topPos += aTag.offsetTop;
		} 
		if(!this.tooltipdiv){
			this.tooltipdiv = $("<div></div>").addClass("hintTip")
			  .append($("<div><div>").addClass("top").html(this.title || this.alt))
			  .append($("<div><div>").addClass("bottom")).appendTo("body");
			this.title = "";
			this.alt = "";
			this.tooltipset = true;
		}
		$(this.tooltipdiv).show().css({left: "0px", top: "0px"});
		var w=800;
		if ( $.browser.opera || ($.browser.safari && parseInt($.browser.version) > 520) )
			w=self.innerWidth ;
		else
      w=document.body.clientWidth;
		var l=leftPos+this.tooltipdiv[0].offsetWidth>w?w-this.tooltipdiv[0].offsetWidth-5:leftPos;
		$(this.tooltipdiv).css({left: l + "px", top: topPos - this.tooltipdiv[0].offsetHeight + "px"});
	})
	.mouseout(function(){if(this.tooltipdiv) this.tooltipdiv.hide();});
	return this;
};

var ubb = { //maxType 0-绝对 1-总宽余额
  imgzoom : function(img,maxSize,maxType){
    if (maxType=="1") maxSize =screen.availWidth - maxSize;
    if(img.width > maxSize) $(img).width(maxSize); 
  },
  
  AddText : function(NewCode) { 
    if (m_GuestContent==null) return;
    m_GuestContent.focus();
    var selTxt='';
    if (document.selection) selTxt = document.selection.createRange().text;   
    var range = document.selection.createRange();
    range.text=NewCode.replace("$1",selTxt);
  },
  AddEmot : function (emotName) {this.AddText("[emot]"+emotName+"[/emot]");},
  bold : function() {this.AddText("[b]$1[/b]");},
  emails : function() {this.AddText("[email]$1[/email]");},
  flash : function () {this.AddText("[flash]$1[/flash]");},
  Cdir : function () {this.AddText("[dir]$1[/dir]");},
  Crm : function () {this.AddText("[rm]$1[/rm]");},
  Cwmv : function () {this.AddText("[mp]$1[/mp]");},
  Cmov : function () {this.AddText("[qt]$1[/qt]");},
  showsize : function (size) {this.AddText("[size="+size+"]$1[/size]");},
  italicize : function () {this.AddText("[i]$1[/i]");},
  quote : function () {this.AddText("[quote]$1[/quote]");},
  showcolor : function (color) {this.AddText("[color="+color+"]$1[/color]");},
  alignTxt : function(alignFs) {this.AddText("[align="+alignFs+"]$1[/align]");},
  hyperlink : function () {this.AddText("[url]$1[/url]");},
  image : function () {this.AddText("[img]$1[/img]");},
  showcode : function () {this.AddText("\r[code]\r$1[/code]");},
  list : function () {
		  AddTxt=" [list][*]  [/*][*]  [/*][*]  [/*][/list]";
		  this.AddText(AddTxt);
  },
  showfont : function (font) {this.AddText("[face="+font+"]$1[/face]");},
  underline : function () {this.AddText("[u]$1[/u]");},
  setfly : function () {this.AddText("[fly]$1[/fly]");},
  move : function () {this.AddText("[move]$1[/move]");},
  shadow : function () {this.AddText("[SHADOW=255,blue,1]$1[/SHADOW]");},
  glow : function () {this.AddText("[glow=255,red,2]$1[/glow]");}

}
