// JavaScript Document
function resize_width() {
	var width;
	width=$('.center').width();
	width-=203;
	$('.right_block').width(width);
	
}
function show_reg() {
	close_avt_reg();
	$('#registration_div').fadeIn(300);
}
function show_avt() {
	close_avt_reg();
	$('#author_div').fadeIn(300);
}
function close_avt_reg() {
	document.getElementById("registration_div").style.display='none';	
	document.getElementById("author_div").style.display='none';	
}
function showvideo(i) {
	newwindow=window.open('popupvideo.php?id='+i,'name','width=465,height=380');
	if (window.focus) {newwindow.focus()}
	return false;
}
function on_submit() {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; 
	if(document.reg_form.reggender.value=='0' || document.reg_form.regmail.value=='' || document.reg_form.regpassword.value=='' || document.reg_form.regname.value=='' || document.reg_form.regsurename.value=='' || document.reg_form.regyear.value=='0' || document.reg_form.regmonth.value=='0' || document.reg_form.regday.value=='0' || reg.test(document.reg_form.regmail.value) == false ) { 
		if(document.reg_form.reggender.value=='0' || document.reg_form.regmail.value=='' || document.reg_form.regpassword.value=='' || document.reg_form.regname.value=='' || document.reg_form.reglname.value=='' || document.reg_form.regyear.value=='0' || document.reg_form.regmonth.value=='0' || document.reg_form.regday.value=='0') 
			alert('გთხოვთ შეავსოთ ყველა ველი'); 
		else 
			alert('გთხოვთ შეიყვანეთ მოქმედი ელფოსტის მისამართი'); 
		return false; 
	}	
	else
		return true;
}

function google_counter() {
	$.ajax({
	   type: "POST",
	   url: "ajax/google_counter.php",
	   cache: true,
	   success: function(msg){
		   $("#google_counter").html(msg);
	   }
	});
}


function question(menu_id) { 
	var question_id=eval("document.question_form_"+menu_id+".question_id_"+menu_id+".value");
	var answer_id=0;
	for (var i=0; i < eval("document.question_form_"+menu_id+".answer_"+menu_id+".length"); i++)
    {
	   if (eval("document.question_form_"+menu_id+".answer_"+menu_id)[i].checked)
		  {
		  	answer_id = eval("document.question_form_"+menu_id+".answer_"+menu_id)[i].value;
		  }
  	}
	if(answer_id==0) {
		alert("მონიშნეთ რომელიმე პასუხი");
	} else {
		$.ajax({
		   type: "GET",
		   url: "ajax/question.php",
		   cache: true,
		   data: "question_id="+question_id+"&answer_id="+answer_id,
		   success: function(msg){
			   $("#gamokitkhva_"+menu_id).html(msg);
		   }
		});
	}
}







function gamokitkhva(id,poll_group,color,index) {
	var name="#div_"+poll_group+"_"+index;
	$.ajax({
	   type: "GET",
	   url: "ajax/poll.php",
	   cache: true,
	   data: "poll_group="+poll_group+"&id="+id+"&color="+color+"&index="+index,
	   success: function(msg){
		   $(name).html(msg);
		   $(".poll_title").easyTooltip();
	   }
	});
}




function show_facebook(url) {
	newwindow=window.open(url,'facebook.com','width=565,height=380');
	if (window.focus) {newwindow.focus()}
	return false;
}









function ateuli() { 
	var xmlhttp; 
	if (window.XMLHttpRequest) 
	{ // code for IE7+, Firefox, Chrome, Opera, Safari 
		xmlhttp=new XMLHttpRequest(); 
	} else if (window.ActiveXObject) { 
		// code for IE6, IE5 
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
	} else { 
		alert("Your browser does not support XMLHTTP!"); 
	} 
	xmlhttp.onreadystatechange=function() { 
		if(xmlhttp.readyState==4) { 
			document.getElementById("right_10").innerHTML=xmlhttp.responseText; 
		} 
		else { 
			document.getElementById("right_10").innerHTML='<div style="position:relative; left:10px; top:10px; font-size:17px; font-weight:bold; color:#000;">loading...</div>';  
		}	 
	} 
	var url="right_10.php"; 
	xmlhttp.open("GET",url,true); 
	xmlhttp.send(null); 
}

