/* 
 * p公共js代码
 * 
 */

/**
 * 选中一个复选框后其他的复选框都不能选择
 * @param parentId 包含所有复选框的元素id
 * @param inputsId 复选框id,该复选框被选中后其他复选框都不能再选择
 **/
function chooseOne(parentId, inputsId) {
	var cb1 = $("#"+inputsId);
	var other = $("#"+parentId+" :checkbox[id!='"+inputsId+"']");
	cb1.bind('click', {'cb1':cb1, 'other':other}, function(event) {
		var cb1 = event.data.cb1;
		var other = event.data.other;
		setTimeout(function(){
			if(cb1.get(0).checked) {other.each(function(){
				this.checked = false; this.disabled = true;
			});}else {other.each(function(){
				this.checked = false; this.disabled = false;
			});}
		}, 2, cb1, other);
	});
	other.bind('click', {'cb1':cb1, 'other':other}, function(event) {
		var cb1 = event.data.cb1;
		var other = event.data.other;
		setTimeout(function(){
			var num = 0;
			other.each(function() {if(this.checked){num++;}});
			if(num > 0) {
				cb1.get(0).checked = false;cb1.get(0).disabled = true;
			}else {
				cb1.get(0).checked = false;cb1.get(0).disabled = false;
			}
		}, 2, cb1, other);
	});
}

/**
 * 全选和取消全选
 * @param parentId 包含所有复选框的元素id
 * @param inputsId 复选框id,该复选框被选中后其他复选框全部选中
 */
function chooseAll(parentId, inputsId) {
	var cb1 = $("#"+inputsId);
	var other = $("#"+parentId+" :checkbox[id!='"+inputsId+"']");
	cb1.bind('click', {'cb1':cb1, 'other':other}, function(event) {
		var cb1 = event.data.cb1;
		var other = event.data.other;
		setTimeout(function(){
			if(cb1.get(0).checked) {other.each(function(){
				this.checked = true;
			});}else {other.each(function(){
				this.checked = false;
			});}
		}, 2, cb1, other);
	});
	other.bind('click', {'cb1':cb1, 'other':other}, function(event) {
		var cb1 = event.data.cb1;
		var other = event.data.other;
		setTimeout(function(){
			var num = 0;
			other.each(function() {if(this.checked){num++;}});
			if(num == other.length) {
				cb1.get(0).checked = true;
			}else {
				cb1.get(0).checked = false;
			}
		}, 2, cb1, other);
	});
}
/**
 * 全选和取消全选
 * 参数 parentId 包含所有复选框的元素id
 * 参数 ckAllId 全选按钮id
 * 参数 reverseId 反选按钮id
 * 参数 chooseOneId
 */
function chosOther(parentId, ckAllId, reverseId, inputsId) {
	var cb1 = $("#"+ckAllId);	//全选框
	var cb2 = $("#"+reverseId);		//反选框
	var other = $("#"+parentId+" :checkbox[id!='"+ckAllId+"'][id!='"+reverseId+"']");	//包含所有复选框的元素
	var cb3 = $("#"+inputsId);
	cb1.bind('click', {'other':other}, function(event){
		//if(this.value == )
		var other = event.data.other;
	});
	cb1.bind('click', {'other':other}, function(event){
		
	});

}

/**
 * 设为首页
 */
function setHomepage(url) {
	if (document.all) {
		document.body.style.behavior='url(#default#homepage)';
		document.body.setHomePage(url);
	} else if (window.sidebar) {
		if(window.netscape) {
			try {
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
			} catch (e) {
				alert( "该操作被浏览器拒绝，如果想启用该功能，请在地址栏内输入 about:config,然后将项 signed.applets.codebase_principal_support 值该为true" );
			}
		}
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components. interfaces.nsIPrefBranch);
		prefs.setCharPref('browser.startup.homepage',url);
	}
}

/**
 * 加入收藏
 */
function addFavorite(title, url) {
	if (document.all) {
		window.external.addFavorite(url,title);
	} else if (window.sidebar) {
		window.sidebar.addPanel(title, url, "");
	}
}

function doPrint(styleurl)
{
	var newnav = document.getElementById("newnavi").innerHTML;
	var newtitle = document.getElementById("newtitle").innerHTML;
	var newcon = document.getElementById("newcon").innerHTML;
	var tempWin=window.open("","","toolbar=yes,scrollbars=yes,resizable=no");

	tempWin.document.open("text/html");
	tempWin.document.write("<table width='674px' border='0' align='center' style=\"margin-top:10px; border:1px solid #CCCCCC;margin:10px auto 0;\"><tr><td align=\"right\" style=\"margin-right:20px; margin-bottom:20px;\">");
	tempWin.document.write("<input type=\"button\" class=\"print_button\" id=\"printbtn\" onclick=\"document.getElementById('printbtn').style.display='none';document.getElementById('printbtn2').style.display='none';window.print();\" value=\"打印\" style=\"display:block;height:23px;_height:24px;width:60px; background: url('"+styleurl+"/cn/images/print/btn.jpg') no-repeat; text-align:center;border:0;border:none;cursor:pointer\" /></td></tr><tr><td>");
	tempWin.document.write("<table border=\"0\" width=\"100%\"><tr><td style=\"font-size:12;line-height:45px;margin-bottom:10px;padding-left:5px;\" align=\"right\"><span style=\"float:left;\">");
	tempWin.document.write(newnav);
	tempWin.document.write("</span><span style\"text-align:right;margin-left:100px;float:right;padding-right:5px;\"><img src=\""+styleurl+"/cn/common/bygongchang.gif\" /></span></td></tr><tr><td style=\"font-size:18;text-align:center;font-weight:bold;line-height:30px;\">");
	tempWin.document.write(newtitle);
	tempWin.document.write("</td></tr><tr><td style=\"font-size:14;line-height:24px;padding-left:5px;padding-right:5px;padding-bottom:30px;\">");
	tempWin.document.write(newcon);
	tempWin.document.write("</td></tr></table>");
	tempWin.document.write("</div>");
	tempWin.document.write("</td></tr><tr><td align=\"right\" style=\"margin-right:5px;\"><input type=\"button\" class=\"print_button\" id=\"printbtn2\" onclick=\"document.getElementById('printbtn').style.display='none';document.getElementById('printbtn2').style.display='none';window.print();\" value=\"打印\" style=\"display:block;height:23px;_height:24px;width:60px; background: url('"+styleurl+"/cn/images/print/btn.jpg') no-repeat; text-align:center;border:0;border:none;cursor:pointer\" />");
	tempWin.document.write("</td></tr></table>");
	tempWin.document.close();
}

function refer_clipboard()
{
	var e = window.location.href;
	var strurlarr = e.split("#");
	var txt = strurlarr[0];
	if(window.clipboardData)
	{
		window.clipboardData.clearData();
		window.clipboardData.setData("Text", txt);
		alert("链接已成功复制到剪切板");
	}
	else if(navigator.userAgent.indexOf("Opera") != -1)
	{
		window.location = txt;
	}
	else if (window.netscape)
	{
		try
		{
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
		}
		catch (e)
		{
			alert("被浏览器拒绝！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
		}
		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) 	return;
		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if (!trans)	return;
		trans.addDataFlavor('text/unicode');
		var str = new Object();
		var len = new Object();
		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
		var copytext = txt;
		str.data = copytext;
		trans.setTransferData("text/unicode",str,copytext.length*2);
		var clipid = Components.interfaces.nsIClipboard;
		if (!clip)   return false;
		clip.setData(trans,null,clipid.kGlobalClipboard);
		alert("链接已成功复制到剪切板！")
	}
}

