var day_name = Array('Ïí','Âò','Ñð','×ò','Ïò','Ñá','Âñ');
var month_name = Array('ßíâ','Ôåâ','Ìàð','Àïð','Ìàé','Èþí','Èþë','Àâã','Ñåí','Îêò','Íîÿ','Äåê');
var holiday_month = Array(1, 1, 1, 2, 3, 5, 5, 5, 6,11,12);
var holiday_day   = Array(1, 2, 7,23, 8, 1, 2, 9,12, 7,12);

var isNullDate = false;

var calendarselects;


function stripHTML(oldString) {

   var newString = "";
   var inTag = false;
   for(var i = 0; i < oldString.length; i++) {
   
        if(oldString.charAt(i) == '<') inTag = true;
        if(oldString.charAt(i) == '>') {
              if(oldString.charAt(i+1)=="<")
              {
              		//dont do anything
	}
	else
	{
		inTag = false;
		i++;
	}
        }
   
        if(!inTag) newString += oldString.charAt(i);

   }

   return newString;
}


function calendar_create(cid,min_date,selected_date) {
  var current_date = new Date();
  
  var te = document.getElementsByName (cid);
  for (i = 0; i < te.length; i++) {
  	te[i].id = cid;
  }
  i = 0;
        //if(min_date < current_date)
        //        min_date = current_date;
  if (!selected_date) {
    isNullDate = true;
    selected_date = new Date();
  }
  if (selected_date < min_date)
    selected_date = min_date;
  with(document) {
    writeln('<DIV ID="calendar_facediv_'+cid+'" STYLE="z-index:-1">');
    writeln('<TABLE CELLPADDING=0 CELLSPACING=2 BORDER=0 MARIGN=0><TR>');
    writeln('<TD><INPUT ID="calendar_day_'+cid+'" TYPE=TEXT VALUE="'+selected_date.getDate()+
	 '" SIZE=2  onclick="calendar_show(\''+cid+'\','+min_date.valueOf()+');" STYLE="BACKGROUND-COLOR: #FFFFFF; BORDER-BOTTOM: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; PADDING-BOTTOM: 1px; PADDING-LEFT: 2px; PADDING-RIGHT: 0px; PADDING-TOP: 1px; border-color: 666666; font-family: Tahoma; font-size: 10px; color: #000000; font-weight:bold; width:20px;" onchange="calendar_redraw(\''+cid+'\','+min_date.valueOf()+','+selected_date.valueOf()+');" READONLY=true onkeydown="key_down(this,\''+cid+'\','+min_date.valueOf()+'); calendar_day_keydown(this,\''+cid+'\','+min_date.valueOf()+');"></TD>');
    writeln('<TD>&nbsp;</TD>');
    writeln('<TD><SELECT ID="calendar_month_'+cid+'" STYLE="BACKGROUND-COLOR: #FFFFFF; BORDER-BOTTOM: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; PADDING-BOTTOM: 0px; PADDING-LEFT: 2px; PADDING-RIGHT: 0px; PADDING-TOP: 0px; border-color: #666666; font-family: Tahoma; font-size: 10px; font-weight: bold; color: #000000;" onchange="check_day(\''+cid+'\','+min_date.valueOf()+'); calendar_redraw(\''+cid+'\','+min_date.valueOf()+');" onkeydown="key_down(this,\''+cid+'\');">');
	for (i=(/*(min_date.getFullYear() == selected_date.getFullYear()) ? min_date.getMonth() : */0); i<12; i++) {
      if (selected_date.getMonth() == i)
        writeln('<OPTION VALUE="'+i+'" SELECTED>'+month_name[i]+'</OPTION>')
	  else 
	    writeln('<OPTION VALUE="'+i+'">'+month_name[i]+'</OPTION>');
    }
    writeln('</SELECT></TD>');
    writeln('<TD>&nbsp;</TD>');
    writeln('<TD><SELECT ID="calendar_year_'+cid+'" STYLE="BACKGROUND-COLOR: #FFFFFF; BORDER-BOTTOM: #000000 1px solid; BORDER-LEFT: #000000 1px solid; BORDER-RIGHT: #000000 1px solid; BORDER-TOP: #000000 1px solid; PADDING-BOTTOM: 0px; PADDING-LEFT: 2px; PADDING-RIGHT: 0px; PADDING-TOP: 0px; border-color: #C0C0C0; font-family: Tahoma; font-size: 11px; font-weight: bold; color: #000000;" onchange="check_day(\''+cid+'\'); calendar_redraw_month_check(\''+cid+'\','+min_date.valueOf()+');" onkeydown="key_down(this,\''+cid+'\');">');
    var today_date = new Date();
    for(i=today_date.getFullYear()+2; i >= min_date.getFullYear(); i--) {
      if (i == selected_date.getFullYear())
        writeln('<OPTION VALUE="' + i + '" SELECTED>' + i + '</OPTION>');
      else
        writeln('<OPTION VALUE="' + i + '">' + i + '</OPTION>');
    }
    writeln('</SELECT></TD><TD><IMG ID="calendar_clear_'+cid+'" src="/icon/delete.gif" onclick="calendar_clear(\''+cid+'\')" STYLE="display:none;"><IMG ID="calendar_new_'+cid+'" src="/icon/new.gif" onclick="calendar_new(\''+cid+'\')" STYLE="display:none;"></TD>');
    writeln('</TR></TABLE>');
    writeln('</DIV>');
    writeln('<DIV ID="calendar_div_'+cid+'" STYLE="position:absolute; display:none; z-index:1; background-color:white">');
    writeln('</DIV>');
  }
  if (isNullDate) {
    document.getElementById('calendar_clear_'+cid).style.display = 'none';
    document.getElementById('calendar_day_'+cid).style.display   = 'none';
    document.getElementById('calendar_month_'+cid).style.display = 'none';
    document.getElementById('calendar_year_'+cid).style.display  = 'none';
    document.getElementById('calendar_new_'+cid).style.display = 'block';
    if (document.getElementById(cid)) 
	  document.getElementById(cid).value = '';
    if (document.getElementById("lnk"+cid)) 
	  document.getElementById("lnk"+cid).value = 0;
    if (cid == 2)
	  if (document.getElementById("filter_1_paid_till"))
	    document.getElementById("filter_1_paid_till").value = '';
    if (cid == 4)
	  if (document.getElementById("filter_2_paid_till")) 
	    document.getElementById("filter_2_paid_till").value = '';
    if (cid == 1)
	  if (document.getElementById("filter_1_contact_date_low"))
	    document.getElementById("filter_1_contact_date_low").value = '';
    if (cid == 2)
      if (document.getElementById("filter_1_contact_date_high"))
	    document.getElementById("filter_1_contact_date_high").value = '';
    if (cid == 3)
	  if (document.getElementById("filter_2_contact_date_low"))
	    document.getElementById("filter_2_contact_date_low").value = '';
    if (cid == 4)
	  if (document.getElementById("filter_2_contact_date_high"))
	    document.getElementById("filter_2_contact_date_high").value = '';
    if (cid == 1)
	  if(document.getElementById("filter_1_addtime_low"))
	    document.getElementById("filter_1_addtime_low").value = '';
    if (cid == 2)
	  if (document.getElementById("filter_1_addtime_high"))
	    document.getElementById("filter_1_addtime_high").value = '';
    if (cid == 3)
	  if (document.getElementById("filter_2_addtime_low"))
	    document.getElementById("filter_2_addtime_low").value = '';
    if (cid == 4)
	  if (document.getElementById("filter_2_addtime_high"))
	    document.getElementById("filter_2_addtime_high").value = '';
  }
}

