/**
* @file zh-cn.js
* @copyright (c) 2005 - 2007 eifr.com
* @license http://www.gnu.org/copyleft/gpl.html gnu/gpl
* eifr is free software
*/

Array.prototype.removeByValue = function(val) {
    for(var i=0; i<this.length; i++) {
        if(this[i] == val) {
            this.splice(i, 1);
            break;
        }
    }
};

Array.prototype.clear = function() {
    for(var i=0; i<this.length; i++) {
        delete this[i];
    }
    this.length = 0;
};

function doSize(tmpValue,tmpType,tmpSize)
{
	var objSize = document.getElementById(tmpValue).size;
	if(tmpType==1)
	{
		objSize += tmpSize;
	}
	if(tmpType==0)
	{
		objSize -= tmpSize;
	}
	if(objSize<tmpSize)
	{
		objSize = tmpSize;
	}
	document.getElementById(tmpValue).size=objSize;

}

function showElementSelect(idName,selectValue)
{
	var selectObj =  document.getElementById(idName);
	for (var i=0;i<selectObj.options.length;i++)
	{
		if (selectObj.options[i].value == selectValue)
		{
			selectObj.options[i].selected = true;
			break;
		}
	}
	
}

function QueryString(key)
{
	var value = null;
	for (var i=0;i<QueryString.keys.length;i++)
	{
		if (QueryString.keys[i]==key)
		{
			value = QueryString.values[i];
			break;
		}
	}
	return value;
}

function QueryString_Parse()
{
	QueryString.keys = new Array();
	QueryString.values = new Array();
	var query = location.search.substring(1);
	var pairs = query.split('&');
	for (var i=0;i<pairs.length;i++)
	{
		var pos = pairs[i].indexOf('=');
		if (pos >= 0)
		{
			var argname = pairs[i].substring(0,pos);
			var value = pairs[i].substring(pos+1);
			QueryString.keys[QueryString.keys.length] = argname;
			QueryString.values[QueryString.values.length] = value;		
		}
	}
				
}


function delRecords()
{
	var strlist = "";
	for(i=0; i<document.all["record_list"].length; i++)
  {
		if(document.all["record_list"][i].checked == true)
		{	    			
			strlist += "','"+document.all["record_list"][i].value;															
		}
	}
	if(strlist=="")
	{
		alert("请选择");
		return;
	}
	
	if(confirm('你确认要"彻底删除"吗？'))
	{    			
		record_list.selList.value = strlist;  			    			    			
    record_list.flag.value = "";
    record_list.act.value = "del";
		record_list.submit();
	}	
}

