﻿// JScript File
var SiteConfigs;  // ArrayList configs of website !Important
var inProcess = false;
//var BottomSectionTop =0;
//var previousTop = 0;
var BottomSection;
var FirstSection;
//var BottomPage = "";
//var FirstPage = "";
var FirstPageWidth = 0;
var CenteringLeft=0;
var userName="";
var AnchorName ="";
//var LoadingImageEnable = true;
var DivList = new Array();
var AutoScrollList = new Array();
//var BottomMarginTop=0;
var ListSectionRandom= []; // using for type Section Rotator
var isCenter = false; // default

function AddCommandToQueue(CommandToAdd)
{ 
    //alert("AddCommandToQueue function start");
    var ExecQueue;
    ExecQueue=GetExecQueue();
    if (Test==true)
    {
		alert("[AddCommandToQueue] ExecQueue Received' Content:\n" + XMLToText(ExecQueue));
		alert("[AddCommandToQueue] Appending a child to command queue:\n----\n" + XMLToText(CommandToAdd) + "----\n\n Command To Add' Child's length: [" + CommandToAdd.childNodes.length + "]");
	}
    var z;
    var Actions;
    Actions=CommandToAdd.getElementsByTagName('Action');
    //alert("Number of commands: " + Actions.length);
    var ActionsLength;
    ActionsLength=Actions.length;
    if (Test==true)
    {
		alert("[AddCommandToQueue] ActionCount: " + ActionsLength);
	}
	var z;
    for (z=0; z<ActionsLength; z++)
    {
        //alert("Enter For Loop z=" + z + "/" + Actions.length)
        if (Test==true)
		{
			alert("[AddCommandToQueue] APPENDING FUNCTION...\n\nCurrent Action Node Content:\n-----\n" + XMLToText(Actions[z]) + "\n----\n\n CommandContent:\n----\n" + XMLToText(CommandToAdd)+ "\n----\n\n EXECQUEUE:\n----\n" + XMLToText(ExecQueue) + "\n----");
		}
		
        //ExecQueue.documentElement.appendChild(CommandToAdd.childNodes[i]);
        if (Test==true) alert(XMLToText(ExecQueue));
        
        var browser = BrowserDetect.browser;
      
        switch (browser)
        {
            case 'Explorer': //IE doesn't reset index of XML Nodes during processing so can go z++
                ExecQueue.documentElement.appendChild(Actions[z]); break;
            case 'Firefox': //FF resets the index of XML Nodes during process so the next node is always 0
                ExecQueue.documentElement.appendChild(Actions[0]); break;
            case 'Safari':
            case 'Chrome':
                {
                    var clonedNode;                    
                    if (ExecQueue.importNode)
		                clonedNode  = ExecQueue.importNode(Actions[z],true);
	                else
		                clonedNode = Actions[z].cloneNode(true);
	                ExecQueue.documentElement.appendChild(clonedNode);
                    break;
                }
            default: ExecQueue.documentElement.appendChild(Actions[z]);  

        }
        
        /*
        if (BrowserDetect.browser == 'Explorer')
            ExecQueue.documentElement.appendChild(Actions[z]); //IE doesn't reset index of XML Nodes during processing so can go z++ 
        else
            ExecQueue.documentElement.appendChild(Actions[0]); //FF resets the index of XML Nodes during process so the next node is always 0
        */
        //alert("z at the end: " + z + "/" + Actions.leSngth);
        
    }
    if (Test==true)
	{
		alert("[AddCommandToQueue] AddCommandToQueue:\nDone appending child:\n----\n" + XMLToText(ExecQueue) + "----\n\n Will now update div...");
	}
    
    UpdateExecQueue(ExecQueue);
    
    if (Test==true)
	{	
		alert("[AddCommandToQueue] Done Updating ExecQueue");
	}
}

function AddSectionToSectionList(RefID, ParentRefID, SectionType)
{
    var SectionList;
    SectionList=GetSectionList();
    var Section;
    Section=LoadXMLString("<Section RefID='" + RefID + "' ParentRefID='" + ParentRefID + "' SectionType='" + SectionType + "'></Section>");
    var SectionsLength;
    
    var browser = BrowserDetect.browser;
 
    switch (browser)
    {
        case 'Explorer': //IE doesn't reset index of XML Nodes during processing so can go z++
            SectionList.documentElement.appendChild(Section.documentElement); break;
        case 'Firefox': //FF resets the index of XML Nodes during process so the next node is always 0
            SectionList.documentElement.appendChild(Section.documentElement); break;
        case 'Safari':
        case 'Chrome':
            {
                var clonedNode;                    
                if (SectionList.importNode)
	                clonedNode  = SectionList.importNode(Section.documentElement,true);
                else
	                clonedNode = Section.documentElement.cloneNode(true);
                SectionList.documentElement.appendChild(clonedNode);
                break;
            }
       default: SectionList.documentElement.appendChild(Section.documentElement);   
      
    }
    
    /*    
    if (BrowserDetect.browser == 'Explorer')
        SectionList.documentElement.appendChild(Section.documentElement); //IE doesn't reset index of XML Nodes during processing so can go z++
    else
        SectionList.documentElement.appendChild(Section.documentElement); //FF resets the index of XML Nodes during process so the next node is always 0
    */
    
    UpdateSectionList(SectionList);
    //alert(XMLToText(SectionList));
}

function GetExecQueue()
{
    //alert("GetExecQueue function start");
    var ExecQueue;
    var ExecQueueText;
    
    //ExecQueueText=document.getElementById("HiddenCommandQueue").innerText;
    
    var browser = BrowserDetect.browser;
    
  
     if (Test==true)alert(BrowserDetect.browser);
    switch (browser)
    {
        case 'Explorer': // code for IE
            ExecQueueText=document.getElementById("HiddenCommandQueue").innerText; break; 
        case 'Firefox': // code for Firefox
            ExecQueueText=document.getElementById("HiddenCommandQueue").innerText; break; 
        case 'Safari':  // code for Safari and Chrome
        case 'Chrome':
            {
            ExecQueueText=HTMLDecode(document.getElementById("HiddenCommandQueue").innerHTML); 
//            while(ExecQueueText.search("<br>")!=-1)
//            {
                //alert('found');
               
          ExecQueueText = ExecQueueText.replace(/<br>/g,"<div></div>");
//          
//           alert('123');
//            }
            break; 
            }
        default: 
        
        ExecQueueText=document.getElementById("HiddenCommandQueue").innerText;    

    }
    
    /*
    if (BrowserDetect.browser == 'Explorer') ExecQueueText=document.getElementById("HiddenCommandQueue").innerText; // code for IE
    if (BrowserDetect.browser == 'Firefox') ExecQueueText=document.getElementById("HiddenCommandQueue").innerText; // code for Firefox
    if (BrowserDetect.browser == 'Safari') ExecQueueText=document.getElementById("HiddenCommandQueue").innerHTML; // code for Safari
    */
    
    if (Test==true)alert(document.getElementById("HiddenCommandQueue").innerHTML);
    if (Test==true)alert("ExecQueue Content:\n----\n" + ExecQueueText);
    
    if (ExecQueueText=="" || ExecQueueText==null )
    {
        //alert("Queue is empty, adding root to it");
        ExecQueueText="<CommandQueue>\n</CommandQueue>";
        //alert("Queue contains the root now: \n" + ExecQueueText);
     }
     else
     {
        //alert("Queue already contains data:\n\n" + ExecQueueText);
     }
     //alert("Converting text to XML \n\n" + ExecQueueText);
     ExecQueue=LoadXMLString(ExecQueueText);
     //alert("CommandQueue at exit of function:\n----\n" + XMLToText(ExecQueue) + "----");
     //alert("returning ExecQueue...");
     return ExecQueue;
}

