﻿document.write('<div id="jsInterface"><script type="text/javascript" id="icibaTest" charset="UTF-8"></script></div>');
function load(){
	
  var ctx=['Dict','Love' ,'Fy', 'Tf', 'Dj','Enen','NetDict' ];
  //alert(K.language); http://plugin.iciba.com/ui.php icibaJsInterface
 // return;
  //document.getElementById('icibaJsInterface').src='http://www.baidu.com';
 // return ;
 
  str='';
  for(i=0;i<ctx.length;i++){
    str+='<li id="'+ctx[i]+'" '+(i==1?'class="select"':'')+' onclick="javascript:icibaSelect(event);"><table> <tr><td height="32" ><input type="checkbox" name="iciba[]" value="'+ctx[i]+'" id="" onclick="javascript:cCheck(event)" checked/>'+K.language.cn[ctx[i]]+'</td><td height="32"><input type="radio" name="icibaGo_'+ctx[i]+'"  value="" checked/>默认展开</td><td height="32"><input type="radio" name="icibaGo_'+ctx[i]+'" value="none" />默认收起</td></tr></table></li>   ';
  }
  K.$('sdContentW').innerHTML=str;
  K.observe(K.$('sdContentW'),'click',initContext);
  gx();
}

function cCheck(e){
	e = e || window.event;
    var src = e.srcElement || e.target; 
	p= elSearch(src,'li');
	//alert(src.id);
	var tmp=p.getElementsByTagName('input');
	
	
		for(i=0;i<tmp.length;i++){
			if(tmp[i].type=='radio')tmp[i].disabled=!src.checked;
		}
	

}
function elSearch(note,tagName){
   
   if(typeof note =='undefined') return null;
   if(note.tagName.toLowerCase()==tagName.toLowerCase()){return note;}
   else {return elSearch(note.parentNode,tagName);}

}
function icibaSelect(e){
    e = e || window.event;
    var src = e.srcElement || e.target; 
	//
	//if(src.tagName!='li'){}
	src= elSearch(src,'li');
	//alert(src.tagName);
	var p=src.parentNode;
   
	var els=p.getElementsByTagName('li');
	for(i=0;i<els.length;i++) els[i].className='';
	src.className='select';
}

function changeContent(type){
   //alert(type);
   
   tem= K.$('sdContentW').getElementsByTagName('li');  
   selectIndex= -1;
   for(i=0;i<tem.length;i++){
      if(tem[i].className=='select'){  selectIndex=i;break;}
   }
   changIndex= type=='up'?(selectIndex-1):(selectIndex+1);
   if(changIndex<0){alert('已经为第一项！'); return;}
   if(changIndex>=tem.length){alert('已经为最后一项！') ;return;}
   up=changIndex>selectIndex?changIndex:selectIndex;
   down=changIndex>selectIndex?selectIndex:changIndex;
  // dlN=K.$('sdContentW').removeChild(tem[down]);
   K.$('sdContentW').insertBefore(K.$('sdContentW').removeChild(tem[down]),tem[up]);
   initContext();
}

function contextItem(tInput){   
      tArr=new Array();
	  for(j=0;j<tInput.length;j++){
	    if(tInput[j].type=='checkbox'){
		  if( tInput[j].checked)tArr[0]=tInput[j].value;
		  else return false;
		}
		if(tInput[j].type=='radio' && tInput[j].checked)tArr[1]=tInput[j].value;
	  }
	  return tArr;
}

function getContext(){
  tem= K.$('sdContentW').getElementsByTagName('li'); 
   j=0;
   str='';
   cont='';
   for(i=0;i<tem.length;i++){      
	  tInput=tem[i].getElementsByTagName('input');	  
	  t=contextItem(tInput);
	  if(t){
	     str+=cont+"['"+t[0]+"','"+t[1]+"']";
		 cont=',';
	  }
      
   }
   if(str=='')return false;
   return str;
}

