has_been_called = Array();
bAllLoaded = false;

function FactoryXMLHttpRequest()
{
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}
function Asynchronous()
{
    this._xmlhttp = new FactoryXMLHttpRequest();
}
function Asynchronous_post(url,data,control)
{
    var instance = this;
    this._xmlhttp.open('POST',url,true);
    this._xmlhttp.onreadystatechange = function()
    {
        switch(instance._xmlhttp.readyState)
        {    
            case 1:
                instance.loading();
                break;
            case 2:
                instance.loaded()
                break;
            case 3:
                instance.interactive();
                break;
            case 4:
                instance.complete(instance._xmlhttp.status,
                                    instance._xmlhttp.statusText,
                                    instance._xmlhttp.responseText,
                                    instance._xmlhttp.responseXML,
                                    control);
                                    
                break;
        }
    }
    
    this._xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    this._xmlhttp.setRequestHeader("Content-length", data.length);
    this._xmlhttp.send(data);
}
function Asynchronous_call(url,control)
{
    var instance = this;
    this._xmlhttp.open('GET',url,true);
    //alert(url);
    this._xmlhttp.onreadystatechange = function()
    {
        switch(instance._xmlhttp.readyState)
        {    
            case 1:
                instance.loading();
                break;
            case 2:
                instance.loaded()
                break;
            case 3:
                instance.interactive();
                break;
            case 4:
                instance.complete(instance._xmlhttp.status,
                                    instance._xmlhttp.statusText,
                                    instance._xmlhttp.responseText,
                                    instance._xmlhttp.responseXML,
                                    control);
                                    
                break;
        }
    }
    this._xmlhttp.send(null);
}
function Asynchronous_loading(){}
function Asynchronous_loaded(){}
function Asynchronous_interactive(){}
function Asynchronous_complete(status,statusText,responseText,responseHTML,control){}

function Asynchronous_status()
{
    return this._xmlhttp.readyState;
}

Asynchronous.prototype.loading = Asynchronous_loading;
Asynchronous.prototype.loaded = Asynchronous_loaded;
Asynchronous.prototype.interactive = Asynchronous_interactive;
Asynchronous.prototype.complete =    Asynchronous_complete;
Asynchronous.prototype.status =		 Asynchronous_status;

Asynchronous.prototype.call = Asynchronous_call;
Asynchronous.prototype.post = Asynchronous_post;/*************************
FUNCTIONS TO CREATE XML
    * createInsertXML();
    * createXML()
    * createStepXML()
*************************/
function asc_update_Event(status,statusText,responseText,responseHTML,control)
{
    window.location = window.location;
}
function createStepXML()
{
    asc_update = new Asynchronous()
    asc_update.complete = asc_update_Event
    data = createXML();
    data = URLEncode(data);
    data = "szXMLFeed=" + data;
    asc_update.post("scripts/dataLayer/updateStep.xml.asp",data,null)
    

}
function createInsertXML()
{
    var tables = document.getElementsByName("newsection");
    var xml = '<?xml version="1.0" encoding="utf-8"?>\n<Root>'; 
    
    for(iCount = 0; iCount < tables.length; iCount++)
    {
        var liSectionOnFormPk = document.getElementsByName("liSectionOnFormPk").item(iCount).value;
        var bSectionVisible = document.getElementsByName("bSectionVisible").item(iCount).value;
        rows = document.getElementsByName("newsection")[iCount].getElementsByTagName("tr");
        
        xml += '<SectionOnForm bSectionVisible="' + ((bSectionVisible="on")?"1":"0") + '" iSectionOrder="' + (iCount + 1) + '">';
        
        for(iCountRows = 0; iCountRows < (rows.length - 1);iCountRows++)
        {
            hasXML = false;
            hasChanged = false;
            //alert(rows[iCountRows].getElementsByName("iFeatureType").item(iCountRows).value);
            //alert(rows[iCountRows].childNodes[3].childNodes.item(0).name);
            xmlRow = "<FeatureInSection "
            for(iCountItems = 0;iCountItems < rows[iCountRows].childNodes[0].childNodes.length; iCountItems++)
            {
                switch(rows[iCountRows].childNodes[0].childNodes.item(iCountItems).name)
                {
                    case "szFriendlyFeatureName":
                        xmlRow += 'szFriendlyFeatureName="' + rows[iCountRows].childNodes[0].childNodes.item(iCountItems).value + '" ';
                        break;
                }
               //alert(rows[iCountRows].childNodes[1].childNodes.item(iCountItems).name);
            }
            for(iCountItems = 0;iCountItems < rows[iCountRows].childNodes[2].childNodes.length; iCountItems++)
            {
                switch(rows[iCountRows].childNodes[2].childNodes.item(iCountItems).name)
                {
                    case "bFeatureVisible":
                        if(rows[iCountRows].childNodes[2].childNodes.item(iCountItems).checked)
                        {
                            xmlRow += 'bFeatureVisible="1" '
                        }
                        else
                        {
                            xmlRow += 'bFeatureVisible="0" '
                        }
                        break;
                    case "iFeatureDataLength":
                        //xmlRow += 'iFeatureDataLength="' + rows[iCountRows].childNodes[3].childNodes.item(iCountItems).value + '" ';
                        break;
                    case "liFeatureId":
                        xmlRow += 'liFeatureId="' + rows[iCountRows].childNodes[2].childNodes.item(iCountItems).value + '" ';
                        break;
                    case "liFeatureInSectionPk":
                        xmlRow += 'liFeatureInSectionPk="' + rows[iCountRows].childNodes[2].childNodes.item(iCountItems).value + '" '; 
                        break;
                        
                    case "bFeatureOptional":
                        if(rows[iCountRows].childNodes[2].childNodes.item(iCountItems).checked)
                        {
                            xmlRow += 'bFeatureOptional="1" '
                        }
                        else
                        {
                            xmlRow += 'bFeatureOptional="0" '
                        }
                        break;
                    case "iFeatureType":
                        if(rows[iCountRows].childNodes[2].childNodes.item(iCountItems).value==2)
                        {
                            hasXML = true;
                        }
                        break;
                    case "hasChanged":
                        if(rows[iCountRows].childNodes[2].childNodes.item(iCountItems).value==1)
                        {
                            hasChanged = true;
                        }
                        break;
                }
                
            }
            xmlRow += 'iFeatureOrder="' + (iCountRows + 1)+ '"'
            if(hasXML)
            {
                xmlRow += ">";
                //FeaturesInFeature
                for(iCountItems = 0;iCountItems < rows[iCountRows].childNodes[1].childNodes.length; iCountItems++)
                {
                    switch(rows[iCountRows].childNodes[1].childNodes.item(iCountItems).name)
                    {
                        case "FeaturesInFeature":
                            xmlDoc = loadXML(rows[iCountRows].childNodes[1].childNodes.item(iCountItems).value);
                            var xmlSet = xmlDoc.getElementsByTagName("FeaturesInFeature");
                            for(i = 0; i < xmlSet.length; i++)
                            {
                                xmlRow += "<FeaturesInFeature "
                                //xmlRow += 'szFeatureName="' + xmlSet[i].getAttribute("szFeatureName") + '" ';
                                xmlRow += 'liFeatureId="' + xmlSet[i].getAttribute("liFeatureId") + '" ';
                                xmlRow += 'iDataSource="' + xmlSet[i].getAttribute("iDataSource") + '" ';
                                //xmlRow += 'iIsJscript="' + xmlSet[i].getAttribute("iIsJScript") + '" ';
                                xmlRow += '/>'
                            }
                        break;
                    }
                }
                xmlRow += "</FeatureInSection>"
            }
            else
            {
                xmlRow += "/>"
            }
            if(hasChanged)
            {
                xml += xmlRow;
            }
            
            //document.getElementByName("iFeatureType")[iCountRow]
        }
        xml += '</SectionOnForm>';
    }
    xml += "</Root>";
//    alert("where am i going?");
//    alert(xml);
//    document.getElementById("debug_xml").value=xml;
    return xml;
}
function createXML()
{
    var tables = document.getElementsByName("section");
    var xml = '<?xml version="1.0" encoding="utf-8"?>\n<Root>'; 
    
    for(iCount = 0; iCount < tables.length; iCount++)
    {
        var szSectionName = document.getElementsByName("szSectionName").item(iCount).value;
        var liSectionOnFormPk = document.getElementsByName("liSectionOnFormPk").item(iCount).value;
        var bSectionVisible = document.getElementsByName("bSectionVisible").item(iCount).value;
        rows = document.getElementsByName("section")[iCount].getElementsByTagName("tr");
        
        xml += '<SectionOnForm szSectionName="' + szSectionName + '" liSectionOnFormPk="' + liSectionOnFormPk + '" bSectionVisible="' + ((bSectionVisible="on")?"1":"0") + '" iSectionOrder="' + (iCount + 1) + '">';
        
        for(iCountRows = 0; iCountRows < (rows.length);iCountRows++)
        {
            hasXML = false;
            hasChanged = false;
            //alert(rows[iCountRows].getElementsByName("iFeatureType").item(iCountRows).value);
            //alert(rows[iCountRows].childNodes[3].childNodes.item(0).name);
            xmlRow = "<FeatureInSection "
            for(iCountItems = 0;iCountItems < rows[iCountRows].childNodes[0].childNodes.length; iCountItems++)
            {
                switch(rows[iCountRows].childNodes[0].childNodes.item(iCountItems).name)
                {
                    case "szFriendlyFeatureName":
                        xmlRow += 'szFriendlyFeatureName="' + rows[iCountRows].childNodes[0].childNodes.item(iCountItems).value + '" ';
                        break;
                }
               //alert(rows[iCountRows].childNodes[1].childNodes.item(iCountItems).name);
            }
            for(iCountItems = 0;iCountItems < rows[iCountRows].childNodes[2].childNodes.length; iCountItems++)
            {
                switch(rows[iCountRows].childNodes[2].childNodes.item(iCountItems).name)
                {
                    case "bFeatureVisible":
                        if(rows[iCountRows].childNodes[2].childNodes.item(iCountItems).checked)
                        {
                            xmlRow += 'bFeatureVisible="1" '
                        }
                        else
                        {
                            xmlRow += 'bFeatureVisible="0" '
                        }
                        break;
                    case "iFeatureDataLength":
                        //xmlRow += 'iFeatureDataLength="' + rows[iCountRows].childNodes[3].childNodes.item(iCountItems).value + '" ';
                        break;
                    case "liFeatureId":
                        xmlRow += 'liFeatureId="' + rows[iCountRows].childNodes[2].childNodes.item(iCountItems).value + '" ';
                        break;
                    case "liFeatureInSectionPk":
                        xmlRow += 'liFeatureInSectionPk="' + rows[iCountRows].childNodes[2].childNodes.item(iCountItems).value + '" '; 
                        break;
                        
                    case "bFeatureOptional":
                        if(rows[iCountRows].childNodes[2].childNodes.item(iCountItems).checked)
                        {
                            xmlRow += 'bFeatureOptional="1" '
                        }
                        else
                        {
                            xmlRow += 'bFeatureOptional="0" '
                        }
                        break;
                    case "iFeatureType":
                        if(rows[iCountRows].childNodes[2].childNodes.item(iCountItems).value==2)
                        {
                            hasXML = true;
                        }
                        break;
                    case "hasChanged":
                        if(rows[iCountRows].childNodes[2].childNodes.item(iCountItems).value==1)
                        {
                            hasChanged = true;
                        }
                        break;
                }
                
            }
            xmlRow += 'iFeatureOrder="' + (iCountRows + 1)+ '"'
            if(hasXML)
            {
                xmlRow += ">";
                //FeaturesInFeature
                for(iCountItems = 0;iCountItems < rows[iCountRows].childNodes[1].childNodes.length; iCountItems++)
                {
                    switch(rows[iCountRows].childNodes[1].childNodes.item(iCountItems).name)
                    {
                        case "FeaturesInFeature":
                            xmlDoc = loadXML(rows[iCountRows].childNodes[1].childNodes.item(iCountItems).value);
                            var xmlSet = xmlDoc.getElementsByTagName("FeaturesInFeature");
                            for(i = 0; i < xmlSet.length; i++)
                            {
                                xmlRow += "<FeaturesInFeature "
                                //xmlRow += 'szFeatureName="' + xmlSet[i].getAttribute("szFeatureName") + '" ';
                                xmlRow += 'liFeatureId="' + xmlSet[i].getAttribute("liFeatureId") + '" ';
                                xmlRow += 'iDataSource="' + xmlSet[i].getAttribute("iDataSource") + '" ';
                                //xmlRow += 'iIsJscript="' + xmlSet[i].getAttribute("iIsJScript") + '" ';
                                xmlRow += '/>'
                            }
                        break;
                    }
                }
                xmlRow += "</FeatureInSection>"
            }
            else
            {
                xmlRow += "/>"
            }
            if(hasChanged)
            {
                xml += xmlRow;
            }
            
            //document.getElementByName("iFeatureType")[iCountRow]
        }
        xml += '</SectionOnForm>';
    }
    xml += "</Root>";
   // alert("where am i going?");
   // alert(xml);
   return xml;
    /*
    
iFeatureDataLength
liFeatureId
liFeatureInSectionPk
    */
}// JScript File
var trQuickLogReg = null;
var liOwnerID = null;

function quickLogin(container,output)
{
    trQuickLogReg = document.getElementById(container);
    liOwnerID = document.getElementById(output);
    displayStepDiv(true);
}
function quickRegister(container,output)
{
    trQuickLogReg = document.getElementById(container);
    liOwnerID = document.getElementById(output);
    displayStepDiv(false);
}

