window.siteurl='http://www.koukokufreemarket.jp/';
var BASEHREF='http://www.koukokufreemarket.jp/';
var patt1=new RegExp("[0-9]+");
$(document).ready(function(){
	$("textarea").resizable();
	$('#move-to').live('change',function(){
		var ids=$('input[name="message"]:checked').map(function() { return $(this).val(); }).get();
		if (ids.length>0) {
			$.ajax({
				type: 'GET',
				url: 'http://www.koukokufreemarket.jp/upload.php',
				data:'move=1&ids='+ids+'&folder='+$('#move-to option:checked').val(),
				success: function(responseText){
					if (responseText=='success') {
						for (var i=0;i<ids.length;i++) {
							$('#message-'+ids[i]).animate({"height": "toggle", "opacity": "toggle"}, "slow", "linear", function(){$('#message-'+ids[i]).remove()});
						}
						alerta(responseText);
					} else {
						error(responseText);
					}
				}
			});
		}
		return false;
	});
	$('#folders a:not(\'#folder-add\')').live('click',function(){
		var id=$(this).attr('class').split('-');
		if (id[0]=='folder' && patt1.exec(id[1])) {
			$('#tab-messages .content').load('http://www.koukokufreemarket.jp/content/account/messages-folders.php?folder='+id[1]);
		}
	});
	$('#free-ads .reactivate-ad').live('click',function(){
		var e=$(this);
		var id=e.parent().parent().parent().attr('id').split('product-')[1];
		id=patt1.exec(id);
		if (id.length>0) {
			$.ajax({
				type: 'GET',
				url: 'http://www.koukokufreemarket.jp/upload.php',
				data:'reactivate=1&id='+id,
				success: function(responseText){
					if (responseText=='success') {
						$('#product-'+id).remove();
						if ($('#free-ads .list ul').length==0) {
							$('#free-ads>*:not(h4)').remove();
							if ($('#free-ads p').length==0) {
								$('#free-ads').append('<p>製品はありません</p>');
							}
						}
						alerta('再出品されました');
					} else {
						error(responseText);
					}
				}
			});
		}
	});
	$('#feedback-ad button').live('click',function(){
		var user=patt1.exec($('input[name="selected-user"]').val());
		var item=patt1.exec($('input[name="item"]').val());
		if (user.length>0 && item.length>0) {
			$.ajax({
				type: 'GET',
				url: 'http://www.koukokufreemarket.jp/upload.php',
				data:'feedback=1&user='+user+'&item='+item,
				success: function(responseText){
					$('#feedback').dialog('close');
					$('#product-'+item).remove();
					alerta(responseText);
				}
			});
		}
		return false;
	});
	$('#select-user-id').live('click focusin focusout',function(){
		$('input[name="selected-user"]').val($('#select-user-id option:selected').val());
		$('#selected-user').val($('#select-user-id option:selected').html());
	});
	$('#usernames li').live('click',function(){
		$('input[name="selected-user"]').val($(this).attr('class').split('user-')[1]);
		$('#selected-user').val($(this).html());
		$('#usernames li').remove();
	});
	$('#username').live('change',function(){
		var o=$(this);
		if (o.val()!='') {
			$.ajax({
				type: 'GET',
				url: 'http://www.koukokufreemarket.jp/upload.php',
				data:'username=2&keywords='+escape(o.val()),
				success: function(responseText){
					$('#usernames').html(responseText);
				}
			});
		}
	});
	$('#sent .list li li:not(".checkbox")').live('click',function(){
		var id=$(this).parent().parent().attr('id').split('-')[1];
		id=patt1.exec(id);
		if (id.length>0) {
			$.ajax({
				type: 'GET',
				url: 'http://www.koukokufreemarket.jp/upload.php',
				data:'sent=2&id='+id,
				success: function(responseText){
					alerta(responseText);
				}
			});
		}
		return false;
	});
	$('#message .list li li:not(".checkbox")').live('click',function(){
		var id=$(this).parent().parent().attr('id').split('-')[1];
		id=patt1.exec(id);
		if (id.length>0) {
			$.ajax({
				type: 'GET',
				url: 'http://www.koukokufreemarket.jp/upload.php',
				data:'message=4&id='+id,
				success: function(responseText){
					alerta(responseText);
				}
			});
		}
		return false;
	});
	$('.flag span').live('click',function(){
		var id=$(this).parent().parent().parent().attr('id');
		if (id.length>0) {
			var id=id.split('message-')[1];
			id=patt1.exec(id);
			if (id.length>0) {
				$.ajax({
					type: 'GET',
					url: 'http://www.koukokufreemarket.jp/upload.php',
					data:'message=2&id='+id,
					success: function(responseText){
						if (responseText=='success') {
							if ($('#message-'+id+' .flag span').attr('class')=='a') {
								$(this).removeAttr('class');
							} else {
								$('#message-'+id+' .flag span').attr('class','a');
							}
						} else {
							error(responseText);
						}
					}
				});
			}
		}
		return false;
	});
	$('#add-folder button').live('click',function(){
		if ($('#folder-name').val()!='') {
			$.ajax({
				type: 'GET',
				url: 'http://www.koukokufreemarket.jp/upload.php',
				data:'folder=1&name='+escape($('#folder-name').val()),
				success: function(responseText){
					if (responseText=='success') {
						$('#folders').load('http://www.koukokufreemarket.jp/content/account/folders.php');
						alerta('あなたのフォルダが正常に追加されました！');
					} else {
						error(responseText);
					}
				}
			});
		} else {
			alerta('フォルダ名を入力してください！');
		}
		return false;
	});
	$('#folder-add').live('click',function(){
		if ($('.add-folder').length>0) {
			alerta($('.add-folder').html());
			$('.add-folder').remove();
		} else {
			alerta('最近フォルダを追加しました！');
		}
		return false;
	});
	$('#message-box button,#reply button').live('click',function(){
		if ($('#user-id').val()!=0) {
			if (!$.validationEngine.loadValidation('#message-title') && !$.validationEngine.loadValidation('#message-content')) {
				$.ajax({
					type: 'GET',
					url: 'http://www.koukokufreemarket.jp/upload.php',
					data:'message=3&id_user='+$('#user-id').val()+'&id_product='+$('#product-id').val()+'&title='+escape($('#message-title').val())+'&content='+escape($('#message-content').val()),
					success: function(responseText){
						$('.message-box').dialog('close');
						if (responseText=='success') {
							alerta('メッセージが送信されました！');
						} else {
							error(responseText);
						}
					}
				});
			}
		}
		return false;
	});
	$('#contact-seller').live('click',function(){
		$('.message-box').dialog({autoOpen:false,width:450,modal:true,title:'出品者にお問い合わせ'}).find('.ui-wrapper').css({'height':'120px','width':'308px'});
		$('.message-box').dialog('open');
	});
	$('#add-alert button').live('click',function(){
		if ($('#keywords').val()=='') {
			error('キーワードを入力してください');
		} else {
			$.ajax({
				type: 'GET',
				url: 'http://www.koukokufreemarket.jp/upload.php',
				data:'alert=2&value='+escape($('#keywords').val())+'&category='+$('#category').val(),
				success: function(responseText){
					if (responseText=='success') {
						$('#tab-activity .navigation .a').removeAttr('class');
						$('#tab-activity .navigation a[rel="alerts"]').addClass('a');
						/*$('#tab-activity .content').animate({opacity:0.111,height:['toggle','swing']},500,'linear',function(){
							$('#tab-activity .content').load('http://www.koukokufreemarket.jp/content/account/alerts.php').animate({opacity:1,height:['toggle','swing']},500,'linear');
						});*/
						$('#tab-activity .content').load('http://www.koukokufreemarket.jp/content/account/alerts.php');
					} else {
						error(responseText);
					}
				}
			});
		}
		return false;
	});
	$('#preview-ad').live('submit',function(){
		var timestamp=new Date().getTime();
		window.open('','preview'+timestamp,'width=1024,height=768,resizeable,scrollbars').moveTo(0,0);
        		this.target='preview'+timestamp;
	});
	$('#feature-ad input[type="checkbox"]').live('click',function(){
		var e=$(this);
		$('input[type="checkbox"][name="'+e.attr('name')+'"]').removeAttr('checked');
		e.attr('checked','checked');
		$('input[name="'+e.attr('title')+'"]').val(e.val());
	});
	$('#free-ads .feature-ad').live('click',function(){
		var e=$(this);
		$('#feature-ad input[name="item"]').val(e.parent().parent().parent().attr('id').split('product-')[1]);
		$('#feature').dialog({autoOpen:false,width:450,modal:true,title:'お勧め出品'});
		$('#feature').dialog('open');
	});
	$('#feedback-ads .feedback-ad').live('click',function(){
		var e=$(this);
		$('#feedback-ad input[name="item"]').val(e.parent().parent().parent().attr('id').split('product-')[1]);
		$('#feedback').dialog({autoOpen:false,width:450,modal:true,title:'評価を取得'});
		$('#feedback').dialog('open');
	});
	$('#preview').live('click',function(){
		$('#preview-ad').html('');
		$('#action input,#action select').each(function(){
			var e=$(this);
			$('#preview-ad').prepend("<input type=\"hidden\" name=\""+e.attr('name')+"\" value=\""+e.val()+"\"");
		});
		$('#preview-ad').submit();
		return false;
	});
	$('#search-box button').live('click',function(){
		$('#search-form').submit();
		return false;
	});
	$('#search-box input,#search-box select').live('change',function(){
		$('#'+$(this).attr('title')).val($(this).val());
	});
	var $search='';
	$('button[title="search-box"]').live('click',function(){
		if ($search=='') {
			$search=$(this).attr('title');
			$(this).removeAttr('title');
		}
		alerta($('.'+$search).html());
		return false;
	});
	$('#account dd a').live('click',function(){
		var e=$(this);
		if (!$.validationEngine.loadValidation('#'+e.attr('rel'))) {
			$.ajax({
				type: 'GET',
				url: 'http://www.koukokufreemarket.jp/upload.php',
				data:'account=1&field='+e.attr('rel')+'&value='+escape($('#'+e.attr('rel')).val()),
				success: function(responseText){
					alerta((responseText=='success'?'データが更新されました':'エラー！'));
				}
			});
		}
		return false;
	});
	$('#account dd input,#account dd textarea,#reply dd input,#reply dd textarea').live('focusout',function(){
		$.validationEngine.loadValidation('#'+$(this).attr('id'));
	});
	$('input.select-all',$('#my-account #tabs')[0]).live('click',function(){
		var e=$(this);
		var $attr=e.attr('title');
		if (e.attr('checked')==true) {
			$('input[name="'+$attr+'"]').attr('checked',true);
		} else {
			$('input[name="'+$attr+'"]').attr('checked',false);
		}
	});
	$('button.action').live('click',function(){
		var e=$(this);
		var ids=$('input[name="'+e.attr('title')+'"]:checked').map(function() { return $(this).val(); }).get();
		//alert(ids);
		//return false;
		if (ids.length>0) {
			$.ajax({
				type: 'GET',
				url: 'http://www.koukokufreemarket.jp/upload.php',
				data:e.attr('title')+'=1&ids='+ids,
				success: function(responseText){
					for (var i=0;i<ids.length;i++) {
						$('#'+e.attr('title')+'-'+ids[i]).animate({"height": "toggle", "opacity": "toggle"}, "slow", "linear", function(){$('#'+e.attr('title')+'-'+ids[i]).remove()});
					}
					if ($('#'+e.attr('title')+' .list ul').length-ids.length==0) {
						$('#'+e.attr('title')+'>*:not(h4)').animate({"height": "toggle", "opacity": "toggle"}, "slow", "linear", function(){
							$('#'+e.attr('title')+'>*:not(h4)').remove();
							if ($('#'+e.attr('title')+' p').length==0) {
								$('#'+e.attr('title')).append('<p>製品はありません</p>');
							}
						});
					}
				}
			});
		}
		return false;
	});
	$('#product a[title="ウォッチリスト"]').live('click',function(){
		var o=$(this);
		var id=o.attr('id').split('-')[1];
		id=patt1.exec(id);
		if (id.length>0) {
			$.ajax({
				type: 'GET',
				url: 'http://www.koukokufreemarket.jp/upload.php',
				data:'wishlist=2&id_ad='+id+'&action='+(o.html()=='ウォッチリスト'?'add':'remove'),
				success: function(responseText){
					alerta(responseText);
					o.html((o.html()=='ウォッチリスト'?'ウォッチリストから削除':'ウォッチリスト'));
				}
			});
		}
		return false;
	});
	$('#per-page a').live('click',function(){
		$('#pages').val($(this).html());
		$('#per-page').submit();
		return false;
	});
	$('.video-loader').live('click',function(){
		var o=$(this);
		var video=o.parent().children('input');
		if (video.val()!='') {
			if (!$.validationEngine.loadValidation('#'+video.attr('id'))) {
				o.parent().children('.embed').load("http://www.koukokufreemarket.jp/upload.php?link="+escape(video.val())+"");
			} else {
				$.validationEngine.loadValidation('#'+video.attr('id'));
			}
		} else {
			$.validationEngine.buildPrompt('#'+video.attr('id'),"動画のリンク先がない方は、プレビューを見ることができません","error");
		}
		return false;
	});
	$("#menu a").live('click',function(){
		var locationHref=window.location.href;
		var href=$(this).attr('href');
		if (href.match('(#)')) {
			var elementClick=$(this).attr("href");
			var destination=$(elementClick).offset().top;
			$("html:not(:animated),body:not(:animated)").animate({scrollTop:destination},1100,function() { window.location.hash=elementClick; });
			return false;
		}
	});
	$("form:not('#account,#reply')").validationEngine({
		inlineValidation:true,
		promptPosition:"centerRight"
	});
	$("#account").validationEngine({
		inlineValidation:false,
		promptPosition:"centerRight"
	});
	$('#tabs .navigation a').live('click',function(){
		var e=$(this);
		var page=e.attr('rel');
		if (page.length>0) {
			var id=$(e).parent().parent().parent().parent().parent().attr('id');
			$('#'+id+' .navigation a').removeAttr('class');
			e.addClass('a');
			//$('#'+id+' .content').animate({opacity:0.111,height:['toggle','swing']},500,'linear',function(){
				$('#'+id+' .content').load('http://www.koukokufreemarket.jp/content/account/'+page+'.php',function(){
					$('#wishlist .category p,#wishlist .price span,#free-ads .category p').each(function(){
						var el=$(this);
						el.css('top',(el.parent().height()/2-el.height()/2));
					});
//				}).animate({opacity:1,height:['toggle','swing']},500,'linear');
			});
			return false;
		}
	});
	$('#tabs .navigation .a').each(function(){
		var e=$(this);
		var page=e.attr('rel');
		if (page.length>0) {
			var id=$(e).parent().parent().parent().parent().parent().attr('id');
			$('#'+id+' .content').load('http://www.koukokufreemarket.jp/content/account/'+page+'.php',function(){
				$('#wishlist .category p,#wishlist .price span,#free-ads .category p').each(function(){
					var el=$(this);
					el.css('top',(el.parent().height()/2-el.height()/2));
				});
			});
		}
	});
	$('#tabs ul a').click(function(){
		var e=$(this);
		if (e.attr('href')) {
			var id=e.attr('href').split('#')[1];
			$('#tabs>ul>li:not(.c)').each(function(){
				$(this).removeAttr('class');
			});
			e.parent().addClass('active');
			$('#tabs>div').each(function(){
				var el=$(this);
				el.removeAttr('class');
				if (el.attr('id')==id) { el.addClass('active'); }
			});
			return false;
		}
	});
	var button=$('#wrapper button'),interval;
	if (button.length>0) {
		new AjaxUpload(button, {
			action:'http://www.koukokufreemarket.jp/upload.php',
			name:'file',
			onSubmit:function(file,ext){
				if (! (ext && /^(jpg|png|jpeg|gif)$/i.test(ext))){
					alerta('エラー：無効なファイル拡張子'); // extension is not allowed
					return false; // cancel upload
				} else {
					/*button.text('Uploading');*/ // change button text, when user selects file
					this.disable(); // If you want to allow uploading only 1 file at time you can disable upload button
					interval=window.setInterval(function() { // Uploading -> Uploading. -> Uploading...
						var text=button.text();
						/*if (text.length<13) { button.text(text+'.'); }
						else { button.text('アップロード'); }*/
					},200);
				}
			},
			onComplete:function(file,response){
				/*button.text('アップロード');*/
				window.clearInterval(interval);
				this.enable(); // enable upload button
				$('<li></li>').appendTo('#files ol').html(utf8_decode(unescape(response))); // add file to the list
			}
		});
	}
	$('#choose-category a').click(function(){
		toggleCatLink($(this));
		return false;
	});
	$(".datepicker").datepicker({
		dateFormat :'mm-dd-yy',
		changeYear:true,
		yearRange:'1930:1995',
		dayNames: ['日','月','火','水','木','金','土'],
		dayNamesMin: ['日','月','火','水','木','金','土'],
		monthNames: ['1月','２月','３月','４月','5月','６月','７月','８月','９月','１０月','１１月','１２月'],
		monthNamesShort: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
		firstDay:1,
		minDate:new Date(1930,1-1,1),
		defaultDate:new Date(1980,1-1,1),
		nextText:'次',
		prevText:'前'
	});
	if ($.fancybox) {
		$("a.group").fancybox({
			'opacity':true,
			'cyclic':true,
			'centerOnScroll':true,
			'overlayColor':'#333',
			'overlayOpacity':0.6,
			'titlePosition':'inside',
			'speedIn':600,
			'speedOut':200,
			'transitionIn':'fade',
			'easingIn':'swing',
			'transitionOut':'fade',
			'easingOut':'swing'
		});
	}
	$("a[rel='external'],#footerLinks a").click(function(){
		window.open($(this).attr('href'));
		return false;
	});
	if ($('#validation').length!=0) {
		$.get(BASEHREF+"includes/token.php",function(txt){$("#validation").val(txt);});
	}
	$('form input,form textarea,form select').live('focus',function(){
		var o=$(this);
		if (o.hasClass('ui-resizable')) {
			var id=o.parent().parent().parent().parent().parent().attr('id');
			var thiseq=$('dd').index(o.parent().parent());
		} else {
			var id=o.parent().parent().parent().parent().attr('id');
			var thiseq=$('dd').index(o.parent());
		}
		$('#'+id+' input,#'+id+' textarea,#'+id+' select').removeClass('focused');
		$('#'+id+' dt').removeAttr('class');
		if(o.attr('type')!='checkbox') o.addClass('focused');
		$('dt:eq('+thiseq+')').addClass('focused');
	});
	$('.clearfield').each(function() {
		var el=$(this);
		if(el.attr('rel')==undefined) { el.attr('rel', el.val()).addClass('cf-blur'); }
		el.focus(function() { if(el.val()==el.attr('rel')) { el.val('').removeClass('cf-blur').addClass('cf-blur'); } });
		el.blur(function() { if(el.val()=='') { el.val(el.attr('rel')).removeClass('cf-blur').addClass('cf-blur'); } });
	});
	clock();
	//	$('#siteContent').css('width',($(window).width()-24>992?$(window).width():992));
	var sum=0;
	if ($('#box-left').css('display')=='block') {
		sum+=$('#box-left').width()+parseInt($('#box-left').css('padding-right').split('px')[0]);
	}
	if ($('#box-right').css('display')=='block') {
		sum+=$('#box-right').width()+parseInt($('#box-right').css('padding-left').split('px')[0]);
	}
	$('#mainContent>.content').css('width',($("#siteContent").width()-sum));
	/*$(window).bind("resize", function() {
	sum=0;
	if ($('#box-left').css('display')=='block') {
	sum+=$('#box-left').width()+parseInt($('#box-left').css('padding-right').split('px')[0]);
	}
	if ($('#box-right').css('display')=='block') {
	sum+=$('#box-right').width()+parseInt($('#box-right').css('padding-left').split('px')[0]);
	}
	if ($(window).width()>=1000) {
	$('#siteContent').css('width',($(window).width()-24>992?$(window).width():992));
	$('#mainContent>.content').css('width',($("#siteContent").width()-sum));
	} else {
	$('#siteContent').css('width',992);
	$('#mainContent>.content').css('width',($("#siteContent").css('width')-sum));
	}
	});*/
	$("input").attr('autocomplete', 'off');
	$("body").append("<div id=\"window_alerta\"></div><div id=\"AjaxLoading\"></div>");
});
if (window.location=='http://koukokufreemarket.jp/') {
	window.location=window.siteurl;
}
function eurl(v) {
	return encodeURIComponent(v);
}
function Ejax(phpfile,params,divelem){
	EjaxCb(phpfile,params,divelem);
}
function alerta(mesaj, error_var, width) {
	if (error_var==null) {
		error_var = false;
	}
	if (width==null) {
		width = 442;
	}
	options={modal:true,width:width,minWidth:442,title:'FreeMarketJapanからのメッセージ！',beforeclose:
		function() {
			if ($('form#reply').length>0) {
				$('#reply input,#reply textarea').each(function(){
					/*$.validationEngine.closePrompt('#'+$(this).attr('id'));*/
					$('.'+$(this).attr('id')+'formError').remove();
				});
			}
		}
	};
	var mesaj_new="";
	if (error_var) {
		mesaj_new="<div class=\"ui-widget\"><div class=\"ui-state-error ui-corner-all\" style=\"padding:20px; margin:12px;\"><span class=\"ui-icon ui-icon-alert\" style=\"float: left; margin-right: 0.3em;\" ></span>" + mesaj + "</div></div>";
	} else {
//		mesaj_new="<div class=\"ui-widget\"><div class=\"ui-state-highlight ui-corner-all\" style=\"padding:20px;  margin:12px;\"><span class=\"ui-icon ui-icon-info\" style=\"float: left; margin-right: 0.3em;\" ></span>" + mesaj + "</div></div>";
		mesaj_new="<div class=\"ui-widget\"><div class=\"ui-dialog-content ui-widget-content\">" + mesaj + "</div></div>";
	}
	do_win(mesaj_new,options);
}
function do_win(mesaj,options,callback) {
	if ($("#window_alerta").dialog('isOpen')!=undefined) $("#window_alerta").dialog('destroy');
	$("#window_alerta").html(mesaj);
	$("#window_alerta").dialog(options);
	if(callback!=null) callback();
}
function confirma(title,mesaj,button,callback) {
	options={
	'modal' :true,
	'width' :240,
	'buttons': { " Renunta ": function() { $(this).dialog("close"); } ,  " Confirma " : function() { callback(); $(this).dialog("close"); }   },
	'title' : title
	};
	do_win(mesaj,options);
}
function error(mesaj) {
	alerta(mesaj, true);
}
function $val(a){
	try{
		return document.getElementById(a).value;
	}
	catch(e){
		alert('Elementul '+a+' nu poate fi gasit reporniti browserul si incercati din nou');
		return false;
	}
}

