function overview_graph_weight(){
    $.ajax({
      url: "/dl_php/mydiary/ajax_overview_graph_weight.php",
      dataType : "script"
    });
}

function overview_graph_waist(){
    $.ajax({
      url: "/dl_php/mydiary/ajax_overview_graph_waist.php",
      dataType : "script"
    });
}

function overview_graph_neck(){
    $.ajax({
      url: "/dl_php/mydiary/ajax_overview_graph_neck.php",
      dataType : "script"
    });
}

function overview_graph_hip(){
    $.ajax({
      url: "/dl_php/mydiary/ajax_overview_graph_hip.php",
      dataType : "script"
    });
}

function overview_graph_nutritional(sdate){
	// random number to make sure  it is really loaded
	
    $.ajax({
      url: "/dl_php/mydiary/ajax_overview_graph_nutritional.php",
      dataType : "script",
      data : "rand="+Math.random()+"&date="+sdate
    });
}

function updateDate(datum, geenAjax){
// change the class of the highlighted date
	var divs = document.getElementById('calendar').getElementsByTagName("div");
	for (var i = 0; i < divs.length; i++) {
		divs[i].className = 'date';
	}

	fb = document.getElementById("d" + datum);
	fb.className="date current";
	
	datum_orig = datum;
	datum = new String(datum);
	
	datumnumber = new Number(datum);
	my_year = datum.substring(0,4);
	my_month = datum.substring(4,6);
	my_day = datum.substring(6,8);
	datumtext = my_day+"/"+my_month;
	
	
	dt = new Date();
	datum_today = dt.getDate()+"/"+(dt.getMonth()+1);
	
	
	if ( (Number(my_day) == dt.getDate()) && (Number(my_month) == dt.getMonth()+1) ){
		datumtext = today_text;
	}
	
	datumtoday = dt.getFullYear()+ " "+dt.getMonth()+" "+dt.getDay();
	
	document.myFoodDiary.day.value = datum;
	document.myRecipes.day.value = datum;
	document.myProducts.day.value = datum;
	document.dlRecipes.regdate.value = datum;
	document.mySport.day.value = datum;
	document.mySportDiary.day.value = datum;
	document.mySportFree.day.value = datum;
	document.mySummary.regdate.value = datum;
	// document.myProducts.regdate.value = datum;
	
// update nutrition
	setTimeout(function(){overview_graph_nutritional(my_year+"-"+my_month+"-"+my_day);},4000);
// weight
    var regEx = new RegExp ('###', 'gi') ;
    
	mydate = new Date();
	mydate.setDate(my_day);
	mydate.setMonth(my_month-1);
	mydate.setFullYear(my_year);

	today = new Date();
	
	if (mydate <= today ){ 
		document.myWeight.day.value = datum.toString();
		document.myWaist.day.value = datum.toString();
		document.myNeck.day.value = datum.toString();
		document.myHip.day.value = datum.toString();
		 
		str = weight_today_text;
		document.getElementById('weight_today').innerHTML =  str.replace(regEx, datumtext);
	// waist
		str = waist_today_text;
		document.getElementById('waist_today').innerHTML =  str.replace(regEx, datumtext);
	// neck
		str = neck_today_text;
		document.getElementById('neck_today').innerHTML =  str.replace(regEx, datumtext);
	// hip
		str = hip_today_text;
		document.getElementById('hip_today').innerHTML =  str.replace(regEx, datumtext);
	}
// food
	str = food_today_text;
	document.getElementById('food_today').innerHTML =  str.replace(regEx, datumtext);
// sport
	str = sport_today_text;
	document.getElementById('sport_today').innerHTML =  str.replace(regEx, datumtext);

    if (geenAjax != "geen")
    {
		// weight
        var options_summary = {
            target:        '#mySummaryTable',
            success:       showResponse,
            resetForm: true
        };
        $('#mySummary').ajaxSubmit(options_summary);
		
        var options_food = {
            target:        '#myFoodDiaryTable',
            success:       showResponse,
            resetForm: true,
            clearForm: true
        };
        $('#myFoodDiary').ajaxSubmit(options_food);

        var options_sportsdiary = {
            target:        '#mySportDiaryTable',
            success:       showResponse,
            resetForm: true,
            clearForm: true
        };
        $('#mySportDiary').ajaxSubmit(options_sportsdiary);
    }
}

function submitFaqZoek(){
    document.getElementById("faqZoekTermForm").value = document.getElementById("faqZoekTerm").value;

    var options_faq_zoek = {
        target:        '#searchresult',
        success:       showResponse,
        resetForm: true
    };
    $('#faqZoek').ajaxSubmit(options_faq_zoek);
}

function submitHomeCheckPromo(){
    document.getElementById("homeCodeForm").value = document.getElementById("subscriptionNumber").value;
    if (document.getElementById("subscriptionNumberContr"))
    {
        document.getElementById("homeContoleForm").value = document.getElementById("subscriptionNumberContr").value;
    }
    else if (document.getElementById("controlNumber"))
    {
        document.getElementById("homeContoleForm").value = document.getElementById("controlNumber").value; 
    }

    var options_check_promo = {
        target:        '#homecheckresult',
        success:       showResponse,
        resetForm: true
    };
    $('#homeCheckPromo').ajaxSubmit(options_check_promo);
}
