﻿// JScript File

var displayJSON = false;


var host = getHostAdress();
var HTTPShost = '';

//"http://www.pro-lab.com.au";// = "http://localhost:4557/NewNS/";
//var host = getHostAdress();

function getHostAdress()
{
    var h;
   if(checkLocation("checkout.aspx"))
        h = "http://www.pro-lab.com.au/";
    else 
        h = "http://www.pro-lab.com.au/";
        
    
    
    HTTPShost = h.replace('http', 'https');
    
    return h;
    
    
    
    
//    if (host == null)
//        {var l = window.location.toString();
//        var ind = l.lastIndexOf('/');
//        host = l.substring(0, ind + 1);
//    }
}


var preLoadTimeout;
//var oXHR;
var oXHR_itemDetail;
var lastItemID;
var stopDownloading;
var nbOfRecords;
//var returnedItemsCount;
var nbOfItemsInscrollContainer = 12;
var followingRequestNbOfRecords = 8;
var finishedDownloading;


var isSearchByKeyword; // as opposite to left menu choice


// product thumbs events
var onclkHandlerMainCatalogue = function () {
    setCookie('itemID', this.id);
    openItem(this.id, this.id , null, false);
    };   

var onmovrHandlerMainCatalogueFade = function () {
    opacity(this.id, 100, 30, 500);
    //changeVisibility('sp_' + this.id , true );
//    document.getElementById('d_colors_' + this.id).style.display = 'block';
    };

var onmoutHandlerMainCatalogueFade = function () {
    opacity(this.id, 30, 100, 500);
    //changeVisibility('sp_' + this.id , false);
    //document.getElementById('d_colors_' + this.id).style.display = 'none';
    };


// colour thumbs events
var onmovrHandlerMainCatalogueColourThumbs = function () {
    changeThumb(this.id, this.name, this.src, 400);
    opacity(this.id, 100, 30, 500);
    };   
var onmoutHandlerMainCatalogueColourThumbs = function () {
    cancelChangeThumb();
    opacity(this.id, 30, 100, 500);
    };   


var onmovrHandlerNoFlickerDiv = function () {
    FP_changeProp(/*id*/(this.id).replace('layer1_', 'layer2_'),0);FP_changeProp(/*id*/(this.id).replace('layer1_', 'layer2_'),0); 
    };   

var onClickDetailsHandler = function () {

    document.getElementById('divFeatures_' + this.id).style.display = document.getElementById('divFeatures_' + this.id).style.display == 'none' ? 'block' : 'none';
    
    };   


function sendXHRreturnJSON(param, webMethod, callbackFunction)
{
    var JSON = '';
    try
    {
    var oXHR;
        oXHR = zXmlHttp.createRequest();
        
        
        
        if(checkLocation("checkout.aspx"))
            oXHR.open("post", HTTPShost + "WS.asmx/" + webMethod , true);
        else
            oXHR.open("post", host + "WS.asmx/" + webMethod , true);
        
        oXHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    
        oXHR.onreadystatechange = function()
        {
            if(oXHR.readyState == 4)
            {
                JSON = extractJSONfrom2NodeXML(oXHR.responseText);
                
                if (JSON == '{NODATA}')
                {
                    JSON = '';  
                }

                callbackFunction(JSON);

                return JSON;
            }
        }
        
        oXHR.send(param);         
    }
    catch(ex)
    {
        alert('error in sendXHRreturnJSON ' + ex.message);
    }
    
}



