

function _sh(id, b)
{
	var e = document.getElementById(id);
	if (e)
		e.style.display = b ? 'inline' : 'none';
}

/* ************************ MENU/SUBMENU CLASS ******************************* */

menuCreator = function (mid, act)
{
	this._mid = mid;
	this._m = document.getElementById(this._mid);
	this._ul = this._m.getElementsByTagName('ul')[0];
	this._a = this._ul.getElementsByTagName('li');
	this._l = this._a.length;
	this._active = act.toLowerCase();
}

menuCreator.prototype.init = function ()
{
	
	var $this = this;

	for (var i=0 ; i<this._l ; ++i)
	{		
		this._a[i].onclick = function () 
		{	
			$this.restore_menu_items ();

			if ($this.onclick)  $this.onclick (this);

			this.onmouseover = function () {};
			this.onmouseout = function () {};
		}
	}

	this.restore_menu_items ();
}

menuCreator.prototype.restore_menu_items = function () 
{
	for (var i=0 ; i<this._l ; ++i)
	{		
		var $this = this;
	
		this._a[i].onmouseover = function () 
		{	
			if ($this.onmouseover)  $this.onmouseover (this);
		}

		this._a[i].onmouseout = function () 
		{
			if ($this.onmouseout)  $this.onmouseout (this);
		}
		if (this.restore)  this.restore (this._a[i]);

		if (this.isActive)
		{
			if (this.isActive (this._a[i], this._active))
			{
				if (this.setActive)  this.setActive (this._a[i]);
				this._a[i].onmouseover = function () {};
				this._a[i].onmouseout = function () {};
			}	
		}
	}
}


showValidChars = function ()
{

	alert("Valid chars:\r\n A-Z a-z 0-9 _ . -");
}

checkUsername = function (s)
{
	if (!s.match (/^[\sA-Za-z0-9_\.\-]{4,16}$/))
		return false;
	return true;
}

checkFullname = function (s)
{
	if (!s.match (/^[\sA-Za-z0-9_\.\-]{5,32}$/))
		return false;
	return true;
}

checkEmail = function (s)
{
	if (!s.match (/^[a-zA-Z0-9\-_\.]+@[a-zA-Z0-9\-\._]+$/))
		return false;
	return true;
}

joinValidate = function (f)
{
	var ret = true;
	var e;
	
	e = f['username'];
	er = document.getElementById("err_" + e.name);
	if (!checkUniq('Username', e.value) || !checkUsername(e.value))
	{		
		er.style.display = "inline";
		e.style.backgroundColor = "#ffaaaa";

		e.focus();
		ret = false;
	}
	else
	{
		er.style.display = "none";
		e.style.backgroundColor = "white";
	}

	e = f['fullname'];
	er = document.getElementById("err_" + e.name);
	if (!checkFullname(e.value))
	{		
		er.style.display = "inline";
		e.style.backgroundColor = "#ffaaaa";

		if (ret) e.focus();
		ret = false;
	}
	else
	{
		er.style.display = "none";
		e.style.backgroundColor = "white";
	}

	e = f['email'];
	er = document.getElementById("err_" + e.name);
	if (!checkUniq('Email', e.value) || !checkEmail(e.value))
	{
		er.style.display = "inline";
		e.style.backgroundColor = "#ffaaaa";

		if (ret) e.focus();
		ret = false;
	}
	else
	{
		er.style.display = "none";
		e.style.backgroundColor = "white";
	}

	return ret;
}

/**                     
 * check unique username or email
 *  @param n    field name (username or email)
 *  @param v    field value
 */                         
checkUniq = function (n, v)
{                       
    if (n != 'Username' && n != 'Email') return false;
                    
    var $this = this;
    var ret = 0;

    var h = function (r)
    {
        var a = r.responseXML.getElementsByTagName('ret');
        ret = parseInt(a[0].getAttribute('val'));
    }           
                
    new BxXmlRequest ('/join.php?check_uniq=' + n + '&val=' + v, h, false);
                    
    return ret;     
}            


onBigPointer = function (bp, id)
{
	var e = document.getElementById(id); 

	if (e.style.display == 'none') 
	{
		e.style.display = 'block';
		bp.onmouseover = function () { this.style.backgroundPosition = '0 26px' };
		bp.onmouseout = function () { this.style.backgroundPosition = '0 52px' };
		e.style.marginBottom = '2px';
	}
	else
	{
		e.style.display = 'none';
		bp.onmouseover = function () { this.style.backgroundPosition = '0 78px' };
		bp.onmouseout = function () { this.style.backgroundPosition = '0 0' };
	}

	bp.onmouseover ();

	return false;
}

/* ************************ DOWNLOAD  ******************************* */

function download (p, m, bool)
{
	var url_plus = '';

	if (bool && m.length)
	{
		url_plus = "&email=" + m;
	}

	document.location = "http://www.boonex.com/thankyou.php?p=" + p + url_plus;

	return false;
}

function payment (p)
{
	document.location = "http://www.boonex.com/payment.php?p=" + p;
}

function $ (id)
{
	return document.getElementById(id);
}

function openRayDemo (m)
{
	
    if (m == 'mp3')
    {
        window.open('http://demozzz.com/ray/?module=mp3&app=player&nick=Boonex&Submit=true&popup=true', 'mp3', 'location=0,status=0,scrollbars=0,resizable=0,width=350,height=95');
    }
    else
    if (m == 'video')
    {
        window.open('http://demozzz.com/ray/?module=video&app=recorder&nick=Boonex&Submit=true&popup=true', 'video', 'location=0,status=0,scrollbars=0,resizable=0,width=545,height=300');
    }
    else
    if (m == 'base')
    {
        window.open('http://www.demozzz.com/dolphin/admindemo/ray/?module=global&app=admin&nick=admin&password=36cdf8b887a5cffc78dcd5c08991b993', 'base', 'location=0,status=0,scrollbars=0,resizable=0,width=800,height=600');
    }
	else if (m == 'whiteboard' || m == 'board')
	{
		if(m == 'whiteboard') m = 'board';
		var params = "location=0,status=1,scrollbars=0,width=800,height=650,resizable=0";
        window.open('http://demozzz.com/ray/?module=board&app=user&inPopup=1', m, params);
	}
    else
    {
		var params = "location=0,status=1,scrollbars=0,width=800,height=650,resizable=1";
		if (m == 'desktop') params = "location=0,status=1,scrollbars=1,width=800,height=650,resizable=1";
        window.open('http://demozzz.com/ray/?module=' + m + '&inPopup=1', m, params);
    }
}
