
function openVerMenu(mid){
	if ($('vsubmenu_'+mid).style.display=='none'){
		$('vsubmenu_'+mid).style.display='';
		$('img_'+mid).src = img_link+"left_menu_open.gif";
		saveOpenedMenu(mid,1);
	}else{
		$('vsubmenu_'+mid).style.display='none';
		$('img_'+mid).src = img_link+"left_menu_close.gif";
		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 take_price(id, check_id, popup_id, count_id, group_id, zx){ //------- Get price from element and count price in group_price
	tmp=check_id.split('_');
	var sub_price=($('yyy_'+tmp[1]));
	if($(count_id) == null){
		count=1;
	}else{
		count=parseFloat($(count_id).value);
	}
	if(zx){
		var all_price_tmp=parseFloat($('group_price_tmp_'+group_id).value);
		var all_price=0;
	}else{
		var all_price_tmp=parseFloat($('group_price_tmp_'+group_id).value);
		var all_price=parseFloat($('group_price_'+group_id).value);
	}
	if(id != '' && check_id != '' && popup_id != ''){
		if($(check_id).type == 'checkbox'){
			if($(check_id).checked == true){
				price=parseFloat($(id).innerHTML);
				all_price+=price;
				//alert(price);
			}
		}else if($(check_id).type == 'radio'){
			if($(check_id).checked == true){
				backup=$(popup_id).innerHTML;
				price=parseFloat($(id).innerHTML);
				all_price=all_price+price;
	            $(popup_id).innerHTML=id;
			}
		}else if($(check_id).tagName == 'OPTION'){
			backup=$(popup_id).innerHTML;
			price=parseFloat($(check_id).value);
			all_price=all_price+price;
			$(popup_id).innerHTML=price;
		}

	}
	sub_price.innerHTML=parseFloat(sub_price.innerHTML)+price;
	$('group_price_org_'+group_id).value=all_price;
	$('group_price_'+group_id).value=all_price*count;
	$('group_price_org_txt_'+group_id).innerHTML=all_price*count;
	//count_all_price();
	//alert($('group_price_org_txt_'+group_id).innerHTML);
	//$('all_price_orig').innerHTML=all_price;
	//$('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($(count_id) == null){
		count=1;
	}else{
		count=parseFloat($(count_id).value);
	}
	if(zx){
		var all_price_tmp=parseFloat($('group_price_tmp_'+group_id).value);;
		var all_price=0;
	}else{
		var all_price_tmp=parseFloat($('group_price_tmp_'+group_id).value);
		var all_price=parseFloat($('group_price_'+group_id).value);
	}

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

	}
	$('group_price_org_'+group_id).value=all_price;
	$('group_price_'+group_id).value=all_price*count;
	$('group_price_org_txt_'+group_id).innerHTML=all_price*count;
	count_all_price();
	//$('all_price_orig').innerHTML=all_price;
	//$('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($(count_id) == null){
		count=1;
	}else{
		count=parseFloat($(count_id).value);
	}
	var all_price=parseFloat($('el_orig_'+sub_id+'_'+el_id).innerHTML);
	if(id != '' && check_id != '' && popup_id != ''){
		if($(check_id).type == 'checkbox'){
			if($(check_id).checked == true){
				price=parseFloat($(id).innerHTML);
				all_price=all_price+price;
			}else{
				price=parseFloat($(id).innerHTML);
				all_price=all_price-price;
			}
		}else if($(check_id).type == 'radio'){
			if($(check_id).checked == true){
				backup=$(popup_id).innerHTML;
				if(backup != ''){
					price=parseFloat($(backup).innerHTML);
					all_price=all_price-price;
				}
				price=parseFloat($(id).innerHTML);
				all_price=all_price+price;
	            $(popup_id).innerHTML=id;
			}
		}else if($(check_id).tagName == 'OPTION'){
			backup=$(popup_id).innerHTML;
			if(backup != ''){
				price=parseFloat($(popup_id).innerHTML);
				all_price=all_price-price;
			}
			price=parseFloat($(check_id).value);
			//alert(price);
			all_price=all_price+price;
			$(popup_id).innerHTML=roundNumber(price,2);
		}
	}
	//alert(all_price);
	$('el_orig_'+sub_id+'_'+el_id).innerHTML=roundNumber(all_price,2);
	$('el_'+sub_id+'_'+el_id).innerHTML=roundNumber(all_price*count,2);
	//$('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();
	//$('all_price_orig').innerHTML=all_price;
	//$('all_price').innerHTML=all_price*count;
	return;
}
function count_all_price(){ //--------- Count Group Price in one price
	if($('constructor')){
		$('all_price').innerHTML='0';
		var piegade=parseFloat($('all_price_befor_orig').innerHTML)/100;
		var chiper=parseFloat($('price_chiper').innerHTML)/100;
		price=fixed_price;
		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.id);
					price=price+value;
				}
			}
		}
		//alert(price);
		chiper=chiper*price;
		chiper2=price+chiper;
		$('price_chiper_value2').innerHTML = roundNumber(chiper,2);
		$('price_chiper_value').innerHTML = roundNumber(chiper2,2);
		var less_div=$('price_less_div');
		var more_div=$('price_more_div');
		var items_title_div=$('items_title_div');
		var opentype_title=$('opentype_title_0');
		//if(roundNumber(price,2) == 0 && less_div.style.display == 'none'){
		if(roundNumber(price,2) == 0){
			less_div.style.display = 'block';
			more_div.style.display = 'none';
			if(items_title_div) items_title_div.className='mebeles_page_title2';
			if(opentype_title) opentype_title.className='mebeles_page_title2';
		//}else if(roundNumber(price,2) > 0 && more_div.style.display == 'none'){
		}else if(roundNumber(price,2) > 0){
			more_div.style.display = '';
			less_div.style.display = 'none';
			if(items_title_div) items_title_div.className='mebeles_page_title';
			if(opentype_title) opentype_title.className='subgroup_title';
		}
		$('all_price').innerHTML = roundNumber(price,2);
		$('all_price_befor').innerHTML = roundNumber(price*piegade,2);

		/*x=document.getElementsByClassName('yyy');
		for(i=0;i<x.length;i++){
			if(parseFloat(x[i].innerHTML) == 0){
				$(x[i].getAttribute("name")).innerHTML='<table cellspacing="0" cellspacing="0">'+
															'<tr>'+
																'<td width="5" height="19" style="background: url('+img_link+'change_left.gif) right center no-repeat;">'+
																	'&nbsp;'+
																'</td>'+
																'<td height="19" width="61" style="background: url('+img_link+'change_px.gif) right center repeat-x;">'+
																	'<div class="count_change">'+
																		'izveleties'+
																	'</div>'+
																'</td>'+
																'<td width="5" height="19" style="background: url('+img_link+'change_right.gif) left center no-repeat;">'+
																	'&nbsp;'+
																'</td>'+
															'</tr>'+
														'</table>';
			}
		}*/

	}
	return;
}
function change_count(value, x, y){
	count_var=parseFloat($(x).value);
	if(value == '+'){
		count_var=count_var+1;
	}else{
		if(count_var > 0){
			count_var=count_var-1;
		}
	}
    $(x).value=count_var;
	take_price('', '', '', x, y);
}
function change_count_el(value, x, y, sub_id, el_id){
	count_var=parseFloat($(x).value);
	if(value == '+'){
		if(count_var == 0){
			$('check_'+sub_id+'_'+el_id).checked = true;
			$(x).className = 'num_center_input2';
		}
		count_var=count_var+1;
	}else{
		if(count_var > 0){
			if(count_var == 1){
				$('check_'+sub_id+'_'+el_id).checked = false;
				$(x).className = 'num_center_input';
			}
			count_var=count_var-1;
		}
	}
    $(x).value=count_var;
	take_price_el('', '', '', x, y, sub_id, el_id);
	
	divsave(sub_id, 'open');
}
function divsave(sub_id, type){
	if(type == 'open'){
		for (k=0; d=document.getElementById('divsave_'+sub_id+'_'+k); k++) {
			if(d.style.display == 'none')
				document.getElementById('divsave2_'+sub_id+'_'+k).style.display = 'none';
				d.style.display = 'block';
		}
	}else{
		for (k=0; d=document.getElementById('divsave_'+sub_id+'_'+k); k++) {
			if(d.style.display != 'none')
				d.style.display = 'none';
				document.getElementById('divsave2_'+sub_id+'_'+k).style.display = 'block';
		}
	}
}
function change_count_basket_el(value, x){
	count_var=parseFloat($('b_count_'+x).innerHTML);
	if(value == '+'){
		count_var=count_var+1;
	}else{
		if(count_var > 0){
			count_var=count_var-1;
		}
	}
    $('b_count_'+x).innerHTML=count_var;
	$('b_count2_'+x).value=count_var;
	b_count(x);
}
function count_price() { // ---------- Count price in Page Load
	if($('constructor') && !non_count_price){
		var zx=0;
		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=$('hide_'+tmp[1]+'_'+tmp[2]).value;
				tmp=h_id.split('_');
				if(zx == tmp[0]){
					zxx=0;
				}else{
					zxx=1;
					//alert(zx);
					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=$('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);
			}
		}
		if(zx == 0){
			e=document.getElementsByName('group_price[]');
			for (var x=0; x<e.length; x++) {
			  e[x].value=0;
			}
			e=document.getElementsByName('group_price_org[]');
			for (var x=0; x<e.length; x++) {
			  e[x].value=0;
			}
		}
		count_all_price();
	}
	return;
}

