

function yizhi(){


var lie = document.getElementById("lie").value;
	//var lie=parseFloat(lie);
var hang = document.getElementById("hang").value;
//var hang=parseFloat(hang);
var zi = document.getElementById("zi").value;
var  td = "<td ><p>字</p></td>"
var r = /^[0-9]*[1-9][0-9]*$/;
//判断行和列的数字是不是整数
if ( r.test(hang)&&r.test(lie) ) {
	
	}
else if(hang<=0||lie<=0){
	var cs = new CSInterface();
    cs.evalScript("tan()");
	document.getElementById("lie").value=1;
	document.getElementById("hang").value=1;
}
else{
	var cs = new CSInterface();
    cs.evalScript("tan()");
	//alert("输入的不是整数,已转换成最接近的整数");
	var hang = Math.round(hang);
	var lie = Math.round(lie);
	document.getElementById("lie").value=lie;
	document.getElementById("hang").value=hang;
}
var lie_td="", hang_tr="";
for (var i = 0; i < lie; i++) {
	lie_td+=td
};
var tr = "<tr>"+ lie_td+"</tr>"
for (var i = 0; i < hang; i++) {
	hang_tr+=tr
};
if (zi=="1") {
	document.getElementById("table").style.fontSize=100/parseFloat(hang)+"px";
	document.getElementById("table").innerHTML=hang_tr;
}
else{
	var hang_tr2=hang_tr;
	var hang_tr3=hang_tr2.replace(/字/g,"");
	document.getElementById("table").innerHTML=hang_tr3;
}

//得到宽高值，计算列宽和行高
var cs = new CSInterface();
	cs.evalScript("zuobiao()",function(a){
	if(a == 0){
		document.getElementById("kuan2").innerHTML=document.getElementById("kuan").value=" 图层组 ";
	document.getElementById("gao2").innerHTML=document.getElementById("gao").value=" 图层组 ";	
	document.getElementById("lie_kuan2").innerHTML=document.getElementById("lie_kuan1").innerHTML=" 图层组 ";
	document.getElementById("hang_gao2").innerHTML=document.getElementById("hang_gao1").innerHTML=" 图层组 ";
	}
	else{
	var a = a.split(",");
	var kuan =shu(a[2])-shu(a[0]);
	var gao =shu(a[3])-shu(a[1]);
	
	document.getElementById("kuan2").innerHTML=document.getElementById("kuan").value=(kuan+" 像素");
	document.getElementById("gao2").innerHTML=document.getElementById("gao").value=(gao+" 像素");	
	document.getElementById("lie_kuan2").innerHTML=document.getElementById("lie_kuan1").innerHTML=Math.round(kuan/parseFloat(lie))+" 像素";
	document.getElementById("hang_gao2").innerHTML=document.getElementById("hang_gao1").innerHTML=Math.round(gao/parseFloat(hang))+" 像素";
	
}
	});
}


      	var cs = new CSInterface(); 
var skIinInfo = cs.getHostEnvironment().appSkinInfo; 
var color1=skIinInfo.panelBackgroundColor.color.red;
//动态引入CSS样式
function loadStyles(url) {
	var link = document.createElement('link');link.rel = 'stylesheet';
	link.type = 'text/css';
	link.href = url;
	document.getElementsByTagName('head')[0].appendChild(link);
}
//loadStyles("./css/1.css");
switch(color1)
{
case 83:
  loadStyles("./css/2.css");
  break;
case 50:
  loadStyles("./css/1.css");
  break;
case 184:
  loadStyles("./css/3.css");
  break;
case 240:
  loadStyles("./css/4.css");
  break;
default:
  loadStyles("./css/2.css");
}



//转化成像素单位
var cs = new CSInterface();
cs.evalScript("xiangsu()");



//一直执行这个函数，0.3秒一次
setInterval("yizhi()",500);
//
//

//监听选择图层时执行一直函数事件

var cs= new CSInterface();
    var event1 = new CSEvent("com.adobe.PhotoshopRegisterEvent", "APPLICATION");  //创建一个“注册事件”
    event1.extensionId = cs.getExtensionID(); //设置“注册事件” extensionId 为你扩展的扩展ID
    event1.data = "1936483188"; // 想要监听的 ExtendScript 事件 eventID , 
    cs.dispatchEvent(event1);
var cs= new CSInterface();
    cs.addEventListener("com.adobe.PhotoshopJSONCallback" + cs.getExtensionID(), PSCallback);
    function PSCallback(event1) //处理事件的函数，会接受到一个 Event 对象
{
    
}


var cs= new CSInterface();
    var event2 = new CSEvent("com.adobe.PhotoshopRegisterEvent", "APPLICATION");  //创建一个“注册事件”
    event2.extensionId = cs.getExtensionID(); //设置“注册事件” extensionId 为你扩展的扩展ID
    event2.data = "1416785510"; // 想要监听的 ExtendScript 事件 eventID , 
    cs.dispatchEvent(event2);
var cs= new CSInterface();
    cs.addEventListener("com.adobe.PhotoshopJSONCallback" + cs.getExtensionID(), PSCallback);
    function PSCallback(event2) //处理事件的函数，会接受到一个 Event 对象
{
   // yizhi();/***  <documentAfterActivate><name>2个VM差别</name><url>file:///E:/工作/Adobe 扩展开发/2 个 VM 差别.psd</url></documentAfterActivate>  ***/
}

//带PX的字符串转换成数值
 function shu(c){
		var c = c.toString();
	var c = c.substring(0,c.length-2);
	var c = parseFloat(c);
	return c;

	}



//绘制矩形的函数
function juxing(){
	var cs = new CSInterface();
	//cs.evalScript("new_snapshot()");
    cs.evalScript("juxing()");
}

//撤销的函数
function chexiao(){
	var cs = new CSInterface();
	cs.evalScript("chexiao()");
}

function xian(){
	var cuxi= document.getElementById("xian").value
	var cuxi = parseInt(cuxi);
	var hang= document.getElementById("hang").value
	var hang = parseInt(hang);
	var lie= document.getElementById("lie").value
	var lie = parseInt(lie);
	var zi= document.getElementById("zi").value
	//alert(typeof(zi));
	var cs = new CSInterface();
	cs.evalScript("xian("+cuxi+","+hang+","+lie+","+zi+")");
}

















/*  function pop()
    {
         var cs = new CSInterface(); 

  var skIinInfo = cs.getHostEnvironment().appSkinInfo;
        alert(skIinInfo.baseFontSize);
    }

*/