/*
**     JavaScript Source Code
**     Created by Kalin Ganev
**     <KalinGanev [AT] Gmail (DOT) com>
**     Date Created:  2008-12-02
**     Last Modified: 2011-11-17
*/





// A global variable needed for preventing page scrolling during displaying product item details:
var  gint_bodyScrollTop = 0;

var gbool_isBrowserIeAny = false;
/*@cc_on
	/*@if (@_jscript)
		gbool_isBrowserIeAny = document.all && !window.opera;
	/*@else @*/
		gbool_isBrowserIeAny = false;
	/*@end
@*/


var  PRODUCTITEMDETAILS_WIDTH_PX  = 660;
var  PRODUCTITEMDETAILS_HEIGHT_PX = 530;
var  PRODUCTITEMDETAILS_FADE_NUM_STEPS = 30;
var  PRODUCTITEMDETAILS_FADE_TIME_MS = 20;


function /*int*/ getScreenWidth () {
	var  x = 0;

	if (self.innerHeight) {
		// All except Explorer.
		x = self.innerWidth;
	} else {
		if (document.documentElement && document.documentElement.clientHeight) {
			// Explorer 6 Strict Mode.
			x = document.documentElement.clientWidth;
		} else {
			if (document.body) {
				// Other Explorers.
				x = document.body.clientWidth;
			}
		}
	}
	return x;
}


function /*int*/ getScreenHeight () {
	var  y = 0;

	if (self.innerHeight) {
		// All except Explorer.
		y = self.innerHeight;
	} else {
		if (document.documentElement && document.documentElement.clientHeight) {
			// Explorer 6 Strict Mode.
			y = document.documentElement.clientHeight;
		} else {
			if (document.body) {
				// Other Explorers.
				y = document.body.clientHeight;
			}
		}
	}
	return y;
}


function /*int*/ getBodyScrollTop () {
	var  int_pos = 0;

	if (window.pageYOffset) {
		int_pos = window.pageYOffset;
	} else {
		if (document.documentElement && document.documentElement.scrollTop) {
			int_pos = document.documentElement.scrollTop;
		} else {
			if (document.body) {
				int_pos = document.body.scrollTop;
			}
		}
	}
	return int_pos;
}


function /*void*/ displayProductItemDetails (int_idProductItem, str_nameArrayProductitems) {
	if (gbool_isBrowserIeAny) {
		// Hiding select-boxes as they cannot be covered with a layer in IE:
		var  objarr_selectBoxes = document.getElementsByTagName('select');
		for (var i=0; i<objarr_selectBoxes.length; i++) {
			objarr_selectBoxes[i].style.visibility = 'hidden';
		}
	}

	document.getElementById('Overlay').style.width      = document.body.clientWidth  + 'px';
	document.getElementById('Overlay').style.height     = document.body.clientHeight + 'px';
	document.getElementById('Overlay').style.visibility = 'visible';

	// Preventing page scrolling:
	gint_bodyScrollTop = this.getBodyScrollTop();
	window.onscroll = function (event) {
		window.scrollTo(0, gint_bodyScrollTop);
	}

	window.fillContentProductItemDetails(int_idProductItem, str_nameArrayProductitems);

	if (!gbool_isBrowserIeAny) {
		document.getElementById('ProductItemDetails').style.visibility = 'visible';
	}
	window.fadeInProductItemDetails(0);
} // displayProductItemDetails() function


var  PRODUCT_PLACE_LIST        = 1;
var  PRODUCT_PLACE_DETAILS     = 2;
var  PRODUCT_PLACE_RANDOM      = 3;
var  PRODUCT_PLACE_RECENT      = 4;
var  PRODUCT_PLACE_BESTSELLING = 5;


