﻿var _carrier;
var _brand;
var _model;
var _sourcesite = 'CellTrust'; 
var _displayLoading = 'none';
var _domainpath;
var _level = '';

function tableCarrierSelect(cell){
    _carrier = this.id;
    loadCarriers();
}
function tableBrandSelect(){
    _brand = this.id; 
    loadBrands();        
}
function tableModelSelect(){
    _model = this.id;
    loadModels();         
}
function setDomainPath(domainpath){
    _domainpath = domainpath;
}
function startCarriers(domainpath){
    _level = "carriers";
    document.getElementById('BreadPath').innerHTML = '';
    loadJSON('http://' + _domainpath + '/services/SupportedPhones.aspx?step=1&callback=processData' + '&sourcesite=' + _sourcesite);
}
function loadCarriers(){
    _level = "brands";
    loadJSON('http://' + _domainpath + '/services/SupportedPhones.aspx?step=2&carrier='+ _carrier.replace('&','%26') + '&callback=processData' + '&sourcesite=' + _sourcesite)
}
function loadBrands(){
    _level = "models";
    loadJSON('http://' + _domainpath + '/services/SupportedPhones.aspx?step=3&carrier='+ _carrier.replace('&','%26')+'&brand='+ _brand.replace('&','%26') + '&callback=processData' + '&sourcesite=' + _sourcesite)
}        
function loadModels(){
    _level = "teststatus";
    loadJSON('http://' + _domainpath + '/services/SupportedPhones.aspx?step=6&carrier='+ _carrier.replace('&','%26')+'&brand='+ _brand.replace('&','%26') +'&model='+ _model.replace('&','%26') + '&callback=processData' + '&sourcesite=' + _sourcesite)
}
        
function loadJSON(url) {
   
        // if script already exists, blank it
        if (document.getElementById('loadJSONScript') != null){
            document.getElementsByTagName("head")[0].removeChild(document.getElementById('loadJSONScript'));
        }
        document.getElementById('loading').style.display = '';
        var headID = document.getElementsByTagName("head")[0];
        var newScript = document.createElement('script');
        newScript.id = "loadJSONScript";
        newScript.type = 'text/javascript';
        newScript.defer = 'defer';
        newScript.src = url;
        headID.appendChild(newScript);
}
     
