function OpenWindow(url, which, width, height) {
  var mywindow = window.open(url, which  + "window", "width=" + width + ",height=" + height+",menubar=no,status=no,location=yes,toolbar=no,scrollbars=yes");
  mywindow.focus();
  return false;
}
function OpenExtWindow(url) {
  var mywindow = window.open(url, "otherwindow", "");
  mywindow.focus();
  return false;
}

function checkexists(fldName, errorMessage) {
        obj = document.getElementById(fldName);
        if (obj) {
                if (obj.value.length == 0) {
                        alert(errorMessage);
                        obj.focus();
                        return false;
                }
        }
        return true;
}
function checklength(fldName, iMin, iMax, errorMessage) {
        obj = document.getElementById(fldName);
        if (obj) {
                if (obj.value.length < iMin || obj.value.length > iMax) {
                        alert(errorMessage);
                        obj.focus();
                        return false;
                }
        }
        return true;
}
function checkemail(fldName, errorMessage) {
        obj = document.getElementById(fldName);
        if (obj) {
                if (obj.value.length > 0) {
                        reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
                        if(reg.test(obj.value) == false) {
                                alert(errorMessage);
                                obj.focus();
                                return false;
                        }
                }
        }
        return true;
}

function checkchecked(fldName, errorMessage) {
        obj = document.getElementById(fldName);
        if (obj) {
                if (!(obj.checked)) {
                        alert(errorMessage);
                        obj.focus();
                        return false;
                }
        }
        return true;
}
function checkselected(fldName, errorMessage) {
        obj = document.getElementById(fldName);
        if (obj) {
                if (!(obj.selectedIndex > 1)) {
                        alert(errorMessage);
                        obj.focus();
                        return false;
                }
        }
        return true;
}


function CheckRegForm1() {
        if (!checkexists("frm_email", "Email is required")) {return false;}
        if (!checklength("frm_email", 0, 150, "Email is too long (max 150 characters)")) {return false;}
        if (!checkemail("frm_email", "Email is invalid")) {return false;}
        if (!checkexists("frm_first", "First name is required")) {return false;}
        if (!checklength("frm_first", 0, 50, "First name is too long (max 50 characters)")) {return false;}
        if (!checkexists("frm_last", "Last name is required")) {return false;}
        if (!checklength("frm_last", 0, 50, "Last name is too long (max 50 characters)")) {return false;}
        if (!checkexists("frm_pass", "Password is required")) {return false;}
        if (!checklength("frm_pass", 6, 20, "Password must be between 6 and 20 characters")) {return false;}
        if (!(document.getElementById("frm_pass").value == document.getElementById("frm_pass2").value)) {
                alert("Password do not match");
                document.getElementById("frm_pass2").focus();
                return false;
        }
        return true;
}

function CheckLoginForm() {
        if (!checkexists("log_username", "Email is required")) {return false;}
        if (!checklength("log_username", 0, 150, "Email is too long (max 150 characters)")) {return false;}
        if (!checkemail("log_username", "Email is invalid")) {return false;}
        if (!checkexists("log_password", "Password is required")) {return false;}
        if (!checklength("log_password", 6, 20, "Password must be between 6 and 20 characters")) {return false;}
        return true;
}

function CheckRegForm2() {
        if (!checkexists("frm_email", "Email is required")) {return false;}
        if (!checklength("frm_email", 0, 150, "Email is too long (max 150 characters)")) {return false;}
        if (!checkemail("frm_email", "Email is invalid")) {return false;}
        if (!checkexists("frm_phone", "Daytime phone number is required")) {return false;}
        if (!checklength("frm_phone", 0, 50, "Daytime phone number is too long (max 50 characters)")) {return false;}
        if (!checkexists("frm_add1", "Address is required")) {return false;}
        if (!checklength("frm_add1", 0, 50, "Address (first line) is too long (max 50 characters)")) {return false;}
        if (!checklength("frm_add2", 0, 50, "Address (second line) is too long (max 50 characters)")) {return false;}
        if (!checkexists("frm_suburb", "Suburb is required")) {return false;}
        if (!checklength("frm_suburb", 0, 50, "Suburb is too long (max 50 characters)")) {return false;}
        if (!checkselected("frm_state", "State is required")) {return false;}
        if (!checkexists("frm_postcode", "Postcode is required")) {return false;}
        if (!checklength("frm_postcode", 3, 4, "Postcode is invalid")) {return false;}
        if (!checkchecked("frm_tc", "You must confirm that you are an Australian Resident and that you accept the terms and conditions")) {return false;}
        return true;
}

function HideErrorBox() {
  obj = document.getElementById('ErrorBox');
  if (obj) {
    obj.style.left="-2600px";
  }
}

