
/**导航栏切换效果***/
window.onload = function() {
	$.each($("#main_tree li a"), function(i, n) {
		$("#main_tree>li>a:eq(" + i + ")").mouseover( function() {
			$("#navbj_mar").children().hide();
			$("#main_tree").children('li').attr("class", '');
			if (i !=10) {
				$("#m0" + (i + 1)).attr("class", 'q');
				$("#c0" + (i + 1)).show();
			} else {
				$("#m" + (i + 1)).attr("class", 'q');
				$("#c" + (i + 1)).show();
			}
			
		});
		$("#main_tree>li>a:eq(1)").trigger('mouseover');
	});
}

var vidnow = "";
function getDailog(url) {
	var over = $('.show').data('over');
	if (over != undefined) {
		changeOut();
	}
	$
			.getJSON(
					url + '/Index/getDailog/folder/' + folder + '/file/' + file,
					function(back) {
						// alert(this.url + '*********' + back);

						if (back != null && over == undefined) {
							for (i = 0; i < back.length; i++) {
								var text = "";
								if (back[i] != null) {
									if (back[i][1] != "$->over") {
										$('.show')
												.append(
														'<dl ><dt id="start">客服说：<span>'
																+ (new Date(
																		back[i][2] * 1000))
																		.toLocaleString()
																+ '</span></dt><dd>'
																+ back[i][1]
																+ '</dd></dl>');
										$('.show').scrollTop(3000000);
									} else {
										$('#over').show();
										if (over == undefined) {
											$('.show').data('over',
													(new Date()).getTime());
										}
										$('#go').attr('href',
												"javascript:alert('已结束！')");
										$('#sand input').attr('onclick', '');
										$('#sand input').bind('click',
												function() {
													alert("对话已结束！");
												});
										$.get(url + '/Index/overDailog/folder/'
												+ folder + '/file/' + file
												+ '/cmd/2', function(back) {
											changeOut();
										});

									}
								}
							}

						}
					});
}

function changeOut() {
	var time = ((new Date()).getTime() - $('.show').data('over')) / 1000
	time = 10 - parseInt(time);
	if (time > 0) {
		$('#over span').html(time);
	} else {
		window.location.href = "/test/";
	}
}
function setVisitor(vid) {
	vidnow = vid;
	$("#c_right li[class='on']").attr('class', '');
	$('#v_' + vid).attr('class', 'on');
}
function sendDailog(url) {
	var dailog = $('#input textarea').val();
	if (dailog != "") {
		var index = dailog.search(/(\^|#)/ig);
		if (index < 0) {
			$('.show').append(
					'<dl ><dt id="start">您说：<span>'
							+ (new Date()).toLocaleString()
							+ '</span></dt><dd>' + dailog + '</dd></dl>');
			$('.show').scrollTop(3000000);

			$.get(url + '/Index/putDailog/folder/' + folder + '/file/' + file
					+ '/status/0/dailog/' + dailog,
					function(back) {
						$('#input textarea').val('');
						// alert(this.url + '*********' + back);
				});
		} else {
			$('#input textarea').val('');
			alert("对话中存在非法字符：" + dailog.charAt(index));
		}
	} else {
		alert('不允许发空消息');
	}
}
/**
 * 结束对话 
 * @param url 指令地址
 * @return
 */
function overDailog(url) {
	$.get(url + '/Index/overDailog/folder/' + folder + '/file/' + file
			+ '/cmd/1', function(back) {
		window.location.href = "/test/";
	});
}

function niMing(obj){
	$(obj).prev('input').attr('disabled',!$(obj).prev('input').attr('disabled'));
}
