﻿
var iframe = document.createElement("iframe");
iframe.setAttribute("src","http://www.check4jobs.com/affiliates/search.aspx?a=" + gup("a") + "&w=" + gup("w") + "&b=" + gup("b") + 
    "&q=" + gup("q") + "&l=" + gup("l") + "&r=" + getBaseUrl());// + "&start=" + gup("start") + "&count=" + gup("count"));
iframe.setAttribute("marginheight","0");
iframe.setAttribute("marginwidth","0");
iframe.setAttribute("border","0");
iframe.frameBorder = "0";
iframe.setAttribute("scrolling","no");
iframe.setAttribute("width","100%");
document.getElementById("c4j-search-results").appendChild(iframe);


function getBaseUrl()
{
    if(document.location.href.indexOf("#") >= 0)
        return encodeURIComponent(document.location.href.substring(0,document.location.href.indexOf("#")));
    else
        return encodeURIComponent(document.location.href);

    /*if(document.location.href.indexOf("?") >= 0)
        return escape(document.location.href.substring(0,document.location.href.indexOf("?")));
    
    return escape(document.location.href);*/
}


if(iframe.attachEvent)
    iframe.attachEvent("onload",function(){window.scrollTo(0,0)});
else
    iframe.addEventListener("load",function(){window.scrollTo(0,0)},false);


var getHashInterval = window.setInterval("setIframeSize()",10);


function setIframeSize()
{
    if(window.location.hash && window.location.hash != "")
    {
        window.clearInterval(getHashInterval);
        
        if(window.location.hash != "#")
            iframe.height = (parseInt(window.location.hash.substring(1)) + 30) + "px";
    }
}


function gup(name)
{
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    
    if(results == null)
        return "";
    else
        return results[1];
}
