//======================================================================
//使IFRAME自适应高度
function dynself(strFrameName)
{
	x=document.getElementById(strFrameName);
    x.height=eval(strFrameName).document.body.scrollHeight;
}

//==============================================================================
//当当前页面改高度时，使IFRAME自适应其高度
function autoHeight(strFrameName)
{
    parent.document.getElementById(strFrameName).style.height=document.body.scrollHeight + 20 + 'px';
}
/***************************************
函数名称:selectAll(obj)
功能:全选
设计目的:把一个表单里面的checkbox进行全选。
设计原理:输入一个表单名,按控件类型查找控件并进行修改checkbox.checked的值为true
实现方法/过程:
出入口参数:
  obj 一个表单对象
返回值描述:无
设计修改日志:
	2006.06.16 建立
相关函数:无
其他补充说明:
selectAll()是把指定的checkbox设定为全选
eg: selectAll(document.form1);
****************************************/
function  selectAll(obj,cks)  
{  
	for(var  i  =  0;i < obj.elements.length;i++)  
		if(obj.elements[i].type  ==  "checkbox")  
		    obj.elements[i].checked  =  cks.checked; 

}

//==================================================================================
/******************************************
函数名称:adverseSelect(obj)
功能:反选
设计目的:把一个表单里面的checkbox进行反选。
设计原理:输入一个表单名,按控件类型查找控件并进行click()操作
实现方法/过程:
出入口参数:
  obj
返回值描述:无
设计修改日志:
	2006.06.16 建立
相关函数:无
其他补充说明:
eg: adveresSelect(document.form1);
******************************************/
//================================================================================
function adverseSelect(obj)
{  
	for(var  i  =  0;i < obj.elements.length;i++)  
		if(obj.elements[i].type  ==  "checkbox")  
			obj.elements[i].click();  
}

//===================================================================================
//检查密码格式输入是否正确
function checkPsw(obj)
{
	if(obj.passwordOldPsw.value == "")
	{
		alert('请输入旧密码！');
		obj.passwordOldPsw.focus();
		return false;
	}

	if(obj.passwordNewPsw.value=='')
	{
		alert('请输入新密码！');
		obj.passwordNewPsw.focus();
		return false;
	}

	if(obj.passwordNewPsw.value!=obj.passwordNewPsw2.value)
	{
		alert('新密码输入不一致！');
		obj.passwordNewPsw2.focus();
		return false;
	}

	if(obj.passwordNewPsw.value.length < 6 || obj.passwordNewPsw2.value.length < 6)
	{
		alert('密码长度最少6位！');
		obj.passwordNewPsw.focus();
		return false;	    
	}

	return true;
}

//=================================================================================
//设置checkbox为选中
function setCheckBoxChecked(checkForm, strValue)
{
    items = strValue.split(',');
    for (var i = 0; i < checkForm.elements.length; i++)
    {
        var e = checkForm.elements[i];
        for(n = 0; n < items.length; n++)
            if(e.type == 'checkbox' && e.value == items[n])
                e.checked = true;
    }
}

//==================================================================================
//设置Radio的值
function setRadio(obj)
{
	obj.checked = "checked";
}

//=================================================================================
//把控件设置为不可用
function setItemDisable(ItemName,theValue)
{
	document.getElementById(ItemName).disabled = theValue;
}

//==================================================================================
function setValue(widgetId,theValue)
{
    document.getElementById(widgetId).value = theValue;
}

