
var http_request = false;
 
function makePOSTRequest(url, parameters) {
	http_request = false;
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
	 http_request = new XMLHttpRequest();
	 if (http_request.overrideMimeType) {
		// set type accordingly to anticipated content type
		//http_request.overrideMimeType('text/xml');
		http_request.overrideMimeType('text/html');
	 }
	} else if (window.ActiveXObject) { // IE
	 try {
		http_request = new ActiveXObject("Msxml2.XMLHTTP");
	 } catch (e) {
		try {
		   http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e) {}
	 }
	}
	if (!http_request) {
	 alert('Cannot create XMLHTTP instance');
	 return false;
	}

	http_request.onreadystatechange = alertContents;
 
	http_request.open('POST', url, true);
	http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http_request.setRequestHeader("Content-length", parameters.length);
	http_request.setRequestHeader("Connection", "close");
	http_request.send(parameters);
}

function alertContents() {
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {

            var success = false;
            resultResponse = http_request.responseText;

            // json encoded return
		    var myObject = JSON.parse(resultResponse);

            if (myObject.result == true) {
                success = true;
                resultVal = "<strong>Congratulations!</strong><br><br>Your account has been successfully migrated to iReward.";
            }
            else {
                resultVal = myObject.msg;
            }

            useClass = "messageReceived_migrate_small";

            if (resultVal.length > 40) {
                useClass = "messageReceived_migrate_medium";
            }
            else if (resultVal.length > 80) {
                useClass = "messageReceived_migrate_large";
            }

		    document.getElementById('messageReceived_migrate').setAttribute("class", useClass);
		    document.getElementById('messageReceived_migrate').innerHTML = resultVal;
    		
		    $('#popupbox_migrate').fadeIn();
		    $('#closePopup').fadeIn();

		    if (success) 
		    {
		        setTimeout('delayer()', 2000)
		    }
	 } else {
		alert('There was a problem with the request.');
	 }
  }
}

function checkEmail(str) 
{
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	
	if (filter.test(str))
	{
		return true;
	}
	
	return false;
}

function delayer() 
{
    //window.location = "http://steve-pc/mbctrunk/logout/";
    window.location = "http://www.moneybackco.com.au/logout/";
}

