var userAgent = navigator.userAgent.toLowerCase();
var ie = false;
var ie6 = false;
var ie7 = false;

if (userAgent.indexOf('msie') > -1) {
	ie = true;
	if (userAgent.indexOf('msie 6.0') > -1) {
		ie6 = true;
	}
	if (userAgent.indexOf('msie 7.0') > -1) {
		ie7 = true;
	}
}


document.write('<script type="text/javascript" src="/common/v1/js/yui/yahoo-dom-event.js"></script>');
document.write('<script type="text/javascript" src="/common/v1/js/yui/element-min.js"></script>');
document.write('<script type="text/javascript" src="/common/v1/js/yui/paginator-min.js"></script>');
document.write('<script type="text/javascript" src="/common/v1/js/yui/build/container/container-min.js"></script>');
document.write('<script type="text/javascript" src="/common/v1/js/yui/connection-min.js"></script>');
document.write('<script type="text/javascript" src="/common/v1/js/avim.js"></script>');
document.write('<script type="text/javascript" src="/common/v1/js/services.js"></script>');
document.write('<script type="text/javascript" src="/common/v1/js/ads.js"></script>');
document.write('<script type="text/javascript" src="/common/v1/js/poll.js"></script>');
document.write('<script type="text/javascript" src="/common/v1/js/vckm_data.js"></script>');
/*document.write('<script type="text/javascript" src="/common/v1/js/yui/utilities.js"></script>');*/
document.write('<script type="text/javascript" src="/common/v1/js/yui/event-min.js"></script>');
document.write('<script type="text/javascript" src="/common/v1/js/yui/yahoo-min.js"></script>');
document.write('<script type="text/javascript" src="/common/v1/js/yui/carousel-min.js"></script>');
document.write('<script type="text/javascript" src="/common/v1/js/yui/container_core-min.js"></script>');

var stats_url = '/service/statistic/statcollector.do';
/*
try{
	document.write('<script type="text/javascript" src="http://megafun.vn/common/v2/js/tvonline.js"></script>');
} catch (e) {}
*/




function redirect(url){
	location.href=url;
}

function search_on_focus(field) {
		if(field.value=='...Từ khóa...'){ field.value = ''; }
}

function search_on_blur(field) {
		if(field.value.split(' ').join('') == ''){ field.value='...Từ khóa...';}
}


function CreateBookmarkLink() {
	var title = document.title;
	var url = window.location.href;
	if (window.sidebar) {
			window.sidebar.addPanel(title, url,"");
	} else if( window.external ) {
			window.external.AddFavorite( url, title);
		}
 else if(window.opera && window.print) {
		var a = document.createElement("A");
		a.rel = "sidebar";
		a.target = "_search";
		a.title = title;
		a.href = url;
		a.click();
	}
}

function setasHome(obj){
	document.body.style.behavior='url(#default#homepag e)';
	document.body.setHomePage('http://www.baoquangngai.com.vn');
}



function link(boxmenu) {
	var url = boxmenu[boxmenu.selectedIndex].value;
	if (url != '') {
		window.location = url;
	}
}

