//公用JAVASCRIPT代码

//会员登陆验证
function CheckUserLogin(frm)     
{
  if (frm.txtIncNum.value=="")
   {
      window.alert("企业编号不能为空！")
      frm.txtIncNum.focus()
      return false
   } //end if
  
   if (frm.txtIncNum.value.length>0 && (frm.txtIncNum.value.indexOf("'")!=-1|| frm.txtIncNum.value.indexOf("=")!=-1||frm.txtIncNum.value.indexOf("%")!=-1||frm.txtIncNum.value.indexOf("&")!=-1||frm.txtIncNum.value.indexOf("?")!=-1||frm.txtIncNum.value.indexOf("$")!=-1))
   {
      window.alert("企业编号中含有非法字符！!")
      frm.txtIncNum.focus()
      return false
   } //end if 

  if (frm.txtUserID.value=="")
   {
      window.alert("登录用户不能为空！")
      frm.txtUserID.focus()
      return false
   } //end if
  
   if (frm.txtUserID.value.length>0 && (frm.txtUserID.value.indexOf("'")!=-1|| frm.txtUserID.value.indexOf("=")!=-1||frm.txtUserID.value.indexOf("%")!=-1||frm.txtUserID.value.indexOf("&")!=-1||frm.txtUserID.value.indexOf("?")!=-1||frm.txtUserID.value.indexOf("$")!=-1))
   {
      window.alert("登录用户中含有非法字符！!")
      frm.txtUserID.focus()
      return false
   } //end if 

   if (frm.txtPassWord.value=="")
   {
      window.alert("登录密码不能为空！")
      frm.txtPassWord.focus()
      return false
   } //end if
 
   if (frm.txtPassWord.value.length>0 && frm.txtPassWord.value.indexOf("'")!=-1)
    {
      window.alert("登录密码中含有非法字符！")
      frm.txtPassWord.focus()
      return false
    } //end if 
 } //end function


//弹出Open窗口
function OpenWin(url,winmc,left,top,width, height)  //打开新窗口
{
	var Win = window.open(url,winmc,'width=' + width + ',height=' + height + ',left=' +left +',top=' + top +',resizable=yes,scrollbars=auto,menubar=no,location=no,status=no');
}

//用ShowModal弹出窗口
function OpenShowModal(Url,Winmc,Left,Top,Width,Height)
{                                          
   var win =showModalDialog(Url,Winmc,"dialogWidth:" + Width + "px;dialogHeight:" + Height + "px;dialogLeft:" + Left + "px;dialogTop:" + Top + "px;resizable=yes,scrollbars=auto,menubar=no,location=no,status=no") ;                                            
 } 

//--------------------------------------附件操作函数----------------------------------------------
var ExistAttaInfo = new Array();
var attaIdx = 1;
var IsIE;

function IsIEBrowser() {
	if (navigator.userAgent.indexOf("MSIE") != -1) {
		return true;
		} else {
		return false;
		}
}

// 增加附件函数 ()，增加到 idfilespan,基数为 attaIdx 。
function AddFileObj() 
{
        if (attaIdx ==9)
        {
          window.alert("最多只能上传10个附件!");
          return false;
         }
	addfile("idfilespan",attaIdx);
 	attaIdx++;
	return false;
}

//----------------------------------------fileexist()----------------------------------------------------------
//edited by alun
function exist(fileId) {
      var file = document.getElementById(fileId);
	  var result = false;
	  if ( file !=null ) {
			if ( file.value != null && file.value != "") {
				result = existFile( file);
			}//if
	  }
	  if( result)
	  {
		alert("此附件已粘贴, 如果在原有附件列表中并已删除，请取消删除；\n如果在新粘贴附件列表中，请先删除再粘贴。");
		//--attaIdx;
		//document.getElementById( "idAttachOper"+ attaIdx).click();
	  }
}//end of function
//added by alun
function getfilename( attaName ) {
	var s = attaName.lastIndexOf( '\\' );
	return attaName.substr(s+1, attaName.length - s -1);
}
//added by alun
function existFile( file)
{
	var form = document.sendmail;
	for ( var i= 0 ; i < form.elements.length ; i ++ ) {				    
		if ( form.elements[i].type == "file" && form.elements[i].name != file.name ) {
			if ( file.value == form.elements[i].value ) {
				return true;
			}
		}
	}//for
	for (var i=0; i<ExistAttaInfo.length; i++) {
		var theName = ExistAttaInfo[i];
		if ( theName != null && theName != "" && theName == getfilename(file.name) ) {
			return true;
		}
	}
	return false;
}

