function selectitem(pid,pidv,pname,pnamev)
{
	if (window.opener){
	//alert(pid+pidv+pname+pnamev);
	window.opener.document.getElementById(pid).value = pidv;
	window.opener.document.getElementById(pname).innerHTML = pnamev;
	window.close();
	}else{
		//document.write("发生错误；主窗口已关闭无法完成刷新");
	}
	
}

function selectline(pid,pidv,pname,sfx)
{
	//alert(pid+pname+sfx);
	//var pidv = document.getElementsByName("check_id[]")[sfx].value;
	var pnamev = document.getElementsByName("line_dsc[]")[sfx].value;
	if (window.opener){
	window.opener.document.getElementById(pid).value = pidv;
	window.opener.document.getElementById(pname).value = pnamev;
	window.close();
	}else{
		//document.write("发生错误；主窗口已关闭无法完成刷新");
	}
	
}

function confirm_msg(msg){
	if (confirm(msg)){
		return true;
	}
	return false;
}

function checkall(form) 
{
	for (var i=0;i<form.elements.length;i++) {
			var e = form.elements[i];
			if (e.name != 'check_all')
			e.checked = form.check_all.checked;
		}
}
function confirm_do(msg,check_msg,check_type){
	var check_length = document.list_form['check_id[]'].length;;
	var checked_num = 0;

	for(i=0;i<document.getElementsByName("check_id[]").length;i++)
	{
		if(document.getElementsByName("check_id[]")[i].checked == true)
		{
			
			checked_num ++;
		}
		
	}
	
	if(checked_num > 0)
	{
		if(document.list_form.check_type.value == '')
		{
			alert(check_type);
			document.list_form.check_type.focus();
			return false;
		}

	
		if (confirm(msg)){
			document.list_form.submit();
			return true;
		}	
	}
	else
	{
		alert(check_msg);
		return false;
	}

}


function check_cart(alert_msg){
	var check_length = document.cart_form['item_cnt[]'].length;;
	var checked_num = 0;

	for(i=0;i<document.getElementsByName("item_cnt[]").length;i++)
	{
		if(document.getElementsByName("item_cnt[]")[i].value > 0)
		{
		}else
		{
			checked_num ++;
		}
		
	}
	
	if(checked_num > 0)
	{
		alert(alert_msg);
		return false;
	}
	return true;
}

//添加option,与xajax同时用
function addOption(selectId,optionId,txt,val)
{
	var objOption = new Option(txt,val);
	objOption.id = optionId;
	document.getElementById(selectId).options.add(objOption);
}

function removeOption(selectId)
{
	var x=document.getElementById(selectId);
		l=x.options.length;
		for(var i=0;i<l;i++)
		{
			x.remove(x.i);
		}
}


//控制图片转换
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}



//打印指定区，记住要加标签
function doPrint() 
{ 
	bdhtml=window.document.body.innerHTML; 
	sprnstr="<!--startprint-->"; 
	eprnstr="<!--endprint-->"; 
	prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17); 
	prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr)); 
	window.document.body.innerHTML=prnhtml; 
	window.print(); 
}

//指定id改变内容
function get_detail(content,ids)
{
	var obj = document.getElementById(ids).innerHTML = "<img src='"+content+"' border='0' alt='' />";
	return obj;
}

function get_id(part)
{
	var val = document.detail.theid.value;
	var links = 'casemeta.php?id='+val+'&part='+part;
	window.open(links);
	//window.location.href = links;
	//alert(links);
}

//disable指定id
function change_disable(type,fid,tid)
{
	if(type == fid)
	{	
		document.getElementById(tid).disabled = false;
	}else
	{
		document.getElementById(tid).disabled = true;
	}
	
}

