/*
	QShop E-Commerce Solutions
	Copyright@Visual Technologies inc. 2002 - 2011
	http://qshop.com.pl
	This software is copyrighted, do not attempt to copy without permission
*/
function add_to_cart(id,default_shipping) {
	document.location.href = 'cart.php?action=add_item&id='+id+'&ship='+default_shipping+'&qty='+document.getElementById('qty_'+id).value;
}
function rotate_baner_hide() {
	//document.getElementById('rotate_baner').style.display = 'none';	
}
function change_opt(item) {
	param = item.options[item.selectedIndex].value;
	window.location.href = "show.php?id="+param;
}
function change_search_cat(obj) {
	catx_g = document.getElementById(obj.id).options[document.getElementById(obj.id).selectedIndex].value;
	document.getElementById(obj.id+'_search').value = catx_g;
	document.search_data_form.submit();
}
function update_co_quick(item) {
	newco = item.options[item.selectedIndex].value;
	document.location.href = 'quick_account.php?next=1'+replace_amp('&amp;')+'co='+newco;
}
function cart_comment_char() {
	document.getElementById('tran_comm_left').innerHTML = 200-parseFloat(document.getElementById('tran_comm').value.length);
	if(window.event.keyCode==8||window.event.keyCode==46) {
		document.getElementById('save_tran_comm').disabled = false;	
		return true;
	} else {
		if(document.getElementById('tran_comm').value.length>=200) {
			document.getElementById('save_tran_comm').disabled = true;
			return false;
		} else {
			document.getElementById('save_tran_comm').disabled = false;	
			return true;
		}
	}
}
function show_zn() {
	window.open('_template/_znaczniki.php', 'Znaczniki', 'width=430,height=200,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
}
function PoliczRate(koszyk,client_ID,wariantSklepu)	{
	 window.open('https://www.eraty.pl/symulator/oblicz.php?numerSklepu='+client_ID+'&wariantSklepu='+wariantSklepu+'&typProduktu=0&wartoscTowarow='+koszyk, 'Policz_rate','width=630,height=500,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
}
function nowe_okno() {
	window.open('https://www.zagiel.com.pl/kalkulator/jak_kupic.html', 'nowe_okno',
	'width=600,height=500,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
}
function validate_Zagiel() {
	if (document.getElementById('agree').checked==false){
		alert ("Zanim złożysz zamówienie, zapoznaj sie z procedura udzielenia kredytu ratalnego eKredyt Żagiel.");
		return false;
	} else {
		return true;
	}
}
function linked(obj) {
	if(GE('view_linked_'+obj).style.display=='') {
		GE('view_linked_'+obj).style.display = 'none';
		GE('view_linked_pic_'+obj).src = dbv+'gif/plus.gif';
	} else {
		GE('view_linked_'+obj).style.display = '';
		GE('view_linked_pic_'+obj).src = dbv+'gif/minus.gif';
	}
}
function OWP(point) { 
	window.open('_template/points.php?point='+point,'',"resizable=no,width=470,height=350");
}
function call_url(obj) {
	document.location.href = obj;
}
function openhelp() {
	Height = 450;
	Width = 500;
	var L = (screen.width - Width) / 8; 
	var T = (screen.height - Height) / 8; 
	var par = "directories=no,fullscreen=no,height=" + Height + ",width=" + Width + ",left=" + L + ",top=" + T + ",";    par += "location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no"; 
	window.open(dbv+"_template/_helpx.php", "", par); 
}
function change_cur_val(dbv,item) {
	param=item.options[item.selectedIndex].value;
	window.location.href = dbv+"index.php?show=start"+replace_amp('&amp;')+"action=change_current_val"+replace_amp('&amp;')+"new_val="+param;
}
function replace_amp(obj) {
	return obj.replace(/&amp;/g,'&');
}
function SCREEN_SIZE(wh) {
	if (parseInt(navigator.appVersion)>3) {
	if (navigator.appName=="Netscape"||navigator.appName=="Opera") {
			winW = window.innerWidth;
			winH = window.innerHeight;
		}
		if (navigator.appName.indexOf("Microsoft")!=-1) {
			winW = document.documentElement.clientWidth;
			winH = document.documentElement.clientHeight;
		}
	}
	if(wh=='width') {
		return winW;	
	} else { 
		return winH;
	}
}
function SCREEN_OFFSET(){ 
	var ns4 = (document.layers)? true:false; 
	if (ns4) 
		return (window.pageYOffset);              
	else 
		return (window.document.documentElement.scrollTop);  
}
// resize and scrolling
function WINDOW_RESIZE() {
	window_scrolling();
}
function GE(element) {
	return document.getElementById(element);	
}
function OPEN_POINTS(theURL,winName,features) {
	window.open(theURL,winName,features);
}
function get_event() {
	WINDOW_RESIZE();
	window.onresize = function() { 
		WINDOW_RESIZE(); 
	}
	window.onscroll = function() { 
		WINDOW_RESIZE(); 
	}
	try {
		startw();
	}
	catch(Error) {
		
	}
}
function tab_over(id) {
	GE('tab_pic1'+id).src = dbv+'themes/'+current_theme+'/pl/backtab_left_normal1.jpg';
	elem = document.getElementById('tab_pic2'+id);
	elem.style.background = 'url('+dbv+'themes/'+current_theme+'/pl/backtab_normal1.jpg)';
	GE('tab_pic3'+id).src = dbv+'themes/'+current_theme+'/pl/backtab_right_normal1.jpg';
	GE('tab_pic_text'+id).className = 'menu_section_up_hover';
}
function tab_out(id) {
	GE('tab_pic1'+id).src = dbv+'themes/'+current_theme+'/pl/backtab_left_normal.jpg';
	elem = document.getElementById('tab_pic2'+id);
	elem.style.background = 'url('+dbv+'themes/'+current_theme+'/pl/backtab_normal.jpg)';
	GE('tab_pic3'+id).src = dbv+'themes/'+current_theme+'/pl/backtab_right_normal.jpg';
	GE('tab_pic_text'+id).className = 'menu_section_up';
}
var last_left_tab = null;
function show_tab_left(obj) {
	try {
		selects = document.getElementsByTagName("div");
		for (i = 0; i != selects.length; i++) {
			ElementID = selects[i].id; 
			if(ElementID.indexOf('left_tab')==0) {
				if(last_left_tab!=obj) {
					selects[i].style.display = "none";
				}
			}
		}
		if(GE(obj)!=null) {
			if(GE(obj).style.display=='none') {
				GE(obj).style.display = '';
				GE(obj+'_pic').src = dbv+'gif/minus.gif';
			} else {
				GE(obj).style.display = 'none';	
				GE(obj+'_pic').src = dbv+'gif/plus.gif';
			}
		}
	}
	catch(Error) {
		
	}
	last_left_tab = obj;
}
function qty_ask(obj) {
	Height = 250;
	Width = 500;
	var L = (screen.width - Width) / 8; 
	var T = (screen.height - Height) / 8; 
	var par = "directories=no,fullscreen=no,height=" + Height + ",width=" + Width + ",left=" + L + ",top=" + T + ",";    par += "location=no,menubar=no,resizable=no,scrollbars=yes,status=no,toolbar=no"; 
	window.open(dbv+"_template/_ask_about_qty.php?itemId="+obj, "", par); 
}
function main() {
	this.objects_sel_catx = function(item) {
		catx = item.options[item.selectedIndex].value
		document.location.href = dbv+catx+','+item.options[item.selectedIndex].text;
	}
	/*
		Wybór marki z wybraną kategorią
	*/
	this.objects_sel_marka_catx = function(item,catx) {
		producer = item.options[item.selectedIndex].value;
		sel_kategoria = document.getElementById('sel_kategoria').options[document.getElementById('sel_kategoria').selectedIndex].value;
		if(producer!="0") {
			document.location.href = dbv+'category_prod.php?prod_id='+producer+'&catx='+sel_kategoria;
		}
	}
	/*
		Wybór marki + kategoria + model
	*/
	this.objects_sel_model_all = function(item,prod_id) {
		sel_model = item.options[item.selectedIndex].value;
		sel_kategoria = document.getElementById('sel_kategoria').options[document.getElementById('sel_kategoria').selectedIndex].value;
		if(sel_model!="0") {
			document.location.href = dbv+'category_prod.php?prod_id='+prod_id+'&catx='+sel_kategoria+'&caty='+sel_model;
		}
	}
	this.objects_sel_producer = function(item,catx) {
		producer = item.options[item.selectedIndex].value;
		if(producer!="0") {
			document.location.href = dbv+item.options[item.selectedIndex].text+'-'+producer+'.html';
		}
	}
	this.objects_sel_caty = function(item,prod_id,nazwa) {
		caty = item.options[item.selectedIndex].value;
		if(caty!="0") {
			document.location.href = dbv+nazwa+'-'+prod_id+','+caty+'.html';
		}
	}
	this.objects_sel_model = function(item) {
		model = item.options[item.selectedIndex].value;
		if(model!="0") {
			document.location.href = dbv+'category.php?caty='+model;
		}
	}
	this.objects_sel_producer_caty = function(item,caty) {
		marka = item.options[item.selectedIndex].value;
		if(marka!="0") {
			document.location.href = dbv+item.options[item.selectedIndex].text+'-'+marka+','+caty+'.html';
		}
	}
}
main = new main();
function dynamic_cart() {
	var http_dynamic_cart;
	var curr_action;
	var preload = 'gif/_lightbox/loading.gif';
	var objov_panel = document.createElement("div");
	var rand = null;
	var curr_rand;
	var load_quick_enabled = false;
	var itemId;
	/*
		Page scroll
	*/
	this.getPageScroll = function(){
		var yScroll;
		if (self.pageYOffset) {
			yScroll = self.pageYOffset;
		} else if (document.documentElement && document.documentElement.scrollTop){	 
			yScroll = document.documentElement.scrollTop;
		} else if (document.body) {
			yScroll = document.body.scrollTop;
		}
		arrayPageScroll = new Array('',yScroll) 
		return arrayPageScroll;
	}
	/*
		Page Size
	*/
	this.getPageSize = function(){
		var xScroll, yScroll;
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ 
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { 
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		var windowWidth, windowHeight;
		if (self.innerHeight) {	
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { 
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { 
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
		if(xScroll < windowWidth){	
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
		return arrayPageSize;
	}
	/*
		Dynamic cart
	*/
	this.http_dynamic_cart_Response = function() {
		if(http_dynamic_cart.readyState == 4){
			var response_autolog = http_dynamic_cart.responseText.split('|');
			try {
				document.getElementById('dynamic_cart').innerHTML = response_autolog[1];
			} catch(Error) {
				
			}
			if(curr_action=='add') {
				switch(response_autolog[0]) {
					case "0":
						document.getElementById('div_cart_added').innerHTML = "<div class='czp_in' style='padding-top:40px;'>Towar dodano do koszyka</div>";
					break;
					case "1":
						document.getElementById('div_cart_added').innerHTML = "<div class='czp_in' style='padding-top:40px;'>Ten towar jest już w koszyku</div>";
					break;
				}
			}
			setTimeout(hideov_panel,2000);
		}
	}
	/*
		Action
	*/	
	this.action = function(action) {
		http_dynamic_cart = createRequestObject();
		http_dynamic_cart.open('get', '_dynamic_cart.php?action='+action);
		http_dynamic_cart.onreadystatechange = this.http_dynamic_cart_Response;
		http_dynamic_cart.send(null);	
	}
	/*
		Hide
	*/
	hideov_panel = function() {
		ov_panel_overlay = document.getElementById('overlay_uv');
		objov_panel = document.getElementById('ov_panel');
		ov_panel_overlay.style.display = 'none';
		selects = document.getElementsByTagName("select");
		for (i = 0; i != selects.length; i++) {
			selects[i].style.visibility = "visible";
		}
		document.onkeypress = '';
		objov_panel.style.display = 'none';
	}
	/*
		Init
	*/
	this.init = function() {
		var ov_panel_overlay_uv = document.createElement("div");
		var ov_panel_body = document.getElementsByTagName("body").item(0);
		ov_panel_overlay_uv.setAttribute('id','overlay_uv');
		ov_panel_overlay_uv.style.display = 'none';
		ov_panel_overlay_uv.style.position = 'absolute';
		ov_panel_overlay_uv.style.top = '0';
		ov_panel_overlay_uv.style.left = '0';
		ov_panel_overlay_uv.style.zIndex = '90';
		ov_panel_overlay_uv.style.width = '100%';
		ov_panel_body.insertBefore(ov_panel_overlay_uv, ov_panel_body.firstChild);
		var imgPreloader = new Image();
		imgPreloader.onload=function(){
			var ov_panel_imgLink = document.createElement("a");
			ov_panel_imgLink.setAttribute('href','#');
			ov_panel_imgLink.onclick = function () {
					hideov_panel(); 
					return false;
				}
			ov_panel_overlay_uv.appendChild(ov_panel_imgLink);
			var ov_panel_img = document.createElement("img");
			ov_panel_img.src = preload;
			ov_panel_img.setAttribute('id','loadingImage');
			ov_panel_img.style.position = 'absolute';
			ov_panel_img.style.zIndex = '150';
			ov_panel_imgLink.appendChild(ov_panel_img);
			return false;
		}
		imgPreloader.src = preload;
		objov_panel.setAttribute('id','ov_panel');
		objov_panel.style.display = 'none';
		objov_panel.style.position = 'absolute';
		objov_panel.style.zIndex = '100';	
		ov_panel_overlay_uv.onclick = function () { hideov_panel();return false; }
		ov_panel_body.insertBefore(objov_panel, ov_panel_overlay_uv.nextSibling);
	}
	/*
		Display
	*/
	this.display = function() {
		var ov_panel_overlay_uv = document.getElementById('overlay_uv');
		var ov_panel_img = document.getElementById('loadingImage');
		var arrayPageSize = this.getPageSize();
		var arrayPageScroll = this.getPageScroll();
		if (ov_panel_img) {
			ov_panel_img.style.border = '0';
			ov_panel_img.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - ov_panel_img.height) / 2) + 'px');
			ov_panel_img.style.left = (((arrayPageSize[0] - 20 - ov_panel_img.width) / 2) + 'px');
			ov_panel_img.style.display = 'block';
		}
		ov_panel_overlay_uv.style.height = ((arrayPageSize[1]+arrayPageScroll[1]) + 'px');
		ov_panel_overlay_uv.style.display = 'block';
		
		ov_panel_img.style.display = 'none';
		var ov_panelTop = arrayPageScroll[1] + ((arrayPageSize[3] - 96) / 2);
		var ov_panelLeft = ((arrayPageSize[0] - 246) / 2);
		objov_panel.style.top = (ov_panelTop<0)?"0px":ov_panelTop+'px';
		objov_panel.style.left = (ov_panelLeft<0)?"0px":ov_panelLeft+'px';
		objov_panel.style.width = 246+'px';
		objov_panel.style.height = 960+'px';
		var html = "";
		html+= "<div style=\"background:url('png/ovr.png');width:246px;height:96px;\" id='div_cart_added'>";
		html+= "<div style='padding-top:20px;width:230px' class='czp_in'>Wpisz ilość sztuk : ";
		html+= "<input type=\"text\" id='ov_panel_id_cart' name=\"textfield\" class=\"frblue\" size='5' maxlength='5' value='1'>";
		html+= "<img src='themes/"+current_theme+"/pl/bt3.gif' onClick='dynamic_cart.add_to_cart_sys();' style='cursor:pointer;padding-top:10px'>";
		html+= "</div>";
		html+= "</div>";
		objov_panel.innerHTML = html;
		objov_panel.style.display = '';
	}
	/*
		Add to cart sys
	*/
	this.add_to_cart_sys = function() {
		curr_action = 'add';
		this.action('add&itemId='+this.itemId+'&qty='+document.getElementById('ov_panel_id_cart').value);
	}
	/*
		Load content
	*/	
	this.load_content = function() {
		curr_action = 'load';
		this.action('load');
	}
	/*
		Add content
	*/
	this.add_content = function(itemId) {
		this.itemId = itemId;
		this.display();
	}
}
dynamic_cart = new dynamic_cart();
dynamic_cart.init();