/// <Summary>
/// Closes the Popup DIV that allows you to add a step
///</Summary>
function closeStepDiv()
{
    var divName = "divNewWizardStep";
    var divControl;
    
    if(document.getElementById(divName) != null)
    {
        divControl = document.getElementById(divName)
        divControl.style.display = "none";
        showAllSelect(new Array())
    }
    if(!document.all)
    {
        var divUnderlay = "divUnderlay";
        var divUnderlayControl;
        if(document.getElementById(divUnderlay) != null)
        {
            divUnderlayControl = document.getElementById(divUnderlay);
            divUnderlayControl.style.display = "none";
        }
    }
}
/// <Summary>
/// Creates a popup DIV that contains an IFRAME with the step information 
/// </Summary>
function displayStepDiv(bLogin)
{
    /// hide any select boxed
     hideAllSelect(new Array())
    /// check to see if we need to create the underlay div 
    if(!document.all)
    {
        var divUnderlay = "divUnderlay";
        var divUnderlayControl;
        if(document.getElementById(divUnderlay) != null)
        {
            divUnderlayControl = document.getElementById(divUnderlay);
            //divUnderlayControl.style.display = "block";
        }
        else
        {
            divUnderlayControl = document.createElement("div");
            divUnderlayControl.id = divUnderlay;
            divUnderlayControl.style.display = "block";
            divUnderlayControl.style.backgroundColor = "black";
            divUnderlayControl.style.position = "absolute";
            divUnderlayControl.style.top = "0px";
            divUnderlayControl.style.left = "0px";
            divUnderlayControl.style.width = "100%";
            divUnderlayControl.style.height = "100%";
            divUnderlayControl.style.opacity = "0.6";
            //document.getElementsByTagName("body")[0].appendChild(divUnderlayControl);
        }
    }
     
    /// clean out any existing DIV's 
    /// check to see a DIV already Exists, if it does clean
    /// the child nodes, if it doesn't then create it and
    /// add it to the document object model
    var divName = "divNewWizardStep";
    var divControl;
    if(document.getElementById(divName) != null)
    {
        divControl = document.getElementById(divName);
        /// clear out any old child nodes
        clearChildNodes(divControl, false );
    }
    else
    {
        divControl = document.createElement("div");
        divControl.id = divName;
        document.getElementsByTagName("body")[0].appendChild(divControl);
    }
    
    /// make sure that the DIV has the correct style and atrributes
    divControl.style.display = "block";
    divControl.style.position = "absolute";
    if(!document.all)
    {
        divControl.style.top = window.pageYOffset + 10 + "px";
    }
    else
    {
        divControl.style.top = (document.documentElement ? document.documentElement.scrollTop : 0) + 10 + "px";
    }
    divControl.style.left = "50%";
    divControl.style.marginLeft = "-400px";
    divControl.style.width = "800px";
    divControl.style.height = "500px";
    divControl.style.border = "solid 1px black";
    divControl.style.backgroundColor = "white"
    // Fill the DIV
    var iFrame = document.createElement("iframe");
    iFrame.style.width = "100%";
    iFrame.style.height = "100%";
    iFrame.style.border = "solid 0px black";
    iFrame.style.backgroundColor = "white";
    iFrame.setAttribute("src","/ads/scripts/quickLoginReg.asp?login=" + bLogin);
    
    var divHeader = document.createElement("div");
    divHeader.style.borderBottom = "solid 1px black";
    divHeader.style.backgroundColor = "white";
    divHeader.style.textAlign = "right";
    
    var aClose = document.createElement("a");
    aClose.appendChild(document.createTextNode("Close"));
    aClose.href = "javascript:;;";
    aClose.onclick = function (){ closeCompleteStepDiv();};
    divHeader.appendChild(aClose);
    divControl.appendChild(divHeader);
        
    var divIframe = document.createElement("div");
    divIframe.style.width = "800px";
    divIframe.style.height = "480px";
    divIframe.style.overflowX = "hidden";
    divIframe.appendChild(iFrame);
        
    divControl.appendChild(divIframe);
}
function quickLoginComplete(liOwnerIdValue)
{
    trQuickLogReg.style.display = "none";
    liOwnerID.value = liOwnerIdValue;
    closeStepDiv();
    document.getElementById("trQuickLogRegLabel").style.display = "block";
}
function quickRegComplete(liOwnerIdValue)
{
    trQuickLogReg.style.display = "none";
    liOwnerID.value = liOwnerIdValue;
    closeStepDiv();
    document.getElementById("trQuickLogRegLabel").style.display = "block";
}
/// create the appropriate functions for the child frame to call once 
/// the form has been submitted
if(!document.all)
{
    Document.prototype.quickLoginComplete = quickLoginComplete;
    Document.prototype.quickRegComplete = quickRegComplete;
}
else
{
    document.quickLoginComplete = quickLoginComplete;
    document.quickRegComplete = quickRegComplete;
}

var szSearchRangeBeds = '';
var szSearchRangePriceMin = '';
var szSearchRangePriceMax = '';

function URLEncode( plaintext )
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
}

function confirmRedirect(question,url)
{
    if(confirm(question))
    {
        window.location = url
    }
    else
    {
        return 0;
    }
}
function amendString(message,old_value)
{
    var value = prompt(message,old_value);
    if(value > "")
    {
        return value;
    }
    else
    {
    }
}
function updateString(url,value)
{
    if(value > "")
    {
        window.location = url + value;
    }
}
function selectColorTableHide()
{
    document.getElementById("selectColor").style.visibility = "hidden";
}
function selectColorTableShow(val)
{
    selectFontTableHide();
    selectFontDecorationTableHide();
    selectFontSizeTableHide();
    document.getElementById("selectColor").style.visibility = "visible";
    document.getElementById("valueStore").value = val;
    
}
function selectFontTableHide()
{
    document.getElementById("selectFont").style.visibility = "hidden";
}
function selectFontTableShow(val)
{
    selectColorTableHide();
    selectFontDecorationTableHide();
    selectFontSizeTableHide();
    document.getElementById("selectFont").style.visibility = "visible";
    document.getElementById("valueStore").value = val;
    
}
function selectFontDecorationTableShow(val)
{
    selectFontTableHide();
    selectColorTableHide();
    selectFontSizeTableHide();
    document.getElementById("selectDecoration").style.visibility = "visible";
    document.getElementById("valueStore").value = val;
    document.getElementById("underline").checked = false;
    document.getElementById("bold").checked = false;
    document.getElementById("italic").checked = false;
}
function selectFontDecorationTableHide()
{
    document.getElementById("selectDecoration").style.visibility = "hidden";  
}
function selectFontSizeTableShow(val)
{
    selectFontDecorationTableHide();
    selectFontTableHide();
    selectColorTableHide();
    document.getElementById("selectFontSize").style.visibility = "visible";
    document.getElementById("valueStore").value = val;
}
function selectFontSizeTableHide()
{
    document.getElementById("selectFontSize").style.visibility = "hidden";  
}
document.writeln('<input type="hidden" id="valueStore"/>');
function selectFontSizeTableDraw()
{
    document.writeln('<div class="styleSelect" id="selectFontSize">');
    document.writeln('<div onclick="selectFontSize(this.style.fontSize);" style="cursor:pointer;font-size:10px">10px</div>');
    document.writeln('<div onclick="selectFontSize(this.style.fontSize);" style="cursor:pointer;font-size:20px">20px</div>');
    document.writeln('<div onclick="selectFontSize(this.style.fontSize);" style="cursor:pointer;font-size:30px">30px</div>');
    document.writeln('</div>');
}
function selectFontDecorationTableDraw()
{
    document.writeln('<div style="overflow:hidden; border:solid 0px white;" class="styleSelect" id="selectDecoration">');
    document.writeln('<p>Underlined: <input type="checkbox" name="underline" id="underline" value="1"/></p>');
    document.writeln('<p>Bold: <input type="checkbox" name="bold" id="bold" value="1"/></p>');
    document.writeln('<p>Italic: <input type="checkbox" name="italic" id="italic" value="1" /></p>');
    document.writeln('<p><input type="button" value="Set Font Decoration" onclick="javascript:selectFontDecoration(document.getElementById(\'underline\').checked,document.getElementById(\'bold\').checked,document.getElementById(\'italic\').checked)"/></p>');
    document.writeln('</div>');
}
function selectFontTableDraw()
{
    document.writeln('<div class="styleSelect" id="selectFont">');
    document.writeln('<div onclick="selectFont(this.style.fontFamily)" style="cursor:pointer;font-family:Arial,sans-sarif;">Arial</div>');
    document.writeln('<div onclick="selectFont(this.style.fontFamily)" style="cursor:pointer;font-family:Arial Black,sans-sarif;">Arial Black</div>');
    document.writeln('<div onclick="selectFont(this.style.fontFamily)" style="cursor:pointer;font-family:Arial Narrow,sans-sarif;">Arial Narrow</div>');
    document.writeln('<div onclick="selectFont(this.style.fontFamily)" style="cursor:pointer;font-family:Book Antiqua,sans-sarif;">Book Antiqua</div>');
    document.writeln('<div onclick="selectFont(this.style.fontFamily)" style="cursor:pointer;font-family:Bookman Old Style,sans-sarif;">Bookman Old Style</div>');
    document.writeln('<div onclick="selectFont(this.style.fontFamily)" style="cursor:pointer;font-family:Comic Sans MS,sans-sarif;">Comic Sans MS</div>');
    document.writeln('<div onclick="selectFont(this.style.fontFamily)" style="cursor:pointer;font-family:Courier New,sans-sarif;">Courier New</div>');
    document.writeln('<div onclick="selectFont(this.style.fontFamily)" style="cursor:pointer;font-family:Georgia,sans-sarif;">Georgia</div>');
    document.writeln('<div onclick="selectFont(this.style.fontFamily)" style="cursor:pointer;font-family:Haettenschweiler,sans-sarif;">Haettenschweiler</div>');
    document.writeln('<div onclick="selectFont(this.style.fontFamily)" style="cursor:pointer;font-family:Impact,sans-sarif;">Impact</div>');
    document.writeln('<div onclick="selectFont(this.style.fontFamily)" style="cursor:pointer;font-family:Lucida Console,sans-sarif;">Lucida Console</div>');
    document.writeln('<div onclick="selectFont(this.style.fontFamily)" style="cursor:pointer;font-family:Mangal,sans-sarif;">Mangal</div>');
    document.writeln('<div onclick="selectFont(this.style.fontFamily)" style="cursor:pointer;font-family:Microsoft Sans Serif,sans-sarif;">Microsoft Sans Serif</div>');
    document.writeln('<div onclick="selectFont(this.style.fontFamily)" style="cursor:pointer;font-family:Tahoma,sans-sarif;">Tahoma</div>');
    document.writeln('<div onclick="selectFont(this.style.fontFamily)" style="cursor:pointer;font-family:Times New Roman,sans-sarif;">Times New Roman</div>');
    document.writeln('<div onclick="selectFont(this.style.fontFamily)" style="cursor:pointer;font-family:Verdana,sans-sarif;">Verdana</div>');
    document.writeln('</div>');
}
function selectColorTableDraw()
{
    document.writeln('<div class="styleSelect" id="selectColor">');
    document.writeln('<input type="hidden" id="valueStore"/>');
    document.writeln('<table width="100" border="0" cellspacing="0" cellpadding="0" align="center">');
    document.writeln('<tr>');
    for (var i=6; i>0; i--) {
	    var ii = i * 3 -3;
	    var hex1 = ii.toString(16);
		/*&
	    if (i == 3) {
		    document.writeln('</table></td>');
		    //document.writeln('<td>&nbsp;</td>');
		    //document.writeln('</tr><tr>');
		    document.writeln('<td valign="top"><table width="100">');
	    }
*/
	    //document.writeln('<tr>');
	    for (var j=6; j>0; j--) {
		    var jj = j * 3 -3;
		    var hex2 = jj.toString(16);
		    document.writeln('<td>');
		    for (var k=6; k>0; k--) {
			    var kk = k * 3 -3;
			    var hex3 = kk.toString(16);
			    var color = hex1 + '' + hex1 + '' + hex2 + '' + hex2 + '' + hex3 + '' + hex3;
			    document.writeln('<div style="cursor:pointer;background-color:#' + color + '; width:20px; height:20px; border: solid 1px black; margin:2px;" onclick="selectWebColor(this, \'' + color + '\');" title="#' + color + '">&nbsp;</div>');
		    }
		    document.writeln('</td>');
	    }
	    document.writeln('</tr>');
    }
    document.writeln('</table>');
    document.writeln('</div>');
}
/*********************************************************
*
*   FUNCTION THAT ARE USED IN WIZARD
*   ================================
*       * invalidItem(elementId)
*       * clearInvalid(elementId)
*       * clearChildNodes(control,bReturnSelectedValue)
*       * appendDefaultOptionElement(control)
*       * appendOptionElement(control,value,text,bSelected)
*       * is_Company(control,szSectionName)
*       * asc_range_Event(status,statusText,responseText,responseXML,control)
*       * asc_localareas_Event(status,statusText,responseText,responseXML,control)
*       * asc_towns_Event(status,statusText,responseText,responseXML,control)
*       * asc_states_Event(status,statusText,responseText,responseXML,control)
*       * asc_countries_Event(status,statusText,responseText,responseXML,control)
*       * getLocalAreas(parentControl,control)
*       * getTowns(parentControl,control)
*       * getStates(parentControl,control)
*       * getCountries(control)
*       * getRange(control,id)
*
**********************************************************/

function invalidItem( elementId )
{
    try
    {
        var qString = new Querystring();
        clearInvalid( elementId );
        //display the invlaud item
        try
        {
            var element_tr = "row_" + document.getElementById(elementId.replace("row_","")).name;
            var cntrl = document.getElementById(elementId.replace("row_",""));
            if(cntrl.style.display != "block")
            {
                cntrl.style.display = "block"    
            }
            if(document.all)
            {
                document.getElementById(element_tr).style.display = "block";
            }
            else
            {
                document.getElementById(element_tr).style.display = "table-row";
            }
        }
        catch(ex)
        {
            //ignore error
            if(qString.get('bDebug')== "1")
            {
	            alert(elementId + ", " + element_tr + ", "  + ex)
	        }
        }
	    switch( document.getElementById(elementId.replace("row_","")).type )
	    {
	        case "hidden":
		    case "checkbox":
			    styleElem = document.getElementById(elementId.replace("row_","wizardElement_")).style;
			    styleElem.background = "#ffc0cb";
			    break;
		    case "textarea":
		        document.getElementById(elementId.replace("row_","")).style.background = "#ffc0cb";
		        break;
		    default:
			    document.getElementById(elementId.replace("row_","")).className = "textboxInvalid";
			    break;
	    }
	}
	catch(ex)
	{
	    if(qString.get('bDebug')== "1")
        {
	        alert(elementId + " " + ex)
	    }
	}
}

function clearInvalid(elementId)
{
    try
    {
        elementId = elementId + "";
	    switch( document.getElementById(elementId.replace("row_","")).type )
	    {
	        case "hidden":
		    case "checkbox":
			    styleElem = document.getElementById(elementId.replace("row_","wizardElement_")).style;
			    styleElem.background = "#ffffff";
			    break;
		    case "textarea":
		        document.getElementById(elementId.replace("row_","")).style.background = "#ffffff";
		        break;
		    default:
			    document.getElementById(elementId.replace("row_","")).className = "textbox";
			    break;
	    }
	}
	catch(ex)
	{
	}
}

function clearChildNodes(control, bReturnSelectedNode )
{
	var liSelectedNode 

    while( control.childNodes.length > 0 )
    {
		if( bReturnSelectedNode )
		{
			if( control.childNodes[0].selected )
			{
				liSelectedNode = control.childNodes[0].value;
			}
		}
        control.removeChild(control.childNodes[0]);
    }
	
	return liSelectedNode;

}

function appendDefaultOptionElement(control)
{
/*
    option = document.createElement("option");
    option.value = "";
    option.appendChild(document.createTextNode("Please Choose"));
    control.appendChild(option);
*/
}
function appendOptionElement( control, value, text, bSelected )
{
    option = document.createElement("option");
    option.value = value;
	if( bSelected )
	{
		option.selected = true;
	}
    option.appendChild(document.createTextNode(text));
    control.appendChild(option);
}
/* END OF GLOBAL FUNCTIONS */

