$(document).ready(function(){

	/* js is work */
	$("#gatar").removeClass("no_js");

	/* capthca */
	$("#captcha").click(function(){
		$(this).attr("src", '/service/captcha/captcha.php?i='+getRandom());
		return false;
	});

	/* search example */
	$("#poisk").click(function(){
		var napr = $(this).html();
		$("#searchinp").attr("value", napr ).focus();
		return false;
	});

	$('.spoiler').click(function(){
		$(this).fadeslide();
		return false;
	});

	/* city list */
	$("#cityid").click(function(){
		if ($.browser.msie && $.browser.version.substr(0,3)=="6.0") {
			return true;
		} else {
			if ( $(this).data('obtained') === true ) {
				$("#citylist").show();
			} else {
				$.gajax({
					data: 'path='+escape(document.location.href),
					acttype: 'citys'
				});
			}
		return false;
		}
	});

	js_funcs = {
		datepicker: function() {
			// datepicker
			$("#mydate").datetimepicker({ dateFormat: 'dd.mm.yy'}).click(function(){
				$(this).prev().children(":first").attr("checked", "checked");
			});
			$("#step-au").bind('change', function() {
				if ($(this).attr('value') == 1 ) {
					$(this).parent().parent().next().show();
				} else {
					$(this).parent().parent().next().hide();
				}
			});
		},

		deletemess: function() {
			$('.messlist .del').live('click', function(){
				mess_id = $(this).parent().parent().attr('id');
				mess_id = mess_id.match(/mess([0-9]+)/);
				if (mess_id !== null ) {
					data = 'idmess='+mess_id[1];
					$.gajax({
						data: data,
						acttype: 'delete_mess'
					});
				}
				return false;
			});
		},

		cancelmessage: function() {
			$('#messlist .backmess').live('click', function(){
				mess_id = $(this).parent().parent().attr('id');
				mess_id = mess_id.match(/mess([0-9]+)/);
				if (mess_id !== null ) {
					data = 'idmess='+mess_id[1];
					$.gajax({
						data: data,
						acttype: 'cancel_mess'
					});
				}
				return false;
			});
		}
	};

	// js funcs loadind when page load
	js_func_page = {

		add_item: function(){
			js_funcs.datepicker();
		},

		item_info: function() {
			/* WATCH */
			$(".vozm").click(function(){
				data = $(this).attr("href");
				clicked = $(this);
				$.gajax({
					data: 'id='+data,
					acttype: 'watch'
				});
				return false;
			});

			// izmenit photo tovara
			$(".reimg").click(function(){
				$("#miniimgs .vibminiimg").removeClass("vibminiimg").addClass("obminiimg");
				$(this).removeClass("obminiimg").addClass("vibminiimg");
				var newimage = $(this).children().attr("src");
				newimage = newimage.match(/(?:[0-9a-z]*.(?:png|jpg|gif))$/);
				var pathimg = $('#osnfoto').attr("src");
				pathimg = pathimg.replace(/(?:[0-9a-z]*.(?:png|jpg|gif))$/, newimage );
				$('#loader').show();
				$('#osnfoto').attr("src", pathimg).load(function(){
					$('#loader').hide();
				});
				return false;
			});

			$('#buythisitem').click(function(){
				loadbox('buyitem', tid );
				return false;
			});

			// share this buttons
			$('#sh_lj').click(function(){
				/* zapolnit */
				return false;
			});
			$('#sh_vk').click(function(){
				PopupCenter('http://vkontakte.ru/share.php?url='+encodeURIComponent(document.location.href), 'title', 625, 450);
				return false;
			});
			$('#sh_face').click(function(){
				PopupCenter('http://www.facebook.com/sharer.php?u='+encodeURIComponent(document.location.href), 'title', 625, 450);
				return false;
			});
			$('#sh_mail').click(function(){
				PopupCenter('http://connect.mail.ru/share?share_url='+encodeURIComponent(document.location.href), 'title', 520, 340);
				return false;
			});
			$('#sh_ya').click(function(){
				/* zapolnit */
				PopupCenter('http://wow.ya.ru/posts_share_link.xml?url='+encodeURIComponent(document.location.href)+'&title=&body=', 'title', 625, 450);
				return false;
			});
			$('#sh_ok').click(function(){
				var elem = $(this);
				$.getScript('http://stg.odnoklassniki.ru/share/odkl_share.js', function(){
					ODKL.Share(elem.get(0));
				});
				return false;
			});

		},

		item_edit: function(){
			// sale type change
			$("#fs").bind('change', function(){
				var i = $(this).attr("value");
				if ( i == 1 ) {
					$("#fsp").show().next().show();
				} else if (i == 2) {
					$("#fsp").show().next().hide();
				} else if (i == 3) {
					$("#fsp").hide().next().show();
				}
			});
			js_funcs.datepicker();
		},

		activity: function() {
			// action in activity
			$('.vipspisok .vip').click(function(){
				vip_id = $(this).next().attr('id');
				$('.spisokinvip').hide();
				$(this).next().fadeIn(150).focus().children(':first').click(function(){
					$(this).parent().hide();
					return false;
				});
				$(document).click(function(e){
					$('.spisokinvip').hide();
					/*if ($(e.target).parents().filter('#'+vip_id+':visible').length != 1) {
					}*/
				});
				return false;
			});

			$("#osn .delitem").click(function(){
				$('.spisokinvip').hide();
				var thisitem = $(this).parent().parent().attr('rel');
				loadbox('delitem', thisitem );
				return false;
			});
		},

		myworld: function() {

			// change password
			$('#repassform').submit(function(){
				$(this).children().children('li.errorka').hide();
				newpass = $('#new_pass').attr("value");
				newpass_a = $('#pass_a').attr("value");
				var err = false;
				if (newpass!=newpass_a) {
					$(this).children().children(':last').prev().fadeIn();
					err = true;
				}
				if (newpass.length < 7) {
					$(this).children().children(':last').prev().prev().fadeIn();
					err = true;
				}
				if (newpass.length > 51 ) {
					$(this).children().children(':last').prev().prev().prev().fadeIn();
					err = true;
				}
				if (err) {
					return false;
				}
				var data = $(this).serialize();
				$.gajax({
					data: data,
					acttype: 'change_pass'
				});
				return false;
			});

			// change email
			$('#remailform').submit(function(){
				$(this).children().children('li.errorka').hide();
				data = $(this).serialize();
				newpass = $('#newmail').attr("value");
				if ( !newpass.match( /\w+@\w+\.[a-z]{2,3}/ ) ) {
					$('#newmail').parent().next().fadeIn();
					return false;
				}
				$.gajax({
					data: data,
					acttype: 'change_email'
				});
				return false;
			});

			// ajax load
			$('#editcontactinfo').live('click', function(){
				$(this).attr('href','#!/myworld/?v=editcontactinfo');
				$('#righttd').loadform('personalinfo');
			});
			$('#myavatar').live('click', function(){
				$(this).attr('href','#!/myworld/?v=myavatar');
				$('#righttd').loadform('myavatar');
			});
			$('#myprivacy').live('click', function(){
				$(this).attr('href','#!/myworld/?v=myprivacy');
				$('#righttd').loadform('privacy');
			});

			// deleting avatar
			$('#deleteava').live('click', function(){
				clicked = $(this);
				$.gajax({
					acttype: 'myavatar_del'
				});
				return false;
			});

			// privacy configuration
			$("#privacy .btnlink").live('click', function() {
				if ($(this).hasClass("lwhite")&&!$(this).hasClass("cancel")){
					$(this).removeClass("lwhite").parent().children(".lblue").removeClass("lblue").addClass("lwhite").end().end().addClass("lblue");
					id = $(this).attr("id");
					found = id.match(/[_a-z]+([0-9]+)/);
					$(this).parent().children(":last").attr("value", found[1]);
					return false;
				} else if ($(this).hasClass("lblue")) {
					return false;
				}
			});

			// feedback rate
			$(".frate a").live('click', function(){

				var rating12, cl;

				if ( $(this).hasClass('lwhite') ) {
					rating12 = 1; cl = 'fneitral';
				} else if ( $(this).hasClass('lred') ) {
					rating12 = 0; cl = 'fbad';
				} else if ( $(this).hasClass('lgreen') ) {
					rating12 = 2; cl = 'frapture';
				}
				if ( $(this).parent().parent().parent().parent().hasClass(cl) ) {
					return false;
				}
				$(this).parent().parent().parent().parent().removeClass('fneitral frapture fbad').addClass(cl);
				$(this).parent().children(':last').attr('value', rating12 );
				return false;
			});

			// save feedback
			$(".sendfeed").saveform('save_feedback');
		},

		mymessages: function() {
			$("#messlist .minimess").click(function(e){
				clicked = $(e.target);
				if ( $(clicked).is("a") ) {
					return true;
				}
				window.location = $(this).children(':first').next().attr('href');
			}).hover(function(){
				$(this).children(':first').next().css('text-decoration', 'underline');
			}, function(){
				$(this).children(':first').next().css('text-decoration', 'none');
			});

			$('#messlist .readths').live('click', function(){
				clicked = $(this);
				mess_id = $(this).parent().parent().attr('id');
				mess_id = mess_id.match(/mess([0-9]+)/);
				if (mess_id !== null ) {
					if ($(this).parent().parent().hasClass("notread") ) {
						/* read mess */
						data = 'idmess='+mess_id[1];
						$.gajax({
							data: data,
							acttype: 'set_read'
						});
					} else {
						/* unread mess */
						data = 'idmess='+mess_id[1];
						$.gajax({
							data: data,
							acttype: 'set_notread'
						});
					}
				}
				return false;
			});
			js_funcs.cancelmessage();
			js_funcs.deletemess();
		},

		onemessage: function() {
			$('#answer').keypress(function (e) {
				if (e.which == 13 && e.ctrlKey||e.metaKey ){
					$('#answerform').submit();
				}
			});
			sendednow = true;
			$('#answerform').submit(function(){
				data = $(this).serialize();
				var value = trim($('#answer').attr('value'));
				if ( value.length === 0 ) {
					prederr(text[3]);
					return false;
				}
				if (sendednow) {
					$.gajax({
						beforeSend: function(){
							$('#answer').next().show();
							$('#sendanswer').children().focus();
							sendednow = false;
						},
						acttype: 'send_answer',
						data: data,
						complete: function(){
							sendednow = true;
							$('#answer').next().hide().prev().focus();
						}
					});
				}
				return false;
			});
			$('#messlist .notread').live('click', function(e){
				clicked = e.target;
				if ( $(clicked).is('a') ) {
					return true;
				}
				mess_id = $(this).attr('id');
				mess_id = mess_id.match(/mess([0-9]+)/);
				if (mess_id !== null ) {
					data = 'idmess='+mess_id[1];
					$.gajax({
						data: data,
						acttype: 'set_read'
					});
				}
				return false;
			});
			js_funcs.deletemess();
			js_funcs.cancelmessage();
		},

		new_message: function() {
			$('#messagetext').keypress(function (e) {
				if (e.which == 13 && e.ctrlKey||e.metaKey ){
					$('#messageform').submit();
				}
			});
		},

		photoedit: function() {
			$('#images').click(function(e) {
				clicked = $(e.target);
				var send = false;
				// delete
				if ($(clicked).hasClass('deletethisitem') ) {
					idf = $(clicked).parent().attr("id");
					type = 'delete';
					send = true;
				}
				// make a main
				if ($(clicked).hasClass('makemeamain') ) {
					idf = $(clicked).parent().attr("id");
					type = 'makeamain';
					send = true;
				}

				if (send) {
					$.gajax({
						beforeSend: function(){
							$(clicked).parent().children(":last").show();
						},
						data: 'idf='+idf+'&type='+type,
						acttype: 'photo',
						complete: function(){
							$(clicked).parent().children(":last").hide();
						}
					}); // close ajax
					return false;
				} // close if

			}); // close function

			$("#loadimage").submit(function(){
				ajaxFileUpload('addimageinitem', tid);
				return false;
			}); // close submit
		}
	};



	// start functions
	if ( window.thispage !== undefined && typeof( js_func_page[thispage]) == 'function' ) {
		js_func_page[thispage]();
	}
});

