function popUp(url, w, h)
{
	newWin=open(url, "win", 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,copyhistory=yes,width='+w+',height='+h+'');
	newWin.focus();
}

function justChar(myString) {
	var outString = "" + myString;
	var got = "";

	for (var j=0; j<myString.length; j++) {
		if (outString.charAt(j) == " ") {
			got += '';
		}
		else {
			got += outString.substring(j, j+1);
		}
	}

	return (got);
}

function checkClientContact(myForm) {
	var companyCode;
	var charRegExp = new RegExp("[^A-z]", "g");

	if (myForm.companyname) {
		companyCode = justChar(myForm.code.value);
		if ((companyCode.length < 3) || charRegExp.test(companyCode)) {
			alert ("The company code must be three (3) letters.");
			myForm.code.focus();
			myForm.code.select();
			return false;
		}

		if (myForm.country.value.toUpperCase() == "CANADA") {
			charRegExp = new RegExp("[A-z][0-9][A-z][0-9][A-z][0-9]");
			postalCode = justChar(myForm.postalcode.value);
			if (charRegExp.test(postalCode) == false) 	{
				alert ("Please enter a valid Canadian postal code.");
				myForm.postalcode.focus();
				myForm.postalcode.select();
				return false;
			}
			else {
				myForm.postalcode.value = postalCode.substring(0, 3) + " " + postalCode.substring(3, 6);
			}

		}
	}

	return true;
}

function setFocus() {
	if (document.frmLogin) {
		document.frmLogin.username.focus();
	}
  
  if (document.frmForgot) {
    document.frmForgot.txtEmail.focus();
  }
}


function beforeDelete(myForm, myField)
{
	var i, ok;
	var x;
	var deleteItemCount;

	myForm = eval(myForm);

	if (myForm.elements[myField][0] == null) {	// In case we only get on record.

		if (eval("myForm." + myField + ".checked") == true)
		{
			ok = confirm("Are you sure you want to delete 1 item?");
			if (ok == true) {
				// submit form here.
				myForm.submit();
			}
			else {
				eval("myForm." + myField + ".checked = false");
				return false;
			}
		}
	}

	else {

		deleteItemCount = 0;

		for (i=0; x=myForm.elements[myField][i], x!=null; i++)
		{
			if (x.checked == true) {
				deleteItemCount++;
			}
		} // End of FOR loop

		if (deleteItemCount > 0) {

			ok = confirm("Are you sure you want to delete " + deleteItemCount + " item(s) ?");
			if (ok == true) {
				// submit form here.
				myForm.submit();
			}
			else {
				// Uncheck all boxes.
				for (i=0; x=myForm.elements[myField][i], x!=null; i++) {
					x.checked = false;
				}
				return false;
			}
		}
	}
	return false;
}


function checkEmployee(myForm) {
	charRegExp = new RegExp("[A-z][0-9][A-z][0-9][A-z][0-9]");
	var postalCode = justChar(myForm.postalcode.value);

	if (justChar(myForm.password.value) != justChar(myForm.confirmpassword.value)) {
		alert ("Please check your password.");
		myForm.password.focus();
		myForm.password.select();
		return false;
	}

	if (charRegExp.test(postalCode) == false) {
		alert ("Please enter a valid Canadian postal code.");
		myForm.postalcode.focus();
		myForm.postalcode.select();
		return false;
	}
	else {
		myForm.postalcode.value = postalCode.substring(0, 3) + " " + postalCode.substring(3, 6);
	}

	return true;
}

function bookmarksite(title, url){
	if (document.all)
		window.external.AddFavorite(url, title);
	else if (window.sidebar)
		window.sidebar.addPanel(title, url, "");
}

function testbox(form, ctrl, value) {
	if (value == "" || value.indexOf ('@', 1) == -1 || value.indexOf ('.', 3) == -1) {
		return (false);
	} else {
		return (true);
	} 
}

function swap() {
	var args = swap.arguments;
	var objId = document.getElementById(args[0]);

	objId.src = "/images/png/"+args[1]+".gif";
}


function trimString (str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function checkPhone(event,id) {
		var p = id.value;
		var l = p.length;
		if(event.keyCode == 32) { id.value = trimString(id.value); }
		if(event.keyCode != 32 && event.keyCode != 8 && event.keyCode != 46 && event.keyCode != 13) {
		if(l==3) { id.value = id.value.substring(0,3) + " "+ id.value.substring(4,l); }
		if(l==7) { id.value = id.value.substring(0,7) + " " + id.value.substring(8,l); }
		}
}
