﻿function hideshow(which)
{
if (!document.getElementById|document.all)
        return
else{
        if (document.getElementById)
                oWhich = eval ("document.getElementById('" + which + "')")
        else
                oWhich = eval ("document.all." + which)
        }

        window.focus()

        if (oWhich.style.display=="none")
                oWhich.style.display=""
        else
                oWhich.style.display="none"
}

function changeGoodsCost(obj){
	var i;
	var gN;
	for(i=0;i<window.goodsCosts.length;i++){
		if(window.goodsIds[i]==parseInt(obj.value)){
			gN=i;
			break;
		}
	}
 $a('limit_cost').value=window.goodsCosts[gN];
 $a('bid_cost').value=window.goodsBids[gN];
 $a('whole_time').value=window.goodsTime[gN];
 $a('bid_count').value=window.goodsBidsCount[gN];



}

function checkAll(){
	if($('#allCheck').attr('style')=='display: inline;' || $('#allCheck').attr('style')==''){
		$('input:checkbox').removeAttr('checked');					
		$('#noneCheck').show();
		$('#allCheck').hide();
	}else{
		$('input:checkbox').attr('checked',true);
		$('#allCheck').show();
		$('#noneCheck').hide();
	}

}

function changeFixed(obj){
	if(obj.checked)
		$a('cost_rate').value='0';

}

function hideshowPlus(which, imag)
{
if (!document.getElementById|document.all)
        return
else{

        if (document.getElementById){
                oWhich = eval ("document.getElementById('" + which + "')");
                oImag = eval ("document.getElementById('" + imag + "')");
        }else{
                oWhich = eval ("document.all." + which);
                oImag = eval ("document.all." + imag);
        }
        }

        window.focus();

        if (oWhich.style.display=="none"){
            oImag.src="img/minus.gif";
                oWhich.style.display=""
        }else{
                oWhich.style.display="none"
                oImag.src="img/plus.gif";
        }
}

function changeInput(sel,inp){
  if(sel.options[sel.selectedIndex].value==0)
    inp.value='';
  else
    inp.value=sel.options[sel.selectedIndex].text;
}

function isEmail(idInp){
	if (document.getElementById(idInp).value.match('^[a-zA-Z0-9\._-]+@[a-zA-Z0-9\._-]+\.[a-zA-Z]{2,4}$')!=null)
		return true;
	else
		return false;
}
// блок работы с фото - увеличение

//конец блока увеличения фото
function auto_fill(form,field,text){
	eval('document.'+form+'.'+field+'.value="'+text+'"');
}

function delconfirm(get){

  if( confirm("Уверены, что хотите удалить?")){
    window.document.location.href=get;
  }
}

function confirmbuy(get,cost){
  if( confirm("Вы приобретаете этот товар без участия в аукционе по цене "+cost+" руб. плюс стоимость доставки.")){
    window.document.location.href=get;
  }
}


function set_date(day){
  action.date_open.value=day
  }

function open_calendar(href){
  popup = window.open(href,'calendar', 'location=0, toolbar=0, menubar=0, resizable=0, scrollbars=0,width=195,height=180,left=150, top=200')
 }

 function showGoods(src,n, c){
   if (!document.getElementById|document.all)
        return
   else{
     if (document.getElementById){
        img = document.getElementById('rightImg');
        name= document.getElementById('goodsName');
        comment= document.getElementById('goodsComment');
     }else{
        img = document.all.rightImg;
        name= document.all.goodsName;
        comment= document.all.goodsComment;
     }
   }
   window.focus();
   img.src=src;
   name.innerHTML=n;
   comment.innerHTML=c;
 }
 function $a(id){
 	return document.getElementById(id);
 }

 function delBlock(name_form,id) {
	$a(name_form).removeChild($a('file_'+id));
	hidId=parseInt($a(idParent+'_hid').value);
	hidId-=1;
	$a(idParent+'_hid').value=hidId;
}


