function openWindowLukas( sAdres) {
var iWidth = 850;
var iHeight = 630;
var iX = ( screen.availWidth - iWidth ) / 2;
var iY = ( screen.availHeight - iHeight ) / 2;
var refOpen = window.open( sAdres, 'LUKAS', "height="+iHeight+",width="+iWidth+",top="+iY+",left="+iX+",resizable=yes,scrollbars=yes,status=0;" );
return refOpen;
}

function sortNumber(a, b)
{
return a - b;
}

function count_price(msg_err){
		sels = $$('#shop_options select');
		var obj_id = 'opt';		
		var obj_id2 = 'opt_id';	
		err = false;
		var arr_option = new Array();
		var i_el = 0;
		
			
		sels.each (function (val) {
			if(val.value!=0){
				arr_option[i_el] = val.value;
				i_el++;
			}
			else{
				err = true;
			}
		});
		//var arr_sort_option = arr_option.sort(sortNumber);
		arr_option.each (function (val) {
				obj_id+='_'+val;
				obj_id2+='_'+val;
		});
		var obj_id_netto = obj_id+'_netto';
		//alert(obj_id);
		//1 opt_art_5303
		//2 opt_art_5303_art_5308
		if ($(obj_id) == null) obj_id=obj_id2;
		//alert(obj_id);  opt_id_art_5304_art_5311
		
		if($(obj_id)){
			$('new_brutto').innerHTML = (parseFloat($('price_new_def').value)+parseFloat($(obj_id).value)).toFixed(2);
			if($('new_brutto_free'))$('new_brutto_free').innerHTML = (parseFloat($('price_new_def').value)+parseFloat($(obj_id).value)).toFixed(2);
			if($('old_brutto')){$('old_brutto').innerHTML = (parseFloat($('price_old_def').value)+parseFloat($(obj_id).value)).toFixed(2);}
			$('option_info').innerHTML = '';
		}
		else if(err){
			$('new_brutto').innerHTML = (parseFloat($('price_new_def').value)).toFixed(2);
			if($('new_brutto_free'))$('new_brutto_free').innerHTML = (parseFloat($('price_new_def').value)).toFixed(2);
			if($('old_brutto')){$('old_brutto').innerHTML = (parseFloat($('price_old_def').value)).toFixed(2);}
			$('option_info').innerHTML = msg_err;
			return;
		}
		else{
			$('option_info').innerHTML = msg_err;
		}
}

function addToBasket (id, domain, optMsg, quaMsg, nooptMsg, vip, pid)
{

	sels = $$('#shop_options select');
	optId = 'opt_id';
	err = false;
	var i_el = 0;
	var arr_option = new Array();
	
	sels.each (function (val) {
			if(val.value!=0){
				arr_option[i_el] = val.value;
				i_el++;
			}
			else{
				err = true;
			}
		});
		
	//var arr_sort_option = arr_option.sort(sortNumber);
		
		arr_option.each (function (val) {
				optId+='_'+val;
		});	
		
	if (err){
		alert(optMsg);
		return;
	}	
	//alert(optId);
	if(!$(optId) && nooptMsg){
		alert(nooptMsg);
		return;
		}

	if (parseInt($('quantity').value) < 1) {
		alert (quaMsg);
		return;
	}
	var quantity = parseInt($('quantity').value);
	optStr = '';
	if ($(optId)) {
		optStr = '&opt=' + $(optId).value;
	}
	url = domain + '/shop/?a=basket&action=add&id='+id+'&q='+quantity+optStr;
  if (vip) {
    url += '&vip=1';
  }
  if (pid) {
    url += '&promotor_id='+pid;
  }
	var myAjax = new Request({
		method: 'get', 
		url: url,
		onSuccess: ansBasket
	}).send();
	showPreloader();
}	

