function printPage (elementId)
{
    if (document.getElementById('contentBody')) {
    	var contentBody = document.getElementById('contentBody').innerHTML;	
    }
    
    if (document.getElementById('contentHeader')) {
    	var contentHeader = document.getElementById('contentHeader').innerHTML;	
    }
    
    if (document.getElementById('contentTitle') ) {
    	var contentTitle = document.getElementById('contentTitle').innerHTML;	
    }
    
    if (document.getElementById('contentAuthor') ) {
    	var contentAuthor = document.getElementById('contentAuthor').innerHTML;	
    }
    
    var myWindow = window.open('','','width=500,height=600,scrollbars=1');
    
	myWindow.print();
				
	myWindow.document.write("<html>")
	myWindow.document.write("<head>")
	myWindow.document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"var/css/style_print.css\">");
	myWindow.document.write("</head>")
	myWindow.document.write("<body>")
	myWindow.document.write("<div style=\"font-size: 11px; font-family: tahoma;\">");
	if (contentTitle) {
	   myWindow.document.write("<h4>"+contentTitle+"</h4>");
	}
	if (contentBody) {
	   myWindow.document.write(contentBody);
	}
	
	if (contentAuthor) {
	   myWindow.document.write("<br><br><div align=\"right\">"+contentAuthor+"</div>");	    
	}
	myWindow.document.write("</div>")
	myWindow.document.write("</body>")
	myWindow.document.write("</html>")
}

function sendPage (elementId) {
    var myWindow = window.open('inc/popup.recommend.php?pId='+elementId,'','width=410,height=300,top=100,left=100,scrollbars=1');
}

function DisplayWindow(url, nazwa) 
{
	var Win = window.open('inc/'+url, nazwa, 'menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,fullscreen=no,channelmode=no,width=500,height=565');
	Win.focus();
}
function DisplayPhoto(url, nazwa) 
{
	var Win = window.open(url, nazwa, 'menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,fullscreen=no,channelmode=no,width=300,height=300');
	Win.focus();
}
function DisplayOffer(url, nazwa) 
{
	var Win = window.open('inc/'+url, nazwa, 'menubar=no,toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,fullscreen=no,channelmode=no,width=700,height=550');
	Win.focus();
}

function SwapPhoto(photo)
{
	var zdjecie = photo.src;
	document.getElementById('main_photo').src=zdjecie;
	
}

function zoom(pId) {
    DisplayWindow('zoom.php?pId='+pId,'Zoom');
}

function closeAlert()
{
    
   var alertWindow = document.getElementById('alertWindow');
   alertWindow.style.display='none';
}

function setCentered(element,width)
{

    if (width=='')
    {
        width = 0;
    }
    
    if (parseInt(navigator.appVersion)>3) 
    {
       if (navigator.appName=="Netscape") 
       {
           winW = window.innerWidth;
    	   winH = window.innerHeight;
       }
       if (navigator.appName.indexOf("Microsoft")!=-1) {
           winW = document.body.offsetWidth;
           winH = document.body.offsetHeight;
       }
    }
    
    positionLeft = (winW-width)/2;
    
    document.getElementById(element).style.left=positionLeft;
}


function showVoteForm()
{
    document.getElementById('vote_form_container').style.display='block';
}

function showRecommendForm(elementId,formId)
{
    formContainer       = document.getElementById(formId);
    elementContainer    = document.getElementById(elementId);
    formDisplay         = formContainer.style.display;
    

    
    if (formDisplay=='' || formDisplay=='none')
    {
        formContainer.style.display='block';
        elementContainer.style.display='none';
        document.getElementById('recommend_form_status').style.display='none';
        document.getElementById('recommend_form_status').innerHTML='';        
    }
    else
    {
        formContainer.style.display='none';
        elementContainer.style.display='block';
        document.getElementById('recommend_form_status').style.display='none';
        document.getElementById('recommend_form_status').innerHTML='';        
    }
    
}