function take_selected(a, b, c, divtype) {
	if(divtype == 'option'){
		popup=$('slave_el_popup_'+a+'_'+b+'_'+c);
		popup.innerHTML = '|'+popup.innerHTML;
		popup2=$('slave_el_popup2_'+a+'_'+b+'_'+c);
		popup2.innerHTML='';
	}else{
	
		collection=$('div_element_'+c+'_'+a).getElementsByTagName('input');
		popup=$('slave_el_popup_'+a+'_'+b+'_'+c);
		popup2=$('slave_el_popup2_'+a+'_'+b+'_'+c);
		popuptitle=$('slave_el_popuptitle_'+a+'_'+b+'_'+c);
		popupsubtitle=$('slave_el_popupsubtitle_'+a+'_'+b+'_'+c);
		popupcom=$('slave_el_popupcom_'+a+'_'+b+'_'+c);
		popupwidth=$('slave_el_popupwidth_'+a+'_'+b+'_'+c);
		popupheight=$('slave_el_popupheight_'+a+'_'+b+'_'+c);
		popupdepth=$('slave_el_popupdepth_'+a+'_'+b+'_'+c);
		popupcount=$('slave_el_popupcount_'+a+'_'+b+'_'+c);
		main=$('mainel_'+a+'_'+b+'_'+c);
		popup.innerHTML='';
		popup2.innerHTML='';
		popuptitle.innerHTML='';
		popupsubtitle.innerHTML='';
		popupcom.innerHTML='';
		popupwidth.innerHTML='';
		popupheight.innerHTML='';
		popupdepth.innerHTML='';
		popupcount.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=$('slave_el_'+tpl[1]+'_'+tpl[2]);
				slave2=$('el_'+tpl[1]+'_'+tpl[2]);
				slavetitle=$('eltitle_'+tpl[1]+'_'+tpl[2]);
				slavesubtitle=$('elsubtitle_'+tpl[1]+'_'+tpl[2]);
				slavecom=$('elcom_'+tpl[1]+'_'+tpl[2]);
				slavewidth=$('elwidth_'+tpl[1]+'_'+tpl[2]);
				slaveheight=$('elheight_'+tpl[1]+'_'+tpl[2]);
				slavedepth=$('eldepth_'+tpl[1]+'_'+tpl[2]);
				slavecount=$('elcount_'+tpl[1]+'_'+tpl[2]);
				popup.innerHTML += '|'+slave.innerHTML;
				popup2.innerHTML += '|'+slave2.innerHTML;
				popuptitle.innerHTML += '|'+slavetitle.innerHTML;
				popupsubtitle.innerHTML += '|'+slavesubtitle.innerHTML;
				popupcom.innerHTML += '|'+slavecom.innerHTML;
				popupwidth.innerHTML += '|'+slavewidth.innerHTML;
				popupheight.innerHTML += '|'+slaveheight.innerHTML;
				popupdepth.innerHTML += '|'+slavedepth.innerHTML;
				popupcount.innerHTML += '|'+slavecount.innerHTML;
	        }else if (collection[x].type.toUpperCase()=='CHECKBOX' && collection[x].checked == true) {
	            tpl=collection[x].id.split('_');
	            slave=$('slave_el_'+tpl[1]+'_'+tpl[2]);
				slave2=$('el_'+tpl[1]+'_'+tpl[2]);
				slavetitle=$('eltitle_'+tpl[1]+'_'+tpl[2]);
				slavesubtitle=$('elsubtitle_'+tpl[1]+'_'+tpl[2]);
				slavecom=$('elcom_'+tpl[1]+'_'+tpl[2]);
				slavewidth=$('elwidth_'+tpl[1]+'_'+tpl[2]);
				slaveheight=$('elheight_'+tpl[1]+'_'+tpl[2]);
				slavedepth=$('eldepth_'+tpl[1]+'_'+tpl[2]);
				slavecount=$('elcount_'+tpl[1]+'_'+tpl[2]);
				popup.innerHTML += '|'+slave.innerHTML;
				popup2.innerHTML += '|'+slave2.innerHTML;
				popuptitle.innerHTML += '|'+slavetitle.innerHTML;
				popupsubtitle.innerHTML += '|'+slavesubtitle.innerHTML;
				popupcom.innerHTML += '|'+slavecom.innerHTML;
				popupwidth.innerHTML += '|'+slavewidth.innerHTML;
				popupheight.innerHTML += '|'+slaveheight.innerHTML;
				popupdepth.innerHTML += '|'+slavedepth.innerHTML;
				popupcount.innerHTML += '|'+slavecount.innerHTML;
	        }
	    }
	}
	//tmp=popup.innerHTML.split('##');
    //tmp.splice(0,1);
	//alert(temp);
	//loop(popup, main);
	ss('mainel_'+a+'_'+b+'_'+c, popup.innerHTML, popup2.innerHTML, popuptitle.innerHTML, popupsubtitle.innerHTML, popupcom.innerHTML, popupwidth.innerHTML, popupheight.innerHTML, popupdepth.innerHTML, popupcount.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, str_idtitle, str_idsubtitle, str_idcom, str_idwidth, str_idheight, str_iddepth, str_idcount, 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+'", "'+str_idtitle+'", "'+str_idsubtitle+'", "'+str_idcom+'", "'+str_idwidth+'", "'+str_idheight+'", "'+str_iddepth+'", "'+str_idcount+'", "0", "'+divtype+'");', 1000);
	}
	else {
		hand_action[ss_id] = 'start';
		var tmp = str_id.split('|');
		var tmp2 = str_id2.split('|');
		var tmptitle = str_idtitle.split('|');
		var tmpsubtitle = str_idsubtitle.split('|');
		var tmpcom = str_idcom.split('|');
		var tmpwidth = str_idwidth.split('|');
		var tmpheight = str_idheight.split('|');
		var tmpdepth = str_iddepth.split('|');
		var tmpcount = str_idcount.split('|');
		tmp.splice(0,1);
		tmp2.splice(0,1);
		tmptitle.splice(0,1);
		tmpsubtitle.splice(0,1);
		tmpcom.splice(0,1);
		tmpwidth.splice(0,1);
		tmpheight.splice(0,1);
		tmpdepth.splice(0,1);
		tmpcount.splice(0,1);
		var div_id = ss_id.split('_');
		if($(tmpcount[cur_el]))
			count_value=$(tmpcount[cur_el]).value;
		else
			count_value='?';
		if(tmp != ''){
			if(divtype == 'option'){
				tmp[cur_el] = tmp[cur_el].split('_');
				$(ss_id).innerHTML = ''+tmp[cur_el][0]+'<div><b>'+tmp[cur_el][1]+'</b></div>';
			}else if(divtype == 'list'){
				$(ss_id).innerHTML = tmp[cur_el]+'<div><b>'+tmp2[cur_el]+' LVL</b></div>';
			}else{
				innerhtml = '<table cellpadding="0" cellspacing="0"  border="0" width="100%">'+
										'<tr>'+
											'<td align="center">'+
												'<a href="javascript:flipWindow2(true, \''+val_link+'data/img/'+tmp[cur_el]+'.jpg\');"><img src="'+val_link+'/data/img/'+tmp[cur_el]+'_libsmall.jpg" alt="" align="absmiddle"/></a>'+
											'</td>'+
										'</tr>'+
										'<tr>'+
											'<td class="subgroup_td2">'+
												'<div class="subgroup_title">'+
													''+tmpsubtitle[cur_el]+''+
												'</div>'+
											'</td>'+
										'</tr>';
				/*innerhtml +=			'<tr>'+
											'<td class="subgroup_td1">'+
											   '<div class="subgroup_price">';
				if(tmptitle[cur_el] != 'none'){innerhtml +=  ''+tmptitle[cur_el]+'';}else{innerhtml +='&nbsp;';}
				innerhtml +=				   '</div>'+
											'</td>'+
										'</tr>';*/
				innerhtml +=			'<tr>'+
											'<td class="subgroup_td1">'+
											   '<div class="subgroup_width">';
				if(parseFloat(tmpwidth[cur_el]) > 0){	   innerhtml +='<img src="'+img_link+'width.gif" alt="" align="absmiddle"/>&nbsp;'+tmpwidth[cur_el]+'<img src="'+img_link+'../0.gif" alt="" style="width: 7px; height: 1px;" />'; }else{ innerhtml +='&nbsp;'; }
				if(parseFloat(tmpheight[cur_el] ) > 0){	   innerhtml +='<img src="'+img_link+'height.gif" alt="" align="absmiddle"/>&nbsp;'+tmpheight[cur_el]+'<img src="'+img_link+'../0.gif" alt="" style="width: 7px; height: 1px;" />'; }else{ innerhtml +='&nbsp;'; }
				if(parseFloat(tmpdepth[cur_el] ) > 0){	   innerhtml +='<img src="'+img_link+'depth.gif" alt="" align="absmiddle"/>&nbsp;'+tmpdepth[cur_el]+''; }else{ innerhtml +='&nbsp;'; }
				if(parseFloat(tmpdepth[cur_el] ) > 0 || parseFloat(tmpheight[cur_el] ) > 0 || parseFloat(tmpwidth[cur_el] ) > 0){ innerhtml +='&nbsp;<font style="font-size:10px;">'+meb_suzeval+'</font>'; }
				innerhtml +=				   '</div>'+
											'</td>'+
										'</tr>';
				if(tmp2[cur_el] > 0){
					innerhtml +=		'<tr>'+
											'<td class="subgroup_td1">'+
											   '<div class="subgroup_price">'+
											   '<span class="subgroup_count">'+tmp2[cur_el]+' LVL</span> '+count_value+' gab.'+
											   '</div>'+
											'</td>'+
										'</tr>';
				}else{
					if(parseFloat(count_value) > 0){
						innerhtml +=	'<tr>'+
											'<td class="subgroup_td1">'+
											   '<div class="subgroup_price">'+
												+count_value+' gab.'+
											   '</div>'+
											'</td>'+
										'</tr>';
					}else{
						innerhtml +=	'<tr>'+
											'<td class="subgroup_td1">'+
											   '<div class="subgroup_price">'+
												'&nbsp;'+
											   '</div>'+
											'</td>'+
										'</tr>';
					}
				}
				innerhtml +=			'</table>';
				$(ss_id).innerHTML=innerhtml;
			}
		}else{
			//$(ss_id).innerHTML = '<div style="border: solid 0px red; display: block; height: 95px; text-decoration: underline;">'+non_items+'</div>';
			if ($(ss_id).innerHTML != $('nonediv_'+div_id[1]+'_'+div_id[2]+'_'+div_id[3]).innerHTML) {
				$(ss_id).innerHTML = $('nonediv_'+div_id[1]+'_'+div_id[2]+'_'+div_id[3]).innerHTML;
			}
			//alert(tmpcom);
		}
		if(browser == 'IE' && version == '6.0'){
			return false;
		}else{
			//alert('asdas');
			if (cur_el < tmp.length-1) {
				hand[ss_id] = setTimeout('ss("'+ss_id+'", "'+str_id+'", "'+str_id2+'", "'+str_idtitle+'", "'+str_idsubtitle+'", "'+str_idcom+'", "'+str_idwidth+'", "'+str_idheight+'", "'+str_iddepth+'", "'+str_idcount+'", "'+(parseInt(cur_el)+1)+'", "'+divtype+'", true);', 3000);
			}
			else {
				hand[ss_id] = setTimeout('ss("'+ss_id+'", "'+str_id+'", "'+str_id2+'", "'+str_idtitle+'", "'+str_idsubtitle+'", "'+str_idcom+'", "'+str_idwidth+'", "'+str_idheight+'", "'+str_iddepth+'", "'+str_idcount+'", "0", "'+divtype+'", true);', 3000);
			}
		}
	}
}








