// JavaScript Document


if (window != top) top.location.href = location.href;

function DisplayWholesaleProfileInBody(sender)
{
	window.location.href="?Nav=Profile";
}


function LogoutWholesaleForm(sender)
{
	new Ajax.Request('/inc/ajax/wholesale_ajax.php', {
		method: 'post',
		parameters: {
			action: 'wholesaleLogout'
		},
			onSuccess: function (r) {
			
			}
	});
}

function SubmitWholesaleForm(sender)
{
	var errors = "";
	/*var loading = '<img src="/images/loading_30_6.gif" alt="Loading..." />';*/
	
	if ($("username").value == "") errors += " - Missing Username\n";
	if ($("loginPassword").value == "") errors += " - Missing Password\n";
	
	if (errors != "")
	{
		alert("You need to fill in some fields:\n"+errors);
		return false;
	}
	else if(errors == "")
	{
		$("wholesaleLoginResponse").innerHTML = "<p class='wholesalerLoginTxt'>Please wait while we check<br />if you are listed";
		
		new Ajax.Request('/inc/ajax/wholesale_ajax.php', {
			method: 'post',
			parameters: {
				action: 'wholesaleLoginCheck',
				username: $("username").value,
				password: $("loginPassword").value
			},
			onSuccess: function (r) {
				if(r.responseText == "1")
				{
					$("wholesaleLoginSuccess").name = "wholesaleLoginSuccess";
					$("wholesaleLoginResponse").innerHTML = "<p class='wholesalerLoginTxt'>We found you, logging in now";
					$("wholesaleLoginForm").submit();
					/*Redirect to Online Store*/
					window.location.href = "/?Nav=Pdt&PageID=14&wp=14";
				}
				else
				{
					$("wholesaleLoginResponse").innerHTML = "<p class='wholesalerLoginTxt'>Sorry. Your Account is Not Activated Or Not Avaiable";
				}
			}
		});
	}
}

function regPostAddress(sender)
{
	if(sender.checked == true)
	{
		$("postalStreetAddress").value = $("streetAddress").value;
		$("postalSubAddress").value = $("subAddress").value;
		$("postalPostcode").value = $("postcode").value;
	}
	else
	{
		$("postalStreetAddress").value = "";
		$("postalSubAddress").value = "";
		$("postalPostcode").value = "";
	}
}
function wholesaleLogout()
{
	new Ajax.Request('/inc/ajax/wholesale_ajax.php', {
		method: 'post',
		parameters: {
			action: 'wholesaleLogout'
		},
		onSuccess: function (r) {
			window.location = r.responseText;
		}
	});
	return true;
}