function $v(a,v){
	try{
		document.getElementById(a).value=v;
		return true;
	}
	catch(e){
		alert('Elementul '+a+' nu poate fi gasit reporniti browserul si incercati din nou');
		return false;
	}
}
function $html(a,v){
	try{
		document.getElementById(a).innerHTML=v;
		return true;
	}
	catch(e){
		alert('Elementul '+a+' nu poate fi gasit reporniti browserul si incercati din nou');
		return false;
	}
}
function $id(a){
	var rez;
	try{
		rez=document.getElementById(a);
		return rez;
	}
	catch(e){
		alert('Elementul '+a+' nu poate fi gasit reporniti browserul si incercati din nou');
		return false;
	}
}
function creazaXmlHttp(){
	var xmlHttp;
	if(window.ActiveXObject){
		try{
			xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e){
			xmlHttp = false;
		}
	}
	else{
		try{
			xmlHttp = new XMLHttpRequest();
		}
		catch (e){
			xmlHttp = false;
		}
	}
	if (!xmlHttp) alert("Nu s-a putut crea obiectul XMLHttpRequest .");
	else return xmlHttp;
}
var xmainpath='images/';
var xmlHttp=creazaXmlHttp();
function EjaxCb(phpfile,params,divelem,callback){
	if(divelem!=''){
		var xdiv=$id(divelem);
		var dispwait=true;
	}
	else {
		var xdiv='';
		var dispwait=false;
	}
	//var dispwait=false; // sa nu mai faca loading
	this.phppath=phpfile;
	var xphp=this.phppath;
	if(params!=''){
		var xparam='?'+params+"&sid="+Math.random();
	}
	else{
		var xparam="?sid="+Math.random();
	}
	var xmlHttp=creazaXmlHttp();
	this.cerere=function(){
		if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0){
			xmlHttp.open("GET", xphp+xparam, true);
			xmlHttp.onreadystatechange = xrez;
			xmlHttp.send(null);
			if(dispwait){
				//xdiv.innerHTML= '<img src="'+xmainpath+'wait.gif'+'" width=25 height=25>'+'PLEASE WAIT!!!';
				document.getElementById('AjaxLoading').style.display='block';
			}
		}
		else{
			if(dispwait){
				//xdiv.innerHTML= '<img src="'+xmainpath+'wait.gif'+'" width=25 height=25>'+'PLEASE WAIT!!!';
				document.getElementById('AjaxLoading').style.display='block';
			}

		}
	};
	var xcer=this.cerere;
	this.rezultat=function(){
		if (xmlHttp.readyState == 4){
			if (xmlHttp.status == 200){
				var raspuns = xmlHttp.responseText;
				if (callback) {callback(raspuns);}
				else if(xdiv==''){
					alert(raspuns);
				}
				else{
					document.getElementById('AjaxLoading').style.display='none';
					xdiv.innerHTML =  raspuns;
				}
			}
			else{
				alert("Problema la accesare: " +xmlHttp.statusText);
			}
		}
		else{
			if(dispwait){
				//xdiv.innerHTML= '<img src="'+xmainpath+'wait.gif'+'" width=25 height=25>'+'PLEASE WAIT!!!';
				document.getElementById('AjaxLoading').style.display='block';
			}

		}
	};
	var xrez=this.rezultat;
	xcer();

}
function delete_uploaded(file,id_form) {
	if (confirm('イメージを削除してもよろしいですか')) {
		$(id_form).parent().remove();
		$.post('ajax/base.php', 'delete_file=1&file=' + file);
	}
}