function take_option_price(sel_id){
	e=$(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(){
	$('shopping_cart_items').innerHTML=items;
	
	if(items == 0){
		$('shopping_cart_items_txt').innerHTML = basket_item_txt1;
	}else if(items == 1){
		$('shopping_cart_items_txt').innerHTML = basket_item_txt2;
	}else if(items >= 2 && items <= 4){
		$('shopping_cart_items_txt').innerHTML = basket_item_txt3;
	}else if(items >= 5 && items <= 20){
		$('shopping_cart_items_txt').innerHTML = basket_item_txt1;
	}
	if(items == 0){
		$('shopping_cart_items2_txt').style.display='none';
		$('shopping_cart_items3_txt').style.display='none';
	}else{
		$('shopping_cart_items2_txt').style.display='';
		$('shopping_cart_items3_txt').style.display='';
	}
}

// ------------------ 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;
			var price_shop = 0;
			for (var i=0;i<myform.elements.length;i++)
			{
				var e=myform.elements[i];
				if (e.type == 'hidden'){
					var tmp=e.name.split('_');
					price_tmp=parseFloat($('b_price_'+tmp[1]).innerHTML);
					price_befor_tmp=parseFloat($('b_price_befor_'+tmp[1]).innerHTML);
					price_shop_tmp=parseFloat($('b_price_shop_'+tmp[1]).innerHTML);
					price=price+price_tmp;
					price_befor=price_befor+price_befor_tmp;
					price_shop=price_shop+price_shop_tmp;
				}
			}
			var price_shop_chiper=roundNumber(price_shop,2)-roundNumber(price,2);
			var price_shop_percent=(roundNumber(price_shop_chiper,2)*100)/roundNumber(price,2);
			$('kop_price').innerHTML=roundNumber(price,2);
			$('kop_price_befor').innerHTML=roundNumber(price_befor,2);
			$('kop_price2').innerHTML=roundNumber(price,2);
			$('kop_price9').value=roundNumber(price,2);
			$('kop_price2_befor').innerHTML=roundNumber(price_befor,2);
			$('kop_price_shop').innerHTML=roundNumber(price_shop,2);
			$('kop_price_shop_chiper').innerHTML=roundNumber(price_shop_chiper,2);
			$('kop_price_shop_percent').innerHTML=roundNumber(price_shop_percent,2);
			$('kop_price_shop_chiper2').innerHTML=roundNumber(price_shop_chiper,2);
			$('kop_price_shop_percent2').innerHTML=roundNumber(price_shop_percent,2);
			$('kop_price_shop2').innerHTML=roundNumber(price_shop,2);
		}
	}
	return true;
}


