//by daviguoshuang at gmail.com

var checkMessageDelay=10000;//检查短消息ajax时间间隔
var hoverDelay=600; //pop 窗口延迟 ms

jQuery(function($){
//////////////////



//ajax done
$('<div style="position:absolute;z-index:99;font-size:16px;font-weight:700;color:#900;top:-999px" id="ajaxDone"></div>').appendTo($('body'));

  
/*topNavi li:first*/
$('#topNavi li:first').addClass('first');
$('.bottomNavi li:first').addClass('first');

//remove lastone's dotted line
$('.gravatarList2 ul').each(function(){
	$(this).find('li').last().addClass('last');
})

$('.gravatarList').each(function(){
	$(this).find('ul:first').css({display:'block'}).show();
})

$('.gravatarList2').each(function(){
	$(this).find('ul:first').css({display:'block'}).show();
})


/*readonly input hidefocus*/
$('input.hidefocus').focus(function(){$(this).blur()});

/*topSearch  start--------------*/
//firefox chrome  的逻辑是： 在 input type="text" 里面按回车键，触发 form 里面第一个 button 的 click！这会导致 05 中那样：搜索关键字  按回车  打开 类别筛选！

$('#topSearch .cat').mousedown(function(){
	$('#topSearch .searchType').fadeIn();
})

$('#topSearch .cat').click(function(){
	e.preventDefault();
})

$('#topSearch .searchType').mouseleave(function(){
	$(this).fadeOut();
})

$('#topSearch .q').focus(function(){
	$(this).select();
	if($.trim($(this).val())=='请输入关键字'){$(this).val('');}
	$(this).addClass('focus');
}).blur(function(){
	if($.trim($(this).val())==''){$(this).val('请输入关键字');}
	$(this).removeClass('focus');
})

$('#sForm').submit(function(){
	if($(this).find('.q').val()==''||$(this).find('.q').val()=='请输入关键字'){
		alert('请输入关键字')
		return false;
	}
})

try{if(gSiteVars.searchType){
	str='';
	$('#topSearch .searchType li').each(function(){
		if($(this).attr('data-type')==gSiteVars.searchType){str=$(this).text();}
	})
	if(str==''){
		alert('没有定义默认搜索类别！');
		$('#topSearch .cat span').text('专家');
		$('#topSearch .realCat').val('exp');
	}else{
		$('#topSearch .cat span').text(str);
		$('#topSearch .realCat').val(gSiteVars.searchType);
	}
}}catch(e){}

$('#topSearch .searchType li').mouseover(function(){$(this).addClass('hover')}).mouseout(function(){$(this).removeClass('hover')}).click(function(){
	$(this).parent().fadeOut();
	obj=$('#topSearch');
	obj.find('.realCat').val($(this).attr('data-type'));
	obj.find('.cat span').text($(this).text());	
});
if(typeof(gSiteVars)!="undefined" ){
	if(gSiteVars.searchStr==''){$('#topSearch .q').val('请输入关键字');}
	else {$('#topSearch .q').val(gSiteVars.searchStr);}
}

/*topSearch  end--------------*/

$('a.linkCollapse').mouseenter(function(){
	$(this).find('span').stop().animate({opacity:1},600)
}).mouseleave(function(){
	$(this).find('span').stop().animate({opacity:0},600)
})


//Initial hide other 1 ul of gravatarList
$('#subMenu .tools a:first').addClass('first');

/*h1.b2home click go back 2 homtpage*/
$('#header h1.b2home').prepend('<div class="b2homeDiv" style="position:absolute;left:0;top:8px;width:160px;height:67px;cursor:pointer;" title="返回首页"></div>')
$('#header h1.b2home .b2homeDiv').click(function(){window.location='/index.htm'})

//auto append clear:both to .addClear
$('.addClear').append('<div class="clear"></div>');

//view Switch
$('h2.th2 .viewSwitch span').mouseover(function(){
	if($(this).hasClass('viewIcon')){$(this).addClass('ihover')}
	else if($(this).hasClass('viewList')){$(this).addClass('lhover')}
	else if($(this).hasClass('viewDetail')){$(this).addClass('dhover')}
}).mouseout(function(){
	$(this).removeClass('lhover ihover dhover');
})

var h2TabsTimer;//mouse over h2tabs delay sometime

$('h2.th2 .h2Tabs span').mouseenter(function(){
	clearInterval(h2TabsTimer);
	var thisspan=$(this);
	var thisnum=$(this).index();
	
	h2TabsTimer=setTimeout(function(){
	//console.log($this)
	obj=thisspan.parents('.sec').find('.gravatarList');
	if(obj.length==0){obj=thisspan.parents('.sec').find('.gravatarList2');}
	if(obj.length==0){obj=thisspan.parents('.sec').find('.gravatarList3');}
	
	if(obj.length==0){obj=thisspan.parents('.halfCol').find('.border1');}
		
	obj.find('ul').hide();
	obj.find('ul:eq('+thisnum+')').show();
	thisspan.parent().find('span').removeClass('current');
	thisspan.addClass('current');
	
	},hoverDelay)
}).mouseleave(function(){
	clearInterval(h2TabsTimer);
})

/*div.halfCol ul {display:none;}*/
$('div.halfCol').each(function(){
	$(this).find('.border1 ul:first').show();
});

//gravatarList mouse enter show
$('.gravatarList .pop,.gravatarList2 .pop,.gravatarList3 .pop').wrapInner('<div class="frameDiv"></div>');

var hoverTimer; //mouse over something delay sometime
$('.gravatarList .gimg').live('mouseenter',function(){
	if($(this).parents('.gravatarList').hasClass('noPop')){return false;}//强制不打开pop
	clearInterval(hoverTimer);
	obj=$(this);
	hoverTimer=setTimeout(function (){
		obj.parents('.gravatarList').find('.pop').hide();
		obj.parents('li').find('.pop').show();
	},hoverDelay)
}).live('mouseleave',function(){
	if($(this).parents('.gravatarList').hasClass('noPop')){return false;}//强制不打开pop
	clearInterval(hoverTimer);
})

$('.gravatarList .pop .close').live('mouseenter',function(){
		$(this).addClass('closeHover');
	}).live('mouseleave',function(){
		$(this).removeClass('closeHover');
	}).live('click',function(){
		$(this).parents('.pop').hide();
})

//close all .pop element if out of it
$('.gravatarList .pop').live('mouseleave',function(){
	clearInterval(hoverTimer);
	$(this).hide();
})

//remove .pop
$('body').mouseenter(function(){
	$('.gravatarList .pop').hide();
})

//
$('h2.th2 .viewSwitch .doff').live('click',function(){
	$(this).parents('.sec').find('.gravatarList').removeClass('gravatarList').addClass('gravatarList2');
	$(this).removeClass('doff').addClass('don');
	$(this).parent().find('.lon').removeClass('lon').addClass('loff');
	$(this).parent().find('.ion').removeClass('ion').addClass('ioff');
	//.pop 隐藏以后就不再显示，这是要初始化 .pop
	$('.gravatarList2 .pop').css({display:'block'})
})

$('h2.th2 .viewSwitch .ioff').live('click',function(){
	$(this).parents('.sec').find('.gravatarList2').removeClass('gravatarList2').addClass('gravatarList');
	$(this).removeClass('ioff').addClass('ion');
	$(this).parent().find('.lon').removeClass('lon').addClass('loff');
	$(this).parent().find('.don').removeClass('don').addClass('doff');
	//.pop 隐藏以后就不再显示，这是要初始化 .pop
	$('.gravatarList .pop').css({display:'none'})
})

/*hack opera*/
if($.browser.opera){
	$('#topSearch .submit').css({'vertical-align':'top'})
} 

/*ajax IM messages*/
$('#topNavi .logined .new').append('<div class="indiNew" style="display:none;"></div>');

function checkMessage(oid){
	$.ajax({
		url:'im.js',//im.php 根据 id 返回用户消息信息；安全问题怎么办？ajax 后台 session 验证
		data:'id='+oid,
		dateType:'json',
		success:function(data){
			eval('data='+data);
			if(data.hasMessgae){
				//alert('has messaqges');
				var oNum=data.invite+data.im+data.apply
				$('#topNavi .new').attr('title','您有'+data.invite+'条邀请，'+data.im+'条短信，'+data.apply+'条申请，'+data.board+'条通知').find('.num').text('('+oNum+')')
				$('#topNavi .indiNew').show();
			}else{
				$('#topNavi .indiNew').hide();
			}
		}
	})
}
 

$('a[rel=external]').attr('target','_blank');

/*for forms*/
$('.button').mouseover(function(){
	$(this).addClass('btnHover');
}).mouseout(function(){
	$(this).removeClass('btnHover');
})

$('.date').datepicker({
	dateFormat:'yy-mm-dd',
	prevText: '«上月',
	nextText: '下月»',
	changeYear:true,
	currentText: '今天',
	monthNames: ['一月','二月','三月','四月','五月','六月',
	'七月','八月','九月','十月','十一月','十二月'],
	dayNamesMin: ['日','一','二','三','四','五','六'],
	defaultDate:'+1'
})
  
$('.date').each(function(i){ 
	if($(this).val()!=''){ 
		$(this).val($(this).val().substring(0,10)); 
	}
}); 
$('input.today').datepicker('setDate', '+0');//设置默认时间为今天！

/*form validate*/
//$(':input.required').after(' <em style="color:#900;font-size:15px;font-weight:700;line-height:25px;">*</em>')

$(':input.required').each(function(){
	if($(this).hasClass('tinymce')){return;} //tinymce 中的 table 会导致 * 号换行
	$(this).after(' <em style="color:#900;font-size:15px;font-weight:700;line-height:25px;">*</em>');
})

$(':checkbox,:radio').each(function(){
	$(this).css({'margin-right':'4px','vertial-align':'middle'});
	$(this).parent().css({'margin-right':'8px'})
})

//$('.collapsable').attr('title','点击打开关闭').click(function(){$(this).next().toggle();$(this).toggleClass('closed')})

$('.collapsable').prepend('<span class="s" title="打开|关闭"></span>')//.find('.s').css({opacity:0});

$('.collapsable').mouseenter(function(){
	//$(this).find('.s').stop().animate({opacity:1},300)
}).mouseleave(function(){
	//$(this).find('.s').stop().animate({opacity:0},300)
}).click(function(){
	obj=$(this);
	//console.log(obj.next().html())
	//alert(obj.next().html())
	obj.next().toggle();
	obj.toggleClass('collapseClosed');
})

$('button.submit').click(function(){
	$(this).parents('form').trigger('submit');
	return false;
})

$('form').submit(function(e){
	var oForm = $(this);
	oForm.find(".submit").attr("disabled","disabled");
	if(oForm.hasClass('noValidate')){return true;}//form.noValidate 使用自己的验证！不执行全局验证
	if(oForm.hasClass('noValidate1')){return true;}//form.noValidate 使用自己的验证！不执行全局验证
	//$(document).scrollTop($('.errorInfoDiv').position().top-20);//scroll 2 errorInfoDiv
	var returnvalue=$(this).validate();
	if(!returnvalue){
		oForm.find(".submit").removeAttr("disabled");
	}
	return returnvalue;
});

//city select
var chinaCity={
	"中国":["中国"],
	"北京":["东城","西城","崇文","宣武","朝阳","丰台","石景山","海淀","门头沟","房山","通州","顺义","昌平","大兴","平谷","怀柔","密云","延庆"],
	"上海":["黄浦","卢湾","徐汇","长宁","静安","普陀","闸北","虹口","杨浦","闵行","宝山","嘉定","浦东","金山","松江","青浦","南汇","奉贤","崇明"],
	"天津":["和平","东丽","河东","西青","河西","津南","南开","北辰","河北","武清","红挢","塘沽","汉沽","大港","宁河","静海","宝坻","蓟县"],
	"重庆":["万州","涪陵","渝中","大渡口","江北","沙坪坝","九龙坡","南岸","北碚","万盛","双挢","渝北","巴南","黔江","长寿","綦江","潼南","铜梁","大足","荣昌","壁山","梁平","城口","丰都","垫江","武隆","忠县","开县","云阳","奉节","巫山","巫溪","石柱","秀山","酉阳","彭水","江津","合川","永川","南川"],
	"河北":["石家庄","邯郸","邢台","保定","张家口","承德","廊坊","唐山","秦皇岛","沧州","衡水"],
	"山西":["太原","大同","阳泉","长治","晋城","朔州","吕梁","忻州","晋中","临汾","运城"],
	"内蒙古":["呼和浩特","包头","乌海","赤峰","呼伦贝尔盟","阿拉善盟","哲里木盟","兴安盟","乌兰察布盟","锡林郭勒盟","巴彦淖尔盟","鄂市"],
	"辽宁":["沈阳","大连","鞍山","抚顺","本溪","丹东","锦州","营口","阜新","辽阳","盘锦","铁岭","朝阳","葫芦岛"],
	"吉林":["长春","吉林","四平","辽源","通化","白山","松原","白城","延边"],
	"黑龙江":["哈尔滨","齐齐哈尔","牡丹江","佳木斯","大庆","绥化","鹤岗","鸡西","黑河","双鸭山","伊春","七台河","大兴安岭"],
	"江苏":["南京","镇江","苏州","南通","扬州","盐城","徐州","连云港","常州","无锡","宿迁","泰州","淮安"],
	"浙江":["杭州","宁波","温州","嘉兴","湖州","绍兴","金华","衢州","舟山","台州","丽水"],
	"安徽":["合肥","芜湖","蚌埠","马鞍山","淮北","铜陵","安庆","黄山","滁州","宿州","池州","淮南","巢湖","阜阳","六安","宣城","亳州"],
	"福建":["福州","厦门","莆田","三明","泉州","漳州","南平","龙岩","宁德"],
	"江西":["南昌市","景德镇","九江","鹰潭","萍乡","新馀","赣州","吉安","宜春","抚州","上饶"],
	"山东":["济南","青岛","淄博","枣庄","东营","烟台","潍坊","济宁","泰安","威海","日照","莱芜","临沂","德州","聊城","滨州","菏泽"],
	"河南":["郑州","开封","洛阳","平顶山","安阳","鹤壁","新乡","焦作","濮阳","许昌","漯河","三门峡","南阳","商丘","信阳","周口","驻马店","济源"],
	"湖北":["武汉","鄂州","宜昌","荆州","襄樊","黄石","荆门","黄冈","十堰","恩施","潜江","天门","仙桃","随州","咸宁","孝感"],
	"湖南":["长沙","常德","株洲","湘潭","衡阳","岳阳","邵阳","益阳","娄底","怀化","郴州","永州","湘西","张家界"],
	"广东":["广州","深圳","珠海","汕头","东莞","中山","佛山","韶关","江门","湛江","茂名","肇庆","惠州","梅州","汕尾","河源","阳江","清远","潮州","揭阳","云浮"],
	"广西":["南宁","柳州","桂林","梧州","北海","防城港","钦州","贵港","玉林","南宁地区","柳州地区","贺州","百色","河池"],
	"海南":["海口","三亚"],
	"四川":["成都","绵阳","德阳","自贡","攀枝花","广元","内江","乐山","南充","宜宾","广安","达川","雅安","眉山","甘孜","凉山","泸州"],
	"贵州":["贵阳","六盘水","遵义","安顺","铜仁","黔西南","毕节","黔东南","黔南"],
	"云南":["昆明","大理","曲靖","玉溪","昭通","楚雄","红河","文山","思茅","西双版纳","保山","德宏","丽江","怒江","迪庆","临沧"],
	"西藏":["拉萨","日喀则","山南","林芝","昌都","阿里","那曲"],
	"陕西":["西安","宝鸡","咸阳","铜川","渭南","延安","榆林","汉中","安康","商洛"],
	"甘肃":["兰州","嘉峪关","金昌","白银","天水","酒泉","张掖","武威","定西","陇南","平凉","庆阳","临夏","甘南"],
	"宁夏":["银川","石嘴山","吴忠","固原"],
	"青海":["西宁","海东","海南","海北","黄南","玉树","果洛","海西"],
	"新疆":["乌鲁木齐","石河子","克拉玛依","伊犁","巴音郭勒","昌吉","克孜勒苏柯尔克孜","博尔塔拉","吐鲁番","哈密","喀什","和田","阿克苏"],
	"香港":["香港"],
	"澳门":["澳门"],
	"台湾":["台北","高雄","台中","台南","屏东","南投","云林","新竹","彰化","苗栗","嘉义","花莲","桃园","宜兰","基隆","台东","金门","马祖","澎湖"],
	"其它":["北美洲","南美洲","亚洲","非洲","欧洲","大洋洲"]
}

var provinceStr='';
$.each(chinaCity,function(key,val){
	provinceStr+='<li title="'+key+'" data-city="'+val.join(',')+'">'+key+'</li>';
})

$('#citySelect').append('<div id="citySelectDiv" style="display:none;padding:10px;"><div class="citytriangle"></div><ul class="provinces">'+provinceStr+'</ul><ul class="citys" style="display:none;"><li class="goBack" style="color:#900">[返回上级]</li></ul><div class="close" title="关闭">关闭</div></div>')

$('#citySelectDiv .close').mouseenter(function(){
	$(this).addClass('closeHover');
}).mouseout(function(){
	$(this).removeClass('closeHover');
}).click(function(){
	$(this).parent().hide();
})

$('#citySelectDiv li').live({
	mouseenter: function() {
		if($(this).hasClass('goBack'))return;
		$(this).addClass('hover');
	},
	mouseleave: function() {
		if($(this).hasClass('goBack'))return;
		$(this).removeClass('hover');
	}
});

$('#citySelect .switch').click(function(){if($('#citySelectDiv').css('display')!='none'){return;};$('#citySelectDiv').fadeIn();})

var choosedProvince='';
var choosedCity='';

$('#citySelectDiv .provinces li').click(function(){
	var thisCitys=$(this).attr('data-city').split(',');
	var citystr='';
	$.each(thisCitys,function(i,val){citystr+='<li>'+val+'</li>'})
	$(this).parent().slideUp('fast','easeInOutBounce',function(){
		$(this).parent().find('.citys').prepend(citystr).slideDown('fast')
	})
	choosedProvince=$(this).text();
})

$('#citySelectDiv .citys li').live('click',function(){
	if($(this).hasClass('goBack')){
		obj=$(this).parent();
		obj.find('li').not('.goBack').remove();
		obj.hide();
		obj.parent().find('.provinces').slideDown('fast','easeInOutBounce')
	}
	else {
		choosedCity=$(this).text();
		$('#citySelectDiv').hide();
		$('#citySelect .nowCity').text(choosedProvince+' '+choosedCity);
		$.getJSON("/changelocation",{"location":choosedProvince+','+choosedCity},function(data){
			if(data.success) window.location.reload(false);
		});
	}
})

var provinceOptions='';
$.each(chinaCity,function(key,val){
	provinceOptions+='<option'+' data-city="'+val.join(',')+'">'+key+'</option>';
})
$('.provinceSel').append(provinceOptions).change(function(i,n){
	var selectedProvince=$(this).find('option:selected').text();
	var oCityData=$(this).find('option:selected').attr('data-city');
	if(oCityData){
		var oCityStr='';
		$.each(oCityData.split(','),function(i,val){
			oCityStr+='<option>'+val+'</option>'
		})	
		$(this).parents('p').find('.citySel').empty().append(oCityStr).change(function(){
			$(this).parents('p').find('.myPlace').val(selectedProvince+','+$(this).find('option:selected').text());
		})
	//选择省以后默认城市为第一个
	$(this).parents('p').find('.myPlace').val(selectedProvince+','+$(this).parents('p').find('.citySel option:first').text());
	}
})

/*textarea with text limit*/

$('textarea[maxlength]').each(function(){
	$(this).after('<span class="g1 textLimit" style="padding-left:6px;">还能输入'+$(this).attr('data-limit')+'个字</span>');
})

$('textarea[maxlength]').limitMaxlength({
	onEdit: function(remaining){
		$(this).siblings('.textLimit').text('还能输入'+remaining+'个字');
	}
});

$('table.gGrid tr:odd').addClass('odd');



/*检测其它浏览器加入 js css hack ---------------------------------*/

/*if ie6*/
if(parseInt($.browser.version)<7&&$.browser.msie){ //ie 6
	$('a').attr('hideFocus','true');
	$('button.btn1').mouseover(function(){$(this).addClass('hover')}).mouseout(function(){$(this).removeClass('hover')});
}

//if ie all
if($.browser.msie){ 
	$('.gravatarList .gimg').live('mouseenter',function(){
		$('.gravatarList li').css({'z-index':1});
		$(this).parents('li').css({'z-index':2});
		//alert($(this).parents('li').find('a').html())
	});
}

//if ie 6-7
if(parseInt($.browser.version)<8&&$.browser.msie){
	
	$('input:text,input:password').focus(function(){$(this).addClass('focus');}).blur(function(){$(this).removeClass('focus')});
	$('.button,input:checkbox,input:radio').focus(function(){$(this).blur();});
	$('input[readonly]').focus(function(){$(this).blur();}); //去掉ie readonly 光标闪呀闪的
}

if($('textarea.xheditors').length!=0){// 如果有 .tinymce 才 lazy load tiny_mce.js
		$('textarea.xheditors').xheditor({upLinkUrl:"/fileupload/uploadfile",
			 upLinkExt:"zip,rar,txt,doc,docx,pdf,ppt,pptx,pps,ppsx,xlsx,xls,7z",
			 upImgUrl:"/fileupload/uploadpic",
             upImgExt:"jpg,jpeg,gif,png", 
             tools:'simple',forcePtag:false,html5Upload:false,
             emotMark:true});
}
//insert user send message
$(".im").live("click",function(){
	window.location.replace('/mailbox/sendMessage/insend/'+$(this).attr("reluserid"));
});

//apply device
$(".lease").live("click",function(){
	var lease=$(this);
	var devicePageId=lease.attr("leasepage");
	window.location.replace(devicePageId+"/member/apply");
});

//////////////////	
});