function processData(JSONData) {
    document.getElementById('loading').style.display = 'none';
    document.getElementById('passedimg').style.display = 'none';
    //document.getElementById('BreadPath2').innerHTML = '';
    if (JSONData.Result){
        if (JSONData.Result.Carrier){
            document.getElementById('BreadCrumbs').innerHTML = '';
            document.getElementById('noback').style.display = 'none';
            //document.getElementById('BreadCrumbs').appendChild(buildCrumb('span','Carriers',startCarriers,null,'#0169d8'));
            document.getElementById("divCard1").innerHTML = '';
            var x = 0;
            if (JSONData.Result.CarrierCount > 1){
                while (JSONData.Result.Carrier[x]){
                    // load the image array
                    addThumb('divCard1',JSONData.Result.Carrier[x].split(',')[0],JSONData.Result.Carrier[x].split(',')[1],tableCarrierSelect, '135', '60', false);
                    x ++;
                }
             }else if (JSONData.Result.CarrierCount == 1){
                addThumb('divCard1',JSONData.Result.Carrier.split(',')[0],JSONData.Result.Carrier.split(',')[1],tableCarrierSelect, '135', '60', false);
             }
             document.getElementById("Card1").style.display = '';
             document.getElementById("Card2").style.display = 'none';
             document.getElementById("Card3").style.display = 'none';
             document.getElementById("Card4").style.display = 'none';
        }
        if (JSONData.Result.Brand){document.getElementById('BreadCrumbs').innerHTML = '';
            document.getElementById('noback').style.display = '';
            document.getElementById('BreadCrumbs').appendChild(buildCrumb('span','Carriers',startCarriers,'underline','#0169d8'));
            document.getElementById('BreadCrumbs').appendChild(buildCrumb('label',' / ',null,null,'#0169d8'));
            document.getElementById('BreadCrumbs').appendChild(buildCrumb('span','Brands',loadCarriers,null,'#0169d8'));
            document.getElementById('BreadPath').innerHTML = '';
            document.getElementById('BreadPath').appendChild(buildCrumb('span',_carrier,null,null,'#777'));
        
            document.getElementById("divCard2").innerHTML = '';
            var x = 0;
            if (JSONData.Result.BrandCount > 1){
                while (JSONData.Result.Brand[x]){
                addThumb('divCard2',JSONData.Result.Brand[x].split(',')[0],JSONData.Result.Brand[x].split(',')[1],tableBrandSelect, '130', '60', false);
                x ++;
                }
            }else if (JSONData.Result.BrandCount == 1){
                addThumb('divCard2',JSONData.Result.Brand.split(',')[0],JSONData.Result.Brand.split(',')[1],tableBrandSelect, '130', '60', false);
            }
            document.getElementById("Card1").style.display = 'none';
            document.getElementById("Card2").style.display = '';
            document.getElementById("Card3").style.display = 'none';
            document.getElementById("Card4").style.display = 'none';
        }
        if (JSONData.Result.Model){
            document.getElementById('BreadCrumbs').innerHTML = '';
            document.getElementById('noback').style.display = '';
            document.getElementById('BreadCrumbs').appendChild(buildCrumb('span','Carriers',startCarriers,'underline','#0169d8'));
            document.getElementById('BreadCrumbs').appendChild(buildCrumb('label',' / ',null,null,'#0169d8'));
            document.getElementById('BreadCrumbs').appendChild(buildCrumb('span','Brands',loadCarriers,'underline','#0169d8'));
            document.getElementById('BreadCrumbs').appendChild(buildCrumb('label',' / ',null,null,'#0169d8'));
            document.getElementById('BreadCrumbs').appendChild(buildCrumb('span','Models',loadBrands,null,'#0169d8'));
            document.getElementById('BreadPath').innerHTML = '';
            document.getElementById('BreadPath').appendChild(buildCrumb('span',_carrier,null,null,'#777'));
            document.getElementById('BreadPath').appendChild(buildCrumb('label',' / ',null,null,'#777'));
            document.getElementById('BreadPath').appendChild(buildCrumb('span',_brand,null,null,'#777'));
            document.getElementById("divCard3").innerHTML = '';
            var x = 0;
            document.getElementById('supported').innerHTML = '';
            document.getElementById('Card3Prompt').innerHTML = 'Please select your mobile device:';
            if (JSONData.Result.Model == "No Models,0"){
                document.getElementById('Card3Prompt').innerHTML = 'No models on file for ' + _brand;
            }else if (JSONData.Result.ModelCount > 1){
                while (JSONData.Result.Model[x]){
                    // div "id" is the model + the dup index, dup index is the last parm on the model line
                    var thismodel = JSONData.Result.Model[x];
                    var dupindex = thismodel.split(',').length-1
                    addThumb('divCard3',thismodel.split(',')[0] + ',' + thismodel.split(',')[dupindex] + ',' + thismodel.split(',')[4], thismodel.split(',')[1], tableModelSelect,'93','129',true, thismodel.split(',')[2],thismodel.split(',')[3], thismodel.split(',')[5], thismodel.split(',')[6], thismodel.split(',')[7]) ;//'130', '180', true, );
                    //addThumb('divCard3',JSONData.Result.Model[x].split(',')[0] + ',' + JSONData.Result.Model[x].split(',')[JSONData.Result.Model[x].split(',').length-1] + ',' + + JSONData.Result.Model[x].split(',')[3],JSONData.Result.Model[x].split(',')[1],tableModelSelect, '130', '180', true);
                    
                    x ++;
                }
            }else if (JSONData.Result.ModelCount == 1){
                // div "id" is the model + the dup index
                addThumb('divCard3',JSONData.Result.Model.split(',')[0] + ',0' + ',' + JSONData.Result.Model.split(',')[4] ,JSONData.Result.Model.split(',')[1],tableModelSelect, '130', '180', true, JSONData.Result.Model.split(',')[2], JSONData.Result.Model.split(',')[3], JSONData.Result.Model.split(',')[5], JSONData.Result.Model.split(',')[6], JSONData.Result.Model.split(',')[7]);                 
            }
            document.getElementById("Card1").style.display = 'none';
            document.getElementById("Card2").style.display = 'none';
            document.getElementById("Card3").style.display = '';
            document.getElementById("Card4").style.display = 'none';
        }
        if (JSONData.Result.TestStatus){
            //window.scroll(0,0); // set page back to top -- horizontal and vertical scroll targets
            // SoftScroll.scrollTo(0,0);
            // if skipping straight from Brand to a single model, then fix up the bread crumb.
            if (document.getElementById('bc_Models')){
                document.getElementById('bc_Models').style.textDecoration = 'underline';
                document.getElementById('bc_Models').style.cursor = 'pointer';
            }
            if (document.getElementById('bc_Brands')){
                document.getElementById('bc_Brands').style.textDecoration = 'underline';
                document.getElementById('bc_Brands').style.cursor = 'pointer';
            }
            _model = JSONData.Result.TestStatus.split(',')[0];
            document.getElementById('BreadCrumbs').appendChild(buildCrumb('label',' / ',null,null,'#0169d8'));
            document.getElementById('BreadCrumbs').appendChild(buildCrumb('span','Handset',null,null,'#0169d8'));
            
            document.getElementById('BreadPath').innerHTML = '';
            
            document.getElementById('downloadways').innerHTML = '';
            document.getElementById('downloadways').style.display = 'none';
            document.getElementById("OS").style.display = 'none';
            document.getElementById("OS").innerHTML = '';
            
            document.getElementById('Card4Img').innerHTML = '';  
            
            var teststatus = JSONData.Result.TestStatus;
            addThumb("Card4Img",teststatus.split(',')[0],teststatus.split(',')[1],null,  '130', '180');  //model image path
            
            document.getElementById("phonecarrier").innerHTML = _carrier.replace('&','&amp;');
            document.getElementById("phonebrand").innerHTML = _brand;
            document.getElementById("phonemodel").innerHTML = teststatus.split(',')[0] + ( JSONData.Result.TestStatus.split(',')[15] ? ( JSONData.Result.TestStatus.split(',')[15].length > 0 ?  ' (' + JSONData.Result.TestStatus.split(',')[15] +  ')' : '' ) : ''); // model
            document.getElementById("phoneos").style.display = 'none';
            document.getElementById("phoneos").innerHTML = '';
            if (JSONData.Result.TestStatus.split(',')[14]){
                document.getElementById("OS").style.display = '';
                document.getElementById("OS").innerHTML = 'Platform/OS:';
                document.getElementById("phoneos").style.display = '';
                document.getElementById("phoneos").innerHTML = JSONData.Result.TestStatus.split(',')[14] ;
            }
            document.getElementById('KB').style.display = 'none';
            document.getElementById('KB').innerHTML = '';
            if (teststatus.split(',')[11]){ //KB field is not empty)
                document.getElementById('KB').style.display = '';
                document.getElementById('KB').innerHTML = ' (';
                addTag('KB','a','id','kblink',null, 'read notes');
                document.getElementById('kblink').setAttribute('href',JSONData.Result.TestStatus.split(',')[11]);
                document.getElementById('kblink').style.textDecoration = 'underline';
                document.getElementById('kblink').setAttribute('target','_blank');
                document.getElementById('KB').innerHTML =  document.getElementById('KB').innerHTML + '}';
            }
            
            document.getElementById('testhistory').style.display = 'none';
            document.getElementById('testhistorytitle').style.display = 'none';
            // delete any testrows from a previous viewing
            document.getElementById('testhistorycol1').innerHTML = "";
            document.getElementById('testhistorycol2').innerHTML = "";
            document.getElementById('testhistorycol3').innerHTML = "";

            if (JSONData.Result.TestHistory && false){ // for now - hide the test history grid 
                document.getElementById('testhistory').style.display = '';
                document.getElementById('testhistorytitle').style.display = '';
                addTag('testhistorycol1','div',null,null,'testheaderrow','SSMS Ver.');
                addTag('testhistorycol2','div',null,null,'testheaderrow','OS Ver.');
                addTag('testhistorycol3','div',null,null,'testheaderrow','Compatibility Test Status');
                var x = 0
                if (JSONData.Result.TestHistoryCount > 1){
                    while (JSONData.Result.TestHistory[x]){
                        addTag('testhistorycol1','div','id','thc1'+x.toString(),'testrowcol1',JSONData.Result.TestHistory[x].split(',')[0] == '' ? '&nbsp;&nbsp;': JSONData.Result.TestHistory[x].split(',')[0]);
                        addTag('testhistorycol2','div','id','thc2'+x.toString(),'testrowcol2',JSONData.Result.TestHistory[x].split(',')[1] == '' ? '&nbsp;&nbsp;': JSONData.Result.TestHistory[x].split(',')[1]);
                        addTag('testhistorycol3','div','id','thc3'+x.toString(),'testrowcol3',JSONData.Result.TestHistory[x].split(',')[2] == '' ? '&nbsp;&nbsp;': JSONData.Result.TestHistory[x].split(',')[2]);
                        document.getElementById('thc1'+x.toString()).setAttribute('title',JSONData.Result.TestHistory[x].split(',')[0] == '' ? '&nbsp;&nbsp;': JSONData.Result.TestHistory[x].split(',')[0]);
                        document.getElementById('thc2'+x.toString()).setAttribute('title',JSONData.Result.TestHistory[x].split(',')[1] == '' ? '&nbsp;&nbsp;': JSONData.Result.TestHistory[x].split(',')[1]);
                        document.getElementById('thc3'+x.toString()).setAttribute('title',JSONData.Result.TestHistory[x].split(',')[2] == '' ? '&nbsp;&nbsp;': JSONData.Result.TestHistory[x].split(',')[2]);
                        x ++;
                    }
                }else if (JSONData.Result.TestHistoryCount == 1){
                    addTag('testhistorycol1','div','id','thc1','testrowcol1',JSONData.Result.TestHistory.split(',')[0] == '' ? '&nbsp;&nbsp;': JSONData.Result.TestHistory.split(',')[0]);
                    addTag('testhistorycol2','div','id','thc2','testrowcol2',JSONData.Result.TestHistory.split(',')[1] == '' ? '&nbsp;&nbsp;': JSONData.Result.TestHistory.split(',')[1]);
                    addTag('testhistorycol3','div','id','thc3','testrowcol3',JSONData.Result.TestHistory.split(',')[2] == '' ? '&nbsp;&nbsp;': JSONData.Result.TestHistory.split(',')[2]);
                    document.getElementById('thc1').setAttribute('title',JSONData.Result.TestHistory.split(',')[0] == '' ? '&nbsp;&nbsp;': JSONData.Result.TestHistory.split(',')[0]);
                    document.getElementById('thc2').setAttribute('title',JSONData.Result.TestHistory.split(',')[1] == '' ? '&nbsp;&nbsp;': JSONData.Result.TestHistory.split(',')[1]);
                    document.getElementById('thc3').setAttribute('title',JSONData.Result.TestHistory.split(',')[2] == '' ? '&nbsp;&nbsp;': JSONData.Result.TestHistory.split(',')[2]);
                }
            }
            document.getElementById("Card1").style.display = 'none';
            document.getElementById("Card2").style.display = 'none';
            document.getElementById("Card3").style.display = 'none';
            document.getElementById("Card4").style.display = '';
        
            document.getElementById("notebackground").style.display = '';
            document.getElementById("note").style.display = '';
            document.getElementById("phonenote").style.display = '';
            document.getElementById("note").innerHTML = 'Description:';
            document.getElementById("phonenote").innerHTML = '';
            document.getElementById("phonestatus").innerHTML = '';
            
            var passed = false;
            var notes = false;
            var ssmspossible = (JSONData.Result.TestStatus.split(',')[3] == 'Yes' ? true : false); // is ssms possible on this phone?
            var certrequired = (JSONData.Result.TestStatus.split(',')[4] == 'Yes' ? true : false); // does carrier require certification?
            var phoneiscertified = (JSONData.Result.TestStatus.split(',')[5] == 'Yes'  ? true : false); // is this phone carrier certified?
            var stilltesting = false;
            if (JSONData.Result.TestHistoryCount > 0){
                // find the latest tested version that passed or the last version tested
                var testhistory = '';
                if (JSONData.Result.TestHistoryCount > 1){
                    var x = JSONData.Result.TestHistoryCount - 1;
                    while (JSONData.Result.TestHistory[x]){ // iterate backwards to find the latest passed version
                        if (JSONData.Result.TestHistory[x].split(',')[2].toLowerCase().indexOf('passed') > -1){
                            testhistory = JSONData.Result.TestHistory[x];
                            passed = true;
                            
                            break;
                        }
                        x --;
                    }
                    if (testhistory.length == 0){
                        testhistory = JSONData.Result.TestHistory[JSONData.Result.TestHistoryCount - 1]; // use the latest test
                    }
                    
                }else if (JSONData.Result.TestHistoryCount == 1){
                    testhistory = JSONData.Result.TestHistory;
                    passed = (testhistory.split(',')[2].toLowerCase().indexOf('passed') > -1 ? true : false);
                }
                if (passed && testhistory.split(',')[2].toLowerCase().indexOf('notes') > -1){
                    notes = true;
                }
                if (passed){
                    document.getElementById("phonestatus").innerHTML = testhistory.split(',')[2];
                    if (notes){
                        document.getElementById("phonenote").innerHTML = 'Compatible handset. Handset is tested and approved for SecureSMS. Minor (cosmetic) issues might have been detected. Select an installation for this handset.';
                    }else{
                        document.getElementById("phonenote").innerHTML = 'Compatible Handset. Handset is tested and approved for SecureSMS. Select an installation for this handset.';
                    }
                   
                }else{  // no passed reports on file, all of these present: Subscribe for notification';
                    stilltesting = true; // inhibit showing any download links
                    if (testhistory.split(',')[2].toLowerCase().indexOf('failed') > -1){
                            document.getElementById("phonestatus").innerHTML = testhistory.split(',')[2];
                            document.getElementById("phonenote").innerHTML = 'This handset failed the test for SecureSMS compatibility. Currently SecureSMS is NOT available for this handset. ';
                    }
                    else if (testhistory.split(',')[2].toLowerCase().indexOf('detected') > -1){
                            document.getElementById("phonestatus").innerHTML = testhistory.split(',')[2];
                            document.getElementById("phonenote").innerHTML = 'CellTrust is testing this handset and has detected some issues. ';
                    }
                    else if (testhistory.split(',')[2].toLowerCase().indexOf('bug') > -1){
                            document.getElementById("phonestatus").innerHTML = testhistory.split(',')[2];
                            document.getElementById("phonenote").innerHTML = 'CellTrust has tested this handset and has detected some issues. ';
                    }
                    else if (testhistory.split(',')[2].toLowerCase().indexOf('regression') > -1){
                            document.getElementById("phonestatus").innerHTML = testhistory.split(',')[2];
                            document.getElementById("phonenote").innerHTML = 'This handset is in regression test. ';
                    }
                    else if (testhistory.split(',')[2].toLowerCase().indexOf('started') > -1){
                            document.getElementById("phonestatus").innerHTML = testhistory.split(',')[2];
                            document.getElementById("phonenote").innerHTML = 'Celltrust is testing this handset. ';
                    }
                    else if (testhistory.split(',')[2].toLowerCase().indexOf('not supported') > -1){
                            document.getElementById("phonestatus").innerHTML = testhistory.split(',')[2];
                            document.getElementById("phonenote").innerHTML = 'CellTrust has tested this handset and has detected some issues. ';
                    }
                    
                    addTag('phonenote','a','id','phonenoteSubscribeLink',null, 'Subscribe');
                    document.getElementById('phonenoteSubscribeLink').href = 'javascript:OpenSubscribe(this)';
                    document.getElementById('phonenoteSubscribeLink').style.textDecoration = 'underline';
                    document.getElementById('phonenote').innerHTML = document.getElementById('phonenote').innerHTML + ' for updates about this phone';
                }
            }else{ // no test history
                if (ssmspossible){
                    document.getElementById("phonestatus").innerHTML = 'Not Tested - Expected to support'; 
                    document.getElementById("phonenote").innerHTML = 'This handset is expected to support SecureSMS although CellTrust has not tested the handset. If you want to try SecureSMS now, select an installation for this handset. ';
                }else{
                    document.getElementById("phonestatus").innerHTML = 'Not Tested - Not Expected to support';
                    document.getElementById("phonenote").innerHTML = 'This handset is not expected to support SecureSMS although CellTrust has not tested the handset or the test is still in progress. ';
                } 
                // add subscribe for notification to the phonenote
                addTag('phonenote','a','id','phonenoteSubscribeLink',null, 'Subscribe');
                document.getElementById('phonenoteSubscribeLink').href = 'javascript:OpenSubscribe(this)';
                document.getElementById('phonenoteSubscribeLink').style.textDecoration = 'underline';
                document.getElementById('phonenote').innerHTML = document.getElementById('phonenote').innerHTML + ' for updates about this phone';                    
            }
            if  (!stilltesting && certrequired && !phoneiscertified){ // does carrier require certification and is phone not certified?
                document.getElementById("phonestatus").innerHTML = (document.getElementById("phonestatus").innerHTML.length > 0 ? document.getElementById("phonestatus").innerHTML + ' - ' : '') + 'Not carrier certified'; //JSONData.Result.TestHistory.split(',')[2];
                document.getElementById("phonenote").innerHTML = 'This handset is in certification process. Currently, SecureSMS is NOT available for this handset. '; 
                addTag('phonenote','a','id','phonenoteSubscribeLink',null, 'Subscribe');
                document.getElementById('phonenoteSubscribeLink').href = 'javascript:OpenSubscribe(this)';
                document.getElementById('phonenoteSubscribeLink').style.textDecoration = 'underline';
                document.getElementById('phonenote').innerHTML = document.getElementById('phonenote').innerHTML + ' for updates about this phone';        
            }
            // installation options if passed testing or ssms is possible, and (if carrier requires certification and phone is certified or certification is not required)
            document.getElementById('installationsList').innerHTML = '';
            if (!stilltesting && ((passed || ssmspossible) && ( certrequired && phoneiscertified  || !certrequired  ))){ 
                //if (passed && (certrequired && phoneiscertified  || !certrequired  )){
                //if (passed){
                    // show the you can download it image
                    var pdiv = document.getElementById('passedimg');
                    pdiv.innerHTML = '';
                    var newImg = document.createElement('img');
                    newImg.setAttribute('src','/images/phones/compatible.png');
                    newImg.setAttribute('width','120');
                    newImg.setAttribute('height','120');
                    pdiv.appendChild(newImg);
                    pdiv.style.display = '';
                //}
                // create a link to the download load file for this phone
//                if (JSONData.Result.TestStatus.split(',')[16]){
//                    document.getElementById('downloadlink').style.display = '';
//                    addTag('downloadlink','a','id','downloadfilelink',null, 'Download Now');
//                    document.getElementById('downloadfilelink').href = JSONData.Result.TestStatus.split(',')[16];
//                    document.getElementById('downloadfilelink').style.textDecoration = 'underline';
//                    //document.getElementById('downloadlink').innerHTML = document.getElementById('downloadlink').innerHTML + ' installation file for this phone';                    
//                }
                if ((certrequired && phoneiscertified  || !certrequired  )){
                    document.getElementById('installationsList').innerHTML = 'Installation(s) available for this handset:';
                    document.getElementById('downloadways').style.display = '';
                    // create a bulleted list of wayst to install SecureSMS
                    addTag('downloadways','ul','id','ulroot',null,null);
                    if (JSONData.Result.TestStatus.split(',')[10] == 'Yes'){ // web download
                        addTag('ulroot','li','id','li1',null,'');
                        addTag('li1','a','id','weblink',null, 'Direct Download on Your Phone');
                        document.getElementById('weblink').setAttribute('href','http://' + _domainpath + '/products/SecureSMS/CellTrust-SecureSMS-Download.html?downloadid=' + JSONData.Result.DownloadID );
                        document.getElementById('weblink').style.textDecoration = 'underline';
                        document.getElementById('li1').innerHTML = document.getElementById('li1').innerHTML + ' (Data service required)';
                    }
                    if (JSONData.Result.TestStatus.split(',')[8] == 'Yes' | JSONData.Result.TestStatus.split(',')[9] == 'Yes' | JSONData.Result.TestStatus.split(',')[6] == 'Yes'){ // Cable, bluetooth, obex
                        // addTag('downloadways','div','id','cableway',null,null);
                        addTag('ulroot','li','id','li2',null,'');
                        addTag('li2','a','id','cablelink',null, 'Get SecureSMS Installation File on your PC');
                        //document.getElementById('cablelink').href = JSONData.Result.TestStatus.split(',')[16];  // download file path
                        document.getElementById('cablelink').href = 'http://'+ _domainpath + '/products/SecureSMS/CellTrust-Secure-SMS_AgreeDownload.html?filepath=' + JSONData.Result.TestStatus.split(',')[16];  // download file path
                        document.getElementById('cablelink').style.textDecoration = 'underline';
                       
                       // installation instructions
//                        addTag('downloadways','span',null,null,null, 'Instructions: ');
//                        addTag('downloadways','a','id','ddoyp',null, 'Cable or Bluetooth');
//                        document.getElementById('ddoyp').setAttribute('href','http://' + _domainpath + '/products/SecureSMS/CellTrust-Secure-SMS-PCInstallation-instruction.html');
//                        document.getElementById('ddoyp').style.textDecoration = 'underline';
//                        document.getElementById('ddoyp').innerHTML = document.getElementById('ddoyp').innerHTML + ' Installation';
//                        addTag('downloadways','span',null,null,null, ', ');
//                        addTag('downloadways','a','id','fmc',null, 'Flash Memory Card');
//                        document.getElementById('fmc').setAttribute('href','http://' + _domainpath + '/products/SecureSMS/CellTrust-Secure-SMS-FlashMemoryInstallation-instruction.html');
//                        document.getElementById('fmc').style.textDecoration = 'underline';
//                        document.getElementById('fmc').innerHTML = document.getElementById('fmc').innerHTML + ' Installation';
                    }       
                }                
            }
        } 
    }
}
     
