﻿window.onload = function(){
    getData2(0,1,'');
    interv = window.setInterval( function (){ getData(0,0,'') } , 10 );
    tabs();
    /*getData(0,0,'');*/
    /* sendRequestXML(1,'a');loadIndex();*/
};

var paging_total;
var lowerBound;
var upperBound;
//var txtBx;
//var targetDiv;
var method_ = 'get';
var URL_ = 'AircraftCatalogCode.aspx';
//var params_ = '?p=';
var params_ = new Array('p','typeID','modelID');
var response;
var path = new Array();
var stored_cats;
var miles;
var x = false;
//##############################################################
//send the ajax request
function getData( w , id_of_sent_cat_or_sub_cat , parent_id ){//alert(w);alert(id_of_sent_cat_or_sub_cat);alert(parent_id);
//alert(parent_id);
    if( x ){
        clearInterval( interv );
        param_value = params_[w];
        p_id = parent_id;
        //$('leftPanel').innerHTML = 'Loading...';
        //alert($(p_id).className);
        
        http.open( method_ , URL_ + "?" + param_value + '=' + id_of_sent_cat_or_sub_cat , true );
        http.onreadystatechange = function (){ handleResponseGetData( w , p_id ) };
	    http.send( null );
	}

}
//##############################################################
//send the ajax request
function getData2( w1 , id_of_sent_cat_or_sub_cat1 , parent_id1 ){
    
    ///////////////////////////////////////////
    //x is the readystate function identifier
    ///////////////////////////////////////////
    
    //alert(w);
    param_value2 = params_[w1];
    //alert(param_value);
    
    http.open( method_ , URL_ + "?" + param_value2 + '=' + id_of_sent_cat_or_sub_cat1 , true );
    
    //if( x == 1 ) http.onreadystatechange = function (){ handleResponseGetManufacturerData() };
    http.onreadystatechange = function (){ handleResponseGetManufacturerData(); };
    //else if( x == 2 ) http.onreadystatechange = function (){ handleResponseDisplayResults1() };
	http.send( null );

}
//##############################################################
function getData3( mnf , r1 , r2 , miles_kilometers , reset , display_back ){

    m_ = $( mnf );
    r1_ = $( r1 );
    r2_ = $( r2 );
    page = $('page'); // for paging
    miles_kilometers_ = $( miles_kilometers );
    const_ = 1.60934;
    r_ = '';
    
    $('distance_two_airports').style.display = 'none';
    if( reset ){
        //reset paging hidden field
        //alert('reset');
        page.value = 1;
    }
    if( display_back ){
        $('back').style.display = 'none';
        $('paging').style.display = 'none';
    }
    
    if( r1_.value != '' ){
        //update [28-10-2008]
        r1_splitted = document.getElementById(r1).value.split("-");
        
        //validate r1 && r2
        r = '';
        //alert( r );
        
        if( r == '' ){ // everything is ok
        
                //check for numbers
                x1 = true;
                x2 = true;
                
                if( x1 && x2 ){ //values entered r ok
                    
                        //if kilometers
                        if( miles_kilometers_.value == 'km' ){//convert to kms
                        
                            _r1_ = r1_splitted[0] / const_;
                            _r2_ = r1_splitted[1] / const_;
                            
                        }else{
                            
                            _r1_ = r1_splitted[0];
                            _r2_ = r1_splitted[1];
                            
                        }
                        
                        //combine
                        r_ = _r1_ + '-' + _r2_;
                    
                }else{
                    alert('Please make sure that range values should be numbers only.');
                    return;
                }
                    
        }else{
            alert('Please make sure you enter a correct range values.');
            return;
        }
    }
    
    //show loading
    showLoadingContent('aircraft_content');
    //showLoadingContent('leftPanel');
    
    rt = GetSelectedRangeType();
    
    http.open( method_ , URL_ + "?p=2&m=" + m_.value + '&r=' + r_ + '&rt=' + rt + '&px=' + page.value , true );
	http.onreadystatechange = function (){ handleResponseDisplayResults1() };
	http.send( null );
	
	
}
//##############################################################
function GetSelectedRangeType() {

    chosen = "";
    len = $('aspnetForm').by.length;
    
    for (i = 0; i <len; i++) {
        if ( $('aspnetForm').by[i].checked ) {
            chosen = $('aspnetForm').by[i].id;
        }
    }

    return chosen;
}
//##############################################################
function getData4( mnf , r1 ){

    m_ = $( mnf );
    r_ = $( r1 );
    page = $('page'); // for paging
    page.value = 1;
    
    //show loading
    showLoadingContent('aircraft_content');
    //showLoadingContent('leftPanel');
    
    //alert(r_);
    
    http.open( method_ , URL_ + "?p=2&m=" + m_.value + '&r=' + r_.value + '&px=' + page.value , true );
	http.onreadystatechange = function (){ handleResponseDisplayResults1() };
	http.send( null );

}
//##############################################################
function IsNumeric( sText ){

   var ValidChars = "0123456789.";
   var IsNumber = true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++){
   
      Char = sText.charAt(i);
       
      if (ValidChars.indexOf(Char) == -1) {
         IsNumber = false;
      }
      
   }
   
   return IsNumber;
}
//##############################################################
function checkRange( r1 , r2 ){
    var r1_ = $( r1 ).value;
    var r2_ = $( r2 ).value;
    var msg;
    
    if( (r1_ == '' && r2_ != '') || (r1_ != '' && r2_ == '') ){ // one of them is empty
        msg = 'Please enter correct ranges.';
    }//else if( r1_ > r2_ ){// r1 < r2
        //msg = 'Range 1 should be less then range 2.';
    //}
    else{//correct
        msg = '';
    }
    
    return msg;
}
//##############################################################
function setDataFromSearch( r ){
    
    var m_len = r.results.length;
    paging_total = r.pagescount;
    
    $("aircraft_content").innerHTML = '<div style="border:0px solid red; float:left; width:100px;"><strong>Search results:</strong></div><br /><br />';
    
    if( $('page').value == 1 ) {
        $('paging').innerHTML = '';
        buildPaging(paging_total);
    }
    
    //$("leftPanel").innerHTML = '<br /><a href="#" onclick=\'$("leftPanel").innerHTML=\"<img src=\"./SiteImages/loading.gif\" />\";getData(0,0,"");return false;\'>&laquo; Back to main categories</a><br /><br /><div><strong>Search results:<br />Found ' + m_len + ' result(s)</strong></div><br />';
    
    for( i=0 ; i<m_len ; i++ ){
    
        b = r.results[i].model.type;
        a = r.results[i].model.manufacturer;
        c = r.results[i].model.name;
        d = r.results[i].model.range;
        id = r.results[i].model.id;
        //id = 90;
        
        $("aircraft_content").innerHTML += "<div style='float:left;border:0px solid red; width:20px; font-size:28px; margin-top:-10px;'>•</div><div style='float:left;border:0px solid red;'>Manufacturer: "+a +"<br />Type: "+ b +"<br />Name: <a href='#' onclick='showLoadingContent(\"aircraft_content\");getData(2,"+id+",\""+b+"|"+c+"\");$(\"back\").style.display=\"block\";$(\"paging\").style.display=\"none\";return false;'>" + c +"</a><br />Range: "+ isEmptyOrZero(d) +"</div><br style='clear:left;' /><br />";
        
        //$("leftPanel").innerHTML += "<div style='border:0px solid red;padding:3px;'><img src='Images/arrowbullet.png'>&nbsp;<a class='sub_cat' id='"+c+"' href='#' onclick='showLoadingContent(\"aircraft_content\");getData(2,"+id+",this.parentNode.id.slice(0,-1)+\"|\"+this.id);return false;'>" + c + "</a></div>";
        
    }
    
    //$("paging").style.display = 'block';
    //$("back").style.display = 'block';
    
    
}
//##############################################################
//when click on paging item
function pagingGo( pageID ){//alert(pageID);
    //change [page] value, then, send call
    document.getElementById('page').value = pageID;
    //reset paging
    resetPaging();
    //highlight the clicked value
    document.getElementById(pageID).className = 'aircraftsLink_over';
    //send the call
    getData3('mnf_menu','rng_from','rng_to','_km_');
    
}
//##############################################################
function resetPaging(){
    //reset all highlights
    for( i=1 ; i<=paging_total ; i++ ){
        document.getElementById( i ).className = 'aircraftsLink';
    }
}
//##############################################################
function buildPaging( p ){
    
    //$("paging").innerHTML += '<div style="border:1px solid red; width:70%; height:20px; margin-left:150px; position:absolute;">';
    //alert(p);
    //empty it first
    $("paging").style.display = 'block';
    $("back").style.display = 'none';
    
    lowerBound = 1;
    upperBound = p;
    
    for( i=1 ; i<=10,i<=upperBound ; i++ ){
    
        classname = 'aircraftsLink';
        if(i==1) classname = 'aircraftsLink_over';
                
        $("paging").innerHTML += '<a href="#" id="'+i+'" class="'+classname+'" onclick="pagingGo(this.id);return false;">' + i + '</a> ';
        
    }
    //alert($("paging").innerHTML);
    
    /*if( p > 10 ){
        $("paging").innerHTML += '<a href="#" id="next" class="aircraftsLink" onclick="getNextTen();return false;">&raquo;</a>';
    }*/
}
//##############################################################
function getNextTen(){

    //alert(lowerBound);alert(upperBound);

    $("paging").innerHTML = '';

    //previous
    $("paging").innerHTML = '<a href="#" id="previous" class="aircraftsLink" onclick="getPreviousTen();return false;">&laquo;</a> ';
        

    for( j=lowerBound+10 ; j<=lowerBound+20 ; j++ ){
        if( j<=upperBound && j<lowerBound+20 ){
            $("paging").innerHTML += '<a href="#" id="'+j+'" class="aircraftsLink" onclick="pagingGo(this.id);return false;">' + j + '</a> ';
        }
    }
    
    //next
    if( j < upperBound ){
        $("paging").innerHTML += '<a href="#" id="next" class="aircraftsLink" onclick="getNextTen();return false;">&raquo;</a>';
    }
    
    lowerBound += 10;
    
}
//##############################################################
function getPreviousTen(){
    
    //alert(lowerBound);alert(upperBound);
    
    $("paging").innerHTML = '';
    
    //previous
    if( lowerBound-10 > 1  ){//alert('display prev');
        $("paging").innerHTML = '<a href="#" id="previous" class="aircraftsLink" onclick="getPreviousTen();return false;">&laquo;</a> ';
    }
    
    for( k=lowerBound-10 ; k<lowerBound ; k++ ){
        $("paging").innerHTML += '<a href="#" id="'+k+'" class="aircraftsLink" onclick="pagingGo(this.id);return false;">' + k + '</a> ';
    }
    
    //next
    $("paging").innerHTML += '<a href="#" id="next" class="aircraftsLink" onclick="getNextTen();return false;">&raquo;</a>';
    
    lowerBound -= 10;
    
}
//##############################################################
function handleResponseDisplayResults1(){
    if(http.readyState == 4 && http.status == 200){
        
        //response is JSON-enabled object
        start_ = http.responseText;
        //alert(start_);
        
        if( start_ == 'no' ){
            response3 = '';
        }else{
            response3 = eval('('+start_+')');
        }
        
        if( response3 != '' ) {
            
            setDataFromSearch( response3 );
            
        }else{
            
            $("aircraft_content").innerHTML = 'We are sorry!<br /><br />No results found.';
            //$("leftPanel").innerHTML = 'We are sorry!<br /><br />No results found.';
                
        }
    }
}
//##############################################################
function handleResponseGetManufacturerData(){
    if(http.readyState == 4 && http.status == 200){
        
        //response is JSON-enabled object
        start2 = http.responseText;
        //alert(start2);
        
        if( start2 == '' ){
            response2 = '';
        }else{
            response2 = eval('('+start2+')');
        }
        
        if( response2 != '' ) {
            
            var m_len = response2.manufacturers.length;
            //alert(m_len);
            $("mnf_menu").options[ ++ $("mnf_menu").options.length-1 ].text = 'All';
            $("mnf_menu").options[ $("mnf_menu").options.length-1 ].value = '';
            
            for( i=0 ; i<m_len ; i++ ){
                k = response2.manufacturers[i].manufacturer.name;
                
                if(k != ''){
                    $("mnf_menu").options[ ++ $("mnf_menu").options.length-1 ].text = k;
                    $("mnf_menu").options[ $("mnf_menu").options.length-1 ].value = k;
                }
            }
            
            //show menu after build [fix here]: it was showing once there's data, even before handling this data
            $("mnf_menu").style.display = 'inline';
            
            
        }
        
        //display types
        x = true;
        
        //hide loading
        $("ldng").style.display = 'none';
        
    }
}
//##############################################################
function handleResponseGetData( id , pt_id ){//alert(id);alert(pt_id);

    if(http.readyState == 4 && http.status == 200){
        
        //response is JSON-enabled object
        start = http.responseText;
        //alert(start);
        
        if( start == 'no' ){
            response = 'no';
        }else{
            response = eval('('+start+')');
        }
        
        if( response != 'no' ) {
            
            //hide loading
            if( $("ll") && $("ll").style.display != 'none' ) $("ll").style.display = 'none';
            
            
            if( id == 0 ){ // get main tree childs
            
                listMainCategories( response );
                
            
            }else if( id == 1 ){ // get second tree sub-childs
                
                listSubCategories( response , pt_id );
                
            }else if( id == 2 ){ // get data of sub-childs
                
                listModelDetails( response , pt_id );
                
            }
        }else{
            //alert
            //alert("No SubCategories found.");
            //release the loading img with text
            $( pt_id + '1' ).innerHTML = '<div style="color:#FFF; padding-left:25px;">No subcategories found.</div><br />';
            $( pt_id ).className = 'cat-buttons-active';
        }
    }
}
//##############################################################
//function jeval(str){return eval('(' +  str + ')')} //var response = jeval(http.responseText);
//##############################################################
function hideMap( map ){
    if( $(map) ){
        $('mnf_menu').style.display = 'none';
        $(map).style.display = 'none';
    }
}
//##############################################################
function listMainCategories( r ){
    //count nodes
    
    var len = r.cats.length;
    stored_cats = r;
    $("leftPanel").innerHTML = '<br />';
    //id_of_cat=0;
    
    for( i=0 ; i < len ; i++ ){
    
        node = r.cats[i].cat.name;
        id_of_cat = r.cats[i].cat.id;
        
        //put the value in the catalog
        //$("leftPanel").innerHTML += "<div id='"+node+"' class='cat-buttons' onmouseover='plusChange(this.id,\"over\");' onmouseout='plusChange(this.id,\"out\");'><a id='"+node+"2' href='#' onclick='showLoadingTree(this.parentNode.id , "+id_of_cat+");getData(1,"+id_of_cat+",this.parentNode.id);return false;' style='text-decoration:none; border:0px solid red;'><img src=\"Images/plus-green.gif\"></a> <a href='#' onclick='showLoadingContent(\"aircraft_content\");setData("+id_of_cat+");return false;' style='text-decoration:none;'>" + node + "</a></div><div id='"+node+"1' style='border:0px solid red; background-color:#666;'></div><br />";  
        $("leftPanel").innerHTML += "<div id='"+node+"' class='cat-buttons'><a id='"+node+"2' href='#' onclick='showLoadingTree(this.parentNode.id , "+id_of_cat+");getData(1,"+id_of_cat+",this.parentNode.id);return false;' style='text-decoration:none; border:0px solid red;'><img src=\"Images/plus-green.gif\"></a> <a href='#' onclick='showLoadingContent(\"aircraft_content\");setData("+id_of_cat+");return false;' style='text-decoration:none;'>" + node + "</a></div><div id='"+node+"1' style='border:0px solid red; background-color:#666;'></div><br />";  
      
    }
}
function plusChange( id , OverOrOut ){

    
    //get conteainer id
    containerID = document.getElementById(id);

    //get IMg tag inside the container id
    internalIMGTag = containerID.getElementsByTagName('img');
    //alert( internalIMGTag.length );
    
    //get access to the IMG src and change it
    if( OverOrOut == 'over' ){
        //alert(id); 
        //alert('plus change over');       
        internalIMGTag[0].src = 'Images/plus-gray.gif';
    }else{
    //alert('plus change out');       
        internalIMGTag[0].src = 'Images/plus-green.gif';
    }
        
}
//##############################################################
function showLoadingTree( id , id_of_cat ){
    $( id + '1' ).innerHTML = '<img src="./SiteImages/loading.gif" /><br />'; //show loading...
    
    $( id + '2' ).innerHTML = '<img src="Images/minus.gif"> '; //show minus sign
    //alert($( id + '2' ).parentNode.onmouseover);
    //alert($( id + '2' ).parentNode.onmouseout);
    $( id + '2' ).parentNode.removeAttribute('onmouseover');
    $( id + '2' ).parentNode.removeAttribute('onmouseout');
    
    $( id + '2' ).onclick = function (){ collapse( id , id_of_cat ); return false; }; //assign code to the minus sign
}
//##############################################################
function collapse( id , id_of_cat ){

    $( id + '2' ).innerHTML = '<img src="Images/plus-green.gif"> '; //show plus sign
    $( id + '2' ).onclick = function (){ /*showLoadingTree( id , id_of_cat );*/expand( id , id_of_cat ); return false; };
    //alert(id);
    //alert($(id).attributes.length);
    //$( id + '2' ).parentNode.onmouseover = function(){ /*alert('collapse over');*/plusChange( id , "over" ); return false; };
    //$( id + '2' ).parentNode.addEventListener('mouseover',xx,false);
    //$( id + '2' ).parentNode.onmouseout = function(){ /*alert('collapse out');*/plusChange( id , "out" ); return false; };
    //alert($(id).attributes.length);
    //alert($(id).attributes[2].value);
    //hide the models
    $( id + '1' ).style.display = 'none';
    //release the over effect
    $( id ).className = 'cat-buttons';
    //if( $( id ).addEventListener ) alert('true');
    //else alert('false');
}
//function xx(){ plusChange( id , "over" ); return false; }
//##############################################################
function expand( id , id_of_cat ){
    //alert(id);
    //alert('hi');$( id + '2' ).innerHTML = '<img src="Images/minus.gif"> '; //show minus sign
    //alert($(id).attributes.length);
    $( id + '2' ).parentNode.removeAttribute('onmouseover');
    $( id + '2' ).parentNode.removeAttribute('onmouseout');
    $( id + '2' ).onclick = function (){ collapse( id , id_of_cat ); return false; };
    $( id + '2' ).innerHTML = '<img src="Images/minus.gif"> ';
    //show the models
    $( id + '1' ).style.display = 'block';
    $( id ).className = 'cat-buttons-active';
    //alert($(id).attributes.length);
}
//##############################################################
function setData( id ){
    
    var cats_len = stored_cats.cats.length;
    
    for( i=0 ; i<cats_len ; i++ ){
        if( stored_cats.cats[i].cat.id == id ){
            notes = stored_cats.cats[i].cat.notes;
        }
    }
    $("aircraft_content").innerHTML = notes;
    //hide the distance calculator results if visible
    $('distance_two_airports').style.display = 'none';
    
}
//##############################################################
function listSubCategories( r , p ){
    //count nodes
    var len_models = r.models.length;
    //alert(len_models);
    //alert(typeof(len_models));
    //hide loading
    $( p + '1' ).innerHTML = ' ';
    
    //loop on types
    for( j=0 ; j < len_models ; j++ ){

        //get models
        model_id = r.models[j].model.id;
        model_name = r.models[j].model.name;
        
        //write models
        $( p + '1' ).innerHTML += "<a class='sub-cat' id='"+model_name+"' href='#' onclick='showLoadingContent(\"aircraft_content\");getData(2,"+model_id+",this.parentNode.id.slice(0,-1)+\"|\"+this.id);document.getElementById(\"distance_two_airports\").style.display=\"none\";return false;'>" + model_name + "</a>";
        //alert(this.id);alert(this.parentNode.id.slice(0,-1));
        
        $(p).className = 'cat-buttons-active';
        
    }//for
    //$( parent_id + '1' ).innerHTML += "<br />";
}
//##############################################################
function listModelDetails( r , p ){

    //alert(response.model.data.images.length);

    /*if( $('paging').style.display == 'none' ){
        $('back').style.display = 'none';
        $('paging').style.display = 'block';
    }else{
        $('paging').style.display = 'none';
        $('back').style.display = 'block';
    }*/
    
    $("paging").style.display = 'none';
    //$("back").style.display = 'none';
    
    s = p.split("|");
    
    writeJSONModelContent();
    hideMap('map');
    m = r.model.data.name;
    $('selected_airjet').value = m;
    
}
//##############################################################
function writeJSONModelContent(){
    
    var c = '';
    var c_ = '';
    
    //suggest
    //c += "<div id='sug' style='border:0px solid red; height:30px; float:left;'>Select airport to check aircraft range:<br /><div style='width:100%; position:absolute;'><div style='position:relative;'><div id='from_ent_ac' class='ac_no_display'></div><input id='from_ent_suggest' type='hidden' value='0' /><input id='from_ent' type='text' onkeyup='searchXML2(\"from_ent\",\"from_ent_ac\");' autocomplete='off' style='width:180px;' /><span id='from_ent_nearby_loading' class='hide' style='vertical-align:bottom;'><img src='SiteImages/loading.gif' width='16' height='16' /></span></div></div></div>";
    
    /***********************************************************************************************/
    //images check
    im = response.model.data.images;
    //alert(im);
    if( im.length != 0 ){
    
        divID = "_mostafa";
        
        //alert(im[0].path);
        //xxx = path[0];
        
        
        //c += '<div style="margin-top:20px;text-align:center;margin:5px;right:75px;float:right; border:5px solid #82BF82;"><a href="#" onclick="$(\'mnf_menu\').style.display= \'none\';$(\'cover\').style.display=\'block\';Effect.Grow($(divID),{duration:.5});showImage(0);hideMap(\'map\');return false;"><img src="./'+im[0].path+'" width="150" height="150" /></a></div>';
        
        var counter = 1;
        var lBreak;
        
        c += '<div style="text-align:right;margin:5px;right:75px; float:right; border:0px solid #82BF82; z-index:3; width:140px;">';
        
        //alert(path[0]);
        //alert(path[1]);
        
        for( r = 0 ; r < im.length ; r++ ){
        
            
            if( counter < 2 ){
                lBreak = '';
            }else{
                lBreak = '<br />';
                counter = 0;
            }

            c += '<a href="#" onclick="$(\'mnf_menu\').style.display= \'none\';$(\'cover\').style.display=\'block\';Effect.Grow($(divID),{duration:.5});showImage('+r+');return false;"><img src="./'+im[r].path+'" width="50" height="50" style="padding:5px;border:1px solid #82BF82;" oncontextmenu="return false;" /></a>'+lBreak;
            
            counter++;
        }
        
        c += '</div>';
        //alert(c);
        
    }else if( im.length == 0 ){
    
        //c += '<div style="text-align:center; float:right;right:75px;margin:5px;"><div style=" border:5px solid red; width:150px; height:150px;">No Image</div></div>';
        
    }
    /***********************************************************************************************/
    //alert(c);
    //alert($('ctl00_content_txt_from_ent').value);
    
    g = response.model.data;
    manufacturer = g.manufacturer;
    PAXExclucingCrew = g.paxexclucingcrew;
    CertificationAOCDoc = g.certificationaocdoc;
	RequiredLandingDistance = g.requiredlandingdistance;
	MaximumSpeed = g.maximumspeed;
	maxCertifiedAltitude = g.maxcertifiedaltitude;
	RangeMaxPAX = g.rangemaxpax;
	maxRange = g.maxrange;
    cabinLength = g.cabinlength;
    cabinHeight = g.cabinheight;
    cabinWidth = g.cabinwidth;
    additionalInfo = g.additionalinfo;
    miles = g.miles;
    entertainment = g.entertainment;
    lavatory = g.lavatory;
    refreshmentOptions = g.refreshmentoptions;
    MedicalEquipment = g.medicalequipment;
    Microwave = g.microwave;
    DVDAirShow = g.dvdairshow;
    LinensForBeds = g.linensforbeds;
    DataPort = g.dataport;
    LeatherSeats = g.leatherseats;
    SatellitePhone = g.satellitephone;
    
    //new items
    maxpaxexcludingcrew = g.maxpaxexcludingcrew;
    pilotseats = g.pilotseats;
    cabinvolume = g.cabinvolume;
    maxtakeoffweight = g.maxtakeoffweight;
    fuelcapacity = g.fuelcapacity;
    maxcruisespeed = g.maxcruisespeed;
    serviceceiling = g.serviceceiling;
    bflmtow = g.bflmtow;
    productionstartedyear = g.productionstartedyear;
    productionendedyear = g.productionendedyear;
    modelnumber = g.modelnumber;
    maxpayloadperfullfuel = g.maxpayloadperfullfuel;
    
   
    //alert('Org: ' + additionalInfo);
    //aa = additionalInfo.split("||");
    
    //alert('Val1: ' + aa[0]);
    //alert('Val2: ' + aa[1]);
    
    c += '<span style="height:50px; border:0px solid red;"><br /><br />&nbsp;<br /><br />'
    
    //PDFs
    pdfs = response.model.data.dataSheets;
    
    if( pdfs.length != 0 ){
        c += '<a href="#" onclick="openPDFDiv();return false;">Aircraft Fact Sheets</a>';
    }
    
    c += '</span>';
    
    
    
    //alert(pdfs.length);
    
    if( pdfs.length != 0 ){
    
        PDFdivID = "_pdfs";
        
        //alert(im[0].path);
        //xxx = path[0];
        
        
        //c += '<div style="margin-top:20px;text-align:center;margin:5px;right:75px;float:right; border:5px solid #82BF82;"><a href="#" onclick="$(\'mnf_menu\').style.display= \'none\';$(\'cover\').style.display=\'block\';Effect.Grow($(divID),{duration:.5});showImage(0);hideMap(\'map\');return false;"><img src="./'+im[0].path+'" width="150" height="150" /></a></div>';
        
        //var counter_PDFs = 1;
        //var lBreak;
        
        c += '<div style="float:left; border:2px solid #3BBD56; z-index:3; width:300px; padding:5px; position:absolute; background-color:#DDFEE4; line-height:20px; display:none; #left:0px; #top:80px;" id="_pdf_" oncontextmenu="return false;">';
        c += '<div style="font-size:10px; float:right; cursor:pointer;" onclick="openPDFDiv();">Close</div>';
        
        //alert(path[0]);
        //alert(path[1]);
        
        for( r_ = 0 ; r_ < pdfs.length ; r_++ ){
        
            
            //if( counter_PDFs < 2 ){
                //lBreak = '';
            //}else{
                //lBreak = '<br />';
                //counter_PDFs = 0;
            //}

            c += '<a href="'+pdfs[r_].path+'" target="_blank">Fact Sheet'+ (r_+1) +'</a><br />';
            
            //counter_PDFs++;
        }
        
        c += '</div>';
        //alert(c);
        
    }else if( pdfs.length == 0 ){
    
        //c += '<div style="text-align:center; float:right;right:75px;margin:5px;"><div style=" border:5px solid red; width:150px; height:150px;">No Image</div></div>';
        
    }
    
    
    c += '<br /><br /><span class="bold_text">Type:</span> '+isEmptyOrZero(s[0])+'<br /><br />';
	c += '<span class="bold_text">Model:</span> '+isEmptyOrZero(s[1])+'<br /><br />';
	c += '<span class="bold_text">Manufacturer:</span> '+isEmptyOrZero(manufacturer)+'<br /><br />';
	c += '<span class="bold_text">PAX Exclucing Crew:</span> '+isEmptyOrZero(PAXExclucingCrew)+'<br /><br />';
//	c += '<span class="bold_text">Certification AOCDoc:</span> '+CertificationAOCDoc+'<br /><br />';
	c += '<span class="bold_text">Required Landing Distance:</span> '+isEmptyOrZero(RequiredLandingDistance)+'<br /><br />';
	c += '<span class="bold_text">Maximum Speed:</span> '+isEmptyOrZero(MaximumSpeed)+'<br /><br />';
	c += '<span class="bold_text">Max CertifiedAltitude:</span> '+isEmptyOrZero(maxCertifiedAltitude)+'<br /><br />';
	c += '<span class="bold_text">Range Max PAX:</span> '+isEmptyOrZero(RangeMaxPAX)+'<br /><br />';
	c += '<span class="bold_text">Max Range:</span> '+isEmptyOrZero(maxRange)+'<br /><br />';
    c += '<span class="bold_text">Cabin Length:</span> '+isEmptyOrZero(cabinLength)+'<br /><br />';
    c += '<span class="bold_text">Cabin Height:</span> '+isEmptyOrZero(cabinHeight)+'<br /><br />';
    c += '<span class="bold_text">Cabin Width:</span> '+isEmptyOrZero(cabinWidth)+'<br /><br />';
    
    //new items
	c += '<span class="bold_text">cabin volume:</span> '+isEmptyOrZero(cabinvolume)+'<br /><br />';
	c += '<span class="bold_text">max pax excluding crew:</span> '+isEmptyOrZero(maxpaxexcludingcrew)+'<br /><br />';
	c += '<span class="bold_text">pilot seats:</span> '+isEmptyOrZero(pilotseats)+'<br /><br />';
	c += '<span class="bold_text">max takeoff weight:</span> '+isEmptyOrZero(maxtakeoffweight)+'<br /><br />';
	c += '<span class="bold_text">fuel capacity:</span> '+isEmptyOrZero(fuelcapacity)+'<br /><br />';
	c += '<span class="bold_text">max cruise speed:</span> '+isEmptyOrZero(maxcruisespeed)+'<br /><br />';
	c += '<span class="bold_text">service ceiling:</span> '+isEmptyOrZero(serviceceiling)+'<br /><br />';
	c += '<span class="bold_text">bflmtow:</span> '+isEmptyOrZero(bflmtow)+'<br /><br />';
	c += '<span class="bold_text">production started year:</span> '+isEmptyOrZero(productionstartedyear)+'<br /><br />';
    c += '<span class="bold_text">production ended year:</span> '+isEmptyOrZero(productionendedyear)+'<br /><br />';
    c += '<span class="bold_text">model number:</span> '+isEmptyOrZero(modelnumber)+'<br /><br />';
    c += '<span class="bold_text">max payload per full fuel:</span> '+isEmptyOrZero(maxpayloadperfullfuel)+'<br /><br />';
    
    c += '<span class="bold_text">Additional Info:</span>';
    
    if (additionalInfo != 'N/A')
        c += '<a href="'+isEmptyOrZero(additionalInfo)+'" target="_blank">Click here for more info...</a><br /><br />';
    else
        c += ' No More Info Available for this Model<br /><br />';
    
    //c += '<span class="bold_text">Additional Features:</span> <br />';
        //c += '<div style="margin-left:30px;">';
            //c += '<span class="bold_text">Entertainment:</span> '+entertainment+'<br /><br />';
            //c += '<span class="bold_text">Lavatory:</span> '+lavatory+'<br /><br />';
            //c += '<span class="bold_text">Refreshment Options:</span> '+refreshmentOptions+'<br /><br />';
            //c += '<span class="bold_text">Medical Equipment:</span> '+MedicalEquipment+'<br /><br />';
            //c += '<span class="bold_text">Microwave:</span> '+Microwave+'<br /><br />';
            //c += '<span class="bold_text">DVD Air Show:</span> '+DVDAirShow+'<br /><br />';
            //c += '<span class="bold_text">Linens For Beds:</span> '+LinensForBeds+'<br /><br />';
            //c += '<span class="bold_text">Data Port:</span> '+DataPort+'<br /><br />';
            //c += '<span class="bold_text">Leather Seats:</span> '+LeatherSeats+'<br /><br />';
            //c += '<span class="bold_text">Satellite Phone:</span> '+SatellitePhone+'<br /><br />';
        //c += '</div>';
    
    //show inner search
    $('catalog_inner_suggest').style.display = 'block';
    $("aircraft_content").innerHTML = c;
    //alert($('_mostafa').offsetParent);
    inputWatermark();
            
}
//##############################################################
//replace 0s with N/As
function isEmptyOrZero( val ){
    var newVal;
    
    if(val == "0" || val == "" || val.indexOf('0.000') > -1) newVal = "N/A";
    else newVal = val;
    
    return newVal;
}
//##############################################################
function showLoadingContent( id ){
    $( id ).innerHTML = '<span id="ll"><img src="./SiteImages/loading.gif" /><br /></span>'; //show loading...
    var catalog_inner_suggest = $('catalog_inner_suggest');
    if(catalog_inner_suggest.style.display == 'block') catalog_inner_suggest.style.display = 'none';
    
    //alert($('catalog_inner_suggest').style.display);
    //$( id ).innerHTML = '- '; // show minus sign
}
//##############################################################
function showImage( imgID ){

    //$('_mostafa').innerHTML = '';
    //alert(imgID);
    //alert(path[+imgID]);
    $('_mostafa').innerHTML = '<span style="float:left; padding:20px;" class="text">'+s[0]+' > <strong>'+s[1]+'</strong></span><a href="#" onclick="hideMap(\'map\');Effect.Shrink($(divID),{duration:.5});xx();return false;" style="float:right; padding:20px;" class="text">Close</a><img src="./'+im[+imgID].path+'" width="600" height="300" oncontextmenu="return false;" />';
    
}
//##############################################################
function xx(){
    //alert('h');
    setTimeout(yy,500);
}
//##############################################################
function yy(){
    $('mnf_menu').style.display= 'inline';
    $('cover').style.display='none';
}
//##############################################################
function openPDFDiv(){
    var D = $('_pdf_');
    
    if(D.style.display == 'none'){
        D.style.display = 'block';
    }else{
        D.style.display = 'none';
    }
}