jQuery.fn.stripTags = function() {
        return this.replaceWith( this.html().replace(/<\/?[^>]+>/gi, '') );
};

function startUpload(){
    document.getElementById('f1_upload_process').style.visibility = 'visible';
    document.getElementById('f1_upload_form').style.visibility = 'hidden';
    return true;
}

function stopUpload(success){
    var result = '';
    if (success == 1){saveChanges('f1_upload_form','Изображение успешно загружено!');}
    else {cancelChanges('f1_upload_form','Изображение не было загружено');}
    document.getElementById('f1_upload_process').style.visibility = 'hidden';
    $('#uploaded').val('');
    document.getElementById('f1_upload_form').style.visibility = 'visible';      
    return true;
}

function setImgUploader(caller,action){
	/* example 1 */
	var button = $('#'+caller),hideB = $('#hide_'+caller), interval;
	new AjaxUpload(button,{
		action: action, 
		name: 'uploaded',
		onSubmit : function(file, ext){
	        if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){
	            // extension is not allowed
	        	cancelChanges(caller,'Неверный формат файла');
	            //alert('Error: invalid file extension');
	            // cancel upload
	            return false;
	        }
			// change button text, when user selects file			
	        hideB.text('Загрузка');
			// If you want to allow uploading only 1 file at time,
			// you can disable upload button
			this.disable();
			// Uploding -> Uploading. -> Uploading...
			interval = window.setInterval(function(){
				var text = hideB.text();
				if (text.length < 13){
					hideB.text(text + '.');					
				} else {
					hideB.text('Загрузка');				
				}
			}, 200);
		},
		onComplete: function(file, response){
			//hideB.text('');
			window.clearInterval(interval);
			// enable upload button
			this.enable();	
			// add file to the list
			saveChanges(caller,'Изображение успешно сохранено');
			xajax_groups_reloadImg($("input#id_groups").val());
/*			if(response == 200){
				saveChanges(caller,'Изображение успешно сохранено');
				xajax_groups_reloadImg($("input#id_groups").val());
			}else {
				switch(response){
					case 400:
						cancelChanges(caller,'У вас нет прав на данное действие');
						break;
					case 401:
						cancelChanges(caller,'Не удалось сохранить изображение');
						break;
					case 500:
						cancelChanges(caller,'Ошибка (500)');
						break;
				}
			}
			$('<div></div>').appendTo('#hide_'+caller).text(response);*/
		}
	});
}

function loadEvents(){
	window.setTimeout('xajax_loadEvents()',300000);
}

function responseTxt(type,txt,timer){
	$("#response"+type).html(txt);
	var Wait = (timer)? timer : 5000;
	$('#response'+type).fadeIn("slow");
	$('#response'+type).wait(Wait).fadeOut("slow");
}

function makeChanges(obj){
	//min 180-200
	var width = ($("#hide_"+obj).width() > 230) ? $("#hide_"+obj).width() : 230;
	$("#hide_"+obj).css({
		width: width + "px",
		border: '1px #B22222 solid',
		background: '#F08080',
		padding: '3px'
	});
	$('#hide_'+obj).html('Изменения не сохранены');
	$('#hide_'+obj).fadeIn("slow");
}

function saveChanges(obj,txt){
	//min 180-200
	var width = ($("#hide_"+obj).width() > 230) ? $("#hide_"+obj).width() : 230;
	$("#hide_"+obj).css({
		width: width + "px",
		border: '1px #32CD32 solid',
		background: '#98FB98',
		padding: '3px'
	});
	if($("#hide_"+obj).css("display") != 'block'){$('#hide_'+obj).fadeIn("slow");}
	$('#hide_'+obj).html(txt);
	$('#hide_'+obj).wait(3000).fadeOut("slow");
}

function cancelChanges(obj,txt){
	//min 180-200
	var width = ($("#hide_"+obj).width() > 230) ? $("#hide_"+obj).width() : 230;
	$("#hide_"+obj).css({
		width: width + "px",
		border: '1px #B22222 solid',
		background: '#F08080',
		padding: '3px'
	});
	$('#hide_'+obj).html(txt);
	$('#hide_'+obj).fadeIn("slow");
	$('#hide_'+obj).wait(3000).fadeOut("slow");
}

