//保存代码
function saveCode(obj) {
        var winname = window.open('', '_blank', 'top=10000');
        winname.document.open('text/html', 'replace');
        winname.document.write(obj.value);
        winname.document.execCommand('saveas','','code.htm');
        winname.close();
}

function saveCode1(daima) {
        var winname = window.open('', '_blank', 'top=10000');
        winname.document.open('text/html', 'replace');
        
		//window.alert("\请输入您的用户名 ?"); 
		
		winname.document.write(document.getElementById("daima").value);
		//window.alert(getElementById(obj).value); 
		//window.alert(document.getElementById("daima").value); 
		
        winname.document.execCommand('saveas','',document.getElementById("title").value+'.htm');
        winname.close();
}

//将代码以JS方式加密、解密
 function jsencode(obj)
 {
    var v = getid('daima').value;
    var es = escape(v);
    return String.format("document.write(unescape('{0}'));",es);
 }
 
function jsdecode(obj)
 {
    var v = getid('daima').value;
    var regex = /unescape\('([a-z%0-9]*)'\)/i;
    if(v.match(regex))
    {
        getid('daima').value = unescape(RegExp.$1);
    }
 }
 
 function test()
 {
    var win = window.open();
    win.document.open();
    win.document.write(getid('daima').value);
    win.document.close();
 }
 
 
String.format = function()
{
    if(arguments.length==0)
        return null;
    var str = arguments[0];
    for(var i=1;i<arguments.length;i++)
    {
      var regExp = new RegExp('\\{' + (i-1) + '\\}','gm');
      str = str.replace(regExp,arguments[i]);
    } 
    return str;
}
 
 function getid(id)
{
    return (typeof id == 'string')?document.getElementById(id):id; 
}

function t()
{
    //alert(jsencode(ipt)); 
	
	//var win = window.open();
    //document.open();
	//document.write('<\script>');
    document.write('<\script>'+jsencode(daima)+'<\/script>');
	//document.write('vv');
	//document.write('<\/script>');
    //document.close();
}
