var userAgent = navigator.userAgent.toLowerCase();
var is_firefox = (userAgent.indexOf('firefox') != -1);

function $(s)
{
    return document.getElementById(s);
}

//flashpicbox
var FlahPic_pic;
var FlahPic_Len = 0;
var FlahPic_CurId = 0;
var FlahPic_Step = 3000;

function FlahPic()
{
    if(FlahPic_CurId >= FlahPic_Len)
    {
        FlahPic_CurId = 0;
    }
        
    var cl;
    for(var k=0; k<FlahPic_Len; k++)
    {
        cl = "index_showflash_txt" + k;
        if(is_firefox)
        {
            $(cl).setAttribute("class", "img_bk");
        }
        else
        {
            $(cl).setAttribute("className", "img_bk");
        }
    }
    //set cur
    cl = "index_showflash_txt" + FlahPic_CurId;
    if(is_firefox)
    {
        $(cl).setAttribute("class", "img_bk1");
    }
    else
    {
        $(cl).setAttribute("className", "img_bk1");
    }
    $("index_showflash_pic") .innerHTML = FlahPic_pic[FlahPic_CurId];
    
    FlahPic_CurId++;
}

var FlahPic_AutoId = null;
function FlahPicAuto()
{
    FlahPic_AutoId = window.setInterval("FlahPic()", FlahPic_Step);
}
function FlahPicAutoStop()
{
    window.clearInterval(FlahPic_AutoId);
}
function FlahPicTurn(id)
{
    FlahPicAutoStop();
    
    FlahPic_CurId = id;
    FlahPic();
}
function FlahPicInitial(piclinks)
{
    FlahPic_pic = piclinks.split('|');
    FlahPic_Len = FlahPic_pic.length;
}
//flashpicbox end

function iXmlHttpReq(url, callback, data) 
{ 
    // init 
    url += url.indexOf("?") >= 0 ? "&" : "?"; 
    url += "random_download_url=" + Math.random(); 
    if (typeof data == 'undefined') 
    { 
        var data = null; 
    } 
    method = data ? 'POST' : 'GET'; 
    // create XMLHttpRequest object 
    if (window.XMLHttpRequest) { 
        var objXMLHttpRequest = new XMLHttpRequest(); 
    } else { 
        var MSXML = ['MSXML2.XMLHTTP.7.0', 'MSXML2.XMLHTTP.8.0', 'MSXML2.XMLHTTP.6.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP.5.0', 'MSXML2.XMLHTTP.4.0', 'MSXML2.XMLHTTP', 'Microsoft.XMLHTTP']; 
        for(var n = 0; n < MSXML.length; n ++) { 
            try { 
                var objXMLHttpRequest = new ActiveXObject(MSXML[n]); 
                break; 
            } catch(e) {
                //alert(e.message);
            } 
        } 
    } 
    // send request 
    with(objXMLHttpRequest) { 
        //setTimeouts(30*1000,30*1000,30*1000,30*60*1000); 
        try { 
            open(method, url, true); 
            if (method == 'POST') 
                setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8'); 
            send(data); 
        } catch(e) {
            //alert(e.message);
        } 
        // on ready 
        onreadystatechange = function() { 
            if (objXMLHttpRequest.readyState == 4) { 
                callback(objXMLHttpRequest.responseText, objXMLHttpRequest.status); 
                delete(objXMLHttpRequest); 
            } 
        } 
    } 
}

function FillMobile(cid)
{
    var _objx = $("m_mobile");
    _objx.options.length = 0;
    _objx.options[0] = new Option("请稍等…","0");
    _objx.disabled = true;
    
	var url = "/js/slt_mobiles.aspx";
	var postdata = "cid="+ cid;
	iXmlHttpReq(url, 
	    function(data, responseCode){
	        var ref = unescape(data);
            var Ls = ref.split('|');
            
            var _obj = $("m_mobile");
            var onew;
            for(var i = 0 ;i<Ls.length;i+=2)
            {
                onew = new Option(Ls[i+1],Ls[i]);
                _obj.options.add(onew);
            }
            _obj.options[0] = new Option("请选择机型","0");
            _obj.options[0].selected = true;
            _obj.disabled = false;
            
	    }, postdata);
}

function ToZone()
{
    var val = $("m_mobile").value;
    if(val == "0")
    {
        alert("请选择手机型号!");
        $("m_mobile").focus();
        return;
    }
    //id,ename,pic,sys
    var Ls = val.split(',');
    window.open(GetZone(Ls[3],Ls[1]));
}

function GetZone(tsys, spath)
{
    if (tsys == 1)
    {
        spath = "http://android.joyes.com/";
    }
    else if (tsys == 2)
    {
        spath = "http://iphone.joyes.com/";
    }
    else if (tsys == 3)
    {
        spath = "http://symbian.joyes.com/";
    }
//    else if (tsys == 4)
//    {
//        spath = "http://winphone7.joyes.com/";
//    }
    else
    {
        spath = "http://" + spath + ".m.joyes.com/";
    }

    return spath;
}

function JoyesMainSearch()
{
    var k = $("sokeyjoyes").value;
    if(k == '' || k == '请输入关键字')
    {
        alert("请输入搜索关键字!")
        $("sokeyjoyes").value = '';
        $("sokeyjoyes").focus();
        return;
    }
    window.location.href = "http://www.joyes.com/search/?words="+ escape(k);
}