function prederr(errmess){
	if ( errmess instanceof Array ) {
		if (showpredmess>0) {
			$("#pred").remove();
		}
		err = '';
		for(var i=0; i<errmess.length; i++) {
			err += '<p class="predmess"><span class="info">.</span>'+errmess[i]+'</p>';
		}
		showpredmess+=i;
		$("#osn").before('<div id="pred" style="opacity: 0;">'+err+'</div>').prev().animate({opacity: 1});
	} else {
		if (showpredmess === 0) {
			$("#osn").before('<div id="pred"><p class="predmess"><span class="info">.</span>'+errmess+'</p></div>');
		} else {
			$("#pred > .predmess:first").remove();
			$("#pred").append('<p class="predmess" style="opacity: 0;"><span class="info">.</span>'+errmess+'</p>').children(':last').animate({opacity: 1});
		}
		showpredmess++;
	}
}

jQuery.fn.fadeslide = function(){
	$(this).children(':first').toggleClass('viewed').end().next().animate({height: 'toggle'}, 'fast');
};

var functions = {

	myavatar: function() {
		$("#righttd .cancel").click(function(){
			$(this).attr('href','#!/myworld/?v=info');
			$("#righttd").loadform("myworld");
		});
		$("#loadimage").submit(function(){
			ajaxFileUpload('myavatar_new');
			return false;
		});
	},

	myavatar_loaded: function( agrs ) {
		upath = agrs.upath;
		path = agrs.path;
		var r = getRandom();
		$("#imagetoupload").attr("value","");
		$("#mainava").attr("src", path+"l"+upath+"?r="+r).load().parent().next().next().next().show();
		$("#miniava").attr("src",path+"m"+upath+"?r="+r).load().parent().parent().parent().next().children().children().children().attr("src",path+"s"+upath+"?r="+r);
		$("#avatr").children(":first").attr( "src", path+"s"+upath+"?r="+r );
		$("#avtrimg").children(":first").attr( "src", path+"m"+upath+"?r="+r );
	},

	myavatar_deleted: function( agrs ) {
		path = agrs.path;
		$("#mainava").attr("src", path+"l/noavatar.jpg").load();
		$("#miniava").attr("src",path+"m/noavatar.jpg").load().parent().parent().parent().next().children().children().children().attr("src",path+"s/noavatar.jpg");
		$("#avatr").children(":first").attr( "src", path+"s/noavatar.jpg" );
		$("#avtrimg").children(":first").attr( "src", path+"m/noavatar.jpg" );
		$(clicked).hide();
	},

	personalinfo: function() {
		$("#righttd .cancel").click(function(){
			$(this).attr('href','#!/myworld/?v=info');
			$("#righttd").loadform("myworld");
		});
		$("#personalinfo").saveform('savemyinfo');
	},

	privacy: function() {
		$(".cancel").click(function(){
			$(this).attr('href','#!/myworld/?v=info');
			$("#righttd").loadform("myworld");
		});
		$("#saveprivacy").saveform('save_privacy');
	},

	feedback_sended: function() {
		k = $(form).parent().parent();
		$(form).parent().slideUp( 'normal', function(){$(this).remove();});
		if ( html[1] !== undefined ) {
			$(k).append(html[1]);
		}
		if ( $(k).html() === '' ) {
			$(k).parent().remove();
		}
		$("#feedfrom").prepend(html[0]).children(':first').css("display", 'none').fadeIn('slow');
	},

	change_pass_success: function() {
		$('#repassform').children().children(':first').next().children().attr("value", '');
		$('#new_pass').attr("value", '');
		$('#pass_a').attr("value", '');
		$("#repassform").parent().prev().fadeslide();
	},

	change_email_succsess: function() {
		$('#remailform').parent().prev().fadeslide();
	},

	city_list: function() {
		$("#page").before(html[0]);
		$("#citylist .mycity").click(function(){
			$.cookie(cookiepref+'city', $(this).attr("id").substr(3), { expires: 14, path: '/' });
			return true;
		});
		$("#cityid").data('obtained', true );
		$("#clcitlist").click(function(){
			$(this).parent().parent().hide();
			return false;
		});
	},

	photo_deleted: function( agrs ) {
		osnfoto = agrs.osnfoto;
		newosn = agrs.newosn;
		$(clicked).parent().animate({"width": "0",opacity: "hide"}, "fast", "linear", function(){
			$(clicked).remove();
		});

		if (osnfoto!='0') {
			var height = $("#mainimagecontainer").height();
			$("#mainimagecontainer").css('height',height).html(html[0]);
		}
		if (newosn!='0') {
			$("#idf-"+newosn).children(":first").next().hide();
		}
	},

	main_image_established: function() {
		var height = $("#mainimagecontainer").height();
		$("#mainimagecontainer").css('height',height).html(html[0]);
		$("#images .makemeamain").show();
		$(clicked).hide();
	},

	image_added: function() {
		$("#images").append(html[0]);
		$('#imagetoupload').attr('value','');
		if ( html[1] !== undefined ){ $("#mainimagecontainer").html(html[1]);}
		$("#images").children(":last").hide().fadeIn(500);
	},

	showbox: function( agrs ) {

		var header = agrs.header;
		var closebtn, gheight;
		if ( agrs.buttons !== undefined) {
			$('#'+boxid+' .box-buttons').html('<div class="box-buttons-inner">'+agrs.buttons+'</div>');
			closebtn = '';
		} else {
			closebtn = '<a href="#" class="cl fr">X</a>';
		}

		$('#'+boxid+' .box-inner').empty().append( html[0]);
		$('#'+boxid+' .box-header').empty().append(closebtn+header);

		var bheight = $('#'+boxid).children().height();
		if(window.innerHeight){
			gheight = window.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) {
			gheight = document.documentElement.clientHeight;
		} else if (document.body && document.body.clientHeight){
			gheight = document.body.clientHeight;
		}

		if ( gheight - 360 < bheight ) {
			gheight -= 400;
			if ( gheight < 400 ) {gheight = 400;}
			$("#gatar .box-inner").css({
				height: gheight
			});
		}

	},

	deletebid: function() {
		$(".deletebid").click( function() {
			bid = $(this).attr("id");
			$.gajax({
				data: 'bid='+bid,
				acttype: 'deletebid'
			});
			return false;
		});
	},

	biddeleted: function() {
		$('#'+bid).parent().parent().parent().after(html[0]).remove();
	},

	messadded: function( agrs ) {
		var countel = document.getElementById('messlist').getElementsByTagName("li").length;
		if ( agrs.cuntmess <= countel ) {
			$('#messlist').children(':last').remove();
		}
		$('#messlist').prepend(html[0]).children(':first').css('display','none').slideDown(300);
		$('#answer').attr( 'value', '');
	},

	messreadsetted: function() {
		$("#mess"+mess_id[1]).removeClass('notread');
	},

	messnotreadsetted: function() {
		$("#mess"+mess_id[1]).addClass('notread');
	},

	messcanceled: function() {
		$("#mess"+mess_id[1]).addClass('cancelledmess');
	},

	youwatched: function() {
		$(clicked).html(text[1]).attr("href", data.replace( /watch/, 'nowatch' )).next().fadeOut(30).fadeIn(300);
	},

	younotwatched: function() {
		$(clicked).html(text[0]).attr("href", data.replace( /nowatch/, 'watch' )).next().hide();
	},

	delconfirm: function(agrs) {
		$("#"+boxid+" .cancel").click(function(){
			$(this).parents().filter('.box').remove();
			return false;
		});
		var tid = agrs.tid;
		var delkey = agrs.delkey;
		$("#"+boxid+" .deleteitem").click(function(){
			$.gajax({
				data: 'delkey='+delkey+'&tid='+tid,
				acttype: 'deleteitem'
			});
			$(this).parents().filter('.box').remove();
			return false;
		});
	},

	buyconfirm: function(agrs) {
		$("#"+boxid+" .cancel").click(function(){
			$(this).parents().filter('.box').remove();
			return false;
		});
	},

	itemdeleted: function(agrs) {
		$("#itemrow"+agrs.gid+" .vipspisok").html(agrs.status);
	},

	selphonegetted: function(agrs){
		if ( $.browser.msie ) {
			agrs.image = '/service/iephonefix/base64decode.php?' + agrs.image.slice(5);
		}
		$('#selph').html('<img src="'+agrs.image+'" />');
	}
};

