var contextPath = "";
var titlePre = "巨灵金融服务平台";

function displayleft(obj,name){
    var divbarid=document.getElementById('divbar');
    var divcontentid=document.getElementById('divContent');
	LeftDiv=eval("document.all."+name)
   	if (LeftDiv.style.display=="none"){
		LeftDiv.style.display="block";
     	obj.src= contextPath + "/images/icon/icon_left.jpg";
     	obj.title="隐藏左侧信息栏";
     	divbarid.style.left="190px";
     	divcontentid.style.left="197px";
       if(checkIEVer()=='7'){
    	   //divcontentid.style.paddingLeft="197px";
    	}else if(checkIEVer()=='6'){
    	  document.getElementById('leftmenu').width="187px";
    	  document.getElementById('middleDivId').style.paddingLeft="186px";
    	}
    }else{
     	LeftDiv.style.display="none";
	    obj.src=contextPath + "/images/icon/icon_right.jpg";
    	obj.title="显示左侧信息栏";
    	divbarid.style.left="5px";
    	if(checkIEVer()=='7'){	   
    	   divbarid.style.left="5px";
    	   divcontentid.style.left="12px";
    	}else if(checkIEVer()=='6'){
    	  divcontentid.style.paddingLeft="12px";
    	  document.getElementById('leftmenu').width="0px";
    	  document.getElementById('middleDivId').style.paddingLeft="0px";
    	}
    }
}

/**用于给window.onload加入新的函数调用,此方法不会覆盖你原先定义的window.load方法,
 *  要会在你原先window.load方法调用之后调用你的方法
 */
function addLoadEvent(func) {
	var oldonload = window.onload;
	if(typeof window.onload != 'function'){
		window.onload = func;
	}else{
		window.onload = function(){
			oldonload();
			func();
		}
	}
}

function trim(str){ 
	return	str.replace(/^\ +|\ +$/ig,"");
}

//用于替换字符串中的某些字符
String.prototype.replaceAll = function (findText,repText){
	regExp = new RegExp(findText,"g");
	return this.replace(regExp,repText);
}

