function updateAccountInfo(sessionid, httpsPort, usingURL) {
	var url = "https://"+window.location.hostname+":"+httpsPort+"/web_mitrya/pricemightysubmit.jsp?sid="+sessionid+"&mode=6";
	emailsubmitcontainer.innerHTML = "<iframe src='" + url + "'></iframe>";	
	securefollowup(sessionid, 1, usingURL);
}

function showUpdateAccountInfo(olduserid, oldpassword, oldzip) {
	closeAllDialogs();
	currentActiveContainer = "newshopperwindow";
	currentActiveHeight = 380;
	currentActiveWidth = 400;	

	var userid = getElement("newuserid");
	var password = getElement("newpwd");
	var verify = getElement("newverifypwd");
	var zip = getElement("newzip");
	var useriderror = getElement("newuseriderror");
	var passworderror = getElement("newpwderror");
	var verifyerror = getElement("newverifypwderror");
	var ziperror = getElement("newziperror");
	var title = getElement("newshoppertitle");
	var note = getElement("newshoppernote");
	var action = getElement("newshopperaction");
	var cancel = getElement("newshoppercancel");
	var mode = getElement("newshoppermode");
	
	userid.value = olduserid;
	password.value = oldpassword;
	verify.value = oldpassword;
	zip.value = oldzip;
	useriderror.innerHTML = "&nbsp;";
	passworderror.innerHTML = "&nbsp;";
	verifyerror.innerHTML = "&nbsp;";
	ziperror.innerHTML = "&nbsp;";
	mode.value = 2;
	
	title.innerHTML = "Modify Shopper Account";
	note.innerHTML = "<b>Welcome to ShopMighty!</b><br>The 'Modify Shopper Account' enables you to modify your account information.";
	action.innerHTML = "Update Account";
	cancel.innerHTML = "Cancel";
	
	openDialog(currentActiveContainer, currentActiveHeight, currentActiveWidth);
	userid.focus();
}

function checkEnterNewAccount(e, sessionid, fromurl) { //e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable

	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e
	characterCode = e.which //character code is contained in NN4's which property
	}
	else{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		submitNewAccount(sessionid, fromurl, '', 0); //submit the form
		return false
	}
	else{
		return true
	}

}

function submitNewAccount(sessionid, fromurl, shopperid, mode) {
	var userid = getElement("newaccountuserid");
	var password = getElement("newaccountpassword");
	var verify = getElement("newaccountpasswordverify");
	var zip = getElement("newaccountzip");
	var email = getElement("newaccountemail");
	var error = getElement("newaccounterror");
	var fail = 0;
	error.innerHTML = "&nbsp;";	
	if (userid.value.length == 0) {
		error.innerHTML = "Please enter a User Id.";
		userid.className = "inputBoxAlert";
		userid.focus();
		fail = 1;
	} else {
		userid.className = "inputBox";
	}
	if (fail == 0) {
		if (password.value.length == 0) {
			error.innerHTML = "Please enter a password.";
			password.className = "inputBoxAlert";
			password.focus();
			fail = 1;
		} else {
			password.className = "inputBox";
		}
	}
	if (fail == 0) {
		if (verify.value.length == 0) {
			error.innerHTML = "Please verify your password.";
			verify.className = "inputBoxAlert";
			verify.focus();
			fail = 1;
		} else {
			verify.className = "inputBox";
		}
	}
	if (fail == 0) {
		if (fail == 0 && password.value != verify.value) {
			error.innerHTML = "Password and Verify Password do not match.";
			password.className = "inputBoxAlert";
			verify.className = "inputBoxAlert";
			password.focus();
			fail = 1;
		} else {
			verify.className = "inputBox";
			password.className = "inputBox";
		}
	}
	if (fail == 0) {
		if (zip.value.length == 0) {
			error.innerHTML = "Please enter a valid zip code.";
			zip.className = "inputBoxAlert";
			zip.focus();
			fail = 1;
		} else {
			if (validateNumber(zip) != "VALID") {
				error.innerHTML = "Zip code must be a number.";
				zip.className = "inputBoxAlert";
				zip.focus();
				fail = 1;			
			} else if ((zip.value.length < 5)) {
				error.innerHTML = "Zip code must contain 5 digits.";
				zip.className = "inputBoxAlert";
				fail = 1;
				zip.focus();
			}
			if (fail == 0) {
				error.innerHTML = "&nbsp;";	
				zip.className = "inputBox";
			}
		}
	}
	if (email.value.length > 0 && fail == 0) {
		var validate = validateEmail(email.value);
		if (validate.length > 0) {
			error.innerHTML = "Please enter a valid E-Mail address.";
			email.className = "inputBoxAlert";
			email.focus();
			fail = 1;
		} else {
			error.innerHTML = "&nbsp;";	
			email.className = "inputBox";
		}
	}
	
	if (fail == 0) {
		var url;

		url = "web_mitrya/pricemightysubmit.jsp?sid="+sessionid;
		if (mode == 0) url = url + "&mode=1";
		if (mode == 1) url = url + "&mode=7&shopperid="+shopperid;
		url = url + "&userid="+encodeURIComponent(userid.value)+"&password="+encodeURIComponent(password.value)+"&zip="+zip.value+"&email="+email.value+"&fromurl="+encodeURIComponent(fromurl);
		emailsubmitcontainer.innerHTML = "<iframe src=\"" + url + "\"></iframe>";
	}
}