function is_Company(control,szSectionName)
{
    if( control[ control.selectedIndex ].text == "Business")
    {
        document.getElementById(szSectionName).style.display = "table";
        return true;
    }
    else
    {
        document.getElementById(szSectionName).style.display = "none";
        return false;
    }
}

function showBusinessForm( control, szSectionName )
{	
	if( document.getElementById( control )[ document.getElementById( control ).selectedIndex ].text == "Business" )
	{
		if(document.all)
		{
			//IE
			document.getElementById( szSectionName ).style.display = "block";
		}
		else
		{
			//Fx
			document.getElementById( szSectionName ).style.display = "table";
		}
	}	
	else
	{
		document.getElementById( szSectionName ).style.display = "none";
	}
}

function toggleSearchDisplay( control, arrSections, iSectionToShow )
{ 
    for( var iSectionCounter = 0; iSectionCounter < arrSections.length; iSectionCounter++ )
    {
        //alert(arrSections[iSectionCounter]);
        document.getElementById( arrSections[ iSectionCounter ] ).style.display = "none";
    } 
    
    if(document.all)
    {
        //IE
        document.getElementById( arrSections[ iSectionToShow ] ).style.display = "block";
    }
    else
    {
        //Fx
        document.getElementById( arrSections[ iSectionToShow ] ).style.display = "table";
    }

	// Load the appropriate range for the site selection.
    asc_loadRanges = new Asynchronous();
    asc_loadRanges.complete = asc_range_Event;
	if( arrSections[ iSectionToShow ] == 'Purchase Options' )
	{
	    asc_loadRanges.call("/ads/scripts/dataLayer/getRange.xml.asp?szRangeName=PropertyPriceBuying&bRangeOverLap=0&bAllRanges=0", getElementsIdByName( 'liPricePTFMin' ) );	  
		document.getElementById( "lblPPTFLabel" ).innerHTML = "Price GBP:-"
	}
	else
	{	
	    asc_loadRanges.call("/ads/scripts/dataLayer/getRange.xml.asp?szRangeName=PropertyPriceRenting&bRangeOverLap=0&bAllRanges=0", getElementsIdByName( 'liPricePTFMin' ) );	  
		document.getElementById( "lblPPTFLabel" ).innerHTML = "Price </b>per <b>Month (GBP):-"
	}

	// Load the appropriate range for the site selection.
    asc_loadRanges = new Asynchronous();
    asc_loadRanges.complete = asc_range_Event;
	if( arrSections[ iSectionToShow ] == 'Purchase Options' )
	{
	    asc_loadRanges.call("/ads/scripts/dataLayer/getRange.xml.asp?szRangeName=PropertyPriceBuying&bRangeOverLap=0&bAllRanges=0", getElementsIdByName( 'liPricePTFMax' ) );	  
	}
	else
	{	
	    asc_loadRanges.call("/ads/scripts/dataLayer/getRange.xml.asp?szRangeName=PropertyPriceRenting&bRangeOverLap=0&bAllRanges=0", getElementsIdByName( 'liPricePTFMax' ) );	  
	}
}

function toggleDisplayOnLoad( arrSections, iSectionToShow )
{ 
    for( var iSectionCounter = 0; iSectionCounter < arrSections.length; iSectionCounter++ )
    {
        //alert(arrSections[iSectionCounter]);
        document.getElementById( arrSections[ iSectionCounter ] ).style.display = "none";
    }
    
    if( iSectionToShow == 2 )
    {
        iSectionToShow = 0;
    }    
    
    if(document.all)
    {
        //IE
        document.getElementById( arrSections[ iSectionToShow ] ).style.display = "block";
    }
    else
    {
        //Fx
        document.getElementById( arrSections[ iSectionToShow ] ).style.display = "table";
    }
	// Load the appropriate range for the site selection.
    asc_loadRanges = new Asynchronous();
    asc_loadRanges.complete = asc_range_Event;
	if( !isNaN( getElementsIdByName( 'liPricePTFMin' ) ) )
	{
		if( arrSections[ iSectionToShow ] == 'Purchase Options' )
		{
			asc_loadRanges.call("/ads/scripts/dataLayer/getRange.xml.asp?szRangeName=PropertyPriceBuying&bRangeOverLap=0&bAllRanges=0", getElementsIdByName( 'liPricePTFMin' ) );	  
		}
		else
		{	
			asc_loadRanges.call("/ads/scripts/dataLayer/getRange.xml.asp?szRangeName=PropertyPriceRenting&bRangeOverLap=0&bAllRanges=0", getElementsIdByName( 'liPricePTFMin' ) );	  
		}
	}
	// Load the appropriate range for the site selection.
    asc_loadRanges = new Asynchronous();
    asc_loadRanges.complete = asc_range_Event;
	if( !isNaN( getElementsIdByName( 'liPricePTFMax' ) ) )
	{
		//debug("/ads/scripts/dataLayer/getRange.xml.asp?szRangeName=PropertyPriceBuying&bRangeOverLap=0&bAllRanges=0");
		if( arrSections[ iSectionToShow ] == 'Purchase Options' )
		{
			asc_loadRanges.call("/ads/scripts/dataLayer/getRange.xml.asp?szRangeName=PropertyPriceBuying&bRangeOverLap=0&bAllRanges=0", getElementsIdByName( 'liPricePTFMax' ) );	  
		}
		else
		{	
			asc_loadRanges.call("/ads/scripts/dataLayer/getRange.xml.asp?szRangeName=PropertyPriceRenting&bRangeOverLap=0&bAllRanges=0", getElementsIdByName( 'liPricePTFMax' ) );	  
		}
	}
}

function asc_range_Event(status,statusText,responseText,responseXML,control)
{
    try
    {
        var s = document.getElementById(control)
        var nodes = responseXML.getElementsByTagName("Ranges");
        var temp = s.options[s.options.selectedIndex].text;
		var tmpVal = s.options[s.options.selectedIndex].value;
		var tmpPostedId;
		var bSelected = false;
		
		switch(s.name)
		{
			case "liNumOfBeds":
				tmpPostedId = szSearchRangeBeds;
				break;
			case "liPricePTFMin":
				tmpPostedId = szSearchRangePriceMin;
				break;
			case "liPricePTFMax":
				tmpPostedId = szSearchRangePriceMax;
				break;
		}
		
        clearChildNodes(s, false);
		if( temp != '' )
		{
			appendOptionElement(s,tmpVal,temp, false);
		}
        var i;

		if( nodes[0].getAttribute("RangeMax") == nodes[1].getAttribute("RangeMin") )
		{
			bOverlap = false;
		}
		else
		{
			bOverlap = true;
		}		

        for(i = 0; i < nodes.length; i++)
        {
            if(nodes[i].getAttribute("RangeMax")==null)
            {
                string_value = nodes[i].getAttribute("RangeMin");
                value = nodes[i].getAttribute("RangeMin");
            }
            else if ( bOverlap )
            {
                string_value = nodes[i].getAttribute("RangeMin");
                value = nodes[i].getAttribute("RangeMin") +","+nodes[i].getAttribute("RangeMax") +","+ nodes[i].getAttribute("DataType");
            }
            else
            {
                string_value = nodes[i].getAttribute("RangeMin") + " - " + nodes[i].getAttribute("RangeMax");
                value = nodes[i].getAttribute("RangeMin") +","+nodes[i].getAttribute("RangeMax") +","+ nodes[i].getAttribute("DataType");
            }
            
			if(tmpPostedId != '' && tmpPostedId == value)
			{
				bSelected = true;
			}
			else
			{
				bSelected = false;
			}
			
            appendOptionElement(
                                s,
                                value,
                                string_value, bSelected
                                );
            max_value = "-1,-1,"+ nodes[i].getAttribute("DataType");
			if ( bOverlap )
			{
				max_range = nodes[i].getAttribute("RangeMin") + "+ "
			}else{
				max_range = nodes[i].getAttribute("RangeMax") + "+ "
			}
            //debug(value);
        }
        
        appendOptionElement(
                                s,
                                max_value,
                                max_range, false 
                                );
                                
        s.disabled = false;
        selectOptionValues( s.name ); // This takes the name of the control not the ID, makes sure you pass the name
    }
    catch(Exception)
    {
		if( s != null )
		{
			alert( " asc_range_Event : " + control + " > " + Exception );
		}
    }
}

function asc_localareas_Event(status,statusText,responseText,responseXML,control)
{
	var liSelectedValue
    var s = document.getElementById( getElementsIdByName( control ) );
    var nodes = responseXML.getElementsByTagName("LocalAreas");
    liSelectedValue = clearChildNodes(s, true);
    appendOptionElement(s,"0","All LocalAreas", false);
    if(nodes.length > 0)
    {
        showRow(control);
    }
    try
    {
		var bSelected = false
		
        for(i = 0; i < nodes.length; i++)
        {
			if( liSelectedValue == nodes[i].getAttribute("LocalAreaId") )
			{
				bSelected = true
			}
            appendOptionElement(
                                s,
                                nodes[i].getAttribute("LocalAreaId"),
                                nodes[i].getAttribute("LocalAreaName"), bSelected
                                );
			bSelected = false;
        }
        
    }
    catch(Exception)
    {
		alert( "asc_localareas_Event : " + Exception );
    }
    s.disabled = false;
    selectOptionValues( control ); // This takes the name of the control not the ID, makes sure you pass the name
}

function asc_towns_Event(status,statusText,responseText,responseXML,control)
{
	var liSelected
    //var s = document.getElementById(getElementsIdByName( control ));
    tmp = getElementsByName_iefix('select',control)
    for(iCountTmp = 0; iCountTmp < tmp.length;iCountTmp++)
    {
        s = tmp[iCountTmp];
        var nodes = responseXML.getElementsByTagName("Towns");
        liSelected = clearChildNodes(s, true);
	    if( liSelected == 0 )
	    { 
		    appendOptionElement(s,"0","All Towns", true);
	    }else{
		    appendOptionElement(s,"0","All Towns", false);
	    }
    	
        if(nodes.length > 0)
        {
            showRow(control);
        }
        try
        {
		    var bSelected = false
		    
            for(i = 0; i < nodes.length; i++)
            {
			    if( liSelected == nodes[i].getAttribute("TownID") )
			    {
				    bSelected = true;
			    }
                appendOptionElement(
                                        s,
                                        nodes[i].getAttribute("TownID"),
                                        nodes[i].getAttribute("TownName"), bSelected
                                    );
			    bSelected = false;
            }
            
        }
        catch(Exception)
        {
		    alert( "asc_towns_Event : " + Exception );
        }
        s.disabled = false;
        selectOptionValues( control ); // This takes the name of the control not the ID, makes sure you pass the name
    }
}

function asc_states_Event(status,statusText,responseText,responseXML,control)
{
    try
    {
        var qString = new Querystring()
        if(qString.get('bDebug')== "1")
        {
            alert(responseText)
        }
		var liSelected
        
        tmp = getElementsByName_iefix('select',control)
         
        for(iCountTmp = 0; iCountTmp < tmp.length;iCountTmp++)
        {
            s = tmp[iCountTmp];

            //var s = document.getElementById( getElementsIdByName( control ) );
    		
		    if( s != null )
		    {
			    var nodes = responseXML.getElementsByTagName("States");
			    
			    liSelected = clearChildNodes(s, true);
			    
			    if(qString.get('bDebug')== "1")
                {
                    alert("Display Data: " + nodes.length)
                }
                
			    if( liSelected == 0 )
			    {
				    appendOptionElement(s,"0","All States", true);
			    }else{
				    appendOptionElement(s,"0","All States", false);
			    }
			    if(nodes.length > 0)
			    {
			        if(qString.get('bDebug')== "1")
                    {
                        alert("Showing Row")
                    }
				    showRow(control);
			    }
			    var bSelected = false;
    			
			    
			    for(i = 0; i < nodes.length; i++)
			    {
				    if( liSelected == nodes[i].getAttribute("StateID") )
				    {
					    bSelected = true;
				    }
				    appendOptionElement(
										    s,
										    nodes[i].getAttribute("StateID"),
										    nodes[i].getAttribute("StateName"), bSelected
									    );
				    bSelected = false;
			    }
			    
			    s.disabled = false;
			    selectOptionValues( control ); // This takes the name of the control not the ID, makes sure you pass the name
		    }
		    else
		    {
		        if(qString.get('bDebug')== "1")
                {
                    alert("s = " + s)
                }
		    }
		}
    }
    catch(Exception)
    {
        alert( "asc_states_Event : " + Exception );
    }
}

function asc_countries_Event(status,statusText,responseText,responseXML,control)
{
    try
    {
		var liSelected
        //var s = document.getElementById( getElementsIdByName( control ) );	
        tmp = getElementsByName_iefix('select',control)
        for(iCountTmp = 0; iCountTmp < tmp.length;iCountTmp++)
        {
            s = tmp[iCountTmp];
            var nodes = responseXML.getElementsByTagName("Countries");
            //var temp = s.options[s.options.selectedIndex].text;
		    //var tmpVal = s.options[s.options.selectedIndex].value;
            liSelected = clearChildNodes(s, true);
		    if( liSelected == 0 )
		    {
			    appendOptionElement(s,"0","Please Choose", true);
		    }else{
			    appendOptionElement(s,"0","Please Choose", false);
		    }

            if(nodes.length > 0)
            {
                showRow( control );
            }
		    var bSelected = false;
            for(i = 0; i < nodes.length; i++)
            {
			    if( liSelected == nodes[i].getAttribute("CountryID") )
			    {
				    //bSelected = true;
			    }
                appendOptionElement(
                                        s,
                                        nodes[i].getAttribute("CountryID"),
                                        nodes[i].getAttribute("CountryName"), bSelected
                                    );
			    bSelected = false;
            }
            s.disabled = false;
            
		    
		    if( 0 != 0 )
		    {	
			    for( var iCountryList = 0; iCountryList < s.length; iCountryList ++ )
			    {
				    if( s[ iCountryList ].value == '0' )
				    {
					    if( document.all )
					    {
						    s.selectedIndex = iCountryList;
						    var timer = setTimeout(  'document.getElementById(  getElementsIdByName( \'' + control + '\' ) ).selectedIndex = ' + iCountryList, 1 );
					    }		
					    else
					    {	
						    s.options[ iCountryList ].selected = true;
					    }
				    }
			    }
			    s.onchange();
		    }
		    
		}
		//selectOptionValues( control ); // This takes the name of the control not the ID, makes sure you pass the name
    }
    catch(Exception)
    {
        alert( "asc_countries_Event : " + Exception);
    }
}