function calendar_show(cid,min_date_val) {
	if (document.all) {
  	var showed_calendars_div = document.getElementsByTagName("div");
	} else {
		var showed_calendars_div = document.getElementsByTagName ('div') ;//document.getElementsByTagName("div");
	}
  for (i=0; i < showed_calendars_div.length; i++) {

    re=/calendar_div_/i;
    if (showed_calendars_div[i].id.match(re) != null)
      if (showed_calendars_div[i].style.display == 'block') {
        return;
      }
    }

  var current_date = new Date();
  var min_date = new Date(min_date_val);
  min_date.setHours(23,59,00,000);  // END_OF_DAY_TIME
  
  var selected_date = new Date(document.getElementById('calendar_year_'+cid).value, document.getElementById('calendar_month_'+cid).value, document.getElementById('calendar_day_'+cid).value);
  selected_date.setHours(23,59,00,000);  // END_OF_DAY_TIME
  var firstday_date = new Date(selected_date.getFullYear(), selected_date.getMonth(), 1);
  var firstday_weekday = ((firstday_date.getDay()+6)%7);
  var tmp_date;
  res_table='';
  res_table+='<TABLE CELLPADDING=0 CELLSPACING=0 BORDER=1 BORDERCOLOR=#C0C0C0 MARIGN=0><TR><TD BORDERCOLOR=white>';
  res_table+='<TABLE ID="calendar_table_'+cid+'" CELLPADDING=1 CELLSPACING=0 BORDER=1 BORDERCOLOR=white STYLE="font-family:Tahoma; font-size:10px;font-weight:bold; text-align:right;">';
  res_table+='<TR STYLE="font-weight:normal;">';

  for (i=0; i<7; i++) {
    res_table+='<TD>'+day_name[i]+'</TD>';
  }
  res_table+='</TR>';

  for (str_num=0;str_num<6;str_num++) {
    res_table+='<TR>';    
    for (i=0; i<7; i++) {
      tmp_date = new Date(selected_date);
      tmp_date.setHours(23,59,00,000);  // END_OF_DAY_TIME
      tmp_date.setDate(i-firstday_weekday+1+str_num*7);
      if (tmp_date.getMonth() == selected_date.getMonth()) {
        if (tmp_date >= min_date) {
          if (tmp_date.toString() == selected_date.toString()) {
            res_table+='<TD ID="selected_day_td_'+cid+'" BORDERCOLOR=red onmouseover="mouse_in(this);" onmouseout="mouse_out(this,true);"  onclick="mouse_click(this,\''+cid+'\');" STYLE="cursor:hand;border-width:2px;">';
          } else {
            res_table+='<TD onmouseover="mouse_in(this);" onmouseout="mouse_out(this,false);" onclick="mouse_click(this,\''+cid+'\');" STYLE="cursor:hand;border-width:2px;">';
          }
          is_holiday = false;
          for (holiday_i=0; holiday_i < holiday_month.length; holiday_i++) {
            if ((tmp_date.getMonth()==(holiday_month[holiday_i]-1) && tmp_date.getDate()==holiday_day[holiday_i]) || ((i)%7==6)) {
              res_table+='<FONT COLOR="red">'+(i-firstday_weekday+1+str_num*7)+'</FONT>';
              is_holiday = true;
              break;
            } else {
              if ((i)%7==5) {
                res_table+='<FONT COLOR="#808080">'+(i-firstday_weekday+1+str_num*7)+'</FONT>';
                is_holiday = true;
                break;
              }
            }
          }
          if (is_holiday == false) {
            res_table+=(i-firstday_weekday+1+str_num*7);
          }
          res_table+='</TD>';
        } else {
          res_table+='<TD STYLE="border-width:2px;"><FONT COLOR="#E0E0E0">' +(i-firstday_weekday+1+str_num*7)+ '</FONT></TD>';
        }
      } else {
        res_table+='<TD></TD>';
      }
      delete tmp_date;
    }
    res_table+='</TR>';
  }
  
  res_table+='</TD></TR></TABLE></TABLE>';
  document.getElementById("calendar_div_"+cid).innerHTML=res_table;
//    alert(cid);
//  alert(document.getElementById('calendar_div_'+cid));
//  alert(document.getElementById('calendar_div_'+cid).style);
  if (document.getElementById('calendar_div_'+cid).style.display=='none') {
//    OLD VERSION
//                document.getElementById("calendar_div_"+cid).style.top  = (event.clientY-event.offsetY-5+20);
//                document.getElementById("calendar_div_"+cid).style.left = (event.clientX-event.offsetX-5);
    document.getElementById("calendar_div_"+cid).style.top  = document.getElementById('calendar_facediv_'+cid).style.top;
    document.getElementById("calendar_div_"+cid).style.left = document.getElementById('calendar_facediv_'+cid).style.left;
    document.getElementById("calendar_div_"+cid).style.display = 'block';
    document.getElementById("calendar_month_"+cid).focus();
//        hide all selects
    var allselects = document.getElementsByTagName("select");
    if (allselects != null) {
      calendarselects = Array();
      for(i=0; i<allselects.length; i++) {
        select_month = 'calendar_month_'+ cid;
        select_year  = 'calendar_year_' + cid;
        re = /calendar_/i;
//alert(getOffset(allselects[i])+";"+document.getElementById('calendar_div_'+cid).offsetTop);
        if ((allselects[i].id!=select_month)&&(allselects[i].id!=select_year)&&(getOffset(allselects[i])>=document.getElementById('calendar_div_'+cid).offsetTop)&&(getOffset(allselects[i])<=document.getElementById('calendar_div_'+cid).offsetTop+document.getElementById('calendar_div_'+cid).offsetHeight)) {
          if (allselects[i].id.match(re) == null) {
            allselects[i].style.display='none';
          } else {
            if (allselects[i].style.display != 'none') {
              calendarselects[calendarselects.length+1] = allselects[i].id;
              allselects[i].style.display = 'none';
            }
          }
        }
      }
    }
  }

}