function start_functions() {
	if ( funcname !== undefined ) {
		for( i=0; i <funcname.length; i++) {
			functions[funcname[i]](params[i]);
		}
		delete funcname;
	}
}

// подгружает вызванный контент
jQuery.fn.loadform = function(typeform){
	var par = $(this);
	// height fix
	height = $(par).height();
	$(par).css('height', height);
	$.ajax({
		url: '/ajax.php',
		type: 'post',
		data: { 'acttype' : 'getpage', 'page' : typeform },
		beforeSend: function(){
			$(par).html('<div class="loader"></div>');
		},
		dataType: 'xml',
		success: function(xml){
			parsercode(xml);
			if ( html[0] !== undefined) {
				$(par).html('<div style="display: none;">'+html[0]+'</div>').children().fadeIn('fast');
			}
			start_functions();
		},
		timeout: 6000,
		complete: function(){
			// end height fix
			$(par).css('height', 'auto');
		},
		error: function(s,err){
			$(par).css('height', 'auto').html('');
			if ( s.status == 200 && err == 'parsererror' ) {
				alert(text[5]);
			} else if (s.status == 12029 || s.status === 0) {
				prederr(text[2]);
			}
		}
	});
};

// сохраняет данные в формах
jQuery.fn.saveform = function(formtype){
	$(this).live( 'submit', function(){
		data = $(this).serialize();
		form = $(this);
		$.gajax({
			data: data+'&saveform='+formtype,
			acttype: 'saveform'
		});
		return false;
	});
};

