function initPage() {
	if (window.attachEvent && !window.opera){ ieHover();}
	main_height();
	box_height();
	gal_list();
	initPost();
	initCheck();
	init_starRating();
	init_rasFavourite();
	displayPopup('myprogram-calendar', 'edit-exercise-popup', 'edit');
	displayPopup('user-tools-area', 'join-group-popup', 'btn');
	displayPopup('my-photos-area', 'photo-edit-popup', 'edit');
	displayPopup('photos', 'add-friend-popup', 'add');
	displayPopup('exercise-area', 'exercise-popup', 'edit-info');
	displayPopup('relaxation-area', 'relaxation-popup', 'edit-info');
	initTabs();
	myDay_init();
	myProgram_init();
	inviteFriendSearch();
	CMP_control();
	WBM_provider_formCheck();
	WBM_join_formCheck();
	WBM_communityProvider();
	WBM_communityGroup();
	WBM_communityGroup_formCheck();
	WBM_recommend_formCheck();
	WBM_profileGallery_doUploadFile();
}
if (window.addEventListener){
	window.addEventListener("load", initPage, false);
}
else if (window.attachEvent){
	window.attachEvent("onload", initPage);
}
function initPost(){
	var _post = document.getElementById("news");
	if (_post)
	{
		var nodes = _post.getElementsByTagName("div");
		for (var i=0; i<nodes.length; i++)
		{
			if ((nodes[i].className.indexOf("news-bar") != -1) && (nodes[i].className.indexOf("top") == -1) && (nodes[i].className.indexOf("bottom") == -1))
			{
				
				//on mouse over
				nodes[i].onmouseover = function()
				{
					this.className += " active";
					
					buttons = this.getElementsByTagName("a");
					for (j=0; j<buttons.length; j++)
					{
						if ((buttons[j].className.indexOf("btn") != -1))
						{
							buttons[j].className += " active";
						}
			
					}
				}


				//on mouse out
				nodes[i].onmouseout = function()
				{
					this.className = this.className.replace(" active", "");

					buttons = this.getElementsByTagName("a");
					for (j=0; j<buttons.length; j++)
					{
						if ((buttons[j].className.indexOf("btn") != -1))
						{
							buttons[j].className = buttons[j].className.replace(" active", "");
						}
					}
				}

				//on click (view profile)
				nodes[i].onclick = function()
				{					
					buttons = this.getElementsByTagName("a");
					for (j=0; j<buttons.length; j++)
					{
						if ((buttons[j].className.indexOf("btn") != -1))
						{
							_section_link = buttons[j].href;
						}
					}

					window.location = _section_link;
				}



			}
		}
	}
}




function gal_list(){
	var nav_t = document.getElementById("gallery-list");
	var gal_list_count;
	var gal_list_auto_close;

	if(nav_t)
	{
		nav_t = nav_t.getElementsByTagName("li");
		gal_list_count = nav_t.length;

		for (var i=0; i<nav_t.length; i++)
		{

			nav_t[i].onclick = function (i)
			{
				if(gal_list_auto_close)
				{
					clearInterval(gal_list_auto_close);
				}

				if(this.className.indexOf("active") !=-1)
				{
					this.className = this.className.replace("active", "");
				}
				else
				{
					for (var j=0; j<nav_t.length; j++){ nav_t[j].className = nav_t[j].className.replace("active", "");}
					
					this.className += ' active ';

					gal_list_auto_close = setTimeout(function() { for (var k=1; k<=gal_list_count; k++){ document.getElementById('expert_popup_'+k).className = '';} }, expert_popup_autoclose);
				}
				
				return false;
			}
		}



	}
}

function initCheck(){
	var _hold = document.getElementsByTagName('ul');
	var _list = [];
	var _k = 0;
	for(var i = 0; i < _hold.length; i++){
		if(_hold[i].className.indexOf('personal-goals') != -1){
			
			var t_btn = _hold[i].getElementsByTagName('a');
			var t_checkbox = _hold[i].getElementsByTagName('input');
			var _btn;
			var _checkbox = [];
			
			for(var j = 0; j < t_btn.length; j++){
				if(t_btn[j].className.indexOf('select-all') != -1){ _btn = t_btn[j];}
			}
			for(var j = 0; j < t_checkbox.length; j++){
				if(t_checkbox[j].type == "checkbox"){
					_checkbox.push(t_checkbox[j]);
				}
			}
			if(_btn){
				_list[_k] = _btn;
				_list[_k]._ind = _k;
				_list[_k]._checkbox = _checkbox;
				_k++;
			}
		}
	}
	for(var i = 0; i < _list.length; i++){
		if(_list[i]){
			_list[i].onclick = function(){
				if(this.className.indexOf('checked') != -1){
					for(var j = 0; j < _list[this._ind]._checkbox.length; j++){
						_list[this._ind]._checkbox[j].checked = false;
					}
					this.className = this.className.replace('checked','');
				}
				else{
					for(var j = 0; j < _list[this._ind]._checkbox.length; j++){
						_list[this._ind]._checkbox[j].checked = true;
					}
					this.className += ' checked ';
				}
				return false;
			}
		}
	}
}
function main_height()
{
	var col = document.getElementsByTagName("div");
	for (var i = 0; i < col.length; i++)
	{
		if(col[i].className.indexOf('information') != -1)
		{
			var _h = col[i].offsetHeight;
			var hold = col[i].getElementsByTagName("div");
			for( var j = 0 ; j < hold.length ; j++)
				if( hold[j].className.indexOf('box-holder') !=-1)
				{
					hold[j].style.minHeight = _h - 50 +'px';
					if (window.attachEvent && !window.opera){ hold[j].style.height = _h - 50 + 'px'; }
				}
				
		}
	}
}
function box_height()
{
	var col1 = document.getElementsByTagName("div");
	for (var i = 0; i < col1.length; i++)
	{
		if(col1[i].className.indexOf('info-row') != -1)
		{
			var _h1 = 0;
			var hold1 = col1[i].getElementsByTagName("div");
			for( var j = 0 ; j < hold1.length ; j++) {
				if( hold1[j].className.indexOf('info-box-bar') !=-1) {
					if(hold1[j].offsetHeight > _h1) { _h1 = hold1[j].offsetHeight;}
				}
			}
			for( var j = 0 ; j < hold1.length ; j++) {
				if( hold1[j].className.indexOf('info-box-bar') !=-1) {
					hold1[j].style.minHeight = _h1 - 46 + 'px';
					if (window.attachEvent && !window.opera){ hold1[j].style.height = _h1 - 46 + 'px'; }
				}
			}
		}
	}
}
function initTabs()
{
	var sets = document.getElementsByTagName("ul");
	for (var i = 0; i < sets.length; i++)
	{
		if (sets[i].className.indexOf("tabset") != -1 || sets[i].className.indexOf("tabset-list") !=-1)
		{
			var tabs = [];
			var links = sets[i].getElementsByTagName("a");
			for (var j = 0; j < links.length; j++)
			{
				if (links[j].className.indexOf("tab") != -1)
				{
					tabs.push(links[j]);
					links[j].tabs = tabs;
					var c = document.getElementById(links[j].href.substr(links[j].href.indexOf("#") + 1));
					if (c) if (links[j].className.indexOf("active") != -1) c.style.display = "block";
					else c.style.display = "none";
					links[j].onclick = function ()
					{
						var c = document.getElementById(this.href.substr(this.href.indexOf("#") + 1));
						if (c)
						{
							//reset all tabs before change
							for (var i = 0; i < this.tabs.length; i++)
							{
								document.getElementById(this.tabs[i].href.substr(this.tabs[i].href.indexOf("#") + 1)).style.display = "none";
								this.tabs[i].className = this.tabs[i].className.replace("active", "");
							}
							this.className += " active";
							c.style.display = "block";
							return false;
						}
					}
				}
			}
		}
	}
}
function displayPopup(hold_id, popup_id, btn_class) {
	var _hold = document.getElementById(hold_id);
	var _popup = document.getElementById(popup_id);
	
	if(_hold && _popup){
		var _btn = _hold.getElementsByTagName('a');
		for(var i=0; i < _btn.length; i++) {
			if(_btn[i].className.indexOf(btn_class) != -1) {
				_btn[i].onclick = function() {
					var t_popup_text = this.parentNode.getElementsByTagName('div');
					var popup_text = null;
					for(var j = 0; j < t_popup_text.length; j++) {
						if(t_popup_text[j].className.indexOf('popup-text') != -1) { popup_text = t_popup_text[j].innerHTML;}
					}
					if(popup_text) {
						var _top = getAbsoluteTop(this);
						var _left = getAbsoluteLeft(this);
						_popup.innerHTML = popup_text;
						if (window.attachEvent && !window.opera && (typeof(hideSelectBoxes) == 'function')){ showSelectBoxes(document.body);}
						_popup.style.display = 'block';
						if(typeof(initRollovers) == 'function'){ initRollovers();}
						_popup.style.top = _top - _popup.offsetHeight + 'px';
						_popup.style.left = _left + 'px';
						if (window.attachEvent && !window.opera && (typeof(hideSelectBoxes) == 'function')){ hideSelectBoxes(_popup);}
						var btn_close = _popup.getElementsByTagName('a');
						for(var j = 0; j < btn_close.length; j++) {
							if(btn_close[j].className.indexOf('close') != -1){
								btn_close[j].onclick = function(){
									if (window.attachEvent && !window.opera && (typeof(hideSelectBoxes) == 'function')){ showSelectBoxes(_popup);}
									_popup.style.display = 'none';
									_popup.innerHTML = '';
									return false;
								}
							}
						}
						return false;
					}
				}
			}
		}
	}
}
function getAbsoluteTop(obj) {
	var posTop = 0;
	while (obj.offsetParent) {posTop += obj.offsetTop; obj = obj.offsetParent;}
	return posTop;
}
function getAbsoluteLeft(obj) {
	var posLeft = 0;
	while (obj.offsetParent) {posLeft += obj.offsetLeft; obj = obj.offsetParent;}
	return posLeft;
}
function ieHover()
{
	var nav = document.getElementById("navigation");
	if (nav)
	{
		var nodes = nav.getElementsByTagName("li");
		for (var i=0; i<nodes.length; i++)
		{
			nodes[i].onmouseover = function() 
			{
				this.className += " hover";
				var t_box = this.getElementsByTagName('div')[0];
				if (window.attachEvent && !window.opera && t_box && (typeof(hideSelectBoxes) == 'function')){ hideSelectBoxes(t_box);}
			}
			nodes[i].onmouseout = function()
			{
				var t_box = this.getElementsByTagName('div')[0];
				if (window.attachEvent && !window.opera && t_box && (typeof(showSelectBoxes) == 'function')){ showSelectBoxes(t_box);}
				this.className = this.className.replace(" hover", "");
			}
		}
	}
	var nav = document.getElementById("gallery-list");
	if (nav)
	{
		var nodes = nav.getElementsByTagName("li");
		for (var i=0; i<nodes.length; i++)
		{
			nodes[i].onmouseover = function() 
			{
				this.className += " hover";
			}
			nodes[i].onmouseout = function()
			{
				this.className = this.className.replace(" hover", "");
			}
		}
	}
	var nav = document.getElementById("myprogram-calendar");
	if (nav)
	{
		var nodes = nav.getElementsByTagName("td");
		for (var i=0; i<nodes.length; i++)
		{
			nodes[i].onmouseover = function() 
			{
				this.className += " hover";
			}
			nodes[i].onmouseout = function()
			{
				this.className = this.className.replace(" hover", "");
			}
		}
	}
}

