/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

(function($) {
    
    
    var waitingMsg  = "<table style=\"width:100%;text-align:center;\" >"+
    "<tr ><td><img alt=\"\" src=\"./images/indicator.gif\" /></td></tr>"+
    "<tr ><td>Please wait...</td></tr>"+
    "</table>";

    $.listMobileSupportByContentId = (function(contentId,typeId,placeId,aMobileVisibleList,aMobileInVisibleList) {
        var datas =({
            mode: "LIST_MOBILE_SUPPORT",
            contentId: contentId,
            typeId: typeId,
            aMobileVisibleList: aMobileVisibleList,
            aMobileInVisibleList: aMobileInVisibleList
        });
                        
        var url ="./GenerateListContent";
           
        $.ajax({
            cache: false,
            url: url,
            data: datas,
            dataType: 'json',
            beforeSend:function(){
                $('#'+placeId).html(waitingMsg  );
            },
            success: function (data) {
                var length="";
                try{
                    length=data.drList.length;
                }catch(Error){}
                            
                if(data!=''&&length>0){
                    $.manipulateDisplayMobileSupport(data,placeId)
                }
            },
            error: function (xhr, desc, er) {
                //alert(xhr.responseText);
            }
        });
    });
    
    
    $.listMobileSupportByContentDesId = (function(contentDesId,typeId,placeId,aMobileVisibleList,aMobileInVisibleList) {
        var datas =({
            mode: "LIST_MOBILE_SUPPORT",
            contentDesId: contentDesId,
            typeId: typeId,
            aMobileVisibleList: aMobileVisibleList,
            aMobileInVisibleList: aMobileInVisibleList
        });
                        
        var url ="./GenerateListContent";
           
        $.ajax({
            cache: false,
            url: url,
            data: datas,
            dataType: 'json',
            beforeSend:function(){
                $('#'+placeId).html(waitingMsg  );
            },
            success: function (data) {
                var length="";
                try{
                    length=data.drList.length;
                }catch(Error){}
                            
                if(data!=''&&length>0){
                    $.manipulateDisplayMobileSupport(data,placeId)
                }
            },
            error: function (xhr, desc, er) {
                //alert(xhr.responseText);
            }
        });
    });
                
    $.manipulateDisplayMobileSupport=(function(data,placeId){
        var row ="";
        var dataSet =data.drList;
                    
        var MAX_COLS=4;
        var brandHeader="";
                    
        for(i=0;i<dataSet.length;i++){
            var brand = dataSet[i].brand;   
            var model = dataSet[i].model;   
                        
            if(brand != brandHeader){
                brandHeader= brand;
                row+="<br/><br/><span class='headMobileSupport'>"+brand+"</span><br/>";
                row+=model;
            }else{
                if(i%MAX_COLS==0){
                    row+="<br/>"+model;
                }else{
                    row+=","+model;
                }
            }
        }
                    
        $("#"+placeId).html(row);
                    
    });
    
    
})(jQuery);