function sendXHR(targetControl, param, buildControlFunction, cleanControl, webMethod)
{
    
    try
    {
    var oXHR;
    
        oXHR = zXmlHttp.createRequest();
//        oXHR.open("post", "http://new.manzoni.com.au/testWS.asmx/" + webMethod , true);
        oXHR.open("post", host + "GetDataWS.asmx/" + webMethod , true);

    
        oXHR.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    
        oXHR.onreadystatechange = function()
        {
            if(oXHR.readyState == 4)
            {
                displayReturnedJson(oXHR.responseText);

                var JSON = extractJSONfrom2NodeXML(oXHR.responseText);
                
                if (JSON == '{NODATA}')
                {
                    finishedDownloading = 1; // to prevent the reloading of everything from downArrow clicking             

                    oXHR.abort();
                    JSON = '';
                    lastItemID = '';
                    return false;
                }
                else
                {
                    finishedDownloading = 0;
                    
                    buildControlFunction(JSON ,targetControl, cleanControl);
                    
                    nbOfRecords = followingRequestNbOfRecords; 

                    if (stopDownloading != true)
                        ;//preLoadTimeout = window.setTimeout('getProdXHR(0)' , 2000);
                    else
                    {
                       if(oXHR)
                       {
                           if(oXHR.readyState !=0)
                           {
                            oXHR.abort();
                           }
                        }
                        alert('stopDownloading  aborted');
                    }
                }
            }
        }
        oXHR.send(param);         
    }
    catch(ex)
    {
        alert('error in sendXHR ' + ex.message);
    }
}




function getProdXHR(cleanControl)
{

    var l = window.location.toString();
//    if (l.indexOf("Products.aspx") > -1 || l.indexOf("Product.aspx") > -1)
//    {
        isSearchByKeyword = 0;
        
        var CategoryID = getCookie('CategoryID');
        var SubCategoryID = getCookie('SubCategoryID');
        
        var param;
        param = encodeURIComponent("spName") + '=' + encodeURIComponent('GetCatalogueByDepartmentAndCategoryForItem_Window') + "&";
        param += encodeURIComponent("dsName") + '=' + encodeURIComponent('dsProducts') + "&";
        param += encodeURIComponent("tblName") + '=' + encodeURIComponent('tblProducts') + "&";

        param += encodeURIComponent("subCategoryID") + '=' + encodeURIComponent(SubCategoryID);

        var paramToSend = "param" + "=" + encodeURIComponent(param);
            
        sendXHR('actualContent', paramToSend, BuildCatalogueContentElement, cleanControl, 'GetJsonData');
//    }
//    else
//        {
//        ;// Do Nothing, the request will be resubmitted onload of the Products.aspx page (via master > body > onload)
//        }

}



function DisplayContentsFromHorizontalMenu(MenuID)
{
    stopDownloading = 0;
    //isSearchByKeyword = 1;
    cleanControl = 1;
    
    var param;
    param = encodeURIComponent("spName") + '=' + encodeURIComponent('GetTextFromMenuSelection') + "&";
    param += encodeURIComponent("dsName") + '=' + encodeURIComponent('dsMenuText') + "&";
    param += encodeURIComponent("tblName") + '=' + encodeURIComponent('tblMenuText') + "&";

    param += encodeURIComponent("MenuID") + '=' + encodeURIComponent(MenuID);
    
    var paramToSend = "param" + "=" + encodeURIComponent(param);
//alert(param);
    sendXHR('actualContent', paramToSend, BuildInfoElement, cleanControl, 'GetJsonData');

}

function DisplayContentsFromMenuLeft(CatID)
{
    stopDownloading = 0;
    //isSearchByKeyword = 1;
    cleanControl = 1;
    
    var param;
    param = encodeURIComponent("spName") + '=' + encodeURIComponent('GetTextFromMenuLeftSelection') + "&";
    param += encodeURIComponent("dsName") + '=' + encodeURIComponent('dsMenuText') + "&";
    param += encodeURIComponent("tblName") + '=' + encodeURIComponent('tblMenuText') + "&";

    param += encodeURIComponent("CatID") + '=' + encodeURIComponent(CatID);
    
    var paramToSend = "param" + "=" + encodeURIComponent(param);
//alert(param);
    sendXHR('actualContent', paramToSend, BuildInfoElement, cleanControl, 'GetJsonData');


}


function downloadMoreContentViaXHR()
{
    if (finishedDownloading == 0)
    {
        if (isSearchByKeyword == 0)
            getProdXHR(0);
        else
            searchProdXHR(document.getElementById('txtKeyword').value, false);    
    }        
}


function restartXHR()
{
//    if(oXHR)
//    {
//        if(oXHR.readyState !=0)
//        {
//            oXHR.abort();
//        }
//    }
//    finishedDownloading = 0;
//    var s = document.getElementById('ScScrollDiv1_divCatalogueScroll');
//    s.scrollTop = 0;
//    var t = document.getElementById('ScScrollDiv1_upArrow');
//    t.style.visibility = 'hidden';
//                
//    
//    window.clearTimeout(preLoadTimeout);
//    lastItemID  = '';
//    stopDownloading = 0;
//    nbOfRecords = 16; 
//    /////returnedItemsCount = 0;
//    setReturnedItemsCount(0);
}

