// Common JavaScript
var w = null;
function isEmail (e) { return e.indexOf('@') + '' != '-1' && e.indexOf('.') + '' != '-1'; }
function ltrim (s) { return s.replace( /^\s*/, "" ); }
function rtrim (s) { return s.replace( /\s*$/, "" ); }
function trim (s) { return rtrim(ltrim(s)); }
function formatStr (v) {
if (!document.selection) return;
var str = document.selection.createRange().text;
if (!str) return;
document.selection.createRange().text = '<' + v + '>' + str + '</' + v + '>';
}
function insertLink () {
if (!document.selection) return;
var str = document.selection.createRange().text;
if (!str) return;
var url = prompt('Enter URL:', 'http://');
if (url != null) document.selection.createRange().text = '<a target="_blank" href="' + url + '">' + str + '</a>';
}
function markupButtons () {
if (document.selection) {
document.write('<input type="button" name="boldbutton" id="boldbutton" onclick="formatStr(\'strong\');" value=" B " />');
document.write('<input type="button" name="italicbutton" id="italicbutton" onclick="formatStr(\'em\');" value=" i " />');
document.write('<input type="button" name="urlbutton" id="urlbutton" onclick="insertLink();" value="URL" />');		
}}
function browsePage (obj) {
var index = obj.selectedIndex;
var url = obj.options[index].value;
if (url != '') document.location = url;	
}
function isUndefined (v) { 
var undef; return v === undef; 
}
function rawPopup (url, target, width, height, scrolling) {
var scrolling = isUndefined(scrolling) ? 'yes' : (scrolling ? 'yes' : 'no');
if (w != null) w.close();
w = window.open(url, target, 'scrollbars=' + scrolling + ',location=0,statusbar=0,menubar=0,width=' + width + ',height=' + height);
w.focus();
return w;
}
function linkPopup (src, width, height) {
if (isUndefined(width)) width = 500;
if (isUndefined(height)) height = 400;
return rawPopup(src.getAttribute('href'), src.getAttribute('target') || '_blank', width, height);
}
function checkCountry () {
var country = document.getElementById('country').value;
var provinceSelect = document.getElementById('provinceselect');
provinceSelect.style.visibility = (country == 'BE' ?  'visible' : 'hidden');
}
