function onF( obj ){obj.style.background='#FFFFFF';}
function onB( obj ){obj.style.background='#F5F4E7';}
function ControlOnmouseIn( _Obj )
{
	_Obj.style.border = "1px #00AAFF solid";
	_Obj.style.background = "#E7F7FF";	
}
function ControlOnmouseOut( _Obj )
{
	_Obj.style.border = "1px #84A6BD solid";	
	_Obj.style.background = "#FFFFFF";	
}
function onMover( obj ){return obj.focus();}
function gid(id){return document.getElementById?document.getElementById(id):null;}
function CheckID_str( ID ,msg )
{
	var _obj = gid( ID );
	if (_obj == null){return true;}
	var _str = _obj.value;
	if (_str == ''){ alert(msg); return false;}
	return true;
}
// 验证是否是数字

function isNumber(str){	
	var oneDecimal=false;	
	var oneChar=0;	
	str=str.toString ();	
	for(var i=0;i<str.length;i++){
		
		oneChar=str.charAt(i).charCodeAt(0);		
		// -
		if(oneChar==45){
			return false;
		}
		// 小数点

		if(oneChar==46){
			if(!oneDecimal){	
				oneDecimal=true;	
				continue;	
			}else {	
				return false;	
			}
		}
		// 数字只能在0和9之间
		if(oneChar<48||oneChar>57){
			return false;	
		}		
	}
	return true;	
}
/*正则表达式验证*/
function V_Expression(_ID,_patn,_Desc){
	var _obj = gid(_ID);
	var _strValue = _obj.value;		
	var matchArray=_strValue.match(_patn);
	if (matchArray==null) { VildateMsgShow(_Desc,_ID); _obj.focus();return false;}	
	return true;
}

/*验证两个对象的值是否相同*/
function V_Sameness(_ID1,_ID2,_Desc){
	var _obj1 = gid(_ID1);
	var _obj2 = gid(_ID2);	
	if (_obj1.value != _obj2.value) { VildateMsgShow(_Desc,_ID2); _obj2.focus();return false;}	
	return true;
}

//是否为数字
function V_ISNumber( _ID ,_Desc )
{
    var _obj = gid(_ID);
    if ( _obj == null ) return true;
    var _str = _obj.value;
    if ( !isNumber(_str) ) {VildateMsgShow(_Desc,_ID);_obj.focus();return false;}
    return true;
}
//是否为空
function V_Empty( _ID ,_Desc )
{
    var _obj = gid(_ID);
    if ( _obj == null ) return true;
    var _str = _obj.value;
    if ( _str =='' ) {VildateMsgShow(_Desc ,_ID);_obj.focus();return false;}
    return true;
}
//是否已选择下拉列表框的项
function V_Select( _ID ,_Desc )
{
    var _obj = gid(_ID);
    if ( _obj == null ) return true;
    var _str = _obj.value;
    if ( _str =='' ) {VildateMsgShow(_Desc,_ID);_obj.focus();return false;}
    if ( _str =='-1' ) {VildateMsgShow(_Desc,_ID);_obj.focus();return false;}
    return true;
}
//是否为money型
function V_Price( _ID ,_Desc  )
{			
	var _obj = gid(_ID);
	if ( _obj == null ) return true;
	if ( _obj.value == '' ) { VildateMsgShow("请输入"+_Desc+"！",_ID); _obj.focus(); return false;}
	if( !isNumber( _obj.value ) ){VildateMsgShow("提示："+_Desc+"格式错误！必须数数字" ,_ID);_obj.focus(); return false;}
	
	return true;
}
//是否为email格式
function V_Email(_ID)
{
	var _obj = gid(_ID);
	var _strValue = _obj.value;
	if (_strValue==""){ VildateMsgShow("请输入电子邮箱。" ,_ID); _obj.focus();return false;}
	var patn = /^[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]*)*@[a-zA-Z0-9\-]+([\.][a-zA-Z0-9\-]+)+$/;
	var matchArray=_strValue.match(patn);
	if (matchArray==null){ VildateMsgShow("电子邮箱格式不正确,请输入正确的电子邮箱地址。",_ID); _obj.focus();return false;}
	return true;
}

//是否为email格式
function V_Email_GS(_ID)
{
	var _obj = gid(_ID);
	var _strValue = _obj.value;
	//if (_strValue==""){ VildateMsgShow("请输入电子邮箱。" ,_ID); _obj.focus();return false;}
	if (_strValue!=""){
	var patn = /^[_a-zA-Z0-9\-]+(\.[_a-zA-Z0-9\-]*)*@[a-zA-Z0-9\-]+([\.][a-zA-Z0-9\-]+)+$/;
	var matchArray=_strValue.match(patn);
	if (matchArray==null){ VildateMsgShow("电子邮箱格式不正确,请输入正确的电子邮箱地址。",_ID); _obj.focus();return false;}
	}
	return true;
}

