﻿// JScript File

// Kiểm tra số ký tự đã nhập
function CharCount(sField, nMaxChar) {

	count = eval(sField).value.length;
	
	diff    = nMaxChar - count;
	msg   = 'Số lượng ký tự tối đa: ' + nMaxChar + '\n';
	if (diff < 0) {
		msg = msg + 'Bạn đã nhập quá số lượng cho phép ' + -diff + ' ký tự.';
		alert(msg);
	}
}

// ArticleView
function writeTime(s)
{
	var mydate=new Date(s);
	
	var year = mydate.getYear()
	if (year < 1000)
		year += 1900;
	var month = mydate.getMonth() + 1;
	if (month < 10)
		month = "0" + month;
	var day = mydate.getDate();
	if (day < 10)
		day = "0" + day;

	var dayw = mydate.getDay();
	
	var hour = mydate.getHours();
	if (hour < 10)
		hour = "0" + hour;
	
	var minute=mydate.getMinutes();
	if (minute < 10)
		minute = "0" + minute;
	var dayarray=new Array("Ch&#7911; Nh&#7853;t","Th&#7913; Hai","Th&#7913; Ba","Th&#7913; T&#432;","Th&#7913; N&#259;m","Th&#7913; S&#225;u","Th&#7913; B&#7843;y");
	document.write(dayarray[dayw]+", "+day+"/"+month+"/"+year+",&nbsp;"+hour+":"+minute+" (GMT+7)");
}

function getTimeString(s)
{
    document.write("<span class=ArticleListDate>");
	writeTime(s);
	document.write("</span>");
}

function Trim(s)
{
var i = 0;
while ((i < s.length) && (s.charCodeAt(i) == 32))
	i++;

var j = s.length - 1;
while ((j > i) && (s.charCodeAt(j) == 32))
	j--;

return s.substr(i, j - i + 1);
}


// Cookies
function addBookID(bookID)
{
    //-- Lay ve Cookie chua BookID
	c = TTOTusachCookie.getSubValue(c_name);
	if(!c)
	{   //-- Neu chua co
	    c = "";
	}
	else
	{
		//-- Kiem tra xem da binh chon cho cuon sach nay chua		
		cc = c.split(split);

		for(i = 0; i < cc.length; i++)
		{
			if(cc[i] == bookID)
			{
				return false;
			}
		}
	}
	//-- Neu chua co trong Cookie thi them vao
	c = c + bookID + split;
	TTOTusachCookie.setSubValue(c_name, c);	
}

function isVoted(bookID)
{
    //-- Lay ve Cookie chua BookID
	c = TTOTusachCookie.getSubValue(c_name);
	
	cc = c.split(split);
	for(i = 0; i < cc.length; i++)
	{  
	    if(cc[i] == bookID)
	    {
	        return true;
	    }
	}
	return false;
}

//function onCmdSearchClick( txtBoxID )
//{
//   alert("Test thu phat nao!!!");
//    var txtSearch = document.getElementByID(txtBoxID);
//    
//    var q = Trim(txtSearch.value);
//	
//	if ((q.indexOf('AND') == -1) && (q.indexOf('OR') == -1) && (q.indexOf('"') == -1) && ( q != '' ) )
//    {
//        q = '"' + q + '"';                    
//        txtSearch.value = q;
//    }   		
//}  