function addBlock(idParent,curId,block) {

	 var newup =document.createElement('div');
	 var str;
	 var i;
	 var hidId;
	 hidId=parseInt($a(idParent+'_hid').value);

	 if (curId+1<=hidId){
	 	return;
	 }
	hidId += 1;
	$a(idParent+'_hid').value=hidId;
	id = hidId;
	newup.id = 'file_'+id;
	str='';
	for (i=0;i<arBlocks.length;i++){
		str+='<div style="width: 200px; float:left;padding-left:10px;">'+arTits[i]+'</div><div style="width: 150px; float:left;padding-left:5px;"><input type="text" name="'+arBlocks[i]+'[]" onkeydown="addBlock(\''+idParent+'\','+id+');"></div><br style="clear:both">'
	}
	str+='<div  style="width: 15px;position:relative; top:-15px;right:0px;float:right; height:15px;"><span style="cursor:pointer" onclick="delBlock(\''+idParent+'\','+id+')"><img src="img/del.gif"></span></div><br>';
	newup.innerHTML = str;
	$a(idParent).appendChild(newup);
}

function displayBySel(obj,hideVal,idDisp){

 if (obj.value==hideVal){
    $a(idDisp).style.display="none";
  }else{
		$a(idDisp).style.display="block"
  }

}

function secToTime(sec){
//console.log('!!!');
var h = Math.floor(sec/3600);
var	m = Math.floor((sec-h*3600)/60);
var s = (sec-h*3600)%60;
  	if(Math.floor(h/10)<1){
  		h='0'+h;
  	}
  	if(Math.floor(m/10)<1){
  		m='0'+m;
  	}
  	if(Math.floor(s/10)<1){
  		s='0'+s;
  	}
  	return h+':'+m+':'+s;
}

function updateAuction() {

  $.post(
  '/scripts/cur_auction.php',
  {
    getData: 1,
    lastUpd: $('#lastUpdate').attr('value')
  },
   function(data){  // загрузку JSON данных из файла example.json
  var i=0;
  j=0;
  //alert(data);
  if(data==''){
  	//alert('sas');
  	return;
  }
   var js = eval("("+data+")");
   var cost;
   var bufTime;
   var auctN=-1;
   //alert(js.auction[1].time);
   if(js.servCon==0){
   	alert('Связь с сервером была прервана');
   	return;
   }
//	 if(js.servCon==2){
//   	alert('До сервера не достуались');
//   	return;
//   }
   if(js.lastUpd==-1){
   	 //alert(window.auctions.length);
   	 if(window.auctions==null){
   	 	return;
   	 }
   	 if(window.auctions){
   	 for (i=0;i<window.auctions.length;i++){
   	 		bufTime=window.auctions[i][1]-js.servTime;
   	 	//	alert(bufTime);
			if (window.auctions[i][6] == 0) {
	  		$('#time' + window.auctions[i][0]).text(secToTime(bufTime));
	  		paintTime(bufTime, window.auctions[i][0]);
	  	}else{
				$('#time' + window.auctions[i][0]).text(secToTime(window.auctions[i][7]));
	  		paintTime(window.auctions[i][7], window.auctions[i][0]);
			}
   	 }}
   	 return;
   }

   $('#lastUpdate').attr('value',js.lastUpd);
   //alert(js.auction);
   for (i=0;i<js.auction.length;i++){
   	//cost=$('#cost'+js.auction[i].id).text();
   	//cost=parseFloat(cost);
		auctN=-1;
	if(window.auctions){	
   	for(j=0;j<window.auctions.length;j++){
   		if(window.auctions[j][0]==js.auction[i].id){
   			window.auctions[j][1]=parseInt(js.auction[i].active_time);
   			auctN=j;
   		//	alert(window.auctions[j][1]);
   		}
   	    }
   	}
		if (auctN == -1) {
			continue;
		}
		if (js.auction[i].stopped == 0) {
			$('#time' + js.auction[i].id).text(js.auction[i].time);
			window.auctions[auctN][6]=0;
		}else{
			$('#time' + js.auction[i].id).text(secToTime(js.auction[i].stop_time));
			window.auctions[auctN][7]=js.auction[i].stop_time;
			window.auctions[auctN][6]=js.auction[i].stopped;
		}
   	$('#time_rate'+js.auction[i].id).text(secToTime(js.auction[i].time_rate));
   	$('#cost'+js.auction[i].id).text(parseFloat(js.auction[i].cost).toFixed(2)+' руб');
		if (js.auction[i].name != '') {
			$('#name' + js.auction[i].id).html(js.auction[i].name);
			$('#last_id_user' + js.auction[i].id).attr('href', '/user/' + js.auction[i].last_id_user+'/');
		}else{
			$('#name' + js.auction[i].id).html('Нет ставок');
			$('#last_id_user' + js.auction[i].id).attr('href', '#');
		}

		if (auctN != -1) {
//		if (window.auctions[auctN][5] != js.auction[i].cost) {
			//	alert(window.auctions[auctN][0]+' - '+window.auctions[auctN][5]+' -- '+js.auction[i].cost);
			window.auctions[auctN][5] = js.auction[i].cost;
			$('#cost' + js.auction[i].id).animate({
				backgroundColor: "#ee8c8d"
			}, 200).animate({
				backgroundColor: "#ffffff"
			}, 200);
//		}
	}
	if (js.auction[i].stopped == 0) {
  	paintTime(js.auction[i].seconds, js.auction[i].id);
  }else{
		paintTime(js.auction[i].stop_time, js.auction[i].id);
	}
   }
   js=null;
  });
}