//vortex
function toggleCatLink(el) {
	var id = el.attr('href');
	if (($(id).hasClass('level-two')) || (el.hasClass('final-level') && el.parents('ul').hasClass('level-one'))) {
		$('ul.level-one li.active, ul.level-two, ul.level-two li.active, ul.level-three, ul.level-three li.active, ul.level-four, ul.level-four li.active, ul.level-five, ul.level-five li.active').removeClass('active');
	}
	if (($(id).hasClass('level-three')) || (el.hasClass('final-level') && el.parents('ul').hasClass('level-two'))) {
		$('ul.level-two li.active, ul.level-three, ul.level-three li.active, ul.level-four, ul.level-four li.active, ul.level-five, ul.level-five li.active').removeClass('active');
	}
	if (($(id).hasClass('level-four')) || (el.hasClass('final-level') && el.parents('ul').hasClass('level-three'))) {
		$('ul.level-three li.active, ul.level-four, ul.level-four li.active, ul.level-five, ul.level-five li.active').removeClass('active');
	}
	if (($(id).hasClass('level-five')) || el.hasClass('final-level') && el.parents('ul').hasClass('level-four')) {
		$('ul.level-four li.active, ul.level-five, ul.level-five li.active').removeClass('active');
	}
	if (el.hasClass('final-level') && el.parents('ul').hasClass('level-five')) {
		$('ul.level-five li.active').removeClass('active');
	}
	if ($(id).hasClass('level-five') || el.closest('ul').hasClass('level-five')) {
		$('#categories').animate({marginLeft:'-201px'}, 200);
	} else {
		$('#categories').animate({marginLeft:'0'}, 200);
	}
	$(id).addClass('active');
	el.parent('li').toggleClass('active');
	$('ul#category-notes li.active').removeClass('active');
	if (el.hasClass('final-level')) {
		var catNum = /\d+/.exec(el.attr('href'));
		$('#id_category').val(catNum);
	} else {
		$('#id_category').val('');
	}
}
function utf8_encode(string) {
	string = string.replace(/\r\n/g,"\n");
	var utftext = "";
	for (var n = 0; n < string.length; n++) {
		var c = string.charCodeAt(n);
		if (c < 128) {
			utftext += String.fromCharCode(c);
		} else if((c > 127) && (c < 2048)) {
			utftext += String.fromCharCode((c >> 6) | 192);
			utftext += String.fromCharCode((c & 63) | 128);
		} else {
			utftext += String.fromCharCode((c >> 12) | 224);
			utftext += String.fromCharCode(((c >> 6) & 63) | 128);
			utftext += String.fromCharCode((c & 63) | 128);
		}
	}
	return utftext;
}
function utf8_decode(utftext) {
	var string = "";
	var i = 0;
	var c = c1 = c2 = 0;
	while ( i < utftext.length ) {
		c = utftext.charCodeAt(i);
		if (c < 128) {
			string += String.fromCharCode(c);
			i++;
		} else if((c > 191) && (c < 224)) {
			c2 = utftext.charCodeAt(i+1);
			string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
			i += 2;
		} else {
			c2 = utftext.charCodeAt(i+1);
			c3 = utftext.charCodeAt(i+2);
			string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
			i += 3;
		}
	}
	return string;
}
function delete_file(file,el) {
	if (confirm('イメージを削除してもよろしいですか')) {
		$(el).parent().remove();
		$.post(BASEHREF+'upload.php','delete_file=1&file='+file);
	}
}
function clock() {
	var now=new Date();
	var outStr=(now.getHours()<10?'0'+String(now.getHours()):now.getHours())+':'+(now.getMinutes()<10?'0'+String(now.getMinutes()):now.getMinutes())+':'+(now.getSeconds()<10?'0'+String(now.getSeconds()):now.getSeconds());
	document.getElementById('time').innerHTML=outStr;
	/*var timezone = "Europe/Bucharest";
	$.getJSON("http://json-time.appspot.com/time.json?tz="+timezone+"&callback=?",function(data){$('#time').html((data.hour<10?'0'+String(data.hour):data.hour)+':'+(data.minute<10?'0'+String(data.minute):data.minute)+':'+(data.second<10?'0'+String(data.second):data.second));});*/
	setTimeout('clock()',1000);
}

