function tops_showCoupleRelatedFields(item){
	var f = document.getElementById('regForm');
		if (item.value >= 3){
			document.getElementById('person_login').style.display = 'none';
			document.getElementById('couple_login').style.display = '';
		} else {
			document.getElementById('person_login').style.display = '';
			document.getElementById('couple_login').style.display = 'none';
		}
}
function tpladd2(){
	var cont = document.getElementsByName('body')[0];
	var fs = document.getElementById('tplSelector');
	var val = fs.options[fs.selectedIndex].value;
	var val = document.getElementById('tpl'+val).innerHTML;
	cont.value += nl2br(val);
}
function nl2br(text){
newtext="";
	for(i=0;i<text.length;i++){
		if(text.charCodeAt(i)==10){
			newtext+="<br/>";
		}else{
			newtext +=text.substring(i,i+1);
		}
	}
	return newtext;
//text=escape(text);
//return unescape(text.replace(/(%5Cr%5Cn)|(%5Cn%5Cr)|%5Cr|%5Cn/g,"<br />"));
}
function tops_regFormSubmit(){
        var f = document.getElementById('regForm');
        var status = true;

        reEmail=/.+\@.+\...+/;
        val=0;
		for(t_i=0;t_i<f.type.length;t_i++){
			if(f.type[t_i].checked){
				val = f.type[t_i].value;
			}
		}
		if (val==0 ){ alert(translate('RegisterSelectType')); status = false; return false; } 

        if (f.login.value == ''){ alert(translate('RegisterEnterLogin')); status = false; return false}
    	
        if (f.mail.value == ''){ alert(translate('RegisterEnterEmail')); status = false; return false}
        
        if (!f.Agreement.checked){ alert(translate('RegisterAgreement')); status = false; return false}
    	
		if (!f.Adult.checked){ alert(translate('RegisterAdult')); status = false; return false}
    			
    	if (f.mail.value != f.mail2.value){ alert(translate('RegisterEmailMissmath')); status = false; return false}
		
		if (reEmail.test(f.mail.value) !=true || f.mail.value.length < 6) { alert(translate('RegisterEmailNotValid')); status = false; return false;}

        if (f.pass1.value == ''){ alert(translate('RegisterEnterPassword')); status = false; return false}
        if (f.pass1.value != f.pass2.value){ alert(translate('RegisterPasswordMissmath')); status = false; return false}
        if (f.pass1.value.length < 3){ p = new Array(); alert(translate('RegisterPasswordShortenThat', '3|2')); status = false; return false}

    	if(parseInt(f.type[f.type.selectedIndex].value) > 2){
	        if (f.pass1c.value == ''){ alert(translate('RegisterEnterPassword')); status = false; return false}
	        if (f.pass1c.value.length < 3 || f.pass2c.value.length < 3){ p = new Array(); alert(translate('RegisterPasswordShortenThat', '3|2')); status = false; return false}
	        if (f.pass1c.value != f.pass2c.value){ alert(translate('RegisterPasswordMissmath')); status = false; return false}
	        if (f.pass1.value == f.pass1c.value){ alert(translate('RegisterPasswordSame')); status = false; return false}
    	}

        if (status == true) {
        	f.submit();
        }
    }