/*电话号码区号*/
function V_TelQH(_TelID,_Desc){
	var _obj = gid(_TelID);
	var _strValue = _obj.value;
	if ( _strValue == "" ) { VildateMsgShow("请输入"+_Desc+"！",_ID); _obj.focus();return false;}
	var patn = /^\d{3,4}$/;
	var matchArray=_strValue.match(patn);
	if (matchArray==null) { VildateMsgShow("您输入的"+_Desc+"格式不正确，请重新输入。",_ID); _obj.focus();return false;}	
	return true;
} 
/*电话号码区号*/
function V_Tel(_TelID,_Desc){
	var _obj = gid(_TelID);
	var _strValue = _obj.value;
	if ( _strValue == "" ) { VildateMsgShow("请输入"+_Desc+"！",_ID); _obj.focus();return false;}
	var patn = /^\d{6,9}$/;
	var matchArray=_strValue.match(patn);
	if (matchArray==null) { VildateMsgShow("您输入的"+_Desc+"格式不正确，请重新输入。",_ID); _obj.focus();return false;}	
	return true;
} 
function SH_SelectOne(obj)
{
	//var obj = window.event.srcElement;
	if( obj.checked == false)
	{
		document.getElementById('chkall').checked = obj.chcked;
	}
}

function CheckAll(form)
{
  for (var i=0;i<form.elements.length;i++)
    {
    var e = form.elements[i];
    if (e.name != 'chkall' && e.name !='deleteMode')
       e.checked = form.chkall.checked;
    }
}

function   checkImagestate( _spanid, imgobj ,nShowWith)     
{        
    var _objspan = gid(_spanid);    
   if ( event.srcElement.readyState == "complete")
   {      
            imgobj.width=nShowWith;   
            _objspan.style.display='none'
            imgobj.style.display = 'block';  
   }
   else
   {
        _objspan.innerHTML = "<font style=\"color:#FFD5B2\">图片加载失败！</font>"
   }   
}  

function checkImagestate(_objImg,_width,_height)
{   
    var _Oldwidth = _objImg.width;
    var _OldHeight = _objImg.height;
    if(_Oldwidth>_width||_OldHeight>_height)
    {//现有图片只有宽或高超了预设值就进行js控制 
        _w=_Oldwidth/_width; 
        _h=_OldHeight/_height; 
        if(_w>_h)//比值比较大==>宽比高大 
        {
            _objImg.width=_width; //定下宽度为width的宽度 
            //以下为计算高度 
            _objImg.height=_OldHeight/_w;
        }
        else//高比宽大 
        {
            _objImg.height=_height; //定下宽度为height高度 
            _objImg.width=_Oldwidth/_h; //以下为计算高度 
         } 
    } 
}

function Select_PriceDwChanage()
{			   
	var _obj = gid('S_Pricedw');
	var _objzdyinput = gid('t_Pricedw');
	
	if (_obj.value=='自定义')
	{
	    _objzdyinput.style.display='block';	 
	     _objzdyinput.value =  '';  	  	    	    
	}
	else
	{
	    _objzdyinput.style.display='none';	
	     _objzdyinput.value =   _obj.value;      	    
	}	
}

function Select_JLDwChanage()
{			   
	var _obj = gid('S_JLDw');
	var _objzdyinput = gid('t_JLDw');
	
	if (_obj.value=='自定义')
	{
	    _objzdyinput.style.display='block';	  
	    _objzdyinput.value =  '';  	  	    
	}
	else
	{
	    _objzdyinput.style.display='none';	
	    _objzdyinput.value =   _obj.value;  	    
	}
}

function Set_FCKeditor_Value(_htmlValue)
{			   
	var _FCKeditoroEditor1 =FCKeditorAPI.GetInstance('FCKeditor_1'); 
	_FCKeditoroEditor1.SetHTML(_htmlValue, true); 	
}

//var SelectTypeToEnd_Total = 0;
//var SelectTypeToEnd_SelCount = 0;
function Validate_SelectTypeToEndISComplete()
{			   
    alert( SelectTypeToEnd_Total );
    alert( SelectTypeToEnd_SelCount );
	if ( SelectTypeToEnd_Total > SelectTypeToEnd_SelCount )
	{alert("请输入选择产品分类。");return false;}
	
	if ( SelectTypeToEnd_Total == SelectTypeToEnd_SelCount )	return true;
	
	return true;
}

var __Win__IsAutoClose = true;
var __Win__IsFilterClose = true;
var __Win__CloseWaitTime = 3000;


