﻿function encode(uri) { 	
    if (encodeURIComponent) { 
	    return encodeURIComponent(uri); 
    } 				
    if (escape) { 
	    return escape(uri); 
    } 
}
function trim(str) { 
    return str.replace(/^\s*|\s*$/g,""); 
}
function stopEvent(e) {
    if(!e) var e = window.event;
	
    //e.cancelBubble is supported by IE - this will kill the bubbling process.
    e.cancelBubble = true;
    e.returnValue = false;

    //e.stopPropagation works only in Firefox.
    if (e.stopPropagation) {
	    e.stopPropagation();
	    e.preventDefault();
    }
    return false;
}

function doEmailSubmit() {
    var email = trim(document.getElementById("txtEmailInput").value);
    if (email == "") {
	    alert("Please enter an email address");
	    //return false;
    }
    else if (!checkEmail(email)){
        alert("Please enter a valid email address");
	    //return false;
    }
    else {
        var loc = "http://www.snow.com/my-account/my-email-preferences.aspx?email=" + encode(email);
        //document.location = loc;
        window.open(loc);
    }
}
function doEmailKeyPress(e) {
    var key;
    if (window.event) {
	    key = window.event.keyCode;
    }
    else {
	    key = e.which;
    }
    if (key == 13) {
	    stopEvent(e);
	    doEmailSubmit();
    }
}
function checkEmail(email) {
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(email)) {
        email.focus;
        return false;
    }
    else
    {
        return true;
    }
}

