var zcom_id = "";

var sGSubscribe = "subscribe";
var sGZID		= "account";
var sGLastSubscribeTime = "lastsubscribetime";

var setuplink = '00010010';

var zcom_ver = null;
var oldClient = false;
var haveClient = false;

var magSource = "99990001";
var magChannel = "99990001";

var downloadMsg = {
		DOWNLOAD:'文件已存在您的下载列表中，不能重复下载',
		FAILED:'软件出错。',
		ERRDISK:'您的磁盘空间不足。'
		};



var ActiveXCreated	= false;
ZCOMActiveX_v2		= null;
ZCOMActiveX			= null;



// 检测是否安装过 3.4 以上的客户端
function ClientV340() {
	try {

		createZcomObject();

		var tmp_ver = ZCOMActiveX_v2.GetInfo("ZcomVersion");

		if( (tmp_ver.toUpperCase()).indexOf("P2P") != -1 ){
			return false;
		}

		sZID = ZCOMActiveX_v2.ReadDataFile(sGZID);
		if (!(new RegExp("^(\\d+)$")).test(sZID)) {
			sZID = null;
		}

		return true;
	} catch(x) {
		return false;
	}
}

function createZcomObject(){
		


	if(!document.createElement){
		alert("Your browser is not supported.");
		return;
	}
	
	oAcrivexContainer = document.getElementById("objectContainer");

	if(ActiveXCreated == false){
		
		try{

			var oZcom		= document.createElement("object");

			oZcom.classid	= "clsid:3A7698F3-1BCC-4838-B3BF-EF4E3C5E209A";
			
			ZCOMActiveX_v2	= oZcom;

		}catch(e){}

			
		try{

			var oZcom		= document.createElement("object");
			oZcom.classid	= "clsid:5C30B6DB-CB04-4C8B-B62A-3C3B9E131DA2";

			ZCOMActiveX		= oZcom;


		}catch(e2){}


		ActiveXCreated = true;

	
	}


	
}

function newSetVersion(noAXopen){

	var needSetVersion = false;

	if(haveClient){
		return;
	}

	try{
		zcom_ver = ZCOMActiveX.getVersion();
	}catch(ex){}

	if(zcom_ver == null || zcom_ver == "" || zcom_ver == "unknown"){
		needSetVersion = true;
	} else if( (zcom_ver.toUpperCase()).indexOf("P2P") != -1 ){
		haveClient = false;
		return;
	}else{
		zcom_ver_info = zcom_ver.split(".");
		if(typeof(zcom_ver_info[2]) == "undefined" || isNaN(parseInt(zcom_ver_info[2])) == true || parseInt(zcom_ver_info[2]) < 3 ){
			needSetVersion = true;
		}else if(typeof(zcom_ver_info[3]) == "undefined" || isNaN(parseInt(zcom_ver_info[3])) == true || parseInt(zcom_ver_info[3]) < 30 ){
			needSetVersion = true;
		}
	}

	if(needSetVersion){
		try{
			ZCOMActiveX.setVersion("zcom.normal.1.86.1");
			debug("Set Version: 'zcom.normal.1.86.1'");
			if(ZCOMActiveX.getLocalAppDataDir() != "错误:您还未安装数字杂志客户端,请先下载安装!"){
				oldClient = true;
				haveClient = true;
			}
			debug("Old Client");
		}catch(ex){
			if(noAXopen){
				noActiveXOpen();
			}
		}
	}else{
		if(ZCOMActiveX.getLocalAppDataDir() != "错误:您还未安装数字杂志客户端,请先下载安装!"){
			haveClient = true;
			oldClient = false;
		}
		debug("New Client Version: "+zcom_ver);
	}
}


window.onload = function() {




	var CNCode = "";
	if (get_cookie("cncn") != "") {
		CNCode = get_cookie("cncn");
	} else {
		if (location.search.length == 9) {
			CNCode = location.search.substr(1);
			try {
				setuplink = CNCode;
				mainMenu.innerHTML = '<img src="http://www.zcom.com/viewstats/' + setuplink + '" style="display: none;" />' + mainMenu.innerHTML;
			} catch (exception) {
			}
		}
	}
	if (CNCode != "") {
		set_cookie("cncn", CNCode);
	}
	

	// magSource
	// 2006-6-2
/*
	magSource = (location.search).replace(/[^\d]/g, '');
	if(magSource.length == 8){
		set_cookie_1day("magSource", magSource);
	}else{
		magSource = get_cookie("magSource");
	}
*/



}