function checkRecommendForm(recommendForm)
{
    if (recommendForm.sender_name.value=='')
    {
        recommendForm.sender_name.focus();
        document.getElementById('recommend_form_status').style.display='block';
        document.getElementById('recommend_form_status').innerHTML='Podaj swoje imię';        
        return false;
    }
    else if (recommendForm.friend_name.value=='')
    {
        recommendForm.friend_name.focus();
        document.getElementById('recommend_form_status').style.display='block';
        document.getElementById('recommend_form_status').innerHTML='Podaj imię przyjaciela';        
        return false;
    }
    else if (recommendForm.friend_email.value=='')
    {
        recommendForm.friend_email.focus();
        document.getElementById('recommend_form_status').style.display='block';
        document.getElementById('recommend_form_status').innerHTML='Podaj email przyjaciela';        
        return false;
    }
    return true;
}

function addVote(vote)
{
    document.forms.vote_form.vote_value.value=vote;
    document.forms.vote_form.submit();
}

            var moving = null;   
        
            var moveBy = 5;
            
            function showImage(imageSrc) {
            	document.getElementById('realizacja_image').src=imageSrc;
            }
            
            
            function move(moveID) 
            {
                if(moving) {
                    clear_move();
                }
                moving = setInterval('move_'+moveID+'()',50);
            }    
            
            
            function move_top_left()
            {
                map = document.getElementById('map_container');
                
                map.scrollLeft  = map.scrollLeft-moveBy/2;
                map.scrollTop   = map.scrollTop-moveBy/2;
            }
            
            
            function move_top_right()
            {
                map = document.getElementById('map_container');
                
                map.scrollLeft  = map.scrollLeft+moveBy/2;
                map.scrollTop   = map.scrollTop-moveBy/2;
            }
            
            function move_bottom_left()
            {
                map = document.getElementById('map_container');
                
                map.scrollLeft  = map.scrollLeft-moveBy/2;
                map.scrollTop   = map.scrollTop+moveBy/2;
            }
            
            function move_bottom_right()
            {
                map = document.getElementById('map_container');
                
                map.scrollLeft  = map.scrollLeft+moveBy/2;
                map.scrollTop   = map.scrollTop+moveBy/2;
            }
            
            function move_bottom()
            {
                map = document.getElementById('map_container');
                map.scrollTop   = map.scrollTop+moveBy;
            }
            

            function move_top()
            {
                map = document.getElementById('map_container');
                map.scrollTop   = map.scrollTop-moveBy;
            }

            function move_right()
            {
                map = document.getElementById('map_container');
                map.scrollLeft  = map.scrollLeft+moveBy;
            }
            
            function move_left()
            {
                map = document.getElementById('map_container');
                map.scrollLeft  = map.scrollLeft-moveBy;
            }
            
            
            function clear_move()
            {
                if(moving) {
                    clearInterval(moving);
                    moving = null;
                }
                else {
                    return true;
                }
            }

function openLink(_numer)
{
	//alert(_numer)
	
	if (_numer == 1) 
	{
		//wszystkie 
		requestList();
   		//document.location="http://mm.idkonsult.net/index.php?pId=30&action=default&display=inwest"
	}
	
	if (_numer == 2)
	{
		//w sprzedarzy 1
		requestList(1);
   		//document.location="http://mm.idkonsult.net/index.php?pId=30&action=default&display=inwest&displayStatus=1"
	}
	
	if (_numer == 3) 
	{
		//planowane 3
		requestList(2);
   		//document.location="http://mm.idkonsult.net/index.php?pId=30&action=default&display=inwest&displayStatus=3"
	}

	if (_numer == 4)  
	{ 
		//sprzedane 4	
   		document.location="http://www.marketmieszkaniowy.pl/galeria.html"
	}

}

