// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

// select forum class


function select_forum() {
	
	if ($("forum_tag").value == "0") {
		update("forum_class", "/forums/show_class?fourm_class=0");
		$("forum_class").style.display = "";

	}else if ($("forum_tag").value == "1") {
		update("forum_class", "/forums/show_class?fourm_class=1");
		$("forum_class").style.display = "";

	}else if ($("forum_tag").value == "2") {
		update("forum_class", "/forums/show_class?fourm_class=2");
		$("forum_class").style.display = "";
	}
	else {
		$("forum_class").style.display = "none";

	}

}

function update(div, fun) {
	new Ajax.Updater(div, fun, {asynchronous:true, evalScripts:true, onComplete:function(request){Element.hide('loading_image')}, onLoading:function(request) { Element.show('loading_image')}});
		return false;
}
function select_location() {
	area_id = $("forum_area_id").value;
	if (area_id != "") {
		update("location", "/forums/show_location?area_id="+area_id);

	}
	else {
		$("forum_class").innerHTML = " ";

	}

}

function commentAdded(request) {
  Element.cleanWhitespace('forum_title');
  new Effect.BlindDown($('forum_title').lastChild);
  $('replyform').elements["forum_reply_content"].value = '';
  window.location.href = "#show_reply";
  $("errors").innerHTML = "<font color='red'>Reply Successfully!</font>"; 
}

function commentAdded_guestbook(request) {

  $('replyform').elements["guestbook_content"].value = '';
  window.location.href = "#show_reply";
  $("errors").innerHTML = "<font color='red'>Reply Successfully!</font>"; 
}


function comment_commentAdded() {
  Element.cleanWhitespace('journal_comment_title');
  Element.cleanWhitespace('journal_comment_content');
  new Effect.BlindDown($('journal_comment_title').lastChild);
  $('commentform').elements["journal_comment_content"].value = '';
  window.location.href = "#show_reply";
  $("errors").innerHTML = "<font color='red'>Comment Is successful!</font>"; 
}	



function failure(request) {
  $('errors').innerHTML = request.responseText;
  new Effect.Highlight('errors');
}

function loading() {
  $('replySubmit').disabled = true;
  Element.show('loading_image');
}

function complete(request) {
  Element.hide('loading_image');
  Element.show('replyform');
  $('replySubmit').disabled = false; 
  if (request.status == 200) { commentAdded() };  
}

function complete_guestbook(request) {
  Element.hide('loading_image');
  Element.show('replyform');
  $('replySubmit').disabled = false; 
  if (request.status == 200) { commentAdded_guestbook() };  
}
function complete_book_request(request) {
  Element.hide('loading_image');
  Element.show('replyform');
  $('replySubmit').disabled = false; 
  if (request.status == 200) { commentAdded_book_request() };  
}

function commentAdded_book_request() {
	$('replyform').elements["request_message_content"].value = '';
  	window.location.href = "#show_reply";
  	//$("errors").innerHTML = "<font color='red'>Reply Successfully!</font>"; 
	alert('Message Sent!');
}

function complete_journal_comment(request) {
	Element.hide('loading_image');
  Element.show('replyform');
  $('replySubmit').disabled = false; 
  if (request.status == 200) { commentAdded_journal_comment() }; 
}

function commentAdded_journal_comment() {
	$('replyform').elements["journal_comment_content"].value = '';
  	window.location.href = "#show_reply";
  	$("errors").innerHTML = "<font color='red'>Reply Successfully!</font>"; 
}

function complete_journal_note(request) {
  Element.hide('loading_image');
  Element.hide('new_note');
  $('replySubmit').disabled = false; 
  if (request.status == 200) { commentAdded_journal_note() }; 	
}

function commentAdded_journal_note() {
	$('replyform').elements["journal_comment_content"].value = '';
  	window.location.href = "#show_reply";
  	$("errors").innerHTML = "<font color='red'>Reply Successfully!</font>"; 
}


