$(document).ready(function() {
	
	$('#changesecurity').click( function(){
		var SID = Math.round(Math.random()*(9999-1000) + 1000);
		$('#securityimgdiv').html('<img id="securityimg" src="class/jpgraph/antispamex.php?rand='+SID+'" align="absmiddle" />');	
	});
	
});

function login(){
	if($("#username").val()==""){
	    alert('请输入你的帐号!');	
		return false;
	}

    if($("#password").val()==""){
	    alert('请输入你的密码!');
		return false;
	}
	$.post("login.php",{m:"checklogin", username: $("#username").val(), password: $("#password").val(),remember:$("input[@name=remember][@checked]").val() }, function(data){
		if(data=="ok"){
			location.href='login-choose.php';
		}else{
			alert(data);
		}
    }
  );
}


function savewall() {
    if($("#wallcontent").val()==""){
	    $("#showmessage").html("<div id='error'><h1>不写点什么吗？</h1></div>");	
		return false;
	}
	var appendid='';
	$.post("profile.php",{m:"savewall", wallcontent: $("#wallcontent").val(), wuid: $("#wuid").val() }, function(data){	
		    $($("#wallpost").children('div')).each(function(i){if(i==0){appendid=this.id}});
			$("#"+appendid).before(data);
			$("#wallcontent").val('');
      }
  );
}

function savewall_content() {
    if($("#wallcontent").val()==""){
	    $("#showmessage").html("<div id='error'><h1>不写点什么吗？</h1></div>");	
		return false;
	}
	var appendid='';
	$.post("profile.php",{m:"savewall_content", wallcontent: $("#wallcontent").val(), wuid: $("#wuid").val() }, function(data){	
			$($("#wallpost").children('div')).each(function(i){if(i==0){appendid=this.id}});
			$("#"+appendid).before(data);
			$("#wallcontent").val('');
      }
  );
}

function delwall(a) {
	  $("#c_"+a).hide();
      $.post("profile.php",{m:"delwall", delid:a}, function(data){	
			 }
	   );
}

