/*

Author: José Guilherme Moreira
Contact: jgmoreira@gangnetworks.com
Web Site: http://www.gangnetworks.com */

// Open Popup 
function openbrWindow(theURL, winName, features) {
window.open(theURL, winName, features);
}

// Ask for Confirmation
function confirmationAlert(id, question, url) {
var temp = window.confirm(question);
if (temp) {
window.location = url + id;
}
}

// Functions to Validate Phone Numbers
var allowed_digits = "0123456789";
var allowed_delimiters = "()- ";
var allowed_world_chars = allowed_delimiters + "+";
var minimum_allowed_digits = 10;

function isInteger(str) {
var i;
for (i=0; i<str.length; i++) {
var current_char = str.charAt(i);
if (((current_char < "0") || (current_char > "9"))) {
return false;
}
}
return true;
}

function stripInputedChars(str, inputed_value) { 
var i;
var return_str = "";
for (i=0; i<str.length; i++) {
var current_char = str.charAt(i);
if (inputed_value.indexOf(current_char) == -1) {
return_str += current_char;
}
}
return return_str;
}

function checkInternationalNumber(str_phone) {
str = stripInputedChars(str_phone, allowed_world_chars);
return (isInteger(str) && str.length >= minimum_allowed_digits);
}

// Allow Only Numbers in Form Fields
function numbersOnly(the_field, e, dec) {
var key;
var keychar;
if (window.event) {
key = window.event.keyCode;
} else if (e) {
key = e.which;
} else {
return true;
}
keychar = String.fromCharCode(key);
if ((key === null) || (key === 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27)) {
return true;
} else if ((("0123456789").indexOf(keychar) > -1)) {
return true;
} else if (dec && (keychar == ".")) {
the_field.form.elements[dec].focus();
return false;
} else {
return false;
}
}

// Anti-Spam
function maskEmail(address) {
address = address.split("*"); // Change the * to any string for better personalization, v.g. (spam@my_domain.com)
address = address.join("@");
window.open ('mailto:'+address,'_blank');
}