function comment_complete(request) {
  Element.hide('loading_image');
  Element.show('commentform');
  $('replySubmit').disabled = false; 
  if (request.status == 200) { comment_commentAdded() }; 

}
function checknewforumform() {
	
	if ($("forum_tag").value == "" || $("forum_tag").value.length == 0) {
		alert("Please select a category");
        $("forum_tag").focus();
        return false;

	} else if ($("forum_tag").value != "" && $("forum_tag").value.length > 0){
		if ($("forum_tag").value == "0") {
			if ($("forum_area_id").value == "" || $("forum_area_id").value.length == 0) {
			alert("Please select a area");
        	$("forum_area_id").focus();
        	return false;

		} else if ($("forum_location_id").value == "" || $("forum_location_id").value.length == 0) {
				alert("Please select a country");
        		$("forum_location_id").focus();
        		return false;
	      }

	} else if ($("forum_tag").value == "1") {
		if ($("forum_travel_class_id").value == "" || $("forum_travel_class_id").value.length == 0) {
			alert("Please select a category");
        	$("forum_travel_class_id").focus();
        	return false;

		}

	}
	

  } if ($("forum_title").value == "" || $("forum_title").value.length == 0) {
  		alert("Please enter a title");
        $("forum_title").focus();
        return false;

  }else if ($("forum_content").value == "" || $("forum_content").value.length == 0) {
  		alert("It can't be empty");
        $("forum_content").focus();
        return false;
	}
   else {
        return true;
    }

}

function checkreplyform() {
	if ($("forum_reply_content").value == "" || $("forum_reply_content").value.length == 0) {
		alert("It can't be empty");
        $("forum_reply_content").focus();
        return false;

	}

}

function checkcommentform() {
		
	 if (trimString($("journal_comment_content").value) == "" || trimString($("journal_comment_content").value).length == 0) {
		alert("It can't be empty");
		$("journal_comment_content").focus();
		return false;

	} 
	
}

//检查上传图片表单
function check_pic_form() {
	pic = trimString($("journal_pic_picture").value);
	if (trimString($("journal_pic_title").value) == "") {
		alert("Please enter a title");
		$("journal_pic_title").focus();
		return false;
	}
	if (pic == "") {
		alert("Please choose a picture");
		$("journal_pic_picture").focus();
		return false;
	}
	if (pic.length > 0) {
	len = pic.substr(pic.length-4);
	
	if (len != ".png" && len != ".PNG" && len != ".jpg" && len != ".jpeg" && len != ".JPG" && len != ".gif" && len != ".GIF") {
		alert("PNG JPG GIF formats only");
		$("journal_pic_picture").focus();
		return false;
	}
	}
}



function submitsearchform() {
	if ($("search").value != "") {
		document.searchform.submit();
	}
	
	

}

function show_div(div) {
	$(div).style.display = "block";
}
function hide_div(div) {
	$(div).style.display = "none";
}
function show_change(city) {
	$("search").value = city;
	$('change_location').show();
	$('search').readOnly=true;


}
function change_location() {
    $('search').value = "";
    $('change_location').hide();
	$("add_location").style.display = "none";
	$("add_location_say").style.display = "none";
	$("add_state").style.display = "none";
	$("add_state_say").style.display = "none";
    $('search').readOnly=false;
}
	  
function observe_search(search) {
	tag = document.search_city.tag.value;
	if (tag == 1) {
		$("add_location").style.display = "none";
		$("add_state").style.display = "none";

	}
	if (search.indexOf(",") > 0) {
		search = search.substring(0, search.indexOf(",")-1);
	}
	if (trimString($("search").value) == "" || trimString($("search").value).length == 0) {
    	$("live_message").style.display = "none";
	} else {
		update_search("live_message", "/admin/search_city?search="+search+"&tag="+tag);
	}
}
function update_search(div, fun) {	
	new Ajax.Updater(div, fun, {asynchronous:true, evalScripts:true, onComplete:function(request){Element.hide('search_spinner');show_div('live_message');},onLoading:function(request) { Element.show('search_spinner')}});
	return false;
}
function show_msg(div, key) {
	$(div).innerHTML = "Sorry, no match city here, please check again or you want to add "+key+" to our city lists?";
}
function show_location(city) {
	update("show_city", "/admin/show_location?city="+city);
}
function av_submit() {
	search = $("search").value;
	start_time = $("start_time").value;
	end_time = $("end_time").value;
	if (search == "" || search.length == 0) {
		$("search_state_error").innerHTML = "Please enter a city you want to search for";
		Effect.Pulsate("search_state_error");
		return false; 

	} else if (start_time == "" || start_time.length == 0) {
		$("search_state_error").innerHTML = "Please choose a start date";
		Effect.Pulsate("search_state_error");
		return false; 

	} else if (end_time == "" || end_time.length == 0) {
		$("search_state_error").innerHTML = "Please choose an end date";
		Effect.Pulsate("search_state_error");
		return false; 
	}else {
		$("search_state_error").innerHTML = "";
		new Ajax.Updater('show_urgent_contact', '/admin/search_urgent_contact', {asynchronous:true, evalScripts:true, onComplete:function(request){Element.hide('search_spinner');show_div('show_urgent_contact_name');show_div('show_urgent_contact');hide_div('live_message');}, onFailure:function(request){failure(request)}, onLoading:function(request){Element.show('search_spinner')}, parameters:Form.serialize("search_city")}); 
		return false;

	}

}