var right_box_cur=0;
function right_box(i,cat,stat_id) {
	var name;
	if(right_box_cur!=i) {
		name='right_box_top_'+i;
		document.getElementById(name).src='img/right_box_'+i+'1.jpg';
		if(right_box_cur!=0) {
			name='right_box_top_'+right_box_cur;
			document.getElementById(name).src='img/right_box_'+right_box_cur+'.jpg';
		}
		if(i==1) {reitinguli(cat);}
		if(i==2) {now_read();}
		if(i==3) {rekomendebuli(stat_id);}
		if(i==4) {axali(stat_id,cat);}
		right_box_cur=i;
	}
}

function now_read() { 
	var xmlhttp; 
	if (window.XMLHttpRequest) 
	{ // code for IE7+, Firefox, Chrome, Opera, Safari 
		xmlhttp=new XMLHttpRequest(); 
	} else if (window.ActiveXObject) { 
		// code for IE6, IE5 
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
	} else { 
		alert("Your browser does not support XMLHTTP!"); 
	} 
	xmlhttp.onreadystatechange=function() { 
		if(xmlhttp.readyState==4) { 
			document.getElementById("right_box_content").innerHTML=xmlhttp.responseText; 
		} 
		else { 
			document.getElementById("right_box_content").innerHTML='<div style="position:relative; left:10px; top:10px; font-size:17px; font-weight:bold; color:#000;">loading...</div>';  
		}	 
	} 
	var url="now_read.php"; 
	xmlhttp.open("GET",url,true); 
	xmlhttp.send(null); 
}

function reitinguli(cat) { 
	var xmlhttp; 
	if (window.XMLHttpRequest) 
	{ // code for IE7+, Firefox, Chrome, Opera, Safari 
		xmlhttp=new XMLHttpRequest(); 
	} else if (window.ActiveXObject) { 
		// code for IE6, IE5 
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
	} else { 
		alert("Your browser does not support XMLHTTP!"); 
	} 
	xmlhttp.onreadystatechange=function() { 
		if(xmlhttp.readyState==4) { 
			document.getElementById("right_box_content").innerHTML=xmlhttp.responseText; 
		} 
		else { 
			document.getElementById("right_box_content").innerHTML='<div style="position:relative; left:10px; top:10px; font-size:17px; font-weight:bold; color:#000;">loading...</div>';  
		}	 
	} 
	var url="reitinguli.php?cat="+cat; 
	xmlhttp.open("GET",url,true); 
	xmlhttp.send(null); 
}

function rekomendebuli(id) { 
	var xmlhttp; 
	if (window.XMLHttpRequest) 
	{ // code for IE7+, Firefox, Chrome, Opera, Safari 
		xmlhttp=new XMLHttpRequest(); 
	} else if (window.ActiveXObject) { 
		// code for IE6, IE5 
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
	} else { 
		alert("Your browser does not support XMLHTTP!"); 
	} 
	xmlhttp.onreadystatechange=function() { 
		if(xmlhttp.readyState==4) { 
			document.getElementById("right_box_content").innerHTML=xmlhttp.responseText; 
		} 
		else { 
			document.getElementById("right_box_content").innerHTML='<div style="position:relative; left:10px; top:10px; font-size:17px; font-weight:bold; color:#000;">loading...</div>';  
		}	 
	} 
	var url="rekomendebuli.php?id="+id; 
	xmlhttp.open("GET",url,true); 
	xmlhttp.send(null); 
}
function axali(id,cat) { 
	var xmlhttp; 
	if (window.XMLHttpRequest) 
	{ // code for IE7+, Firefox, Chrome, Opera, Safari 
		xmlhttp=new XMLHttpRequest(); 
	} else if (window.ActiveXObject) { 
		// code for IE6, IE5 
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
	} else { 
		alert("Your browser does not support XMLHTTP!"); 
	} 
	xmlhttp.onreadystatechange=function() { 
		if(xmlhttp.readyState==4) { 
			document.getElementById("right_box_content").innerHTML=xmlhttp.responseText; 
		} 
		else { 
			document.getElementById("right_box_content").innerHTML='<div style="position:relative; left:10px; top:10px; font-size:17px; font-weight:bold; color:#000;">loading...</div>';  
		}	 
	} 
	var url="axali.php?cat="+cat+"&id="+id; 
	xmlhttp.open("GET",url,true); 
	xmlhttp.send(null); 
}

