function PopWin(popurl, popname, w, h, scroll) {
    var winw = (screen.width - w) / 2;
    var winh = (screen.height - h) / 2;
    winprops = 'height=' + h + ',width=' + w + ',top=' + winh + ',left=' + winw + ',scrollbars=' + scroll + ',resizable';
    win = window.open(popurl, popname, winprops);
    if (parseInt(navigator.appVersion) >= 4) {
        win.window.focus();
    }
}

function validateContact(frm2chk) {
    if ((/^[a-zA-Z._ \-]{2,20}$/.test(frm2chk.name.value)) == false) {
        alert("Please Enter Your full Name.");
        frm2chk.name.focus();
        return false;
    }

    else if ((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(frm2chk.email.value)) == false) {
        alert("Please Enter a valid Email Address.");
        frm2chk.email.focus();
        return false;
    }

    else if (frm2chk.subject.value == "") {
        alert("Please Enter a subject for your message.");
        frm2chk.subject.focus();
        return false;
    }


    else if (frm2chk.message.value == "") {
        alert("Please Enter a message.");
        frm2chk.message.focus();
        return false;
    }

    else {
        return true;
    }
}

function validateHtSignup(frm2chk) {
    if ((/^[a-zA-Z. \-]{2,20}$/.test(frm2chk.category2.value)) == false) {
        alert("Please Enter Your full First Name");
        frm2chk.category2.focus();
        return false;
    }
    else if ((/^[a-zA-Z. \-]{2,20}$/.test(frm2chk.custom_lastname.value)) == false) {
        alert("Please Enter Your full Last Name");
        frm2chk.custom_lastname.focus();
        return false;
    }
    else if ((/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(frm2chk.category3.value)) == false) {
        alert("Please Enter a valid Email Address");
        frm2chk.category3.focus();
        return false;
    }
    else {
        return true;
    }
}

function SendMail(addy, dom, tld, subj) {
    self.location = 'mailto:' + addy + '@' + dom + '.' + tld + '?Subject=' + subj;
}

$(document).ready(function() {
    $('#auth_form').submit(function() {

            // Dependencies
            //   Jquery
            //   sha1 - which depends on utf8_encode

            // form element names
            var formID = "auth_form";
            var dataElement = "key_text";
            var saltElement = "key_val";
            var sha_key_element = "sha_key_text";

            // Collect form data values
            var key_text_data = $('[name=' + dataElement + ']').val();
            var key_salt_data = $('[name=' + saltElement + ']').val();
            var key_text_sha = sha1(key_text_data);
            var key_sha_data = sha1(key_text_sha + key_salt_data);

            // Set form values and submit
            $('[name=' + sha_key_element + ']').val(key_sha_data);
            $('[name=' + dataElement + ']').val(key_text_sha);

            return true;
    });
});

function addJavascript(jsname, pos) {
    // Append JS file 'jsname to the end of element pos (head or body)
    // May not be suitable for calling code that will execute loaded library
    // as the dependent library may not be ready by the time it is called
    var th = document.getElementsByTagName(pos)[0];
    var s = document.createElement('script');
    s.setAttribute('type', 'text/javascript');
    s.setAttribute('src', jsname);
    th.appendChild(s);
}
