clicked = false;
Ext.BLANK_IMAGE_URL='/gfx/blank.gif';

// MZ: Suppress errors (dijit will not trigger otherwise)
function stopError() 
{
  return true;
}

window.onerror = stopError;

		
function initTabs()
{
	var tabIndex = 0;
	// get the widget
	var el = Ext.get("fldCategory");
	if (Ext.get("tabProducts").getAttribute('selected') == "true")
	{
		el = Ext.get("fldProduct");
		tabIndex = 1;
	}
    // basic tabs 1, built from existing content
    var tabs = new Ext.TabPanel({
        renderTo: 'mainTabContainer',
        width: 980,
        activeTab: tabIndex,
        frame:true,
        plain:true,
        defaults: {autoHeight: true},
        items:[
            {contentEl:'tabCompanies', width: 300, title: '<img src="gfx/icons/companies.png" /> Bedrijven zoeken' },
            {contentEl:'tabProducts', title: '<img src="gfx/icons/products.png" /> Producten zoeken'}
        ]
    });

}		
		
Ext.onReady(function()
{ 

	// Custom rendering Template
	var resultTpl = new Ext.XTemplate(
	    '<tpl for="."><div class="search-item"><div class="label"><h3>{name}</h3><br /><div class="subinfo">{extra}</div></div>',
	    '</span><div class="clr"></div></div></tpl>'
	);

	var ds = new Ext.data.Store({
	    proxy: new Ext.data.ScriptTagProxy({
	        url: 'data.cfm'
	    }),
	    reader: new Ext.data.JsonReader({
	        root: 'results'
	    }, [
	        {name: 'id', mapping: 'id'},
	        {name: 'name', mapping: 'name'},
	        {name: 'extra', mapping: 'extra'}
	    ]),
		baseParams: {
	        r: 'geodata'
	    }
	});
	
	
	var cbSearch = new Ext.form.ComboBox({
	    store: ds,
	    displayField: 'displayCity',
	    typeAhead: false,
	    minChars: 3,
	    loadingText: 'Bezig met zoeken...',
	    width: 200,
		listWidth : 200,
	    height: 40,
	    tpl: resultTpl,
	    applyTo: 'fldCity',
	    itemSelector: 'div.search-item',
	    onSelect: function(record)
	    { 
			document.getElementById('fldCity').value = record.data.name;
	    	if (cbSearch) 
			{
				cbSearch.collapse();
			}
			
			
	    }
	});
	
	
	
});	

function initCategoryCB()
{
	// Custom rendering Template
	var resultCatTpl = new Ext.XTemplate(
	    '<tpl for="."><div class="search-item"><div class="label"><h3>{name}</h3><br /><div class="subinfo">{extra}</div></div>',
	    '</span><div class="clr"></div></div></tpl>'
	);
	
	var dsCats = new Ext.data.Store({
	    proxy: new Ext.data.ScriptTagProxy({
	        url: 'data.cfm'
	    }),
	    reader: new Ext.data.JsonReader({
	        root: 'results'
	    }, [
	        {name: 'id', mapping: 'id'},
	        {name: 'name', mapping: 'name'},
	        {name: 'extra', mapping: 'extra'}
	    ]),
		baseParams: {
	        r: 'catdata'
	    }
	});
	
	var cbSearchCat = new Ext.form.ComboBox({
	    store: dsCats,
	    displayField: 'displayCats',
	    typeAhead: false,
	    minChars: 3,
	    loadingText: 'Bezig met zoeken...',
	    width: 200,
		listWidth : 200,
	    height: 40,
	    tpl: resultCatTpl,
	    applyTo: 'fldCategoryEdit',
	    itemSelector: 'div.search-item',
	    onSelect: function(record)
	    { 
			document.getElementById('fldCategoryEdit').value = record.data.name;
	    	if (cbSearchCat) 
			{
				cbSearchCat.collapse();
			}
			
			
	    }
	});
							
}	
	


           
function errorHandler(message)
{
	$('disabledZone').style.visibility = 'hidden';
    if (typeof message == "object" && message.name == "Error" && message.description)
    {
        alert("Error: " + message.description);
    }
    else
    {
        alert(message);
    }
};

