/*
 *
 * Copyright 2007 by LongTop Corporation.
 * Softpack ChuangXin Building 15F, XiaMen, FuJian, PRC 361005
 *
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * LongTop Corporation ("Confidential Information").  You
 * shall not disclose such Confidential Information and shall use
 * it only in accordance with the terms of the license agreement
 * you entered into with LongTop.
 *
 */

/**
 * 应用程序全局方法脚本。
 *
 * @author IntelliWeb Team
 * @version 2.o
 */

Server='http://www.xiamencredit.gov.cn:8086/CREDIT/';
var AppConstants = {}
AppConstants.button = {};
AppConstants.button.add = "新增";
AppConstants.button.edit = "编辑";
AppConstants.button.del = "删除";
AppConstants.button.query = "查询";
AppConstants.button.imp = "导入";
AppConstants.button.exp = "导出";
AppConstants.button.reply = "回复";
AppConstants.button.detail = "详情";
AppConstants.button.repair = "信用手动修复";
AppConstants.button.back = "退回";
AppConstants.screen_shield = true;/**true:右键屏蔽*/
/**
 * @class 应用皮肤管理类，用于从Cookie中取出当前皮肤并进行设置：<br>
 * SkinUtil.getSkin();//取得皮肤
 * SkinUtil.setSkin(skin); //设置皮肤
 */
var SkinUtil = {};

/**
 * 取得服务端设置的皮肤
 * @detail
 * 服务端皮肤会传下var __SKIN_PATH="/intelliwebSampleCenter/resources/skins/blue/"来，
 * 该方法为了取得gray
 * @type String
 * @return 如果没有取到，则返回"blue"默认值
 * @private
 */
SkinUtil.getServerSkin = function() {
    if (typeof(__SKIN_PATH) == "undefined") return "blue";
    var _arrSkin = __SKIN_PATH.split("/");
    return _arrSkin[_arrSkin.length - 2];
}

/**
 * 设置皮肤，保存到Cookie中。并重新刷新界面。
 * @param {String} skin 可选项，如果没有设置，则取服务端__SKIN_PATH中设置的皮肤
 */
SkinUtil.setSkin = function(skin) {
    var _serverSkin = this.getServerSkin();
    //从Cookie中取得当前皮肤。
    var currSkin = Cookie.getValue("appskin");
    if (!currSkin) {
        currSkin = _serverSkin;
    }

    if (currSkin != skin) {
        if (confirm("更换皮肤会导致打开的页面关闭，是否确定进行更换？")) {
            //保存30天
            Cookie.setValue("appskin", skin, 24 * 30);
            document.location.reload();
        }
    } else {
        MsgBox.showInfoMsg("您准备更换的皮肤与当前使用的一致，不需要更换。");
    }
}

/**
 * 取得当前主界面皮肤
 */
SkinUtil.getSkin = function() {
    var _serverSkin = this.getServerSkin();
    var currSkin = Cookie.getValue("appskin");
    if (!currSkin) {
        currSkin = _serverSkin;
    }
    document.write('<link rel="stylesheet" type="text/css"  href="' + __CONTEXT_PATH + 'styles/' + currSkin + '/default.css">');
}

/**
 * 取得当前模块界面皮肤
 */
SkinUtil.getModuleSkin = function() {
    var _serverSkin = this.getServerSkin();
    var currSkin = Cookie.getValue("appskin");
    if (!currSkin) {
        currSkin = _serverSkin;
    }

    if (currSkin == _serverSkin) return;
    
    if (__SKIN_PATH) {
        var _tmpPath = __SKIN_PATH.substring(0, __SKIN_PATH.length - 1);
        var _prex = __SKIN_PATH.substring(0, _tmpPath.lastIndexOf("/"));
        __SKIN_PATH = _prex + "/" + currSkin + "/";
    }

    document.write('<link rel="stylesheet" type="text/css"  href="' + __SKIN_PATH + '/skin.css">');
}

/**
 * @class Tab标签页工具类：<br>
 * TabUtil.getSkin();//取得皮肤
 * SkinUtil.setSkin(skin); //设置皮肤
 */
var TabUtil = {};

/**
 * 取得TabSet对象
 * @type TabSet
 * @return 如果没有取到，则提示并返回null
 * @private
 */
TabUtil.getTabSet = function() {
    var tabset = $J(TabSet_Apps);
    if (tabset == null) {
        MsgBox.showErrorMsg("TabSet对象不存在！");
        return null;
    }
    return tabset;
}