function require_urgent_contact(span_id, sid, start_time, end_time) {
	
	new Ajax.Updater(span_id, "/admin/require_urgent_contact?id="+sid+"&start_time="+start_time+"&end_time="+end_time, {asynchronous:true, evalScripts:true, onComplete:function(request){Element.hide('search_spinner_'+sid)}, onLoading:function(request) { Element.show('search_spinner_'+sid)}});
	return false;

}
function add_city(city) {
//	$("live_message").style.display = "none";
	
	
	$("add_location").style.display = "block";
	$("add_state").style.display = "block";
	$("add_location_say").style.display = "block";
	$("add_location_say").innerHTML = "Select a Country:";
	new Ajax.Updater("add_location", "/admin/show_location", {asynchronous:true, evalScripts:true, onComplete:function(request){Element.hide('search_spinner')}, onLoading:function(request) { Element.show('search_spinner')}});
	$("search").value = city;
	$('change_location').show();
	$('search').readOnly=true;
	
}

function select_state() {
	location_id = $("admin_location_id").value;

	$("add_state_say").style.display = "block";
	$("add_state_say").innerHTML = "Select a State:";
	new Ajax.Updater("add_state", "/admin/show_state?location_id="+location_id, {asynchronous:true, evalScripts:true, onComplete:function(request){Element.hide('search_spinner')}, onLoading:function(request) { Element.show('search_spinner')}});
	return false;

}

function av_new_urgent_contact() {
	urgent_contact_name = $("urgent_contact_name").value;
	urgent_contact_phone = $("urgent_contact_phone").value;
	search = $("search").value;
	urgent_contact_start_time = $("urgent_contact_start_time").value;
	urgent_contact_end_time = $("urgent_contact_end_time").value;
    if (urgent_contact_name == ""  || urgent_contact_name.length == 0 || urgent_contact_phone == "" || urgent_contact_phone.length == 0 || search == "" || search.length == 0 || urgent_contact_start_time == "" || urgent_contact_start_time.length == 0 || urgent_contact_end_time == "" || urgent_contact_end_time.length == 0) {
	if (urgent_contact_name == ""  || urgent_contact_name.length == 0) {
		$("urgent_contact_name_error").innerHTML = "请输入您所用的姓名！";
		Effect.Pulsate("urgent_contact_name_error");
		

	}else{
		Effect.Fade("urgent_contact_name_error");

	} if (urgent_contact_phone == "" || urgent_contact_phone.length == 0) {
		$("urgent_contact_phone_error").innerHTML = "请输入您的联系电话！";
		Effect.Pulsate("urgent_contact_phone_error");

	} else {
		Effect.Fade("urgent_contact_phone_error");

	} if (search == "" || search.length == 0) {
		$("urgent_contact_search_error").innerHTML = "请输入您所在的城市！";
		Effect.Pulsate("urgent_contact_search_error");
	} else {
		Effect.Fade("urgent_contact_search_error");

	} if (urgent_contact_start_time == "" || urgent_contact_start_time.length == 0) {
		$("urgent_contact_start_time_error").innerHTML = "请输入您申请的开始时间！";
		Effect.Pulsate("urgent_contact_start_time_error");
	}  else {
		Effect.Fade("urgent_contact_start_time_error");
	}  if (urgent_contact_end_time == "" || urgent_contact_end_time.length == 0) {
		$("urgent_contact_end_time_error").innerHTML = "请输入您申请的结束时间！";
		Effect.Pulsate("urgent_contact_end_time_error");
	}  else {
		Effect.Fade("urgent_contact_end_time_error");
	}  
	return false;
	} else {
		Element.show('search_spinner');
		return true;

	}

}