function b_count(id){
	var b_count=parseFloat($('b_count_'+id).innerHTML);
	var b_count2=parseFloat($('b_count2_'+id).value);
	var price=parseFloat($('b_price_orig_'+id).innerHTML);
	var price_shop=parseFloat($('b_price_chiper_'+id).innerHTML)/100;
	var price_befor=parseFloat($('b_price_befor_orig_'+id).innerHTML)/100;
	price=b_count * price;
	price_befor=price * price_befor;
	$('b_price_'+id).innerHTML=roundNumber(price,2);
	$('b_price_befor_'+id).innerHTML=roundNumber(price_befor,2);
	$('b_price_'+id+'_2').innerHTML=roundNumber(price,2);
	$('b_price_befor_'+id+'_2').innerHTML=roundNumber(price_befor,2);
	$('b_count_'+id+'_2').innerHTML=b_count;
	document.getElementsByName('b_counter_'+id)[0].value=b_count;
	$('b_price_shop_'+id).innerHTML=(roundNumber(price,2)*price_shop)+roundNumber(price,2);
	$('b_price_shop2_'+id).innerHTML=(roundNumber(price,2)*price_shop)+roundNumber(price,2);
	//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 roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places
  var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
  return newnumber; // Output the result to the form field (change for your purposes)
}
function flipWindow(show, content) {
	var html;
	if (show) {
		$('block').style.display = 'block';
		$('window').style.display = 'block';
	} else {
		$('block').style.display = 'none';
		$('window').style.display = 'none';
	}
	switch (content) {
		case 'chiper' :
			html = '<form name="chiper" method="post"><table cellpading="5" cellspacing="5" class="order_txt2" style="padding: 0 0 0 15px;">'+
						'<tr>'+
							'<td align="right">'+
								'Jusu vards'+
							'</td>'+
							'<td align="left">'+
								'<input id="name" type="text" name="name" id="name" value="" onChange="if(this.value != \'\') callAjax(\'checkName\', this.value, this.id);">'+
								'<span id="rsp_name"></span>'+
							'</td>'+
						'</tr>'+
						'<tr>'+
							'<td align="right">'+
								'Talrunis'+
							'</td>'+
							'<td align="left">'+
								'<input type="text" name="phone" id="phone" value="" onChange="if(this.value != \'\') callAjax(\'checkPhone\', this.value, this.id);">'+
								'<span id="rsp_phone"></span>'+
							'</td>'+
						'</tr>'+
						'<tr>'+
							'<td align="right">'+
								'E-pasts'+
							'</td>'+
							'<td align="left">'+
								'<input type="text" name="email" id="email" value="" onChange="if(this.value != \'\') callAjax(\'checkEmail\', this.value, this.id);">'+
								'<span id="rsp_email"></span>'+
							'</td>'+
						'</tr>'+
						'<tr>'+
							'<td align="right" valign="top">'+
								'Teksts'+
							'</td>'+
							'<td align="left">'+
								'<textarea id="text" type="text" name="text" onfocus="if(this.value==\''+chiper_txt+'\')this.value=\'\'" onblur="if(this.value==\'\')this.value=\''+chiper_txt+'\'">'+
									chiper_txt+
								'</textarea>'+
							'</td>'+
						'</tr>'+
						'<tr>'+
							'<td align="center">'+
							'</td>'+
							'<td align="left">'+
								'<div id="submit">'+
									'<table cellspacing="0" cellspacing="0"  style="cursor: pointer;" onclick="document.chiper.submit();flipWindow(true, \'after_post\');">'+
										'<tr>'+
											'<td width="5" height="19" style="background: url('+img_link+'change_left2.gif) right center no-repeat;">'+
												'&nbsp;'+
											'</td>'+
											'<td height="19" style="background: url('+img_link+'change_px2.gif) right center repeat-x;">'+
												'<div class="const_add_basket">&nbsp;'+calc_submit+'&nbsp;</div>'+
											'</td>'+
											'<td width="5" height="19" style="background: url('+img_link+'change_right2.gif) left center no-repeat;">'+
												'&nbsp;'+
											'</td>'+
										'</tr>'+
									'</table>'+
								'</div>'+
								'<div id="submit_nonok" style="display: none;">'+
									'<table cellspacing="0" cellspacing="0"  style="cursor: pointer;" onclick="document.constructor.submit();flipWindow(true, \'after_post\');">'+
										'<tr>'+
											'<td width="5" height="19" style="background: url('+img_link+'change_left2.gif) right center no-repeat;">'+
												'&nbsp;'+
											'</td>'+
											'<td height="19" style="background: url('+img_link+'change_px2.gif) right center repeat-x;">'+
												'<div  class="const_add_basket">&nbsp;'+calc_submit+'&nbsp;</div>'+
											'</td>'+
											'<td width="5" height="19" style="background: url('+img_link+'change_right2.gif) left center no-repeat;">'+
												'&nbsp;'+
											'</td>'+
										'</tr>'+
									'</table>'+
								'</div>'+
								'<input name="chiper" type="hidden" value="add">'+
							'</td>'+
						'</tr>'+
					'</table></form>';
			break;
		case 'after_post' :
			html = '<div style="width: 100%; height: 100%;" align="center"><img src="/img/menu/ajax-loader.gif" alt="Loading..." width="100" height="100"/></div>';
			break;
		case 'chiper_ok' :
			html = '<div style="width: 100%;" align="center">'+mebeles_sendmail_ok+'<div>';
			break;
		case 'chiper_empty' :
			html = '<div style="width: 100%;" align="center">'+mebeles_sendmail_empty+'<div>'+
				   '<div style="width: 100%; cursor: pointer;" align="center" onclick="flipWindow(true, \'chiper\');">'+mebeles_sendmail_again+'<div>';
			break;
		case 'calc' :
			html = '<table style="padding: 10px 0 0 15px;" class="order_txt2" cellpading="10" cellspacing="5">'+
						'<tr>'+
							'<td>'+
								calc_price+
							'</td>'+
							'<td>'+
								'<input type="text" class="basket_inp" name="calc_price" id="calc_price" onblur="count_calc();">'+
							'</td>'+
						'</tr>'+
						'<tr>'+
							'<td>'+
								calc_first+
							'</td>'+
							'<td>'+
								'<select class="basket_inp3" name="calc_first" id="calc_first" onchange="count_calc();">'+
									'<option value="5" {if $calc_first eq 5}selected{/if}>5</option>'+
									'<option value="10" {if $calc_first eq 10}selected{/if}>10</option>'+
									'<option value="15" {if $calc_first eq 15}selected{/if}>15</option>'+
									'<option value="20" {if $calc_first eq 20}selected{/if}>20</option>'+
									'<option value="25" {if $calc_first eq 25}selected{/if}>25</option>'+
									'<option value="30" {if $calc_first eq 30}selected{/if}>30</option>'+
									'<option value="35" {if $calc_first eq 35}selected{/if}>35</option>'+
									'<option value="40" {if $calc_first eq 40}selected{/if}>40</option>'+
									'<option value="45" {if $calc_first eq 40}selected{/if}>45</option>'+
									'<option value="50" {if $calc_first eq 50}selected{/if}>50</option>'+
								'</select>'+
							'</td>'+
						'</tr>'+
						'<tr>'+
							'<td>'+
								calc_long+
							'</td>'+
							'<td>'+
								'<select class="basket_inp3" name="calc_long" id="calc_long" onchange="count_calc();">'+
									'<option value="3" {if $calc_long eq 3}selected{/if}>3</option>'+
									'<option value="6" {if $calc_long eq 6}selected{/if}>6</option>'+
									'<option value="9" {if $calc_long eq 9}selected{/if}>9</option>'+
									'<option value="12" {if $calc_long eq 12}selected{/if}>12 (1 gads)</option>'+
									'<option value="18" {if $calc_long eq 18}selected{/if}>18</option>'+
									'<option value="24" {if $calc_long eq 24}selected{/if}>24 (2 gadi)</option>'+
									'<option value="36" {if $calc_long eq 36}selected{/if}>36 (3 gadi)</option>'+
								'</select>'+
							'</td>'+
						'</tr>'+
						'<tr>'+
							'<td>'+
								calc_proc+
							'</td>'+
							'<td>'+
								'<input class="basket_inp" type="text" name="calc_proc" value="6" id="calc_procenti" onblur="count_calc();">'+
							'</td>'+
						'</tr>'+
						'<tr>'+
							'<td colspan="2">'+
								'<br>&nbsp;<br>'+
								'<div>'+calc_end_first+'&nbsp;<span id="calc_end_first">0</span></div>'+
								'<div>'+calc_end_pay+'&nbsp;<span id="calc_end_pay">0</span></div>'+
							'</td>'+
						'</tr>'+
					'</table>';

			break;
		case 'loading' :
			html = '<img src="'+img_link+'ajax-loader.gif" alt="Loading..." width="100" height="100"/>';
			break;
		default : html = '<span class="inactive">Nothing here</span>';
	}
	$('windowContent').innerHTML = html;
	if(show && content == 'calc'){
		if($('kop_price2')){
			$('calc_price').value=$('kop_price2').innerHTML;
			//$('kop_price9').value=$('kop_price2').innerHTML;
		}else if($('all_price')){
			$('calc_price').value=$('all_price').innerHTML;
		}
		count_calc();
	}
}
function flipWindow2(show, content) {
	var html;
	if (show) {
		$('block2').style.display = 'block';
		$('window2').style.display = 'block';
	} else {
		$('block2').style.display = 'none';
		$('window2').style.display = 'none';
	}
	h = (typeof window.innerHeight != 'undefined' ? window.innerHeight : document.body.offsetHeight);
	w = (typeof window.innerWidth != 'undefined' ? window.innerWidth : document.body.offsetWidth);
	
	
	html = '<table cellpadding="0" cellspacing="0" style="width:'+w+'px;height:'+h+'px;text-align:center;"><tr><td width="50%">&nbsp;</td><td align="center" valign="middle" style="background:#fff;height:10%;">'+
			'<img src="'+content+'" alt="" align="absmiddle"/>'+
			'</td><td width="50%">&nbsp;</td></tr><tr><td></td><td valign="top" align="right">'+
			'<div width="100%" style="background:#ffffff;"><img src="'+close_link+'closelabel.gif" alt="Close"/></div>'+
			'</td><td></td></tr></table>';
	$('windowContent2').innerHTML = html;
}
function count_calc(){
	var calc_first=$('calc_first');
	var calc_price=$('calc_price');
	var calc_long=$('calc_long');
	var calc_proc=$('calc_procenti');

	var calc_end_first=$('calc_end_first');
	var calc_end_pay=$('calc_end_pay');

	disable(true);

	calc_end_first.innerHTML=roundNumber(calc_price.value*(calc_first.value/100),2);
	var x=calc_proc.value/(12*100);
	var y=Math.pow(((1/(1+x))),calc_long.value);
	var z=x/(1-y);
	var a=z*(calc_price.value-calc_end_first.innerHTML);

	setTimeout("disable(false)",100);
	calc_end_pay.innerHTML=roundNumber(a,2);
}
function disable(val){
	var calc_first=$('calc_first');
	var calc_price=$('calc_price');
	var calc_long=$('calc_long');
	var calc_proc=$('calc_procenti');
	calc_first.disabled=val;
	calc_price.disabled=val;
	calc_long.disabled=val;
	calc_proc.disabled=val;
}
function callAjax(method, value, target) {
	if(encodeURIComponent) {
		var req = new AjaxRequest();
		var params = "method=" + method + "&value=" + encodeURIComponent(value) + "&target=" + target; req.setMethod("POST"); req.loadXMLDoc(val_link+'validate/validate.php', params);
	}
}