function url_params( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

function get_http_request()
	{
		var http_request;
		if (window.XMLHttpRequest)
		{ // Mozilla, Safari,...
			http_request = new XMLHttpRequest();
		}
		else if (window.ActiveXObject)
		{ // IE
			try
			{
				http_request = new ActiveXObject("Msxml2.XMLHTTP");

			}
			catch (e)
			{
				try
				{
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}

		if (!http_request)
		{
			alert('Giving up :( Cannot create an XMLHTTP instance');
			return false;
		} else {
			return http_request;
		}
	}

function clientSideInclude(id, url)
{
	var req = false;

	// For Safari, Firefox, and other non-MS browsers
	if (window.XMLHttpRequest)
	{
		try
		{
			req = new XMLHttpRequest();
		}
		catch (e)
		{
			req = false;
		}
	}

	// For Internet Explorer on Windows
	else if (window.ActiveXObject)
	{
		try
		{
			req = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e)
		{
			try
			{
				req = new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e)
			{
				req = false;
			}
		}
	}

	var element = document.getElementById(id);
	if (!element)
	{
		alert("Bad id " + id + "passed to clientSideInclude. You need a div or span element with this id in your page.");
		return;
	}

	if (req)
	{
		// Synchronous request, wait till we have it all
            try
            {
		req.open('GET', url, false);
		req.send(null);
		element.innerHTML = req.responseText;
              if (req.responseText.indexOf("not found") > 0 )
                   element.innerHTML = "";
             }
             catch (e)
			{
element.innerHTML = "";

			}
	}
	else
	{
		element.innerHTML = "";
	}
}




function creater_player(url) {
	document.getElementById('song').innerHTML= '<embed type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="file=' + url + '&autostart=true&showeq=true&repeat=list&shuffle=false" width="400" height="250" wmode="opaque" src="/common/v1/player/mediaplayer.swf" />';
}


try {
	YAHOO.util.Event.onDOMReady(function (ev) {

		var spotlight = YAHOO.util.Dom.get("spotlight");

		var carousel = new YAHOO.widget.Carousel("news-top", {
			animation: {
				speed: 0.5
			},
			numVisible: 1,
			isCircular: true,
			autoPlayInterval: 8000
		});

		var numItems = carousel.get("numItems");
		var numVisible = carousel.get("numVisible");

		carousel.render();
		carousel.show();
		carousel.startAutoPlay();

		var paginator = new YAHOO.widget.Paginator({
				containers : "pagination",
				rowsPerPage : 1,
				template : "{PageLinks} ",
				totalRecords : Math.ceil(numItems / numVisible)
		});

		paginator.subscribe("changeRequest", function (state) {
			carousel.set("selectedItem", (state.page - 1) * numVisible);
			paginator.setState(state);
			carousel.stopAutoPlay();
		});

		carousel.on("pageChange", function (page) {
			// Paginator's page begins from 1
			// Also, we need to suppress this triggering a changeRequest
			// event.
			paginator.setPage(page + 1, true);
		});

		paginator.render();
	});
}
catch (e) {}

/*
function mail_this() {
	try {
		var articleUrl = window.location;
		var articleTitle = $('title').innerHTML;
				alert (1);
		window.open('/service/article/sendmail.vckm?request_locale=vi&siteId=161&articleTitle=' + articleTitle + '&articleUrl=' + articleUrl + '&logoUrl=/common/v1/image/header.jpg', '','width=400,height=550,left=300');
	}
	catch (e) {}
}*/

function mail_this() {
	try {
		var articleUrl = location.pathname;
		var articleTitle = document.getElementById('title').innerHTML;
		var _left = (screen.width - 465)/2;
		var _top = (screen.height - 600)/2;
		window.open('/service/article/sendmail.do?request_locale=vi&siteId=161&articleTitle=' + articleTitle + '&articleUrl=' + articleUrl + '&logoUrl=/common/v1/image/header.gif', '', 'width=550,height=600,left=' + _left + ',top=' + _top);
	}
	catch (e) {}
}

function print_article() {
	try {
		window.open('/channel/4501/');
	}
	catch (e) {}
}




function get_list_cate() {
	var url = "index.next";
	var obj = document.createElement('div');

	var handleSuccess = function(o) {
		if (o.responseText !== undefined) {
			obj.innerHTML = o.responseText;
			var items= obj.getElementsByTagName('blockquote');
			var data = new Array();
			for (var i = 0; i < items.length; i++) {
				data[i] = items[i].innerHTML;
			}

			YAHOO.util.Event.onDOMReady(function() {

				var list = YAHOO.namespace('vsolutions');
				list.content = YAHOO.util.Dom.get('list-cate-next');
					list.handlePagination = function (state) {
					var startIndex = state.recordOffset;
					recs = data.slice(startIndex, startIndex + state.rowsPerPage);
					list.content.start = startIndex + 1;
					list.content.innerHTML = recs.join('');
					list.paginator.setState(state);
				};

				list.paginator = new YAHOO.widget.Paginator({
					rowsPerPage: 10,
					totalRecords: data.length,
					containers: ['paging'],
					template: '{PreviousPageLink} {PageLinks} {NextPageLink}',
					nextPageLinkLabel: 'Trang sau',
					previousPageLinkLabel: 'Trang trước',
					nextPageLinkClass : 'yui-pg-next next',
					previousPageLinkClass : 'yui-pg-previous prev'
				});

				list.paginator.subscribe('changeRequest', list.handlePagination);
				list.paginator.render();
				list.paginator.subscribe('pageChange', function() {
					window.location.href = '#';
				});
				list.handlePagination(list.paginator.getState());

			});

		}
	};

	var handleFailure = function(o) {
		if (o.responseText !== undefined) {return null;}
	};

	var callback = {
		success: handleSuccess,
		failure: handleFailure
	};
	var request = YAHOO.util.Connect.asyncRequest('GET', url, callback);

}

/*Lấy giờ*/
Date.prototype.format = function(config) {
	this.formatString = config.format;
	this.lang = (config.lang) ? config.lang : 'vi';

	this.day = this.getDay();

	this.langText = {
		vi: [
			'Chủ Nhật',
			'Thứ Hai',
			'Thứ Ba',
			'Thứ Tư',
			'Thứ Năm',
			'Thứ Sáu',
			'Thứ Bảy'
		],
		en: [
			'Sunday',
			'Monday',
			'Tuesday',
			'Wednesday',
			'Thursday',
			'Friday',
			'Saturday'
		]
	};

	switch (this.lang) {
		case 'vi':
		case 'en':
		break;

		default:
			this.lang = 'vi';
	}

	this.day = this.langText[this.lang][this.day];

	return this.formatString
		.replace(/DAY/, this.day)
		.replace(/DD/, this.getDate())
		.replace(/MM/, this.getMonth() + 1)
		.replace(/YYYY/, this.getFullYear())
		.replace(/HH/, this.getHours())
		.replace(/MI/, this.getMinutes())
		.replace(/SS/, this.getSeconds())
};

var now = new Date().format({
	format: 'DAY, DD/MM/YYYY HH:MI'
});


function menu_active() {
	
}

function Ie6CountDown() {
	try{
		if ((ie6) || (ie7)){
			var newdiv = document.createElement('div');
			var divIdName = 'isFloat';
			newdiv.setAttribute('id', divIdName);
			newdiv.style.clear = "both";
			newdiv.style.cursor = "pointer";
			newdiv.style.background = "#ffd url(/common/v1/image/warn.gif) no-repeat 5px center";
			newdiv.style.padding = "5px 10px 5px 30px";
			newdiv.style.marginBottom = "10px";
			newdiv.style.borderBottom = "1px solid black"; 
			newdiv.style.position = "relative";
			newdiv.style.zIndex = "1";
			newdiv.style.top="0";
			newdiv.style.font ="10pt Tahoma";
			newdiv.style.color="#000";
			newdiv.onmouseover= linkHover;
			newdiv.onmouseout = linkOut;
			newdiv.onclick = linkClick;
			newdiv.innerHTML="Trình duyệt Internet Explorer của bạn đã lỗi thời. Bấm vào đây để tải về bản mới, nhanh và an toàn hơn.";
			document.body.insertBefore(newdiv, document.getElementById('main'));
		}

	}
	catch (e){}

}

function linkClick() {
	window.open('http://windows.microsoft.com/en-us/internet-explorer/products/ie/home');
} 

function linkHover() {
	this.style.backgroundColor='#316ac5'; 
	this.style.color='white';
} 

function linkOut() {
	this.style.backgroundColor='#ffd'; 
	this.style.color='black';
}
