var WeekTitles=new Array('M','D','M','D','F','S','S');
var selected_cell_id,calendar_mode;
function showallweektitles()
{
	var i, answer="  <tr>\n";
	for(i=0;i<WeekTitles.length;i++) 
	{
		if ((i==5)||(i==6)) {answer+="<th CLASS=\"calendar_holiday\">"+WeekTitles[i]+"</th>\n";}
		else {answer+="<th CLASS=\"calendar\">"+WeekTitles[i]+"</th>\n";}
	}
	answer+="  </tr>\n";
	return answer;
}
function calendar_show(m, d, y)
{
	var sdate= new Date(m+'/1/'+y);
	var mdate= new Date(m+'/'+d+'/'+y);
	var todaydate= new Date(m+'/'+d+'/'+y);
	var days=dayonmonth(m,y);
	var iday=0, day, answer='';
	month_title=get_month_title(m);
	answer+='<table border=0 CLASS="calendar">';
	answer+='  <tr CLASS="calendar">';
	answer+='  	<th CLASS="calendar" colspan=7>';
	answer+='		<table width="100%" border=0 cellpadding=0 cellspacing=0 height="100%">';
	answer+='  			<tr CLASS="calendar">';
	//answer+='    			<td align="left"><b>Calendar</b></td>';
	answer+='    			<td align="center"><b>'+month_title+' '+y+'</b></td>';
	answer+='  			</tr>';
	answer+='		</table>';
	answer+='	</th>';
	answer+='  </tr>';
	answer+='  <tr CLASS="calendar">';
	answer+='  	<th colspan=7>';
	answer+='<table border=0 cellpadding=0 cellspacing=0 width="100%" height="100%">';
	answer+='  <tr CLASS="calendar">';
	answer+='    <td width="25%"><table onClick="calendar_move(\'-\',\'y\','+m+','+d+','+y+')" CLASS="calendar_button_0_1" onMouseOver="this.className=\'calendar_button_1_1\'" onMouseOut="this.className=\'calendar_button_0_1\'" border=0 cellpadding=0 cellspacing=0 width="100%" height="100%"><tr CLASS="calendar"><td><<</td></tr></table></td>';
	answer+='    <td width="25%"><table onClick="calendar_move(\'-\',\'m\','+m+','+d+','+y+')" CLASS="calendar_button_0_2" onMouseOver="this.className=\'calendar_button_1_2\'" onMouseOut="this.className=\'calendar_button_0_2\'" border=0 cellpadding=0 cellspacing=0 width="100%" height="100%"><tr CLASS="calendar"><td><</td></tr></table></td>';
	answer+='    <td width="25%"><table onClick="calendar_move(\'+\',\'m\','+m+','+d+','+y+')" CLASS="calendar_button_0_2" onMouseOver="this.className=\'calendar_button_1_2\'" onMouseOut="this.className=\'calendar_button_0_2\'" border=0 cellpadding=0 cellspacing=0 width="100%" height="100%"><tr CLASS="calendar"><td>></td></tr></table></td>';
	answer+='    <td width="25%"><table onClick="calendar_move(\'+\',\'y\','+m+','+d+','+y+')" CLASS="calendar_button_0_1" onMouseOver="this.className=\'calendar_button_1_1\'" onMouseOut="this.className=\'calendar_button_0_1\'" border=0 cellpadding=0 cellspacing=0 width="100%" height="100%"><tr CLASS="calendar"><td>>></td></tr></table></td>';
	answer+='  </tr>';
	answer+='</table>';
	answer+='	</th>';
	answer+='  </tr>';
	answer+='  <tr>';
	answer+=showallweektitles();

	if(sdate.getDay()==0){mydate=7;}else{mydate=sdate.getDay();}
	for(day=1;day<mydate;day++){
		iday++;
		answer+="<td></td>";
		//alert(answer);
	}
	var cell_ids=1;
	for(day=1;day<=days;day++)
	{
		iday++;
		cell_id="cell_id_"+cell_ids;
		if(((todaydate.getMonth()+1)==m) && (todaydate.getDate()==day) && (todaydate.getFullYear()==y)) {selected_cell_id=cell_ids; answer+="<td id=\""+cell_id+"\" onClick=\"window.returnValue='"+m+"/"+day+"/"+y+"';get_date("+m+","+day+","+y+","+cell_ids+");\" CLASS=\"calendar_today\"><table onMouseOver=\"this.className='calendar_active'\" onMouseOut=\"this.className=''\" border=0 cellpadding=0 cellspacing=0 width=\"100%\" height=\"100%\"><tr CLASS=\"calendar\"><td>"+day+"</td></tr></table></td>";}
		else {answer+="    <td id=\""+cell_id+"\" onClick=\"window.returnValue='"+m+"/"+day+"/"+y+"';get_date("+m+","+day+","+y+","+cell_ids+");\" CLASS=\"calendar\"><table onMouseOver=\"this.className='calendar_active'\" onMouseOut=\"this.className=''\" border=0 cellpadding=0 cellspacing=0 width=\"100%\" height=\"100%\"><tr CLASS=\"calendar\"><td>"+day+"</td></tr></table></td>";}
		if(iday==7)
		{
			answer+="</tr><tr>";
			iday=0;
		}
		cell_ids++;
	}
	//alert(cell_ids);
	answer+="  </tr>";
	answer+='</table>';
	//self.calendar.innerHTML=answer
	document.all.calendar.innerHTML=answer;
}


