// JavaScript Document 
var temp_a = parseInt(Math.random()*10);
var temp_b = parseInt(Math.random()*10);	
$(function(){
		/**
		* Mian Area width adapt 
		* @ author zhaiyu
		* @ date 2009.11.21
		* user client pixel different can show us a different width 
		* and elements always center
		*/	
		var fullwidth = window.screen.availWidth;   
		if(fullwidth>=1280){  
			//let elements center(1280 -950)/2;   
			$(".fillReq").css("margin-left",590);  
			$(".position").css("margin-left",165); 
			$(".caseIntro").css("margin-left",165);  
			$("#tabs").css("margin-left",165); 
		} 
		
		//change the small direction icon opacity
		$(".towards").animate({opacity:0.6}, 0); 
		
		/**
		 *	when focus blogdetial input box initialize the value to ""
		 */
		$("input[name='username']").focus(function(){ 	
			$(this).css("color","#999");
			var username = $.trim($(this).val()); 
			if(username=="姓名"){
				$(this).val("");    
			} 
		});	
		
		$("input[name='email']").focus(function(){ 	
			$(this).css("color","#999");
			var email = $.trim($(this).val()); 
			if(email=="Email"){
				$(this).val("");    
			} 
		});	
		
		$("input[name='website']").focus(function(){ 	
			$(this).css("color","#999");
			var website = $.trim($(this).val());  
			if(website=="website"){
				$(this).val("");  
			} 
		});	
 
 		/**
		 *	when .subButton click check the form value
		 */
		$(".submit").click(function(){  
			//获取表单数据
			var username = $.trim($("input[name='username']").val());  
			var email = $.trim($("input[name='email']").val()); 
			var code = $.trim($("input[name='code']").val()); 
			var content = $.trim($(".content").val());  
			
			//表单数据验证
			if(username.length==0||username=="姓名"){
				$("input[name='username']").css("border","1px red solid"); 
				return false;
			}else{
				$("input[name='username']").css("border","1px #ccc solid"); 
			} 
			 
			if(email.length==0||email=="Email"){
				$("input[name='email']").css("border","1px red solid"); 
				return false;
			}else{
				$("input[name='email']").css("border","1px #ccc solid"); 
			}
			 
			if (email.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1){
				$("input[name='email']").css("border","1px red solid"); 
				return false;
			}else{
				$("input[name='email']").css("border","1px #ccc solid"); 
			}
			
			if(content.length==0||email==""){
				$(".content").css("border","1px red solid"); 
				return false;
			}else{
				$(".content").css("border","1px #ccc solid"); 
			} 
			
			if(code==(temp_a+temp_b)){
				$('#code').css("border","solid #ccc 1px");
			}else{
				$('#code').css("border","solid red 1px");	
				return false;
			}  
			
			/*$.ajax({       
						type:"POST",
						url:"http://127.0.0.1:8080/PeugeotRace/MgmtLoginServlet.do?action=add",				       
						data:"content="+content,
						success:function(msg){  
							$("#tips").css("color", "red"); 
							$("#tips").html(msg);  
						}    
			});*/ 
		});
});		
