var qgoImagePath = "/unigarantwebsite/templates/images/qgo/";
var qgoSearchButton = document.getElementById("button");
var qgoFaqButton = document.getElementById("q_go_faq_button");
var gqoDialogDiv =  document.getElementById("qg");
var tab_zoeken = document.getElementById("tabZoeken");;
var tab_faq = document.getElementById("tabFaq");;
var tab_top10 = document.getElementById("tabTop10");;
var normalSearchButton = document.getElementById("qg");
var qGo_iFrame = document.getElementById("iframeQGo");
var overlay = document.getElementById('sa-overlay');

var windowHeight = 660;
var windowWidth = 590;

var iFrameHeight = windowHeight - 142;
var iFrameWidth = windowWidth - 14;

qGo_iFrame.style.height = iFrameHeight+"px";
qGo_iFrame.style.width = iFrameWidth+"px";
		
function onSearchKeyPressClosed(e, searchTextBox)
{
	if (getKey(e) == 13)
	{	
		StopBubbling(e);
		if((searchTextBox.value != ""))
		{
			openSearchDialog();
			return false;
		}
		else 
		{
			return false;
		}
	}
	else
	{
		return true;
	}
}
	
function onSearchKeyPress(e, searchTextBox)
{
	
	if (getKey(e) == 13)
	{	
		StopBubbling(e);
		if((searchTextBox.value != ""))
		{
			DoSearch();
			return false;
		}
		else 
		{
			return false;
		}
	}
	else
	{
		return true;
	}
}
	
function getKey(e)
{
		if (window.event)
		{
			return window.event.keyCode;
		}
		else if (e)
		{
			return e.which;
		
		}
		else
		{
			return null;
		}
}
	
function StopBubbling(e)
{
		if(window.event && window.event.cancelBubble != null)
		{
			window.event.cancelBubble = true;
		}
		else if(e && e.stopPropogation)
		{
			e.stopPropogation();
		}
}	
	

function openSearchDialog()
{
		if(document.getElementById('QGoWrapperSearch').value != "Stel hier uw vraag:" && document.getElementById('QGoWrapperSearch').value != "")
		{
			document.getElementById('QGoVragenTextBox').value =document.getElementById('QGoWrapperSearch').value;
			HideButton();
			qgoSearchButton.onclick = closeDialog;
			document.getElementById('sq').style.display = 'block';
			
			document.getElementById('iframeQGo').src = 'http://interface.q-go.net/unigarant/index.php?sQuestion=' + document.getElementById('QGoWrapperSearch').value;
			
		$("#sq").animate({
		width: "591px",
		height: "660px"
		}, 500, ShowCloseButton);
			
		if(window.XMLHttpRequest)
		{ 
			overlay.style.display = 'block';
		}
			
			SwitchTab(tab_zoeken);
		} else
		{
			document.getElementById('QGoVragenTextBox').value =document.getElementById('QGoWrapperSearch').value;
			HideButton();
			qgoSearchButton.onclick = closeDialog;
			document.getElementById('sq').style.display = 'block';
			
			document.getElementById('iframeQGo').src = 'http://interface.q-go.net/unigarant/index.php';
			
			
		$("#sq").animate({
		width: "591px",
		height: "660px"
		}, 500, ShowCloseButton);
			
		if(window.XMLHttpRequest)
		{ 
			overlay.style.display = 'block';
		}
			SwitchTab(tab_zoeken);
	}
}
	
function openFaqDialog()
{
		HideButton();
		qgoSearchButton.onclick = closeDialog;
	
		document.getElementById('sq').style.display = 'block';
	document.getElementById('iframeQGo').src = 'http://interface.q-go.net/unigarant/faq.php?cat=' + document.getElementsByName('QGoFaqCategorieID')[0].value;
	
	$("#sq").animate({
		width: "590px",
		height: "660px"
		}, 500, ShowCloseButton);
		
	
		if(window.XMLHttpRequest)
		{ 
			overlay.style.display = 'block';
		}
	
		
		SwitchTab(tab_faq);
		
}
	
function GotoFaqTab()
{
		if(tab_faq.className != "active")
		{
			qGo_iFrame.src = 'http://interface.q-go.net/unigarant/faq.php?cat=' + document.getElementsByName('QGoFaqCategorieID')[0].value;
			SwitchTab(tab_faq);
		}
	}
	
function GotoZoekenTab()
{
		if(tab_top10.className != "active")
		{
			qGo_iFrame.src = 'http://interface.q-go.net/unigarant/index.php?sQuestion=';
			SwitchTab(tab_zoeken);
		}
	}
	
function GotoTop10Tab()
{
		if(tab_top10.className != "active")
		{
			qGo_iFrame.src = 'http://interface.q-go.net/unigarant/top10.php';
			SwitchTab(tab_top10);
		}
	}
	
function SwitchTab(tab)
{
		tab_faq.className = tab_zoeken.className = tab_top10.className = "inactive";
		tab.className = "active";
}
	
function DoSearch()
{
		SwitchTab(tab_zoeken);
		document.getElementById('iframeQGo').src = 'http://interface.q-go.net/unigarant/index.php?sQuestion=' + document.getElementById('QGoVragenTextBox').value;
		if(tab_zoeken.className != "active")
		{
			SwitchTab(tab_zoeken);
		}
}

function openDialog()
{
		HideButton();
		
		qgoSearchButton.onclick = closeDialog;
		
		document.getElementById('sq').style.display = 'block';
		if(document.getElementById('QGoWrapperSearch').value=='Stel hier uw vraag:')document.getElementById('QGoWrapperSearch').value='';
		//document.getElementById('QGoVragenSearch').value = document.getElementById('QGoWrapperSearch').value;
		document.getElementById('iframeQGo').src = 'http://interface.q-go.net/unigarant/index.php?sQuestion=' + document.getElementById('QGoWrapperSearch').value;
}
	
function closeDialog()
{
		HideButton();
		
		document.getElementById('iframeQGo').src = "about:blank";
	document.getElementById('iframeQGo').style.display = 'none';
	document.getElementById('trBanner3').style.display = 'block';
		
		qgoSearchButton.onclick = openSearchDialog;
		
	$("#sq").animate({
		width: "150px",
		height: "81px"
		},500, ShowSearchButton );
		
}
		
function HideButton()
{
		qgoSearchButton.style.display = "none";
		qgoFaqButton.style.display = "none";
}
function ShowSearchButton()
{
		qgoSearchButton.src = qgoImagePath + "searchbutton.gif";
		qgoSearchButton.style.display = "block";
		qgoFaqButton.style.display = "block";
		document.getElementById('sq').style.display = 'none';
	overlay.style.display = 'none';
}
function ShowCloseButton()
{
		qgoSearchButton.src = qgoImagePath + "closebutton.gif";
		qgoSearchButton.style.display = "block";
	qgoSearchButton.style.zIndex = "15";
	document.getElementById('iframeQGo').style.display = 'block';
}