/*
var iClientX = 0;
var iClientY = 0;
var iNoActiveXX = 0;
var iNoActiveXY = 0;


var cursorX = 0;
var cursorY = 0;



document.onmousemove = function() {
	
	if (iNoActiveXX == 0) {
		try {
			iNoActiveXX = Math.ceil(noActiveX.offsetWidth / 2);
		} catch (exception) {
		}
	}
	if (iNoActiveXY == 0) {
		try {
			iNoActiveXY = Math.ceil(noActiveX.offsetHeight / 2);
		} catch (exception) {
		}
	}

	iClientX = event.clientX + document.body.scrollLeft - iNoActiveXX;
	iClientY = event.clientY + document.body.scrollTop  - iNoActiveXY;

}
*/

function winPopup(sWinName, iWidth, iHeight) {

	iX = Math.ceil((window.screen.width - iWidth) / 2);
	iY = Math.ceil((window.screen.height - iHeight) / 3);

	sFeatures = "scrollbars = 1, "
	sFeatures += "left = " + iX + ", top = " + iY + ", width = " + iWidth + ", height = " + iHeight;

	window.open('about:blank', sWinName, sFeatures);
}

document.onkeydown = fkeydown;

function fkeydown() {
	if ((event.ctrlKey)&&(event.altKey)) {
		if (event.keyCode == 76) { // Ctrl + Alt + L 调试信息

			newSetVersion(false);

			sZID = ZCOMActiveX.getActiveUser();

			/password\t([0-9a-zA-Z]{32})\n/.exec(ZCOMActiveX.getUserInfo(sZID));
			sPassword = RegExp.$1;

			scZID = get_cookie("member_id");
			scPassword = get_cookie("pass_hash");

			outString = "ActiveX Values\n\n"
				+ "    ZID = " + sZID + "\n"
				+ "    Password = " + sPassword + "\n"
				+ "\nCookie Values\n\n"
				+ "    ZID = " + scZID + "\n"
				+ "    Password = " + scPassword

			alert(outString);
			return false;

		} else if (event.keyCode == 73) {   // 字母 I
			newSetVersion(false);
			alert(ZCOMActiveX.getUserInfo(ZCOMActiveX.getActiveUser()));
			return false;

		} else if (event.keyCode == 79) {   // 字母 O
			newSetVersion(false);
			alert(ZCOMActiveX.getLocalXML("/downloads/record.xml"));
			return false;

		} else if (event.keyCode == 80) {   // 字母 P
			newSetVersion(false);
			alert(ZCOMActiveX.getLocalXML("/oem.xml"));
			return false;

	} else if (event.keyCode == 67) {   // 字母 C
			alert(document.cookie.replace(/; /g, ";\n\n"));
			return false;
		}
	}
}

function closePopup() {
	noActiveX.style.display = 'none';
}





var laterHash;

