//1、把每一个code调试功能的代码放到一个form里面，主要是方便修改查找
//2、调用的时候传值直接传this,通过节点关系找到他们所在的form,然后找到对应的textarea
//3、里面查找textarea的时候需要遍历一次，getElementsByTagName找到第一个textarea，有可能在这个form下会有多个textarea标签，比如调试代码里面有textarea

function RunCode(obj){
	var nodiv = obj.parentNode.parentNode.parentNode.getElementsByTagName("textarea")[0];//此行代码就是找到放调试代码的textarea，如果下面结构变化的话，这里也会爱到影响。
	var code = nodiv.value;
	if (code!=""){
		var newwin=window.open('','','');  
		newwin.opener = null 
		newwin.document.write(code);  
		newwin.document.close();
		}
}

function CopyCode(obj){
	var nodiv = obj.parentNode.parentNode.parentNode.getElementsByTagName("textarea")[0];
	if (document.all){
		 textRange = nodiv.createTextRange(); 
		 textRange.execCommand("Copy"); 
		 alert("代码已经复制到剪切板");
	}
	else{
		 alert("此功能只能在IE上有效\n\n请在文本域中用Ctrl+A选择再复制")
	}
}

function SaveCode(obj) {
	var nodiv = obj.parentNode.parentNode.parentNode.getElementsByTagName("textarea")[0];
	var winname = window.open('','','width=0,height=0,top=1,left=1');
	winname.document.open('text/html', 'replace');
	winname.document.write(nodiv.value);
	winname.document.execCommand('saveas','','Code.htm');
	winname.close();
}
