function addslashes(str){return(str+'').replace(/([\\"'])/g,"\\$1").replace(/\0/g,"\\0")}
function go(loc){location.href=loc}
function price(price){var np='';for(var i=f.length-3;i>=0;i=i-3){if(np!='')np=np+' ';np=np+price.substr(i,3)}return np}
function setValue(tn,field,value,id,reload){$.post("/ajax/setValue",{tn:tn,field:field,value:value,id:id},function(data){if(data!='false')if(reload)go(location.href)})}
function getTKdata(city,v,xyz,count,type){$.post("/ajax/getTKdata",{city:city,v:v,xyz:xyz,count:count,type:type},function(data){if(data=='false')$('#dostBlock').css('display','none');else{$('#dostBlock').css('display','block');$('#dostTxt').html(data)}})}
function getValue(tn,field,where,elem){$.post("/ajax/getValue",{tn:tn,field:field,where:where},function(data){if(elem){$('#'+elem).attr('value',data);return data}else return data})}
function reloadValue(tn,field,id,elementId){
	var remoteVal = $.ajax({url: "/ajax/getValue",type: "POST",async:false,data:'tn='+tn+'&field='+field+'&where=id='+id+''}).responseText;
	var mainVal =   $('#'+elementId).val();	
	if (mainVal!=remoteVal){
		alert('Значение в базе удаленно измененно! значение в поле будет обновлено');
		$('#'+elementId).val(remoteVal);	
	}	
}
function delValue(tn,fieldname,fvalue,reload){$.post("/ajax/delRec",{tn:tn,fieldname:fieldname,fvalue:fvalue},function(data){if(data!='false')if(reload)go(location.href)})}
function setPriority(tn,action,id,where){ $.post("/ajax/setPriority",{tn:tn,action:action,id:id,where:where},function(data){if(data!='false')go(location.href)})}
function clearForm(formname){var f=document.getElementById(formname);for(var i=0;i<f.length;i++){switch(f[i].type){case'checkbox':f[i].checked='';break;case'select-one':f[i].value=1;break;case'textarea':f[i].value='';var oEditor=FCKeditorAPI.GetInstance(f[i].id);oEditor.SetHTML("");break;default:f[i].value='';break}}}
function fillForm(tn,id){
	$.post("/ajax/getRec",{tn:tn,id:id},
	function(data){
		if(data!='false'){
			for(var i in data){
				//switch($('#'+i).attr('type')){
				if ($('#'+i).prop('tagName') == 'TEXTAREA'){
					$('#'+i).attr('value',data[i]);
					var oEditor=FCKeditorAPI.GetInstance(i);
					oEditor.SetHTML(''+data[i]);
				} else if($('#'+i).attr('type')=='checkbox') {
					if(data[i]==1)
						$('#'+i).attr('checked','checked');
					else 
						$('#'+i).removeAttr('checked');
				} else {
					$('#'+i).attr('value',data[i]);
				}
			}
		}
	},"json")
}
function saveForm(fname,tn,reload){
		var fdata='';
		var f=document.getElementById(fname); 
		for(var i=0;i<f.length;i++){
			if ($('#'+f[i].id).prop('tagName') == 'TEXTAREA'){
				if(f[i].id!='short')
						var val=FCKeditorAPI.GetInstance(f[i].id).GetXHTML(); 
					else 
						var val=f[i].value+'';
			} else if ($('#'+f[i].id).attr('type')=='checkbox'){
						if(document.getElementById(f[i].id).checked)
							var val=1;
						else 
							var val=0;
					}else
						var val=f[i].value; 
			fdata=fdata+f[i].id+'::'+val;
			if(i<f.length-1)fdata=fdata+';;;'}
			$.post("/ajax/setRec",{tn:tn,fdata:fdata},function(data){if(data!='false')if(reload){}else{return data}})
}
$(document).ready( function(){$("i").each(function(){$(this).replaceWith("<a class='" + $(this).attr("class") +"'" +" href='" + $(this).attr("title") + "'>" +$(this).text() + "</a>");}); });
