var releas = Class.create();
releas.prototype = {
	initialize: function(name, id) {
		this.name = name;
		this.id = id;
		var width = 450;
		var bdyw = Prototype.Browser.IE ? document.body.clientWidth : document.documentElement.clientWidth;
		var padding = Prototype.Browser.IE ? document.body.scrollTop : document.documentElement.scrollTop;
        var clientHeight = Prototype.Browser.IE ? document.body.clientHeight : document.documentElement.clientHeight;
      padding += clientHeight /3;
		// padding += event.clientY;					
		var left = (bdyw - width) / 2;
		this.tagStart = '<div id="'+this.id+'" style="padding:0;position:absolute;z-index:110;left:'+left+'px;top:'+padding+'px;width:'+width+'px;background-color:#ECECEC;border:1px solid #99CCFF;"><form onsubmit="return '+this.name+'._submit(this, \''+this.id+'\');">';
		this.tagEnd = '</form></div>';
	},
	show: function(mai) {
		//if ($(this.id)) this._hide();
		this.mail=mai;
		var caption = 'Leave Me a Message';
		var html = this.tagStart;
		html += '<table align="center" style="margin:0;width:100%;border-collapse:collapse;table-layout:auto">';
		html += '<thead><tr>';
		html += '<th width="40%" align="right" style="padding-left:10px;height:34px;font-size:13px;color:#003399;background-color:#E5F1F8;border-bottom:1px solid #99CCFF;">'+caption+'</th>';
		html += '<th id="free_msg_loading" width="40%" align="center" style="height:34px;font-weight:normal;background-color:#E5F1F8;border-bottom:1px solid #99CCFF;">&nbsp;</th>';
		html += '<th width="20%" align="right" style="padding-right:5px;height:34px;background-color:#E5F1F8;border-bottom:1px solid #99CCFF;"><span onclick="'+this.name+'._hide();" style="font-size:13px;color:#ff0000;cursor:pointer;">Close</span></th>';
		html += '</tr></thead><tbody><tr><td width="100%" align="center" colspan="3"><div style="margin:10px 0;font-size:12px;"><span style="color:#ff0000">*</span>Required information</div>';
		html += '<table align="center"><tbody>';
		html += '<tr><td width="25%" height="24" align="center" nowrap style="font-size:12px;font-weight:bold;color:#666666;">UserName£º<span style="font-weight:normal;color:#ff0000">*</span></td>';
		html += '<td width="75%" height="24" align="left"><input id="username" type="text" name="username"  size="30" maxlength="20" style="padding-top:2px !important;padding-top:3px;height:14px !important;height:20px;font-size:12px;border:1px solid #CCCCCC;" /></td></tr>';
		html += '<tr><td width="25%" height="24" align="center" nowrap style="font-size:12px;font-weight:bold;color:#666666;">PassWord£º<span style="font-weight:normal;color:#ff0000">*</span></td>';
		html += '<td width="75%" height="24" align="left"><input id="password" type="password" name="password"  size="30" maxlength="20" style="padding-top:2px !important;padding-top:3px;height:14px !important;height:20px;font-size:12px;border:1px solid #CCCCCC;" /></td></tr>';
		html += '<tr><td width="25%" height="24" align="center" nowrap style="font-size:12px;font-weight:bold;color:#666666;">Content£º<span style="font-weight:normal;color:#ff0000">*</span></td>';
		html += '<td width="75%" height="24" align="left" style="font-size:12px;"><textarea id=content name=content cols=50 rows=10 wrap="hard"></textarea></td></tr>';
        html += '<td width="100%" height="30px" align="center" colspan="3" style="padding:10px 0"><input type="hidden" name="action" value="submitted" /><input type="hidden" name="mail" value="'+this.mail+'" />';
		html += '<input type="submit" value="OK" style="padding:2px 2px 2px 7px !important;padding:2px 2px 0px 5px;font-size:14px;color:#003399;letter-spacing:5px;background-color:#E5F1F8;border:1px solid #CCCCCC;cursor:pointer;" /></td>';
		html += '</tr></tfoot></table>'
		html += this.tagEnd;
		new Insertion.Top(document.body, html);
		var height = $(this.id).getHeight();
		var bdyh = Prototype.Browser.IE ? document.body.clientHeight : document.documentElement.clientHeight;
	//	var top = bdyh -  height - 50;
	 	var top = event.clientY+document.body.scrollTop - 10;
		  top +='px';
		$(this.id).setStyle({top:top});
	},
	
	_hide: function() {
		$(this.id).remove();
	},
	
	
	_submit: function(form, divElt) {
		try {
			var element = 'username';
			var value = $F(element);
			if (!value) throw new Error('Please Input UserUame!');
			element = 'password';
			value = $F(element);
			if (!value) throw new Error('Please Input PassWord!');
			element = 'content';
			value = $F(element);
			if (!value) throw new Error('Please Input Content!');
		//	loading.insert('free_msg_loading', 'top');
        	var url = 'http://www.bearing.com.cn/quote/releas_ok.php';
        	var postData = $(form).serialize();
			ajaxRequest(url, postData, function(thisRequest) {
			//	loading.hide();
	            var response = thisRequest.responseText.strip();
	            if (response && !/^<br\s?\/?>\s*<b>/i.test(response)) {
	            	alert(response);
	            	$(divElt).remove();
	            } else {
	            	alert(response);
	            }
			});
		} catch (e) {
			alert(e.message);
			if (typeof(element) != 'undefined') {
				if ($F(element)) $(element).clear();
				$(element).focus();
			}
		} finally {
			return false;
		}
	}
};