
var gProfile = null;
var gUrlForLoad = 'http://www.greniusvirtualcity.nl/VirtualCity/Pages/DataSendPage.aspx';
//var gUrlForLoad = 'http://203.197.124.164/VirtualCity/Pages/DataSendPage.aspx';
var gFuncForLoad = processXmlResponseForLoad;
var gUrlForChange = 'http://www.greniusvirtualcity.nl/VirtualCity/Pages/DataReceivePage.aspx';
//var gUrlForChange = 'http://203.197.124.164/VirtualCity/Pages/DataReceivePage.aspx';
var gFuncForChange = processXmlResponseForChange;
var gCurrentDocument = this;
var gFramesetName = 'FrameAjax.htm';

function Profile(lang, style, msid, mhid, maid, defButton)
{
	this.DefaultButton = defButton;
    this.Language = lang;
    this.Stylesheet = style;
    try {
        this.MaxSearchId = Math.floor(msid);
    }
    catch (e) {
        this.MaxSearchId = 0;
    }
    try {
        this.MaxHouseTypeId = Math.floor(mhid);
    }
    catch (e) {
        this.MaxHouseTypeId = 0;
    }
    try {
        this.MaxActionId = Math.floor(maid);
    }
    catch (e) {
        this.MaxActionId = 0;
    }
    
    this.PointsOfInterest = new Array();
    this.Searches = new Array();
    this.HouseTypes = new Array();
    this.Action3Ds = new Array();
    this.Tabs = new Array();
    this.Buttons = new Array();
    this.Frame = new Frame(20, 50, 20, 50, 10, "Information", "None", "Buttons", "Search", "Point of Interest", "red", "green", "blue", "yellow", "red");
    this.DefMap = new Array();
    //this.Frame = new Frame(0, 0, 0, 0, 0, "", "", "", "", "", "", "", "", "", "");  
    this.GenerateXML = GenerateProfileXML;
    this.AddNewSearch = AddNewSearchToProfile;
    this.DeleteSearch = DeleteSearchFromProfile;
}

function AddNewSearchToProfile(keyword, fixed, type, text)
{
    //alert("keyword: "+ keyword +", fixed: "+ fixed +", type: "+ type +", text: "+ text);
    this.MaxSearchId++;
    this.Searches[this.Searches.length] = new Search(this.MaxSearchId, keyword, fixed, type, text);
}

function DeleteSearchFromProfile(id)
{
    var b = false;
    var i, j;
    if (id > 0 && id <= this.MaxSearchId) {
        for (i = 0; i < this.Buttons.length; i++) {
            var sids = this.Buttons[i].SearchIdList.split(",");
            for (j = 0; j < sids.length; j++) {
                if (Math.floor(sids[j]) == Math.floor(id)) { // Foreign Key Violation
                    b = false;
                    return b;
                }
            }
        }
        // Now, there can be no foreign key violation
        for (i = 0; i < this.Searches.length; i++) {
            if (Math.floor(this.Searches[i].Id) == Math.floor(id)) { // found
                for (j = i; j < this.Searches.length - 1; j++) {
                    this.Searches[j] = this.Searches[j + 1];
                }
                delete this.Searches[this.Searches.length - 1];
                this.Searches.length--;
                b = true;
                break;
            }
        }
    }
    return b;
}