function migratetoireward(existing) 
{
	// First check for all fields
    var ireward_username = document.getElementById('ireward_username');
    var ireward_password = document.getElementById('ireward_password');
    var username = document.getElementById('username');
    var firstname = document.getElementById('firstname');
    var lastname = document.getElementById('lastname');
    var email = document.getElementById('email');
    var agree = document.getElementById('agree');
    var gender_male = document.getElementById('gender_male');
    var gender_female = document.getElementById('gender_female');
    var day = document.getElementById('day');
    var month = document.getElementById('month');
    var year = document.getElementById('year');
    var postcode = document.getElementById('postcode');
    var password = document.getElementById('password');
    var errors = false;
    var exiting_ireward = "False";
    var gender = "Male";
    var dob = "";
    
    if (existing) 
    {
        exiting_ireward = "True";
    }
	
	var alertText = "There are errors in the form:<ul>";

	if (existing) {
	
	    if ((ireward_username.value == null) || (ireward_username.value == "")) {
	        errors = true;
	        alertText += "<li>iReward username missing</li>";
	    }

	    if ((ireward_password.value == null) || (ireward_password.value == "")) {
	        errors = true;
	        alertText += "<li>iReward password is missing</li>";
	    }

	    if ((password.value == null) || (password.value == "")) {
	        errors = true;
	        alertText += "<li>Password is missing</li>";
	    }
	    
	    if (agree.checked != 1) {
	        errors = true;
	        alertText += "<li>You need to agree to the T&C's</li>";
	    }
	}
	else {
	
	    if ((ireward_username.value == null) || (ireward_username.value == "")) {
	        errors = true;
	        alertText += "<li>iReward username missing</li>";
	    }

	    if ((firstname.value == null) || (firstname.value == "")) {
	        errors = true;
	        alertText += "<li>First name is missing</li>";
	    }

	    if ((lastname.value == null) || (lastname.value == "")) {
	        errors = true;
	        alertText += "<li>Last name is missing</li>";
	    }

	    if ((email.value == null) || (email.value == "")) {
	        errors = true;
	        alertText += "<li>Email address is missing</li>";
	    }

	    if ((gender_male.checked == false) && (gender_female.checked == false)) {
	        errors = true;
	        alertText += "<li>Please select Gender</li>";
	    }
	    else {
	        if (gender_female.checked) {
	            gender = "Female";
	        }
	    }

	    if ((day.value == null) || (day.value == "") || (day.value == "Day") || (month.value == null) || (month.value == "") || (month.value == "Month") || (year.value == null) || (year.value == "") || (year.value == "Year")) {
	        errors = true;
	        alertText += "<li>Please select Date of Birth</li>";
	    }
	    else {
	        dob = day.value + "/" + month.value + "/" + year.value;
	    }

	    if ((postcode.value == null) || (postcode.value == "")) {
	        errors = true;
	        alertText += "<li>Postcode is missing</li>";
	    }

	    if ((password.value == null) || (password.value == "")) {
	        errors = true;
	        alertText += "<li>Password is missing</li>";
	    }

	    if (agree.checked != 1) {
	        errors = true;
	        alertText += "<li>You need to agree to the T&C's</li>";
	    }

	}

	alertText += "</ul>";
	
	var messageReceived = "<br>Processing...Please wait";
	
	if (errors)
	{
		messageReceived = alertText;
	}
	else
	{
		var parameters;

		if (existing == false) {
		    parameters = '&existing=' + exiting_ireward
		                + '&ir_username=' + ireward_username.value
		                + '&ir_firstname=' + firstname.value
		                + '&ir_lastname=' + lastname.value
		                + '&ir_email=' + email.value
		                + '&ir_gender=' + gender
		                + '&ir_dob=' + dob
		                + '&ir_postcode=' + postcode.value
		                + '&ir_agree=yes'
		                + '&mbc_username=' + username.value
		                + '&mbc_ir_password=' + password.value;
		}
		else {
		    parameters = '&existing=' + exiting_ireward
		                + '&ir_username=' + ireward_username.value
		                + '&ir_password=' + ireward_password.value
		                + '&mbc_username=' + username.value
		                + '&mbc_ir_password=' + password.value
		                
		}
		
		var url = "http://www.moneybackco.com.au/ireward_migration_ajax.php";
		//var url = "http://steve-pc/mbctrunk/ireward_migration_ajax.php";
		
		makePOSTRequest(url, parameters);
	}
	
	// call jquery post method here to pass variables to the server---
	// display the message returned in div
	var useClass = "messageReceived_migrate_small";
	
	if (messageReceived.length > 100)
	{
		useClass = "messageReceived_migrate_medium";
	}
	
	if (messageReceived.length > 300)
	{
		useClass = "messageReceived_migrate_large";
	}
	
	document.getElementById('messageReceived_migrate').setAttribute("class", useClass);
	document.getElementById('messageReceived_migrate').innerHTML = messageReceived;
	$('#popupbox_migrate').fadeIn();
	$('#closePopup').fadeIn();
}

