function do_submit(form_position, element_positions)
{
	if (!form_position) {
		var form_position = 0;
	}

	if (!element_positions) {
		var element_positions = new Array();
	}

	var form_elements = document.forms[form_position].elements.length;

	for (i = 0; i < form_elements; i++) {
		var current_value = document.forms[form_position].elements[i].value;
		if ((current_value.match(/^s+$/) || current_value == '') && in_array(i, element_positions) == true) {
			alert('Nincs minden szükséges adat megadva!');
			return false;
		}
	}

	function in_array(needle, haystack) {
		for (j = 0; j < haystack.length; ++j) {
			if (haystack[j] == needle) {
				return true;
			}
		}
		return false;
	}

	document.forms[form_position].submit();
	return false;
}

function do_enter_submit(event, form_position, element_positions)
{
	if (event.keyCode == 13) {
		return do_submit(form_position, element_positions);
	}
}

function do_confirm(text)
{
	return confirm(text);
}

function set_defaults()
{
	if (!document.getElementsByTagName) {
		return;
	}

	var anchors = document.getElementsByTagName('a');
	for (var i = 0; i < anchors.length; i++) {
		var anchor = anchors[i];
		anchor.href = anchor.href.replace('[kukac]', '@');
    		anchor.href = anchor.href.replace('[pont]', '.');
		if (anchor.getAttribute('href') && anchor.getAttribute('rel') == 'external') {
			anchor.target = "_blank";
		}
	}
}

function init_info_box() 
{
	var infobox = document.getElementById('information');
	if(infobox) {
		var height_of_screen = document.documentElement.clientHeight > 0?document.documentElement.clientHeight:document.body.clientHeight;
		var width_of_screen = document.documentElement.clientWidth ;
		infobox.style.position = 'absolute';
		var info_box_y = height_of_screen/2;
		var info_box_x = width_of_screen/2;
		
		info_box_x -= 357/2;
		info_box_y += 95/2;

		infobox.style.left  = info_box_x + 'px';
		infobox.style.bottom   = info_box_y + 'px';
		if(!infobox.setAttribute('class', 'infobox')) {
			infobox.setAttribute('className', 'infobox');
		}
		t = setTimeout("hide_information()", 3000);
	}	
	
}

function init()
{
	set_defaults();
	init_info_box();
}

function qsearch_info(state)
{
	$('qsearch_info_bubble').style.display=state;
}


function hide_information() 
{
	var infobox = document.getElementById('information');
	if(!infobox.setAttribute('class', 'infobox_hidden')) {
		infobox.setAttribute('className', 'infobox_hidden');
	}
	
	clearTimeout(t);
	
}

function recount_cart(form_id, elements_position)
{
	//var amounts_form = document.getElementById(form_id);
	//var amounts = amounts_form.amounts;
	
	
		
	do_submit(form_id, elements_positions);
	return false;
}


function kosar_belerak(product_id) 
{
	
	amount_box = document.getElementById('amount_' + product_id);
	kosar_belerak_form = document.getElementById('kosar_belerak');
	if(!IsNum(amount_box.value)) {
		alert('Kérem számot adjon meg mennyiségnek!!');
		amount_box.value = 1;
		return false;
	}
	amount = amount_box.value;
	kosar_belerak_form.product_id.value = product_id;
	kosar_belerak_form.amount.value = amount;
	kosar_belerak_form.submit();
	
	return false;
}

 function IsNum(field) 
{
  if (field == '')
  {
  	return false;
  }
  theNum = parseInt(field);
  if (field != '' + theNum)
  {
  	return false;
  }
	return true;
}

 function IsNum_cart(key_code) 
{
  if (key_code < 55)
  {
  	return true;
  }
  
  field = String.fromCharCode(key_code);
  
  theNum = parseInt(field);
  if (field != '' + theNum)
  {
  	return false;
  }
	return true;
}

function increase(amount_box_id)
{
	
	amount_box = document.getElementById('amount_' + amount_box_id);
	amount =  parseInt(amount_box.value);
	amount_box.value = amount + 1;
	return false;

}

function decrease(amount_box_id)
{
	amount_box = document.getElementById('amount_' + amount_box_id);
	amount = parseInt(amount_box.value);
	amount_box.value = amount - 1;
	if(amount_box.value < 0) {
		amount_box.value = 0;
	}
	return false;
}

function change_scale(href, scale) 
{
	location.href = href +  '/' + scale;
}

function change_password()
{
	password = document.getElementById('login_pass');
	//password.setAttribute('type', 'password');
	password.value = ''; 
	password.focus();
}


function popup_window(admin_url) 
{
	window.open("/" + admin_url , "Adminisztracio", "menubar=no,location=no,resizable=no,scrollbars=yes,status=no,width=800,heigth=600");
	return false;
}

function createRequestObject() 
{
	var ro;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer")
	{
		ro = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		ro = new XMLHttpRequest();
	}
		
	return ro;
}

var http = createRequestObject();

function more_content(id) 
{
	http.open('get', 'set_step.php?id='+id);
	http.onreadystatechange = set_step;
	http.send(null);
	
	return false;
}

function set_step() 
{
	if(http.readyState == 4)
	{
		$('buy_steps_content').innerHTML=http.responseText;
	}
}

function change_step(which)
{
	if (act_step=='step_1')
	{
		$(act_step).innerHTML='<div class="step_grey"><a href="" title="Ajánlatkérés" id="step2"  onclick="return change_step(\'step_1\')"><span>1</span>Ajánlatkérés</a></div>';
	}
	
	if (act_step=='step_2')
	{
		$(act_step).innerHTML='<div class="step_grey"><a href="" title="Megrendelés" id="step2"  onclick="return change_step(\'step_2\')"><span>2</span>Megrendelés</a></div>';
	}
	
	if (act_step=='step_3')
	{
		$(act_step).innerHTML='<div class="step_grey"><a href="" title="Rendelés nyomonkövetése" id="step3"  onclick="return change_step(\'step_3\')"><span>3</span>Rendelés nyomonkövetése</a></div>';
	}
	
	act_step=which;
	
	if (which=='step_1')
	{
		$(which).innerHTML='<div class="step_white" id="step_white_step1"><span>1</span>Ajánlatkérés</div>';
	}
	
	if (which=='step_2')
	{
		$(which).innerHTML='<div class="step_white" id="step_white_step1"><span>2</span>Megrendelés</div>';
	}
	
	if (which=='step_3')
	{
		$(which).innerHTML='<div class="step_white" id="step_white_step3"><span>3</span>Rendelés nyomonkövetése</div>';
	}
	
	
	more_content(which) ;
	
	return false;
}

function welcome_popup()
{
	var anchor = document.createElement("a");
	anchor.href = 'images/ia_ad.jpg';
	popup_image(anchor, false, true);
}

var t;
var act_step='step_1';

window.onload = init;

