﻿var digits = "0123456789";
var phoneNumberDelimiters = "()- ";
var validWorldPhoneChars = phoneNumberDelimiters + "+";
var minDigitsInIPhoneNumber = 10;

function isEmpty(str) {
    strRE = new RegExp();
    strRE.compile('^[\s ]*$', 'gi');
    return strRE.test(str.value);
}

function notValidEmail(str) {
    mailRE = new RegExp();
    mailRE.compile('^[\._a-z0-9-]+@[\.a-z0-9-]+[\.]{1}[a-z]{2,4}$', 'gi');
    return !(mailRE.test(str.value));
}

function checkForm(form) {
    if (isEmpty(form.fname)) {
        alert('Please fill in your First name');
        form.fname.focus();
        return false;
    }

    if (isEmpty(form.company)) {
        alert('Please fill in your Company');
        form.company.focus();
        return false;
    }

    if (isEmpty(form.phone)) {
        alert('Please fill in your Phone');
        form.phone.focus();
        return false;
    }

    if (notValidEmail(form.email)) {
        alert('Incorrect or missing Email address!');
        form.email.focus();
        return false;
    }

    if (isEmpty(form.comment)) {
        alert('Please fill in your Comment');
        form.comment.focus();
        return false;
    }

    return true;
}

function isInteger(s) {
    var i;
    for (i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag) {
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++) {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function popupclose() {
    document.getElementById("pp_body").style.display = "none";
    document.getElementById("pp_bg").style.display = "none";
}

function HasBadWords(str) {
    var x;
    var BadWords = new Array("Piss", "Shit", "Bitch", "CONFIDENTIAL", "Cunt", "Asshole", "Dickhead", "Pussy", "Slut", "Sex", "Porn", "Fuck", "fuck", "scam", "spam", "asdf", "asd", "sdf", "qwer", "qwe", "zxc", "zxcv", "joke", "Joke", "Metrobank", "metro", "pizza", "wingding");
    for (x = 0; x < BadWords.length; x++) {
        if (str.value == BadWords[x]) {
            return true;
        }
    }
    return false;
}

function isAllDigits(text) {

    return (/^[\d]*$/gi).test(text);
}