function getElementsByClassName_div(classname, node) {
  if(!node) node = document.getElementsByTagName("body")[0];
  var a = [];
  var re = new RegExp('\\b' + classname + '\\b');
  var els = node.getElementsByTagName("*");
  for(var i=0,j=els.length; i<j; i++)
  if(re.test(els[i].className))a.push(els[i]);
  return a;
 }


function show_div(div_id) {
	if ($(div_id).style.display == 'none') {
		$(div_id).style.display = 'block';
	} else {
		$(div_id).style.display='none';
	}
}
function change_div() {
	div_id='add_basket_button';
	if($(div_id+'1')) $(div_id+'1').style.display = 'none';
	if($(div_id+'1_nonact')) $(div_id+'1_nonact').style.display='block';
	if($(div_id+'1_2')) $(div_id+'1_2').style.display = 'none';
	if($(div_id+'1_nonact2')) $(div_id+'1_nonact2').style.display='block';
	if($(div_id+'1_nonact2_shopping')) setTimeout("$(div_id+'1_nonact2_shopping').innerHTML=$('top_shopping_txt').innerHTML;", 2000);
	//$(div_id+'2').style.display = 'none';
	//$(div_id+'2_nonact').style.display='block';
}
function show_div_more() {
	$('more_short').style.display = 'none';
	$('more_full').style.display='';
}
function show_div_more2() {
	$('more_short').style.display = '';
	$('more_full').style.display='none';
}

