function getInternetExplorerVersion()
{
   var rv = -1; // Return value assumes failure.
   if (navigator.appName == 'Microsoft Internet Explorer')
   {
      var ua = navigator.userAgent;
      var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
      if (re.exec(ua) != null)
         rv = parseFloat( RegExp.$1 );
   }
   return rv;
}

if(getInternetExplorerVersion()!=6){
	Cufon.replace('.cufon');
}

function setFeedbackHtml()
{
	var pagehtml = "<html>" + $("html").html() + "</html>";
	document.getElementById('pagehtml').value = pagehtml;

}

function loadCommon()
{
	/*
	$("#modalLogin").dialog({
		autoOpen: false,
		bgiframe: true,
		width: 380,
		height: 395,
		modal: true,
		draggable: false,
		resizable: false
	});

	$("#modalRegistration").dialog({
		autoOpen: false,
		bgiframe: true,
		width: 380,
		height: 360,
		modal: true,
		draggable: false,
		resizable: false
	});
	*/	
	$("#modalFeedback").dialog({
		autoOpen: false,
		bgiframe: true,
		width: 380,
		height: 400,
		modal: true,
		draggable: false,
		resizable: false	
	});
	
	$("#modalError").dialog({
		autoOpen: false,
		bgiframe: true,
		width: 380,
		height: 300,
		modal: true,
		draggable: false,
		resizable: false
	});
	
	$('#buttonSubmit').click( 
		function(e) {
			e.preventDefault();
			setFeedbackHtml();
			
			$.post('/search/feedback/create', { feedType: 	$('#feedType').val(), 
												feedSubject: 	$('#feedSubject').val(),
												emailAddr: 	$('#emailAddr').val(),
												feedMessage: $('#feedMessage').val(),
												pageuri: $('#pageuri').val(),
												pagehtml: $('#pagehtml').val(),
												userAgent: navigator.userAgent,
												format: 'json'},
			  function(data){
			  	if(data.feedbackSaved==true)
			  	{
			  		$('#feedSubject').val('');
			  		$('#feedMessage').val('');
			  		/*
			  		$('#message_dialog').html('<p><span class=\'ui-icon ui-icon-circle-check\' style=\'float:left; margin:0 7px 50px 0;\'></span>Your feedback has been received by Zoombu.</p><p>Thank you for helping us improve our product.</p>');
			  		$('#message_dialog').dialog('open');
			  		$('#title').val('');
					$('#feedbacktext').val('');*/
			  	}
			  	else
			  	{
			  		showModalError("There was a problem submitting your feedback. Please check that the message is between 1 and 2000 characters long and that you have entered a valid email address.<br /><br /> Click the feedback button to try again.",'0');
			  	}
			  },'json');
			$('#modalFeedback').dialog('close');
		}
	);

	//$('#buttonLogin').click(function(){ $('#modalLogin').dialog('open'); });
	//$('#buttonRegistration').click(function(){ $('#modalRegistration').dialog('open'); });
	$('#buttonFeedback').click(function(){ scroll(0,0); $('#modalFeedback').dialog('open'); });
	$('#linkFeedback').click(function(){ $('#modalFeedback').dialog('open'); });
}

function showModalError(message,status)
{
	$('#modalErrorMessage').html(message);
	$('#modalErrorStatus').html(status);	
	$('#modalError').dialog('open');	
}

function hideModalError()
{
	$('#modalError').dialog('close');
}