function showForm(existing, closebutton, username, firstname, lastname, email, migratebutton, cancellink, cancelbutton) {
    var html = '<table width="100%">';
	
	if (existing)
	{
        //html += '	<table>';
        html += '		<tr>';
        html += '			<td class="home-page-main">';
        html += '			<p><h4 style="color: #0b5d86;">2. Please enter your iReward credentials, below, in order to migrate your account:</h4></p>';
        html += '			</td>';
        html += '		</tr>';
        html += '		<tr>';
        html += '			<td class="home-page-main">';
        html += '			<div id="overlay_migrate">';
        html += '				<div id="popupbox_migrate" style="display:none">';
        html += '					<a id="closePopup" onclick="$(\'#popupbox_migrate\').fadeOut();$(\'#closePopup\').fadeOut();"><img border=0 src="' + closebutton + '" /></a><span class="messageReceived_migrate_small" id="messageReceived_migrate">You have been Subscribed</span>	</div>';
        html += '				</div>';
        html += '			</div>';
        html += '				<input type="hidden" name="username" id="username" value="' + username + '" />';
        html += '					<table width="100%">';
        html += '						<tr>';
        html += '							<td width="60%">';
        html += '								iReward username:';
        html += '							</td>';
        html += '							<td>';
        html += '								<input class=shadeform type="text" size="40" maxlength="50" id="ireward_username" name="ireward_username" />';
        html += '							</td>';
        html += '						</tr>';
        html += '						<tr>';
        html += '							<td colspan="2">';
        html += '								<br>';
        html += '						</td>';
        html += '						</tr>';
        html += '						<tr>';
        html += '							<td width="60%">';
        html += '								iReward password:';
        html += '							</td>';
        html += '							<td>';
        html += '								<input class=shadeform type="password" size="40" maxlength="50" id="ireward_password" name="ireward_password" />';
        html += '							</td>';
        html += '						</tr>';
        html += '						<tr>';
        html += '							<td colspan="2">';
        html += '								<br>';
        html += '							</td>';
        html += '						</tr>';
        html += '						<tr>';
        html += '							<td width="60%">';
        html += '								Please enter your existing MBC password to confirm account migration:';
        html += '							</td>';
        html += '							<td>';
        html += '								<input class=shadeform type="password" size="40" maxlength="50" id="password" name="password" />';
        html += '							</td>';
        html += '						</tr>';
        html += '						<tr>';
        html += '							<td colspan="2">';
        html += '								<br>';
        html += '							</td>';
        html += '						</tr>';
        html += '						<tr>';
        html += '							<td colpsan="2">';
        html += '								<input class=shadeform type="checkbox" name="agreecheck" value="agree" id="agree"> I agree to the iReward-MBC <a href="http://www.moneybackco.com.au/ireward-mbc-policy/" onclick="window.open(\'http://www.moneybackco.com.au/ireward-mbc-policy/\',\'popup\',\'width=1000,height=500,scrollbars=yes,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0\'); return false">Migration Policy</a>.';
        html += '							</td>';
        html += '						</tr>';
        html += '						<tr>';
        html += '							<td colspan="2">';
        html += '								<br>';
        html += '							</td>';
        html += '						</tr>';
        html += '						<tr>';
        html += '							<td colspan="2" style="text-align:center;">';
        html += '								<input type="image" onclick="migratetoireward(true)" id="migrateBtn" src="' + migratebutton + '" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="' + cancellink + '"><img border=0 src="' + cancelbutton + '" /></a>';
        html += '							</td>';
        html += '						</tr>';
        html += '					</table>';
        //html += '				</td>';
        //html += '			</tr>';
        //html += '		</table>';
	}
	else
	{
	    //html += '	<table>';
	    html += '<tr>';
			html += '<td class="home-page-main">';
			html += '<p><h4 style="color: #0b5d86;">2. Please complete the following details below, all fields are mandatory unless otherwise stated:</h4></p>';
			html += '</td>';
		html += '</tr>';
		html += '<tr>';
			html += '<td class="home-page-main">';
				html += '<div id="overlay_migrate">';
					html += '<div id="popupbox_migrate" style="display:none">';
						html += '<a id="closePopup" onclick="$(\'#popupbox_migrate\').fadeOut();$(\'#closePopup\').fadeOut();"><img border=0 src="' + closebutton + '" /></a><span class="messageReceived_migrate_small" id="messageReceived_migrate">You have been Subscribed</span>	</div>';
		html += '';
					html += '</div>';
				html += '</div>';
					html += '<input type="hidden" name="username" id="username" value="' + username + '" />';
					html += '<table width="100%">';
						html += '<tr>';
							html += '<td width="60%">';
								html += 'Choose a username for iReward (6 - 25 characters):';
							html += '</td>';
							html += '<td>';
								html += '<input class=shadeform type="text" value="' + username + '" size="40" maxlength="50" name="ireward_username" id="ireward_username"  />';
							html += '</td>';
						html += '</tr>';
						html += '<tr>';
							html += '<td colspan="2">';
								html += '<br>';
							html += '</td>';
						html += '</tr>';
						html += '<tr>';
							html += '<td width="60%">';
								html += 'Your first name which will be used to create your iReward account:';
							html += '</td>';
							html += '<td>';
								html += '<input READONLY class=shadeform type="text" value="' + firstname + '" size="40" maxlength="50" name="firstname"  id="firstname"/>';
							html += '</td>';
						html += '</tr>';
						html += '<tr>';
							html += '<td colspan="2">';
								html += '<br>';
							html += '</td>';
						html += '</tr>';
						html += '<tr>';
							html += '<td width="60%">';
								html += 'Your last name which will be used to create your iReward account:';
							html += '</td>';
							html += '<td>';
								html += '<input READONLY class=shadeform type="text" value="' + lastname + '" size="40" maxlength="50" name="lastname"  id="lastname"/>';
							html += '</td>';
						html += '</tr>';
						html += '<tr>';
							html += '<td colspan="2">';
								html += '<br>';
							html += '</td>';
						html += '</tr>';
						html += '<tr>';
							html += '<td width="60%">';
								html += 'Your email address which will be used to create your iReward account:';
							html += '</td>';
							html += '<td>';
								html += '<input READONLY class=shadeform type="text" value="' + email + '" size="40" maxlength="50" name="email"  id="email"/>';
							html += '</td>';
						html += '</tr>';
						html += '<tr>';
							html += '<td colspan="2">';
								html += '<br>';
							html += '</td>';
						html += '</tr>';
						html += '<tr>';
							html += '<td width="60%">';
								html += 'Please indicate your gender:';
							html += '</td>';
							html += '<td>';
								html += '<input type="radio" name="gender" value="Male" id="gender_male"> Male <input type="radio" name="gender" value="Female" id="gender_female"> Female';
							html += '</td>';
						html += '</tr>';
						html += '<tr>';
							html += '<td colspan="2">';
								html += '<br>';
							html += '</td>';
						html += '</tr>';
						html += '<tr>';
							html += '<td width="60%">';
								html += 'Please enter your Date of Birth:';
							html += '</td>';
							html += '<td>';
								html += '<select id="day" name="Day">';
									html += '<option value="">Day</option> ';
									html += '<option value="1">1</option> ';
									html += '<option value="2">2</option> ';
									html += '<option value="3">3</option> ';
									html += '<option value="4">4</option> ';
									html += '<option value="5">5</option> ';
									html += '<option value="6">6</option> ';
									html += '<option value="7">7</option> ';
									html += '<option value="8">8</option> ';
									html += '<option value="9">9</option> ';
									html += '<option value="10">10</option> ';
									html += '<option value="11">11</option> ';
									html += '<option value="12">12</option> ';
									html += '<option value="13">13</option> ';
									html += '<option value="14">14</option> ';
									html += '<option value="15">15</option> ';
									html += '<option value="16">16</option> ';
									html += '<option value="17">17</option> ';
									html += '<option value="18">18</option> ';
									html += '<option value="19">19</option> ';
									html += '<option value="20">20</option> ';
									html += '<option value="21">21</option> ';
									html += '<option value="22">22</option> ';
									html += '<option value="23">23</option> ';
									html += '<option value="24">24</option> ';
									html += '<option value="25">25</option> ';
									html += '<option value="26">26</option> ';
									html += '<option value="27">27</option> ';
									html += '<option value="28">28</option> ';
									html += '<option value="29">29</option> ';
									html += '<option value="30">30</option> ';
									html += '<option value="31">31</option> ';
								html += '</select>';
								html += '<select id="month" name="Month">';
									html += '<option value="">Month</option> ';
									html += '<option value="1">1</option> ';
									html += '<option value="2">2</option> ';
									html += '<option value="3">3</option> ';
									html += '<option value="4">4</option> ';
									html += '<option value="5">5</option> ';
									html += '<option value="6">6</option> ';
									html += '<option value="7">7</option> ';
									html += '<option value="8">8</option> ';
									html += '<option value="9">9</option> ';
									html += '<option value="10">10</option> ';
									html += '<option value="11">11</option> ';
									html += '<option value="12">12</option> ';
								html += '</select>';
								html += '<select id="year" name="Year">';
									html += '<option value="">Year</option> ';
									html += '<option value="2010">2010</option> ';
									html += '<option value="2009">2009</option> ';
									html += '<option value="2008">2008</option> ';
									html += '<option value="2007">2007</option> ';
									html += '<option value="2006">2006</option> ';
									html += '<option value="2005">2005</option> ';
									html += '<option value="2004">2004</option> ';
									html += '<option value="2003">2003</option> ';
									html += '<option value="2002">2002</option> ';
									html += '<option value="2001">2001</option> ';
									html += '<option value="2000">2000</option> ';
									html += '<option value="1999">1999</option> ';
									html += '<option value="1998">1998</option> ';
									html += '<option value="1997">1997</option> ';
									html += '<option value="1996">1996</option> ';
									html += '<option value="1995">1995</option> ';
									html += '<option value="1994">1994</option> ';
									html += '<option value="1993">1993</option> ';
									html += '<option value="1992">1992</option> ';
									html += '<option value="1991">1991</option> ';
									html += '<option value="1990">1990</option> ';
									html += '<option value="1989">1989</option> ';
									html += '<option value="1988">1988</option> ';
									html += '<option value="1987">1987</option> ';
									html += '<option value="1986">1986</option> ';
									html += '<option value="1985">1985</option> ';
									html += '<option value="1984">1984</option> ';
									html += '<option value="1983">1983</option> ';
									html += '<option value="1982">1982</option> ';
									html += '<option value="1981">1981</option> ';
									html += '<option value="1980">1980</option> ';
									html += '<option value="1979">1979</option> ';
									html += '<option value="1978">1978</option> ';
									html += '<option value="1977">1977</option> ';
									html += '<option value="1976">1976</option> ';
									html += '<option value="1975">1975</option> ';
									html += '<option value="1974">1974</option> ';
									html += '<option value="1973">1973</option> ';
									html += '<option value="1972">1972</option> ';
									html += '<option value="1971">1971</option> ';
									html += '<option value="1970">1970</option> ';
									html += '<option value="1969">1969</option> ';
									html += '<option value="1968">1968</option> ';
									html += '<option value="1967">1967</option> ';
									html += '<option value="1966">1966</option> ';
									html += '<option value="1965">1965</option> ';
									html += '<option value="1964">1964</option> ';
									html += '<option value="1963">1963</option> ';
									html += '<option value="1962">1962</option> ';
									html += '<option value="1961">1961</option> ';
									html += '<option value="1960">1960</option> ';
									html += '<option value="1959">1959</option> ';
									html += '<option value="1958">1958</option> ';
									html += '<option value="1957">1957</option> ';
									html += '<option value="1956">1956</option> ';
									html += '<option value="1955">1955</option> ';
									html += '<option value="1954">1954</option> ';
									html += '<option value="1953">1953</option> ';
									html += '<option value="1952">1952</option> ';
									html += '<option value="1951">1951</option> ';
									html += '<option value="1950">1950</option> ';
									html += '<option value="1949">1949</option> ';
									html += '<option value="1948">1948</option> ';
									html += '<option value="1947">1947</option> ';
									html += '<option value="1946">1946</option> ';
									html += '<option value="1945">1945</option> ';
									html += '<option value="1944">1944</option> ';
									html += '<option value="1943">1943</option> ';
									html += '<option value="1942">1942</option> ';
									html += '<option value="1941">1941</option> ';
									html += '<option value="1940">1940</option> ';
									html += '<option value="1939">1939</option> ';
									html += '<option value="1938">1938</option> ';
									html += '<option value="1937">1937</option> ';
									html += '<option value="1936">1936</option> ';
									html += '<option value="1935">1935</option> ';
									html += '<option value="1934">1934</option> ';
									html += '<option value="1933">1933</option> ';
									html += '<option value="1932">1932</option> ';
									html += '<option value="1931">1931</option> ';
									html += '<option value="1930">1930</option> ';
									html += '<option value="1929">1929</option> ';
									html += '<option value="1928">1928</option> ';
									html += '<option value="1927">1927</option> ';
									html += '<option value="1926">1926</option> ';
									html += '<option value="1925">1925</option> ';
									html += '<option value="1924">1924</option> ';
									html += '<option value="1923">1923</option> ';
									html += '<option value="1922">1922</option> ';
									html += '<option value="1921">1921</option> ';
									html += '<option value="1920">1920</option> ';
									html += '<option value="1919">1919</option> ';
									html += '<option value="1918">1918</option> ';
									html += '<option value="1917">1917</option> ';
									html += '<option value="1916">1916</option> ';
									html += '<option value="1915">1915</option> ';
									html += '<option value="1914">1914</option> ';
									html += '<option value="1913">1913</option> ';
									html += '<option value="1912">1912</option> ';
									html += '<option value="1911">1911</option> ';
									html += '<option value="1910">1910</option> ';
									html += '<option value="1909">1909</option> ';
									html += '<option value="1908">1908</option> ';
									html += '<option value="1907">1907</option> ';
									html += '<option value="1906">1906</option> ';
									html += '<option value="1905">1905</option> ';
									html += '<option value="1904">1904</option> ';
									html += '<option value="1903">1903</option> ';
									html += '<option value="1902">1902</option> ';
									html += '<option value="1901">1901</option> ';
									html += '<option value="1900">1900</option> ';
								html += '</select>';
							html += '</td>';
						html += '</tr>';
						html += '<tr>';
							html += '<td colspan="2">';
								html += '<br>';
							html += '</td>';
						html += '</tr>';
						html += '<tr>';
							html += '<td width="60%">';
								html += 'Please enter your postcode:';
							html += '</td>';
							html += '<td>';
								html += '<input class=shadeform type="text" size="40" maxlength="50" name="postcode"  id="postcode"/>';
							html += '</td>';
						html += '</tr>';
						html += '<tr>';
							html += '<td colspan="2">';
								html += '<br>';
							html += '</td>';
						html += '</tr>';
						html += '<tr>';
							html += '<td width="60%">';
								html += 'Please enter your existing MBC password to confirm account migration, this will also be your iReward password, which you can change via the iReward control panel if required:';
							html += '</td>';
							html += '<td>';
								html += '<input class=shadeform type="password" size="40" maxlength="50" name="password" id="password"/>';
							html += '</td>';
						html += '</tr>';
						html += '<tr>';
							html += '<td colspan="2">';
								html += '<br>';
							html += '</td>';
						html += '</tr>';
						html += '<tr>';
							html += '<td colpsan="2">';
								html += '<input class=shadeform type="checkbox" name="agreecheck" value="agree" id="agree"> I agree to the iReward <a href="http://www.ireward.com.au/Privacy" onclick="window.open(\'http://www.ireward.com.au/Privacy\',\'popup\',\'width=800,height=500,scrollbars=yes,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0\'); return false">Privacy Protection Policy</a>, iReward <a href="http://www.ireward.com.au/Terms" onclick="window.open(\'http://www.ireward.com.au/Terms\',\'popup\',\'width=800,height=500,scrollbars=yes,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0\'); return false">Terms of Use</a> and the iReward-MBC <a href="http://www.moneybackco.com.au/ireward-mbc-policy/" onclick="window.open(\'http://www.moneybackco.com.au/ireward-mbc-policy/\',\'popup\',\'width=1000,height=500,scrollbars=yes,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0\'); return false">Migration Policy</a>.';
							html += '</td>';
						html += '</tr>';
						html += '<tr>';
							html += '<td colspan="2">';
								html += '<br>';
							html += '</td>';
						html += '</tr>';
						html += '<tr>';
							html += '<td colspan="2" style="text-align:center;">';
								html += '<input type="image" onclick="migratetoireward(false)" value="Migrate account" id="migrateBtn" src="' + migratebutton + '" />';
								html += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
								html += '<a href="' + cancellink + '"><img border=0 src="' + cancelbutton + '" /></a>';
							html += '</td>';
						html += '</tr>';
					html += '</table>';
			html += '</td>';
		html += '</tr>';
	}
	
	html += '</td></tr></table>';
	
	document.getElementById('migrate-form').innerHTML = html;
}