// загружает попап
function loadbox( type, param ){

	boxid = 'box'+getRandom();
	var box = '<div class="box" id="'+boxid+'"><div class="box-container"><div class="box-dialog"><div class="box-content"><div class="box-header"><a href="#" class="cl fr">X</a>'+text[4]+'</div><div class="box-inner"><div class="cc"><img src="/style/img/loader.gif" /></div></div><div class="box-buttons"></div></div></div></div></div>';
	$('#gatar').prepend(box);
	$(".cl").live('click', function(){
		$(this).parent().parent().parent().parent().parent().fadeOut( 300, function(){$(this).remove();});
		return false;
	});

	var scr;
	if(window.innerHeight){
		scr = window.scrollY;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		scr = document.documentElement.scrollTop;
	} else if (document.body && document.body.clientHeight){
		scr = 0;
	}
	$('#'+boxid).css('top',scr);
	$.gajax({
		data: 'parametr1='+param+'&boxtype='+type,
		acttype: 'box'
	});
}


/* SecAjaxParser */
function parsercode(xml){

	// warnings errors
	var ajerror = [];
	$(xml).find('error').each(function(){
		ajerror[ajerror.length] = $(this).text();
	});
	if ( ajerror.length > 0) {
		prederr(ajerror);
		//show_errors(ajerror);
	}
	// info messages
	var ajmess = [];
	$(xml).find('message').each(function(){
		ajmess[ajmess.length] = $(this).text();
	});
	if ( ajmess.length > 0) {
		prederr(ajmess);
		//show_secmess(ajmess);
	}

	html = [];

	// html
	$(xml).find('html').each(function(){
		html[html.length] = $(this).text();
	});

	// js
	funcname = [];
	params = [];
	$(xml).find('script').each(function(){
		funcname[funcname.length] = $(this).find('funcname').text();
		params[funcname.length - 1] = [];
		$(this).find('parameter').each(function(){
			params[funcname.length - 1][$(this).find('name').text()] = $(this).find('value').text();
		});
	});
}

