var agt=navigator.userAgent.toLowerCase();
var appVer = navigator.appVersion.toLowerCase();
var is_minor = parseFloat(appVer);
var is_major = parseInt(is_minor);
var iePos = appVer.indexOf('msie');
if (iePos !=-1) {
is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
is_major = parseInt(is_minor);
}
var is_getElementById = (document.getElementById) ? "true" : "false";
var is_getElementsByTagName = (document.getElementsByTagName) ? "true" : "false";
var is_documentElement = (document.documentElement) ? "true" : "false";
var is_ie = ((iePos!=-1));
var is_ie6 = (is_ie && is_major == 6);



var isIE=is_ie;

//Show and hide section at My profile->goals page
function hide_table_section(id){
    if(!(document.getElementById(id).style.display=='none')){
        document.getElementById(id).style.display='none';
        document.getElementById(id+"_arrow").className="arrow_down";
		document.getElementById(id+"_hide").className="unhide";
        document.getElementById(id+"_title").style.marginBottom="13px";
    }else{
        document.getElementById(id).style.display='inline';
        document.getElementById(id+"_arrow").className="arrow_up";
		document.getElementById(id+"_hide").className="hide";
        document.getElementById(id+"_title").style.marginBottom="0px";    
    }    
}

//Show and hide row data on click at X and V images at My profile->goals page
function hide_row_data(id){
    if(!(document.getElementById(id+"_select").className=='selected')){
        document.getElementById(id+"_select").className='selected';
        document.getElementById(id+"_target").className='column_title_inner';
		document.getElementById(id+"_remind").className='column_title_inner';
		document.getElementById(id+"_check").checked = true;
		document.getElementById(id+"_check").value = '1';
		document.getElementById("ch"+id).value = '1';

    }else{
        document.getElementById(id+"_select").className='unselected';
        document.getElementById(id+"_target").className=document.getElementById(id+"_target").className+' hidden';
		document.getElementById(id+"_remind").className=document.getElementById(id+"_remind").className+' hidden';
		document.getElementById(id+"_check").checked = false;
		document.getElementById(id+"_check").value = '';
		document.getElementById("ch"+id).value = '';

    }    
}
//change innerHTML of object
function changeInnerHTML(el, text)
{
	document.getElementById(el).innerHTML=text;
}

//show and hide "My goals" section on right menu 
function hide_goals_rm(id){
    if(!(document.getElementById(id).style.display=='none')){
        document.getElementById(id).style.display='none';
        document.getElementById(id+"_link").className="view";
		changeInnerHTML(id+"_link", "View my goals");
    }else{
        document.getElementById(id).style.display='inline';
        document.getElementById(id+"_link").className="hide";   
		changeInnerHTML(id+"_link", "Hide my goals");
    }    
}

//show and hide meal details on "My nutrition" section in My Fitbug Lobby page 
function show_meal_details(id){
    if(!(getStyle($(id+"_details"),"display")=='none')){
		$(id+"_details").style.display='none';
		changeInnerHTML(id, "Show details");
	}
	else{
		$(id+"_details").style.display='inline';
		changeInnerHTML(id, "Hide details");
	}
}

//show and hide "search" pic in search box on topTabsNav bar
function search_pic(){
	if(document.getElementById("search_box").className=='pic'){
		document.getElementById("search_box").className='no_pic';
	}
	else{
		if(document.getElementById("search_box").value==""){
			document.getElementById("search_box").className='pic';
		}
	}
}
//show element by id - change actual style.display property to opposed value.
function showElement(id){
	if(!(getStyle(document.getElementById(id),"display")=='none')){
		document.getElementById(id).style.display='none';
	}
	else{
		document.getElementById(id).style.display='inline';
	}

}
//show element by id - change actual style.display property to opposed value.
function showObj(obj){
	if(!(getStyle(obj,"display")=='none')){
		obj.style.display='none';
	}
	else{
		obj.style.display='inline';
	}
}
//returns the rendered style of an element (as opposed to specified style)
function getStyle(oElm, strCssRule){
	var strValue = "";
	if(document.defaultView && document.defaultView.getComputedStyle){
		strValue = document.defaultView.getComputedStyle(oElm, "").getPropertyValue(strCssRule);
	}
	else if(oElm.currentStyle){
		strCssRule = strCssRule.replace(/-(w)/g, function (strMatch, p1){
			return p1.toUpperCase();
		});
		strValue = oElm.currentStyle[strCssRule];
	}
	return strValue;
}

	function toggle_cross(id){
		var btn=document.getElementById(id);
		
		if(btn.className=="minus_btn"){
			changeClass(id,"cross_btn");
		}
		else{
			changeClass(id,"minus_btn");
		}
	}

//Clear default text in text area on Health Living->Ask an Expert page->ask your question section
function clearTextAreaText(id){
	if(document.getElementById(id).value==document.getElementById(id).defaultValue){
		document.getElementById(id).value="";
	}
	else{
		if(document.getElementById(id).value==""){
			document.getElementById(id).value=document.getElementById(id).defaultValue;
		}
	}
}
//this function check if value for password was entered. If not - it return input "text" with default value "Password"
function clearPasswordArea(textId,passId,currType){
	if(currType=="text"){
		$(textId).style.display="none";
		$(passId).style.display="inline";
		$(passId).focus();
	}
	else{
		if($(passId).value==""){
			$(passId).style.display="none";
			$(textId).style.display="inline";
			$(textId).value=$(textId).defaultValue;
		}
	}			
		
}

/*<set label='02' value='1484' color='ff0000'/><set label='03' value='1484' color='ff0000'/><set label='04' value='1492' color='ff0000'/><set label='05' value='1484' color='ff0000'/><set label='06' value='1484' color='ff0000'/><set label='07' value='1484' color='ff0000'/><set label='08' value='1484' color='ff0000'/><set label='09' value='1484' color='ff0000'/><set label='10' value='1484' color='ff0000'/><set label='11' value='1549' color='ff0000'/><set label='12' value='1372' color='ff0000'/><set label='13' value='1447' color='ff0000'/><set label='14' value='1519' color='ff0000'/><set label='15' value='1484' color='ff0000'/></chart>
*/