function asc_properties_Event(status,statusText,responseText,responseXML,control)
{
    var s = document.getElementById( getElementsIdByName( control ) );
	var szPropertyShowHideStatus;
    var nodes = responseXML.getElementsByTagName("Property");
    clearChildNodes(s, false);
    appendOptionElement(s,"0","All Items", false); 
	
    for(i = 0; i < nodes.length; i++)
    {	
		szPropertyShowHideStatus = "";
		if( nodes[i].getAttribute("bShowAdvert") == 0 )
		{
			szPropertyShowHideStatus = " (hidden)";
		}
        appendOptionElement(
                                s,
                                nodes[i].getAttribute("liPropertyPkRef"),
                                nodes[i].getAttribute("szPropertyDetail") + szPropertyShowHideStatus, false
                            );
		
    }
    s.disabled = false;
    selectOptionValues( control ); // This takes the name of the control not the ID, makes sure you pass the name
}

function asc_wanted_Event(status,statusText,responseText,responseXML,control)
{
    var s = document.getElementById(control);
    var nodes = responseXML.getElementsByTagName("WantedAds_SavedSearches");
    clearChildNodes(s, false);
    appendOptionElement(s,"0","All Wanted Notices", false); 
    for(i = 0; i < nodes.length; i++)
    {
        appendOptionElement(
                                s,
                                nodes[i].getAttribute("liSavedSearchPk"),
                                nodes[i].getAttribute("szWantedAdvertHeadline"), false
                            );
    }
    s.disabled = false;
    selectOptionValues( control ); // This takes the name of the control not the ID, makes sure you pass the name
}

function getLocalAreas(parentControl,control)
{
    asc_localareas = new Asynchronous();
    asc_localareas.complete = asc_localareas_Event;
    var id = parentControl.value;
    if(id > 0)
    {
        asc_localareas.call('/ads/scripts/dataLayer/getRegions.xml.asp?iRegion=3&liIdValue=' + id,control);    
    }
    
}

function getLocalAreasWithTownId(id,control)
{
    asc_localareas = new Asynchronous();
    asc_localareas.complete = asc_localareas_Event;
    if(id > 0)
    {
        asc_localareas.call('/ads/scripts/dataLayer/getRegions.xml.asp?iRegion=3&liIdValue=' + id,control);    
    }
    
}

function getTowns(parentControl,control)
{
    asc_towns = new Asynchronous();
    asc_towns.complete = asc_towns_Event;
    var id = parentControl.value;
    if(id > 0)
    {
		//debug( '/ads/scripts/dataLayer/getRegions.xml.asp?iRegion=2&liIdValue=' + id );
        asc_towns.call('/ads/scripts/dataLayer/getRegions.xml.asp?iRegion=2&liIdValue=' + id,control);    
    }
}

function getTownsWithStateId(id,control)
{
    asc_towns = new Asynchronous();
    asc_towns.complete = asc_towns_Event;
    if(id > 0)
    {
		//debug( '/ads/scripts/dataLayer/getRegions.xml.asp?iRegion=2&liIdValue=' + id );
        asc_towns.call('/ads/scripts/dataLayer/getRegions.xml.asp?iRegion=2&liIdValue=' + id,control);    
    }
}

function getStates(parentControl,control)
{
    asc_states = new Asynchronous();    
    asc_states.complete = asc_states_Event;
    var id = parentControl.value;
    
    var qString = new Querystring()
    if(qString.get('bDebug')== "1")
    {
        alert(id)
    }
    
    if(id > 0)
    {
        asc_states.call('/ads/scripts/dataLayer/getRegions.xml.asp?iRegion=1&liIdValue=' + id,control);    
    }
}

function getCountries( control )
{
	bAllLoaded = false;
	if( 0 == 0 )
	{
		// Load all the country values and then set the first one as the default country
		if( has_been_called[control] )
		{
			return;
		}
		else
		{
			has_been_called[control] = true; 
			asc_countries = new Asynchronous();    
			asc_countries.complete = asc_countries_Event;
			asc_countries.call('/ads/scripts/dataLayer/getRegions.xml.asp?iRegion=0&liIdValue=1&liSatelliteSiteId=29',control);
		}
	}
	else
	{
		// Set the value of the liCountryPkRef drop down to the default country value, hide the row and run getStates and reset all the locations.
		control = document.getElementById( getElementsIdByName( control ), false );
		appendOptionElement( control, "0","", false); 
		for( var iCountryList = 0; iCountryList < control.length; iCountryList ++ )
		{
			if( control[ iCountryList ].value = 0 )
			{
				control.selectedIndex = iCountryList;
			}
		}		
		//control.onchange();
		hideRow( control.name );
	}	
	bAllLoaded = true;
}

function getWantedNotices(control)
{
    asc_wanted = new Asynchronous();
    asc_wanted.complete = asc_wanted_Event;
    asc_wanted.call('/ads/scripts/dataLayer/getWantedAd_SavedSearch.xml.asp?liOwnerPkRef=',control)
}
function getProperties(control)
{
    asc_properties = new Asynchronous();    
    asc_properties.complete = asc_properties_Event;
    asc_properties.call('/ads/scripts/dataLayer/getProperties.xml.asp?liOwnerPkRef=',control);
}
function asc_delProp_Event(status,statusText,responseText,responseXML,control)
{
    window.location.href = window.location.href;
}
function deleteProperty(control)
{
    var control = document.getElementById(getElementsIdByName( control ));
    var liPropertyPkRef = control.options[control.selectedIndex].value
    if(liPropertyPkRef > 0)
    {
        asc_delProp = new Asynchronous();
        asc_delProp.complete = asc_delProp_Event;
        asc_delProp.call('/ads/scripts/dataLayer/deleteProperty.xml.asp?liPropertyPkRef=' + liPropertyPkRef,null)
    }
}

function getRange(control,id,iOverlap)
{
    //Get A Range Once For Each Control???
    if(has_been_called[control])
    {
        return;
    }
    else
    {
        has_been_called[control] = true;   
        asc_range = new Asynchronous();
        asc_range.complete = asc_range_Event
		//debug( '/ads/scripts/dataLayer/getRange.xml.asp?liRangeRef=' + id + '&iRangeOverlap=' + iOverlap + " > '" + control + "' = " + getElementsIdByName( control ) );
        asc_range.call('/ads/scripts/dataLayer/getRange.xml.asp?liRangeRef=' + id + '&iRangeOverlap=' + iOverlap ,getElementsIdByName( control ));
			
    }
	
	if( control == 'liPricePTFMax_WA' )
	{
		var ctrlRdoRentBuy = document.getElementById("rdoRentingBuying_WA")
		// Load the appropriate range for the site selection.
		asc_loadRanges = new Asynchronous();
		asc_loadRanges.complete = asc_range_Event;
		if( !isNaN( getElementsIdByName( 'liPricePTFMax_WA' ) ) )
		{
			if( ctrlRdoRentBuy.value == 1 )
			{
				asc_loadRanges.call("/ads/scripts/dataLayer/getRange.xml.asp?szRangeName=PropertyPriceBuying&bRangeOverLap=0&bAllRanges=0", getElementsIdByName( 'liPricePTFMax_WA' ) );	  
				document.getElementById( "lblPPTFLabel_WA" ).innerHTML = " Price";
			}
			else
			{	
				asc_loadRanges.call("/ads/scripts/dataLayer/getRange.xml.asp?szRangeName=PropertyPriceRenting&bRangeOverLap=0&bAllRanges=0", getElementsIdByName( 'liPricePTFMax_WA' ) );	  
				document.getElementById( "lblPPTFLabel_WA" ).innerHTML = " Budget </b>per <b>Month (GBP)";
			}
		}
    }

}
function asc_defCurr_Event(status,statusText,responseText,responseXML,control)
{
    var liCurrency = document.getElementById( getElementsIdByName( control ) );
    /// liRooms is null so try to get the element by its name
    if(liCurrency == null)
    {
        var tmp = getElementsByName_iefix('select',control);
        liCurrency = tmp[0];
    }
    var nodes = responseXML.getElementsByTagName("SatelliteSite");
    if(nodes.length > 0 )
    {
        for(iCount = 0; iCount < nodes.length; iCount++)
        {    
            for(i = 0; i < liCurrency.options.length; i++)
            {
                if(liCurrency.options[i].text == nodes[iCount].getAttribute("defaultCurrency"))
                {
                    liCurrency.options[i].selected = true;
                }
            }
        }
    }
}
function setDefCurr(control)
{
    asc_defCurr = new Asynchronous();
	asc_defCurr.complete = asc_defCurr_Event;
	asc_defCurr.call("/ads/scripts/dataLayer/getSatelliteSiteDefaults.xml.asp",control);
}

function resetLocations( country, state, town, area )
{
    if(country > '')
    {
		if( getElementsIdByName( country ) != null )
		{
			//clearChildNodes( document.getElementById(getElementsIdByName( country )), false );
			//appendOptionElement(document.getElementById(getElementsIdByName( country )),"0","Countries", false); 
			try
			{
				hideRow(country);
			}
			catch(Exception)
			{
				alert( "resetLocations : '" + country + "','" + state + "','" + town + "','" + area + "' > " + Exception );
			}
		}
    }
    if(state > '')
    {
		if( getElementsIdByName( state ) != null )
		{
			//clearChildNodes( document.getElementById(getElementsIdByName( state )), false );
			//appendOptionElement(document.getElementById(getElementsIdByName( state )),"0","States", false); 
			try
			{
				//hideRow(state);
			}
			catch(Exception)
			{
				alert( "resetLocations : '" + country + "','" + state + "','" + town + "','" + area + "' > " + Exception );
			}
		}
    }
    if(town > '')
    {
		if( getElementsIdByName( town ) != null )
		{
			//clearChildNodes(document.getElementById(getElementsIdByName( town )), false);
			//appendOptionElement(document.getElementById(getElementsIdByName( town )),"0","Towns", false); 
			try
			{
				hideRow(town);
			}
			catch(Exception)
			{
				alert( "resetLocations : '" + country + "','" + state + "','" + town + "','" + area + "' > " + Exception );
			}
		}
    }
    if(area > '')
    {
		if( getElementsIdByName( area ) != null )
		{
			//clearChildNodes(document.getElementById(getElementsIdByName( area )), false);
			//appendOptionElement(document.getElementById(getElementsIdByName( area )),"0","Areas", false); 
			try
			{
				hideRow(area);
			}
			catch(Exception)
			{
				alert( "resetLocations : '" + country + "','" + state + "','" + town + "','" + area + "' > " + Exception );
			}
		}
    }
}

function debug(debug_text)
{
    document.getElementsByTagName("body").item(0).appendChild(document.createTextNode(debug_text));
    document.getElementsByTagName("body").item(0).appendChild(document.createElement("br"));
}

/// display the edit section
function showEditSection(szTableName)
{
    /// make the section for editing links visible
    var tblEdit = document.getElementById(szTableName);
    /// tblEdit is null so try to get the element by its name
    if(tblEdit == null)
    {
        var tmp = getElementsByName_iefix('table',szTableName);
        tblEdit= tmp[0];
    }
    if(document.all)
    {
        tblEdit.style.display = "block";
    }
    else
    {
        tblEdit.style.display = "table";
    }	
}
/// hide the edit section
function hideEditSection(szTableName)
{
    /// make the section for editing links visible
    var tblEdit = document.getElementById(szTableName);
    /// tblEdit is null so try to get the element by its name
    if(tblEdit == null)
    {
        var tmp = getElementsByName_iefix('table',szTableName);
        tblEdit= tmp[0];
    }
    tblEdit.style.display = "none";	
}

function checkRadioButtons(controlName)
{
    var controls = document.getElementsByName(controlName);
    for(i = 0 ; i < controls.length; i++)
    {  
        if(controls[i].checked)
        {
            return true;
        }
    }
    return false;
}

function ammendXML(parentControl,control)
{
    if(control.checked == true)
    {
        var xml = document.getElementById(getElementsIdByName( parentControl )).value;
        
        xml_output = '<?xml version="1.0" encoding="utf-8"?><Root>';
        if(xml > "")
        {
            var xmlDoc = loadXML(xml);
            
            var xmlSet = xmlDoc.getElementsByTagName("xmlfid");
            for(i = 0; i < xmlSet.length; i++)
            {
                xml_output += '<xmlfid liFeatureListID="' + xmlSet[i].getAttribute("liFeatureListID") + '"/>'
            } 
        }
        xml_output += '<xmlfid liFeatureListID="' + control.id + '"/>'
        xml_output += '</Root>'
        document.getElementById(getElementsIdByName( parentControl )).value = xml_output;
    }
    else
    {
        var xml = document.getElementById(getElementsIdByName( parentControl )).value;
        xml_output = '<?xml version="1.0" encoding="utf-8"?><Root>';
        if(xml > "")
        {
            var xmlDoc = loadXML(xml);
            var xmlSet = xmlDoc.getElementsByTagName("xmlfid");
            for(i = 0; i < xmlSet.length; i++)
            {
                if(xmlSet[i].getAttribute("liFeatureListID") != control.id)
                {
                    xml_output += '<xmlfid liFeatureListID="' + xmlSet[i].getAttribute("liFeatureListID") + '"/>'
                }
            } 
        }
        xml_output += '</Root>'
        //alert(xml_output);
        document.getElementById(getElementsIdByName( parentControl )).value = xml_output;
    }
}

var bGetStates = false;
function getStatesOnce(parentControl,control)
{
    if(!bGetStates)
    {
        var parentControl = document.getElementById(getElementsIdByName( parentControl ));
        getStates(parentControl,control);
    }
    bGetStates = true;
}



function inArray(array,find)
{
    for(i = 0; i < array.length; i++)
    {
        if(array[i] == find)
        {
            alert(array[i]);
            //return true;
         
        }
    }
    return false;
}

function hideAllSelect(exceptions)
{
    var options = document.getElementsByTagName("select");
    //debug("showAllSelect()");
    for(i = 0; i < options.length; i++)
    {
        options[i].style.visibility = "hidden";
    }
    for(j = 0; j < exceptions.length; j++)
    {
        document.getElementById(exceptions[j]).style.visibility = "visible"
    }
}

function showAllSelect(exceptions)
{
    var options = document.getElementsByTagName("select");
   // debug("showAllSelect()");
    for(i = 0; i < options.length; i++)
    {
        options[i].style.visibility = "visible";
    }
    for(j = 0; j < exceptions.length; j++)
    {
        document.getElementById(exceptions[j]).style.visibility = "hidden"
    }
}

function featureHasChanged(control,section)
{
    var section = document.getElementById('hasChanged_' + section).value = 1
    if(control != null)
    {
        var control = document.getElementById('hasChanged_' + getElementsIdByName( control ));
        control.value = 1;
    }
}


function asc_loadfeatures_Event(status,statusText,responseText,responseXML,control)
{
    var s = document.getElementById(getElementsIdByName( control ));
    var nodes = responseXML.getElementsByTagName("FeatureList");
    clearChildNodes(s, false);
    //appendDefaultOptionElement(s); 
    for(i = 0; i < nodes.length; i++)
    {
        appendOptionElement(
                                s,
                                nodes[i].getAttribute("liFeaturePk") + "|" + nodes[i].getAttribute("iIsJScript") + "|" + nodes[i].getAttribute("iDataSource"),
                                nodes[i].getAttribute("szFeatureItemValue"), false
                            );
    }
    s.disabled = false;
    selectOptionValues();
}