function ismail(mail){ 
	return(new RegExp(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(mail));
} 

function iswebsite(website){ 
	return(new RegExp(/^http:\/\/.*?([com|net|cn|org]){1}(\/.*)?$/).test(website));
} 

function reg(){

	if($("#data_username").val()=="" || $("#data_password").val()=="" || $("#data_email").val()==""){
	    $("#showmessage").html("<div id='error'><h1>你需要全部填写完毕!</h1></div>");	
		return false;
	}
	
	if($("#data_username").val().length>15){
	    $("#showmessage").html("<div id='error'><h1>用户错误!</h1></div>");	
		return false;
	}
	
	if($("#data_password").val().length<6 || $("#data_password").val().length>12 ){
	    $("#showmessage").html("<div id='error'><h1>密码错误!</h1></div>");	
		return false;
	}
/**
	if($("#data_password").val()!=$("#password1").val()){
	    $("#showmessage").html("<div id='error'><h1>Confirm Password Error!</h1></div>");	
		return false;
	}
**/	
	if(!ismail($("#data_email").val())){
	    $("#showmessage").html("<div id='error'><h1>邮箱错误!</h1></div>");	
		return false;
	}
	
    if($("#data_sex")[0].checked){
		var sexvalue=1;
	}else{
		var sexvalue=0;
	}
/**	
    if(!($("#check")[0].checked)){
		$("#showmessage").html("<div id='error'><h1>Check Error!</h1></div>");	
		return false;
	}else{
	    var checkvalue=1;	
	}	
**/	
	$.post("reg.php",{m:"savemember", data_username: $("#data_username").val(), data_email: $("#data_email").val() ,password: $("#data_password").val() ,data_portrait:$("#data_portrait").val(),data_sex:sexvalue, birthday_month: document.getElementById('birthday_month').value,birthday_day:document.getElementById('birthday_day').value,birthday_year: document.getElementById('birthday_year').value,data_country: document.getElementById('data_country').value, VerificationCode:$("#VerificationCode").val(), data_referred: $("#data_referred").val()}, function(data){
		if(data=="ok"){
			location.href='login-choose.php';
		}else{
			$("#showmessage").html(data);
		}
    }
  );
}

function checkIsFloat(inputval){
		return(new RegExp(/^-?([1-9]*|0)(\.\d*)?$/g).test(inputval));
  }

function updatedata(){
	//alert(document.getElementById('birthday_year').value);
	
	if($("#data_password").val()!=""){
		if($("#data_password").val().length<6 || $("#data_password").val().length>12 ){
	    	$("#showmessage").html("<div id='error'><h1>密码必须在6-12位!</h1></div>");	
			return false;
		}
	}
	
	if(!ismail($("#data_email").val())){
	    $("#showmessage").html("<div id='error'><h1>请输入正确的邮件格式!</h1></div>");	
		return false;
	}
	
	if($("#data_zip").val()!="" && !checkIsFloat($("#data_zip").val())){
	    $("#showmessage").html("<div id='error'><h1>请输入正确的邮政编码格式!</h1></div>");	
		return false;
	}
	
	if($("#data_website").val()!="" && !iswebsite($("#data_website").val())){
	    $("#showmessage").html("<div id='error'><h1>请输入正确的个人主页格式!</h1></div>");	
		return false;
	}
	
	
	if($("#data_sex")[0].checked){
		var sexvalue=1;
	}else
	{
		if($("#vv_sex").val() == 1)
		{
			var sexvalue=1;
		}else{
			var sexvalue=0;
		}
	}

	$.post("editprofile.php",{m:"update", data_email: $("#data_email").val() ,password: $("#data_password").val() ,data_portrait:$("#data_portrait").val(),data_sex:sexvalue, birthday_month: document.getElementById('birthday_month').value,birthday_day: document.getElementById('birthday_day').value,birthday_year: document.getElementById('birthday_year').value, data_zip:$("#data_zip").val(),data_website:$("#data_website").val(),data_mobilephone:$("#data_mobilephone").val(),data_landphone:$("#data_landphone").val(),data_address:$("#data_address").val(),data_city:$("#data_city").val()}, function(data){
		if(data=="ok"){
			location.href='profile.php';
		}else{
			$("#showmessage").html(data);
		}
    }
  );
}

function show2(a){

   if(a=="1"){
 
		$("#sign_boy").animate({ opacity: 'show'}, 'slow');
		$("#sign_girl").hide();

   }else{

		$("#sign_boy").hide();   
		$("#sign_girl").animate({ opacity: 'show'}, 'slow');

   }
}

function showabout(afile,va)
{
	$("#show_about_header").load('template/header/'+afile+'.html');
	$("#temp_set").val(va);
}
function showaboutgirl(afile,va)
{

	$("#show_about_header_girl").load('template/header/'+afile+'.html');
	$("#temp_set").val(va);
}

function confirmabout()
{
	$("#sign_boy").animate({ opacity: 'hide'}, 'slow');
    $("#sign_girl").animate({ opacity: 'hide'}, 'slow');
	var slectva = $("#temp_set").val();
	$("#data_portrait").val(slectva);

}


function showface(id,src,closeid){
	if(closeid=="boy_header"){
  $("#"+id).html("<img src=\"template/img/header/"+src+"\" width=\"16\" height=\"16\"  onclick=\"show('1')\" style=\"cursor:hand\">");
	}else{
		$("#"+id).html("<img src=\"template/img/header/"+src+"\" width=\"16\" height=\"16\"  onclick=\"show('0')\" style=\"cursor:hand\">");
	}
  $("#data_portrait").val(src);
  $("#"+closeid).hide();
}

function upload(a){
	if(a==1){
	if($("#uploadpic").val()!=""){
    	if(!($("#checkpic")[0].checked)){
				$("#showmessage").html("<div id='error'><h1>检查错误!</h1></div>");	
				return false;
		 }else{
			document.getElementById('edit1').target="uploadif";
			document.getElementById('edit1').action="editprofile.php?m=1";
			document.getElementById('edit1').submit();
		 }
	}else{
		$("#showmessage").html("<div id='error'><h1>请选择要上传的图片!</h1></div>");
		return false;
	}
	}else{
		document.getElementById('edit1').target="uploadif";
		document.getElementById('edit1').action="editprofile.php?m=2";
		document.getElementById('edit1').submit();
	}
}


function delfeed(a) {
    $("#s_"+a).hide(); 
	 $.post("profile.php",{m:"delfeed", id:a}, function(data){
		 if(data == "ok")
		{
			window.location.reload();
		}		 
	 }
	);
}


function inputshoutoutadd()
{
	$("#inputshoutoutadd").animate({ opacity: 'show'}, 'slow');

}
function inputshoutoutedit()
{
	$("#inputshoutoutedit").animate({ opacity: 'show'}, 'slow');

}

function saveshoutout() {
    if($("#shoutoutscontent").val()==""){
	    $("#inputshoutoutmsg").html("No Shout-Out text entered!");	
		return false;
	}

	$.post("profile.php",{m:"saveshoutout", shoutoutscontent: $("#shoutoutscontent").val(), sid: $("#shoutoutsid").val() }, function(data){	
		if(data == "ok")
		{
			window.location.reload();
		}else{
			$("#inputshoutoutmsg").html("Error!");	
		}
      }
  );
}


function reg1(){

	if($("#username").val()==""){
	    $("#showmessage_account").html("<div id='error' style='color:#FF0000; font-size:14px;display:inline; margin-left:20px;'>请输入VV龙帐号！</div>");	
		return false;
	}

	// 检查是否为中文
	var strC = $("#username").val();
	var number_chars = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_";
	var i;
	for (i=0;i<strC.length;i++)
	{
		if (number_chars.indexOf(strC.charAt(i))==-1)
		{
			$("#showmessage_account").html("<div id='error' style='color:#FF0000; font-size:14px;display:inline; margin-left:20px;'>VV龙帐号不能含有中文及特殊字符！</div>");	
			return false;
		}
	}

	if($("#username").val().length>12 || $("#username").val().length<3){
	    $("#showmessage_account").html("<div id='error' style='color:#FF0000; font-size:14px;display:inline; margin-left:20px;'>VV龙帐号只能是3-12位的英文或者数字！</div>");	
		return false;
	}

	//禁止注册含有"travel"的帐号
	var str1 = $("#username").val();
		str1 = str1.toLowerCase();
	var str2 = 'travel';
	var str3 = 'vvdragon';
	var finded  = str1.indexOf(str2);
	var finded2 = str1.indexOf(str3);

	if(finded !="-1"){
	    $("#showmessage_account").html("<div id='error' style='color:#FF0000; font-size:14px;display:inline; margin-left:20px;'>VV龙帐号不可以含有travel字眼！</div>");	
		return false;
	}

	if(finded2 !="-1"){
	    $("#showmessage_account").html("<div id='error' style='color:#FF0000; font-size:14px;display:inline; margin-left:20px;'>VV龙帐号不可以含有vvdragon字眼！</div>");	
		return false;
	}

    $("#showmessage_account").html("由3－12位字母或数字组成");	

	if($("#nickname").val().length>8 || $("#nickname").val() ==""){
	    $("#showmessage_nickname").html("<div id='error' style='color:#FF0000; font-size:14px;display:inline; margin-left:20px;'>昵称必须是1-8位的中文，英文或者数字！</div>");	
		return false;
	}

	//禁止注册含有"travel"的帐号
	var str11 = $("#nickname").val();
		str11 = str11.toLowerCase();
	var str12 = 'vv龙';
	var finded3 = str11.indexOf(str12);

	if(finded3 !="-1"){
	    $("#showmessage_nickname").html("<div id='error' style='color:#FF0000; font-size:14px;display:inline; margin-left:20px;'>昵称不可以含有'vv龙'字眼！</div>");	
		return false;
	}

	$("#showmessage_nickname").html("在游戏中显示的名字");	

	if($("#password").val().length>16 || $("#password").val().length<6){
	    $("#showmessage_psw").html("<div id='error' style='color:#FF0000; font-size:14px;display:inline; margin-left:20px;'>请输入6-16位的密码！</div>");	
		return false;
	}

	if($("#password").val() != $("#confirm_password").val()){
	    $("#showmessage_psw").html("<div id='error' style='color:#FF0000; font-size:14px;display:inline; margin-left:20px;'>两次输入的密码要保持一致哦！</div>");	
		return false;
	}

	/*if(!/\w+@\w+(\.\w+)+/ig.test($("#email").val())){
	    $("#showmessage").html("<div id='error' style='color:#FF0000; font-size:14px'>请输入正确的邮箱地址！</div>");
		return false;
	}*/

	$("#showmessage_psw").html("由6－16位字母或数字组成");	

	if($("#license").attr("checked") != true){
	    $("#showmessage").html("<div id='error' style='color:#FF0000; font-size:14px;display:inline; margin-left:20px;'>只有同意VV龙世界守则，才能注册！</div>");
		return false;
	}
	
	$("#showmessage").html("");	

	$.post("signup_2.php",{m:"next", username: $("#username").val(),nickname: $("#nickname").val(), email: $("#email").val() ,password: $("#password").val()}, function(data){
		if(data=="account_exist"){
			$("#showmessage_account").html("<div id='error' style='color:#FF0000; font-size:14px;display:inline; margin-left:20px;'>此帐号已存在，请换名再试！</div>");	
		}
		if(data=="nickname_exist"){
			$("#showmessage_nickname").html("<div id='error' style='color:#FF0000; font-size:14px;display:inline; margin-left:20px;'>此昵称已存在，请换名再试！</div>");	
		}
		if(data=="email_exist"){
			$("#showmessage_email").html("<div id='error' style='color:#FF0000; font-size:14px;display:inline; margin-left:20px;'>此邮箱已使用，请换个再试！</div>");	
		}
		if(data=="ok"){
			location.href='signup_2.php';
		}
    }
  );
}

function reg2(){

	if($("#selectheaderimg").val()==""){
	    $("#showmessage").html("<div id='error' style='color:#FF0000'><h3>请选择一个你喜欢的VV龙作为你的角色！</h3></div>");	
		return false;
	}
	

	$.post("signup_3.php",{m:"next", selectheaderimg: $("#selectheaderimg").val()}, function(data){
		if(data=="ok"){
			location.href='signup_3.php';
		}else{
			$("#showmessage").html(data);
		}
    }
  );
}

function reg3(){

	if($("#selectroomimg").val()==""){
	    $("#showmessage").html("<div id='error' style='color:#FF0000'><h3>请选择一个你喜欢的房间！</h3></div>");	
		return false;
	}

	$("#showmessage").html("<div id='error' style='color:#FF0000'><h3>请稍等,别关闭此页面！</h3></div>");

	/*$.post("signup_4.php",{m:"next", selectroomimg: $("#selectroomimg").val()}, function(data){
		if(data=="ok"){
			$("#showmessage").html("<div id='error' style='color:#FF0000'><h3>确认信已经成功发送到你的邮箱了！</h3></div>");
		}else{
			$("#showmessage").html("<div id='error' style='color:#FF0000'><h3>注册失败，请稍后再试或者与我们联系！</h3></div>");
		}
    }*/

	$.post("signup_4.php",{m:"next", selectroomimg: $("#selectroomimg").val()}, function(data){
		//alert(data);
		if(data=="ok1"){
			window.location.href="newer-choose.php";
		}
		if(data=="ok2"){
			window.location.href="newer-choose.php";
		}
    }
  );
}

function confirmheader(imgsrc)
{
	$("#selectheaderdiv").animate({ opacity: 'show'}, 'slow');
	//$("#htmlheaderiimg").html = '<img id="selectheader" name="selectheader" src="template/header/'+imgsrc+'" width="104" height="135" />';
	document.getElementById('htmlheaderiimg').innerHTML = '<img id="selectheader" name="selectheader" src="template/header/'+imgsrc+'" width="104" height="135" />';
	$("#selectheaderimg").val(imgsrc);
	//alert($("#selectheaderimg").val());

}

function confirmroom(imgsrc)
{
	$("#selectheaderdiv").animate({ opacity: 'show'}, 'slow');
	//$("#htmlheaderiimg").html = '<img id="selectheader" name="selectheader" src="template/header/'+imgsrc+'" width="104" height="135" />';
	document.getElementById('htmlheaderiimg').innerHTML = '<img id="selectheader" name="selectheader" src="template/rooms/'+imgsrc+'" />';
	$("#selectroomimg").val(imgsrc);
	//alert($("#selectheaderimg").val());

}

$(document).ready(function() {
	$('#clicknotes').toggle(function(){
		 $("#clicknotes").attr({ src: "template/img/three1.gif"});
		 $("#Notes").animate({
  				opacity: 'hide'
			}, 'slow');
	},function(){
		$("#clicknotes").attr({ src: "template/img/three.gif"});
		$("#Notes").animate({
			opacity: 'show'
			}, 'slow');
	});

	$('#clickminifeed').toggle(function(){
		 $("#clickminifeed").attr({ src: "template/img/three1.gif"});
		 $("#MiniFeed").animate({
  				opacity: 'hide'
			}, 'slow');
	},function(){
		$("#clickminifeed").attr({ src: "template/img/three.gif"});
		$("#MiniFeed").animate({
			opacity: 'show'
			}, 'slow');
	});

	$('#clickinfomation').toggle(function(){
		 $("#clickinfomation").attr({ src: "template/img/three1.gif"});
		 $("#Information").animate({
  				opacity: 'hide'
			}, 'slow');
	},function(){
		$("#clickinfomation").attr({ src: "template/img/three.gif"});
		$("#Information").animate({
			opacity: 'show'
			}, 'slow');
	});

	$('#clickthewall').toggle(function(){
		 $("#clickthewall").attr({ src: "template/img/three1.gif"});
		 $("#TheWall").animate({
  				opacity: 'hide'
			}, 'slow');
	},function(){
		$("#clickthewall").attr({ src: "template/img/three.gif"});
		$("#TheWall").animate({
			opacity: 'show'
			}, 'slow');
	});
	
	$('#buttom_basic').click(function(){
		 $('#buttom_basic').html('<div class="albums_menu_div"><img src="template/img/left_photo_title.gif"></div><div class="albums_menu_center_div">基本资料</div><div class="albums_menu_div"><img src="template/img/right_photo_title.gif"></div>');
		 $('#buttom_contact').html('<div class="albums_menu_div"><img src="template/img/left_photo_title1.gif"></div><div class="albums_menu_center_div1"><a href="#">联系方式</a></div><div class="albums_menu_div"><img src="template/img/right_photo_title1.gif"></div>');
		 $('#buttom_picture').html('<div class="albums_menu_div"><img src="template/img/left_photo_title1.gif"></div><div class="albums_menu_center_div1"><a href="#">头像</a></div><div class="albums_menu_div"><img src="template/img/right_photo_title1.gif"></div>');
		 
		 $("#edit_basic").css({ display: ""});
		 $("#edit_contact").css({ display: "none"});
		 $("#edit_picture").css({ display: "none"});
		 $("#savechange").show();
	});
	
	$('#buttom_contact').click(function(){
		 $('#buttom_basic').html('<div class="albums_menu_div"><img src="template/img/left_photo_title1.gif"></div><div class="albums_menu_center_div1"><a href="#">基本资料</a></div><div class="albums_menu_div"><img src="template/img/right_photo_title1.gif"></div>');
		 $('#buttom_contact').html('<div class="albums_menu_div"><img src="template/img/left_photo_title.gif"></div><div class="albums_menu_center_div">联系方式</div><div class="albums_menu_div"><img src="template/img/right_photo_title.gif"></div>');
		 $('#buttom_picture').html('<div class="albums_menu_div"><img src="template/img/left_photo_title1.gif"></div><div class="albums_menu_center_div1"><a href="#">头像</a></div><div class="albums_menu_div"><img src="template/img/right_photo_title1.gif"></div>');
 
		 $("#edit_basic").css({ display: "none"});
		 $("#edit_contact").css({ display: ""});
		 $("#edit_picture").css({ display: "none"});
		 $("#savechange").show();
	});
	
	$('#buttom_picture').click(function(){
		 $('#buttom_basic').html('<div class="albums_menu_div"><img src="template/img/left_photo_title1.gif"></div><div class="albums_menu_center_div1"><a href="#">基本资料</a></div><div class="albums_menu_div"><img src="template/img/right_photo_title1.gif"></div>');
		 $('#buttom_contact').html('<div class="albums_menu_div"><img src="template/img/left_photo_title1.gif"></div><div class="albums_menu_center_div1"><a href="#">联系方式</a></div><div class="albums_menu_div"><img src="template/img/right_photo_title1.gif"></div>');
		 $('#buttom_picture').html('<div class="albums_menu_div"><img src="template/img/left_photo_title.gif"></div><div class="albums_menu_center_div">头像</div><div class="albums_menu_div"><img src="template/img/right_photo_title.gif"></div>');
		 
		 $("#edit_basic").css({ display: "none"});
		 $("#edit_contact").css({ display: "none"});
		 $("#edit_picture").css({ display: ""});
		 $("#savechange").hide();
	});

});
