//userPanne:Init
var _target,_Width,_Height,_top,_Point,_w_step,_h_step,_p_step,_interval,_url,_form;
function userPannelInit(x) {
	if (typeof(_target) == 'undefined')
	{
			_target = document.getElementById("user_pannel");
			_Width = 550;
			_w_step = 50;
			_p_step = _w_step/2;
			_top = 35;
			_Point = document.body.clientWidth/2;
			_interval = 0;
			_form = 'form_up';
	}
	if (x)
	{
		switch (x.id)
			{
			case 'up_info':
				_Height = 290;
			    _h_step = _Height*(_w_step/_Width);
				_url = 'http://chem.2006b2b.com/post_info.php';
			    return(_Height);
			    break;
			case 'up_price':
				_Height = 550;
			    _h_step = _Height*(_w_step/_Width);
				_url = 'http://member.2006b2b.com/price/price_post.html';
			    return(_Height);
			    break;
			case 'up_close':
				return true;
			    break;
			case 'up_submit':
				return true;
			    break
			default:
				return false;
			    break;
			}
	} else {
		return false;
	}
}

function userPannelControl(x,evt,_openObj){
	if (!_openObj)
	{
	var isIE = (navigator.appName == "Microsoft Internet Explorer");
	if (isIE)
	{
		var handle = event.srcElement;
	} else {
		var handle = evt.target;
	}
	} else {
		var handle = document.getElementById(_openObj);
	}
	if (!userPannelInit(handle))
	{
		return false;
	}
	var userPannelObj = new userPannel(_target);
	switch (x)
	{
	case 'Open':
		userPannelObj.open();
	    break;
	case 'Close':
		userPannelObj.close();
	    break;	
	case 'Submit':
		userPannelObj.up();
	    break;
	}

}

function userPannel(x) {
	this.obj = x;
}

userPannel.prototype.open = function() {
	if (getPixcel(this.obj.style.width) > 0)
	{
		//document.write("draw("+this.obj.id+",\"diff\",0,0,\"draw("+this.obj.id+",'add',"+_Width+","+_Height+",'')\")");
		if (_interval == 0)
		{
			_interval = setInterval("draw('"+this.obj.id+"',\"diff\",0,0,\"draw('"+this.obj.id+"','add',"+_Width+","+_Height+",'')\")",1);
		}
	}
	if (_interval == 0)
	{
		_interval = setInterval("draw('"+this.obj.id+"',\"add\","+_Width+","+_Height+",\"\")",1);
	}
	var ajax = new InitAjax();
	ajax.open('GET',_url,true);
	ajax.onreadystatechange = function() {
		if (ajax.readyState == 4) {
			if (ajax.status == 200) {
				if (ajax.responseText == '请先登录')
				{
					alert('普通会员免费发布\n请先登录');
					clearInterval(_interval);
					_interval = 0;
					new userPannel(_target).close();
					return false;
				}
				_target.innerHTML = ajax.responseText;
			} else {
				alert('系统错误\n请与系统管理员联系');
			}
		}
	}
	ajax.send(null);
	new hidden_Select();
}

userPannel.prototype.close = function() {
	if (_interval == 0)
	{
		_interval = setInterval("draw('"+this.obj.id+"',\"diff\",0,0,\"\")",1)
	}
	new show_Select();
}