function OpenSubscribe(parent){
    var url = "http://" + _domainpath + "/products/SecureSMS/SecureSMS_Subscription.html";
    url = url + "?var carrier = " + _carrier.replace('&','%26') + "& var brand = " + _brand + "& var model = " + _model;
    var w = window.open (url,"mywindow","menubar=1,resizable=1,width=400,height=445"); 
    w.moveTo(this.screenLeft+50,this.screenTop+50);
}

function buildCrumb(tag, text, func, decoration, color){
    var span = document.createElement('span');
    span.innerHTML = text.replace('&','&amp;');
    if (func){
        span.onclick = func;
    }
    if (decoration){
        span.style.textDecoration = decoration;
    }
    span.style.color = color;
    span.setAttribute('id','bc_'+text);
    if (decoration == 'underline'){
        span.style.cursor = 'pointer';
        
    }
    return span;
}
     
function addTag(parentDiv, tag, attribute , attriValue, classname, innerhtml){
    var tableDiv = document.getElementById(parentDiv);
    //var newDiv = document.createElement('div');
    var newDiv = document.createElement(tag);
    if (attribute != null && attriValue != null){
        newDiv.setAttribute(attribute,attriValue);
    }
    if (classname != null){
        newDiv.className = classname;
    }
    if (innerhtml != null){
        newDiv.innerHTML = innerhtml;
    }
    tableDiv.appendChild(newDiv);
}
 
