//first, tell the browsers to react to the event
if( document.captureEvents && Event.KEYUP ) {
  //remove this part if you do not need Netscape 4 to work
  document.captureEvents( Event.KEYUP );
}

/* this next line tells the browser to detect a keyup
event over the whole document and when it detects it,
it should run the event handler function 'alertkey' */
document.onkeyup = alertkey;

//now create the event handler function to process the event
function alertkey(e) {
  if( !e ) {
    //if the browser did not pass the event information to the
    //function, we will have to obtain it from the event register
    if( window.event ) {
      //Internet Explorer
      e = window.event;
    } else {
      //total failure, we have no way of referencing the event
      return;
    }
  }
  if( typeof( e.keyCode ) == 'number'  ) {
    //DOM
    e = e.keyCode;
  } else if( typeof( e.which ) == 'number' ) {
    //NS 4 compatible
    e = e.which;
  } else if( typeof( e.charCode ) == 'number'  ) {
    //also NS 6+, Mozilla 0.9+
    e = e.charCode;
  } else {
    //total failure, we have no way of obtaining the key code
    return;
  }
  if (e == "13")
	{

		if (CurrentModalWindow == "none")
		{
		
		}
	else
		{
		if (CurrentModalWindow == "sendJob")
			{
			sendJob();
			}
		else
			{
			sendPage();
			}
		}
	}
 // window.alert('The key pressed has keycode ' + e +
 //   ' and is key ' + String.fromCharCode( e ) );
 
}

function showSendJob(jobID){
	document.getElementById("sendJobId").innerHTML = jobID;
	engJobs.getJobDetailsForSendByJobID(jobID, callback_showSendJob);
	
	
	
}

function callback_showSendJob(res){

	if (res.error!=null){alert(res.error)};
	
	var dt = res.value;
	
	
	
	document.getElementById("jobTitle").innerHTML = dt.Rows[0].Job_Position;
	document.getElementById("jobLocation").innerHTML = dt.Rows[0].Job_Location;
	if (dt.Rows[0].Job_Short_Description!=null)
		{
		if (dt.Rows[0].Job_Short_Description!="")
			{
			document.getElementById("jobDescription").innerHTML = dt.Rows[0].Job_Short_Description;		
			}
		else
			{
			document.getElementById("jobDescription").innerHTML = "";
			}
		}
	else
		{
		document.getElementById("jobDescription").innerHTML = "";
		}
	
	
	openModalWindow('sendJob');
}


function sendJob(){
	
	var sender = getControlValue('txtSendJobEmailSender');
	var recip = getControlValue('txtSendJobEmailRecipient');
	var jobID = document.getElementById("sendJobId").innerHTML;
	var mess = document.getElementById("txtMessage-sendJob").value;
	
	showFeedback('sendJobActionContainer')
	engSendToFriend.sendJobToFriend(jobID, 'txtSendJobEmailRecipient', recip, 'txtSendJobEmailSender', sender, mess, callback_sendJob);	
	
}

function callback_sendJob(res){
if (res.error!=null){alert(res.error)};

var results = res.value.Tables[0];
	if (results.Rows[0].result == "True")
	{
		var controls = res.value.Tables[1];
		for (var i=0; i<controls.Rows.length; i++)
		{
			clearInputField(controls.Rows[i].controlID);
			setControlErrorMessage(controls.Rows[i].controlID,'');
		}
		switch (results.Rows[0].errMessage)
		{
			case "valid":
			clearInputField('txtMessage-sendJob');
			feedbackValid('Sending','Sent');
			window.setTimeout('hideSendJob();', 4000);
			
			break
		}
	}								
	else
	{
		var controls = res.value.Tables[1];
		switch (results.Rows[0].errMessage)
		{
			case "invalid":
			feedbackInvalid('sendJobActionContainer');
			window.setTimeout(function(){processValidationResponse(controls)}, 2001);
			break
		}
	}
}

function hideSendJob(){

		
	cleanupFeedback('sendJobActionContainer');
	
	window.setTimeout("closeModalWindow('sendJob');", 2000);
}