var lastEvent;
var lastThis;
function preloadBox(arg,callerID,event,type){
	lastEvent = event;
	lastThis = callerID;
	if(!type)xajax_loadUser(arg);
	else{
		switch(type){
			case 'ig':
				xajax_eGroups();
				break;
		}
	}
}

function setTT(heading,txt){
	switch(heading){
		case 1:Box['htt'] = 'Описание фотографии';break;
		case 2:Box['htt'] = 'Просмотр изображения';break;
	}
	Box['btt'] = txt;
}

var Box = new Array();
function loadBox(loadID,callerID,event,center,width,fadeout){
	if(!callerID) var callerID = lastThis;
	if(!event) var event = lastEvent;
	$(callerID).jWindow({
		container:'#'+loadID,
		title: Box['h'+loadID],
		text: Box['b'+loadID],
		ev: event,
		width: width,
		center: center,
		fadeout: fadeout
	});
	boxEval(loadID);
}

function boxEval(loadID){
	switch(loadID){
		case 'gBoxCrt':
			eval('$("#gBoxCrtB").click(function(){xajax_addGroup($("input#eBoxIn").val());$("#gBoxCrt").fadeOut("slow");});');
			break;
		case 'gBoxWallMsg':
			eval('$("#gBoxWallMsgB").click(function(){xajax_wall_addMsg($("textarea#eBoxIn").val());$("#gBoxWallMsg").fadeOut("slow");});');
			break;
		case 'gBoxSearchGroup':
			eval('$("#gBoxSearchGroupB").click(function(){xajax_getGroups($("input#mass").val(),$("input#perpage").val(),$("input#eBoxIn").val(),$("input#cat").val(),$("input#country").val(),$("input#city").val());$("#gBoxSearchGroup").fadeOut("slow");});');
			break;
		case 'gBoxInvite':
			eval('$("#gBoxInviteB").click(function(){xajax_sendInvite(0,$("textarea#eBoxIn2").val(),$("input#eBoxIn").val());$("#eBoxIn").val("");$("#eBoxIn2").val("");});');
			break;
		case 'gGalleryA':
			eval('$("#gGalleryAB").click(function(){xajax_addAlbum($("input#eBoxIn").val());$("#gGalleryA").fadeOut("fast");});');
			break;
	}
}

function inlineEdit(objID,width){
	$("#"+objID).hide();
	$("#updtime_"+objID).hide();
	$("#parent_"+objID).append('<textarea id="inline_'+ objID +'" rows="4" onblur="inlineSave(\''+ objID +'\')" style="width:'+ width +'px;">'+ $("#"+objID).html().replace(/<br>/g, "\n") +'</textarea><div id="inlineB_'+objID+'" style="text-align:right; margin-right:5px; padding-top:5px;"><button title="Сохранить" id="wallMsgFakeB" name="wallMsgFakeB" type="button"><div class="container"><div class="corner"><div class="spacer"></div></div><div class="but-text">Сохранить</div></div></button></div>');
	$("#inline_"+ objID).focus();
}

function inlineSave(objID){
	xajax_groups_inlineUpd(objID,$("textarea#inline_"+objID).val());
	$("#"+objID).html($("textarea#inline_"+objID).val().replace(/\n/g, "<br />"));
	$("#inline_"+objID).remove();
	$("#inlineB_"+objID).remove();
	$("#"+objID).show();
	$("#updtime_"+objID).show();
	$("#parent_"+objID).highlightFade({color:'yellow',speed:1000});
}

function removeObj(objID){
	//$("#"+objID).highlightFade({color:'yellow',speed:1000,complete:function(){$("#"+objID).remove();},iterator:'exponential'});
	$("#"+objID).remove();
}

function removeObjFade(objID){
	$("#"+objID).highlightFade({color:'yellow',speed:1000,complete:function(){$("#"+objID).remove();},iterator:'exponential'});
}

function addObj(locID,objID,html){
	$("#"+locID).append(html);
	$("#"+objID).highlightFade({color:'yellow',speed:1000});
}

function replaceObj(locID,objID,html){
	removeObj(objID);
	addObj(locID,objID,html);
}