function openVerMenu(mid){
	if ($('vsubmenu_'+mid).style.display=='none'){
		$('vsubmenu_'+mid).style.display='';
		saveOpenedMenu(mid,1);
	}else{
		$('vsubmenu_'+mid).style.display='none';
		saveOpenedMenu(mid,0);
	}
}
function saveOpenedMenu(mid,stat){
	var url = saveMenuScript+'?mid='+mid+'&stat='+stat+'';

	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	    void(0);
	  }
	});
}

function showDiv(div_id) {
	if (document.getElementById(div_id).style.display == 'none') {
	document.getElementById(div_id).style.display = 'block';
	} else {
		document.getElementById(div_id).style.display='none';
	}
}





function take_price(id, check_id, popup_id, count_id, group_id, zx){ //------- Get price from element and count price in group_price
	if(document.getElementById(count_id) == null){
		count=1;
	}else{
		count=parseFloat(document.getElementById(count_id).value);
	}
	if(zx){
		var all_price_tmp=parseFloat(document.getElementById('group_price_tmp_'+group_id).value);;
		var all_price=0;
	}else{
		var all_price_tmp=parseFloat(document.getElementById('group_price_tmp_'+group_id).value);
		var all_price=parseFloat(document.getElementById('group_price_'+group_id).value);
	}

	if(id != '' && check_id != '' && popup_id != ''){
		if(document.getElementById(check_id).type == 'checkbox'){
			if(document.getElementById(check_id).checked == true){
				price=parseFloat(document.getElementById(id).innerHTML);
				all_price=all_price+price;
			}
		}else if(document.getElementById(check_id).type == 'radio'){
			if(document.getElementById(check_id).checked == true){
				backup=document.getElementById(popup_id).innerHTML;
				price=parseFloat(document.getElementById(id).innerHTML);
				all_price=all_price+price;
	            document.getElementById(popup_id).innerHTML=id;
			}
		}else if(document.getElementById(check_id).tagName == 'OPTION'){
			backup=document.getElementById(popup_id).innerHTML;
			price=parseFloat(document.getElementById(check_id).value);
			//alert(price);
			all_price=all_price+price;
			document.getElementById(popup_id).innerHTML=price;
		}

	}
	document.getElementById('group_price_org_'+group_id).value=all_price;
	document.getElementById('group_price_'+group_id).value=all_price*count;
	document.getElementById('group_price_org_txt_'+group_id).innerHTML=all_price*count;
	count_all_price();
	//document.getElementById('all_price_orig').innerHTML=all_price;
	//document.getElementById('all_price').innerHTML=all_price*count;
	return;
}
// FOR GROUP

