//检测相关

function checkPost(cmid){
	var form1=document.add_frm;
	if (cmid == 1){ 
	    if (form1.Topic.value==""){
		    alert("标题不能为空，请先填写！");
		    form1.Topic.focus();
		    return false;
	    }
	}
	else{
	    if (form1.name.value==""){
		    alert("标题或名称不能为空，请先填写！");
		    form1.name.focus();
		    return false;
	    }		
	}
	if (form1.ClassID.value==""){
		alert("请选择分类！\n\n若该分类含有下属分类，请选择其下属分类。");
		form1.ClassID.focus();
		return false;
	}
	if (form1.ClassID.value=="0"){
		alert("该分类是外部连接，不能添加内容！");
		form1.ClassID.focus();
		return false;
	}
	if (cmid==3){
	   if (form1.Brief.value==""){
		   alert("商品摘要不能为空，请先填写！");
		   form1.Brief.focus();
		   return false;
	   }
	   //isNaN(form1.Price.value) 表单已限制只可输入数字  
	   if (form1.Price.value==""||form1.Price_Original.value==""||form1.Price_Market.value==""){
		   alert("商品原价,当前价格，参考价格不能为空，且必须是数字！");
		   form1.Price.focus();
		   return false;
	   }
	   //还有错误，呆会儿修改
	   if (form1.is_emoney.checked==true){
	       if (form1.emoney.value==""||isNaN(form1.emoney.value)){
	          alert("你已选择可用虚拟货币购买，故虚拟货币不能为空，且必须是大于0的数字！");
	          form1.emoney.focus();
	   	    return false;
	       }
	   }	   
	}	
	if (Editor1.getHTML()==""){
		alert("正文内容不能为空，请先填写！");
		return false;
	}
	if (cmid==5){
	   if (form1.pic.value==""){
		   alert("缩略图地址不能为空，请先填写！");
		   form1.pic.focus();
		   return false;
	   }		
	}	
	if (cmid==2||cmid==5||cmid==6){
	   //加载地址
	   PostUrl('add_frm','Url','Urls')
	   if (form1.Urls.value==""){
		   alert("相关地址不能为空，请先填写！");
		   form1.Url.focus();
		   return false;
	   }		
	}
}

//检测是否有指定的对象
function chkdiv(divid){
var chkid=document.getElementById(divid);
if(chkid != null){return true; }
else {return false; }
}



function doPreview(objname,Wpath,Upath){
	var obj=document.getElementById(objname);
	if(obj.length==0) return false;
	var url=obj.value; 

	if (url){
		url = url.replace("{$web_dir}",Wpath);
		url = url.replace("{$download_dir}",Upath);
		var sExt=url.substr(url.lastIndexOf(".")+1);
		sExt=sExt.toUpperCase();
		var sHTML;
		switch(sExt){
		case "GIF":
		case "JPG":
		case "BMP":
		case "PNG":
			tdPreview.innerHTML = "<img border=0 src='" + url + "' width='170' height='140'>";
			document.add_frm.showuploadlist.checked = true;
			uploadlist.style.display = "";
			break;
		//case "SWF":
		//	sHTML = "<img border=0 src='" + url + "' width='170' height='140'>";
		//	break;
		default:
			tdPreview.innerHTML = "";
			break;
		}
		//tdPreview.innerHTML = sHTML;
	}else{
		tdPreview.innerHTML = "";
	}
}

