
window.onunload = function()
{
	//window.alert("window.onunload " + event.srcElement + "\r\n" + event.keyCode);
}

window.onbeforeunload = function()
{
	//this.alert("window.onbeforeunload " + event.srcElement + "\r\n" + event.keyCode);
}


var statu=false;
function actMenu(num)
{
	var chmenu=	"child"+num;
	var child=document.getElementById(chmenu);
		if(statu==false)
		{
			child.style.display="block";
			statu=true;
		}
		else
		{
			child.style.display="none";
			statu=false;
		}
}
var selectedSta=false;
function setColor(obj,color)
{
	if(selectedSta!=false)
	{
		selectedSta.style.backgroundColor="";
		obj.style.backgroundColor=color;
		}
		obj.style.backgroundColor=color;
		selectedSta=obj;
	}

function openinframe(url)
{
	//window.open(url,'mainshow');		// have a wrong!!!
	window.parent.document.getElementsByName("mainshow")[0].src = url;
	//con.innerHTML='<iframe name="mainshow" frameborder="0" framespace="0" scrolling="scroll" src='+url+' style="height:expression(body.offsetHeight-132);width:100%;"></iframe>';
}

function openwin(url)
{
	window.open(url,"newopen","width=450px,height=500px,left=100px,top=80px,status=no,toolsbar=no,menubar=no,scrollbars=no")
}

function getMenu(url)
{
	menubar.location.href=url;
	
	//var s = url.indexOf("leftMenu") ;
	
	//if  ( s > 0 ){
	//	mainshow.location.href="indexpic.jsp";
	//}
}

//一些验证函数