function take_price_gr(id, check_id, popup_id, count_id, group_id, zx){ //------- Get price from element and count price in group_price
	if(document.getElementById(count_id) == null){
		count=1;
	}else{
		count=parseFloat(document.getElementById(count_id).value);
	}
	if(zx){
		var all_price_tmp=parseFloat(document.getElementById('group_price_tmp_'+group_id).value);;
		var all_price=0;
	}else{
		var all_price_tmp=parseFloat(document.getElementById('group_price_tmp_'+group_id).value);
		var all_price=parseFloat(document.getElementById('group_price_'+group_id).value);
	}

	if(id != '' && check_id != '' && popup_id != ''){
		if(document.getElementById(check_id).type == 'checkbox'){
			if(document.getElementById(check_id).checked == true){
				price=parseFloat(document.getElementById(id).innerHTML);
				all_price=all_price+price;
			}else{
				price=parseFloat(document.getElementById(id).innerHTML);
				all_price=all_price-price;
			}
		}else if(document.getElementById(check_id).type == 'radio'){
			if(document.getElementById(check_id).checked == true){
				backup=document.getElementById(popup_id).innerHTML;
				if(backup != ''){
					price=parseFloat(document.getElementById(backup).innerHTML);
					all_price=all_price-price;
				}
				price=parseFloat(document.getElementById(id).innerHTML);
				all_price=all_price+price;
	            document.getElementById(popup_id).innerHTML=id;
			}
		}else if(document.getElementById(check_id).tagName == 'OPTION'){
			backup=document.getElementById(popup_id).innerHTML;
			if(backup != ''){
				price=parseFloat(document.getElementById(popup_id).innerHTML);
				all_price=all_price-price;
			}
			price=parseFloat(document.getElementById(check_id).value);
			//alert(price);
			all_price=all_price+price;
			document.getElementById(popup_id).innerHTML=price;
		}

	}
	document.getElementById('group_price_org_'+group_id).value=all_price;
	document.getElementById('group_price_'+group_id).value=all_price*count;
	document.getElementById('group_price_org_txt_'+group_id).innerHTML=all_price*count;
	count_all_price();
	//document.getElementById('all_price_orig').innerHTML=all_price;
	//document.getElementById('all_price').innerHTML=all_price*count;
	return;
}
// FOR ELEMENTS
function take_price_el(id, check_id, popup_id, count_id, group_id, sub_id, el_id, edit){ //------- Get price from element and count price in group_price
	if(document.getElementById(count_id) == null){
		count=1;
	}else{
		count=parseFloat(document.getElementById(count_id).value);
	}
	var all_price=parseFloat(document.getElementById('el_orig_'+sub_id+'_'+el_id).innerHTML);
	if(id != '' && check_id != '' && popup_id != ''){
		if(document.getElementById(check_id).type == 'checkbox'){
			if(document.getElementById(check_id).checked == true){
				price=parseFloat(document.getElementById(id).innerHTML);
				all_price=all_price+price;
			}else{
				price=parseFloat(document.getElementById(id).innerHTML);
				all_price=all_price-price;
			}
		}else if(document.getElementById(check_id).type == 'radio'){
			if(document.getElementById(check_id).checked == true){
				backup=document.getElementById(popup_id).innerHTML;
				if(backup != ''){
					price=parseFloat(document.getElementById(backup).innerHTML);
					all_price=all_price-price;
				}
				price=parseFloat(document.getElementById(id).innerHTML);
				all_price=all_price+price;
	            document.getElementById(popup_id).innerHTML=id;
			}
		}else if(document.getElementById(check_id).tagName == 'OPTION'){
			backup=document.getElementById(popup_id).innerHTML;
			if(backup != ''){
				price=parseFloat(document.getElementById(popup_id).innerHTML);
				all_price=all_price-price;
			}
			price=parseFloat(document.getElementById(check_id).value);
			//alert(price);
			all_price=all_price+price;
			document.getElementById(popup_id).innerHTML=roundNumber(price,2);
		}
	}
	document.getElementById('el_orig_'+sub_id+'_'+el_id).innerHTML=roundNumber(all_price,2);
	document.getElementById('el_'+sub_id+'_'+el_id).innerHTML=roundNumber(all_price*count,2);
	//document.getElementById('group_price_org_txt_'+group_id).innerHTML=all_price*count;
	//take_price('el_'+sub_id+'_'+el_id, 'check_'+sub_id+'_'+el_id, 'popup_'+sub_id, 'count_'+group_id, group_id);
	if(edit == false)	count_all_price();
	//document.getElementById('all_price_orig').innerHTML=all_price;
	//document.getElementById('all_price').innerHTML=all_price*count;
	return;
}
function count_all_price(){ //--------- Count Group Price in one price
	if(document.getElementById('constructor') && !non_count_price){
		document.getElementById('all_price').innerHTML='0';
		var piegade=parseFloat(document.getElementById('all_price_befor_orig').innerHTML)/100;
		price=0;
		for (var i=0;i<document.forms[1].elements.length;i++)
		{
			var p=document.forms[1].elements[i];
			if (p.name == 'group_price_org[]')
			{
				value=parseFloat(p.value);
				if(value > 0){
					//alert(p.name);
					price=price+value;
				}
			}
		}
		//alert(price);
		document.getElementById('all_price').innerHTML = roundNumber(price,2);
		document.getElementById('all_price_befor').innerHTML = roundNumber(price*piegade,2);
	}else if(document.getElementById('all_price_befor_orig')){
		var piegade=parseFloat(document.getElementById('all_price_befor_orig').innerHTML)/100;
		price = document.getElementById('all_price').innerHTML;
		document.getElementById('all_price_befor').innerHTML = roundNumber(price*piegade,2);
	}	
	return;
}
function change_count(value, x, y){
	count_var=parseFloat(document.getElementById(x).value);
	if(value == '+'){
		count_var=count_var+1;
	}else{
		if(count_var > 0){
			count_var=count_var-1;
		}
	}
    document.getElementById(x).value=count_var;
	take_price('', '', '', x, y);
}
function change_count_el(value, x, y, sub_id, el_id){
	count_var=parseFloat(document.getElementById(x).value);
	if(value == '+'){
		count_var=count_var+1;
	}else{
		if(count_var > 0){
			count_var=count_var-1;
		}
	}
    document.getElementById(x).value=count_var;
	take_price_el('', '', '', x, y, sub_id, el_id);
}
function count_price() { // ---------- Count price in Page Load
	if(document.getElementById('constructor') && !non_count_price){
		var zx;
		for (var i=0;i<document.forms[1].elements.length;i++)
		{
			var e=document.forms[1].elements[i];

			if (((e.type=='checkbox' || e.type=='radio') && e.checked == true) || e.name == '')
			{
				tmp=e.id.split('_');
				h_id=document.getElementById('hide_'+tmp[1]+'_'+tmp[2]).value;
				tmp=h_id.split('_');
				if(zx == tmp[0]){
					zxx=0;
				}else{
					zxx=1;
					zx = tmp[0];
				}
				take_price('el_'+tmp[1]+'_'+tmp[2], 'check_'+tmp[1]+'_'+tmp[2], 'popup_'+tmp[1], 'count_'+tmp[0], tmp[0], zxx);
			}else if(e.tagName == 'SELECT'){ //------ pri zagruzki stranici nahodim proce dlja option
				for (var x=0; x<e.options.length; x++) {
				  if (e.options[x].selected == true) {
				  	opt=e.options[x].id;
				  }
				}
				tmp=opt.split('_');
				h_id=document.getElementById('hide_'+tmp[1]+'_'+tmp[2]).value;
				tmp=h_id.split('_');
				if(zx == tmp[0]){
					zxx=0;
				}else{
					zxx=1;
					zx = tmp[0];
				}
				take_price('el_'+tmp[1]+'_'+tmp[2], 'check_'+tmp[1]+'_'+tmp[2], 'popup_'+tmp[1], 'count_'+tmp[0], tmp[0], zxx);
			}
		}
	}
	count_all_price();
	return;
}