function initContext(){

   K.CClose();
   //iciba_param['context']=new Array();
   str=getContext();
   if(!str) return false;
   iciba_param['context']=eval('['+str+']');
  if(typeof(iciba_param['context']) !='undefined' && iciba_param['context'].length>0){
		try{
			tLanguage= _icibaLanguage=='en'?K.language.en:K.language.cn;
			var contextHtml='';
			for(i=0;i<iciba_param['context'].length;i++){
				var el=iciba_param['context'][i];
				if(i>0)contextHtml+='<div id="iciba'+el[0]+'" class="icibaItemTitle">'+tLanguage[el[0]]+'<span class="icibaItemIcon">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span> </div>			<div id="iciba'+el[0]+'_context" class="icibaItemContext" isDisplay="'+el[1]+'">Loading......</div>';
				else contextHtml+='<div id="iciba'+el[0]+'_context" class="icibaItemContext">Loading......</div>'
			}
			//alert(contextHtml);
			K.$('icibaContext').innerHTML=contextHtml;
		}catch(e){

		}
	}
	K.regShow();
	gx();
}
//改版风格
function cStyle(e){
    e = e || window.event;
    var src = e.srcElement || e.target;
    var n=parseInt(src.value)-1;
	css=(K.skin[n].url);
	
	if(K.$('icibaCssInterface')){
		K.$('icibaCssInterface').href=css;
	}else if(K.$('icibaCssDefault')){
		K.$('icibaCssDefault').href=css;
	}
	gx();
}

//改版长 宽
function changObj(e){
    e = e || window.event;
    var src = e.srcElement || e.target;
	//alert(src.name);
	switch (src.name)
	{
	case 'searchInputDisplay':
	   K.$('icibaSearchToolBar').style.display = src.value=='none'?'none':'';
	   K.$('icibaSearchToolBar').setAttribute('display',K.$('icibaSearchToolBar').style.display );
	  // alert('456');
	   K.$('searchHW').style.display= K.$('icibaSearchToolBar').style.display;
	break;
	case 'isDw':
	   K.config.isDw=src.value=='1'?false:true;
	   if(K.$('icibaDw'))K.$('icibaDw').className=K.config.isDw?'icibaDw2':'icibaDw';
	    K.$('dw').style.display=( K.config.isDw) ?'':'none';
		
	break;
    case 'oObjWidth': 
	   K.config.oObjWidth=src.value
	   K.$(K.config.icibaDiv).style.width= K.config.oObjWidth+'px';
	break;
	case'oObjHeight':
	  //alert(src.name);
	  K.config.oObjHeight=src.value;
	  K.$('icibaContext').style.height= ( K.config.oObjHeight)+'px';	
	 
	break;
	case 'searchInputWidth':		
		K.$('icibaInputWord').style.width=src.value+'px';
	break;

	case'language':
	   //alert(src.value);
	   
	   jsurl= src.value=='en'?'http://dict-co.iciba.com/ui.php?language=en&skinUi=en':'http://dict-co.iciba.com/ui.php?skinUi=zh';
	   var jsNote=K.$('icibaJsInterface');	
	   _icibaLanguage= src.value;
	if(!K.is_ie)K.$('jsInterface').innerHTML="<script type=\"text\/javascript\" id=\"icibaTest\" \charset=\"UTF-8\"><\/script>";
   
     try{
		   K.CClose();
		   K.$('icibaTest').src=jsurl;
		 }catch(e){}
	break;
	case 'selfDeter':
	   //alert(src.value);
	   K.config.isSelfDeter=src.value=='0'?false:true;
	break;
	case'defalutDwTop':
		K.$(K.config.icibaDiv).style.top=src.value+'px';
	break;
	case'defalutDwLeft':
	    K.$(K.config.icibaDiv).style.left=src.value+'px';
    break;
	case 'isPopIcon':
		//alert(src.value);
        K.$('isPop').style.display=(src.value==1)?'':'none';
		if(src.value==1){
			//K.$('icibaPopIcon').style.display= K.$('isPop').style.display;	
			if(!K.$('icibaPopIcon')){
				//alert(iciba_param['isPopStyle']);
				div=document.createElement("DIV");
				div.id='icibaPopIcon';
				if(typeof(iciba_param['isPopStyle'])=='undefined')iciba_param['isPopStyle']='4';
				src=K.$('span'+parseInt(iciba_param['isPopStyle'].replace("'",'')));
				//alert('span'+parseInt(iciba_param['isPopStyle']));
				//alert(src);
				div.style.backgroundPosition=src.style.backgroundPosition;	
				div.style.width=src.style.width;
				div.style.height=src.style.height;
				document.body.appendChild(div);

			}
		}else{			
			if(K.$('icibaPopIcon')){document.body.removeChild(K.$('icibaPopIcon'));}
		}
		//alert(src.value);
	break;
	case 'isPopStyle':
		//alert(src.style);
       // K.$('isPop').style.display=(src.value==1)?'':'none';
	    if(K.$('icibaPopIcon')){
			src=K.$('span'+src.value);
			K.$('icibaPopIcon').style.backgroundPosition=src.style.backgroundPosition;	
			K.$('icibaPopIcon').style.width=src.style.width;
			K.$('icibaPopIcon').style.height=src.style.height;
		}
		
	break;
	case 'gx':
	  gx();
	break;
	case 'copy':
		if(!K.is_ie){alert('请使用ctrl+c复制代码');K.$('copyText').select();}
        else{
			try{
				window.clipboardData.clearData();				
				copyDate=K.$('copyText').value;
				window.clipboardData.setData("Text",copyDate);
				K.CClose();
				alert('请使用ctrl+v贴到您的网站中！')
			}catch(e){alert('请使用ctrl+c复制代码');K.$('copyText').select();}
		}
	break;
	case 'isInputCan':		
	    K.config.isInputCan=src.value=='1'?true:false;		
	break;
	default:
	  alert(src.name);
	
	}
	gx();
}

