//刷新验证码
var intervalId1 = 0;
var intervalId2 = 0;
var isFocus1 = false;
var isFocus2 = false;
function changeNum(authimgURL)
{
	document.getElementById("check_num").src = authimgURL+'?rand='+new Date().getTime();
}

// load pages
function load(div, url) {
	$(div).addClass('loading');
	$(div).html('<span>载入中...</span>');
	$(div).load(url, 
	   function() {
		  $(div).removeClass('loading');
		  $(div+" li img").addClass("transparent");
		  register_event();
	});
}
function load_vendor(type) {
	if (type == 'pc') {
		$("#touch").hide();
		$("#pc").show();
		$("#mobile").hide();
		load("#pc", 'pc.php');
		$("#step2").html("电脑版下载");
		$("#step2").width(75);
		$("#step2").show();
		$("#step3").hide();
		$("#step4").hide();
	} else if(type == 'touch') {
		$("#pc").hide();
		$("#mobile").hide();
		$("#touch").show();
		load("#touch", 'touch_down.php');
		$("#step2").width(500);
		$("#step2").html("Java触摸屏版本下载");
		$("#step2").show();
		$("#step3").hide();
		$("#step4").hide();
	} else {
		$("#pc").hide();
		$("#touch").hide();
		$("#vendor").show();
		$("#phone").show();
		$("#mobile").show();
		load("#vendor", 'vendor.php');
		$("#step2").html("手机品牌");
		$("#step2").width(75);
		$("#step2").show();
		$("#step3").hide();
		$("#phone").html("");
		$("#step4").hide();
		$("#download").html("");
		intervalId1 = setInterval("singleSelected('"+type+"')",2000);		
		/*if($("#phone").html() != '')
			$("#step3").show();
		if($("#download").html() != '')
			$("#step4").show();
		*/
	}
	return false;
}

function load_phone(vandor, vandorname, type,reflink) {
	load('#phone', 'phone.php?vandor='+vandor+'&vandorName='+vandorname+'&type='+type+'&reflink='+reflink);
	$("#step4").hide();
	$("#step3").show();
	intervalId2 = setInterval("singleSelected('"+vandor+"_"+vandorname+"')",2000);
	$("#download").html("");
}

function load_download(vandor, phone, type,reflink) {
	if(type == 'popularize')
  {
  	if(phone == "") return false;
  	load("#download_url", 'download.php?vandor=' + vandor + '&phone=' + encodeURIComponent(phone) + '&down_type=' + type+'&reflink='+reflink);
  }
  else
  {  		
		load("#download", 'download.php?vandor=' + vandor + '&phone=' + encodeURIComponent(phone));
		if(type == "top")
	  {
	    	$("#pc").hide();
	    	$("#download").width(380);
			isFocus1 = false;
			isFocus2 = false;
			clearInterval(intervalId1);
			clearInterval(intervalId2);
			load_vendor(vandor);
			load_phone(vandor, phone, '');
			$("#step4").show();
	  }
		else
		{
			$("#download").width(380);
			$("#step4").show();
		} 	
	}
}

function register_event() {
    $("li img").unbind("mouseover");
    $("li img").unbind("mouseout");
    $("li img").unbind("click");
    
    $("li img").mouseover(function(){
		$(this).removeClass("transparent");
	});
	$("li img").mouseout(function(){
		$(this).addClass("transparent");
	});
	
	$("li img").click(function(){
		clearInterval(intervalId1);
		clearInterval(intervalId2);
		div = $(this).parents("div").attr("id");
		$("#" + div + " .selected").each(function() {
			$(this).removeClass("selected");
			$(this).addClass("transparent");
		});
		
		$(this).addClass("selected");
		$(this).removeClass("transparent");
		
	});
}
$(function() {
	$("#platform img").addClass("transparent");
	register_event();
})
function sms_download(requestURL,urlRoot) {
	$('#sms_down').addClass('loading');	
	$('#sms_down').html('<span>发送中...</span>');
	$.post( requestURL + "?time="+new Date().getTime(), 
	{ 
		mobile: $("#mobile1").val(),
		dlpath: $("#dlpath").val(),
		random: $("#random").val()
	}, 
	function(xml)
	{ 
		try
		{
			var msg = xml.getElementsByTagName("checkmsg")[0].childNodes[0].nodeValue;
			if(msg == 'success') 
			{
				changeNum(urlRoot+'/include/authimg.php');
				$('#sms_down').removeClass('loading');$('#sms_down').html('<span style=\"#fff00\">发送成功，请查收！</span>');
			}
			else
			{
				$("#sms_down").html(msg);
			}					
		}
		catch(e)
		{
			$("#sms_down").removeClass('loading');
			$("#sms_down").html('');
			alert(e);
		}							
	} 
	);
}
function singleSelected(id)
{
	$("#platform img").addClass("transparent");
	if(isFocus1 == false && $("#"+id+"_a1").attr("id") != undefined)
	{
		$("#"+id+"_a1").focus();
		isFocus1 = true;
	}	
	if(isFocus2 == false && isFocus1 == true && $("#"+id+"_a2").attr("id") != undefined)
	{
		$("#"+id+"_a2").focus();
		//alert($("#"+id+"_a2").attr("id"));
		isFocus2 = true;
	}	
	$("#"+id).addClass("selected");
}