clicked = false;

var searchBoxStatus = true;
var searchUserBoxStatus = true;

function errorHandler(message)
{
	$('disabledZone').style.visibility = 'hidden';
    if (typeof message == "object" && message.name == "Error" && message.description)
    {
        alert("Error: " + message.description);
    }
    else
    {
        alert(message);
    }
};

function sort(u)
{
	document.location = u;
}

$(document).ready(function()
{
	try
	{
		initScrollBox();
		initAutoComplete();
		initLightbox();
		initTooltips();
	}
	catch (e)
	{
	}
	
});



function initAutoComplete()
{
	var acOptions = {
		source: 'data.cfm',
	    minChars: 3,
	    max: 100,
	    dataType: 'json', // this parameter is currently unused
	    extraParams: {
	        format: 'json' // pass the required context to the Zend Controller
	        ,'r': 'producttitles'
	    },
	    select: function( event, ui )
	    {
	    	document.getElementById('fldProduct').value = ui.item.value;
			document.getElementById('frmProductSearch').submit();
	    },
	    formatItem: function(item) {
	        return item.displayName + ' (' + item.mail + ')';
	    }
	};
	
    $("#fldProduct").autocomplete(acOptions);
				
}	

function initLightbox()
{
	$("div[rel]").overlay();
	$("a[rel='photos']").colorbox();
	$("#id_pricealarm").overlay({

		mask: 'darkred',
		effect: 'apple',

		onBeforeLoad: function() 
		{
			// grab wrapper element inside content
			var wrap = this.getOverlay().find(".contentWrap");
			if (wrap)
			{
				// load the page specified in the trigger
				wrap.load(this.getTrigger().attr("href"));
			}
		}

	});	
}	

function initTooltips()
{

	$("[title]").tooltip({
	
	   // tweak the position
	   offset: [10, 2],
	
	   // use the "slide" effect
	   effect: 'slide'
	
	// add dynamic plugin with optional configuration for bottom edge
	}).dynamic({ bottom: { direction: 'down', bounce: true } });

}

function stopError() {
  return true;
}

window.onerror = stopError;

function scrollToTop()
{
	Ext.getBody().scrollTo('top', 0);

}

function scrollToBottom()
{
	Ext.getBody().scrollTo('bottom', 200);

}

function resetSearchForm() {
	document.getElementById('fldCategory').value = '';
	document.getElementById('fldCity').value = '';
//	document.getElementById('fldKeyword').value = '';
}

function activateTab(e) {

	if (e == 'tabProductenSearchContent') 
	{
	
		document.getElementById('tabProductenContent').className = 'tabcontent hidden';
		document.getElementById('tabContentProductSearch').className = 'tabcontent visible';
		document.getElementById('imgPleaseWait').style.backgroundImage = 'url(gfx/animations/progress_green_large.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';
	}
}




var loginBoxStatus = true;
var winLogin;
function toggleLogin() 
{
 	loginBoxStatus = !loginBoxStatus;
     if (loginBoxStatus == true) 
     { 
     
		winLogin.hide();

     }	
     else
     {
     	if (!winLogin)
     	{
    		winLogin = showDialog('Inloggen', 'loginBox', {
                    text:'Inloggen',
                    handler: function()
                    {
                    	document.getElementById('frmLogin').submit();
                    }
                },{
                    text: 'Sluiten',
                    handler: function(){
                        win.winLogin();
                    }
                });
		}
		winLogin.show();
     }
}

var pricewatchBoxStatus = true;
var pricewatchBoxStatusInit = true;
function showDialog(title, div, buttons)
{
	alert(title);
}


 function toggleSearchOptions() {
 	searchBoxStatus = !searchBoxStatus;
     if (searchBoxStatus == true) 
     { 
     	document.getElementById('searchExpandIcon').src = 'gfx/icons/expand.png';

		Ext.get('searchOptions').syncFx().fadeOut().slideOut();

     }	
     else
     {
     

     	document.getElementById('searchExpandIcon').src = 'gfx/icons/collapse.png';

		Ext.get('searchOptions').syncFx().fadeIn().slideIn();

     }
}

function toggleUserOptions() 
{
	setCookie('searchUserBoxStatus', searchUserBoxStatus, 30);
 	searchUserBoxStatus = !searchUserBoxStatus;
	
     if (searchUserBoxStatus == true) 
     { 
     	document.getElementById('userOptionsExpandIcon').src = 'gfx/icons/expand.png';
		var e = document.getElementById('userOptionsBox');
		e.style.display = 'none';
     }	
     else
     {
     
     	document.getElementById('userOptionsExpandIcon').src = 'gfx/icons/collapse.png';
		var e = document.getElementById('userOptionsBox');
		e.style.display = 'block';
     }
}

function toggleOptions(e) {
	
	o = dojo.byId(e);
	if (!o.getAttribute('expanded')) 
	{
		o.setAttribute('expanded', false);
	}
     if (o.expanded == true) 
     { 
		o.expanded = false;
     	document.getElementById(e + 'Icon').src = 'gfx/icons/expand.png';
		var wipeOut = dojo.fx.wipeOut({node: e,duration: 300});
		var fadeOut = dojo.fadeOut({node: e,duration: 300});
		
		var ani = dojo.fx.combine([wipeOut, fadeOut]);
		ani.play();

     }	
     else
     {
		o.expanded = true;
     
     	document.getElementById(e + 'Icon').src = 'gfx/icons/collapse.png';
		var wipeIn = dojo.fx.wipeIn({node: e,duration: 300});
		var fadeIn = dojo.fadeIn({node: e,duration: 300});

		var ani = dojo.fx.combine([wipeIn, fadeIn]);
		ani.play();


     }
}

function deleteMonitor(o)
{
	if (confirm('Weet u zeker dat u deze product monitor wilt verwijderen ?'))
	{
		document.location.search = '?action=delete&id=' + o;
	}
}

function deleteFavorite(o)
{
	if (confirm('Weet u zeker dat u deze product favoriet wilt verwijderen ?'))
	{
		document.location.search = '?action=delete&id=' + o;
	}
}

function setFamilyFilter(o)
{
	document.location.search = '?action=familyfilter&set=' + o;
}


function setSpotLight(o)
{
	document.location.search = '?action=spotlight&set=' + o;
}

function resetClicks()
{
	document.location.search = '?action=resetclicks';
}

function cycleLayout(o)
{
	document.location.search = '?layout=' + o;
}

function doSearch()
{
	activateTab('tabProductenSearchContent');
}

function map(e) {
	toggleDisplay(e);		
	if (!clicked) {
		clicked = true;
		load();
	}
}

function setCookie(c_name, value, expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	document.cookie = c_name + "=" +escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toGMTString() + "; path=/");
}

function getCookie(c_name)
{
	if (document.cookie.length>0)
	{
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1)
		{ 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
		} 
	}
	return "";
}

