//Firefox 3
is_ff3=(function x(){})[-5]=='x';
//Firefox 2
is_ff2=(function x(){})[-6]=='x';
//IE detector I posted previously
is_ie='\v'=='v';
//Safari
is_safari=/a/.__proto__=='//';
//Chrome
is_chrome=/source/.test((/a/.toString+''));
//Opera
is_opera=/^function \(/.test([].sort);


var _cookieContactOpenerIdent = 'contactOpenerCookie';
var _contactBodyId = 'contactBody';
var _contactOpenerId = 'contactOpener';
function openerContact (co) {
    var status = getCookie(_cookieContactOpenerIdent);
    
    if(co == 2) {
        if(status == 'close') closeContact();
        else openContact();
    } else {
        if(status == 'open') {
            status = 'close';
            closeContact();
        } else {
            status = 'open';
            openContact();
        }
        
        setCookie(_cookieContactOpenerIdent, status);
    }
}

function closeContact() {
    var el = document.getElementById(_contactBodyId);
    el.style.display = 'none';
    
    var elOp = document.getElementById(_contactOpenerId);
    elOp.className = 'open';
    elOp.innerHTML = 'Rozwiń kontakt';
}
function openContact() {
    var el = document.getElementById(_contactBodyId);
    el.style.display = 'block';

    var elOp = document.getElementById(_contactOpenerId);
    elOp.className = 'close';
    elOp.innerHTML = 'Zwiń kontakt';
}


function setCurrenties(curr) {
    document.cookie= "RandallChangeCurrency=" + escape(curr);
}

function changeCurrency(lg) {
	var valueIE=0;
    
    IE7 = (navigator.appVersion.indexOf("MSIE 7.")==-1) ? false : true;
    
    // jesli 3 waluty to musi być =1 jeśli cztery to  =0
    if(IE7){
        var valueIE=0;
    }
        
    
                
	if (!document.styleSheets) return;
	var theRules = new Array();
	if (document.styleSheets[1].cssRules)
		theRules = document.styleSheets[1].cssRules
	else if (document.styleSheets[1].rules)
		theRules = document.styleSheets[1].rules
	else return;
	
	var elPLN = document.getElementById('cPLN');
	var elEUR = document.getElementById('cEUR');
	var elUSD = document.getElementById('cUSD');
	var elCHF = document.getElementById('cCHF');

	//PLN
	if(lg=='PLN') {
		theRules[theRules.length-1-valueIE].style.display = 'inline';
		theRules[theRules.length-2-valueIE].style.display = 'none';
		theRules[theRules.length-3-valueIE].style.display = 'none';
		theRules[theRules.length-4-valueIE].style.display = 'none';
        if(elPLN) {
		    elPLN.className='button active';
		    elEUR.className='button';
		    elUSD.className='button';
		    elCHF.className='button';
            
            //elPLN.style.textDecoration='underline';
            //elEUR.style.textDecoration='none';
            //elCHF.style.textDecoration='none';
            
        }
	}
	if(lg=='EUR') {
		theRules[theRules.length-1-valueIE].style.display = 'none';
		theRules[theRules.length-2-valueIE].style.display = 'inline';
		theRules[theRules.length-3-valueIE].style.display = 'none';
		theRules[theRules.length-4-valueIE].style.display = 'none';
        if(elPLN) {
		    elPLN.className='button';
		    elEUR.className='button active';
		    elUSD.className='button';
		    elCHF.className='button';
            
            //elPLN.style.textDecoration='none';
            //elEUR.style.textDecoration='underline';
            //elCHF.style.textDecoration='none';
        }
	}

	if(lg=='USD') {
		theRules[theRules.length-1-valueIE].style.display = 'none';
		theRules[theRules.length-2-valueIE].style.display = 'none';
		theRules[theRules.length-3-valueIE].style.display = 'inline';
		theRules[theRules.length-4-valueIE].style.display = 'none';
        if(elPLN) {
    		elPLN.className='button';
	    	elEUR.className='button';
		    elUSD.className='button active';
		    elCHF.className='button';
            
            //elPLN.style.textDecoration='none';
            //elEUR.style.textDecoration='none';
            //elCHF.style.textDecoration='underline';
        }
	}

	if(lg=='CHF') {
		theRules[theRules.length-1-valueIE].style.display = 'none';
		theRules[theRules.length-2-valueIE].style.display = 'none';
		theRules[theRules.length-3-valueIE].style.display = 'none';
		theRules[theRules.length-4-valueIE].style.display = 'inline';
        if(elPLN) {
    		elPLN.className='button';
	    	elEUR.className='button';
		    elUSD.className='button';
		    elCHF.className='button active';
        }
	}

	
	xajax_SetCurrency(lg);
	
    //if(document.easysearch) {
	    //xajax_QSRefreshForm(document.easysearch.typ_transakcji_nieruchomosci.selectedIndex+1);
    //}
}

function QSstartChangeType() {
	document.getElementById('QStyp').disabled = true;
	document.getElementById('QSlocal').disabled = true;
	document.getElementById('QScena').disabled = true;
}
function QSstopChangeType() {
	document.getElementById('QStyp').disabled = false;
	document.getElementById('QSlocal').disabled = false;
	document.getElementById('QScena').disabled = false;
}

function addOption(selectId, val, txt, selDef, sel) {
    var objOption = new Option(txt, val, selDef, sel);
     document.getElementById(selectId).options.add(objOption);
}



function get_typ_transakcji_nieruchomosci(typ_transakcji,typ_nieruchomosci){    
    if(typ_transakcji=='oferta wynajmu' && typ_nieruchomosci=='mieszkanie') return '3';        
    if(typ_transakcji=='oferta wynajmu' && typ_nieruchomosci=='dom') return 4;        
    if(typ_transakcji=='oferta wynajmu' && typ_nieruchomosci=='działka') return 6;        
    if(typ_transakcji=='oferta wynajmu' && typ_nieruchomosci=='sklep') return 8;        
    if(typ_transakcji=='oferta sprzedaży' && typ_nieruchomosci=='mieszkanie') return 1;        
    if(typ_transakcji=='oferta sprzedaży' && typ_nieruchomosci=='dom') return 2;        
    if(typ_transakcji=='oferta sprzedaży' && typ_nieruchomosci=='działka') return 5;        
    if(typ_transakcji=='oferta sprzedaży' && typ_nieruchomosci=='sklep') return 7;
}

function changeType_new(typ_transakcji_nieruchomosci) {
	if(typ_transakcji_nieruchomosci == 2 || typ_transakcji_nieruchomosci == 7 || typ_transakcji_nieruchomosci == 5 || typ_transakcji_nieruchomosci == 4 || typ_transakcji_nieruchomosci == 8) {
		document.getElementById('QSpokoiTR').style.display='none';
		document.getElementById('QSpowierzchniaTR').style.display='';
		//f.pokoi.value='';
	} else {
		document.getElementById('QSpokoiTR').style.display='';		
		document.getElementById('QSpowierzchniaTR').style.display='none';
		//f.powierzchnia.value='';
	}
}

function changeType(field) {
	f = field.form;

	if(field.value == 3 || field.value == 4 || field.value == 6 || field.value == 8) {
		f.typ_transakcji.value='oferta wynajmu';
	} else {
		f.typ_transakcji.value='oferta sprzedaży';
	}
	if(field.value == 1 || field.value == 3) {
		f.typ_nieruchomosci.value='mieszkanie';
	} else if (field.value == 2 || field.value == 4){
		f.typ_nieruchomosci.value='dom';
	} else if (field.value == 5 || field.value == 6){
		f.typ_nieruchomosci.value='działka';
	} else if (field.value == 7 || field.value == 8){
		f.typ_nieruchomosci.value='sklep';
	}

	
	if(field.value == 2 || field.value == 7 || field.value == 5 || field.value == 4 || field.value == 8) {
		document.getElementById('QSpokoiTR').style.display='none';
		document.getElementById('QSpowierzchniaTR').style.display='';
		//f.pokoi.value='';
	} else {
		document.getElementById('QSpokoiTR').style.display='';		
		document.getElementById('QSpowierzchniaTR').style.display='none';
		//f.powierzchnia.value='';
	}

}

function printOpt(withPic,full) {
	var basketForm = document.getElementById('basketForm');
	basketForm.withPic.value = withPic ? 1 : '';
	basketForm.full.value = full ? 1 : '';
	basketForm.submit();
}

function checkContactOblicatory (f, fieldsPrefix) {
	var error = 0;
	var emailerror = 0;
	

	if(!f[fieldsPrefix+'_tav'][0].checked && !f[fieldsPrefix+'_tav'][1].checked) {
		changeBg (f[fieldsPrefix+'_tav'][0]);
		changeBg (f[fieldsPrefix+'_tav'][1]);
		error = 1;
	} else { 
	    changeBgTr (f[fieldsPrefix+'_tav'][0]);
	    changeBgTr (f[fieldsPrefix+'_tav'][1]);
	}

	if(f[fieldsPrefix+'_voornaam'].value == '') {
		changeBg (f[fieldsPrefix+'_voornaam']);
		error = 1;
	} else changeBgTr (f[fieldsPrefix+'_voornaam'])
	if(f[fieldsPrefix+'_achternaam'].value == '') {
		changeBg (f[fieldsPrefix+'_achternaam']);
		error = 1;
	} else changeBgTr (f[fieldsPrefix+'_achternaam'])
	if(f[fieldsPrefix+'_voorletters_1'].value == '') {
		changeBg (f[fieldsPrefix+'_voorletters_1']);
		error = 1;
	} else changeBgTr (f[fieldsPrefix+'_voorletters_1'])


	
	if(f[fieldsPrefix+'_emailadres'].value == '' || !checkEmailAddress(f[fieldsPrefix+'_emailadres'])) {
		changeBg (f[fieldsPrefix+'_emailadres']);
		emailerror = 1;
	} else changeBgTr (f[fieldsPrefix+'_emailadres'])
	
	if(f[fieldsPrefix+'_uw_vraag_of_reactie'].value == '') {
		changeBg (f[fieldsPrefix+'_uw_vraag_of_reactie']);
		error = 1;
	} else changeBgTr (f[fieldsPrefix+'_uw_vraag_of_reactie'])

    
	if(error || emailerror) {
		if(error && emailerror) {
			//alert(al + ' ' +emailal);
		}
		if(error && !emailerror) {
			//alert(al);
		}
		if(!error && emailerror) {
			//alert(emailal);
		}
		return;
	} else {
		f.submit();
	}
}

function checkNewsletterOblicatory(f,action,fieldsPrefix) {

	var error = 0;
	var emailerror = 0;
	
	if(f.melden[0].checked) {
    	if(f[fieldsPrefix+'_email'].value == '' || !checkEmailAddress(f[fieldsPrefix+'_email'])) {
    		changeBg (f[fieldsPrefix+'_email']);
    		emailerror = 1;
    	} else changeBgTr (f[fieldsPrefix+'_email'])
    	
    	if(f[fieldsPrefix+'_name'].value == '') {
    		changeBg (f[fieldsPrefix+'_name']);
    		error = 1;
    	} else changeBgTr (f[fieldsPrefix+'_name'])
    
    	if(f[fieldsPrefix+'_surname'].value == '') {
    		changeBg (f[fieldsPrefix+'_surname']);
    		error = 1;
    	} else changeBgTr (f[fieldsPrefix+'_surname'])
    
    	if(!f[fieldsPrefix+'_sex'][0].checked && !f[fieldsPrefix+'_sex'][1].checked) {
    		changeBg (f[fieldsPrefix+'_sex'][0]);
    		changeBg (f[fieldsPrefix+'_sex'][1]);
    		error = 1;
    	} else { 
    	    changeBgTr (f[fieldsPrefix+'_sex'][0]);
    	    changeBgTr (f[fieldsPrefix+'_sex'][1]);
    	}
    }
	if(f.melden[1].checked) {
    	if(f[fieldsPrefix+'_email'].value == '' || !checkEmailAddress(f[fieldsPrefix+'_email'])) {
    		changeBg (f[fieldsPrefix+'_email']);
    		emailerror = 1;
    	} else changeBgTr (f[fieldsPrefix+'_email'])
    }
    
	if(error || emailerror) {
		if(error && emailerror) {
			//alert(al + ' ' +emailal);
		}
		if(error && !emailerror) {
			//alert(al);
		}
		if(!error && emailerror) {
			//alert(emailal);
		}
		return;
	} else {
	    f.nbaction.value = action
		f.submit();
	}

}

function checkNewsletterForm(f) {
    var anDiv = document.getElementById ('Aanmelden');
    var afDiv = document.getElementById ('Afmelden');
    if(f.melden[0].checked) {
        anDiv.style.display = 'block';
        afDiv.style.display = 'none';
    } else if (f.melden[1].checked) {
        anDiv.style.display = 'none';
        afDiv.style.display = 'block';
    } else {
        anDiv.style.display = 'none';
        afDiv.style.display = 'none';
    }
    if(f.melden[0].checked) {
        anDiv.style.visibility = 'visible';
        afDiv.style.visibility = 'hidden';
    } else if (f.melden[1].checked) {
        anDiv.style.visibility = 'hidden';
        afDiv.style.visibility = 'visible';
    } else {
        anDiv.style.visibility = 'hidden';
        afDiv.style.visibility = 'hidden';
    }

}

function blankGoTo (l) {
    window.open(l);
}

function goTo (l) {
	location.href=l;
}

function changeBg (el) {
	el.style.backgroundColor = '#ffaaaa';
}
function changeBgTr (el) {
	el.style.backgroundColor = 'white';
}

function movieWindow(urlImg, title, width, height) {   
	var width = parseInt(width);
	var height = parseInt(height);
	var width = (isNaN(width) ? 420 : width+20);
	var height = (isNaN(height) ? 420 : height+20);
 
	var Win = window.open('',"",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=no, menubar=no, left=350, top=100' );
	Win.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>'+title+'</title></head><body style="background-color:navy" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">');
	
	Win.document.write('<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align=center><table bgcolor="white" style="padding:4px;border:silver 1px solid"><tr><td><embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/MediaPlayer/" SRC="'+urlImg+'" name="wmp" SHOWCONTROLS="1" SHOWDISPLAY="0" AutoStart="true"></embed></td></tr></table></td></tr></table>');
	Win.document.write('</body></html>');
	
};


function imageWindow(urlImg, title, width, height) {   
	var width = parseInt(width);
	var height = parseInt(height);
	var width = (isNaN(width) ? 420 : width+20);
	var height = (isNaN(height) ? 420 : height+20);
 
	var Win = window.open('',"",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=no, menubar=no, left=350, top=100' );
	Win.document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><title>'+title+'</title></head><body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">');
	
	Win.document.write('<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align=center><table style="padding:4px;border:silver 1px solid"><tr><td><a href="javascript:self.close();"><img src="'+urlImg+'" alt="" border="0"></a></td></tr></table></td></tr></table>');
	Win.document.write('</body></html>');
	
};

function win(url, title, width, height) {   
	var width = parseInt(width);
	var height = parseInt(height);
	var width = (isNaN(width) ? 420 : width+20);
	var height = (isNaN(height) ? 420 : height+20);
 
	var Win = window.open(url,"",'width=' + width + ',height=' + height + ',resizable=0,scrollbars=no, menubar=no, left=350, top=100' );
	
};

function checkEmailAddress(field) {
	var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,4}))$)\b/gi);
	
	if (goodEmail){
	  return true
	} else {
    field.focus()
    field.select()
    return false
  }
}



function sprawdzemail(adres){
	a = adres.value.search(/@/i);
	a1 = adres.value.substring(0,a);
	a2 = a1.length;
	a = a + 1;
	b = adres.value.indexOf(".");
	b1 = adres.value.substring(a,b);
	b2 = b1.length;
	b = b + 1;
	c = adres.value.length;
	c1 = adres.value.substring(b,c);
	c2 = c1.length;
	if(adres.value.indexOf("@") != "-1" && adres.value.indexOf(".") != "-1" && a2 >= 1 && b2 >= 1 && c2 >= 1){
		return true;
	}else{
		return false;
	}
}

function sprawdzemail2(adres){
	a = adres.search(/@/i);
	a1 = adres.substring(0,a);
	a2 = a1.length;
	a = a + 1;
	b = adres.indexOf(".");
	b1 = adres.substring(a,b);
	b2 = b1.length;
	b = b + 1;
	c = adres.length;
	c1 = adres.substring(b,c);
	c2 = c1.length;
	if(adres.indexOf("@") != "-1" && adres.indexOf(".") != "-1" && a2 >= 1 && b2 >= 1 && c2 >= 1){
		return true;
	}else{
		return false;
	}
}
