/*
	This file is part of the hatatitla.biz
	Copyright (C) 2002-2010 Hatatitla
	All Rights Reserved

±¿¼æ¶³ó
*/

function ht_chk_all(ids)
{
	var a = ids.split(";");
	for (var i=0; i<a.length; ++i)
	{
		var o = mwl_obj(a[i]);
		if (o) o.checked = true;
	}
}

function ht_uchk_all(ids)
{
	var a = ids.split(";");
	for (var i=0; i<a.length; ++i)
	{
		var o = mwl_obj(a[i]);
		if (o) o.checked = false;
	}
}

function show_chat()
{
	window.open("chat.php", "chat_window", "toolbar=no,scrollbars=no,resizable=no,width=620,height=420");
}

function open_email_office()
{
	location.href = "mai"+"lt"+"o:b"+"iur"+"o@"+"hatati"+"tla.b"+"iz";
}

function open_email_marketing()
{
	location.href = "mai"+"lt"+"o:ma"+"rke"+"t"+"ing"+"@"+"hatati"+"tla.b"+"iz";
}

/* Common 2 */
function ht_smh_put(id, s1, s2)
{
	var o = mwl_obj(id);
	o.value += s1 + s2;
	o.focus();
}

function ht_smh_put_itemize(id)
{
	var o = mwl_obj(id);
	o.value += "\n* ";
	o.focus();
}

var ht_smh_enabled = 0;
var ht_smh_interval;
var ht_smh_limit = 0;

function ht_smh_chk_ok(id, limit)
{
	ht_smh_enabled = 1;
	ht_smh_limit = limit;
	ht_smh_interval = setInterval('ht_smh_check_form(\'' + id + '\');', 300);
}

function ht_smh_chk_off()
{
	ht_smh_enabled = 0;
	ht_smh_limit = 0;
	clearInterval(ht_smh_interval);
}

function ht_smh_check_form(id)
{
	var st = mwl_obj('smart_status_' + id);
	var rest = ht_smh_limit - mwl_obj(id).value.length;
	if (rest>=0)
		st.innerHTML = rest;
	else
		st.innerHTML = "0 (przekroczono limit)";
}

/* Common 3*/
function ht_submit(formId, ctrlId, par)
{
	var f = document.forms[formId];
	var ctrl = f['ht_ctrl'];
	if (ctrl!=null)
		ctrl.value = ctrlId;
	var p = f['ht_params'];
	if (p!=null)
		p.value = par;
	f.submit();
}

function ht_submit_conf(formId, ctrlId, par, quest)
{
	if (confirm(quest))
		ht_submit(formId, ctrlId, par);
}

function show_popup_window(sURL, width, height)
{
	var s = "toolbar=no,location=no,scrollbars=yes,resizable=yes,width="+width+",height="+height;
	window.open(sURL, "_blank", s);
}

/* Common 4 */
function shop_prod_mouse(o, ov)
{
	o.style.borderColor = ov ? '#80C0FF' : '#C0C0C0';
	o.style.borderStyle = ov ? 'solid' : 'dotted';
	o.style.backgroundColor = ov ? '#F8F8F8' : '#F0F0F0';
}

function shop_prod_show(id)
{
	window.location.href = 'shop-more.php?id=' + id;
}

function shop_prod_show2(id, category)
{
	window.location.href = 'shop-more.php?id=' + id + '&category=' + category;
}

function ht_rep_chk_all(prefix, ids)
{
	var a = ids.split(';');
	if (a.length > 0)
	{
		var found0 = false;
		for (var i=0; i<a.length; ++i)
		{
			var o = mwl_obj(prefix + a[i]);
			if (o)
			{
				if (false == o.checked)
					found0 = true;
			}
		}
		var newState = true;
		if (false == found0)
			newState = false;
		for (var i=0; i<a.length; ++i)
		{
			var o = mwl_obj(prefix + a[i]);
			if (o)
				o.checked = newState;
		}
	}
}

function home_seg_mouse(o, color)
{
	o.style.backgroundColor = color;
}

function home_seg_mouse_out(o)
{
	o.style.backgroundColor = '';
}

function em35_dec3(enc)
{
	var em = '';
	for (var i=0; i<enc.length; i += 2)
	{
		var c = enc.substr(i+1, 1) + enc.substr(i, 1);
		var nCode = parseInt(c, 16);
		nCode = (nCode - 7) % 0x100;
		em = em + String.fromCharCode(nCode);
	}
	return em;
}

function em35_draw3(container, enc)
{
	var o = mwl_obj(container);
	if (null != o)
		o.innerHTML = em35_dec3(enc);
}

function em35_link3(enc, subject)
{
	var s = 'm'+'ai'+'lt'+'o'+':'+em35_dec3(enc);
	if ('' != subject)
		s += '?su'+'bj'+'ect='+em35_dec3(subject);
	parent.location = s;
}

function ht_set_form_ctrl_value(formName, id, value) {
	var f = document.forms[formName];
	var ctrl = f[id];
	if (ctrl != null)
		ctrl.value = value;
}

function ht_get_form_ctrl_value(formName, id) {
	var f = document.forms[formName];
	var ctrl = f[id];
	if (ctrl != null)
		return ctrl.value;
	else
		return null;
}

function ht_vo_ref_selector_clear_obj_cf(field, previewId, clearBtn) {
	if (confirm('Czy chcesz usunac powiazanie?')) {
		$('#'+field).val('0');
		$('#'+previewId).html('(brak)');
		$('#'+clearBtn).empty();
		$('#'+clearBtn).removeClass('a59');
		$('#'+clearBtn).addClass('a60');
	}
}

var _home_splash_img_interval = 0;

function home_splash_img_set(index) {
	home_splash_img_stop();

	var imgId = 'home_splash_' + index;
	$('#home_splash_img > div').removeClass('a104i1');
	$('#home_splash_img > div').addClass('a104i0');
	$('#' + imgId).removeClass('a104i0');
	$('#' + imgId).addClass('a104i1');
	
	var navId = 'home_splash_n_' + index;
	$('#home_splash_n > td').removeClass('a104n1');
	$('#home_splash_n > td').addClass('a104n0');
	$('#' + navId).removeClass('a104n0');
	$('#' + navId).addClass('a104n1');
	
	ht_set_form_ctrl_value('main', 'home_splash_cur', ''+index);
	home_splash_img_run();
}

function home_splash_img_stop() {
	if (0 != _home_splash_img_interval)
		clearInterval(_home_splash_img_interval);
}

function home_splash_img_run() {
	home_splash_img_stop();
	_home_splash_img_interval = window.setInterval('home_splash_img_next()', 5000);
}

function home_splash_img_next() {
	var curIndex = ht_get_form_ctrl_value('main', 'home_splash_cur');
	if (curIndex != null) {
		var index = parseInt(curIndex) + 1;
		if (home_splash_img_exists(index))
			home_splash_img_set(index);
		else if (home_splash_img_exists(0))
			home_splash_img_set(0);
	}
}

function home_splash_img_exists(index) {
	var imgId = 'home_splash_' + index;
	if (mwl_obj(imgId))
		return 1;
	else
		return 0;
}

function label_menu_sel(id, key) {
	var labelId = id + '_label';
	var itemId = id + '_item_' + key;
	var itemName = $('#'+itemId+'>a').html();
	$('#'+labelId).html(itemName);
	$('#'+id).val(key);
}
