function js_enumerate_dates_value( thisday, thismonth , thisyear ) {
	
	date_value_population = new Array;
    array_months = new Array("01" , "02" , "03" , "04" , "05" , "06" , "07" , "08" , "09" , "10" , "11" , "12" );
    array_dates = new Array ("01" , "02" , "03" , "04" , "05" , "06" , "07" , "08" , "09" , "10" , "11" , "12" , "13" , "14" , "15" , "16" , "17" , "18" , "19" , "20" , "21" , "22" , "23" , "24" , "25" , "26" , "27" , "28" , "29" , "30" , "31");
    
	var myYear  = parseInt(thisyear);
	var myMonth = parseInt(thismonth,10);
    var cmDate  = parseInt(thisday,10);
    var calDate = new Date( thisyear,  thismonth, thisday, 0,0,0,0 ); 
    var mDays   = isLeapYear(thisyear) ? leapdays[thismonth]: yeardays[thismonth]; 
    
    for (var idate =0 ; idate < 366 ; cmDate++, idate++) {//diff_date
        if(cmDate>mDays) { 
            cmDate=1;
            myMonth = (myMonth +1)%12;
            mDays  = isLeapYear(myYear) ? leapdays[myMonth]: yeardays[myMonth]; 
            myYear = (myMonth == 0)? (myYear + 1): myYear;
        }
        
        var get_date = cmDate; 
        var get_month = myMonth; 
        var get_year = myYear; 

        var date_in_array = get_date-1;
        var date_value_format = get_year + "-" + array_months[get_month] + "-" + array_dates[date_in_array];
        date_value_population.push(date_value_format);
    }   

    return date_value_population;
}

function js_enumerate_dates_description( thisday, thismonth , thisyear ) {
    
    description_date_population = new Array;
    desc_short_month = new Array("Jan" , "Feb" , "Mar" , "Apr" , "May" , "Jun" , "Jul" , "Aug" , "Sep" , "Oct" , "Nov" , "Dec" );
    desc_shot_date   = new Array("Sun" , "Mon" , "Tue" , "Wed" , "Thu" , "Fri" , "Sat" );

    var myYear  = parseInt(thisyear);
	var myMonth = parseInt(thismonth,10);
    var cmDate  = parseInt(thisday,10);

    var calDate = new Date( thisyear,  thismonth, thisday, 0,0,0,0 ); 
    var mDays = isLeapYear(thisyear) ? leapdays[thismonth]: yeardays[thismonth]; 
    var wkDay = calDate.getDay(); 

    for (var idate =0 ; idate < 366 ; cmDate++, idate++) {//diff_date   
        var get_day = desc_shot_date[((idate +wkDay)%7)]  ;
        
        
        if(cmDate>mDays) { 
            cmDate=1;
            myMonth = (myMonth +1)%12;
            mDays = isLeapYear(myYear) ? leapdays[myMonth]: yeardays[myMonth]; 
            myYear    = (myMonth == 0)? myYear + 1: myYear;
        }        
        var get_date = cmDate; 
        var get_month = myMonth; 
        var get_year = myYear; 
        
        var date_desc_format =  get_day  + " " + get_date + " " + months[get_month] + " " + get_year;  
        description_date_population.push( date_desc_format );
    }   

    return description_date_population;
}
function isLeapYear( year ){
    return ( (0 == (year%4)) && ( (0 != (year%100)) || (0 == (year%400)))); 
}

function js_enumerate_dates_value_old( start_date_value, end_date_value ) {
    
    date_value_population = new Array();
    
    array_months = new Array("01" , "02" , "03" , "04" , "05" , "06" , "07" , "08" , "09" , "10" , "11" , "12" );
    array_dates  = new Array("01" , "02" , "03" , "04" , "05" , "06" , "07" , "08" , "09" , "10" , "11" , "12" , "13" , "14" , "15" , "16" , "17" , "18" , "19" , "20" , "21" , "22" , "23" , "24" , "25" , "26" , "27" , "28" , "29" , "30" , "31");
    
    var epoch_start_date_value = Date.parse(start_date_value);
    var epoch_end_date_value   = Date.parse(end_date_value);
    var total_epoch_in_one_day = (24*60*60*1000);
    var diff_date              = Math.round( (epoch_end_date_value - epoch_start_date_value) / total_epoch_in_one_day );

    for (var idate =0 ; idate <= diff_date ; idate++) {
        
        var epoch_next_date = epoch_start_date_value + (total_epoch_in_one_day * idate);
        next_date_object = new Date(epoch_next_date);
        
        var get_date = next_date_object.getDate();
        var get_month = next_date_object.getMonth();
        var get_year = next_date_object.getFullYear();
        
        var date_in_array = get_date-1;
        var date_value_format = get_year + "-" + array_months[get_month] + "-" + array_dates[date_in_array];

        date_value_population.push(date_value_format);
        
    }   

    return date_value_population;
}

