	$(function() {
		$('#datepicker').datepicker({
			changeYear: true,
			firstDay: 1,
			minDate: 0,
			dateFormat: 'yy-mm-dd',
			prevText: '&#x3c;Пред', // Display text for previous month link
			nextText: 'След&#x3e;', // Display text for next month link
			currentText: 'Сегодня', // Display text for current month link
			monthNames: ['Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'], // Names of months for drop-down and formatting
			monthNamesShort: ['Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек'], // For formatting
			monthStatus: 'Показать другой месяц', // Status text for selecting a month
			yearStatus: 'Показать другой год', // Status text for selecting a year
			weekHeader: 'Нед', // Header for the week of the year column
			weekStatus: 'Неделя года', // Status text for the week of the year column
			dayNames: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'], // For formatting
			dayNamesShort: ['Вск', 'Пнд', 'Втр', 'Срд', 'Чтв', 'Птн', 'Сбт'], // For formatting
			dayNamesMin: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'], // Column headings for days starting at Sunday
			initStatus: 'Выбрать дату', // Initial Status text on opening
			isRTL: false // True if right-to-left language, false if left-to-right

		});
	});
	$(function() {
		$('#datepicker1').datepicker({
			duration: '',
			showTime: true,
		    time24h: true,
		    closeText:"Выбрать",
			changeYear: true,
			firstDay: 1,
			minDate: 0,
			dateFormat: 'yy-mm-dd',
			prevText: '&#x3c;Пред', // Display text for previous month link
			nextText: 'След&#x3e;', // Display text for next month link
			currentText: 'Сегодня', // Display text for current month link
			monthNames: ['Январь','Февраль','Март','Апрель','Май','Июнь','Июль','Август','Сентябрь','Октябрь','Ноябрь','Декабрь'], // Names of months for drop-down and formatting
			monthNamesShort: ['Янв', 'Фев', 'Мар', 'Апр', 'Май', 'Июн', 'Июл', 'Авг', 'Сен', 'Окт', 'Ноя', 'Дек'], // For formatting
			monthStatus: 'Показать другой месяц', // Status text for selecting a month
			yearStatus: 'Показать другой год', // Status text for selecting a year
			weekHeader: 'Нед', // Header for the week of the year column
			weekStatus: 'Неделя года', // Status text for the week of the year column
			dayNames: ['Воскресенье', 'Понедельник', 'Вторник', 'Среда', 'Четверг', 'Пятница', 'Суббота'], // For formatting
			dayNamesShort: ['Вск', 'Пнд', 'Втр', 'Срд', 'Чтв', 'Птн', 'Сбт'], // For formatting
			dayNamesMin: ['Вс','Пн','Вт','Ср','Чт','Пт','Сб'], // Column headings for days starting at Sunday
			initStatus: 'Выбрать дату', // Initial Status text on opening
			isRTL: false // True if right-to-left language, false if left-to-right

		});
	});


var months = new Array(12);
months[0] = "января";
months[1] = "февраля";
months[2] = "марта";
months[3] = "апреля";
months[4] = "мая";
months[5] = "июня";
months[6] = "июля";
months[7] = "августа";
months[8] = "сентября";
months[9] = "октября";
months[10] = "ноября";
months[11] = "декабря";

function showTime(){
 var tmN=new Date()
 var dH=''+tmN.getHours();dH=dH.length<2?'0'+dH:dH
 var dM=''+tmN.getMinutes();dM=dM.length<2?'0'+dM:dM
 var dS=''+tmN.getSeconds();dS=dS.length<2?'0'+dS:dS
 if (tmN.getYear()<1900)
  {y=tmN.getYear()+1900}
 else
  {y=tmN.getYear()}
 var tmp=''+dH+ ':'+dM+':'+dS+'&nbsp;&nbsp;'+tmN.getDate()+' '+months[tmN.getMonth()]+' '+y
document.getElementById('tm').innerHTML=tmp
 var t=setTimeout('showTime()',1000)
}


function makeInvisible(sel,div)
{  var obj_sel=document.getElementById(sel);
   var obj=document.getElementById(div);
   var obj1=document.getElementById(div+'1');
   if (obj_sel.value=='да')
     {
	    obj.style.display = 'block';
	    obj1.style.display = 'block';
     }
     else
     {
     	obj.style.display = 'none';
     	obj1.style.display = 'none';
     }

}


function SendForm (this_form, required, required_show) {
var i, j;
for(j=0; j<required.length; j++) {
for (i=0; i<this_form.length; i++) {
 if (this_form.elements[i].name == required[j] && this_form.elements[i].value == "" ) {
alert('Пожалуйста, введите ' + required_show[j]);
this_form.elements[i].focus();
return false;
}
}
}
return true;
}



