/**
$(document).ready(function () {
	$("#succe").hide();
	if(userEmail==null || userEmail==""){
		window.location.href = '../index.jsp';
	}else{
		$("#username").val(username);
		$("#country").val(country);
		$("#sex").val(sex);
		$("#city").val(city);
		$("#zipcode").val(zipcode);
		$("#telephone").val(telephone);
		var datat = datatime.split('-');
		$("#year").val(datat[0]);
		$("#month").val(datat[1]);
		$("#day").val(datat[2]);
	}
	
});
function editinfo(){
		$("#succe").hide();
		var para = 'method=editprofile';
		para += "&username="+$.trim($("#username").val());
		para += "&sex="+$.trim($("#sex").val());
		para += "&country="+$.trim($("#country").val());
		para += "&city="+$.trim($("#city").val());
		para += "&zipcode="+$.trim($("#zipcode").val());
		para += "&month="+$.trim($("#month").val());
		para += "&day="+$.trim($("#day").val());
		para += "&year="+$.trim($("#year").val());
		para += "&telephone="+$.trim($("#telephone").val());
		$.post('../userManager.do', para, function (data) {
			if (data=="error") {
				alert("error");
			}else{
				$("#succe").show();
				$(".success").html("Success");
				
			} 
		});
}
**/
$(function(){
$("#editProfile").click(function(){
edit_user_profile();
});
});
function   edit_user_profile(){
var userId=$("#userId").text();
var userEmail=$("#editEmail").text();
var nickName=$("#nickName").val();
var validateCode=$("#validateCode").val();
var userName=$("#userName").val();
var userSex=$("#userSex").val();
var userCountry=$("#userCountry").val();
var userCity=$("#userCity").val();
var userTelephone=$("#userTelephone").val();
var zipcode=$("#zipcode").val();
var month=$("#month").val();
var day=$("#day").val();
var year=$("#year").val();
var birthday="";
if(year==""&&month==""&&day==""){
birthday="--";
}else if(year!=""&&month==""&&day==""){
birthday=year+"--";
}else if(year!=""&&month!=""&&day==""){
birthday=year+"-"+month+"-";
}else if(year!=""&&month!=""&&day!=""){
birthday=year+"-"+month+"-"+day;
}
if(nickName==""){
  $("#nicknameTip").html("Please Fill in Your Nick Name!");
  $("#nicknameTip").show("slow");
}else if(validateCode==""){
  $("#codeTip").html("Please Fill in Your Validation Code!");
  $("#nicknameTip").hide("slow");
  $("#codeTip").show("slow");
}else if(userName==""){
        $("#userNameTip").html("Please Fill in Your Full Name!");
        $("#nicknameTip").hide("slow");
        $("#codeTip").hide("slow");
}else if(userSex==""){
        $("#sexTip").html("Please Select Your Sex!");
        $("#userNameTip").html("");
        $("#nicknameTip").hide("slow");
         $("#codeTip").hide("slow");
}else if(userCountry==""){
        $("#countryTip").html("Please Select Your Country!");
        $("#sexTip").html("");
        $("#userNameTip").html("");
        $("#nicknameTip").hide("slow");
        $("#codeTip").hide("slow");
}else if(userCity==""){
        $("#cityTip").html("Please Fill in Your City!");
        $("#countryTip").html("");
        $("#sexTip").html("");
        $("#userNameTip").html("");
        $("#nicknameTip").hide("slow");
         $("#codeTip").hide("slow");
 }else if(userTelephone=="Plaese Fill in Your Phone Num"){
        $("#phoneNumTip").html("");
        $("#cityTip").html("");
        $("#countryTip").html("");
        $("#sexTip").html("");
        $("#userNameTip").html("");
        $("#nicknameTip").hide("slow");
        $("#codeTip").hide("slow");
}else{
        finish_edit_profile(userId,userEmail,nickName,validateCode,userName,userSex,userCountry,userCity,userTelephone,zipcode,birthday);
}

}


function  finish_edit_profile(userId,userEmail,nickName,validateCode,userName,userSex,userCountry,userCity,userTelephone,zipcode,birthday){
var editURL="../user/edit_user_profile.jsp";
$.ajax({
type:"post",
url:editURL,
data:{userId:userId,userEmail:userEmail,nickName:nickName,validateCode:validateCode,userName:userName,userSex:userSex,userCountry:userCountry,userCity:userCity,userTelephone:userTelephone,zipcode:zipcode,birthday:birthday},
success:function(msg){
var result=$.trim(msg);
if(result.indexOf("Error1")!=-1){
alert("Time Out, Please your Login again!");
document.location.reload();
}else{
if(result=="V_CODE_NO"){
$("#codeTip").html("Validation Code isn't Valid,Please try again!");
$("#codeTip").fadeIn("slow");
}else{
   alert("Edit Success!");
   $("#codeTip").fadeOut("slow");
   window.location.href=document.location.href;
}
}
}
});
}


function   set_select_value(id,value){
$("#"+id+" option").each(function(index){
      if($.trim($(this).val())==$.trim(value)){
         $(this).attr("selected","selected");
      }
});
}
