
var MPCWIN;

function chk_quotes(str)
{
	re = /(\'.*\")|(\".*\')/;
	return str.search(re) == -1;
}


function chk_pd_name(dir)
{
	re = /^[0-9a-zA-Z-_.\/]+$/;
	// forbid / and /../ and // and ^./ and ^../  and /./  and /..$ and /.$ and ^.$
	re1 = /(^\/$|\/\.\.\/|\/\/|^\.\/|^\.\.\/|\/\.\/|\/\.\.$|\/\.$|^\.$)/;
	return (dir.search(re) != -1) && (dir.search(re1) == -1);
}

function chk_db_name(db)
{
	re = /^[a-zA-Z]{1}[A-Za-z0-9-_]{0,31}$/;
	return db.search(re) != -1;
}

function chk_db_usr_name(usr)
{
	re = /^[a-zA-Z]{1}[A-Za-z0-9_]{0,15}$/;
	return usr.search(re) != -1;
}

function chk_pos_int(pos_int)
{
	re = /^\s*[1-9]{1}[0-9]*\s*$/;
	return pos_int.search(re) != -1;
}

function chk_sys_login(nm)
{
	re = /^[a-z]{1}[a-z0-9_-]{0,15}$/;
	return nm.search(re) != -1;
}

function chk_mn(mail_name)
{
	re = /^[\w-\+]+((\.)[\w-\+]+)*$/;
	return mail_name.search(re) != -1;
}


function chk_resp_name(resp_name)
{
	re = /^[\.\w\s]+$/;
	return resp_name.search(re) != -1;
}



function chk_login(login)
{
	re = /^[a-zA-Z0-9]{1}[A-Za-z0-9_.-]{0,19}$/;
	return login.search(re) != -1;
}

function chk_realm(realm)
{
	re = /^[^\"]*$/;
	return realm.search(re) != -1;
}

function chk_dom(dom_name)
{
	if ('localhost.rev' == dom_name)
		return false;

	inaddr = /\.in-addr.arpa$/;
	if (dom_name.search(inaddr) != -1)
		return false;

	if (chk_ip(dom_name))	// no domain name like IP address
		return false;

	nore = /\.$/;
	re = /^[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])*(\.[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])*)+$/;
	return (dom_name.search(nore) == -1) && (dom_name.search(re) != -1);
}

function chk_subdom(dom_name)
{
	re = /^[A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])*$/;
	return dom_name.search(re) != -1;
}

function chk_email(email)
{
	re = /^([^\@]+){1}\@([^\@]+){1}$/;
	found = email.match(re);
	if (!found)
		return false;
	return chk_mn(found[1]) && chk_dom(found[2]);
}