//地址栏的图片预览
function doPreviews(objname,Wpath,Upath){
	var obj=document.getElementById(objname);
	if(obj.length==0) return false;
	var urls=obj.value; 

	if (urls){
		urls = urls.split("|");
		url = urls[1]
		url = url.replace("{$web_dir}",Wpath);
		url = url.replace("{$download_dir}",Upath);
		var sExt=url.substr(url.lastIndexOf(".")+1);
		sExt=sExt.toUpperCase();
		var sHTML;
		switch(sExt){
		case "GIF":
		case "JPG":
		case "BMP":
		case "PNG":
			tdPreview.innerHTML = "<img border=0 src='" + url + "' width='170' height='140'>";
			document.add_frm.showuploadlist.checked = true;
			uploadlist.style.display = "";
			break;
		//case "SWF":
		//	sHTML = "<img border=0 src='" + url + "' width='170' height='140'>";
		//	break;
		default:
			tdPreview.innerHTML = "";
			break;
		}
		//tdPreview.innerHTML = sHTML;
	}else{
		tdPreview.innerHTML = "";
	}
}
function InsertEditor(objname,Wpath,Upath)
{
	var obj=document.getElementById(objname);
	if(obj.length==0) return false;
	var url=obj.value;
		url = url.replace("{$web_dir}",Wpath);
		url = url.replace("{$download_dir}",Upath);
	var sFilePic = getFilePic(url);
	var sPicSrc = Wpath + "Images/FileType/"+sFilePic;
  	var sPicStr = ""
		switch(sFilePic){
		case "gif.gif":
		case "jpg.gif":
		case "bmp.gif":
		case "png.gif":
			sPicStr = "<img src='"+url+"' border='0'><br />" 
			break;
		//case "swf.gif":
		//	sPicStr = "<img src='"+url+"' border='0'><br />" 
		//	break;
		default:
			sPicStr = ""
			break;
		}
	var sFileName = url.substr(url.lastIndexOf("/")+1);
	Editor1.eWebEditor.focus()
	Editor1.insertHTML("<img border=0 src='"+sPicSrc+"'> <a href='"+url+"' target=_blank><b>"+sFileName+"</b></a><br />"+sPicStr);
}

function SetPicUrl(objname,Insobjname)
{
	var obj=document.getElementById(objname);
	if(obj.length==0) return false;
	document.getElementById(Insobjname).value=obj.value;
}


function getFilePic(url){
	var sExt;
	sExt=url.substr(url.lastIndexOf(".")+1);
	sExt=sExt.toUpperCase();
	var sPicName;
	switch(sExt){
	case "TXT":
		sPicName = "txt.gif";
		break;
	case "DOC":
		sPicName = "doc.gif";
		break;
	case "PDF":
		sPicName = "pdf.gif";
		break;
	case "MDB":
		sPicName = "mdb.gif";
		break;
	case "GIF":
		sPicName = "gif.gif";
		break;
	case "JPG":
		sPicName = "jpg.gif";
		break;
	case "BMP":
		sPicName = "bmp.gif";
		break;
	case "PNG":
		sPicName = "pic.gif";
		break;
	case "ASP":
	case "JSP":
	case "JS":
	case "PHP":
	case "PHP3":
	case "ASPX":
		sPicName = "code.gif";
		break;
	case "HTM":
	case "HTML":
	case "SHTML":
		sPicName = "htm.gif";
		break;
	case "ZIP":
		sPicName = "zip.gif";
		break;
	case "RAR":
		sPicName = "rar.gif";
		break;
	case "EXE":
		sPicName = "exe.gif";
		break;
	case "AVI":
		sPicName = "avi.gif";
		break;
	case "MPG":
	case "MPEG":
	case "ASF":
		sPicName = "mp.gif";
		break;
	case "RA":
	case "RM":
		sPicName = "rm.gif";
		break;
	case "MP3":
		sPicName = "mp3.gif";
		break;
	case "MID":
	case "MIDI":
		sPicName = "mid.gif";
		break;
	case "WAV":
		sPicName = "audio.gif";
		break;
	case "XLS":
		sPicName = "xls.gif";
		break;
	case "PPT":
	case "PPS":
		sPicName = "ppt.gif";
		break;
	case "SWF":
		sPicName = "swf.gif";
		break;
	default:
		sPicName = "unknow.gif";
		break;
	}
	return sPicName;
}

function AMH_resize(tnum,tname)
{
  var obj=document.getElementById(tname);
  if (parseInt(obj.rows)+tnum>=3) { obj.rows = parseInt(obj.rows) + tnum; }
  if (tnum>0) { obj.width="90%"; }
}