//控制多语言菜单
function show_div(theObj)//查找并显示对应详细信息的过程。
{
	//alert(theObj);
	var num=3;
	//alert(document.getElementById("lang_menu_div"+theObj));
	
	if((document.getElementById("lang_menu_div"+theObj)!=null) && (document.getElementById("lang_type_menu"+theObj)!=null) )
	{
		for(var j=1;j<=num;j++)
		{
			if(theObj!=j)
			{
				document.getElementById("lang_menu_div"+j).style.display="none";
				document.getElementById("lang_type_menu"+j).style.color='';
				document.getElementById("lang_type_menu"+j).style.background='transparent';
			}
		}
		document.getElementById("lang_menu_div"+theObj).style.display='inline';
		document.getElementById("lang_type_menu"+theObj).style.color='#FF0000';
		document.getElementById("lang_type_menu"+theObj).style.background='#E1F8C2';
	}
	
}

//tinymce 压缩加速
function call_gzip(lang)
{
	tinyMCE_GZ.init({
		plugins : 'paste,layer,table,advimage,advlink,media,contextmenu,fullscreen',
		languages : lang
	});
}

//tinymce 编辑器
function call_editor(elang,eareaname,ewidth,eheight,etheme)
{
	//初始化
	if(eareaname == '')									//加载的textarea
	{
		eareaname = 'dsc,dsc1,dsc2';
	}
	if(ewidth == '')									//宽
	{
		ewidth = '90%';
	}
	if(eheight == '')									//高
	{
		eheight = '400';
	}
	if(etheme == '')									//级别
	{
		etheme = 'advanced';
		//etheme = 'simple';
	}	
	
	tinyMCE.init({
		mode : "exact",//mode : "textareas",
		elements : eareaname,//save_callback : "customSave",
		//language :elang,
		language :elang,
		theme : etheme,//theme : "simple",
		width : ewidth,
		height : eheight,
		//theme_advanced_layout_manager : "SimpleLayout",
		plugins : "paste,layer,table,advimage,advlink,media,contextmenu,fullscreen",
		theme_advanced_buttons1 : "bold,italic,underline,strikethrough,separator,justifyleft,justifycenter,justifyright, justifyfull,separator,bullist,numlist,separator,outdent,indent,separator,forecolor,backcolor,fontsizeselect,separator,sub,sup,separator,charmap",
		theme_advanced_buttons2 : "insertlayer,moveforward,movebackward,absolute,separator,tablecontrols,separator,undo,redo,cleanup,code,fullscreen",
		theme_advanced_buttons3 : "cut,copy,paste,pastetext,pasteword,separator,hr,removeformat,visualaid,separator,link,unlink,anchor,separator,image,ibrowser,media",
		//plugins : "layer,table,save,advhr,advimage,advlink,insertdatetime,preview,media,searchreplace,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,ibrowser",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_path_location : "bottom",
		file_browser_callback : "fileBrowserCallBack",
		//content_css : "example_full.css",
	    //plugin_insertdate_dateFormat : "%Y-%m-%d",
	   // plugin_insertdate_timeFormat : "%H:%M:%S",
		//extended_valid_elements : "hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
		//external_link_list_url : "example_link_list.js",
		//external_image_list_url : "example_image_list.js",
		//flash_external_list_url : "example_flash_list.js",
		//media_external_list_url : "example_media_list.js",
		//template_external_list_url : "example_template_list.js",
		theme_advanced_resize_horizontal : false,
		//theme_advanced_resizing : true,
		nonbreaking_force_tab : true,
		apply_source_formatting : true
	});



}	

function fileBrowserCallBack(field_name, url, type, win) {
	var connector = "../../filemanager/browser.html?Connector=connectors/php/connector.php";
	var enableAutoTypeSelection = true;

	var cType;
	tinyfck_field = field_name;
	tinyfck = win;

	switch (type) {
		case "image":
			cType = "Image";
			break;
		case "flash":
			cType = "Flash";
			break;
		case "file":
			cType = "File";
			break;
	}

	if (enableAutoTypeSelection && cType) {
		connector += "&Type=" + cType;
	}

	window.open(connector, "tinyfck", "modal,width=600,height=400");
}