//loads flash for my_fitbug -> activity--> activityTargets popUp
function loadATargetsFlash(){

	var so = new SWFObject("./images/flash/fitBugHrizontalSlide3.swf", "reg_slider_flash", "264", "26", "8", "#ffffff");
	so.addVariable("dataBarSavedValue", "35");
	so.addVariable("dataMaximumValue","12500");
	so.addVariable("roundBy","2");
	so.addVariable("roundBy","2");
	so.addParam("wmode", "opaque");	
	so.write("reg_slider_container");
	
	var so = new SWFObject("./images/flash/fitBugHrizontalSlide3.swf", "aerobic_slider_flash", "264", "26", "8", "#ffffff");
	so.addVariable("dataBarSavedValue", "7820");
	so.addVariable("dataMaximumValue","10500");
	so.addVariable("roundBy","2");
	so.addParam("wmode", "opaque");	
	so.write("aerobic_slider_container");	
		
}
//loads flash for ms_print
function loadMSPFlash(){
	var so = new SWFObject("./images/flash/myfood.swf", "m_f_flash", "234", "174", "8", "#FFFFFF");
	so.addVariable("actualValueString", "47#30#15#8");
	so.addVariable("targetValueString", "21#15#35#29");	
	so.addParam("wmode", "opaque");
	so.write("m_f_container");		
	
	var so = new SWFObject("./images/flash/bar_normalratio.swf", "e_in_flash", "254", "52", "8", "#FFFFFF");
	so.addVariable("titleCaption", "avg energy in");
	so.addVariable("partialValue", "1800");
	so.addVariable("partialValueUnit", "kcal");
	so.addVariable("targetValue", "1200");
	so.addVariable("fullSquareColorCode", "cccc33");
	so.addVariable("emptySquareBorderCode", "cccccc");	
	so.addVariable("partialValueColorCode", "cccc33");	
	so.addParam("wmode", "opaque");	
	so.write("e_in_container");	
	
	var so = new SWFObject("./images/flash/energy_balance.swf", "energy_ballance_flash", "234", "88", "8", "#FFFFFF");
	so.addVariable("balanceUnits", "600");
	so.addVariable("balanceScale", "1982");	
	so.addParam("wmode", "opaque");	
	so.write("energy_ballance_container");
	
		
}
//loads flash for ms_lobby
function loadMSLFlash(){
	var so = new SWFObject("./images/flash/energy_balance_large.swf", "e_b_big_flash", "322", "117", "8", "#FFFFFF");
	so.addVariable("balanceUnits", "600");
	so.addVariable("balanceScale", "1982");	
	so.addParam("wmode", "opaque");	
	so.write("e_b_big_container");
	
	var so = new SWFObject("./images/flash/bar_normalratio.swf", "e_in_flash", "301", "62", "8", "#FFFFFF");
	so.addVariable("titleCaption", "avg energy in");
	so.addVariable("partialValue", "1800");
	so.addVariable("partialValueUnit", "kcal");
	so.addVariable("targetValue", "1200");
	so.addVariable("fullSquareColorCode", "cccc33");
	so.addVariable("emptySquareBorderCode", "cccccc");	
	so.addVariable("partialValueColorCode", "cccc33");	
	so.addParam("wmode", "opaque");	
	so.write("e_in_container");	
	
	var so = new SWFObject("./images/flash/myfood.swf", "m_f_flash", "234", "174", "8", "#FFFFFF");
	so.addVariable("actualValueString", "47#30#15#8");
	so.addVariable("targetValueString", "21#15#35#29");	
	so.addParam("wmode", "opaque");
	so.write("m_f_container");	
}

//loads flash for my_goals -> goals history popUp
function loadMGFlash(){
	var so = new SWFObject("./images/flash/Column2D.swf", "gh_weight_flash", "616", "279", "8", "#fef4e8");
	so.addVariable("yAxisValuesPadding", "0");
	so.addVariable("showToolTip", "0");
	so.addVariable("rotateValues", "1");
	so.addVariable("toolText", "1484");
	so.addVariable("xAxisName", "Week of year");
	so.addVariable("yAxisName", "Avarage calories per day");
	so.addVariable("showValues", "1");
	so.addVariable("decimals", "1");
	so.addVariable("bgColor", "#ffe6cd");
	so.addVariable("borderColor", "#fef4e8");
	so.addVariable("formatNumberScale", "0");
	so.addVariable("yAxisValuesPadding", "0");
	so.addVariable("yAxisValuesPadding", "0");
	so.addParam("wmode", "opaque");	
	so.write("gh_graph_container");
		
}

//loads flash for my_fitbug_lobby
function loadMF_lobbyFlash(){
	var so = new SWFObject("./images/flash/energy_balance_large.swf", "e_ballance_l_flash", "474", "172", "8", "#FFFFFF");
	so.addVariable("balanceUnits", "600");
	so.addVariable("workLink", "uk");
	 
	so.addVariable("balanceScale", "1982");	
	so.addParam("wmode", "opaque");	
	so.write("energy_ballance_big_container");
		
}

//loads flash for progress_report
function loadPRFlash(){
	var so = new SWFObject("./images/flash/energy_balance_large.swf", "e_b_big_flash", "322", "117", "8", "#FFFFFF");
	so.addVariable("balanceUnits", "600");
	so.addVariable("balanceScale", "1982");	
	so.addParam("wmode", "opaque");	
	so.write("e_b_big_container");
	
	var so = new SWFObject("./images/flash/energy_balance.swf", "e_b_small_flash", "234", "88", "8", "#FFFFFF");
	so.addVariable("balanceUnits", "600");
	so.addVariable("balanceScale", "1982");	
	so.addParam("wmode", "opaque");	
	so.write("e_b_small_container");

	var so = new SWFObject("./images/flash/myfood.swf", "m_f_flash", "234", "174", "8", "#FFFFFF");
	so.addVariable("actualValueString", "47#30#15#8");
	so.addVariable("targetValueString", "21#15#35#29");	
	so.addParam("wmode", "opaque");
	so.write("m_f_container");		
	
	var so = new SWFObject("./images/flash/bar_normalratio.swf", "t_s_flash", "301", "62", "8", "#FFFFFF");
	so.addVariable("titleCaption", "total steps");
	so.addVariable("partialValue", "6250");
	so.addVariable("partialValueUnit", "");
	so.addVariable("targetValue", "6700");
	so.addVariable("fullSquareColorCode", "fb46a4");
	so.addVariable("emptySquareBorderCode", "cccccc");	
	so.addVariable("partialValueColorCode", "fb46a4");
	so.addParam("wmode", "opaque");	
	so.write("t_s_container");
	

	var so = new SWFObject("./images/flash/bar_normalratio.swf", "a_s_flash", "301", "62", "8", "#FFFFFF");
	so.addVariable("titleCaption", "aerobic steps");
	so.addVariable("partialValue", "3200");
	so.addVariable("partialValueUnit", "");
	so.addVariable("targetValue", "3000");
	so.addVariable("fullSquareColorCode", "1db6ca");
	so.addVariable("emptySquareBorderCode", "cccccc");
	so.addVariable("partialValueColorCode", "fb46a4");
	so.addParam("wmode", "opaque");
	so.write("a_s_container");	
	
	
	var so = new SWFObject("./images/flash/bar_normalratio.swf", "e_in_flash", "301", "62", "8", "#FFFFFF");
	so.addVariable("titleCaption", "total energy in");
	so.addVariable("partialValue", "1800");
	so.addVariable("partialValueUnit", "kcal");
	so.addVariable("targetValue", "1200");
	so.addVariable("fullSquareColorCode", "cccc33");
	so.addVariable("emptySquareBorderCode", "cccccc");	
	so.addVariable("partialValueColorCode", "cccc33");	
	so.addParam("wmode", "opaque");	
	so.write("e_in_container");	
	
		
}


