﻿
var mobilewin = null;
function showBrandList(k,rootPath){
    k = k || '0';
    rootPath = rootPath || '';
    myAjax({
        url:AjaxFuncPhone,
        ajaxProMethod : 'getPhoneBrandList',
        params:{
            key:k,
            rootPath:rootPath
        },
        success : function(backinfo , params){
            var content = '';
            if(backinfo)
            {
                var arr = [];
                arr.push('<div style="width:650px;height:200px;background-color:#fff;font-size:20px;">'); 
                arr.push('<table style="width:645px;height:30px;font-size:16px;margin-left:5px;">');
                arr.push('<tr>');
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'0\',\'\')">热门品牌</a></td>',params.key=='0'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'A\',\'\')">A</a></td>',params.key=='A'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'B\',\'\')">B</a></td>',params.key=='B'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'C\',\'\')">C</a></td>',params.key=='C'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'D\',\'\')">D</a></td>',params.key=='D'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'E\',\'\')">E</a></td>',params.key=='E'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'F\',\'\')">F</a></td>',params.key=='F'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'G\',\'\')">G</a></td>',params.key=='G'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'H\',\'\')">H</a></td>',params.key=='H'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'I\',\'\')">I</a></td>',params.key=='I'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'J\',\'\')">J</a></td>',params.key=='J'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'K\',\'\')">K</a></td>',params.key=='K'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'L\',\'\')">L</a></td>',params.key=='L'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'M\',\'\')">M</a></td>',params.key=='M'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'N\',\'\')">N</a></td>',params.key=='N'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'O\',\'\')">O</a></td>',params.key=='O'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'P\',\'\')">P</a></td>',params.key=='P'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'Q\',\'\')">Q</a></td>',params.key=='Q'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'R\',\'\')">R</a></td>',params.key=='R'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'S\',\'\')">S</a></td>',params.key=='S'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'T\',\'\')">T</a></td>',params.key=='T'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'U\',\'\')">U</a></td>',params.key=='U'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'V\',\'\')">V</a></td>',params.key=='V'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'W\',\'\')">W</a></td>',params.key=='W'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'X\',\'\')">X</a></td>',params.key=='X'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'Y\',\'\')">Y</a></td>',params.key=='Y'?"style=\"color:#ff6600;\"":""));
                arr.push(String.Format('<td><a href="javascript:void(0)" class="b01" {0} onclick="showBrandList(\'Z\',\'\')">Z</a></td>',params.key=='Z'?"style=\"color:#ff6600;\"":""));
                arr.push('</tr>');
                arr.push('</table>');
                
                arr.push('<hr>');

                arr.push('<table style="width:645px;font-size:16px;margin-left:5px;">');
                var phoneBrand = backinfo.Data;
                if(phoneBrand.length>0){
                    for(var i=0;i<phoneBrand.length;i++){
                        if(i%6==0)arr.push('<tr>'); 
                        arr.push('<td style="width:100px;height:50px;float:left;">'); 
                        arr.push(String.Format('<a href="javascript:void(0)" class="b" onclick="showMoelChar({0},\'{1}\',\'{2}\')">{1}</a>',phoneBrand[i].BrandId,phoneBrand[i].BrandName,params.rootPath)); 
                        arr.push('</td>');  
                        if(i%6==5)arr.push('</tr>');    
                    } 
                }
                else{
                    arr.push('<tr>'); 
                    arr.push('<td style="width:600px;height:50px;float:left;color:#ff6600;">'); 
                    arr.push('<b>对不起,没有找到您要的手机品牌</b>'); 
                    arr.push('</td>');  
                    arr.push('</tr>');   
                }
                arr.push('</table>');
                arr.push('</div>'); 
                content = arr.join('');
            }
            if(params.key=='0' && mobilewin==null){
                mobilewin = GB_showCenter('选择手机','',350,650,function(){mobilewin=null;});
            }
            mobilewin.setHTML(content);	 
            brandlistHtml = mobilewin.getHTML();              
        }
    });
}