/**
 * Function : dump()
 * Arguments: The data - array,hash(associative array),object
 *    The level - OPTIONAL
 * Returns  : The textual representation of the array.
 * This function was inspired by the print_r function of PHP.
 * This will accept some data as the argument and return a
 * text that will be a more readable version of the
 * array/hash/object that is given.
 * Docs: http://www.openjs.com/scripts/others/dump_function_php_print_r.php
 */
function dump(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0;j<level+1;j++) level_padding += "    ";
	if(typeof(arr) == 'object') { //Array/Hashes/Objects
		for(var item in arr) {
			var value = arr[item];
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "'=> array\n";
				dumped_text += dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}
function activate_uploader(id,folder,maxfiles,extensions,instance) {
	var button=$('#'+id+' .wrapper button'),interval;
	var regexp=new RegExp('^('+extensions+')$','i');
	if (button.length>0) {
		new AjaxUpload(button, {
			action:'http://www.koukokufreemarket.jp/upload.php',
			name:id,
			console:1,
			data: { folder:folder,id:id,instance:instance },
			onSubmit:function(file,ext){
				if (maxfiles>$('#'+id+' .files li').length) {
					if (! (ext && regexp.test(ext))){
						alerta('エラー：無効なファイル拡張子');
						return false;
					} else {
						this.disable();
						interval=window.setInterval(function() { var text=button.text(); },200);
					}
				} else {
					alerta('のみ '+maxfiles+' 許可ファイル');
					return false;
				}
			},
			onComplete:function(file,response){
				window.clearInterval(interval);
				this.enable();
				$('<li></li>').appendTo('#'+id+' .files ol').html(unescape(response));
			}
		});
	}
};