function gx(){
   var ipt=K.$('icibaUiForm').getElementsByTagName('input');  
   str='';
   jsUrl='';
   for(i=0;i<ipt.length;i++){
      if(ipt[i].type=='radio' && ipt[i].checked){
	     //alert(ipt[i].name+':'+ipt[i].value);
		 if(ipt[i].name=='cstyle') str +="iciba_param['skin'] = "+ipt[i].value+";// 皮肤\n";
		 if(ipt[i].name=='searchInputDisplay') {
			 str +="iciba_param['searchInputDisplay'] = '"+ipt[i].value+"';// 搜寻框是否显示 默认是'' 当为 'none'的时候不显示\n";
			 if(ipt[i].value!='none'){
				  str +="iciba_param['searchInputWidth'] ="+K.$('searchInputWidth').value+";////输入框长度 当iciba_param['searchInputDisplay'] !='none'的时候起作用  \n";
			 }
		 }
		 if(ipt[i].name=='isDw'){
		    str +="iciba_param['isCanDraw'] = '"+ipt[i].value+"';//是否能拖动？0表示不可以拖动 默认为1可拖动 \n";
	       
			if(ipt[i].value=='0'){			 
			    str +="iciba_param['defalutDwTop'] ='"+K.$('defalutDwTop').value+"';//默认定位的距离顶部的高度 \n";
				str +="iciba_param['defalutDwLeft'] ='"+K.$('defalutDwLeft').value+"';//默认定位的距离左变的长度 \n";
			}
		 }
		 if(ipt[i].name=='selfDeter')str +="iciba_param['selfDeter'] ='"+ipt[i].value+"';//是否自己划词自己？0 表示不可以\n";

		 if(ipt[i].name=='isPopIcon'  ){
			 str +="iciba_param['isPopIcon'] ='"+ipt[i].value+"';//是否需要 小icon 需要为1 不需要为0\n";
			 isPopIcon=ipt[i].value;
		 }
		 if(ipt[i].name=='isInputCan'  ){
			 str +="iciba_param['isInputCan'] ='"+ipt[i].value+"';//是否能在文本域输入框内划词 默认不可以 只有'1'的时候才能起作用\n";
		 }
		 if(ipt[i].name=='isPopStyle'&& isPopIcon==1){
			 str +="iciba_param['isPopStyle'] ='"+ipt[i].value+"';//小icon的 图标\n";
			 iciba_param['isPopStyle']="'"+ipt[i].value+"'";
		 }

	     if(ipt[i].name=='language'){
		   jsUrl = '<script type="text/javascript" src="http://dict-co.iciba.com/ui.php'+(ipt[i].value=='en'?'?language=en':'')+'" charset="UTF-8"></'+'script>';
		 }
	}
	if(ipt[i].name=='oObjWidth')str +="iciba_param['width'] = '"+ipt[i].value+"'; // 宽度\n";
	if(ipt[i].name=='oObjHeight')str +="iciba_param['height'] = '"+ipt[i].value+"';  // 内容高度\n";
	  
   }
   strCont=str;
   str=getContext();
   if(str){strCont+="iciba_param['context']=["+str+"];//词典功能\n"}
   if(strCont!=''){
      strCont="<script type=\"text/javascript\">\n var iciba_param =new Array();\n"+ strCont+"</"+"script>";
   }
   K.$('copyText').value=strCont+"\n"+jsUrl;
}
window.onload=load;