function chk_url(url)
{
	re = /^((http[s]?|ftp):\/\/)?([^\/:]+)(:\d{1,5})?(\/[^\s\"\'`]*)?$/i;
	found = re.exec(url);
	if (!found) 
		return false;

	return chk_dom(found[3]);
}

function chk_ip(ip)
{
	re = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
	found = ip.match(re);
	if (!found)
		return false;
	for (i = found.length; i-- > 1;) {
		if ((found[i] < 0) || (found[i] > 255))
			return false;
	}
	return true;
}

function chk_mask(mask)
{
	re = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;
	found = mask.match(re);
	if (!found)
		return false;
	i = found.length - 1;
	while (i && (found[i] == 0)) i--;
	if (!i)
		return true;
	if (
		(found[i] != 128) &&
		(found[i] != 192) &&
		(found[i] != 224) &&
		(found[i] != 240) &&
		(found[i] != 248) &&
		(found[i] != 252) &&
		(found[i] != 254) &&
		(found[i] != 255)
	)
		return false;
	i--;
	while (i && (found[i] == 255)) i--;

	return i == 0;
}

function dot_to_num(str)
{
	var num = 0;
	var re = /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/;

	found = str.match(re);
	if (!found)
		return null;
	for (i = 0; ++i < found.length; ) {
		num <<= 8;
		num  |= found[i];
	}
	return num;
}

function chk_ip_mask(ip, mask)
{
	if (!top.chk_ip(ip) || !top.chk_mask(mask))
		return false;

	var num_ip;
	var num_mask;

	if ((num_ip = dot_to_num(ip)) == null)
		return false;

	if ((num_mask = dot_to_num(mask)) == null)
		return false;

	// check ip/mask combination for interface:
	// 1) mask not null
	// 2) host part not null (num_ip & ~num_mask)
	// 3) host part not all 1 ~((num_ip & ~num_mask) | num_mask)
	return num_mask && (num_ip & ~num_mask) && ~((num_ip & ~num_mask) | num_mask);
}

function chk_net_mask(net, mask)
{
	if (!top.chk_ip(net) || !top.chk_mask(mask))
		return false;

	var num_net;
	var num_mask;

	if ((num_net = dot_to_num(net)) == null)
		return false;

	if ((num_mask = dot_to_num(mask)) == null)
		return false;

	return num_mask && (num_net & num_mask) && ((num_net & num_mask) == num_net);
}

function chk_sys_passwd(username, passwd)
{
	if ((passwd.length < 5) || (passwd.length > 16))
		return false;

	if (passwd.length >= username.length) {
		if (passwd.indexOf(username, 0) != -1)
			return false;
	}

	if ((passwd.indexOf('\'') != -1) || (passwd.indexOf(' ') != -1))
		return false;

	for (i = passwd.length; i-- > 0;) {
		if (passwd.charCodeAt(i) > 127)
			return false;
	}

	return true;
}

function chk_filename(filename)
{
	re = /^[^\']*$/;
	return filename.search(re) != -1;

}

function chk_uint(uint)
{
	re = /^[0-9]+$/;
	found = uint.match(re);
	if (!found) {
		return false;
	}

	return true;
}


function set_focus(d, el)
{
	if (!el)	// if form element not set - do nothing
		return;

	if ((x = findObj(e, d)) != null) {
		if (x.focus)
			x.focus();
		if (x.select)
			x.select();
	}
}


function syn(s)
{
	if (!s || !s.options || !s.options.length) 
		return false;
	
	if (s.options[s.options.length - 1].selected)
		s.options[s.options.length - 1].selected = false;
}

function plesk_scroll(w)
{
	var nav = navigator.appName;
	var ver = parseInt(navigator.appVersion);
	if ((nav.indexOf('Netscape') != -1) && (ver == 4) && w.document.location.hash) {
		var aname = w.document.location.hash.substr(1);
		var an = w.document.anchors[aname];
		if (an)
			w.scrollTo(an.x, an.y);
	}
}

function MM_reloadPage(init)	// reloads the window if Nav4 resized
{
	if (init == true)
		with (navigator) {
			if ((appName == 'Netscape') && (parseInt(appVersion) == 4)) {
				document.MM_pgW = innerWidth;
				document.MM_pgH = innerHeight;
				onresize = MM_reloadPage;
			}
		}
	else
		if ((innerWidth != document.MM_pgW) || (innerHeight != document.MM_pgH))
			location.reload();
}

MM_reloadPage(true);

function getButtonName(name)
{
    re = /^bname_([A-Za-z0-9-]+)$/;
    return name.replace(re,"$1");
}
	
function leftFrameLoaded()
{
	if (!top || !top.mainFrame || !top.mainFrame.leftFrame || !top.mainFrame.leftFrame.document || !top.mainFrame.leftFrame.document.forms[0])
		return false;
	return true;
}

function setActiveButtonByName(name)
{
	if (!leftFrameLoaded())
		return false;
	
	return top.mainFrame.leftFrame.setActiveNode(name);
}
	
function setActiveButton(o)
{
	if (!leftFrameLoaded())
		return false;
	
	return top.mainFrame.leftFrame.setActiveNode(o.id);
}
var help_prefix = '';


var context = '';
var helpPerm = true;

function mouse_move(context)
{
	if(!top.helpPerm)
		return false;

	top.SetConHelp(context)
}

function SetContext(context)
{
	if (context)
		top.context = context;
	top.SetConHelp();
	return false;
}

var _c = new Array;	// context help messages
//<? include ("lang/".$_SESSION['lang']."/texte_help.php"); ?>

// BrowserCheck Object
function BrowserCheck()
{
        var b = navigator.appName
        if (b=='Netscape') this.b = 'ns'
        else if (b=='Microsoft Internet Explorer') this.b = 'ie'
        else this.b = b
        this.version = navigator.appVersion
        this.v = parseInt(this.version)
        this.ns = (this.b=='ns' && this.v>=4)
        this.ns4 = (this.b=='ns' && this.v==4)
        this.ns5 = (this.b=='ns' && this.v==5)
        this.ie = (this.b=='ie' && this.v>=4)
        this.ie4 = (this.version.indexOf('MSIE 4')>0)
        this.ie5 = (this.version.indexOf('MSIE 5')>0)
        this.ie55 = (this.version.indexOf('MSIE 5.5')>0)
        this.min = (this.ns||this.ie)
}

is = new BrowserCheck()

function SetConHelp(conhelp_name)
{
	if(!conhelp_name)
		conhelp_name = top.context;

	names = (typeof(conhelp_name) == 'object') ? conhelp_name : [conhelp_name];
	
	msg = '';
	for (i = 0; i < names.length; i++) {
		if (!_c[names[i]] && names[i].indexOf('b_') == 0)	// remove b_ for custom buttons' conhelps
			names[i] = names[i].substr(2);

		msg += (_c[names[i]]) ? _c[names[i]] : names[i];
	}

	return ShowConHelp(msg);
}

function ShowConHelp(conhelp_string)
{
	var prefix = "<div><span class='hint'>";
	var suffix = "</span></div>";
	msg = prefix + conhelp_string + suffix;

	if (is.ns4) {
		if (!top.mainFrame	||
			!top.mainFrame.leftFrame ||
			!top.mainFrame.leftFrame.document ||
			!top.mainFrame.leftFrame.document.layers ||
			!top.mainFrame.leftFrame.document.layers['contexthelp'] ||
			!top.mainFrame.leftFrame.document.layers['contexthelp'].document) {
				top.helpPerm = true;
				return false;
		}
		lyrdoc = top.mainFrame.leftFrame.document.layers['contexthelp'].document;
		lyrdoc.open();
		lyrdoc.write(msg);
		lyrdoc.close();
	}

	if (is.ns5) {
		if (!top.mainFrame ||
		    !top.mainFrame.leftFrame ||
			!top.mainFrame.leftFrame.document) {
				top.helpPerm = false;
				return false;
			 }
		lyrdoc = top.mainFrame.leftFrame.document.getElementById('contexthelp');
		if (lyrdoc && lyrdoc.innerHTML)
			lyrdoc.innerHTML = msg;
	}

	if (is.ie) {
		if (!top.mainFrame	||
			!top.mainFrame.leftFrame ||
			!top.mainFrame.leftFrame.document ||
			!top.mainFrame.leftFrame.document.all ||
			!top.mainFrame.leftFrame.document.all['contexthelp'] ||
			!top.mainFrame.leftFrame.document.all['contexthelp'].innerHTML) {
				top.helpPerm = true;
				return false;
		}
		top.mainFrame.leftFrame.document.all['contexthelp'].innerHTML = msg;
	}

	return false;
}

