var doing = false;

$(document).ready(function() {
	$("a[id^='search_cat']").click(function(){				
		$("#selected_cat").text($(this).text());
	});
});

function toggleArea(id) {
	$("#"+id).toggle();
}

function ShowHideArea(id) {
	// Muc dich: Thay doi class tieu de + an/hien phan noi dung.
	t_id = id; // ID cua phan tieu de.
	c_id = id.replace('t-',''); // ID cua phan noi dung.
	
	//convert to element:
	t_id = document.getElementById(t_id);
	c_id = document.getElementById(c_id);
	
	if ($("#" + id).attr('src').match(/bulletExpand/)) { //neu dang mo tieu de
		$('#' + id).attr("src", "../images/bulletCollapse.jpg"); // thi dong lai
	} else {
		$('#' + id).attr("src", "../images/bulletExpand.jpg"); // neu khong thi mo lai
	}
	// An hien phan noi dung tu dong:
	$(c_id).toggle();
}

//Change class name: 
function ChangeClass(sid,sclassname) { 
   document.getElementById(sid).className = sclassname; 
}

function check_search_content() {
	var content = $("#searchContent").val();
	if (content == 'Nhập từ khóa cần tìm...')
		$("#searchContent").val("");
}

function key_press(e) {
	var Ucode=e.keyCode? e.keyCode : e.charCode;
	
	if (Ucode == 13)
		window.location.href = "http://search.tamtay.vn/?q="+$("#searchContent").val();
}

function goto_search_page() {
	
	var cat = $('#selected_cat').text();
	var sel_cat="";
	var url="";
	
	switch (cat)
	{
		case "Video":
			sel_cat="video";			
			break;
		case 'Nhạc':
			sel_cat="music";			
			break;
		case 'Ảnh':
			sel_cat="photo";			
			break;
		case 'Blog':
			sel_cat="blog";				
			break;
		default:
			sel_cat = "";
	}		
	
	if(sel_cat!="")					
		window.location.href = "http://search.tamtay.vn/?q="+$("#searchContent").val() + "&f=" + sel_cat;		
	else
 		window.location.href = "http://search.tamtay.vn/?q="+$("#searchContent").val();
	
}

function insertSymbol(symbol, name) {
	var obj=$('#'+name).get(0);
	if (document.selection)
	{
		obj.focus();
		sel = document.selection.createRange();
		sel.text = symbol;
	}
	else if (obj.selectionStart || obj.selectionStart == 0)
	{
		var startPos = obj.selectionStart;
		var endPos = obj.selectionEnd;
		obj.value = obj.value.substring(0, startPos)
					+ symbol
					+ obj.value.substring(endPos, obj.value.length);
	} 
	else
	{
		obj.value += symbol;
	}
}		