function init_rasFavourite()
{
	var ras = $('rasbox-favourite');
	if(ras)
	{
		var id_ras = ras.name;

		new Ajax.Request('/public_panel/includes/ajax/ras_favourite.php', {
			method: 'get',
			parameters: {id: id_ras},
		  
			onSuccess: function(transport){
				var response = transport.responseText;
				$('rasbox-favourite').innerHTML = response;
			},
			onComplete: function(){ control_rasFavourite(); }
		  });
	}
}

function control_rasFavourite()
{
	var ras = $('rasbox-favourite');
	var ras_box = $('rasbox-favourite-box');
	
	if(ras)
	{
		var id_ras = ras.name;
		ras_box.onclick = function()
		{
			new Ajax.Request('/public_panel/includes/ajax/ras_favourite.php', {
				method: 'get',
				parameters: {id: id_ras, action: 'switch'},
			  
				onSuccess: function(){ init_rasFavourite(); },
				onFailure: function(){ init_rasFavourite(); }
			  });

		}
	}	
}

function init_starRating()
{

	var rating = $('rasbox-rating');
	var initResponse;

	if(rating)
	{
		var id_ras = rating.title;

		new Ajax.Request('/public_panel/includes/ajax/ras_rate_it.php', {
			method: 'get',
			parameters: {id: id_ras, rate: 0},
		  
			onSuccess: function(transport){
				initResponse = transport.responseText;
				$('rasbox-rating').innerHTML = initResponse;
			},
			onComplete: function(){ control_starRating(); }
		  });
	}
}


function control_starRating()
{

	var rating = $('rasbox-rating');
	var stars = $('ras-rate-container');
	var current_rating = 0;
	var nodes, i, j;
	var id_ras = rating.title;

	//Getting the current rating
	nodes = stars.getElementsByTagName("a");
	for (i=0; i<nodes.length; i++)
	{
		if(nodes[i].className.indexOf('ras-star-active') != -1)
		{
			star_number = nodes[i].id.replace("ras-rate-", "") * 1;
			if(star_number > current_rating)
			{
				current_rating = star_number;
			}
		}
	}
	// -- end -- 

	for (i=0; i<nodes.length; i++)
	{
		nodes[i].onmouseover = function() 
		{
			this_rate = this.id.replace("ras-rate-", "") * 1;

			for(j=1; j<=5; j++)
			{
				$('ras-rate-'+j).className = $('ras-rate-'+j).className.replace(" ras-star-active", "");
			}
			for(j=1; j<=this_rate; j++)
			{
				$('ras-rate-'+j).className += " ras-star-active";
			}
		}

		nodes[i].onmouseout = function()
		{
			for(j=1; j<=5; j++)
			{
				$('ras-rate-'+j).className =$('ras-rate-'+j).className.replace(" ras-star-active", "");
			}
			for(j=1; j<=current_rating; j++)
			{
				$('ras-rate-'+j).className += " ras-star-active";
			}
		}

		nodes[i].onclick = function()
		{
			this_rate = this.id.replace("ras-rate-", "") * 1;
			if(this_rate >= 1 && this_rate <= 5)
			{
				new Ajax.Request('/public_panel/includes/ajax/ras_rate_it.php', {
					method: 'get',
					parameters: {id: id_ras, rate: this_rate},
					  
					onSuccess: function(){ init_starRating(); },
					onFailure: function(){ init_starRating(); }
				  });
			}
		}


	}
	
}


function WBM_gotoURL(_url)
{
	if(_url != '')
	{
		window.location = _url;
	}
}

