// This file holds the JavaScripts that will be used on the site.

// Open a new window.
var newWindow;
function win(url) {
	newwindow=window.open(url,'name','resizable=yes, screenx=700. screeny=50, right=-700, top=50, height=500,width=580');
	newWindow.focus()
}

function printwin(url) {
	newwindow=window.open(url,'Promotion Testing Application','resizable=yes, screenx=700. screeny=50, right=-700, top=50, scrollbars=yes');
	newWindow.focus()
}

// Count the number of text type in a text area.
function textCounter(field, countfield, maxlimit) {
/*
* The input parameters are: the field name;
* field that holds the number of characters remaining;
* the max. numb. of characters.
*/
	if (field.value.length > maxlimit) // if the current length is more than allowed
		field.value =field.value.substring(0, maxlimit); // don't allow further input
	else
		countfield.value = maxlimit - field.value.length; // set the display field to remaining number
}

function CheckData(form) {

	if(form.username.value.length <= 0) {
		alert("Enter a username.");
		form.username.value = "*** Username";
		form.username.focus();
		var problem = true;
	}

	if(form.first.value.length <= 0) {
		alert("Enter your first name.");
		form.first.value = "*** First Name";
		form.first.focus();
		var problem = true;
	}

	if(form.last.value.length <= 0) {
		alert("Enter your last name");
		form.last.value = "*** Last Name";
		form.last.focus();
		var problem = true;
	}

	if(form.email.value.length <= 0) {
		alert("Enter your email address.");
		form.email.value = "*** Email Address";
		form.email.focus();
		var problem = true;
	}

	if(form.pass1.value.length < 8) {
		alert("Enter a password at least 8 charaters long.");
		var problem = true;
	}

	if(form.pass1.value != form.pass2.value) {
		alert("Your confirmed password does not match the entered password.");
		var problem = true;
	}

	if(problem == true) {
		return false;
	} else {
		return true;
	}

}


// check login information
function CheckLogin(form) {

	if(form.first.value.length <= 0) {
		alert("Enter your first name.");
		form.first.value = "*** First Name";
		form.first.focus();
		var problem = true;
	}

	if(form.last.value.length <= 0) {
		alert("Enter your last name");
		form.last.value = "*** Last Name";
		form.last.focus();
		var problem = true;
	}

	if(form.email.value.length <= 0) {
		alert("Enter your email address.");
		form.email.value = "*** Email Address";
		form.email.focus();
		var problem = true;
	}

	if(form.email.value != form.conferm_email.value) {
		alert("Your confirmed email does not match the entered email.");
		var problem = true;
	}

	if(form.address.value.length <= 0) {
		alert("Enter a numeric address.");
		var problem = true;
	}

	if(problem == true) {
		return false;
	} else {
		return true;
	}

}
