// JavaScript Document
windowsize = function() {
	var w = 0;
	var h = 0;
	var sl = 0;
	var st = 0;

	//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			w = document.documentElement.clientWidth;
			h = document.documentElement.clientHeight;
			sl = document.documentElement.scrollLeft;
			st = document.documentElement.scrollTop;
		}
		//quirks mode
		else
		{
			w = document.body.clientWidth;
			h = document.body.clientHeight;
			sl = document.body.scrollLeft;
			st = document.body.scrollTop;
		}
	}
	//w3c
	else
	{
		w = window.innerWidth;
		h = window.innerHeight;
		sl = window.scrollLeft;
		st = window.scrollTop;
		
	}
	return {width:w,height:h,scrollLeft:sl,scrollTop:st};
}


function positionPopup(id,width,height) {
	
	if(windowsize().width > width) {
		document.getElementById(id).style.left = (windowsize().width - width)/2 + 'px';
	} else {
		document.getElementById(id).style.left = 0;
	}
	if(windowsize().height > height) {
		document.getElementById(id).style.top = ((windowsize().height - height)/2) + document.body.scrollTop + 'px';
		//document.getElementById(id).style.top = windowsize().scrollTop + 100;
	} else {
		document.getElementById(id).style.top = 0;
	}
	
	
	return true;
}



$(document).ready(function()  {
	
	$("#list2").jqGrid({ 
			url:'/index.cfm/do/jsondata.UsersByItemID/itemID/'+0+'/surveyControllerID/' +0, 
			datatype: "json", 
			colNames:['First Name','Last Name','Completed','Date Completed'], 
			colModel:[ 
				{name:'firstname',index:'firstname', width:70, align:'left'}, 
				{name:'lastname',index:'lastname', width:70, align:'left'},
				{name:'completed',index:'completed', width:30, align:'center'},
				{name:'dateCompleted',index:'dateCompleted', width:30, align:'center'}
			], 
			rowNum:100,
			rownumbers:true,
			rowList:[100,500,1000], 
			pager: '#pager2', 
			sortname: 'lastname', 
			sortorder: 'asc',
			viewrecords: true, 
			caption:"Roster",
			hidegrid:0,
			height:400,
			width:600
		}); 
	
	$('.completed-link').click(function(){
		$('#list2').data('itemID', $(this).attr('itemID'),'surveyControllerID', $(this).attr('surveyControllerID'));
		$("#list2").jqGrid('clearGridData');
		$('#list2').setGridParam({url: '/index.cfm/do/jsondata.UsersByItemID/itemID/' + $(this).attr('itemID') + '/surveyControllerID/' + $(this).attr('surveyControllerID')});
    	$('#list2').trigger("reloadGrid");  
		
	
		$("#list2").jqGrid('navGrid','#pager2',{edit:false,add:false,del:false}); 	
		
	});
	
});



