// 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 = "";



// 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 createMailM(id, m1, m2, m3) {
	document.getElementById(id).innerHTML='<a style="color: #0066ff;" href="mailto:'+m1+m2+m3+'">Napisz do nas</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 PoliczRateAig(kwota) { 
	window.open('http://www.rtvagd.sklep.pl/aig_sym.php?wartoscTowarow='+kwota, 'Policz_rate_aig', 'width=810,height=700,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');
}

function PokazProcedureAig() {
	window.open('http://www.aigcredit.pl/kalkulator/index.php?action=about&partnerId=35577', 'Pokaz_procedure_aig', 'width=880,height=650,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
}

function move(m){
	window.location.href='http://www.rtvagd.sklep.pl/?m='+m;
}

function move2prod(href){
	window.location.href='http://www.rtvagd.sklep.pl/'+href;
}