function newAccountUserIdUsed() {
	var userid = getElement("newaccountuserid");
	var password = getElement("newaccountpassword");
	var error = getElement("newaccounterror");
	error.innerHTML = "User Id is used. Please select <u>another</u> User Id";
	userid.focus();
}

function newAccountSummary(userid, password, zip, passphrase) {
	currentActiveContainer = "newshoppercreatedwindow";
	currentActiveHeight = 400;
	currentActiveWidth = 400;	

	var id = getElement("newshoppercreatedid");
	var pwd = getElement("newshoppercreatedpassword");
	var zipcode = getElement("newshoppercreatedzip");
	var phrase = getElement("newshoppercreatedpassphrase");
	var email = getElement("newaccountcreatedemail");
	
	id.innerHTML = userid;
	pwd.value = password;
	zipcode.innerHTML = zip;
	phrase.innerHTML = passphrase;
	email.value = "";
	
	openDialog(currentActiveContainer, currentActiveHeight, currentActiveWidth);

} 

function closeNewShopperCreated(boot) {
	if (boot == null) {
		var objNewAccount = getElement("newshoppercreatedwindow");
		closeDialog(objNewAccount);
	} else {
		window.location.reload();
	}
}

function logOut(sessionid) {
	var url = "web_mitrya/pricemightysubmit.jsp?sid="+sessionid+"&mode=3";
	emailsubmitcontainer.innerHTML = "<iframe src='" + url + "'></iframe>";
}

function continueNewAccount(sessionid, httpsPort, usingURL) {

	var emailInfo = getElement("newaccountcreatedemail");
	var emailerror = getElement("newaccountcreatedemailerror");
	var url = "https://"+window.location.hostname+":"+httpsPort+"/web_mitrya/pricemightysubmit.jsp?sid="+sessionid+"&mode=2";
	if (emailInfo.value.length > 0) {
		var validate = validateEmail(emailInfo.value);
		if (validate.length > 0) {
			emailerror.innerHTML = "Please enter a valid E-Mail address.";
		} else {
			url = url + "&email="+encodeURIComponent(emailInfo.value);
		}
	}
	emailsubmitcontainer.innerHTML = "<iframe src=\"" + url + "\"></iframe>";
	securefollowup(sessionid, 1, usingURL);
}

function clearemailsubmitcontainer() {
	emailsubmitcontainer.innerHTML = "";
}

function clearsecurefollowupcontainer() {
	emailsubmitcontainer.innerHTML = "";
}

function closeLoginShopper() {
	var objNewAccount = getElement("shopperloginwindow");
	closeDialog(objNewAccount);
}

