function ID(id)
{
	return document.getElementById(id);
}

function getMyXY(o)
{
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) //Non-IE
	{
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) //IE 6+ in 'standards compliant mode'
	{
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) //IE 4 compatible
	{
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	else
	{
		myHeight = document.getElementById('mesure').offsetHeight;
		myWidth = document.getElementById('mesure').offsetWidth;
	}

	var w = o.offsetWidth;
	var h = o.offsetHeight;

	var x = Math.round((myWidth/2)-(w/2));
	var y = Math.round((myHeight/2)-(h/2));
	y += document.body.scrollTop;

	o.style.left = x+'px';
	o.style.top = (y+100)+'px';
}
/*
function getMyXY(o)
{
	var myWidth = 0, myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) //Non-IE
	{
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	}
	else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) //IE 6+ in 'standards compliant mode'
	{
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	}
	else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) //IE 4 compatible
	{
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	else
	{
		myHeight = document.getElementById('mesure').offsetHeight;
		myWidth = document.getElementById('mesure').offsetWidth;
	}

	var w = o.offsetWidth;
	var h = o.offsetHeight;

	var x = Math.round((myWidth/2)-(w/2));
	var y = Math.round((myHeight/2)-(h/2));
	y += document.body.scrollTop;

	if(o.id != 'pre_loader')
	{
		//o.style.left = (x-200)+'px';
		//o.style.top = (y-200)+'px';
		o.style.left = (x)+'px';
		o.style.top = (y)+'px';

	}
	else
	{
		o.style.left = (x+50)+'px';
		o.style.top = (y-50)+'px';
	}
}
*/

function getX(o)
{
	var myWidth = 0;
	if( typeof( window.innerWidth ) == 'number' ) //Non-IE
	{
		myWidth = window.innerWidth;
	}
	else if( document.documentElement && document.documentElement.clientWidth) //IE 6+ in 'standards compliant mode'
	{
		myWidth = document.documentElement.clientWidth;
	}
	else if( document.body && document.body.clientWidth) //IE 4 compatible
	{
		myWidth = document.body.clientWidth;
	}
	else
	{
		myWidth = document.getElementById('mesure').offsetWidth;
	}

	var w = o.offsetWidth;
	var x = Math.round((myWidth/2)-(w/2));
	return x;
}

function getY(o)
{
	var myHeight = 0;
	if( typeof( window.innerWidth ) == 'number' ) //Non-IE
	{
		myHeight = window.innerHeight;
	}
	else if(document.documentElement && document.documentElement.clientHeight) //IE 6+ in 'standards compliant mode'
	{
		myHeight = document.documentElement.clientHeight;
	}
	else if(document.body && document.body.clientHeight) //IE 4 compatible
	{
		myHeight = document.body.clientHeight;
	}
	else
	{
		myHeight = document.getElementById('mesure').offsetHeight;
	}

	var h = o.offsetHeight;

	var y = Math.round((myHeight/2)-(h/2));
	y += document.body.scrollTop;
	return y;
}

function load()
{
	getMyXY(ID('pre_loader'));
}
/*
function closePopup()
{
	var options = {};

	if($("#system_message_popup").dialog('isOpen'))
	{
		$.closePopupLayer('myStaticPopup');
		$("#system_message_popup").dialog('destroy');
	}
}

function setSystemMessage(html)
{
	ID('system_message').innerHTML = html;
	checkSystemMessage();
}

function checkSystemMessage()
{
	if(ID('system_message').innerHTML != '')
	{
		openStaticPopup();
		openPopup();
	}

	if(ID('system_task_message'))
	{
		if(ID('system_task_message').innerHTML != '')
		{
			ID('system_message').innerHTML = ID('system_task_message').innerHTML;
			openStaticPopup();
			openPopup();
		}

	}
}

function openPopup()
{
	$.ui.dialog.defaults.bgiframe = true;
	$(function()
	{
		var resizable = $("#system_message_popup").dialog('option', 'resizable');
		$("#system_message_popup").dialog({ resizable: true});
		$("#system_message_popup").bind('dialogclose', function(event, ui)
		{
			closePopup();
		});
	});
}

function openStaticPopup()
{
	$.openPopupLayer({
		name: "myStaticPopup",
		width: 550,
		target: "system_message_hidden",
		beforeClose: function(){closePopup();}
	});
}
*/
function clearSearchBox()
{
	var text = document.getElementById('query').value;
	if (text == 'Search')
	{
		document.getElementById('query').value = '';
	}
}