function take_selected(a, b, c, divtype) {
	if(divtype == 'option'){
		popup=document.getElementById('slave_el_popup_'+a+'_'+b+'_'+c);
		popup.innerHTML = '|'+popup.innerHTML;
		popup2=document.getElementById('slave_el_popup2_'+a+'_'+b+'_'+c);
		popup2.innerHTML='';
	}else{
		collection=document.getElementById('div_element_'+c+'_'+a).getElementsByTagName('input');
		popup=document.getElementById('slave_el_popup_'+a+'_'+b+'_'+c);
		popup2=document.getElementById('slave_el_popup2_'+a+'_'+b+'_'+c);
		main=document.getElementById('mainel_'+a+'_'+b+'_'+c);

		popup.innerHTML='';
		popup2.innerHTML='';
		for (var x=0; x<collection.length; x++) {
	        if (collection[x].type.toUpperCase()=='RADIO' && collection[x].checked == true) {
	            tpl=collection[x].id.split('_');
	            slave=document.getElementById('slave_el_'+tpl[1]+'_'+tpl[2]);
				slave2=document.getElementById('el_'+tpl[1]+'_'+tpl[2]);
				popup.innerHTML += '|'+slave.innerHTML;
				popup2.innerHTML += '|'+slave2.innerHTML;
	        }else if (collection[x].type.toUpperCase()=='CHECKBOX' && collection[x].checked == true) {
	            tpl=collection[x].id.split('_');
	            slave=document.getElementById('slave_el_'+tpl[1]+'_'+tpl[2]);
				slave2=document.getElementById('el_'+tpl[1]+'_'+tpl[2]);
				popup.innerHTML += '|'+slave.innerHTML;
				popup2.innerHTML += '|'+slave2.innerHTML;
	        }
	    }
	}
	//tmp=popup.innerHTML.split('##');
    //tmp.splice(0,1);
	//alert(temp);
	//loop(popup, main);
	ss('mainel_'+a+'_'+b+'_'+c, popup.innerHTML, popup2.innerHTML, 0, divtype)
	return ;
}
/*function loop(popup, main){
	tmp=popup.innerHTML.split('|');
	tmp.splice(0,1);
	for (var i = 0; i < tmp.length; ++i) {
	   	var item = tmp[i];
	  	setTimeout('main.innerHTML=tmp['+i+']',1000*i);
	}
	setTimeout('loop(popup, main)',1000*i);
	return;
}
*/


