// JavaScript Document
function validatelogin(formlogin)
{
	if(document.formlogin.str_top_wtt_id.value==''){
		alert ("Vui lòng nhập ID WTT  !");
		document.formlogin.str_top_wtt_id.focus();
		return false;
	}
	if(document.formlogin.str_top_wtt_pass.value==''){
		alert ("Vui lòng nhập mật khẩu !");
		document.formlogin.str_top_wtt_pass.focus();
		return false;
	}
   	return true;
}

function addcommentxxx(){
	obj = document.getElementById('addcomment');
	if (obj.style.display=="none"){
		obj.style.display="block";
	}else{
	 	obj.style.display="none";
	}
}

function listcomment(){
	obj = document.getElementById('listcomment');
	if (obj.style.display=="none"){
		obj.style.display="block";
	}else{
	 	obj.style.display="none";
	}
}

function sendfriend(){
	obj = document.getElementById('sendfriend');
	if (obj.style.display=="none"){
		obj.style.display="block";
	}else{
	 	obj.style.display="none";
	}
}

function popup( windowWidth, windowHeight, windowName, windowUri, windowscroll)
{
    var centerWidth = (window.screen.width - windowWidth) / 2;
    var centerHeight = (window.screen.height - windowHeight) / 2;
    newWindow = window.open(windowUri, windowName, 'resizable=no,width=' + windowWidth + 
        ',height=' + windowHeight + 
        ',left=' + centerWidth + 
        ',top=' + centerHeight +
		',scrollbars='+windowscroll);
    newWindow.focus();
    return newWindow.name;
}

function selectturn(id)
{
	var poststr = "id=" + encodeURIComponent(id) ;
	makePOSTRequest('index.php/main/selectturn', poststr,'phienthoigian');
}

function selectdate(id)
{
	var poststr = "id=" + encodeURIComponent(id) ;
	makePOSTRequest('index.php/main/selectdate', poststr,'thoigian');
}

function changepage(url,div)
{
    makePOSTRequest(url, '',div);
}

function valsearch(frm){ 
	if(frm.strSearch.value==''){
		alert('Nhập thông tin cần tìm');
		frm.strSearch.focus();
		return false;
	}
	return true;
}
function questionsend(){
	/*		
	if(document.getElementById('txt_nickname').value==''){
		alert ("Vui lòng nhập nickname  !");
		document.getElementById('txt_nickname').focus();
		return ;
	}
	var strEmail = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	if (document.getElementById('txt_email').value== "")
	{
		alert ("Vui lòng nhập email !");
		document.getElementById('txt_email').focus();
		return ;
	}
	else if (!document.getElementById('txt_email').value.match(strEmail)) 
	{
		alert("Email không hợp lệ !");
		document.getElementById('txt_email').select();
		return;
	}
	*/
	if(document.getElementById('txt_title').value==''){
		alert ("Vui lòng nhập tiêu đề  !");
		document.getElementById('txt_title').focus();
		return ;
	}
	if(document.getElementById('txt_questioncontent').value==''){
		alert ("Vui lòng nhập nội dung  !");
		document.getElementById('txt_questioncontent').focus();
		return ;
	}
	
	//kiem tra 100 tu
	var f=document.frmquestion;
	var sotu=f.txt_questioncontent.value.split(' ').length;
	if(parseFloat(sotu)>100){
		alert ("Bạn nhập vượt quá 100 từ, vui lòng nhập lại !");
		document.getElementById('txt_quesctioncontent').focus();
		f.word_count.value=sotu;
		return ;
	}
	//var nickname=document.getElementById('txt_nickname').value;
	//var email=document.getElementById('txt_email').value;

	var nickname = "";
	var email = "";

	var title=document.getElementById('txt_title').value;
	var content=document.getElementById('txt_questioncontent').value;
	var t_id=document.getElementById('txt_t_id').value;
	
	var poststr = "nickname=" + encodeURIComponent(nickname)+"&email=" + encodeURIComponent(email)+"&title=" + encodeURIComponent(title)+"&content=" + encodeURIComponent(content)+"&t_id=" + encodeURIComponent(t_id);
	makePOSTRequest('index.php/main/addquestion', poststr,'frmguicauhoi');
}

function questioncancel(){
	document.getElementById('txt_nickname').value='';
	document.getElementById('txt_email').value='';
	document.getElementById('txt_title').value='';
	document.getElementById('txt_questioncontent').value='';
}
function questioncontinue(){
	//frmquestion
	var t_id=document.getElementById('txt_t_id').value;
	var poststr = "t_id=" + encodeURIComponent(t_id);
	makePOSTRequest('index.php/main/guicauhoigiaoluu', poststr,'frmguicauhoi');
}

function selectexchange(t_id)
{
	var poststr = "t_id=" + encodeURIComponent(t_id);
	makePOSTRequest('index.php/main/selectexchange', poststr,'listinfo');
}
//////mR cuong