function stopDownl()
{
    if(oXHR)
    {
        if(oXHR.readyState !=0)
        {
            oXHR.abort();
        }
    }
    stopDownloading = 1; 
    nbOfRecords = 0;

}



//********************************************************
//*****************    HELPERS     ***********************
//********************************************************



function extractJSONfrom2NodeXML(xml) // as returned by the WebMethod of the WebService
{
    var json = xml.substring(xml.indexOf('>{') + 1, xml.lastIndexOf('}<') + 1);
    return json;
    
    //    XML version - does not work on SAFARI

    //    var xmlDoc = zXmlDom.createDocument();
    //    alertxmlDoc);
    //    xmlDoc.loadXML(xml);
    //    var result = xmlDoc.lastChild;
    //    BuildCatalogueContentElement(result.text, 'ScScrollDiv1_x_divCatalogueScroll')
    //    return result.text;

}


function displayReturnedJson(responseText)
{
    if (displayJSON)
    {
        var rawXML = decodeURIComponent(responseText);
        var JSON = extractJSONfrom2NodeXML(rawXML);
        
        var x = document.getElementById('ccc');
        
        var old = document.getElementById('huj1');
        if(old)
        {
            x.removeChild(old);
        }
        var b = document.createElement("div");
        b.setAttribute('id', 'huj1');  
        
        var txt = 'Last Item ' + lastItemID + '.................. JSON:   ';
        var t = document.createTextNode(txt + JSON);
        b.appendChild(t);
        x.appendChild(b);
    }
}




//********************************************************
//*****************    CONTROL BUILDERS     **************
//********************************************************






function BuildInfoElement(JSONdata, controlToAttachTo, cleanControl)
{

    try
    {
        var x = eval("(" + JSONdata + ")");
    
        try
        {
            var z = new Array(x);
            var a = z[0];

            var contents = a.dsMenuText.tblMenuText;

            if (contents)
            {
                
                var xx = document.getElementById(controlToAttachTo);
                
                var old = xx.firstChild;
                
                if(cleanControl == true )
                {
                    if (old != null)
                        xx.removeChild(old);
                }


                var tempCM;
                
                var copyOfTempCM = document.getElementById('tempCM'); // a means od checking if temp DIV exists already without causing errors
                if(copyOfTempCM)
                {
                    tempCM = copyOfTempCM;
                }
                else
                {
                    tempCM = document.createElement("div");
                    tempCM.setAttribute('id', 'tempCM');  
//                    tempCM.style.width = elWidth; 
//                    tempCM.style.position = 'relative';
                }                
                
                
                
                var info = document.createElement("div");
                info.style.paddingLeft = '15px';
                
                
                info.innerHTML = '<span>' + formatHtml(contents.Text) + '</span>';
//                info.innerText = '<span>' + contents.Text + '</span>';
                tempCM.appendChild(info);
                
                xx.appendChild(tempCM); 
                xx.style.height = '100%';
                xx.style.display = 'block';
                
                document.getElementById('divLoading').style.visibility = 'hidden';                

            }
        }
        catch(ex)
        {
            alert('Inner Error In BuildInfoElement :\n' + ex.message);
        }
    }
    catch(e)
    {
        alert('Outer Error In BuildInfoElement :\n' + e.message);
    }

}