function gamokitxva_answer(pas,gmk_id, cat)
{	
	if(pas>0) {
		var xmlhttp; 
		if (window.XMLHttpRequest) 
		{ // code for IE7+, Firefox, Chrome, Opera, Safari 
			xmlhttp=new XMLHttpRequest(); 
		} else if (window.ActiveXObject) { 
			// code for IE6, IE5 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} else { 
			alert("Your browser does not support XMLHTTP!"); 
		} 
		xmlhttp.onreadystatechange=function() { 
			if(xmlhttp.readyState==4) { 
				document.getElementById("div"+gmk_id).innerHTML=xmlhttp.responseText; 
			} 
			else { 
				//document.getElementById("right_box_content").innerHTML="<div style='position:relative; left:10px; top:10px; font-size:17px; font-weight:bold; color:#000;'>loading...</div>";  
			}	 
		} 
		var url="answer.php?pas="+pas+"&gmk_id="+gmk_id+"&cat="+cat; 
		xmlhttp.open("GET",url,true); 
		xmlhttp.send(null);
	}
	return false;
}

function right_poll_cat(cat,type) {
	var xmlhttp; 
	if (window.XMLHttpRequest) 
	{ // code for IE7+, Firefox, Chrome, Opera, Safari 
		xmlhttp=new XMLHttpRequest(); 
	} else if (window.ActiveXObject) { 
		// code for IE6, IE5 
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
	} else { 
		alert("Your browser does not support XMLHTTP!"); 
	} 
	xmlhttp.onreadystatechange=function() { 
		if(xmlhttp.readyState==4) { 
			document.getElementById("right_poll_cat").innerHTML=xmlhttp.responseText; 
		} 
		else { 
			//document.getElementById("cat_top").innerHTML="<div style='position:relative; left:10px; top:10px; font-size:17px; font-weight:bold; color:#000;'>loading...</div>";  
		}	 
	} 
	var url="right_poll_cat.php?cat="+cat+"&type="+type; 
	xmlhttp.open("GET",url,true); 
	xmlhttp.send(null); 
}
function right_poll_q(cat,id,type) {
	var xmlhttp; 
	if (window.XMLHttpRequest) 
	{ // code for IE7+, Firefox, Chrome, Opera, Safari 
		xmlhttp=new XMLHttpRequest(); 
	} else if (window.ActiveXObject) { 
		// code for IE6, IE5 
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
	} else { 
		alert("Your browser does not support XMLHTTP!"); 
	} 
	xmlhttp.onreadystatechange=function() { 
		if(xmlhttp.readyState==4) { 
			document.getElementById("right_poll_question").innerHTML=xmlhttp.responseText; 
		} 
		else { 
			//document.getElementById("cat_top").innerHTML="<div style='position:relative; left:10px; top:10px; font-size:17px; font-weight:bold; color:#000;'>loading...</div>";  
		}	 
	} 
	var url="right_poll_q.php?cat="+cat+"&id="+id+"&type="+type; 
	xmlhttp.open("GET",url,true); 
	xmlhttp.send(null); 
}