function GenerateProfileXML()
{
    var s = "";
    var i;
    s += "<Profile language=\"" + this.Language + "\" style=\"" + this.Stylesheet + "\" maxsid=\"" + 
        this.MaxSearchId +  "\" maxhid=\"" + this.MaxHouseTypeId +  "\" maxaid=\"" + this.MaxActionId + "\">";
        this.MaxActionId + "\" DefaultButton=\"" + this.DefaultButton + "\">";    
    s += "<POIs>";
    for (i = 0; i < this.PointsOfInterest.length; i++) {
        s += this.PointsOfInterest[i].GenerateXML();
    }
    s += "</POIs>";
    
    s += "<SEARCHES>";
    for (i = 0; i < this.Searches.length; i++) {
        s += this.Searches[i].GenerateXML();
    }
    s += "</SEARCHES>";

    s += "<HOUSETYPEs>";
    for (i = 0; i < this.HouseTypes.length; i++) {
        s += this.HouseTypes[i].GenerateXML();
    }
    s += "</HOUSETYPEs>";

    s += "<ACTION_3Ds>";
    for (i = 0; i < this.Action3Ds.length; i++) {
        s += this.Action3Ds[i].GenerateXML();
    }
    s += "</ACTION_3Ds>";

    s += "<TABs>";
    for (i = 0; i < this.Tabs.length; i++) {
        s += this.Tabs[i].GenerateXML();
    }
    s += "</TABs>";

    s += "<BUTTONs>";
    for (i = 0; i < this.Buttons.length; i++) {
        s += this.Buttons[i].GenerateXML();
    }
    s += "</BUTTONs>";
    
    s += "<FRAMEs>";
    if (this.Frame != null) {
        s += "<LEFT width=\"" + this.Frame.LeftPanelWidth + "\">";
        s += "<TOP height=\"" + this.Frame.LeftTopPanelHeight + "\" mapped_function=\"" + this.Frame.Functionality[0] + "\" stylesheet=\""+this.Frame.LeftPanelStylesheet+"\"/>";
        s += "<BOTTOM mapped_function=\"" + this.Frame.Functionality[1] + "\" stylesheet=\""+this.Frame.LeftTopPanelStylesheet+"\"/>";
        s += "</LEFT>";
        s += "<MIDDLE height=\"" + this.Frame.MiddleTopPanelHeight + "\" mapped_function=\"" + this.Frame.Functionality[2] + "\" stylesheet=\""+this.Frame.MiddleTopPanelStylesheet+"\"/>";
        s += "<RIGHT width=\"" + this.Frame.RightPanelWidth + "\">";
        s += "<TOP height=\"" + this.Frame.RightTopPanelHeight + "\" mapped_function=\"" + this.Frame.Functionality[3] + "\" stylesheet=\""+this.Frame.RightPanelStylesheet+"\"/>";
        s += "<BOTTOM mapped_function=\"" + this.Frame.Functionality[4] + "\" stylesheet=\""+this.Frame.RightTopPanelStylesheet +"\"/>";
        s += "</RIGHT>";
    }
    s += "</FRAMEs>";

    s += "<DEFMAP>";
    for (i = 0; i < this.DefMap.length; i++) {
        s += this.DefMap[i].GenerateXML();
    }
    s += "</DEFMAP>";

    s += "</Profile>";
    
    return s;
}

function POI(keyword, display)
{
    this.Keyword = keyword;
    this.Display = display;

    this.GenerateXML = GeneratePointofInterestXML;
}

function GeneratePointofInterestXML()
{
    var s = "";
    s += "<POI>";
    s += "<KEYWORD>" + this.Keyword + "</KEYWORD>";
    s += "<DISPLAY>" + this.Display + "</DISPLAY>";
    s += "</POI>";
    return s;    
}

function Search(id, keyword, fixed, type, text)
{
	//alert("id: "+ id +", keyword: "+ keyword +", fixed: "+ fixed +", type: "+ type +", text: "+ text);
    this.Id = id;
    this.Keyword = keyword;
    this.FixedString = fixed;
    this.Type = type;
    this.Text = text;

    this.GenerateXML = GenerateSearchXML;
    this.RenderItem = RenderOneSearchItemForDisplay;
    this.RenderFinal = RenderLookAndFeel;
}

function GenerateSearchXML()
{
    var s = "";
    s += "<SEARCH id=\"" + this.Id + "\">";
    s += "<TYPE>" + this.Type + "</TYPE>";
    s += "<KEYWORD>" + this.Keyword + "</KEYWORD>";
    s += "<FIXED>" + this.FixedString + "</FIXED>";
    s += "<PARAM>" + this.Text + "</PARAM>";
    s += "</SEARCH>";
    return s;
}


function HouseType(id, keyword, display)
{
    this.Id = id;
    this.Keyword = keyword;
    this.Display = display;

    this.GenerateXML = GenerateHouseTypeXML;
}

