var selOptInp={};

	
function ChangeImg() {
  var inpPID = $("#prodVal").attr("pid");
  var ihtml = '';	
  jQuery.ajax({
	type: 'post',
	dataType: 'json',
	url: HTTP_HOS_S+'/mine/api_smarty.php?json=yes&callback=?',
	data: ({'likeProd':'yes','PID':inpPID,'limit':'7'}), /*change*/
	success: function(dat){
	  jQuery.each(dat.likeProd, function(i,item){ 
		ihtml = ' <a href="'+HTTP_HOST_S+'productID/'+ item.ID+ '" ><img src="http://fege.com.ua/img/s_'+item.img+'" border="0"></a>'+ihtml; 
	  });
	},
	complete: function(xhr, status) { jQuery('#viFrame').html(ihtml); }	
  });	

}



function BuyItem( pid ){
  varPOST = {};
  varPOST['cart_x'] = 'yes';
  varPOST['add_prod'] = 'yes';
  varPOST['show_shopping_cart_info']= 1; // выводит инфо о корзине
  varPOST['productID']= pid;
  varPOST['sess_id']= sess_id;
  
  varPOST['option_select_hidden_0'] = selOptInp[1];//размер
  varPOST['option_select_hidden_1'] = selOptInp[2];//цвет
  
  jQuery.ajax({
	type: 'POST',
	url: HTTP_HOS_S+'/mine/api_smarty.php?json=yes&callback=?',
	cache: true,
	data: varPOST,
	dataType: "json",
	async: true, // false == waiting  
	success: function(data){
	  //alert( data );
	  //ajax( {"CoH":"h","type":"GET","dataType":"html","succ":"mct_succ","dhash":"none","data":{"ajax":"mct"}} ); // ajax redirect
	  shop_cart_info_upd_html(data); //обновляет shopping_cart_info data=json
	}
  });
}
function m_img( imgname ){
  jQuery('#m_img').attr('href','http://fege.com.ua/img/m_'+imgname);
  jQuery('#m_img img').attr('src','http://fege.com.ua/img/m_'+imgname);
  
  return true;
}
function add_favorite(a) {
  title=document.title;
  url=document.location;
  try { window.external.AddFavorite(url, title); /* Internet Explorer */ }
  catch (e) {
	try { window.sidebar.addPanel(title, url, ""); /* Mozilla */ }
	catch (e) {
	 // Opera
	  if (typeof(opera)=="object") {
		a.rel="sidebar";
		a.title=title;
		a.url=url;
		return true;
	  } else {
		// Unknown
		alert('Нажмите Ctrl-D чтобы добавить страницу в закладки');
	  }
	}
  }
  return false;
}

function ShowAboutModel(element) { /*  product detailes  */
  switch(element.id)  {
	case "showDescription": {
	  document.getElementById("menuImg_1").src="/images/design/img01a.gif";
	  document.getElementById("menuImg_2").src="/images/design/img02a.gif";
	  document.getElementById("menuImg_3").src="/images/design/img03a.gif";
	  document.getElementById("showDescription").className="gc10";
	  document.getElementById("showCharacteristics").className="gc11";
	  document.getElementById("showDescription").style.cursor="";
	  document.getElementById("showCharacteristics").style.cursor="pointer";
	  document.getElementById("ItemDescription").style.display="inline";
	  document.getElementById("ItemCharacteristics").style.display="none";
	  //document.getElementById("descText").title="";
	  document.getElementById("charText").title="Показать характеристики модели";
	  break;
	}
	case "showCharacteristics": {
	  document.getElementById("menuImg_1").src="/images/design/img01b.gif";
	  document.getElementById("menuImg_2").src="/images/design/img02b.gif";
	  document.getElementById("menuImg_3").src="/images/design/img03b.gif";
	  document.getElementById("showDescription").className="gc11";
	  document.getElementById("showCharacteristics").className="gc10";
	  document.getElementById("showDescription").style.cursor="pointer";
	  document.getElementById("showCharacteristics").style.cursor="";
	  document.getElementById("ItemDescription").style.display = "none";
	  document.getElementById("ItemCharacteristics").style.display = "inline";
	  document.getElementById("charText").title="";
	  //document.getElementById("descText").title="Показать описание модели";
	  break;
	}
  } 
}

function showSub(o){    /*  раскрываем product news */
  var sub = o.parentNode.getElementsByTagName("ul");
  if (sub.length)
    sub[0].style.display = (sub[0].style.display=='') ? 'none' : '';
}

/* ====disc_time==== */
function add_week(seks){
  seks = parseInt(seks);
  if(seks<0) seks=seks+60*60*24*7;
  
  if(seks<0) return add_week(seks);
  else return seks;
}

function to_date( date ){ 
  if(date === undefined){
	var val = jQuery('#disc_time').attr('val2');
  }
  
  var d1 = new Date(); // текущее время
  d1 = d1.getTime();
  var d2 = val*1000; // время окончания (день включительно) в милесекундах с 01.01.1970 getTime setTime
  var d3 = d2-d1; // осталось в сек
  d3 = (d3/1000).toFixed(0);
  d3 = add_week( d3 ); // прибавляем неделю
  
  //if( d2.getTime()<d1.getTime() ) d3 = parseInt(d3) + 60*60*24*7; 
  //alert( "d1="+d1+"-----------"+"d1.getTime()="+d1.getTime()+"-----------"+"d2="+d2+"-----------"+"d2.getTime()="+d2.getTime()+"d3="+d3+"-----------" );
  
  return [d3,d2,d1];
}

function addday( count ){
  
  if(count === undefined) count=1;
  var d1 = new Date();
  var day = d1.getDate();
  var month = d1.getMonth();
  var year = d1.getFullYear();
  
  daysmonth = [31,28,31,30,31,30,31,31,30,31,30,31];
  
  if(day+count > daysmonth[month]){ // последний день месяца
	day = day+count-daysmonth[month];
	if(daysmonth[month]==12){ // последний месяц года help@finam.eu
	  month = 1;
	  year = year + 1;
	}else month = month + 1;
  }else{
	day = day + count;
  }
  
  var d2 = new Date(year, month, day, 0, 0, 0, 0 );
  var d3 = ((d2.getTime()-d1.getTime())/1000).toFixed(0);
  
  
  
  return [d3,d2,d1];
}


// Converting date difference from seconds to actual time
function convert_to_time(secs){
  //secs = 60*60*24;
  secs = parseInt(secs);
  
  ss = secs%60; secs = (secs/60).toFixed(0);
  mm = secs%60; secs = (secs/60).toFixed(0);
  hh = secs%24; secs = (secs/24).toFixed(0);
  dd = secs;
  
  if(ss < 10) ss = "0"+ss; 
  if(mm < 10) mm = "0"+mm; 
  if(hh < 10) hh = "0"+hh; 
  
  d2 = dayordays(dd);
  
  jQuery("#disc_time #s").html( ss );
  jQuery("#disc_time #m").html( mm );
  jQuery("#disc_time #h").html( hh );
  jQuery("#disc_time #d").html( dd );
  jQuery("#disc_time #d2").html( d2 );
}

// Our function that will do the actual countdown
function do_cd(){
  
  convert_to_time(countdown);
  setTimeout('do_cd()', 1000*7);
  countdown = countdown - 7;
  
}

function dayordays( count ){
  if(count%10 == 1) return "день";
  if(count%10 >= 2 && count%10 <= 4) return "дня";
  if(count%10 == 0 || count%10 >= 5) return "дней";
}