function paintTime(seconds,id){
var auctN=0;
  for (i=0;i<window.auctions.length;i++){
   	if(window.auctions[i][0]==id){
   		auctN=i;
   		break;
   	}
  }
	if(window.auctions[auctN][4]==0&&seconds<=1){
		//alert('chEnd');
  	isEnded(id);
	}
if(seconds>12){
   		$('#time'+id).css('color','');
   	}else{
   		if(seconds>0){
   			$('#time'+id).css('color', '#EB5F14');
   		}else{
   			if(window.auctions[auctN][4]==1){
   				$('#time'+id).text('Завершен');
   				$('#time'+id).animate( { color: "#E30000"}, 200 )
   					.animate( { color: "#EB5F14"}, 200 );
				$('#doBidR'+id).hide();
				$('#doBidN'+id).hide();
				$('#make'+id).hide();
				$('#enter'+id).hide();
			}else{
   				$('#time'+id).text(secToTime(0));
   			}
   		}
   	}
}

function updateHistory(idG) {
  var i=0;
  $.post(
  '/scripts/cur_auction.php',
  {
    updHis: idG,
    lastUpd: $('#lastAuctUpdate').attr('value'),
    idUser: window.idUser
  },
   function(data){  // загрузку JSON данных из файла example.json
   if(data==''){
  	//alert('sas');
  	return;
  }
   var js = eval("("+data+")");
   if(js.lastUpd==-1){
   return;
   }
   var str;
   var ec;

    str='';
    //$('#out_cost').html(parseFloat(js.auction[0].cost).toFixed(2)+' руб.');
    ec=parseFloat($('#market_cost').attr('value'))- parseFloat(js.auction[0].cost)-window.yourSum;

    //alert(ec);
    //$('#yourSum'+idG).text(js.auction[0].done_bids);
    if(ec>=0){
    	$('#economy').html(splitDimens(ec)+' руб.');
    }
   	$('#out_cost').html(js.auction[0].cost+' руб.');

    $('#done_bids'+idG).text(js.auction[0].done_bids);

  str='<tr><th>userID </th><th>ставка</th><th>md5 кодставки <a href="/help/71/"><img src="/images/question_mark_ico2.jpg" alt="" /></a></th><th>время ставки</th><th>логин</th><th>место</th></tr>';
if(js.auction.length>0 &&js.auction[i].name!=""){
   for (i=0;i<js.auction.length;i++){
	if(js.auction[i].id_user==window.idUser){
    	    str+='<tr class="gray_table_color2">';
	}else{
		if (i%2==0)
	    str+='<tr class="gray_table_color">';
		else
	    str+='<tr>';
	}
   	str+='<td>'+js.auction[i].id_user+'</td><td>'+js.auction[i].cost+' руб.</td><td>'+js.auction[i].hash+'</td><td>'+js.auction[i].time+'</td><td>'+js.auction[i].name+'</td><td>'+js.auction[i].place+'</td>';
	str+='</tr>';
   }}
   $('#history_tab').html(str);
   $('#lastAuctUpdate').val(js.lastUpd)
   js=null;
  });
}

function getExel(idG){
  $.post(
  '/scripts/cur_auction.php',
  {
    getFile:idG
  },function(data){
	location.href='/tmp/'+data;	
    });

}