function GenerateHouseTypeXML()
{
    var s = "";
    s += "<HOUSETYPE id=\"" + this.Id + "\">";
    s += "<KEYWORD>" + this.Keyword + "</KEYWORD>";
    s += "<DISPLAY>" + this.Display + "</DISPLAY>";
    s += "</HOUSETYPE>";
    return s;
}


function Action3D(id, display)
{
    this.Id = id;
    this.Display = display;

    this.GenerateXML = GenerateAction3DXML;
}

function GenerateAction3DXML()
{
    var s = "";
    s += "<ACTION_3D id=\"" + this.Id + "\">";
    s += "<DISPLAY>" + this.Display + "</DISPLAY>";
    s += "</ACTION_3D>";
    return s;
}

function Tab(keyword, display, aids)
{
    this.Keyword = keyword;
    this.Display = display;
    this.Action3DIdList = aids;

    this.GenerateXML = GenerateTabXML;
}

function GenerateTabXML()
{
    var s = "";
    s += "<TAB>";
    s += "<KEYWORD>" + this.Keyword + "</KEYWORD>";
    s += "<DISPLAY>" + this.Display + "</DISPLAY>";
    s += "<ACTION_IDs>" + this.Action3DIdList + "</ACTION_IDs>";
    s += "</TAB>";
    return s;
}

function Button(display, color, hids, sids, info, title, alertmsg)
{
    this.Display = display;
    this.Color = color;
    this.HouseTypeIdList = hids;
    this.SearchIdList = sids;
    this.Information = info;
	this.Title = title;
	this.AlertMsg = alertmsg;
		
    this.GenerateXML = GenerateButtonXML;
}

function GenerateButtonXML()
{
    var s = "";
    s += "<BUTTON>";
    s += "<DISPLAY>" + this.Display + "</DISPLAY>";
    s += "<COLOR>" + this.Color + "</COLOR>";
    s += "<INFO>" + this.Information + "</INFO>";
    s += "<HOUSE_IDs>" + this.HouseTypeIdList + "</HOUSE_IDs>";
    s += "<SEARCH_IDs>" + this.SearchIdList + "</SEARCH_IDs>";
    s += "<TITLE>" + this.Title + "</TITLE>";
    s += "<ALERTMESSAGE>" + this.AlertMsg + "</ALERTMESSAGE>";    
    s += "</BUTTON>";
    return s;
}

function Frame(v1, v2, v3, v4, v5, map1, map2, map3, map4, map5, css1, css2, css3, css4, css5)
{
    this.LeftPanelWidth = v1;
    this.LeftTopPanelHeight = v2;
    this.RightPanelWidth = v3;
    this.RightTopPanelHeight = v4;
    this.MiddleTopPanelHeight = v5;

    this.Functionality = new Array();
    this.Functionality[this.Functionality.length] = map1;    
    this.Functionality[this.Functionality.length] = map2;    
    this.Functionality[this.Functionality.length] = map3;    
    this.Functionality[this.Functionality.length] = map4;    
    this.Functionality[this.Functionality.length] = map5;    
    
    this.LeftPanelStylesheet = css1;
    this.LeftTopPanelStylesheet = css2;
    this.RightPanelStylesheet = css3;
    this.RightTopPanelStylesheet = css4;
    this.MiddleTopPanelStylesheet = css5;
}

//////For Defalut Map************** /////////////Suman
function DefaultMap(lat, lng, zoom, mapType, overlay)
{
    this.Lat = lat;
    this.Lng = lng;
    this.Zoom = zoom;
    this.MapType = mapType;
    this.Overlay = overlay;
    this.GenerateXML = GenerateDefMapXML;
}
////////for Default Map////////////Suman
function GenerateDefMapXML()
{
    var s = "";
    s += "<LAT>" + this.Lat + "</LAT>";
    s += "<LNG>" + this.Lng + "</LNG>";
    s += "<ZOOM>" + this.Zoom + "</ZOOM>";
    s += "<MAPTYPE>" + this.MapType + "</MAPTYPE>";
    s += "<OL>" + this.Overlay + "</OL>";    
    return s;
}

function DoOnLoad()
{
    var s = "";
    var w = gProfile.GenerateXML();
    var t = w.split("<");
    for (var i = 1; i < t.length; i++) s += "<BR>&lt;" + t[i];
 //   alert(s);
    document.getElementById("MyDiv").innerHTML = s;
}




