function checkData(objtextbox)
{
    objtextbox.value = objtextbox.value.replace(/\,/, ".");

    var exp = /[^\d.,]/g;
    objtextbox.value = objtextbox.value.replace(exp,'');
}

function MakePrint(urla,PrintDiv){ 

    var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,";
    disp_setting+="scrollbars=yes,width=750, height=600, left=50, top=50";
    var content_vlue = jQuery('#'+PrintDiv).html();
    var docprint=window.open("","",disp_setting);
    docprint.document.open();
    docprint.document.write('<!DOCTYPE html PUBLIC "-\/\/W3C\/\/DTD XHTML 1.0 Strict\/\/EN" "http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-strict.dtd"><html xmlns="http:\/\/www.w3.org\/1999\/xhtml"><html><head><title>Myfitness<\/title>');
    //docprint.document.write('<link href="http:\/\/' + urla+ '\/gfx\/style.css" rel="stylesheet" type="text\/css">');
    docprint.document.write('<link href="http:\/\/' + urla+ '\/gfx\/schedule_print.css" rel="stylesheet" type="text\/css">');
    docprint.document.write('<\/head><body onload="window.print()">');

    docprint.document.write('<div class="schedule_wrap"><div class="schedule_content">'+content_vlue+'<\/div><\/div>');
  
    docprint.document.write('<\/body><\/html>');
    docprint.document.close();
    docprint.focus();
}

function ResetEditFields(date){
    $('[rel=ewdm]').each(function() {
        $('#'+this.id).attr('value','');
    });
    $('[rel=btns]').hide();
    $('#box2').hide();
    $('#b_add').show();
    $('#weditdate').attr('value',date);
    $('#wedivdate').html(date);
}

function EditWatcher(id,date){
    $('[rel=btns]').hide();
    $('#b_save').show();

    $('[rel=editbox]').show();
    $('#box2').hide();
    $('[rel=editboxes]').hide();
    $('#weditarea').show();
    $('[rel2=e'+id+']').each(function() {
        $('#efill_'+this.dir).attr('value',this.title);
    });
    $('#wid').attr('value',id);
    $('#weditdate').attr('value',date);
    $('#wedivdate').html(date);
}

function uaGetPassword(){
    var request='';
    $('[rel=uafp]').each(function(idx, item) {
        var name= item.name;
        var value= item.value;
        request = request +'&'+name+'='+value;
    });
    ua_ajax('ua_content','ua_page=forgot_password&action=forgot_password'+request);
}
function uaUpdatePassword(){
    var request='';
    $('[rel=uapp]').each(function(idx, item) {
        var name= item.name;
        var value= item.value;
        request = request +'&'+name+'='+value;
    });
    ua_ajax('ua_content|ua_mydata','ua_page=myprofile&action=modpassword'+request);
}

function uaUpdateProfile(){
    var request='';
    $('[rel=uapf]').each(function(idx, item) {
        var name= item.name;
        var value= item.value;
        request = request +'&'+name+'='+value;
    });
    ua_ajax('ua_content|ua_mydata','ua_page=myprofile&action=modprofile'+request);
}

function getwuaCalendar(year, month)
{
    var id = $("#ua_wcalendar_id").val();
    ua_ajax('ua_wcalendar','id='+id+'&_year='+year+'&_month='+month);
}


function getuaCalendar(year, month)
{
    var id = $("#ua_calendar_id").val();
    ua_ajax('ua_calendar','id='+id+'&_year='+year+'&_month='+month);
}

function toggleScheduleWrap(caser) {
    height = $(document).height();
    $('.overlay_schedule').css('height', height);

    if (caser=="hide") {
        $('.overlay_schedule').hide();
    } else if(caser=="show"){
        $('.overlay_schedule').show();
        ua_ajax('ua_mainmenu|ua_mydata|ua_content|ua_mydata','');
    }

    return false;
};
function toggleSchedule() {
    if ($('.schedule').is(':visible')) {
        $('.schedule').hide();
        $('.heading_grey').removeClass('open');
    } else {
        $('.schedule').show();
        $('.heading_grey').addClass('open');
    }
    return false;
};

