$(function() {
	var value = 2;
	var O_C_Types = $("#O_C_Types");
	var O_C_Names = $("#O_C_Names");
	var O_C_Name = $("#O_C_Name");
	var question_submit = $("#question_submit");
	var question_title = $("#question_title");
	var question_content = $("#question_content");
	var visa_id = $("#visa_id").attr('value');
	var book_submit = $("#book_submit");
	
	$(".visa_left_title li").bind("click",function(i){

		$(".on").attr('class' , '');	
		$('#content_'+value).hide();
		
		value = $(this).attr('value');
		$(this).attr('class' , 'on');	
		
		$('#content_'+value).show();
		
		
	});
	
	book_submit.click(function(){
		var adult = $('#adult').attr('value');
		var children = $('#children').attr('value');
		
		
		$('#visa_frm').submit();						   
    });
	
	question_submit.click(function(){
								   
			
		var content = $("#question_content").attr('value');
		var title = $("#question_title").attr('value');
		
		var v_account = $("#member_account").attr('value');
		var v_password = $("#password").attr('value');
		
		var O_Valid = $("#valid");
		var v_valid = O_Valid.val();
		
	/*	if(title == '' || title == '标题')
		{
			alert('请输入标题');	
			$("#question_title").select();
			return;
		}*/
		
		if(content == '' || content == '内容')
		{
			alert('请输入内容');	
			$("#question_content").select();
			return;
		}
		
		if(v_valid == '')
		{
			alert('请输入验证码');	
			$("#valid").select();
			return;
		}
		
		if(v_account != '' && v_password != '')
		{
		
			//登陆
			$.post(basePath + "?m=login.check",{ account:v_account, password:v_password, valid:v_valid, isSetCookieDate:1 }, function(data) {
																																				

					if(data[0] == "success")
					{		
						var member_id = data[1];
					
						$.post(root + "?m=visa.addQuestion", { valid:v_valid , title:title , content:content , visa_id:visa_id , member_id:member_id}, function(data) {
																																	
							var ary = eval("(" + data + ")");
							if(ary[0] == 'success')
							{
								alert('发问成功,请等待回复');	
								location.reload();
								
							}else{
								alert(ary[1]);	
								return;
							}
						});
						
					}else{
						
						return;
					}
					return;
		
			return;
		}, "json");
		}else{
					
			$.post(root + "?m=visa.addQuestion", { valid:v_valid , title:title , content:content , visa_id:visa_id , member_id:0}, function(data)
			{																										
				var ary = eval("(" + data + ")");
				if(ary[0] == 'success')
				{
					alert('发问成功,请等待回复');	
					location.reload();
				}else{
					alert(ary[1]);	
					return;
				}
			});
		}
		
		
	});							   
	
		//国家名的搜索
	O_C_Names.change(function() {

		var text= O_C_Names.find("option:selected").text(); 
		var value = O_C_Names.attr('value');
		var str = '';
		
		
		text = text.substr(3,text.length).replace(/\s+/g,""); 
		O_C_Name.attr('value' , text);
		
		
		
		$.post(root + "?m=visa.getVisaType", { countryid:value }, function(data) {
			
			var ary = eval("(" + data + ")");
			for(var i=0 ; i < ary.length ; i++)
			{
				str += '<option value="'+ ary[i]['id'] +'">' + ary[i]['name'] + '</option>';	
			}
			O_C_Types.html(str);

		});
	}); 
	
	function change_text_fontcolor(obj)
	{
		obj.css("color","#000000");
	}
	
	question_title.keydown(function() {
		change_text_fontcolor(question_title);				   
  	});
	
	question_content.keydown(function() {
		change_text_fontcolor(question_content);				   
  	});
	
	question_content.focus(function(){
		var value = question_content.attr('value');
		if(value == '内容')
		{
			question_content.attr('value' , '');	
		}
	});
	
	question_content.blur(function(){
		var value = question_content.attr('value');
		if(value == '')
		{
			question_content.attr('value' , '内容');	
		}
	});
	
	$('.question_title').each(function(i){
		$(this).click(function(){
			var id = $('.question_content')[i].id;
			$('#'+id).toggle();
			
		});
   });
	

}); 