function dayonmonth(m, y){ // �������, ��� ����������� ���������� ���� � ������
	var answer;
	if(m!=2){ // ���� �� "�������"
		var date1=new Date(m+'/31/'+y);
		var mm=(m<12)?(m+1):1;
		var yy=(m<12)?y:(y+1);
		var date2=new Date(mm+'/1/'+yy);
		answer=(date1.getDay()==date2.getDay())?'30':'31';
	}else{
		var date1=new Date(m+'/29/'+y);
		var mm=(m<12)?(m+1):1;
		var yy=(m<12)?y:(y+1);
		var date2=new Date(mm+'/1/'+yy);
		answer=(date1.getDay()==date2.getDay())?'28':'29';
	}
	return answer;
}
function calendar_move(to, index, m, d, y){
	switch(to){
		case('-'):
			switch(index){
				case('m'):
				//alert(m);
					if(m>1){
						m--;
					}else{
					if (m==1) {m=13;y--;}
					   m--;
						//m=1;
						//y--;
					}
					break;
				case('d'):
					var mm=(m>1)?--m:1;
					var yy=(m>1)?y:--y;
					var days=dayonmonth(mm, yy);
					if(d>1){
						d--;
					}else{
						d=days;
						m=mm;
						y=yy;
					}
					break;
				case('y'):
					y--;
					break;
			}
			break;
		case('+'):
			switch(index){
				case('m'):
					if(m<12){
						m++;
					}else{
						m=1;
						y++;
					}
					break;
				case('d'):
					var mm=(m<12)?++m:1;
					var yy=(m<12)?y:++y;
					var days=dayonmonth(m, y);
					if(d<days){
						d++;
					}else{
						d=1;
						m=mm;
						y=yy;
					}
					break;
				case('y'):
					y++;
					break;
				}
			break;
	}
	calendar_show(m, d, y);
}

function get_month_title(m)
{
	m=parseInt(m);
	var month_title='null';
	switch(m)
	{
		case(1): month_title='Januar';break;
		case(2): month_title='Februar';break;
		case(3): month_title='Maerz';break;
		case(4): month_title='April';break;
		case(5): month_title='Mai';break;
		case(6): month_title='Juni';break;
		case(7): month_title='Juli';break;
		case(8): month_title='August';break;
		case(9): month_title='September';break;
		case(10): month_title='Oktober';break;
		case(11): month_title='November';break;
		case(12): month_title='December';break;
	}
	return month_title;
}

function get_month_title2(m)
{
	m=parseInt(m);
	var month_title='null';
	switch(m)
	{
		case(1): month_title='Januar';break;
		case(2): month_title='Februar';break;
		case(3): month_title='Maerz';break;
		case(4): month_title='April';break;
		case(5): month_title='Mai';break;
		case(6): month_title='Juni';break;
		case(7): month_title='Juli';break;
		case(8): month_title='August';break;
		case(9): month_title='September';break;
		case(10): month_title='Oktober';break;
		case(11): month_title='November';break;
		case(12): month_title='December';break;
	}
	return month_title;
}  

