function signInUp(formId){	

		var frm = document.getElementById(formId);
		var url;
		var propertyID;
		var redirectToAcct = (formId == 'formSignUp') ? frm.chkToNewAcct.checked : frm.chkToMyAcct.checked;

		url = '/listmailer/ListMailerSignIn/signUp_AJAX.asp?doNotCacheIE=' + Math.random();
		//url += (formId == 'formSignUp' ? '&email=' +  $("#"+formId + " #email").val() + '&password=' +  $("#"+formId + " #password").val() + '&password2=' +  $("#"+formId + " #password2").val() + '&firstName=' + $("#"+formId + " #firstName").val() : '&email=' + $("#"+formId + " #emailSignIn").val() + '&password=' +  $("#"+formId + " #passwordSignIn").val());
		url += (formId == 'formSignUp' ? '&email=' + $("#" + formId + " #email").val() + '&firstName=' + $("#" + formId + " #firstName").val() : '&email=' + $("#" + formId + " #emailSignIn").val());

		$.get(url, function(data) {
		    if (data == 'signedUp' || data == 'signedIn') {
		        if (getCookie('saveProperty')) {     /* Save Property */
		            propertyID = getCookie('saveProperty').split('|');
		            saveProperty(propertyID[0], propertyID[1]);
		            savePropertyOnload();
		            setCookie('saveProperty', '', '', '/', '', '');
		        }
		        else if (getCookie('saveSearch')) {   /* Save Search */
		            saveSearch(getCookie('saveSearch'));
		            setCookie('saveSearch', '', '', '/', '', '');
		        }

		        $.fn.colorbox.close();
		        redirectToAcct ? location.href = '/listmailer/' : refreshWidget();
		    }
		    else {
		        if (data == 'wrongEmail') {
		            $('#RequiredSignIn').html('Sorry, we have no record of this e-mail address. Please try again or create a new account.');
		        } else if (data == 'invalidPassword') {
		            $('#RequiredSignIn').html('Sorry, Your password did not match.');
		        } else if (data == 'wrongPassword') {
		            $('#RequiredSignIn').html('Sorry, Your password did not match. Try again, or click I Forgot My Password and we will e-mail your password.');
		        }
		    }
		});
	}

function forgotPwd(formId) {
    
    $.get('/_include/listmailercom/AJAX_ForgotPassword.asp', { Subscriber: $("#" + formId + " #emailSignIn").val() }, function(data) {

        if(data == 'passwordSent'){
            $('#RequiredSignIn').html('Your password has been sent to you.');
        } 
        else {
            $('#RequiredSignIn').html('Sorry, we have no record of this e-mail address. Please try again or create a new account.');
        }
    });
}

function showColorbox(href) {
    $.fn.colorbox({
        'opacity': 0.7,
        'width': 450,
        'href': href
    });    
}

function refreshWidget() {
    
    var widgetPinned = (getCookie('widgetPinned') == 'true');

    $.get('/listmailer/widgetcontent.asp', function(data) {
        $('#listmailerContent #widget').html(data);

        $('#quicksignout').click(function() {
            setCookie('listmailerlogin', '', '', '/', '', '');
            setCookie('listmaileremail', '', '', '/', '', '');
            setCookie('widgetPinned', '', '', '/', '', '');
            setCookie('savedPropertyList', '', '', '/', '', '');
            location.reload();
        });

        $('.quicksignin').click(function(evt) {
            evt.preventDefault();
            showColorbox($(this).attr('href'));
        });

        $('.quicksignup').click(function(evt) {
            evt.preventDefault();
            showColorbox($(this).attr('href'));
        });

        if (widgetPinned) {
            $('.listmailercallout').css({ 'width': '220px', 'opacity': '0.9' });
            $('#pinslider').attr('src', '/images/pushpin.png');
        }
        else {
            $('#pinslider').attr('src', '/images/pushpin_unpinned.png');
        }

        $('.open').click(function() {
            $('.listmailercallout').animate({
                width: '220px',
                opacity: '0.9'
            }, 'fast', 'linear');
        });

        $.closeSlider = function() {
            $('.listmailercallout').animate({
                width: '52px',
                opacity: '0.9'
            }, 'fast', 'linear');
        }

        $('.listmailercallout').hover(function() { }, function() {
            if (location.pathname != '/' && location.pathname != '/default.asp' && !widgetPinned) $.closeSlider();
        });

        $('#pinslider').click(function() {
            if (widgetPinned) {
                $.cookie('widgetPinned', '', { path: '/' });
                $('#pinslider').attr('src', '/images/pushpin_unpinned.png');
                $.closeSlider();
                widgetPinned = false;
            }
            else {
                $.cookie('widgetPinned', 'true', { path: '/' });
                $('#pinslider').attr('src', '/images/pushpin.png');
                $('.listmailercallout').unbind('mouseenter mouseleave')
                widgetPinned = true;
            }
        });
    });
}

jQuery(document).ready(function() {
    refreshWidget();
});