function av_new_message() {
	
	user_name = $("message_user_name").value;
	title = $("message_title").value;
	content = $("message_content").value;

    if (user_name == ""  || user_name.length == 0 || title == "" || title.length == 0 || content == "" || content.length == 0 ) {
	
	if (user_name == ""  || user_name.length == 0) {
		$("user_name_error").innerHTML = "Please enter a addressee";
		Effect.Pulsate("user_name_error");
		
	}else{
		Effect.Fade("user_name_error");
	} if (title == "" || title.length == 0) {
		$("title_error").innerHTML = "Plese enter a title";
		Effect.Pulsate("title_error");
	} else {
		Effect.Fade("title_error");
	} if (content == "" || content.length == 0) {
		$("content_error").innerHTML = "Message can't be empty";
		Effect.Pulsate("content_error");
	} else {
		Effect.Fade("content_error");
	}  
	return false;
	} else {

		Element.show('search_spinner');
		return true;
	}
}

function selAll(checkbox){
	
 var form = checkbox.form, z = 0;
 for(z=0; z<form.length;z++){
  if(form[z].type == 'checkbox' && form[z].name != 'checkall'){
  form[z].checked = checkbox.checked;
  }
 }
}


function delMessage(checkbox, link_title, link_tag){
var obj=checkbox.form;
	if(!obj[0]){
		if(obj.checked)
		{
	        isDelete = confirm("Are you sure?");
    		if(!isDelete)return ;
    		if (link_tag == "0") {
    		  location.href='/admin/delete_message?ids='+obj.value+"&link_title="+link_title+"&link_tag=1";
    		}
    		else if (link_tag == "1") {
    		  location.href='/admin/delete_message?ids='+obj.value+"&link_title="+link_title+"&link_tag=0";
    		}
            return true;
		}
		else{
			alert("Please select a note！");
			return false;
		}
 }else
 {
 flag=0;
 id='';
	for(var i=0;i<obj.length;i++)
	{
		if(obj[i].checked)
		{
		   id+=obj[i].value+",";
		   flag++;
		}
	}
	if(flag==0)
	{
	    alert("Please select notes！");
	    return false;	
	}else{
		isDelete = confirm("Are you sure?");
		if(!isDelete)return ;
    	if (link_tag == "0") {
    		  location.href='/admin/delete_message?ids='+id+"&link_title="+link_title+"&link_tag=1";
    		}
    		else if (link_tag == "1") {
    		  location.href='/admin/delete_message?ids='+id+"&link_title="+link_title+"&link_tag=0";
    		}
	}
  }
}

//去空格
function trimString(str) {
	var i,j;
	if(str == "") return "";
	for(i=0;i<str.length;i++)
		if(str.charAt(i) != ' ') break;
	if(i >= str.length) return "";
	for(j=str.length-1;j>=0;j--)
		if(str.charAt(j) != ' ') break;
	return str.substring(i,j+1);
}


function bookRequest(id) {
	if (confirm('确定要订阅吗?')) { 
	
	new Effect[Element.visible('new_trip') ? 
            'BlindUp' : 'BlindDown']('new_trip', {duration: 0.25});		
	new Ajax.Updater('new_trip', '/hi/book_request/'+id, {
            method:     'get',
            onFailure:  function() {Element.classNames('new_trip').add('failure')},
            onComplete: function() {new Effect.BlindDown('new_trip', {duration: 0.25})}
          });
  }

}