function WBM_Facebook_click()
{
	var _url = location.href;
	var _title = document.title;
	window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(_url)+'&t='+encodeURIComponent(_title),'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}
function WBM_Delicious_click()
{
	var _url = location.href;
	var _title = document.title;
	window.open('http://del.icio.us/post?url='+encodeURIComponent(_url)+'&title='+encodeURIComponent(_title),'delicious_sharer','toolbar=0,status=0,width=850,height=600');
	return false;
}

function WBM_Digg_click()
{
	var _url = location.href;
	var _title = document.title;
	window.open('http://digg.com/submit?phase=2&url='+encodeURIComponent(_url),'digg_sharer','scrollbars=1,toolbar=0,status=0,width=950,height=700');
	return false;
}



function WBM_checkIncorrectPassword_form()
{
	var _username = document.getElementById('pbox_frm_username');
	var _password = document.getElementById('pbox_frm_password');

	var _has_errors = false;

	if(_username.value == '')
	{
		_username.style.borderColor = '#FF8C00';
		_has_errors = true;
		_username.focus();
		return false;
	}
	else
	{
		_username.style.borderColor = '#C3C3C3';
	}

	if(_password.value == '')
	{
		_password.style.borderColor = '#FF8C00';
		_has_errors = true;
		_password.focus();
		return false;
	}
	else
	{
		_password.style.borderColor = '#C3C3C3';
	}

	if(_has_errors == true)
	{
		return false;
	}
	else
	{
		document.pbox_form.submit();
	}

}

function WBM_checkForgotPassword_form()
{
	var _username = document.getElementById('pbox_frm_username');

	var _has_errors = false;

	if(_username.value == '')
	{
		_username.style.borderColor = '#FF8C00';
		_has_errors = true;
		_username.focus();
		return false;
	}
	else
	{
		_username.style.borderColor = '#C3C3C3';
	}

	if(_has_errors == true)
	{
		return false;
	}
	else
	{
		document.pbox_form.submit();
	}

}


function WBM_checkCreatePassword_form()
{
	var _password = document.getElementById('pbox_frm_password');
	var _confirm = document.getElementById('pbox_frm_confirm');

	var _has_errors = false;

	if(_password.value == '')
	{
		_password.style.borderColor = '#FF8C00';
		_has_errors = true;
		_password.focus();
		return false;
	}
	else
	{
		_password.style.borderColor = '#C3C3C3';
	}

	if(_confirm.value == '')
	{
		_confirm.style.borderColor = '#FF8C00';
		_has_errors = true;
		_confirm.focus();
		return false;
	}
	else
	{
		_confirm.style.borderColor = '#C3C3C3';
	}

	if(_password.value != '' && _confirm.value != '' && _confirm.value != _password.value)
	{
		_password.style.borderColor = 'red';
		_confirm.style.borderColor = 'red';
		_has_errors = true;
		_password.focus();
		return false;
	}

	if(_has_errors == true)
	{
		return false;
	}
	else
	{
		document.pbox_form.submit();
	}

}

function WBM_gotoItem(_id, _direction, _view, _category) {

	new Ajax.Request('/public_panel/includes/ajax/ras_homepage.php', {
		method: 'get',
		parameters: {item_id: _id, direction: _direction, viewDIV: _view, category: _category},
			  
		onSuccess: function(transport){
			var response = transport.responseText;
			document.getElementById(_view).innerHTML = response;
		},
		onFailure: function() { },
		onComplete: function() { main_height(); }
	});	

}

function WBM_documentPrint()
{
	window.print(); 
}

function WBM_communityProvider()
{
    var searchType = $('providerServiceType');
    var searchSubType = $('providerServiceSubType');
    var searchSubTypeContainer = $('search-sub-type-container');

    var serviceType = $('service-type');
	var serviceSubType = $('service-sub-type');
	var serviceSubTypeContainer = $('service-sub-type-container');

    var serviceType2 = $('service-type2');
	var serviceSubType2 = $('service-sub-type2');
	var serviceSubTypeContainer2 = $('service-sub-type-container2');

    var serviceType3 = $('service-type3');
	var serviceSubType3 = $('service-sub-type3');
	var serviceSubTypeContainer3 = $('service-sub-type-container3');

    var serviceType4 = $('service-type4');
	var serviceSubType4 = $('service-sub-type4');
	var serviceSubTypeContainer4 = $('service-sub-type-container4');   

    var serviceID = 'service-sub-type';
    var serviceName = 'service-sub-type';
    var serviceClass = 'inp-select';
    var serviceStyle = '';

    var searchID = 'providerServiceSubType';
    var searchName = 'providerServiceSubType';
    var searchClass = 'inp-select';
    var searchStyle = 'width: 132px;';

	if(serviceType && serviceSubType)
	{		
		serviceType.onchange = function()
		{
			new Ajax.Request('/public_panel/includes/ajax/provider_subtype.php', {
				method: 'get',
				parameters: {pos: this.value, sID: serviceID, sName: serviceName, sClass: serviceClass, sStyle: serviceStyle},
			  
				onSuccess: function(transport){
					var response = transport.responseText;
					serviceSubTypeContainer.innerHTML = response;
				}
			});
		}
	}

    if(serviceType2 && serviceSubType2)
	{		
		serviceType2.onchange = function()
		{
			new Ajax.Request('/public_panel/includes/ajax/provider_subtype.php', {
				method: 'get',
				parameters: {pos: this.value, sID: serviceID + '2', sName: serviceName + '2', sClass: serviceClass, sStyle: serviceStyle},
			  
				onSuccess: function(transport){
					var response = transport.responseText;
					serviceSubTypeContainer2.innerHTML = response;
				}
			});
		}
	}

    if(serviceType3 && serviceSubType3)
	{		
		serviceType3.onchange = function()
		{
			new Ajax.Request('/public_panel/includes/ajax/provider_subtype.php', {
				method: 'get',
				parameters: {pos: this.value, sID: serviceID + '3', sName: serviceName + '3', sClass: serviceClass, sStyle: serviceStyle},
			  
				onSuccess: function(transport){
					var response = transport.responseText;
					serviceSubTypeContainer3.innerHTML = response;
				}
			});
		}
	}

    if(serviceType4 && serviceSubType4)
	{		
		serviceType4.onchange = function()
		{
			new Ajax.Request('/public_panel/includes/ajax/provider_subtype.php', {
				method: 'get',
				parameters: {pos: this.value, sID: serviceID + '4', sName: serviceName + '4', sClass: serviceClass, sStyle: serviceStyle},
			  
				onSuccess: function(transport){
					var response = transport.responseText;
					serviceSubTypeContainer4.innerHTML = response;
				}
			});
		}
	}
   
    if(searchType && searchSubType)
	{	   
		searchType.onchange = function()
		{
			new Ajax.Request('/public_panel/includes/ajax/provider_subtype.php', {
				method: 'get',
				parameters: {pos: this.value, sID: searchID, sName: searchName, sClass: searchClass, sStyle: searchStyle, show_all: '1'},
			  
				onSuccess: function(transport){
					var response = transport.responseText;
					searchSubTypeContainer.innerHTML = response;
				}
			});
		}
	}
}

var WBM_providerFocus = true;
var WBM_providerError = false;
var WBM_providerValidDegrees = 0;
var WBM_providerTriedDegrees = 0;
var WBM_providerValidEmployment = 0;
var WBM_providerTriedEmployment = 0;

function WBM_provider_inputValidation(_element)
{
	if(_element.value == '' || _element.value*1 == 0)	
	{
		_element.style.border = '1px solid #FF0000';
	   
		WBM_providerError = true;

		if(WBM_providerFocus == true)
		{
			_element.focus();
			WBM_providerFocus = false;
		}
	}
	else
	{
		_element.style.borderColor = '#C3C3C3';
		return false;
	}
}

function WBM_provider_inputValidationDropDown(_element)
{
	if(_element.selectedIndex == 0)	
	{
		_element.style.border = '1px solid #FF0000';

		if(_element.id == 'service-type')
		{
			$('service-sub-type').style.border = '1px solid #FF0000';
		}
		WBM_providerError = true;

		if(WBM_providerFocus == true)
		{
			_element.focus();
			WBM_providerFocus = false;
		}
	}
	else
	{
		_element.style.borderColor = '#C3C3C3';
		return false;
	}
}

function WBM_provider_inputValidationDegree(_name, _year)
{
	var _validSet = true;

	if(_name.value + '' != '' && _year.value + '' != '')
	{
		_name.style.borderColor = '#C3C3C3';
		_year.style.borderColor = '#C3C3C3';

		WBM_providerTriedDegrees ++;
		WBM_providerValidDegrees ++;
		_validSet = true;
	}
	else if(_name.value + '' != '' || _year.value + '' != '')
	{
		_name.style.borderColor = (_name.value + '' == '') ? '#FF0000' : '#C3C3C3';
		_year.style.borderColor = (_year.value + '' == '') ? '#FF0000' : '#C3C3C3';

		WBM_providerTriedDegrees ++;
		_validSet = false;
	}
	else
	{
		_name.style.borderColor = '#C3C3C3';
		_year.style.borderColor = '#C3C3C3';
	}
}

function WBM_provider_inputValidationEmployment(_name, _year)
{
	var _validSet = true;

	if(_name.value + '' != '' && _year.value + '' != '')
	{
		_name.style.borderColor = '#C3C3C3';
		_year.style.borderColor = '#C3C3C3';

		WBM_providerTriedEmployment ++;
		WBM_providerValidEmployment ++;
		_validSet = true;
	}
	else if(_name.value + '' != '' || _year.value + '' != '')
	{
		_name.style.borderColor = (_name.value + '' == '') ? '#FF0000' : '#C3C3C3';
		_year.style.borderColor = (_year.value + '' == '') ? '#FF0000' : '#C3C3C3';

		WBM_providerTriedEmployment ++;
		_validSet = false;
	}
	else
	{
		_name.style.borderColor = '#C3C3C3';
		_year.style.borderColor = '#C3C3C3';
	}

}

function WBM_provider_inputConfirmValidation(_element, _element_confirm)
{
	var _inputsConfirmed = true;

	if(_element.value == '' || _element.value*1 == 0 || _element_confirm.value == '' || _element_confirm.value*1 == 0)
	{
		_inputsConfirmed = false;
	}
	else if(_element.value != _element_confirm.value)
	{
		_inputsConfirmed = false;
	}

	if(_inputsConfirmed == false)	
	{
		_element.style.borderColor = '#FF0000';
		_element_confirm.style.borderColor = '#FF0000';

		WBM_providerError = true;

		if(WBM_providerFocus == true)
		{
			_element.focus();
			WBM_providerFocus = false;
		}
	}
	else
	{
		_element.style.borderColor = '#C3C3C3';
		_element_confirm.style.borderColor = '#C3C3C3';
		return false;
	}
}


function WBM_provider_formCheck()
{
	var checkIt = $('community-provider-form') ? true : false;

	if(checkIt)
	{
		var _businessName = $('business-name');
		var _abnAcn = $('abn-acn');
		var _firstName = $('first-name');
		var _lastName = $('last-name');
		var _businessAddress = $('business-address');
		var _suburb = $('suburb');
		var _state = $('state');
		var _postcode = $('postcode');
		var _contactNumber = $('contact-number');
		var _email = $('email');
		var _confirmEmail = $('confirm-email');
		var _password = $('password');
		var _confirmPassword = $('confirm-password');
		var _serviceType = $('service-type');
		var _serviceSubType = $('service-sub-type');
		var _typeOfBusiness = $('type-of-business');

		var _degreesQualifications01 = $('degrees-qualifications-01');
		var _defreesQualificationsYear01 = $('year-completed-01');
		var _degreesQualifications02 = $('degrees-qualifications-02');
		var _defreesQualificationsYear02 = $('year-completed-02');
		var _degreesQualifications03 = $('degrees-qualifications-03');
		var _defreesQualificationsYear03 = $('year-completed-03');

		var _employmentHistory01 = $('employment-history-01');
		var _employmentYear01 = $('employment-year-01');
		var _employmentHistory02 = $('employment-history-02');
		var _employmentYear02 = $('employment-year-02');
		var _employmentHistory03 = $('employment-history-03');
		var _employmentYear03 = $('employment-year-03');

		$('button-apply').onclick = function()
		{
			WBM_providerFocus = true;
			WBM_providerError = false;

			WBM_providerValidDegrees = 0;
			WBM_providerTriedDegrees = 0;
			WBM_providerValidEmployment = 0;
			WBM_providerTriedEmployment = 0;

			WBM_provider_inputValidation(_businessName);
			WBM_provider_inputValidation(_abnAcn);
			WBM_provider_inputValidation(_firstName);
			WBM_provider_inputValidation(_lastName);
			WBM_provider_inputValidation(_businessAddress);
			WBM_provider_inputValidation(_suburb);
			WBM_provider_inputValidation(_state);
			WBM_provider_inputValidation(_postcode);
			WBM_provider_inputValidation(_contactNumber);
			WBM_provider_inputValidation(_email);
			WBM_provider_inputValidation(_confirmEmail);
			WBM_provider_inputValidation(_password);
			WBM_provider_inputValidation(_confirmPassword);			
			WBM_provider_inputValidation(_typeOfBusiness);

            WBM_provider_inputValidationDropDown(_serviceType);

			WBM_provider_inputConfirmValidation(_email, _confirmEmail);
			WBM_provider_inputConfirmValidation(_password, _confirmPassword);

			WBM_provider_inputValidationDegree(_degreesQualifications01, _defreesQualificationsYear01);
			WBM_provider_inputValidationDegree(_degreesQualifications02, _defreesQualificationsYear02);
			WBM_provider_inputValidationDegree(_degreesQualifications03, _defreesQualificationsYear03);

			WBM_provider_inputValidationEmployment(_employmentHistory01, _employmentYear01);
			WBM_provider_inputValidationEmployment(_employmentHistory02, _employmentYear02);
			WBM_provider_inputValidationEmployment(_employmentHistory03, _employmentYear03);

			if(WBM_providerTriedDegrees == 0)
			{
				WBM_provider_inputValidation(_degreesQualifications01);
				WBM_provider_inputValidation(_defreesQualificationsYear01);	
				WBM_providerError = true;
			}
			else if((WBM_providerTriedDegrees != WBM_providerValidDegrees) && (WBM_providerTriedDegrees > 0))
			{
				WBM_providerError = true;
			}

			if(WBM_providerTriedEmployment == 0)
			{
				WBM_provider_inputValidation(_employmentHistory01);
				WBM_provider_inputValidation(_employmentYear01);
				WBM_providerError = true;
			}
			else if((WBM_providerTriedEmployment != WBM_providerValidEmployment) && (WBM_providerTriedEmployment > 0))
			{
				WBM_providerError = true;
			}

			return (WBM_providerError == true ? false : true); 
		}
	}
}

function WBM_communityGroup()
{
	var communityGroupType = $('community-group-type');
	var communityGroupSubType = $('community-group-sub-type');
	var communityGroupSubTypeContainer = $('community-group-sub-type-container');

    var communityGroupSearchType = $('searchGroupType');
	var communityGroupSearchSubType = $('searchGroupSubType');
	var communityGroupSearchSubTypeContainer = $('community-group-search-sub-type-container');   

    var stdID = 'community-group-sub-type';
    var stdName = 'community-group-sub-type';
    var stdClass = 'inp-select';
    var stdStyle = '';

    var searchID = 'searchGroupSubType';
    var searchName = 'groupSubType';
    var searchClass = 'inp-select';
    var searchStyle = 'width: 132px;';

	if(communityGroupType && communityGroupSubType)
	{
        communityGroupType.onchange = function()
		{
			new Ajax.Request('/public_panel/includes/ajax/community_group_subtype.php', {
				method: 'get',
				parameters: {pos: this.value, sID: stdID, sName: stdName, sClass: stdClass, sStyle: stdStyle},
			  
				onSuccess: function(transport){
					var response = transport.responseText;
					communityGroupSubTypeContainer.innerHTML = response;
				}
			});
		}       
	}

    if(communityGroupSearchType && communityGroupSearchSubType)
	{
        communityGroupSearchType.onchange = function()
		{
			new Ajax.Request('/public_panel/includes/ajax/community_group_subtype.php', {
				method: 'get',
				parameters: {pos: this.value, sID: searchID, sName: searchName, sClass: searchClass, sStyle: searchStyle},
			  
				onSuccess: function(transport){
					var response = transport.responseText;
					communityGroupSearchSubTypeContainer.innerHTML = response;
				}
			});
		}
	}
}

var WBM_communityGroupFocus = true;
var WBM_communityGroupError = false;

function WBM_communityGroup_inputValidation(_element)
{
	if(_element.value == '' || _element.value*1 == 0)	
	{
		_element.style.border = '1px solid #FF0000';

		WBM_communityGroupError = true;

		if(WBM_communityGroupFocus == true)
		{
			_element.focus();
			WBM_communityGroupFocus = false;
		}
	}
	else
	{
		_element.style.borderColor = '#C3C3C3';
		return false;
	}
}

function WBM_communityGroup_inputValidationDropDown(_element)
{
	if(_element.selectedIndex == 0)	
	{
		_element.style.border = '1px solid #FF0000';

		if(_element.id == 'community-group-type')
		{
			$('community-group-sub-type').style.border = '1px solid #FF0000';
		}
		WBM_communityGroupError = true;

		if(WBM_communityGroupFocus == true)
		{
			_element.focus();
			WBM_communityGroupFocus = false;
		}
	}
	else
	{
		_element.style.borderColor = '#C3C3C3';
		return false;
	}
}

function WBM_communityGroup_formCheck()
{
	var checkIt = $('community-group-form') ? true : false;

	if(checkIt)
	{
		var _groupType = $('community-group-type');
		var _groupSubType = $('community-group-sub-type');
		var _groupName = $('group-name');
		var _groupLeader = $('group-leader');
		var _website = $('website');
		var _state = $('state');
		var _suburb = $('suburb');
		var _groupDescription = $('group-description');

		var _uploadTermsLabel = $('upload-terms');
		var _uploadTermsCheck = $('upload-pictures-check');
		var _uploadMainPicture = $('upload-picture');
		var _uploadMainPictureLabel = $('upload-picture-label');
		
		$('button-create').onclick = function()
		{
			WBM_communityGroupFocus = true;
			WBM_communityGroupError = false;

			WBM_communityGroup_inputValidationDropDown(_groupType);
			WBM_communityGroup_inputValidation(_groupName);
			WBM_communityGroup_inputValidation(_state);
			WBM_communityGroup_inputValidation(_suburb);

			return (WBM_communityGroupError == true ? false : true); 
		}
	}
}



/* ----------- RECOMMEND/SEND POPUP FORM CHECK --------------*/
var WBM_recommendFocus = true;
var WBM_recommendError = false;

function WBM_recommend_inputValidation(_element)
{
	if(_element.value == '' || _element.value*1 == 0)	
	{
		_element.style.border = '1px solid #FF0000';

		WBM_recommendError = true;

		if(WBM_recommendFocus == true)
		{
			_element.focus();
			WBM_recommendFocus = false;
		}
	}
	else
	{
		_element.style.borderColor = '#C3C3C3';
		return false;
	}
}



function WBM_recommend_formCheck()
{
	var checkIt = $('tell_a_friend_form2') ? true : false;

	if(checkIt)
	{
		var _name = $('name');
		var _email = $('email');
		var _friends_name = $('friends_name');
		var _friends_email = $('friends_email');
		var _message = $('message');
		var _validate = $('validate');
		
		if($('send'))
		{
			$('send').onclick = function()
			{
				WBM_recommendFocus = true;
				WBM_recommendError = false;

				WBM_recommend_inputValidation(_message);
				WBM_recommend_inputValidation(_name);
				WBM_recommend_inputValidation(_email);
				WBM_recommend_inputValidation(_friends_name);
				WBM_recommend_inputValidation(_friends_email);
				WBM_recommend_inputValidation(_validate);

				return (WBM_recommendError == true ? false : true); 
			}
		}

	}
}

/* my_profile_registration.php*/
var WBM_joinFocus = true;
var WBM_joinError = false;

function WBM_join_inputValidation(_element)
{
	if(_element.id == 'frm_birthdate_day')
	{
		if (_element.value == ''){
			$('lblbday').style.width = '44px';			
			$('lblbday').style.border = '1px solid #FF0000';
			_element.style.width = '44px';
		}else{
			$('lblbday').style.border = '0px solid #FF0000';
		}
	}
	if(_element.id == 'frm_birthdate_month')
	{
		if (_element.value == ''){
			$('lblmonth').style.width = '44px';			
			$('lblmonth').style.border = '1px solid #FF0000';
			_element.style.width = '44px';			
		}else{
			$('lblmonth').style.border = '0px solid #FF0000';
		}
	}
	if(_element.id == 'frm_birthdate_year')
	{
		if (_element.value == ''){
			$('lblyear').style.border = '1px solid #FF0000';
			$('lblyear').style.width = '64px';						
			_element.style.width = '64px';			
		}else{
			$('lblyear').style.border = '0px solid #FF0000';
		}
	}
	if(_element.id == 'frm_state')
	{
		if (_element.value == ''){
			$('lblstate').style.border = '1px solid #FF0000';
		}else{
			$('lblstate').style.border = '0px solid #FF0000';
		}
	}
	if(_element.id == 'frm_about_springday')
	{
		if (_element.value == ''){
			$('lblabout').style.border = '1px solid #FF0000';
		}else{
			$('lblabout').style.border = '0px solid #FF0000';
		}
	}
	if(_element.value == '' || _element.value*1 == 0)	
	{
		if(_element.id != 'frm_birthdate_day' && _element.id != 'frm_birthdate_month' && _element.id != 'frm_birthdate_year' && _element.id != 'frm_state' && _element.id != 'frm_about_springday'){
			_element.style.border = '1px solid #FF0000';

			WBM_joinError = true;

			if(WBM_joinFocus == true)
			{
				_element.focus();
				WBM_joinFocus = false;
			}
		}
	}
	else
	{
		_element.style.borderColor = '#C3C3C3';
		return false;
	}
}
function WBM_join_inputConfirmValidation(_element, _element_confirm)
{
	var _inputsConfirmed = true;

	if(_element.value == '' || _element.value*1 == 0 || _element_confirm.value == '' || _element_confirm.value*1 == 0)
	{
		_inputsConfirmed = false;
	}
	else if(_element.value != _element_confirm.value)
	{
		_inputsConfirmed = false;
	}

	if(_inputsConfirmed == false)	
	{
		_element.style.borderColor = '#FF0000';
		_element_confirm.style.borderColor = '#FF0000';

		WBM_joinError = true;

		if(WBM_joinFocus == true)
		{
			_element.focus();
			WBM_joinFocus = false;
		}
	}
	else
	{
		_element.style.borderColor = '#C3C3C3';
		_element_confirm.style.borderColor = '#C3C3C3';
		return false;
	}
}


function WBM_join_formCheck()
{
	var checkIt = $('button-proceed') ? true : false;

	if(checkIt)
	{
		var _firstName = $('frm_first_name');
		var _lastName = $('frm_last_name');
		var _userName = $('frm_user_name');
        var _address = $('frm_address');
		var _suburb = $('frm_suburb');
		var _state = $('frm_state');
		var _country = $('frm_country');
		var _postcode = $('frm_post_code');
        var _phonenumber = $('frm_phone_number');
		var _email = $('frm_email');
		var _confirmEmail = $('frm_confirm_email');
		var _password = $('frm_join_password');
		var _confirmPassword = $('frm_confirm_password');
		var _dob_day = $('frm_birthdate_day');
		var _dob_month = $('frm_birthdate_month');
		var _dob_year = $('frm_birthdate_year');
		var _hear_about = $('frm_about_springday');		

		$('button-proceed').onclick = function()
		{
			WBM_joinFocus = true;
			WBM_joinError = false;

			WBM_join_inputValidation(_email);
			WBM_join_inputValidation(_confirmEmail);
			WBM_join_inputValidation(_firstName);
			WBM_join_inputValidation(_lastName);
			WBM_join_inputValidation(_userName);
			WBM_join_inputValidation(_password);
			WBM_join_inputValidation(_confirmPassword);
			WBM_join_inputValidation(_country);
			WBM_join_inputValidation(_state);
            WBM_join_inputValidation(_address);
			WBM_join_inputValidation(_suburb);
            WBM_join_inputValidation(_phonenumber);
			WBM_join_inputValidation(_postcode);
			WBM_join_inputValidation(_dob_day);
			WBM_join_inputValidation(_dob_month);
			WBM_join_inputValidation(_dob_year);
			WBM_join_inputValidation(_hear_about);

			WBM_join_inputConfirmValidation(_email, _confirmEmail);
			WBM_join_inputConfirmValidation(_password, _confirmPassword);

			return (WBM_joinError == true ? false : true); 
		}
	}
}

function WBM_joinFemale_extra(_gender)
{
	$('M_F').style.display = _gender == 'Female' ? 'block' : 'none';
}

function WBM_deleteSingleUploadImage() 
{
    $('id_image_uploaded').hide();
    $('id_no_image_uploaded').show();
    $('id_uploaded_file_link').hide();

    $('frm_inp_check_01').checked = false;

    $('id_temp_uploaded').value = '';
    $('frm_temp_code').value = '';
    $('is_preloaded').value = '';
    $('frm_preloaded_file').value = '';
}

function WBM_deleteMultipleUploadImage(_id) 
{
    if(_id == 0)
    {
        $('id_no_image_uploaded_' + _id).show();
    }

    $('id_image_uploaded_' + _id).hide();
    $('id_uploaded_file_link_' + _id).hide();
      
    $('id_temp_uploaded_' + _id).value = '';
    $('frm_temp_code_' + _id).value = '';
    $('is_preloaded_' + _id).value = '';
    $('frm_preloaded_file_' + _id).value = '';

    var _checked_status;

    _checked_status = false;
    for(i=0;i<4;i++)
    {
        if( ($('frm_preloaded_file_' + i).value != '')
            || ($('is_preloaded_' + i).value != '')
            || ($('frm_temp_code_' + i).value != '')
            || ($('id_temp_uploaded_' + i).value != '') )
            {
                _checked_status = true;
            }
    }

    $('frm_inp_check_01').checked = _checked_status;
}

/*end - my_profile_registration.php*/

function WBM_recommendPopup()
{
	window.open('/public_panel/tell_a_friend.php?label=Recommend', 'tell_a_friend', 'resizable=0, width=292, height=277');
}
function WBM_sendPopup()
{
	window.open('/public_panel/tell_a_friend.php?label=Send', 'tell_a_friend', 'resizable=0, width=292, height=277');
}
function WBM_addFriendPopup(_id)
{
    window.open('/public_panel/add_friend.php?id=' + _id, 'add_friend', 'resizable=0, width=279, height=163');
}
function WBM_requestChatPopup(_id)
{
    window.open('/public_panel/request_chat.php?id=' + _id, 'request_chat', 'resizable=0, width=279, height=163');
}
function WBM_inviteFriendstoJoinPopup(_id)
{
	window.open('/public_panel/invite_friends_to_join.php?id=' + _id, 'invite_friends_to_join', 'resizable=0, width=265, height=461');
}
function WBM_inviteFriendsToJoinSpringdayPopup(_id)
{
	window.open('/public_panel/invite_friends.php', 'invite_friends', 'resizable=0, width=265, height=160');
}
function WBM_smallRequestPopupClose()
{
	setTimeout("window.close()", 3000);
}

function WBM_load_graph_data (_chart_id,_data_file,_view){

	$(_chart_id+'_week').className='';
	$(_chart_id+'_month').className='';
	$(_chart_id+'_year').className='';
	$(_chart_id+'_'+_view).className='in-select';

	chart_id = _chart_id+'_chart';
	viewID = _chart_id+_view;

	new Ajax.Request('/public_panel/includes/ajax/'+_data_file, {
		method: 'post',
		parameters: {view: _view, save_state: 'yes'},
		onSuccess: function(transport){
			var response = transport.responseText;
			var t = findSWF(chart_id); 
			t.load(response);
			//$(_view).innerHTML = response;
		},
		onFailure: function() { }
	});
}

function findSWF(movieName) {
 /* if (navigator.appName.indexOf("Microsoft")!= -1) {
    return window["ie_" + movieName];
  } else {*/
    return document[movieName];
  //}
}


function WBM_profileGallery_uploadOpen()
{
	window.open('/public_panel/my_profile_photo_gallery_upload.php', 'upload_photo', 'resizable=0,width=385,height=175');
}

function WBM_profileGallery_uploadFinish()
{
	var _opener = window.opener;

	if(_opener)
	{
		var _opener_location = _opener.location.toString();
		_opener.location = _opener_location;
	}

	setTimeout("window.close()", 3000);
}

function WBM_profileGallery_doUploadFile()
{
	var checkIt = $('upload-gal-btn') ? true : false;

	if(checkIt)
	{
		$('upload-gal-btn').onclick = function()
		{
			var _photo_title = $('frm_title');
			var _photo_title_label = $('frm_title_label');

			var _photo_file = $('frm_photo');
			var _photo_file_label = $('frm_photo_label');

			var _has_errors = false;


			if(_photo_title.value == '')
			{
				_has_errors = true;
				_photo_title_label.style.color = '#FF0000';
			}
			else
			{
				_photo_title_label.style.color = '#000000';
			}

			if(_photo_file.value == '')
			{
				_has_errors = true;
				_photo_file_label.style.color = '#FF0000';
			}
			else
			{
				_photo_file_label.style.color = '#000000';
			}

			return (_has_errors == false ? true : false);
		}

	}
}

function WBM_openWindow(url, PageWidth, PageHeight, _scrollbars, _status)
{
	var popleft = ((document.body.clientWidth - PageWidth) / 2) + window.screenLeft;
	var poptop = ((( document.body.clientHeight - PageHeight) / 2)) + window.screenTop-40;
		
	str = "" + Math.random() + "";
	_unique_id = str.substr(2, str.length);
		
	window.open(url, _unique_id ,"status=" + _status + ",resizable=0,scrollbars=" + _scrollbars + ",width=" + PageWidth + ",height=" + PageHeight + ",left=" + popleft + ",top=" + poptop);
}


/*------------- MY PROGRAM -------------*/
function myProgram_init()
{
	if($('my-this-week-total'))
	{
		myProgram_thisWeekTotal();
	}
	if($('my-progressive-total'))
	{
		myProgram_progressiveTotal();
	}
	if($('myprogram-calendar'))
	{
		myProgram_dayPoints();
	}
}

function myProgram_progressiveTotal()
{
	var _points = $('my-progressive-total');

	new Ajax.Request('/public_panel/includes/ajax/myday_update.php', {
		method: 'get',
		parameters: {action: 'points', type: 'progressive'},
					  
		onComplete: function(transport){
			initResponse = transport.responseText;
			_points.innerHTML = initResponse;
		}			
	});
}

function myProgram_thisWeekTotal()
{
	var _points = $('my-this-week-total');

	new Ajax.Request('/public_panel/includes/ajax/myday_update.php', {
		method: 'get',
		parameters: {action: 'points', type: 'this_week', prefix: 'THIS WEEK: '},
					  
		onComplete: function(transport){
			initResponse = transport.responseText;
			_points.innerHTML = initResponse;
		}			
	});
}

function myProgram_editMyDay(_hash)
{
	 WBM_openWindow('my_program_edit_my_day.php?d='+_hash, 300, 410, 1, 0)
}
function myProgram_previewMyDay(_hash, _id_prg)
{
	 WBM_openWindow('my_program_edit_my_day.php?id='+_id_prg+'&d='+_hash, 300, 321, 1, 0)
}
function myProgram_editMyExercise(_hash)
{
	 WBM_openWindow('my_program_edit_my_day.php?d='+_hash+'&mode=exercise', 300, 410, 1, 0)
}
function myProgram_editMyRelaxation(_hash)
{
	 WBM_openWindow('my_program_edit_my_day.php?d='+_hash+'&mode=relaxation', 300, 410, 1, 0)
}

function myProgram_dayPoints()
{
	_calendar = $('myprogram-calendar');
	_days = _calendar.getElementsByTagName("span");


	for(var i=0; i < _days.length; i++)
	{
		if(_days[i].id.indexOf('myprogram-daypoints-') != -1)
		{
			var _date = _days[i].id.replace('myprogram-daypoints-', '');
			var _day = _days[i];

			new Ajax.PeriodicalUpdater(_days[i].id, '/public_panel/includes/ajax/myday_update.php', {
				method: 'get', frequency: 3, decay: 2,
				parameters: {action: 'points', type: 'all', date: _date, prefix: 'Points: '}		
			});
		}
	}


}
/*------------- MY PROGRAM EDIT POPUP -------------*/

function editMyDay_switchTo(_type)
{
	if(_type == 'exercise')
	{
		$('type_MYPRG').value = 'exercise';
		$('edit-my-day-exercise').style.display = 'block';
		$('edit-my-day-note').style.display = 'none';
		$('edit-my-day-relaxation').style.display = 'none';
	}

	if(_type == 'note')
	{
		$('type_MYPRG').value = 'note';
		$('edit-my-day-exercise').style.display = 'none';
		$('edit-my-day-note').style.display = 'block';
		$('edit-my-day-relaxation').style.display = 'none';
	}
	
	if(_type == 'relaxation')
	{
		$('type_MYPRG').value = 'relaxation';
		$('edit-my-day-exercise').style.display = 'none';
		$('edit-my-day-note').style.display = 'none';
		$('edit-my-day-relaxation').style.display = 'block';
	}

}

function editMyDay_selectExercise(_value)
{
	$('custom_exercise_MYPRG').style.display = (_value + '' == '') ? 'block' : 'none';
}
/*------------ end --- MY PROGRAM EDIT POPUP -------------*/



/* ---------------- MY DAY -----------------*/
var myDay_date_PRG;

function myDay_init()
{
	if($('date_MYPRG'))
	{
		myDay_date_PRG = $('date_MYPRG').value;
		
		if($('my-progressive-total'))
		{
			myProgram_progressiveTotal();
		}
		if($('my-this-week-total'))
		{
			myProgram_thisWeekTotal();
		}
		if($('myday-rating'))
		{
			init_myDay_starRating();
		}
		if($('myday-exercise-points'))
		{
			myDay_exercise();
		}
		if($('myday-relaxation-points'))
		{
			myDay_relaxation();
		}
		if($('myday-nutrition-points'))
		{
			myDay_nutrition();
		}
		if($('myday-water-points'))
		{
			myDay_water();
		}
		if($('myday-sleep-points'))
		{
			myDay_sleep();
		}
		if($('myday-notes'))
		{
			init_myDay_notes();
		}
		if($('myday-daily-points'))
		{
			myDay_dailyPoints();
		}
		if($('auto_print_page'))
		{
			WBM_documentPrint();
		}


	}
}

function myDay_printTodayProgram(_date)
{
	WBM_openWindow('my_day_exercise_print.php?d='+_date, 610, 650, 1, 0)
}


/*-----daily points---*/
function myDay_onChange()
{
	myDay_dailyPoints();
	myProgram_progressiveTotal();
	myProgram_thisWeekTotal();
}

function myDay_dailyPoints()
{
	var _points = $('myday-daily-points');

	new Ajax.Request('/public_panel/includes/ajax/myday_update.php', {
		method: 'get',
		parameters: {action: 'points', type: 'all', date: myDay_date_PRG},
					  
		onComplete: function(transport){
			initResponse = transport.responseText;
			_points.innerHTML = initResponse;
		}			
	});

}
/*-----daily points---*/


/*----relaxation items--*/
function myDay_relaxationPoints()
{
	var _points = $('myday-relaxation-points');

	new Ajax.Request('/public_panel/includes/ajax/myday_update.php', {
		method: 'get',
		parameters: {action: 'points', type: 'relaxation', date: myDay_date_PRG},
					  
		onComplete: function(transport){
			initResponse = transport.responseText;
			_points.innerHTML = initResponse;
			myDay_onChange();
		}			
	});
}
function myDay_relaxation()
{
	myDay_relaxationPoints();

	var _items = $('myday-relaxation-items');

	if(_items)
	{
		_nodes = _items.getElementsByTagName("input");

		for(var i=0; i < _nodes.length; i++)
		{
			if(_nodes[i].id.indexOf('myday-relaxation-item-') != -1)
			{
				_nodes[i].onclick = function()
				{
					_item_id = this.id.replace('myday-relaxation-item-', '') * 1;
					_item_done = this.checked == true ? 1 : 0;

					new Ajax.Request('/public_panel/includes/ajax/myday_update.php', {
						method: 'get',
						parameters: {action: 'done', type_MYPRG: 'relaxation', id_MYPRG: _item_id, done_MYPRG: _item_done, date: myDay_date_PRG},
						  
						onComplete: function(transport){ myDay_relaxationPoints(); }
					  });

				}
			}
		}
	}
}
/*--end--relaxation items--*/



/*----exercise items--*/
function myDay_exercisePoints()
{
	var _points = $('myday-exercise-points');

	new Ajax.Request('/public_panel/includes/ajax/myday_update.php', {
		method: 'get',
		parameters: {action: 'points', type: 'exercise', date: myDay_date_PRG},
					  
		onComplete: function(transport){
			initResponse = transport.responseText;
			_points.innerHTML = initResponse;
			myDay_onChange();
		}			
		
	});
}

function myDay_exercise()
{
	myDay_exercisePoints();

	var _items = $('myday-exercise-items');

	if(_items)
	{
		_nodes = _items.getElementsByTagName("input");

		for(var i=0; i < _nodes.length; i++)
		{
			if(_nodes[i].id.indexOf('myday-exercise-item-') != -1)
			{
				_nodes[i].onclick = function()
				{
					_item_id = this.id.replace('myday-exercise-item-', '') * 1;
					_item_done = this.checked == true ? 1 : 0;

					new Ajax.Request('/public_panel/includes/ajax/myday_update.php', {
						method: 'get',
						parameters: {action: 'done', type_MYPRG: 'exercise', id_MYPRG: _item_id, done_MYPRG: _item_done, date: myDay_date_PRG},
						  
						onComplete: function(transport){ myDay_exercisePoints();}
					  });

				}
			}
		}
	}
}
/*--end--exercise items--*/

/*-----notes--*/
function list_myDay_notes()
{
	new Ajax.Request('/public_panel/includes/ajax/myday_notes.php', {
		method: 'get',
		parameters: {date: myDay_date_PRG},
		  
		onSuccess: function(transport){
			initResponse = transport.responseText;
			$('myday-notes').innerHTML = initResponse;
			control_myDay_notes();
		}
	  });
}


function control_myDay_notes()
{
	var _notes = $('myday-notes');
	
	_nodes = _notes.getElementsByTagName("a");
	for (i=0; i < _nodes.length; i++)
	{
		//-----delete
		if(_nodes[i].id.indexOf('myday-note-delete-') != -1)
		{
			_note_id = _nodes[i].id.replace('myday-note-delete-', '') * 1;
			
			_nodes[i].onclick = function()
			{
				_note_id = this.id.replace('myday-note-delete-', '') * 1;

				new Ajax.Request('/public_panel/includes/ajax/myday_notes.php', {
					method: 'get',
					parameters: {action: 'delete', id: _note_id},
					onComplete: function(){ list_myDay_notes(); }
				  });
			}
		}

		//-----edit
		if(_nodes[i].id.indexOf('myday-note-edit-') != -1)
		{
			_note_id = _nodes[i].id.replace('myday-note-edit-', '') * 1;
			
			_nodes[i].onclick = function()
			{
				_note_id = this.id.replace('myday-note-edit-', '') * 1;

				$('myday-note-preview-container-' + _note_id).style.display = 'none';
				$('myday-note-edit-container-' + _note_id).style.display = 'block';

				$('myday-update-but-' + _note_id).onmouseover = function()
				{
					this.src = this.src.replace('btn-update.gif', 'btn-update-hover.gif');
				}

				$('myday-update-but-' + _note_id).onmouseout = function()
				{
					this.src = this.src.replace('btn-update-hover.gif', 'btn-update.gif');
				}

				$('myday-update-but-' + _note_id).onclick = function()
				{
					new Ajax.Request('/public_panel/includes/ajax/myday_notes.php', {
						method: 'get',
						parameters: {action: 'update', note: $('myday-update-note-' + _note_id).value, id: _note_id},
						onComplete: function(){ list_myDay_notes(); }
					});
				}


			}
		}

	}
}
function init_myDay_notes()
{
	list_myDay_notes();

	var _notes = $('myday-notes');

	$('myday-new-note').onclick = function()
	{
		var _new_note = $('myday-new-note');
		_new_note.value = _new_note.value == 'Enter your note here' ? '' : _new_note.value;
	}
	$('myday-new-note').onblur = function()
	{
		var _new_note = $('myday-new-note');
		_new_note.value = _new_note.value == '' ? 'Enter your note here' : _new_note.value;
	}

	$('myday-new-note-add').onclick = function()
	{
		var _new_note = $('myday-new-note');
		if(_new_note.value == '' || _new_note.value == 'Enter your note here')
		{
			_new_note.value = 'Enter your note here';
			_new_note.select();
		}
		else
		{

			new Ajax.Request('includes/ajax/myday_notes.php', {
				method: 'get',
				parameters: {action: 'add', note: _new_note.value, date: $('date_MYPRG').value},
				onSuccess: function(){ _new_note.value = 'Enter your note here'; list_myDay_notes(); }
			  });
		}
	}	 
}
/*-----end STAR RATING---*/



/*-----star rating--*/
function get_myDay_starRating(_allow)
{
	var rating = $('myday-rating');
	
	if(rating)
	{
		new Ajax.Request('/public_panel/includes/ajax/myday_rate_it.php', {
			method: 'get',
			parameters: {rate: 0, date: myDay_date_PRG},
		  
			onSuccess: function(transport){
				initResponse = transport.responseText;
				$('myday-rating').innerHTML = initResponse;
			},
			onComplete: function(){ if(_allow * 1 == 1) {control_myDay_starRating();}else{ rating.style.cursor = 'default'; } }
		  });
	}

}



function init_myDay_starRating()
{
	var rating = $('myday-rating');
	var initResponse;

	if(rating)
	{
		new Ajax.Request('/public_panel/includes/ajax/myday_rate_it.php', {
			method: 'get',
			parameters: {rate: 0, date: myDay_date_PRG, action: 'allow_rate'},
		  
			onSuccess: function(transport){
				initResponse = transport.responseText;
				get_myDay_starRating(initResponse);
			}
		  });
	}
}


function control_myDay_starRating()
{

	var rating = $('myday-rating');
	var stars = $('myday-rate-container');
	var current_rating = 0;
	var nodes, i, j;
	var id_ras = rating.title;

	//Getting the current rating
	nodes = stars.getElementsByTagName("a");
	for (i=0; i<nodes.length; i++)
	{
		if(nodes[i].className.indexOf('myday-star-active') != -1)
		{
			star_number = nodes[i].id.replace("myday-rate-", "") * 1;
			if(star_number > current_rating)
			{
				current_rating = star_number;
			}
		}
	}
	// -- end -- 

	for (i=0; i<nodes.length; i++)
	{
		nodes[i].onmouseover = function() 
		{
			this_rate = this.id.replace("myday-rate-", "") * 1;

			for(j=1; j<=5; j++)
			{
				$('myday-rate-'+j).className = $('myday-rate-'+j).className.replace(" myday-star-active", "");
			}
			for(j=1; j<=this_rate; j++)
			{
				$('myday-rate-'+j).className += " myday-star-active";
			}
		}

		nodes[i].onmouseout = function()
		{
			for(j=1; j<=5; j++)
			{
				$('myday-rate-'+j).className =$('myday-rate-'+j).className.replace(" myday-star-active", "");
			}
			for(j=1; j<=current_rating; j++)
			{
				$('myday-rate-'+j).className += " myday-star-active";
			}
		}

		nodes[i].onclick = function()
		{
			this_rate = this.id.replace("myday-rate-", "") * 1;
			if(this_rate >= 1 && this_rate <= 5)
			{
				new Ajax.Request('/public_panel/includes/ajax/myday_rate_it.php', {
					method: 'get',
					parameters: {rate: this_rate, date: myDay_date_PRG},
					  
					onSuccess: function(){ init_myDay_starRating(); },
					onFailure: function(){ init_myDay_starRating(); }
				  });
			}
		}


	}	
}
/*-----end STAR RATING---*/




/*----------- NUTRITION---*/
function myDay_nutritionInit(_subtype)
{
	new Ajax.Request('/public_panel/includes/ajax/myday_update.php', {
		method: 'get',
		parameters: {action: 'get', type: 'nutrition', subtype: _subtype, date: myDay_date_PRG},
					  
		onComplete: function(transport){
			initResponse = transport.responseText;
			$('myday-nutrition-'+_subtype).value = initResponse;
		}			
		
	});
}

function myDay_nutritionUpdate(_subtype)
{
	var _element = $('myday-nutrition-'+_subtype);
	_element.onchange = function()
	{
		new Ajax.Request('/public_panel/includes/ajax/myday_update.php', {
			method: 'get',
			parameters: {action: 'set', type: 'nutrition', subtype: _subtype, value: _element.value, date: myDay_date_PRG},
						  
			onSuccess: function(){ myDay_nutritionPoints(); },
			onFailure: function(){ myDay_nutritionPoints(); }
		});
	}
}

function myDay_nutritionPoints()
{
	var _points = $('myday-nutrition-points');

	new Ajax.Request('/public_panel/includes/ajax/myday_update.php', {
		method: 'get',
		parameters: {action: 'points', type: 'nutrition', date: myDay_date_PRG},
					  
		onComplete: function(transport){
			initResponse = transport.responseText;
			_points.innerHTML = initResponse;
			myDay_onChange();
		}			
		
	});
}

function myDay_nutrition()
{
	var _points = $('myday-nutrition-points');
	var _items = new Array('breakfast', 'snack1', 'lunch', 'snack2', 'dinner', 'alcohol');

	myDay_nutritionPoints();

	for(i=0; i<_items.length; i++)
	{
		myDay_nutritionInit(_items[i]);
		myDay_nutritionUpdate(_items[i]);
	}
}
/*----------- end NUTRITION---*/



/*----------- WATER---*/
function myDay_waterInit()
{
	new Ajax.Request('/public_panel/includes/ajax/myday_update.php', {
		method: 'get',
		parameters: {action: 'get', type: 'water', date: myDay_date_PRG},
					  
		onComplete: function(transport){
			initResponse = transport.responseText;
			$('myday-water').value = initResponse;
		}			
		
	});
}

function myDay_waterUpdate()
{
	var _element = $('myday-water');
	_element.onchange = function()
	{
		new Ajax.Request('/public_panel/includes/ajax/myday_update.php', {
			method: 'get',
			parameters: {action: 'set', type: 'water', value: _element.value, date: myDay_date_PRG},
						  
			onSuccess: function(){ myDay_waterPoints(); },
			onFailure: function(){ myDay_waterPoints(); }
		});
	}
}

function myDay_waterPoints()
{
	var _points = $('myday-water-points');

	new Ajax.Request('/public_panel/includes/ajax/myday_update.php', {
		method: 'get',
		parameters: {action: 'points', type: 'water', date: myDay_date_PRG},
					  
		onComplete: function(transport){
			initResponse = transport.responseText;
			_points.innerHTML = initResponse;
			myDay_onChange();
		}			
		
	});
}

function myDay_water()
{
	myDay_waterPoints();
	myDay_waterInit();
	myDay_waterUpdate();
}
/*----------- end WATER---*/


/*----------- SLEEP---*/
function myDay_sleepInit()
{
	new Ajax.Request('/public_panel/includes/ajax/myday_update.php', {
		method: 'get',
		parameters: {action: 'get', type: 'sleep', date: myDay_date_PRG},
					  
		onComplete: function(transport){
			initResponse = transport.responseText;
			$('myday-sleep').value = initResponse;
		}			
		
	});
}

function myDay_sleepUpdate()
{
	var _element = $('myday-sleep');
	_element.onchange = function()
	{
		new Ajax.Request('/public_panel/includes/ajax/myday_update.php', {
			method: 'get',
			parameters: {action: 'set', type: 'sleep', value: _element.value, date: myDay_date_PRG},
						  
			onSuccess: function(){ myDay_sleepPoints(); },
			onFailure: function(){ myDay_sleepPoints(); }
		});
	}
}

function myDay_sleepPoints()
{
	var _points = $('myday-sleep-points');

	new Ajax.Request('/public_panel/includes/ajax/myday_update.php', {
		method: 'get',
		parameters: {action: 'points', type: 'sleep', date: myDay_date_PRG},
					  
		onComplete: function(transport){
			initResponse = transport.responseText;
			_points.innerHTML = initResponse;
			myDay_onChange();
		}			
		
	});
}

function myDay_sleep()
{
	myDay_sleepPoints();
	myDay_sleepInit();
	myDay_sleepUpdate();
}
/*----------- end SLEEP---*/

/* ---------------- end MY DAY POINTS -----------------*/



/*------ INVITE FRIEND POPUP SEARCH ------ */
function inviteFriendSearch_update()
{
	var _search = $('invite_search_friend_str');

	new Ajax.Request('includes/ajax/invite_friends.php', {
		method: 'get',
		parameters: {str: _search.value},
			  
		onSuccess: function(transport){
			var response = transport.responseText;
			$('sel_friend_container').innerHTML = response;
		}
	  });
}

function inviteFriendSearch()
{
	var _search = $('invite_search_friend_str');

	if(_search)
	{
		inviteFriendSearch_update();

		_search.onkeyup = function()
		{
			inviteFriendSearch_update();
		}
		_search.onkeydown = function()
		{
			inviteFriendSearch_update();
		}
	}

}
/*------ end INVITE FRIEND POPUP SEARCH ------ */




/* ----------- COMMUNITY MEMBER PROFILE - EXPAND/COLLAPSE CONTROL ------- */
function CMP_controlSave(_section)
{
	var _save = $('cmp-save-control');

	if(_save)
	{
		var _mode = $(_section).style.display + '' == 'block' ? 1 : 0;
		var _sect = _section.replace('cmp-container-', '');
	
		new Ajax.Request('includes/ajax/community_member_profile_sections.php', {
			method: 'get',
			parameters: {section: _sect, display: _mode}
		});
	}
}

function CMP_control()
{
	var _control = $('cmp-control');
	var _save = $('cmp-save-control');

	if(_control)
	{
		if($('cmp-toogle-journal'))
		{
			$('cmp-toogle-journal').onclick = function()
			{
				if($('cmp-toogle-journal').className.indexOf('closed') == -1)
				{
					$('cmp-my-journal-holder').style.visibility = 'hidden';
					$('cmp-toogle-journal').className = 'closed';
					slideup('cmp-container-journal');
				}
				else
				{
					slidedown('cmp-container-journal');
					$('cmp-toogle-journal').className = '';
					setTimeout("$('cmp-my-journal-holder').style.visibility = 'visible';", 500);
				}
			}
		}

		if($('cmp-toogle-photos'))
		{
			$('cmp-toogle-photos').onclick = function()
			{
				if($('cmp-toogle-photos').className.indexOf('closed') == -1)
				{
					$('cmp-toogle-photos').className = 'closed';
				}
				else
				{
					$('cmp-toogle-photos').className = '';
				}
				toggleSlide('cmp-container-photos');
			}
		}

		if($('cmp-toogle-chat'))
		{
			$('cmp-toogle-chat').onclick = function()
			{
				if($('cmp-toogle-chat').className.indexOf('closed') == -1)
				{
					$('cmp-toogle-chat').className = 'closed';
				}
				else
				{
					$('cmp-toogle-chat').className = '';
				}
				toggleSlide('cmp-container-chat');
			}
		}

		if($('cmp-toogle-community'))
		{
			$('cmp-toogle-community').onclick = function()
			{
				if($('cmp-toogle-community').className.indexOf('closed') == -1)
				{
					$('cmp-toogle-community').className = 'closed';
				}
				else
				{
					$('cmp-toogle-community').className = '';
				}
				toggleSlide('cmp-container-community');
			}
		}

		if($('cmp-toogle-journey'))
		{
			$('cmp-toogle-journey').onclick = function()
			{
				if($('cmp-container-journey').style.display == 'none')
				{
					slidedown('cmp-container-journey');
					setTimeout("$('cmp-toogle-journey').className = ''; $('journey-graphs-holder').style.display = 'block';", 1000);
				}
				else
				{
					$('journey-graphs-holder').style.display = 'none';
					slideup('cmp-container-journey');
					$('cmp-toogle-journey').className = 'closed';
				}			
			}
		}

		if($('cmp-toogle-statistics'))
		{
			$('cmp-toogle-statistics').onclick = function()
			{
				if($('cmp-toogle-statistics').className.indexOf('closed') == -1)
				{
					$('cmp-toogle-statistics').className = 'closed';
				}
				else
				{
					$('cmp-toogle-statistics').className = '';
				}
				toggleSlide('cmp-container-statistics');
			}
		}

		if($('cmp-toogle-favourites'))
		{
			$('cmp-toogle-favourites').onclick = function()
			{
				if($('cmp-toogle-favourites').className.indexOf('closed') == -1)
				{
					$('cmp-toogle-favourites').className = 'closed';
				}
				else
				{
					$('cmp-toogle-favourites').className = '';
				}
				toggleSlide('cmp-container-favourites');
			}
		}
	}
}


/* ----------- end COMMUNITY MEMBER PROFILE - EXPAND/COLLAPSE CONTROL ------- */

//document.write("<script type=\"text/javascript\" src=\"includes/other/login.js\"></script>");
//document.write("<script type=\"text/javascript\" src=\"includes/other/search.js\"></script>");
//document.write("<script type=\"text/javascript\" src=\"includes/other/sidebar.js\"></script>");