userPannel.prototype.up = function() {
	var post_str = '';
	for (i=0;i<document.forms[_form].length;i++ )
	{
		if (document.forms[_form][i].name.substr(document.forms[_form][i].name.length-2,2) == '_r')
		{
			if (document.forms[_form][document.forms[_form].length-1].name.substr(document.forms[_form][document.forms[_form].length-1].name.length-2,2) == '_r' && document.forms[_form][document.forms[_form].length-1].value == '您可以填写贵企业的每天生产状况、销售状况、价格趋势、库存情况、装置动态等,以便让更多的潜在客户发掘了解您，并增加您的订单机会！')
			{
				alert('输入错误\n项目 ' + document.forms[_form][document.forms[_form].length-1].title + ' 未填写\n');
				document.forms[_form][document.forms[_form].length-1].focus();
				return false;
			}
			if (document.forms[_form][i].value == '')
			{
				alert('输入错误\n项目 ' + document.forms[_form][i].title + ' 未填写\n');
				document.forms[_form][i].focus();
				return false;
			}
			post_str += '&' + document.forms[_form][i].name.substr(0,document.forms[_form][i].name.length-2) + '=' + document.forms[_form][i].value;
		} else {
			post_str += '&' + document.forms[_form][i].name + '=' + document.forms[_form][i].value;
		}
	}
	var ajax = new InitAjax();
	ajax.open('POST',_url,true);
	ajax.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	ajax.send(post_str);
	ajax.onreadystatechange = function() {
		if (ajax.readyState == 4) {
			if (ajax.status == 200) {
				if (ajax.responseText == 'OK')
				{
					alert('谢谢您的提交，我们会30分钟内给予审核！');
					new userPannel(_target).close();
				} else {
					if (ajax.responseText == 'DATA EXIST')
					{
						alert('信息以存在\n请不要重复发布');
						new userPannel(_target).close();
					} else {
						alert('未提交成功\n请稍候再试或联系系统管理员');
						new userPannel(_target).close();
						//this.close();
					}
				}
			} else {
				alert('系统错误\n请与系统管理员联系');
			}
		}
	}
}

getPixcel = function(x) {
	return parseInt(x.replace('px',''));
}

draw = function(obj,type,to_w,to_h,after){
	obj = document.getElementById(obj);
	if (type == 'diff')	{
		_w_step = _w_step > 0?-(_w_step):_w_step;
		_h_step = _h_step > 0?-(_h_step):_h_step;
		_p_step = _p_step < 0?-(_p_step):_p_step;
		var _left = _Point;
		var _tmp = '<=';
		var _b_tmp = 'obj.style.border = \'0px solid #ffffff\'';
	}
	if (type == 'add')	{
		obj.style.border = '1px solid #2fa2ea';
		_w_step = _w_step < 0?-(_w_step):_w_step;
		_h_step = _h_step < 0?-(_h_step):_h_step;
		_p_step = _p_step > 0?-(_p_step):_p_step;
		var _left = _Point - (_Width/2);
		var _tmp = '>='
	}
	obj.style.top = _top;
	var _w_tmp = getPixcel(obj.style.width) + _w_step;
	var _h_tmp = getPixcel(obj.style.height) + _h_step;
	var _l_tmp = getPixcel(obj.style.left) + _p_step;
	if (eval(_w_tmp + _tmp + to_w) || eval(_h_tmp + _tmp + to_h))	{
		obj.style.width = to_w + 'px';
		obj.style.height = to_h + 'px';
		obj.style.left = _left + 'px';
		if (_b_tmp)
		{
			eval(_b_tmp);
			_b_tmp = null;
		}
		clearInterval(_interval);
		_interval = 0;
		if (after && (_interval == 0))
		{
			_interval = setInterval(after,1);
		}
	} else {
		obj.style.width = _w_tmp + 'px';
		obj.style.height = _h_tmp + 'px';
		obj.style.left = _l_tmp + 'px';
	}
}

function hidden_Select() {
	if (document.getElementById('product_position'))
	{
		var _ss = document.getElementById('product_position');
		_ss.style.display = 'none';
		_ss = null;
	}

	if (document.getElementById('product_province'))
	{
		var _ss = document.getElementById('product_province');
		_ss.style.display = 'none';
		_ss = null;
	}

	if (document.getElementById('product_contrast'))
	{
		var _ss = document.getElementById('product_contrast');
		_ss.style.display = 'none';
		_ss = null;
	}

	if (document.getElementById('product_big_class_Id'))
	{
		var _ss = document.getElementById('product_big_class_Id');
		_ss.style.display = 'none';
		_ss = null;
	}
}

function show_Select() {
	if (document.getElementById('product_position'))
	{
		var _ss = document.getElementById('product_position');
		_ss.style.display = 'inline';
		_ss = null;
	}

	if (document.getElementById('product_province'))
	{
		var _ss = document.getElementById('product_province');
		_ss.style.display = 'inline';
		_ss = null;
	}

	if (document.getElementById('product_contrast'))
	{
		var _ss = document.getElementById('product_contrast');
		_ss.style.display = 'inline';
		_ss = null;
	}

	if (document.getElementById('product_big_class_Id'))
	{
		var _ss = document.getElementById('product_big_class_Id');
		_ss.style.display = 'inline';
		_ss = null;
	}
}