/**
 * 取得父类的TabSet对象
 * @type TabSet
 * @return 如果没有取到，则提示并返回null
 * @private
 */
TabUtil.getParentTabSet = function() {
    var tabset = $J(parent.parent.TabSet_Apps);
    if (tabset == null) {
        MsgBox.showErrorMsg("TabSet对象不存在！");
        return null;
    }
    return tabset;
}

/**
 * 打开一个Tab页(如果该Tab不存在，则先创建)并激活。该方法触发onBeforeChangeTab及onAfterChangeTab事件。
 * 该方法一般由主界面的菜单调用
 * @param {String} name 必选项，Tab页名称
 * @param {String} label 可选项，Tab页标签
 * @param {String} path 可选项，Tab页装载的路径
 * @param {Boolean} reload 可选项，是否重新装载
 */
TabUtil.openTab = function(name, label, path, reload) {
    var _tabset = this.getTabSet();
    if (!_tabset || !name) return;
    var tab = _tabset.addTab(name);
    tab.setLabel(label);
    tab.setPath(path, Util.getBool(reload, false));
    tab.activate();
}

/**
 * 关闭指定的Tab页(如果tab不指定，则为当前页)。
 * 该方法一般由主界面的调用
 * @param {int|String|Tab} name 可选项，可以为页号(从0开始) 或 页名称(区分大小写) 或 页对象。
 */
TabUtil.closeTab = function(name) {
    var _tabset = this.getTabSet();
    if (!_tabset) return;
    var _tab = null;

    if (Util.isDefined(name)) {
        _tab = _tabset.getTab(name);
    }

    _tabset.removeTab(_tab);
}

/**
 * 打开一个Tab页(如果该Tab不存在，则先创建)并激活。该方法触发onBeforeChangeTab及onAfterChangeTab事件。
 * 该方法一般由具体模块调用
 * @param {String} name 必选项，Tab页名称
 * @param {String} label 可选项，Tab页标签
 * @param {String} path 可选项，Tab页装载的路径
 * @param {Boolean} reload 可选项，是否重新装载
 */
TabUtil.openParentTab = function(name, label, path, reload) {
    var tabset = this.getParentTabSet();
    if (!tabset || !name) return;
    var tab = tabset.addTab(name);
    tab.setLabel(label);
    tab.setPath(path, Util.getBool(reload, false));
    tab.activate();
}

/**
 * 关闭指定的Tab页(如果tab不指定，则为当前页)。
 * 该方法一般由具体模块调用
 * @param {int|String|Tab} name 可选项，可以为页号(从0开始) 或 页名称(区分大小写) 或 页对象。
 */
TabUtil.closeParentTab = function(name) {
    var _tabset = this.getParentTabSet();
    if (!_tabset) return;
    var _tab = null;

    if (Util.isDefined(name)) {
        _tab = _tabset.getTab(name);
    }

    _tabset.removeTab(_tab);
}
/**
 * convert the escape character 
 */
function convertUrlESC(c){
	var rtn ;
	switch(c) {
		case ('+') : rtn = '%2B'; break;
		case (' ') : rtn = '%20'; break;
		case ('/') : rtn = '%2F'; break;
		case ('?') : rtn = '%3F'; break;
		case ('%') : rtn = '%25'; break;
		case ('#') : rtn = '%23'; break;
		case ('&') : rtn = '%26'; break;
		case ('=') : rtn = '%3D'; break;
		default : rtn = c;
	}
	return rtn;
}
/**
 * open a new tab; 
 */
function openTab(name,label,path,reload){
	var tabset = $J(parent.parent.TabSet_Apps);
	if (!tabset) return;
    var tab = tabset.getTab(name);
    if(path.indexOf("openerTabName") == -1) {
        var index = path.indexOf("?");
        var openerTabName = tabset.activeTab.name;
        if(index == -1){
        	path += "?openerTabName="+openerTabName;	
        }else{
        	path += "&openerTabName="+openerTabName;	
        }
    }
    if (!tab) {
        tab = tabset.addTab(name);
        tab.setName(name);
        tab.setLabel(label);
        tab.setPath(path);
    }
    else {
	    if(path == tab.getPath()) {
	    	if(reload) {
	    		tab.setPath(path, true);
	    	}
	    	else {
		    	tab.setReload(false);
		    }
	    }
	    else {
	    	if(reload == null || reload) {
	    		tab.setPath(path, true);
	    	}
	    	else {
		    	tab.setReload(false);
		    }
	    }
    }
    tab.activate();
}
/**
 * getParentTab
 */
 function getParentTab() {
 	  var tabset = $J(parent.parent.TabSet_Apps);
      if (!tabset) {
      	return null;
      }
	  var tabName = __getURLParameter("openerTabName");
      return tabset.getTab(tabName);
 }