jQuery.fn.validate = function() {
	var oForm=$(this);
	var ok=true;
	$('.errorInfoDiv,.minLenDiv').remove();
	oForm.find('p').removeClass('error');
	oForm.find(':input').each(function(){
		//validate start
		if($(this).hasClass('required')&&$(this).val()==''){//required
			$(this).parents('p').addClass('error').append('<span class="errorInfoDiv">这是必填项</span>').find('.errorInfoDiv').css({paddingLeft:'20px'}).stop().animate({paddingLeft:0},200,'easeOutBounce')
			ok=false;
			return false;
		//email
		}else if($(this).val()!=''&&$(this).hasClass('email')&&!($(this).val().match(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/))){
			$(this).parents('p').addClass('error').append('<span class="errorInfoDiv">请输入有效邮箱</span>').find('.errorInfoDiv').css({paddingLeft:'20px'}).stop().animate({paddingLeft:0},200,'easeOutBounce')
			ok=false;
			return false;
		//url
		}else if($(this).val()!=''&&$(this).hasClass('url')&&!($(this).val().match(/^(http|ftp|https|file):\/\/([\w\-]+\.)+[\w\-]+(\/[\w\u4e00-\u9fa5\-\.\/?\@\%\!\&=\+\~\:\#\;\,]*)?$/))){
			$(this).parents('p').addClass('error').append('<span class="errorInfoDiv">请输入有效URL</span>').find('.errorInfoDiv').css({paddingLeft:'20px'}).stop().animate({paddingLeft:0},200,'easeOutBounce')
			ok=false;
			return false;
		//number
		}else if($(this).val()!=''&&$(this).hasClass('number')&&!($(this).val().match(/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\.\d+)?$/))){
			$(this).parents('p').addClass('error').append('<span class="errorInfoDiv">请输入有效数字</span>').find('.errorInfoDiv').css({paddingLeft:'20px'}).stop().animate({paddingLeft:0},200,'easeOutBounce')
			ok=false;
			return false;
		//digits
		}else if($(this).val()!=''&&$(this).hasClass('digits')&&!($(this).val().match(/^\d+$/))){
			$(this).parents('p').addClass('error').append('<span class="errorInfoDiv">请输入有效整数</span>').find('.errorInfoDiv').css({paddingLeft:'20px'}).stop().animate({paddingLeft:0},200,'easeOutBounce')
			ok=false;
			return false;
		//letter
		}else if($(this).val()!=''&&$(this).hasClass('letter')&&!($(this).val().match(/^[a-zA-Z]*$/))){
			$(this).parents('p').addClass('error').append('<span class="errorInfoDiv">请输入有效字母</span>').find('.errorInfoDiv').css({paddingLeft:'20px'}).stop().animate({paddingLeft:0},200,'easeOutBounce')
			ok=false;
			return false;
		//letNum
		}else if($(this).val()!=''&&$(this).hasClass('letNum')&&!($(this).val().match(/^[A-Za-z0-9]+$/))){
			$(this).parents('p').addClass('error').append('<span class="errorInfoDiv">请输入有效字母和数字</span>').find('.errorInfoDiv').css({paddingLeft:'20px'}).stop().animate({paddingLeft:0},200,'easeOutBounce')
			ok=false;
			return false;
		//userName
		}else if($(this).val()!=''&&$(this).hasClass('userName')&&!($(this).val().match(/^[A-Za-z0-9]+$/))){
			$(this).parents('p').addClass('error').append('<span class="errorInfoDiv">请输入有效用户名(字母+数字)</span>').find('.errorInfoDiv').css({paddingLeft:'20px'}).stop().animate({paddingLeft:0},200,'easeOutBounce')
			ok=false;
			return false;
		//QQ
		}else if($(this).val()!=''&&$(this).hasClass('checkqq')&&!($(this).val().match(/^[1-9]+\d{4,15}$/))){
			$(this).parents('p').addClass('error').append('<span class="errorInfoDiv">请输入有效QQ</span>').find('.errorInfoDiv').css({paddingLeft:'20px'}).stop().animate({paddingLeft:0},200,'easeOutBounce')
			ok=false;
			return false;
		//dateCN
		}else if($(this).val()!=''&&$(this).hasClass('dateCN')&&!($(this).val().match(/^\d{4}-\d{1,2}-\d{1,2}$/))){
			$(this).parents('p').addClass('error').append('<span class="errorInfoDiv">请输入有效日期格式  例如:2009-05-06</span>').find('.errorInfoDiv').css({paddingLeft:'20px'}).stop().animate({paddingLeft:0},200,'easeOutBounce')
			ok=false;
			return false;
		//chinese
		}else if($(this).val()!=''&&$(this).hasClass('chinese')&&!($(this).val().match(/^[\u4e00-\u9fa5]*$/))){
			$(this).parents('p').addClass('error').append('<span class="errorInfoDiv">请输入有效中文</span>').find('.errorInfoDiv').css({paddingLeft:'20px'}).stop().animate({paddingLeft:0},200,'easeOutBounce')
			ok=false;
			return false;
		//float
		}else if($(this).val()!=''&&$(this).hasClass('float')&&!($(this).val().match(/^[0-9]+\.[0-9]+$/))){
			$(this).parents('p').addClass('error').append('<span class="errorInfoDiv">请输入有效小数</span>').find('.errorInfoDiv').css({paddingLeft:'20px'}).stop().animate({paddingLeft:0},200,'easeOutBounce')
			ok=false;
			return false;
		//phone
		}else if($(this).val()!=''&&$(this).hasClass('phone')&&!($(this).val().match(/((^(((1[0-9]{1}[0-9]{1}))+\d{8})$)|(^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})(\-[0-9]{1,4})?$))/))){
			$(this).parents('p').addClass('error').append('<span class="errorInfoDiv">请输入有效电话 例如:010-80000000</span>').find('.errorInfoDiv').css({paddingLeft:'20px'}).stop().animate({paddingLeft:0},200,'easeOutBounce')
			ok=false;
			return false;
		//fax
		}else if($(this).val()!=''&&$(this).hasClass('fax')&&!($(this).val().match(/((^(((1[0-9]{1}[0-9]{1}))+\d{8})$)|(^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})?$))/))){
			$(this).parents('p').addClass('error').append('<span class="errorInfoDiv">请输入有效传真 例如:010-80000000</span>').find('.errorInfoDiv').css({paddingLeft:'20px'}).stop().animate({paddingLeft:0},200,'easeOutBounce')
			ok=false;
			return false;
		//mobile
		}else if($(this).val()!=''&&$(this).hasClass('mobile')&&!($(this).val().match(/^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/))){
			$(this).parents('p').addClass('error').append('<span class="errorInfoDiv">请输入有效手机号码</span>').find('.errorInfoDiv').css({paddingLeft:'20px'}).stop().animate({paddingLeft:0},200,'easeOutBounce')
			ok=false;
			return false;
		//contact
		}else if($(this).val()!=''&&$(this).hasClass('contact')&&!($(this).val().match(/(^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})(\-[0-9]{1,4})?$)/))&&!($(this).val().match(/^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/))){
			$(this).parents('p').addClass('error').append('<span class="errorInfoDiv">请输入有效联系方式</span>').find('.errorInfoDiv').css({paddingLeft:'20px'}).stop().animate({paddingLeft:0},200,'easeOutBounce')
			ok=false;
			return false;
		//zipcode
		}else if($(this).val()!=''&&$(this).hasClass('zipcode')&&!($(this).val().match(/^[0-9]{6}$/))){
			$(this).parents('p').addClass('error').append('<span class="errorInfoDiv">请输入有效邮政编码</span>').find('.errorInfoDiv').css({paddingLeft:'20px'}).stop().animate({paddingLeft:0},200,'easeOutBounce')
			ok=false;
			return false; 
		//nameEN
		}else if($(this).val()!=''&&$(this).hasClass('nameEN')&&!($(this).val().match(/^[\w]+([ ]?[\w]+)$/))){
			$(this).parents('p').addClass('error').append('<span class="errorInfoDiv">请输入英文字母、数字和下划线</span>').find('.errorInfoDiv').css({paddingLeft:'20px'}).stop().animate({paddingLeft:0},200,'easeOutBounce')
			ok=false;
			return false;
		//检查身份证号 
		}else if($(this).val()!='' && $(this).hasClass('idCard') && !isIdCardNo($(this).val())){
			$(this).parents('p').addClass('error').append('<span class="errorInfoDiv">请输入有效身份证号码</span>').find('.errorInfoDiv').css({paddingLeft:'20px'}).stop().animate({paddingLeft:0},200,'easeOutBounce')
			ok=false;
			return false; 
		//密码是否相等 
		}else if($(this).val()!='' && $(this).hasClass('equalTo')){
			var equaltoid=$(this).attr('equaltoid');
			if($(this).val()!=$("#"+equaltoid).val()){
				$(this).parents('p').addClass('error').append('<span class="errorInfoDiv">两次输入的密码不一致</span>').find('.errorInfoDiv').css({paddingLeft:'20px'}).stop().animate({paddingLeft:0},200,'easeOutBounce')
				ok=false;
				return false;  
			} 
		}else if($(this).attr('minlength')){//minlength
			if($(this).val().length<$(this).attr('minlength')){
				ok=false;
				$(this).parents('p').addClass('error').append('<span class="minLenDiv">请至少输入'+$(this).attr('minlength')+'个字符</span>').find('.minLenDiv').css({paddingLeft:'20px'}).stop().animate({paddingLeft:0},200,'easeOutBounce')
			}		
			posObj=$(this);
			return ok;
		}
		//validate end
	});
	return ok;
};

