 
 
function nav(ur)
{
	ColdFusion.navigate(ur,'DivMain');
}
 
 
function navdiv(ur,dn)
{
	ColdFusion.navigate(ur,dn);
}


function edobject(id)
{
	ColdFusion.Window.show("edobj");
	ColdFusion.navigate('/ed_obj.cfm?id_obj='+id,'edobj');
}


function edimage(id)
{
	ColdFusion.Window.show("edimage");
	ColdFusion.navigate('/ed_image.cfm?id_image='+id,'edimage');
}


function ed(ur,ctr)
{
	ColdFusion.Window.show(ctr);
	ColdFusion.navigate(ur,ctr);
}


function edtyp(id)
{
		ColdFusion.Window.show("edtyp");
		ColdFusion.navigate('/ed_typ.cfm?id_objtyp='+id,'edtyp');
}


function popupo(addr,h,w)
{
window.open(addr,"_blank",
            "height="+h+",width="+w+",left="+Math.ceil(document.body.clientWidth/2-w/2)+",top="+
			Math.ceil(document.body.clientHeight/2-h/2)+",status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=yes");
}

function refreshActiveTab(tabname){
var activeID = ColdFusion.Layout.getTabLayout(tabname).getActiveTab().id;
ColdFusion.Layout.hideTab(tabname, activeID);
ColdFusion.Layout.showTab(tabname, activeID);
ColdFusion.Layout.selectTab(tabname, activeID);
return;
}		


   function closeWin(){
      try{
      ColdFusion.Window.getWindowObject(winName).destroy();
      } catch (err) {}   
   }
		
            function doLogin() {
                // Create the ajax proxy instance.
                var aut = new auth();

                // setForm() implicitly passes the form fields to the CFC function.
                aut.setForm("loginform");
                //Call the CFC validateCredentials function.
                if (aut.validateCredentials()) {
                    var msg = document.getElementById("loginwindow_title");
                    msg.innerHTML = "Ж Д И Т Е !!!!  Производится вход в систему....";
					window.location.href=window.location.href;
//                    ColdFusion.Window.hide("loginwindow");
//					window.location.href=window.location.href;
                } else {
                    var msg = document.getElementById("loginwindow_title");
//                    msg.innerHTML = "Не правильно. Попробуйте еще разок!";
					alert('Не правильно, попробуйте еще разок. Если у Вас нет имени и пароля, просто зарегистрируйтесь.')
                }
            }
			
            function testuser() {
                var aut = new auth();
                aut.setForm("regform");
                if (aut.validateUser()==false) {
				alert('Такое имя пользователя уже занято!');
				document.all('username').value='';
                }
            }		


	function refreshtree(treename) {
    ColdFusion.Tree.refresh(treename);
	 }

    function callback(text)
    {
        alert("Сообщение: " + text);
    }
    
    function errorHandler(code, msg)
    {
        alert("Ошибка!!! " + code + ": " + msg);
    }



   function ajaxFileUpload(tbl,fld,idrec)
   {
      $("#loading")
      .ajaxStart(function(){
         $(this).show();
      })
      .ajaxComplete(function(){
         $(this).hide();
      });

      $.ajaxFileUpload
      (
         {
            url:'/ajaxuploadfile.cfm?table='+tbl+'&FIELD='+fld+'&IDREC='+idrec,
            secureuri:false,
            fileElementId:fld,
            dataType: 'json',
            success: function (data, status)
            {
               if(typeof(data.error) != 'undefined')
               {
                  if(data.error != '')
                  {
                     alert(data.error);
                  }else
                  {
                     alert(data.msg);
                  }
               }
            },
            error: function (data, status, e)
            {
               alert(e);
            }
         }
      )
      
      return false;

   }

/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/

var Url = {

	// public method for url encoding
	encode : function (string) {
		return escape(this._utf8_encode(string));
	},

	// public method for url decoding
	decode : function (string) {
		return this._utf8_decode(unescape(string));
	},

	// private method for UTF-8 encoding
	_utf8_encode : function (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;
	},

	// private method for UTF-8 decoding
	_utf8_decode : function (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 ted(idfl)
{
	tinyMCE.init({
		// General options
<!---mode : "textareas",--->
mode : "exact",
	elements : idfl,	
		theme : "advanced",
		plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

		// Theme options
		theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
		theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
		theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
		theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
		theme_advanced_toolbar_location : "top",
		theme_advanced_toolbar_align : "left",
		theme_advanced_statusbar_location : "bottom",
		theme_advanced_resizing : true,
		// Example content CSS (should be your site CSS)
		content_css : "css/content.css",

		// Drop lists for link/image/media/template dialogs
		template_external_list_url : "lists/template_list.js",
		external_link_list_url : "lists/link_list.js",
		external_image_list_url : "lists/image_list.js",
		media_external_list_url : "lists/media_list.js",

fullpage_default_encoding : 'utf-8',
fullpage_default_langcode : 'ru',

		// Replace values for the template plugin
		template_replace_values : {
			username : "Some User",
			staffid : "991234"
		}
	});
}


initbigtext = function() {
    ted('BIGTEXT');
}

function refreshtree(treename) {
    ColdFusion.Tree.refresh(treename);
	 }

    function callback(text)
    {
        alert("Сообщение: " + text);
    }
    
    function errorHandler(code, msg)
    {
        alert("Ошибка!!! " + code + ": " + msg);
    }

   function ajaxFileUpload(tbl,fld,idrec)
   {
      $("#loading")
      .ajaxStart(function(){
         $(this).show();
      })
      .ajaxComplete(function(){
         $(this).hide();
      });

      $.ajaxFileUpload
      (
         {
            url:'/ajaxuploadfile.cfm?table='+tbl+'&FIELD='+fld+'&IDREC='+idrec,
            secureuri:false,
            fileElementId:fld,
            dataType: 'json',
            success: function (data, status)
            {
               if(typeof(data.error) != 'undefined')
               {
                  if(data.error != '')
                  {
                     alert(data.error);
                  }else
                  {
                     alert(data.msg);
                  }
               }
            },
            error: function (data, status, e)
            {
               alert(e);
            }
         }
      )
      
      return false;

   }