function  show_calendar(mode)
{
//alert(mode); 
	if (mode=="start_date")
	{
		  var p = document.getElementById("calendar_start_date");
		  oWnd=document.getElementById('calendar');
		
		  var top  = (oWnd["at_position"] == "y") ? p.offsetHeight+2 : 0;
		  var left = (oWnd["at_position"] == "x") ? p.offsetWidth +2 : 0;
		
		  for (; p; p = p.offsetParent)
		  {
		    top  += p.offsetTop;
		    left += p.offsetLeft;
		  }
		
		  oWnd.style.position   = "absolute";
		  oWnd.style.top        = top +'px';
		  oWnd.style.left       = left+'px';
		  //c.style.visibility = "visible";
		
		
		
		
		calendar_mode=mode;
		oWnd=document.getElementById('calendar');
		oWnd.style.visibility='visible';
		//var workAreaWidth=document.getElementById('body').offsetWidth;
		//oWnd.style.left=workAreaWidth/2;
		//oWnd.style.top=30;
		oInput=document.getElementById('start_year');
		year=parseInt(oInput.value);
		oInput=document.getElementById('start_month');
		//month=oInput.value;
		switch(oInput.value)
		{
			case("01"): month=1;break;
			case("02"): month=2;break;
			case("03"): month=3;break;
			case("04"): month=4;break;
			case("05"): month=5;break;
			case("06"): month=6;break;
			case("07"): month=7;break;
			case("08"): month=8;break;
			case("09"): month=9;break;
			default: month=oInput.value;
		}

		oInput=document.getElementById('start_day');
		switch(oInput.value)
		{
			case("01"): day=1;break;
			case("02"): day=2;break;
			case("03"): day=3;break;
			case("04"): day=4;break;
			case("05"): day=5;break;
			case("06"): day=6;break;
			case("07"): day=7;break;
			case("08"): day=8;break;
			case("09"): day=9;break;
			default: day=parseInt(oInput.value);
		}
		//day=parseInt(oInput.value);day=9;
		//alert(day);
		calendar_show(month,day,year);	
	}
	
	if (mode=="end_date")
	{
		calendar_mode=mode;
		 var p = document.getElementById("calendar_end_date");
		  oWnd=document.getElementById('calendar');
		
		  var top  = (oWnd["at_position"] == "y") ? p.offsetHeight+2 : 0;
		  var left = (oWnd["at_position"] == "x") ? p.offsetWidth +2 : 0;
		
		  for (; p; p = p.offsetParent)
		  {
		    top  += p.offsetTop;
		    left += p.offsetLeft;
		  }
		
		  oWnd.style.position   = "absolute";
		  oWnd.style.top        = top +'px';
		  oWnd.style.left       = left+'px';
		  
		//oWnd=document.getElementById('calendar');
		oWnd.style.visibility='visible';
		//var workAreaWidth=document.getElementById('body').offsetWidth;
		//oWnd.style.left=workAreaWidth/2;
		//oWnd.style.top=30;
		oInput=document.getElementById('end_year');
		year=parseInt(oInput.value);
		oInput=document.getElementById('end_month');
		//month=parseInt(oInput.value);
		switch(oInput.value)
		{
			case("01"): month=1;break;
			case("02"): month=2;break;
			case("03"): month=3;break;
			case("04"): month=4;break;
			case("05"): month=5;break;
			case("06"): month=6;break;
			case("07"): month=7;break;
			case("08"): month=8;break;
			case("09"): month=9;break;
			default: month=oInput.value;
		}
		oInput=document.getElementById('end_day');
		//day=parseInt(oInput.value);
		switch(oInput.value)
		{
			case("01"): day=1;break;
			case("02"): day=2;break;
			case("03"): day=3;break;
			case("04"): day=4;break;
			case("05"): day=5;break;
			case("06"): day=6;break;
			case("07"): day=7;break;
			case("08"): day=8;break;
			case("09"): day=9;break;
			default: day=parseInt(oInput.value);
		}
		calendar_show(month,day,year);	
	}
}