//获得cookie解码后的值
function getCookieVal(offset){
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

//设定cookie值
function setCookie(name, value){
	var expdate = new Date();
	var argv = setCookie.arguments;
	var argc = setCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : 60*60*24;
	var path = (argc > 3) ? argv[3] : contextPath;
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
	//alert(expdate);
	document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
	+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
	+((secure == true) ? "; secure" : "");
}

//删除cookie
function delCookie(name){
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}

//获得cookie原始值
function getCookie(name){
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen){
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function openwinUlr(url){
   if(url.charAt(0) != '/'){
      openWindow(contextPath + "/" + url);
   }else{
      openWindow(contextPath + url);
   }
}

function openWindow(url, width, height) {
	if(width==null) width=850;
	if(height==null) height=600;
	open(url, new Date().getTime().toString(), "scrollbars=yes,resizable=yes,titlebar=yes,toolbar=no,menubar=no,status=no,location=no,top=0,left=0,left="+((screen.availWidth)/2-(width/2))+",top="+((screen.availHeight)/2-(height/2))+",width="+width+",height="+height);
}

//打开模态的对话框
function OpenModelessDialog(URL,arr,width,height){
  if (width==null) width=800;
  if (height==null) height=600;
  var opts = "dialogWidth:"+width+"px;dialogHeight:"+height+"px;status:no;help:no;scroll:yes;";
  window.showModelessDialog(URL,arr,opts);
}

//打开非模态的对话框
function OpenModalDialog(URL,arr,width,height){
  if (width==null) width=800;
  if (height==null) height=600;
  var opts = "dialogWidth:"+width+"px;dialogHeight:"+height+"px;status:no;help:no;scroll:yes;";
  window.showModalDialog(URL,arr,opts);
}

function StringBuffer(){ 
	this.data = []; 
}

StringBuffer.prototype.append = function(){ 
	this.data.push(arguments[0]);
}

StringBuffer.prototype.toString = function(){
	return this.data.join("");
}
function checkIEVer(){
  var browser=navigator.appName 
  var b_version=navigator.appVersion 
  var version=b_version.split(";"); 
  var trim_Version=version[1].replace(/[ ]/g,"");
  if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE7.0") { 
     return '7';
  } 
  else if(browser=="Microsoft Internet Explorer" && trim_Version=="MSIE6.0") { 
     return '6';
  }
}

//--001 start 移动层开始  
var moveDiv; //移动的定位层
var inity; //原始鼠标位置坐标的变量
var mousey; //声明存放当前鼠标位置坐标的变量
var oTime;
//clone调整大小的节点 
function setResize(div1,divX,divY){
  moveDiv=document.getElementById(div1);
  divX=document.getElementById(divX);
  divY=document.getElementById(divY);
  if (event.button == 1) { 
    if (oTime) { 
      clearTimeout(oTime);  
    } 
    moveDiv.setAttribute("onmousemove", function(){startResize(divX,divY)}); 
    moveDiv.setAttribute("onmouseup", function(){endResize(divX,divY)}); 
    mousey=document.body.scrollTop+event.clientY; //获取当前鼠标位置的Y坐标
    inity=document.body.scrollTop+event.clientY;
    moveDiv.setCapture();    
  } 
} 

//拖动调整大小 
function startResize(divX,divY) {
  if (event.button == 1){
    var nY = document.body.scrollTop+event.clientY;
    if(mousey!=nY){
      //divX.style.height = parseInt(nY) + "px";
      moveDiv.style.top=parseInt(nY-65) + "px";
      //divY.style.top = parseInt(nY-5) + "px";
      mousey=nY;
    }
  }
} 

//调整大小结束 
function endResize(divX,divY) {
   moveDiv.releaseCapture();
    if(moveDiv.style.top=='')return;
   divX.style.height = parseInt(mousey-65) + "px";  
   var oY=divY.clientHeight;  
   divY.style.top = parseInt(parseInt(moveDiv.style.top)+5) + "px";
   divY.style.height = parseInt(oY+inity-mousey+4) + "px";  
   //回调函数 参数为拖动层的上面层的对象

   if (typeof(resizeLocation1)!="undefined"){
      resizeLocation1(moveDiv);
   }
  // moveDiv='';
}
//--001 end 移动层结束

var Gti = {};
Gti.Common = {};

Gti.Common.getPosTop = function(A,B){
  B=B||window;
  var C=A.offsetTop;
  A=A.offsetParent;
  while(A!=null&&A!=B){
    C+=(A.offsetTop-A.scrollTop);
    A=A.offsetParent
  }
  return C
}

// Same as Gti.Common.getPosTop 
Gti.Common.getTop = function(target ,reference){
	return Gti.Common.getPosTop(target, reference); 
}

Gti.Common.getPosLeft = function(A,B){
  B=B||window;
  var C=A.offsetLeft;
  A=A.offsetParent;
  while(A!=null&&A!=B){
    C+=(A.offsetLeft-A.scrollLeft);
    A=A.offsetParent
  }
  return C;
}

// Same as Gti.Common.getPosLeft
Gti.Common.getLeft = function(target, reference){
	return Gti.Common.getPosLeft(target, reference); 
}

Gti.Common.getPosRight = function(A){
  return Gti.Common.getPosLeft(A)+A.offsetWidth;
}

// Same as Gti.Common.getPosRight
Gti.Common.getRight = function(target){
	return Gti.Common.getPosRight(target);
}

Gti.Common.getPosBottom = function(A){
  return Gti.Common.getPosTop(A)+A.offsetHeight;
}

// Same as Gti.Common.getPosBottom
Gti.Common.getBottom = function(target){
	return Gti.Common.getPosBottom(target); 
}

Gti.Common.getHeight = function(C,A){
  var E=C.offsetHeight||0;
  if(A!==true)return E;
  var D=Gti.Common.getBorderWidths(C),B=Gti.Common.getPaddings(C);
  return E-D[0]-D[2]-B[0]-B[2];
}

Gti.Common.getWidth = function(D,B){
  var A=D.offsetWidth||0;
  if(B!==true)return A;
  var E=Gti.Common.getBorderWidths(D),C=Gti.Common.getPaddings(D);
  return A-E[1]-E[3]-C[1]-C[3];
}

Gti.Common.getBorderWidths = function(A){
  return [Gti.Common.parseInt(A.style.borderTopWidth),
    Gti.Common.parseInt(A.style.borderRightWidth),
    Gti.Common.parseInt(A.style.borderBottomWidth),
    Gti.Common.parseInt(A.style.borderLeftWidth)];
}

Gti.Common.getPaddings = function(A){
  return[Gti.Common.parseInt(A.style.paddingTop),
    Gti.Common.parseInt(A.style.paddingRight),
    Gti.Common.parseInt(A.style.paddingBottom),
    Gti.Common.parseInt(A.style.paddingLeft)];
}

Gti.Common.parseInt = function(A,C){
  var B=parseInt(A);
  return isNaN(parseInt(A))?C||0:B;
}


Gti.Common.browser = {};
Gti.Common.browser.IE6 = 0;
Gti.Common.browser.IE7 = 1;
Gti.Common.browser.Mozilla = 2;

Gti.Common.browser.getBrowser = function() {
	if (window.XMLHttpRequest) {
		// Mozilla, Safari,...IE7 
		if(!window.ActiveXObject) {
			// Mozilla, Safari,...
			return Gti.Common.browser.Mozilla;
		} else {
			// IE7
			return Gti.Common.browser.IE7; 
		}
	} else {
		return Gti.Common.browser.IE6;
	}
}



var DataLoading = {};

DataLoading.createDiv = function(id){
  var divId = document.getElementById(id);
  if(!divId){
    alert("在页面上没有找到节点id为" + id + "的dom节点");
    return ;
  }
  var dlDiv = document.getElementById('dataLoadingDiv');
  if(!dlDiv){
    dlDiv = document.createElement("div");
    dlDiv.id = 'dataLoadingDiv';
    dlDiv.className='dataLoadingDivClass';
    dlDiv.style.display = 'none';
    dlDiv.innerHTML = "<p class='ajax-text-class'>数据提取中</p><img class='ajax-loader2-class' src='" + contextPath + "/images/ajax-loader2.gif'/>";
    divId.appendChild(dlDiv);

  }
  dlDiv.style.top=Gti.Common.getPosTop(divId);
  dlDiv.style.left=Gti.Common.getPosLeft(divId);
  dlDiv.style.width='280px';
  dlDiv.style.height='80px';

}

DataLoading.show = function(){
  var dlDiv = document.getElementById('dataLoadingDiv');
  dlDiv.style.display = '';
}

DataLoading.hide = function(){
  var dlDiv = document.getElementById('dataLoadingDiv');
  dlDiv.style.display = 'none';
}
//检查日期是否符合YYYY-MM-dd格式
function myCheckDate(str){ 
  var reg = /^(\d{4})(-|\/)(\d{1,2})\2(\d{1,2})$/; 
  var r = str.match(reg);
  if(r==null){
    alert("请输入YYYY-MM-dd格式的日期");
    return false;
  }

  var v_mon = r[3] - 0;
  var months = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  if(v_mon == 2){
    var nYear = r[1];
    if ( (nYear % 4 == 0 && nYear % 100 != 0 ) || nYear % 400 == 0 ) { //闰年
      if(r[4] > 29){
        alert("输入日期非法");
        return false;
      } 
    }else{
      if(r[4] > 28){
        alert("输入日期非法");
        return false;
      }
    }
  }else{
    if(months[v_mon] < r[4]){
      alert("输入日期非法");
      return false;
    }
  }
  return true;
}

//检查是否超时,用于在ajax取数据过来后判断
function checkTimeOut(txt){
  if(txt.indexOf('__loginPage') > -1){
    location.href = contextPath + '/system/gotoLogin.action';
    return true;
  }
  return false;
}

var Request = {
    /**
     * 查询url后面的参数的值
     * @param {} item 参数项
     * @param {} url url地址
     */
    QueryString : function(item, url){
        var urlStr = location.search;
        if(url){
            urlStr = url;
        }
        var svalue = urlStr.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)","i"));
        return svalue ? svalue[1] : svalue;
    }
}