function find_copy(n, d)
{
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[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers.document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function AsaiMHcopy(ob,nb)
{
  var obj=find_copy(ob);
  if (obj)
  {
    obj.select();
    js=obj.createTextRange();
    if (nb==1) js.execCommand("Copy");
  }
}
window.onerror=function(a,b,c){return true;}

function runscript(n){
	txtRun=n;
	open_win("AMH_templatesview.asp","AMH_templatesview",800,500,"yes");
}




function doChange(objText, objDrop){
	if (!objDrop) return;
	var str = objText.value;
	var arr = str.split("|");
	var d = objDrop.length;
	var j = arr.length;
	j-=1;
	objDrop.options[d] = new Option(arr[j], arr[j]);
}

function PostUrl(strfrm,objname,objname2)
{
	var tmpobj=eval("document."+strfrm+"."+objname);
	var tmpobj2=eval("document."+strfrm+"."+objname2);
  for(var i=0;i<tmpobj.length;i++)
  {
    if (tmpobj2.value=='') 
    {
      tmpobj2.value=tmpobj.options[i].value;
    }
    else 
    {	
      tmpobj2.value+='@@@'+tmpobj.options[i].value;
    }
  }
}

function AddUrl(cname,objname){
  var obj=document.getElementById(objname);
  var thisurl=cname+(obj.length+1)+'|http://'; 
  var url=prompt('请输入'+cname+'和链接，中间用“|”隔开：',thisurl);
  if(url!=null&&url!=''){obj.options[obj.length]=new Option(url,url);}
}

function ModifyUrl(cname,objname){
  var obj=document.getElementById(objname);
  if(obj.length==0) return false;
  var thisurl=obj.value; 
  if (thisurl=='') {alert('请先选择一个'+cname+'，再点修改按钮！');return false;}
  var url=prompt('请输入'+cname+'和链接，中间用“|”隔开：',thisurl);
  if(url!=thisurl&&url!=null&&url!=''){obj.options[obj.selectedIndex]=new Option(url,url);}
}

function DelUrl(cname,objname){
  var obj=document.getElementById(objname);
  if(obj.length==0) return false;
  var thisurl=obj.value; 
  if (thisurl=='') {alert('请先选择一个'+cname+'，再点删除按钮！');return false;}
  if(obj.selectedIndex==0){alert('不能删除第一个'+cname+'！');return false;}
  obj.options[obj.selectedIndex]=null;
}

function UpUrl(cname,objname) {
	var obj=document.getElementById(objname);
	var nIndex = obj.selectedIndex;
	var nLen = obj.length;
	if ((nLen<1)||(nIndex==0)) return;
	if (nIndex<0) {
		alert("请选择一个要移动的"+cname+"！");
		return;
	}
	var sValue=obj.options[nIndex].value;
	var sValue2=obj.options[nIndex-1].value;
	//var sHTML=obj.options[nIndex].innerHTML;
	obj.options[nIndex]=new Option(sValue2,sValue2);
	obj.options[nIndex-1]=new Option(sValue,sValue);
	obj.selectedIndex=nIndex-1;
}

function DownUrl(cname,objname) {
	var obj=document.getElementById(objname);
	var nIndex = obj.selectedIndex;
	var nLen = obj.length;
	if ((nLen<1)||(nIndex==nLen-1)) return;
	if (nIndex<0) {
		alert("请选择一个要移动的"+cname+"！");
		return;
	}
	var sValue=obj.options[nIndex].value;
	var sValue2=obj.options[nIndex+1].value;
	obj.options[nIndex]=new Option(sValue2,sValue2);
	obj.options[nIndex+1]=new Option(sValue,sValue);
	obj.selectedIndex=nIndex+1;
}

function SelectFiles(sChannelID,type,objname,objname2)
{
  var arr=window.showModalDialog('AMH_UploadFiles.asp?FileType=select&cid='+sChannelID, '', 'dialogWidth:750px;dialogHeight:450px;help:no;scroll:yes;status:no;directories:yes;scrollbars:no;Resizable=no;');
	if(arr!=null)
	{
		var obj = document.getElementById(objname);
		var strT=arr.split('|');
		if (type=='1'){
			var url='下载地址'+(obj.length+1)+'|'+strT[0];
			obj.options[obj.length]=new Option(url,url);
		}
		else if (type=='2'){
			var url='图片名称'+(obj.length+1)+'|'+strT[0];
			obj.options[obj.length]=new Option(url,url);
		}
		else if (type=='3'){
			var url='影片名称'+(obj.length+1)+'|'+strT[0];
			obj.options[obj.length]=new Option(url,url);
		}
		else {
			obj.value=strT[0];
		}
		if (objname2!='') {document.getElementById(objname2).value=strT[1];}
	}
}

function SelectColor(tcstr)
{
  var c=window.showModalDialog("../Editor/Html/Dialog/selcolor2.htm","s","dialogWidth=300px;dialogHeight=270px;status=0");
  var d=c;
  if (c && c!="")
  {
    if (d.length==7) { d=d.substr(1,d.length); }
    eval("window.document.all."+tcstr+".value=d;window.document.all."+tcstr+".style.backgroundColor=c;");
  }
}
function ClearColor(tcstr)
{
  eval("window.document.all."+tcstr+".value='';window.document.all."+tcstr+".style.backgroundColor='';");
}

function slect_color(tcstr)
{
  var c=window.showModalDialog("../Editor/Html/Dialog/selcolor.htm","s","dialogWidth=300px;dialogHeight=270px;status=0");
  var d=c;
  if (c && c!="")
  {
    if (d.length==7) { d=d.substr(1,d.length); }
    eval("window.document.all."+tcstr+".value=d;");
  }
}

//<input type=test name=tim value='2003-5-19' size=12 maxlength=10 readonly>
//<input type=button name=st_btn value="选择" onclick="javascript:select_time(tim);return false;">

function select_time(st_obj)
{
  var showx=event.screenX-event.offsetX-14;
  var showy=event.screenY-event.offsetY-168;
  var retval=window.showModalDialog("../asaiadmin/Include/AMH_Select_Data.asp?"+st_obj.value,"","dialogWidth:197px; dialogHeight:210px; dialogLeft:"+showx+"px; dialogTop:"+showy+"px; status:no; directories:yes;scrollbars:no;Resizable=no;");
  if( retval!=null ) { st_obj.value=retval; }
  //else { }
}

function sel_type(trsurl,turl)
{
	var sn,i,wdim,temp1,nurl;
	wdim=turl.split(":");
	sn=wdim.length;
	for (i=0;i<sn;i++)
	{
	nurl=wdim[i];
		temp1="<OPTION value='"+nurl+"'";
		if (trsurl==nurl) { temp1+=" selected"; }
		temp1+=">"+nurl+"</option>";
	document.write(temp1);
	}
}

function re_load() { location.reload(); }

function click_return(cvar,ct)
{
  var nvar='';
  switch (ct)
  {
    case 1:
      nvar='提示信息！';
    default :
      nvar='您确定要'+cvar+'吗？\n\n执行该操作后将不可恢复！';
  }
  var cf=window.confirm(nvar);
  if (cf) { return true; }
  return false;
}

function open_win(url,name,width,height,scroll)
{
  var Left_size = (screen.width) ? (screen.width-width)/2 : 0;
  var Top_size = (screen.height) ? (screen.height-height)/2 : 0;
  var open_win=window.open(url,name,'width=' + width + ',height=' + height + ',left=' + Left_size + ',top=' + Top_size + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=' + scroll + ',resizable=no' );
}

function AsaiMHint(itp)
{
  var knum=event.keyCode;
  var ktrue=false;
  if (knum >= 48 && knum <= 57) { ktrue=true; }
  if (itp==1)
  {
    if (!ktrue && knum==46) { ktrue=true; }
  }
  return ktrue;
}

function frm_submitonce(theform)
{
  if (document.all||document.getElementById)
  {
    for (i=0;i<theform.length;i++)
    {
      var tempobj=theform.elements[i]
      if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset") { tempobj.disabled=true; }
    }
  }
}
//*****************选择框 开始******************
function select_all(frm)
{
  var slength=0;
  if (frm.sel_id==null) { return false; }
  var sall=frm.sel_all.checked;
  if (frm.sel_id.length)
  {
    slength=frm.sel_id.length;
    for (var i=0;i<slength;i++) { frm.sel_id[i].checked=sall; }
  }
  else { frm.sel_id.checked=sall; }
}

function sel_click(frm)
{
  var slength=0;
  var issel=false;
  if (frm.sel_id!=null)
  {
    if (frm.sel_id.length)
    {
      slength=frm.sel_id.length;
      for (var i=0;i<slength;i++) { if (frm.sel_id[i].checked==true) { issel=true; break; } }
    }
    else { if (frm.sel_id.checked==true) { issel=true; } }
  }
  if (issel==true)
  {
    if (confirm("执行此操作后可能无法恢复！你确定吗？")) { return true; }
    else { return false; }
  }
  else { alert("没有选择任何记录！"); return false; }
}
//*****************选择框 结束******************

//window.onerror=function(a,b,c){return true;}

//浏览器类型变量
var InternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

var client_browse="";
if (document.getElementById)	// IE5+,NN6+	document.getElementById("id");
{ client_browse="ie5"; }
else if (document.all)		// IE4		document.all("id");
{ client_browse="ie4"; }
else if (document.layers)	// NN4		document.layers["id"];
{ client_browse="ns4"; }

function get_id(strname)
{
  switch (client_browse)
  {
    case "ie5":
      return document.getElementById(strname);
      break;
    case "ns4":
      return document.layers[strname];
      break;
    default :	//"ie4"
      return document.all(strname);
      break;
  }
}

function insert_value(strinput,strvalue)
{
  var tmpstr="";
  switch (client_browse)
  {
    case "ie5":
      tmpstr="document.all."+strinput+".value='"+strvalue+"';";
      break;
    case "ns4":
      tmpstr="document.layers.[\""+strinput+"\"].value='"+strvalue+"';";
      break;
    default :	//"ie4"
      tmpstr="document.all."+strinput+".value='"+strvalue+"';";
      break;
  }
  if (tmpstr!="") eval(tmpstr);
}

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) { //v3.0
  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); 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];}
}