//document.write('<div style="position: relative; top: 45%; z-index: 100; height: 100%; background-color: white; filter: alpha(opacity=50); -moz-opacity: .50;	opacity: .50;" id="page_loading"><center>L&#363;dzu uzgaidiet! Lappu&#353;u iel&#257;de...</center></div>');
//document.write('<div style="position:absolute;z-index:10000;height:100%;width:100%;background-color:#fff;scroll:none;" id="page_loading"><table cellpadding="0" cellspacing="0" height="100%" width="100%"><tr><td valign="middle"><center>L&#363;dzu uzgaidiet! Lappu&#353;u iel&#257;de...</center></td></tr></table></div>');
//document.write('<div style="position: absolute; left: 45%; top: 45%; z-index: 100;" id="page_loading"><img src="/img/menu/ajax-loader.gif" alt="loading" /></div>');
window.onload=function() {
	try {
		if(meb_bask_pr == 0) count_price();
	}catch(err){
	}
	count_basket();
	try {
		if(edit){
			if(edit > 0){
				init_edit();
			}else{
				init(1);
			}
		}
	}catch(err){
	}
	//document.getElementById('page_loading').style.display = 'none';

	/*var d = new Date()
	var seconds=d.getSeconds();
	seconds=((seconds < 10) ? "0" : "")+ seconds;
	var time_end=d.getHours()+''+(d.getMinutes()+1)+''+seconds;
	time=parseInt(time_end)-parseInt(time_start);
	//alert('start time: '+time_start+'; end time: '+time_end+'; Page loading: '+time+'sec.');
	alert('Page loading: '+time+'sec.');*/
}
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;
			initLightbox();
        }else{
        	//document.getElementById(sub).innerHTML = "Error: returned status code " + req.status + " " + req.statusText;
        }
      }
    }

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

}
function ajax_sendnews(url, container, value) {
	if(value != ''){
		if (typeof XMLHttpRequest == "undefined")
			XMLHttpRequest = function() {
				try { return new ActiveXObject("Msxml2.XMLHTTP.6.0") } catch(e) {}
				try { return new ActiveXObject("Msxml2.XMLHTTP.3.0") } catch(e) {}
				try { return new ActiveXObject("Msxml2.XMLHTTP") }     catch(e) {}
				try { return new ActiveXObject("Microsoft.XMLHTTP") }  catch(e) {}
				throw new Error( "This browser does not support XMLHttpRequest or XMLHTTP." )
			};
		var request =  new XMLHttpRequest();
		var params = "email="+value;
		//request.open("GET", url+"?"+params, true);
		request.open("POST", url, true);
		request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		request.setRequestHeader("Content-length", params.length);
		request.setRequestHeader("Connection", "close");
		//request.setRequestHeader("Content-Type", "application/x-javascript;");
		request.onreadystatechange = function() {
			if (request.readyState == 4 && request.status == 200) {
				if (request.responseText) {
					//document.getElementById('loader').style.display = 'none';
					//document.getElementById('block').style.zIndex = 2;
					document.getElementById(container).innerHTML = request.responseText;
				}
			}
		}
		request.send(params);
	}
}
function ajax_help(url, container, name, desc, email, action) {
	if(url != ''){
		if (typeof XMLHttpRequest == "undefined")
			XMLHttpRequest = function() {
				try { return new ActiveXObject("Msxml2.XMLHTTP.6.0") } catch(e) {}
				try { return new ActiveXObject("Msxml2.XMLHTTP.3.0") } catch(e) {}
				try { return new ActiveXObject("Msxml2.XMLHTTP") }     catch(e) {}
				try { return new ActiveXObject("Microsoft.XMLHTTP") }  catch(e) {}
				throw new Error( "This browser does not support XMLHttpRequest or XMLHTTP." )
			};
		var request =  new XMLHttpRequest();
		var params = "email="+email+"&desc="+desc+"&name="+name+"&action="+action;
		//request.open("GET", url+"?"+params, true);
		request.open("POST", url, true);
		request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		request.setRequestHeader("Content-length", params.length);
		request.setRequestHeader("Connection", "close");
		//request.setRequestHeader("Content-Type", "application/x-javascript;");
		request.onreadystatechange = function() {
			if (request.readyState == 4 && request.status == 200) {
				if (request.responseText == 'OK') {
					//document.getElementById('loader').style.display = 'none';
					//document.getElementById('block').style.zIndex = 2;
					document.getElementById(container).innerHTML = helpResponseText;
				}
			}
		}
		request.send(params);
	}
}

