var timeouts=[];timeouts=[1,2,3,3,7,10,7,3,3,2];var loops_count=3;var start_from=1;var latency=60;var final_transparency=1;var storage;

function flash(obj_id){var obj;if(obj_id&&obj_id!==''){storage=obj_id;obj=document.getElementById(storage);if(obj){obj.counter=start_from;obj.loops=loops_count;}}else{obj=document.getElementById(storage);if(obj){if(obj.counter>timeouts.length){obj.counter=1;obj.loops--;}}}
if(obj){obj.style.opacity=(10-timeouts[obj.counter-1])/10;if(document.body.filters&&navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5){obj.style.filter='alpha(opacity='+obj.style.opacity*100+')';}
obj.counter++;}
if(obj){if(obj.loops>0){setTimeout("flash('')",latency);}else{obj.style.opacity=1-final_transparency/10;}}}

//window.onload=function(){flash('messerr');}





 


	
		
// появление формы об информировании поступления товара
function inform(id, name, email){

if(email != '') {
	val_email = email;
} else {
	val_email = 'Введите свой E-mail';
}

var form_inform_print = "<form action='http://www.okfit.ru/shop.php?op=product&productid=187' method='GET'>" +
				
				"<div class=\"legend\">Оповестить при поступлении на склад <span>" + name + "</span></div>" +
				"<input id=\"email_inform" + id + "\" class=\"email\" type=\"text\" value=\"" + val_email + "\" onblur=\"if(this.value=='') this.value='Введите свой E-mail';\" onfocus=\"if(this.value=='Введите свой E-mail') this.value='';\" />" +
				"<input class=\"submit\" type=\"button\" onclick=\"checkName(" + id + ",'', '')\" value=\"Отправить\" />" +
				
				"<div class=\"status_inform\"><img class=\"hidden\" src=\"/img/sucsess_inform.png\" id=\"message_inform" + id + "\" /></div>" +
				"<div class=\"status_message\" id=\"status_message" + id + "\"></div>" +
				
			"</form>";	
			
$("#form_inform" + id).html(form_inform_print); 			
			


		$("#form_inform" + id).slideToggle(500);
		
		if( $("#showr" + id).attr('value') == '' || !$("#showr" + id).attr('value')) {
		
			$("#showr" + id).fadeOut(250, function() {$("#showr" + id).attr('src', '/img/drop_inform2.png');});
			$("#showr" + id).fadeIn(250);
			
			
		
			//$("#showr" + id).attr('src', '/img/drop_inform2.png');
			$("#showr" + id).attr('title', 'Закрыть форму');
			$("#showr" + id).attr('value', '1');
		} else {
		
			$("#showr" + id).fadeOut(250, function() {$("#showr" + id).attr('src', '/img/mail.png');});
			$("#showr" + id).fadeIn(250);		
			//$("#showr" + id).attr('src', '/img/mail.png');
			$("#showr" + id).attr('title', 'Оповестить по E-mail при поступлении на склад');
			$("#showr" + id).attr('value', '');
		}



    

  };
  
  
  
  // ajax для работы с базой после отправки формы об информировании о поступлении
  function checkName(input, response, email)
{
//if(email == '') email = $("#email_inform" + input).attr('value');
email = $("#email_inform" + input).attr('value');
if(email == '' || email == 'Введите свой E-mail') email = '*';
//image   = document.getElementById('imgCheckFailed');

  if (response != ''){ 
    // Режим ответа
  //  message   = document.getElementById('nameCheckFailed');
   // image.className = 'hidden';
    
    if (response == 4 || response == 5){
      //message.className = 'error';
     // $("#message_inform" + input).text(response);
     $("#message_inform" + input).attr('src', "/img/sucsess_inform.png");
     $("#message_inform" + input).attr('title', "Успешно!");
     $("#message_inform" + input).fadeIn("slow");
     
     $("#status_message" + input).attr('class', 'status_message_ok');
     if(response == 4) $("#status_message" + input).text('Вы подписаны на одноразовое оповещение!');
     if(response == 5) $("#status_message" + input).text('Вы снова подписаны на данный товар');

    }else{
	  //message.className = 'hidden';
	  
	  $("#message_inform" + input).attr('src', "/img/slash.png");
	  $("#message_inform" + input).attr('title', "Неудачно!");
	  $("#message_inform" + input).fadeIn("slow");
	  
	  $("#status_message" + input).attr('class', 'status_message_error');
	  if(response == 0) $("#status_message" + input).text('Вы ввели некорректный E-mail');
	  if(response == 1) $("#status_message" + input).text('Вы не указали E-mail');
	  if(response == 2) $("#status_message" + input).text('Ошибка соединения с базой!');
	  if(response == 3) $("#status_message" + input).text('Вы уже подписаны на данный продукт');
	  if(response == 6) $("#status_message" + input).text('Id товара не число!');
	  
    } 
  }else{
    // Режим приема
   // image.className = 'loadd';
    url  = 'http://www.okfit.ru/includes/inform_ajax.php?q=' + input + '&email=' + email;
    loadXMLDoc(url);
  }
}
 
var req;
 
function loadXMLDoc(url) {
    // ветка для родного XMLHttpRequest объекта
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    // ветка для IE/Windows ActiveX версии
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}
 
function processReqChange() 
{
    // если запрос показывает "готово"
    if (req.readyState == 4) {
        // если статус ответа сервера "OK"
        if (req.status == 200) {
            // выполняем парсинг пришедшего и выполняем с этими параметрами checkName() 
      response = req.responseXML.documentElement;
      method = response.getElementsByTagName('method')[0].firstChild.data;
      result = response.getElementsByTagName('result')[0].firstChild.data;
      id =     response.getElementsByTagName('id')[0].firstChild.data;
      email =  response.getElementsByTagName('email')[0].firstChild.data;
      eval(method + '(id, result, email)');
        } else {
            alert("There was a problem retrieving the XML data:\n" + req.statusText);
        }
    }
}
  

		