//提示框
//***********默认设置定义.*********************
var tPopWait=300;    //停留tWait豪秒后显示提示。
var tPopShow=10000;    //显示tShow豪秒后关闭提示
var showPopStep=20;
var popOpacity=95;
var tfontcolor="#000000";
var tbgcolor="#ffffff";
var tbordercolor="#808080";

//***************内部变量定义*****************
var sPop=null,curShow=null,tFadeOut=null,tFadeIn=null,tFadeWaiting=null;

document.write("<style type='text/css'id='defaultPopStyle'>");
document.write(".cPopText {  background-color: " + tbgcolor + ";color:" + tfontcolor + "; border: 1px " + tbordercolor + " solid;font-color: font-size: 12px; padding-right: 4px; padding-left: 4px; height: 20px; padding-top: 2px; padding-bottom: 2px; filter: Alpha(Opacity=0)}");
document.write("</style>");
document.write("<div id='dypopLayer' style='position:absolute;z-index:1000;' class='cPopText'></div>");

function showPopupText()
{
  var o=event.srcElement;
  MouseX=event.x;
  MouseY=event.y;
  if(o.alt!=null && o.alt!=""){o.dypop=o.alt;o.alt=""};
  if(o.title!=null && o.title!=""){o.dypop=o.title;o.title=""};
  if(o.dypop!=sPop)
  {
    sPop=o.dypop;
    clearTimeout(curShow);
    clearTimeout(tFadeOut);
    clearTimeout(tFadeIn);
    clearTimeout(tFadeWaiting);  
    if(sPop==null || sPop=="")
    {
      dypopLayer.innerHTML="";
      dypopLayer.style.filter="Alpha()";
      dypopLayer.filters.Alpha.opacity=0;  
    }
    else
    {
      if(o.dyclass!=null) popStyle=o.dyclass 
      else popStyle="cPopText";
      curShow=setTimeout("showIt()",tPopWait);
    }
  }
}