function calendar_redraw_month_check(cid, min_date_val) {
  var min_date = new Date(min_date_val);
  var month_option;
  if (document.getElementById('calendar_year_'+cid).value > min_date.getFullYear()) {
    with(document.getElementById('calendar_month_'+cid)) {
      if (options.length < 12) {
        var old_value = value;
        for(i=options.length; i>0; i--) {
          options.remove(i-1);
        }
        for(i=0; i<12; i++) {
          month_option = document.createElement("OPTION");
          add(month_option);
          month_option.text = month_name[i];
          month_option.value = i;
        }
        value = old_value;
      }
    }
  }	else {
    with(document.getElementById('calendar_month_'+cid).options) {
      if (options.length == 12){
        var old_value = value;
        for (i=12; i>0; i--) {
          options.remove(i-1);
        }
        for (i=min_date.getMonth(); i<12; i++) {
          month_option = document.createElement("OPTION");
          add(month_option);
          month_option.text = month_name[i];
          month_option.value = i;
        }
        if (old_value > min_date.getMonth())
          value = old_value;
        else
          value = min_date.getMonth();
      }
    }
  }
  if (document.getElementById('calendar_div_'+cid).style.display=='block') {
    calendar_show(cid, min_date_val);
  }
// INFRACAT INTEGRATION
  export_date(cid);
}