//检查身份证号
function isIdCardNo(num){
	num = num.toUpperCase();
	//身份证号码为15位或者18位，15位时全为数字，18位前17位为数字，最后一位是校验位，可能为数字或字符X。
	if (!(/(^\d{15}$)|(^\d{17}([0-9]|X)$)/.test(num))){
		return false;
	}
	//校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。
	//下面分别分析出生日期和校验位
	var len, re; len = num.length;
	if (len == 15){
		re = new RegExp(/^(\d{6})(\d{2})(\d{2})(\d{2})(\d{3})$/);
		var arrSplit = num.match(re);
		//检查生日日期是否正确
		var dtmBirth = new Date('19' + arrSplit[2] + '/' + arrSplit[3] + '/' + arrSplit[4]);
		var bGoodDay;
		bGoodDay = (dtmBirth.getYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4]));
		if (!bGoodDay){
			return false;
		} else{
			//将15位身份证转成18位
			//校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。
			var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
			var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
			var nTemp = 0, i;
			num = num.substr(0, 6) + '19' + num.substr(6, num.length - 6);
			for(i = 0; i < 17; i ++)
			{
				nTemp += num.substr(i, 1) * arrInt[i];
			}
			num += arrCh[nTemp % 11];
			return num;
		}
	}
	if (len == 18){
		re = new RegExp(/^(\d{6})(\d{4})(\d{2})(\d{2})(\d{3})([0-9]|X)$/);
		var arrSplit = num.match(re);  //检查生日日期是否正确
		var dtmBirth = new Date(arrSplit[2] + "/" + arrSplit[3] + "/" + arrSplit[4]);
		var bGoodDay;
		bGoodDay = (dtmBirth.getFullYear() == Number(arrSplit[2])) && ((dtmBirth.getMonth() + 1) == Number(arrSplit[3])) && (dtmBirth.getDate() == Number(arrSplit[4])); 
		if (!bGoodDay) {
			return false; 
		} else{
			//检验18位身份证的校验码是否正确。
			//校验位按照ISO 7064:1983.MOD 11-2的规定生成，X可以认为是数字10。
			var valnum;
			var arrInt = new Array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
			var arrCh = new Array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
			var nTemp = 0, i;
			for(i = 0; i < 17; i ++){ 
				nTemp += num.substr(i, 1) * arrInt[i]; 
			} 
			valnum = arrCh[nTemp % 11]; 
			if (valnum != num.substr(17, 1)) {
				return false;
			}
			return num;
		} 
	} 
	return false; 
}   


//console.log(str)
function setCookie(name,value)//两个参数，一个是cookie的名子，一个是值
{
    var Days = 30; //此 cookie 将被保存 30 天
    var exp  = new Date();    //new Date("December 31, 9998");
    exp.setTime(exp.getTime() + Days*24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
}

function getCookie(name)//取cookies函数        
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;
}