function av_new_request_guide() {
	
	journal_peoples = trimString($("journal_peoples").value);
	search = trimString($("search").value);
	journal_content = trimString($("journal_content").value);
	journal_start_time = trimString($("journal_start_at").value);
	journal_end_time = trimString($("journal_finish_at").value);
	
	
	if (stringToDate(journal_start_time, true) > stringToDate(journal_end_time, true)) {
		alert("End Date shouldn't be earlier than Start Date.");
		return false;
	}
	
    if ( journal_peoples == "" || journal_peoples.length == 0 || search == "" || search.length == 0 || journal_content == "" || journal_content.length == 0 || journal_start_at == "" || journal_start_at.length == 0 || journal_finish_at == "" || journal_finish_at.length == 0) {
	 if (journal_peoples == "" || journal_peoples.length == 0) {
		$("journal_peoples_error").innerHTML = "Please enter HOW MANY PEOPLE";
		Effect.Pulsate("journal_peoples_error");
	} else {
		Effect.Fade("journal_peoples_error");
	}
	
	if (search == "" || search.length == 0) {
		$("journal_search_error").innerHTML = "Please enter a destination city";
		Effect.Pulsate("journal_search_error");
	} else {
		Effect.Fade("journal_search_error");
	} if (journal_start_time == "" || journal_start_time.length == 0) {
		$("journal_start_time_error").innerHTML = "Please choose a start date";
		Effect.Pulsate("journal_start_time_error");
	}  else {
		Effect.Fade("journal_start_time_error");
	}  if (journal_end_time == "" || journal_end_time.length == 0) {
		$("journal_end_time_error").innerHTML = "Please choose an end date";
		Effect.Pulsate("journal_end_time_error");
	}  else {
		Effect.Fade("journal_end_time_error");
	}  if (journal_content == "" || journal_content.length == 0) {
		$("journal_content_error").innerHTML = "<br/>It can't be empty in BRIEF ABOUT THE TRIP";
		Effect.Pulsate("journal_content_error");
	}  else {
		Effect.Fade("journal_content_error");
	} 
	return false;
	}
	else {
		if (journal_peoples.match("/^[0-9]+$/")) {
			$("journal_peoples_error").innerHTML = "It must be a number in HOW MANY PEOPLE";
			Effect.Pulsate("journal_peoples_error");
			return false;
	} else {
		Effect.Fade("journal_peoples_error");
		Element.show('search_spinner');
		return true;
	}
	}
}


function av_new_request_guide_directly() {
	
	journal_content = trimString($("journal_content").value);
	journal_start_time = trimString($("journal_start_at").value);
	journal_end_time = trimString($("journal_finish_at").value);
	
	
	if (stringToDate(journal_start_time, true) > stringToDate(journal_end_time, true)) {
		alert("End Date shouldn't be earlier than Start Date.");
		return false;
	}
	
    if ( journal_content == "" || journal_content.length == 0 || journal_start_at == "" || journal_start_at.length == 0 || journal_finish_at == "" || journal_finish_at.length == 0) {
	
    if (journal_start_time == "" || journal_start_time.length == 0) {
		$("journal_start_time_error").innerHTML = "Please choose a start date";
		Effect.Pulsate("journal_start_time_error");
	}  else {
		Effect.Fade("journal_start_time_error");
	}  if (journal_end_time == "" || journal_end_time.length == 0) {
		$("journal_end_time_error").innerHTML = "Please choose an end date";
		Effect.Pulsate("journal_end_time_error");
	}  else {
		Effect.Fade("journal_end_time_error");
	}  if (journal_content == "" || journal_content.length == 0) {
		$("journal_content_error").innerHTML = "<br/>It can't be empty in BRIEF ABOUT THE TRIP";
		Effect.Pulsate("journal_content_error");
	}  else {
		Effect.Fade("journal_content_error");
	} 
	return false;
	}
}


function av_password() {
	old_password = trimString($("old_password").value);
	password = trimString($("user_password").value);
	password_confirmation = trimString($("user_password_confirmation").value);
	if (old_password.length == 0 || password.length == 0 || password_confirmation.length == 0) {
		if (old_password.length == 0) {
			alert("Please enter the old password");
			$("old_password").focus();

		} else if (password.length == 0) {
			alert("Please enter the new password");
			$("user_password").focus();

		} else if (password_confirmation.length == 0) {
			alert("Please enter the new password again in <<Confirm Password>>");
			$("user_password_confirmation").focus();

		} else if (password.length < 5) {
			alert("The new password must be at least 5 characters.")
		}
		return false;

	} else {
		if (password != password_confirmation) {
			alert("The confirmation password does not match the original password");
			$("user_password").focus();
			return false;

		} else {
			return true;

		}

	}
 	

}

function check_guestbook() {
	if ($("guestbook_content").value == "" || $("guestbook_content").value.length == 0) {
					 alert("Empty...");
        $("guestbook_content").focus();
        return false;
	}
}

