function setCookie(cookie_name,value,expiration_days) { var expiration_date=new Date(); expiration_date.setDate(expiration_date.getDate() + expiration_days); var cookie_value=escape(value) + ((expiration_days==null) ? "" : "; expires="+expiration_date.toUTCString()); document.cookie=cookie_name + "=" + cookie_value + '; path=/'; } function getCookie(cookie_name) { var i, key, value, cookie_array=document.cookie.split(";"); for (i=0; i < cookie_array.length; i++) { key = cookie_array[i].substr(0,cookie_array[i].indexOf("=")); value = cookie_array[i].substr(cookie_array[i].indexOf("=")+1); key = key.replace(/^\s+|\s+$/g,""); if (key==cookie_name) { return unescape(value); } } return 0; } $(document).ready(function() { $('#ajax_logn').dialog({ autoOpen: false, width: 514, modal: true, resizable: false, minHeight: 230 }).css('height', '230px'); $('.ajax-login-container a').click(function(event) { event.preventDefault(); $('#ajax_logn').dialog('open'); $('#ajax_Customer_Login').focus(); }); $('#ajax_logn_button').click(function(event) { $('p.error').remove(); $('#ajax_logn input.error,#ajax_logn label.error').removeClass('error'); event.preventDefault(); var ajaxPost = 'Action=LOGN'; ajaxPost += '&PreAction=PREACTION_LOGN'; ajaxPost += '&Current_Screen=JQUERY-READY'; ajaxPost += '&Product_Code='; ajaxPost += '&Category_Code='; ajaxPost += '&Customer_Login=' + $('#ajax_Customer_Login').val(); ajaxPost += '&Customer_Password=' + $('#ajax_Customer_Password').val(); ajaxPost += '&function=sign-in'; $.ajax({ type: "POST", url: "/mm5/merchant.mvc?store_code=den&screen=ajax-functions", data: ajaxPost, success: function(response) { response = jQuery.parseJSON(response); switch(response.response) { case 'success': var firstName = response.bill_firstname; var lastName = response.bill_lastname; var secureURL = decodeURIComponent(response.secure_url); var storeCode = response.store_code; var sessionID = response.session_id; setCookie('mm5-den-customer-session', sessionID, 1); $('#ajax_logn').dialog('close'); $('body').append('

Thank you for logging in, ' + firstName + ' ' + lastName + '

'); $('#confirm-login').show(750).delay(1500).hide(250, function() { window.location.assign(secureURL); }); break; case 'wrong-username': $('#ajax_logn .forgot-password').after('

User does not exist

'); $('#ajax_Customer_Login').addClass('error').prev().addClass('error'); break; case 'wrong-password': $('#ajax_logn .forgot-password').after('

Wrong password

'); $('#ajax_Customer_Password').addClass('error').prev().addClass('error'); break; case 'need-username': $('#ajax_logn .forgot-password').after('

Enter a username

'); $('#ajax_Customer_Username').addClass('error').prev().addClass('error'); break; case 'need-password': $('#ajax_logn .forgot-password').after('

Enter a password

'); $('#ajax_Customer_Password').addClass('error').prev().addClass('error'); break; } } }); }); });