var request = null;

var temp = document.URL; //获得当前的url路径

var tranurl = temp.slice(0,24);

try {

  request = new XMLHttpRequest();

} catch (trymicrosoft) {

  try {

    request = new ActiveXObject("Msxml2.XMLHTTP");

  } catch (othermicrosoft) {

    try {

      request = new ActiveXObject("Microsoft.XMLHTTP");

    } catch (failed) {

      request = null;

    }

  }

}



if (request == null){

  alert("Error creating request object!");

}



function setLeave() {

	if(request.readyState == 4 && request.status == 200){

		document.getElementById('leave_word').innerHTML = request.responseText;

	}

}



function getLeave(artist_id, web_ref, page){

	var now = Date.parse(new Date());

	var url =tranurl+"php/video_talk.php?artist_id=" + artist_id + "&web_ref=" + web_ref + "&page=" + page + "&now=" + now;

	request.open("GET", url, true);

	request.onreadystatechange = setLeave;

	request.send(null);

}



function subLeave(artist_id, web_ref, artist_name, artist_url) {

	var username = document.getElementById('username').value;

	if(document.getElementById('checkbox').checked == true){

		var username = '匿名网友';

	}

	

	var content = document.getElementById('content').value;

	

	if(username == null || username == ""){

		alert('请输入用户名');

		return 0;

	}

	

	if(content == null || content == ""){

		alert('请输入留言内容');

		return 0;

	}

	

	if(content.length > 400){

		alert('请将留言字数控制在400字以内');

		return 0;

	}

	

	leaveLeave(artist_id, web_ref, artist_name, artist_url, username, content);

}



function leaveLeave(artist_id, web_ref, artist_name, artist_url, username, content){

	$.ajax({

		type: "POST",

		url: tranurl+"php/video_addtalk.php",

		data: "artist_id=" + artist_id + "&web_ref=" + web_ref + "&username=" + username + "&content=" + content + "&artist_name=" + artist_name + "&artist_url=" + artist_url,

		success: function(msg){

					//alert(msg);

					//alert('留言成功');

					document.getElementById('username').value = '';

					var content = document.getElementById('content').value = '';

					getLeave(msg, '1', 1);

				}

	});

}



function killErrors() {

    return true;

}

window.onerror = killErrors;