function mOpt(sHash, sType) {

	var temp = false;

	if (ClientV340()) {
		//alert("Client 3.4");
		xmlData = document.all.item("xmlData_" + sType + "_" + sHash + "_v2");
		if (xmlData[1]) { // 防止重复，如果重复（为数组）则去第一个。
			xmlData = xmlData[0];
		}
		xmlData = xmlData.innerHTML;
		xmlData = xmlData.replace(/&lt;/g, "<").replace(/&gt;/g, ">");

		// mag source
		// jsm 2006-5-27
		getMagSource();
		magSource = magSource.replace(/[^\d]/g, '');
		if(magSource.length == 8){
			xmlData = xmlData.replace(" magSource=\"0\"", " magSource=\"" + magSource + "\"");
		}
		//alert(xmlData);
		var downloadStatus = ZCOMActiveX_v2.send(xmlData);

		switch(downloadStatus.toLowerCase()){
			case 'downloading':	alert(downloadMsg.DOWNLOAD);break;
			case 'complete':	openComplete(sHash);break;
			case 'errdisksp':	alert(downloadMsg.ERRDISK);break;
			case 'failed':		alert(downloadMsg.FAILED);break;
		}

		try {
			/\sid=\"([0-9]+)\"\s/.exec(xmlData);
			var clickZzid = RegExp.$1;
			document.getElementById("clickTrackImg").src = "http://tempanalytics.zcom.com/t/magazine2/" + clickZzid ;

		} catch(e) {
		}

		temp = true;

	} else {

		try {
			newSetVersion(false);
			if(haveClient == false){
				noActiveXOpen();
			} else if (ZCOMActiveX.getLocalAppDataDir() != "错误:您还未安装数字杂志客户端,请先下载安装!") {
				temp = true;
			} else {
				noActiveXOpen();
			}
		} catch (exception) {
			noActiveXOpen();
		}



		if (temp == true) {
			//alert("Client 3.3");
			xmlData = document.all.item("xmlData_" + sType + "_" + sHash);
			if (xmlData[1]) { // 防止重复，如果重复（为数组）则去第一个。
				xmlData = xmlData[0];
			}
			xmlData = xmlData.innerHTML;
			xmlData = xmlData.replace(/&lt;/g, "<").replace(/&gt;/g, ">");

			if(oldClient == true){
				xmlData = getOldXmlData(xmlData);
			}//else{
			//	xmlData = getNewXmlData(xmlData);
			//}

			debug(xmlData);
 
			ZCOMActiveX.SenMessage(xmlData);
			debug("Finish SendMessage");
			if ((sType == "Delete")||(sType == "Open")) {
				XMLRebuild();
			}

			try{
				/\sid=\"([0-9]+)\"\s/.exec(xmlData);
				var clickZzid = RegExp.$1;
				document.getElementById("clickTrackImg").src = "http://tempanalytics.zcom.com/t/magazine2/" + clickZzid ;

			}catch(ex){}

		}

	}


	if( sType == 'Download' ){

		var d_mode = '0' ;

		if(temp == true){

			d_mode = '1' ;
		}

		try{
			document.getElementById("myHiddenIframe").src = "/download_later_x340b.html?" + sHash + "_" + d_mode ;
		}catch(exx){}
	}

}



function mOptHT(sHash, sType) {

	var ht_have_cl = false;

	if (ClientV340()) {
		ht_have_cl = true;

	} else {

		try {
			newSetVersion(false);
			if(haveClient == false){
			
			} else if (ZCOMActiveX.getLocalAppDataDir() != "错误:您还未安装数字杂志客户端,请先下载安装!") {
				ht_have_cl = true;
			}
		} catch (exception) {
		}

	}


	if(ht_have_cl == true){
		mOpt(sHash, sType);
	} else {

		try{

			var mid = 0;
			var msz = 0;


			xmlData = document.getElementById("xmlData_" + sType + "_" + sHash);
			xmlData = xmlData.innerHTML;
			xmlData = xmlData.replace(/&lt;/g, "<").replace(/&gt;/g, ">");

			/\sid=\"([0-9]+)\"\s/.exec(xmlData);
			mid = RegExp.$1;

			/\sfileSize=\"([0-9]+)\"\s/.exec(xmlData);
			msz = RegExp.$1;

			location.href = "http://httpdown.zcominc.com/magazine/file/" + mid + ".exe";
			httpDown(mid, msz);
		
		}catch(e){}
	}

}




function getOldXmlData(xData){

	var reOld = new RegExp(" caseCate=\"([0-9]+)\" ");
	var oldCategory = xData.match(reOld);
	if(typeof(oldCategory[1]) != "undefined" && oldCategory[1] != "" && oldCategory[1] != null && isNaN(parseInt(oldCategory[1])) != true && oldCategory[1] > 0 ){

		var reNew = new RegExp(" category=\"[0-9]+\" ");
		var newCategory = xData.match(reNew);
		xData = str_replace(newCategory[0], " ", xData);
		xData = str_replace(" caseCate=", " category=", xData);
	}

	return xData;
}

function getNewXmlData(xData){

	var reOld = new RegExp(" caseCate=\"([0-9]+)\" ");
	var oldCategory = xData.match(reOld);
	if(typeof(oldCategory[0]) != "undefined" && oldCategory[1] != "" && oldCategory[1] != null ){
		xData = str_replace(oldCategory[0], " ", xData);
	}
	xData = str_replace(" caseCate=\"\"", " ", xData);
	return xData;
}