//loads all flashes on right side SPATIAL menu
function loadRightSMenuFlash(){
	var so = new SWFObject("./images/flash/essentials_water.swf", "water_flash", "107", "57", "8", "#FFFFFF");
	so.addVariable("counterValue", "5");
	so.addParam("wmode", "opaque");	
	so.write("water_container");

	var so = new SWFObject("./images/flash/essentials_coffee.swf", "coffee_flash", "107", "57", "8", "#FFFFFF");
	so.addVariable("counterValue", "5");
	so.addParam("wmode", "opaque");
	so.write("coffee_container");

	var so = new SWFObject("./images/flash/essentials_fruit.swf", "fruit_flash", "107", "57", "8", "#FFFFFF");
	so.addVariable("counterValue", "5");
	so.addParam("wmode", "opaque");	
	so.write("fruit_container");

	var so = new SWFObject("./images/flash/essentials_feel.swf", "feel_flash", "107", "57", "8", "#FFFFFF");
	so.addVariable("counterValue", "5");
	so.addParam("wmode", "opaque");
	so.write("feel_container");
	
	var so = new SWFObject("./images/flash/bar_normalratio.swf", "my_goals_flash", "251", "52", "8", "#FFFFFF");
	so.addVariable("titleCaption", "weight");
	so.addVariable("partialValue", "136");
	so.addVariable("partialValueUnit", "kg");
	so.addVariable("targetValue", "120");
	so.addVariable("fullSquareColorCode", "1db6ca");
	so.addVariable("emptySquareBorderCode", "cccccc");	
	so.addVariable("partialValueColorCode", "1db6ca");	
	so.addParam("wmode", "opaque");
	so.write("my_goals_container");		
}
//loads all flashes on right side menu
function loadRightMenuFlash(){
	return;
	var so = new SWFObject("/35/images/Flash/bar_normalratio.swf", "total_steps_flash", "251", "52", "8", "#FFFFFF");
	so.addVariable("titleCaption", "total steps");
	so.addVariable("partialValue", "6250");
	so.addVariable("partialValueUnit", "");
	so.addVariable("targetValue", "6700");
	so.addVariable("fullSquareColorCode", "1db6ca");
	so.addVariable("emptySquareBorderCode", "cccccc");	
	so.addVariable("partialValueColorCode", "fb46a4");												
	so.addParam("wmode", "opaque");	
	so.write("total_steps_container");

	var so = new SWFObject("/35/images/Flash/bar_normalratio.swf", "aerobic_steps_flash", "251", "52", "8", "#FFFFFF");
	so.addVariable("titleCaption", "aerobic steps");
	so.addVariable("partialValue", "3200");
	so.addVariable("partialValueUnit", "");
	so.addVariable("targetValue", "3000");
	so.addVariable("fullSquareColorCode", "fb46a4");
	so.addVariable("emptySquareBorderCode", "cccccc");
	so.addVariable("partialValueColorCode", "fb46a4");													
	so.addParam("wmode", "opaque");
	so.write("aerobic_steps_container");	
	
	var so = new SWFObject("/35/images/Flash/energy_balance.swf", "energy_ballance_flash", "234", "88", "8", "#FFFFFF");
	so.addVariable("balanceUnits", "600");
	so.addVariable("balanceScale", "1982");												
	so.addParam("wmode", "opaque");	
	so.write("energy_ballance_container");
	
	var so = new SWFObject("/35/images/Flash/bar_normalratio.swf", "my_goals_flash", "251", "52", "8", "#FFFFFF");
	so.addVariable("titleCaption", "weight");
	so.addVariable("partialValue", "136");
	so.addVariable("partialValueUnit", "kg");
	so.addVariable("targetValue", "120");
	so.addVariable("fullSquareColorCode", "1db6ca");
	so.addVariable("emptySquareBorderCode", "cccccc");	
	so.addVariable("partialValueColorCode", "1db6ca");												
	so.addParam("wmode", "opaque");
	so.write("my_goals_container");	

	var so = new SWFObject("/35/images/Flash/bar_normalratio.swf", "energy_in_flash", "251", "52", "8", "#FFFFFF");
	so.addVariable("titleCaption", "total energy in");
	so.addVariable("partialValue", "1800");
	so.addVariable("partialValueUnit", "kcal");
	so.addVariable("targetValue", "1200");
	so.addVariable("fullSquareColorCode", "cccc33");
	so.addVariable("emptySquareBorderCode", "cccccc");	
	so.addVariable("partialValueColorCode", "cccc33");												
	so.addParam("wmode", "opaque");	
	so.write("energy_in_container");		
	var so = new SWFObject("./images/flash/myfood.swf", "my_food_flash", "234", "174", "8", "#FFFFFF");
	so.addVariable("actualValueString", "47#30#15#8");
	so.addVariable("targetValueString", "21#15#35#29");	
	so.addParam("wmode", "opaque");
	so.write("my_food_container");	
	
	var so = new SWFObject("./images/flash/essentials_water.swf", "water_flash", "107", "57", "8", "#FFFFFF");
	so.addVariable("counterValue", "5");
	so.addParam("wmode", "opaque");	
	so.write("water_container");

	var so = new SWFObject("./images/flash/essentials_coffee.swf", "coffee_flash", "107", "57", "8", "#FFFFFF");
	so.addVariable("counterValue", "5");
	so.addParam("wmode", "opaque");
	so.write("coffee_container");

	var so = new SWFObject("./images/flash/essentials_fruit.swf", "fruit_flash", "107", "57", "8", "#FFFFFF");
	so.addVariable("counterValue", "5");
	so.addParam("wmode", "opaque");	
	so.write("fruit_container");

	var so = new SWFObject("./images/flash/essentials_feel.swf", "feel_flash", "107", "57", "8", "#FFFFFF");
	so.addVariable("counterValue", "5");
	so.addParam("wmode", "opaque");
	so.write("feel_container");
}

//add function to window.onload
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

//add loadRightMenuFlash function to window.onload
addLoadEvent(loadRightMenuFlash);

//returns an array of elements that match full or partial (indexOf) classname
function ElementsByClass(rootElement,ElementClass,ElementType,partialMatch){        
            ElementType=ElementType?ElementType:'*';
			var elementsArray=new Array();			
            var theElements=rootElement.getElementsByTagName(ElementType);                  

            for (var x=0;x<theElements.length;x++){
				      if(partialMatch){
					       if (theElements[x].className.indexOf(ElementClass)>-1){ 
							    elementsArray[elementsArray.length]=theElements[x];
						    }
					  }else{
	                        if (theElements[x].className==ElementClass){ 
							  elementsArray[elementsArray.length]=theElements[x];
						    }
					  }
				}                          

	            return elementsArray;
} 