function /*void*/ fillContentProductItemDetails (int_idProductItem, str_nameArrayProductitems) {
	var  int_cntRows = 1;
	window.eval('var  arr_productitemCurr = ' + str_nameArrayProductitems + '[' + int_idProductItem + '];');
	document.getElementById('ProductItemDetails').className = arr_productitemCurr['is_promo']
			? 'ProductItemDetailsPromo ProductItemDetailsPromo_' + LANG_ABBR : '';
	document.getElementById('ProductItemDetails').style.left = (getScreenWidth()   - PRODUCTITEMDETAILS_WIDTH_PX)  / 2 + 'px';
	document.getElementById('ProductItemDetails').style.top  = ((getScreenHeight() - PRODUCTITEMDETAILS_HEIGHT_PX) / 2 + getBodyScrollTop()) + 'px';
	var  str_htmlNavClose =
			      '<div id="ProductItemDetails_NavigationClose">'
			+         '<a href="#" onclick="fadeOutProductItemDetails(PRODUCTITEMDETAILS_FADE_NUM_STEPS); return false;"><img src="' + BASE + 'images/btn_close_' + LANG_ABBR + '.png" id="ImgNavigationClose" alt="close" title="" /></a> '
			+     '</div>';
	var  str_html =
			'<div id="ProductItemDetails_Navigation">'
			+     '<div id="ProductItemDetails_NavigationPrev"' + (arr_productitemCurr['productitem_id_prev'] > 0 ? ' class="ProductItemDetails_NavigationEnabled"' : '') + '>'
			+         (arr_productitemCurr['productitem_id_prev'] > 0 ? '« <a href="#" onclick="fillContentProductItemDetails(' + arr_productitemCurr['productitem_id_prev'] + ', \'' + str_nameArrayProductitems + '\'); return false;">' + gstr_captionBtnPrev + '</a>' : '')
			+     '</div>'
			+     '<div id="ProductItemDetails_NavigationNext"' + (arr_productitemCurr['productitem_id_next'] > 0 ? ' class="ProductItemDetails_NavigationEnabled"' : '') + '>'
			+         (arr_productitemCurr['productitem_id_next'] > 0 ? '<a href="#" onclick="fillContentProductItemDetails(' + arr_productitemCurr['productitem_id_next'] + ', \'' + str_nameArrayProductitems + '\'); return false;">' + gstr_captionBtnNext + '</a> »' : '')
			+     '</div>';
	if (!arr_productitemCurr['is_promo']) {
		// Not a promo productitem.
		str_html += str_htmlNavClose;
	}
	str_html +=
			      '<div class="Cleaner"></div>'
			+ '</div>'

			+ '<table id="TblProductItemInfo" cellspacing="0" border="0">'
			+ '<tr>'
			+     '<td id="TdProductItemImage">'
			+         '<img src="' + BASE + arr_productitemCurr['image_medium_location'] + '" id="ProductItemImage" width="' + arr_productitemCurr['image_medium_width_px'] + '" height="' + arr_productitemCurr['image_medium_height_px'] + '" alt="" />'
			+         '<div id="ProductItemPrice">'
			+             '<a href="#" class="LinkProductItemBuy" onclick="onClickAddProductItemToCart(' + PRODUCT_PLACE_DETAILS + ',' + int_idProductItem + '); return false;">' + gstr_captionBtnBuy + '</a>'
			+             '<div class="ProductItemQuantity"><input type="text" class="SearchInputTextPrice" size="4" value="1" title="' + gstr_captionQuantity + '" id="productitem_quantity_place_id' + PRODUCT_PLACE_DETAILS + '_productitem_id' + int_idProductItem + '" /></div>'
			+             '<div id="CaptionPriceValue">' + (arr_productitemCurr['is_promo'] ? arr_productitemCurr['price_promo'] : arr_productitemCurr['price']) + ' ' + gstr_captionCurrency + '</div>';
	if (arr_productitemCurr['is_promo']) {
		// A promo productitem.
		str_html +=
			              '<div id="CaptionPriceValueOld">' + arr_productitemCurr['price'] + ' ' + gstr_captionCurrency + '</div>';
	}
	str_html +=
			              '<div id="CaptionPriceTtl">' + gstr_captionPrice + ': </div>'
			+         '</div>'
			+     '</td>'

			+     '<td id="TdProductItemDetails">'
			+         '<table id="TblProductItemDetails" cellpadding="6" cellspacing="2" border="0">'
			+         '<tr class="' + (0==int_cntRows%2 ? 'TrEven' : 'TrOdd') + '">'
			+             '<th width="96">' + gstr_captionName + ':</th>'
			+             '<td>' + arr_productitemCurr['name'] + '</td>'
			+         '</tr>';
	int_cntRows++;

	if ('' != arr_productitemCurr['code']) {
		str_html +=
						  '<tr class="' + (0==int_cntRows%2 ? 'TrEven' : 'TrOdd') + '">'
				+             '<th>' + gstr_captionCode + ':</th>'
				+             '<td>' + arr_productitemCurr['code'] + '</td>'
				+         '</tr>';
		int_cntRows++;
	}

	if ('' != arr_productitemCurr['brand_name']) {
		str_html +=
						  '<tr class="' + (0==int_cntRows%2 ? 'TrEven' : 'TrOdd') + '">'
				+             '<th>' + gstr_captionBrand + ':</th>'
				+             '<td>' + arr_productitemCurr['brand_name'] + '</td>'
				+         '</tr>';
		int_cntRows++;
	}

	if (arr_productitemCurr['count_pack'] > 0) {
		str_html +=
						  '<tr class="' + (0==int_cntRows%2 ? 'TrEven' : 'TrOdd') + '">'
				+             '<th>' + gstr_captionCountPack + ':</th>'
				+             '<td>' + arr_productitemCurr['count_pack'] + '</td>'
				+         '</tr>';
		int_cntRows++;
	}

	if (arr_productitemCurr['count_box'] > 0) {
		str_html +=
						  '<tr class="' + (0==int_cntRows%2 ? 'TrEven' : 'TrOdd') + '">'
				+             '<th>' + gstr_captionCountBox + ':</th>'
				+             '<td>' + arr_productitemCurr['count_box'] + '</td>'
				+         '</tr>';
		int_cntRows++;
	}

	if ('' != arr_productitemCurr['note_colors']) {
		// Current productitem has color information.
		str_html +=
			          '<tr class="' + (0==int_cntRows%2 ? 'TrEven' : 'TrOdd') + '">'
			+             '<td colspan="2" id="TdProductItemDetailsNote"><span class="TextProductItemDetails">' + gstr_captionNoteColors + ':</span> ' + arr_productitemCurr['note_colors'] + '</td>'
			+         '</tr>';
		int_cntRows++;
	}

	if ('' != arr_productitemCurr['note']) {
		str_html +=
						  '<tr class="' + (0==int_cntRows%2 ? 'TrEven' : 'TrOdd') + '">'
				+             '<td colspan="2" id="TdProductItemDetailsNote"><span class="TextProductItemDetails">' + gstr_captionNote + ':</span> ' + arr_productitemCurr['note'] + '</td>'
				+         '</tr>';
		int_cntRows++;
	}

	str_html +=
			          '</table>'
			+     '</td>'
			+ '</tr>'
			+ '</table>'

			+ '<div id="NoteVatIncluded">' + gstr_captionVatIncluded + '</div>'
	;
	if (arr_productitemCurr['is_promo']) {
		// A promo productitem.
		str_html += str_htmlNavClose;
	}
	str_html +=
		      '<div class="Cleaner"></div>';
	document.getElementById('ProductItemDetails').innerHTML = str_html;
} // fillContentProductItemDetails()