function ss(ss_id, str_id, str_id2, cur_el, divtype, self_called) {
	//console.info('ss_id:'+ss_id+' str_id:'+str_id+' cur_el:'+cur_el);
	if (hand_action[ss_id] == 'start' && self_called != true) {
		clearTimeout(hand[ss_id]);
		hand_action[ss_id] = 'stop';
		hand[ss_id] = setTimeout('ss("'+ss_id+'", "'+str_id+'", "'+str_id2+'", "0", "'+divtype+'");', 1000);
	}
	else {
		hand_action[ss_id] = 'start';
		var tmp = str_id.split('|');
		var tmp2 = str_id2.split('|');
		tmp.splice(0,1);
		tmp2.splice(0,1);
		//alert(tmp);
		if(tmp != ''){
			if(divtype == 'option'){
				tmp[cur_el] = tmp[cur_el].split('_');
				document.getElementById(ss_id).innerHTML = ''+tmp[cur_el][0]+'<div><b>'+tmp[cur_el][1]+'</b></div>';
			}else if(divtype == 'list'){
				document.getElementById(ss_id).innerHTML = ''+tmp[cur_el]+'<div><b>'+tmp2[cur_el]+' LVL</b></div>';
			}else{
				document.getElementById(ss_id).innerHTML = '<br/><a href="javascript:flipWindow2(true, '+val_link+tmp[cur_el]+'.jpg\');"><img src="'+val_link+tmp[cur_el]+'_lib.jpg" alt=""/></a><div>'+tmp2[cur_el]+' LVL</div>';
			}
		}else{
			document.getElementById(ss_id).innerHTML = '<br/><div style="border: solid 0px red; display: block; height: 95px; text-decoration: underline;">'+non_items+'</div>';
		}
		if (cur_el < tmp.length-1)
			hand[ss_id] = setTimeout('ss("'+ss_id+'", "'+str_id+'", "'+str_id2+'", "'+(parseInt(cur_el)+1)+'", "'+divtype+'", true);', 1000);
		else
			hand[ss_id] = setTimeout('ss("'+ss_id+'", "'+str_id+'", "'+str_id2+'", "0", "'+divtype+'", true);', 1000);

	}
}









function take_option_price(sel_id){
	e=document.getElementById(sel_id)
	for (var x=0; x<e.options.length; x++) {
	  if (e.options[x].selected == true) {
	  	opt=e.options[x].value;
	  	//alert(opt);
	  }
	}
	tmp=opt.split('_');
	take_price_gr('el_'+tmp[2]+'_'+tmp[3], 'check_'+tmp[2]+'_'+tmp[3], 'popup_'+tmp[2], 'count_'+tmp[1], tmp[1]);
}
function count_basket(){
	document.getElementById('shopping_cart_items').innerHTML=items;
}

// ------------------ BASKET FUNCTION ---------------


function count_b_price(){
	if(document.forms[1]){
		if(document.forms[1].name == 'basket'){
			var myform=document.forms[1];
			var price = 0;
			var price_befor = 0;
			for (var i=0;i<myform.elements.length;i++)
			{
				var e=myform.elements[i];
				if (e.type == 'text'){
					var tmp=e.name.split('_');
					price_tmp=parseFloat(document.getElementById('b_price_'+tmp[1]).innerHTML);
					price_befor_tmp=parseFloat(document.getElementById('b_price_befor_'+tmp[1]).innerHTML);
					price=price+price_tmp;
					price_befor=price_befor+price_befor_tmp;
				}
			}
			document.getElementById('kop_price').innerHTML=roundNumber(price,2);
			document.getElementById('kop_price_befor').innerHTML=roundNumber(price_befor,2);
			document.getElementById('kop_price2').innerHTML=roundNumber(price,2);
			document.getElementById('kop_price2_befor').innerHTML=roundNumber(price_befor,2);
		}
	}
	return true;
}