function HandlePOIs(element) 
{
     var keyword = "UNKNOWN";
    var display = "UNKNOWN";
   
    for (var i = 0; i < element.childNodes.length; i++) {
        var search = element.childNodes[i];
               
        for (var j = 0; j < search.childNodes.length; j++) {
          //  var e = search.childNodes[j];
            var e = search.childNodes[j];
            var t = "";
            try{
				t = e.childNodes[0].nodeValue;
            }catch(err){
            }
            if (false);
            else if (e.nodeName == "KEYWORD") {
                keyword = t;
            }
            else if (e.nodeName == "DISPLAY") {
                display = t;
            }            
        }
        // Create a new housetype object here
        gProfile.PointsOfInterest[gProfile.PointsOfInterest.length] = new POI(keyword, display);
    }
}
function HandleSearches(element) 
{
    var id = "UNKNOWN";
    var type = "UNKNOWN";
    var keyword = "UNKNOWN";
    var fixed = "UNKNOWN";
    var param = "UNKNOWN";
    for (var i = 0; i < element.childNodes.length; i++) {
        var search = element.childNodes[i];
        var j;
        for (j = 0; j < search.attributes.length; j++) {
            if (search.attributes[j].name == "id") {
                id = search.attributes[j].value;
                break;
            }
        }
        for (var j = 0; j < search.childNodes.length; j++) {
            var e = search.childNodes[j];
            var t = "";
            try{
				t = e.childNodes[0].nodeValue;
            }catch(err){
            }
            if (false);
            else if (e.nodeName == "TYPE") {
                type = t;
            }
            else if (e.nodeName == "KEYWORD") {
                keyword = t;
            }
            else if (e.nodeName == "FIXED") {
                fixed = t;
            }
            else if (e.nodeName == "PARAM") {
                param = t;
            }
        }
        // Create a new search object here
        gProfile.Searches[gProfile.Searches.length] = new Search(id, keyword, fixed, type, param);
        // done
    }
}
function HandleHouseTypes(element) 
{
    var id = "UNKNOWN";
    var keyword = "UNKNOWN";
    var display = "UNKNOWN";
    for (var i = 0; i < element.childNodes.length; i++) {
        var search = element.childNodes[i];
        var j;
        for (j = 0; j < search.attributes.length; j++) {
            if (search.attributes[j].name == "id") {
                id = search.attributes[j].value;
                break;
            }
        }
        for (var j = 0; j < search.childNodes.length; j++) {
            var e = search.childNodes[j];
            var t = "";
            try{
				t = e.childNodes[0].nodeValue;
            }catch(err){
            }
            if (false);
            else if (e.nodeName == "KEYWORD") {
                keyword = t;
            }
            else if (e.nodeName == "DISPLAY") {
                display = t;
            }
        }
        // Create a new housetype object here
        gProfile.HouseTypes[gProfile.HouseTypes.length] = new HouseType(id, keyword, display);
    }
}
function HandleActions(element) 
{
    var id = "UNKNOWN";
    var display = "UNKNOWN";
    for (var i = 0; i < element.childNodes.length; i++) {
        var search = element.childNodes[i];
        var j;
        for (j = 0; j < search.attributes.length; j++) {
            if (search.attributes[j].name == "id") {
                id = search.attributes[j].value;
                break;
            }
        }
        for (var j = 0; j < search.childNodes.length; j++) {
            var e = search.childNodes[j];
            var t = "";
            try{
				t = e.childNodes[0].nodeValue;
            }catch(err){
            }
            if (false);
            else if (e.nodeName == "DISPLAY") {
                display = t;
            }
        }
        // Create a new action object here
        gProfile.Action3Ds[gProfile.Action3Ds.length] = new Action3D(id, display);
    }
}