function mycase() {

	if (ClientV340()) {

		ZCOMActiveX_v2.send('<'+'?xml version="1.0" encoding="UTF-8"?'+'><item action="OpenLocal" infoName="书柜" />');

	} else {

		try {
			newSetVersion(false);
			if(haveClient == false){
				noActiveXOpen();
				return;
			}
			if (ZCOMActiveX.getLocalAppDataDir() != "错误:您还未安装数字杂志客户端,请先下载安装!") {
				location.href = "http://www.zcom.com/mycase.html";
			} else {
				iClientY += (iNoActiveXX / 2) + 20;
				noActiveXOpen();
			}

		} catch (exception) {
			iClientY += (iNoActiveXX / 2) + 20;
			noActiveXOpen();
		}
	}
}

function callManage() {

	if (ClientV340()) {

		ZCOMActiveX_v2.send('<'+'?xml version="1.0" encoding="UTF-8"?'+'><item action="OpenLocal" infoName="进度" />');

	} else {

		try {
			newSetVersion(false);
			if(haveClient == false){
				noActiveXOpen();
				return;
			}
			if (ZCOMActiveX.getLocalAppDataDir() != "错误:您还未安装数字杂志客户端,请先下载安装!") {
				xmlData = '<'+'?xml version="1.0" encoding="UTF-8" ?'+'>\n'
					+ '<item type="callWindow" window="downloadManage" />';
				ZCOMActiveX.SenMessage(xmlData);
			} else {
				iClientY += (iNoActiveXX / 2) + 20;
				noActiveXOpen();
			}
		} catch (exception) {
			iClientY += (iNoActiveXX / 2) + 20;
			noActiveXOpen();
		}
	}
}

function noActiveXOpen() {

	getMagSource();

	try{
		window.showModalDialog('http://mag.zcom.com/download_message/?' + magChannel,'','dialogHeight:385px;dialogWidth:436px;resizable:no;center:yes;help:no;status:no;');
	}catch(e){
		try{
			window.openDialog('http://mag.zcom.com/download_message/?' + magChannel,'ZCOM');
		}catch(e){}
	}
	

/*

	try {

		if(iClientY < 10){
			iClientY = 10;
		}

		var maxX = document.body.clientWidth - 400 ;

		if(iClientX > maxX ){
			iClientX = maxX;
		}

		noActiveX.style.posLeft = iClientX;
		noActiveX.style.posTop  = iClientY;

		noActiveX.style.display   = "block";

	} catch (exception) {
		alert(exception.description);
	}
*/
}



// 读写 COOKIE


function set_cookie(sKey, sValue) {
	var tcookie_time = new Date();
	var tcookie_expiry = new Date(tcookie_time.getTime() + 1000 * 3600 * 24 * 31* 24);
	document.cookie = sKey + "=" + sValue + "; expires=" + tcookie_expiry.toGMTString()
		+ "; domain = .zcom.com; path = /";
}

function set_cookie_1day(sKey, sValue) {
	var tcookie_time = new Date();
	var tcookie_expiry = new Date(tcookie_time.getTime() + 1000 * 3600 * 24);
	document.cookie = sKey + "=" + sValue + "; expires=" + tcookie_expiry.toGMTString()
		+ "; domain = .zcom.com; path = /";
}

function set_cookie_thisDomain(sKey, sValue) {
	var tcookie_time = new Date();
	var tcookie_expiry = new Date(tcookie_time.getTime() + 1000 * 3600 * 24 * 31* 24);
	document.cookie = sKey + "=" + sValue + "; expires=" + tcookie_expiry.toGMTString()
		+ "; path = /";
}

function get_cookie(Name) {
	var search = Name + "="
	var returnvalue = "";
	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;
			returnvalue = unescape(document.cookie.substring(offset, end))
		}
	}
	return returnvalue;
}





///////////订阅 test中
var updateSublist = false;
var subscribeSendProc = false;

