﻿var IE = (navigator.userAgent.indexOf("IE ") > -1);//判断是否为IE

function DSelect(t1,s){//选中默认下拉列表
	for(i=0; i<t1.length; i++) {
		if(t1.options[i].value==s){t1.options[i].selected=true;return;}
	}
}
function DRadio(t1,s){//选中默认单选框
	if(typeof(t1.length)=="undefined"){//只有一个选项
		if(t1.value==s){t1.checked=true;return;}
		return false;
	}
	for(i=0; i<t1.length; i++) {
		if(t1[i].value==s){t1[i].checked=true;return;}
	}
}

function DChkSelectLike(t1,s){//选中多个多选框
	if(t1.length>0){
		//有多个选项
		for(i=0; i<t1.length; i++) {
			if(s.indexOf(','+t1[i].value+',')>-1){
				t1[i].checked=true;
			}
		}
	}else{
		//只有一个选项
		if(s.indexOf(','+t1.value+',')>-1){
			t1.checked=true;
		}
	}
}

function CheckAll(form){//全选
  for (var i=0;i<form.elements.length;i++){
    var e = form.elements[i];
    if (e.name != 'chkall' )
       e.checked = form.chkall.checked;}
}

function ReverseCheckAll(form){//反选
  for (var i=0;i<form.elements.length;i++){
    var e = form.elements[i];
    if (e.name != 'chkall' )
       e.checked = !e.checked;}
}

function confirmF(act, str, frm, FrmAct){//
//act 操作参数, str 提示字符, url　当前网址，必需含act=list; frmAct 指单act值对象
	if(window.confirm(str)){
		if( typeof(FrmAct)=="object" ){
			FrmAct.value = act;
		}else{
			frm.act.value = act;
		}
		frm.submit();
	}
}

function selectFileStF(id){
	document.writeln("<label for=\"" + id + "radio1\"><input name=\"" + id + "radio\" id=\"" + id + "radio1\" type=\"radio\" onClick=\"selectFileF('" + id + "')\" value=\"1\">上传</label> <label for=\"" + id + "radio2\"><input name=\"" + id + "radio\" id=\"" + id + "radio2\" type=\"radio\" onClick=\"selectFileF('" + id + "')\" value=\"0\" checked>URL</label><BR>");
}
function selectFileF(id){//选择隐藏输入框
	if( !document.getElementsByName(id+'radio')[0].checked ){
		document.getElementById(id+"R1").style.display="none";
		document.getElementById(id+"R2").style.display="block";
	}else{
		document.getElementById(id+"R1").style.display="block";
		document.getElementById(id+"R2").style.display="none";
	}
	//判断是否显示预览图
	show_imgF(document.getElementById(id+"_url").value, id)
}
	
function show_imgF(url, id){//预览图片
	var url2;
	var strHtml, regExp1;
	if(url==""){return false;}
	
	//取得文件扩展名并转为小写
	var pos = url.lastIndexOf(".");
	var lastname = url.substring(pos,url.length).toLowerCase();
	var imgList = ".jpg|.jpeg|bmp|.gif|.png";
	var swfList = ".swf";
	//alert(lastname)
 	
	if( (url.substring(0,4)).toLowerCase() == "http" ){
		//网络上图片, 不处理URL
	}else if(url.indexOf(":\\")>-1){
		//本机图片, 链接特殊处理, IE7需要把站点添加到可信区域才行；Firefox不支持；
		//改进为Frame方式:不可行
		//新窗口也不行
		//IE7 要添加到可信站点
	}else if(url.substring(0,1)!="/"){
		//相对径径,用户上传的文件返回上级目录
		url = "../" + url;
	}
	if( imgList.indexOf(lastname) >-1 ){//图
		strHtml = "<a href='"+ url +"' target='_blank'><img src='"+ url +"' border='0' onload='if(this.width>250)this.width=250' onmousemove='if(this.width>250)this.width=250'></a>";
	}else if( swfList.indexOf(lastname) > -1 ){//flash文件
		strHtml = MediaCodeF(url, 250, 200)
		strHtml += "<BR><a href='"+ url +"' target='_blank'>"+ url +"</a>";
	}else{//其它文件
		strHtml = "<a href='"+ url +"' target='_blank'>"+ url +"</a>";
	}
	document.getElementById(id+"Show").innerHTML = strHtml;
}

function openimgF(shtml){//新窗口中写入HTML
	var win = window.open("","","");
	win.document.open();
	win.document.writeln("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /><title></title></head><body>");
	win.document.writeln(shtml);
	win.document.writeln("</body></html>");	
	win.document.close();
}


function showcates(a2)
{
	if(document.getElementById(a2).style.display =="none" ){
		document.getElementById(a2).style.display = "block";
	}else{
		document.getElementById(a2).style.display = "none";
	}
}