/**
 * click action of return button; by wujj 2009-01-09
 * parameter:reload(true-reload the parent tab;false-unreload the parent tab)
 */
function returnParentTab(reload){
	  var tabset = $J(parent.parent.TabSet_Apps);
      var tab = getParentTab();
      var tmpTab = tabset.activeTab;
	  tabset.removeTab(tmpTab);
      if (tab != null) {
      	if(reload){
	      	tab.setPath(tab.getPath(), true);
      	}
      	else{
      		tab.setReload(false);
      		tab.activate();
      	}
	  } else {
		tabset.activateTab();
	  }
}
/**
 * 
 */
function close_refreshParent() {
	var openerTabName = __getURLParameter("openerTabName");
	returnToParentTab(openerTabName,true)
}
/**
 * Close Current Tab
 */
function close_norefreshParent(){
	var openerTabName = __getURLParameter("openerTabName");
	returnToParentTab(openerTabName,false)
}
/**
 * \u8fd4\u56de\u7236tab\u9875\u9762,\u5237\u65b0\u7236\u9875\u9762\u7684\u6570\u636e\u3002\u8981\u6c42\u67e5\u8be2\u7684\u547d\u4ee4Id\u4e3a\uff1aCommand_Search
 *
 * @param tabName \u7236tab\u540d\u79f0
 * @param refresh \u662f\u5426\u5237\u65b0\u6570\u636e\u3002true \u5237\u65b0\u6570\u636e;false \u4e0d\u5237\u65b0\u6570\u636e
 */
function returnToParentTab(tabName,refresh){
	var tabset = $J(parent.parent.TabSet_Apps);
	if (!tabset){ 
		return;
	}
	var tmpTab = tabset.activeTab;
	//var tabName = "<%=request.getParameter("openerTabName"); %>"; 
	var tab = tabset.getTab(tabName);
	if (tab) {
	  	tabset.activateTab(tab);
	} else {
	  	tabset.activateTab();
	}
	if(refresh){
		var iFrame = tab.getFrame();
		if(iFrame){
			var cmd = $J(iFrame.Command_Search);
			if(cmd){
				var showSuccessMsg = cmd.showHintInfoOnSuccess;
				cmd.showHintInfoOnSuccess = false;
				cmd.execute();
				cmd.showHintInfoOnSuccess = showSuccessMsg;
			}
		}
	}
	tabset.removeTab(tmpTab);
}
/**
 * method of get URL parameter; 
 */
function __getURLParameter(name){
	if (document.location.href.match(new RegExp("(&|\\u003F)" + name + "=([^&]*)(&|$)"))){  
	    return RegExp.$2;
	}else{  
		return null;
	}  
}
/**
  * synParentData
  * @param parentDataset, record 
  */
  function synParentData(parentDataset, currentRecord) {
  	if(parentDataset && currentRecord != null) {
    	var record = parentDataset.getFirstRecord();
    	while (record != null) {
			if (record.getValue("id") == currentRecord.getValue("id")) {
				if (currentRecord.getValue("validflag") == "1") {
					record.copyFrom(currentRecord);
					record.setState(Constant.RECORD.STATE_NONE);
				}
				else {
					parentDataset.deleteRecord(record);
					returnParentTab(false);
				}
				return;
			}
			record = record.getNextRecord();
		}
		if (currentRecord.getValue("validflag") == "0") {
			returnParentTab(false);
			return;
		}
		record = parentDataset.insertRecord("begin");
		record.copyFrom(currentRecord);
		record.setState(Constant.RECORD.STATE_NONE);
    }
  }
/**
* open modal dialog
* url
* width
* height
*/
function openModalDialog(url,width,height){
	url = __CONTEXT_PATH+url;
	var sFeature = "dialogWidth:"+width+"px;dialogHeight:"+height+"px;status:0;resizable:1;help:0;scroll:no";
	return window.showModalDialog(url,null,sFeature);
}
/**
 * __parseInt
 * @param {obj} obj 
 * @param int(Decimal)
 */
 function __parseInt(obj) {
 	if (obj == null) {
 		return 0;
 	}
 	var s = obj.toString().replace(/^0*/,"");
 	if(s == "") {
 		return 0;
 	}
 	return parseInt(s, 10);
 }