//订阅主方法,参数为杂志id.-0-
function subscribeMe( zzhID){

	if (ClientV340()) {
		sSubscribe = ZCOMActiveX_v2.ReadDataFile(sGSubscribe);
		if ((sSubscribe == "FALSE")||(sSubscribe == "")) {
			sSubscribe = ",";
		}
		if (sSubscribe.indexOf("," + zzhID + ",") == -1) {
			sSubscribe += zzhID + ",";
			sub_tmp = true;
			ZCOMActiveX_v2.WriteDataFile(sGSubscribe, "w", sSubscribe);
		}else{

			if(confirm("您确定要退订本杂志么?") == false){
				return;
			}

			sSubscribe = str_replace("," + zzhID + ",", ",", sSubscribe);
			sub_tmp = false;
			ZCOMActiveX_v2.WriteDataFile(sGSubscribe, "w", sSubscribe);
		}


	} else {

		var sub_tmp = false;
		//检测控件存在
		try {
			newSetVersion(false);
		
			if(haveClient == false){
				noActiveXOpen();
				return;
			} else if (ZCOMActiveX.getLocalAppDataDir() != "错误:您还未安装数字杂志客户端,请先下载安装!") {
				
			} else {
				noActiveXOpen();
				return;
			}
		
		} catch (exception) {
			return ;
		}

		//alert("处理订阅");
		//记录用户订阅信息
		sZID = ZCOMActiveX.getActiveUser();

		if ((sZID != "unknow")&&(sZID > 0)) {


			if(sSubscribe == null) sSubscribe = readSubscribe();

			if(sSubscribe=='blank' || sSubscribe==''){
				sSubscribe = ',';
			}

			if( sSubscribe.indexOf(','+zzhID+',') == -1 ){
				//订阅
				sub_tmp = true;

				sSubscribe = sSubscribe + zzhID + ',' ;

			}else{

				if(confirm("您确定要退订本杂志么?") == false){
					return;
				}

				//取消订阅
				sub_tmp = false;
				re = new RegExp(","+zzhID+",");
				sSubscribe = sSubscribe.replace(re, ",");

			}

			saveSubscribe(sSubscribe);

			try{
				if(subscribeSendProc == false){
					setTimeout("sendSubscribe();", 2000);
					subscribeSendProc = true;
				}
			}catch(ess){}
		}

	}


	//switch subscribe image
	

	if(sub_tmp){
		setSubscribeImg('no', zzhID);

		// market 070323
		if(zzhID == '3200'){
			window.open("http://60.28.197.44/apps/mk_070323/", "nWin", "height=335,width=280,top=100,left=500,status=no,toolbar=no,menubar=no,location=no");
		}

	}else{
		setSubscribeImg('yes', zzhID);
	}


	//reload subscribe menu
	if(load_menu_done == true){
		updateSublist = true;
		setTimeout("initSubscribeMenu()",100);
		//initSubscribeMenu();
	}

}

var load_menu_done = false;

//初始化 subscribe image
// 在img标签中用onload调用
function initSubscribeImg(zzhID){

	
	if (ClientV340()) {
		sSubscribe = ZCOMActiveX_v2.ReadDataFile(sGSubscribe);
		if ((sSubscribe == "FALSE")||(sSubscribe == "")) {
			sSubscribe = ",";
		}


	} else {
		try {
			newSetVersion(false);
			//用户订阅信息
			sZID = ZCOMActiveX.getActiveUser();

			if ((sZID != "unknow")&&(sZID > 0)) {
				if(sSubscribe == null) sSubscribe = readSubscribe();
			}

		} catch(e) {
		}
	}


	if(sSubscribe == null || sSubscribe == "" || sSubscribe == ","){
		setSubscribeImg('yes', zzhID);
		return;
	}

	if(zzhID != '0'){
		if( sSubscribe.indexOf(','+zzhID+',') == -1 ){
			setSubscribeImg('yes', zzhID);
		}else{
			setSubscribeImg('no', zzhID);
		}

	}else{

		var subInfo = sSubscribe.split(",");

		for(var i=0;i<subInfo.length;i++){
			setSubscribeImg('no', subInfo[i]);
		}
	}



}