function HandleTabs(element) 
{
    var actionids = "UNKNOWN";
    var keyword = "UNKNOWN";
    var display = "UNKNOWN";
    for (var i = 0; i < element.childNodes.length; i++) {
        var search = element.childNodes[i];
        var j;
        for (var j = 0; j < search.childNodes.length; j++) {
            var e = search.childNodes[j];
            var t = "";
            try{
				t = e.childNodes[0].nodeValue;
            }catch(err){
            }
            if (false);
            else if (e.nodeName == "KEYWORD") {
                keyword = t;
            }
            else if (e.nodeName == "DISPLAY") {
                display = t;
            }
            else if (e.nodeName == "ACTION_IDs") {
                actionids = t;
            }
        }
        // Create a new tab object here
        gProfile.Tabs[gProfile.Tabs.length] = new Tab(keyword, display, actionids);
    }
}

function HandleButtons(element) 
{
    var searchids = "UNKNOWN";
    var houseids = "UNKNOWN";
    var color = "UNKNOWN";
    var info = "UNKNOWN";
    var display = "UNKNOWN";
    var title = "UNKNOWN";
    var alertmsg = "UNKNOWN";    
    for (var i = 0; i < element.childNodes.length; i++) {
    
        var search = element.childNodes[i];
        var j;
        for (var j = 0; j < search.childNodes.length; j++) {
            var e = search.childNodes[j];
            var t = "";
            try{
				t = e.childNodes[0].nodeValue;
            }catch(err){
            }
            if (false);
            else if (e.nodeName == "COLOR") {
                color = t;
            }
            else if (e.nodeName == "INFO") {
                info = t;
            }
            else if (e.nodeName == "DISPLAY") {
                display = t;
            }
            else if (e.nodeName == "HOUSE_IDs") {
                houseids = t;
            }
            else if (e.nodeName == "SEARCH_IDs") {
                searchids = t;
            }
            else if (e.nodeName == "TITLE") {
                title = t;
            }
            else if (e.nodeName == "ALERTMESSAGE") {
                alertmsg = t;
            }            
            
        }
        // Create a new button object here
        gProfile.Buttons[gProfile.Buttons.length] = new Button(display, color, houseids, searchids, info, title, alertmsg);
        // done
    }
}