//Show and hide tabs with recipes on  Health Living->Recipes-> tabs
function select_recipes_tab(tab){

//if tab hidden -->
    if(document.getElementById(tab).className.indexOf(tab+"_off")>-1){
	//show it's recipes
        document.getElementById(tab+"_recipes").style.display='inline';
	//and show tab- change his class to ON state
        document.getElementById(tab).className="tab "+tab+"_on";
	//collect all a elemets inside recipes_table that have "tab" string in they className to Array
		var tabElementsArray=new Array();
		tabElementsArray=ElementsByClass(document.getElementById("recipes_table"), "tab", "a", true);
	
		for(var x=0;x<tabElementsArray.length;x++){
		//find ellements that have different from "shown tab" name and turn them and they "recipes" part off
			if(tabElementsArray[x].className.indexOf(tab)<=-1){			
				tabElementsArray[x].className="tab "+tabElementsArray[x].id+"_off";
				document.getElementById(tabElementsArray[x].id+"_recipes").style.display='none';
			}
		}
    }  
	
}
function change_graf_view(id){
	//if tab hidden -->
    if(document.getElementById(id+"_icon").className.indexOf(id+"_on")<=-1){	
		var iconsArray=new Array();
		iconsArray=ElementsByClass(document.getElementById("graf_icons"), "_icon", "a", true);
	
		for(var x=0;x<iconsArray.length;x++){
		//find ellements that have different from "shown tab" name and turn them and they "recipes" part off
			if(iconsArray[x].id.indexOf(id)<=-1){			
				iconsArray[x].className=iconsArray[x].id;
			}
		}
		/*
		var tabElementsArray=new Array();
		
		tabElementsArray=ElementsByClass(document.getElementById("graf_content"), "graf_border", "div", false);
	
		for(var x=0;x<tabElementsArray.length;x++){
		//find ellements that have different from "shown tab" name and turn them and they "recipes" part off
			if(tabElementsArray[x].id.indexOf(id)<=-1){			
				tabElementsArray[x].style.display="none";
			}
		}
		*/
		document.getElementById(id+"_icon").className=id+"_icon_on";
		//document.getElementById(id).style.display="inline";		
		
	}

}

function hideSelectBox(){
    //hide selects to fix annoying select bug in ie
	if(isIE){
		var allSelects=document.getElementsByTagName("select");
		for(var x=0;x<allSelects.length;x++){		
			//if not in a modal box
			if(allSelects[x].className.indexOf('modal')==-1){
			    allSelects[x].style.visibility="hidden";	
			    }
		}
	}
}

function showSelectBox(){
    //show selects to fix annoying select bug in ie
	if(isIE){	
		var allSelects=document.getElementsByTagName("select");

		for(var x=0;x<allSelects.length;x++){
			allSelects[x].style.visibility="visible";	
		}
	}
}

/*Modal Add Non Bug Activities functions */
function select_row(id){    
	var selectedRowId=getSelectedRowId();
	if($(selectedRowId)) {
		document.getElementById(selectedRowId).className="list_row";
		showElement("atribute_table");	
		showElement("finished");
		clearAttributes();	
	}
	
	if((document.getElementById(id).className.indexOf("_selected")<=-1)&&(getStyle(document.getElementById("atribute_table"),"display")=='none')){
		
		var rowsArray=new Array();
		rowsArray=ElementsByClass(document.getElementById("activities_list_inner"), "list_row", "div", false);

		for(var x=0;x<rowsArray.length;x++){
		//find ellements that have different from "shown tab" name and turn them and they "recipes" part off
			if(rowsArray[x].id.indexOf(id)<=-1){			
				rowsArray[x].className="list_row";
			}
		}	
		document.getElementById(id).className="list_row_selected";
		showElement("finished");
		showElement("atribute_table");
	}

	if (id == '21_all' || id== '21')
	{
	    if (document.getElementById('lowPressSlash') != null && document.getElementById('lowPress') != null)
	    {	    
	        document.getElementById('lowPressSlash').style.display = 'inline';
	        document.getElementById('lowPress').style.display = 'inline';
	    }
	}
	else
	{
	    if (document.getElementById('lowPressSlash') != null && document.getElementById('lowPress') != null)
	    {
	        document.getElementById('lowPressSlash').style.display = 'none';
	        document.getElementById('lowPress').style.display = 'none';
	    }
	}	
}
function getSelectedRowId(){
	var rowsArray=new Array();
	rowsArray=ElementsByClass(document.getElementById("activities_list_inner"), "list_row", "div", true);

	for(var x=0;x<rowsArray.length;x++){
	
	//find ellements that have different from "shown tab" name and turn them and they "recipes" part off
		if(rowsArray[x].className.indexOf("_selected")>-1){	
			return rowsArray[x].id;
		}
	}
}
function getLastRowNumber(){
	var actRowArray=new Array();
	actRowArray=ElementsByClass(document.getElementById("non_bug_activities"), "added_activity", "div", false);
	return actRowArray.length;
}

function go(){

	var selectedRowId=getSelectedRowId();
	if($(selectedRowId)) {
		document.getElementById(selectedRowId).className="list_row";
		showElement("atribute_table");	
		showElement("finished");
		clearAttributes();	
	}	
	
	if(getStyle($('atribute_table'),"display")!="none"){
	
		$('atribute_table').style.display="none";
	}
		var rowsArray=new Array();
		rowsArray=ElementsByClass(document.getElementById("activities_list_inner"), "list_row", "div", true);
		
		if(!($('select_activity_type').value=='All')){
			for(var x=0;x<rowsArray.length;x++){
				if(rowsArray[x].id.indexOf($('select_activity_type').value)>-1){	
					rowsArray[x].style.display='inline';
				}
				else{
					rowsArray[x].style.display='none';
				}
			}
		}

		else{
			for(var x=0;x<rowsArray.length;x++){
				rowsArray[x].style.display='inline';
			}	
			
		}
	
	
}
function getLastRowNumber_goals(){
	var actRowArray=new Array();
	actRowArray=ElementsByClass(document.getElementById("non_bug_activities"), "added_activity", "div", false);
	return actRowArray.length;
}


function getDataType_goals(id){
	var dataTypesArray=new Array();
	dataTypesArray=ElementsByClass(document.getElementById("goals_table"), "table_sub_title", "div", false);

	for(var x=0;x<dataTypesArray.length;x++){
	//find ellements that have different from "shown tab" name and turn them and they "recipes" part off
		if(dataTypesArray[x].id.indexOf(id)>-1){	
			return true;
		}
	}
	return false;
}

