﻿// JScript 文件
function GetDecode_onclick(url)
{   
    var theCode = $get("TextTraceCode").value;
    if( theCode =="" || theCode ==null)
    {
        return;
    }
    
    var contextObj = 
    {
        Pcode:theCode,
        theUrl:url
    };
    WebServiceDecode.Getdecode(theCode,getdecodeOnSucceeded, getdecodeOnFailed,contextObj);
}

function GetDecode_onclickIndex(url)
{   
    var theCode = $get("CodeInput").value;
    if( theCode =="" || theCode ==null)
    {
        return;
    }
    
    var contextObj = 
    {
        Pcode:theCode,
        theUrl:url
    };
    WebServiceDecode.Getdecode(theCode,getdecodeOnSucceeded, getdecodeOnFailed,contextObj);
}

function getdecodeOnSucceeded(result,context)
{
    var type = result.Type;
    var code = result.Code;

    if( context.theUrl == 1)
    {
        if(type =='TypeError' || code =='CodeError')
        {
             window.location.href = 'Trace/ErrorCode.aspx?code='+context.Pcode;
            return;
        }
        
        switch(type)
        {
            case '0':
                window.location.href='Trace/VegetableTrace.aspx?code='+code+'&ProductCode='+context.Pcode;
                break; 
            case '99':
                 window.location.href='Trace/MarketTrace.aspx?code='+code+'&ProductCode='+context.Pcode;
                break; 
           default:
                break;
        }
     
     }   
       
    if( context.theUrl == 2)
    {
        if(type =='TypeError' || code =='CodeError')
        {
             window.location.href = 'ErrorCode.aspx?code='+context.Pcode;
            return;
        }
        
        switch(type)
        {
            case '0':
                window.location.href='VegetableTrace.aspx?code='+code+'&ProductCode='+context.Pcode;
                break; 
            case '99':
                 window.location.href='MarketTrace.aspx?code='+code+'&ProductCode='+context.Pcode;
                break; 
           default:
                break;
        }        
    }
}

function getdecodeOnFailed()
{
    alert("Error");
}