function setSubscribeImg(img_stl, zzhID){

	if(img_stl=='') img_stl='yes';

	img = document.getElementById("img_subs");
	
	img_re = new RegExp("_(blank|yes|no|32)\\.png$");

	if(img != null){

		if(zzhID == '3200' && img_stl == 'yes'){
			// mk_070323
			img.src = img.src.replace(img_re, '_32.png');	
			return;
		}

		img.src = img.src.replace(img_re, '_'+ img_stl +'.png');
		return;
	}
	
	// category subscribe
	// 2006-6-1
	try{
		var imgc = document.all.item("subs_img_"+zzhID);
		
		if(typeof(imgc) != "undefined"){
		

			if(typeof(imgc.length) != "undefined"){
				for(var i=0;i<imgc.length;i++){
					imgc[i].src = document.getElementById("subs_" + img_stl + "_p").src ;
				}
			}else{
				imgc.src = document.getElementById("subs_" + img_stl + "_p").src ;
			}

		}

	}catch(ex){}


	try{

		var imgc2 = document.all.item("subs_img2_"+zzhID);
		
		if(typeof(imgc2) != "undefined"){
		

			if(typeof(imgc2.length) != "undefined"){
				for(var i=0;i<imgc2.length;i++){
					imgc2[i].src = document.getElementById("subs_" + img_stl + "_p2").src ;
				}
			}else{
				imgc2.src = document.getElementById("subs_" + img_stl + "_p2").src ;
			}

		}

	}catch(ex){}

}

//搜索框
function fnCheckSearchBox(oSe){

	if(oSe.value=='杂志搜索'){
		oSe.value="";
		return false;
	}


	oSe.focus();
	oSe.select();

	if(oSe.value==''){
		return false;
	}

	return true;
}

function goSearch(checkEnter){

	if(checkEnter){

		if(event.keyCode != 13){
			return;
		}

	}

	fmObj = document.getElementById('search_form');
	inpObj = document.getElementById('inp_keyword');


	if(fnCheckSearchBox(inpObj)){

		try{
			var act = fmObj.action;
			fmObj.action = act + "/" + encodeURI(inpObj.value) ;
			fmObj.submit();
			fmObj.action = act;
		}catch(e){}

	}
	return false;

}


function switchCategoryList(cid){
	
	try{

		o = document.getElementById("tb_sub_" + cid);
		m = document.getElementById("a_" + cid);
		if (o == null) return;
		if (o.style.display == 'block') {
			o.style.display = 'none';
			if (m) m.innerHTML = img_menu_open;
		} else {
			o.style.display = 'block';
			if (m) m.innerHTML = img_menu_close;
		}

	}catch(e){}
}

function openComplete(sHash){

	if(confirm('此杂志已下载，是否立即阅读？') != true){

		return;

	}

	var sXML = '<'+'?xml version="1.0" encoding="utf-8"?'+'>'
		+ '<item action="OpenFile" hash="' + sHash + '" />';

	ZCOMActiveX_v2.Send(sXML);

}

function getMagSource(){

	/*	ver: 2006-7-7
		magSourceT: temp
		magSourceN: new from cookie and config
		magSourceC: value of cookie
	*/

	var magSourceT = "";
	var magSourceN = "";


	var magChannelN = "";

	if(location.search != ""){
		var queryString = location.search;
		magSourceT = queryString.replace(/[^\d]/g, '');
		if(magSourceT.length == 8){
			magSourceN = magSourceT;
		}
	}

	if(magSourceT.length == 16){
		magChannelN	= magSourceT.substring(8, 16);
		magSourceN	= magSourceT.substring(0, 8);

	}


	// mag source
	if(magSourceN.length != 8){
		var magSourceC = get_cookie("magsource");
		if(magSourceC.length == 8){
			magSource = magSourceC;
		}
	}else{
		set_cookie_1day("magsource", magSourceN);
		magSource = magSourceN;
	}



	// mag channel
	if(magChannelN.length != 8){
		var magChannelC = get_cookie("magchannel");
		if(magChannelC.length == 8){
			magChannel = magChannelC;
		}
	}else{
		set_cookie_1day("magchannel", magChannelN);
		magChannel = magChannelN;
	}

	return magSource;

}



function openPreview(url){

	if((window.navigator.userAgent).indexOf('MSIE') != -1){
		window.showModelessDialog(url,'','dialogHeight:580px;dialogWidth:750px;resizable:no;center:yes;help:no;status:no;');
		
	} else {

		location.href = url;

	}

}



function changeCateTab(cateType){

	
	if(cateType == 'mag'){
			
		_ge("catetab_mag").className = 'sel';
		_ge("catetab_org").className = 'unsel';

		_ge("menuMag").style.display = 'block';
		_ge("menuOrg").style.display = 'none';

	}else{

		_ge("catetab_mag").className = 'unsel';
		_ge("catetab_org").className = 'sel';

		_ge("menuMag").style.display = 'none';
		_ge("menuOrg").style.display = 'block';

	}

}


