// copyright (c) Piotr Sawicki
//

// dropdown menus

var isDOM = (document.getElementById ? true : false); 
var isIE4 = ((document.all && !isDOM) ? true : false);
var isNS4 = (document.layers ? true : false);
var selecteddivid ;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
function getRef(id) {
	if (isDOM) return document.getElementById(id);
	else if (isIE4) return document.all[id];
	else if (isNS4) return document.layers[id];
}

function getSty(id) {
	return (isNS4 ? getRef(id) : getRef(id).style);
} 

function getImg(id) {
	return document.images[id];
}

function imgChange(name, src) {
	getImg(name).src = src;
}

var int_menuTimer = 0;
var int_menuPrevId = 0;
var int_barTimer = 0;
var int_menuId = false;
var int_menuClass = "";
function int_menuDivHide(divId) {
	getSty(divId).visibility ="hidden";
	if ( int_menuId ) {
		getRef(int_menuId).className = int_menuClass;
	}
	if(selecteddivid!=divId)
	{
	hidebar(divId);
	int_menuId = false;
	}
	else
		showbar2(divId);
}

function menuDropDown(divId, menuId) {
	if ( int_menuPrevId ) int_menuDivHide(int_menuPrevId);
	if ( int_menuTimer ) clearTimeout(int_menuTimer);
	int_menuId = menuId;
	int_menuClass = getRef(menuId).className;
	getRef(menuId).className = "a";
	getSty(divId).visibility = "visible";
}

function menuDropDown2(divId, menuId) {
	if ( int_menuPrevId ) int_menuDivHide(int_menuPrevId);
	if ( int_menuTimer ) clearTimeout(int_menuTimer);
	if ( int_barTimer ) clearTimeout(int_barTimer);
	int_menuId = menuId;
	int_menuClass = getRef(menuId).className;
	getRef(menuId).className = "a";
	getSty(divId).visibility = "visible";
	showbar(divId);
}

function showbar(divid){
	
	if(document.getElementById('leftbar'+divid)) 
		document.getElementById('leftbar'+divid).style.visibility='visible';
		
		
	if(document.getElementById('rightbar'+divid))
		document.getElementById('rightbar'+divid).style.visibility='visible';

	if(document.getElementById('centerbar'+divid)){
		if(version<5)
			document.getElementById('centerbar'+divid).style.background="url(/img2/centerbar.gif)";
		else
			document.getElementById('centerbar'+divid).className="left centerbar red";			               

		document.getElementById('centerbar'+divid).parentNode.style.zIndex='500';
		document.getElementById('centerbar'+divid).firstChild.firstChild.className="red";
		document.getElementById('s'+divid).style.background="none";
		if(divid == 'k7m' || divid == 'k8m' || divid == 'k9m') {
			if(version<5)
				document.getElementById('centerbar'+divid).style.background="url(/img2/centerbar_blue.gif)";
			else
				document.getElementById('centerbar'+divid).className="left centerbar red";
			document.getElementById('centerbar'+divid).firstChild.firstChild.className="blue";
		}
	}
}

function showbar2(divid){
if(document.getElementById('leftbar'+divid))
{
		document.getElementById('leftbar'+divid).style.visibility='visible';
		
		}
if(document.getElementById('rightbar'+divid))
		document.getElementById('rightbar'+divid).style.visibility='visible';
		if(document.getElementById('centerbar'+divid))
		{
			document.getElementById('centerbar'+divid).style.background="url(/img2/centerbar.gif)";
			document.getElementById('centerbar'+divid).parentNode.style.zIndex='1';
			document.getElementById('centerbar'+divid).firstChild.firstChild.className="red";
			document.getElementById('s'+divid).style.background="none";
			 if(divid == 'k7m' || divid == 'k8m' || divid == 'k9m')
			 {
				document.getElementById('centerbar'+divid).style.background="url(/img2/centerbar_blue.gif)";
				document.getElementById('centerbar'+divid).firstChild.firstChild.className="blue";			               }
		}
}