function ajaxFileUpload(acttype, mytid) {
	//starting setting some animation when the ajax starts and completes

	$.ajaxFileUpload({
		url:'/ajax.php',
		secureuri:false,
		fileElementId:'imagetoupload',
		acttype: acttype,
		beforeSend: function(){
			$("#imgloader").show();
		},
		mytid: mytid,
		dataType: 'xml',
		success: function (xml) {
			parsercode(xml);
			start_functions();
		},
		complete: function() {
			$("#imgloader").hide();
		},
		error: function (data, status, e)
		{
			alert(e);
		}
	});

	return false;
}

jQuery.extend({
	gajax: function(s)
	{
		if (s.acttype === undefined) {
			alert('error with gatar ajax request');
		}
		if ( !('data' in s) || s.data.length === 0 ) {
			s.data = 'acttype='+s.acttype;
		} else {
			s.data = s.data+'&acttype='+s.acttype;
		}
		$.ajax({
			url: '/ajax.php',
			type: 'post',
			data: s.data,
			beforeSend: s.beforeSend,
			dataType: 'xml',
			success: function(xml){
				parsercode(xml);
				start_functions();
			},
			timeout: 6000,
			complete: s.complete,
			error: function(s,err){
				if ( s.status == 200 && err == 'parsererror' ) {
					alert(text[5]);
				} else if (s.status == 12029 || s.status === 0) {
					prederr(text[2]);
				}
			}
		});
	}
});

function getRandom(){
	var rand = Math.random()+' ';
	return rand.substr(2,3);
}

function trim(str) {
	var newstr = str.replace(/^\s*(.+?)\s*$/, "$1");
	if (newstr == " ") {
		return "";
	}
	return newstr;
}

function PopupCenter(pageURL, title, w, h) {
	var left = (screen.width/2)-(w/2);
	var top = (screen.height/2)-(h/2);
	var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
}


/////////// for item_info and user info
function showphone(seller){
	$.gajax({
		data: 'seller='+seller,
		acttype: 'selphone'
	});
}