function calendar_redraw(cid, min_date_val) {
  if (document.getElementById('calendar_div_'+cid).style.display=='block') {
    calendar_show(cid, min_date_val);
  }
// INFRACAT INTEGRATION
  export_date(cid);
}

function check_day(cid, min_date_val) {
  var min_date = new Date(min_date_val);
  min_date.setHours(23,59,00,000);  // END_OF_DAY_TIME
  var selected_date = new Date(document.getElementById('calendar_year_'+cid).value, document.getElementById('calendar_month_'+cid).value, document.getElementById('calendar_day_'+cid).value);
  selected_date.setHours(23,59,00,000);  // END_OF_DAY_TIME
  if (selected_date < min_date) {
    document.getElementById('calendar_day_'+cid).value = min_date.getDate()
  }
  if (selected_date.getMonth()!=document.getElementById('calendar_month_'+cid).value) {
    document.getElementById('calendar_day_'+cid).value -= selected_date.getDate();
  }
  export_date (cid);
}

function mouse_in(src_element) {
  src_element.borderColor='pink';
}

function mouse_out(src_element,selected) {
  if (selected)
    src_element.borderColor='red';
  else
    src_element.borderColor='white';
}

function mouse_click(src_element,cid) {
  document.getElementById("calendar_day_"+cid).value = stripHTML (src_element.innerHTML);
  document.getElementById("calendar_div_"+cid).style.display = 'none';
//        show all selects
  var allselects = document.getElementsByTagName("select");
  if (allselects != null) {
    for (i=0; i<allselects.length; i++) {
      select_month = 'calendar_month_'+ cid;
      select_year  = 'calendar_year_' + cid;
      re = /calendar_/i;
      if ((allselects[i].id != select_month) && (allselects[i].id != select_year)) {
        if (allselects[i].id.match(re) == null) {
          allselects[i].style.display = 'block';
        } else {
          for (j=0; j<calendarselects.length; j++) {
            if (allselects[i].id == calendarselects[j]) {
              allselects[i].style.display = 'block';
            }
          }
        }
      }
    }
  }
  export_date (cid);
  
}


