/*
function showPopup(popup) {
	$('#black').height(document.body.offsetHeight);
	currentOffset2 = 0;
	currentOffset = document.documentElement.scrollTop || document.documentElement.scrollTop;
	var windowHeight;
	if (!($.browser.opera)) { windowHeight = document.documentElement.clientHeight } 
 else { windowHeight = document.body.clientHeight }
	if (windowHeight < $('#'+popup).height()) {
		currentOffset = (windowHeight - $('#'+popup).height() + currentOffset - 10);
	} else {
		currentOffset2 = parseInt((windowHeight - $('#'+popup).height()) / 2);
	}
	pLeft = (document.body.clientWidth - $('#'+popup).width()) / 2;
	$('#black').show();
	$('#'+popup).css({top:currentOffset+currentOffset2,left:pLeft}).show();
}
*/
function showPopup(popup) {
	$('#black').height(document.body.offsetHeight);
	currentOffset2 = 0;
	currentOffset = document.documentElement.scrollTop || document.documentElement.scrollTop;
	var windowHeight;
	windowHeight = document.documentElement.clientHeight;
	/*if (!($.browser.opera)) { windowHeight = document.documentElement.clientHeight } else { windowHeight = document.body.clientHeight}*/
	if (window.navigator.userAgent.substr(window.navigator.userAgent.indexOf("Opera")+6,4) == 9.27) { windowHeight = document.body.clientHeight}

	if (windowHeight < $('#'+popup).height()) {
		currentOffset = (windowHeight - $('#'+popup).height() + currentOffset - 10);
	} else {
		currentOffset2 = parseInt((windowHeight - $('#'+popup).height()) / 2);
	}
	pLeft = (document.body.clientWidth - $('#'+popup).width()) / 2;
	$('#black').show();
	$('#'+popup).css({top:currentOffset+currentOffset2,left:pLeft}).show();
	
}

function sendIdImage(id){
 var action = "/zal/load_product_xml.php";
 
 $('#bImg img').eq(0).remove();
 /// Добавляем новую
 var img = new Image();

 img.onload = function() {
     $('#bImg').append(this);
     $('#bImg img').eq(0).hide();
     $('#bImg img').eq(0).fadeIn(200);
 };
 /// Вывод фото
 img.src = "/img/loader.gif"; 
 
 $.post(action,{id:id},loadImage);
}

function loadImage(xml){   

  showPopup('photoPopup'); 
 //собираем данные
 var art = $("art",xml);
 var prc = $("prc",xml);
 var pro = $("pro",xml);
 var mat = $("mat",xml);
 var src = $("src",xml);
 var w   = $("w",xml);
 var y   = $("y",xml);
 
 var old_prc = $("old_prc", xml);
 var dis = $("dis", xml);
 var favorite = $("favorite", xml);
 
 var site_part = $("site_part", xml);
 var catalog_id = $("catalog_id", xml);
 var product_id = $("product_id", xml);
 
 //назначить значения и показать PopUp
 $("#art").attr("innerHTML",art.text());
 $("#pro").attr("innerHTML",pro.text());
 $("#mat").attr("innerHTML",mat.text());
 $("#prc").attr("innerHTML",prc.text() + ".-");

 $("#old_prc").attr("innerHTML","");  
 if (old_prc.text() != "0") {
    $("#old_prc").attr("innerHTML","<em class=\"old_price\"></em>" + old_prc.text() + ".-");
 }
 /* */
 
 $("#id_catalog").attr("value", catalog_id.text());
 $("#id_product").attr("value", product_id.text());
 $("#site_part").attr("value", site_part.text());
 
  
 $("#dis").attr("innerHTML","");
 $("#dis").attr("class","discount_no");
 if (dis.text() != "0"){
     $("#dis").attr("innerHTML"," - <strong>"+dis.text() + "</strong>" + "%");
     $("#dis").attr("class","discount");
 }
 
 if (favorite.text() != "1") {
     $("#add_remove_favoite").attr("innerHTML","<a href=\"\" onclick=\"add_favorit('" + site_part.text() + "','" + catalog_id.text() + "','" + product_id.text() + "');return false;\" class=\"add\"><span>Обязательно куплю</span></a>");
 } else {
     $("#add_remove_favoite").attr("innerHTML","<a href=\"\"  onclick=\"del_favorit('" + site_part.text() + "','" + catalog_id.text() + "','" + product_id.text() + "');return false;\" class=\"remove\"><span>Удалить из списка покупок</span></a>");
 }
 
 $('#bImg img').eq(0).remove();

 /// Добавляем новую
 var img = new Image();

 img.onload = function() {
     $('#bImg').append(this);
     $('#bImg img').eq(0).hide();
     $('#bImg img').eq(0).fadeIn(200);
 };
 
 /// Вывод фото   
  img.src = src.text();
 /*img.width = w.text();
 img.height = y.text();
  */
 return true;
}

function sendMapIdWay(id,fkey){
 var action = "/zal/load_scheme_xml.php";
 
 
 $('#bImg img').eq(0).remove();
 /// Добавляем новую
 var img = new Image();

 img.onload = function() {
     $('#bImg').append(this);
     $('#bImg img').eq(0).hide();
     $('#bImg img').eq(0).fadeIn(200);
 };
 /// Вывод фото
 img.src = "/img/loader.gif"; 
 
 
 $.post(action,{id:id,fkey:fkey},loadMapWay);
}

function loadMapWay(xml){
 var src = $("src",xml);
 var w   = $("w",xml);
 var h   = $("h",xml);
 var alt = $("alt",xml);
 var htext = $("htext",xml);
 var phone = $("phone",xml);

 $("#address").attr("innerHTML","<B>Магазин на "+htext.text()+"</B><BR>Телефон: "+phone.text());
 
 $('#bImg img').eq(0).remove();
 /// Добавляем новую
 var img = new Image();

 img.onload = function() {
     $('#bImg').append(this);
     $('#bImg img').eq(0).hide();
     $('#bImg img').eq(0).fadeIn(200);
 };
 /// Вывод фото
 document.bImg.src = src.text();
 
 
 showPopup('photoPopup');
 return true; 
}