function openAddres()
{
	alert('test');
}
function roundVal(val, dig) {
    var fac = Math.pow(10, dig);
    return Math.round(val * fac) / fac;
}

function numeric(number) {
	var str = new String(number);
	var out= str.replace(/,/, '.');
	return parseFloat(out);
}


function obliczZdolnosc()
{
	
	var KK 		= document.getElementById('KK').value;
	var waluta1 	= document.getElementById('waluta1').checked;
	var waluta2 	= document.getElementById('waluta2').checked;
	var IN 		= document.getElementById('IN').value;
	var N 		= document.getElementById('N').value;
	var rata1 	= document.getElementById('rata1').checked;
	var rata2 	= document.getElementById('rata2').checked;
	var DMN 	= document.getElementById('DMN').value;
	var IO 		= document.getElementById('IO').value;
	var WUM 	= document.getElementById('WUM').value;
	var WRK 	= document.getElementById('WRK').value;
	var WUB 	= document.getElementById('WUB').value;
	var LKK 	= document.getElementById('LKK').value;
	
	
	var A =  LKK * 5 / 100;
	var B =  IO * 500;
	
	var C = parseInt(WUM) + parseInt(WRK) + parseInt(WUB) + A + B;
	var MDD  = DMN - C;
	
	
	if(waluta1 == true)
	{
		KK = parseInt(KK) + parseInt(KK * 20/100);		
	}
	var F = KK / N / 12;
	var G = KK * IN / 100 / 12;
	var PRAM =  parseInt(F) + parseInt(G);
	var X = Math.pow(  ( 1 + IN / 100 / 12 ), ( N * 12 )  );
	var PRAR = KK * X * ( ( IN / 100 / 12 ) / ( X - 1 ) );
	
	alert(KK);
	alert(PRAM);
	alert(PRAR);
	alert(MDD);
	
	
	if(rata1 == true )
	{
		var NRZ = PRAM;
	}
	if(rata2 == true )
	{
		var NRZ = PRAR;
	}
	if(MDD >= NRZ)
	{
		alert('MDD='+MDD+"\n NRZ="+NRZ);
		document.getElementById('wynik').style.display='block';
		document.getElementById('output').innerHTML='Obliczenia wykazują, że masz zdolność kredytową przy wpisanych przez Ciebie danych.<br>Skontaktuj się z nami celem przedstawienia oferty kredytowej.<br><br><a href="javascript: void=0;" onclick=" closeWynik();" >Powrót do kalkulatora</a><br><br><a href="http://mm.idkonsult.net/index.php?pId=36">FORMULARZ KONTAKTOWY</a>';
	
	}	
	if(MDD < NRZ)
	{
		alert('MDD='+MDD+"\n NRZ="+NRZ);
		document.getElementById('wynik').style.display='block';
		document.getElementById('output').innerHTML='Obliczenia wykazują, że nie masz zdolnośi kredytowej przy wpisanych przez Ciebie danych.<br>Koniecznie skontaktuj się z nami, zweryfikujemy obliczenia i poszukamy odpowiedniego dla ciebie rozwiązania.<br><br><a href="javascript: void=0;" onclick=" closeWynik();" >Powrót do kalkulatora</a><br><br><a href="http://mm.idkonsult.net/index.php?pId=36">FORMULARZ KONTAKTOWY</a>';
		
	}
	
	return false;
}
function closeWynik()
{
	document.getElementById('wynik').style.display='none';
}


