PasswordRequest=function(){}

PasswordRequest.prototype.Render = function(container)
{
    var obj = 'passwordRequest',
		firstName = new TextBox(obj + 'Firstname', 'First Name', null, null, null, true),
		lastName = new TextBox(obj + 'Lastname', 'Last Name', null, null, null, true),
		phone = new PhoneBox(obj + 'Phone', 'Phone', null, null, null, true),
		company = new TextBox(obj + 'Company', 'Company Name', null, null, null, true),
		companyFax = new FaxBox(obj + 'Fax', 'Company Fax (optional)'),
		email = new EmailBox(obj + 'Email', 'E-mail', null, null, null, true),
		sendButton = document.createElement('<input type="button">'),
		cancelButton = document.createElement('<input type="button">'),
		modalBack = document.createElement('div'),
		request = document.createElement('table');

    request.id = 'passwordRequest';
    request.className = 'passwordRequest';
    request.style.width = '400px';

    modalBack.id = request.id + '_modalBack';
    modalBack.className = 'passwordRequest_background';

    sendButton.value = 'Send';
    sendButton.onclick = '__passwordRequest_Send();';
    cancelButton.value = 'Cancel';
    cancelButton.onclick = '$getControl(\'' + modalBack.id + '\').style.visibility=\'hidden\';$getControl(\'' + request.id + '\').style.visibility=\'hidden\';'
    sendButton.className = cancelButton.className = 'passwordRequest_button';

    var title = request.insertRow().insertCell();
    title.className = 'passwordRequest_title';
    title.innerHTML = 'Request a New User Name and Password';
    request.insertRow().insertCell().appendChild(firstName.Render());
    request.insertRow().insertCell().appendChild(lastName.Render());
    request.insertRow().insertCell().appendChild(phone.Render());
    request.insertRow().insertCell().appendChild(company.Render());
    request.insertRow().insertCell().appendChild(companyFax.Render());
    request.insertRow().insertCell().appendChild(email.Render());

    var buttons = document.createElement("<table>")
    row = buttons.insertRow();
    row.insertCell().appendChild(sendButton);
    row.insertCell().appendChild(cancelButton);
    var buttonCell = request.insertRow().insertCell();
    buttonCell.colSpan = 2;
    buttonCell.appendChild(buttons);

    if (container)
    {
        if (typeof container != 'object')
            container = $getControl(container);
        container.appendChild(modalBack);
        container.appendChild(request);
        firstName.AddEvents();
        lastName.AddEvents();
        phone.AddEvents();
        company.AddEvents();
        companyFax.AddEvents();
        email.AddEvents();
        new Event('onclick').AddToElement(cancelButton, cancelButton.onclick + 'document.body.removeChild($getControl(\'' + modalBack.id + '\'));document.body.removeChild($getControl(\'' + request.id + '\'));');
        new Event('onclick').AddToElement(sendButton, sendButton.onclick);
    }
    return request;
}

__passwordRequest_Send = function()
{
    var obj = 'passwordRequest',
		first = new TextBox(obj + 'Firstname'),
		last = new TextBox(obj + 'Lastname'),
		phone = new PhoneBox(obj + 'Phone'),
		company = new TextBox(obj + 'Company'),
		fax = new FaxBox(obj + 'Fax'),
		email = new EmailBox(obj + 'Email');

    if (first.IsValid() && last.IsValid() && phone.IsValid() && company.IsValid() && fax.IsValid() && email.IsValid())
        PageMethods.SendPasswordRequest(first.Text, last.Text, phone.Text, company.Text, fax.Text, email.Text, "info@alberta1call.com", __passwordRequest_onComplete, __passwordRequest_onError);
    else
        alert('Some of the fields are invalid. Hover your mouse over the error marks (X) to see what\'s wrong.');
}

__passwordRequest_onComplete = function(result, response, method)
{
    alert('Your User Name and temporary password will be emailed to the address you provide within 3 business days');
    document.body.removeChild($getControl('passwordRequest'));
    document.body.removeChild($getControl('passwordRequest_modalBack'));
}

__passwordRequest_onError = function(error, response, method)
{
    if (error) alert(error.get_message());
}

///<UnitTests>
try
{
	if(__JSUnit_version>0)
	{
		
		__jsUnit.AddTest('PasswordRequest','Render','Display the password request box.','positive',
			function()
			{
				var 	actual=new PasswordRequest('Your User Name and temporary password will be emailed to the address you provide within 3 business days').Render().outerHTML.replace(/[\r\n]/g,''),
						expected='';
				
				return new JSUnitTestResult(actual,expected,true);
			});
	}
}
catch(err){}
///</UnitTests>