var show_main_cat_cur=0;
function show_main_cat() {
	show_main_cat_cur++;
	if(show_main_cat_cur%2==1) {
		document.getElementById("main_cat_list").style.display='block';
	} else {
		document.getElementById("main_cat_list").style.display='none';
	}
	
}
function show_cat(i) {
	document.getElementById("main_cat_list_"+i).style.display='block';
}
function hide_cat(i) {
	document.getElementById("main_cat_list_"+i).style.display='none';
}
function main_cat(cat,i) { 
	setCookie("main_cat_"+i,cat,7);
	var xmlhttp; 
	if (window.XMLHttpRequest) 
	{ // code for IE7+, Firefox, Chrome, Opera, Safari 
		xmlhttp=new XMLHttpRequest(); 
	} else if (window.ActiveXObject) { 
		// code for IE6, IE5 
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
	} else { 
		alert("Your browser does not support XMLHTTP!"); 
	} 
	xmlhttp.onreadystatechange=function() { 
		if(xmlhttp.readyState==4) { 
			document.getElementById("main_cat_"+i).innerHTML=xmlhttp.responseText; 
			jQuery('#mycarousel_main_cat_'+i).jcarousel();
		} 
		else { 
			document.getElementById("main_cat_"+i).innerHTML='<div style="position:relative; left:10px; top:10px; font-size:17px; font-weight:bold; color:#000;">loading...</div>';  
		}	 
	} 
	var url="main_cat.php?cat="+cat+"&i="+i; 
	xmlhttp.open("GET",url,true); 
	xmlhttp.send(null); 
}
function setCookie(c_name,value,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}
function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}

function cat_top(cat,id,i,type) { 
	var name;
	if(i!=cur_cat_bottom) {
		name='cat_bottom_'+type+'_'+i;
		document.getElementById(name).src='img/news_'+i+'_2.jpg';
		
		if(cur_cat_bottom!=0) {
			name='cat_bottom_'+type+'_'+cur_cat_bottom;
			document.getElementById(name).src='img/news_'+cur_cat_bottom+'_1.jpg';
		}
		cur_cat_bottom=i;
	}
	
	var xmlhttp; 
	if (window.XMLHttpRequest) 
	{ // code for IE7+, Firefox, Chrome, Opera, Safari 
		xmlhttp=new XMLHttpRequest(); 
	} else if (window.ActiveXObject) { 
		// code for IE6, IE5 
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
	} else { 
		alert("Your browser does not support XMLHTTP!"); 
	} 
	xmlhttp.onreadystatechange=function() { 
		if(xmlhttp.readyState==4) { 
			if(type==1) {
				document.getElementById("cat_top").innerHTML=xmlhttp.responseText; 
				jQuery('#mycarousel_cat_1').jcarousel();
			} else {
				document.getElementById("cat_bottom").innerHTML=xmlhttp.responseText; 
				jQuery('#mycarousel_cat_2').jcarousel();
			}
		} 
		else { 
			if(type==1) {
				document.getElementById("cat_top").innerHTML='<div style="position:relative; left:10px; top:10px; font-size:17px; font-weight:bold; color:#000;">loading...</div>';  
			} else {
				document.getElementById("cat_bottom").innerHTML='<div style="position:relative; left:10px; top:10px; font-size:17px; font-weight:bold; color:#000;">loading...</div>';
			}
		}	 
	} 
	var url="cat_top.php?cat="+cat+"&id="+id+"&i="+i+"&type="+type; 
	xmlhttp.open("GET",url,true); 
	xmlhttp.send(null); 
	
}




function testform(pas,id,qid,test) { 
	var k=0;
	for (i=0;i<document.getElementById(id).elements.length;i++) {
		if (document.getElementById(id).elements[i].checked) {k++;}
	}
	if(k<1) {  
		alert('გთხოვთ აირჩიოთ პასუხის რომელიმე ვარიანტი');  
	} else {
		var xmlhttp; 
		if (window.XMLHttpRequest) 
		{ // code for IE7+, Firefox, Chrome, Opera, Safari 
			xmlhttp=new XMLHttpRequest(); 
		} else if (window.ActiveXObject) { 
			// code for IE6, IE5 
			xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
		} else { 
			alert("Your browser does not support XMLHTTP!"); 
		} 
		xmlhttp.onreadystatechange=function() { 
			if(xmlhttp.readyState==4) { 
				document.getElementById("testform").innerHTML=xmlhttp.responseText; 
			} 
			else { 
				//document.getElementById("testform").innerHTML='<div style="position:relative; left:10px; top:10px; font-size:17px; font-weight:bold; color:#000;">loading...</div>';  
			}	 
		} 
		var url="test.php";	
		url=url+"?pas="+pas+"&qid="+qid+"&test="+test;
		xmlhttp.open("GET",url,true); 
		xmlhttp.send(null);
	}
}