function HandleFrames(element) 
{
    var v1, v2, v3, v4, v5;
    var map1, map2, map3, map4, map5;
    var css1, css2, css3, css4, css5;
    var j, top, bot;
    for (var i = 0; i < element.childNodes.length; i++) {
        var search = element.childNodes[i];
        if (false);
        else if (search.nodeName == "LEFT") {
            for (j = 0; j < search.attributes.length; j++) {
                if (search.attributes[j].name == "width") {
                    v1 = search.attributes[j].value;
                }
            }
            try {
                if (search.childNodes[0].nodeName == "TOP") {
                    for (j = 0; j < search.childNodes[0].attributes.length; j++) {
                        if (search.childNodes[0].attributes[j].name == "height") {
                            v2 = search.childNodes[0].attributes[j].value;
                        }
                        if (search.childNodes[0].attributes[j].name == "mapped_function") {
                            map1 = search.childNodes[0].attributes[j].value;
                        }
                        if (search.childNodes[0].attributes[j].name == "stylesheet") {
                            css1 = search.childNodes[0].attributes[j].value;
                        }
                    }            
                }
                else if (search.childNodes[0].nodeName == "BOTTOM") {
                    for (j = 0; j < search.childNodes[0].attributes.length; j++) {
                        if (search.childNodes[0].attributes[j].name == "mapped_function") {
                            map2 = search.childNodes[0].attributes[j].value;
                        }
                        if (search.childNodes[0].attributes[j].name == "stylesheet") {
                            css2 = search.childNodes[0].attributes[j].value;
                        }
                    }            
                }
                if (search.childNodes[1].nodeName == "TOP") {
                    for (j = 0; j < search.childNodes[1].attributes.length; j++) {
                        if (search.childNodes[1].attributes[j].name == "height") {
                            v2 = search.childNodes[1].attributes[j].value;
                        }
                        if (search.childNodes[1].attributes[j].name == "mapped_function") {
                            map1 = search.childNodes[1].attributes[j].value;
                        }
                        if (search.childNodes[1].attributes[j].name == "stylesheet") {
                            css1 = search.childNodes[1].attributes[j].value;
                        }
                    }            
                }
                else if (search.childNodes[1].nodeName == "BOTTOM") {
                    for (j = 0; j < search.childNodes[1].attributes.length; j++) {
                        if (search.childNodes[1].attributes[j].name == "mapped_function") {
                            map2 = search.childNodes[1].attributes[j].value;
                        }
                        if (search.childNodes[1].attributes[j].name == "stylesheet") {
                            css2 = search.childNodes[1].attributes[j].value;
                        }
                    }            
                }
            }
            catch (e) {
            }
        }
        else if (search.nodeName == "MIDDLE") {
            for (j = 0; j < search.attributes.length; j++) {
                if (search.attributes[j].name == "height") {
                    v5 = search.attributes[j].value;
                }
                if (search.attributes[j].name == "mapped_function") {
                    map3 = search.attributes[j].value;
                }
                if (search.attributes[j].name == "stylesheet") {
                    css5 = search.attributes[j].value;
                }
            }            
        }
        else if (search.nodeName == "RIGHT") {
            for (j = 0; j < search.attributes.length; j++) {
                if (search.attributes[j].name == "width") {
                    v3 = search.attributes[j].value;
                }
            }            
            try {
                if (search.childNodes[0].nodeName == "TOP") {
                    for (j = 0; j < search.childNodes[0].attributes.length; j++) {
                        if (search.childNodes[0].attributes[j].name == "height") {
                            v4 = search.childNodes[0].attributes[j].value;
                        }
                        if (search.childNodes[0].attributes[j].name == "mapped_function") {
                            map4 = search.childNodes[0].attributes[j].value;
                        }
                        if (search.childNodes[0].attributes[j].name == "stylesheet") {
                        css3 = search.childNodes[0].attributes[j].value;
                        }
                    }            
                }
                else if (search.childNodes[0].nodeName == "BOTTOM") {
                    for (j = 0; j < search.childNodes[0].attributes.length; j++) {
                        if (search.childNodes[0].attributes[j].name == "mapped_function") {
                            map5 = search.childNodes[0].attributes[j].value;
                        }
                        if (search.childNodes[0].attributes[j].name == "stylesheet") {
                        css4 = search.childNodes[0].attributes[j].value;
                        }
                    }            
                }
                if (search.childNodes[1].nodeName == "TOP") {
                    for (j = 0; j < search.childNodes[1].attributes.length; j++) {
                        if (search.childNodes[1].attributes[j].name == "height") {
                            v4 = search.childNodes[1].attributes[j].value;
                        }
                        if (search.childNodes[1].attributes[j].name == "mapped_function") {
                            map4 = search.childNodes[1].attributes[j].value;
                        }
                        if (search.childNodes[1].attributes[j].name == "stylesheet") {
                        css3 = search.childNodes[1].attributes[j].value;
                        }
                    }            
                }
                else if (search.childNodes[1].nodeName == "BOTTOM") {
                    for (j = 0; j < search.childNodes[1].attributes.length; j++) {
                        if (search.childNodes[1].attributes[j].name == "mapped_function") {
                            map5 = search.childNodes[1].attributes[j].value;
                        }
                        if (search.childNodes[1].attributes[j].name == "stylesheet") {
                        css4 = search.childNodes[1].attributes[j].value;
                        }
                    }            
                }
            }
            catch (e) {
            }
        }
    }
    if(gProfile.Frame != null)
        delete gProfile.Frame;
    gProfile.Frame = new Frame(v1, v2, v3, v4, v5, map1, map2, map3, map4, map5, css1, css2, css3, css4, css5);
}

function HandleDefMap(element) 
{
    var lat = "UNKNOWN";
    var lng = "UNKNOWN";
    var zoom = "UNKNOWN";
    var mapType = "UNKNOWN";
    var overlay = "UNKNOWN";
    for (var i = 0; i < element.childNodes.length; i++) {
        var search = element.childNodes[i];
        /*var j;
        for (var j = 0; j < search.childNodes.length; j++) {
            var e = search.childNodes[j];*/
			var t = "";
            try{
				t = search.childNodes[0].nodeValue;
            }catch(err){
            }            if (false);
            else if (search.nodeName == "LAT") {
                lat = t;
            }
            else if (search.nodeName == "LNG") {
                lng = t;
            }
            else if (search.nodeName == "ZOOM") {
                zoom = t;
            }
            else if (search.nodeName == "MAPTYPE") {
                mapType = t;
            }
            else if (search.nodeName == "OL") {
                overlay = t;
            }
      // }
        // Create a new button object here

        // done
    }
   gProfile.DefMap[gProfile.DefMap.length] = new DefaultMap(lat, lng, zoom,mapType,overlay);
}