function upd_goals(){

//get last added activity row number and give to new row next number for ID
	var newRowNum=getLastRowNumber()+1;
	var rowId="added_activity_"+newRowNum;
//get the number of selected row in activities_list and it's inner 	
	var selectedRow=getSelectedRowId();
	var selectedRow_inner=selectedRow+"_inner";
	
//create new added activity row
    var row = document.createElement("div");
    row.className = "added_activity";
	row.id=rowId;
	document.getElementById("non_bug_activities").appendChild(row);
	
//create new added activity row inner	
    var row_inner = document.createElement("div");
    row_inner.className = "added_activity_inner";	
	row_inner.id="added_activity_inner_"+newRowNum;
	document.getElementById(row.id).appendChild(row_inner);

//create name container for new added activity	
    var atribute_1 = document.createElement("div");
    atribute_1.className = "atribute_name";	
	atribute_1.id="atribute_name_"+newRowNum+"_1";	
	document.getElementById(row_inner.id).appendChild(atribute_1);
	
//create minutes container for new added activity
    var atribute_2 = document.createElement("div");
    atribute_2.className = "atribute_value";	
	atribute_2.id="atribute_value_"+newRowNum+"_2";	
	atribute_2.style.width="36px";
	document.getElementById(row_inner.id).appendChild(atribute_2);

//create time of day  container for new added activity
    var atribute_3 = document.createElement("div");
    atribute_3.className = "atribute_value";	
	atribute_3.id="atribute_value_"+newRowNum+"_3";	
	atribute_3.style.width="57px";
	document.getElementById(row_inner.id).appendChild(atribute_3);

//create effort level  container for new added activity	
    var atribute_4 = document.createElement("div");
    atribute_4.className = "atribute_value";	
	atribute_4.id="atribute_value_"+newRowNum+"_4";	
	atribute_4.style.width="56px";
	document.getElementById(row_inner.id).appendChild(atribute_4);

//create calories container for new added activity
    var atribute_5 = document.createElement("div");
    atribute_5.className = "atribute_value";	
	atribute_5.id="atribute_value_"+newRowNum+"_5";	
	atribute_5.style.width="39px";
	document.getElementById(row_inner.id).appendChild(atribute_5);	
	
//create steps container for new added activity	
    var atribute_6 = document.createElement("div");
    atribute_6.className = "atribute_value";	
	atribute_6.id="atribute_value_"+newRowNum+"_6";	
	atribute_6.style.width="40px";
	document.getElementById(row_inner.id).appendChild(atribute_6);	

//create remove button for new added activity	
    var removeBtn = document.createElement("a");
    removeBtn.className = "remove_btn";	
	removeBtn.id="remove_btn_"+newRowNum;	
	removeBtn.href="javascript:void(0);";
	//removeBtn.onclick="removeAddedActivity(rowId)";
	removeBtn.onclick= function(){removeAddedActivity('non_bug_activities',rowId)};
	document.getElementById(row.id).appendChild(removeBtn);		

//insert innerHTML for those containers 	using users values (except calories and steps -they values added hardcoded for now)
	changeInnerHTML(atribute_1.id,document.getElementById(selectedRow_inner).innerHTML);
	changeInnerHTML(atribute_2.id,document.getElementById("how_long").value);
	changeInnerHTML(atribute_3.id,document.getElementById("time").value);
	changeInnerHTML(atribute_4.id,document.getElementById("effort").value);
	changeInnerHTML(atribute_5.id,"99999");
	changeInnerHTML(atribute_6.id,"111111");
	if(getStyle($('added_activity_none'),"display")!="none"){
		$('added_activity_none').style.display="none";
	}
	
//unselect row
	document.getElementById(selectedRow).className="list_row";
//hide attribute table and unhide finished button
	showElement("atribute_table");	
	showElement("finished");
//clear all attributes in attribute_table;
	clearAttributes();
}

function getLastRowNumber_goals(){
	var actRowArray=new Array();
	actRowArray=ElementsByClass(document.getElementById("non_bug_activities"), "added_activity", "div", false);
	return actRowArray.length;
}


function getDataType_goals(id){
	var dataTypesArray=new Array();
	dataTypesArray=ElementsByClass(document.getElementById("goals_table"), "table_sub_title", "div", false);

	for(var x=0;x<dataTypesArray.length;x++){
	//find ellements that have different from "shown tab" name and turn them and they "recipes" part off
		if(dataTypesArray[x].id.indexOf(id)>-1){	
			return true;
		}
	}
	return false;
}

function upd_goals(){

//get last added activity row number and give to new row next number for ID
	var newRowNum=getLastRowNumber()+1;
	var rowId="added_activity_"+newRowNum;
//get the number of selected row in activities_list and it's inner 	
	var selectedRow=getSelectedRowId();
	var selectedRow_inner=selectedRow+"_inner";
	
//create new added activity row
    var row = document.createElement("div");
    row.className = "added_activity";
	row.id=rowId;
	document.getElementById("non_bug_activities").appendChild(row);
	
//create new added activity row inner	
    var row_inner = document.createElement("div");
    row_inner.className = "added_activity_inner";	
	row_inner.id="added_activity_inner_"+newRowNum;
	document.getElementById(row.id).appendChild(row_inner);

//create name container for new added activity	
    var atribute_1 = document.createElement("div");
    atribute_1.className = "atribute_name";	
	atribute_1.id="atribute_name_"+newRowNum+"_1";	
	document.getElementById(row_inner.id).appendChild(atribute_1);
	
//create minutes container for new added activity
    var atribute_2 = document.createElement("div");
    atribute_2.className = "atribute_value";	
	atribute_2.id="atribute_value_"+newRowNum+"_2";	
	atribute_2.style.width="36px";
	document.getElementById(row_inner.id).appendChild(atribute_2);

//create time of day  container for new added activity
    var atribute_3 = document.createElement("div");
    atribute_3.className = "atribute_value";	
	atribute_3.id="atribute_value_"+newRowNum+"_3";	
	atribute_3.style.width="57px";
	document.getElementById(row_inner.id).appendChild(atribute_3);

//create effort level  container for new added activity	
    var atribute_4 = document.createElement("div");
    atribute_4.className = "atribute_value";	
	atribute_4.id="atribute_value_"+newRowNum+"_4";	
	atribute_4.style.width="56px";
	document.getElementById(row_inner.id).appendChild(atribute_4);

//create calories container for new added activity
    var atribute_5 = document.createElement("div");
    atribute_5.className = "atribute_value";	
	atribute_5.id="atribute_value_"+newRowNum+"_5";	
	atribute_5.style.width="39px";
	document.getElementById(row_inner.id).appendChild(atribute_5);	
	
//create steps container for new added activity	
    var atribute_6 = document.createElement("div");
    atribute_6.className = "atribute_value";	
	atribute_6.id="atribute_value_"+newRowNum+"_6";	
	atribute_6.style.width="40px";
	document.getElementById(row_inner.id).appendChild(atribute_6);	

//create remove button for new added activity	
    var removeBtn = document.createElement("a");
    removeBtn.className = "remove_btn";	
	removeBtn.id="remove_btn_"+newRowNum;	
	removeBtn.href="javascript:void(0);";
	//removeBtn.onclick="removeAddedActivity(rowId)";
	removeBtn.onclick= function(){removeAddedActivity('non_bug_activities',rowId)};
	document.getElementById(row.id).appendChild(removeBtn);		

//insert innerHTML for those containers 	using users values (except calories and steps -they values added hardcoded for now)
	changeInnerHTML(atribute_1.id,document.getElementById(selectedRow_inner).innerHTML);
	changeInnerHTML(atribute_2.id,document.getElementById("how_long").value);
	changeInnerHTML(atribute_3.id,document.getElementById("time").value);
	changeInnerHTML(atribute_4.id,document.getElementById("effort").value);
	changeInnerHTML(atribute_5.id,"99999");
	changeInnerHTML(atribute_6.id,"111111");
	if(getStyle($('added_activity_none'),"display")!="none"){
		$('added_activity_none').style.display="none";
	}
	
//unselect row
	document.getElementById(selectedRow).className="list_row";
//hide attribute table and unhide finished button
	showElement("atribute_table");	
	showElement("finished");
//clear all attributes in attribute_table;
	clearAttributes();
}
function dont_add_activity(){
	var selectedRowId=getSelectedRowId();
	document.getElementById(selectedRowId).className="list_row";
	showElement("atribute_table");	
	showElement("finished");

	clearAttributes();
}