function GetSectionList()
{
     var SectionList;
     var SectionListText;
     //SectionListText=document.getElementById("HiddenPageSections").innerText;
     
     var browser = BrowserDetect.browser;

    switch (browser)
    {
        case 'Explorer': // code for IE
            SectionListText=document.getElementById("HiddenPageSections").innerText; break; 
        case 'Firefox': // code for Firefox
            SectionListText=document.getElementById("HiddenPageSections").innerText; break; 
        case 'Safari': // code for Safari and Chrome
        case 'Chrome':
            {
            SectionListText=HTMLDecode(document.getElementById("HiddenPageSections").innerHTML); 
//            while(SectionListText.search("<br>")!=-1)
//            {
            SectionListText = SectionListText.replace(/<br>/g,"");
//            }
            break; 
            }
        default: SectionListText=document.getElementById("HiddenPageSections").innerText;  

    }
    
     if (SectionListText=="" || SectionListText==null)
     {
        SectionListText="<Sections>\n</Sections>";
     }
     else
     {
        //alert("SectionList already contains data:\n\n" + SectionListText);
     }
    
     SectionList=LoadXMLString(SectionListText);
     return SectionList;
}
     
function UpdateExecQueue(ExecQueue)
{
    var XMLtxt;
    XMLtxt=XMLToText(ExecQueue);
    
    //Update the ExecQueue hidden div
    if(Test==true)
    {
		alert("[UpdateExecQueue] About to Update Div with XML CommandQueue:\n\n" + XMLtxt);
	}
	    
	    document.getElementById("HiddenCommandQueue").innerText=XMLtxt;
    if(Test==true)
    {
		alert("[UpdateExecQueue] Done updating Div with XML CommandQueue:\n\n" + document.getElementById("HiddenCommandQueue").innerText);
	}
}

function UpdateSectionList(SectionList)
{
    var XMLtxt;
    XMLtxt=XMLToText(SectionList);
    
    document.getElementById("HiddenPageSections").innerText=XMLtxt;
}

function ClearExecQueue()
{
    document.getElementById("HiddenCommandQueue").innerText="<CommandQueue>\n</CommandQueue>";
}

function ClearSections()
{
    var SectionList;
    SectionList=GetSectionList();
    var Sections;
    Sections=SectionList.getElementsByTagName('Section');
    //alert("Number of commands: " + Actions.length);
    var SectionsLength;
    SectionsLength=Sections.length
    //for (z=0; z<SectionsLength; z++)
    var z;
    for (z=SectionsLength-1; z>=0; z--)
    {
        
        //if (BrowserDetect.browser == 'Explorer') //IE doesn't reset counter of array right away.. does FF??
        //{
            RemoveSectionDiv(AttributeValue(Sections[z],"RefID"));
        //}
        //else
        //{
        //    RemoveSectionDiv(AttributeValue(Sections[0],"RefID"));
        //}
        
        SectionList.documentElement.removeChild(Sections[z]);
        
    }
    UpdateSectionList(SectionList);
}

function RemoveSectionByType(SectionTypeName)
{
    var SectionList;
    SectionList=GetSectionList();
    var Sections;
    Sections=SectionList.getElementsByTagName('Section')
    //alert("Number of commands: " + Actions.length);
    var SectionsLength;
    SectionsLength=Sections.length;
    /*
    for (z=0; z<SectionsLength; z++)
    {
        //alert(AttributeValue(Sections[z],"SectionType") + "=="+SectionTypeName+"?");
        if (AttributeValue(Sections[z],"SectionType")==SectionTypeName)
        {
            //alert("Yes");
            RemoveSectionDiv(AttributeValue(Sections[z],"RefID"));
            SectionList.documentElement.removeChild(Sections[z]);
            if (!BrowserDetect.browser == 'Explorer') //IE doesn't reset counter of array right away.. does FF??
            {
                z--;
            }
        }
    }
    */
    var z;
    for (z=SectionsLength-1; z>=0; z--)
    {
//        for (z=0; z<SectionsLength; z++)
//            {
        if (AttributeValue(Sections[z],"SectionType")==SectionTypeName)
        {
          
            //alert(Sections[z]);
            
            // remove by type
            RemoveSectionDiv(AttributeValue(Sections[z],"RefID"));
            SectionList.documentElement.removeChild(Sections[z]);

            // remove parent and child
//            RemoveSectionByRefID(AttributeValue(Sections[z],"RefID"),SectionList);
        }   
    }
    UpdateSectionList(SectionList);
}

function RemoveSectionByRefID(SectionRefID)
{
    var SectionList;
    SectionList=GetSectionList();
    var Sections;
    Sections=SectionList.getElementsByTagName('Section');
    //alert("Number of commands: " + Actions.length);
    var SectionsLength;
    SectionsLength=Sections.length;
    var z;
    
    for (z=Sections.length; z>=0; z--)
    {
        if (Sections[z]!=null)
        {
//            if (AttributeValue(Sections[z],"ParentRefID")==SectionRefID)
//            {
//               RemoveSectionByRefID(AttributeValue(Sections[z],"RefID"),SectionList);
//            }
//            else 
            if (AttributeValue(Sections[z],"RefID")==SectionRefID)
            {   try {
                RemoveSectionDiv(AttributeValue(Sections[z],"RefID"));
                SectionList.documentElement.removeChild(Sections[z]);
                }catch(ex){};
            }
        }
//        else
//        {alert("null "+SectionRefID);
//            if (!BrowserDetect.browser == 'Explorer') //If FireFox, must move forward as otherwise stays on first item
//            {
//                z++;
//            }
//        }
//        if (!BrowserDetect.browser == 'Explorer') //FireFox updates array when removing so z++ is actually z already...
//        {
//            z--;
//        }
    }
    UpdateSectionList(SectionList);
}

