// Onload, fire
$('#candidate-iframe').load(function(){	
	//Filter out the html
	var f = $('#candidate-iframe')[0];
	
	var iframe = f.contentWindow ? f.contentWindow.document : f.contentDocument ? f.contentDocument : f.document;
	var html = $('body', iframe);
	//alert((iframe.body.scrollHeight + 30));
	//(queryFrame.contentWindow.document.body.scrollHeight
	  // alert(document.getElementById("candidate-iframe").contentWindow.document.body.scrollHeight);
	//$('#candidate-iframe').css('height', (document.getElementById("candidate-iframe").contentWindow.document.body.scrollHeight + 30));

	
	//setup unload
	$(f.contentWindow).unload(function(){
										   //alert('unloading');
		$('#candidate-iframe').css('display', 'none');					 
	});
	
	//alert(html.html());
	//alert($('body table:eq(0) tr:eq(0) > td:eq(2) > table:eq(1) > tbody:eq(0) > tr:gt(1)', iframe).html());
	//Change grey background colors
	$('table[bgcolor="#eeeeee"]', iframe).css('backgroundColor', '#F4EFEB');
	//alert($('body table:eq(0) tr:eq(0) > td:eq(2) > table:eq(1) > tbody:eq(0) > tr:eq(0) table > tbody table:eq(0) tr:eq(3)', iframe).html());
	$('body table:eq(0) tr:eq(0) > td:eq(2) > table:eq(1) > tbody:eq(0) > tr:eq(0) table > tbody table:eq(0) tr:eq(3)', iframe).remove();//remove extra tr 
	$('body table:eq(0) tr:eq(0) > td:eq(2) > table:eq(1) > tbody:eq(0) > tr:gt(0)', iframe).remove();//remove footer
	$('body table:eq(0) td:eq(0)', iframe).remove();
	$('body table:eq(1) tr:eq(0)', iframe).remove();
	$('body table:eq(4) tr:eq(1)', iframe).remove();
	$('body table:eq(4) tr:eq(0)', iframe).remove();
	
	$('#candidate-iframe').show();

	$('body table[width="585"]', iframe).attr('width', '').css('width', 620);
	$('body table[width="443"]', iframe).attr('width', '100%');
	$('body td[width="443"]', iframe).attr('width', '100%');
	
	
	
	 var queryFrame = document.getElementById('candidate-iframe');
	 
	 queryFrame.contentWindow.document.body.style.backgroundColor="#F4EFEB"; 

	queryFrame.style.height = (queryFrame.contentWindow.document.body.scrollHeight + 30) + 'px';
});