function /*void*/ applyOpacityProductItemDetails (obj_styleProductItemDetails, int_numStep) {
	var  fl_opacity = int_numStep/PRODUCTITEMDETAILS_FADE_NUM_STEPS;
	obj_styleProductItemDetails.opacity      = fl_opacity;
	obj_styleProductItemDetails.MozOpacity   = fl_opacity;
	obj_styleProductItemDetails.KhtmlOpacity = fl_opacity;
}


function /*void*/ fadeInProductItemDetails (int_numStep) {
	var  obj_divProductItemDetails = document.getElementById('ProductItemDetails');
	var  obj_styleProductItemDetails = obj_divProductItemDetails.style;
	if (gbool_isBrowserIeAny) {
		// Applying IE "blendtrans" visual filter:
		// Make sure the filter is not playing:
		if (obj_divProductItemDetails.filters.blendTrans.status != 2) {
			obj_divProductItemDetails.filters.blendTrans.apply();
			obj_styleProductItemDetails.visibility = 'visible';
			obj_divProductItemDetails.filters.blendTrans.play();
		}
	} else {
		// Mozilla, Opera, etc.
		applyOpacityProductItemDetails(obj_styleProductItemDetails, int_numStep);
		if (int_numStep < PRODUCTITEMDETAILS_FADE_NUM_STEPS) {
			window.setTimeout('fadeInProductItemDetails(' + (int_numStep+1) + ');', PRODUCTITEMDETAILS_FADE_TIME_MS/PRODUCTITEMDETAILS_FADE_NUM_STEPS);
		}
	}
}