function resetSearchForm() {
	document.getElementById('fldCategory').value = '';
	document.getElementById('fldCity').value = '';
//	document.getElementById('fldKeyword').value = '';
}

function activateTab(e) {

	if (e == 'tabBedrijvenContent') {
		document.getElementById('tabBedrijven').className = 'tabhome active';
		document.getElementById('tabProducten').className = 'tabhome inactive';

		document.getElementById('tabBedrijvenContent').className = 'tabcontent visible';
		document.getElementById('tabProductenContent').className = 'tabcontent hidden';
	} 
	if (e == 'tabProductenContent') 
	{
		document.getElementById('tabBedrijven').className = 'tabhome inactive';
		document.getElementById('tabProducten').className = 'tabhome active';

		document.getElementById('tabBedrijvenContent').className = 'tabcontent hidden';
		document.getElementById('tabProductenContent').className = 'tabcontent visible';
	}
	if (e == 'tabProductenSearchContent') 
	{

		document.getElementById('tabProductSearchInnercontent').className = 'hidden';
		document.getElementById('tabContentProductSearch').className = 'visible';
		document.getElementById('imgPleaseWait').style.backgroundImage = 'url(gfx/animations/progress_loader.gif)';
	}

}

function fav(desc, url) {
if ( navigator.appName != 'Microsoft Internet Explorer' )
{ window.sidebar.addPanel(desc ,url,""); }
else { window.external.AddFavorite(url, desc); } }

function toggleDisplay(en) {
	var e = document.getElementById(en);
	if (e.className == 'hideBox') {
		e.className = 'showBox';
	} else {
		e.className = 'hideBox';
	}
}

function setSearch(o)
{
	document.location.search = '?' + o;
}

function searchCompanyKeywords(o)
{
	var e = document.getElementById('fldCategory');
	e.value = o;
	document.getElementById('fSearch').submit();
}

function searchCompanyRegion(o)
{
	var e = document.getElementById('fldCity');
	e.value = o;
	document.getElementById('fSearch').submit();
}


function searchAll()
{
	var e = document.getElementById('fldCompanyId');
	e.value = '';
	document.getElementById('frmProductSearch').submit();
	
}

var mapStatus = true;
 function swapMap() {
 	mapStatus = !mapStatus;
     if (mapStatus == true) 
     { 
	    Ext.get('GMapBox').syncFx().fadeOut().slideOut();
     }	
     else
     {
	    Ext.get('GMapBox').syncFx().fadeIn().slideIn();
     }
}

function map(e) 
{
	load();
}

function setFamilyFilter(o)
{
	document.location.search = '?action=familyfilter&set=' + o;
}

function cycleLayout(o)
{
	document.location.search = '?layout=' + o;
}


function resetClicks()
{
	document.location.search = '?action=resetclicks';
}

function sort(u)
{
	document.location = u;
}


function setCity(arguments)
{
	alert(arguments.event);
}


function getProfile() {  
  //The form data is sent to the given URL using a POST method, 
  //rather than a GET by using the dojo.xhrPost function.
  dojo.xhrPost({
    url: "ajax/profile",
    load: function(response, ioArgs){
      dojo.byId("divNewProfile").innerHTML = response;
      
      //Dojo recommends that you always return(response); to propagate 
      //the response to other callback handlers. Otherwise, the error 
      //callbacks may be called in the success case.
      return response;
    },
    error: function(response, ioArgs){
      dojo.byId("divNewProfile").innerHTML = 
        "An error occurred, with response: " + response;
      return response;
    },
    
    //Setting the 'form' parameter to the ID of a form on the page
    //submits that form to the specified URL
    form:"frmProfile"
  });
}
