function InitTinyMCE(type)
{
    tinymce.create('tinymce.plugins.ExamplePlugin', {
	createControl: function(n, cm) {
            switch (n) {
                case 'mymenubutton':
                    var c = cm.createMenuButton('mymenubutton', {
                        title : 'Insert Virtual Tour',
                        image : 'img/example.gif',
                        icons : false
                    });

                    c.onRenderMenu.add(function(c, m) {
                        var sub;

                        m.add({title : 'Insert table & Virtual Tour', onclick : function() {
                            var url = prompt("Virtual Tour URL", "http://www.toom.rs/");
                            if (url != null)
                            {
                                var content = '<table style="width: 100%; height: 400px;" border="0"><tr><td>';
                                content += '<iframe src="'+url+'" width="100%" height="400px"></iframe>';
                                content += '<br style="clear: both;" /></td></tr></table><p></p>';
                                tinyMCE.activeEditor.execCommand('mceInsertContent', false, content);
                            }
                        }});                        
                    });

                    // Return the new menu button instance
                    return c;
            }

            return null;
        }
        });


    tinymce.PluginManager.add('example', tinymce.plugins.ExamplePlugin);
    
	if (type == 'simple')
	{
		tinyMCE.init({
			// General options,
			mode : "textareas",
			theme : "simple",
            force_br_newlines : true,
            force_p_newlines : false
		});
	}else if (type == 'advanced')
	{
		tinyMCE.init({
			// General options
			mode : "textareas",
			theme : "advanced",
			plugins : "-example, phpimage, safari, pagebreak,style,layer,table,save,advhr,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,iframe",

			// Theme options
			theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontsizeselect,|,styleprops,cite,abbr,acronym,del,ins,attribs",
			theme_advanced_buttons2 : "cut,copy,paste,|,undo,redo,|,link,unlink,phpimage,cleanup",
			theme_advanced_buttons3 : "tablecontrols,|,hr,|,fullscreen,|,template,|,iframe, mymenubutton",
			theme_advanced_buttons4 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			theme_advanced_resizing : false,

			// Example content CSS (should be your site CSS)
			content_css : "short.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",
            extended_valid_elements : "iframe[src|width|height|name|align]"
		});
	}else if (type == 'news')
	{
		tinyMCE.init({
			// General options
			mode : "textareas",
			theme : "advanced",
			plugins : "phpimage, safari, pagebreak,style,layer,table,save,advhr,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount",

			// Theme options
			theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontsizeselect,|,styleprops,cite,abbr,acronym,del,ins,attribs",
			theme_advanced_buttons2 : "cut,copy,paste,|,undo,redo,|,link,unlink,phpimage,cleanup,|,tablecontrols,|,hr,|,fullscreen,|,template",
			theme_advanced_buttons3 : "",
			theme_advanced_buttons4 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			theme_advanced_resizing : false,

			// Example content CSS (should be your site CSS)
			content_css : "short.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"
		});
	}
	else
	{
		tinyMCE.init({
			// General options
			mode : "textareas",
			theme : "advanced",
			plugins : "phpimage, safari, pagebreak,style,layer,table,save,advhr,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount",

			// Theme options
			theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,fontsizeselect,|,styleprops,cite,abbr,acronym,del,ins,attribs",
			theme_advanced_buttons2 : "cut,copy,paste,|,undo,redo,|,link,unlink,phpimage,cleanup,|,tablecontrols,|,hr,|,fullscreen,|,template",
			theme_advanced_buttons3 : "",
			theme_advanced_buttons4 : "",
			theme_advanced_toolbar_location : "top",
			theme_advanced_toolbar_align : "left",
			theme_advanced_statusbar_location : "bottom",
			theme_advanced_resizing : false,

			// Example content CSS (should be your site CSS)
			content_css : "short.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"
		});
	}
}

function printPage(URL)
{
    window.open(URL, "PrintLayout", "");
}

function LoadPrice(roomid, datum1, datum2, brojdece, brojodraslih, indeks)
{
    url = "calcPrice.php?roomid="+roomid+"&rezervisiod="+datum1+"&rezervisido="+datum2+"&brojdece="+brojdece+"&brojodraslih="+brojodraslih+"&i="+indeks;
    //window.location.replace(url);
    $('#price'+indeks).load(url);
}

function LoadAvailabilityCalendar(month, year, accid)
{
    var url = "ajax/availabilityCalendar.php?month="+month+"&year="+year+"&accid="+accid;
    $('#availabilityCalendar').load(url);
}

function GetSelectedValue(divId)
{
    var value = document.getElementById(divId).value;
    return value;
}

function LogIn(korisnicko_ime, sifra)
{
    $.get('ajax/login.php?korisnickoime='+korisnicko_ime+'&sifra='+sifra, function(data) {
          if (data.toString().indexOf("LogInAccepted") != -1)
              {
                  $('#LogInBox').slideUp("slow");
                  document.getElementById('loginbutton').disabled = false;
                  document.getElementById('loginbutton').type = 'submit';
                  document.getElementById('korisnik').value = data.toString().substring(data.toString().indexOf("LogInAccepted:")+14, data.toString().indexOf(";"));
              }else
              {
                    document.getElementById('LogInMsg').innerHTML = data;
                    $('#LogInMsg').show();
              }
        });
}

function CheckAll(checkId,allCheckedId)
{
    var i;
    i = 1;
    if (document.getElementById(allCheckedId).checked)
    {
        while (document.getElementById(checkId+i) != null)
        {
            document.getElementById(checkId+i).checked = true;
            i++;
        }
    }else
    {
        while (document.getElementById(checkId+i) != null)
        {
            document.getElementById(checkId+i).checked = false;
            i++;
        }
    }
}

function CheckIfAll(checkId, allCheckedId, current)
{
    var i, allc;
    i = 1;
    allc = true;
    if (!document.getElementById(current).checked)
        allc = false;
    else
    {
        while (document.getElementById(checkId+i) != null)
        {
            if (current != checkId+i)
            {
                if (!document.getElementById(checkId+i).checked)
                    allc = false;
            }
            i++;
        }
    }
    if (allc)
    {
       if (document.getElementById(allCheckedId) != null)
            document.getElementById(allCheckedId).checked = true;
    }else
        {
           if (document.getElementById(allCheckedId)!= null)
                document.getElementById(allCheckedId).checked = false;
        }
}


function ActivePreview(divId)
{
    document.getElementById(divId).style.backgroundImage = "url('images/menu-active.png')";
    document.getElementById(divId).style.backgroundRepeat = "repeat-x";
    document.getElementById(divId).style.backgroundPosition = "top left";
    document.getElementById(divId).style.color = "#077ee3";
    document.getElementById(divId).style.textShadow = "2px 2px 5px #FFFFFF";
}

function NormalPreview(divId)
{
    document.getElementById(divId).style.backgroundImage = "";
    document.getElementById(divId).style.backgroundRepeat = "repeat-x";
    document.getElementById(divId).style.backgroundPosition = "top left";
    document.getElementById(divId).style.color = "#FFFFFF";
    document.getElementById(divId).style.textShadow = "2px 2px 5px #000000";
}