function submitSearchForm()
{
	var text = document.getElementById('search').value;
	if (text == 'Search' || text == '')
	{
		alert('Please enter search query.');
	}
	else
	{
		document.getElementById('searchform').submit();
	}
}

function submitNewsletterEmail()
{
	var email = ID('newsletter_email').value;
	if (email == '')
		alert("Please enter email address.");
	else
		addEmail(email,{'target':'newsletter_status','preloader':'news_pre_loader'});
}

function openNewsletter()
{
	loadNewsletterHTML({'target':'system_message','onUpdate':loadPopUp});
}

function openLogin()
{
	loadLogin({'target':'system_message','onUpdate':loadPopUp});
}

function closePopUp()
{
	//fade('popup_div',false);
	document.getElementById('popup_div').style.visibility = 'hidden';

	fade('opacity_div',false);
}

function loadPopUp()
{
	var msg = document.getElementById('system_message').innerHTML;
	if(msg)
		document.getElementById('popup_msg').innerHTML = msg;

	fade('opacity_div',true);
	var popup_div = document.getElementById('popup_div');
	var x  = getX(popup_div);
	popup_div.style.left = x+'px';
	var y  = getY(popup_div);
	popup_div.style.top = y-200+'px';
	//getMyXY(document.getElementById('popup_div'));
	fade('popup_div',true);
	document.getElementById('popup_div').style.visibility = 'visible';
}

var fadeOpacity  = new Array();
var fadeTimer    = new Array();
var fadeInterval = 100;  // milliseconds

function fade(o,d)
{
  // o - Object to fade in or out.
  // d - Display, true =  fade in, false = fade out

  var obj = document.getElementById(o);

  if((fadeTimer[o])||(d&&obj.style.display!='block')||(!d&&obj.style.display=='block')) {
	if(fadeTimer[o])
	  clearInterval(fadeTimer[o]);
	else
	{
		if(o != 'opacity_div')
		{
		if(d) fadeOpacity[o] = 0;
		else  fadeOpacity[o] = 9;
		}
		else
		{
		if(d) fadeOpacity[o] = 0;
		else  fadeOpacity[o] = 7;

		}
	}

	obj.style.opacity = "."+fadeOpacity[o].toString();
	obj.style.filter  = "alpha(opacity="+fadeOpacity[o].toString()+"0)";

	if(d) {
	  obj.style.display = 'block';
	  fadeTimer[o] = setInterval('fadeAnimation("'+o+'",1);',fadeInterval);
	} else
	  fadeTimer[o] = setInterval('fadeAnimation("'+o+'",-1);',fadeInterval);
  }
}

function fadeAnimation(o,i)
{
  // o - o - Object to fade in or out.
  // i - increment, 1 = Fade In

  var obj = document.getElementById(o);
  fadeOpacity[o] += i;
  obj.style.opacity = "."+fadeOpacity[o].toString();
  obj.style.filter  = "alpha(opacity="+fadeOpacity[o].toString()+"0)";

  if((fadeOpacity[o]=='9')|(fadeOpacity[o]=='0'))
  {
	if(fadeOpacity[o]=='0')
	  obj.style.display = 'none';
	else
	{
		if(o == 'opacity_div')
		{
			obj.style.opacity = "0.7";
			obj.style.filter  = "alpha(opacity=70)";
		}
		else
		{
			obj.style.opacity = "1";
			obj.style.filter  = "alpha(opacity=100)";
		}
	}

	clearInterval(fadeTimer[o]);
	delete(fadeTimer[o]);
	delete(fadeTimer[o]);
	delete(fadeOpacity[o]);
  }
}

function resetWorkBtn()
{
	if(document.getElementById('work_btn_0'))
		document.getElementById('work_btn_0').className='whats_hot_button';

	if(document.getElementById('work_btn_1'))
		document.getElementById('work_btn_1').className='whats_hot_button';

	if(document.getElementById('work_btn_2'))
		document.getElementById('work_btn_2').className='whats_hot_button';
}