function load() {
	recomended_banner(0);
	kw(1);
}

function js_cookie_check() {
	if (readCookie('hide_intro') != 'true' ) 	{
		showDiv('black_overlay');
		showDiv('intro_holder');
	}
	getObj('div_top_note').innerHTML = '';
	setCookie('test_cookie', 'test', 1/24/60);
	if (readCookie('test_cookie') != 'test')	{ 
		getObj('div_top_note').innerHTML = '<img src="imgs/sauktukas.gif" style="position: absolute; left: 20px;"><b>Jūsų naršyklėje išjungtas slapukų (Cookies) palaikymas.</b> <br>Svetainės veikimas bus nepilnavertis, o kai kurios funkcijos gali būti nepasiekiamos. &nbsp;&nbsp;<a href="#" title="Kaip įjungti slapukų (Cookies) palaikyma?">Kaip įjungti slapukų (Cookies) palaikyma?</a>';
	} else hideDiv('div_top_note');
}

function recomended_banner(pos) {
	var obj = getObj('div_recomended_banner');
	//fade('div_recomended_banner', 0, 100, 2000);
	//obj.style.top = '-'+(227*pos)+'px';
	$("#div_recomended_banner").animate({"top": "" + (240*pos*-1) + "px"}, "slow", "swing");
	if (pos==3) pos=-1;
	setTimeout('recomended_banner('+(pos+1)+')', 10000);
}
function kw(id) {
	hideDiv('kw_'+id, 1);
	var rand=Math.floor(Math.random()*6)+1;
	if(rand==id) rand=Math.floor(Math.random()*6)+1;
	showDiv('kw_'+rand, 1);
	setTimeout('kw('+(rand)+')', 10000);
}
	


function intro_pos(pos, total) {
	total--;
	var c = getObj('intro_content');
	if (c.style.left == '')	{ c.style.left = '0px'	}
	var new_pos = parseInt(c.style.left) - (240*pos);
	if (new_pos > 0)	{ new_pos = 0 }
	if (new_pos < -total*240)	{ new_pos = -total*240 }
	c.style.left = new_pos+'px';
}