//function RemoveSectionByRefID(SectionRefID,SectionList)
//{
//    var Sections;
//    Sections=SectionList.getElementsByTagName('Section');
//    var SectionsLength;
//    SectionsLength=Sections.length;
//    var z;
//    for (z=Sections.length; z>=0; z--)
//    {
//        if (Sections[z]!=null)
//        {
//            if (AttributeValue(Sections[z],"ParentRefID")==SectionRefID)
//            {
//               RemoveSectionByRefID(AttributeValue(Sections[z],"RefID"),SectionList);
//            }
//            else 
//            if (AttributeValue(Sections[z],"RefID")==SectionRefID)
//            {   try {
//                RemoveSectionDiv(AttributeValue(Sections[z],"RefID"));
//                SectionList.documentElement.removeChild(Sections[z]);
//                }catch(ex){};
//            }
//        }
// 
//    }
//    UpdateSectionList(SectionList);
//}

function RemoveSectionDiv(SectionRefID)
{
    var DivToRemove;
    DivToRemove=document.getElementById(SectionRefID);
   
    if (Test==true)
    {
		alert("[RemoveSectionDiv] SectionRefID: " + SectionRefID);
    }
    if (DivToRemove!=null)
    {
		if (Test==true)
		{
			alert("[RemoveSectionDiv] Div to Remove:" + DivToRemove);
		}
		
		AnimationRemove(DivToRemove); // Run Animation Finish
		
		// Remove in RelateList
		for(var i=0; i < RelateList.length; i++)
          if (RelateList[i][0] == DivToRemove.id)
            RelateList.splice(i,1);
            
        for(var j=0; j < DivList.length; j++)
          if (DivList[j].name == DivToRemove.id)
            DivList.splice(j,1);
        
		DivToRemove.parentNode.removeChild(DivToRemove);
		//Clear AutoReload
		if (ListSectionRandom[SectionRefID]!=null){
		clearInterval(ListSectionRandom[SectionRefID]);
		}
	}
	else
	{
		if (Test==true)
		{
			alert("[RemoveSectionDiv] Could Not find Div to Remove... ");
		}
	}
}
var CommandQueueTemp,IndexAction;
var RelateList = new Array(); ;
function CommandExec(CommandQueue,indexAction)
{
//if (FirstLoad==null)
//FirstLoad = CommandQueue;
    inProcess = true;
//    var isQuery = false;
//	BottomSectionTop =0;
//	RelateList = new Array(); 

   // alert("Starting CommandExec with:\n\n" + XMLToText(CommandQueue));
    //Get First Action Node from the Command Queue
    xmlhttp=null;
    var ActionNodes;
   
    ActionNodes=CommandQueue.documentElement.getElementsByTagName('Action');
    var i;
    if(indexAction!=null) 
    i =indexAction;
    else i =0;

    if (false==true)
        {
			alert("Commands in Queue: " + ActionNodes.length + "\n---------------\nQueue:\n" + XMLToText(CommandQueue));
		}
		
    for (i; i<ActionNodes.length; i++)
    {   
        var ActionCount;
        ActionCount=i+1;
        var ActionNodeName;
        ActionNodeName=ActionNodes[i].nodeName;
        
        //alert("Action Node #"+ i + ": " + ActionNodeName );
        
        var StatusMsg ="";
        //Check Action Type
        var ActionType;
        var DivToUpdate;
        var DivName;
        var ParentDivName;
        var SectionType;
		var SpecialParams;
		divfocus=DivToUpdate;
		//Animation
		var XMLAnimation = ActionNodes[i].getElementsByTagName('Animation')[0];
		//Events
		var XMLEvents = ActionNodes[i].getElementsByTagName('Events')[0];
		//SendMail, PopUp
		var DragDrop;
        var ShadowBg;
        ActionType=AttributeValue(ActionNodes[i], "Type");

        SectionType=AttributeValue(ActionNodes[i], "SectionType");
        ClosePage =AttributeValue(ActionNodes[i], "ClosePage");
        DragDrop =AttributeValue(ActionNodes[i], "DragDrop");
        ShadowBg =AttributeValue(ActionNodes[i], "ShadowBg");
        //End SendMail, PopUp
        
        var BehaviorNode;
		BehaviorNode=GetXMLChild(ActionNodes[i],"Behavior");
//		if(AttributeValue(BehaviorNode, "FirstPage")!=null)
//        {
//	        FirstPage = AttributeValue(BehaviorNode, "FirstPage");
//        }
//        if(AttributeValue(BehaviorNode, "BottomPage")!=null)
//        {
//            BottomPage = AttributeValue(BehaviorNode, "BottomPage");
//        }

     
        //DisplayS
        
        /*
        StatusMsg=StatusMsg + "Proceeding with action number: " + (ActionCount+1) + "/" + ActionNodes.length + "  (" + DivName + "(" + ActionNodeName + ")" + ":" + ActionType + ")";
        StatusMsg=StatusMsg + " \n -----------------\n" + XMLToText(ActionNodes[i]);
        alert(StatusMsg);
        */
       if (SectionType==null)
        {
            SectionType="Undefined";
        }
        DivName=AttributeValue(ActionNodes[i], "RefID");
        if(true)
        //(DivName!=null)
        {
			ParentDivName=AttributeValue(ActionNodes[i], "ParentRefID");
			if (ParentDivName==null)
			{
				ParentDivName="_UnknownParent"
				//ParentDivName="";
			}
			SpecialParams=AttributeValue(ActionNodes[i], "SpecialParams");
			if (SpecialParams==null)
			{
				SpecialParams=""
			}
						
			DivToUpdate=document.getElementById(DivName);
			//alert("CommandType: " + AttributeValue(ActionNodes[i], "Type"));
	                
			if (Test==true)
			{
				alert(ActionType + "- RefID:" + DivName + " - ParenRefID:" + ParentDivName + " - SectionType:" + SectionType + ".");
			}
	        
			if (ActionType=="Update")
			{
				if(TestSpecific==true)
				{
					Test=true;
				}
				
				if (DivName==null)
	            continue;
	            
	            //Check if Div already exists
	            if (DivToUpdate!=null)
	            RemoveSectionByRefID(DivName);
	            
//				if (DivToUpdate==null)
//				{
					if (Test==true)
					{
						alert("[CommandExec] Div does not Exist, creating it");
					}
			    	//Create
					DivToUpdate=document.createElement("div", DivName);
					DivToUpdate.setAttribute("id",DivName);					
					document.getElementById('form1').appendChild(DivToUpdate);
					AddSectionToSectionList(DivName,ParentDivName,SectionType);
					//alert(DivToUpdate.id);
					
					if(DivName == SiteConfigs["BottomPage"]) BottomSection = DivToUpdate;
					if(DivName == SiteConfigs["FirstPage"]){
					    FirstSection = DivToUpdate;
					    if(AttributeValue(BehaviorNode, "Width") != null)
					        FirstPageWidth = parseInt(AttributeValue(BehaviorNode, "Width"));
					    else
					        FirstPageWidth = 800;
					       
					    // Get position Center    
//					    if(AttributeValue(BehaviorNode, "Centering") == "True") {
                        if( SiteConfigs["Centering"]) {
					    isCenter = true;
					    var WindowWidth = document.body.offsetWidth ;
					    //+parseInt(window.screenLeft) + parseInt(window.screenRight);
					    var SectionWidth = FirstPageWidth;
					    CenteringLeft =parseInt( WindowWidth > SectionWidth ? ((WindowWidth - SectionWidth)/2) : 0);
					    }
					}
								
					//if(DivName == FirstPage) FirstSection = DivToUpdate;
//	   			}
	            
				//Update content
	            
				if (document.getElementById(DivName)==null)
				{
					if (Test==true)
					{
						alert("[CommandExec] Although supposed to be created Div still does not Exist");
					}
				}
				else
				{
					if (Test==true)
					{
						alert("[CommandExec] Div to update has been located!");
					}
					
					//UPDATE DIV'S CONTENT
					var InnerHTMLNode; 
					InnerHTMLNode=GetXMLChild(ActionNodes[i],"InnerHTML");
		            
					DivToUpdate.innerHTML=GetCDataValue(InnerHTMLNode);
										
					if(Test==true)
					{
						alert("[CommandExec] Content of the updated div:\n" + DivToUpdate.innerHTML);
					}
		            DivToUpdate.style.display="none";
					//UPDATE DIV'S BEHAVIOR INFORMATION
					
					if (DivName != null && DivName != '') {
					    var DivInfo = new Object();
					    DivInfo.name = DivToUpdate.id;
					    DivInfo.top = (AttributeValue(BehaviorNode, "PositionTop"));
					    DivInfo.left = (AttributeValue(BehaviorNode, "PositionLeft"));
					    DivList.push(DivInfo);
					}
					    
					//Position Type
					if(Test==true)
					{
						alert("[CommandExec - Update] Position");
					}
					if(AttributeValue(BehaviorNode, "PositionType")=="Absolute")
					{
						DivToUpdate.style.position="absolute";
					}
					else
					{
						DivToUpdate.style.position="relative";
					}
					
					var maxduration=0;
					var AttributeLong;
					//Position Left
					var LeftFrom="",LeftFinish ="";
					if(Test==true)
					{
						alert("[CommandExec - Update] Left");
					}
					if(AttributeValue(BehaviorNode, "PositionLeft")!=null)
					{ 
//					if(AttributeValue(BehaviorNode, "Centering") == "True") {
//					    var WindowWidth = document.body.offsetWidth ;
//					    //+parseInt(window.screenLeft) + parseInt(window.screenRight);
//					    var SectionWidth = FirstPageWidth;
//					    CenteringLeft =parseInt( WindowWidth > SectionWidth ? ((WindowWidth - SectionWidth)/2) : 0);
//					    }
					    //alert('WindowWidth: ' + WindowWidth + '  SectionWidth: ' + SectionWidth + '  StartLeft: ' + CenteringLeft + '   ' + AttributeValue(BehaviorNode, "PositionLeft"));
				       // ---- Animation ----
				       try {
			                LeftFrom = XMLAnimation.getElementsByTagName("Left")[0].getAttribute("From");
			                LeftFinish =XMLAnimation.getElementsByTagName("Left")[0].getAttribute("Finish");
			                } catch(ex){}
			           var DurationLeft,DurationFinish;
			           try {
			                  DurationLeft=parseInt(XMLAnimation.getElementsByTagName("Left")[0].getAttribute("DurationFrom"));
			                  DurationFinish=parseInt(XMLAnimation.getElementsByTagName("Left")[0].getAttribute("DurationFinish"));
			                 }
			            catch (ex){DurationLeft=defaultDuration;}
			            
			            if (isNaN(DurationLeft))
			            DurationLeft=defaultDuration;
//			            alert(DurationLeft);
			            var left = parseInt(AttributeValue(BehaviorNode, "PositionLeft")) + CenteringLeft;
			            if (LeftFrom!=""&&LeftFrom!=null){
			            DivToUpdate.style.left = parseInt(LeftFrom)+CenteringLeft;
			       
			            if (DurationLeft>maxduration){
			            maxduration=DurationLeft;
			            AttributeLong="left";
			            }
			            //Run
//			            Animation(DivToUpdate,"left",left,DurationLeft,false);
			            }
			            else 
			            {			            
					        DivToUpdate.style.left = left;
						    DivToUpdate.style.posLeft = left;
						}
						if (LeftFinish!=""&&LeftFinish!=null){
			            DivToUpdate.setAttribute("leftfinish",parseInt(LeftFinish)+CenteringLeft);
			            DivToUpdate.setAttribute("leftdurationfinish",DurationFinish);}
					}
					
					//Position Top
					var TopFrom="",TopFinish="";	
					if(Test==true)
					{
						alert("[CommandExec - Update] Top");
					}
					if(AttributeValue(BehaviorNode, "PositionTop")!=null)
					{
					    try {
			                TopFrom = XMLAnimation.getElementsByTagName("Top")[0].getAttribute("From");
			                TopFinish =XMLAnimation.getElementsByTagName("Top")[0].getAttribute("Finish");
			                } catch(ex){}
			            var top = parseInt(AttributeValue(BehaviorNode, "PositionTop"));
			            
			            var DurationTop,DurationFinish;
			            try {
			            DurationTop=parseInt(XMLAnimation.getElementsByTagName("Top")[0].getAttribute("DurationFrom"));
			            DurationFinish=parseInt(XMLAnimation.getElementsByTagName("Top")[0].getAttribute("DurationFinish"));
			            } catch (ex){DurationTop=defaultDuration;}
			            if (DurationTop=="NaN")
			            DurationTop=defaultDuration;
			            if (TopFrom!=""&&TopFrom!=null){
			            DivToUpdate.style.top = TopFrom;
			            
			            if (DurationTop>maxduration){
			            maxduration=DurationTop;
			            AttributeLong="top";
			            }
//			            Animation(DivToUpdate,"top",top,DurationTop,false);
			             }
			            else {	
						DivToUpdate.style.top=top;
						DivToUpdate.style.posTop=top;
						}
						
				        if (TopFinish!=""&&TopFinish!=null){
			            DivToUpdate.setAttribute("topfinish",TopFinish);
			            DivToUpdate.setAttribute("topdurationfinish",DurationFinish);}
						//alert("SectionName: " + DivName + "; top: " + DivToUpdate.style.top + "; posTop: " + DivToUpdate.style.posTop + ";")
					}
                    DivToUpdate.style.display="";
                    
					//Background Color
					var BackColorFrom="",BackColorFinish="";
					if(Test==true)
					{
						alert("[CommandExec - Update] Background Color");
					}
					if(AttributeValue(BehaviorNode, "BackgroundColor")!=null&&AttributeValue(BehaviorNode, "BackgroundColor")!="")
					{
						//alert("BackgroundColor: " + AttributeValue(BehaviorNode, "BackgroundColor"));
						try {
			                BackColorFrom = XMLAnimation.getElementsByTagName("BackColor")[0].getAttribute("From");
			                BackColorFinish =XMLAnimation.getElementsByTagName("BackColor")[0].getAttribute("Finish");
			                } catch(ex){}
			            var BackColor = AttributeValue(BehaviorNode, "BackgroundColor");
			            var DurationBackColor,DurationFinish;
			            try {
			            DurationBackColor=parseInt(XMLAnimation.getElementsByTagName("BackColor")[0].getAttribute("DurationFrom"));
			            DurationFinish=parseInt(XMLAnimation.getElementsByTagName("BackColor")[0].getAttribute("DurationFinish"));
			            } catch (ex){}
			             if (DurationBackColor=="NaN")
			            DurationBackColor=defaultDuration;
			            if (BackColorFrom!=""&&BackColorFrom!=null){
			            DivToUpdate.style.backgroundColor = BackColorFrom;
			          
			            if (DurationBackColor>maxduration){
			            maxduration=DurationBackColor;
			            AttributeLong="backcolor";}
			            }else DivToUpdate.style.backgroundColor=BackColor;
			             if (BackColorFinish!=""&&BackColorFinish!=null){
			            DivToUpdate.setAttribute("backcolorfinish",BackColorFinish);
			            DivToUpdate.setAttribute("backcolordurationfinish",DurationFinish);}
					}
					else DivToUpdate.style.backgroundColor="";
					//BackgroundImage
					if(Test==true)
					{
						alert("[CommandExec - Update] BackgroundImage");
					}
					if(AttributeValue(BehaviorNode, "BackgroundImage")!="")
					DivToUpdate.style.backgroundImage="url("+AttributeValue(BehaviorNode, "BackgroundImage")+")";
					else DivToUpdate.style.backgroundImage=""; 
					
					//BackgroundRepeat
					if(Test==true)
					{
						alert("[CommandExec - Update] BackgroundRepeat");
					}
					if(AttributeValue(BehaviorNode, "BackgroundRepeat")!="")
					DivToUpdate.style.backgroundRepeat=AttributeValue(BehaviorNode, "BackgroundRepeat");
					else DivToUpdate.style.backgroundRepeat=""; 
						
					//BackgroundAttachment
					if(Test==true)
					{
						alert("[CommandExec - Update] BackgroundAttachment");
					}
					if(AttributeValue(BehaviorNode, "BackgroundAttachment")!="")
					DivToUpdate.style.backgroundAttachment=AttributeValue(BehaviorNode, "BackgroundAttachment");
					else DivToUpdate.style.backgroundAttachment=""; 
						
					//BackgroundPosition
					if(Test==true)
					{
						alert("[CommandExec - Update] BackgroundPosition");
					}
					if(AttributeValue(BehaviorNode, "BackgroundPosition")!="")
					DivToUpdate.style.backgroundPosition=AttributeValue(BehaviorNode, "BackgroundPosition");
					else DivToUpdate.style.backgroundPosition=""; 
							
					//ZIndex
					if(Test==true)
					{
						alert("[CommandExec - Update] Z-Index");
					}
					//alert("Out: DivName: " + DivName + " Z-Indexed: " + AttributeValue(BehaviorNode, "Z-Index"));
					if(AttributeValue(BehaviorNode, "Z-Index")!=null)
					{
						if(AttributeValue(BehaviorNode, "Z-Index")!=0)
						{
							//alert("In: DivName: " + DivName + " Z-Indexed: " + AttributeValue(BehaviorNode, "Z-Index"));
						}
						DivToUpdate.style.zIndex=AttributeValue(BehaviorNode, "Z-Index");
					}
					//Padding
					if(AttributeValue(BehaviorNode, "PaddingTop")!=null)
					{						
						DivToUpdate.style.paddingTop=AttributeValue(BehaviorNode, "PaddingTop")+"px";
					}
						if(AttributeValue(BehaviorNode, "PaddingBottom")!=null)
					{						
						DivToUpdate.style.paddingBottom=AttributeValue(BehaviorNode, "PaddingBottom")+"px";
					}
						if(AttributeValue(BehaviorNode, "PaddingLeft")!=null)
					{						
						DivToUpdate.style.paddingLeft=AttributeValue(BehaviorNode, "PaddingLeft")+"px";
					}
						if(AttributeValue(BehaviorNode, "PaddingRight")!=null)
					{						
						DivToUpdate.style.paddingRight=AttributeValue(BehaviorNode, "PaddingRight")+"px";
					}
					//overflow
					if(Test==true)
					{
						alert("[CommandExec] Overflow");
					}
					if(AttributeValue(BehaviorNode, "Overflow")!=null)
					{
						//alert("Overflow: " + AttributeValue(BehaviorNode, "Overflow"));
						DivToUpdate.style.overflow=AttributeValue(BehaviorNode, "Overflow");
						
						if(DivToUpdate.style.overflow == 'auto' || DivToUpdate.style.overflow == 'scroll'){
						    if(Test==true){
						        alert("[CommandExec] Custom Scrollbar");
						    }
						    DivToUpdate.style['scrollbar3dLightColor']=AttributeValue(BehaviorNode, "scrollbar3dLightColor");
						    DivToUpdate.style['scrollbarArrowColor']=AttributeValue(BehaviorNode, "scrollbarArrowColor");
						    DivToUpdate.style['scrollbarBaseColor']=AttributeValue(BehaviorNode, "scrollbarBaseColor");
						    DivToUpdate.style['scrollbarDarkShadowColor']=AttributeValue(BehaviorNode, "scrollbarDarkShadowColor");
						    DivToUpdate.style['scrollbarFaceColor']=AttributeValue(BehaviorNode, "scrollbarFaceColor");
						    DivToUpdate.style['scrollbarHighlightColor']=AttributeValue(BehaviorNode, "scrollbarHighlightColor");
						    DivToUpdate.style['scrollbarShadowColor']=AttributeValue(BehaviorNode, "scrollbarShadowColor");
						    DivToUpdate.style['scrollbarTrackColor']=AttributeValue(BehaviorNode, "scrollbarTrackColor");
						}
					}
					if(Test==true)
					{
						alert("[CommandExec] Overflow is " + DivToUpdate.style.overflow);
					}
					
				    //Width
				    DivOverflow = DivToUpdate.style.overflow;
					var	WidthFrom="",WidthFinish="";
					if(Test==true)
					{
						alert("[CommandExec - Update] Width");
					}
					if(AttributeValue(BehaviorNode, "Width")!=null)
					{
					try {
			                WidthFrom = XMLAnimation.getElementsByTagName("Width")[0].getAttribute("From");
			                WidthFinish =XMLAnimation.getElementsByTagName("Width")[0].getAttribute("Finish");
			            } catch(ex){}
			             var DurationWidth,DurationFinish;
			            try {
			            DurationWidth=parseInt(XMLAnimation.getElementsByTagName("Width")[0].getAttribute("DurationFrom"));
			            DurationFinish=parseInt(XMLAnimation.getElementsByTagName("Width")[0].getAttribute("DurationFinish"));
			            } catch (ex){DurationWidth=defaultDuration;}
			            
			            if (DurationWidth=="NaN")
			            DurationWidth=defaultDuration;
			            
			            var width = parseInt(AttributeValue(BehaviorNode, "Width"));
			            if (WidthFrom==""||WidthFrom==null)
			            DivToUpdate.style.width=width;
			            else{
			            DivToUpdate.style.width = WidthFrom;
			            
			            if (DurationWidth>maxduration){
			            maxduration=DurationWidth;
			            AttributeLong="width";
			            }
//			            Animation(DivToUpdate,"width",width,DurationWidth,false);
			            }
			            if (WidthFinish!=""&&WidthFinish!=null){
			             DivToUpdate.setAttribute("widthfinish",WidthFinish);
			             DivToUpdate.setAttribute("widthdurationfinish",DurationFinish);}
			            
					}
					
					//Height
				    var	HeightFrom="",HeightFinish="";
					if(Test==true)
					{
						alert("[CommandExec - Update] Height");
					}
					if(AttributeValue(BehaviorNode, "Height")!=null)
					{
				        try {
			                HeightFrom = XMLAnimation.getElementsByTagName("Height")[0].getAttribute("From");
			                HeightFinish =XMLAnimation.getElementsByTagName("Height")[0].getAttribute("Finish");
			            } catch(ex){}
			             var DurationHeight,DurationFinish;
			            try {
			            DurationHeight=parseInt(XMLAnimation.getElementsByTagName("Height")[0].getAttribute("DurationFrom"));
			            DurationFinish=parseInt(XMLAnimation.getElementsByTagName("Height")[0].getAttribute("DurationFinish"));
			            } catch (ex){DurationHeight=defaultDuration;}
			            
			            if (DurationHeight=="NaN")
			            DurationHeight=defaultDuration;
			            
			            var height = parseInt(AttributeValue(BehaviorNode, "Height"));
			            if (HeightFrom==""||HeightFrom==null)
			            DivToUpdate.style.height=height;
			            else{
			            DivToUpdate.style.height = HeightFrom;
			            
			            if (DurationHeight>maxduration){
			            maxduration=DurationHeight;
			            AttributeLong="height";
			            }
//			            Animation(DivToUpdate,"height",height,DurationHeight,false);
			             }
			             if (HeightFinish!=""&&HeightFinish!=null){
			             DivToUpdate.setAttribute("heightfinish",HeightFinish);
			             DivToUpdate.setAttribute("heightdurationfinish",DurationFinish);}
									
					}
					
					//Opacity
					if(Test==true)
					{
						alert("[CommandExec] Applying opacity");
					}
					if(AttributeValue(BehaviorNode, "Opacity")!=null)
					{
					var DivOpacity=AttributeValue(BehaviorNode, "Opacity");
					DivOpacity=DivOpacity.valueOf();
					var OpacityFrom ="",OpacityFinish="";
					try {
					OpacityFrom = XMLAnimation.getElementsByTagName("Opacity")[0].getAttribute("From");
					OpacityFinish =XMLAnimation.getElementsByTagName("Opacity")[0].getAttribute("Finish");
					} catch (ex){}
					var DurationOpacity,DurationFinish;
			        try {
			        DurationOpacity=parseInt(XMLAnimation.getElementsByTagName("Opacity")[0].getAttribute("DurationFrom"));
			        DurationFinish=parseInt(XMLAnimation.getElementsByTagName("Opacity")[0].getAttribute("DurationFinish"));
			        } catch (ex){DurationOpacity=defaultDuration;}
			        
			        if (DurationOpacity=="NaN")
			            DurationOpacity=defaultDuration;
			    
					if (OpacityFrom==""||OpacityFrom==null){
			            setOpacity(DivToUpdate,DivOpacity);
					}
					else {
					    setOpacity(DivToUpdate,OpacityFrom);
					    if (DurationOpacity>maxduration){
			            maxduration=DurationOpacity;
			            AttributeLong="opacity";
			            }
//			            Animation(DivToUpdate,"opacity",DivOpacity,DurationOpacity,false);
					}
			
					if (OpacityFinish!=""&&OpacityFinish!=null){
			            DivToUpdate.setAttribute("opacityfinish",OpacityFinish);
			            DivToUpdate.setAttribute("opacitydurationfinish",DurationFinish);
			            }
					}
					
					if(Test==true)
					{
						alert("[CommandExec] Done with opacity");
					}
					
					// ClassName
					
					if(AttributeValue(BehaviorNode, "ClassName")!=null)
					{
					    if (AttributeValue(BehaviorNode, "ClassName"))
					    DivToUpdate.className = AttributeValue(BehaviorNode, "ClassName");
					}
	
					
					// Save sections that relate to another section for later
					if(AttributeValue(BehaviorNode, "RelateTo")!= null && AttributeValue(BehaviorNode, "RelateTo")!= '')
					{
					    var relateItem = new Array();
					    relateItem.push(DivToUpdate.id);
					    relateItem.push(AttributeValue(BehaviorNode, "RelateTo"));
					    relateItem.push(AttributeValue(BehaviorNode, "PositionTop"));
					    relateItem.push(AttributeValue(BehaviorNode, "PositionLeft"));
					    RelateList.push(relateItem);
					    DivToUpdate.style.display = "none";
					}
					if(Test==true)
					{
						alert("[CommandExec] Add " + DivToUpdate.id + " to RelateList ");
					}
					
					if(TestSpecific==true)
					{
						alert("[var TestSpecific] turning Test off");
						Test=false;
						TestSpecific=false;
					}					
					
				}
				//End of if div was located for update        
				
				// Code for type page popup
				if(SectionType == 'PopUp'){
				 getScript("Javascripts/lytebox.js");
				 setPagePopup(DivToUpdate,ClosePage);
					  if (ShadowBg =='True')
				        showshadowbg();
				        }
			    if(DragDrop=='True'){
			    getScript("Javascripts/drapdrop.js");
			           setDragDrop(DivToUpdate); 		
			           }
			   
                // --- Exec Script ---
                ExecScript(AttributeValue(BehaviorNode, "PageType"),DivToUpdate);
                
	            // --- Hide Loading Image ---
                if (document.getElementById('imgLoadingImage') != null && ActionType=="Update")
                    document.getElementById('imgLoadingImage').style.visibility = 'hidden';
                 
                //---Separate Animation --- 
                var isSeparate=false;
                if (AttributeValue(BehaviorNode, "Separate")=="True"){
                if (maxduration>0){ 
                isSeparate=true;
                CommandQueueTemp = CommandQueue;
                IndexAction= i+1;
                }
                }
                // ---Int Events---
                InitEvents(DivToUpdate,XMLEvents);
                
                // ---Start Animation ---
                 if (LeftFrom!=""&&LeftFrom!=null)
                    if(isSeparate&&AttributeLong=="left"){    
                        Animation(DivToUpdate,"left",left,DurationLeft,false,true);}
                    else
                        Animation(DivToUpdate,"left",left,DurationLeft,false,false);
                        
                 if (TopFrom!=""&&TopFrom!=null)
                    if(isSeparate&&AttributeLong=="top"){    
                        Animation(DivToUpdate,"top",top,DurationTop,false,true);}
                    else
                        Animation(DivToUpdate,"top",top,DurationTop,false,false);
                        
                 if (WidthFrom!=""&&WidthFrom!=null)
                    if(isSeparate&&AttributeLong=="width"){    
                        Animation(DivToUpdate,"width",width,DurationWidth,false,true);}
                    else
                        Animation(DivToUpdate,"width",width,DurationWidth,false,false);     
                        
                 if (HeightFrom!=""&&HeightFrom!=null)
                    if(isSeparate&&AttributeLong=="height"){    
                        Animation(DivToUpdate,"height",height,DurationHeight,false,true);}
                    else
                        Animation(DivToUpdate,"height",height,DurationHeight,false,false);  
                        
                 if (OpacityFrom!=""&&OpacityFrom!=null)
                    if(isSeparate&&AttributeLong=="opacity"){    
                        Animation(DivToUpdate,"opacity",DivOpacity,DurationOpacity,false,true);}
                    else
                        Animation(DivToUpdate,"opacity",DivOpacity,DurationOpacity,false,false);
                        
                 if (BackColorFrom!=""&&BackColorFrom!=null)
                    if(isSeparate&&AttributeLong=="backcolor"){    
                        AnimationBackColorInit(DivToUpdate,BackColor,DurationBackColor,false,true);}
                    else
                        AnimationBackColorInit(DivToUpdate,BackColor,DurationBackColor,false,false);                            
               
                                                       
               if (isSeparate) return;
               
			}
			//End of Update
			else if (ActionType=="RemoveSection")
			{   
				RemoveSectionByRefID(DivToUpdate);
			}
			else if  (ActionType=="RemoveType")
			{   
				RemoveSectionByType(AttributeValue(ActionNodes[i],"SectionType"));
			}
			else if  (ActionType=="RemoveAll")
			{
				ClearSections();
			}
			else if (ActionType=="Query")
			{
				var TheURL;
	            isQuery = true;
				SpecialParams=SpecialParams.replace(/\*/g,"&");
	            
				//TheURL='ContentStreamer.aspx?PageName=' + AttributeValue(ActionNodes[i], "RefID") + "&ParentRefID=" + ParentDivName + SpecialParams ; //+ "&LangID=" + document.getElementById('txtLangID').value
				TheURL='Default.aspx?PageName=' + AttributeValue(ActionNodes[i], "RefID") + "&ParentRefID=" + ParentDivName + SpecialParams ; 
				if(Test==true)
				{
					alert("URL Queried: " + TheURL);
				}
				 //SHOW LOADING IMAGE
                 var imgLoadingImage = document.getElementById('imgLoadingImage');
                 if (imgLoadingImage != null ) {
                 if (/^img$/i.test(imgLoadingImage.tagName)) {
                 //imgLoadingImage.style.top = 0 + (document.body.offsetHeight - imgLoadingImage.height) /2;
                 //imgLoadingImage.style.left = 0 + (document.body.offsetWidth - imgLoadingImage.width) /2;
                 //reDo();
                 imgLoadingImage.style.visibility = 'visible';
                        }
                    }
				GetXMLFromServer(TheURL);
				return;
			}
			else if (ActionType=="NewWindow")
			{
			    
				var NewWindow;
				NewWindow=window.open(DivName,"_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, resizable=yes, copyhistory=no, width=574, height=500");
			    if (document.getElementById('imgLoadingImage') != null )
                    document.getElementById('imgLoadingImage').style.visibility = 'hidden';
			}
			else
			{
				alert("[" + DivName + "] called for an unknown action: " + ActionType);
			}
                
        }
        else
        {
			//DIVNAME WAS NULL
        }
    }
    
    setTimeout("RelateListExec();SetPosBottom();",200);

//    reDo();

    //  Reposition some sections that relate to another sections
    
    //alert("Finished Executions...");
    inProcess = false;

 
};