// 报刊子菜单被点击前应设置cookie
function newsPaperPreClick(liID) {
    setCookie("SELECTED_MENU_ITEM", liID);
    return true;
};

function $chk(para){
    return !!( para || para===0 || para==="" );
};

/**
 * 判断 select 对象中是否存在值为 comparedValue 的 option
 * 
 * @selectObj html 中的 select 对象
 * @comparedValue 需要和 option.value 相比较的值
 * @return true - 存在值为 comparedValue 的 option，否则不存在
 */
function isExistsValueOfSelect(selectObj, comparedValue) {
	for (var i = 0; i < selectObj.options.length; i++) {
		if (selectObj.options[i].value == comparedValue) {
			return true;
		}
	}
	return false;
};

/**
 * 将 option 添加到 select(<select>) 元素中
 * 
 * @selectObj html 中的 select 元素
 * @optionArr 要添加的 Option，这里既可以是一个单纯的 Option 对象，也可以是 Option 数组
 */
function addOptions2SelectObject(selectObj, option) {
	var optionArr = [];
	if (! (option instanceof Array)) {
		optionArr.push(option);
	} else {
		optionArr = option;
	}
	
	for (var i = 0; i < optionArr.length; i++) {
		if (! isExistsValueOfSelect(selectObj, optionArr[i].value)) {
			selectObj.add(optionArr[i]);
		}
	}
};

/**
 * 从 select(<select>) 对象中移除 option
 * 
 * @selectObj html 中的 select 元素
 * option 要移除的 option，这里既可以是一个单纯的 Option 对象，也可是是 Option 数组
 */
function removeOptionsFromSelectObject(selectObj, option) {
	var optionArr = [];
	if (! (option instanceof Array)) {
		optionArr.push(option);
	} else {
		optionArr = option;
	}
	
	for (var i = 0; i < optionArr.length; i++) {
		selectObj.removeChild(optionArr[i]);
	}
};

/**
 * 获得 select 元素被选中的 option 集合
 * 
 * @return select 元素中被选中的 option 数组
 */
function getSelectedOptions(selectObj) {
	var selectedOptionArr = [];
	for (var i = 0; i < selectObj.options.length; i++) {
		if (selectObj.options[i].selected) {
			selectedOptionArr.push(selectObj.options[i]);
		}
	}
	return selectedOptionArr;
};


/**
 * 华泰证券，新闻，公告，法律法规等正文不显示 "收藏"，"打印" 等操作
 */
function hideContentOperations() {
	// 终端这边什么都不做(do nothing)
}