function getHistory(idG,page,el) {
  var i=0;
  $.post(
  '/scripts/cur_auction.php',
  {
    idAuction: idG,
    page:page
  },
   function(data){  // загрузку JSON данных из файла example.json
   if(data==''){
  	//alert('sas');
  	return;
  }
   var js = eval("("+data+")");
   var str;
    str='';

  str='<tr><th>userID </th><th>ставка</th><th>md5 кодставки <a href="/help/71/"><img src="/images/question_mark_ico2.jpg" alt="" /></a></th><th>время ставки</th><th>логин</th><th>место</th></tr>';
   for (i=0;i<js.auction.length;i++){
	if(js.auction[i].id_user==window.idUser){
    	    str+='<tr class="gray_table_color2">';
	}else{
if (i%2==0)
	    str+='<tr class="gray_table_color">';
		else
	    str+='<tr>';
	}
   	str+='<td>'+js.auction[i].id_user+'</td><td>'+js.auction[i].cost+' руб.</td><td>'+js.auction[i].hash+'</td><td>'+js.auction[i].time+'</td><td>'+js.auction[i].name+'</td><td>'+js.auction[i].place+'</td>';
	str+='</tr>';
   }
   $('#history_tab').html(str);
   js=null;
    $('.paging_list li').removeClass('paging_list_a');
    $(el.parentNode).addClass('paging_list_a');

  });
}

function splitDimens(num){
 	var tis;
 	var sotn;
 	num=num.toFixed(2)*100;
	tis=Math.floor(num/100000);
  sotn=num%100000;
  sotn=sotn/100;
  sotn=sotn.toFixed(2);

  if(sotn==0&&tis>0){
  	sotn='000';
  }else{
  	if(sotn/10<1&&tis>0){
  		sotn='00'+sotn;
  	}else{
  		if(sotn/100<1&&tis>0){
  			sotn='0'+sotn;
  		}
  	}
  }
  if (tis>0)
  	return tis+' '+sotn;
  else
  	return sotn;
}

function doBidUpper(id,idUser,idType,sum){
  $.post(
  '/scripts/cur_auction.php',
  {
    doBid: id,
    lastUpd: $('#lastUpdate').attr('value'),
    idUser: idUser,
    sum:parseFloat(sum)
  },
   function(data){  // загрузку JSON данных из файла example.json
   	var json = eval("("+data+")");
   if(data=='' || !json.auction){
  	//alert('sas');
    $('#enter'+id).hide();  
if(window.balance<parseFloat($('#bid_cost'+id).html()))  
    $('#text'+id).html('<center>Недостаточно средств, <a href="/kabinet/buy_bids/">пополните баланс</a></center>');
else
    $('#text'+id).html('<center>Вы делали такую ставку</center>');
    $('#make'+id).show();
	$('#make'+id).oneTime("1s", function() {
	    $('#make'+id).hide();
	    $('#enter'+id).hide();
	    $('#k'+id).attr('value','');
	    $('#r'+id).attr('value','');

	});
  	return;
  }
	$('#text'+id).html('<center>Ставка принята!</center>');
	$('#enter'+id).hide();
	$('#make'+id).show();
	$('#make'+id).oneTime("1s", function() {
	    $('#make'+id).hide();
	    $('#enter'+id).hide();
	    $('#k'+id).attr('value','');
	    $('#r'+id).attr('value','');
	});

   	var cost=$('#cost'+id).text();
   	var auctN=-1;
   	if(json.lastUpd==-1){
   		return;
   	}
   	if(window.balance>0&&idType!=2){
		if(json.auction[0].bid_cost<=window.balance)window.balance-=json.auction[0].bid_cost;
   		for(j=0;j<window.auctions.length;j++){
   			if(window.auctions[j][0]==id){
   				//alert(json.auction[0].active_time);
   				window.auctions[j][1]=json.auction[0].active_time;
   				window.auctions[j][2]++;
   				//window.auctions[j][3]=0;
   				if(window.bidCost>0){
   				    window.auctions[j][3]+=window.bidCost;
				}else{
				    window.auctions[j][3]=0;
				}				  
   				window.yourBids=window.auctions[j][2];
   				if(window.auctions[j][3]){
   				    window.yourSum=window.auctions[j][3];					
   				}
   				auctN=j;
   			}
   		}
   		$('#balance').text(parseFloat(window.balance));
		$('#countBids'+id).html(json.auction[0].countBids);
		if($('#countBidsL'+id))$('#countBidsL'+id).html(json.auction[0].countBidsL);
   		$('#possibleBids'+id).html(json.auction[0].possibleBids);
   		$('#time'+id).text(json.auction[0].time);
   		$('#name'+id).html(json.auction[0].name);
   		$('#last_id_user'+id).attr('href','/user/'+json.auction[0].last_id_user+'/');

   		ec=parseFloat($('#market_cost').attr('value'))- parseFloat(json.auction[0].cost)-window.yourSum;
    	$('#economy').html(splitDimens(ec)+' руб.');
   		$('#yourSum'+id).text(splitDimens(window.yourSum));
   		$('#yourBids'+id).text(window.yourBids);
   		if(window.auctions[auctN][5]!=json.auction[0].cost){
   			window.auctions[auctN][5]!=json.auction[0].cost;
   			$('#cost'+id).text(parseFloat(json.auction[0].cost).toFixed(2)+' руб');
   			$('#cost'+id).animate( { backgroundColor: "#ee8c8d"}, 200 )
   				.animate( { backgroundColor: "#ffffff"}, 200 );
   		}
   		$('#lastUpdate').val(json.lastUpd);
 	}

   	if(window.educ_balance>0&&idType==2){
   		window.educ_balance-=1;
   		$('#educ_balance').text(window.educ_balance+window.educ_frozen_balance);

   		$('#time'+id).text(json.auction[0].time);
   		$('#cost'+id).text(parseFloat(json.auction[0].cost).toFixed(2)+' руб');
   		$('#name'+id).html(json.auction[0].name);
   		window.yourSum+=window.bidCost;
   		window.yourBids++;
   		$('#yourBids').text(window.yourBids);
   	$('#yourSum').text(splitDimens(window.yourSum));
   		if(cost!=json.auction[0].cost){
   			$('#cost'+id).animate( { backgroundColor: "#ee8c8d"}, 200 )
   				.animate( { backgroundColor: "#ffffff"}, 200 );
   		}
   		$('#lastUpdate').val(json.lastUpd);
   	}

  });

}


