﻿function pg(src,id)
{ 
	var isposible=0;
	var img;
	var s=src.lastIndexOf('/')+1;
	var address=src.substring(0,s);
	src=src.substring(s);
	for(var i=1;i<4;i++)
	{
		var ok=0;
		img=document.getElementById('img'+i).src;
		s=img.lastIndexOf('/')+1;
		img=img.substring(s); 
		if(img == src)
		{ 
			document.getElementById('img'+i).src='admin/upload/spacer.gif';
			document.form.elements[i-1].value='';
			isposible=1;
			return;
		}
	}
	
	for(i=1;i<4;i++)
	{ 
			s=document.getElementById('img'+i).src.lastIndexOf('/')+1;
			var imagesrc=document.getElementById('img'+i).src.substring(s); 
			if(imagesrc=='spacer.gif' || imagesrc=='question.gif' )
			{	
				document.getElementById('img'+i).src=address+src;
				document.form.elements[i-1].value=id;
				isposible=1;
				return;
			}
	}
	
	if(isposible==0)
	alert('თქვენ უკვე შეავსეთ ყველა ადგილი, თუ გსურთ მისცეთ ხმა ამ სურათს ჯერ გააცარიელეთ რომელიმე ადგილი შესაბამის სურათზე დაკლიკებით');
}
function  validation()
{
for(i=0;i<3;i++)
	{ 
		if(document.form.elements[i].value=='')
		{
			alert('გთხოვთ მიუთითოთ ყველა ადგილი');
			return false;
		}
	}
}
function pg_def()
{ 
var s;
var imagesrc;
var q=0;
	for(i=1;i<4;i++)
	{ 
			s=document.getElementById('img'+i).src.lastIndexOf('/')+1;
			imagesrc=document.getElementById('img'+i).src.substring(s);  
			if(imagesrc=='question.gif')
			{	
				q=i;
			}
	}
	for(i=1;i<4;i++)
	{ 
			s=document.getElementById('img'+i).src.lastIndexOf('/')+1;
			imagesrc=document.getElementById('img'+i).src.substring(s);  
			if(imagesrc=='spacer.gif')
			{	
				if(q==0)
				{
					document.getElementById('img'+i).src='admin/upload/question.gif';
					return;
				}
				else
				if(q<i)
				{
					return;
				}
				else
				{
					document.getElementById('img'+i).src='admin/upload/question.gif';
					document.getElementById('img'+q).src='admin/upload/spacer.gif';
					document.form.elements[q-1].value='';
					return;
				}
				
			}
	}
}
function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        auto: 4,
        wrap: 'last',
        initCallback: mycarousel_initCallback
    });
});