function loadFeatures(control,iFeatureType,bFeaturesInFeatures,bSystemFeatures,liAssociatedSection,iIsJScript,liFeaturePk)
{
    asc_loadfeatures = new Asynchronous();
    asc_loadfeatures.complete = asc_loadfeatures_Event;
    asc_loadfeatures.call("scripts/dataLayer/getFeatures.xml.asp?iFeatureType=" + iFeatureType + "&bFeaturesInFeatures=" + bFeaturesInFeatures + "&bSystemFeatures=" + bSystemFeatures + "&liAssociatedSection=" + liAssociatedSection + "&iIsJScript=" + iIsJScript + "&liFeaturePk=" + liFeaturePk,control);
    
    //debug("scripts/dataLayer/getFeatures.xml.asp?iFeatureType=" + iFeatureType + "&bFeaturesInFeatures=" + bFeaturesInFeatures + "&bSystemFeatures=" + bSystemFeatures + "&liAssociatedSection=" + liAssociatedSection + "&iIsJScript=" + iIsJScript + "&liFeaturePk=" + liFeaturePk);
}

function asc_featureInfo_Event(status,statusText,responseText,responseXML,control)
{

    //<input type=""text class=""textbox"" value=""" & objFeats(iCountFeat).getAttribute("szFriendlyFeatureName") &""" id=""friendlyname_" & objFeats(iCountFeat).getAttribute("szFeatureName") & """ class=""textbox"" name=""szFriendlyFeatureName""/><
    var nodes = responseXML.getElementsByTagName("FeatureList");
    
   
    for(i = 0; i < nodes.length; i++)
    {
        var lastRow = control.rows.length -1;
        var row = control.insertRow(lastRow);
        row.setAttribute("id","row_" + nodes[i].getAttribute("szFeatureItemValue"));
        var cell = row.insertCell(0);
        
        var input = document.createElement("input");
         
        input.setAttribute("type","text");
        input.setAttribute("class","textbox");
        input.setAttribute("value",nodes[i].getAttribute("szFeatureItemValue"));
        input.setAttribute("name","szFriendlyFeatureName");
        cell.appendChild(input);
        
        cell = row.insertCell(1);
        switch(nodes[i].getAttribute("iFeatureType"))
        {
            case "0":
                //<input type=""text"" class=""textbox"" name=""szFeatureName"" id=""" & objFeats(iCountFeat).getAttribute("szFeatureName") & """/>
                input = document.createElement("input");
                input.setAttribute("type","text");
                input.setAttribute("class","textbox");
                input.setAttribute("value",nodes[i].getAttribute("szFeatureName"));
                input.setAttribute("name","szFeatureName");
                cell.appendChild(input);
                
                break;
            case "1":
                //Response.Write "<input type=""checkbox"" class=""checkbox"" name=""" & objFeats(iCountFeat).getAttribute("szFeatureName") & """ id=""" & objFeats(iCountFeat).getAttribute("szFeatureName") & """/>"
                input = document.createElement("input");
                input.setAttribute("type","checkbox");
                input.setAttribute("class","checkbox");
                input.setAttribute("name",nodes[i].getAttribute("szFeatureName"));
                input.setAttribute("id",nodes[i].getAttribute("szFeatureName"));
                cell.appendChild(input);
                
                break;
            case "2":
                //<textarea name=""FeaturesInFeature"" style=""display:none;"" id=""tempXML_" & objFeats(iCountFeat).getAttribute("szFeatureName") & """><Root>" & temp_XML & "</Root></textarea>"
                //        Response.Write "<select class=""select""><option>&nbsp;</option></select>
                input = document.createElement("textarea");
                input.setAttribute("name","FeaturesInFeature");
                input.setAttribute("id","tempXML_" + nodes[i].getAttribute("szFeatureName"));
                input.setAttribute("style","display:none;");
                input.value = "<Root></Root>";
                cell.appendChild(input);
                
                
                input = document.createElement("select");
                input.setAttribute("class","select");
                cell.appendChild(input);
                
                cell.appendChild(document.createTextNode(" "));
                
                //<a href=""javascript:showAmmendSelect('tempXML_" & objFeats(iCountFeat).getAttribute("szFeatureName") & "');"">Edit</a>" & vbCrLf
                a = document.createElement("a");
                a.setAttribute("href","javascript:showAmmendSelect('tempXML_" + nodes[i].getAttribute("szFeatureName") + "');");
                a.appendChild(document.createTextNode("Edit"));
                cell.appendChild(a);
                break;
            case "3":
                //<textarea class=""textarea"" name=""" & objFeats(iCountFeat).getAttribute("szFeatureName") & """ id=""" & objFeats(iCountFeat).getAttribute("szFeatureName") & """ onchange=""javascript:featureHasChanged('" & objFeats(iCountFeat).getAttribute("szFeatureName") & "','" & objLst(iCount).getAttribute("szSectionName") & "');""></textarea>"
                input = document.createElement("textarea");
                input.setAttribute("class","textarea");
                input.setAttribute("name","");
                input.setAttribute("id",nodes[i].getAttribute("szFeatureName"));
                cell.appendChild(input);
                break;
            case "4":
                //<input type=""radio"" name=""" & objFeats(iCountFeat).getAttribute("szFeatureName") & """/>
                input = document.createElement("input");
                input.setAttribute("type","radio");
                input.setAttribute("class","radio");
                input.setAttribute("name",nodes[i].getAttribute("szFeatureName"));
                cell.appendChild(input);
                break;
            case "5":
                    
                a = document.createElement("a");
                a.setAttribute("href","javascript:getCalendarDate('" + nodes[i].getAttribute("szFeatureName") + "');");

                img  = document.createElement("img");
                img.setAttribute("id","imgToDate");
                img.setAttribute("alt","Choose Date");
                img.setAttribute("title","Choose Date");
                img.setAttribute("src","../images/seldate.gif");

                a.appendChild(img);
                cell.appendChild(a);

                lbl = document.createElement("lable");
                lbl.setAttribute("id","label_" + nodes[i].getAttribute("szFeatureName"));
                cell.appendChild(lbl);

                input = document.createElement("input");
                input.setAttribute("type","hidden");
                input.setAttribute("name",nodes[i].getAttribute("szFeatureName"));

                cell.appendChild(input);
                break;
            case "6":
                lbl = document.createElement("lable");
                lbl.appendChild(document.createTextNode("Label"));
                cell.appendChild(lbl);
                break;
            case "7":
                lbl = document.createElement("lable");
                lbl.appendChild(document.createTextNode("HTML Object"));
                cell.appendChild(lbl);
                break
        }
        
        cell = row.insertCell(2);
        
        cell.appendChild(document.createTextNode("Visible: "));
        
        input = document.createElement("input");
        input.setAttribute("type","checkbox");
        input.setAttribute("class","checkbox");
        input.setAttribute("name","bFeatureVisible");
        input.setAttribute("value",1);
        cell.appendChild(input);
        
        cell.appendChild(document.createTextNode("Required: "));
        
        input = document.createElement("input");
        input.setAttribute("type","checkbox");
        input.setAttribute("class","checkbox");
        input.setAttribute("name","bFeatureOptional");
        input.setAttribute("value",1);
        cell.appendChild(input);
        
        input = document.createElement("input");
        input.setAttribute("type","hidden");
        input.setAttribute("name","iFeatureType");
        input.setAttribute("value",nodes[i].getAttribute("iFeatureType"));
        cell.appendChild(input);
        
        input = document.createElement("input");
        input.setAttribute("type","hidden");
        input.setAttribute("name","iFeatureDataLength");
        input.setAttribute("value",nodes[i].getAttribute("iFeatureDataLength"));
        cell.appendChild(input);
        
        input = document.createElement("input");
        input.setAttribute("type","hidden");
        input.setAttribute("name","liFeatureId");
        input.setAttribute("value",nodes[i].getAttribute("liFeatureId"));
        cell.appendChild(input);
        
        input = document.createElement("input");
        input.setAttribute("type","hidden");
        input.setAttribute("name","liFeatureInSectionPk");
        input.setAttribute("value",nodes[i].getAttribute("liFeatureInSectionPk"));
        cell.appendChild(input);
        
        input = document.createElement("input");
        input.setAttribute("type","hidden");
        input.setAttribute("name","iFeatureType");
        input.setAttribute("value",nodes[i].getAttribute("iFeatureType"));
        cell.appendChild(input);
        
        input = document.createElement("input");
        input.setAttribute("type","hidden");
        input.setAttribute("name","hasChanged");
        input.setAttribute("id","hasChanged_" + nodes[i].getAttribute("szFeatureName"));
        input.setAttribute("value",1);
        cell.appendChild(input);
        
        var section = (control.id.replace("select_feature_",""));
        
        cell = row.insertCell(3);
        //<a href=""javascript:moveTRUp('" & objLst(iCount).getAttribute("szSectionName") & "','row_" & objFeats(iCountFeat).getAttribute("szFeatureName") & "');""><img src=""images/up.gif"" alt=""Up""/></a><br/><a href=""javascript:moveTRDown('" & objLst(iCount).getAttribute("szSectionName") & "','row_" & objFeats(iCountFeat).getAttribute("szFeatureName") & "');""><img src=""images/down.gif"" alt=""Down""/></a>
        a = document.createElement("a");
        a.setAttribute("href","javascript:moveTRUp('row_" + nodes[i].getAttribute("szFeatureItemValue") + "',document.getElementById('row_" + nodes[i].getAttribute("szFeatureItemValue") + "').previousSibling)");
        img = document.createElement("img");
        img.setAttribute("src","images/up.gif");
        img.setAttribute("alt","Up");
        a.appendChild(img);
        cell.appendChild(a);
        cell.appendChild(document.createElement("br"));
        
        a = document.createElement("a");
        a.setAttribute("href","javascript:moveTRDown('row_" + nodes[i].getAttribute("szFeatureItemValue") + "',document.getElementById('row_" + nodes[i].getAttribute("szFeatureItemValue") + "').previousSibling.previousSibling);");
        img = document.createElement("img");
        img.setAttribute("src","images/down.gif");
        img.setAttribute("alt","Down");
        a.appendChild(img);
        cell.appendChild(a);
    }
    selectOptionValues();
}

function addSectionToForm()
{
    var random_Id = Math.random();
    random_Id = (random_Id * 100000) + '';
    random_Id = random_Id.substr(0,5);
    var table = document.createElement("table");
    table.setAttribute("class","wizardSectionTable");
    table.setAttribute("name","newsection");
    table.setAttribute("id",random_Id);
    
    var caption = table.createCaption();
    
    var input = document.createElement("input");
    input.setAttribute("type","text");    
    input.setAttribute("class","textbox");
    input.setAttribute("value","");
    caption.appendChild(input);
    
    input = document.createElement("input")
    input.setAttribute("type","hidden");
    input.setAttribute("id","hasChanged_" + random_Id);
    
    input = document.createElement("input")
    input.setAttribute("type","hidden");    
    input.setAttribute("class","textbox");
    input.setAttribute("value","");
    caption.appendChild(input);
    
    input = document.createElement("input")
    input.setAttribute("type","hidden");
    input.setAttribute("name","newSection");
    input.setAttribute("value","1")
    caption.appendChild(input);
    
    caption.appendChild(document.createTextNode("Visible: "));
    input = document.createElement("input");
    input.setAttribute("type","checkbox");
    input.setAttribute("class","checkbox");
    input.setAttribute("name","bSectionVisible");
    caption.appendChild(input);
    
    caption.appendChild(document.createTextNode("Caption Visible: "));
    input = document.createElement("inputput");
    input.setAttribute("type","checkbox");
    input.setAttribute("class","checkbox");
    input.setAttribute("name","bCaptionVisible");
    caption.appendChild(input);
    
    
    a = document.createElement("a");
    a.setAttribute("href","javascript:moveTRUp('row_" + random_Id + "',document.getElementById('row_" + random_Id + "').previousSibling)");
    img = document.createElement("img");
    img.setAttribute("src","images/up.gif");
    img.setAttribute("alt","Up");
    a.appendChild(img);
    caption.appendChild(a);
    caption.appendChild(document.createElement("br"));
    
    a = document.createElement("a");
    a.setAttribute("href","javascript:moveTRDown('row_" +  random_Id + "',document.getElementById('row_" +  random_Id + "').previousSibling.previousSibling);");
    img = document.createElement("img");
    img.setAttribute("src","images/down.gif");
    img.setAttribute("alt","Down");
    a.appendChild(img);
    caption.appendChild(a);
    
    var row = table.insertRow(0)
    cell = row.insertCell(0);
    cell.appendChild(document.createTextNode("Add Feature"));
    cell = row.insertCell(1);
    
    var select = document.createElement("select");
    select.setAttribute("id","select_feature_" + random_Id);
    select.setAttribute("class","select");
    cell.appendChild(select);
    
    cell = row.insertCell(2);
    input = document.createElement("input");
    input.setAttribute("type","button");
    input.setAttribute("class","button");
    input.setAttribute("value","Add");
    input.setAttribute("onclick","javascript:addFeatureToForm('select_feature_" + random_Id  + "','" + random_Id + "');");
    cell.appendChild(input);
    
    cell = row.insertCell(3);
    cell.appendChild(document.createTextNode(" "));
    
    siW = document.getElementById("stepInWizard");
    var lastRow = siW.rows.length -1;
    var row = siW.insertRow(lastRow);
    row.setAttribute("id","row_" + random_Id);
    row.appendChild(table);
    loadFeatures("select_feature_" + random_Id,'null','null','null','null','null','null');
}
 
function addFeatureToForm(control,output)
{
    var control = document.getElementById(control);
    var output = document.getElementById(output);
 
    asc_featureInfo = new Asynchronous();
    asc_featureInfo.complete = asc_featureInfo_Event;
    temp = control.value.split('|');
    asc_featureInfo.call("scripts/dataLayer/getFeatures.xml.asp?iFeatureType=null&bFeaturesInFeatures=null&bSystemFeatures=null&liAssociatedSection=null&iIsJScript=null&liFeaturePk=" + temp[0],output);
    
}

function addFeature(control_input,control_output)
{
    var control_output = document.getElementById(control_output);
    var control_input = document.getElementById(control_input);
    if(!checkOptionExists(
                            control_output,
                            control_input.options[control_input.options.selectedIndex].value,
                            control_input.options[control_input.options.selectedIndex].text
                        )
                        
        )
    {
        appendOptionElement(
                            control_output,
                            control_input.options[control_input.options.selectedIndex].value,
                            control_input.options[control_input.options.selectedIndex].text, false
                            )
        control_input.options.selectedIndex = 0;
    }
    else
    {
        alert("This feature already exists in this list, please select another feature.");
    }
}

function checkOptionExists(control,value,text)
{
    for(i = 0; i < control.options.length; i++)
    {
        if(control.options[i].text == text && control.options[i].value == value)
        {
            return true;
        }
    }
    return false;
}