function doBid(id,idUser,idType){
	if(idUser==-1){
		//alert('Авторизируйтесь, чтобы сделать ставку');
		$('#doBid'+id).hide();
		$('#doBidR'+id).attr('style','display:block;margin:0 auto;width:123px;');
		$('#doBidIM'+id).attr('src',document.authImg.src);


		/*$('#doBid'+id).oneTime("1s", function() {
  		$('#doBid'+id).attr('src',document.auctImg.src);
		});*/

		return;
	}
	if(window.balance==0&&idType!=2){
		if(window.popUp==0){		
			$("#popup").show();
		}else{
			alert('У Вас недостаточно ставок. Пополните, пожалуйста, счет.');
		}
		
		$('#doBid'+id).attr('src',document.scoreImg.src);
		$('#doBid'+id).oneTime("1s", function() {
  		$('#doBid'+id).attr('src',document.auctImg.src);
		});
		return;
	}
	if(window.educ_balance==0&&idType==2){
		alert('У Вас закончились учебные ставки.');
		return;
	}

	if(window.nickname==$('#name'+id).text()){

		$('#doBid'+id).attr('src',document.liderImg.src);
		$('#doBid'+id).oneTime("1s", function() {
  		$('#doBid'+id).attr('src',document.auctImg.src);
		});
		return;
	}
  $.post(
  '/scripts/cur_auction.php',
  {
    doBid: id,
    lastUpd: $('#lastUpdate').attr('value'),
    idUser: idUser
  },
   function(data){  // загрузку JSON данных из файла example.json
   if(data==''){
  	//alert('sas');
  	return;
  }
   	var json = eval("("+data+")");
   	var cost=$('#cost'+id).text();
   	var auctN=-1;
   	if(json.lastUpd==-1){
   		return;
   	}

   	if(window.balance>0&&idType!=2){
		window.balance-=1;
   		for(j=0;j<window.auctions.length;j++){
   			if(window.auctions[j][0]==id){
   				//alert(json.auction[0].active_time);
   				window.auctions[j][1]=json.auction[0].active_time;
   				window.auctions[j][2]++;
   				//window.auctions[j][3]=0;
   				if(window.bidCost>0){
   				    window.auctions[j][3]+=window.bidCost;
				}else{
				    window.auctions[j][3]=0;
				}				  
   				window.yourBids=window.auctions[j][2];
   				if(window.auctions[j][3]){
   				    window.yourSum=window.auctions[j][3];					
   				}
   				auctN=j;
   			}
   		}
   		$('#balance').text(window.balance+window.frozen_balance);

   		$('#time'+id).text(json.auction[0].time);

   		$('#name'+id).html(json.auction[0].name);
   		$('#last_id_user'+id).attr('href','/user/'+json.auction[0].last_id_user+'/');

   		ec=parseFloat($('#market_cost').attr('value'))- parseFloat(json.auction[0].cost)-window.yourSum;
    	$('#economy').html(splitDimens(ec)+' руб.');
   		$('#yourSum'+id).text(splitDimens(window.yourSum));
   		$('#yourBids'+id).text(window.yourBids);
   		if(window.auctions[auctN][5]!=json.auction[0].cost){
   			window.auctions[auctN][5]!=json.auction[0].cost;
   			$('#cost'+id).text(parseFloat(json.auction[0].cost).toFixed(2)+' руб');
   			$('#cost'+id).animate( { backgroundColor: "#ee8c8d"}, 200 )
   				.animate( { backgroundColor: "#ffffff"}, 200 );
   		}
   		$('#lastUpdate').val(json.lastUpd);
 	}

   	if(window.educ_balance>0&&idType==2){
   		window.educ_balance-=1;
   		$('#educ_balance').text(window.educ_balance+window.educ_frozen_balance);

   		$('#time'+id).text(json.auction[0].time);
   		$('#cost'+id).text(parseFloat(json.auction[0].cost).toFixed(2)+' руб');
   		$('#name'+id).html(json.auction[0].name);
   		window.yourSum+=window.bidCost;
   		window.yourBids++;
   		$('#yourBids').text(window.yourBids);
   	$('#yourSum').text(splitDimens(window.yourSum));
   		if(cost!=json.auction[0].cost){
   			$('#cost'+id).animate( { backgroundColor: "#ee8c8d"}, 200 )
   				.animate( { backgroundColor: "#ffffff"}, 200 );
   		}
   		$('#lastUpdate').val(json.lastUpd);
   	}

  });

}

