function onClickMenu(event)
{
	var t	= event.srcElement || event.target;
	var s	= t.getElementsByTagName('ul').item(0);
	if ('li' == t.tagName.toLowerCase() && s)
	{
		s.className = (s.className.indexOf('hidden') > -1 ? '' : 'hidden');
	}
	return false;
}

function showImage(sURL, iWidth, iHeight, sTitle)
{
	var sTitle		= (sTitle ? sTitle : 'Click to close');
	var sAlt		= sTitle;
	var sImg		= sURL;
	var iMargin		= 10;
	var winwidth	= (Number(iWidth) + 2*iMargin);
	var winheight	= (Number(iHeight) + 2*iMargin);
	var scrollbars	= '0';

	if (screen.availHeight - iHeight < 100)
	{
		scrollbars = '1';
		winwidth = winwidth + 20
		winheight = screen.availHeight - 100;
	}

	if (screen.availWidth - iWidth < 100)
	{
		scrollbars = '1';
		winheight = (winheight != screen.availHeight - 100) ? winheight + 20 : winheight;
		winwidth = screen.availWidth - 100;
	}
	var screenx = Math.floor((screen.availWidth - winwidth)/2);
	var screeny = Math.floor((screen.availHeight - winheight)/2);
	var w = self.open('','','width=' + winwidth + ',height=' + winheight + ',top=' + screeny + ',left=' + screenx + ',toolbar=0,status=0,menubar=0,resizable=1,titlebar=0,scrollbars=' + scrollbars)
	var s = ''
	var CRLF = '\r\n'
	s += '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" ' + CRLF
	s += '		  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">' + CRLF
	s += '<html xmlns="http://www.w3.org/1999/xhtml">' + CRLF
	s += '<head>' + CRLF
	s += '<title>' + sTitle + '</title>' + CRLF
	s += '<style> html, body { margin: 0; padding: 0; height: 100%; } </style>' + CRLF
	s += '</head>' + CRLF
	s += '<body marginheight="0" marginwidth="0">' + CRLF
	s += '<table cellspacing="0" cellpadding="0" border="0" width="100%" height="100%">' + CRLF
	s += '<tr><td align="center" valign="middle" width="100%" height="100%">' + CRLF
	s += '<a href="javascript:self.close()"><img style="border: 1px solid black" src="' + sImg + '" width="' + iWidth + '" height="' + iHeight + '" border="0" title="' + sAlt + '" alt="' + sAlt + '" /></a>' + CRLF
	s += '</td></tr>' + CRLF
	s += '</table>' + CRLF
	s += '</body>' + CRLF
	s += '</html>' + CRLF
	w.document.open()
	w.document.write(s)
	w.document.close()
	void(0)
}

function getWindowHeight(w)
{
	var res = 0;
	if (null == w) w = window;
	if (typeof(w.innerHeight)=='number')
	{
		res = w.innerHeight;
	}
	else if (w.document.documentElement && w.document.documentElement.clientHeight)
	{
		res = w.document.documentElement.clientHeight;
	}
	else if (w.document.body && w.document.body.clientHeight)
	{
		res = document.body.clientHeight;
	}
	return res;
}

function fixHeights()
{
	var wh	= getWindowHeight();
	var o	= document.getElementById('content');
	var o2	= document.getElementById('sidebar_border');
	var fh	= document.getElementById('footer').clientHeight;
	var hh	= 120;
	var th	= document.getElementById('title').clientHeight;
	var bh	= 60;
	var borderH			= wh - hh - fh - th - bh;
	var contentH		= borderH - 15;
	o.style.height		= contentH + 'px';
	o.style.maxHeight	= contentH + 'px';
	o2.style.height		= borderH + 'px';
	o2.style.height		= borderH + 'px';
}

function fixLeftBorder()
{
	var el1 = document.getElementById('sidebar-border');
	var el2 = document.getElementById('pre').getElementsByTagName('td').item(0);
	//	var el3 = document.getElementById('header');
	var el4 = document.getElementById('title');
	var el5 = document.getElementById('buttons');
	var el6 = document.getElementById('footer');
	var diff = 120 + el4.clientHeight + el5.clientHeight + el6.clientHeight;
	el1.style.height = (el2.clientHeight - diff) + 'px';
}

function validateEmail(sEmail)
{
	if (null == sEmail.match(/^([0-9a-zA-Z]+[-._+&])*[0-9a-zA-Z]+@([-0-9a-zA-Z]+[.])+[a-zA-Z]{2,6}$/))
		return false;
	else
		return true;
}