//取得输入长度
function valcha(obj)
{
	var str=obj.value;
	var length=0;
	for(var i=0;i<str.length;i++)
	{
		var temp=str.charAt(i);
		if(/[^\x00-\xff]/g.test(temp))
		length+=2;
		else length++;
	}
	return length;
}
// check pwd 
function validatePwd(strObj) {
	
	if(!validateNotNull(strObj)){
		return false;
	}
	
	//regword = /^([A-Z]*|[a-z]*)+$/;
	//regdigital = /^(\d*)+$/;
	//regdigital = /^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\/]*)|.{0,5})$|\s/;
	//reg1 = /^(([A-Z]*|[a-z]*|\d*)$/;
	//reg2 = /^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\/]*)|.{0,5})$|\s/;
	//reg3 = /^(([A-Z]*|[a-z]*|\d*|[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\/]*)|.{0,5})$|\s/;

	if ( strObj.length < 6 ) {
	   return false;
	}
	
    var p1= (strObj.search(/[a-zA-Z]/)!=-1) ? true : false;
    var p2= (strObj.search(/[0-9]/)!=-1) ? true : false;
    var p3= (strObj.search(/[^A-Za-z0-9_]/)!=-1) ? true : false;
    var p4= (strObj.search(/[-_\~!@#\$%\^&\*\.\(\)\[\]\{\}<>\?\/]/)!=-1) ? true : false;
	
	if (  ( p1 == true  &&  p2 == true && p4 == true  )    ||
	       ( p1 == true  &&  p2 == true ) ||
	       ( p3 == true ) ||
	       ( p1 == true  &&  p4 == true ) ||
	       ( p2 == true  &&  p4 == true ) ||
	       ( p3 == true  &&  p4 == true ) 	
	 ){
	   return true;
	}
	else{
	   return false;
	}
	
   
	
	
}
//验证输入长度[长度对象与指定长度num比较]
function vallen(ol,num)
{
  if(ol<num)
  return true;
  else return false;
}
/*验证手机号(所有手机号)*/
function validateMobileTel(strObj) {
	if(!validateNotNull(strObj)){
		return true;
	}
	reg = /^(1)[0-9]{10}$/;
	return reg.test(strObj);
}

/*验证手机号或座机号(小灵通)*/
function validateTelOrMobileTel(strObj) {
	if(validateTel(strObj) != true) {
			if(validateMobileTel(strObj) == true) {
				return true;
			}else{
				return false;
		  }
	}else{
		return true;
	}
		return false;
}

/*验证座机号(小灵通)*/
function validateTel(strObj) {
	if(!validateNotNull(strObj)){
		return true;
	}
	reg = /^((0)[1-9][0-9]){0,1}(-){0,1}[1-9][0-9]{6,7}$/;
	return reg.test(strObj);
}

/*验证移动公司号码*/
function validateMobileCom(strObj) {
	if(!validateNotNull(strObj)){
		return true;
	}
	reg = /^(13)[4-9]{1}[0-9]{8}$/;
	return reg.test(strObj);
}

/*验证联通公司号码*/
function validateUniCom(strObj) {
	if(!validateNotNull(strObj)){
		return true;
	}
	reg = /^(13)[0-3]{1}[0-9]{8}$/;
	return reg.test(strObj);
}

/*验证是否数字(整数)*/
function validateIsInt(strObj) {
	if(!validateNotNull(strObj)){
		return true;
	}
	reg = /^[1-9][0-9]{0,}$/;
	return reg.test(strObj);
}

/*验证是否数字(小数)*/
function validateIsDecimal(strObj) {
	if(!validateNotNull(strObj)){
		return true;
	}
	reg = /^[1-9][0-9]{0,}((\.)[0-9]{0,}){0,1}$|^(0\.)[0-9]{0,}$/;
	return reg.test(strObj);
}

/*验证E-mail*/
function validateEmail(strObj) {
	if(!validateNotNull(strObj)){
		return true;
	}
	reg = /^[a-zA-Z0-9_]{1,}(\@)[a-zA-Z0-9_]{1,}(\.)[a-zA-Z0-9_]{1,}$/;
	return reg.test(strObj);
}

/*验证邮编*/
function validatePostalcode(strObj) {
	if(!validateNotNull(strObj)){
		return true;
	}
	reg = /^[1-9]{1}\d{5}$/;
	return reg.test(strObj);
}

/*验证身份证*/
function validateIDCard(strObj) {
	if(!validateNotNull(strObj)){
		return true;
	}
	reg = /^[1-9]{1}(\d{17}|\d{14})$/;
	return reg.test(strObj);
}

/*验证年,月,日 格式为 yyyy-MM-dd*/
function validateDate(strObj) {
	if(!validateNotNull(strObj)){
		return true;
	}
	reg = /^[1-2]\d{3}-((0)[1-9]|(1)[0-2])-([0-2]\d|(3)[0-1])$/;
	return reg.test(strObj);
}

/*验证年,月 格式为 yyyy-MM*/
function validateYearMonth(strObj) {
	if(!validateNotNull(strObj)){
		return true;
	}
	reg = /^[1-2]\d{3}-((0)[1-9]|(1)[0-2])$/;
	return reg.test(strObj);
}

/*验证年格式为 yyyy*/
function validateYear(strObj) {
	if(!validateNotNull(strObj)){
		return true;
	}
	reg = /^[1-2]\d{3}/;
	return reg.test(strObj);
}

/*验证必须输入的内容,不能有前后空格,不能有回车符,制表符,换页符*/
function validateNotNull(strObj) {
	strObj = strObj.replace(/(^\s*)|(\s*$)/g, "");
	if(strObj.length > 0){
		return true;
	}else{
		return false;
	}
}

/*验证路径和文件名是否正确*/
function validateFile(strObj) {
	if(!validateNotNull(strObj)){
		return true;
	}
	reg = /[^\\\/\*\?\"\<\>\|]{1,}(\\)[^\\\/\:\*\?\"\<\>\|]{1,}(\.)[^\\\/\:\*\?\"\<\>\|]{1,}/;
	return reg.test(strObj);
}

/**控件内容不能为空
 *@param control 控件对象
 *@param controlShowName显示的名字
 *@retun boolean
 */
function controlNotNull(control, controlShowName)
{
	if(control.type == "select-one") {
		if(!validateNotNull(control.options[control.options.selectedIndex].value)) {
			alert("请选择" + controlShowName + "!");
			control.focus();
			return false;
		}
	}else{
		control.value = control.value.replace(/(^\s*)|(\s*$)/g, "");
		if(!validateNotNull(control.value)) {
			alert(controlShowName + "不能为空!");
			if(control.type != "hidden") {
				control.focus();
			}
			return false;
		}
	}
	return true;
}

/**select控件内容要必须选择
 *@param control 控件对象
 *@param controlShowName显示的名字
 *@param maxLength 控件最大长度
 *@retun boolean
 */
function controlLength(control, controlShowName, maxLength) {
	control.value = control.value.replace(/(^\s*)|(\s*$)/g, "");
	if(valcha(control) > maxLength) {
		alert(controlShowName + "不能大于" + maxLength + "个字符!");
		if(control.type != "hidden") {
				control.focus();
		}
		return false;
	}
	return true;
}

/**控件内容是否为时间
 *@param control 控件对象
 *@param controlShowName显示的名字
 *@retun boolean
 */
function controlDate(control, controlShowName) {
	control.value = control.value.replace(/(^\s*)|(\s*$)/g, "");
	if(!validateDate(control.value)) {
		alert(controlShowName + "格式不对,正确格式为yyyy-mm-dd!");
		if(control.type != "hidden") {
				control.focus();
		}
		return false;
	}
	return true;
}

/**控件内容是否为时间(年,月)
 *@param control 控件对象
 *@param controlShowName显示的名字
 *@param maxLength 控件最大长度
 *@retun boolean
 */
function controlYearMonth(control, controlShowName) {
	control.value = control.value.replace(/(^\s*)|(\s*$)/g, "");
	if(!validateYearMonth(control.value)) {
		alert(controlShowName + "格式不对,正确格式为yyyy-mm!");
		if(control.type != "hidden") {
				control.focus();
		}
		return false;
	}
	return true;
}

/**控件内容是否为整数
 *@param control 控件对象
 *@param controlShowName显示的名字
 *@retun boolean
 */
function controlIsInt(control, controlShowName) {
	control.value = control.value.replace(/(^\s*)|(\s*$)/g, "");
	if(!validateIsInt(control.value)) {
		alert(controlShowName + "只能输入整数!");
		if(control.type != "hidden") {
				control.focus();
		}
		return false;
	}
	return true;
}

/**控件内容是否为小数
 *@param control 控件对象
 *@param controlShowName显示的名字
 *@retun boolean
 */
function controlIsDecimal(control, controlShowName) {
	control.value = control.value.replace(/(^\s*)|(\s*$)/g, "");
	if(!validateIsDecimal(control.value)) {
		alert(controlShowName + "只能输入整数或小数!");
		if(control.type != "hidden") {
				control.focus();
		}
		return false;
	}
	return true;
}

/**控件内容是否为电话号码
 *@param control 控件对象
 *@param controlShowName显示的名字
 *@retun boolean
 */
function controlTelOrMobileTel(control, controlShowName) {
	control.value = control.value.replace(/(^\s*)|(\s*$)/g, "");
	if(!validateTelOrMobileTel(control.value)) {
		alert(controlShowName + "只能输入电话号码!");
		if(control.type != "hidden") {
				control.focus();
		}
		return false;
	}
	return true;
}

/**控件内容是否为手机号码
 *@param control 控件对象
 *@param controlShowName显示的名字
 *@retun boolean
 */
function controlMobileTel(control, controlShowName) {
	control.value = control.value.replace(/(^\s*)|(\s*$)/g, "");
	if(!validateMobileTel(control.value)) {
		alert(controlShowName + "只能输入手机号码!");
		if(control.type != "hidden") {
				control.focus();
		}
		return false;
	}
	return true;
}


/**控件内容是否为文件
 *@param control 控件对象
 *@param controlShowName显示的名字
 *@retun boolean
 */
function controlFile(control, controlShowName) {
	control.value = control.value.replace(/(^\s*)|(\s*$)/g, "");
	if(!validateFile(control.value)) {
		alert("您输入的 " + controlShowName + " 的文件路径或文件名称不正确!");
		if(control.type != "hidden") {
				control.focus();
		}
		return false;
	}
	return true;
}

/**
 *@param url_ 用户传过来的链接
 */
function getReqData(url_, div_) {
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
    	http_request.overrideMimeType('text/xml');
    }
	} else if (window.ActiveXObject) { // IE
	  try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}

	if (!http_request) {
    alert("http_request 对象为空!");
    return false;
  }
	http_request.onreadystatechange = function() {
		if (http_request.readyState == 2) {
			// 正在装载
		}else if (http_request.readyState == 4) {
	    // 完成
	    if (http_request.status == 200) {
	    	//return http_request.responseText;
//                    alert(http_request.responseText);
				div_.innerHTML = http_request.responseText;
                                //alert(http_request.responseText);
			} else {
				alert("返回值错误!");
			}
		} else {
		   // still not ready
		}
	};
	http_request.open('GET', url_, true);
	http_request.send();
}

function returnReqValue(url_) {
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    http_request = new XMLHttpRequest();
    if (http_request.overrideMimeType) {
    	http_request.overrideMimeType('text/xml');
    }
	} else if (window.ActiveXObject) { // IE
	  try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	http_request.open("GET", url_, false);
	http_request.send();
	return http_request.responseText;
}

/*
function() {
		if (http_request.readyState == 2) {
			// 正在装载
		}else if (http_request.readyState == 4) {
	    // 完成
	    if (http_request.status == 200) {
	    	//return http_request.responseText;
				//div_.innerHTML = http_request.responseText;
			} else {
				alert("返回值错误!");
			}
		} else {
		   // still not ready
		}
	};
*/

/*
if (http_request.readyState == 2) {
		// 正在装载
	}else if (http_request.readyState == 4) {
    // 完成
    if (http_request.status == 200) {
    	//div_.innerHTML = http_request.responseText;
    	return http_request.responseText;
		} else {
			alert("返回值错误!");
		}
	} else {
	   // still not ready
	}
*/


//点击按钮后生成一个页标签按钮
//tabname页标签的文本 taburl点击后加载的地址 
  //onClick="tabs_add('第三个页','tab3.html')"
function tabs_add(tabname,taburl){
//window.parent.list2_S('h');//如果三级菜单存在 关闭
//tabhtml=parent.document.getElementById("tabs").innerHTML;//获得div里的html
//if(tabhtml.indexOf(taburl)!=-1){//tbs里的html已经存在当前url
//alert('当前页标签已存在。');//提示
//parent.frames["main_frame"].document.location.href=taburl;
//}else{
//var tabid="id"+Math.round(Math.random()*10000);//产生一个随机id
//if(tabhtml.indexOf(tabid)!=-1){//如果id号已存在
//tabid="id"+Math.round(Math.random()*100000);//再生成一次
//}
//newtab="<span><div class='button2'  onmouseover=showdiv('"+tabid+"') onmouseout=hidden('"+tabid+"');><H4><div class='parent_url' id='"+tabid+"' style='display:none;width:auto'>"+document.getElementById("parent_url").value+"</div></H4><H1></H1><H2><a href=\"javascript:void(null)\" onClick='main_frame.location.href=\""+taburl+"\";window.parent.list2_S(\"h\");'><input type='button'value='"+tabname+"'/><input id='tab_url' value="+taburl+" type=hidden></a>&nbsp;<a href='javascript:void(null)' onClick=\"tab_remove(this.parentNode.parentNode.parentNode.innerHTML);\"><img src=\"../view/images/icons/tab_close.gif\" align='absmiddle' border=0/></a></H2><H3></H3></div></span>";//兼容IE和FF 前后要加span
//parent.document.getElementById("tabs").innerHTML=tabhtml+newtab;
parent.frames["main_frame"].document.location.href=taburl;//js跳转
//}
};
//****注：IE和FF在父窗口调用iframe里的对象有差异，为了兼容火狐，清除tab按钮的js加在index.js里。

/**
 * 
 * @param _id
 * @param _handler
 * @return
 * @author dragon
 */
function id(_id, _handler)
{
	// 
	if ( this.id.arguments.length == 0 ) return /*null*/;
	
	//return document.all._id;
	if ( id.arguments.length == 1 || window.id.arguments[1] == null || this.id.arguments[1] == undefined || typeof arguments[1] != "object" )
		return document.getElementById(_id);
	else // hehe
		return id.arguments[1].getElementById(_id);
}

/**
 * 
 * @param _name
 * @return
 * @author dragon
 */
function name(_name)
{
	return names(_name)[0];
}

/**
 * 封装的函数，也可以直接用引用的形(方)式
 * @param _names
 * @return
 * @author dragon
 */
/*function names(_names)
{
	return document.getElementsByName(_names);
}*/
names = document.getElementsByName; // 直接引用的方式、取个别名(synonyms(oracle))。也可以直接用封装的形式。

/**
 * 
 * @param _name
 * @return
 * @author dragon
 */
function tagName(_name)
{
	return document.getElementsByTagName(_name)[0]; // this.tagNames(_name)[0]
}

/**
 * 
 * @param _names
 * @param _handle
 * @return
 * @author dragon
 */
function tagNames( _names, _handle )
{
	if ( _handle == undefined )
		return document.getElementsByTagName(_names);
	else 
		return _handle.getElementsByTagName(_names);
}

/**
 * current page form
 * @return
 * @author dragon
 */
function form()
{
	var frms;
	
	frms = this.forms(this.form.arguments.length > 0 ? window.form.arguments[0] : null);
	
	if ( frms.length == 0 )
		return null;
	
	return frms[0];
}

/**
 * 
 * @param _handler
 * @return
 * @author dragon
 */
function forms( _handler )
{
	if ( _handler != undefined && _handler != null /*&& typeof _handler == "object" */)
		return _handler.forms;
	return this.document.forms; // tagNames("form")
}

/**
 * 
 * @param _id
 * @return
 * @author dragon
 */
function clean(_id)
{
	id(_id).value = "";
}

/**
 * 
 * @param _handler
 * @return
 * @author dragon
 */
function hide(_handler)
{
	if ( typeof _handler == "object" )
		_handler.style.display = "none";
	else 
		id(_handler).style.display = 'none';
}

/**
 * 
 * @param _handler
 * @param left
 * @param top
 * @return
 * @author dragon
 */
function show( _handler, left, top )
{
	if ( typeof _handler == "object" )
		_handler.style.display = "inline";
	else 
	{
		var __handler = id(_handler);
		if ( left != undefined )
			__handler.style.left = left;
		if ( top != undefined )
			__handler.style.top = top;
		
		id(_handler).style.display = 'inline';
	}
}

/**
 * 
 * @param _sender
 * @return
 * @author dragon
 */
function $disable(_sender) // disable动词，disabled名词，呵呵。
{
	if ( 
			arguments.length == 0 
			|| 
			arguments[0] == null
			)
	{
		return;
	}
	
	if ( typeof arguments[0] == "object" && arguments[0].length ) // 数组
	{
		for (var i = arguments[0].length - 1; i > -1; arguments[0][i--].disabled = true);
	}
	else if ( typeof arguments[0] == "object" ) // 对象
	{
		arguments[0].disabled = true;
	}
	else if ( typeof arguments[0] == "string" ) // 字符串（对象的ID或者是名称？）
	{
	}
}

/**
 * 
 * @param _sender
 * @return
 * @author dragon
 */
function $enable(_sender) // enable动词，enabled名词，呵呵。
{
	if ( 
			! arguments.length 
			|| 
			arguments[0] == null
			)
	{
		return ;
	}
	
	if ( typeof arguments[0] == "object" && arguments[0].length ) // 数组
	{
		for (var i = arguments[0].length - 1; i > -1; arguments[0][i--].removeAttribute("disabled"));
	}
	else if ( typeof arguments[0] == "object" ) // 对象
	{
		arguments[0].removeAttribute("disabled");
	}
	else if ( typeof arguments[0] == "string" ) // 字符串（对象的ID或者是名称？）
	{
	}
}

/**
 * 
 * @param _url
 * @param _id
 * @param _idval
 * @param _status
 * @param _statusval
 * @return  
 */
function EnableOrDisable(_url, _id, _idval, _status, _statusval)
{
	id(_id).value = _idval;
	if ( arguments.length > 4 && _status != null )
		id(_status).value = _statusval;
	if ( _statusval == suspend ){
		if (!window.confirm(confirmSuspend.replace("{0}", "(" + id('chk_' + _idval).parentNode.parentNode.childNodes[1].innerText + ")")) ) // are you sure ?
			return;
	}else{
		if (!window.confirm(confirmActive.replace("{0}", "(" + id('chk_' + _idval).parentNode.parentNode.childNodes[1].innerText + ")")) ) // are you sure ?
			return;
	}
	var _statusActive = arguments.length > 5 ? arguments[5] : statusNormal, _statusSuspend = arguments.length > 6 ? arguments[6] : statusForbidden;
	ajax(
			_url + "?" + _id + "=" + _idval + "&" + _status + "=" + _statusval, 
			
			function(data, textStatus)
			{
				id('lbl_' + _idval).innerText = _statusval == active ? _statusActive : _statusSuspend;//statusNormal : statusForbidden;
				id('a_' + _idval).innerText = _statusval == active ? statusSuspend : statusActive;
				id('a_' + _idval).tag = _statusval == active ? suspend : active;
			}
			);
}

/**
 * 
 * @param _url
 * @param _callback
 * @return
 * @author dragon
 */
function ajax( _url, _callback )
{
	$.ajax({
		type: "get", 
		url: _url, 
		dataType:"text", 
		//contentType:"application/json", 
		beforeSend: function(XMLHttpRequest){
			XMLHttpRequest.setRequestHeader("If-Modified-Since", "0");
			XMLHttpRequest.setRequestHeader("Cache-Control", "no-cache");
		},
		success: _callback
		,
		/*success: function(data, textStatus){
			alert('successfully!~~');
		},*/
		complete: function(XMLHttpRequest, textStatus){
			//HideLoading();
		},
		error: function(){
			//请求出错处理
		}
	});
}

/**
 * 
 * @param select
 * @param value
 * @param text
 * @param selected
 * @return
 * @author dragon
 */
function addOptionToSelect(select, value, text, selected)
{
	var opt = document.createElement("option");
	select.options.add(opt);
	opt.value = value;
	opt.innerText = text;
	opt.selected = selected;
}

/**
 * 
 * @param _handler
 * @return
 * @author dragon (2011/03/11 16:18:11)
 */
function getValue( _handler )
{
	if ( _handler == undefined ) // this.getValue.arguments.length == 0
		return null;
	
	var value = "";
	//alert('_handler.tagName::->' + _handler.tagName + '\n_handler.type::->' + _handler.type);
	
	if ( _handler.tagName == "SELECT" || _handler.type == "select-one" )
	{
		//alert('_handler.selectedIndex::->' + _handler.selectedIndex + '\n_handler.options.length::->' + _handler.options.length);
		if ( _handler.selectedIndex != -1 && _handler.options.length != 0 ) // ?.length > 0
			value = _handler.options[_handler.selectedIndex].value;
		//alert('value::->' + value);
	}
	else if ( _handler.tagName == "INPUT" || _handler.type == "radio" )
	{
		var es = names( _handler.name );
		for (var i = es.length - 1; i > -1; value = es[i].checked ? es[i].value : value, i--);
	}
	else if ( typeof _handler == "string" ) // 其它的情况根据名称取
	{
		var __handler = name( _handler ); // 根据名称取得其组(component)（控(control)）件的句柄
		
		if ( __handler.tagName == "INPUT" && __handler.type == "checkbox" ) // 多选框
		{
			__handler = names( _handler );
			
			if ( getValue.arguments.length > 1 && getValue.arguments[1] ) // isChoice ?
			{
				for (var i = __handler.length; i > 0; value += __handler[--i].checked ? (__handler[i].value + ',') : "");
				if ( value.length > 0 )
					value = value.substring(0, value.length - 1);
			}
			else // 取所有的多选框的值
			{
				for (var i = 0; i < __handler.length; value += __handler[i++].value + ',');
				value = value.substring(0, value.length - 1);
			}
		}
	}
	
	return value;
}

/**
 * 
 * @author dragon
 */
if ( document.addEventListener )
{
	//document.addEventListener("DOMContentLoaded", init, false);
}
// for Internet Explorer (using conditional comments)
/*@cc_on @*/
/*@if (@_win32)
document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
  if (this.readyState == "complete") {
    init(); // call the onload handler // 会比直接写在页面的后面慢一点点，但是是事件中的比较快的了
  }
};
/*@end @*/
//window.onload = init; // function() // window.onload事件都慢了
/**
 * 
 * @return
 * @author dragon
 */
function init()
{
	
	initial_Details();
	
	try
	{
		this.initialization();
	}
	catch ( errMsg )
	{
		//alert('errMsg::->' + errMsg);
		//alert(errMsg.message);
		/*alert(errMsg.description);
		alert(errMsg.number);
		alert(errMsg.name);*/
		//throw new Error(10, "这是将要显示的错误说明");
	}

	initial_Tabs();

	window.search_init(window.name('searchState'));
		/**
	 * form提交时，显示ajax等待信息。
	 */
	var _form = form();
	if ( _form ){
		_form.onsubmit = function()
		{
			if(flag){
					window.parent.setLoading(true,"正在处理数据..."); 
				}else{
					setLoading(true,"正在处理数据..."); 
				}
		}
	}
	intocolor();
	document.onmousedown = OnDocumentClick;
}
/**
 * form submit 时所需判断的值。
 */
var flag = true;

/**
 * window.location.href = url;
 * @param url
 * @return
 * @author dragon
 */
function href(url) // 和直接href的区别是需要结尾的括号，呵呵。可有时却需要这种样子的结构
{
	if ( href.arguments.length == 1 )
		javascript:window.location.href = url;
	else 
		arguments[1].location.href = url;
}
	 
function setLoading(_display ,_text){
	 var m = id("overlay");
	 var e = id("loading");
	 if(e==null){
		  e = document.createElement("div");
		  e.id="loading";
		  e.className="loading";
		  document.body.appendChild(e);
		  
		  m = document.createElement("div");
		  m.id="overlay";
		  document.body.appendChild(m);
	  }
	  if(e!=null && m!=null){
	  	 m.style.display = _display ? "block":"none";
		 e.style.display = _display ? "block":"none";
		 e.innerHTML  = (_text==null)? 'Loading ......':_text;
		 if(flag){
			 e.style.left = (window.screen.width) * 0.4 ;
			 e.style.top  = (window.screen.height) * 0.4 ;
		 }else{
			 e.style.left = (document.body.scrollWidth) * 0.4 ;
			 e.style.top  = (document.body.scrollHeight) * 0.4 ;
		 }
		 m.style.height = document.body.clientHeight;
		 m.style.width = document.body.clientWidth;
	  }
	
}

/**
 * 
 * @param url
 * @return
 * @author dragon
 */
function form_submit(url)
{
	var frm;
	
	if ( form_submit.arguments.length == 0 ) return;
	
	if ( this.document.forms.length == 0 ) return;
	
	frm = /*window*/this.form_submit.arguments.length > 2 ? window.form_submit.arguments[2] : form(); // forms()[0]
	
	var oldAction = frm.action;
	
	frm.action = url;
	frm.method = arguments.length >= 2 && arguments[1] != null && arguments[1] != undefined && typeof arguments[1] == "string" ? arguments[1] : "post";
	window.parent.setLoading(true,"正在处理数据..."); 
	frm.submit();
	frm.action = oldAction; // 还原form的action（用的struts2的form标签的话，它自己还会检查是否存在，呵呵。）是吗？
}

/**
 * 
 * @return
 * @author dragon
 */
function formSubmit() // submitForm
{
	if ( this.forms().length == 0 )
	{
		return;
	}
	
	this.form_submit(this.form().action);
}

/**
 * 
 * @return
 * @author dragon
 */
function initialization()
{
	/*// 获取当前页面的当前form表单的submit按钮。
	var inputes = tagNames('input', this.form());
	for (var i = inputes.length - 1; i > -1; i--)
	{
		/*if ( inputes[i].type == "submit" && inputes[i].isSubmit != undefined ) // info页面的默认按钮
		{
			this.sbmtBtn = inputes[i]; // 也可以用window，this只表示是当前对象，当前函数是（window）下的时，this也就相当是window
			break;
		}* /
		if ( inputes[i].type == "submit" && inputes[i].onclick.toString().indexOf('search(') != -1 ) // 是否需要加上click的主体来组合判断？（是的需要）不能以引用方式判断
		{
			this.sbmtBtn = inputes[i]; // 也可以用window，this只表示是当前对象，当前函数是（window）下的时，this也就相当是window
			break;
		}
	}*/
	//var buttones = tagNames('button', this.form()); // 先只需要在input中查找就可以了。
	
	
	// 设置是否有a链接时的样式
	var aes = document.getElementsByTagName("a");
	
	for ( var i = aes.length - 1; i > -1; i--)
	{
		if ( !aes[i].href )
		{
			aes[i].style['color'] = '#666';
		}
	}
	
	// 光标停留在空白的文本框上。
	var elementes = this.form().elements;
	for (var i = 0; i < elementes.length; i++)
	{
//		alert(elementes[i] + '\n' + elementes[i].tagName + '\n' + elementes[i].type + '\n' + elementes[i].value);

		//if ( readOnlyForm == 1 ) // 禁用form的所有组件（控件）（这种写法和另外搞个迭代（循环），那样就可以不用每次都判断是否等于1，是差不多的）
		if ( 
				elementes[i].tagName == "INPUT" && elementes[i].type == "button" 
				&& 
				elementes[i].value == "关闭" // 后加  只属于关闭的按钮才不禁用。
					) // 只是为button（少数组件（控件））服务,还要写个判断
			continue;
		{
			elementes[i].readOnly = this.readOnlyForm; // why select or anOther can't
			elementes[i].disabled = this.readOnlyForm;
		}
		
		if ( 
				!this.readOnlyForm 
				&&
				(
					( // input 里面的几种
						elementes[i].tagName == "INPUT"
						&&
						(
							elementes[i].type == "text"
							||
							elementes[i].type == "radio"
							||
							elementes[i].type == "checkbox"
						)
					)
					/*||
					elementes[i].tagName == "SELECT"*/ 
					/*|| 
					elementes[i].tagName == "TEXTAREA"*/
				)/*
				&&
				elementes[i].value == ""*/
				)
		{
			//alert('here::->' + elementes[i] + '\n' + elementes[i].tagName + '\n' + elementes[i].type + '\n' + elementes[i].value);
			elementes[i].focus();
			break;
		}
	}
	// 为什么这里后面就还不能执行了呢？（有待解决）
}

/**
 * 
 * @return
 * @author dragon
 */
function initial_Details()
{
	// add style to the table
	var table = document.all.details;
	
	if ( !table ) return;
	
	for ( var i = table.rows.length - 1; i > -1; i--)
	{
		if ( table.rows[i].cells.length < 2 )	continue;
		
		for ( var j = table.rows[i].cells.length - 1; j > -1; j--)
		{
			table.rows[i].cells[j].className = !(j % 2) ? "text_right" : "text_left";
			table.rows[i].cells[j].style.width = !(j % 2) ? "10%" : "30%";
//			table.rows[i].cells[j].width = !(j % 2) ? "10%" : "30%";
		}
	}
}

/**
 * 
 * @return
 * @author dragon
 */
function initial_Tabs()
{
	// tab is current
	var tabs = document.all.tabs;
	
	if ( !tabs ) return;
	
	for ( var i = tabs.childNodes.length - 1; i > -1; i--)
	{
		if ( tabs.childNodes[i].tagName == "div" || tabs.childNodes[i].tagName == "DIV" )
		{
			if ( window.document.title == tabs.childNodes[i].childNodes[1].childNodes[0].innerHTML )
			{
				tabs.childNodes[i].className = "button3"; // 高亮显示
			}
			
			// 是否禁用（启用）所有的文字和链接。
			if ( this.enable )
			{
				//alert(this.enable+'-----------------');
				//if ( i == 0 && !tabs.childNodes[i].childNodes[1].childNodes[0].enabled ) // 列表的tab项始终可以选择。添加了一个例外项(enabled)属性，也只会在最后一个tab上出现和进行判断（栏目的例外，现不需要）
				if ( tabs.childNodes[i].childNodes[1].childNodes[0].notEnable != undefined ) // 启动例外项
					continue;
				
				//tabs.childNodes[i].disabled = this.disable;
				//tabs.childNodes[i].childNodes[1].childNodes[0].disabled = this.disable;
				//tabs.childNodes[i].childNodes[1].childNodes[0].href = "javascript:void(0);";
				
				//为了调节产品资源中的图片信息和视频详细信息添加的一段js 判断
				if(tabs.childNodes[i].childNodes[1].childNodes[0].exception != null 
					&& tabs.childNodes[i].childNodes[1].childNodes[0].exception == "toAdd" )
				{
				   	//alert('除掉不符合的');
					continue;
				}
				//alert('进入测试');
				tabs.childNodes[i].childNodes[1].childNodes[0].removeAttribute("disabled");
				tabs.childNodes[i].childNodes[1].childNodes[0].href = tabs.childNodes[i].childNodes[1].childNodes[0].charset;//tag; // 随便搞个属性都行，呵呵。
				
				continue;
			}
			
			// 例外项（第一个选项卡 或者 是标签的“exception”属性的值为"1" 的情况）
			if ( i == 0 || tabs.childNodes[i].childNodes[1].childNodes[0].exception == 1)
			{
				tabs.childNodes[i].childNodes[1].childNodes[0].removeAttribute("disabled");
				tabs.childNodes[i].childNodes[1].childNodes[0].href = tabs.childNodes[i].childNodes[1].childNodes[0].charset;//tag;
				continue; // break 也可以  因为到 “0” 了。
			}
			
		}
	}
}

/**
 * 全局变量区（开始）
 */
var sbmtBtn = null;
/**
 * 全局变量区（结束）
 */

/**
 * 
 * @param categoryId
 * @param categoryName
 * @param operatedObjType
 * @param operatorObjType
 * @return
 * @author dragon
 */
function dataRightes(categoryId, categoryName, operatedObjType, operatorObjType)
{
	var url = "";
	
	url += "../publisher/part_list.do";
	url += "?categoryId=" + categoryId;
	url += "&categoryName=" + categoryName;
	url += "&datarightsFrom.operatedObjType=" + operatedObjType;
	url += "&datarightsFrom.operatorObjType=" + operatorObjType;
	url += "&clear_ObjName=true";//Constants.STRING_TRUE
	
	this.ShowModalDialog(url);
	//window.open(url);
	//window.location.href = url;

	//window.refresh(window); // 刷新页面。
	form_submit(document.forms[0].action); // location.href
}

/**
 * 
 * @param _url
 * @param sFeatures
 * @return
 * @author dragon
 */
function ShowModalDialog( _url, sFeatures ) // 区分大小写。
{
	return window.showModalDialog
		(
			_url, 
			this, 
			arguments.length == 1 || sFeatures == undefined || sFeatures == null || sFeatures == '' ? 
				'scroll=1;status=0;help=0;resizable=0;dialogWidth=820px;dialogHeight=500px' : 
					sFeatures
		)
		;
}

/**
 * 
 * @param _url
 * @param sFeatures
 * @return
 * @author dragon
 */
function details( _url, sFeatures )
{
	_url += "&isDetails=true&tabsType=";
	if ( sFeatures == undefined )
		sFeatures = 'scroll=1;status=0;help=0;resizable=0;dialogWidth=860px;dialogHeight=660px';
	return ShowModalDialog( _url, sFeatures );
}

/**
 * 
 * @param _url
 * @param sFeatures
 * @return
 * @author dragon
 */
function ShowModalDialogAndReLoad( _url, sFeatures )
{
	var retVal = this.ShowModalDialog( _url, sFeatures );
	
	//alert(retVal);
	
	// reload
	this.reload(/**/);
	
	return retVal;
}

/**
 * refresh
 * @return
 * @author dragon
 */
function refresh()
{
	if ( window.refresh.arguments.length >= 2 )
		this.refresh.arguments[0].location.href = arguments[1];
	else if ( this.refresh.arguments.length > 0 )
		this.refresh.arguments[0].location.reload();
	else 
		window.location.reload();
}

/**
 * 
 * @param _sender
 * @return
 * @author dragon
 */
function reload( _sender )
{
	if ( _sender != undefined )
		_sender.reload();
	else 
		window.location.reload(/**/);
}

/**
 * 
 * @return
 * @author dragon
 */
function checkForm()
{
	// 动态遍历form里面的元素
	
	return true;
}

/**
 * 
 * @param url
 * @return
 * @author dragon
 */
function add(url)
{
	href(url);
	
	//tabs_add(common_title_add, "*_toAdd.do");
}

/**
 * 
 * @param _url
 * @return
 * @author dragon
 */
function $AddOrModify(_url)
{
	/*if ( !checkForm() ) // chkFrm
	{
		return;
	}*/
	
	document.forms[0].action = _url;
	//form_submit(_url);
}

/**
 * 
 * @param _ides
 * @param _ids
 * @param _url
 * @return
 * @author dragon
 */
function remove(_ides, _ids, _url) // 可以写成Array数组对多个组件进行赋值。
{
	var id = " "; // 默认一个空格可避免后面的那个判断，呵呵。
	
	if ( typeof _ides == 'string' )
	{
		var eles = this.names(_ides), names = '';
		var chkCount = 0;
		
		//for (var i = 0; i < eles.length; chkCount += eles[i].checked ? 1 : 0, id = eles[i++].value);
		for (var i = 0; i < eles.length; i++)
		{
			if ( eles[i].checked )
			{
				chkCount++;
				id += eles[i].value + ",";
				//names += eles[i].parentNode.parentNode.childNodes[1].innerText + ',';
				// 又是动态取得对象的名字？（得全部统一这些格式的来）
				if ( 
						arguments.length == 4 
						&& 
						arguments[3] == 'thumbnail'
						) // 在系统系统上的缩略图的布局格式。
					names += eles[i].parentNode.parentNode.previousSibling.childNodes[0].childNodes[0].innerText + ',';
				else if ( 
						arguments.length == 4 
						&& 
						arguments[3] == 'thumbnailList'
						) // 在系统系统上的缩略图的列表的布局格式。
					names += eles[i].parentNode.nextSibling.nextSibling.childNodes[0].innerText + ',';
				else if ( 
						eles[i].parentNode != null 
						&& 
						eles[i].parentNode.parentNode != null 
						&& 
						eles[i].parentNode.parentNode.childNodes[1] != null 
						&& 
						eles[i].parentNode.parentNode.childNodes[1].innerText != null 
						) // 在这个系统上的列表表格布局格式。
					names += eles[i].parentNode.parentNode.childNodes[1].innerText + ',';
			}
		}
//		id = id.substring(0, id.length - 1);
//		names = names.length > 0 ? names.substring(0, names.length - 1) : names; // 也可以躲在 if ( chkCount == 0 ) 后面就不用判断了，呵呵。
		
		if ( chkCount == 0 )
		{
			window.alert(noneChoose);
			return false;
		}
		
		/*if ( chkCount > 1 ) // 是否支持同时删除多个
		{
			window.alert(chooseOnlyOne);
			return;
		}*/
		
		id = id.substring(1, id.length - 1);
		names = names.substring(0, names.length - 1);
		
		// 是否确认删除×××
		if ( !window.confirm(confirmRemove.replace("{0}", "(" + names + ")")) )
		{
			return false;
		}
	}
	else if ( typeof _ides == 'number' )
	{
		id = _ides;
	}
	
	//document.form1.action = "advert_remove.do?id=" + id;

	resetPageIndex(); // 重置分页page的索引
	
	this.id(_ids).value = id;

	form_submit(_url);
	
	return false;
}

/**
 * 
 * @param _url
 * @return
 * @author dragon
 */
function removeAll(_url)
{
	if ( !window.confirm(confirmRemoveAll) )
	{
		return;
	}

	form_submit(_url);	
}

/**
 * 
 * @param _id
 * @param _val
 * @param _url
 * @return
 * @author dragon
 */
function modify(_id, _val, _url)
{
	id(_id).value = this.modify.arguments[1];
	
	form_submit(_url);
}

/**
 * 
 * @param _name
 * @param _url
 * @return
 * @author dragon
 */
function choiceValue( _name, _url )
{
	var value = this.ShowModalDialog(_url);
	
	if( undefined == value )
	{
		return;
	}
	
	value = value.split(",");
	var oldValue = id(_name).value, newValue = ''; // 多定义几个变量性能会好点，呵呵。不过小数据不大影响，也可以总共一个变量搞定
	for (var i = value.length - 1; i > -1; i--)
	{
//		alert("oldValue::->" + oldValue + "\n" + "value[" + i + "]::->" + value[i] + "\n" + oldValue.indexOf(value[i]));
		if ( oldValue.indexOf(value[i]) == -1 )
		{
			newValue += "," + value[i];
		}
	}
	if ( oldValue == '' && newValue != '' ) newValue = newValue.substring(1, newValue.length);
	
	id(_name).value = oldValue + newValue;
}

/**
 * 
 * @param _ides
 * @return
 * @author dragon
 */
function getSelectedCheckBoxesValue( _ides )
{
	var es = names( _ides );
	var str = '';
	
	for (var i = es.length - 1; i > -1; i--)
	{
		if ( es[i].checked )
		{
			str += es[i].value + ",";
		}
	}
	
	if ( str.length > 0 )
		str = str.substring(0, str.length - 1);
	
	return str;
}

/**
 * 
 * @param file
 * @return
 * @author dragon
 */
function removeFileUploadValue( file )
{
	var _file = file.cloneNode(false);
//	_file.onchange= file.onchange;// events are not cloned 
	file.parentNode.replaceChild(_file, file);
}

/**
 * 
 * @param _url
 * @return
 * @author dragon
 */
function search(_url)
{
//	alert('search');
	resetPageIndex();
	
	form().action = (_url);
	//form_submit(_url);
}

/**
 * 
 * @return
 * @author dragon
 */
function resetPageIndex()
{
	// 要清空分页的数据，重新从第一页开始。
	//alert('here::->' + id('page'));
	if ( (page = id('page')) != null )
		page.selectedIndex = 0;
}

/*format("a{0}b", new Array(1, 2, 3));
function format(srcStr, args)
{
	alert(srcStr + "\n" + (typeof args) + "\n" + args.length);
	
	var match = srcStr.match("");
}*/

/**
 * 
 * @param _searchState
 * @return
 * @author dragon
 */
function search_init(_searchState)
{
	// judge argument
	if ( typeof _searchState == 'undefined' )
	{
		return;
	}
	window.parent.setLoading(false,"正在打开数据..."); 
	search_hide();
//	if (_searchState.value == '')
//    {
//		search_hide();
//		//search_showAndNotRefresh();
//    }
//    else
//    {
//		search_show();
//    	//search_hideAndNotRefresh();
//    }
}

/**
 * 
 * @return
 * @author dragon
 */
function search_hide(){
	$("#search_body").slideUp(500);
	$("#search_s").show();
	$("#search_h").hide();
	
	name('searchState').value = " ";

	//refresh();
	//form_submit(form().action);
};

/**
 * 
 * @return
 * @author dragon
 */
function search_hideAndNotRefresh(){
//	alert("search_hideAndNotRefresh::->" + name('searchState').value + "<-::");
	$("#search_body").slideUp(500);
	$("#search_s").show();
	$("#search_h").hide();
	
	name('searchState').value = " ";
}

/**
 * 
 * @return
 * @author dragon
 */
function search_show(){
	$("#search_body").slideDown(500);
	$("#search_s").hide();
	$("#search_h").show();
	
	name('searchState').value = "";
//	alert('search_show::->' + name('searchState').value + "<-::");

	//refresh();
	//form_submit(form().action);
};

/**
 * 
 * @return
 * @author dragon
 */
function search_showAndNotRefresh(){
//	alert("search_showAndNotRefresh::->" + name('searchState').value + "<-::");
	$("#search_body").slideDown(500);
	$("#search_s").hide();
	$("#search_h").show();
	
	name('searchState').value = "";
}

/**
 * 测试时使用，打印参数的值（下一层的所有的值）
 * @param sender
 * @return
 * @author dragon
 */
function debug( sender )
{
	if (sender == null || sender == undefined)
		return;
	
	for (var i = 0; i < sender.childNodes.length; alert(i + "::->" + sender.childNodes[i++].value));
}

//onload 用作页面css效果----------------------------
$(document).ready(function(){
							   
							   
//$(".table").mouseover(function(){
//$(this).css("border","solid 1px #ccc");

//});	

//$(".table").mouseout(function(){
//$(this).css("border","1px solid #74B3DC");
//});	



//table里鼠标移到td上改变td的背景图
var tdcss1={
	background:'url(../view/images/bg/bg11.gif) repeat-x'
	
	};

$("td").mouseover(function(){
$(this).css(tdcss1);
});		

var tdcss2 = {
	background:'url(../view/images/bg/bg2.gif) repeat-x'
 };


$("td").mouseout(function(){
$(this).css(tdcss2);
});	



$("input:text").mouseover(function(){
$(this).addClass("input_border");
});	

$("input:text").mouseout(function(){
$(this).removeClass("input_border");
});			   

$("input:text[readonly='true']").addClass("readonly");//输入框为readonly添加css


//★IE外的disabled无效的处理
if(!$.browser.msie){//如果当前浏览器不是IE
var tabs_title=$("a[disabled]:first").html();//tabs里第一个具有disabled属性的div里的文本
var w_title=window.document.title;//当前页面的title
if(tabs_title && tabs_title==w_title){//如果两者相同，则在主页面，除了自己后面的都不可以点
	$("a[disabled]").css("color","#ccc");	//将所有有disabled属性的文本都变灰色
	$("a[disabled]:first").css("color","#333");//第一个高亮
}};

//return; // by dragon
trerror();//页面加载时默认隐藏,tr的第一行错误显示的tr（查询里的错误) 显示trerror('v')
mainerror();//页面加载时默认隐藏,隐藏main 内容表格的错误。显示mainerror('v')：

 });//ready

function trerror(v){//查询里的table里的th 错误的显示与隐藏 trerror()为隐藏， trerror('s')为显示
	return; // by dragon
  if(v){
	$("tr[id='errorMP']").css('display','block');  
	  }else{
		$("tr[id='errorMP']").css('display','none');};
	
};

function mainerror(v){//内容table里错误的显示和隐藏,
	if(v){
		$("center[id='errorMP']").css('display','block'); //筛选:<center >里的
		$("div[id='errorMP']").css('display','block');//筛选:<div >里的
	}else{
		$("center[id='errorMP']").css('display','none');
		$("div[id='errorMP']").css('display','none');
	};
};


//缩略图
//pvid 兼容IE
//pvidff 兼容火狐
function onUploadImgChange(sender,pvid,pvidff){   
    
   
    if( !sender.value.match( /.jpg|.gif|.png|.bmp/i ) ){      
        alert('图片格式无效！');      
        return false;      
    }      
          
    var objPreview = document.getElementById( pvidff );      
    var objPreviewf = document.getElementById(pvid);
    var objPreviewSizef = document.getElementById( 'preview_size_f' );      
          
    if( sender.files &&  sender.files[0] ){      
        objPreview.style.display = 'block';      
        objPreview.style.width = 'auto';      
        objPreview.style.height = 'auto';      
              
        // Firefox 因安全性问题已无法直接通过 input[file].value 获取完整的文件路径      
        objPreview.src = sender.files[0].getAsDataURL();          
    }else if( objPreviewf.filters ){       
        // IE7,IE8 在设置本地图片地址为 img.src 时出现莫名其妙的后果      
        //（相同环境有时能显示，有时不显示），因此只能用滤镜来解决      
              
        // IE7, IE8因安全性问题已无法直接通过 input[file].value 获取完整的文件路径   
		try{    
        sender.select();      
        var imgSrc = document.selection.createRange().text;      
              
        objPreviewf.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;
			      
        objPreviewSizef.filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = imgSrc;      
              
        autoSizePreview( objPreviewf,       
            objPreviewSizef.offsetWidth, objPreviewSizef.offsetHeight );      
        objPreview.style.display = 'none';  
		}catch   (e){   
       //如果加载失败
        alert("您选择了一个非法的文件名，请选择正确的图片格式(GIF/JPG/PNG/BMP)，否则系统将无法完成上传操作。");
       };    
    }      
};     
     
function onPreviewLoad(sender){
    autoSizePreview( sender, sender.offsetWidth, sender.offsetHeight );      
};
  
function autoSizePreview( objPre, originalWidth, originalHeight ){      
    var zoomParam = clacImgZoomParam( 300, 300, originalWidth, originalHeight );
    objPre.style.width = zoomParam.width + 'px';      
    objPre.style.height = zoomParam.height + 'px';      
    objPre.style.marginTop = zoomParam.top + 'px';      
    objPre.style.marginLeft = zoomParam.left + 'px';      
}; 
     
function clacImgZoomParam( maxWidth, maxHeight, width, height ){
    var param = { width:width, height:height, top:0, left:0 };  
          
    if( width>maxWidth || height>maxHeight ){      
        rateWidth = width / maxWidth;      
        rateHeight = height / maxHeight;      
              
        if( rateWidth > rateHeight ){      
            param.width =  maxWidth;      
            param.height = height / rateWidth;      
        }else{      
            param.width = width / rateHeight;      
            param.height = maxHeight;      
        };  
    };    
          
    param.left = (maxWidth - param.width) / 2;      
    param.top = (maxHeight - param.height) / 2;      
          
    return param;      
};

//图片自适应大小 根据此方法,来判断是否选择的图片和预定的相差不大
//使用方法<img src="" onload="proDownImage(this,'100','100')"/>
function proDownImage(nID,nMaxWidth,nMaxHeight){

　　var image=new Image();
	
　　　image.src=nID.src;
　　　if(image.width>0 && image.height>0){
		
　　　var rate = (nMaxWidth/image.width < nMaxHeight/image.height)?nMaxWidth/image.width:nMaxHeight/image.height;
　　	if(rate <= 1)
	{　
　　 	nID.width = image.width*rate;
　　	 	nID.height =image.height*rate;
　　	}
　　else {
　　　　　　nID.width = image.width;
　　　　　　nID.height =image.height;
　　　　　}
　　　};
	nID.style.display = 'inline';
};

function acquireFocus(btnId)
{
    document.getElementById(btnId).focus();
}

/*window.document.onkeydown = function()
{
	if ( window.event.keyCode == 13 ) // 回车按键
	{
		if ( sbmtBtn != undefined ) // 默认的提交按钮不为未定义(undefined) // 和不为空(null)
		{
			/*if ( document.activeElement.tagName == "TEXTAREA" ) // 只要有一个textarea文本域聚光标的话就不执行。
				return;*/
			/*var txtas = tagNames("textarea");
			for (var i = 0; i < txtas.length; i++);* /
			//alert('here was clicked!~~');
			sbmtBtn.click();
		}
	}
}*/


/**
*设Form 下所有元素为只读或者失效状态。
*@param readOnlyFlag ,是否设为只读
*@param selectDisabledFlag ,是否disabled select 控件。
*/
function enableWithForm(formName, readOnlyFlag , selDisFlag ){
	var htmlForm = document.getElementsByName(formName);
	if(htmlForm && htmlForm[0]){
		for ( var i = 0, j = htmlForm[0].elements.length; i < j; ++i ){   
        	ele= htmlForm[0].elements[i];
        	if(ele){ 
    			//alert("元素名:"+ele.name+",元素类别:"+ele.type);
    			if(readOnlyFlag){
         			ele.onfocus = function(){ };//去除日期控件属性
          			ele.ondblclick = function(){ };  //去除双击事件
          			ele.onblur = function(){ }; //去除onblur 事件
      			}
      			ele.readOnly = readOnlyFlag;
      			 
      			if(ele.type == 'select-one' || ele.type == 'checkbox' ){ //select 控件不能设readonly 模式。
          			ele.disabled = selDisFlag;
	        	}
	  		}
  		}
	}
}	

var ColorHex=new Array('00','33','66','99','CC','FF');
var SpColorHex=new Array('FF0000','00FF00','0000FF','FFFF00','00FFFF','FF00FF');
var current=null;
var colorTable='';
var colorValue='';
var v_id='';
  function initColor (v_name)
   {
       $('#colorpanel').show();
       v_id=v_name;
       var s=$("#"+v_name);
       var ss=s.offset();
       var list=$('#colorpanel');
       list.css
       ({
               position:'absolute',
               border:'1px solid #ccc',   
               left:ss.left+'px',
               top:ss.top+s.height()+5+'px',
               width:s.width()+90+'px',
               'font-size':'15px'
       });
       list.html(colorTable);
   };
		    	    
function intocolor()
{
	for (i=0;i<2;i++)
	{
		for (j=0;j<6;j++)
		   {
		    colorTable=colorTable+'<tr height=12>';
		    colorTable=colorTable+'<td width=11 style="background-color:#000000">';
		    
		    if (i==0){
		    colorTable=colorTable+'<td width=11 style="background-color:#'+ColorHex[j]+ColorHex[j]+ColorHex[j]+'">';
		    } 
		    else{
		    colorTable=colorTable+'<td width=11 style="background-color:#'+SpColorHex[j]+'">'
		    }
		
		    
		    colorTable=colorTable+'<td width=11 style="background-color:#000000">';
		    for (k=0;k<3;k++)
		     {
		       for (l=0;l<6;l++)
		       {
		        colorTable=colorTable+'<td width=11 style="background-color:#'+ColorHex[k+i*3]+ColorHex[l]+ColorHex[j]+'">';
		       }
		     }
		}
	}
	colorTable='<table width=100% border="0" cellspacing="0" cellpadding="0" style="border:1px #000000 solid;border-bottom:none;border-collapse: collapse" bordercolor="000000">'
	           +'<tr height=30><td colspan=21 bgcolor=#cccccc>'
	           +'<table cellpadding="0" cellspacing="1" border="0" style="border-collapse: collapse">'
	           +'<tr><td width="3"><td><input type="text" name="DisColor" size="6" disabled style="border:solid 1px #000000;background-color:#000000" readonly="readonly"></td>'
	           +'<td width="3"><td><input type="text" name="HexColor" size="7" style="border:inset 1px;font-family:Arial;" value="#000000" readonly="readonly"></td></tr></table></td></table>'
	           +'<table border="1" cellspacing="0" cellpadding="0" style="border-collapse: collapse" bordercolor="000000" onmouseover="doOver()" onmouseout="doOut()" onclick="doclick()" style="cursor:hand;">'
	           +colorTable+'</table>';  
	                   
}

function doOver() {
      if ((event.srcElement.tagName=="TD") && (current!=event.srcElement)) {
        if (current!=null){current.style.backgroundColor = current._background}     
        event.srcElement._background = event.srcElement.style.backgroundColor
        DisColor.style.backgroundColor = event.srcElement.style.backgroundColor
        HexColor.value = event.srcElement.style.backgroundColor
        event.srcElement.style.backgroundColor = "white"
        current = event.srcElement
      }
}

function doOut() {
    if (current!=null) current.style.backgroundColor = current._background
}

function doclick(){
	if (event.srcElement.tagName=="TD"){
		//alert("选取颜色: "+event.srcElement._background);
		$("#"+v_id).attr('value',event.srcElement._background);
 		$('#colorpanel').hide();
		return event.srcElement._background;
	}
}

 function OnDocumentClick()                     //点击其它时关闭颜色对话框
{
    var srcElement = event.srcElement;
        while (srcElement && srcElement.id!="colorpanel")     
        {
            srcElement = srcElement.parentElement;
        }
        if (!srcElement)
        {
            if(document.getElementById("colorpanel")!=null){
             	document.getElementById("colorpanel").style.display = 'none';
            }
        }
}

 