function loadXMLDocForLoad() 
{
//  if(document.frames){    
//	gCurrentDocument = document.frames["AJAX_FRAME"];	
//  }
  try{
		var path;
		try {
			path = parent.location.pathname;
		}
		catch(e)
		{
			path = location.pathname;
		}
		var n = path.toLowerCase().indexOf("user/" + gFramesetName.toLowerCase());
		if(n == -1) n = path.lastIndexOf('/');
		
		var xmlpath = path.substring(0, n) + "/Template.xml";
	    if (window.XMLHttpRequest && (navigator.appName.indexOf("Explorer") == -1)) {
		    req = 	new XMLHttpRequest();
		    req.onreadystatechange = gFuncForLoad;
		    req.overrideMimeType('text/xml');
		    req.open("POST", gUrlForLoad, true);
		    req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		    req.send("XMLFILE="+xmlpath);
		    
		}
		else if (window.ActiveXObject) 
		{
			req = new ActiveXObject("Microsoft.XMLHTTP");
			if (req)
			{
			    DisableAllControls();
                req.onreadystatechange = gFuncForLoad;
				req.open("POST", gUrlForLoad, true);
				req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				req.send("XMLFILE="+xmlpath);
			}
		}
		
	}
	catch(e)
	{debugger;
		alert("Failure in Loading XML DOM");	
	}
}

function processXmlResponseForLoad()
{
	//alert(req.readyState+";"+req.status);
	
    var response;    
    var status;
    try {
    	if (req.readyState == 4) 
    	{
    		if (req.status == 200)
    		{
    			renderXMLDocument(req.responseXML.firstChild);
			    EnableAllControls();
    		}
    	}
    }
    catch(e){
		alert("In processXmlResponseForLoad, error is: " + e);
		alert(req.responseText);
        alert('Error Processing HTML Request');
    }
}

function renderXMLDocument(root)
{
    var elementProfile = root.firstChild;
    if (elementProfile.nodeName != "Profile") {
        // Something wrong
    }
    
    var j;
    var maxSearchId = 0;
    var maxHouseTypeId = 0;
    var maxActionId = 0;
    var language = "UNKNOWN";
    var style = "UNKNOWN";
    var defButton = "NONE";
    
    for (j = 0; j < elementProfile.attributes.length; j++) {
        if (elementProfile.attributes[j].name == "language") {
            language = elementProfile.attributes[j].value;
        }
        if (elementProfile.attributes[j].name == "style") {
            style = elementProfile.attributes[j].value;
        }
        if (elementProfile.attributes[j].name == "maxsid") {
            maxSearchId = elementProfile.attributes[j].value;
        }
        if (elementProfile.attributes[j].name == "maxhid") {
            maxHouseTypeId = elementProfile.attributes[j].value;
        }
        if (elementProfile.attributes[j].name == "maxaid") {
            maxActionId = elementProfile.attributes[j].value;
        }
        if (elementProfile.attributes[j].name == "DefaultButton") {
            defButton = elementProfile.attributes[j].value;
        }
    }
    // Create Profile object here
    gProfile = new Profile(language, style, maxSearchId, maxHouseTypeId, maxActionId, defButton);
    // done
    for (var i = 0; i < elementProfile.childNodes.length; i++)
    {
		if (false);
        else if (elementProfile.childNodes[i].nodeName == "SEARCHES")
        {
           HandleSearches(elementProfile.childNodes[i]);
        }
        else if (elementProfile.childNodes[i].nodeName == "HOUSETYPEs")
        {
            HandleHouseTypes(elementProfile.childNodes[i]);
        }
        else if (elementProfile.childNodes[i].nodeName == "ACTION_3Ds")
        {
            HandleActions(elementProfile.childNodes[i]);
        }
        else if (elementProfile.childNodes[i].nodeName == "TABs")
        {
            HandleTabs(elementProfile.childNodes[i]);
        }
        else if (elementProfile.childNodes[i].nodeName == "BUTTONs")
        {
            HandleButtons(elementProfile.childNodes[i]);
        }
        else if (elementProfile.childNodes[i].nodeName == "FRAMEs")
        {
            HandleFrames(elementProfile.childNodes[i]);
        }
        else if (elementProfile.childNodes[i].nodeName == "DEFMAP")
        {
            HandleDefMap(elementProfile.childNodes[i]);
        } 
        else if (elementProfile.childNodes[i].nodeName == "POIs")
        { 
            HandlePOIs(elementProfile.childNodes[i]);
        }
    }
   gCurrentDocument.DisplayItemForThisPage();
}