function showJoinForm(firsttimeshow, joinlink, firstnamecolour, firstname, lastnamecolour, lastname, emailcolour, email, confirmemailcolour, confirmemail, usernamecolour, username, 
                      passwordcolour, confirmpasswordcolour, referreremailcolour, referreremail, newslettercolour, newslettermodifier, agreecolour, refid, termslink, joinbutton) {

    var html = '';
    html += '<form action="' + joinlink + '" method="post" ID="Form1">';
    html += '<table width="100%">';

	html += '<tr><td colspan=2 class="home-page-main">';

	if (firsttimeshow)
	{
		html += 'To start earning when you shop join us today! ';
	}
	
	html += 'echo "All fields are mandatory unless stated otherwise.';
	
	html += '</td></tr>';
	
	html += '<tr>';
	html +=	'<td align=left width=20% class="home-page-main">';
	html += '	<span style="color: ' + firstnamecolour + '"> First name: </span>';
	html +=	'</td>';
	html +=	'<td align=left class="home-page-main"> ';
	html +=	'	<input class=shadeform type="text" value="' + firstname + '" size="40" maxlength="50" name="firstname" ID="Text4">';
	html +=	'</td>';
	html += '</tr>';
	html += '<tr>';
	html +=	'<td align=left width=20% class="home-page-main">';
	html +=	'	<span style="color: ' + lastnamecolour + '">Last name: </span>';
	html +=	'</td>';
	html +=	'<td align=left class="home-page-main"> ';
	html +=	'	<input class=shadeform type="text" value="' + lastname + '" size="40" maxlength="50" name="lastname" ID="Text3">';
	html +=	'</td>';
	html += '</tr>';
	html += '<tr><td><br></td></tr>';
	html += '<tr>';
	html +=	'<td align=left width=20% class="home-page-main">';
	html +=	'	<span style="color:' + emailcolour + '">Email address: </span>';
	html +=	'</td>';
	html +=	'<td align=left class="home-page-main"> ';
	html +=	'	<input class=shadeform type="text" value="' + email + '" size="40" maxlength="50" name="email" ID="Text5">';
	html +=	'</td>';
	html += '</tr>';
	html += '<tr>';
	html +=	'<td align=left width=20% class="home-page-main">';
	html +=	'	<span style="color:' + confirmemailcolour + '">Confirm email address: </span>';
	html +=	'</td>';
	html +=	'<td align=left class="home-page-main"> ';
	html +=	'	<input class=shadeform type="text" value="' + confirmemail + '" size="40" maxlength="50" name="confirmemail" ID="Text6">';
	html +=	'</td>';
	html += '</tr>';
	html += '<tr><td><br></td></tr>';
	html += '<tr>';
	html +=	'<td align=left width=20% class="home-page-main">';
	html +=	'	<span style="color:' + usernamecolour + '">Username: </span>';
	html +=	'</td>';
	html +=	'<td align=left class="home-page-main"> ';
	html +=	'	<input class=shadeform type="text" value="' + username + '" size="40" maxlength="50" name="username" ID="Text7">';
	html +=	'</td>';
	html += '</tr>';
	html += '<tr>';
	html +=	'<td align=left width=20% class="home-page-main">';
	html +=	'	<span style="color:' + passwordcolour + '">Password: </span>';
	html +=	'</td>';
	html +=	'<td align=left class="home-page-main"> ';
	html +=	'	<input class=shadeform type="password" size="40" maxlength="50" name="password" ID="Password1">';
	html +=	'</td>';
	html += '</tr>';
	html += '<tr>';
	html +=	'<td align=left width=20% class="home-page-main">';
	html +=	'	<span style="color:' + confirmpasswordcolour + '">Confirm password: </span>';
	html +=	'</td>';
	html +=	'<td align=left class="home-page-main"> ';
	html +=	'	<input class=shadeform type="password" size="40" maxlength="50" name="confirmpassword" ID="Password2">';
	html +=	'</td>';
	html += '</tr>';
	html += '<tr><td><br></td></tr>';
	html += '<tr>';
	html +=	'<td align=left width=20% class="home-page-main">';
	html +=	'	<span style="color:' + referreremailcolour + '">Referrer email address (optional): </span>';
	html +=	'</td>';
	html +=	'<td align=left class="home-page-main"> ';
	html +=	'	<input class=shadeform type="text" value="' + referreremail + '" size="40" maxlength="50" name="referreremail" ID="Text8">';
	html +=	'</td>';
	html += '</tr>';
	html += '<tr><td><br></td></tr>';
	html += '<tr>';
	html +=	'<td align=left width=20% class="home-page-main">';
	html +=	'	<span style="color:' + newslettercolour + '"><input ' + newslettermodifier + ' class=shadeform type="checkbox" name="newsletter" value="yes"> Newsletter subscription (optional): </span>';
	html +=	'</td>';
	html +=	'<td class="home-page-main">';
	html +=	'	 <span>Don\'t miss out on the latest cashback offers, exclusive sales, discount coupon codes and member competitions. <strong>Uncheck</strong> if you <strong>don\'t</strong> want to recieve our weekly newsletter.</span>';
	html +=	'</td>';
	html += '</tr>';
	html += '<tr><td><br></td></tr>';
	html += '<tr>';
	html +=	'<td colspan=2 class="home-page-main">';
	html +=	'	<input class=shadeform type="checkbox" name="agreecheck" value="agree"> <span style="color:' + agreecolour + '">I confirm I have read, understand and agree to the <a href="' + termslink + '" onclick="window.open(\'' + termslink + '\',\'popup\',\'width=1000,height=500,scrollbars=yes,resizable=yes,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0\'); return false">Terms and Conditions</a> of Moneybackco.</span>';
	html +=	'</td>';
	html += '</tr>';
	html += '<tr><td></td></tr>';
	html += '<tr>';
	html +=	'<td align=left width=100% class="home-page-main">';
	html +=	'	<input type="hidden" value="' + refid + '" name="refid">';
	html +=	'	<input type="image" style="border:0" src="' + joinbutton + '" name="registersubmit" value="register" title="Join now" alt="Join" ID="Image2">';
	html += '</td>';
	html += '</tr>';



    html += '</table>';
    html += '</form>';

    document.getElementById('join-form').innerHTML = html;

}
