var timeoutHnd;
var gridimgpath;

function createEventGrid(gridID, catID) {	

	var idDesc = gridID.split("_");
	if(idDesc.length > 0) {
		typeID = idDesc[1];
	}

	var colHeaders = [$("#"+ gridID).metadata({type:'attr',name:'data'}).head1,
				      $("#"+ gridID).metadata({type:'attr',name:'data'}).head2,
				      $("#"+ gridID).metadata({type:'attr',name:'data'}).head3,
				      $("#"+ gridID).metadata({type:'attr',name:'data'}).head4,
				      $("#"+ gridID).metadata({type:'attr',name:'data'}).head5,];
	
	if($("#"+ gridID).metadata({type:'attr',name:'data'}).head3 == "Location" ||
	   $("#"+ gridID).metadata({type:'attr',name:'data'}).head3 == "Ort")
		colModField3 = "location";
	else
		colModField3 = "time";
		
	var tblSortOrder = $("#"+ gridID).metadata({type:'attr',name:'data'}).sortorder;	
	
	if(tblSortOrder=="")
		tblSortOrder="asc";

	$("#"+ gridID).jqGrid({        
		url:'/'+ contextRootURI +'includes/getEventsOverview.php?lang=' + lang + "&evt_typeID=" + typeID + "&evt_catID=" + catID,
		datatype: "json",
		height: "auto",
		colNames:colHeaders,
		colModel:[
			{name:'title',index:'title_' + lang, width:310,resizable:false},
			{name:'date',index:'startDate', width:220,resizable:false},
			{name:colModField3,index:colModField3, width:130,resizable:false},
			{name:'price',index:'price', width:160,resizable:false},
			{name:'docRegisterLink', index:'none', width:140,sortable:false,resizable:false}			
		],
		rowNum:-1,
		width:"960",
		imgpath: gridimgpath,
		mtype: "POST",
		autowidth: false,
		forceFit: false,
		shrinkToFit: false,
		sortname: 'startDate',
		viewrecords: true,
		altRows: false,
		sortorder: tblSortOrder, 
		gridComplete: function() {
            if($("a.lightbox").length > 0) {
				$("a.lightbox").fancybox({
					'transitionIn'	:	'elastic',
					'transitionOut'	:	'elastic',
					'speedIn'		:	600, 
					'speedOut'		:	200, 
					'overlayShow'	:	true,
					'autoDimensions':   true,
					'autoScale' 	: 	false,
					'scrolling' 	: 	'no',
					'type'			:	'ajax',
					'ajax'			:	{'type'	: "POST"}
				});
			}
        } 
	});
}

function createReferenceGrid() {
	if (lang == "de")	
	{
		colHeaders = new Array('Firma','Land', 'Branche / Anwendung', 'L&ouml;sung', 'Download');
	}
	else {
		colHeaders = new Array('Company','Country', 'Branch / Application', 'Solution', 'Download');
	}
	
	$("#references").jqGrid({        
		url:'/'+ contextRootURI +'includes/getReferencesOverview.php?lang=' + lang,
		datatype: "json",
		height: "auto",
		colNames:colHeaders,
		colModel:[
			{name:'company',index:'company', width:220,resizable:false},
			{name:'country',index:'country', width:110,resizable:false},
			{name:'branch',index:'branch', width:230,resizable:false},
			{name:'solutions',index:'tableText_' + lang, width:250,resizable:false},
			{name:'doc', index:'none', width:150,sortable:false,resizable:false}			
		],
		rowNum:-1,
		width:"960",
		imgpath: gridimgpath,
		mtype: "POST",
		autowidth: false,
		forceFit: false,
		shrinkToFit: false,
		sortname: 'company',
		viewrecords: true,
		altRows: false,
		sortorder: "asc"
	});
}

function doSearch(ev){ 
	if(timeoutHnd)
		clearTimeout(timeoutHnd)
	timeoutHnd = setTimeout(gridReload,500)
}

function gridReload(){
	var countryID = $("#countryID").val();
	var solutionID = $("#solutionID").val();
	var branch = $("#branch").val();
	$("#references").setGridParam({url:"/"+ contextRootURI +"includes/getReferencesOverview.php?lang=" + lang + "&countryID="+countryID+"&solutionID="+solutionID+"&branch="+branch,page:1}).trigger("reloadGrid");
}