function getParentTbody(obj)
{
    var tmp = obj;
    while (tmp = tmp.parentNode)
    {
        if (tmp.nodeName.toUpperCase() == "TBODY")
        {
            return tmp;
        }
    }
}

function moveTRUp(controlId,prevRow)
{
    var row = document.getElementById(controlId);
    var rowParent = getParentTbody(row);
    rowParent.insertBefore(row, prevRow);
    
}

function moveTRDown(controlId,nextRow)
{
    var row = document.getElementById(controlId);
    var rowParent = getParentTbody(row);
    rowParent.insertBefore(row, nextRow);
}

//check to see if its IE and then make the changes
if(!document.all)
{
    Document.prototype.loadXML = function( s ) 
    {
       // parse the string to a new doc
       var doc2 = (new DOMParser()).parseFromString(s, "text/xml");

       // remove all initial children
       while (this.hasChildNodes())
          this.removeChild(this.lastChild);

       // insert and import nodes
       for (var i = 0; i < doc2.childNodes.length; i++) {
          this.appendChild(this.importNode(doc2.childNodes[i], true));
       }
   };
}

function loadXML(xml)
{
    //load xml file
    // code for IE
    if (window.ActiveXObject)
    {
        xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
        xmlDoc.async=false;
        xmlDoc.loadXML(xml);
        return xmlDoc
    }
    // code for Mozilla, etc.
    else if (document.implementation &&
        document.implementation.createDocument)
    {
        xmlDoc= document.implementation.createDocument("","Root",null);
        xmlDoc.loadXML(xml);
        return xmlDoc
    }
    else
    {
        alert('Your browser cannot handle this script');
    }
    return null;
}

/*************************
FUNCTIONS FOR AMMENDSELECT   
    * hideAmmendSelect()
    * saveFeatures(control)
    * showAmmendSelect()
    * addFeature(feature_input,feature_output)
    * removeFeature(feature)
    * moveOPTIONUp(control)
    * moveOPTIONDown(control)
    * asc_loadRanges_Event(status,statusText,responseText,responseXML,control)
    * loadRanges(control)
    * loadFeatureList(id,control)
*************************/
//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function replaceAll( str, from, to ) {
    var idx = str.indexOf( from );


    while ( idx > -1 ) {
        str = str.replace( from, to );
        idx = str.indexOf( from );
    }

    return str;
}

function makeSafe(string,flag)
{
    if(flag)
    {
        string = replaceAll(string,'<','&lt;');
        string = replaceAll(string,'>','&gt;');
        string = replaceAll(string,'"','&quot;');
    }
    else
    {
        string = replaceAll(string,'&lt;','<');
        string = replaceAll(string,'&gt;','>');
        string = replaceAll(string,'&quot;','"');
    }
    return string;
}

function hideAmmendSelect()
{
    document.getElementById("ammendSelect").style.visibility = "hidden";
    document.getElementById("overlay_ammendSelect").style.visibility = "hidden";
    showAllSelect(Array('features_list','features_szFeat','FeaturesListDataSource'));
    
}

function saveFeatures(control)
{
    var xml = "<Root>";
    var szFeat = document.getElementById("features_szFeat")
    for(i = 0; i < szFeat.options.length;i++)
    {
        //alert(szFeat.options[i].value);
        //<FeaturesInFeature liFeatureId="90" szFeatureName="getTowns( this, 'liTownRef' );" iIsJScript="1"/>
        var temp = szFeat.options[i].value.split('|');
        xml += '<FeaturesInFeature liFeatureId="' + temp[0] + '" szFeatureName="' + makeSafe(szFeat.options[i].text,true) +'" iIsJScript="' + temp[1] + '" iDataSource="' + temp[2] + '"/>'
    }
    xml += "</Root>"
    document.getElementById(control).value = xml;
    hideAmmendSelect();
}

function showAmmendSelect(xmlSource)
{
    document.getElementById("FeaturesListDataSource").options[0].selected = "selected"
    hideAllSelect(Array('features_list','features_szFeat','FeaturesListDataSource'));
    document.getElementById("ammendSelect").style.top = ((document.all)?document.body.scrollTop:window.pageYOffset) + 100;
    var arrayPageSize = getPageSize();
    document.getElementById("overlay_ammendSelect").style.height = arrayPageSize[1];
    var xml = document.getElementById(xmlSource).value;
    //alert(xmlSource);
    var xmlDoc = loadXML(xml);
    var xmlSet = xmlDoc.getElementsByTagName("FeaturesInFeature");
    
    //alert(xmlSet.length)
    clearChildNodes(document.getElementById("features_szFeat"), false);
    for(i = 0; i < xmlSet.length; i++)
    {
        appendOptionElement(
                                document.getElementById("features_szFeat"),
                                xmlSet[i].getAttribute("liFeatureId") + "|" + xmlSet[i].getAttribute("iIsJScript"),
                                makeSafe(xmlSet[i].getAttribute("szFeatureName"),false), false
                            );
    }
    document.getElementById("save_feature_XML").href = "javascript:saveFeatures('" + xmlSource  + "')";
    
    loadFeatures('features_list','null',1,'null','null','null','null');
    document.getElementById("ammendSelect").style.visibility = "visible";
    document.getElementById("overlay_ammendSelect").style.visibility = "visible";
}

function addFeature(feature_input,feature_output)
{
    var feature_input = document.getElementById(feature_input);
    var feature_output = document.getElementById(feature_output);
    if(!checkOptionExists(
                            feature_output,
                            feature_input.options[feature_input.selectedIndex].value,
                            feature_input.options[feature_input.selectedIndex].text
                        )
        )
    {
        appendOptionElement(
                                feature_output,
                                feature_input.options[feature_input.selectedIndex].value,
                                feature_input.options[feature_input.selectedIndex].text, false
                            );
    }
    else
    {
        alert("This feature already exists in this list, please select another feature.");
    }
    
}

function removeFeature(feature)
{
    var feature = document.getElementById(feature);
    var iSelected = feature.options.selectedIndex;
    feature.remove(feature.options.selectedIndex);
    feature.options.selectedIndex = iSelected;
}

function moveOPTIONUp(control)
{
    var objList = document.getElementById(control);
	if (objList.selectedIndex > 0)
	{
		var tmpText = objList[objList.selectedIndex - 1].innerHTML;
		var tmpValue = objList[objList.selectedIndex - 1].value;
		objList[objList.selectedIndex - 1].innerHTML = objList[objList.selectedIndex].innerHTML;
		objList[objList.selectedIndex - 1].value = objList[objList.selectedIndex].value;
		objList[objList.selectedIndex].innerHTML = tmpText;
		objList[objList.selectedIndex].value = tmpValue;
		objList.selectedIndex = objList.selectedIndex - 1
	}
}

function moveOPTIONDown(control)
{
    var objList = document.getElementById(control);
	if (objList.selectedIndex > -1 && objList.selectedIndex < (objList.length - 1))
	{
		var tmpText = objList[objList.selectedIndex + 1].innerHTML;
		var tmpValue = objList[objList.selectedIndex + 1].value;
		objList[objList.selectedIndex + 1].innerHTML = objList[objList.selectedIndex].innerHTML;
		objList[objList.selectedIndex + 1].value = objList[objList.selectedIndex].value;
		objList[objList.selectedIndex].innerHTML = tmpText;
		objList[objList.selectedIndex].value = tmpValue;
		objList.selectedIndex = objList.selectedIndex + 1
	}
}

function filter_list(control,filter)
{
    var control = document.getElementById(control);
    var re = new RegExp(filter);
    control.size = "10"
    var itemsVisible = 0
    for(i = 0; i < control.options.length; i++)
    {
        if(control.options[i].text.match(re))
        {
            control.options[i].style.display = "block";
            itemsVisible++;
        }
        else
        {
            control.options[i].style.display = "none";
        }
    }
    if(itemsVisible > 0)
    {
        document.getElementById("filter").className = "textbox";
    }
    else
    {
        document.getElementById("filter").className = "textboxInvalid";
    }
}

function asc_loadRanges_Event(status,statusText,responseText,responseXML,control)
{
    //alert(responseText);
    //liRangePkRef="470" RangeMin="Jun 21 2006 12:00AM" RangeMax="Dec 13 2006 12:00AM" RangeMultiplier="1.00" RangeUnits="months" RangeDataType="date"
    var s = document.getElementById(control);
    var nodes = responseXML.getElementsByTagName("Ranges");
    clearChildNodes( s, false );
    for(i = 0; i < nodes.length; i++)
    {
        appendOptionElement(
                                s,
                                nodes[i].getAttribute("liRangePkRef"),
                                nodes[i].getAttribute("RangeMin") + " - " + nodes[i].getAttribute("RangeMax") + " increments of " + nodes[i].getAttribute("RangeMultiplier") + " " + nodes[i].getAttribute("RangeUnits"), false
                            );
    }
        appendOptionElement(
                                s,
                                nodes[i].getAttribute("liRangePkRef"),
                                nodes[i].getAttribute("RangeMax") + "+ increments of " + nodes[i].getAttribute("RangeMultiplier") + " " + nodes[i].getAttribute("RangeUnits"), false
                            );
    selectOptionValues();
    
}

function loadRanges(control)
{
    asc_loadRanges = new Asynchronous();
    asc_loadRanges.complete = asc_loadRanges_Event;
    asc_loadRanges.call("/ads/scripts/dataLayer/getRange.xml.asp?liRangeRef=0&bRangeOverLap=null&bAllRanges=1",control);
}

function loadFeatureList(id,control)
{
    switch(id)
    {
        case "0":
            loadFeatures('features_list','null',1,'null','null','null','null');
            break;
        case "1":
            getCountries(control);
            break;
        case "2":
            loadRanges(control);
            break;
    }
}