function clearAttributes(){
	document.getElementById("how_long").value="0";
	document.getElementById("time").value="00:00";
	document.getElementById("effort").value="light";
	
}
function closeAddNonBugModal(id){
	clearAttributes();
	closeModal(id);
}
function showUpdateProgress(id){
	if(getStyle($('update_progress'),"display")=="none"){
		document.getElementById(id).style.display="inline";
		document.getElementById('upd_goal_progress_btn').style.display="none";
	}
	else{
		document.getElementById(id).style.display="none";
		$('select_activity_type').value='All';
		//go();
		document.getElementById('upd_goal_progress_btn').style.display="inline";		
	}
}

function closeModal(id){
	if (isIE){
		showSelectBox();
	}
	document.getElementById("modalBackdrop").style.display="none";
	document.getElementById(id).style.display="none";
}

function showModal(id){
    var modalBackdrop=$('modalBackdrop');
	if (!modalBackdrop){
	    modalBackdrop=createModalBackdrop();
	}
	modalBackdrop.style.display="block";
	
	$(id).style.left=countModalPosition(id,"left");
	if(id=="modalCcBack"){
		$(id).style.top=countModalPosition(id,"top");	
	}
	
	if (document.getElementById('is_converter')!= null && document.getElementById('is_converter').value == 1)
	{
	   $(id).style.top='165px';
	   $(id).style.left='100px';
	}
	
	$(id).style.display="block";

	if (isIE){
	    hideSelectBox();		
		modalBackdrop.style.height=document.documentElement.scrollHeight+"px";
	}
}
function countModalPosition(id,pos){
	var position=pos;
	
	if(position=="left"){
		var modal_width_px=getStyle($(id+"_body"),"width");
		var indexof_px=modal_width_px.indexOf("px");
		var modal_width=modal_width_px.substring(0,indexof_px);

		var screen_width=screen.width;
		var leftPosition=(screen_width-modal_width)/2;   
		return leftPosition+"px";
	}
	if(position=="top"){
		var modalObj=$(id);
		var objectHeight=modalObj.offsetHeight;		
		return ((xClientHeight()/2-objectHeight/2+xScrollTop(window,true))+"px");
	
	}
}

function xClientHeight()
{
  var v=0,d=document,w=window;
  if((!d.compatMode || d.compatMode == 'CSS1Compat') && !w.opera && d.documentElement && d.documentElement.clientHeight)
	{v=d.documentElement.clientHeight;}
  else if(d.body && d.body.clientHeight)
	{v=d.body.clientHeight;}
  else if(xDef(w.innerWidth,w.innerHeight,d.width)) {
	v=w.innerHeight;
	if(d.width>w.innerWidth) v-=16;
  }
  return v;
}
function xScrollTop(e, bWin)
{
  var offset=0;
  if (!xDef(e) || bWin || e == document || e.tagName.toLowerCase() == 'html' || e.tagName.toLowerCase() == 'body') {
	var w = window;
	if (bWin && e) w = e;
	if(w.document.documentElement && w.document.documentElement.scrollTop) offset=w.document.documentElement.scrollTop;
	else if(w.document.body && xDef(w.document.body.scrollTop)) offset=w.document.body.scrollTop;
  }
  else {
	e = xGetElementById(e);
	if (e && xNum(e.scrollTop)) offset = e.scrollTop;
  }
  return offset;
}
function xDef()
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}



function removeAddedActivity(table_id,id){
	if(getLastRowNumber()==2){
		$('added_activity_none').style.display="inline"
	}
	$(table_id).removeChild($(id));
}
function createModalBackdrop(){
    modalBackdrop=document.createElement('div');
    modalBackdrop.id="modalBackdrop";
    modalBackdrop.style.display="none";
    document.body.appendChild(modalBackdrop);
    return modalBackdrop;
}

function closeAtributeTable(id){
	var selectedRowId=getSelectedRowId();
	document.getElementById(selectedRowId).className="list_row";
	
	showElement('atribute_table');
	showElement('finished');
	clearGoalsAttribute();
}
function clearGoalsAttribute(){
	document.getElementById("att_value").value="";
	
}


goalsTypes={
	listObjID: 'goalsTypesList',
	items:[
	{
		key:1,
		goalType: "Body Data"
	},
	{
		key:2,
		goalType: "Medical Data"
	},
	{
		key:3,
		goalType: "Fitness Data"
	},
	{
		key:4,
		goalType: "Nutrition Data"
	}

	]
}

goalsSubTypes={
	listObjID: 'goalsSubTypesList',
	items:[
	{
		key:1,
		id:1,
		goalSubType: "weight"
	},
	{
		key:1,
		id:2,
		goalType: "waist"
	},
	{
		key:1,
		id:3,
		goalType: "blood pressure"
	},
	{
		key:1,
		id:4,
		goalType: "hips"
	},
	{
		key:2,
		id:1,
		goalSubType: "cholesterol"
	},
	{
		key:2,
		id:2,
		goalType: "blood sugare"
	},
	{
		key:2,
		id:3,
		goalType: "lung capacity"
	},
	{
		key:3,
		id:1,
		goalType: "fitness test score"
	},	
	{
		key:3,
		id:2,
		goalType: "activity time"
	},	
	{
		key:3,
		id:3,
		goalType: "activity intensivity"
	},	
	{
		key:3,
		id:4,
		goalType: "activity frequency"
	},	
	{
		key:4,
		id:1,
		goalType: "water"
	},	
	{
		key:4,
		id:2,
		goalType: "smoking"
	},
	{
		key:4,
		id:3,
		goalType: "junk food"
	}	
	

	]
}

// toggle tabs 
function toggleTabs(id) {

	var tabsArray=new Array(); // tabs array
		tabsArray=ElementsByClass(document.getElementById("tabs"), "tab ", "div", true);
	var tabsContentArray=new Array(); //tab content array
		tabsContentArray=ElementsByClass(document.getElementById("tabs_content"), "display_", "div", true);
	var idObj = document.getElementById(id); // clicked tab
	var idContentObj = document.getElementById('tab_' + id); // clicked tab content to be displayed
		
	for(var i=0; i<tabsArray.length; i++) {
		if(tabsArray[i] == idObj) {	
			idObj.className = 'tab '+ id + '_on'; // turn on clicked tab
			for(var j=0; j<tabsContentArray.length; j++) {
				if(tabsContentArray[j] == idContentObj) {
					idContentObj.className = 'display_on'; //turn on clicked tab content
				}
				else {
					tabsContentArray[j].className = 'display_off'; // turn off other contents
				}
			}
		}
		else {
			tabsArray[i].className = 'tab '+ tabsArray[i].id + '_off'; // turn off other tabs	
		}
	}
}

var planRowsCounter=1;
function updatePlanRowsCounter(sign){
	if(sign=="add"){
		planRowsCounter=planRowsCounter+1;
	}
	if(sign=="remove"){
		planRowsCounter=planRowsCounter-1;
	}
}

//Show and hide "Is one of them for you" area
function showForUArea(id){
	if(planRowsCounter<2){
		$(id).style.display='none';
	}
	else{
		$(id).style.display='inline';
	}
}