function formRegistrationValidate(elForm)
{
	with (elForm)
	{
		var aRequired = ['Email', 'Email2', 'Password', 'Password2', 'Login', 'Company', 'FullName', 'Phone', 'Address', 'City', 'StateID', 'Zip', 'CountryID'];
		for (var i=0; i<aRequired.length; i++)
		{
			if ('' == elements['registration'+aRequired[i]].value)
			{
				alert('Fill all the required fields');
				elements['registration'+aRequired[i]].focus();
				return false;
			}
		}
		var sError = '';
		var sFocus = '';
		if (!validateEmail(registrationEmail.value))
		{
			sError = 'The email specified is invalid';
			sFocus = 'Email';
		}
		else if (registrationEmail.value != registrationEmail2.value)
		{
			sError = "The Email doesn't match its confirm";
			sFocus = "Email";
		}
		else if (registrationPassword.value.length < 6)
		{
			sError = "The password must be at least 6 chars";
			sFocus = "Password";
		}
		else if (registrationPassword.value != registrationPassword2.value)
		{
			sError = "The password doesn't match its confirmation";
			sFocus = "Password";
		}
		if ('' != sError)
		{
			alert(sError);
			elements['registration'+sFocus].focus();
			return false;
		}
	}
	return true;
}

function formFeedbackValidate(elForm)
{
	with (elForm)
	{
		var aRequired = ['Name', 'Email', 'Message'];
		for (var i=0; i<aRequired.length; i++)
		{
			if ('' == elements['feedback'+aRequired[i]].value)
			{
				alert('Fill all the required fields');
				elements['feedback'+aRequired[i]].focus();
				return false;
			}
		}
		var sError = '';
		var sFocus = '';
		if (!validateEmail(feedbackEmail.value))
		{
			sError = "The Email specified is invalid";
			sFocus = "Email";
		}
		if ('' != sError)
		{
			alert(sError);
			elements['feedback'+sFocus].focus();
			return false;
		}		
	}
	return true;
}


function formServiceOrderValidate(elForm)
{
	with (elForm)
	{
		var aRequired = ['FromName', 'Initials', 'JobName', 'Sample'];
		for (var i=0; i<aRequired.length; i++)
		{
			if ('' == elements['serviceorder'+aRequired[i]].value)
			{
				alert('Fill all the required fields');
				elements['serviceorder'+aRequired[i]].focus();
				return false;
			}
		}
/*
		var sError = '';
		var sFocus = '';
		if ('' != sError)
		{
			alert(sError);
			elements['serviceorder'+sFocus].focus();
			return false;
		}		
*/
		var c		= elements['serviceorderStage[]'];
		var bStage	= false;
		for (var i=0; i < c.length; i++)
		{
			if (true == c[i].checked)
			{
				bStage = true;
			}
		}
		if (false == bStage)
		{
			alert("You have to choose at least one stage");
			return false;
		}
	}
	return true;
}

function formProductOrderValidate(elForm)
{
	with (elForm)
	{
		var aRequired = ['FromName', 'Initials'];
		for (var i=0; i<aRequired.length; i++)
		{
			if ('' == elements['productorder'+aRequired[i]].value)
			{
				alert('Fill all the required fields');
				elements['productorder'+aRequired[i]].focus();
				return false;
			}
		}
		
		var bProducts = false;
		var c = elements['productorderProducts[]'];
		for (var i=0; i < c.length; i++)
		{
			if (c[i].checked == true)
			{
				bProducts = true;
			}
		}
		
		if (false == bProducts)
		{
			alert("You have to choose at least one product");
			return false;
		}
	}
	return true;
}

function mailto(a)
{
	var _em = 'sup'+'po'+'rt'+'@'+'cnt'+'-mc'+'.com';
	if (a && a.tagName && a.tagName.toLowerCase() == 'a')
	{
		_em = a.innerHTML.toString().replace(/<[^>]+>/, '').replace(/<\/[^>]+>/,'');
	}
	self.document.location = 'mailto:'+_em;
}

function doLogin(elForm)
{
	var s = elForm.loginLogin.value + ":" +MD5(elForm.loginPassword.value) + ":" +elForm.loginChallenge.value;
	elForm.loginPassword.value = '';
	elForm.loginResponse.value = MD5(s);
	elForm.submit();
	return false;
}

function doOnload()
{
	fixLeftBorder();
	if (window.event && document.all)
	{
		document.body.onresize = new Function("event", "self.fixLeftBorder()");
	}
	else
	{
		self.onresize = new Function("event", "self.fixLeftBorder()");
	}
	if (aOnloadAddOns.length > 0)
	{
		for (var i=0; i < aOnloadAddOns.length; i++)
		{
			aOnloadAddOns[i]();
		}
	}
}

var aOnloadAddOns = [];

function handleGallery()
{
	var ca = document.getElementsById('content').getElementsByTagName('a');
	for (var i=0; i<ca.length ;  i++)
	{
		var a = ca.item(i);
		if ("img" == a.className)
		{
			a.onclick = showImage(a.href, a.firstChild.title);
		}
	}
}