function isEnded(id){

  $.post(
  '/scripts/cur_auction.php',
  {
    isEnded: 1,
    idLot: id
  },
  function(data){  // загрузку JSON данных из файла example.json
  var i=0;
  var auctN=0;
  var js = eval("("+data+")");
  for (i=0;i<window.auctions.length;i++){
   	if(window.auctions[i][0]==id){
   		auctN=i;
   		break;
   	}
  }
   if(js.ended==1){
   	window.auctions[auctN][4]=1;
   	return true;
   }else{
   	window.auctions[auctN][1]=js.secs;
   	$('#time'+id).text(js.time);
   	 return false;
   }
   js=null;
  });
}

function ShowPay(){
	if($("#sms_cost").attr("style")=="" || $("#sms_cost").attr("style")=="display: block;" || $("#sms_cost").attr("style")=="display: block"){
	    $("#sms_cost").hide();
	    $("#sms_link").text('Узнать стоимость SMS');
	}
	else {
		$("#sms_cost").show();
	           $("#sms_link").text('Скрыть стоимость SMS');
	}
}

function showAddWinner(){
	if($("#commentsD").attr("style")=="" || $("#commentsD").attr("style")=="display: block;"){
	    $("#commentsD").hide();
	}
	else {
		$("#commentsD").show();
	}

}

var options_finish={
        success: onSubmitSuccessFinish,
        beforeSubmit: onBeforeSubmitFinish
};

function onBeforeSubmitFinish(){
}

function onSubmitSuccessFinish(data){
    if(!data || data==""){window.location.reload();}
    else $("#error").html(data);
    return false;
}

function  submitAuto(id){
    $("#auto_frm").ajaxSubmit(options_finish);
}

var options_finish_com={
        success: onSubmitSuccessFinishCom,
        beforeSubmit: onBeforeSubmitFinishCom
};

function onBeforeSubmitFinishCom(){
}

function onSubmitSuccessFinishCom(data){
    if(!data || data==""){
		$("#error-com").html("<span style='color:green;'>Спасибо за отзыв! После модерации он появится на этой странице.</span>");
		$("#com").hide();
		$("#btn-s").hide();
		}
    else $("#error-com").html(data);
    return false;
}

function  submitComment(){
    $("#comments").ajaxSubmit(options_finish_com);
}

function submitCommentP(){
    $("#commentsP").ajaxSubmit(options_finish_com);
}


function checkPack(count,order,el){
var ua = navigator.userAgent.toLowerCase();

isOpera = (ua.indexOf("opera") != -1); 
$(":radio").removeAttr("checked");
 $.post(
  '/kabinet/buy_bids/',
  {
     count: count,
     getSign:1,
     order:order
  },
  function(data){ 
	$('#SignatureValue').attr('value',data);
	$('#OutSum').attr('value',count);
	$("#WM_FRM").attr("action","https://merchant.roboxchange.com/Index.aspx");
	 $('#shpa').attr('name','');	 
	 $(el).attr("checked","true");
});
}

