function delCtg(id, url){
	if (confirm('Вы подтверждаете удаление?')){
		document.getElementById('dib'+id).src="/system/admin/themes/src/img/inf/loading.gif";
		parent.location= url+'&id='+id;
	}
}

function ChangeOption(selectedOption) {
	document.getElementById('floor').style.display = "none";
	document.getElementById('wall').style.display = "none";
	document.getElementById('door').style.display = "none";
	document.getElementById('ceiling').style.display = "none";
	document.getElementById('electrician').style.display = "none";
	document.getElementById('any').style.display = "none";
	
	if(selectedOption == 'floor') {document.getElementById('floor').style.display = "";}
	if(selectedOption == 'wall') {document.getElementById('wall').style.display = "";}
	if(selectedOption == 'door') {document.getElementById('door').style.display = "";}
	if(selectedOption == 'ceiling') {document.getElementById('ceiling').style.display = "";}
	if(selectedOption == 'electrician') {document.getElementById('electrician').style.display = "";}
	if(selectedOption == 'any') {document.getElementById('any').style.display = "";}
}


function del_photo(id, image, cat){
	if (confirm('Вы подтверждаете удаление?')){
		document.getElementById('imd'+id).src = '/system/admin/themes/src/img/inf/loading.gif';
		$.ajax({type: "POST",url: "admin.php?m=engine&a=foto_del&t="+image+"&c="+cat,cache: false,success: 
			function(){
				$('#entrP'+id).fadeOut('slow', function() {$(this).remove();});
			}
		});
	}
}

function dmpd_save_setup(type){
		document.getElementById('buts').src="/system/admin/themes/src/img/inf/loading.gif";
		document.getElementById('buts').title="Загрузка";
		
		var str = $("#setup").serialize();
		$.post("admin.php?m=engine&a=foto_setup_edit", str, function(data, status) {
			document.getElementById('buts').src="/system/admin/themes/src/img/inf/good.png";
			document.getElementById('buts').title="Настройке сохранены!";
		});

}

function dmpd_send_mail(){
		document.getElementById('buts').src="/system/admin/themes/src/img/inf/loading.gif";
		document.getElementById('buts').title="Загрузка";
		
		$.ajax({
			url: "index.php?do=mail&t=mail_send",
			global: false,
			type: "POST",
			data: ({id : this.getAttribute('id')}),
			dataType: 'json',
			async:false,
			success: function(msg){
				alert(msg);
			}
		});
		
		
		/*
		var str = $("#setup").serialize();
		$.post("index.php?do=mail&t=mail_send", str, function(data, status) {
			alert(data.error);
				if(typeof(data.error) != 'undefined'){
	
					if(data.error != ''){
						document.getElementById('buts').src="/system/admin/themes/src/img/inf/error.png";
						document.getElementById('buts').title=data.error;
						//alert(data.error);
					} else {
						document.getElementById('buts').src="/system/admin/themes/src/img/inf/good.png";
						document.getElementById('buts').title=data.msg;
						//alert(data.msg);
					}
				}
			
			
			//document.getElementById('buts').src="/system/admin/themes/src/img/inf/good.png";
			//document.getElementById('buts').title="Настройке сохранены!";
		});
*/
}


function ajaxFileUpload(){
	document.getElementById('buts').src="/system/admin/themes/src/img/inf/loading.gif";
	document.getElementById('buts').title="Загрузка";
	$.ajaxFileUpload
	(
		{
			url:'admin.php?m=engine&a=foto_add&t=' + $( '#dmpd_cat' ).val(),
			secureuri:false,
			fileElementId:'fileToUpload',
			dataType: 'json',
			success: function (data, status){
				if(typeof(data.error) != 'undefined'){
	
					if(data.error != ''){
						document.getElementById('buts').src="/system/admin/themes/src/img/inf/error.png";
						document.getElementById('buts').title=data.error;
						//alert(data.error);
					} else {
						document.getElementById('buts').src="/system/admin/themes/src/img/inf/good.png";
						document.getElementById('buts').title=data.msg;
						//alert(data.msg);
					}
				}
			},
			error: function (data, status, e){
				document.getElementById('buts').src="/system/admin/themes/src/img/inf/error.png";
				document.getElementById('buts').title=e;
				//alert(e);
			}
		}
	)
	return false;
}


function g_k_c(){
	var ct;
	for(var i=0;i<k_c_a_t.length;i++){
		if (k_c_a_t[i][1]==1){
			ct += '<option value="10000" style="background:#000000;color:#FFFFFF;">'+k_c_a_t[i][2]+'</option>';
		} else {
			ct += '<option value="'+k_c_a_t[i][0]+'"'+(k_c_a_t[i][3]?' selected':'')+'>'+(k_c_a_t[i][4]?'&nbsp; &nbsp;':'')+k_c_a_t[i][2]+'</option>';
		}
	}
	document.write('<select size="1" onchange="if(this.options[this.selectedIndex].value!=\'10000\'){window.location.href=\'/admin.php?m=photo&c=\'+this.options[this.selectedIndex].value}"><option value="">-Выберите категорию-</option><option value="0">Все фотографии</option>'+ct+'</select>');
}

function g_k_c_u(){
	var ct;
	for(var i=0;i<k_c_a_t.length;i++){
		if (k_c_a_t[i][1]==1){
			ct += '<option value="0" style="background:#000000;color:#FFFFFF;">'+k_c_a_t[i][2]+'</option>';
		} else {
			ct += '<option  value="'+k_c_a_t[i][0]+'"'+(k_c_a_t[i][3]?' selected':'')+'>'+(k_c_a_t[i][4]?'&nbsp; &nbsp;':'')+k_c_a_t[i][2]+'</option>';
		}
	}
	document.write('<select style="width: 100%" id="dmpd_cat" size="1"><option value="0">-Выберите категорию-</option>'+ct+'</select>');
}



function _coloredTDs(d, e) {
	var a = "";
	if (typeof(d) != "object") {
		d = document.getElementById(d)
	}
	if (typeof(document.getElementsByTagName) != "undefined") {
		a = d.getElementsByTagName("td")
	} else {
		if (typeof(d.cells) != "undefined") {
			a = d.cells
		} else {
			return false
		}
	}
	for (var b = 0; b < a.length; b++) {
		a[b].className = e
	}
}

function window_open(url, width, height, name, scroll_bar, location){

	_top = Math.ceil((screen.height - height)/2);
	_left = Math.ceil((screen.width - width)/2);

	if(scroll_bar != true){
		var scroll = 'no';
	}else{
		var scroll = 'yes';
	}
	if(typeof location != "undefined" && location == true){
		var location = 'yes';
	}else{
		var location = 'no';
	}

	if(name == undefined){
		name = Math.round(999999 * Math.random());
	}
	new_win = window.open(url, name , 'width=' + width + ',height=' + height + ',location='+ location +',status=no,toolbar=no,menubar=no,resizable=yes,scrollbars=' + scroll + ',top=' + _top + ',left=' + _left);
	new_win.focus();
	return new_win;
}

function window_close(do_refresh, url){

	if(do_refresh == true){
		if (url == undefined){
			try {
				window.opener.location.reload();
			}
			catch(err){
				window.close();
			}
		}else {
			try {
				window.opener.location.href = url;
			}
			catch(err){
				window.close();
			}
		}
	}
	window.close();
	return false;
}