function obliczRaty()
{
	
	var KK 		= document.getElementById('KK').value;
	var IN 		= document.getElementById('IN').value;
	var N 		= document.getElementById('N').value;
	
	IN = numeric(IN);
	
	
	var PRKM = KK / N / 12;
	var PRIM = KK * IN / 100 / 12;
	var PRAM = PRKM + PRIM;
	var SRKM = KK;
	var SRAM = ((PRAM + PRKM + (PRKM * (IN / 100 / 12)) ) / 2 ) * N * 12;
	var SRIM = SRAM - KK;
	
	var POT = N * 12;
	var TEST = 1 + ( IN / 100 / 12 );
	
	
	var TEST = 1 + ( IN / 100 / 12 );
	var X = Math.pow(TEST, POT);
	X = X.toPrecision(5);
	
	var DUPA =  KK * X;
	
	var CHUJ = IN / 100 / 12;
	var Y = 1 + ( IN / 100 / 12 );
	var Z = Math.pow(Y, POT);
	Z = Z.toPrecision(5);
	var CIPA = ( Z )- 1;
	CIPA = CIPA.toPrecision(5);
	var PRAR = DUPA * CHUJ / CIPA ;
	PRAR = PRAR.toPrecision(5);
	alert(PRAR);
	
	
	var PRIR = KK * IN / 100 / 12;
	var PRKR = PRAR - PRIR;
	var SRAR = PRAR * N * 12;
	var SRKR = KK;
	var SRIR = SRAR - KK;
	
	PRKM = roundVal(PRKM, 2);
	PRIM = roundVal(PRIM, 2); 
	PRAM = roundVal(PRAM, 2);
	SRKM = roundVal(SRKM, 2);
	SRIM = roundVal(SRIM, 2);
	SRAM = roundVal(SRAM, 2);
	
	PRAR = roundVal(PRAR, 2);
	PRIR = roundVal(PRIR, 2);
	PRKR = roundVal(PRKR, 2);
	SRAR = roundVal(SRAR, 2);
	SRKR = roundVal(SRKR, 2);
	SRIR = roundVal(SRIR, 2);
	
	
	
	document.getElementById('wynik').style.display='block';
	document.getElementById('output').innerHTML='<h2 class="raty">Raty malejące</h2><table border="1" class="raty" cellpadding="0" cellspacing="0"><tr>	<th>&nbsp; </th><th>Część kapitałowa raty</th><th>Część odsetkowa raty</th><th>Całkowita wysokość raty</th></tr><tr><td>Pierwsza najwyższa rata</td><td>' + PRKM + ' zł</td><td>' + PRIM + ' zł</td><td>' + PRAM + ' zł</td></tr><tr><td>Suma wszystkich rat</td><td>' + SRKM + ' zł</td><td>' + SRIM + ' zł</td><td>' + SRAM + ' zł</td></tr></table><h2 class="raty">Raty równe</h2><table border="1"  class="raty"  cellpadding="0" cellspacing="0"><tr><th>&nbsp; </th><th>Część kapitałowa raty</th><th>Część odsetkowa raty</th><th>Całkowita wysokość raty</th></tr><tr><td>Pierwsza najwyższa rata</td><td>' + PRKR + ' zł</td><td>' + PRIR + ' zł</td><td>' + PRAR + ' zł</td></tr><tr><td>Suma wszystkich rat</td><td>' + SRKR + ' zł</td><td>' + SRIR + ' </td><td>' + SRAR + ' zł</td></tr></table><br><br><br><a href="javascript: void=0;" onclick=" closeWynik();" >Powrót do kalkulatora</a><br><br><a href="http://mm.idkonsult.net/index.php?pId=36">FORMULARZ KONTAKTOWY</a>';
	
		
	
	return false;
}
function confirmDelete(delUrl) {
	if (confirm("Czy na pewno usunąć rekord??")) {
		document.location = delUrl;
	}
}

function getElementsByClassName(className, tag, elm){
	var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
	var tag = tag || "*";
	var elm = elm || document;
	var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
	var returnElements = [];
	var current;
	var length = elements.length;
	for(var i=0; i<length; i++){
		current = elements[i];
		if(testClass.test(current.className)){
			returnElements.push(current);
		}
	}
	return returnElements;
}

function switchFaq(faq_id)
{
	document.getElementById(faq_id).style.display='block';
}
