﻿// JScript File
function CreateSemina(url)
{
    if(navigator.appName == "Microsoft Internet Explorer")
    {
	    var xhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	else
	{
        var xhttp = new XMLHttpRequest();
    }
	xhttp.open("GET", url, false);
	
	xhttp.onreadystatechange = 
	function() 
	{
		if (xhttp.readyState == 4 && xhttp.responseText) 
		{
			validateResponse(xhttp);			
			var sSplit = xhttp.responseText.split('$'); 
            var sXML = sSplit[0];
            
            if(sXML!="")
            {
               var xmlDoc = loadXMLData(sXML);
               var root = new Ext.tree.TreeNode({           
                    id: '0',           
                    text : 'Nextw@ver.com',
                    iconCls:'iapps',
                    expanded:true
               });               
                
                var XMLElement=xmlDoc.getElementsByTagName('Items')[0];
                if(XMLElement!=null)
                {        
                    for(var i = 0; i<XMLElement.childNodes.length; i++)
                    { 
                        var xx = XMLElement.childNodes[i];  
                        var Name = xx.attributes.getNamedItem("Name").nodeValue; 
                        var Month = xx.attributes.getNamedItem("Month").nodeValue;
                        var Year = xx.attributes.getNamedItem("Year").nodeValue;
                        var ID = Month+'_'+Year;
                      
                        var P1 =  new Ext.tree.TreeNode({           
                                id: ID,      
                                text : Name,
                                iconCls:'idocuments'
                        });     
                        P1.on('click', function(node,e){
                            addSemina('สัมมนา '+node.text,'idocuments',node.id);
                        }); 
           
                        root.appendChild(P1);    
                    }
                }               
                treeSemina.setRootNode(root);
                
            }          
		}		
	}	
	xhttp.send(null); 
   
}

function addSemina(tabName,tabIcon, SeminaID)
{
    var tabInformation =  Ext.getCmp('tabinfomation');
    
    var iindex = tabInformation.items.length;
    var bbool = true;
    for(var i=1; i<iindex; i++)
    {
        //var itabName = tabInformation.items.items[i].title;
        if(tabInformation.items.items[i].title==tabName){ 
                bbool = false; 
                tabInformation.items.items[i].show();
                //tabInformation.items.items[0].autoShow = true;
                break;
        }
    }
    var src = "../semina/semina.aspx?Semina="+SeminaID;
    if(bbool){
        tabInformation.add({
            title: tabName,
            iconCls: tabIcon,            
            autoScroll:true,       
            html: '<iframe src="'+src+'" width="100%" height="100%" frameborder="0"></iframe>',
            closable:true
            }).show();
    }
}