function addThumb(parentDiv,altTag,imgPath, func, width, height, showAltTag, passedStatus, testingStatus, certRequired, phoneIsCertified, ssmsPossible ) {
    var tableDiv = document.getElementById(parentDiv);
    var newDiv = document.createElement('div');
    newDiv.setAttribute('id',altTag);
    newDiv.style.position = 'relative';
    newDiv.onclick = func;
    var certrequired;
    var phoneiscertified; 
    var ssmspossible;

    if (certRequired)
        certrequired = certRequired.toLowerCase() == 'yes' ? true : false;
    if (phoneIsCertified)
        phoneiscertified = phoneIsCertified.toLowerCase() == 'yes' ? true : false;
    if (ssmsPossible)
        ssmspossible = ssmsPossible.toLowerCase() == 'yes' ? true : false;

    
    var newImg = document.createElement('img');
    newImg.setAttribute('id','img_'+altTag);
    newImg.setAttribute('src','http://' + _domainpath + imgPath);
    if (width){
        newImg.setAttribute('width',width);
    }
    if (height){
        newImg.setAttribute('height',height);
    }
    if (func){
        newImg.style.cursor = 'pointer';
    }
    //newImg.style.position = 'relative';
    //newImg.style.top = '0';
    newDiv.appendChild(newImg);
    if (showAltTag && altTag){
        var newBr = document.createElement('br');
        newDiv.appendChild(newBr);
        var newSpan = document.createElement('span');
        newSpan.innerHTML = altTag.replace('&','&amp;').split(',')[0] + ( altTag.replace('&','&amp;').split(',')[2].length > 0 ?  ' (' + altTag.replace('&','&amp;').split(',')[2] +  ')' : '' ); // show only model name + pretty name, don't show dupindex
        newDiv.appendChild(newSpan);
    }
    
    // add the test status icon to the newDiv
    var passed = false;
    var stilltesting = false;
    if (passedStatus){
        if (passedStatus.toLowerCase().indexOf('notes') > -1){
            passed = true; // = '/images/phones/status_notes.png';
        }else if (passedStatus.toLowerCase().indexOf('passed') > -1){
            passed = true; // = '/images/phones/sms_approved.png';
        }
    }else if (testingStatus){
        if (testingStatus.toLowerCase().indexOf('started') > -1){
            stilltesting = true;
        }
        if (testingStatus.toLowerCase().indexOf('not supported') > -1){
            stilltesting = true;
        }
    }
    
    if (!stilltesting && ((passed || ssmspossible) && ( certrequired && phoneiscertified  || !certrequired  ))){ 
        var statusImgPath = '';
        statusImgPath = '/images/phones/status_notes.png';
//        else if (testStatus.toLowerCase().indexOf('failed')  > -1){
//        statusImgPath = '/images/phones/status_failed.png';
//        }else if (testStatus.toLowerCase().indexOf('started')  > -1){
//        statusImgPath = '/images/phones/status_started.png';
//        }
        if (statusImgPath.length > 0){
            var newStatusImg = document.createElement('img');
            newStatusImg.setAttribute('id','img_'+altTag);
            newStatusImg.setAttribute('src',statusImgPath);
            newStatusImg.style.position = 'absolute';
            newStatusImg.style.bottom = '30px';
            newStatusImg.style.right = '10px';
            newDiv.appendChild(newStatusImg);
        }
    }
    
    tableDiv.appendChild(newDiv);
}

