// $Id: xspHelper.js,v 1.3 2009/12/14 14:13:29 hbr Exp $
	
// Create new pop-up window
function newWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 3;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable';
	setTimeout(
		function(){
			var w = window.open(mypage, myname, winprops);
			w.focus();
		},
	1);
}

// Form manipulation for the profile page
function profileDisableNotificationElements() {
  profileDisableArray(document.getElementsByName("Method"));
  profileDisableArray(document.getElementsByName("NotificationLimit"));
}
function profileDisableArray(array) {
  for (i = 0; i < array.length; i++) {
    array[i].disabled = true;
  }
}

// Reload the whole window
function windowReload() {
	var path = window.location.pathname;
	var qs = window.location.search;
	window.location.replace(path + qs);
	return false;
}

// Send a password reminder to the address defined
function sendPassword(email, lang) {
    var targetURL = "/services/mymarketpulse/send_password_" + lang + ".json?email=" + email;
    
    dojo.style("sendPasswordInfoOKButtonRow", "display", "none");
    dojo.style("sendPasswordInfoBeforeRequest", "display", "");
    dojo.style("sendPasswordInfoAfterRequest", "display", "none");
    dijit.byId("sendPasswordDialog").show();
    dojo.style("sendPasswordInfo", "opacity", 1);
    dojo.style("sendPasswordInfo", "display", "");
    
    // Make a request to the XSP that handles the send password function
    dojo.xhrGet( {
        url: targetURL,
        handleAs: "json-comment-filtered",
        timeout: 20000,

        // If HTTP 200 (successful or "Problem")
        load: function(response, ioArgs) {
                dojo.byId("sendPasswordInfoAfterRequest").innerHTML = response.Message;
			    dojo.style("sendPasswordInfoBeforeRequest", "display", "none");
			    dojo.style("sendPasswordInfoAfterRequest", "display", "");
			    
                // Show button and wait for user
				dojo.style("sendPasswordInfoOKButtonRow", "display", "");
				dijit.byId("sendPasswordInfoOKButton").setDisabled(false);
                return response;
            },
        // HTTP not OK - report error message and wait for user
        error: function(response, ioArgs) {
			dojo.style("sendPasswordInfo", "display", "");
		    dojo.byId("sendPasswordInfoAfterRequest").innerHTML = message;
		    dojo.style("sendPasswordInfoBeforeRequest", "display", "none");
		    dojo.style("sendPasswordInfoAfterRequest", "display", "");
		    dojo.style("sendPasswordInfoOKButtonRow", "display", "");
		    dijit.byId("sendPasswordInfoOKButton").setDisabled(false);
		    dijit.byId("sendPasswordDialog").show();
        	return response;
        }
    });
}
