function showp(im) {
	var t = document.getElementById('large_photo');
	t.src = im;
}


function del(id) {
var answer = confirm ("ნამდვილად გსურთ ამ ჩანაწერის წაშლა?");
if (answer) {
	jQuery.post('edit.php', { del: id }, function(data){
	if (data=='OK')
		$('#r'+id).remove();
	});
}
}
var playerVersion = swfobject.getFlashPlayerVersion();
var majorVersion = playerVersion.major;


$(function() {

function delimg() {
	var n = this.getAttribute('id').substring(3);
	//alert(id);
	$.ajax({
		url: 'edit.php',
		type: "GET",
		data: ({delimg: n, sid: $('#sid').val(), id: $('#rid').val()}),
		dataType: "html",
		success: function(data) {
			$("#img"+n).attr("src", 'img/nofoto.jpg');
		}
	});
}

$(".btn").click(clk);


function clk() {
$.ajax({
	url: 'edit.php',
	type: "GET",
	data: ({id : this.getAttribute('id')}),
	dataType: "html",
	success: function(data) {
		$('#contact_form').hide();
		if ($.browser.msie) {
			$('#typi').css('visibility', 'hidden');
			$("#contact_form").keypress(gadartekartulze);
		} else {
			$("#contact_form").keypress(handleKeys);
		}


		$('#contact_form').html(data);
		$('#contact_form').css('top', 20);
		$('#contact_form').css('left', ($(window).width() - $('#contact_form').width())/2);
		//$('#contact_form').css('z-index', 999);

// tu flashi ar ukeniat ???
if (majorVersion==0) {
	for(i=0; i<5; i++) {
		$('#upl'+i).replaceWith('<a id="upl'+i+'" style="width: 24px; height: 16px; padding: 0px; margin: 0px;"><img src="img/edit.png" border="0"></a>');
	}
	var but0 = $('#upl0'), but1 = $('#upl1'), but2 = $('#upl2'), but3 = $('#upl3'), but4 = $('#upl4'), interval;

		new AjaxUpload(but0, {
			action: 'js/uploadify.php',
			data : {
				'id': $('#rid').val(),
				'sid': $('#sid').val(),
				'no': 0
			},
			name: 'Filedata',
			onSubmit : function(file, ext){
				but0.html('');
				this.disable();
				interval = window.setInterval(function(){
					var text = but0.html();
					if (text.length>0){
						but0.html('');
					} else {
						but0.html('<img src="img/edit.png" border="0">');
					}
				}, 200);
			},
			onComplete: function(file, response){
				but0.html('<img src="img/edit.png" border="0">');
				window.clearInterval(interval);
				this.enable();
				$("#img0").attr("src", response);
			}
		});
		new AjaxUpload(but1, {
			action: 'js/uploadify.php',
			data : {
				'id': $('#rid').val(),
				'sid': $('#sid').val(),
				'no': 1
			},
			name: 'Filedata',
			onSubmit : function(file, ext){
				but1.html('');
				this.disable();
				interval = window.setInterval(function(){
					var text = but1.html();
					if (text.length>0){
						but1.html('');
					} else {
						but1.html('<img src="img/edit.png" border="0">');
					}
				}, 200);
			},
			onComplete: function(file, response){
				but1.html('<img src="img/edit.png" border="0">');
				window.clearInterval(interval);
				this.enable();
				$("#img1").attr("src", response);
			}
		});
		new AjaxUpload(but2, {
			action: 'js/uploadify.php',
			data : {
				'id': $('#rid').val(),
				'sid': $('#sid').val(),
				'no': 2
			},
			name: 'Filedata',
			onSubmit : function(file, ext){
				but2.html('');
				this.disable();
				interval = window.setInterval(function(){
					var text = but2.html();
					if (text.length>0){
						but2.html('');
					} else {
						but2.html('<img src="img/edit.png" border="0">');
					}
				}, 200);
			},
			onComplete: function(file, response){
				but2.html('<img src="img/edit.png" border="0">');
				window.clearInterval(interval);
				this.enable();
				$("#img2").attr("src", response);
			}
		});
		new AjaxUpload(but3, {
			action: 'js/uploadify.php',
			data : {
				'id': $('#rid').val(),
				'sid': $('#sid').val(),
				'no': 3
			},
			name: 'Filedata',
			onSubmit : function(file, ext){
				but3.html('');
				this.disable();
				interval = window.setInterval(function(){
					var text = but3.html();
					if (text.length>0){
						but3.html('');
					} else {
						but3.html('<img src="img/edit.png" border="0">');
					}
				}, 200);
			},
			onComplete: function(file, response){
				but3.html('<img src="img/edit.png" border="0">');
				window.clearInterval(interval);
				this.enable();
				$("#img3").attr("src", response);
			}
		});
		new AjaxUpload(but4, {
			action: 'js/uploadify.php',
			data : {
				'id': $('#rid').val(),
				'sid': $('#sid').val(),
				'no': 4
			},
			name: 'Filedata',
			onSubmit : function(file, ext){
				but4.html('');
				this.disable();
				interval = window.setInterval(function(){
					var text = but4.html();
					if (text.length>0){
						but4.html('');
					} else {
						but4.html('<img src="img/edit.png" border="0">');
					}
				}, 200);
			},
			onComplete: function(file, response){
				but4.html('<img src="img/edit.png" border="0">');
				window.clearInterval(interval);
				this.enable();
				$("#img4").attr("src", response);
			}
		});

} else {


		$('#upl0').uploadify({
			'uploader': 'js/uploadify.swf',
			'script': 'js/uploadify.php',
			'cancelImg': 'js/wait.gif',
			'buttonImg': 'js/edit.gif',
			'width': '16px',
			'height': '16px',
			'scriptData': {id: $('#rid').val(), sid: $('#sid').val(), no: 0},
			'queueID': 'fileQueue',
			'auto': true,
			'fileExt': '*.jpg;*.jpeg;*.png;*.gif',
			'multi': false,
			'onComplete': function(e,qid,fo,r,d) {
				$("#img0").attr("src", r);
			}
		});
		$('#upl1').uploadify({
			'uploader': 'js/uploadify.swf',
			'script': 'js/uploadify.php',
			'cancelImg': 'js/wait.gif',
			'buttonImg': 'img/edit.png',
			'width': 16,
			'height': 16,
			'scriptData': {id: $('#rid').val(), sid: $('#sid').val(), no: 1},
			'queueID': 'fileQueue',
			'auto': true,
			'fileExt': '*.jpg;*.jpeg;*.png;*.gif',
			'multi': false,
			'onComplete': function(e,qid,fo,r,d) {
				$("#img1").attr("src", r);
			}
		});
		$('#upl2').uploadify({
			'uploader': 'js/uploadify.swf',
			'script': 'js/uploadify.php',
			'cancelImg': 'js/wait.gif',
			'buttonImg': 'img/edit.png',
			'width': 16,
			'height': 16,
			'scriptData': {id: $('#rid').val(), sid: $('#sid').val(), no: 2},
			'queueID': 'fileQueue',
			'auto': true,
			'fileExt' : '*.jpg;*.jpeg;*.png;*.gif',
			'multi': false,
			'onComplete': function(e,qid,fo,r,d) {
				$("#img2").attr("src", r);
			}
		});
		$('#upl3').uploadify({
			'uploader': 'js/uploadify.swf',
			'script': 'js/uploadify.php',
			'cancelImg': 'js/wait.gif',
			'buttonImg': 'img/edit.png',
			'width': 16,
			'height': 16,
			'scriptData': {id: $('#rid').val(), sid: $('#sid').val(), no: 3},
			'queueID': 'fileQueue',
			'auto': true,
			'fileExt' : '*.jpg;*.jpeg;*.png;*.gif',
			'multi': false,
			'onComplete': function(e,qid,fo,r,d) {
				$("#img3").attr("src", r);
			}
		});
		$('#upl4').uploadify({
			'uploader': 'js/uploadify.swf',
			'script': 'js/uploadify.php',
			'cancelImg': 'js/wait.gif',
			'buttonImg': 'img/edit.png',
			'width': 16,
			'height': 16,
			'scriptData': {id: $('#rid').val(), sid: $('#sid').val(), no: 4},
			'queueID': 'fileQueue',
			'auto': true,
			'fileExt' : '*.jpg;*.jpeg;*.png;*.gif',
			'multi': false,
			'onComplete': function(e,qid,fo,r,d) {
				$("#img4").attr("src", r);
			}
		});
}
		$('#contact_form').fadeIn(300);
		$(".cancel").click(function() {
			$.ajax({
				url: 'edit.php',
				type: "POST",
				data: ({sid : $('#sid').val(), cancel: 1}),
				dataType: "html"});
			$('#contact_form').fadeOut(200);
			if ($.browser.msie) $('#typi').css('visibility', 'visible');
			return false;
		});
		$("#category").mcDropdown("#categorymenu", {delim: ' » '});
		$(".bd").click(delimg);


		$("#bul").click(function() {
			//$('#contact_form').fadeOut(200);
			$.ajax({
	url: 'edit.php',
	type: "POST",
	data: ({id : $('#rid').val(),
		oid : $('#oid').val(),
		sid : $('#sid').val(),
		cat_id : $('#cat_id').val(),
		category : $('#category').val(),
		val_id : $('#val_id').val(),
		caption : $('#caption').val(),
		price : $('#price').val(),
		coment : $('#coment').val(),
		addays : $('#addays').val(),
		phpref : $('#phpref').val(),
		phone : $('#phone').val()}),
	dataType: "html",
	success: function(xml) {
		$('#contact_form').fadeOut(200);
		//alert('განცხადება დამატებულია');
		if (document.location != 'mypage.php') {
			document.location = 'mypage.php';
		} else {
			if ($('#rid').val()>0) {
				$('#r'+$('#rid').val()).replaceWith(xml);
			} else {
			 	$('#mgrid').append(xml);
			}
			$(".btn").click(clk);
			if ($.browser.msie) $('#typi').css('visibility', 'visible');
		}

	}
});
			return false;
		});

	}
});

return false;
}


if ($.browser.msie) {
	$(".geo").keypress(gadartekartulze);
} else {
	$(".geo").keypress(handleKeys);
}

});



