var interval1,interval2;
function getqrpic(){
	var getvcurl= loginurl + '?do=getqrpic&r='+Math.random(1);
	$.ajax({
              type: "GET",
              url: getvcurl,
              dataType: "json",
              success: function(d){
                if(d.saveOK ==0){
					$('#qrimg').attr('qrsig',d.qrsig);
					$('#qrimg').html('<img onclick="getqrpic()" style="margin-bottom:-10px;"  class="form-control" src="data:image/png;base64,'+d.data+'" title="点击刷新">');
				}else{
					alert(d.msg);
				}
             }
	});
	/*$.get(getvcurl, function(d) {
		
		alert(ret.saveOK);
		if(d.saveOK ==0){
			$('#qrimg').attr('qrsig',d.qrsig);
			$('#qrimg').html('<img onclick="getqrpic()" style="margin-bottom:-10px;"  class="form-control" src="data:image/png;base64,'+d.data+'" title="点击刷新">');
		}else{
			alert(d.msg);
		}
	});*/
}
function ptuiCB(code,uin,sid){
	var msg='请扫描二维码';
	switch(code){
		case '0':
			msg = sid;
			cleartime();
			alert(msg);
			break;
		case '1':
			getqrpic();
			msg='请重新扫描二维码';
			break;
		case '2':
			msg='使用QQ手机版扫描二维码';
			break;
		case '3':
			msg='扫描成功，请在手机上确认授权登录';
			break;
		default:
			msg=sid;
			cleartime();
			alert(msg);
			break;
	}
}
function loadScript(c) {
	var qrsig=$('#qrimg').attr('qrsig');
	c = c || loginurl + "?do=qqlogin&qrsig="+decodeURIComponent(qrsig)+"&r=" + Math.random(1);
	var a = document.createElement("script");
	a.onload = a.onreadystatechange = function() {
		if (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") {
			if (typeof d == "function") {
				d()
			}
			a.onload = a.onreadystatechange = null;
			if (a.parentNode) {
				a.parentNode.removeChild(a)
			}
		}
	};
	a.src = c;
	document.getElementsByTagName("head")[0].appendChild(a)
}
function cleartime(){
	clearInterval(interval2);
	login_stop = true;
}
$(document).ready(function(){
	getqrpic();
	interval2=setInterval(loadScript,3000);
});