function get_date(newmonth,newday,newyear,cell_ids)
{
	if(cell_ids!=selected_cell_id)
	{
		cell_id="cell_id_"+cell_ids;
		cTD=document.getElementById(cell_id);
		cTD.className="calendar_today";
		if(document.getElementById('cell_id_'+selected_cell_id))
		{
			cTD=document.getElementById('cell_id_'+selected_cell_id);
			cTD.className="calendar";
		}
		selected_cell_id=cell_ids;
	}
	
	if (calendar_mode=="start_date")
	{
		oInput=document.getElementById('start_year');
		oInput.value=newyear;
		oInput=document.getElementById('start_month');
		oInput.value=newmonth;

		month_title=get_month_title2(newmonth);
		oInput=document.getElementById('start_day');
		oInput.value=newday;
		start_date_span=newday+' '+month_title+' '+newyear;
		//oInput=document.getElementById('start_date');
		//if (document.getElementById('start_date_inner')){toDelete=document.getElementById('start_date_inner'); toDelete.removeNode(true);}
		//cDiv=document.createElement('span');
		//cDiv.id="start_date_inner";
		//oText=document.createTextNode(start_date_span);	
		//alert(start_date_span);
		Arri=document.getElementById('arri');
		Arri.value=start_date_span;
		//cDiv.appendChild(oText);
		//oInput.appendChild(cDiv);
		oWnd=document.getElementById('calendar');
		oWnd.style.visibility='hidden';
	} 
	if (calendar_mode=="end_date")
	{
		oInput=document.getElementById('end_year');
		oInput.value=newyear;
		oInput=document.getElementById('end_month');
		oInput.value=newmonth;
		//oInput=document.getElementById('end_month_title');
		month_title=get_month_title2(newmonth);
		//oInput.value=month_title;
		oInput=document.getElementById('end_day');
		oInput.value=newday;

		end_date_span=newday+' '+month_title+' '+newyear;
		//oInput=document.getElementById('end_date');
		//if (document.getElementById('end_date_inner')){toDelete=document.getElementById('end_date_inner'); toDelete.removeNode(true);}
		//cDiv=document.createElement('span');
		//cDiv.id="end_date_inner";
		//oText=document.createTextNode(end_date_span);	
		//cDiv.appendChild(oText);
		//oInput.appendChild(cDiv);
		Arri=document.getElementById('leave');
		Arri.value=end_date_span;
		
		oWnd=document.getElementById('calendar');
		oWnd.style.visibility='hidden';
	}
}


if(window.HTMLElement)
{
	HTMLElement.prototype.removeNode = function(removeChildren) 
	{
	  if (Boolean(removeChildren)) {return this.parentNode.removeChild(this);}
	  else 
	  {
	    var r=document.createRange();
	    r.selectNodeContents(this);
	    return this.parentNode.replaceChild(r.extractContents(),this);
	  }
	}
}


function whentocallh(vtime)
{
	if(vtime==4)
	{
		oInsert=document.getElementById('time1');
		cDiv=document.createElement('div');
		oInput=document.createElement("input"); ///создание элемента INPUT   
		oInput.id='whentocallinp';
		oInput.name='whentocallinp';
		oInput.type='text';
		cDiv.appendChild(oInput);
		oInsert.appendChild(cDiv);
	}else
	{
		if (document.getElementById('whentocallinp')){toDelete=document.getElementById('whentocallinp'); toDelete.removeNode(true);}
	}
	
} 

function submitFeedback()
{
	current_year=parseInt(current_year);
	current_month=parseInt(current_month); 
	current_day=parseInt(current_day);
	start_year=parseInt(document.getElementById('start_year').value);
	end_year=parseInt(document.getElementById('end_year').value);
	start_month=parseInt(document.getElementById('start_month').value);
	end_month=parseInt(document.getElementById('end_month').value);
	start_day=parseInt(document.getElementById('start_day').value);
	end_day=parseInt(document.getElementById('end_day').value);
	if(start_month<10) start_month='0'+start_month;
	if(start_day<10) start_day='0'+start_day;
	start=''+start_year+''+start_month+''+start_day;
	if(end_month<10) end_month='0'+end_month;
	if(end_day<10) end_day='0'+end_day;
	end=''+end_year+''+end_month+''+end_day;
	if(current_month<10) current_month='0'+current_month;
	if(current_day<10) current_day='0'+current_day;
	var current_date=current_year+''+current_month+''+current_day;
	start=parseInt(start);
	end=parseInt(end);
	
	err=0;
	if (document.getElementById('name').value=="") {document.getElementById('name').style.background="#FFDFDF"; err=1;}
	if (document.getElementById('phone').value=="") {document.getElementById('phone').style.background="#FFDFDF"; err=1;}
	if (document.getElementById('code').value!=secret) {document.getElementById('code').style.background="#FFDFDF"; err=1;}
	if (document.getElementById('placement').value=="") {document.getElementById('placement').style.background="#FFDFDF"; err=1;}
	
	
	if (document.getElementById('name').value!="") {document.getElementById('name').style.background="#FFFFFF";}
	if (document.getElementById('phone').value!="") {document.getElementById('phone').style.background="#FFFFFF";}
	if (document.getElementById('code').value==secret) {document.getElementById('code').style.background="#FFFFFF";}
	if (document.getElementById('placement').value!="") {document.getElementById('placement').style.background="#FFFFFF";}
	
	if (start<current_date)
	{
	document.getElementById('start_date').style.background="#FFDFDF";
	alert("Начальная дата не может быть установлена задним числом!");
	err=1;
	} else {document.getElementById('start_date').style.background="";}
	if (end<start)
	{
	document.getElementById('end_date').style.background="#FFDFDF";
	alert("Конечная дата не может быть меньше начальной даты!");
	err=1;
	}
	
	if (err==1){alert("Не все обязательные поля заполнены корректно!");return false;} else return true;
	
}