var szDateTarget = "";
function getCalendarDate(szTargetId)
{
	szDateTarget = szTargetId;
	
    var objCalendar = document.getElementById("divCalendar");
    objCalendar.style.display = "";
    var iOffset = 0;
    
    objCalendar.style.left = findPosX(document.getElementById("layer_" + getElementsIdByName(szTargetId))) + 15 + "px";
    objCalendar.style.top = findPosY(document.getElementById("layer_" + getElementsIdByName(szTargetId))) + 15 + "px";
    hideAllSelect(Array('selMonth','selYear'));
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function setCalendarDate(iDay)
{
	var objMonth = document.getElementById("selMonth");
	var szMonth = objMonth[objMonth.selectedIndex].value;
	var objYear = document.getElementById("selYear");
	var szYear = objYear[objYear.selectedIndex].value;
	var objLabel = document.getElementById("label_" + getElementsIdByName(szDateTarget) );
	
	while(objLabel.childNodes.length > 0)
	{
		objLabel.removeChild(objLabel.firstChild);
	}
	
	objLabel.appendChild(document.createTextNode(iDay + '/' + szMonth + '/' + szYear));
	document.getElementById(getElementsIdByName(szDateTarget)).value = iDay + '/' + szMonth + '/' + szYear;
	document.getElementById("divCalendar").style.display = "none";
	showAllSelect(Array('selMonth','selYear'));
}

function closeCalendarDate()
{
    document.getElementById("divCalendar").style.display = "none";
    showAllSelect(Array('selMonth','selYear'));
}


function savePropertyFeature()
{
    asc_save = new Asynchronous()
    asc_save.complete = asc_save_Event;
    var szUrl = ""
    asc_save.call();
}

function openWizard( szUrl )
{
    var randomnumber=Math.floor(Math.random()*11)
    window.open( szUrl ,"postad_wizard_" + randomnumber,"width=700px,height=600px,scrollbars=yes");
}

function loadValue( ctrlControl, szValue )
{
	document.getElementById( getElementsIdByName( ctrlControl ) ).innerHTML = szValue;
}

function constrictInput(evt,bFlag)
{
    switch(bFlag)
    {
        case 0:
            ///numbers only
            var charCode = (evt.which) ? evt.which : evt.keyCode
            if (charCode > 31 && (charCode < 48 || charCode > 57))
            {
                return false;
            }
            return true;
            break;
        case 1:
            //floats only
            var charCode = (evt.which) ? evt.which : evt.keyCode
            if ((charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46))
            {
                return false;
            }
            return true;
            break;
    }
}


function isArray(a)
{
    return isObject(a) && a.constructor == Array;
}

function isObject(a)
{
    return (typeof a == 'object' && !!a) || isFunction(a);
}

function isFunction(a)
{
    return typeof a == 'function';
}

function propFeat(control,hdnXml)
{
    var writeProp = true;
    var hdnXml
    if(isArray(hdnXml))
    {
        //alert(hdnXml[0]);
        hdnXml = document.getElementById( getElementsIdByName( hdnXml[0] ) );
        writeProp = false;
    }
    else
    {
        //alert(hdnXml);
        hdnXml = document.getElementById( getElementsIdByName( hdnXml ) );
    }
    
    var xml = '<?xml version="1.0" encoding="utf-8"?><Root>' + hdnXml.value + '</Root>';
    var xmlDoc = loadXML(xml);
    var xmlSet = xmlDoc.getElementsByTagName("feature");
    
    var script_name = "../scripts/dataLayer/writePropertyFeature.xml.asp?";
    if(control.value == 0 && control.type == "select-one")
    {
        script_name = "../scripts/dataLayer/updatePropertyFeature.xml.asp?";
    }
    var Found = false;
	var liPropFeaturePkRef;
	var iFeatureCount;
	var iSelFeatureIndex;
	var szPropSubFeatRef;

    script_name += "liPropertyPKRef=" + document.getElementById("liRecordPkRef").value + "&";
    xml = '';
    
    for(i = 0; i < xmlSet.length;i++)
    {
        if(xmlSet[i].getAttribute("id") == control.name)
        {
            script_name = "../scripts/dataLayer/updatePropertyFeature.xml.asp?";
            script_name += "liPropFeatPkRef=" + xmlSet[i].getAttribute("liRecordPkRef") + "&";
			liPropFeaturePkRef = xmlSet[i].getAttribute("liRecordPkRef")
            Found = true;
        }
        else
        {
            xml += '<feature id="' + xmlSet[i].getAttribute("id") + '" liRecordPkRef="' + xmlSet[i].getAttribute("liRecordPkRef") + '"/>'
        }
        
    }
    if(!liPropFeaturePkRef > 0)
	{
	    liPropFeaturePkRef = control.id;
	}
    if(writeProp)
    {
        //alert("Writing Property Feature");
        data = Array(script_name,control,hdnXml);

        switch(control.type)
        {
            case "select-one":
                if( ( control.selectedIndex > 0 ) || ( control.options[control.selectedIndex].text != 0 ) )
                {
					if( IsNumeric(control.options[control.selectedIndex].text) )
					{
						iFeatureCount = parseInt( control.options[control.selectedIndex].text );
						iSelFeatureIndex = 0;
						szPropSubFeatRef = "";
					}
					else
					{
						iFeatureCount = 1;
						iSelFeatureIndex = control.selectedIndex;
						szPropSubFeatRef = "liPropertySubFeatRef=" + control.options[ control.selectedIndex ].value + "&";
					}

					asc_feat = new Asynchronous();
					asc_feat.complete = asc_feat_Event;

					asc_feat.call(
									script_name +   
									"liPropertyFeatureRef=" + control.id + "&" +
									szPropSubFeatRef + 
									"iPropertyFeatureCount=" + iFeatureCount + "&" +
									"flPropFeatureWidth=-1&" + 
									"flPropFeatureLength=-1&" + 
									"liSatelliteSiteID=29",
									data
								);
                }
                else
                {
						//delete the feature
						///if( Found )
						///{
							asc_delfeat = new Asynchronous();
							asc_delfeat.complete = asc_delfeat_Event;
							asc_delfeat.call("../scripts/dataLayer/deletePropertyFeature.xml.asp?liPkRefToDelete=" + liPropFeaturePkRef + "&bDeleteTypeFlag=1", data );
						///}
						///else
						///{
						///		alert( "Cannot delete the feature, feature was not found at property." );
						///}
                }
				break;
            case "text":
                if( control.value != "" )
                {
					iFeatureCount = 1;
					szPropFeatDesc = "szPropFeatureDescription=" + control.value + "&";

					asc_feat = new Asynchronous();
					asc_feat.complete = asc_feat_Event;

					asc_feat.call(
									script_name +   
									"liPropertyFeatureRef=" + control.id + "&" +
									szPropFeatDesc + 
									"iPropertyFeatureCount=" + iFeatureCount + "&" +
									"flPropFeatureWidth=-1&" + 
									"flPropFeatureLength=-1&" + 
									"liSatelliteSiteID=29",
									data
								);
                }
                else
                {
						//delete the feature
						///if( Found )
						///{
							asc_delfeat = new Asynchronous();
							asc_delfeat.complete = asc_delfeat_Event;
							asc_delfeat.call("../scripts/dataLayer/deletePropertyFeature.xml.asp?liPkRefToDelete=" + liPropFeaturePkRef + "&bDeleteTypeFlag=1", data );
						///}
						///else
						///{
						///		alert( "Cannot delete the feature, feature was not found at property." );
						///}
                }
                break; 
            case "textarea":
                if( control.value != "" )
                {
					iFeatureCount = 1;
					szPropFeatDesc = "szPropFeatureDescription=" + control.value + "&";

					asc_feat = new Asynchronous();
					asc_feat.complete = asc_feat_Event;

					asc_feat.call(
									script_name +   
									"liPropertyFeatureRef=" + control.id + "&" +
									szPropFeatDesc + 
									"iPropertyFeatureCount=" + iFeatureCount + "&" +
									"flPropFeatureWidth=-1&" + 
									"flPropFeatureLength=-1&" + 
									"liSatelliteSiteID=29",
									data
								);
                }
                else
                {
						//delete the feature
						///if( Found )
						///{
							asc_delfeat = new Asynchronous();
							asc_delfeat.complete = asc_delfeat_Event;
							asc_delfeat.call("../scripts/dataLayer/deletePropertyFeature.xml.asp?liPkRefToDelete=" + liPropFeaturePkRef + "&bDeleteTypeFlag=1", data );
						///}
						///else
						///{
						///		alert( "Cannot delete the feature, feature was not found at property." );
						///}
                }
                break; 
            case "checkbox":
                if( control.checked )
                {
                    //alert(control.name);
                    asc_feat = new Asynchronous();
                    asc_feat.complete = asc_feat_Event;
                    
                    asc_feat.call(
                                    script_name +   
                                    "liPropertyFeatureRef=" + control.id + "&" +
                                    "iPropertyFeatureCount=1&" +
									"flPropFeatureWidth=-1&" + 
									"flPropFeatureLength=-1&" + 
                                    "liSatelliteSiteID=29",
                                    data
                                );
                }
                else
                {
					//delete the feature
					///if( Found )
					///{
					    /// check the alt of the control, and that flag has been set then delete it using the PropertyPk and FeaturePk
					    /// otherwise then use the old method of deleting the feature
					    var liPropertyPkRef = document.getElementById("liRecordPkRef").value;
					    if(control.alt == 1)
					    {
					        asc_delfeat = new Asynchronous();
						    asc_delfeat.complete = asc_delfeat_Event;
						    asc_delfeat.call("../scripts/dataLayer/deletePropertyFeatureByPropertyPk.xml.asp?liPkRefToDelete=" + liPropFeaturePkRef + "&liPropertyPkRef=" + liPropertyPkRef, data);
					    }
					    else
					    {  
					        asc_delfeat = new Asynchronous();
						    asc_delfeat.complete = asc_delfeat_Event;
						    asc_delfeat.call("../scripts/dataLayer/deletePropertyFeature.xml.asp?liPkRefToDelete=" + liPropFeaturePkRef + "&bDeleteTypeFlag=1", data);
					    }
					    control.alt = ""
						
					///}
					///else
					///{
					///	alert( "Cannot delete the feature, feature was not found at property." );
					///}
                }
            break;       
        }
    }
    hdnXml.value = xml;
}

function wantedFeat(control,hdnXml)
{
    var writeProp = true;
    var hdnXml
    if(isArray(hdnXml))
    {
        //alert(hdnXml[0]);
        hdnXml = document.getElementById( getElementsIdByName( hdnXml[0] ) );
        writeProp = false;
    }
    else
    {
        //alert(hdnXml);
        hdnXml = document.getElementById( getElementsIdByName( hdnXml ) );
    }
    
    var xml = '<?xml version="1.0" encoding="utf-8"?><Root>' + hdnXml.value + '</Root>';
    var xmlDoc = loadXML(xml);
    var xmlSet = xmlDoc.getElementsByTagName("feature");
    var script_name = "../scripts/dataLayer/writeWantedFeature.xml.asp?";
    var Found = false;
	var liPropFeaturePkRef;
	var iFeatureCount;
	var iSelFeatureIndex;
	var szPropSubFeatRef;

    script_name += "liWantedAd_SavedSearchPkRef=" + document.getElementById("liRecordPkRef").value + "&";
    xml = '';
    
    for(i = 0; i < xmlSet.length;i++)
    {
        if(xmlSet[i].getAttribute("id") == control.name)
        {
            script_name = "../scripts/dataLayer/updateWantedFeature.xml.asp?";
            script_name += "liPropFeatPkRef=" + xmlSet[i].getAttribute("liRecordPkRef") + "&";
			liPropFeaturePkRef = xmlSet[i].getAttribute("liRecordPkRef")
            Found = true;
        }
        else
        {
            xml += '<feature id="' + xmlSet[i].getAttribute("id") + '" liRecordPkRef="' + xmlSet[i].getAttribute("liRecordPkRef") + '"/>'
        }
        
    }
    if(!liPropFeaturePkRef > 0)
	{
	    liPropFeaturePkRef = control.id;
	}
    if(writeProp)
    {
        //alert("Writing Property Feature");
        data = Array(script_name,control,hdnXml);

        switch(control.type)
        {
            case "select-one":
                if( ( control.selectedIndex > 0 ) || ( control.options[control.selectedIndex].text != 0 ) )
                {
					if( IsNumeric(control.options[control.selectedIndex].text) )
					{
						iFeatureCount = parseInt( control.options[control.selectedIndex].text );
						iSelFeatureIndex = 0;
						szPropSubFeatRef = "";
					}
					else
					{
						iFeatureCount = 1;
						iSelFeatureIndex = control.selectedIndex;
						szPropSubFeatRef = "liPropertySubFeatRef=" + control.options[ control.selectedIndex ].value + "&";
					}

					asc_feat = new Asynchronous();
					asc_feat.complete = asc_feat_Event;

					asc_feat.call(
									script_name +   
									"liWantedFeatureRef=" + control.id + "&" +
									szPropSubFeatRef + 
									"iWantedFeatureCount=" + iFeatureCount + "&" +
									"flWantedFeatureWidth=-1&" + 
									"flWantedFeatureLength=-1&" + 
									"liSatelliteSiteID=29",
									data
								);
                }
                else
                {
						//delete the feature
						if( Found )
						{
							asc_delfeat = new Asynchronous();
							asc_delfeat.complete = asc_delfeat_Event;
							asc_delfeat.call("../scripts/dataLayer/deleteWantedFeature.xml.asp?liPkRefToDelete=" + liPropFeaturePkRef + "&bDeleteTypeFlag=1", data );
						}
						else
						{
								alert( "Cannot delete the feature, feature was not found at property." );
						}
                }
				break;
            case "text":
                if( control.value != "" )
                {
					iFeatureCount = 1;
					szPropFeatDesc = "szPropFeatureDescription=" + control.value + "&";

					asc_feat = new Asynchronous();
					asc_feat.complete = asc_feat_Event;

					asc_feat.call(
									script_name +   
									"liWantedFeatureRef=" + control.id + "&" +
									szPropFeatDesc + 
									"iWantedFeatureCount=" + iFeatureCount + "&" +
									"flWantedFeatureWidth=-1&" + 
									"flWantedFeatureLength=-1&" + 
									"liSatelliteSiteID=29",
									data
								);
                }
                else
                {
						//delete the feature
						if( Found )
						{
							asc_delfeat = new Asynchronous();
							asc_delfeat.complete = asc_delfeat_Event;
							asc_delfeat.call("../scripts/dataLayer/deleteWantedFeature.xml.asp?liPkRefToDelete=" + liPropFeaturePkRef + "&bDeleteTypeFlag=1", data );
						}
						else
						{
								alert( "Cannot delete the feature, feature was not found at property." );
						}
                }
                break; 
            case "textarea":
                if( control.value != "" )
                {
					iFeatureCount = 1;
					szPropFeatDesc = "szPropFeatureDescription=" + control.value + "&";

					asc_feat = new Asynchronous();
					asc_feat.complete = asc_feat_Event;

					asc_feat.call(
									script_name +   
									"liWantedFeatureRef=" + control.id + "&" +
									szPropFeatDesc + 
									"iWantedFeatureCount=" + iFeatureCount + "&" +
									"flWantedFeatureWidth=-1&" + 
									"flWantedFeatureLength=-1&" + 
									"liSatelliteSiteID=29",
									data
								);
                }
                else
                {
						//delete the feature
						if( Found )
						{
							asc_delfeat = new Asynchronous();
							asc_delfeat.complete = asc_delfeat_Event;
							asc_delfeat.call("../scripts/dataLayer/deleteWantedFeature.xml.asp?liPkRefToDelete=" + liPropFeaturePkRef + "&bDeleteTypeFlag=1", data );
						}
						else
						{
								alert( "Cannot delete the feature, feature was not found at property." );
						}
                }
                break; 
            case "checkbox":
                if( control.checked )
                {
                    //alert(control.name);
                    asc_feat = new Asynchronous();
                    asc_feat.complete = asc_feat_Event;
                    
                    asc_feat.call(
                                    script_name +   
                                    "liWantedFeatureRef=" + control.id + "&" +
                                    "iWantedFeatureCount=1&" +
									"flWantedFeatureWidth=-1&" + 
									"flWantedFeatureLength=-1&" + 
                                    "liSatelliteSiteID=29",
                                    data
                                );
                }
                else
                {
					//delete the feature
					var liPropertyPkRef = document.getElementById("liRecordPkRef").value;
					if(control.alt == 1)
				    {
				        asc_delfeat = new Asynchronous();
						asc_delfeat.complete = asc_delfeat_Event;
						asc_delfeat.call("../scripts/dataLayer/deleteWantedFeatureByPropertyPk.xml.asp?liPkRefToDelete=" + liPropFeaturePkRef + "&liPropertyPkRef=" + liPropertyPkRef, data);
				    }
				    else
				    {  
				        asc_delfeat = new Asynchronous();
					    asc_delfeat.complete = asc_delfeat_Event;
					    asc_delfeat.call("../scripts/dataLayer/deleteWantedFeature.xml.asp?liPkRefToDelete=" + liPropFeaturePkRef + "&bDeleteTypeFlag=1", data);
				    }
				    control.alt = ""
					//}
					//else
					//{
					//	alert( "Cannot delete the feature, feature was not found at property." );
					//}
                }
            break;       
        }
    }
    hdnXml.value = xml;
}

function asc_delfeat_Event(status,statusText,responseText,responseXML,data)
{
    //alert(responseText);
}
function asc_featlookup_Event(status,statusText,responseText,responseXML,data)
{
    var nodes = responseXML.getElementsByTagName("FeatureList");
    for( i =0; i < nodes.length; i++)
    {
        var script_name = data[0];
        var control = data[1];
        var liFeaturePk = nodes[i].getAttribute("liFeaturePk")

        asc_feat = new Asynchronous();
        asc_feat.complete = asc_feat_Event;
        if(IsNumeric(control.value))
        {
            asc_feat.call(
                            script_name +   
                            "liPropertyFeatureRef=" + liFeaturePk + "&" +
                            "iPropertyFeatureCount=" + control.value + "&" + 
                            "szPropFeatureDescription=" + control.value + "&" +
                            "liSatelliteSiteID=29",
                            data
                        );
        }
        else
        {
            asc_feat.call(
                            script_name +   
                            "liPropertyFeatureRef=" + liFeaturePk + "&" +
                            "iPropertyFeatureCount=1&" + 
                            "szPropFeatureDescription=" + control.value + "&" +
                            "liSatelliteSiteID=29",
                            data
                        );
        }
    }
}
function asc_feat_Event(status,statusText,responseText,responseXML,data)
{
    var control = data[1];
    
    var nodes = responseXML.getElementsByTagName("OutputParameters")
    var xml;    
    for(i = 0; i <nodes.length;i++)
    {
        xml = '<feature liRecordPkRef="' + nodes[i].getAttribute("liRecordPkRef") + '" id="' + control.name + '"/>'    
    }
    data[2].value += xml
}

function openWizardForEdit(control,szUrl)
{
    var control = document.getElementById( getElementsIdByName( control ) )
    if(control.value > 0)
    {
    /*
        var randomnumber=Math.floor(Math.random()*11)
        window.open( szUrl + "?liRecordPkRef=" + control.value ,"postad_wizard_" + randomnumber,"width=700px,height=600px,scrollbars=yes");
        */
        window.location = szUrl + "?liRecordPkRef="+ control.value;
    }
}

function openWizardForEditById(controlId,szUrl)
{
    var control = document.getElementById( controlId )
    if(control.value > 0)
    {
        window.location = szUrl + "?liRecordPkRef="+ control.value;
    }
}

function asc_loadRental_Event(status,statusText,responseText,responseXML,data)
{
    var lszRentIncludesXML = document.getElementById(data);
    var nodes = responseXML.getElementsByTagName("RentalIncludes");
    
    for(i = 0; i < nodes.length; i++)
    {
        var item = document.getElementsByName(nodes[i].getAttribute("lblRentalIncludeText"));
        for(j = 0; j < item.length; j++)
        {
            item[j].checked = true;
            ammendXML(lszRentIncludesXML.id,item[j]);
        }
    }
}
function loadRentalInclude(lszRentIncludesXML)
{
    asc_loadRental = new Asynchronous();
    asc_loadRental.complete = asc_loadRental_Event;
    asc_loadRental.call("/ads/scripts/dataLayer/getRentalIncludes.xml.asp?liPropertyPkRef=" + document.getElementById("liRecordPkRef").value,lszRentIncludesXML);
}
function asc_loadRentalReq_Event(status,statusText,responseText,responseXML,data)
{
    var lszRentRequiresXML = document.getElementById(data);
    var nodes = responseXML.getElementsByTagName("RentalRequirements");
    
    for(i = 0; i < nodes.length; i++)
    {
        var item = document.getElementsByName(nodes[i].getAttribute("lblRentalRequirementsText"));
        for(j = 0; j < item.length; j++)
        {
            item[j].checked = true;
            ammendXML(lszRentRequiresXML.id,item[j]);
        }
    }
}
function loadRentalRequirements(lszRentRequiresXML)
{
    asc_loadRental = new Asynchronous();
    asc_loadRental.complete = asc_loadRentalReq_Event;
    asc_loadRental.call("/ads/scripts/dataLayer/getRentalRequirements.xml.asp?liPropertyPkRef=" + document.getElementById("liRecordPkRef").value,lszRentRequiresXML);
}

function asc_loadpropFeat_Event(status,statusText,responseText,responseXML,data)
{
    var lszXML = document.getElementById(data);
    var nodes = responseXML.getElementsByTagName("PropertyFeature");
    
    var xml = '';
    for(i = 0; i < nodes.length; i++)
    {
        //var item = document.getElementsByName(nodes[i].getAttribute("lblFeatureType"));
        var item = document.getElementsByTagName("*");
        for(j = 0; j < item.length; j++)
        {
            if(nodes[i].getAttribute("lblFeatureType") == item[j].name)
            {
                switch(item[j].type)
                {
                    case "text":
                        item[j].value = nodes[i].getAttribute("lblPropFeatDescription")
                        break;
                    case "checkbox":
                        item[j].checked = true;
                        break;
                    default:
                        item[j].selected = true;
                }
                xml += '<feature id="' + nodes[i].getAttribute("liPropertyFeaturePk") + '" liRecordPkRef="' + nodes[i].getAttribute("lblFeatureType") + '"/>'
            }
        }
        item = document.getElementsByTagName("option");
        for(j = 0; j < item.length;j++)
        {
            if(item[j].text == nodes[i].getAttribute("lblFeatureType"))
            {
                item[j].selected = true;
            }
        }
    }
    lszXML.value = xml;
}
function loadPropertyFeatures(lszXML)
{
    asc_loadRental = new Asynchronous();
    asc_loadRental.complete = asc_loadpropFeat_Event;
    asc_loadRental.call("/ads/scripts/dataLayer/getPropertyFeature.xml.asp?liPropertyPkRef=" + document.getElementById("liRecordPkRef").value,lszXML);
}
function getControlByFeatureName(szName,controlType)
{
    if(document.getElementById(szName) == null)
    {
        var tmp = getElementsByName_iefix(controlType,szName);
        return tmp[0];
    }
    else
    {
        return document.getElementById(szName);
    }  
}
function generate_TFXml(cvalue,szOutput,dteFrom,liPropertyOwner,liUnits)
{
    try
    {
        var szopUnits
        /*
        if(liUnits != null)
        {
            if(document.getElementById(liUnits) == null)
            {
                var tmp = getElementsByName_iefix('select',liUnits);
                liUnits = tmp[0].value;
            }
            else
            {
            szopUnits = document.getElementById(liUnits).value;
            }
        }
        else
        {
            szopUnits = "GBP"
        }
        */
        var liUnitsControl = getControlByFeatureName( liUnits,'select' );
        szopUnits = liUnitsControl[liUnitsControl.selectedIndex].value;
        
        var output = getControlByFeatureName( szOutput,'textarea' );//document.getElementById(szOutput);
        var cvalue = getControlByFeatureName(cvalue,'input');
        var dteFrom = getControlByFeatureName(dteFrom,'input');//document.getElementById(dteFrom);
        var dteFromValue = '1/Jan/1970';
        if(dteFrom != null)
        {
            dteFromValue = dteFrom.value
        }
        var dteTo = document.getElementById(dteTo);
        var liPropertyOwner = document.getElementById(liPropertyOwner);
        var szPropertyOwner = "";
        if(liPropertyOwner != null)
        {
            szPropertyOwner = liPropertyOwner.options[liPropertyOwner.selectedIndex].text;
        }
        var xml = '<Root>';
        xml += '<xmltf liTfCurrency="' + szopUnits + '" sztfName="' + szPropertyOwner + '" sztfDataType="date" sztfMin="' + dteFromValue + '" sztfMax="-1" sztfUnits="date">';
        xml += '<xmlop iopPeriod="1000" szopUnits="Years" flopValue="' + cvalue.value + '" />';
        xml += '</xmltf>';
        xml += '</Root>';
        
        output.value = xml;
    }
    catch(Exception)
    {
        debug(Exception);
    }
    
}
function generate_TFXml_renting(cvalue,szOutput,dteFrom,dteTo,liUnits)
{
    try
    {
        var szopUnits
        /*
        if(liUnits != null)
        {
            szopUnits = document.getElementById(liUnits)
            if(szopUnits == null)
            {
                var tmp = getElementsByName_iefix('select',liUnits);
                liUnits = tmp.value;
            }
            else
            {
                szopUnits = document.getElementById(liUnits).value
            }
            //alert(szopUnits);
        }
        else
        {
            szopUnits = "GBP"
        }
        */
         var liUnitsControl = getControlByFeatureName( liUnits,'select' );
        szopUnits = liUnitsControl[liUnitsControl.selectedIndex].value;
        
        var output = getControlByFeatureName( szOutput,'textarea' );//document.getElementById(szOutput);
        var cvalue = getControlByFeatureName(cvalue,'input');
        var dteFrom = getControlByFeatureName(dteFrom,'input');//document.getElementById(dteFrom);
        
        var dteFromValue = '1/Jan/1970';
        if(dteFrom != null)
        {
            dteFromValue = dteFrom.value
        }
        
        var dteTo = getControlByFeatureName(dteTo,'input');
        var dteToValue = '1/Jan/2200';
        if(dteTo != null)
        {
            dteToValue = dteTo.value
        }
        
        
        var xml = '<Root>';
        xml += '<xmltf liTfCurrency="' + szopUnits + '" sztfName="All Year" sztfDataType="date" sztfMin="' + dteFromValue + '" sztfMax="' + dteToValue + '" sztfUnits="date">';
        xml += '<xmlop iopPeriod="1" szopUnits="" flopValue="' + cvalue.value + '" />';
        xml += '</xmltf>';
        xml += '</Root>';
        
        output.value = xml;
        //alert(xml);
    }
    catch(Exception)
    {
        debug(Exception);
    }
    
}

function co_checkHide(iCompanyType,controlRenting,controlBuying,radioButtons,bDoNotHide)
{
    var nodes
    var radio_nodes
    switch( iCompanyType )
    {
        case 2: //both
            if(!bDoNotHide)
            {
                document.getElementById( controlRenting ).style.display = "none";
            }
            if( radioButtons != null )
            {
                toggleDisplayOnLoad( new Array( controlRenting , controlBuying  ), 2 );
            }
            break;
        case 0: //renting
            document.getElementById( controlBuying ).style.display = "none";
            
            if(radioButtons != null)
            {          
                if(document.all)
                {
                    nodes = getElementsByName_iefix("tr","row_" + radioButtons);
                    radio_nodes  = getElementsByName_iefix("input",radioButtons);
                }
                else
                {
                    nodes = document.getElementsByName("row_" + radioButtons);
                    radio_nodes = document.getElementsByName(radioButtons);
                    
                }
                for(i =0; i < nodes.length; i++)
                {
                    nodes[i].style.display = "none";
                }
                toggleDisplayOnLoad( new Array( controlRenting , controlBuying  ), 2 );
            }
            break;
        case 1: //buying
            document.getElementById(controlRenting).style.display = "none";
            
            if(radioButtons != null)
            {          
                if(document.all)
                {
                    nodes = getElementsByName_iefix("tr","row_" + radioButtons);
                    radio_nodes  = getElementsByName_iefix("input",radioButtons);
                }
                else
                {
                    nodes = document.getElementsByName("row_" + radioButtons);
                    radio_nodes = document.getElementsByName(radioButtons);
                    
                }
                bFound = false;
                for(i = 0; i < nodes.length; i++)
                {
                    nodes[i].style.display = "none";
                    if(bFound == false)
                    {
                        radio_nodes[i].checked = "";
                        bFound = true;
                    }
                    else
                    {
                        radio_nodes[i].checked = "true";
                    }
                }
                toggleDisplayOnLoad( new Array( controlRenting , controlBuying  ), 2 );
            }
            break;
    }
}

function checkHide(controlRenting,controlBuying,radioButtons,bDoNotHide)
{
    var nodes
    var radio_nodes
    switch(2)
    {
        case 2: //both
            if(!bDoNotHide)
            {
                document.getElementById( controlRenting ).style.display = "none";
            }
            if( radioButtons != null )
            {
                toggleDisplayOnLoad( new Array( controlRenting , controlBuying  ), 2 );
            }
            break;
        case 0: //renting
            document.getElementById( controlBuying ).style.display = "none";
            
            if(radioButtons != null)
            {          
                if(document.all)
                {
                    nodes = getElementsByName_iefix("tr","row_" + radioButtons);
                    radio_nodes  = getElementsByName_iefix("input",radioButtons);
                }
                else
                {
                    nodes = document.getElementsByName("row_" + radioButtons);
                    radio_nodes = document.getElementsByName(radioButtons);
                    
                }
                for(i =0; i < nodes.length; i++)
                {
                    nodes[i].style.display = "none";
                }
                toggleDisplayOnLoad( new Array( controlRenting , controlBuying  ), 2 );
            }
            break;
        case 1: //buying
            document.getElementById(controlRenting).style.display = "none";
            
            if(radioButtons != null)
            {          
                if(document.all)
                {
                    nodes = getElementsByName_iefix("tr","row_" + radioButtons);
                    radio_nodes  = getElementsByName_iefix("input",radioButtons);
                }
                else
                {
                    nodes = document.getElementsByName("row_" + radioButtons);
                    radio_nodes = document.getElementsByName(radioButtons);
                    
                }
                bFound = false;
                for(i = 0; i < nodes.length; i++)
                {
                    nodes[i].style.display = "none";
                    if(bFound == false)
                    {
                        radio_nodes[i].checked = "";
                        bFound = true;
                    }
                    else
                    {
                        radio_nodes[i].checked = "true";
                    }
                }
                toggleDisplayOnLoad( new Array( controlRenting , controlBuying  ), 2 );
                toggleSearchDisplay( '', new Array( 'Rental Options', 'Purchase Options' ), '1' );
            }
            break;
    }
}

function goNav(control)
{
    var url = control.options[control.selectedIndex].value;
    if(url > "")
    {
        window.location.href = url
    }
}
function viewAdvert(liPropertyPkRef, bAdvertType, bWanted, liSatelliteSiteId)
{
    //document.innerHTML += '<form id="hdnForm" action="viewadvertdetail.asp"><input type="hidden" name="liPropertyPkRef" id="hdnPropPkRef"/></form>';
    document.getElementById("hdnPkRef").value = liPropertyPkRef;
    document.getElementById("hdnAdverType").value = bAdvertType;
    document.getElementById("hdnWanted").value = bWanted;
	document.getElementById("hdnliSatelliteSiteId").value = liSatelliteSiteId; 

	if( bAdvertType == 0 )
	{    
		document.getElementById( "hdnForm0" ).submit();
	}
	else
	{
		document.getElementById( "hdnForm1" ).submit();
	}
}

function updateTimeframeLbl( ctrlInput, szOutput )
{
	var ctrlOutput = document.getElementById( szOutput );

	if ( ctrlInput.selectedIndex < 1 )
	{
		ctrlOutput.innerHTML = "</b>per <b>Month";
	}
	else
	{
		ctrlOutput.innerHTML = ctrlInput[ ctrlInput.selectedIndex ].text;
	}
}

/****************************************************************************************************************
* VACATION RENTAL FUNCTIONS | VACATION RENTAL FUNCTIONS | VACATION RENTAL FUNCTIONS | VACATION RENTAL FUNCTIONS *
****************************************************************************************************************/

function adjustTimeframe( ctrlSeasons )
{
	switch( ctrlSeasons[ ctrlSeasons.selectedIndex ].text )
	{
		case "One Night":
			document.getElementById("SR_lblTimeframe").innerHTML = "Night";		
			document.getElementById("DR_lblTimeframe").innerHTML = "Night";		
			document.getElementById("TR_lblTimeframe").innerHTML = "Night";		
			break;
		default:
			document.getElementById("SR_lblTimeframe").innerHTML = "</b>per <b>Month";
			document.getElementById("DR_lblTimeframe").innerHTML = "</b>per <b>Month";
			document.getElementById("TR_lblTimeframe").innerHTML = "</b>per <b>Month";
			break;
	}
}

//data = array(hdnSeasonsXML,item-to-show,bShow
function asc_lookup_Event(status,statusText,responseText,responseXML,data)
{
    //
    //   
    var nodes = responseXML.getElementsByTagName("FeatureList");
    for( i =0; i < nodes.length; i++)
    {
        var xml = '<?xml version="1.0" encoding="utf-8"?><Root>' + document.getElementById( getElementsIdByName( data[0] ) ).value + '</Root>';
        var xmlDoc = loadXML(xml);
        /*var xmlSet = xmlDoc.getElementsByTagName("season");
        for(j = 0; j < xmlSet.length; j++)
        {
            if(xmlSet[i].getAttribute("id") == nodes[i].getAttribute("liFeaturePk"))
            {
                if(data[2] == 1)
                {
                    document.getElementById("row_"  + data[1]).style.display = "table-row"
                    alert("showing: row_"  + data[1]);
                }
                else
                {
                    document.getElementById("row_"  + data[1]).style.display = "none"
                    alert("hiding: row_"  + data[1]);
                }
            }
        }
        */
    }
}

function showSeasonPriceAll(szFeatsandtoShow,hdnSeasonsXML)
{
    for(i = 0;i < szFeatsandtoShow.length;i++)
    {
        showSeasonPrice(szFeatsandtoShow[i][0],hdnSeasonsXML,szFeatsandtoShow[i][1])
    }
}

function hideSeasonPrice(toHide)
{
    for (var i in toHide)
    {
        
        document.getElementById("row_" + toHide[i]).style.display = "none";
        
    }
}

function showSeasonPrice(szFeatName,hdnSeasonsXML,toShow)
{
    data = Ar