/**
 /** SetCookie
 * @param name cookie name
 * @param value 
 * @param exptime 
 */
function SetCookie(name,value,exptime)
{
    var Days = exptime; 
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}
/**
 * getCookie
 * @param name Cookie name
 */
function getCookie(name)
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;

}
/**
 * delCookie
 * @param name cookie name
 */
function delCookie(name)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}
/*
 * validate the object
 * @param obj 	
 */
function isEmpty(obj) {
	if (obj == null || trim(obj) == "") {
		return true;
	}
	return false;
}
AppConstants.window = {};
AppConstants.window.title = "消息对话框";
AppConstants.window.confirm = {};
AppConstants.window.confirm.title = "消息确认框";
AppConstants.window.confirm.del = "是否要删除？";
AppConstants.window.confirm.exp = "确定要导出吗？";
AppConstants.window.confirm.saveregistor = "您修改了法定代表人，是否将之前的法定代表人记录下来？";
//AppConstants.window.confirm.savemediatorid = "您编辑的从业人员已有所属中介机构，是否将之前的该从业人员历史从业记录保存下来？";
AppConstants.window.confirm.savesameindustryid = "您编辑的从业人员已在同行业其他中介机构执业，请确认该从业人员是否在原机构已办理好离职手续？\n如已办理完成，点确定，保存该信息，并将之前的该从业人员历史从业记录保存下来。\n如未办理，点取消，不保存该信息。";
AppConstants.window.confirm.savedifferentindustryid = "您编辑的从业人员已在其他行业的中介机构执业，请判断是否属于合法？\n属合法兼职的，点确定，保存该信息。\n属非法兼职的，点取消，不保存该信息。";
AppConstants.window.confirm.audit = "是否要审核？";
AppConstants.window.confirm.back = "是否要退回？";
AppConstants.window.confirm.noaudit = "是否要反审核？";
AppConstants.window.confirm.repair = "是否要修复？";
AppConstants.window.modifyFail_0 = "您没有修改任何信息";
AppConstants.window.modifyFail_1 = "您没有选择要操作的记录";
AppConstants.command = {};
AppConstants.command.success = "操作成功";
AppConstants.command.fail = "操作失败";
AppConstants.updateimport = {};
AppConstants.updateimport.url = "jsp/framework/uploadImportFile.jsp";
/**
 * 打开导入页面
 * @param tabId    tab的ID
 * @param title    tab的title
 * @param biztype　业务Id 如service.BEAN_ID
 * @param params   需要传的参数列表 param1=xxx&[param2=yyyy...]
 */
function frame_import_page(tabId,title,biztype,params){
	if(!biztype) {
		alert("导入功能的业务类型不能为空，请联系管理员！");
		return;
	}
	var path = 'jsp/framework/ImportExcelJsp.jsp?BT=' + biztype;
	if(params) {
		path += params; 
	}
	openTab(tabId,title,path,true);
}
/**
 * 设置初始化页面
 */
function frame_init_page(){
	if(AppConstants.no_screen_shield) {
		//初始化控件
		
	}
	if(AppConstants.screen_shield) {
		document.body.attachEvent("oncontextmenu",frame_oncontextmenu); 
		document.body.attachEvent("ondragstart",frame_ondragstart); 
		document.body.attachEvent("onselectstart",frame_onselectstart); 
		document.body.attachEvent("onselect",frame_onselect); 
		document.body.attachEvent("oncopy",frame_oncopy); 
		document.body.attachEvent("onbeforecopy",frame_onbeforecopy); 
		document.body.attachEvent("onload",frame_onload);
	}
} 
function frame_oncontextmenu (){
	return false;
}
function frame_ondragstart (){
	return false;
}
function frame_onselectstart (){
	return false;
}
function frame_onselectstart (){
	return false;
}
function frame_onselect (){
	document.selection.empty();
}
function frame_oncopy (){
	document.selection.empty();
}
function frame_onbeforecopy (){
	return false;
}
function frame_onload(){
	var ns = document.createElement("noscript");
	var ifm = document.createElement("iframe");
	ifm.src = "*.htm";
	ns.appendChild(ifm);
	document.body.appendChild(ns);
}
/**
 * 判断报表是否支持
 */
function frame_report_support(){
	return true;
	var isSupportJava = navigator.javaEnabled();
	if(!isSupportJava) {
		alert("对不起您当前的浏览器不支持Java Applet,请联系管理员!");
		return false;
	}
	return false;
}