function calendar_day_keydown(src_element,cid,min_date_val) {
  var new_day = document.getElementById("calendar_day_"+cid).value;
  switch(event.keyCode) {
    case(40): 
	  new_day++;
	  break;
    case(38):
	  new_day--;
	  break;
    case(13): 
	  calendar_day_keyenter(cid, min_date_val); 
	  break;
    default: break;//alert('Unknown keyCode:'+event.keyCode);
  }
  var min_date = new Date(min_date_val);
  min_date.setHours(23,59,00,000);  // END_OF_DAY_TIME
  var selected_date = new Date(document.getElementById('calendar_year_'+cid).value, document.getElementById('calendar_month_'+cid).value, document.getElementById('calendar_day_'+cid).value);
  selected_date.setHours(23,59,00,000);  // END_OF_DAY_TIME
  var new_date = new Date(document.getElementById('calendar_year_'+cid).value, document.getElementById('calendar_month_'+cid).value, new_day);
  new_date.setHours(23,59,00,000);  // END_OF_DAY_TIME
  if ((new_date >= min_date) && (new_date.getFullYear() < (min_date.getFullYear()+5))) {
    document.getElementById("calendar_day_"+cid).value = new_day;
    if (new_date.getMonth() != selected_date.getMonth()) {
      document.getElementById('calendar_year_'+cid).value = new_date.getFullYear();
      document.getElementById('calendar_month_'+cid).value = new_date.getMonth();
      document.getElementById('calendar_day_'+cid).value = new_date.getDate();
    }
    calendar_redraw_month_check(cid, min_date);
  }
}

function calendar_day_keyenter(cid, min_date_val) {
  if (document.getElementById('calendar_div_'+cid).style.display == 'block') {
    document.getElementById("calendar_day_"+cid).value=stripHTML (document.getElementById('selected_day_td_'+cid).innerHTML);
    document.getElementById("calendar_div_"+cid).style.display = 'none';
  } else {
    calendar_show(cid, min_date_val);
  }
}


function key_down(src_element,cid) {
  switch(src_element.id) {
    case('calendar_day_'+cid):
      if (event.keyCode==39)
	    document.getElementById('calendar_month_'+cid).focus();
      break;
    case('calendar_month_'+cid):
      if (event.keyCode==39)
	    document.getElementById('calendar_year_'+cid).focus();
      if (event.keyCode==37)
	    document.getElementById('calendar_day_'+cid).focus();
      break;
    case('calendar_year_'+cid):
      if (event.keyCode==37)
	    document.getElementById('calendar_month_'+cid).focus();
        break;
    default: break;
  }
}

