jQuery.each(["Left","Right","Top","Bottom"], function(i, name){
	jQuery.fn["padding" + name] = function(){
		return parseInt(this.css("padding" + name))||0;
	};
	jQuery.fn["border" + name + "Width"] = function(){
		return parseInt(this.css("border" + name + "Width"))||0;
	};
	jQuery.fn["margin" + name] = function(margin) {
		return parseInt(this.css("margin" + name))||0;
	};
});
jQuery.each(["Height","Width"], function(i, name){
	var tl = i ? "Left":"Top",br = i ?"Right":"Bottom";
	jQuery.fn["layout" + name] = function(options) {
		var setting = $.extend({
			id       : null,
			body     : null,
			padding  : null,
			data     : [],
			callback : null
		},options);
		$.fn.num = function(){
			var _marg = [];
				_marg.push(parseInt(this.css("margin" + tl))||0);
				_marg.push(parseInt(this.css("margin" + br))||0);
				_marg.push(parseInt(this.css("padding" + tl))||0);
				_marg.push(parseInt(this.css("padding" + br))||0);
				_marg.push(parseInt(this.css("border" + tl + name))||0);
				_marg.push(parseInt(this.css("border" + br + name))||0);
			return eval(_marg.join("+"));
		};
		$.fn.getSize = function(){
			var _data = [];
			this.each(function(i){
				_data.push(eval('$(this).outer'+name+'(true)'));
			});
			return _data;
		};
		$.fn.setSize = function(value,data,idx){
			this.each(function(i){
				var _obj = $(this);
				var _num = _obj.num();
				if(i==idx)return;
				try{
					var n = data[i];
					if(n.id&&i==n.index){
						var _item = $(n.id);
						_num += _item.num()+eval(_item.getSize().join('+'))+_item.parent().num();
					}else if(i==n.index){
						_num += n.height;
					}
				}catch(e){}
				var _min = $.browser.msie&&$.browser.version=='6.0'?name.toLowerCase():"min"+name;
				_obj.css(_min,value-_num);
			});
		};
		if(this.size()>0){
			var _ret = this.getSize();
			var _max = Math.max.apply(Math,_ret);
			var _re = new RegExp(","+_max+",","i");
			var idx = ((","+_ret.toString()+",").replace(_re,"|").replace(/[^,|]/g,"")).indexOf("|");
			this.setSize(_max,setting.data,idx);
			if($.isFunction(setting.callback)) setting.callback.apply(this,[_max]);
		}
	};
});
$(function(){
	$('#select').change(function(){
		this.form.action = this.value;
	});
	$.formValidator.initConfig({formid:"form1",onerror:function(msg){}});
	$(".feedback #company").formValidator({
		onshow    : "请输入公司名称",
		onfocus   : "公司名称不能为空",
		oncorrect : "输入正确"
	}).inputValidator({
		min       : 1,
		onerror   : "公司名称不能为空"
	});
	$(".feedback #linkman").formValidator({
		onshow    : "请输入联系人",
		onfocus   : "联系人不能为空",
		oncorrect : "输入正确"
	}).inputValidator({
		min       : 1,
		onerror   : "联系人不能为空"
	});
	$(".feedback #tel").formValidator({
		onshow    : "请输入电话号码",
		onfocus   : "电话号码不能为空",
		oncorrect : "输入正确"
	}).inputValidator({
		min       : 1,
		onerror   : "电话号码不能为空"
	}).regexValidator({regexp:"^(\\d{3,4}[ -])?\\d{7,8}$",onerror:"电话码号格式不正确"});

	$(".feedback #email").formValidator({
		onshow    : "请输入电子邮箱",
		onfocus   : "电子邮箱不能为空",
		oncorrect : "输入正确"
	}).inputValidator({
		min       : 1,
		onerror   : "电子邮箱不能为空"
	}).regexValidator({regexp:"^([\\w-.]+)@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.)|(([\\w-]+.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(]?)$",onerror:"你输入电子邮件格式不正确"});;
	$(".feedback #address").formValidator({
		onshow    : "请输入地址",
		onfocus   : "地址不能为空",
		oncorrect : "输入正确"
	}).inputValidator({
		min       : 1,
		onerror   : "地址不能为空"
	});
	$(".feedback #country").formValidator({
		onshow    : "请输入国家",
		onfocus   : "国家不能为空",
		oncorrect : "输入正确"
	}).inputValidator({
		min       : 1,
		onerror   : "国家不能为空"
	});
	$(".feedback #remark").formValidator({
		onshow    : "请输入您要反馈内容",
		onfocus   : "您要反馈内不能为空容",
		oncorrect : "输入正确"
	}).inputValidator({
		min       : 1,
		onerror   : "您要反馈内不能为空容"
	});
	$('#main').find('#left>#content,#right>#content').layoutHeight({
		data    : [
			{index:0,height:-2},
			{index:1,height:5}
		]
	});
});