function ua_ajax(divs,params,location)
{
    if(location == 'kristiine')
		from_time = new Date(2012,1,2,1,1,1,1).getTime();
	else
		from_time = new Date().getTime();
	
    target_id="ajax";
    ajax_url="/ua_ajax.php?divs=" + divs+"&"+params+"&nc=" + from_time;
	
    div_array=divs;
    div_array=div_array.split('|');
	
    jQuery.each(div_array, function(key1,div_id1){
        $('#'+div_id1).html('<img src="http://www.myfitness.ee/gfx/ajax-loader.gif" class="ajaxloader" />');
    });
	
    $.ajax({
        url: ajax_url,
        dataType: "json",
        success: function(html){           
            if (typeof(html)=="object"){
                jQuery.each(html.divs, function(key,div_id){
                    var c_data='html.data.'+div_id;
	        		
                    if($('#'+div_id)){                        
                        $('#'+div_id).html(eval(c_data));
                    }
	        		
                    $(document).ready(function() {
                        
                        $('div.overlay_schedule').css('height', $(document).height() + 10);
                    });
                });
                $(document).ready(function() {
                    Cufon.refresh();
                    $('div.overlay_schedule').css('height', $(document).height());
                });
            }
        }
    });
}    

function DeleteWatcher(wid){
    ua_ajax('ua_content','ua_page=watcher&caser=rwdm&action=delete&wid='+wid);
}

function RefreshDiary(q_period,period_start,period_end,compare_start,compare_end){
    ua_ajax('ua_content','ua_page=diary&q_period='+q_period+'&period-start='+period_start+'&period-end='+period_end+'&compare-start='+compare_start+'&compare-end='+compare_end);
}


function RefreshWatcher (q_period,from,to,cf,ct){
    if(from && to && cf && ct){
        ua_ajax('ua_content','ua_page=watcher&q_period=compare&period-start='+from+'&period-end='+to+'&compare-start='+cf+'&compare-end='+ct);
    }
    else if(from && to && cf==1 && ct==1){
        ua_ajax('ua_content','ua_page=watcher&q_period=compare&period-start='+from+'&period-end='+to+'&act=clean_compare');
    }
    else if(from && to){
        ua_ajax('ua_content','ua_page=watcher&q_period=period&period-start='+from+'&period-end='+to);
    }
    else {
        ua_ajax('ua_content','ua_page=watcher&q_period='+q_period);
    }
}



function WatherSave(caser,wact,ic ){
    var pre_url = '&caser='+caser+'&action='+wact ;

    $('[rel='+caser+ic+']').each(function() {
        var value = '';
        
        if(this.type=="checkbox"){
            if ($('#'+this.id+':checked').val()) {
                value = '1';
            }
            else {
                value = '0';
            }
        }
        else {
            value = this.value;
        }

        params[this.name] = value;
        pre_url=pre_url+'&'+this.name+'='+value;
        
    });
    
    ua_ajax('ua_content','ua_page=watcher&'+pre_url);
    
}

function umenu(menu){
    $('[rel=subs]').hide();
    $('#subh_'+menu).show();
    $('[rel=umenu]').removeClass('active');
    $('#um_'+menu).addClass('active');
}

function sub_menu(menu){		
    $('[rel=sub_menu]').removeClass('active');
    $('#subm_'+menu).addClass('active');
}

function ua_GetSchDate(ua_gim,ua_date){
    ua_ajax('ua_content','ua_page=schedule&ua_gim='+ua_gim+'&date='+ua_date);
}


function ua_tooltip(div_id,what,lisa){
    var current_div_content=$('#'+div_id+'A').html();
	
    if(lisa){
        var div_id = div_id + lisa;
    }
    else {
		
    }
	
    var current_div_width=$('#'+div_id).outerWidth();
	
    var current_div_pos = $('#'+div_id).offset();
    var current_div_opos = $('#'+div_id).position();
	
    var eWidth = $('#big_schedule').offset();
    var start_p = $('[class=schedule_container]').position();
	
    var tooltip_div='#ua_tooltip';
    var new_x=Math.round(current_div_pos.left-eWidth.left+current_div_width-30);
    var new_y=Math.round(current_div_pos.top-eWidth.top-start_p.top-55);

    if($(tooltip_div)){
        $(tooltip_div).show();
        $(tooltip_div).html(current_div_content);
        $(tooltip_div).css('left',new_x);
        $(tooltip_div).css('top',new_y);
    }
	
	
}