function addToBasketWidthFree (id, domain, optMsg, quaMsg, nooptMsg)
{
	sels = $$('#shop_options select');
	optId = 'opt_id';
	err = false;
	var i_el = 0;
	var prod_freeId = 0;
	var prod_freeP = 0;
	var arr_option = new Array();
	
	sels.each (function (val) {
		if(val.value!=0){
			arr_option[i_el] = val.value;
			i_el++;
		}
		else{
			err = true;
		}
	});
		
	//var arr_sort_option = arr_option.sort(sortNumber);		
		arr_option.each (function (val) {optId+='_'+val;});	
		
	if (err){alert(optMsg);return;}	

	if(!$(optId) && nooptMsg){alert(nooptMsg);return;}
	
	sels = $$('#freeOptRadio input');
	sels.each (function (val) {
		if(val.checked==true){	
			var tmp = val.value.split('|');
			prod_freeId = tmp[0];
			prod_freeP = tmp[1];	
		}
	});
	
	if (parseInt($('quantity').value) < 1) {
		alert (quaMsg);
		return;
	}
	var quantity = parseInt($('quantity').value);
	optStr = '';
	if ($(optId)) {
		optStr = '&opt=' + $(optId).value;
	}
	
	url = domain + '/shop/?a=basket&action=add&id='+id+'&q='+quantity+optStr+'&free='+prod_freeId+'&promotor_id='+prod_freeP;
  if ($('free_'+prod_freeId)) {
    url += '&free_opt='+$('free_'+prod_freeId).value;
  }
	var myAjax = new Request({
		method: 'get', 
		url: url,
		onSuccess: ansBasket
	}).send();
	showPreloader();
}	

function ansBasket(res)
{
	hidePreloader();	
	ret = JSON.decode (res);
/*	if (ret['msg']) {
		alert (ret['msg']);
	}
*/	
	if (ret['success'] == 1) {
		$('simple_basket').innerHTML = ret['details'];
		$('codalejId').style.display = '';
	}else if(ret['msg']){
		alert (ret['msg']);
	}	
}

function addToComparator (id, domain)
{
	url = domain + '/shop/?a=comparator&action=add&id='+id;
	var myAjax = new Request({
		method: 'get', 
		url: url,
		onSuccess: ansComparator
	}).send();
	showPreloader();
}	

function ansComparator(res)
{
	hidePreloader();	
	ret = JSON.decode (res);
	if (ret['msg']) {
		alert (ret['msg']);
	}
	if (ret['success'] == 1) {
		$('simple_comparator').innerHTML = ret['details'];
	}
}

function removeComparator (domain, cfr, id) 
{
	if (confirm(cfr)) {
		var myAjax = new Request({
			method: 'get', 
			url: domain + '/shop/?a=comparator&action=remove&id=' + id,
			onSuccess: ansRemComparator
		}).send();
		showPreloader();		
	}
}

function ansRemComparator(res)
{
	hidePreloader();
	ret = JSON.decode (res);
	if (ret['msg']) {
		alert (ret['msg']);
	}
	if (ret['success'] == 1) {
		window.location.reload();
		$('simple_comparator').innerHTML = ret['details'];
	}
}

function change_pict(obj_id, ph_id){
	sels = $$('#'+obj_id+' img');
	sels.each (function (val) {
		val.style.display = 'none';
	});	
	$('main'+ph_id).style.display = '';

}

function changePict_navi(val, allP){
	
	var nextP = parseInt($('currPhoto').value)+val;
	
	if(parseInt($('currPhoto').value)==5){
		$('mainzoom_photo_5').style.display = 'none';
		$('mainzoom_photo_0').style.display = '';
		$('currPhoto').value = 	0;
	}
	else if(nextP>=0 && nextP<=allP){
		$('mainzoom_photo_'+$('currPhoto').value).style.display = 'none';
		$('mainzoom_photo_'+nextP).style.display = '';
		$('currPhoto').value = 	nextP;
	}
	else if(nextP<0){
		nextP=allP;
		$('mainzoom_photo_'+$('currPhoto').value).style.display = 'none';
		$('mainzoom_photo_'+nextP).style.display = '';
		$('currPhoto').value = 	nextP;
	}
	else if(nextP>allP){
		nextP=0;
		$('mainzoom_photo_'+$('currPhoto').value).style.display = 'none';
		$('mainzoom_photo_'+nextP).style.display = '';
		$('currPhoto').value = 	nextP;
	}
}

