var selects;
var inputs;
var radios = new Array();
var formContainer = null;
var formContainerId = 'divSearchAndSave'

//this function runs when the page is loaded so put all your other onload stuff in here too.
function init() {
    //check if styles are enabled and only then start replacing elements
    formContainer =  document.getElementById(formContainerId);
    if(findPosX(document.getElementById('stylesheetTest')) == -999) {
        replaceRadios();
     }
}

function findPosY(obj) {
	var posTop = 0;
	if(formContainer!=null)
	{
	    while (obj.offsetParent && obj.id!=formContainer.id) 
	    {
		    posTop += obj.offsetTop;
		    obj = obj.offsetParent;
	    }
	}
	return posTop;
}
function findPosX(obj) {
	var posLeft = 0;
	if(formContainer!=null)
	{
	    while (obj.offsetParent && obj.id!=formContainer.id) 
	    {
		    posLeft += obj.offsetLeft;
		    obj = obj.offsetParent;
		}
	}
	return posLeft;
}

function replaceRadios() {
    //get all the radio buttons on the page
    var inputs = document.getElementsByTagName('input');
    var j = 0;
    for(var i=0; i < inputs.length; i++) {
        if(inputs[i].type=='radio') {
            radios[j] = inputs[i];
            ++j;
        }
    }

    //cycle through the radio inputs
    for(var i=0; i <radios.length; i++) {

        //make them transparent
        radios[i].className = "transparent";

        //get their position
        var x = findPosX(radios[i]);
        var y = findPosY(radios[i]);

        //build new div
        var radioArea = document.createElement('div');
        if(radios[i].checked) {
            radios[i].nextSibling.className = "chosen"; 
            radioArea.className = "radioAreaChecked";
        }
        else if(!radios[i].checked) 
        {
            radioArea.className = "radioAreaUnchecked";
        }
        radioArea.style.left = x + 'px';
        radioArea.style.top = y + 'px';
        radioArea.id = 'myRadio'+i;
        radioArea.onclick = new Function('checkRadio('+i+')');       
        radios[i].onclick = new Function('checkRadio('+i+')');
        

        //insert div
       formContainer.appendChild(radioArea);
    }
}

function checkRadio(g) 
{
    for (var k = 0; k < radios.length; k++)
    {
        if(k != g) {
            document.getElementById('myRadio'+k).className = "radioAreaUnchecked";
            radios[k].nextSibling.className = "";
        }
        else if(k == g) {
            document.getElementById('myRadio'+k).className = "radioAreaChecked";
            radios[g].nextSibling.className = "chosen";
        }
    }
}

function AddButtons()
{
    var tableresult = document.getElementById("listingResults");
    var i;
    
    arrLinks = tableresult.getElementsByTagName("a");
       
    for(i=0;i<arrLinks.length;i++)
    {
        var a = arrLinks[i];
        var href = a.getAttribute("href");
        
        if(href.indexOf("click.asp") > -1 && a.firstChild != null && a.firstChild.nodeType ==3 )
        {
            var extrabutton = document.createElement('a'); 
            extrabutton.setAttribute('href',href);
            extrabutton.style.display = 'block';
            extrabutton.style.position = 'absolute';            
            extrabutton.style.background = 'url(buttonGo.jpg)';            
            extrabutton.style.width = 130 + 'px';
            extrabutton.style.height = 57 + 'px';
            extrabutton.style.left = 350 + 'px';
            extrabutton.style.top = 10 + 'px';
            extrabutton.id = 'extrabutton'+i;
            a.parentNode.appendChild(extrabutton);
            
        }
    }
}