var __Win__BlockFlag = false;


 
//关闭气泡提示
function HideWinErrMsgTips(elementid)
{

    var ua = navigator.userAgent.toLowerCase();
    var isOpera = (ua.indexOf('opera') != -1);
    var isIE = (ua.indexOf('msie') != -1 && !isOpera);
    
    var objWinDiv = document.getElementById(elementid);

    if(isIE&&typeof(__Win__IsFilterClose)!="undefined"&&__Win__IsFilterClose)
    {
       __Win__BlockFlag = false;
       HideIEWinErrMsgTips(objWinDiv.id);
    }
    else
    {
	    objWinDiv.style.visibility = "hidden";
	}
}

function HideIEWinErrMsgTips(elementid)
{
     var obj___ = document.getElementById(elementid+"____")
     var  opacty=obj___.filters.alpha.opacity;   
     obj___.filters.alpha.opacity-=9;
     if(obj___.filters.alpha.opacity>0)
     {
        if(!__Win__BlockFlag)
            setTimeout("HideIEWinErrMsgTips('"+elementid+"')",100);
     }
     else
     {
        document.getElementById(elementid).style.visibility = "hidden";
     }
    
}

//得到某obj的x,y坐标,兼容大部分的浏览器
function getWinElementPos(obj)
{

 var ua = navigator.userAgent.toLowerCase();
 var isOpera = (ua.indexOf('opera') != -1);
 var isIE = (ua.indexOf('msie') != -1 && !isOpera); // not opera spoof

 var el = obj;

 if(el.parentNode === null || el.style.display == 'none') 
 {
  return false;
 }

 var parent = null;
 var pos = [];
 var box;

 if(el.getBoundingClientRect) //IE
 {
  box = el.getBoundingClientRect();
  var scrollTop = Math.max(document.documentElement.scrollTop, document.body.scrollTop);
  var scrollLeft = Math.max(document.documentElement.scrollLeft, document.body.scrollLeft);

  return {x:box.left + scrollLeft, y:box.top + scrollTop};
 }
 else if(document.getBoxObjectFor) // gecko
 {
  box = document.getBoxObjectFor(el);
     
  var borderLeft = (el.style.borderLeftWidth)?parseInt(el.style.borderLeftWidth):0;
  var borderTop = (el.style.borderTopWidth)?parseInt(el.style.borderTopWidth):0;

  pos = [box.x - borderLeft, box.y - borderTop];
 }
 else // safari & opera
 {
  pos = [el.offsetLeft, el.offsetTop];
  parent = el.offsetParent;
  if (parent != el) {
   while (parent) {
    pos[0] += parent.offsetLeft;
    pos[1] += parent.offsetTop;
    parent = parent.offsetParent;
   }
  }
  if (ua.indexOf('opera') != -1 
   || ( ua.indexOf('safari') != -1 && el.style.position == 'absolute' )) 
  {
    pos[0] -= document.body.offsetLeft;
    pos[1] -= document.body.offsetTop;
  } 
 }
  
 if (el.parentNode) { parent = el.parentNode; }
 else { parent = null; }
  
 while (parent && parent.tagName != 'BODY' && parent.tagName != 'HTML') 
 { // account for any scrolled ancestors
  pos[0] -= parent.scrollLeft;
  pos[1] -= parent.scrollTop;
  
  if (parent.parentNode) { parent = parent.parentNode; } 
  else { parent = null; }
 }
 return {x:pos[0], y:pos[1]};
}


//验证控件显示设置
//_strmsg :显示的提示信息
function VildateMsgShow( _strmsg ,_ValidateControlID )
{   
   var val = gid('SpanVildateMsg');
   if (typeof(val.display) == "string")
     {
        if (val.display == "None")
        {
            return;
        }
    }
    if ((navigator.userAgent.indexOf("Mac") > -1) &&(navigator.userAgent.indexOf("MSIE") > -1))
    {
        val.style.display = "inline";
    }
    val.style.position = "absolute";
    val.style.className = "";  
    
    var closestr = " [<span style=\"cursor:hand;color:red\" title=\"关闭提示\" onclick=\"javascript:HideWinErrMsgTips('"+val.id+"')\">关闭</span>]&nbsp;";
    val.innerHTML="<div style=\"position:absolute;z-index:9999;filter:alpha(opacity=100)\" class='tip-bg' id='"+val.id+"____'><div class=\"tip-bulb\">&nbsp;&nbsp;"+_strmsg+closestr+"</div></div>";
    var obj = document.getElementById(_ValidateControlID)
    var WinElementPos = getWinElementPos(obj)
	val.style.left = (parseInt(WinElementPos.x+obj.offsetWidth)).toString() + "px";
	val.style.top = (parseInt(WinElementPos.y)).toString() + "px";   
     val.style.visibility ="visible";
    __Win__BlockFlag = true;
    if(typeof(__Win__IsAutoClose)!="undefined"&&__Win__IsAutoClose&&typeof(__Win__CloseWaitTime)!="undefined")
        setTimeout("HideWinErrMsgTips('"+val.id+"')",__Win__CloseWaitTime);
        
    return false;
}