/***** Set Position Bottom Section ******/
function SetPosBottom(){
//alert("Start bottom position");
if (BottomSection==null)
return;
var curSection,newTop;
var maxTop =0;

//reset height of first page
FirstSection.style.height="1px";
BottomSection.style.top = "0px";

/*
var BottomTop;
BottomTop = 
alert("Body Height: " + BottomTop);
BottomSection.style.top = BottomTop;
*/  


var RelateBottom =";";
var relateItem;
for(var i=0; i < RelateList.length; i++){
    relateItem = RelateList[i];  
    if (relateItem[1] ==BottomSection.id)
         RelateBottom+=relateItem[0]+";";   
}

for(var i=0; i<DivList.length; i++) {
   curSection = document.getElementById(DivList[i].name);
       if ( curSection != null) 
       if (curSection.id!= BottomSection.id){
            if (RelateBottom.indexOf(";"+curSection.id+";")==-1){
               var elementID;
               elementID = curSection.id
               
               var Olivier;
               Olivier= document.getElementById(curSection.id);
               //alert("Section: " + curSection.id + "\nTop : " + curSection.style.top + "\nOlivier offsetHeight: " + Olivier.offsetHeight + "\nStyleHeight: " + curSection.style.height + "\nScrollHeight: " + document.getElementById(curSection.id).scrollHeight);
               newTop = parseInt(curSection.style.top) + document.getElementById(curSection.id).scrollHeight;
               
               //newTop = parseInt(curSection.style.top)+curSection.offsetHeight;
               if (newTop>maxTop) maxTop=newTop;
            }
		}
  }
  BottomSection.style.top = SiteConfigs["BottomMarginTop"]+ maxTop+"px";
  
 
  //alert('Bottom Top: ' + BottomSection.style.top);
  //alert('FirstSection: ' + FirstSection.style.height);
  
  var PageHeight;
  var BottomHeight;

  PageHeight = Number(BottomSection.style.top.replace(/px/,""));
  //alert('PageHeight: ' + PageHeight + "px");

  BottomHeight = Number(BottomSection.style.height.replace(/px/,""));
  //alert('BottomHeight: ' + BottomHeight + "px");

  OverAllPageHeight = PageHeight + BottomHeight;
  //alert('OverAllPageHeight: ' + OverAllPageHeight + "px");

  FirstSection.style.height = OverAllPageHeight + "px";
  
}
/***** RelateList *****/
function RelateListExec(){
    for(var i=0; i < RelateList.length; i++)
    {
        var relateItem = RelateList[i];        
        if ( document.getElementById(relateItem[0]) != null && document.getElementById(relateItem[1]) != null)
        {
        var relateTop = parseInt(relateItem[2]) + parseInt(document.getElementById(relateItem[1]).style.top);
        var relateLeft = parseInt(relateItem[3]) + parseInt(document.getElementById(relateItem[1]).style.left);
        //alert(relateItem);
        //alert('relateTop: ' + relateTop + '    relateLeft: ' + relateLeft);
        document.getElementById(relateItem[0]).style.top = relateTop;
        document.getElementById(relateItem[0]).style.left = relateLeft;
        document.getElementById(relateItem[0]).style.display = "";
        }
    }
}

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 ;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    } 
  }