function checkrequest_msgform() {
	if ($("request_message_content").value == "" || $("request_message_content").value.length == 0) {
					 alert("Empty...");
        $("request_message_content").focus();
        return false;
	}
}

function change_area(type) {
	if (type == "country") {
		$("type").value = "1";
		new Ajax.Updater("area", "/guides/change_area?type=country", {asynchronous:true, evalScripts:true, onComplete:function(request){Element.hide('loading_image')}, onLoading:function(request) { Element.show('loading_image')}});
		return false;
	}
	else if (type == "city") {
		$("type").value = "2";
		new Ajax.Updater("area", "/guides/change_area?type=city", {asynchronous:true, evalScripts:true, onComplete:function(request){Element.hide('loading_image')}, onLoading:function(request) { Element.show('loading_image')}});
		return false;
	}
}

function loading_photo() {
	$("show_big_pic").innerHTML = "<img src=\"/images/loading.gif\" id=\"loading_image\"/>";
}

function select_rating(rating) {
	if (rating == 1) {
		$("rating").innerHTML = "<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating1.gif\" border=\"0\" onclick=\"select_rating(1);\"/></a>\
		<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating2.gif\" border=\"0\" onclick=\"select_rating(2);\"/></a>\
		<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating2.gif\" border=\"0\" onclick=\"select_rating(3);\"/></a>\
		<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating2.gif\" border=\"0\" onclick=\"select_rating(4);\"/></a>\
		<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating2.gif\" border=\"0\" onclick=\"select_rating(5);\"/></a>";
		$("journal_comment_rating").value = 1;
	} else if (rating == 2) {
		$("rating").innerHTML = "<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating1.gif\" border=\"0\" onclick=\"select_rating(1);\"/></a>\
		<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating1.gif\" border=\"0\" onclick=\"select_rating(2);\"/></a>\
		<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating2.gif\" border=\"0\" onclick=\"select_rating(3);\"/></a>\
		<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating2.gif\" border=\"0\" onclick=\"select_rating(4);\"/></a>\
		<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating2.gif\" border=\"0\" onclick=\"select_rating(5);\"/></a>";
		$("journal_comment_rating").value = 2;
	} else if (rating == 3) {
		$("rating").innerHTML = "<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating1.gif\" border=\"0\" onclick=\"select_rating(1);\"/></a>\
		<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating1.gif\" border=\"0\" onclick=\"select_rating(2);\"/></a>\
		<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating1.gif\" border=\"0\" onclick=\"select_rating(3);\"/></a>\
		<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating2.gif\" border=\"0\" onclick=\"select_rating(4);\"/></a>\
		<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating2.gif\" border=\"0\" onclick=\"select_rating(5);\"/></a>";
		$("journal_comment_rating").value = 3;
	} else if (rating == 4) {
		$("rating").innerHTML = "<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating1.gif\" border=\"0\" onclick=\"select_rating(1);\"/></a>\
		<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating1.gif\" border=\"0\" onclick=\"select_rating(2);\"/></a>\
		<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating1.gif\" border=\"0\" onclick=\"select_rating(3);\"/></a>\
		<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating1.gif\" border=\"0\" onclick=\"select_rating(4);\"/></a>\
		<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating2.gif\" border=\"0\" onclick=\"select_rating(5);\"/></a>";
		$("journal_comment_rating").value = 4;
	} else if (rating == 5) {
		$("rating").innerHTML = "<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating1.gif\" border=\"0\" onclick=\"select_rating(1);\"/></a>\
		<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating1.gif\" border=\"0\" onclick=\"select_rating(2);\"/></a>\
		<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating1.gif\" border=\"0\" onclick=\"select_rating(3);\"/></a>\
		<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating1.gif\" border=\"0\" onclick=\"select_rating(4);\"/></a>\
		<a href=\"javasctipt:void(0);\" ><img src=\"/images/rating1.gif\" border=\"0\" onclick=\"select_rating(5);\"/></a>";
		$("journal_comment_rating").value = 5;
	}
	
	
}

