/**
 * @author Tran Ngoc
 */


function showFullText(isFull, shortId, fullId){ 
    if (isFull){
        $(shortId).style.display = "none";
        $(fullId).style.display  = "";
    } else{
        $(shortId).style.display = "";
        $(fullId).style.display  = "none";
    }
}


function btnTabChange_OnClick( tabId)
{
	if (tabId == 1){
		$('tab-intro').className = "active";
		$('tab-offer').className = "";
		$('content-intro').style.display="";
		$('content-offer').style.display="none";
	}else{
		$('tab-intro').className = "";
		$('tab-offer').className = "active";
		$('content-intro').style.display="none";
		$('content-offer').style.display="";
	}
}
function btnPostComment_OnClick(objId){
	var content ;
	var postContent;
	
//	if (($('name').value != "")|| ($('name').value != "Tên của bạn"))
//	{
//		alert("Bạn chưa nhập tên");
//        return false;
//	}
    if (objId)
	{
		postContent = $('post_content_' + objId);
		content = $('content_' + objId);
	}else
	{
		postContent = $('post_content');
		content = $('content');
	}
    postContent.value = "";
    if (content.value != null && content.value != "" && content.value != "Nhập nội dung bình luận") {
        postContent.value = content.value;
        content.value = "";
        return true;
    }
    else {
        alert("Bạn phải nhập nội dung bình luận");
        return false;
    }
}
function btnReplyOpen_OnClick(objId)
{
	$('reply_to_comment_'+objId).style.display = "";
}
function btnReplyClose_OnClick(objId)
{
	$('reply_to_comment_'+objId).style.display = "none";
}
function isAuthenticated()
{
	var retVal = false;
	new Ajax.Request(
		'/account/isAuthenticated',
		{
			method: 'post',
			asynchronous: false,
			onComplete: function(res) {
				var result = res.responseText;
				if (result == "logined") {
					retVal = true;
				}
				
			}
		}
	);
	return retVal;
}

/**
 * Check email validate
 * @param {Object} s
 */
function isEmail(s){
	if(s=="") 
		return false;
	if( s.indexOf(" ")>0) 
		return false;
	if( s.indexOf("@") == -1)
	 	return false;
	var i = 1; 
	var sLength = s.length;
	if(	s.indexOf(".") == -1 )
			return false;
			
	if(	s.indexOf("..")	!=	-1)
		return false;
	
	if(s.indexOf("@")!=s.lastIndexOf("@")) 
		return false;
		
	if( s.lastIndexOf(".") == s.length-1 )
		return false;
	var str = "abcdefghikjlmnopqrstuvwxyz-@._0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	for( var j=0; j<s.length; j++ )
	{
		if( str.indexOf( s.charAt(j) ) == -1 )
			return false;
	}
		return true;
}
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