//----------------------------------------addfile(spanId,index)----------------------------------------------
function addfile(spanId,index)
{

       var strIndex = "" + index;
	   var fileId = "FileUp"+ strIndex;
	   var brId = "idAttachBr" + strIndex;
	   addInputFile(spanId,fileId);
	   adddel(spanId,index);
	   addbr(spanId,brId);
	   return;
}

//-------------------------------------------sub function----------------------------------------------------
function addInputFile(spanId,fileId)
{
	  var span = document.getElementById(spanId);
	  if ( span !=null ) {
	                if ( !IsIE ) {
						var fileObj = document.createElement("input");
						if ( fileObj != null ) {
							fileObj.type="file";
							fileObj.name = fileId;
							fileObj.id = fileId;
							fileObj.size="50";
							fileObj.RUNAT=SERVER;
							//var clickEvent = "exist('" + fileId + "',frm)";
							fileObj.setAttribute("onclick",clickEvent,0);  
							span.appendChild(fileObj);
						}//if fileObj
					}// !IsIE

					if ( IsIE ) {
						var fileTag = "<input type='file' id ='" + fileId + "' name='" + fileId + "' size=50 RUNAT=SERVER>";
						var fileObj = document.createElement(fileTag); 
						span.appendChild(fileObj);
					}//IsIE if
			
	  }//if span
}

function addbr(spanId,brId)
{
	  var span = document.getElementById(spanId);
	  if ( span !=null ) {
			var brObj = document.createElement("br");
			if ( brObj !=null ) {
				brObj.name = brId;
				brObj.id = brId;
				span.appendChild(brObj);
            }//if
     }//if
	 return;
}

function adddel(spanId,index)
{
      var strIndex = "" + index;
	  var delId = "idAttachOper" + strIndex;
	  var span = document.getElementById(spanId);
	  if ( span != null ) {
			var oTextNode = document.createElement("<span></span>");
			oTextNode.style.width="5px";
			span.appendChild(oTextNode);
		        if ( IsIE ) {
	                var tag = "<input type='button' id='" + delId + "' onclick=delfile('" + spanId + "',"+strIndex+")></input>";
			var delObj = document.createElement(tag);
			if ( delObj != null ) {
				span.appendChild(delObj);
			}//if

			}// Is IE
			
	        if ( !IsIE ) {
				var delObj = document.createElement("input");
				if ( delObj != null ) {
					delObj.name = delId;
					delObj.id = delId;
					delObj.type = "button";
					var clickEvent = "return delfile('" + spanId + "',"+strIndex+");";
					delObj.setAttribute("onclick",clickEvent);  
					span.appendChild(delObj);
				}//if
			}// !IsIE if
			if( delObj != null) delObj.value = "删除";
		}//main if
		return;
}


//---------------------------------------------delete input file-----------------------------------------------
function delfile(spanId,index)
{
	   var strIndex = "" + index;
	   var fileId = "FileUp"+ strIndex;
	   var brId = "idAttachBr" + strIndex;
	   var delId = "idAttachOper" + strIndex;
	   //first,get the element
       var span = document.getElementById(spanId);
	   //alert(  "del span: " + span  );
	   if ( span == null ) return false;

	   var fileObj = document.getElementById(fileId);
	   if ( fileObj == null ) return false;

	   var brObj = document.getElementById(brId);
	   if ( brObj ==null ) return false;

	   var delObj = document.getElementById(delId );
	   //alert(  "del delId: " + delObj  );
	   if ( delObj == null ) return false;

           //second,create the replace element
	   var temp= document.createElement("<span>");
	   //third,replace it
	   span.replaceChild(temp,fileObj);
	   span.replaceChild(temp,brObj);
	   span.replaceChild(temp,delObj);	
           attaIdx--;
	   return false;
}

function resetForm(){
	if (navigator.userAgent.indexOf("MSIE") != -1) {
		IsIE = true;
		} else {
		IsIE = false;
		}
}
resetForm();

function Prompt(str)
 {
   if (str == "0")
     {
        if (confirm("您确认要注销登录吗？")== false) return false;
        else 
         {
          //return true;
          top.window.location.href='../LoginOut.aspx';
         }
    }
    else
     {
      if (confirm("确认退出会员后台管理系统，返回登录窗口？") == false) return false;
      else
      {
        //return true;
	top.window.location.href='../LoginOut.aspx';
       }
    }
}


//获取下拉框的值
function GetDropValue(obj1,obj2,message,isvalue,IsNeed)
 {
    if ((obj1.value == "" || obj1.value == "0") && IsNeed == "0")
     {
	window.alert(message);
	return false;
     }
    else
     {
	if (isvalue == "0")
	  obj2.value = obj1.value;
	else
	  obj2.value = obj1.options[obj1.selectedIndex].text;
     }
}