function zoom_pict(obj){
	
	sels = $$('#zoom_main_photo img');
	sels.each (function (val) {
		val.style.display = 'none';
	});	
	$('currPhoto').value = obj.getAttribute("alt");
	if($('currPhoto').value!='0'){
		$('mp_link').style.display = 'none';
	}
	$('mainzoom_photo_'+obj.getAttribute("alt")).style.display = '';
	$('prodZoom').style.display = '';
}

function change_color_select(obj_id, s_val, pict_id, select_id){

	if(s_val==0){
		sels = $$('#'+obj_id+' img');
		sels.each (function (val) {
			val.style.display = 'none';
		});	
		$('mainphoto_0').style.display = '';
	}
	else{
		var sel_num=-1;
		var count_num=-1;
		
		sels = $$('#'+select_id+' option');
		sels.each (function (val) {
			if(parseInt(s_val)==val.value){				
				var opt_id = 's_'+val.value;	
				if($(opt_id)){sel_num=count_num;}
			}	
			count_num++;
		});
		if(sel_num>=0){
			sels = $$('#'+obj_id+' img');
			sels.each (function (val) {
				val.style.display = 'none';
			});
		
			$(pict_id+'_5').src = objectsArray[sel_num].p_main;
			$(pict_id+'_5').style.display = '';
			$(pict_id+'_5').setAttribute("alt","5,"+sel_num);
		}	
	}	
}

function change_color_pict(obj_id, pict_num, pict_id){
	
	sels = $$('#'+obj_id+' img');
	sels.each (function (val) {
		val.style.display = 'none';
	});	
	
	$(pict_id+'_5').src = objectsArray[pict_num].p_main;
	$(pict_id+'_5').style.display = '';
	$(pict_id+'_5').setAttribute("alt","5,"+pict_num);
}

function change_color_zoompict(obj_id, pict_num, pict_id){
	
	sels = $$('#'+obj_id+' img');
	sels.each (function (val) {
		val.style.display = 'none';
	});	
	$('mp_link').style.display = 'none';
	$(pict_id+'_5').src = objectsArray[pict_num].p_zoom;
	$(pict_id+'_5').style.display = '';
	$(pict_id+'_5').setAttribute("alt","5,"+pict_num);
}

function zoom_color_pict(obj){
	
	sels = $$('#zoom_main_photo img');
	sels.each (function (val) {
		val.style.display = 'none';
	});	
	
	$('mp_link').style.display = 'none';
	
	var a = obj.getAttribute("alt").split(",");
	
	$('currPhoto').value = a[0];
	$('mainzoom_photo_'+a[0]).src = objectsArray[a[1]].p_zoom;
	$('mainzoom_photo_'+a[0]).style.display = '';
	$('prodZoom').style.display = '';
}

var objectsArray = new Array();

function addToArray(obj, pos1){
	objectsArray[pos1] = obj;
}

function pictureObject(p_main, p_zoom){
	this.p_main=p_main;
	this.p_zoom=p_zoom;
}

function changeFreeOpt(objId){
	sels = $$('#freeOptSelect select');
	sels.each (function (val) {
		val.setStyle('display', 'none');
	});	
	if($('free_'+objId))$('free_'+objId).setStyle('display', '');

	sels = $$('#freeOptSelect span.free_price');
	sels.each (function (val) {
		val.setStyle('display', 'none');
	});	
	$('freeprice_'+objId).setStyle('display', '');

	sels = $$('#freeOptSelect .free_href');
	sels.each (function (val) {
		val.setStyle('display', 'none');
	});	
	$('freehref_'+objId).setStyle('display', '');
	
	sels = $$('#freePhotoBox img.free_photo');
	sels.each (function (val) {
		val.setStyle('display', 'none');
	});	
	if($('freephoto_'+objId))$('freephoto_'+objId).setStyle('display', '');
	
	sels = $$('#freeBoxAll .c_allow_free');
	sels.each (function (val) {
		val.setStyle('display', 'none');
	});	
	$('freeBox3').setStyle('display', 'none');
	if($('callowfree_'+objId)){$('freeBox3').setStyle('display', '');$('callowfree_'+objId).setStyle('display', '');}	
}