return "Guest";
};

//ReCentering
window.onresize = reDo;
function reDo(nothing) {
    var imgLoadingImage = document.getElementById('imgLoadingImage');
    if (imgLoadingImage != null) {
    imgLoadingImage.style.top = 0 + (document.body.offsetHeight - imgLoadingImage.height) /2;
    imgLoadingImage.style.left = 0 + (document.body.offsetWidth - imgLoadingImage.width) /2;
    }
    if(isCenter) {
	    isCenter = true;
	    var WindowWidth = document.body.offsetWidth ;
	    var SectionWidth = FirstPageWidth;
	    CenteringLeft =parseInt( WindowWidth > SectionWidth ? ((WindowWidth - SectionWidth)/2) : 0);
	}
    for(var i=0; i<DivList.length; i++) {
        DivToChange = document.getElementById(DivList[i].name);
        if ( DivToChange != null) {
            var WindowWidth = document.body.offsetWidth;
			var SectionWidth = FirstPageWidth;
//		    var CenteringLeft = WindowWidth > SectionWidth ? ((WindowWidth - SectionWidth)/2) : 0;
		    var left = parseInt(DivList[i].left) + CenteringLeft;
		        DivToChange.style.left = left;
			    DivToChange.style.posLeft = left;
        }
    }
    RelateListExec();
};