function hidebar(divid){
if(document.getElementById('leftbar'+divid))
		document.getElementById('leftbar'+divid).style.visibility='hidden';
if(document.getElementById('rightbar'+divid))
		document.getElementById('rightbar'+divid).style.visibility='hidden';
if(document.getElementById('centerbar'+divid))
{

		if(version<5)		
			document.getElementById('centerbar'+divid).style.background="";
		else
			document.getElementById('centerbar'+divid).className="left centerbar";			               
		if(divid == 'k7m' || divid == 'k8m' || divid == 'k9m')
		{
			document.getElementById('centerbar'+divid).firstChild.firstChild.className="";
		}
		else
		{
			document.getElementById('centerbar'+divid).firstChild.firstChild.className="";
		}
			
//		document.getElementById('s'+divid).style.background="url('/img2/border_menu.png') no-repeat right -2px";
		}
}
function menuPrepare(divId) {
	int_menuPrevId	= divId;
	int_menuTimer	= setTimeout('int_menuDivHide(\'' + divId + '\')', 100);
}

function menuPrepare2(divId) {
	int_menuPrevId	= divId;
	int_menuTimer	= setTimeout('int_menuDivHide(\'' + divId + '\')', 100);
	//int_barTimer    = setTimeout('hidebar(\''+ divId +'\')',100);
}
function menuDivOver() {
	if ( int_menuTimer ) clearTimeout(int_menuTimer);
	if ( int_barTimer  ) clearTimeout(int_barTimer);
}

function menuDivOut(divId) {
	int_menuTimer = setTimeout('int_menuDivHide(\'' + divId + '\')', 100);
}

// top10 combobox

var int_t10Timer	= 0;
function int_t10DivHide() {
	getSty('t10_menu').visibility ="hidden";
}

function t10DropDown() {
	if ( getSty('t10_menu').visibility == "visible" ) {
		getSty('t10_menu').visibility = "hidden";
	} else {
		getSty('t10_menu').visibility = "visible";
	}
	return false;
}

function t10Prepare() {
	int_t10Timer	= setTimeout('int_t10DivHide()', 100);
}

function t10DivOver() {
	if ( int_t10Timer ) clearTimeout(int_t10Timer);
}

function t10DivOut() {
	int_t10Timer = setTimeout('int_t10DivHide()', 100);
}

var int_t10PrevUlId	= 't10_def';
function t10SetGroup(ulID, nazwa) {
	getSty(int_t10PrevUlId).visibility = 'hidden';
	getSty(int_t10PrevUlId = ulID).visibility = 'visible';
	getRef('t10_combo_sp').innerHTML = nazwa;
	int_t10DivHide();
	return false;
}