function validateLoginKeyEntry(evt, sessionid, httpsPort, sessionFromURL) {
    evt = (evt) ? evt : event;
    var target = (evt.target) ? evt.target : evt.srcElement;
    var form = target.form;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
    if (charCode == 13 || charCode == 3) {
        validateLogin(sessionid, httpsPort, sessionFromURL);
        return false;
    }
    return true;
}

function checkEnterLogin(e, sessionid, fromurl) { //e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable

	if(e && e.which){ //if which property of event object is supported (NN4)
		e = e
	characterCode = e.which //character code is contained in NN4's which property
	}
	else{
		e = event
		characterCode = e.keyCode //character code is contained in IE's keyCode property
	}

	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		validateLogin(sessionid, fromurl); //submit the form
		return false
	}
	else{
		return true
	}

}

function validateLogin(sessionid, fromurl) {
	var userid = getElement("userid");
	var password = getElement("password");
	var error = getElement("loginerror");
	var fail = 0;
	
	if (userid.value.length == 0) {
		error.innerHTML = "Please enter a valid User Id.";
		userid.className = "inputBoxAlert";
		userid.focus();
		fail = 1;
	} else {
		userid.className = "inputBox";
	}
	if (fail == 0) {
		if (password.value.length == 0) {
			error.innerHTML = "Please enter a valid Password.";
			password.className = "inputBoxAlert";
			password.focus();
			fail = 1;
		} else {
			password.className = "inputBox";
		}
	}
	if (fail == 0) {
		var url = "web_mitrya/pricemightysubmit.jsp?sid="+sessionid+"&mode=4";
		url = url + "&userid="+encodeURIComponent(userid.value)+"&password="+encodeURIComponent(password.value)+"&fromurl="+encodeURIComponent(fromurl);
		emailsubmitcontainer.innerHTML = "<iframe src=\"" + url + "\"></iframe>";	
	}
}

function refreshPage(sessionid) {
	if (location.href.indexOf("listmighty") == -1 && location.href.indexOf("pricemighty") == -1 && location.href.indexOf("pricemightydeals") == -1) {
		if (!cookiesEnabled()) {
			if (location.href.indexOf(sessionid) == -1) {
				location.replace(location.href+";jsessionid="+sessionid);
			} else {
				location.reload();
			}
		} else {
			location.reload();
		}
	} else {
		var url = "/"
		if (location.href.indexOf(sessionid) > -1) {
			url = url+";jsessionid="+sessionid;
		} 
		
		changeParentURL(url);
	}
}

function forcerefreshPage(sessionid) {
	if (!cookiesEnabled()) {
		if (location.href.indexOf(sessionid) == -1) {
			location.replace(location.href+";jsessionid="+sessionid);
		} else {
			location.reload();
		}
	} else {
		location.reload();
	}
}

function noAccountMatch() {
	var userid = getElement("userid");
	var password = getElement("password");
	var error = getElement("loginerror");
	error.innerHTML = "No Account found matching User Id/Password";
	userid.className = "inputBoxAlert";
	password.className = "inputBoxAlert";
	userid.focus();
}

function transitionSession(mode, accountid, url, accountowner) {
	var url = "web_mitrya/transitionsession.jsp?mode="+encodeURIComponent(mode)+"&accountid="+encodeURIComponent(accountid)+"&url="+encodeURIComponent(url)+"&accountowner="+encodeURIComponent(accountowner);
	emailsubmitcontainer.innerHTML = "<iframe src=\"" + url + "\"></iframe>";
}

function changeParentURL(url, sessionid) {
	if (!cookiesEnabled()) {
		if (url.indexOf(sessionid) == -1) {
			url = url+";jsessionid="+sessionid;
		} 
	}
	document.location = url;
}

function loadHTTP(server, url, sessionid) {
	var retVal = "http://";
	retVal += server;
	if (server == "localhost") retVal += ":8080";
	retVal += url;
	retVal += ";jsessionid="+sessionid;
	document.location = retVal;
}