/***** Load Script *****/
var ScriptsLoaded = new Array();
function getScript(url){
if (ScriptsLoaded.toString().indexOf(url)!=-1)
    return;
ScriptsLoaded.push(url);
var http_request;
if (window.XMLHttpRequest) 
http_request = new XMLHttpRequest();
else if (window.ActiveXObject)
http_request = new ActiveXObject("Microsoft.XMLHTTP");

//http_request.onreadystatechange = function() {
//       if (http_request.readyState == 4) {
//           if (http_request.status == 200) {
//               globalEval(http_request.responseText);
//           } else {
//               alert('There was a problem with the request.(Code: ' + http_request.status + ')');
//           }
//       }
//   } 
http_request.open('GET', url, false);
http_request.send(null); 
 if (http_request.readyState == 4) {
           if (http_request.status == 200) {
               globalEval(http_request.responseText);
           } else {
               alert('There was a problem with the request.(Code: ' + http_request.status + ')');
           }
       }
}

function globalEval(data){
var head = document.getElementsByTagName("head")[0] || document.documentElement,
    script = document.createElement("script");
script.type = "text/javascript";
if (BrowserDetect.browser=="Explorer" )
    script.text = data;
else
    script.appendChild( document.createTextNode( data ) );
head.appendChild( script );
//head.removeChild( script );
}

