
function clearit(id){
	if(document.getElementById(id).value.match(/^Please/))//if the contents of the input starts with 'please'
		document.getElementById(id).value="";
		document.getElementById(id).className='';//so that the text is no longer red
}


function getInfoChild(elem){
	//alert(elem.nodeName);
	if(typeof(elem.getElementsByClassName) != 'undefined'){
		divs = elem.getElementsByClassName('info');
		if(divs.length) return divs[0];
		return false;
	}
	//	return elem.getElementsByClassName('info')[0];
	//else, IE....
	divs = elem.getElementsByTagName('div');
	num_divs = divs.length; //IE can't even do for(index in divs)
	for(index=0; index<num_divs; index++){
		div = divs[index];
		class_names = div.className.split(/\s+/);
		for(i in class_names){
			if(class_names[i] == 'info') return div;
		}
	}
	return false;
}


function getParentX(obj){
	var curleft = 0;
	var parent = obj.parentNode;
	if(parent.offsetParent){
		while(1){
			curleft += parent.offsetLeft;
			if(!parent.offsetParent)
				break;
			parent = parent.offsetParent;
		}
	}
	else if(parent.x)
			curleft += parent.x;
	return curleft;
}

function getParentY(obj){
	var curtop = 0;
	var parent = obj.parentNode;
	if(parent.offsetParent){
		while(1){
			curtop += parent.offsetTop;
			if(!parent.offsetParent)
				break;
			parent = parent.offsetParent;
		}
	}
	else if(parent.y)
			curtop += parent.y;
	return curtop;
}






function getPosition(e) {
	e = e || window.event;
	var cursor = {x:0, y:0};
	if (e.pageX || e.pageY) {
		cursor.x = e.pageX;
		cursor.y = e.pageY;
	}
	else {
	    cursor.x = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft) - document.documentElement.clientLeft;
	    cursor.y = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop) - document.documentElement.clientTop;
	}
	return cursor;
}







// ATTACH ONMOUSE_X HANDLERS TO RELEVANT ANCHORS

anchors = document.getElementsByTagName('a');
num_a = anchors.length;
for(i=0; i<=num_a+2; i++){
	if(i>=num_a){ //dirty: how do I append things to an object that's returned by getElementsByTagName ?
		if(i==num_a)
			a = document.getElementById('name_input');
		else if(i==num_a+1)
			a = document.getElementById('email_input');
		else if(i==num_a+2)
			a = document.getElementById('message_input');
		if(!a)
			continue; //email form is not there because it has not been submitted
	}
	else
		a = anchors[i];
	
	class_names = a.className.split(/\s+/);
	for(j in class_names){
		if(class_names[j] == 'has_info'){//if it's an anchor that should trigger an info box
			
			// MOUSE OUT
			a.onmouseout = function(){
				elem = getInfoChild(this.parentNode);
				if(elem) elem.style.display='none';
			}
			
			
			
			
			//MOUSE OVER
			a.onmouseover = function (event){
				if(disable_info_boxes)//if the layout moves are NOT finished
					return;
				
				element = getInfoChild(this.parentNode);
				
				if(!element) return; //might be hovering over a form field when there's no error message for it
				
				element.style.display='block';
				mouse_pos = getPosition(event);
				parent_x = getParentX(element);
				parent_y = getParentY(element);
				
				if(element.className.match(/left/)){//if the box needs to be put on the left of the mouse
						mouse_x = mouse_pos.x -20;//set the offset to the left
						mouse_x -=200;//the info box is 200px wide so shift it 200px to the left as well
				}
				else
					mouse_x = mouse_pos.x +20;//20px offset is so that the box doesn't sit right on top of the mouse pointer
				
				//vertical postition:
				mouse_y = mouse_pos.y -20;
				vert_os = element.className.match(/vert_os\d+/)
				if(vert_os)//if there's a vertical offset
					mouse_y -=parseInt(vert_os[0].replace(/vert_os/,''));
				
				//now make the mouse positions relative to the parent element, not the page
				mouse_x -= parent_x;
				mouse_y -= parent_y;
				element.style.top=mouse_y +'px';
				element.style.left=mouse_x +'px';
			}
			
			
			
			//MOUSE MOVE
			a.onmousemove = function (event){
				element = getInfoChild(this.parentNode);
				
				if(!element) return; //might be hovering over a form field when there's no error message for it
				
				mouse_pos = getPosition(event);
				parent_x = getParentX(element);
				parent_y = getParentY(element);
				
				if(element.className.match(/left/)){//if the box needs to be put on the left of the mouse
						mouse_x = mouse_pos.x -20;//set the offset to the left
						mouse_x -=200;//the info box is 200px wide so shift it 200px to the left as well
				}
				else
					mouse_x = mouse_pos.x +20;//20px offset is so that the box doesn't sit right on top of the mouse pointer
				
				//vertical postition:
				mouse_y = mouse_pos.y -20;
				vert_os = element.className.match(/vert_os\d+/)
				if(vert_os)//if there's a vertical offset
					mouse_y -=parseInt(vert_os[0].replace(/vert_os/,''));
				
				//now make the mouse positions relative to the parent element, not the page
				mouse_x -= parent_x;
				mouse_y -= parent_y;
				
				element.style.top=mouse_y +'px';
				element.style.left=mouse_x +'px';
			} //end mousemove function
		}
	}
}


////pre-load images into cache
w = new Image();
x = new Image();
y = new Image();
z = new Image();
w.src = 'img/info_box_top.png';
x.src = 'img/info_box_bottom.png';
y.src = 'img/pink_box_bottom.png';
z.src = 'img/pink_box_bottom.png';