function BuildCatalogueContentElement(JSONdata, controlToAttachTo, cleanControl)
{
        
    lastItemID = '';
    
    var elWidth, elMargin;
    var returnedItems;
    
    elWidth = '655px';
    elMargin = '20px'
    
    
    try
    {

        var x = eval("(" + JSONdata + ")");
    

        try
        {
            var z = new Array(x);
            var a = z[0];
            
            var products = a.dsProducts.tblProducts;
            
                                   
            var c = 0;
            if (products[1])
                c = 2;
        
            if (c > 1)
                ;
            else
            {
                products = new Array();
                    products[0] = a.dsProducts.tblProducts;
            }
        
            if (products[0])
            {
                var j = 0 ;
                
                var xx = document.getElementById(controlToAttachTo);
                
                
                
                var old = xx.firstChild;
                
                if(cleanControl == true )
                {
                    if (old != null)
                        xx.removeChild(old);
                }

                var bottomScrollBuffer = document.getElementById('bottomScrollBuffer');  
                if (bottomScrollBuffer)
                    xx.removeChild(bottomScrollBuffer);

                var tempCM;
                
                var copyOfTempCM = document.getElementById('tempCM'); // a means od checking if temp DIV exists already without causing errors
                if(copyOfTempCM)
                {
                    tempCM = copyOfTempCM;
                }
                else
                {
                    tempCM = document.createElement("div");
                    tempCM.setAttribute('id', 'tempCM');  
                    tempCM.style.width = elWidth; 
                    tempCM.style.position = 'relative';
                    //tempCM.style.height = '1000px';
                    //tempCM.style.backgroundColor = 'blue';
                    
//                    tempCM.style.overflowY = 'scroll';
                    
                }                
                
                while(products[j])
                {
                    var productContent = document.createElement("div"); //productContent.setAttribute('class', 'd_m');
                    productContent.setAttribute('id', 'productContent');  
                    productContent.style.position = 'relative'; 
	                productContent.style.marginLeft = '10px'; 
	                productContent.style.width = elWidth;
	                //productContent.style.backgroundColor = 'blue';
	                //productContent.style.backgroundColor = '#fdfdfd';
	                productContent.style.styleFloat = 'left'; 
	                productContent.style.cssFloat = 'left'; 
	                productContent.style.textAlign = 'left';
	                

                    var productContentMiddle = document.createElement("div"); //productContentMiddle
                    productContentMiddle.setAttribute('id', 'productContentMiddle');  
                    //productContentMiddle.style.styleFloat = 'left';
                    //productContentMiddle.style.backgroundColor = 'blue';
                    //productContent.style.cssFloat = 'left'; 
	                
                    var productContentTop = document.createElement("div"); //productContentTop
                    productContentTop.setAttribute('id', 'productContentTop');  
                    productContentTop.style.width = elWidth;
	                productContentTop.style.backgroundImage = 'url(..\Images\bg_column_top_middle.jpg)'; 
	                productContentTop.style.backgroundTepeat = 'repeat-x';
	                //productContentTop.style.backgroundColor = 'lightblue';
                    //productContentTop.style.cssFloat = 'left'; 
	                var img_bg_column_top_middle = document.createElement("img");  
	                img_bg_column_top_middle.style.height = '5px';
                    img_bg_column_top_middle.style.width = elWidth;
                    img_bg_column_top_middle.setAttribute('src', './Images/bg_column_top_middle.jpg'); 
                    
                    productContentTop.appendChild(img_bg_column_top_middle);
                    
                    var productContentBottom = document.createElement("div"); //productContentBottom
                    productContentBottom.setAttribute('id', 'productContentBottom');  
                    productContentBottom.style.width = elWidth;
	                //productContentBottom.style.height = '5px';
	                productContentBottom.style.marginBottom = '10px';
//	                productContentBottom.style.backgroundImage = 'url(../Images/bg_column_bottom_middle.jpg)'; 
	                productContentBottom.style.backgroundTepeat = 'repeat-x';
	                //productContentBottom.style.backgroundColor = 'lightgreen';
                    //productContentBottom.style.cssFloat = 'left'; 
	                var img_bg_column_bottom_middle = document.createElement("img");  
	                img_bg_column_bottom_middle.style.height = '5px';
                    img_bg_column_bottom_middle.style.width = elWidth;
                    img_bg_column_bottom_middle.setAttribute('src', './Images/bg_column_bottom_middle.jpg'); 
                    
                    productContentBottom.appendChild(img_bg_column_bottom_middle);
                    
	                
	                
                    var productTitle = document.createElement("div"); //productTitle
                    productTitle.setAttribute('id', 'productTitle');  
                    productTitle.style.width = elWidth; 
                    productTitle.style.height = '25px';
                    productTitle.style.marginLeft = '15px';
                    productTitle.style.fontWeight = 'bold';
	                //productTitle.style.backgroundColor = 'lightgrey';
                    //productTitle.style.cssFloat = 'left'; 
	                                            
                    var actualProductContent = document.createElement("div"); //actualProductContent
                    productContentTop.setAttribute('id', 'productContentTop');  
                    //productContentTop.style.marginLeft = '5px';   
                    productContentTop.style.width = elWidth; 
                    //productContentTop.style.backgroundColor = 'red';
                    productContentTop.style.cssFloat = 'left'; 
                    productContentTop.style.styleFloat = 'left'; 
                                        
                    var imagesDiv = document.createElement("div"); //imagesDiv
                    imagesDiv.style.width = '100px';
                    imagesDiv.style.height = '90px';
                    imagesDiv.style.paddingLeft = '15px';
                    imagesDiv.style.paddingRight = '15px';
                    //imagesDiv.style.borderRight = 'solid 1px gainsboro';
                    //imagesDiv.style.backgroundColor = 'gainsboro';
                    imagesDiv.style.cssFloat = 'left';
                    imagesDiv.style.styleFloat = 'left'; 
                    
                    var descriptionDiv = document.createElement("div");//descriptionDiv
                    descriptionDiv.setAttribute('id', 'descriptionDiv');  
                    descriptionDiv.style.width = '378px';                                                                                     
                    descriptionDiv.style.height = '100%';                                                                                     
                    descriptionDiv.style.paddingLeft = '15px';                                                                                     
                    descriptionDiv.style.paddingRight = '15px';                                                                                     
                    descriptionDiv.style.borderLeft = 'solid 1px gainsboro';                                                                                     
                    descriptionDiv.style.borderRight = 'solid 1px gainsboro';   
                    descriptionDiv.style.marginBottom = '5px';   
                                                                                                      
                    //descriptionDiv.style.backgroundColor = 'green';                                                                                     
                    descriptionDiv.style.cssFloat = 'left'; 
                    descriptionDiv.style.styleFloat = 'left'; 	                                                        

                    var dataSheetDiv = document.createElement("div");//descriptionDiv
                    dataSheetDiv.setAttribute('id', 'dataSheetDiv');  

                    if (products[j].Features)
                    {
                        var divFeatures = document.createElement("div");//descriptionDiv
                        divFeatures.setAttribute('id', 'divFeatures_' + products[j].ProductID);
                        divFeatures.style.display = 'none';
                        divFeatures.innerHTML = '<br>' + formatHtml(products[j].Features);
                    }
                                        
                    var priceDiv = document.createElement("div");
                    priceDiv.setAttribute('id', 'priceDiv');  
                    priceDiv.style.width = '100px';                                                                                     
                    priceDiv.style.height = '100%';                                                                                     
                    priceDiv.style.marginLeft = '15px';
                    priceDiv.style.paddingTop = '25px';
                    priceDiv.style.styleFloat = 'left';                        
                    //priceDiv.style.backgroundColor = 'skyblue';                        
                    priceDiv.style.cssFloat = 'left'; 
                    priceDiv.style.styleFloat = 'left'; 
	                                        
	                                        
                    var aEnquire = document.createElement("a");
                    aEnquire.setAttribute('id', 'aEnq_' + products[j].PartName);   
                    aEnquire.style.textDecoration = 'underline';
                    
                    aEnquire.style.color = 'dimgray'; 
                    aEnquire.onmouseover = function()
                    {
                        this.style.color = 'blue';
                        this.style.cursor = 'pointer';
                    }; 
                    aEnquire.onmouseout = function()
                    {
                        this.style.color = 'dimgray';
                    }; 
                    aEnquire.onclick = function()
                    {
                        EnquireAboutProduct(this.id);
                    }; 
                    
                    var txtEnquire = document.createTextNode('Enquire');
                    aEnquire.appendChild(txtEnquire);	                                        

                    priceDiv.appendChild(aEnquire);                    	                                        
	                                        
	                                        
                    var cartDiv = document.createElement("div"); 
                    cartDiv.setAttribute('id', 'cartDiv');  
                    cartDiv.style.width = '20px';
                    cartDiv.style.styleFloat = 'left';                        
                    //cartDiv.style.backgroundColor = 'ivory';                        
                    cartDiv.style.cssFloat = 'left'; 
                    cartDiv.style.styleFloat = 'left'; 
	                                                        
                    var i = document.createElement("img");  //i.setAttribute('class', 'i_m');
                    i.style.height = '60px';
                    i.style.width = '100px';
//                    i.style.marginTop = '10px';
                    i.style.cssFloat = 'left'; 
                    i.style.styleFloat = 'left'; 
	                
                    i.setAttribute('id', products[j].ProductID);
                    i.setAttribute('name', products[j].ImageName);
                    i.setAttribute('alt', '');
                    i.setAttribute('tabIndex', j + getReturnedItemsCount());
                    
                    if (products[j].ImageName)
                        i.setAttribute('src', './ProductImages/' + products[j].ImageName);
                    else
                        i.setAttribute('src', './ProductImages/blank.jpg');
                        
                        
//                    i.onclick = onclkHandlerMainCatalogue;
                    
//                    var m1 = document.createElement("div"); 
//                    m1.setAttribute('id', 'huj');
//                    m1.style.width = '20px';
//                    m1.style.cssFloat = 'left'; 
//                    m1.styleFloat = 'left'; 
//                    m1.style.backgroundColor = 'yellow';                        
//                    m1.innerHtml = '&amp;nbsp;'
//                    //var txtMargin1 = document.createTextNode('&amp;nbsp;');
//                    //m1.appendChild(txtMargin1);
//                    
//                    var m2 = document.createElement("div"); 
//                    m2.setAttribute('id', 'huj');
//                    m2.style.width = '20px';
//                    m2.style.cssFloat = 'left'; 
//                    m2.styleFloat = 'left'; 
//                    m2.style.backgroundColor = 'yellow';                        
//                    var txtMargin2 = document.createTextNode(' ');
//                    m2.appendChild(txtMargin2);
//                    
//                    var m3 = document.createElement("div"); 
//                    m3.setAttribute('id', '');
//                    m3.style.width = '20px';
//                    m3.style.cssFloat = 'left'; 
//                    m3.styleFloat = 'left'; 
//                    m3.style.backgroundColor = 'yellow';                        
//                    var txtMargin3 = document.createTextNode(' ');
//                    m3.appendChild(txtMargin3);
//                    
//                    var m4 = document.createElement("div"); 
//                    m4.setAttribute('id', 'huj');
//                    m4.style.width = '20px';
//                    m4.style.cssFloat = 'left'; 
//                    m4.styleFloat = 'left'; 
//                    m4.style.backgroundColor = 'yellow';                        
//                    var txtMargin4 = document.createTextNode(' ');
//                    m4.appendChild(txtMargin4);
                    
                    
                    
                    var txtProductName = document.createTextNode(products[j].PartName);
                    var txtProductDescription = document.createTextNode(formatHtml(products[j].Description));

                    var funAs = products[j].FunctionsAs;
                    if (funAs)
                    {
                        var txtPartCompatibleWith = document.createTextNode(products[j].PartCompatibleWith);
                        var txtFunctionsAsCap = document.createTextNode('Compatible with: ');
                        var txtFunctionsAs = document.createTextNode(products[j].FunctionsAs);
                        var bfn = document.createElement("b"); 
                        bfn.appendChild(txtFunctionsAs);
                    }
                    var br0 = document.createElement("br"); 
                    
                    var aDetails = document.createElement("a"); 
                    aDetails.style.textDecoration = 'underline';
                    
                    aDetails.style.color = 'dimgray'; 
                    aDetails.onmouseover = function()
                    {
                        this.style.color = 'blue';
                        this.style.cursor = 'pointer';
                    }; 
                    aDetails.onmouseout = function()
                    {
                        this.style.color = 'dimgray';
                    }; 

                    
                    var txtDataSheet = document.createTextNode('Details');
                    
                    aDetails.appendChild(br0);
                    aDetails.appendChild(txtDataSheet);

                    if (products[j].DataSheet != null)
                    { 
                        aDetails.setAttribute('href', './DataSheets/' + products[j].DataSheet);  
                        aDetails.setAttribute('target', 'blank');  

                        dataSheetDiv.appendChild(aDetails);
                    }
                    else
                    {
                        if (products[j].Features)
                        {
                            aDetails.setAttribute('id', products[j].ProductID);        
//                            aDetails.style.color = 'blue';
                            aDetails.onclick = onClickDetailsHandler;
                            dataSheetDiv.appendChild(aDetails);
                        }
                    }           
                    
                    
                    var txtCompBrand = document.createTextNode(products[j].CompBrand);
                    var br1 = document.createElement("br"); 
                    var br2 = document.createElement("br"); 
                    
                    productTitle.appendChild(txtProductName);
                    descriptionDiv.innerHTML = formatHtml(products[j].Description);
//                    descriptionDiv.appendChild(txtProductDescription);
                    descriptionDiv.appendChild(br1);
                    descriptionDiv.appendChild(br2);

                    if (funAs)
                    {    descriptionDiv.appendChild(txtFunctionsAsCap);
                        descriptionDiv.appendChild(bfn);
                    }
                    descriptionDiv.appendChild(dataSheetDiv);
                    
                    if(products[j].Features)
                        descriptionDiv.appendChild(divFeatures);
                    
                    imagesDiv.appendChild(i);

                    actualProductContent.appendChild(imagesDiv);
                    actualProductContent.appendChild(descriptionDiv);

                    
                    actualProductContent.appendChild(priceDiv);
                    
                    productContentMiddle.appendChild(productContentTop);
                    productContentMiddle.appendChild(productTitle);
                    productContentMiddle.appendChild(actualProductContent);
                    productContentMiddle.appendChild(productContentBottom);
                    

                    productContent.appendChild(productContentMiddle);
                    
    
                    tempCM.appendChild(productContent);
                    j++;
                }
                xx.appendChild(tempCM);
                xx.style.height = '100%';
                xx.style.display = 'block';
                document.getElementById('divLoading').style.visibility = 'hidden';
//                document.getElementById('actualContent').parentNode.parentNode.parentNode.style.height = '100%';
//                document.getElementById('divMaster').style.height = '100%';
//                document.getElementById('divMasterCenter').style.height = '100%';
                
            }
        
        }
        catch(ex)
        {
            alert('BuildCatalogueContentElement 1:' + ex.message);
        }
    }
    catch(ex)
    {
//        stopDownl();
    }
    

}