//this plans object contains all types of plans that exists
plans=[
		{key: 1,
		 desc: "3 month plan",
		 price: "49.00"
		},
		{key: 2,
		 desc: "12 month plan",
		 price: "94.00"
		},
		{key: 3,
		 desc: "12 month plan pay monthly",
		 price: "9.00"
		}
]

// add new plan to plans object
function addPlan(planDesc,newPlanPrice){
	var newKey=plans[plans.length-1].key +1;
	plans.push({key: newKey,desc: planDesc,price: newPlanPrice});
}
// remove plan from plans object
function removePlan(key){
	for(var i=0; i<plans.length; i++) {		
		if(plans[i].key==key){
			plans.splice(plans[i],1);
		}
	}
	
}
//this function add item to planItems object
function addPlanItem(key,times){
	for(var j=0; j<times; j++) {
		var newId=planItems.length;	
		var itemPlanObj;
		for(var i=0; i<plans.length; i++) {		
			if(plans[i].key==key){
				itemPlanObj=plans[i];
			}
		}
		planItems.push({Id: newId,plan: itemPlanObj});
		updatePlanRowsCounter('add');
	}
	showForUArea('for_u_wrapper');	
}
//this planItems object that contains all items in added_plans_table
planItems=[
		{Id: 0,
		 plan: plans[0] 
		}
]

//this function "drow" added_plans_table according to items that saved in planItems object.

function drowPlanTable(){
	var tableObj=$('added_plans_table');
	
	for(var i=0; i<planItems.length; i++) {
	//create new row
	    var newRow = document.createElement("div");
		if(i<(planItems.length-1)){
			newRow.className = "added_plan_row";
		}
		else if(i==(planItems.length-1)){	
			newRow.className = "added_plan_row last_row";	
		}
		newRow.id="row_"+i;
		tableObj.appendChild(newRow);
		
	//create plan_desc div in created row
	    var newPlanDesc = document.createElement("div");
	    newPlanDesc.className = "plan_desc";
		newPlanDesc.id = "plan_desc_"+newRow.id;
		$(newRow.id).appendChild(newPlanDesc);
		
	//create plan_price div in created row
	    var newPlanPrice = document.createElement("div");
	    newPlanPrice.className = "plan_price";
		newPlanPrice.id = "plan_price_"+newRow.id;
		$(newRow.id).appendChild(newPlanPrice);	

	//create plan_remove div in created row
	    var newPlanRemove = document.createElement("div");
	    newPlanRemove.className = "plan_remove";
		newPlanRemove.id = "plan_remove_"+newRow.id;
		$(newRow.id).appendChild(newPlanRemove);	
		
	//create cell_inner div in newPlanDesc and newPlanPrice
	    var desc_cell_inner = document.createElement("div");
	    desc_cell_inner.className = "cell_inner";
		desc_cell_inner.id="desc_cell_inner_"+newRow.id;
		$(newPlanDesc.id).appendChild(desc_cell_inner);
		
	    var price_cell_inner = document.createElement("div");
	    price_cell_inner.className = "cell_inner";
		price_cell_inner.id="price_cell_inner_"+newRow.id;
		$(newPlanPrice.id).appendChild(price_cell_inner);

	//create remove button for new added activity	
	    var removeBtn = document.createElement("a");
	    removeBtn.className = "remove_wbg_btn";	
		removeBtn.id="remove_"+newRow.id;	
		removeBtn.href="javascript:void(0);";
		removeBtn.onclick= function(){removeRow(i);}
		//check if this row the only row in table. if it is - turn removeBtn display to none.
		if(planItems.length<2){
			removeBtn.style.display='none';
		}
		$(newPlanRemove.id).appendChild(removeBtn);
		
		//take values for plan description and plan price from planItems and put it to the table
		changeInnerHTML('desc_cell_inner_'+newRow.id,planItems[i].plan.desc);
		changeInnerHTML('price_cell_inner_'+newRow.id,'&pound; '+planItems[i].plan.price);
	}
}

//this function "remove" plan table with removePlanTable function, then remove planItem from planItems and then "drow" updated plan table with drowPlanTable function
function removeRow(id){
	//update planRowsCounter 
	updatePlanRowsCounter('remove');
	//check with showForUArea if the number of rows in plan table more then 2 - if it's great then 2 forUArea will be showen
	showForUArea('for_u_wrapper');	
	removePlanTable();
	planItems.splice(planItems[id],1);
	drowPlanTable();
}

//just erase all HTML code inside added_plans_table.
function removePlanTable(){
	changeInnerHTML('added_plans_table','');
}

//this function collect all checked checkboxes in modalPlan and they quantities (kept in select) to array , then run on this array and add plans to planItems with addPlanItem function
function addPlans(){
	var addedPlans= new Array();
	var planTypeArray=new Array(); //collect all checkboxes to array
		planTypeArray=ElementsByClass($("plansRow"), "addPlan", "input", true);
	var counter=0;
	var quantityArray=new Array(); //collect all selects with quantity to array
		quantityArray=ElementsByClass($("plansRow"), "modal", "select", true);
	
	for(var i=0; i<planTypeArray.length; i++) {
		//if current box checked:
		if(planTypeArray[i].checked == true) {
			//create new Array for next (counter) addedPlans element
			addedPlans[counter]=new Array(2);
			//put type of added plan to the 0 position 
			addedPlans[counter][0]=planTypeArray[i].value;
			//put quantity of added plan to the 1 position 
			addedPlans[counter][1]=quantityArray[i].options[quantityArray[i].selectedIndex].value;
			counter=counter+1;
			
			
			
		}
	}
	//"run" on addedPlans array and add all added plans to planItems with addPlanItem function
	for(var i=0; i<addedPlans.length; i++){
		addPlanItem(addedPlans[i][0],addedPlans[i][1]);
	}
}

//get step- current step and position - back=="back", continue "fwd"
function totPages(step, position) {
	var backStep=step-1;
	var fwdStep=step+1;
	var nextStep;
	var stepsArray=new Array(); // steps array
		stepsArray=ElementsByClass($("steps_container"), "inner", "div", false);
		

//assign to nextStep value of next step and change onclick of back and continue buttons to relevant.
	if(position=="back"){
		nextStep=backStep;
		$("back_step").onclick=function(){totPages(nextStep,'back')};
		$("fwd_step").onclick=function(){totPages(nextStep,'fwd')};
	}
	else{
			nextStep=fwdStep;
			$("back_step").onclick=function(){totPages(nextStep,'back')};
			/*if(nextStep>stepsArray.length){
				$("fwd_step").onclick=function(){};
				$("fwd_step").href="/uk.members"; //put here the address of page that you want	
				nextStep=step;
			}
			else{*/
				$("fwd_step").onclick=function(){totPages(nextStep,'fwd')};
				$("back_step").onclick=function(){totPages(nextStep,'back')};				
			/*}*/
	}

	for(var i=0; i<stepsArray.length; i++) {
	//if id of current element of array == "next" step than show it, else - hide it.
		if(stepsArray[i].id==("tot_step_"+nextStep)){
			stepsArray[i].style.display='inline';
		}
		else{
			stepsArray[i].style.display='none';
		}
	}
	//if you reached to first or last step - hide back button
	if(nextStep==1){
		$("back_step").style.display='none';
		$("fwd_step").style.display='inline';
	}
	else if(nextStep==7){
		$("fwd_step").style.display='none';
		$("back_step").style.display='inline';
	}

	else{
		$("back_step").style.display='inline';
		$("fwd_step").style.display='inline';
	}	
}


