$(document).ready(function() {
    
    //bVersion = getInternetExplorerVersion();

    init();
    
    // Handle the newsletter subscribe functionality
    var options = { 
        success:		showNewsletterSubscribeResponse,  // post-submit callback
        dataType:		'xml'
	}; 
	
	// bind form using 'ajaxForm'
	var message = ''; 
    $('.newsletterSubscribeForm').each(function(i) {
    	$(this).ajaxForm(options);
    });
    
    $('a.csc').click(function() {
		$('#whatsThis').slideToggle('normal');
	});
	
	$('a#loginFormForgotPassword').click(function(){
		var emailAddress = $('#emailAddress').val();
		if (emailAddress.length > 0) this.href += '&emailAddress='+emailAddress;
	});
});

function getInternetExplorerVersion() {
	var rv = -1;
	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;
}

function init() {
    $('a.popupLink').bind('click', function(e) { popupWindow($(this).attr('href'), $(this).attr('title').replace(/[^A-z]/ig, ''),'width=710, height=750, scrollbars'); e.preventDefault(); });
}

function popupWindow(url, name, attributes){
	var newWindow = window.open(url, name, attributes);
	newWindow.focus();
}


// Show response from the newsletter subscribe AJAX form submit
function showNewsletterSubscribeResponse(responseText, statusText)  {
	var responseStatus = $('response', responseText).attr('status');
	
	// Check the response status
	var responseMessage  = '';
	if(responseStatus == 'ok') {
		// We had a successful response
		// Display a success message
		responseMessage = 'Your email address has been submitted. You will receive an email shortly to confirm your registration.';
		$('.newsletterSubscribeForm input:text').val('');
		$('.newsletterSubscribeForm').hide();
		window.location = 'index.php?nodeId=104';
	} else if(responseStatus == 'fail') {
		// We had a failure
		// Display errors
		responseMessage = $('response error-message', responseText).text();
	} else {
		// There was some unknown error
		// Display message
		responseMessage = 'An error occurred communicating with the server. Please try again later';
	}
	
	$('.newsletterResponseMessage').html(responseMessage);
}

function stateChangeHandler() {
	//$("#refinesearchForm").submit();
	$('#submitFilter').click();
}

 