function createNoFlickerDivLayer1(id, width, height)
{
    var d = document.createElement("div"); 
    d.id = 'layer1_' + id; 
    d.style.position = 'absolute'; 
    d.style.width = width; 
    d.style.height = height; 
    d.style.left = '0px'; 
    d.style.top = '0px'; 
    d.style.zIndex = '1'; 
    d.style.textAlign = 'center';

    d.onmouseover = onmovrHandlerNoFlickerDiv;
    
    return d;
}

function createNoFlickerDivLayer2(id, width, height)
{
    var d = document.createElement("div"); 
    d.id = 'layer2_' + id; 
    d.style.position = 'absolute'; 
    d.style.width = width; 
    d.style.height = height; 
    d.style.left = '0px'; 
    d.style.top = '0px'; 
    d.style.zIndex = '2';
    d.style.textAlign = 'center'; 
    
    return d;
}


function formatHtml(html)
{
    var textToChange = html;
    textToChange = textToChange.replace(/&amp;bull;/g, '&nbsp;&bull;&nbsp;');
    textToChange = textToChange.replace(/&amp;nbsp;/g, '&nbsp;');
    textToChange = textToChange.replace(/\\u000d\\u000a/g, '<br>');
    textToChange = textToChange.replace(/&amp;lt;/g, '<');
    textToChange = textToChange.replace(/&amp;gt;/g, '>');
    textToChange = textToChange.replace(/&lt;/g, '<');
    textToChange = textToChange.replace(/&gt;/g, '>');
    textToChange = textToChange.replace(/\\/g, '');
    textToChange = textToChange.replace(/u0027/g, '\'');

    return textToChange;
}



function EnquireAboutProduct(Product)
{
    
    document.getElementById('actualContent').style.display = 'none';
    document.getElementById('enqEmail').style.display = 'block';
    document.getElementById('ctl00_ContentPlaceHolder1_enqSubject').value = 'Enqiry about ' + Product.substring(5);
    
}