function showIt()
{
  dypopLayer.className=popStyle;
  dypopLayer.innerHTML=sPop;
  popWidth=dypopLayer.clientWidth;
  popHeight=dypopLayer.clientHeight;
  if(MouseX+12+popWidth>document.body.clientWidth) popLeftAdjust=-popWidth-24
    else popLeftAdjust=0;
  if(MouseY+12+popHeight>document.body.clientHeight) popTopAdjust=-popHeight-24
    else popTopAdjust=0;
  dypopLayer.style.left=MouseX+12+document.body.scrollLeft+popLeftAdjust;
  dypopLayer.style.top=MouseY+12+document.body.scrollTop+popTopAdjust;
  dypopLayer.style.filter="Alpha(Opacity=0)";
  fadeOut();
}

function fadeOut(){
  if(dypopLayer.filters.Alpha.opacity<popOpacity)
  {
    dypopLayer.filters.Alpha.opacity+=showPopStep;
    tFadeOut=setTimeout("fadeOut()",1);
  }
  else
  {
    dypopLayer.filters.Alpha.opacity=popOpacity;
    tFadeWaiting=setTimeout("fadeIn()",tPopShow);
  }
}

function fadeIn()
{
  if(dypopLayer.filters.Alpha.opacity>0)
  {
    dypopLayer.filters.Alpha.opacity-=1;
    tFadeIn=setTimeout("fadeIn()",1);
  }
}

document.onmouseover=showPopupText;