function show_live_message() {
	tag = document.search_city.tag.value;
	search = document.search_city.search.value;
	
	if (tag == 1) {
		$("add_location").style.display = "none";
		$("add_state").style.display = "none";
	}
	
	if (trimString($("search").value) == "" || trimString($("search").value).length == 0 || search.indexOf(",") > 0) {
    	$("live_message").style.display = "none";
	} else {
			$("live_message").style.display = "block";
	}
	
}

function av_password2() {
	password = trimString($("password").value);
	password_confirmation = trimString($("password_confirmation").value);
	if ( password.length == 0 || password_confirmation.length == 0) {
		if (password.length == 0) {
			alert("Please enter a new password");
			$("password").focus();
		} else if (password_confirmation.length == 0) {
			alert("Please enter the new password again");
			$("password_confirmation").focus();
		} else if (password.length < 4) {
			alert("Password must be at least 4 characters")
		}
		return false;
	} else {
		if (password != password_confirmation) {
			alert("The confirmation password does not match the original password");
			$("password").focus();
			return false;
		} else {
			return true;
		}
	}
 	
}

function changetips(name,styles){
		obj=document.getElementById(name);
		obj.className=styles;
	}
function checkrouteform() {
	routeName = trimString($("journal_route_route_name").value);
	
	if (routeName == "" || routeName.length <= 0) {
		
		alert("Route name can not empty！");
	} else {
		new Ajax.Updater({success:'routes'}, '/journal/create_route', {asynchronous:true, evalScripts:true, onComplete:function(request){Element.hide('loading')}, onLoading:function(request){Element.show('loading');}, parameters:Form.serialize(this)}); 		
	}
	return false;
	
}

//时间比较

function stringToDate(sDate, bIgnore)

{	var bValidDate, year, month, day

	var iaDate = new Array(3)

	

	if (bIgnore) bValidDate = true

	else bValidDate = isDateString(sDate)

	

	if (bValidDate)

	{  iaDate = sDate.toString().split("-")

		year = parseFloat(iaDate[0])

		month = parseFloat(iaDate[1]) - 1

		day=parseFloat(iaDate[2])

		return (new Date(year,month,day))

	}

	else return (new Date(1900,1,1))

}


//是否符合时间格式

function isDateString(sDate)

{	var iaMonthDays = [31,28,31,30,31,30,31,31,30,31,30,31]

	var iaDate = new Array(3)

	var year, month, day



	if (arguments.length != 1) return false

	iaDate = sDate.toString().split("-")

	if (iaDate.length != 3) return false

	if (iaDate[1].length > 2 || iaDate[2].length > 2) return false

	if (isNaN(iaDate[0])||isNaN(iaDate[1])||isNaN(iaDate[2])) return false



	year = parseFloat(iaDate[0])

	month = parseFloat(iaDate[1])

	day=parseFloat(iaDate[2])



	if (year < 1900 || year > 2100) return false

	if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)) iaMonthDays[1]=29;

	if (month < 1 || month > 12) return false

	if (day < 1 || day > iaMonthDays[month - 1]) return false

	return true

}


function Verify_journal_note() {
	if(trimString($('journal_comment_title').value) == '') {
		alert('Title can not empty！'); 
		return false;
	}
	if(trimString($('journal_comment_content').value) == '') {
		alert('Content can not empty！'); 
		return false;
	}
			
}

function clear_city() {
	if (document.search_city.search.value == 'Enter city name') { document.search_city.search.value = ''; } 
}


function handle_user_partial() {
	var login_cookie = readCookie('login');
    if (document.getElementById('logged_in') !=null) {
    document.getElementById('bold_link').firstChild.nodeValue=login_cookie;
    }
}

function handle_cached_user() {
	var login_cookie = readCookie('login');
    var logged_in = document.getElementById('logged_in');
    var logged_out = document.getElementById('logged_out');
    var loginreg2 = document.getElementById('loginreg2');
    var loginreg = document.getElementById('loginreg');

    if(login_cookie == null) {
      if (logged_in !=null) {
	  logged_in.style.display = 'none';
      logged_out.style.display = 'block';
      }
      loginreg2.style.display = 'none';
      loginreg.style.display = 'block';
    } else {
	  handle_user_partial();
	  if (logged_in !=null) {
      logged_out.style.display = 'none';
      logged_in.style.display = 'block';
      }
	  loginreg2.style.display = 'block';
      loginreg.style.display = 'none';
    }
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
