// JScript File

function appendQuery()
{
    //Get the full URL of the page
    var strHref = window.location.href;
    
    //Check if URL has a Querystring
    if (strHref.indexOf("?")>-1)
    {      
        //extract the query from the full URL of the page
        var strQuery = strHref.substr(strHref.indexOf("?") +1);

        //these are the parameters that need to be passed through
        var param4 = "CAMPAIGN";
        var param5 = "TFN";
        var param6 = "SRC";
        
        //while there there is still more than 1 parameter on the query...
        while (strQuery.indexOf('&') > -1) 
        {  
            //get the first param
            var token = strQuery.substring(0,strQuery.indexOf('&'));
            //get the name of the param only
            var key = token.substring(0,token.indexOf('=')).toUpperCase();

            //CAMPAIGN
            if(key == param4)
            {
                window.document.getElementById(param4).value = token.substr(token.indexOf('=') + 1)
            }
            //TFN
            if(key == param5)
            {
                window.document.getElementById(param5).value = token.substr(token.indexOf('=') + 1)
            }    
            //SRC
            if(key == param6)
            {
                window.document.getElementById(param6).value = token.substr(token.indexOf('=') + 1)
            }
            
            //remove param from original query to avoid duplicate search.
            strQuery = strQuery.substring((strQuery.indexOf('&')) + 1);
        }
        
        //Get name of last param
        var key2 = strQuery.substring(0,strQuery.indexOf('=')).toUpperCase();
        
        //CAMPAIGN
        if(key2 == param4)
        {
            window.document.getElementById(param4).value = strQuery.substr(strQuery.indexOf('=') + 1);
        }
        //TFN
        if(key2 == param5)
        {
            window.document.getElementById(param5).value = strQuery.substr(strQuery.indexOf('=') + 1);
        }    
        //SRC
        if(key2 == param6)
        {
            window.document.getElementById(param6).value = strQuery.substr(strQuery.indexOf('=') + 1);
        }    
    }
}