function export_date(cid) {	
	if (document.getElementById(cid)) {
		
    document.getElementById(cid).value=
	 document.getElementById("calendar_year_"+cid).value+'.'+
	 eval(eval(document.getElementById('calendar_month_'+cid).value))+'.'+
	 document.getElementById('calendar_day_'+cid).value;
    if (document.getElementById("lnk"+cid))
	  document.getElementById("lnk"+cid).value = 1;
//alert("Date: "+ document.getElementById(cid).value);
  }
  if (cid == 4){
    if (document.getElementById("filter_2_paid_till")) {
      document.getElementById("filter_2_paid_till").value=
	   document.getElementById("calendar_day_"+cid).value+'.'+
	   eval(eval(document.getElementById('calendar_month_'+cid).value))+'.'+
	   document.getElementById('calendar_year_'+cid).value;
      if (document.getElementById("lnk"+cid))
	    document.getElementById("lnk"+cid).value = 1;
    }
  }
  if (cid == 2){
    if (document.getElementById("filter_1_paid_till")) {
      document.getElementById("filter_1_paid_till").value=
       document.getElementById("calendar_day_"+cid).value+'.'+
	   eval(eval(document.getElementById('calendar_month_'+cid).value))+'.'+
	   document.getElementById('calendar_year_'+cid).value;
      if (document.getElementById("lnk"+cid))
        document.getElementById("lnk"+cid).value=1;
    }
  }
  if (cid == 4){
    if (document.getElementById("filter_2_contact_date_high")) {
      document.getElementById("filter_2_contact_date_high").value=
	   document.getElementById("calendar_day_"+cid).value+'.'+
	   eval(eval(document.getElementById('calendar_month_'+cid).value))+'.'+
	   document.getElementById('calendar_year_'+cid).value;
      if (document.getElementById("lnk"+cid))
	    document.getElementById("lnk"+cid).value = 1;
    }
  }
  if (cid == 3){
    if (document.getElementById("filter_2_contact_date_low")) {
      document.getElementById("filter_2_contact_date_low").value=
       document.getElementById("calendar_day_"+cid).value+'.'+
       eval(eval(document.getElementById('calendar_month_'+cid).value))+'.'+
       document.getElementById('calendar_year_'+cid).value;
      if (document.getElementById("lnk"+cid))
        document.getElementById("lnk"+cid).value=1;
    }
  }
  if (cid == 2){
    if (document.getElementById("filter_1_contact_date_high")) {
      document.getElementById("filter_1_contact_date_high").value=
       document.getElementById("calendar_day_"+cid).value+'.'+
       eval(eval(document.getElementById('calendar_month_'+cid).value))+'.'+
       document.getElementById('calendar_year_'+cid).value;
      if (document.getElementById("lnk"+cid))
        document.getElementById("lnk"+cid).value=1;
    }
  }
  if (cid == 1){
    if (document.getElementById("filter_1_contact_date_low")) {
      document.getElementById("filter_1_contact_date_low").value=
       document.getElementById("calendar_day_"+cid).value+'.'+
       eval(eval(document.getElementById('calendar_month_'+cid).value))+'.'+
       document.getElementById('calendar_year_'+cid).value;
      if (document.getElementById("lnk"+cid))
        document.getElementById("lnk"+cid).value=1;
    }
  }
  if (cid == 4){
    if (document.getElementById("filter_2_addtime_high")) {
      document.getElementById("filter_2_addtime_high").value=
       document.getElementById("calendar_day_"+cid).value+'.'+
       eval(eval(document.getElementById('calendar_month_'+cid).value))+'.'+
       document.getElementById('calendar_year_'+cid).value;
      if (document.getElementById("lnk"+cid))
        document.getElementById("lnk"+cid).value=1;
    }
  }
  if (cid == 3){
    if (document.getElementById("filter_2_addtime_low")) {
      document.getElementById("filter_2_addtime_low").value=
       document.getElementById("calendar_day_"+cid).value+'.'+
       eval(eval(document.getElementById('calendar_month_'+cid).value))+'.'+
       document.getElementById('calendar_year_'+cid).value;
      if (document.getElementById("lnk"+cid))
        document.getElementById("lnk"+cid).value=1;
    }
  }
  if (cid == 2){
    if (document.getElementById("filter_1_addtime_high")) {
      document.getElementById("filter_1_addtime_high").value=
       document.getElementById("calendar_day_"+cid).value+'.'+
       eval(eval(document.getElementById('calendar_month_'+cid).value))+'.'+
       document.getElementById('calendar_year_'+cid).value;
      if (document.getElementById("lnk"+cid))
        document.getElementById("lnk"+cid).value = 1;
    }
  }
  if ( cid == 1){
    if (document.getElementById("filter_1_addtime_low")) {
      document.getElementById("filter_1_addtime_low").value=
       document.getElementById("calendar_day_"+cid).value+'.'+
       eval(eval(document.getElementById('calendar_month_'+cid).value))+'.'+
       document.getElementById('calendar_year_'+cid).value;
      if(document.getElementById("lnk"+cid)) document.getElementById("lnk"+cid).value = 1;
    }
  }
}