var brandlistHtml = '';
function showMoelChar(brandid,brandname,rootPath){
    myAjax({
        url:AjaxFuncPhone,
        ajaxProMethod : 'getPhoneModelChar',
        params:{
            BrandId : brandid,
            key:'',
            rootPath:rootPath
        },
        success : function(backinfo , params){
            var content = '';
            if(backinfo)
            {
                var arr = [];
                var cModel = backinfo.Data;
                if(cModel.length>0){
                    var hdiv = (cModel.length/5 + 2) * 38;
                    arr.push(String.Format('<div style="width:650px;height:{0}px;background-color:#fff;font-size:20px;">',hdiv)); 
                    arr.push(String.Format('<div style="width:650px;height:32px;"><div style="float:left;" class="text_08">选机型:{0}系列手机</div><div style="float:right;"><a href="#" onclick="returnbrand()">返回</a></div></div>',brandname)); 
                    arr.push('<table style="width:645px;font-size:15px;margin-left:5px;">');
                    for(var i=0;i<cModel.length;i++){
                        if(i%5==0)arr.push('<tr>'); 
                        arr.push('<td style="width:120px;height:32px;float:left;">'); 
                        arr.push(String.Format('<a href="javascript:void(0)" class="b" onclick="showModelList({0},\'{1}\',\'{2}\',\'{3}\')">{2}开头手机</a>',params.BrandId,brandname,cModel[i],params.rootPath)); 
                        arr.push('</td>');  
                        if(i%5==4)arr.push('</tr>');    
                    } 
   
                    arr.push('</table>');
                    arr.push('</div>'); 
                }
                
                content = arr.join('');
            }
            mobilewin.setHTML(content);	                
        }
    });
}
function showModelList(brandid,brandname,k,rootPath){
    myAjax({
        url:AjaxFuncPhone,
        ajaxProMethod : 'getPhoneModelList',
        params:{
            BrandId : brandid,
            key:k,
            rootPath:rootPath
        },
        success : function(backinfo , params){
            var content = '';
            if(backinfo)
            {
                var arr = [];
                var phoneModel = backinfo.Data;
                if(phoneModel.length>0){
                    var hdiv = (phoneModel.length/5 + 2) * 38;
                    arr.push(String.Format('<div style="width:650px;height:{0}px;background-color:#fff;font-size:20px;">',hdiv)); 
                    arr.push(String.Format('<div style="width:650px;height:32px;"><div style="float:left;" class="text_08">选机型:{1}</div><div style="float:right;"><a href="#" onclick="showMoelChar({0},\'{1}\',\'{2}\')">返回</a></div></div>',brandid,brandname,rootPath)); 
                    arr.push('<table style="width:645px;font-size:15px;margin-left:5px;">');
                    for(var i=0;i<phoneModel.length;i++){
                        if(i%5==0)arr.push('<tr>'); 
                        arr.push('<td style="width:120px;height:32px;float:left;">'); 
                        arr.push(String.Format('<a href="javascript:getPhoneConent({0},\'{1}\',\'{2}\')" class="b">{3}</a>',phoneModel[i].MobileId,phoneModel[i].urlParams,params.rootPath,phoneModel[i].MobileName)); 
                        arr.push('</td>');  
                        if(i%5==4)arr.push('</tr>');    
                    } 
                    
                    arr.push('</table>');
                    arr.push('</div>'); 
                }
                else{
                    arr.push('<tr>'); 
                    arr.push('<td style="width:600px;height:50px;float:left;color:#ff6600;">'); 
                    arr.push('<b>对不起,没有找到您要的手机型号</b>'); 
                    arr.push('</td>');  
                    arr.push('</tr>');   
                }
                
                content = arr.join('');
            }
            mobilewin.setHTML(content);	                
        }
    });
}

function returnbrand(){
    mobilewin.setHTML(brandlistHtml);    
}

function getPhoneConent(mobileid,urlk,rootPath){
    mobilewin.close();
    rootPath = rootPath || '';
    AddMobileClickCount(mobileid,rootPath);
    window.location = rootPath + urlk +'index.aspx';
}

//增加手机型号点击次数
function AddMobileClickCount(mid,rootPath){
    myAjax({
        url:AjaxFuncPhone,
        ajaxProMethod : 'AddMobileClickCount',
        params:{
            MobileId : mid,
            rootPath:rootPath
        },
        success : function(backinfo , params){ }
    });
}