function checkPin(el){
	$(":radio").removeAttr("checked");	
	 $.post(
	  '/kabinet/buy_bids/',
	  {
	
	  },
	  function(data){ 
	$(el).attr("checked","true");
	$("#WM_FRM").attr("action","");
	});
}

function checkPurse(el){
	
	$(":radio").removeAttr("checked");		
	 $.post(
	  '/kabinet/buy_bids/',
	  {
	     count: $("#sum").attr('value'),
	     getSignShpa:1,
	     order:$('#InvId').attr('value')
	  },
	  function(data){ 
		$('#SignatureValue').attr('value',data);
		$('#OutSum').attr('value',$("#sum").attr('value'));
		 $('#shpa').attr('name','shpa');
		 $('#shpa').attr('value','');
		$("#WM_FRM").attr("action","https://merchant.roboxchange.com/Index.aspx");	
		 $(el).attr("checked","true");	

	});

}

function submitFormWM(){
	if($('#shpa').attr('name')=='shpa'){
	 $.post(
	  '/kabinet/buy_bids/',
	  {
	     count: $("#sum").attr('value'),
	     getSignShpa:1,
	     order:$('#InvId').attr('value')
	  },
	  function(data){ 
		$('#SignatureValue').attr('value',data);
		$('#OutSum').attr('value',$("#sum").attr('value'));
		$('#WM_FRM').submit();
	});
	}else $('#WM_FRM').submit();
}

function hoverD(id){
    $('#enter'+id).show();
}

function unhoverD(id){
    $('#enter'+id).hide();
}

function hoverMD(id){
    $('#enter'+id).show();

}

function unhoverMD(id){
    $('#enter'+id).hide();
}

function checkInputBuy(val,id){
 var patt=new RegExp("^[0-9]*$");
    if(parseInt($('#r'+id).attr('value'))<=0 || $('#r'+id).attr('value')==""){
	$('#status'+id).html('<input type="button" class="make_bid_form_button" value="" onclick="return false;"/>');$('#doBidR'+id).hide();$('#doBidN'+id).show();return;
    }
  if (!patt.test(val)){
    $('#status'+id).html('<input type="button" class="make_bid_form_button" value="" onclick="return false;"/>');
    $('#doBidR'+id).hide();
    $('#doBidN'+id).show();
    }
  else{
    $('#status'+id).html('<input type="button" class="balans_form_button" value="" onclick="return false;"/>');
    $('#doBidR'+id).show();
    $('#doBidN'+id).hide();
    }
}

function checkInput(val,id,el){
  var patt=new RegExp("^[0-9]*$");
  if(parseInt($('#r'+id).attr('value'))<=0 || $('#r'+id).attr('value')==""){
	$('#status'+id).html('<input type="image" class="make_bid_form_button" value="" onclick="return false;"/>');$('#doBidR'+id).hide();$('#doBidN'+id).show();return;
}
   if(el=="k"){
   }else{
  if(val==""){$('#status'+id).html('<input type="image" class="make_bid_form_button" value="" onclick="return false;"/>');$('#doBidR'+id).hide();$('#doBidN'+id).show();return;
    }
if(val >parseFloat($('#wanted_cost'+id).attr('value'))){$('#status'+id).html('<input type="image" style="cursor:normal"  class="make_bid_form_button" value="" onclick="return false;"/>');$('#doBidR'+id).hide();$('#doBidN'+id).show();return;
    }}
  if (!patt.test(val)){
    $('#status'+id).html('<input type="image"  class="make_bid_form_button" value="" onclick="return false;"/>');
    $('#doBidR'+id).hide();
    $('#doBidN'+id).show();
    }
  else{
    $('#status'+id).html('<input type="image" class="main_product_show_button" value="" onclick="return false;"/>');
    $('#doBidR'+id).show();
    $('#doBidN'+id).hide();
    }
}
function ajax_search(){ 
  var search_val=$("#city").val();
 $('#city_res').html('');
  $.post("/city.php", {city : search_val}, function(data){
   if (data.length>0){ 
    $('#city_res').html(data);
   }else{
     $('#city_res').html('<strong>Нет такого города</strong>');
    }
  });
} 