function listcomment(url)
{
//    alert (div);
    document.getElementById("addcomment").style.display = "none";
    document.getElementById("sendfriend").style.display = "none";
	obj = document.getElementById('listcomment');
	if (obj.style.display=="none"){
		obj.style.display="block";
	}else{
	 	obj.style.display="none";
	}
    makePOSTRequest(url, '','listcomment');
}
function sendfriend(){
    document.getElementById("addcomment").style.display = "none";
    document.getElementById("listcomment").style.display = "none";
	obj = document.getElementById('sendfriend');
	if (obj.style.display=="none"){
		obj.style.display="block";
	}else{
	 	obj.style.display="none";
	}

}
function sendfriend_ok(){
    document.getElementById("addcomment").style.display = "none";
    document.getElementById("listcomment").style.display = "none";
    makePOSTRequest('index.php/main/mailok', '','sendfriend');

}
function comment_ok(){
    document.getElementById("listcomment").style.display = "none";
    document.getElementById("sendfriend").style.display = "none";
    makePOSTRequest('index.php/main/commentok', '','addcomment');

}

function addcomment(){
    document.getElementById("listcomment").style.display = "none";
    document.getElementById("sendfriend").style.display = "none";
	obj = document.getElementById('addcomment');
	if (obj.style.display=="none"){
		obj.style.display="block";
	}else{
	 	obj.style.display="none";
	}
}

function addcomment1(){

  	var txt_name=document.getElementById('txt_name').value;
	var txt_email_comment=document.getElementById('txt_email_comment').value;
	var txt_content=document.getElementById('txt_content').value;
	var lession_comment=document.getElementById('lession_comment').value;
    if(txt_name==''){
		alert('Vui lòng nhập tên');
		document.getElementById('txt_name').focus();
		status = false;
        return ;
	}
     var strEmail = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	if (txt_email_comment == "")
	{
		alert("Vui lòng nhập email !");
		document.getElementById('txt_email_comment').focus();
		status = false;
        return ;
	}
	else if (!document.getElementById('txt_email_comment').value.match(strEmail))
	{
		alert("Email không hợp lệ !");
		document.getElementById('txt_email_comment').focus();
		status = false;
        return ;
	}
	if(document.getElementById('txt_content').value==''){
		alert('Bạn chưa nhập nội dung');
		document.getElementById('txt_content').focus();
		status = false;
		return ;
	}
	var f=document.form_add_comment;
	var sotu=f.txt_content.value.split(' ').length;
	if(parseFloat(sotu)>100){
		alert ("Bạn nhập vượt quá 100 từ, vui lòng nhập lại !");
		document.getElementById('txt_content').focus();
		f.word_count.value= 100 - sotu;
		return ;
	}
	var poststr = "txt_name=" + encodeURIComponent(txt_name)+"&txt_email_comment=" + encodeURIComponent(txt_email_comment)+"&txt_content=" + encodeURIComponent(txt_content)+"&lession_comment=" + encodeURIComponent(lession_comment) ;
	makePOSTRequest('index.php/main/add_comment1', poststr,'addcomment');
}

function emailfriend(){
//alert ('aaaa');
	var strEmail = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
	if (document.getElementById('txt_email2').value == "")
	{
		alert("Vui lòng nhập email của bạn!");
		document.getElementById('txt_email2').focus();
		status = false;
        return  ;
	}
	else if (!document.getElementById('txt_email2').value.match(strEmail))
	{
		alert("Email không hợp lệ !");
		document.getElementById('txt_email2').select();
		status = false;
        return ;
	}
    	if (document.getElementById('txt_email3').value == "")
	{
		alert("Vui lòng nhập email người nhận!");
		document.getElementById('txt_email3').txt_email3.focus();
		status = false;
       return ;
	}
	else if (!document.getElementById('txt_email3').value.match(strEmail))
	{
		alert("Email không hợp lệ !");
		document.getElementById('txt_email3').select();
		status = false;
        return ;
	}
	if(document.getElementById('txt_title2').value==''){
		alert('Vui lòng nhập tiêu đề');
		document.getElementById('txt_title2').focus();
        status = false;
       return ;
	}
    if(document.getElementById('txt_content2').value==''){
		alert('Vui lòng nhập nội dung');
		document.getElementById('txt_content2').focus();
        status = false;
       return ;
	}
  	var txt_email2=document.getElementById('txt_email2').value;
	var txt_email3=document.getElementById('txt_email3').value;
	var txt_title2=document.getElementById('txt_title2').value;
    var txt_content2=document.getElementById('txt_content2').value;
	var lession_mail=document.getElementById('lession_mail').value;

	var poststr = "txt_email2=" + encodeURIComponent(txt_email2)+"&txt_email3=" + encodeURIComponent(txt_email3)+"&txt_title2=" + encodeURIComponent(txt_title2)+"&txt_content2=" + encodeURIComponent(txt_content2)+"&lession_mail=" + encodeURIComponent(lession_mail) ;
	makePOSTRequest('index.php/main/guimail2', poststr,'sendfriend');
}