function ExecScript(type,DivToUpdate){
switch (type){
case "Inventory" :
case "ImagesGallery" :  getScript("Javascripts/lytebox.js");
                        try{
                        if (myLytebox==null)
                        myLytebox = new  LyteBox();
                        myLytebox.updateLyteboxItems();
                        window.parent.myLytebox.updateLyteboxItems();
                        }
                        catch (ex){}; 
                        break;  
case "VotesContent" : getScript("Javascripts/Votes.js");
                      RunColumnVotes(DivToUpdate);break;
case "AutoScroll" : getScript("Javascripts/marquee/marquee.js");     
                    var marquee = DivToUpdate.getElementsByTagName('marquee')[0];
	                if(marquee)
	                    marquee.start();
	                else initteAutoScroll(DivToUpdate.id);
	                break;
case "SendMail" : getScript("Javascripts/SendMail.js");	                                                           
                  getScript("Javascripts/validation.js");break;	
case "PasswordRecovery" : getScript("Javascripts/ResetPassword.js");               
case "Register" : getScript("Javascripts/Register.js");
                  getScript("Javascripts/validation.js");  
                  getScript("Javascripts/md5.js");
                  break;
                     	                                                                           
case "Login" : getScript("Javascripts/md5.js");break;
case "NewsLetter" : getScript("Javascripts/validation.js");break;
case "ImagesRotator" :
case "SectionsRotator" : getScript("Javascripts/RandomSection.js");
                         
                         if (ref(DivToUpdate.id+'AutoReload').value == "True"){
                         
                         var Timeout = parseInt(ref(DivToUpdate.id+'Timeout').value);                          
                         ExecRandom(DivToUpdate.id,Timeout*1000);
                         }  
                         break;	                                                                           
}
}