//=================================================================================
//把地点ID转为相应的地点
function getPlaceValue(strProvinceID)
{
    if (strProvinceID.length < 6) return false;//地点ID小于6是返回false
    var i = 0;
    var strProvince = "",strCity = "",strCounty = "";
    ProvinceID = strProvinceID.substr(0,6);
    CityID = strProvinceID.substr(0,9);
    CountyID = strProvinceID;
	strProvince = getProvince(ProvinceID)
    if (strProvinceID.length > 8)//地点ID小于8不执行以下代码
    {
		strCity = getCity(ProvinceID,CityID)
        if(strProvinceID.length > 11)//地点ID小于11不执行以下代码
        {
        	strCounty = getCounty(CityID,CountyID)
        }
    }
    var strPlace = strProvince + strCity + strCounty;
    return strPlace;
}
//取得省份=======================
function getProvince(ProvinceID)
{
	strProvince = "&nbsp;";
	if(ProvinceID.length != 6)
	    return strProvince;
    for (i = 0;i < Province.length;i += 2)
    {
        if(Province[i] == ProvinceID)
        {
        	strProvince = Province[i+1]
        	break;
        }
    }
	return strProvince;
}
//取得市名====================
function getCityName(ProvinceID,CityID)
{
	var strCity = "&nbsp;";
	if(ProvinceID.length != 6 || (CityID.length != 9 && CityID.length != 12))
	    return strCity;
	if(CityID.length == 9)
	{
		for (i = 0;i < City[ProvinceID].length;i += 2)
		{
			if (City[ProvinceID][i] == CityID)
			{
				strCity = City[ProvinceID][i+1];
				break;
			}
		}	
	}	
	if(CityID.length == 12)
	{
		var CountyID = CityID;
		CityID = CityID.substr(0,9);
		for (i = 0;i < County[CityID].length;i += 2)
		{
			if (County[CityID][i] == CountyID)
			{
				strCity = County[CityID][i+1];
				break;
			}
		}
	}	
	return strCity;
}
//取得区域名=================
function getCounty(CityID,CountyID)
{
	var strCounty = "&nbsp;";
	if(CityID.length != 9 || CountyID.length != 12)
	    return strCounty;
	for (i = 0;i < County[CityID].length;i += 2)
	{
		if (County[CityID][i] == CountyID)
		{
			strCounty = County[CityID][i+1];
			break;
		}
	}
	return strCounty
}
//取得市名====================
function getCity(ProvinceID,CityID)
{
	var strCity = "&nbsp;";
	if(ProvinceID.length != 6 || CityID.length != 9)
	    return strCity;
	for (i = 0;i < City[ProvinceID].length;i += 2)
	{
		if (City[ProvinceID][i] == CityID)
		{
			strCity = City[ProvinceID][i+1];
			break;
		}
	}
	return strCity;
}
//取得区域名=================
function getCounty(CityID,CountyID)
{
	var strCounty = "&nbsp;";
	if(CityID.length != 9 || CountyID.length != 12)
	    return strCounty;
	for (i = 0;i < County[CityID].length;i += 2)
	{
		if (County[CityID][i] == CountyID)
		{
			strCounty = County[CityID][i+1];
			break;
		}
	}
	return strCounty
}

//===============================================================================
//取得控件的值
function getItemValue(itemName)
{
    return document.getElementById(itemName).value;
}

//===============================================================================

//更改itemName显示的信息为strValue
function setInnerHTML(itemName,strValue)
{
	document.getElementById(itemName).innerHTML = strValue;
}

//===============================================================================
//是否为空
function isNull(obj)
{
    if(getCharsLen(obj) == 0)
    {
        return true;
    }
    return false;
}

//===============================================================================
//数字检测
function isNumber(obj)
{
    if(obj.value.match(/^[0-9]+$/) == null)
        return false;
    else
        return true;
}
//===============================================================================
//取得text里面字符串的长度
function getCharsLen(obj)
{ 
    obj.value = obj.value.replace(/(^\s+)|(\s+$)/,'');
    var charsLen=0; 
    for (var i = 0; i< obj.value.length; i++) 
    {     
        if (obj.value.charCodeAt(i) > 127 || obj.value.charCodeAt(i) == 94) 
        { 
            charsLen=charsLen+2;   //中文加2
        } 
        else 
        { 
            charsLen=charsLen+1;  //英文加1
        }    
    }  //结束FOR循环  
    return (charsLen); 
} 