function b_count(id){
	var b_count=parseFloat(document.getElementById('b_count_'+id).value);
	var price=parseFloat(document.getElementById('b_price_orig_'+id).innerHTML);
	var price_befor=parseFloat(document.getElementById('b_price_befor_orig_'+id).innerHTML)/100;
	price=b_count * price;
	price_befor=price * price_befor;
	document.getElementById('b_price_'+id).innerHTML=roundNumber(price,2);
	document.getElementById('b_price_befor_'+id).innerHTML=roundNumber(price_befor,2);
	document.getElementById('b_price_'+id+'_2').innerHTML=roundNumber(price,2);
	document.getElementById('b_price_befor_'+id+'_2').innerHTML=roundNumber(price_befor,2);
	document.getElementById('b_count_'+id+'_2').innerHTML=b_count;
	document.getElementsByName('b_counter_'+id)[0].value=b_count;
	//alert(document.getElementsByName('b_counter_'+id)[0].value);
	count_b_price();
	return true;
}
// -------- FIND element position -------------- //
function getElementTop(Elem) {
	return($(Elem).offsetTop)
}
function getElementLeft(Elem) {
	return($(Elem).offsetLeft);
}
// -------- END FIND element position -------------- //

function aj(grid,divload,sub) {

     var req = null;
    if (window.XMLHttpRequest) req = new XMLHttpRequest();
    else if (window.ActiveXObject) {
      try {
        req = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      }
    }

    req.onreadystatechange = function() {
	  document.getElementById(sub).style.display = 'block';
	  document.getElementById(sub).innerHTML = '<div align="center"><img src="/img/menu/ajax-loader.gif"></div>';
      if (req.readyState == 4) {
        //if (req.status == 200) {
        	document.getElementById(sub).innerHTML = req.responseText;
        /*}else{
        	//document.getElementById(sub).innerHTML = "Error: returned status code " + req.status + " " + req.statusText;
        } */
      }
    }

    req.open("GET", "./?grid="+grid, true);
    req.send(null);

}


function showDivLizingTypeWarning(type,id){
	if(type == 'show')
		{
		document.getElementById(id).style.display = 'block';
	    
		}
	else
	
		document.getElementById(id).style.display = 'none';
	return true;
}


jQuery(function($) {
    
	$(document).ready(function(){
	
		$('.mm_l').mouseenter(function() {
		  $('.submenu', this).css('display','block');
		  $(this).parent().parent().addClass('mm_bg');
		  $(this).parent().addClass('mmr_bg');
		  $(this).addClass('mml_bg');
		});
		
		$('.mm_l').mouseleave(function() {
		  $('.submenu', this).css('display','none');
		  $(this).parent().parent().removeClass('mm_bg');
		  $(this).parent().removeClass('mmr_bg');
		  $(this).removeClass('mml_bg');
		});
		
	    $('#order_txt2').css('display','none');
		$('a.thickbox').fancybox({ 'zoomSpeedIn': 300, 'zoomSpeedOut': 300, 'overlayShow': true }); 	
	});
});

function sub(obj){
	var out=jQuery('#outer').offset().left;
	var left=jQuery(obj).offset().left-out;
	var right=jQuery(window).width()-jQuery(obj).offset().left-jQuery('#outer').offset().left-jQuery(obj).width()-25;
	var center=right-100+(jQuery(obj).width()/2);
	//if(left+195>970) jQuery(obj+' .submenu').css("right",right); 
	if(left+195>970){
		jQuery(obj+' .submenu').css("right",right); 
	}
	if(left+340>970){
		jQuery(obj+' .submenu .sub2').css("left",-185); 
	}
//	if((right+195>970) && (left+195>970)) jQuery(obj+' .submenu').css("right",center); 
	
}