function _ge(id){
	return document.getElementById(id);
}




var cacheStatus = "";
var aStatusList = {
	"doc":"书柜",
	"task":"进度",
	"help":"帮助",
	"subscribe":"订阅"
};
var bOnlineMark = false;

function fnStatusBarButtonGoPage(sStatus) {

	if(ClientV340()){

		if(typeof(sStatus) != "undefined"){
			cacheStatus = sStatus ;
		}

		if( extractVersion() == 0 ){
			ZCOMActiveX_v2.send('<'+'?xml version="1.0" encoding="UTF-8"?'+'><item action="OpenLocal" infoName="' + aStatusList[cacheStatus] + '" />');
			return;
		}

		if( extractVersion() < 350 ){
			
			window.showModalDialog('http://mag.zcom.com/update_message/?' + magChannel,'','dialogHeight:385px;dialogWidth:436px;resizable:no;center:yes;help:no;status:no;');

			return;
		}
		
		if( ZCOMActiveX_v2.GetInfo("ZcomRunning") != "TRUE"){
			
			ZCOMActiveX_v2.GetTaskInfo("0", "status");
			setTimeout("fnStatusBarButtonGoPage()", 500);
			return;

		}

		var baseLocalURL ;
		
		if(bOnlineMark == true){
			baseLocalURL = (ZCOMActiveX_v2.Getlocalhost()).replace("127.0.0.1", "local.zcom.com") + "/client/" + cacheStatus + "/";
		} else {
			baseLocalURL = ZCOMActiveX_v2.Getlocalhost() + "/client/" + cacheStatus + "/";
		}


		if(baseLocalURL.indexOf("http://") == -1){
			setTimeout("fnStatusBarButtonGoPage()", 1000);
			return;
		}
		

		location.href = baseLocalURL;


	} else {

		switch(sStatus){

			case "doc":
				mycase();
			break;

			case "task":
				callManage();
			break;

			case "subscribe":
				mycase();
			break;

			case "help":
				location.href = "http://www.zcom.com/soft_down/sysm.html";
			break;

		}

	}
}

var sGSearchStr = "";
function fnWriteFile(){}


function extractVersion(){

	var sVer = ZCOMActiveX_v2.GetInfo("zcomVersion");

	if(sVer.indexOf("zcom.lite") == -1){
		// not the common version, send cancle message.
		return 0;
	}

	var aVer = sVer.split(".");

	var mainVer = parseInt(aVer[2]);
	var subVer = parseInt(aVer[3]);

	if(isNaN(mainVer)){
		mainVer = 0;
	}

	if(isNaN(subVer)){
		subVer = 0;
	}

	if(subVer < 10){
		subVer = subVer * 10;
	}

	return mainVer * 100 + subVer;

}




// http

function httpDown(mid, sz){

	var hd_zid = getRegZID();
	var hd_channelID = '00000000';
	var hd_time = (new Date()).getTime();
	var hd_rand = parseInt( Math.random()* hd_time ) + 1;


	var hd_container = document.getElementById('clickTrackImg');
	var hd_stat_src = ''
			+'http://magstat.zcominc.com/clientaction/click/zcom/http/80'
			+'/'+hd_zid
			+'/'+hd_channelID
			+'/'+hd_rand
			+'/'+mid
			+'/5'
			+'/'+sz
			+'/0'
			+'/99990008'
			+'';

	try{
		hd_container.src = hd_stat_src;
	}catch(e){}

	return true;

}

function checkHttpDown(mid, sz){
	if(event.keyCode = 31){
		httpDown(mid, sz);
	}
	return true;
}

function getRegZID(){
	var sZID = "0";
	try{
		createZcomObject();

		if(ZCOMActiveX_v2 != null){
			sZID = ZCOMActiveX_v2.ReadDataFile(sGZID);
			if (!(new RegExp("^(\\d+)$")).test(sZID)) {
				sZID = "";
			}
		} else if(ZCOMActiveX != null){
			sZID = ZCOMActiveX.getActiveUser();
		}

		if(sZID == ''){
			sZID = '0';
		}
	}catch(e){}
	return sZID;
}


// ver 070115


