function setCookie(name,value,days) {
 if (days) {
   var date = new Date();
   date.setTime(date.getTime()+(days*24*60*60*1000));//
   var expires = ";expires="+date.toGMTString();
 } else {
   expires = "";
 }
 document.cookie = name+"="+value+expires+";path=/";
}

function readCookie(name) {
 var needle = name + "=";
 var cookieArray = document.cookie.split(';');
 
 for(var i=0;i < cookieArray.length;i++) {
   var pair = cookieArray[i];
   while (pair.charAt(0)==' ') {
     pair = pair.substring(1, pair.length);
	 
   }
   if (pair.indexOf(needle) == 0) {
     return pair.substring(needle.length, pair.length);
   }
 }
 return null;
}

function swapView(addID, removeID){
 var e = document.getElementById(addID);
 e.setAttribute("class", addID+'_active');
 e.setAttribute("className", addID+'_active'); // for IE which does not recognize "class"

 setCookie("view", addID, 365);
 setCookie("unview", removeID, 365);

 var ee = document.getElementById(removeID);
 ee.setAttribute("class", removeID+'_inactive');
 ee.setAttribute("className", removeID+'_inactive');
 return;
}

function setupBody(){
  var doc; var doc2;		
  var mode1 = readCookie('view');
  var mode0 = readCookie('unview');
  if (mode1){  	
	doc = document.getElementById(mode1);
 	doc.setAttribute("class", mode1+'_active');
	doc.setAttribute("className", mode1+'_active');
	
	if (mode1=='view1'){  
		display("blokasby1", "blokasby3");		
	}else{	
		display("blokasby3", "blokasby1");
	}
	
	doc2 = document.getElementById(mode0);
	doc2.setAttribute("class", mode0+'_inactive');
	doc2.setAttribute("className", mode0+'_inactive');
  }else{
	doc = document.getElementById("view3");
 	doc.setAttribute("class", "view3_active"); 
	doc2 = document.getElementById("view1");  
  	doc2.setAttribute("class", "view1_inactive");
  }
  return;
}

function submit_form(vars){	
	vars.submit();
	
}

function value(num,select_name){
	document.getElementById(select_name).value=num;	
	form_name=select_name+'_form';
	submit_form(document.forms[form_name]);
}

function display(id, idne) {	
	if (document.getElementById(id).style.display=="block"){
		document.getElementById(idne).style.display="none";
		document.getElementById(id).style.display="block";
	} else {
		document.getElementById(id).style.display="block";
		document.getElementById(idne).style.display="none";
	}
}

function display2(id, idne) {
	if (document.getElementById(id).style.display=="block"){
		document.getElementById(id).style.display="none";
		document.getElementById(idne).style.display="block";
	} 
}

function itraukti(pid,uid){
	var xmlhttp;
	var gURL = '../inc/itraukti.php?pid='+pid+'&uid='+uid;
   if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc
		   xmlhttp=new XMLHttpRequest();
		  if (xmlhttp.overrideMimeType) {
				 xmlhttp.overrideMimeType('text/xml');
		  }
	
		  xmlhttp.open("GET", gURL, true);
		  xmlhttp.send(null);
   } else if (window.ActiveXObject) { //IE
		  xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
		  if (xmlhttp) {
				 xmlhttp.open('GET', gURL, true);
				 xmlhttp.send();
		  }
   }
}
function isimti(pid,uid){
	var xmlhttp;	
	var gURL = '../inc/isimti.php?pid='+pid+'&uid='+uid;
	
   if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc
		   xmlhttp=new XMLHttpRequest();
		  if (xmlhttp.overrideMimeType) {
				 xmlhttp.overrideMimeType('text/xml');
		  }      	
		  xmlhttp.open("GET", gURL, true);
		  xmlhttp.send(null);
   } else if (window.ActiveXObject) { //IE
		  xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
		  if (xmlhttp) {
				 xmlhttp.open('GET', gURL, true);
				 xmlhttp.send();
		  }
   }
}

function ivertinimas(pid,rate){
	temp = new Object();
	temp.pid = pid;
	var gURL = '../inc/ivertinimas.php?pid='+pid+'rate'+rate;
	
   if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc
		   xmlhttp=new XMLHttpRequest();
		  if (xmlhttp.overrideMimeType) {
				 xmlhttp.overrideMimeType('text/xml');
		  }      
		xmlhttp.onreadystatechange=loadivertinimas;
	
		  xmlhttp.open("GET", gURL, true);
		  xmlhttp.send(null);
   } else if (window.ActiveXObject) { //IE
		  xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
		  if (xmlhttp) {
				 xmlhttp.onreadystatechange=loadivertinimas;
				 xmlhttp.open('GET', gURL, true);
				 xmlhttp.send();
		  }
   }
}

function loadivertinimas() {	
   if (xmlhttp.readyState==4) {
	  if (xmlhttp.status==200) {
		 var pid = temp.pid;	
		// document.getElementById('post-ratings-'+pid+'du').innerHTML=xmlhttp.responseText;
		 document.getElementById('ivertinimas').innerHTML=xmlhttp.responseText;
	 }
   }
}



function show_error(txt) {
	var obje = document.getElementById('atliekama');	
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	obje.style.left = (arrayPageSize[2] / 2 - 50)+"px"; // 200 - puse langelio plocio
	obje.style.top = (arrayPageScroll[1] + arrayPageSize[3] / 2 - 20)+"px"; // 60 - puse langelio aukscio
	obje.style.display='block';
	obje.innerHTML=txt;	
	setTimeout(function(){document.getElementById('atliekama').style.display='none'},1000);	
	
	
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}

}



function load(gid){
	temp = new Object();
	temp.pid = gid;
	var gURL = '../inc/gs.php?gid='+gid;
	
   if (window.XMLHttpRequest) { // code for Mozilla, Safari,
		   xmlhttp=new XMLHttpRequest();
		  if (xmlhttp.overrideMimeType) {
				 xmlhttp.overrideMimeType('text/xml');
		  }      
		xmlhttp.onreadystatechange=loading;
	
		  xmlhttp.open("GET", gURL, true);
		  xmlhttp.send(null);
   } else if (window.ActiveXObject) { //IE
		  xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
		  if (xmlhttp) {
				 xmlhttp.onreadystatechange=loading;
				 xmlhttp.open('GET', gURL, true);
				 xmlhttp.send();
		  }
   }
}

function loading() {	
   if (xmlhttp.readyState==4) {
	  if (xmlhttp.status==200) {
		 var gid = temp.gid;	
		 document.getElementById('game_screen').innerHTML=xmlhttp.responseText;
	 }
   }
}




/* <![CDATA[ */
var ratingsL10n = {
	plugin_url: "",
	ajax_url: "http://www.zaidimai2.lt/inc/rating.php",
	text_wait: "Balsuoti galima 1 karta.",
	image: "../img/rating",
	image_ext: "gif",
	max: "5",
	show_loading: "0",
	show_fading: "0",
	custom: "0"
};
var ratings_mouseover_image=new Image();
//ratings_mouseover_image.src=ratingsL10n.plugin_url+"/images/"+ratingsL10n.image+"/rating_over."+ratingsL10n.image_ext;
ratings_mouseover_image.src=ratingsL10n.image+"/rating_over."+ratingsL10n.image_ext;
/* ]]> */