function MM_jumpMenu(targ,selObj,restore)
{ 
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function openSelectWin(tourl, winName)
{ 
	window.open(tourl, winName, 'top=100,left=200,width=600,height=480,scrollbars=1,resizable=1,status=1');
}

function openChannelSelect(form_input, selecttype)
{
	//the third argv is 'all' indicates can select all channels
	var selecturl = arguments[2] ? arguments[2] : '';
    iframeUrl = '../mod_channel/channel_select.php?act='+selecttype+'&form_input='+form_input+'&selecturl='+selecturl;
    $('#modalWindow').jqmShow();
}

function openTemplateSelect(tpfile)
{
	openSelectWin('../mod_template/template_select.php?pfile='+tpfile);
}

function setFlag(sValue,strMsg)
{
	var strlist = "";
	for(i=0; i<document.all["record_list"].length; i++)
	{
		if(document.all["record_list"][i].checked == true)
		{	    			
			strlist += "','"+document.all["record_list"][i].value;															
		}
	}
	if(strlist=="")
	{
		alert("请选择");
		return;
	}
	
	if(confirm("你确认要\""+strMsg+"\"吗？"))
	{    			
		//record_list.action="pdlist.php?act=setflag&flag="+sValue+"";  
		record_list.selList.value = strlist;  			    			    			
		record_list.flag.value = sValue;
		record_list.act.value = "setflag";
		record_list.submit();
	}	
}

function getTagNumByName(tag,name)
{
    var count = 0;
    var tagObj =  document.getElementsByTagName(tag);
	if(tagObj.length>0) {			
		for(i=0; i<tagObj.length; i++)
		{
			if(tagObj[i].name.toLowerCase()==name) {
				count++;
			}
		}
	}
    return count;
}

function selectAll(click_chk,select_chk)
{
	var cO = document.getElementById(click_chk);
	var inputO =  document.getElementsByTagName("input");
	
	if(inputO.length>0)
	{			
		for(i=0; i<inputO.length; i++)
		{
			if(inputO[i].name.toLowerCase()==select_chk)
			{
				if(cO.checked)
				{
					inputO[i].checked = true;
				}
				else
				{
					inputO[i].checked = false;
				}
			  }
		}
	}
}



function imgExceedSize(w,h){
if(!document.IUpload.picsrc.value==""){
if(picshow.width>w||picshow.height>h){
alert("图像尺寸："+picshow.width+"X"+picshow.height+"。\\n图像尺寸过大！你只能上传尺寸为 "+w+"×"+h+"的图像，请重新浏览图片！");
return true;
}else{
return false;
}
}else{
return true;
}
}

function detect()
{
	var ok=imgExceedSize(50,50);
	if(ok)
	{
		document.IUpload.reset();
	}
	else
	{
		document.IUpload.submit();
	}
}

function showHidden(strid)
{
	if(document.getElementById(strid))
		document.getElementById(strid).style.display="";
}

function hiddenDisplay(strid)
{
	if(document.getElementById(strid))
		document.getElementById(strid).style.display="none";
}

function showDisplayHidden(chk,area)
{
	var chkO = document.getElementById(chk);
	if(chkO.checked)
	{
		document.getElementById(area).style.display="";
		chkO.checked = true;
	}
	else
	{
		document.getElementById(area).style.display="none";
		chkO.checked = false;
	}
}

function showHiddenDisplay(chk,area)
{
	var chkO = document.getElementById(chk);
	if(chkO.checked)
	{
        document.getElementById(area).style.display="none";
		chkO.checked = true;
	}
	else
	{
		document.getElementById(area).style.display="";
		chkO.checked = false;
	}
}

function showRemark_radio(prefix,suffix)
{
	var tagO = document.getElementsByTagName('div');
	if(suffix!='')
	{
		for (var ti=0;ti<tagO.length;ti++)
        {    
            if(tagO[ti].id.substr(0,prefix.length)==prefix)
            {
                if(tagO[ti].id==prefix+'_'+suffix)
                {	
                    tagO[ti].style.display="";
                }
                else
                {
                    tagO[ti].style.display="none";
                } 
            }
        }
	}
	
}

function showSubClassTr(sid,img_path)
{
	var tagO = document.getElementsByTagName('tr');

	if (document.getElementById("img" + sid ).src.indexOf("plus.gif")!=-1)
	{
		document.getElementById("img" + sid ).src = img_path+"minus.gif";
		
		for (var ti=0;ti<tagO.length;ti++)
	  {    
	    if(tagO[ti].id)
	    {	
	    	if(tagO[ti].id.length>sid.length && tagO[ti].id.substr(0,sid.length)==sid)
		    {	
		    	tagO[ti].style.display="";
		    	if(document.getElementById("img" + tagO[ti].id )) 
		    		document.getElementById("img" + tagO[ti].id ).src = img_path+"minus.gif";
		    }
				
	    } 
	  }
	  
	}
	else
	{
		document.getElementById("img" + sid ).src = img_path+"plus.gif";
		
		for (var ti=0;ti<tagO.length;ti++)
	  {
	    if(tagO[ti].id)
	    {
	    	if(tagO[ti].id.length>sid.length && tagO[ti].id.substr(0,sid.length)==sid)
		    {
		    	tagO[ti].style.display="none";
		    	if(document.getElementById("img" + tagO[ti].id )) 
		    		document.getElementById("img" + tagO[ti].id ).src = img_path+"plus.gif";
		    }
				
	    } 
	  }
	  
	}
}

function submitButton(tourl,strmsg,is_confirm)
{
	if(is_confirm)
	{		
		if(confirm("你确认要\""+strmsg+"\"吗？"))
		{    			
			location.href=tourl;
		}
	}
	else
	{
		location.href=tourl;
	}
}

function submitOpenerValue(form_input,tmpValue,tmpTxt)
{	
	if(confirm("你确认选择\""+tmpTxt+"\"吗？"))
	{    			
		if(window.opener.document.getElementById(form_input))
		{
			window.opener.document.getElementById(form_input).value=tmpValue;
			if(window.opener.document.getElementById(form_input+'_show')) 
			{
				window.opener.document.getElementById(form_input+'_show').value = tmpTxt;
			}
			window.close();
		}
	}	
}


function clearInputList(name)
{
	var inputO =  document.getElementsByTagName("input");
	if(inputO.length>0)
	{			
		for(i=0; i<inputO.length; i++)
		{
			if(inputO[i].name.toLowerCase()==name)
			{
                inputO[i].checked = false;
			}
		}
	}
}

function getInputList(name)
{
	var strlist = "";	
	var inputO =  document.getElementsByTagName("input");
	if(inputO.length>0)
	{			
		for(i=0; i<inputO.length; i++)
		{
			if(inputO[i].name.toLowerCase()==name)
			{
				if(inputO[i].getAttribute("type") == "checkbox")
				{
					if(inputO[i].checked == true)
					{	    			
						strlist += ","+inputO[i].value;															
					}
				}
				else if(inputO[i].getAttribute("type") == "radio")
				{
					if(inputO[i].checked == true)
					{	    			
							strlist += ","+inputO[i].value;		
							break;													
					}
					
				}
				else if(inputO[i].getAttribute("type") == "hidden")
				{
					strlist += ","+inputO[i].value;
					break;
				}
			}
		}
		  
		if(strlist!='')
		{
			strlist = strlist.substr(1,strlist.length); 	
		}
	}
	
	return strlist;
}

function submitsSelect(actTyle,tourl,doevent)
{
	var strlist = "";	
	var strmsg = "";
	var isconfirm = false;
	eval(doevent);
	strlist = getInputList("selectid")

	switch(actTyle)
	{
		case "add":
			strmsg = "增加";
			break;
		case "copy":
			strmsg = "复制";
			isconfirm = true;
			break;
		case "edit":
			strmsg = "编辑";
			break;
		case "delete":
			strmsg = "删除";
			isconfirm = true;
			break;
		case "delete_forever":
			strmsg = "永久删除";
			isconfirm = true;
			break;
		case "save":
			strmsg = "保存";
			break;
			
	}

	if(actTyle=="save")
	{
		if(typeof(KindEditor)!='undefined') {
			if(typeof(KindEditor.eifrEditorData)!='undefined') {
                for(var i =0; i<KindEditor.eifrEditorData.length; i++){ 
                    var row  = KindEditor.eifrEditorData[i];
                    document.getElementById(row.fieldName).value = row.editorObj.html();
                }
			}
		}

	}

	if(actTyle=="edit" || actTyle=="copy" ||  actTyle=="preview")
	{
		var strlist_arr = strlist.split(",");
		
		if(strlist=="" || strlist_arr.length>1)
		{
			alert("请选择一个");
			return;
		}
	}
	
	if((actTyle=="delete" || actTyle=="delete_forever") && strlist=="")
	{
		alert("请选择");
		return;
	}
	document.getElementById("selectValue").value = strlist;	
	
	if(isconfirm)
	{		
		if(confirm("你确认要\""+strmsg+"\"吗？"))
		{    			 
			submitAction(actTyle,tourl);
		}
	}
	else
	{  			    			    			
		submitAction(actTyle,tourl);
	}
	
}

function submitAction(actTyle,tourl)
{
	if(actTyle=='save' || actTyle=='copy')
	{
		if(Validator.Validate(document.editForm,3))
		{			    			    			
			document.editForm.action = tourl;
			document.editForm.submit();
		}
	}
	else
	{
		document.editForm.action = tourl;
		document.editForm.submit();
	}
}

function checkSearch()
{
	if( document.getElementById("search_keyword").value.length<1)
	{
		alert("\请输入搜索关键字")
		return false;
	}
	return true;
	
}


function winOpen(Url,width,height)
{
	var left = ( screen.width - width ) / 2;
  var top = 0;
  if(!width) width=600;
  if(!height) height=480;
	window.open(Url,'','width='+width+',height='+height+',top='+top+',left='+left+',scrollbars=1,resizable=1,status=1');
	return false;
}


// function to return a reference from the popup window back into the widget
function referencebrowser_setReference(widget_id, tmpValue, label, multi)
{
	// differentiate between the single and mulitselect widget
	// since the single widget has an extra label field.
	if (multi==0)
	{
	  var element=document.getElementById(widget_id)
	  label_element=document.getElementById(widget_id + '_label')
	  element.value=tmpValue
	  label_element.value=label
	}
	else
	{
		var list=document.getElementById(widget_id);
		// check if the item isn't already in the list
		for (var x=0; x < list.length; x++) {
		  if (list[x].value == tmpValue) {
		    return false;
		  }
		}         
		// now add the new item
		theLength=list.length;
		list[theLength] = new Option(label);
		list[theLength].selected='selected';
		list[theLength].value=tmpValue
	 }
}

// function to clear the reference field or remove items
// from the multivalued reference list.
function referencebrowser_removeReference(widget_id, multi)
{
	if (multi)
	{
    var list=document.getElementById(widget_id)
    for (var x=list.length-1; x >= 0; x--)
    {
      if (list[x].selected)
      {
        list[x]=null;
      }
    }
    for (var x=0; x < list.length; x++)
    {
        list[x].selected='selected';
    }        
	}
	else
	{
    element=document.getElementById(widget_id);
    label_element=document.getElementById(widget_id + '_label');
    label_element.value = "";
    element.value="";
	}
}

// function to select all the reference field items
// from the multivalued reference list.
function referencebrowser_selectAllReference(widget_id, multi)
{
	if (multi)
	{
    var list=document.getElementById(widget_id)
    for (var x=0; x < list.length; x++)
    {
        list[x].selected='selected';
    }        
	}
	
}

// function to open the popup window
function referencebrowser_openBrowser(widget_id,url)
{
	var list=document.getElementById(widget_id)
  for (var x=list.length-1; x >= 0; x--)
  {
    if (list[x].selected)
    {
      winOpen(url+list[x].value);
      break;
    }
  }

}


function thisKeyPress(evt,actEvt) 
{  
	var keyCode = evt.keyCode ? evt.keyCode :
                evt.charCode ? evt.charCode :
								evt.which ? evt.which : void 0;
	if (keyCode == 13) 
	{
		eval(actEvt);
	}	
} 

function getTitle()
{
	if(document.getElementsByTagName("title"))
	{
		var ot = window.top.main.document.getElementsByTagName("title");
		if(ot[0])
		{
			document.getElementById("curpage").innerHTML=ot[0].innerText;
		}
	}
	setTimeout("getTitle();",10);
	
}


function printWinMsg(msgtype,msg,nav,goback,add,edit,manage,extra_link)
{
	var lang_add = '增加';
	var lang_edit = '编辑';
	var lang_manage = '管理';
	var lang_back = '返回';
	var wintitle = '提示信息!';
	var msgimg = 'dialog-info.gif';
	switch(msgtype)
	{
		case "ok":
			msgimg = "dialog-ok.gif";
			break;
		case "warning":
			msgimg = "dialog-warning.gif";
			break;
		case "error":
			msgimg = "dialog-error.gif";
			break;
		default :
			msgimg = "dialog-info.gif";
			break;
			
	}
	if(goback!='') goback = "<img src='"+window.top.img_path+"back.gif' align='absmiddle'>&nbsp;<a href='javascript:history.go(-1);'>"+lang_back+"</a>&nbsp;";
	if(add!='') add = "<img src='"+window.top.img_path+"doc-new.gif' align='absmiddle'>&nbsp;<a href='"+add+"'>"+lang_add+"</a>&nbsp;";
	if(edit!='') edit = "<img src='"+window.top.img_path+"doc-edit.gif' align='absmiddle'>&nbsp;<a href='"+edit+"'>"+lang_edit+"</a>&nbsp;";
	if(manage!='') manage = "<img src='"+window.top.img_path+"doc-manage.gif' align='absmiddle'>&nbsp;<a href='"+manage+"'>"+lang_manage+"</a>&nbsp;";
	
	document.write("<body leftmargin='0' topmargin='0'>");
	document.write("<center>");
	document.write("<div class='nav_div'>"+nav+"</div>");
	document.write("<br/><div class='msg_t_div'>&nbsp;"+wintitle+"</div>");
	document.write("<div class='msg_c_div'><br/>");
	document.write("<img src='"+window.top.img_path+msgimg+"' align='absmiddle'>&nbsp;");
	document.write(""+msg+"<br/><br/>");
	document.write(""+goback+add+edit+manage+extra_link+"");
	document.write("<br/><br/></div>");
	document.write("</center>");
	document.write("</body>");


}

function loadFramePage()
{
	if(!window.top.loadHead) window.top.headfrm.location.reload();
	if(!window.top.loadMenu) window.top.menufrm.location.reload();

}

function cleanStatusMsg()
{
	if(window.top.statusfrm && window.top.statusfrm.document.getElementById('showmsg'))
	{
		window.top.statusfrm.document.getElementById('showmsg').innerHTML = window.top.curShowMsg;
		setTimeout(function(e){	
		window.top.statusfrm.document.getElementById('showmsg').innerHTML ="";window.top.curShowMsg="";
		},3000)
	}
}



//window.onerror = true;
