function isMobileDevice() {
    var ua = navigator.userAgent.toLowerCase();

    if (ua == null)
        return false;

    var match = new RegExp('iphone|ipod|blackberry|opera mini|opera mobi|nokia|android|symbian|windows ce|ppc;|iemobile|smartphone|up.browser|up.link|sonyericsson|motorola|tablet browser|midp|portalmmm|htc |htc_|htc-|sqh|hp |hp-|spv|palm|xda |xda_|vodafone|configuration/cldc|mmp|pocket|kindle|mobile|alcatel|samsung|sgh-|tianyu|openwave|wap_browser|wap browser|phone|asus');
    if (match.exec(ua) != null)
        return true;

    if (ua.length >= 4) {
        var match2 = new RegExp('acs-|amoi|benq|doco|eric|huaw|lct_|lg(-|/|_| |\w)*|leno|mobi|mot-|moto|nec-|pana|phil|sage|sams|sec-|sch-|sgh-|shar|sie-|sony|wap_|zte-');
        if (match2.exec(ua.substring(0, 4)) != null)
            return true;
    }

    return false;
}

function getUrlVars() {
    var vars = {};
    var parts = window.location.href.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(m,key,value) {
        vars[key] = typeof(value) !==undefined  ? value : true;
    });
    return vars;
}

function setCookie(c_name,value,exhours)
{
	var exdate=new Date();
	exdate.setHours(exdate.getHours() + exhours);
	var c_value=escape(value) + ((exhours==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}
function getCookie(c_name)
{
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++)
	{
	  x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
	  y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
	  x=x.replace(/^\s+|\s+$/g,"");
	  if (x==c_name)
	    {
		return unescape(y);
		}
	}
}

if(typeof(getUrlVars()['nomobile']) !== 'undefined') {
	setCookie('nomobile', 1, 5);
}

if(typeof(getCookie('nomobile')) === 'undefined') {
	if(isMobileDevice()){
		var sitemobpath = 'http://m.evz.ro';
		urlCurent = window.location.href;
		partUrlCurent = urlCurent.split("/");
		nrParts = partUrlCurent.length;
		if(partUrlCurent[3] == 'detalii' && partUrlCurent[4] =='stiri'){
			partsNews = partUrlCurent[5].split("-");
			nrElem = partsNews.length;
			newsId = partsNews[nrElem-1].replace('.html',"");
			window.location.href = sitemobpath + '/news/' + newsId;
		}
		else {
			window.location.href = sitemobpath;
		}
	}
}
