// ==========================================
var CefObj = new cef.taobao.test_object;

function jump(url){
  CefObj.jump(url);  
}
function sightClient(input){
    return 'sign='+CefObj.addSign(input)+'&v='+CefObj.getVersion();
    //return 'sign=b206f9ba523894697b86a1654dac3c3a&mac=b206f9ba523894697b86a1654dac3c3a&sigeCode=b206f9ba523894697b86a1654dac3c3a&v=1.0.0.1';
}
function countVersion(v){
    return parseInt(v.replace(/\./g,''));
}
function rawurlencode(str) {
	str = (str + '').toString();
	return encodeURIComponent(str).replace(/!/g, '%21').replace(/'/g, '%27').replace(/\(/g, '%28').replace(/\)/g, '%29').replace(/\*/g, '%2A');
}
function checktm_www(){
        $("#hint_tm_www").html('');
        var tm_www = $.trim($("#tm_www").val());
        if(tm_www!=""){
                if(IsURL(tm_www)){
                        $.ajax({
                                url:'./taskwc.php?a=gettitle&url='+encodeURIComponent(tm_www),
                                type:'get',
                                success:function(result){
                                        if(result=='E'){
                                                $("#hint_tm_www").html('这个网址不对');
                                                $("#tm_www").val('');
                                        }else{
                                                $("#tm_title").val($.trim(result));
                                        }
                                }
                        });
                }else{
                        $("#hint_tm_www").html('网址格式不对');
                }
        }else{
                $("#hint_tm_www").html('填写网址那是必须的');
        }
}
function checktm_title(){
        $("#hint_tm_title").html('');
        var tm_title = $.trim($("#tm_title").val());
        if(tm_title==""){
                $("#hint_tm_title").html('名称填一下，可帮您区分任务，可以随便填，对流量无影响');
        }
}
function deltask(tm_ids){
    if(confirm('您确定要删除优化网址？')){
        $.ajax({
            url:'./taskwc.php?a=DelTask&tm_ids='+tm_ids+'&'+sightClient(tm_ids),
            dataType:'json',
            success:function(retext){
                if(retext.e==0){
                    location.reload();
                }else{
                    msg(retext.msg,0);
                }
             }
        });
    }
}
function openLink(url){
    location.href=url;
}
function backup(){
    $.ajax({
        url:'./taskwc.php?a=dOut',
        type:'get',
        dataType:'json',
        success:function(retext){
              msg(retext.msg,0);
        }
    });
}
function showInput(){
    if($("#recoverInputDiv").css("display")=="none"){
        $("#recoverInputDiv").show();
    }else{
        $("#recoverInputDiv").hide();
    }
}
function recover(){
    var code=$.trim($("#recoverInput").val());
    if(code.length==32){
        if(confirm('从备份中恢复将覆盖当前在线的所有优化网址，您确定要恢复吗？')){
            $("#reconverBut").attr('disabled',true);
            $.ajax({
                url:'./taskwc.php?a=puarIn&code='+code,
                dataType:'json',
                type:'get',
                success:function(retext){
                     if(retext.e==0){
                         location.reload();  
                     }else{
                        msg(retext.msg,0);
                        $("#reconverBut").attr('disabled',false);
                     }
                }
            });
        }else{
            $("#reconverBut").attr('disabled',false);
        }
    }else{
        msg('输入有误',0);
    }
}
function msg(msg, type)
{
  if (type === 'undefined') {type = 3};
  $.layer({
    shadeClose: true,
    fix: true,
    title: false,
    closeBtn: false,
    time: 3,
    dialog: {
      msg: msg,
      type: type
    }
  });
}
$(function(){
    $(".need_tooltip").each(function(){
		if($(this).attr("title")!=''){
                    $(this).simpletip({
                            fixed: true,
                            boundryCheck:true,
                            content:$(this).attr("title")
                    });
                }
		
    });
    document.onkeydown=function (ev){
        var oEvent=ev||event;
        if(oEvent.keyCode==116){
         location.reload();
        }
    };
});