function resizeIframe(ifr){
    ifr.parentNode.style.height = ifr.contentWindow.document.body.scrollHeight + 1 + 'px';
    setTimeout("SetPosBottom();RelateListExec();",100);
}

// ---Event---
function InitEvents(div,XMLEvents){
try{
var ListEvent =  XMLEvents.getElementsByTagName("Event");
var i=0;
var flag;
for (i; i<ListEvent.length; i++){
flag = false;
if (ListEvent[i].getAttribute("DisplaySection")!=""){
div.setAttribute("Display"+ListEvent[i].getAttribute("Name"),ListEvent[i].getAttribute("DisplaySection"));
flag=true;
}
if (ListEvent[i].getAttribute("RemoveSection")!=""){
div.setAttribute("Remove"+ListEvent[i].getAttribute("Name"),ListEvent[i].getAttribute("RemoveSection"));
flag=true;
}
if (flag)
addEvent(div,ListEvent[i].getAttribute("Name"),ExecEvent); 

}
}
catch(ex){}
}

function ExecEvent(e){
if (!e) 
var e = window.event;
var div;
if (document.all) div = e.srcElement; 
else  div = e.target;

var DisName = div.getAttribute("Display"+e.type);
var RemoveName = div.getAttribute("Remove"+e.type);
if (DisName!=null&DisName!=""){
RequestToServer("Default.aspx?PageName=" + DisName );
}
if (RemoveName!=null&RemoveName!=""){
RemoveSectionByRefID(RemoveName);
}

}