eng=new Array(97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,87,82,84,83,67,74,90);
geo=new Array(4304,4305,4330,4307,4308,4324,4306,4336,4312,4335,4313,4314,4315,4316,4317,4318,4325,4320,4321,4322,4323,4309,4332,4334,4327,4310,4333,4326,4311,4328,4329,4319,4331,91,93,59,39,44,46,96);
function Is ()
{
    var agt=navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.nav  = (
		(agt.indexOf('mozilla')!=-1)      
		&& (agt.indexOf('spoofer')==-1)
                && (agt.indexOf('compatible') == -1) 
		&& (agt.indexOf('opera')==-1)   
		&& (agt.indexOf('konqueror')==-1)             
		&& (agt.indexOf('safari')==-1)                  
                && (agt.indexOf('webtv')==-1) 
		&& (agt.indexOf('hotjava')==-1)
		);
if  ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('konqueror')>=0) || (agt.indexOf('safari')>=0))) {this.nav=true;} 
    this.nav2 = (this.nav && (this.major == 2));
    this.nav3 = (this.nav && (this.major == 3));
    this.nav4 = (this.nav && (this.major == 4));
    this.nav4up = (this.nav && (this.major >= 4));
    this.navonly      = (this.nav && ((agt.indexOf(";nav") != -1) ||
                          (agt.indexOf("; nav") != -1)) );
    this.nav6 = (this.nav && (this.major == 5));
    this.nav6up = (this.nav && (this.major >= 5));
    this.gecko = (agt.indexOf('gecko') != -1);
    this.ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    this.ie3    = (this.ie && (this.major < 4));
    this.ie4    = (this.ie && (this.major == 4) && (agt.indexOf("msie 4")!=-1) );
    this.ie4up  = (this.ie && (this.major >= 4));
    this.ie5    = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    this.ie5_5  = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.5") !=-1));
    this.ie5up  = (this.ie && !this.ie3 && !this.ie4);
    this.ie5_5up =(this.ie && !this.ie3 && !this.ie4 && !this.ie5);
    this.ie6    = (this.ie && (this.major == 4) && (agt.indexOf("msie 6.")!=-1) );
    this.ie6up  = (this.ie && !this.ie3 && !this.ie4 && !this.ie5 && !this.ie5_5);
    this.aol   = (agt.indexOf("aol") != -1);
    this.aol3  = (this.aol && this.ie3);
    this.aol4  = (this.aol && this.ie4);
    this.aol5  = (agt.indexOf("aol 5") != -1);
    this.aol6  = (agt.indexOf("aol 6") != -1);
    this.opera = (agt.indexOf("opera") != -1);
    this.opera2 = (agt.indexOf("opera 2") != -1 || agt.indexOf("opera/2") != -1);
    this.opera3 = (agt.indexOf("opera 3") != -1 || agt.indexOf("opera/3") != -1);
    this.opera4 = (agt.indexOf("opera 4") != -1 || agt.indexOf("opera/4") != -1);
    this.opera5 = (agt.indexOf("opera 5") != -1 || agt.indexOf("opera/5") != -1);
    this.opera6 = (agt.indexOf("opera 6") != -1 || agt.indexOf("opera/6") != -1);
    this.opera7 = (agt.indexOf("opera 7") != -1 || agt.indexOf("opera/7") != -1);
    this.opera7up = (this.opera && !this.opera2 && !this.opera3 && !this.opera4 && !this.opera5 && !this.opera6 && !this.opera7 );
    this.webtv = (agt.indexOf("webtv") != -1); 
    this.TVNavigator = ((agt.indexOf("navio") != -1) || (agt.indexOf("navio_aoltv") != -1)); 
    this.AOLTV = this.TVNavigator;
    this.hotjava = (agt.indexOf("hotjava") != -1);
    this.hotjava3 = (this.hotjava && (this.major == 3));
    this.hotjava3up = (this.hotjava && (this.major >= 3));
    this.konqueror=   (agt.indexOf("konqueror") != -1); 
    this.safari=   (agt.indexOf("safari") != -1);   
}
function handleKeys(e)
{
var key=(window.event)?event : e;
if(key.altKey || key.ctrlKey) return true;

var theKey
theKey = e.which
if (e.which==96) geoobj.checked = !geoobj.checked;

var i=formobj.value.length - 1;
if (e.which==96) { var f=e.target; var g=f.selectionStart; f.value=f.value.substring(0, f.selectionStart)+""+ f.value.substring(f.selectionEnd); f.setSelectionRange(g,g); return false;}
if (geoobj.checked )
{
	for (i=0; i<=geo.length; i++){
		if (eng[i]==e.which){
			var f=e.target; 
			var g=f.selectionStart;  
 			var b1=f.selectionStart;
	    	var b2=f.selectionEnd;
			var str=f.value		
			f.value=str.substring(0,b1)+String.fromCharCode(geo[i])+str.substring(b2);
			g++; 
			f.setSelectionRange(g,g); 
			return false;
		}
	}
status=theKey;
}
return true;
}

function changeVal(formobj2,geoobj2)
{
formobj=formobj2;
geoobj=geoobj2;
var is=new Is();
if (is.konqueror && formobj.value=='') {formobj.value=" ";} 
if (is.ie4up)  { 
if (event.keyCode==96) geoobj.checked = geoobj.checked ? false : true;
if (event.keyCode==96) event.keyCode=''; 
} else if (is.nav6up    || is.konqueror || is.safari) {	
	document.onkeypress = handleKeys;
}
if (geoobj.checked)
{
if (is.ie4up || (is.opera && !is.opera7up))  {	
var theKey
theKey=event.keyCode
	for (i=0; i<=geo.length; i++){
		if (eng[i]==event.keyCode) {
			event.keyCode=geo[i];
		}
	}
status = theKey;
}
else if (is.nav6up  || is.opera ) {  
        document.onkeypress = handleKeys;
} else {
    alert("We doesn't currently support your browser");
    geoobj.checked=false;
  }
 }
}

var xmlhttp
function detsearch(num, all_kat)
{
	xmlhttp=GetXmlHttpObject_s();
	if (xmlhttp==null)
	  {
	  alert ("Your browser does not support XMLHTTP!");
	  return;
	  }
	var url="ajax_detsearch.php";
	
	var kat='';
	if(all_kat==1)
	{
		for(var i=0 ; i< num; i++)
		{
			
				var j=i+1;
				kat=kat+j+'-';
	
		}
	}
	else
	{
		for(var i=0 ; i< num; i++)
		{
			if(document.getElementById('box'+i).checked==true)	
			{
				var j=i+1;
				kat=kat+j+'-';
				
			}
		}
	}
	url=url+"?kat="+kat;
	xmlhttp.onreadystatechange=stateChanged_s;
	xmlhttp.open("GET",url,true);
	xmlhttp.send(null);
}
function stateChanged_s()
{
if (xmlhttp.readyState==4)
  {
  document.getElementById("person").innerHTML=xmlhttp.responseText;
  }
}

function GetXmlHttpObject_s()
{
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  return new XMLHttpRequest();
  }
if (window.ActiveXObject)
  {
  // code for IE6, IE5
  return new ActiveXObject("Microsoft.XMLHTTP");
  }
return null;
}