/*
 * Copyright : (c) 2006 Webfish IT Services
 * Website   : http://www.webfish.nl
 * Email     : info@webfish.nl
 * -------------------------------------------------------------------------
 *   $Id: block.js 376 2010-07-19 09:36:06Z caspar $
 * -------------------------------------------------------------------------
 */

var str_prev_nr = '';

function blocking(str_nr)
{
	if (str_prev_nr != '')
	{
		var prev = document.getElementById(str_prev_nr);
		if (prev)
			prev.style.display = 'none';
	}
	if (str_prev_nr != str_nr)
	{
		var nr = document.getElementById(str_nr);
		if (nr)
		{
			nr.style.display = '';
			str_prev_nr = str_nr;
		}
		else
		{
			str_prev_nr = '';
		}
	}
	else
	{
		str_prev_nr = '';
	}

	return false;
}

function swapLink()
{
	str_display = (document.getElementById('link').style.display == 'none') ? '' : 'none';
	document.getElementById('link').style.display = str_display;
}

function swapMenuImg(obj_img, str_img)
{
	if (obj_img && obj_img.src && (obj_img != obj_prev_cat_img))
	{
		obj_img.src = strScriptPath + 'upload/images_page/image_'+ str_img +'.jpg';
	}
}

function swapCatImg(obj_img, str_onoff, str_img, bln_force)
{
	if (!bln_force)
		bln_force = false;
	if (obj_img && obj_img.src && (obj_img != obj_prev_cat_img) || bln_force)
	{
		obj_img.src = strScriptPath + 'upload/images_cat/image_'+ str_onoff + '_'+ str_img +'.jpg';
	}
}

var obj_prev_cat_img = -1;
var obj_prev_cat_id  = -1;
function clickCatImg(obj_img, str_img)
{
	if (obj_prev_cat_img != -1)
		swapCatImg(obj_prev_cat_img, '1', obj_prev_cat_id, true);

	if (obj_prev_cat_img != obj_img)
	{
		swapCatImg(obj_img, '2', str_img);
		obj_prev_cat_img = obj_img;
		obj_prev_cat_id  = str_img;
	}
	else
	{
		obj_prev_cat_img = -1;
		obj_prev_cat_id  = -1;
	}
}

function sizesHover()
{
	var allHTMLTags = document.getElementsByTagName('*');
	var numHTMLTags = allHTMLTags.length;
	for (i = 0; i < numHTMLTags; i++)
	{
		if (allHTMLTags[i].className == 'sizeshover')
		{
			var item = allHTMLTags[i];
			item.onmouseover = function(){
				var itemdiv = document.getElementById(this.id +'_div');
				if (itemdiv)
				{
					itemdiv.style.display = 'block';
				}
			}
			item.onmouseout = function(){
				var itemdiv = document.getElementById(this.id +'_div');
				if (itemdiv)
				{
					itemdiv.style.display = 'none';
				}
			}
		}
	}
}

var appendSizesHover_oldOnload = (window.onload) ? window.onload : function () { };
window.onload = function () {appendSizesHover_oldOnload(); initCartHover(); sizesHover();}

function initCartHover()
{
	var counterATags = 1;
	var allATags = document.getElementsByTagName('a');
	var numATags = allATags.length;
	for (i = 0; i < numATags; i++)
	{
		if (allATags[i].className == 'cart_product_link')
		{
			var p = allATags[i];
			if (p.rel != '')
			{
				p.id = 'cart_link'+ counterATags;
				var d = document.createElement('div');
				d.id = 'cart_image'+ counterATags;
				d.innerHTML = '<img src="'+ p.rel +'">';
				d.style.display = 'none';
				d.style.position = 'absolute';
				d.className = 'cart_product_image';
				d.style.left = findPosX(p) +'px';
				d.style.top = (findPosY(p) + 13) +'px';
				document.body.appendChild(d);

				p.onmouseover = function(){
					var id = this.id.substr(9);
					var d = document.getElementById('cart_image'+ id);
					if (d)
					{
						d.style.display = 'block';
					}
				}

				p.onmouseout = function(){
					var id = this.id.substr(9);
					var d = document.getElementById('cart_image'+ id);
					if (d)
					{
						d.style.display = 'none';
					}
				}

				counterATags++;
			}
		}
	}
}

function appendOnLoadAlert(str_msg)
{
	var appendOnLoadAlert_oldOnload = (window.onload) ? window.onload : function () { };
	window.onload = function () {appendOnLoadAlert_oldOnload();alert(str_msg);}
}

function input_initSelect(str_id, fnc_changed, bln_callonchange)
{
	if (typeof bln_callonchange == 'undefined')
	{
		bln_callonchange = false;
	}
	var obj_input = document.getElementById(str_id);
	obj_input.onfocus   = input_selectFocussed;
	obj_input.onchange  = input_selectChanged;
	obj_input.onkeydown = input_selectKeyed;
	obj_input.onclick   = input_selectClicked;

	obj_input.fnc_changed = fnc_changed;

	if (bln_callonchange)
	{
		obj_input.changed = true;
		obj_input.onchange();
	}
}

function input_selectChanged(obj_e)
{
	var obj_input;
	if (obj_e && obj_e.value)
	{
		obj_input = obj_e;
	}
	else
	{
		obj_input = this;
	}
	if (!obj_input.changed)
	{
		return ;
	}

	if (obj_input.fnc_changed)
		obj_input.fnc_changed();

	obj_input.changed = false;
}

function input_selectClicked()
{
	this.changed = true;
}

function input_selectFocussed()
{
	this.initValue = this.value;
}

function input_selectKeyed(e)
{
	var obj_e;
	var keyCodeTab   = "9";
	var keyCodeEnter = "13";
	var keyCodeEsc   = "27";

	if (e)
	{
		obj_e = e;
	}
	else
	{
		obj_e = event;
	}

	if ((obj_e.keyCode == keyCodeEnter || obj_e.keyCode == keyCodeTab) && this.value != this.initValue)
	{
		this.changed = true;
		this.onchange(this);
	}
	else if (obj_e.keyCode == keyCodeEsc)
	{
		this.value = this.initValue;
	}
	else
	{
		this.changed = false;
	}
}

function input_onfocus(obj_input, str_default)
{
	if (obj_input.value == str_default)
		obj_input.value = '';
	else
		obj_input.select();

	return true;
}

function input_onblur(obj_input, str_default)
{
	if (obj_input.value == '')
		obj_input.value = str_default;
	return true;
}


var product_int_prev_id = '';
var product_obj_large = false;
function product_swapOver(str_id)
{
	try
	{
		if (!product_obj_large)
		{
			product_obj_large = product_getLarge();
		}
		product_obj_large.src = strScriptPath + 'upload/images_product/large_'+ str_id +'.jpg';
	}
	catch (e)
	{
	}
	return false;
}

function product_swapOut(str_id)
{
	try
	{
		if (!product_obj_large)
		{
			product_obj_large = product_getLarge();
		}
		product_obj_large.src = strScriptPath + 'upload/images_product/large_'+ product_int_prev_id +'.jpg';
	}
	catch (e)
	{
	}
	return false;
}

function product_swapClick(str_id)
{
	try
	{
		if (!product_obj_large)
		{
			product_obj_large = product_getLarge();
		}
		product_int_prev_id = str_id;
		product_obj_large.src = strScriptPath + 'upload/images_product/large_'+ str_id +'.jpg';
	}
	catch (e)
	{
	}
	return false;
}

function product_getLarge()
{
	product_obj_large = document.getElementById('product_large');
	return product_obj_large;
}