function PopPreview(url) {
	var iMyWidth;
	var iMyHeight;
	//half the screen width minus half the new window width (plus 5 pixel borders).
	iMyWidth = (window.screen.width/2) - (620 + 10);
	//half the screen height minus half the new window height (plus title and status bars).
	iMyHeight = (window.screen.height/2) - (770 + 50);
	//Open the window.
	var win2 = window.open(url,"Window2","status=no,height=700,width=1100,resizable=yes,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
	win2.focus();
}

function PopWin(url, w, h) {
	if (w == undefined) { w = 500; }
	if (h == undefined) { h = 600; }
	var iMyWidth;
	var iMyHeight;
	iMyWidth = (window.screen.width/2) - (620 + 10);
	iMyHeight = (window.screen.height/2) - (770 + 50);
	var win2 = window.open(url,"Window2","status=no,height="+h+",width="+w+",resizable=yes,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",toolbar=no,menubar=no,scrollbars=yes,location=no,directories=no");
	win2.focus();
}

function getObj(objID) {
    if (document.getElementById) {return document.getElementById(objID);}
    else if (document.all) {return document.all[objID];}
    else if (document.layers) {return document.layers[objID];}
}

function confirmme(url,question) {
	var agree = confirm(question);
	if (agree) 	window.location=url; else return false;
}
function confirmajax(url,targetas, question) {
	var agree = confirm(question);
	if (agree) ajax(url,targetas); else {
		next_ajax = '';
		next_ajax2 = '';
		return false;
	}
}

function setclass(id, style) {
	var obj = getObj(id);
	if (obj != undefined) { obj.className = style; }
}


function hideDiv(divid, anim) {
	obj = getObj(divid);
	if (anim){ 
			  var evalMe = "document.getElementById(\""+divid+"\").style.display = \"none\"; changeOpac(\""+divid+"\", 100);";
			  fade(divid, 100, 0, 100, evalMe);	
	} else {
		if (obj != undefined) { obj.style.display = 'none'; }
	}
}
function showDiv(divid, anim) {
	obj = getObj(divid);
	
	if (anim){ 
			  var evalMe = "document.getElementById(\""+divid+"\").style.display = \"block\"; changeOpac(\""+divid+"\", 100);";
			  changeOpac(divid, 0);
			  document.getElementById(divid).style.display = 'block';
			  fade(divid, 0, 100, 500, evalMe);	
	} else {
		if (obj != undefined) { obj.style.display = 'block'; }
	}
}

function showRow(divid){
	browser = BrowserDetect.browser;
	if (browser == 'Explorer') var style = 'block';	else var style = 'table-row';
	if (divid != undefined) { document.getElementById(divid).style.display = style;	}
}
function hideRow(divid){
	if (divid != undefined) { document.getElementById(divid).style.display = '';	}
}

function toggleRow(divid){
	browser = BrowserDetect.browser;
	if (browser == 'Explorer') var style = 'block'; else var style = 'table-row';
	if (divid != undefined) {
	    if(document.getElementById(divid).style.display == ''){
	      document.getElementById(divid).style.display = style;
	    }else{
	      document.getElementById(divid).style.display = '';
	    } 
	}
}
function toggleDiv(divid, anim){
	if (divid != undefined) {
	    if(document.getElementById(divid).style.display == 'none'){
	      if (anim){ 
			  var evalMe = "document.getElementById(\""+divid+"\").style.display = \"block\"; changeOpac(\""+divid+"\", 100);";
			  changeOpac(divid, 0);
			  document.getElementById(divid).style.display = 'block';
			  fade(divid, 0, 100, 500, evalMe);	
		  } else {
			document.getElementById(divid).style.display = 'block';
		  }
	    }else{
		  if (anim){ 
			  var evalMe = "document.getElementById(\""+divid+"\").style.display = \"none\"; changeOpac(\""+divid+"\", 100);";
			  fade(divid, 100, 0, 100, evalMe);	
		  } else {
			document.getElementById(divid).style.display = 'none';
		  }
	    } 
	}
}


function check_email(email, div, nowarn) {
	obj = getObj(div);
	if (obj == undefined)	{ alert('Wrong ID!'); return false;	}
	if (email_preg(email.value))	{
		obj.innerHTML = '<img src="http://upg.lt/zurnalai/imgs/done.gif" alt="OK" title="OK">';
	} else {
		if (!nowarn) {
			obj.innerHTML = '<img src="http://upg.lt/zurnalai/imgs/error_icon.png" alt="!!!" title="Neteisingas el. pato adresas!">';
			blink_class(email.id, 'txt_error', 'txt');
		} else {
			obj.innerHTML = '';
		}
	}
}

function buy_this_issue(url) {
	alert(url);
}

function blink_class(id, class1, class2) {
	if (class2 == '') class2 = getObj(id).className;
	setTimeout('setclass(\''+id+'\', \''+class1+'\')', 200);
	setTimeout('setclass(\''+id+'\', \''+class2+'\')', 300);
	setTimeout('setclass(\''+id+'\', \''+class1+'\')', 400);
	setTimeout('setclass(\''+id+'\', \''+class2+'\')', 500);
}
function email_preg(email) {
	var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	if (filter.test(email)) return true; else return false;
}

function checkAll(field) {
	for (i = 0; i < field.length; i++) field[i].checked = true ;
}
function uncheckAll(field) {
	for (i = 0; i < field.length; i++) 	field[i].checked = false ;
}


function centerDiv(divid) {
	obj = getObj(divid);
	alert("screen: "+screen.availHeight+"h "+screen.availWidth+"w");
	alert("element: "+obj.offsetHeight+" h ");
    var IpopTop = (document.body.offsetHeight - document.getElementById(divid).offsetHeight)/2;
    var IpopLeft = (document.body.offsetWidth - document.getElementById(divid).offsetWidth)/2;
    document.getElementById(divid).style.left=IpopLeft + document.body.scrollLeft;
    document.getElementById(divid).style.top=IpopTop + document.body.scrollTop;
}


var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();


function changeOpac(id, opacity) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}
function fade(id, opacStart, opacEnd, millisec, evalMe) {
	id = document.getElementById(id);
    var speed = Math.round(millisec / 100);
    var timer = 0;
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--) {
            setTimeout(		"changeOpac('" + id.id + "','" + i + "')"		,(timer * speed));
            timer++;
        }
		if (eval != undefined) { setTimeout(		"eval('" + evalMe + "')"		,(timer * speed));	}

    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
            {
            setTimeout(		"changeOpac('" + id.id + "','" + i + "')"		,(timer * speed));
            timer++;
        } 
		if (eval != undefined) { setTimeout(		"eval('" + evalMe + "')"		,(timer * speed));	}

    } 
} 

function setCookie(cookieName,cookieValue,nDays) {
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	//document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString()+'; path=/;domain=zurnalai.lt';
	document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString()+'; path=/;';
}

function readCookie(cookieName) {
	var theCookie=""+document.cookie;
	var ind=theCookie.indexOf(cookieName);
	if (ind==-1 || cookieName=="") return ""; 
	var ind1=theCookie.indexOf(';',ind);
	if (ind1==-1) ind1=theCookie.length; 
	return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

function gat(category, action, optional_label, optional_value) {
	zurnalai_pageTracker._trackEvent(category, action, optional_label, optional_value);
}	