/* popups */
function popupOpen(url, cx, cy) {
	var xOffset = (screen.availWidth - cx) / 2;
	var yOffset = (screen.availHeight - cy) / 2.3;
	popup = window.open(url, 'popup'+cx+'_'+cy, 'alwaysRaised=yes,dependent,scrollbars=yes,resizable=yes,width='+cx+',height='+cy+',screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
	popup.focus();
	return false;
}

function popupOpenNS(url, cx, cy) {
	var xOffset = (screen.availWidth - cx) / 2;
	var yOffset = (screen.availHeight - cy) / 2.3;
	popup = window.open(url, 'popup'+cx+'_'+cy, 'alwaysRaised=yes,dependent,width='+cx+',height='+cy+',screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
	popup.focus();
	return false;
}

function popupOpenImg(url, cx, cy) {
	var xOffset = (screen.availWidth - cx) / 2;
	var yOffset = (screen.availHeight - cy) / 2.3;
	popup = window.open(url, 'popup'+cx+'_'+cy, 'alwaysRaised=yes,dependent,scrollbars=auto,resizable=no,width='+cx+',height='+cy+',screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+'');
	popup.focus();
	return false;
}


function sprawdzKomentarz(form) {
	if ( !form.nazwa.value ) {
		window.alert('Wpisz swoje imię lub pseudonim.');
		form.nazwa.focus();
		return false;
	}
	if ( form.email.value
		&& (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(form.email.value)) == false ) {
		window.alert('Wpisz poprawny adres e-mail.');
		form.email.focus();
		return false;
	}
	if ( !form.tekst.value ) {
		window.alert('Wpisz opinię.');
		form.tekst.focus();
		return false;
	}
	return true;
}

function sprawdzNeg(form) {
	if ( !form.nazwa.value ) {
		window.alert('Podaj imię i nazwisko.');
		form.nazwa.focus();
		return false;
	}
	if ( !form.email.value && !form.telefon.value ) {
		window.alert('Podaj adres e-mail lub telefon kontaktowy.');
		form.email.focus();
		return false;
	}
	if ( (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(form.email.value)) == false ) {
		window.alert('Wpisz poprawny adres e-mail.');
		form.email.focus();
		return false;
	}
	if ( !form.cena_klient.value ) {
		window.alert('Wpisz cenę, jaką chcesz uzyskać.');
		form.cena_klient.focus();
		return false;
	}
	return true;
}

function sprawdzPyt(form) {
	if ( !form.nazwa.value ) {
		window.alert('Wpisz swoje imię i/lub nazwisko.');
		form.nazwa.focus();
		return false;
	}
	if ( (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(form.email.value)) == false ) {
		window.alert('Wpisz poprawny adres e-mail.');
		form.email.focus();
		return false;
	}
	if ( !form.pytanie.value ) {
		window.alert('Proszę podać treść pytania.');
		form.pytanie.focus();
		return false;
	}
	return true;
}

function sprawdzQ(form) {
	if ( !form.q.value ) {
		form.q.focus();
		return false;
	}
	return true;
}

function is_integer(val) {
	var reg2 =/[.]/;
	//sprawdzenie integer
	if (reg2.test(val)){
        return false;
	}
	return true;
} 

function sprawdzRaty(cenaProd) {
	if( document.raty.wplata.value<0 ) {
		alert('Kwota wpłaty musi być większa lub równa zero. ')
		document.raty.wplata.focus();
		return false;
	}

	if ( isNaN(document.raty.wplata.value) ) {
		alert('W pole wpłaty wpisz liczbę.')
		document.raty.wplata.focus();
		return false;
	}
	if ( document.raty.wplata.value>cenaProd ) {
		alert('Wpłata nie może być większa niż cena produktu. ')
		document.raty.wplata.focus();
		return false;
	}
	if( cenaProd-document.raty.wplata.value<100 ) {
		alert('Minimalna kwota kredytu to 100zł.');
		document.raty.wplata.focus();
		return false;
	}
	
	document.raty.elements['raty_result'].value=Math.round( (document.raty.elements['ile_rat'].value*0.01*(cenaProd-document.raty.elements['wplata'].value)+cenaProd-document.raty.elements['wplata'].value)*100/(document.raty.elements['ile_rat'].value) )/(100);
}

function showhidediv(id) {
if(document.getElementById(id).style.visibility=='visible')
{
document.getElementById(id).style.visibility='hidden';
}
else
document.getElementById(id).style.visibility='visible';
}

function showimage(image)
{
var ob=document.getElementById('ob');
node=image.parentNode.nextSibling.cloneNode(true);
node.style.display='block';
ob.innerHTML=node.innerHTML;
}

function displaydiff(){
getSty('diff').height = document.body.clientHeight+'px';
getSty('diff').width = document.body.clientWidth+'px';
getSty('baner').visibility ="hidden";
getSty('diff').visibility ="visible";
 getSty('diffcontent').left = document.body.clientWidth/2 - getSty('diffcontent').width.replace('px','') / 2 + 'px';
getSty('diffcontent').visibility ="visible";
$('#diff').bgiframe(); 

}

function fixPNG(Image) {
	if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
		var imgID = (Image.id) ? "id='" + Image.id + "' " : "";
		var imgClass = (Image.className) ? "class='" + Image.className + "' " : "";
		var imgTitle = (Image.title) ? "title='" + Image.title  + "' " : "title='" + Image.alt + "' ";	
		var imgStyle = "display:inline-block;" + Image.style.cssText	
		var strNewHTML = "<span " + imgID + imgClass + imgTitle 	+ " style=\"" + "width:" + Image.width + "px; height:" + Image.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"+ "(src=\'" + Image.src + "\', sizingMethod='scale');\"></span>";	
		Image.outerHTML = strNewHTML;	  
	}
}

function createMail(id, m1, m2, m3) {
	document.getElementById(id).innerHTML='<a style="color: #0066ff;" href="mailto:'+m1+m2+m3+'">'+m1+m2+m3+'</a>';
}

function PoliczRateLukas(kwota) { 
	window.open('https://www.rtvagd.sklep.pl/lukas_sym.php?kwota='+kwota, 'Policz_rate', 'width=820,height=560,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
}

function PoliczRateZagiel(kwota) { 
	window.open('https://www.rtvagd.sklep.pl/zagiel_sym.php?wartoscTowarow='+kwota, 'Policz_rate_zagiel', 'width=810,height=500,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
}

function PokazProcedureLukas() {
	window.open('https://www.rtvagd.sklep.pl/lukas_proc.php', 'Pokaz_procedure_lukas', 'width=810,height=500,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
}

function PokazProcedureZagiel() {
	window.open('http://www.rtvagd.sklep.pl/zagiel_proc.php', 'Pokaz_procedure_zagiel', 'width=810,height=650,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
}