function loadXMLDocForChange() 
{
  try{
        var s = gProfile.GenerateXML();
        s = "NEWXML=<TEMPLATE>" + s + "</TEMPLATE>";
	    if (window.XMLHttpRequest) {
		    req = 	new XMLHttpRequest();
		    req.onreadystatechange = gFuncForChange;
		    req.overrideMimeType('text/xml');
		    req.open("POST", gUrlForChange, true);
		    req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		    req.send(s);
		}
		else if (window.ActiveXObject) 
		{
			req = new ActiveXObject("Microsoft.XMLHTTP");
			if (req)
			{
			    DisableAllControls();
                req.onreadystatechange = gFuncForChange;
				req.open("POST", gUrlForChange, true);
				req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				req.send(s);
			}
		}
	}
	catch(e)
	{debugger;
		alert("Failure in Loading XML DOM");	
	}
}

function processXmlResponseForChange()
{
    var response;    
    var status;
    try {
    	if (req.readyState == 4) 
    	{
    		if (req.status == 200)
    		{
    			VerifyOKAfterChange(req.responseXML.firstChild); 
    		}
    	}
    }
    catch(e){
        alert('Error Processing HTML Request');
    }
}

function VerifyOKAfterChange(root)
{
    var element = root.firstChild;
    if (element.nodeName != "STATUS") {
        ShowSubmitStatus(false);
    }
    else {
        if (element.text == "OK") {
            ShowSubmitStatus(true);
            loadXMLDocForLoad();
        }
    }
}

function DisableAllControls()
{
}

function EnableAllControls()
{
}

 function RenderOneSearchItemForDisplay(){}

 function RenderLookAndFeel(){}

function ShowSubmitStatus(b)
{
    var obj = document.getElementById("Status");
    var s = "The Result of Operation was ";
    var u = "NOT ";
    var v = "Successful";
    if (b) s += v; else s += u + v;
    obj.value = s;
}


////********Generic Function ***************/

        function Trim(TRIM_VALUE){
            if(TRIM_VALUE.length < 1){
                return"";
            }
            TRIM_VALUE = RTrim(TRIM_VALUE);
            TRIM_VALUE = LTrim(TRIM_VALUE);
            if(TRIM_VALUE==""){
                return "";
            }else{
                return TRIM_VALUE;
            }
        } 

        function RTrim(VALUE){
            var w_space = String.fromCharCode(32);
            var v_length = VALUE.length;
            var strTemp = "";
            if(v_length < 0){
                return"";
            }
            var iTemp = v_length -1;
            while(iTemp > -1){
                if(VALUE.charAt(iTemp) == w_space){
                }else{
                    strTemp = VALUE.substring(0,iTemp +1);
                    break;
                }
                iTemp = iTemp-1;
            } 
            return strTemp;
        }

        function LTrim(VALUE){
            var w_space = String.fromCharCode(32);
            if(v_length < 1){
                return"";
            }
            var v_length = VALUE.length;
            var strTemp = "";
            var iTemp = 0;
            while(iTemp < v_length){
                if(VALUE.charAt(iTemp) == w_space){
                }else{
                    strTemp = VALUE.substring(iTemp,v_length);
                    break;
                }
                iTemp = iTemp + 1;
            } 
            return strTemp;
        }

	