// Copyright (C) 2005-2008 Ilya S. Lyubinskiy. All rights reserved.
// Technical support: http://www.php-development.ru/
//
// YOU MAY NOT
// (1) Remove or modify this copyright notice.
// (2) Re-distribute this code or any part of it.
//     Instead, you may link to the homepage of this code:
//     http://www.php-development.ru/javascripts/dropdown.php
//
// YOU MAY
// (1) Use this code on your website.
// (2) Use this code as part of another product.
//
// NO WARRANTY
// This code is provided "as is" without warranty of any kind.
// You expressly acknowledge and agree that use of this code is at your own risk.


// ***** Popup Control *********************************************************

// ***** at_show_aux *****

function at_show_aux(parent, child)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child );

  var top  = (c["at_position"] == "y") ? p.offsetHeight+2 : 0;
  var left = (c["at_position"] == "x") ? p.offsetWidth +2 : 0;

  for (; p; p = p.offsetParent)
  {
    top  += p.offsetTop;
    left += p.offsetLeft;
  }

  c.style.position   = "absolute";
  c.style.top        = top +'px';
  c.style.left       = left+'px';
  c.style.visibility = "visible";
}

// ***** at_show *****

function at_show()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  at_show_aux(p.id, c.id);
  clearTimeout(c["at_timeout"]);
}

// ***** at_hide *****

function at_hide()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  c["at_timeout"] = setTimeout("document.getElementById('"+c.id+"').style.visibility = 'hidden'", 333);
}

// ***** at_click *****

function at_click()
{
  var p = document.getElementById(this["at_parent"]);
  var c = document.getElementById(this["at_child" ]);

  if (c.style.visibility != "visible") at_show_aux(p.id, c.id); else c.style.visibility = "hidden";
  return false;
}

// ***** at_attach *****

// PARAMETERS:
// parent   - id of the parent html element
// child    - id of the child  html element that should be droped down
// showtype - "click" = drop down child html element on mouse click
//            "hover" = drop down child html element on mouse over
// position - "x" = display the child html element to the right
//            "y" = display the child html element below
// cursor   - omit to use default cursor or specify CSS cursor name

function at_attach(parent, child, showtype, position, cursor)
{
  var p = document.getElementById(parent);
  var c = document.getElementById(child);

  p["at_parent"]     = p.id;
  c["at_parent"]     = p.id;
  p["at_child"]      = c.id;
  c["at_child"]      = c.id;
  p["at_position"]   = position;
  c["at_position"]   = position;

  c.style.position   = "absolute";
  c.style.visibility = "hidden";

  if (cursor != undefined) p.style.cursor = cursor;

  switch (showtype)
  {
    case "click":
      p.onclick     = at_click;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
    case "hover":
      p.onmouseover = at_show;
      p.onmouseout  = at_hide;
      c.onmouseover = at_show;
      c.onmouseout  = at_hide;
      break;
  }
}

function set_arri_time(param)
{
	Arri=document.getElementById('arri_time');
	Arri.value=param;
	var c = document.getElementById("sample_attach_menu_child");
	c.style.visibility = "hidden";
} 

function set_leave_time(param)
{
	Arri=document.getElementById('leave_time');
	Arri.value=param;
	var c = document.getElementById("sample_attach_menu_child2");
	c.style.visibility = "hidden";
}

