var core = 
{
		active: 	null,
		menu	: 	null,
		typ		: 	null,
		ida		: 	null,
		verif : 	null,
		editor: 	null,
		editor2: 	null,
		AdminLoginTimer: null,
		AdminLoginTime: null,
		actuality: null,
		
		pathCheck : function ()
		{
//         alert(window.location);
//         alert(window.location.hash);
        
        if (window.location.hash != "#/" && window.location.hash != "")
				{
            
            var tmp_location = window.location.hash.replace("#/","");
            
            var tmp_path = "";
            if (tmp_location.indexOf('-') != -1 )
            {
                tmp_path  = tmp_location.split("/");
                tmp_path[0] = tmp_path[1].replace('/','');
                tmp_path[1] = tmp_path[2].replace('/','');
                if (tmp_path[0]=="fotoreporty"){tmp_path[0]="foto_detail";}
                main_content(tmp_path[0],'',tmp_path[1],'ini');
            }
            else if (tmp_location.indexOf('_') != -1 )
            {
                tmp_path  = tmp_location.split("/");
                tmp_path[0] = tmp_path[0].replace('/','');
                tmp_path[1] = tmp_path[1].replace('/','');
                if (tmp_path[0]=="fotoreporty"){tmp_path[0]="foto_detail";}
                main_content(tmp_path[0],'',tmp_path[1],'ini');
            }
            else
            {
                tmp_path = tmp_location.replace('/','');
                tmp_path = tmp_path.replace('/','');
                main_content(tmp_path,'','','ini');
            }
        }
        else if (window.location.pathname != "/")
				{
            alert(window.location.pathname);
            var tmp_path = "";
            if (window.location.pathname.indexOf('-') != -1 )
            {
                tmp_path  = window.location.pathname.split("/");
                tmp_path[1] = tmp_path[1].replace('/','');
                tmp_path[2] = tmp_path[2].replace('/','');
                if (tmp_path[1]=="fotoreporty"){tmp_path[1]="foto_detail";}
                main_content(tmp_path[1],'',tmp_path[2],'ini');
            }
            else if (window.location.pathname.indexOf('_') != -1 )
            {
                tmp_path  = window.location.pathname.split("/");
                tmp_path[1] = tmp_path[1].replace('/','');
                tmp_path[2] = tmp_path[2].replace('/','');
                if (tmp_path[1]=="fotoreporty"){tmp_path[1]="foto_detail";}
                main_content(tmp_path[1],'',tmp_path[2],'ini');
            }
            else
            {
                tmp_path = window.location.pathname.replace('/','');
                tmp_path = tmp_path.replace('/','');
                main_content(tmp_path,'','','ini');
            }
        }
        else
        {
            main_content(core.menu,core.typ,core.ida,'ini');
        }
        core.init();
        PlayerIniState(true);
    },
		
    init 	: function ()
		{
// 				clearTimeout(timeout2);
        try
        {mailer.init();}
        catch(e)
        {}
				var index = document.getElementById("inpIndex");
				var temp  = index.innerHTML.split(";");
				
				core.menu 	= temp[0];
				core.typ 	= temp[1];
				core.ida 	= temp[2];
				core.verif = temp[3];
// 				alert(core.menu);
				
				if (!core.active)
				{
						core.active= true;
            
				}
				(core.menu=="administrace" && core.verif == "low" ? loader_admin() : loader_off());
				
        var a = document.getElementsByTagName('a');
        for (var i=0; i<a.length; i++)
        {
        		if (a[i].id.substr(0,1) == "_" || a[i].id.substr(0,4).toLowerCase() == "inp_")
						  {a[i].onclick = core.href;}
						else if (a[i].id.substr(0,6) == "admin_" || a[i].id.substr(0,6) == "erase-" || a[i].id.substr(0,6) == "dyna::")
						  {a[i].onclick = core.admin_href;}                                            
        }
        
        var but = document.getElementsByTagName('input');
        for (var i=0; i<but.length; i++)
        {
        		if(but[i].type=="button")
        		{
								if (but[i].id.substr(0,1) == "_" || but[i].id.substr(0,4).toLowerCase() == "inp_")
								{but[i].onclick = core.href;}
								else if (but[i].id.substr(0,6) == "admin_" || but[i].id.substr(0,6) == "erase-" || but[i].id.substr(0,6) == "forms-" || but[i].id.substr(0,7) == "forms::")
								{but[i].onclick = core.admin_href;}                                            
						}						
        }
        
        var d = document.getElementsByTagName('div');
				for (var j=0; j<d.length; j++)
        {
        		if (d[j].className == "MesicCont" || d[j].className == "PartCont")
        		{d[j-1].onclick = core.displayFix;}                          
        }
				        
        var s = document.getElementsByTagName('span');
        for (var i=0; i<s.length; i++)
        {
        		if (s[i].id.substr(0,4) == "img-")
						{s[i].onclick = core.galery_detail;}    
        }
        
        var AExit = document.getElementById('FloaterAdminExit');
        if (AExit)
        {
						AExit.onclick = core.adminexit;
				}
				
				if (document.getElementById('AdminLoginCounter'))
				{
						var now = new Date();
						var timeThen = now.getTime();
						timeThen = timeThen + 60000*15;
					  core.AdminLoginTime = parseInt(timeThen);
						core.AdminLoginCounter();
            if (!TextRunActive)
            {
                TextRun       = document.getElementById('TextRun');
                if (TextRun)
                {
                    TextRunObsah  = TextRun.innerHTML;
                    _TextRun();
                }
            }
        }
		},
		
		adminexit : function()
		{
				this.parentNode.parentNode.style.display = "none";
				ObjectsDisplay("true");
        //document.getElementById("Banner").style.display = "block";
				
		},
		
		AdminLoginCounter : function()
		{
				var x	=	document.getElementById('AdminLoginCounter');
        var kdy;
        var pri;
        kdy = 'April 25, 2009 21:00:00';
        pri = false;
        var now = new Date();
        var timeThen = core.AdminLoginTime;
        var timeNow = now.getTime();
        
				timeLeft = core.AdminLoginTime - timeNow; 
        
        mins = parseInt(timeLeft / 60000);
        timeLeft = parseInt(timeLeft % 60000);
        secs = parseInt(timeLeft / 1000);
        
        m1 = parseInt(mins / 10);
        if ( m1=="NaN") m1 = 0;
        
        m2 = parseInt(mins % 10);
        if ( m2=="NaN") m2 = 0;
        
        s1 = parseInt(secs / 10);
        if ( s1=="NaN") s1 = 0;
        
        s2 = parseInt(secs % 10);
        if ( s2=="NaN") s2 = 0;
        
        if (!pri)
        {
            if  ((core.AdminLoginTime - timeNow) <= 0) 
            {
                x.innerHTML = "Byli jste odhlášeni!";
                window.location = "./admin/manage.php?do=admin_logoff";
            } 
            else 
                {
										x.innerHTML = "<b>" + (m1=="0"? '' : m1 ) + m2 + ":" + (s1=="0"? '0' : s1 ) + s2 + "</b>";
                    core.checkActual();
										AdminLoginTimer = setTimeout("core.AdminLoginCounter();", 60000*10);
                }
        }
        else 
            {x.innerHTML = days + " Dnů " + (h1=="0"? '' : h1 ) + h2 + ":" + m1 + m2 + ":" + s1 + s2;}
    },
    
    checkActual : function ()
    {
				if (core.actuality==null)
				{        	
						core.actuality = true;
						Actualxml=GetAdminXmlHttpObject();
    
				    if (Actualxml == null)
				    {
				       alert ("Váš prohližeč nepodporuje HTTP Request!");
				       return;
				    }
				    var url = "./admin/actual.php";
				    var params = "do=check";
				    Actualxml.onreadystatechange = core.actualChecked;
				    Actualxml.open("POST",url,true);
				    Actualxml.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
						Actualxml.setRequestHeader("Content-length", params.length);
						Actualxml.setRequestHeader("Connection", "close");
				    Actualxml.send(params);				 		
				}
		},
		
		actualChecked : function ()
		{
				if (Actualxml.readyState==4 || Actualxml.readyState=="complete")
				{
	      		var now = new Date();
						var timeThen = now.getTime();
						timeThen = timeThen + 60000*15;
    				core.AdminLoginTime = parseInt(timeThen);
						Actualxml = null;
						core.actuality = null;
				}
		},
		
		displayFix : function ()
		{
				var n = this;
				do n = n.nextSibling;
				while (n && n.nodeType != 1);
				                                                                          
				if(n.style.display=="block")
						{
                n.style.display="none";
                this.style.paddingTop ="0px";
                this.style.fontWeight ="normal";
            }
				else
						{
                n.style.display="block";
                this.style.paddingTop ="10px";
                this.style.fontWeight ="bold";
            }
				
		}, 
		
		forms : function ()
		{
        try
				{
            core.editor 	= core.removeEditor(core.editor);
            core.editor2 = core.removeEditor(core.editor2);            
				}
				catch(e)
				{
//             alert (e);
        }
				try
				{
						core.editor 	= core.createEditor(core.editor,'1');
            core.editor2 = core.createEditor(core.editor2,'2');            
				}
				catch(e)
				{
//             alert (e);
        }  

        try
        {
        		x = document.getElementById('cal_datum_trigger');
            if(x)
            {
								Calendar.setup({
                inputField     :    'cal_datum',
                ifFormat       :    '%e.%N.%Y %H:%M:00',
                button         :    'cal_datum_trigger',
                align          :    'Bl',
                singleClick    :    true, 
                firstDay       :    1,
                showsTime			 : 		true
                });
						}
        }
        catch(e)
				{
// 						alert(e);
        }

				try
        {
        		x = document.getElementById('cal_datumdo_trigger');
        		if(x)
        		{
								Calendar.setup({
                inputField     :    'cal_datumdo',
                ifFormat       :    '%e.%N.%Y %H:%M:00',
                button         :    'cal_datumdo_trigger',
                align          :    'Bl',
                singleClick    :    true, 
                firstDay       :    1,
                showsTime			 : 		true
                });
						}
        }
        catch(e)
				{
        }  
				
				x = document.getElementById('datum1_trigger');
        		if(x)
        		{
								Calendar.setup({
                inputField     :    'datum1',
                ifFormat       :    '%e.%N.%Y %H:%M:00',
                button         :    'datum1_trigger',
                align          :    'Bl',
                singleClick    :    true, 
                firstDay       :    1,
                showsTime			 : 		true
                });
						}
				x = document.getElementById('datum2_trigger');
        		if(x)
        		{
								Calendar.setup({
                inputField     :    'datum2',
                ifFormat       :    '%e.%N.%Y %H:%M:00',
                button         :    'datum2_trigger',
                align          :    'Bl',
                singleClick    :    true, 
                firstDay       :    1,
                showsTime			 : 		true
                });
						}
				x = document.getElementById('datum3_trigger');
        		if(x)
        		{
								Calendar.setup({
                inputField     :    'datum3',
                ifFormat       :    '%e.%N.%Y %H:%M:00',
                button         :    'datum3_trigger',
                align          :    'Bl',
                singleClick    :    true, 
                firstDay       :    1,
                showsTime			 : 		true
                });
						}
				x = document.getElementById('datum4_trigger');
        		if(x)
        		{
								Calendar.setup({
                inputField     :    'datum4',
                ifFormat       :    '%e.%N.%Y %H:%M:00',
                button         :    'datum4_trigger',
                align          :    'Bl',
                singleClick    :    true, 
                firstDay       :    1,
                showsTime			 : 		true
                });
						}
				
        var f = document.getElementsByTagName('form');
        for (var i=0; i<f.length; i++)
        {
//         		alert (f[i].id);
// 						alert ("ok");
						if (f[i].id.substr(0,6) == "admin_")
						{
// 								alert ("ok");
                f[i].onsubmit = core.admin_form;
						}    
						else if (f[i].id.substr(0,4).toLowerCase() == "inp_")
						{
								f[i].onsubmit = core.formSubmit;
						}
						else if (f[i].id.substr(0,6).toLowerCase() == "forms-")
						{
								f[i].onsubmit = core.floatForms;
// 								alert ("ok end");
						}
        }
        
        var chb = document.getElementsByTagName('input');
        for (var i=0; i<chb.length; i++)
        {
        		if (chb[i].type == "checkbox")
        		{
								if (chb[i].id.substr(0,1) == "_")
								{
										chb[i].onclick = core.CheckAll;
								}
						}    
        }
        
        try
        {
            $(function(){$('form.jNice').jNice();	});
        }
        catch (e)
        {}
    },
    
    createEditor : function (ckedit,no)
    {
				ckedit = CKEDITOR.appendTo( 'editor' + no );
        var TA_admin = document.getElementById( 'TA' + no + '_admin' ).innerHTML;
				
				if ( ckedit.setData )
						ckedit.setData( TA_admin );
				else
						CKEDITOR.on( 'loaded', function()
							{
								ckedit.setData( TA_admin );
							});

				document.getElementById( 'TA' + no + '_admin' ).style.display = "none";
				return ckedit;
		},
		
		removeEditor : function (ckedit)
		{
		    if ( !ckedit )
				return;
				
				ckedit.destroy();
				ckedit = null;
				return null;
		},
    
    floatForms : function ()
    {
				if(this.id=="admin_hitparada")
				{
            return AIM.submit(this, ''); //premisteno do iframu..
				}
				else if (this.id=="admin_import")
				{
            return AIM_import.submit(this, ''); //premisteno do iframu..        
        }
				else
				{
						if (this.id.indexOf("#") != -1)
						{
								var anchor = this.id.split("#");
								admin_submit(anchor[0],anchor[1],anchor[2]);
						}
						else
						{
								admin_submit(this.id,'');				
						}
				}
        var done = document.getElementById('done');
        if (done)
        {
            done.parentNode.removeChild(done);
            done = null;
        }
        if (!done)
        {
            var divDone = document.createElement('div');
            divDone.setAttribute('id','done');
            divDone.setAttribute('class',this.id);
            this.appendChild(divDone);
        }
        var d = document.getElementById("done");
        d.style.display     = "block";
        d.style.color       = "#FFFFFF";
        d.style.fontSize    = "12px";
        d.style.fontWeight  = "bold";
        d.style.paddingLeft = "2px";
        d.style.backgroundColor 
                            = "#00AA00";
        d.style.textAlign = "center";
        d.style.className = this.id;
        var check = "";
        if(this.id.indexOf("verify")==-1)
				{check = checkfloat(this);}else{check="OK";}
        
        if (check=="OK")
				{
						if (this.id.indexOf("-") != -1)
						{
								var anchor = this.id.split("-");
								form_submit(anchor[0],anchor[1],anchor[2]);
						}
						else
						{
								form_submit(this.id,'');
                alert(this.id);				
						}
						this.reset();
				}				
				else
				{
            d.style.backgroundColor = "#A00";
            document.getElementById("done").innerHTML = check;
        }
		},
				
    formSubmit : function ()
    {
				var done = document.getElementById('done');
        if (done)
        {
            done.parentNode.removeChild(done);
            done = null;
        }
        if (!done)
        {
            var divDone = document.createElement('div');
            
            divDone.setAttribute('id','done');
            divDone.setAttribute('class',this.id);
            this.appendChild(divDone);
        }
        var d = document.getElementById("done");
        d.style.display     = "block";
        d.style.color       = "#FFFFFF";
        d.style.fontSize    = "12px";
        d.style.fontWeight  = "bold";
        d.style.paddingLeft = "2px";
        d.style.backgroundColor 
                            = "#00AA00";
        d.style.textAlign = "center";
        d.style.className = this.id;
        var check = "";
        if(this.id.indexOf("verify")==-1)
				{check = checkinfo(this);}else{check="OK";}
        
        if (check=="OK")
				{
						if (this.id.indexOf("-") != -1)
						{
								var anchor = this.id.split("-");
								form_submit(anchor[0],anchor[1],anchor[2]);
						}
						else
						{
								form_submit(this.id,'');				
						}
						this.reset();
				}				
				else
				{
            d.style.backgroundColor = "#A00";
            document.getElementById("done").innerHTML = check;
        }
		},
    
    CheckAll : function ()
    {
				var ActForm = this.form.id;
				var chb = document.getElementsByTagName('input');
        for (var i=0; i<chb.length; i++)
        {
        		if (chb[i].type == "checkbox")
        		{
								if (chb[i].form.id == ActForm)
								{
										if (chb[i].value == this.id.substr(1,this.id.length) && chb[i].name != "operative")
										{
												chb[i].checked = this.checked;
										}
								}
						}    
        }
		},
		CheckAllInfo : function ()
    {
				var chbs = document.getElementsByTagName('input');
        for (var i=0; i<chbs.length; i++)
        {
        		if (chbs[i].type == "checkbox")
        		{
								if (chbs[i].className == "multiSelect")
								{
										chbs[i].checked = this.checked;
								}
						}    
        }
		},
		
		href 	: function ()
		{ 
				this.id = this.id.replace("inp_","_");
				this.id = this.id.replace("InP_","_");
        if (this.id.indexOf("#") != -1)
				{
						var anchor = this.id.substr(1,this.id.length -1).split("#");
						main_content(anchor[0],anchor[1],anchor[2]);
				}
				else if (this.id.indexOf("-") != -1)
				{
						var anchor = this.id.substr(1,this.id.length -1).split("-");
						main_content(anchor[0],anchor[1],anchor[2]);
				}
				else if (this.id.indexOf("dyna::") != -1)
				{
						var args = new Array();
						args = this.id.split("::");
						formType = args[1];
						args["spec"]="yes";
						dynaAppend(formType,args);
						main_content(formType + "_con",args[2],args[3]);
// 						alert ("menu:" + core.menu + "\r\n typ:" + core.typ + "\r\n ida:" + core.ida );
				}
				else
				{
						main_content(this.id.substr(1,this.id.length -1),'');				
				}				
		},
		
		galery_detail : function ()
		{
				var image = this.id.substr(1,this.id.length -1).split("-");
				galery_detail("http://"+window.location.hostname+"/core/picture.php",image[1],image[2]);
		},
		
		admin_href 	: function ()
		{ 
				if (this.id.indexOf("forms-") != -1)
				{
						var formType = this.id.split("-");
						formType = formType[1];
						forms.showForm(formType);
				}
				else if (this.id.indexOf("forms::") != -1)
				{						
						var args = new Array();var no;
						args = this.id.split("::");
						var formType = args[1];
						if (formType.indexOf(":")  != -1)
						{
								var a = formType.split(":");
								formType = a[0];
								no = a[1];
						}
						forms.showForm(formType,args,no);
				}
				else if (this.id.indexOf("dyna::") != -1)
				{
						var args = new Array();
						args = this.id.split("::");
						formType = args[1];
						dynaAppend(formType,args);
				}
				else if (this.id.indexOf("erase-") != -1)
				{
						var eraseItem = this.id.split("-");
						erase(eraseItem[1], eraseItem[2],'');
				}
				else if (this.id.indexOf("#") != -1)
				{
						var anchor = this.id.split("#");
						admin_content(anchor[0],anchor[1],anchor[2]);
				}
				else if (this.id.indexOf("-") != -1)
				{
						var anchor = this.id.split("-");
						
						if (anchor.length == 3)
								{admin_content(anchor[0],anchor[1],anchor[2]);}
						else if (anchor.length == 4)
								{admin_content(anchor[0],anchor[1],anchor[2],anchor[3]);}
						else if (anchor.length == 5)
								{admin_content(anchor[0],anchor[1],anchor[2],'','','',anchor[3],anchor[4]);}
						else if (anchor.length == 6)
								{admin_content(anchor[0],anchor[1],anchor[2],anchor[5],'','',anchor[3],anchor[4]);}
				}
				else
				{
						admin_content(this.id.replace("_bar",""),'');				
				}
		},
		
		admin_form 	: function ()
		{
				if(this.id=="admin_hitparada")
				{
            return AIM.submit(this, ''); //premisteno do iframu..
				}
				else if (this.id=="admin_import")
				{
            return AIM_import.submit(this, ''); //premisteno do iframu..        
        }
				else
				{
						if (this.id.indexOf("#") != -1)
						{
								var anchor = this.id.split("#");
								admin_submit(anchor[0],anchor[1],anchor[2]);
						}
						else if (this.id.indexOf("-") != -1)
						{
								var anchor = this.id.split("-");
								admin_submit(anchor[0],anchor[1],anchor[2]);
						}
						else
						{
								admin_submit(this.id,'');				
						}
				}
		}
		
}
// var timeout2 = setTimeout("core.init()", 1100);
window.onload = core.pathCheck;


// jmeno, telefon, email, www str8nky, co se poptava, datum pl8novan0 akce a poznamka... 