function doLoadHistory(value) {
    // Create new JsHttpRequest object.
if (document.getElementById('history').style.display == 'none')
{    var req = new JsHttpRequest();
    req.caching = false;
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            if (req.responseJS.percents!='')
             {document.getElementById('history').innerHTML = req.responseJS.percents;
              document.getElementById('history').style.display = 'block';
              window.scrollBy(0,100);
             }

        }
    }
    req.open(null, '/deposit/load_history.phtml', true);
    req.send( { q: value} );
}
else
{	document.getElementById('history').style.display = 'none';}
}

function doLoadHistoryAfterPersents(value) {
    var req = new JsHttpRequest();
    req.caching = false;
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            document.getElementById('history').innerHTML =
                req.responseJS.percents;
            document.getElementById('history').style.display = 'block';
        }
    }
    req.open(null, '/deposit/load_history.phtml', true);
    req.send( { q: value } );

}


function doMakeStake(value) {
    nr = document.getElementById('next_rate').value;
if (confirm("Хотите поднять ставку?"))
{
    var req = new JsHttpRequest();
    req.caching = false;
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            if (req.responseJS.err!='')
            {            	alert(req.responseJS.err);
            	doLoad_percents(value);            }
            else
            {
            	document.getElementById('percents').innerHTML = req.responseJS.ps;
           		document.getElementById('up_rate').value = "Поднять ставку до "+req.responseJS.next_rate+"%";
           		document.getElementById('next_rate').value = req.responseJS.next_rate;
            	if (req.responseJS.percents!='')
             	{             		document.getElementById('history').innerHTML = req.responseJS.percents;
	              	document.getElementById('history').style.display = 'block';
        	     }
             }
         }
    }
    req.open(null, '/deposit/make_stake.phtml', true);
    req.send( { q: value, pers: nr } );
}
}

function doMakeStake_win(value) {
if (confirm("Хотите принять ставку 'Выиграть сейчас'?"))
{
    var req = new JsHttpRequest();
    req.caching = false;
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            if (req.responseJS.err!='')
            {
            	alert(req.responseJS.err);
            	//doLoad_percents(value);
            }
            else
            {
            document.getElementById('percents').innerHTML = req.responseJS.ps;
           	document.getElementById('up_rate').value = "Торги по лоту окончены";
            document.getElementById('next_rate').value = req.responseJS.next_rate;
            if (req.responseJS.percents!='')
             {document.getElementById('history').innerHTML = req.responseJS.percents;
              document.getElementById('history').style.display = 'block';
             }
            }
         }
    }
    req.open(null, '/deposit/make_stake_win.phtml', true);
    req.send( { q: value } );
}
}

function doLoad_percents(value) {
    var req = new JsHttpRequest();
    req.caching = false;
    req.onreadystatechange = function() {
		if (req.readyState == 4) {            if ( (document.getElementById('history').style.display == 'block')&&((document.getElementById('percents').innerHTML) != (req.responseJS.percents+"%"))||(req.responseJS.exp==1))
               {               	if(req.responseJS.exp==1)
               	 {            		document.getElementById('up_rate').value = "Торги по лоту окончены";
               	 	document.getElementById('next_rate').value = "0";
               	 }
               	else
               	 {               	 	document.getElementById('up_rate').value = "Поднять ставку до "+req.responseJS.next_rate+"%";
               	 	document.getElementById('next_rate').value = req.responseJS.next_rate;
            	 }

               	doLoadHistoryAfterPersents(value);
               	}
            else {               	 	document.getElementById('up_rate').value = "Поднять ставку до "+req.responseJS.next_rate+"%";
                    document.getElementById('next_rate').value = req.responseJS.next_rate;

            	 }
       	 	now=new Date();
			document.getElementById('time_correction').value=now.getTime();
			document.getElementById('percents').innerHTML =  req.responseJS.percents;
       	    document.getElementById('time_to_expire').value =  req.responseJS.time_to_expire_lot;
        }
    }
    req.open(null, '/deposit/load_percents.phtml', true);
    req.send( { q: value } );
}

function doLoad_percents_client(value) {
    var req = new JsHttpRequest();
    req.caching = false;
    req.onreadystatechange = function() {
        if (req.readyState == 4) {
            	if (req.responseJS.exp==1)
            	 {            	 	document.getElementById('percents').innerHTML =  req.responseJS.percents+" Торги по лоту окончены";
            	 }
            	 else
            	  {
            	    document.getElementById('percents').innerHTML =  req.responseJS.percents;
            	    document.getElementById('time_to_expire').innerHTML =  req.responseJS.time_to_expire_lot;
                  }
        }
    }
    req.open("POST", '/deposit/load_percents.phtml', true);
    req.send( { q: value });
}