function js_enumerate_dates_desc_old( start_date_desc, end_date_desc ) {
    
    description_date_population = new Array();
    desc_short_month = new Array("Jan" , "Feb" , "Mar" , "Apr" , "May" , "Jun" , "Jul" , "Aug" , "Sep" , "Oct" , "Nov" , "Dec" );
    desc_shot_date   = new Array("Sun" , "Mon" , "Tue" , "Wed" , "Thu" , "Fri" , "Sat" );

    var epoch_start_date_desc  = Date.parse( start_date_desc);
    var epoch_end_date_desc    = Date.parse( end_date_desc  );
    var total_epoch_in_one_day = (24*60*60*1000);
    var diff_date              = Math.round( (epoch_end_date_desc - epoch_start_date_desc) / total_epoch_in_one_day )

    for(var sdate =0 ; sdate <= diff_date ; sdate++) {
        
        var epoch_next_date  = epoch_start_date_desc + (total_epoch_in_one_day * sdate);
        next_date_object = new Date(epoch_next_date);
        
        var get_day   = next_date_object.getDay();
        var get_date  = next_date_object.getDate();
        var get_month = next_date_object.getMonth();
        var get_year  = next_date_object.getFullYear();
        
        var date_desc_format = desc_shot_date[get_day] + " " + get_date + " " + desc_short_month[get_month] + " " + get_year; 
        description_date_population.push( date_desc_format );
    }   

    return description_date_population;
}

function create_date_object_from_string( input_date_string ) {

    var split_date_string = input_date_string.split("-");

    var year  = split_date_string[0];
    var month = split_date_string[1]-1;
    var ndate = split_date_string[2]
    
    date_object = new Date( year , month , ndate );
    
    return date_object;
}

function do_create_option_dropdown( value_population , desc_population , default_value , tag_id ) {
    
    var option_dropdown;
    if(tag_id){
        var tags_id = tag_id;
        var tag_object = document.getElementById( tag_id );
    
    if( tag_object.hasChildNodes() == true )
	{
	  	tag_object.innerHTML = '';
	}else{
	}

    for(var i = 0; i < value_population.length ; i++) {  
        
        var tag_option  = document.createElement("option");
        var att_value   = document.createAttribute("value");
        att_value.value = value_population[i];
        tag_option.setAttributeNode(att_value);
        
        if (value_population[i] == default_value )
        {
            var att_selected = document.createAttribute("selected");
            att_selected.value = "selected" ;
            tag_option.setAttributeNode(att_selected);
        }
        
        var label_value = document.createTextNode( desc_population[i] )
        tag_option.appendChild(label_value)

       document.getElementById(tags_id).appendChild( tag_option );  
    }   
    
    return option_dropdown;
    }
    else {
  	    return false;
    }
}

function create_next_date_string( begin_date_string , number_next_date ) {
    
    var split_date_string = begin_date_string.split("-");
    var year  = split_date_string[0];
    var month = split_date_string[1]-1;
    var ndate = split_date_string[2];
    
    next_date_object = new Date(year, month, ndate);
    next_date_object.setDate( next_date_object.getDate() + number_next_date );
    
    var array_month = (next_date_object.getMonth()+1);
    var array_day   = next_date_object.getDate();
    
    var next_month      = ( ( array_month < 10) ? "0" : "") + array_month;
    var next_day        = ( ( array_day   < 10) ? "0" : "") + array_day;
        
    var next_date_string = ( next_date_object.getFullYear() ) + "-" + next_month  + "-" + next_day;

    return next_date_string;
}