function changeClass(elId,newClass){
	var el = $(elId);
	el.className=newClass;
}
function changeJoinClass(elId,newClass){
	var el = $(elId);
	if(isIE){
		if(el.className.indexOf("sales_join_cont_hover")<0){
			el.className=newClass;
			pngBgDivFix(elId);
		}
		else{
			el.className=newClass;
			pngBgDivFix(elId);
		}

	}
	else{
		el.className=newClass;
	}
}


function show_meal_details(id){
    if(!(getStyle($(id+"_details"),"display")=='none')){
		$(id+"_details").style.display='none';
		changeInnerHTML(id, "Show details");
	}
	else{
		$(id+"_details").style.display='inline';
		changeInnerHTML(id, "Hide details");
	}
}


function referafriendSubmit()
{
	document.referafriendForm.submit();
}


var lastClassSelection = new Array();
function class_toggle(to_id,class1,class2,init_id) {
	
	if($(init_id)) 
		if($(init_id).className==class1) 
			$(init_id).className=class2;
    if($(lastClassSelection[init_id])) 
		$(lastClassSelection[init_id]).className = class2;
    if($(to_id)) {
		$(to_id).className = class1;
		lastClassSelection[init_id] = to_id;
	} 	
}	

var slidersActive = new Array();
function activateSlider(sliderID) {
	
	if($(sliderID)) slidersActive[sliderID] = true;
}
function deactivateSlider(sliderID) {
	
	if($(sliderID)) slidersActive[sliderID] = false;
}
function isSliderActive(sliderID) {
	
	if(slidersActive[sliderID]) return true;
	else return false;
}
var slidersValues = new Array();
function setSliderValue(sliderID,value) {

	if(sliderID.length) slidersValues[sliderID] = value;
}

	
function bg_change(to_id){
    ten = document.getElementById(to_id);
    ten.style.background = "#FED7B0";
  }

function bg_restore(number){
  for (var i=0; i<=number; i++){
    document.getElementById("row_"+i).style.background = "#FEF4E8";
  }
}

var lastSelection;

function bg_toggle(to_id,selected,notselected) {				
	
	var notselectedColor = '#FEF4E8';
	var selectedColor = '#FED7B0';
	if(selected) selectedColor = selected;
	if(notselected) notselectedColor = notselected;
	
    if(document.getElementById(lastSelection)){
		document.getElementById(lastSelection).style.backgroundColor = '#FEF4E8'; //notSelectedColor
		//document.getElementById("link"+lastSelection).style.color = "#000000"
	}
    if(document.getElementById(to_id)) {
		document.getElementById(to_id).style.backgroundColor = '#FED7B0'; //selectedColor
		//document.getElementById("link"+to_id).style.color = "#ffffff";
		lastSelection = to_id;
	}       		
}

function btoggle(to_id) {				
    
    if(document.getElementById(to_id)) {document.getElementById(to_id).style.background = "#FED7B0";lastSelection = to_id;}       		
}	

function gotoSite() 
{
	var number = NavSelect.selectedIndex;
	location.href = NavSelect.options[number].value; 
}

function sendInviteByAjax(){
	setReqUrl('uk.community.ff.manage.invite');
	req('invitefreind',{
		"nicknames" : document.getElementById('nicknames').value,
		"invitemessage" : document.getElementById('inviteMessage').value,
		"leagueId" : document.getElementById('leagueId').value,
		"leagueManager" : document.getElementById('leagueManager').value
	});
}


function redrowMystats()
{
   // setReqUrl('uk.mystats');
    //setTimeout("req('generate_flashs')", 4000);	
}

function OtherActEffortDrop(val) {
	
	if($('effort')) {
				
		$('effort').options.length = 0;
		switch(val) {
			
			case 1:
				$('effort').options[0] = new Option('Normal','2');
				break;
			case 2:
				$('effort').options[0] = new Option('Normal','2');
				$('effort').options[1] = new Option('Heavy','3');				
				break;
			default:
				$('effort').options[0] = new Option('Light','1');
				$('effort').options[1] = new Option('Normal','2');
				$('effort').options[2] = new Option('Heavy','3');				
		}
	}
}


function mouseOverToggle(obj,eventType){

	var isPNG=false;

	if (obj.className.indexOf("pngFix")!=-1 && is_ie6){
			obj.style.backgroundImage="";		
			obj.style.filter="";
			obj.className=obj.className.replace(/pngBgFix/g,'')
			isPNG=true;
	}
	if (eventType.type=="mouseover"){		
		obj.className=obj.className.replace(/mouseOut/g,'mouseOver')
	}
	if (eventType.type=="mouseout"){
		obj.className=obj.className.replace(/mouseOver/g,'mouseOut')
	}		
	
	if (isPNG){
		obj.className=obj.className+" pngFix";	
	}
}

var fitbug_confirm_response = 0;
var cacheHtml = null;

function fitbug_confirm(title, text , js) {
	
	if(!$('popupContainer') || !$('confirm_popup')) return false;
	if($('confirm_popup_title')) $('confirm_popup_title').innerHTML = title;
	if($('confirm_popup_text')) $('confirm_popup_text').innerHTML = text;
	if(cacheHtml==null) cacheHtml = $('popupContainer').innerHTML;
	if($('popupContainer').innerHTML!=$('confirm_popup').innerHTML)	$('popupContainer').innerHTML = $('confirm_popup').innerHTML;
	
	if(fitbug_confirm_response == 0) {
		
		setTimeout("fitbug_confirm(\""+ title + "\",\""+ text + "\",\"" + js + "\");",200);
		return null;
	} else {
		if(cacheHtml!=null)	$('popupContainer').innerHTML = cacheHtml;
		cacheHtml = null;
		var resp = fitbug_confirm_response;
		fitbug_confirm_response = 0;
		if(resp==1) {			
			eval(js);
			return true;
		} else 
			return false;
	}	
}
function ffHelpLinks(id){
	var helpLinksArray=new Array();
	helpLinksArray=ElementsByClass(document.getElementById("ffHelpLinks"), "ffHelpL", "a", true);
	
	var helpSecArray=new Array();
	helpSecArray=ElementsByClass(document.getElementById("modalFFHelp_body"), "nh_pop_col2", "div", false);
	
	for(var x=0;x<helpLinksArray.length;x++){
		if(helpLinksArray[x].id==id+"_l"){			
			helpLinksArray[x].className="ffHelpLC";
		}
		else{
			helpLinksArray[x].className="ffHelpLReg";
		}
	}
	for(var x=0;x<helpSecArray.length;x++){
		if(helpSecArray[x].id==id){			
			helpSecArray[x].style.display="block";
		}
		else{
			helpSecArray[x].style.display="none";
		}
	}	
	

}