function tops_reg2FormSubmit(){
	 	var f = document.getElementById('reg2Form');
        var status = true;

       
   
        if (f.fname.value == ''){
            alert(translate('RegisterEnterFirstName'));
            status = false;
            return false;
        }
        
        if (f.fname2 && f.fname2.value == ''){
            alert(translate('RegisterEnterPartnersName'));
            status = false;
            return false;
        }        
        
        if (f.city2.value == '' && f.city.value=='null'){
            alert(translate('RegisterEnterCity'));
            status = false;
            return false;
        }
       

		//ak 26.11
        if (f.country.options[f.country.selectedIndex].text=='Polska' && f.region[f.region.selectedIndex].value == 'null'){
            alert(translate('RegisterEnterRegion'));
            status = false;
            return false;
        }
        
        if (f.country[f.country.selectedIndex].value == ''){
            alert(translate('RegisterSelectCountry'));
            status = false;
            return false;
        }

//ak 26.11
//         if (f.regionOther.disabled != true && f.regionOther.value == ''){
//             alert(translate('RegisterEnterOtherRegion'));
//             status = false;
//             return false;
//         }
        
        if(status == true){
        	 if(f.city2.value!='null'){
        			f.city.value=f.city2.value;
			}
            f.submit();
        }
}
function cityChange(item){
	var cityName = item[item.selectedIndex].value;
	var f = document.getElementById('reg2Form');
	f.city.value = cityName;
}
function cityNotExist(item){
	var f = document.getElementById('citySelect');
	var f2 = document.getElementById('cityWrite');
	f.style.display = 'none';
	f2.style.display = 'block';
}
function tops_mailFormSubmit(){
	 var f = document.getElementById('mailForm');
	var tops_from = document.getElementById('from').value;
	var tops_subject = document.getElementById('subject').value;
	var tops_body = document.getElementById('body').value;
	var status=true;
	if(tops_from.length<3){
		alert('Za krótki adres e-mail'); status=false;
	}
	if(tops_subject.length<3){
		alert('Za krótki temat'); status=false;
	}
	if(tops_body.length<50){
		alert('Za krótka treść'); status=false;
	}
	if (status == true) {
        	f.submit();
        }
}
function tops_checkAllSpamers(){
	els = document.getElementsByName('spamers[]');
	for(i=0;i<els.length;i++){
		els[i].checked=true;
	}
}
function tops_smiliesFormSubmit(){
	var f = document.getElementById('smiliesForm');
	var els = document.getElementsByName('spamers[]');
	var status=false;
	for(i=0;i<els.length;i++){
		if(els[i].checked==true || els[i].checked=="checked"){
			status=true;
		}
	}
	if(status==false){
		alert('nie wybrano spamerów');
	}
	if (status == true) {
        	f.submit();
        }
}

function reakcja(zdarzenie) {
 if(!zdarzenie.keyCode){
	return;
 }
 var klawisz=zdarzenie.keyCode ? zdarzenie.keyCode : zdarzenie.charCode;
 control = zdarzenie.ctrlKey;
 if(control){
 		return false;
	}
 return true;
}
/*function tops_changeRegion(item){
	woj_id = item.value;
	cityS = document.getElementById('citySelector');
	if(woj_id!='null'){
		cityS.disabled=false;
		cityS.selectedIndex=0;
		for(i=1;i<cityS.length;i++){
			if(cityS[i].id!='woj'+woj_id){
				cityS[i].style.display='none';
			}else{
				cityS[i].style.display='block';
			}
		}
	}else{
		cityS.disabled=true;
	}
}*/
alloptions = Array();
function set_alloptions(){
	cityS = document.getElementById('citySelector');
	for(i=1;i<cityS.length;i++){
		alloptions[i] = cityS.options[i];
	}
}

function tops_changeRegion(item){
	woj_id = item.value;
	cityS = document.getElementById('citySelector');
	if(woj_id!='null'){
		cityS.disabled=false;
		cityS.selectedIndex=0;
		for(i=1;i<1000;i++){
			cityS.options[1] = null;
		}
		k=1;
		for(i=1;i<898;i++){
			if(alloptions[i].id =='woj'+woj_id){
				cityS.options[k] = alloptions[i];
				k++;
			}
		}
	}else{
		cityS.disabled=true;
	}
}
function tops_changeCountry(item){
    var f = document.getElementById('reg2Form');
	selind = item.selectedIndex;
	if(selind!=0){
		document.getElementById('citySelect').style.display='none';
		document.getElementById('wojewodztwo').style.visibility='hidden';
		document.getElementById('cityWrite').style.display='block';
		
	}else{
		document.getElementById('citySelect').style.display='block';
		document.getElementById('wojewodztwo').style.visibility='visible';
		document.getElementById('cityWrite').style.display='none';
	}
	if(f){
		f.city.value='';
		f.city2.value='null';
	}else{
		 var f = document.getElementById('profileEditForm');
		 f.city.value='';
		 f.city2.value='null';
		
	}
}

