window_handle = null;

function open_popup_window(_url,_width, _height) {
    if (window_handle) window_handle.close();
    if (_width<1) { _width = 300; }
    if (_height<1) { _height = 300; }
    window_handle = window.open(_url,'popupWindowName1','status=no,width='+(_width+20)+',height='+(_height+20)+',screenX=50,screenY=50,left=50,top=50');
}

function open_popup_window_new(_url,_width, _height) {
    if (_width<1) { _width = 300; }
    if (_height<1) { _height = 300; }
    window.open(_url,'','status=no,width='+(_width+20)+',height='+(_height+20)+',screenX=50,screenY=50,left=50,top=50,scrollbars=yes,resizable=yes');
}


function isdigit(s) {
    for(var i=0;i<s.length;i++) {
        if (s.charAt(i)<'0'||s.charAt(i)>'9') {
            return false;
        }
    }
    return true;
}

function isNipValid(s) {
    var mn = [6,5,7,2,3,4,5,6,7]; var cr = 0;
    if (!s.match(/^[0-9]{3}-[0-9]{3}-[0-9]{2}-[0-9]{2}$/gi)) { return false; }
    s = s.substring(0,3)+s.substring(4,7)+s.substring(8,10)+s.substring(11,13);
    for(var i=0;i<mn.length;i++) { cr += mn[i]*parseInt(s.charAt(i),10); }
    cr%=11; cr=(cr==10?0:cr);
    return (cr == parseInt(s.charAt(mn.length),10))?true:false;
}

function isRegon9Valid(s) {
    var mn = [8,9,2,3,4,5,6,7]; var cr = 0;
    if (!s.match(/^[0-9]{9}$/gi)) { return false; }
    for(var i=0;i<mn.length;i++) { cr += mn[i]*parseInt(s.charAt(i),10); }
    cr%=11; cr=(cr==10?0:cr);
    return (cr == parseInt(s.charAt(mn.length),10))?true:false;
}

function isZipValid(s) {
    return (s.match(/^[0-9]{2}(-)?[0-9]{3}$/gi));
}

function jstrim(s) {
    return s.replace(/(^\s+)|(\s+$)/g, "");
}

function htmlspecialchars(s) {
    s = String(s);
    if (s.length==0) { return s; }
    s = s.replace(/&/,'&amp;');
    s = s.replace(/</,'&lt;');
    s = s.replace(/>/,'&gt;');
    s = s.replace(/"/,'&quot;');
    return s;
}


function fulltextand(s) {
    s = String(s);
    if (s.length==0) { return s; }
    s = s.replace(/ /,' +');
    return s;
}


function isEmailValid(emailstring) {
	if (!emailstring.match(/^[a-z0-9+]{1}[a-z_0-9-\.]*@[a-z0-9]{1}[a-z0-9-]*(\.[a-z0-9]{1}[a-z0-9-]*)+$/gi)) {
		return false;
	}
	return true;
}