//===============================================================================
//判断是否为空并返回信息
function checkNull(obj,strName,strMsg)
{
    if(isNull(obj))
    {
        setInnerHTML(strName,strMsg);
        autoHeight('theFrame');
        return false;
    }
    else
    {
         setInnerHTML(strName,"");
        return true;
    }
}
//===============================================================================
//检查邮件地址的完整性
function isEmail(strValue)
{
    if(strValue.match(/^\w+([-+.]\w+)*@(\w+.)+\w{2,3}$/) == null)//
    return false;
    else
    return true;
}
//===============================================================================
//检查价格的完整性
function isPrice(strValue)
{
    if(strValue.match(/^\d+\.\d{2}$/) == null)//
    return false;
    else
    return true;
}
//===============================================================================
//检查是否长日期格式，即yyyy-mm-dd
function CheckDate(strDate)
{
    if(strDate.match(/^\d{4}-[0-1]\d-[0-3]\d$/) == null)
    return false;
    else
    return true;
}
//===============================================================================
//在对象名为strName的对象上进行一次点击操作
function actionOnClick(strFrameName,strName)
{
	//alert(strName);//
	setTimeout(top.eval(strFrameName).document.getElementById(strName).click(),1000);
	
}
//================================================================================
function jerqueName(obj)
{ 
    if (getCharsLen(obj) >= 4 && getCharsLen(obj) < 20 )
    {
        if(obj.value.match(/^[\u4E00-\u9FA5A-Za-z_]/g) != null)//以汉字，英文字母及下划线开头
        {
            if(obj.value.match(/[^\u4E00-\u9FA5\w]+/g) == null)//是否以中文字、英文字母、下划线及数字组成
            {
                return true;
            }
            else
            {
                strInfo = '<font color="#FF0000">名字要以中文字、英文字母、下划线及数字组成</font>';
                return strInfo;
            }
        }
        else
        {
           strInfo = '<font color="#FF0000">名字要以中文字、英文字母、下划线开头</font>';
           return strInfo;
        }
    }
    else
    {
        strInfo = '<font color="#FF0000">至少4个字符(2个汉字)最多20个字符(10个汉字)!</font>';
        return strInfo;
    }
}
//=================================================================================
//电话号码格式为"区号-电话号码(-分机号)"或11位电话号码
function jerquePhone(strPhone)
{ 
    if(strPhone.match(/(^\d+(-\d+){1,2}\d+$)|(^\d{11}$)/) == null)
        return false;
    else
        return true;
}
//=================================================================================
//判断Email地址是否正确并返回信息
function jerqueEmail(obj,strName)
{
    if(!isEmail(obj.value))
    {
        if(strName != "")setInnerHTML(strName,"<font style='color:red;'>邮件地址不正确</font>");
        autoHeight('theFrame');
        return false;
    }
    else
    {
        if(strName != "")setInnerHTML(strName,"");
        autoHeight('theFrame');
        return true;
    }
}
//=================================================================================
//判断价格是否全为数字并返回信息
function jerquePrice(obj,strName)
{
    if(!isPrice(obj.value))
    {
        if(strName != "")setInnerHTML(strName,"<font style='color:red;'>价格格式不正确</font>");
        autoHeight('theFrame');
        return false;
    }
    else
    {
        if(strName != "")setInnerHTML(strName,"");
        autoHeight('theFrame');
        return true;
    }
}

//====================================================================================
function checkLenght(obj,intLen)
{
    if(getCharsLen(obj) > intLen)
        return false;
    else
        return true;
}

//=====================================================================================
//改变表格背景色
function changeColor(obj,strColor)
{
	obj.style.background = strColor;
}
//=====================================================================================
//module:system
//action:addnewclass
//改变select里面的显示值,并更新数据库
function changeAtt(strSpanID,obj,objSelected)
{
	
	document.getElementById('spanshow').innerHTML = "处理中...";
	if(obj.value == "")//当text的值为空时,把记录删除
	{
		getinfo('spanshow','/system/index.php?module=System&action=ActModifyAtt&attributeID='+objSelected.value+'&attributeValue='+obj.value);
		objSelected.removeChild(objSelected.options[objSelected.selectedIndex]);
	}
	else
	{
		var intFlag = 0;
		for(var i = 0;i< objSelected.length;i++)//判断在同一个select里面是否有重复
		{
			if(objSelected.selectedIndex == i)//当为本option时跳过
			{
				continue;
			}
			else
			{
				if(obj.value == objSelected.options[i].text)
					intFlag = 1;
			}
		}
		if(intFlag == 0)//当没有重复时执行
		{
			getinfo('spanshow','/system/index.php?module=System&action=ActModifyAtt&attributeID='+objSelected.value+'&attributeValue='+obj.value);
			objSelected.options[objSelected.selectedIndex].text = obj.value;
		}
		else//有重复时显示警告
		{
			document.getElementById('spanshow').innerHTML = "<font style='color:#FF0000'>您输入的内容有重复!</font>";
		}
	}
	document.getElementById(strSpanID).innerHTML = "";
}
//=====================================================================================
//module:system
//action:addnewclass
//新增一个text,并在里面显示在select先中的元素(option)的text
function setTextValue(strSpanID,obj)
{
	//先清空所有text========================
	document.getElementById('span1').innerHTML ="";
	document.getElementById('span2').innerHTML ="";
	document.getElementById('span3').innerHTML ="";
	//======================================
	if(obj.selectedIndex != -1)//当select中有元素时执行
	{
		var strText = '<input name="textAtt" type="text" value="'+obj.options[obj.selectedIndex].text+'" size="5" onblur="changeAtt(\''+strSpanID+'\',this,document.getElementById(\''+obj.name+'\'))">';
		document.getElementById(strSpanID).innerHTML = strText;
	}
}
//=======================================================================================