/* =====================================================================

Not Interested Javascript Code (Technojobs Site)

Revision:     1
Author:       Derek Almond <andy@WebMetric.co.uk>
Date Created: 2005-12-05 11:17

This code is copyright (C)2005 Technojobs Ltd.
All rights reserved.

===================================================================== */


function addEvent(elm, evType, fn, useCapture)
{
	// Cross-browser event handling for IE5+, NS6+, Mozilla/Gecko and Safari/Konqueror
	// By Scott Andrew
	if (elm.addEventListener) {
		elm.addEventListener(evType, fn, useCapture);
		return true;
	}
	else if (elm.attachEvent) {
		return elm.attachEvent('on'+evType, fn);
	}
	else {
		elm['on' + evType] = fn;
	}
}


function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function positionNearTarget(t)
{
	var niwindow = document.getElementById("notinterestedpopup");
	niwindow.style.top = findPosY(t) + "px";
	niwindow.style.left = findPosX(t) + "px";
	return;
	
	var top = (parseInt(getTop(t))+parseInt(getHeight(t)));
	niwindow.style.top = top + "px";
		
	if (parseInt(getLeft(t)) > (getWindowWidth()/2)) {
		niwindow.style.left = (parseInt(getLeft(t))-(parseInt(getWidth(t)) + parseInt(getWidth(niwindow))))+"px";
	}
	else {
		niwindow.style.left = (parseInt(getLeft(t))+parseInt(getWidth(t)))+"px";
	}
}

function hideJob(id)
{
	document.getElementById("jobwrapper"+id).style.display = "none";
	// Or refresh the page - not sure which is better
	//window.location.reload( false );
}

function sendNotInterested()
{
	var id = document.getElementById("notinterestedid").value;
	var reason = encodeURIComponent(document.getElementById("notinterestedreason").value);
	document.getElementById("notinterestedreason").value = "";
	ajaxCallServer("/candidate/notinterested.phtml?id=" + id + "&ajax=true&reason=" + reason);
	document.getElementById("notinterestedpopup").style.display = "none";
}

function onNotInterestedClick(t, id)
{
	if (t.nodeType == 3)
		t = t.parentNode; // Fix for Safari that triggers the event on the content
	
	if (t.nodeName == "IMG")
		t = t.parentNode;
	
	cancelOldWindow(); // Clear any old popup

	positionNearTarget(t);
	document.getElementById("notinterestedid").value = id;
	document.getElementById("notinterestedpopup").style.display = "block";
	return false;
}


function cancelOldWindow()
{
	document.getElementById("notinterestedpopup").style.display = "none";
}


/* STANDARD AJAX STUFF BELOW THIS LINE - DO NOT TOUCH 
   --------------------------------------------------------------------------------*/


var ajax=null;

function createXMLHTTPObject(){
	var A=null;
	try{
		A=new ActiveXObject("Msxml2.XMLHTTP")
	}catch(e){
		try{
			A=new ActiveXObject("Microsoft.XMLHTTP")
		} catch(oc){
			A=null
		}
	}
	if(!A && typeof XMLHttpRequest != "undefined") {
		A=new XMLHttpRequest()
	}
	return A
}

function standard_eval_callback()
{
    if (ajax.readyState==4 && ajax.responseText) {
		// The response text gets executed as javascript, so the server should return something like... 
		// myfuncname("fast bug", new Array("fast bug track", "fast bugs", "fast bug", "fast bugtrack"), new Array("793,000 results", "2,040,000 results", "6,000,000 results", "7,910 results"));
		eval(ajax.responseText)
    }
}

function ajaxCallServer(request_url){
  if (ajax && ajax.readyState!=0) {
    ajax.abort()
  }
  ajax=createXMLHTTPObject();
  if (ajax) {
    ajax.open("GET",request_url,true);
    ajax.onreadystatechange=standard_eval_callback;
    ajax.send(null)
  }
}
