var xmlhttp = false
if (window.XMLHttpRequest) {
          xmlhttp = new XMLHttpRequest()
} else if (window.ActiveXObject) {
          xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); 
}

function fetchData(e, name) {
	var left = e.offsetLeft + 50
	var top = e.offsetTop + 100
	xmlhttp.open("GET", "/img.php?i=" + name, true);
	xmlhttp.onreadystatechange=function() {
		if (xmlhttp.readyState==4) {
			var x = xmlhttp.responseText
			if (x) {
				var blurb = document.getElementById('blurb')
				blurb.innerHTML = x
				blurb.style.top = top + 'px'
				blurb.style.left = left + 'px'
				blurb.style.display = 'block'
			}
		}
	}
	xmlhttp.send(null)
}
function closeBlurb() {
	var blurb = document.getElementById('blurb')
	blurb.style.display = 'none'
}

var greyed = [ 
    ['name', 'any'],
    ['price', 'any'],
    ['people', 'any'],
    ['from', 'any'],
    ['to', 'any']
]

// http://www.scottandrew.com/weblog/articles/cbs-events
function addEvent(obj, evType, fn){ 
    if (obj.addEventListener){ 
        obj.addEventListener(evType, fn, true); 
        return true; 
    } else if (obj.attachEvent){ 
        var r = obj.attachEvent("on"+evType, fn); 
        return r; 
    } else { 
        return false; 
    }
}

function fadein(thi) {
    id = thi.id
    for (var j = 0; j < greyed.length; j++) {
        if (greyed[j][0] == id && greyed[j][1] == thi.value) {
            thi.style.color = '#000000';
            thi.value = '';
        }
    }
}
function fadeout(thi) {
    id = thi.id
    for (var j = 0; j < greyed.length; j++) {
        if (greyed[j][0] == id && thi.value == '') {
            thi.style.color = '#999999';
            thi.value = greyed[j][1];
        }
    }
}

addEvent(window, 'load', greyOutInputs);
function greyOutInputs() {
    if (!document) return
    if (document.getElementById) {
        for (var j = 0; j < greyed.length; j++) {
            d = document.getElementById(greyed[j][0])
            if (d && d.value == '') d.value = greyed[j][1]
            if (d && d.value == greyed[j][1]) d.style.color = '#999999'
        }
        d = document.getElementById('ref')
        if (d && d.value.length<6) d.style.color = '#999999'

    }
}