function export_empty_date(cid) {
  if (document.getElementById(cid)) {
    document.getElementById(cid).value='';
  }
  if (document.getElementById("lnk"+cid))
     document.getElementById("lnk"+cid).value=1;
  if (document.getElementById("filter_1_paid_till")) {
    document.getElementById("filter_1_paid_till").value='';
  }
  if (document.getElementById("filter_2_paid_till")) {
    document.getElementById("filter_2_paid_till").value='';
  }
  if (document.getElementById("filter_1_addtime")) {
    document.getElementById("filter_1_addtime").value = '';
  }
  if (document.getElementById("filter_2_addtime")) {
    document.getElementById("filter_2_addtime").value = '';
  }
  if (document.getElementById("filter_1_contact_date")) {
    document.getElementById("filter_1_contact_date").value = '';
  }
  if (document.getElementById("filter_2_contact_date")) {
    document.getElementById("filter_2_contact_date").value = '';
  }
}

function calendar_clear(cid) {
  document.getElementById('calendar_clear_'+cid).style.display = 'none';
  document.getElementById('calendar_day_'+cid).style.display   = 'none';
  document.getElementById('calendar_month_'+cid).style.display = 'none';
  document.getElementById('calendar_year_'+cid).style.display  = 'none';
  document.getElementById('calendar_new_'+cid).style.display = 'block';
  export_empty_date(cid);
}


function calendar_new(cid) {
  document.getElementById('calendar_new_'+cid).style.display = 'none';
  document.getElementById('calendar_day_'+cid).style.display   = 'block';
  document.getElementById('calendar_month_'+cid).style.display = 'block';
  document.getElementById('calendar_year_'+cid).style.display  = 'block';
  document.getElementById('calendar_clear_'+cid).style.display = 'block';
  export_date(cid);
}

function getOffset(obj) {
  var offset = 0;
  while (obj!=document.body) {
    offset += obj.offsetTop;
    obj = obj.offsetParent;
  }
  return offset;
}

//if (window.event) {
//        document.captureEvents(Event.MOUSEDOWN);
//        document.onmousedown = hide_onclink;
//}

function hide_onclink() {
//        alert("111");
//        var showed_calendars_div = document.getElementsByTagName("div");
//        for(i=0;i<showed_calendars_div.length;i++) {
//                re = /calendar_div_/i;
//                if(showed_calendars_div[i].id.match(re)!=null)
//                        if(showed_calendars_div[i].style.display == 'block')
//                                if((showed_calendars_div[i].offsetTop >= event.clientY)||((showed_calendars_div[i].offsetTop+showed_calendars_div[i].offsetHeight) <= event.clientY))
//                                if((showed_calendars_div[i].offsetLeft >= event.clientX)||((showed_calendars_div[i].offsetLeft+showed_calendars_div[i].offsetWidth) <= event.clientX))
//                                        showed_calendars_div[i].style.display = 'none';
//        }


//        if(event.srcElement.id.match(re))
//                 if(showed_calendars_div[i].id.match(re)!=null)
//                         alert(event.srcElement.id);

//                 event.srcElement.style.display = 'none';

}