//// disable browser's back unless were showing carriers list
//onbeforeunload = function checkLevels(){
// "please use the breadcrumbs links to go back to a previous level"; return false;
//}
//if (typeof window.event != 'undefined')
//	document.onkeydown = function()
//	{
//	alert('onkeydown');
//		if (event.srcElement.tagName.toUpperCase() != 'INPUT')
//			return (event.keyCode != 8);
//	}
//else
//	document.onkeypress = function(e)
//	{
//	alert('onkeypress');
//		if (e.target.nodeName.toUpperCase() != 'INPUT')
//			return (e.keyCode != 8);
//	}

//window.onkeydown="escBackSpace();";
//window.onblur="lostBfocus();" 

//var gotBodyFocus=0; // used in gotBFocus() function.

//function escBackSpace() // called on document.body keydown event
// {
//    if(event.keyCode == 8)
//       {
//          if  (gotBodyFocus == 1 | document.activeElement.getAttribute("type") != "text") // to avoid the backspace event except the Textbox 
//           {
//             //event.keyCode = 0;
//             event.returnValue=false
//           }
//           
//       }    
// }

//function gotBfocus() //called on document.body onfocus event
//{
//  gotBodyFocus = 1;
// }

//function lostBfocus() // called on document.body onblur event
//{
//  gotBodyFocus = 0;
//}



