
function myAddDays(dCount)
{
	var msDay = 1000 * 3600 *24;
	var msNow = this.getTime();
	this.setTime(msNow + msDay * dCount);
}

Date.prototype.addDays = myAddDays;

function make_order(e_price, price)
{
	window.scrollTo(0,260);
	var url = 'includes/order_back.php';
	
	var cust_name = get_cookie('cust_name');
	var cust_mail = get_cookie('cust_mail');
	var cust_address = get_cookie('cust_address');

	var pars = 'order=true&price=' + price + '&ebay_price=' + e_price;

	var myAjax = new Ajax.Request(
		url,
		{
			method: 'post', 
			parameters: pars,
			onCreate: function(){$('order').innerHTML = '<img src="images/spinner.gif">';},
			onComplete: function(myAjax){
					$('order').innerHTML = myAjax.responseText;
          
				 	if(cust_name != null)
					{
						$('msg_name').value = cust_name;
					}
					if(cust_mail != null) 
					{
						$('mail_from').value = cust_mail;
					}
					if(cust_address != null)
					{
						$('address').value = cust_address;
					}
			 }
		});
}


function request()
{
	window.scrollTo(0,260);
	var url = 'includes/order_back.php';
	
	var cust_name = get_cookie('cust_name');
	var cust_mail = get_cookie('cust_mail');
	var cust_address = get_cookie('cust_address');
	var pars = 'request=true';

	var myAjax = new Ajax.Request(
		url,
		{
			method: 'post', 
			parameters: pars,
			onCreate: function(){$('order').innerHTML = '<img src="images/spinner.gif">';},
			onComplete: function(myAjax){
						$('order').innerHTML = myAjax.responseText;
            
						if(cust_name != null)
						{
							$('msg_name').value = cust_name;
						}
						if(cust_mail != null) 
						{
							$('mail_from').value = cust_mail;
						}
						if(cust_address != null)
						{
							$('address').value = cust_address;
						}
				}
		});
}


function show_lot(ebay_url)
{
	var url = 'http://209.85.135.104/translate_c?hl=en&langpair=en%7Cru&u=' + ebay_url;

	window.open(url,'','');
}
//if we recieve 0 by value of "order_or_help" it means, that it was an help query.
//if we recieve 1 by value of "order_or_help" it means, that it was an order order.

function send_msg(order_or_help)
{
	if(check_msg())
	{
    var h = document.viewport.getHeight() / 2;
		var msg_name = escape($('msg_name').value);
		var mail_from = escape($('mail_from').value);
		var address = escape($('address').value);
		var d = new Date();
		var n = 360;
		d.addDays(n);
		window.document.cookie = "cust_name=" + msg_name + ";expires=" + d.toGMTString() + ";path=/;false";
		window.document.cookie = "cust_mail=" + mail_from + ";expires=" + d.toGMTString() + ";path=/;false";
		window.document.cookie = "cust_address=" + address + ";expires=" + d.toGMTString() + ";path=/;false";
		var itemId = $('item_id').value;
		var pars = 'ID=' + itemId + '&o_h=' + order_or_help;
		var myAjax = $('msg_form').request(
		{
			method: 'post',
			parameters: pars,
			onCreate: function(){$('order').innerHTML = '<img src="images/spinner.gif">';},
			onComplete: function(myAjax, h){ scrollTo(0,h);$('order').innerHTML = myAjax.responseText; setTimeout("window.location.href=window.location.href", 5000);}
		});
	}
}

function check_msg()
{
	var a ='';
	if($('mail_from').value == '')
	{
  	a = 'Вы не указали Ваш электронный адрес\n';
  }
  if($('msg_name').value == null)
	{
	  a += 'Вы не указали Ваше имя\n';
  }
	if($('key').value == null)
	{
	  a += 'Вы не ввели цифры, изображенные на картинке';
	}
  if(a != '')
  {
	  alert(a);
  	return false;
  }
  else
  {
	  return true;
  }
}

function show_page(query)
{
	var url = 'includes/main_menu_backend.php';
	var pars = 'query=' + query;
	var close = '<center style="cursor:pointer;" onclick=$("information").innerHTML="";><b><u>Закрыть</u></b></center><hr>';
	var myAjax = new Ajax.Request(
	url,
	{
		method: 'post', 
		parameters: pars,
		onComplete: function(myAjax){ $('information').innerHTML = myAjax.responseText + close;}
	});

}

function bgli()
{
	var l = document.getElementsByTagName('li');
	for(var i = 0; i < l.length; i++)
	{
		l[i].onmouseover = bgl;
		l[i].onmouseout = bgr;
	}
}

function bgl()
{
	this.style.backgroundColor = '#efefef';
}
function bgr()
{
	this.style.backgroundColor = '#ffffff';
}



function get_cookie(pName)
{	
	var sCookie = document.cookie;
	var sCookieLength = sCookie.length;
	var sName = pName + "=";
	var sNameLength = sName.length;
	var sValue = null;
	var i = 0;
	var j = 0;
	while(i < sCookieLength)
	{
		j = i + sNameLength;
		if(sCookie.substring(i, j) == sName)
		{
			var n = sCookie.indexOf(";", j);
			if(n == -1) n = sCookieLength;
			sValue = unescape(sCookie.substring(j, n));
			break; 
		}
		i = sCookie.indexOf(" ", i) + 1;
		if(i == 0) break;
	}
	return sValue;
}

function makeTime(offset) 
{
  var localTime = new Date()
  var ms = localTime.getTime() + (localTime.getTimezoneOffset() * 60000) + offset * 3600000
  var time = new Date(ms) 
  var hour = time.getHours() 
  var minute = time.getMinutes()
  var second = time.getSeconds()
  var temp = "" + hour 
  if(temp.length == 1) 
    temp = " " + temp
  temp += ((minute < 10) ? ":0" : ":") + minute
  temp += ((second < 10) ? ":0" : ":") + second
  return temp;
}

function jsClockTimeZone()
{
  if($('msk') != null)
  {
    $('msk').innerHTML = makeTime(4);
    $('vld').innerHTML = makeTime(11); 
    $('nvs').innerHTML = makeTime(7); 
    $('spb').innerHTML = makeTime(4); 
    $('ekt').innerHTML = makeTime(6); 
    setTimeout("jsClockTimeZone()", 1000)
  }
}