function /*void*/ fadeOutProductItemDetails (int_numStep) {
	var  obj_divProductItemDetails = document.getElementById('ProductItemDetails');
	var  obj_styleProductItemDetails = obj_divProductItemDetails.style;
	if (gbool_isBrowserIeAny) {
		// Applying IE "blendtrans" visual filter:
		// Make sure the filter is not playing:
		if (obj_divProductItemDetails.filters.blendTrans.status != 2) {
			obj_divProductItemDetails.filters.blendTrans.apply();
			obj_styleProductItemDetails.visibility = 'hidden';
			obj_divProductItemDetails.filters.blendTrans.play();
		}
		window.setTimeout('hideProductItemDetails();', 1000);
	} else {
		// Mozilla, Opera, etc.
		applyOpacityProductItemDetails(obj_styleProductItemDetails, int_numStep);
		if (int_numStep > 0) {
			window.setTimeout('fadeOutProductItemDetails(' + (int_numStep-1) + ');', PRODUCTITEMDETAILS_FADE_TIME_MS/PRODUCTITEMDETAILS_FADE_NUM_STEPS);
		} else {
			hideProductItemDetails();
		}
	}
}


function /*void*/ hideProductItemDetails () {
	document.getElementById('Overlay').style.visibility = 'hidden';
	if (gbool_isBrowserIeAny) {
		// Unhiding select-boxes:
		var  objarr_selectBoxes = document.getElementsByTagName('select');
		for (var i=0; i<objarr_selectBoxes.length; i++) {
			objarr_selectBoxes[i].style.visibility = 'visible';
		}
	} else {
		document.getElementById('ProductItemDetails').style.visibility = 'hidden';
	}

	// Restoring page scrolling:
	window.onscroll = null;
}




function /*String*/ getOrderByParameterGet () {
	var  str_orderByUserSelected = document.getElementById('order').value;
	if ('name' == str_orderByUserSelected) {
		// Order by product name.
		return 'order=name';
	}
	if ('price' == str_orderByUserSelected) {
		// Order by product name.
		return 'order=price';
	}
	return '';
}


function /*void*/ changeProductItemOrderDefault (int_idProductType) {
	window.self.location.href = BASE + 'products/?producttype_id=' + int_idProductType + '&' + getOrderByParameterGet() + LANG_PAR_EFFECTIVE_AMP_SIMPLE;
}
function /*void*/ changeProductItemOrderSearch (int_idProductCategory, str_priceFrom, str_priceTo) {
	var  str_priceFromParameterGet = ('' == str_priceFrom ? '' : '&price_from=' + str_priceFrom);
	var  str_priceToParameterGet   = ('' == str_priceTo   ? '' : '&price_to='   + str_priceTo);
	window.self.location.href = BASE + 'search/?productcategory_id=' + int_idProductCategory
			+ str_priceFromParameterGet + str_priceToParameterGet + '&' + getOrderByParameterGet() + LANG_PAR_EFFECTIVE_AMP_SIMPLE;
}
function /*void*/ changeProductItemOrderSearchCode (str_code) {
	window.self.location.href = BASE + 'search-code/?SearchInputTextCode=' + str_code + '&' + getOrderByParameterGet() + LANG_PAR_EFFECTIVE_AMP_SIMPLE;
}
function /*void*/ changeProductItemOrderSearchBrandId (int_idBrand) {
	window.self.location.href = BASE + 'search-brand/?brand_id=' + int_idBrand + '&' + getOrderByParameterGet() + LANG_PAR_EFFECTIVE_AMP_SIMPLE;
}
function /*void*/ changeProductItemOrderPromo () {
	window.self.location.href = BASE + 'products-promo/?' + getOrderByParameterGet() + LANG_PAR_EFFECTIVE_AMP_SIMPLE;
}


