/*
var hasFlash8 = DetectFlashVer(8, 0, 0);
var hasFlash9 = DetectFlashVer(9, 0, 0);
*/
var isIE  = (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin = (navigator.appVersion.toLowerCase().indexOf("win") != -1) ? true : false;
var isOpera = (navigator.userAgent.indexOf("Opera") != -1) ? true : false;

function emptyNode(id)
{
	var thenode = document.getElementById(id);
	while(thenode.hasChildNodes() == true)
	{
		thenode.removeChild(thenode.childNodes[0]);
	}
}
			
function mailLink(domain,name)
{
	var link = '<a href="mailto:'+name+'@'+domain+'">'+name+'@'+domain+'</a>';
	document.write( link );
}



/************************/
/*                      */
/*    Init functions    */
/*                      */
/************************/

// Set keyboard actions for search field
document.observe("dom:loaded", function() 
{
	if ($('searchbox'))
	{
		$('searchbox').observe('keyup',function(event)
		{
			var el = event.element();
			if(event.keyCode == 13){
				// Enter key pressed
				var value = el.getValue();
				if (value == '')
				{
					// No value
					Event.stop(event);
				}
				else
				{
					// Search text was given, so continue
					runSearch(value);
				}
			}
		});
	}
	
	if ($('contactform') && $('sendbutton'))
	{
		$('sendbutton').observe('mousedown',function(event)
		{
			sendContactMail();
		});
	}
});

function runSearch(value)
{
	if (value == undefined)
	{
		if ($('searchbox')) {
			var value = $('searchbox').getValue();
		}
	}

	if (value != null && value != '')
	{
		// Replace spaces with underscores
		value = value.replace(' ','_');
		document.location = '/search/'+encodeURIComponent(value);
	}
}

function sendContactMail()
{
	var at = new AjaxTool2;
	at.url = '/ajax/sendContactMail.php';
	
	$$('#contactform input').each(function(item) {
	  at.addField(item.name,item.getValue());
	});
	$$('#contactform select').each(function(item) {
	  at.addField(item.name,item.getValue());
	});
	$$('#contactform textarea').each(function(item) {
	  at.addField(item.name,item.getValue());
	});
	//alert(trace);
	at.responseFunction = function(obj)
	{
		if (obj.result == "error")
		{
			alert(obj.message);
		}
		else
		{
			// Check if a response function is defined and if it is, set the AjaxTool response function
			if(typeof window.senContactMailResponse == 'function')
			{
				// function exists, so we can use it
				senContactMailResponse(obj);
			}
		}
	}
	at.send();
}

/****************************
*
*   Debug functions
*
*****************************/

function trace(str)
{
	var secs = msTime() - startTime;
	//Spry.Debug.trace(secs+" ms. - "+str);
}

function unix_time()
{
	var now = new Date();
	return parseInt(now.getTime().toString().substring(0,10));
}

function msTime()
{
	var now = new Date();
	return now.getTime();
}

startTime = msTime();
trace("Page start");