jQuery.extend({
	Form					:	{
		Validate			:	function(fId)
		{
			var rs=true;
			$('form[id="'+fId+'"]').find('*[id^="*"]').each(function(i){
				if($(this).val()==''){ $(this).focus(); $.Form.Alert.On($(this),$(this).attr('title')); rs=false; return false; }
				if($(this).attr('form:type')=='email'){
					if(!$.Form.Check.Email($(this).val())){$.Form.Alert.On($(this),$(this).attr('title')); $(this).focus(); rs=false; return false; }
				}
				if($(this).attr('form:type')=='curpassword'){
					if($(this).val().length<9){ $.Form.Alert.On($(this),$(this).attr('title')); $(this).val(''); $(this).focus(); rs=false; return false; }
				}				
				if($(this).attr('form:type')=='password'){
					if($(this).val().length<9){ $.Form.Alert.On($(this),$(this).attr('title')); $(this).val(''); $(this).focus(); rs=false; return false; }
				}
				if($(this).attr('form:type')=='repassword'){
					if($(this).val().length<9){ $.Form.Alert.On($(this),$(this).attr('title')); $(this).val(''); $(this).focus(); rs=false; return false; }
					var rePw=$(this).val(); var Pid=$(this)
					$('form[id="'+fId+'"]').find('*[id^="*"]').each(function(t){
						if($(this).attr('form:type')=='password'){
							if($(this).val()!=rePw){ $.Form.Alert.On($(this),$(this).attr('title')); $(Pid).val(''); $(Pid).focus(); rs=false; return false; }
						}
						$.Form.Alert.Off($(this));
					});
				}
				$.Form.Alert.Off($(this));
			});
			return rs;
		}
		,
		Alert				:	{
			On				:	function(obj,title,css){
				var css='display:none;\
				overflow:auto;\
				position:absolute;\
				border:1px solid #333;\
				background-color:#EDEDED;\
				padding:3px 5px 3px 5px;\
				color:#000;\
				font-family:tahoma;\
				font-size:11px;\
				';
				var o=$(obj).attr('id').replace('*','');
				var s='<div id="'+o+'_Alert" class="'+css+'" style="'+css+'">'+title+'</div>';
				$(obj).before(s);
				$('#'+o+'_Alert').css({'opacity':0.8,'display':'block'});
				$('#'+o+'_Alert').animate({left:$(obj).offset().left+$(obj).width()+5},500);
			}
			,
			Off				:	function(obj){
				var o=$(obj).attr('id').replace('*','');
				$('#'+o+'_Alert').slideUp(500);
			}
		}
		,
		Check				:	{
			Email			:	function(s)
			{
				var reg = new RegExp("^[0-9a-zA-Z]+@[0-9a-zA-Z]+[\.]{1}[0-9a-zA-Z]+[\.]?[0-9a-zA-Z]+$");
				return reg.test(s);
			}
		}
		,
		Combobox			:	{
			Create			:	function(o,w,path,isCheck){
				var id=$(o).attr('id'); var layer=''; var initTitle='';
				try{ var initVal=$(o).attr('form:init'); if(!initVal) initVal=''; }catch(err){ return false; }
				try{ var isCheck=(!isCheck)?'':'*'; }catch(err){ return false; }				
				try{ var initTitle=$(o).attr('title'); if(!initTitle) initTitle=''; }catch(err){ return false; }
				alen=0;
				$('#'+id+'>li').each(function(i){
					alen++;
					try{ title=$(this).find('a').html(); if(!title) title=$(this).html(); }
					catch(err){ return false; }
					try{ var ref=$(this).find('a').attr('href'); var events=(ref && ref!='#' && ref!='')?'onmousedown="document.location=\''+ref+'\'"':''; }
					catch(err){ return false; }
					value=$(this).attr('value');
					step=title.split('|'); var symbol='';
					css=$(this).attr('class');
					if(step.length>1){
						title=step[1];
						step=step[0].length;
						for(var t=1; t<=step; t++) 
						symbol+=(t==step)
						?'<img src="'+path+'resources/client/form/combobox/step01.gif" align="absmiddle" />'
						:'<img src="'+path+'resources/client/form/combobox/step00.gif" align="absmiddle" />';
						css+='Sub';
					}
					if(initVal==value) initTitle=title;
					layer+='<div title="'+$(this).attr('title')+'" value="'+value+'" style="width:'+w+'px" id="'+id+'Item'+i+'" onclick="$.Form.Combobox.Select(\''+o+'\',this)" '+events+' class="'+css+'">'+symbol+title+'</div>';
				});
				if(alen>10) alen=10; height=alen*25;
				layer='<div id="'+id+'ComboboxLayer" class="comboboxLayer" style="height:'+height+'px">'+layer+'</div>';
				rs='<table cellpadding="0" cellspacing="0"><tr><td><input id="'+id+'ComboboxTitle" class="comboboxTitle" style="width:'+(w-3)+'px; background-image:url('+path+'../resources/client/form/combobox/comboboxBg.png)" ondblclick="$.Form.Combobox.Show(\''+o+'\')" value="'+initTitle+'" /></td>\
				<td align="left"><button id="'+id+'ComboboxBtn" type="button" class="comboboxBtn" onfocus="$.Form.Combobox.Show(\''+o+'\')" onclick="$.Form.Combobox.Show(\''+o+'\')"></button></td></tr>\
				<tr><td colspan="2" height="0" align="left">'+layer+'</td></tr></table><input title="'+isCheck+'" type="hidden" name="'+id+'" id="'+id+'" value="'+initVal+'" />';
				$('#'+id).replaceWith(rs);
				$('#'+id+'ComboboxBtn').css('background-image',path+'resources/client/form/combobox/combobox.png');
			}
			,
			Show			:	function(o){
				var id=$(o).attr('id');
				$('.comboboxLayer').hide(0,$('#'+id+'ComboboxLayer').slideDown(200));
			}
			,
			Select			:	function(o,oItem){
				var id=$(o).attr('id'); var idItem=oItem.id;
				$('#'+id+'ComboboxTitle').val($('#'+idItem).text());
				$('#'+id).val($('#'+idItem).attr('value'));
				$('#'+id+'ComboboxLayer').slideUp(200);
			}
		}
	}	
});
