var youtubeRE = /(http:\/\/)?([a-zA-Z]+.)?youtube.com\/watch\?v=([\w-]+)/;
var gvRE = /(http:\/\/)?video.google.com\/videoplay\?docid=([\w-]+)/;
var flickrRE = /http:\/\/.*?\.flickr.com\/.*/;
var photobucketRE = /http:\/\/.*?\.flickr.com\/.*/;

var Edu_maxLen_specialization = 255;
var Edu_maxLen_city = 255;
var Edu_maxLen_state = 255;
var Edu_maxLen_im = 150;
var maxScCou = maxColCou = maxOrgCou = maxEmCou = maxImCou = 5;

var getOptDay = function(){
	var d = '';
	for(i=1; i<=31; i++){
		d += "<option value='"+i+"'>"+i+"</option>";
	}
	return d;
}

var getOptMonth = function(){
	var m = '';
	for(i=1; i<=12; i++){
		m += "<option value='"+i+"'>"+i+"</option>";
	}
	return m;
}

var getOptYear = function(){
	var currentDate = new Date()
	var year = currentDate.getFullYear();
	var y = '';
	for(i=year; i>=1900; i--){
		y += "<option value='"+i+"'>"+i+"</option>";
	}
	return y;
}

var callType = function (type){
	switch(type){
		case 'em': makeEm('emTable'); break;
		case 'im': makeIm('imTable'); break;
		case 'pf': makePf('pfTable'); break;
		case 'sc': makeSc('scTable'); break;
		case 'co': makeCo('coTable'); break;
	}
}

var makeEm = function (id){
		var table=$(id);
		var cou = $('emCou').value;
		if(cou > maxEmCou) return false;
		cou++;
		var row=table.insertRow(-1);
		var cell=row.insertCell(-1);
		cell.innerHTML ="<input class='searchbox' type='text' name='em[]' value='' maxlength="+Edu_maxLen_im+" />";
		$('emCou').value = cou;
		if(cou == maxEmCou) {
			$('callTypeTableRow').style.display = 'none';
		}
}

var makeIm = function (id){
		var table=$(id);
		var cou = $('imCou').value;
		if(cou > maxImCou) return false;
		cou++;
		var row=table.insertRow(-1);
		var cell=row.insertCell(-1);
		var input = "";
		input+="<input class='searchbox' type='text' name='im[]' value='' maxlength="+Edu_maxLen_im+" />&nbsp;&nbsp;";
		input+="<select class='searchbox' name='domain[]'>";
		input+=$('domain').innerHTML;
		input+="</select>";
		cell.innerHTML=input;
		$('imCou').value = cou;
}

var makePf = function (id){
		var table = $(id);
		var cou = $('cou').value;
		if(cou >= maxOrgCou) return false;
		cou++;

		var row1 = table.insertRow(-1);
		var cell1 = row1.insertCell(-1); cell1.innerHTML = "&nbsp;";
		cell1.setAttribute('colspan','2');

		var row2 = table.insertRow(-1);
		var cell1 = row2.insertCell(-1); cell1.innerHTML = "Nazwa";
		cell1.setAttribute('class','right');
		cell1.setAttribute('valign','top');
		var cell2 = row2.insertCell(-1); cell2.innerHTML = "<input class='searchbox'type='text' name='org["+cou+"][orgName]' value='' />";

		var row3 = table.insertRow(-1);
		var cell1 = row3.insertCell(-1); cell1.innerHTML = "O Tobie";
		cell1.setAttribute('class','right'); cell1.setAttribute('valign','top');
		var cell2 = row3.insertCell(-1); cell2.innerHTML = "<input class='searchbox' type='text' name='org["+cou+"][designation]' value='' maxlength="+Edu_maxLen_specialization+" />";

		var row4 = table.insertRow(-1);
		var cell1 = row4.insertCell(-1); cell1.innerHTML = "Opis Twojej pracy";
		cell1.setAttribute('class','right'); cell1.setAttribute('valign','top');
		var cell2 = row4.insertCell(-1); cell2.innerHTML = "<textarea class='searchbox' name='org["+cou+"][description]'></textarea>";

		var row5 = table.insertRow(-1);
		var cell1 = row5.insertCell(-1); cell1.innerHTML = "Kraj";
		cell1.setAttribute('class','right'); cell1.setAttribute('valign','top');
		var cell2 = row5.insertCell(-1);
		var country = "<select class='searchbox' name='org["+cou+"][country]'>";
		country+=$('country').innerHTML;
		country+="</select>";
		cell2.innerHTML = country;

		var row6 = table.insertRow(-1);
		var cell1 = row6.insertCell(-1); cell1.innerHTML = "Miasto";
		cell1.setAttribute('class','right'); cell1.setAttribute('valign','top');
		var cell2 = row6.insertCell(-1); cell2.innerHTML = "<input class='searchbox' type='text' name='org["+cou+"][city]' value='' maxlength="+Edu_maxLen_city+" />";

		var row7 = table.insertRow(-1);
		var cell1 = row7.insertCell(-1); cell1.innerHTML = "Województwo";
		cell1.setAttribute('class','right'); cell1.setAttribute('valign','top');
		var cell2 = row7.insertCell(-1); cell2.innerHTML = "<input class='searchbox' type='text' name='org["+cou+"][state]' value='' maxlength="+Edu_maxLen_state+" />";

		var row8 = table.insertRow(-1);
		var cell1 = row8.insertCell(-1); cell1.innerHTML = "Od";
		cell1.setAttribute('class','right'); cell1.setAttribute('valign','top');
		var cell2 = row8.insertCell(-1);
		var startMonth = "<select id='frmStartMonth"+cou+"' class='searchbox' name='org["+cou+"][startMon]'>";
		startMonth+='<option value="">MM</option>';
		startMonth+=getOptMonth();
		startMonth+="</select>";
		var startYear = "<select id='frmStartYear"+cou+"' class='searchbox' name='org["+cou+"][startYear]'>";
		startYear+='<option value="">YYYY</option>';
		startYear+=getOptYear();
		startYear+="</select>";
		var endMonth = "<select id='toEndMonth"+cou+"' class='searchbox' name='org["+cou+"][endMon]'>";
		endMonth+='<option value="">MM</option>';
		endMonth+=getOptMonth();
		endMonth+="</select>";
		var endYear = "<select id='toEndYear"+cou+"' class='searchbox' name='org["+cou+"][endYear]' onchange=\"presentDate('toEndYear"+cou+"', 'toEndMonth"+cou+"');\">";
		endYear+='<option value="">YYYY</option>';
		endYear+='<option value="0">Do teraz</option>';
		endYear+=getOptYear();
		endYear+="</select>";
		cell2.innerHTML = startMonth+"&nbsp;"+startYear+"&nbsp;&nbsp;Do&nbsp;&nbsp;"+endMonth+"&nbsp;"+endYear;

		$('cou').value = cou;
}

var makeSc = function (id){
		var table = $(id);
		var cou = $('scCou').value;
		if(cou >= maxScCou) return false;
		cou++;


		var row1 = table.insertRow(-1);
		var cell1 = row1.insertCell(-1); cell1.innerHTML = "&nbsp;";
		cell1.setAttribute('colspan','2');

		var row2 = table.insertRow(-1);
		var cell1 = row2.insertCell(-1); cell1.innerHTML = "Nazwa";
		cell1.setAttribute('class','right'); cell1.setAttribute('valign','top');
		var cell2 = row2.insertCell(-1); cell2.innerHTML = "<input class='searchbox' type='text' name='school["+cou+"][orgName]' value='' />";

		var row3 = table.insertRow(-1);
		var cell1 = row3.insertCell(-1); cell1.innerHTML = "Kraj";
		cell1.setAttribute('class','right'); cell1.setAttribute('valign','top');
		var cell2 = row3.insertCell(-1);
		var country = "<select class='searchbox' name='school["+cou+"][country]'>";
		country+=$('country').innerHTML;
		country+="</select>";
		cell2.innerHTML = country;

		var row4 = table.insertRow(-1);
		var cell1 = row4.insertCell(-1); cell1.innerHTML = "Miasto";
		cell1.setAttribute('class','right'); cell1.setAttribute('valign','top');
		var cell2 = row4.insertCell(-1); cell2.innerHTML = "<input class='searchbox' type='text' name='school["+cou+"][city]' value='' maxlength="+Edu_maxLen_city+" />";

		var row5 = table.insertRow(-1);
		var cell1 = row5.insertCell(-1); cell1.innerHTML = "Województwo";
		cell1.setAttribute('class','right'); cell1.setAttribute('valign','top');
		var cell2 = row5.insertCell(-1); cell2.innerHTML = "<input class='searchbox' type='text' name='school["+cou+"][state]' value='' maxlength="+Edu_maxLen_state+" />";

		var row6 = table.insertRow(-1);
		var cell1 = row6.insertCell(-1); cell1.innerHTML = "Rok";
		cell1.setAttribute('class','right'); cell1.setAttribute('valign','top');
		var cell2 = row6.insertCell(-1);
		var startYear = "<select class='searchbox' name='school["+cou+"][startDate]'>";
		startYear+='<option value="">YYYY</option>';
		startYear+=getOptYear();
		startYear+="</select>";
		var endYear = "<select class='searchbox' name='school["+cou+"][endDate]'>";
		endYear+='<option value="">YYYY</option>';
		endYear+='<option value="0">Do teraz</option>';
		endYear+=getOptYear();
		endYear+="</select>";
		cell2.innerHTML = startYear+"&nbsp;&nbsp;Do&nbsp;&nbsp;"+endYear;

		$('scCou').value = cou;
		if(cou == maxScCou) {
			$('callTypeYourSchoolTableRow').style.display = 'none';
		}

}

var makeCo = function (id){
		var table = $(id);
		var cou = $('coCou').value;
		if(cou >= maxColCou) return false;
		cou++;


		var row1 = table.insertRow(-1);
		var cell1 = row1.insertCell(-1); cell1.innerHTML = "&nbsp;";
		cell1.setAttribute('colspan','2');

		var row2 = table.insertRow(-1);
		var cell1 = row2.insertCell(-1); cell1.innerHTML = "Nazwa";
		cell1.setAttribute('class','right'); cell1.setAttribute('valign','top');
		var cell2 = row2.insertCell(-1); cell2.innerHTML = "<input class='searchbox' type='text' name='college["+cou+"][orgName]' value='' />";

		var row3 = table.insertRow(-1);
		var cell1 = row3.insertCell(-1); cell1.innerHTML = "Specjalizacja";
		cell1.setAttribute('class','right'); cell1.setAttribute('valign','top');
		var cell2 = row3.insertCell(-1); cell2.innerHTML = "<input class='searchbox' type='text' name='college["+cou+"][description]' value='' maxlength="+Edu_maxLen_specialization+" />";

		var row4 = table.insertRow(-1);
		var cell1 = row4.insertCell(-1); cell1.innerHTML = "Kraj";
		cell1.setAttribute('class','right'); cell1.setAttribute('valign','top');
		var cell2 = row4.insertCell(-1);
		var country = "<select class='searchbox' name='college["+cou+"][country]'>";
		country+=$('country').innerHTML;
		country+="</select>";
		cell2.innerHTML = country;

		var row5 = table.insertRow(-1);
		var cell1 = row5.insertCell(-1); cell1.innerHTML = "Miasto";
		cell1.setAttribute('class','right'); cell1.setAttribute('valign','top');
		var cell2 = row5.insertCell(-1); cell2.innerHTML = "<input class='searchbox' type='text' name='college["+cou+"][city]' value='' maxlength="+Edu_maxLen_city+" />";

		var row6 = table.insertRow(-1);
		var cell1 = row6.insertCell(-1); cell1.innerHTML = "Województwo";
		cell1.setAttribute('class','right'); cell1.setAttribute('valign','top');
		var cell2 = row6.insertCell(-1); cell2.innerHTML = "<input class='searchbox' type='text' name='college["+cou+"][state]' value='' maxlength="+Edu_maxLen_state+" />";

		var row7 = table.insertRow(-1);
		var cell1 = row7.insertCell(-1); cell1.innerHTML = "Rok";
		cell1.setAttribute('class','right'); cell1.setAttribute('valign','top');
		var cell2 = row7.insertCell(-1);
		var startYear = "<select class='searchbox' name='college["+cou+"][startDate]'>";
		startYear+='<option value="">YYYY</option>';
		startYear+=getOptYear();
		startYear+="</select>";
		var endYear = "<select class='searchbox' name='college["+cou+"][endDate]'>";
		endYear+='<option value="">YYYY</option>';
		endYear+='<option value="0">Do teraz</option>';
		endYear+=getOptYear();
		endYear+="</select>";
		cell2.innerHTML = startYear+"&nbsp;&nbsp;Do&nbsp;&nbsp;"+endYear;

		$('coCou').value = cou;
		if(cou == maxColCou) {
			$('callTypeYourCollegeTableRow').style.display = 'none';
		}
}

function hideNshow(){
	var idArray = new Array('marTo', 'marDate', 'marPlace');
	if($('married').checked || $('divorced').checked){
		for(i=0; i<idArray.length; i++)
			$(idArray[i]).style.display = '';
	}
	else{
		for(i=0; i<idArray.length; i++)
			$(idArray[i]).style.display = 'none';
	}
}

function callDelete(pcid, ouid, wuid){
	if(confirm('Czy na pewno chcesz skasować ten komentarz?')){
		$('deleteId').value = pcid;
		$('ouid').value = ouid;
		$('wuid').value = wuid;
		document.deleteCommentForm.submit();
	}
	else return false;
}

function callMsgDelete(mid, ouid, suid){
	if(confirm('Czy na pewno chcesz skasować tą wiadomość? ')){
		$('deleteId').value = mid;
		$('ownerUid').value = ouid;
		document.messageForm.submit();
	}
	else return false;
}

function threadDelete(nid, did, tdid){
  if(confirm('Czy na pewno chcesz skasować tą odpowiedź?')){
		$('Dtdid').value = tdid;
		$('Dnid').value = nid;
		$('Ddid').value = did;
		document.threadDelForm.submit();
	}
	else return false;
}

function callHistoryDelete(fnid, hsid, hid){
	if(confirm('Czy na pewno chcesz skasować tą część rodzinnej historii?')){
		$('deletefnid').value = fnid;
		$('deletehsid').value = hsid;
		$('deletehid').value = hid;
		document.historyForm.submit();
	}
	else return false;
}

function msgDelete(mid, ouid, suid){
	if(confirm('Czy na pewno chcesz skasować tą wiadomość? ')){
		$('messDeleteId').value = mid;
		$('messOwnerUid').value = ouid;
		$('messSenderUid').value = suid;
		document.profileMessageForm.submit();
	}
	else return false;
}

function callAnecApprove(tid, ouid, suid, bool){
	$('tid').value = tid;
	$('isA').value = bool;
	$('appSenderUid').value = suid;
	$('appOwnerUid').value = ouid;
	document.anecForm.submit();
}

function callAnecDelete(tid){
	if(confirm('Czy na pewno chcesz usunąć tą anegdotę?')){
		$('dtid').value = tid;
		document.anecForm.submit();
	}
	else return false;
}

function callDeletePhoto(pid, aid, albc, npid){
	if(confirm('Czy na pewno chcesz usunąć to zdjęcie?')){
		$('delPid').value = pid;
		$('aid').value = aid;
		$('albC').value = albc;
		$('nexPid').value = npid;
		document.singlePhoto.submit();
	}
	else return false;
}

function checkAllBox(elementName, chk1, chk2){
	var qq = document.getElementsByName(elementName);
	$(chk1).checked = $(chk1).checked == false ? 	false : true;
	$(chk2).checked = $(chk1).checked == false ? 	false : true;
	for(i=0; i<qq.length; i++){
		qq[i].checked = ($(chk1).checked == false && $(chk2).checked == false) ? false : true;
	}
}

function callFrnzReject(url, fid){
	data='inviterUid='+fid;
	sendData(url, data, 1);
}

function callInvDel(url, invid){
	data='invId='+invid;
	sendData(url, data, 1);
}

function reinvite(url, invid, email){
	data='invId='+invid+'&email='+email;
	sendData(url, data, 1);
}

function rein(elementName){
	var qq = document.getElementsByName(elementName);
	var fl = 0;
	for(i=0; i<qq.length; i++){
		if(qq[i].checked == true){
			val = qq[i].value;
			$('email'+val).checked = true;
			fl = 1;
		}
	}
	if(fl==1){
		if(confirm('Czy na pewno chcesz ponownie zaprosić wybranych znajomych?')){
			$('type').value = 'zaproś ponownie';
			submitForm('allInvForm');
		}
		else
			return false;
	}
	else{
		alert('Wybierz co najmniej jedno zaproszenie')
		return false;
	}
}

var closeApproveBox = function(item){
	hw = document.getElementsByName('how[]');
	for(i=0; i<hw.length; i++) hw[i].checked = false;
	$(item).style.display = 'none';
}

var submitForm = function(frm){
	eval('document.'+frm+'.submit();');
}

var chkNDelete = function(elementName){
	var qq = document.getElementsByName(elementName);
	var fl = 0;
	for(i=0; i<qq.length; i++){
		if(qq[i].checked == true){
			fl =1; break;
		}
	}
	if(fl==1){
		if(confirm('Czy na pewno chcesz usunąć wybrane wiadomości?')){
			submitForm('allMsgsForm');
		}
		else
			return false;
	}
	else{
		alert('Wybierz przynajmniej jedną wiadomość.')
		return false;
	}
}

var invDel = function(elementName){
	var qq = document.getElementsByName(elementName);
	var fl = 0;
	for(i=0; i<qq.length; i++){
		if(qq[i].checked == true){
			fl =1; break;
		}
	}
	if(fl==1){
		if(confirm('Czy na pewno chcesz usunąć wybrane zaproszenia?')){
			submitForm('allInvForm');
		}
		else
			return false;
	}
	else{
		alert('Wybierz co najmniej jedno zaproszenie')
		return false;
	}
}

function loadingBox(status, message, toid, item){
	if(status == 0){
		closeLoadingBox(item);
		return;
	}
	div = '<div id="'+item+'">'+message+'</div>';
	$('loader').innerHTML = div;
	$('loader').style.display = 'block';
}

function closeLoadingBox(item){
	$('loader').innerHTML = '';
	$('loader').style.display = 'none';
	//$(item).remove();
}

function getRelation(uid1){
	if($('fp'+uid1) && $('fp'+uid1).innerHTML != '' ){
		h = 'Twoje powiązania';
		b = $('fp'+uid1).innerHTML;
		aBox({header: h, body: b, footer: { button:[{text:'ok'}]} });
	}
	else{
		var e = new Element('div',{'id':'fp'+uid1});
		$('myCache').innerHTML+='<div id="fp'+uid1+'"></div>';
		addScript(appsUrl+'Relation/findPath/'+uid1);
		loadingBox(1, 'Ładowanie...', 'body', 'loadBox');
	}
}

function sendNoticeComments(){
	if($('comment').value == ''){ $('error').innerHTML = 'Dodaj swój komentarz'; return false; }
	data = '';
	data+= 'fnid=' + $('fnid').value + '&nid=' + $('nid').value + '&owneruid=' + $('owneruid').value + '&comment=' + $('comment').value;
	sendData(baseUrl+'NoticeBoard/writeComment', data, 1);
}

function callNoticeCommentDelete(ncid, nid, fnid){
	data = '';
	data+='ncid=' + ncid + '&nid=' + nid + '&fnid=' + fnid;
	sendData(baseUrl+'NoticeBoard/deleteComment', data, 1);
}

function deleteNotice(fnid, nid){
	if(confirm("Czy na pewno chcesz usunąć to ogłoszenie?")){
		data = '';
		data+='fnid=' + fnid + '&nid=' + nid;
		sendData(baseUrl+'NoticeBoard/deleteNotice', data, 1);
	}
}

var addmoreUploads = function(){
	var tab = '';
	var counter = +($('counter').value);
	for(i=1; i<=2; i++){
		counter++;
		tab+='&nbsp;'+counter+'.&nbsp;<input name="up[]" type="file" style="color:#999999;font-size:11px;" value="" size="65" /><br/><br/>';
	}
	$('uploaderDiv'+counter).innerHTML+=tab;
	$('counter').value = counter;
	if(counter == 4) $('more').innerHTML = '';
}

var archives = function(){
	if($('archivesTable').style.display == 'none'){
		$('archivesTable').style.display = 'inline';
		$('arcId').innerHTML = 'Ukryj wszystkie';
	}
	else{
		$('archivesTable').style.display = 'none';
		$('arcId').innerHTML = 'Pokaż wszystkie';
	}
}


function show_spinner(id) {
		$(id).style.display="inline";
		$(id).innerHTML="Dodaj...";
}

function getProfile(item, uid){
	switch(item){
		case 'personal':
					if($('divPersonal') && $('divPersonal').innerHTML == '')
						sendData(baseUrl+'Profile/feed/personal/'+uid);
					else
						$('profileHolder').innerHTML = $('divPersonal').innerHTML;
					$('personalHead').addClass('blacklink');
					$('educationalHead').removeClass('blacklink');
					$('professionalHead').removeClass('blacklink');
					$('interestsHead').removeClass('blacklink');
					$('contactHead').removeClass('blacklink');
					break;
		case 'educational':
					if($('divEducational') && $('divEducational').innerHTML == '')
						sendData(baseUrl+'Profile/feed/educational/'+uid);
					else
						$('profileHolder').innerHTML = $('divEducational').innerHTML;
					$('educationalHead').addClass('blacklink');
					$('personalHead').removeClass('blacklink');
					$('professionalHead').removeClass('blacklink');
					$('interestsHead').removeClass('blacklink');
					$('contactHead').removeClass('blacklink');
					break;
		case 'professional':
					if($('divProfessional') && $('divProfessional').innerHTML == '')
						sendData(baseUrl+'Profile/feed/professional/'+uid);
					else
						$('profileHolder').innerHTML = $('divProfessional').innerHTML;
					$('professionalHead').addClass('blacklink');
					$('educationalHead').removeClass('blacklink');
					$('personalHead').removeClass('blacklink');
					$('interestsHead').removeClass('blacklink');
					$('contactHead').removeClass('blacklink');
						break;
		case 'interests':
					if($('divInterests') && $('divInterests').innerHTML == '')
						sendData(baseUrl+'Profile/feed/interests/'+uid);
					else
						$('profileHolder').innerHTML = $('divInterests').innerHTML;
					$('interestsHead').addClass('blacklink');
					$('educationalHead').removeClass('blacklink');
					$('personalHead').removeClass('blacklink');
					$('professionalHead').removeClass('blacklink');
					$('contactHead').removeClass('blacklink');
					break;
		case 'contact':
					if($('divContact') && $('divContact').innerHTML == '')
						sendData(baseUrl+'Profile/feed/contact/'+uid);
					else
						$('profileHolder').innerHTML = $('divContact').innerHTML;
					$('contactHead').addClass('blacklink');
					$('educationalHead').removeClass('blacklink');
					$('personalHead').removeClass('blacklink');
					$('professionalHead').removeClass('blacklink');
					$('interestsHead').removeClass('blacklink');
					break;
	}
}

function photoStream(uid, aid, page){
	offset = 7 * page;
	if($('pc'+offset) && $('pc'+offset).innerHTML != '')
		$('streamBox').innerHTML = $('pc'+offset).innerHTML;
	else
		sendData(baseUrl+'Photos/photoStream/'+uid+'/'+aid+'/'+page);
}

function presentDate(year, month){
	if($(year).value == '0'){
		$(month).disabled = true;
		$(month).value = "";
	}
	else
		$(month).disabled = false;
}

function validateDate(){
	cou = $('cou').value;
	if(cou==0){
		if($('frmStartMonth').value == '' && $('frmStartYear').value == '' && $('toEndMonth').value == '' && $('toEndYear').value == '') return true;
		if($('frmStartMonth').value == '' || $('frmStartYear').value == ''){ alert('Data Od niepoprawna'); return false; }
		if(($('toEndMonth').value == '' && $('toEndYear').value != '0') || $('toEndYear').value == ''){ alert('Data Do niepoprawna'); return false; }
	}
	else{
		for(i=0; i<=cou; i++){
			if(i==0){
				if($('frmStartMonth').value == '' && $('frmStartYear').value == '' && $('toEndMonth').value == '' && $('toEndYear').value == '') continue;
				if($('frmStartMonth').value == '' || $('frmStartYear').value == ''){ alert('Data Od niepoprawna'); return false; }
				if(($('toEndMonth').value == '' && $('toEndYear').value != '0') || $('toEndYear').value == ''){ alert('Data Do niepoprawna'); return false; }
			}
			else{
				if($('frmStartMonth'+i).value == '' && $('frmStartYear'+i).value == '' && $('toEndMonth'+i).value == '' && $('toEndYear'+i).value == '') continue;
				if($('frmStartMonth'+i).value == '' || $('frmStartYear'+i).value == ''){ alert('Data Od niepoprawna'); return false; }
				if(($('toEndMonth'+i).value == '' && $('toEndYear'+i).value != '0') || $('toEndYear'+i).value == ''){ alert('Data Do niepoprawna'); return false; }
			}
		}
	}
	//return false;
}

/* Functions for popups */

var apop = '';

function aBox(item, interval){
	if(dialog.status) dialog.close();
	dialog.open(item);
	if(interval && interval !='') apop = setTimeout("dialog.close()", interval);
}

function cSMsgPopup(name, suid, ouid){
	dialog.open({header: 'Wyślij wiadomość do '+name, body: sm, footer: { button:[{text:'Wyślij', action:'sMsg(\''+suid+'\', \''+ouid+'\', "")'},{text:'<span style="*margin-right:15px;">zamknij</span>', link:1}]} });
}

function cSMultMsgPopup(name, suid, ouid){
	dialog.open({header: 'Wyślij wiadomość do '+name, body: sm, footer: { button:[{text:'Wyślij', action:'sMultMsg(\''+suid+'\', \''+ouid+'\', "")'},{text:'zamknij', link:1}]} });
}

function sMultMsg(suid, ouid, type){
	url = baseUrl+'Message/multipleMsgInsert';
	url+= type == 1 ? '/1' : '';
	if($('msgRply').value=='') { $('footer_text').innerHTML='wpisz wiadomość'; return false }
	else{
		data = 'message=' + encodeURIComponent($('msgRply').value);
		data+= $('type_pri').checked == true ? '&type=1' : '&type=0';
		data+= '&senderUid='+suid+'&ownerUid='+ouid;
		$('msgRply').value = '';
		sendData(url, data, 1);
	}
}

function sMsg(suid, ouid, type){
	url = baseUrl+'Message/send_message';
	url+= type == 1 ? '/1' : '';
	if($('msgRply').value=='') { $('footer_text').innerHTML='wpisz wiadomość'; return false }
	else{
		data = 'message=' + encodeURIComponent($('msgRply').value);
		data+= $('type_pri').checked == true ? '&type=1' : '&type=0';
		data+= '&senderUid='+suid+'&ownerUid='+ouid;
		$('msgRply').value = '';
		sendData(url, data, 1);
	}
}

function cSMMsgPopup(name, suid, ouid, count){
	dialog.open({header: 'Wyślij wiadomość do '+name, body: msm, footer: { button:[{text:'Wyślij', action:'sMMsg(\''+suid+'\', \''+ouid+'\', 1, '+count+')'},{text:'zamknij', link:1}]} });
}

function sMMsg(suid, ouid, type, count){
	url = baseUrl+'Message/send_message';
	url+= type == 1 ? '/1/'+count : '';
	if($('msgRply').value=='') { $('footer_text').innerHTML='wpisz wiadomość'; return false }
	else{
		data = 'message=' + encodeURIComponent($('msgRply').value);
		data+= $('type_pub').checked == true ? '&type=0' : ''
		data+= $('type_pri').checked == true ? '&type=1' : '';
		if($('type_b').checked == true){
			data+= '&type=2';
			data+= $('family').checked == true ? '&family=1' : '';
			data+= $('friends').checked == true ? '&friends=1' : '';
		}
		data+= '&senderUid='+suid+'&ownerUid='+ouid;
		$('msgRply').value = '';
		sendData(url, data, 1);
	}
}

function cSInvPopup(){
	dialog.open({header: 'Zaproś Przyjaciół', body: si, footer: { button:[{text:'Wyślij', action:'sInv()'},{text:'zamknij', link:1}]} });
}

function sInv(){
	if($('addresses').value == ''){
		$('footer_text').innerHTML = 'Wpisz przynajmniej jeden adres e-mail';
		return false;
	}
	else{
		address = $('addresses').value.trim();
		var re = /\s*;|\s*,/;
		address = address.split(re);
		flg = 1;
		for(i=0; i<address.length; i++){
			if(address[i] == '') continue;
			if(!is_email(address[i].trim())){
				$('footer_text').innerHTML = 'Błąd! Sprawdź podany adres e-mail, '+ address[i];
				flg = 0;
				return false;
			}
		}
		if(flg){
				url = baseUrl+'Friends/invite';
				data = 'emails='+$('addresses').value+'&notes='+encodeURIComponent($('notes').value);
				sendData(url, data, 1);
			}

	}
}

function neighbourhoodInvPopup(nid){
	dialog.open({header: 'Zaproś przyjaciół do swojego sąsiedztwa', body: neighbourInvite, footer: { button:[{text:'Wyślij', action:'sendNeighbourhoodInv('+nid+')'},{text:'zamknij', link:1}]} });
}

function sendNeighbourhoodInv(nid){
	if($('addresses').value == ''){
		$('footer_text').innerHTML = 'Wpisz przynajmniej jeden adres e-mail';
		return false;
	}
	else{
		address = $('addresses').value.trim();
		var re = /\s*;|\s*,/;
		address = address.split(re);
		flg = 1;
		for(i=0; i<address.length; i++){
			if(address[i] == '') continue;
			if(!is_email(address[i].trim())){
				$('footer_text').innerHTML = 'Błąd! Sprawdź podany adres e-mail, '+ address[i];
				flg = 0;
				return false;
			}
		}
		if(flg){
				url = baseUrl+'Neighborhood/invite/'+nid;
				data = 'emails='+$('addresses').value+'&notes='+encodeURIComponent($('notes').value);
				sendData(url, data, 1);
			}

	}
}

function cAFrndPopup(name, uid, frnduid, hash){
	dialog.open({header: 'Dodaj '+name+' jako przyjaciel', body: af, footer: { button:[{text:'Wyślij', action:'aFrnd(\''+uid+'\', \''+frnduid+'\', \''+hash+'\')'},{text:'zamknij', link:1}]} });
}

function aFrnd(uid, frnduid, hash){
	form = 'addFriendReqForm';
	url = baseUrl+'Friends/add';
	how = '';
	data = 'frndUid=' + frnduid + '&hash='+hash;
	for(i=0; i<$(form).elements.length; i++){
		if($(form).elements[i].type=='checkbox' && $(form).elements[i].checked == true){
			how += $('addFriendReqForm').elements[i].value + ',';
		}
	}
	if(how != ''){
		data += '&how=' + how;
	}
	data+= $('level_yes').checked == true ? '&level=1' : '&level=0';
	data+='&note=' + encodeURIComponent($('note').value);
	sendData(url, data, 1);
}

function cAppFrndPopup(name, frnduid, how){
	dialog.open({header: 'Zaakceptuj '+name+' jako Twój przyjaciel', body: af, footer: { button:[{text:'Zaakceptuj', action:'appFrnd(\''+frnduid+'\')'},{text:'zamknij', link:1}]} });
	cAppBox(how);
}

function cAppBox(how){
	if(how != ''){
		hw = document.getElementsByName('how[]');
		h = how.split(",");
		for(i=0; i<hw.length; i++){
			for(j=0; j<h.length;j++){
				if(h[j] == hw[i].value) hw[i].checked = true;
			}
		}
	}
}

function appFrnd(frnduid){
	form = 'approveFriendReqForm';
	url = baseUrl+'Friends/accept';
	how = '';
	data = 'inviterUid=' + frnduid;
	for(i=0; i<$(form).elements.length; i++){
		if($(form).elements[i].type=='checkbox' && $(form).elements[i].checked == true){
			how += $('approveFriendReqForm').elements[i].value + ',';
		}
	}
	if(how != ''){
		data += '&how=' + how;
	}
	data+= $('level_yes').checked == true ? '&level=1' : '&level=0';
	sendData(url, data, 1);
}

function cEFrndPopup(name, frnduid, how, level){
	dialog.open({header: 'Edytuj '+name+' cechy przyjaźni', body: ef, footer: { button:[{text:'Aktualizuj', action:'eFrnd(\''+frnduid+'\')'},{text:'zamknij', link:1}]} });
	cEBox(how, level);
}

function cEBox(how, level){
	hw = document.getElementsByName('chhow[]');
	if(how != ''){
		hw = document.getElementsByName('chhow[]');
		h = how.split(",");
		for(i=0; i<hw.length; i++){
			for(j=0; j<h.length;j++){
				if(h[j] == hw[i].value) hw[i].checked = true;
			}
		}
	}
	if(level == 1){
		$('chlevel_yes').checked = true;
		$('chlevel_no').checked = false;
	}
	else if(level == 0){
		$('chlevel_yes').checked = false;
		$('chlevel_no').checked = true;
	}
}

function eFrnd(frnduid){
	form = 'editFriendReqForm';
	url = baseUrl+'Friends/edit';
	how = '';
	data = 'frndUid=' + frnduid;
	for(i=0; i<$(form).elements.length; i++){
		if($(form).elements[i].type=='checkbox' && $(form).elements[i].checked == true){
			how += $('editFriendReqForm').elements[i].value + ',';
		}
	}
	if(how != ''){
		data += '&how=' + how;
	}
	data+= $('chlevel_yes').checked == true ? '&level=1' : '&level=0';
	sendData(url, data, 1);
}

function cAnecPopup(name, ouid, suid){
	dialog.open({header: 'Napisz anegdotę o '+name, body: anec, footer: { button:[{text:'Dodaj', action:'sAnec()'},{text:'zamknij', link:1}]} });
	$('anecOwnerUid').value = ouid;
	$('anecSenderUid').value = suid;
}

function sAnec(){
	var flag = 1;
	if($('title').value=='') { $('footer_text').innerHTML='Wstaw tytuł'; flag = 0; return false }
	else if($('rply').value=='') { $('footer_text').innerHTML='wpisz wiadomość'; flag = 0; return false }
	else if($('videoLink').value!=''){
		var url = $('videoLink').value;
    if(youtubeRE.exec(url) == null && gvRE.exec(url) == null){
    	$('footer_text').innerHTML='Proszę podać link video tylko do Youtube lub Google';
    	flag = 0;
      return false;
    }
	}
	if(flag) document.addAnecForm.submit();
	else return false;
}

function cHisPopup(uid, fnid){
	dialog.open({header: 'Dadaj historię swojej rodziny', body: ah, footer: { button:[{text:'Dodaj', action:'sHis()'},{text:'zamknij', link:1}]} });
	$('uid').value = uid;
	$('fnid').value = fnid;
}

function sHis(){
	if($('title').value=='') { $('footer_text').innerHTML='Wstaw tytuł'; return false }
	else if($('history').value=='') { $('footer_text').innerHTML='Wpisz historię'; return false }
	else document.addHistoryForm.submit();
}

function cOEHisPopup(title, fnid, hsid, hid, uid){
	dialog.open({header: 'Edytuj tę część historii', body: owh, footer: { button:[{text:'Aktualizuj', action:'eOHis()'},{text:'zamknij', link:1}]} });
	$('history').value = $('hidDiv'+hid).innerHTML;
	$('fnid').value = fnid;
	$('hsid').value = hsid;
	$('hid').value = hid;
	$('uid').value = uid;
}

function eOHis(){
	if($('history').value=='') { $('footer_text').innerHTML='Wpisz historię'; return false }
	else{/*alert($('ownersHistory').toQueryString());*/ document.ownersHistory.submit();}
}


function cOtEHisPopup(fnid, hsid, hid, uid){
	dialog.open({header: 'Edytuj I dodaj nową część historii', body: oth, footer: { button:[{text:'Aktualizuj', action:'eOtHis()'},{text:'zamknij', link:1}]} });
	$('ohistory').value = $('hidDiv'+hid).innerHTML;
	$('ofnid').value = fnid;
	$('ohsid').value = hsid;
	$('ohid').value = hid;
	$('ouid').value = uid;
}

function eOtHis(){
	if($('ohistory').value=='') { $('footer_text').innerHTML='Wpisz historię'; return false }
	else document.othersHistory.submit();
}

function cPEPopup(){
	dialog.open({header: 'Edytuj to zdjęcie', body: ep, footer: { button:[{text:'Aktualizuj', action:'eP()'},{text:'zamknij', link:1}]} });
}

function eP(){
	document.photoEditForm.submit();
}

function cANPopup(){
	dialog.open({header: 'Dodaj ogłoszenie', body: an, footer: { button:[{text:'Dodaj', action:'aN()'},{text:'zamknij', link:1}]} });
}

function aN(){
	document.photoEditForm.submit();
}

function callEventBox(){
		$('evt').hasClass('displayNone') ? $('evt').toggleClass('displayBlock') : $('evt').toggleClass('displayNone');
		if($('event_box').checked == false && $('evt').hasClass('displayBlock')){ $('evt').removeClass('displayBlock'); $('evt').addClass('displayNone');}
}

function cNBPopup(uid, fnid){
	dialog.open({header: ' Dodaj ogłoszenie ', body: nb, footer: { button:[{text:'Dodaj', action:'sNotice(\''+uid+'\', \''+fnid+'\')'},{text:'zamknij', link:1}]} });
}

function sNotice(uid, fnid){
	var flag = 1;
	if($('title').value == ''){ $('footer_text').innerHTML = 'Wstaw tytuł'; flag = 0; return false; }
	else if($('notice').value == ''){ $('footer_text').innerHTML = 'Dodaj szczegóły ogłoszenia'; flag = 0; return false; }
	else if($('videoLink').value!=''){
		var url = $('videoLink').value;
    if(youtubeRE.exec(url) == null && gvRE.exec(url) == null){
    	$('footer_text').innerHTML='Dodaj aktualny url Google Video lub YouTube ';
    	 flag = 0;
    	return false;
    }
	}
	if(flag){
		data = '';
		data+= 'title=' + encodeURIComponent($('title').value) + '&notice=' + encodeURIComponent($('notice').value) + '&videoLink=' + encodeURIComponent($('videoLink').value)+'';
		data+= '&fnid=' + fnid + '&owneruid=' + uid;
		if($('event_box').checked == true){
			data+='&isEvent=1';
			if($('location').value == ''){
				$('footer_text').innerHTML='Dodaj miejscowość';
				return false;
			}
			else
				data+='&eventLocation='+$('location').value;

			if($('dayE').value !='' && $('monE').value !='' && $('yearE').value !=''){
				if(isNaN(DateGood($('yearE').value, $('monE').value, $('dayE').value))){
					$('footer_text').innerHTML='Wprowadzona data jest nieprawidłowa';
					return false;
				}
				else
					data+='&eventDate='+$('yearE').value+'-'+$('monE').value+'-'+$('dayE').value;
			}
			else if($('dayE').value =='' || $('monE').value =='' || $('yearE').value ==''){ $('footer_text').innerHTML = 'Please enter event date'; flag = 0; return false; }

			if($('shhE').value !='' && $('smmE').value !=''){
				if(!TimeGood($('shhE').value+':'+$('smmE').value)){
					$('footer_text').innerHTML='Wprowadzony czas rozpoczęcia jest nieprawidłowy';
					return false;
				}
				else
					data+='&eventStartTime='+$('shhE').value+':'+$('smmE').value;
			}
			else if($('shhE').value =='' || $('smmE').value ==''){ $('footer_text').innerHTML = 'Please enter event start time'; flag = 0; return false; }

			if($('ehhE').value !='' && $('emmE').value !=''){
				if(!TimeGood($('ehhE').value+':'+$('emmE').value)){
					$('footer_text').innerHTML='Wprowadzony czas zakończenia jest nieprawidłowy';
					return false;
				}
				else
					data+='&eventEndTime='+$('ehhE').value+':'+$('emmE').value;
			}
			else if($('ehhE').value =='' || $('emmE').value ==''){ $('footer_text').innerHTML = 'Please enter event end time'; flag = 0; return false; }

			if($('shhE').value !='' && $('smmE').value !='' && $('ehhE').value !='' && $('emmE').value !=''){
				if(!testTime('"'+$('shhE').value+':'+$('smmE').value+':00"', '"'+$('ehhE').value+':'+$('emmE').value+':00"')){
					$('footer_text').innerHTML='Czas rozpoczęcia jest większy od czasu zakończenia';
					return false;
				}
			}
			if($('reminder_no').checked == true)
				data+='&eventReminder=0';
			if($('reminder_yes').checked == true)
				data+='&eventReminder='+$('rhrE').value;
		}
		sendData(baseUrl+'NoticeBoard/write', data, 1);
	}
	else return false;
}

function cENBPopup(){
	dialog.open({header: 'Edytuj ogłoszenie', body: nb, footer: { button:[{text:'Aktualizuj', action:'eNotice()'},{text:'zamknij', link:1}]} });
}

function eNotice(){
	if($('title').value == ''){ $('footer_text').innerHTML = 'Wstaw tytuł'; return false; }
	else if($('notice').value == ''){ $('footer_text').innerHTML = 'Dodaj szczegóły ogłoszenia'; return false; }
	else if($('videoLink').value!=''){
		var url = $('videoLink').value;
    if(youtubeRE.exec(url) == null && gvRE.exec(url) == null){
    	$('footer_text').innerHTML=' Proszę podać aktualny link video tylko do Youtube lub Google ';
    	return false;
    }
	}
	data = '';
	data+= 'title=' + encodeURIComponent($('title').value) + '&notice=' + encodeURIComponent($('notice').value) + '&videoLink=' + encodeURIComponent($('videoLink').value);
	data+= '&fnid=' + $('editFnid').value + '&nid=' + $('editNid').value
	if($('event_box').checked == true){
		data+='&isEvent=1';
		if($('location').value == ''){
			$('footer_text').innerHTML='Dodaj miejscowość';
			return false;
		}
		else
			data+='&eventLocation='+$('location').value;

		if($('dayE').value !='' && $('monE').value !='' && $('yearE').value !=''){
			if(isNaN(DateGood($('yearE').value, $('monE').value, $('dayE').value))){
				$('footer_text').innerHTML='Wprowadzona data jest nieprawidłowa';
				return false;
			}
			else
				data+='&eventDate='+$('yearE').value+'-'+$('monE').value+'-'+$('dayE').value;
		}
		else if($('dayE').value =='' || $('monE').value =='' || $('yearE').value ==''){ $('footer_text').innerHTML = 'Podaj datę zdarzenia'; flag = 0; return false; }

		if($('shhE').value !='' && $('smmE').value !=''){
			if(!TimeGood($('shhE').value+':'+$('smmE').value)){
				$('footer_text').innerHTML='Wprowadzony czas rozpoczęcia jest nieprawidłowy';
				return false;
			}
			else
				data+='&eventStartTime='+$('shhE').value+':'+$('smmE').value;
		}
		else if($('shhE').value =='' || $('smmE').value ==''){ $('footer_text').innerHTML = 'Podaj czas rozpoczęcia się zdarzenia'; flag = 0; return false; }

		if($('ehhE').value !='' && $('emmE').value !=''){
			if(!TimeGood($('ehhE').value+':'+$('emmE').value)){
				$('footer_text').innerHTML='Wprowadzony czas zakończenia jest nieprawidłowy';
				return false;
			}
			else
				data+='&eventEndTime='+$('ehhE').value+':'+$('emmE').value;
		}
		else if($('ehhE').value =='' || $('emmE').value ==''){ $('footer_text').innerHTML = 'Podaj czas zakończenia się zdarzenia'; flag = 0; return false; }

		if($('shhE').value !='' && $('smmE').value !='' && $('ehhE').value !='' && $('emmE').value !=''){
			if(!testTime('"'+$('shhE').value+':'+$('smmE').value+':00"', '"'+$('ehhE').value+':'+$('emmE').value+':00"')){
				$('footer_text').innerHTML='Czas rozpoczęcia jest większy od czasu zakończenia';
				return false;
			}
		}
		if($('reminder_no').checked == true)
			data+='&eventReminder=0';
		if($('reminder_yes').checked == true)
			data+='&eventReminder='+$('rhrE').value;
	}
	sendData(baseUrl+'NoticeBoard/editNotice', data, 1);
}

function cDisPopup(){
	dialog.open({header: 'Rozpocznij nową rozmowę', body: discussion, footer: { button:[{text:'Start', action:'sDis()'},{text:'zamknij', link:1}]} });
}

function sDis(){
	if($('title').value=='') { $('footer_text').innerHTML='Tutaj zapisuj swoją rozmowę'; return false }
	else document.discussionForm.submit();
}

function cThreadPopup(did){
	dialog.open({header: 'Odpowiedz do tej rozmowy', body: thread, footer: { button:[{text:'Odpowiedz', action:'sThread()'},{text:'zamknij', link:1}]} });
	$('discid').value = did;
}

function sThread(){
	if($('reply').value=='') { $('footer_text').innerHTML='Tutaj wpisz swoją odpowiedz'; return false }
	else document.threadForm.submit();
}

/* -------------------- */

var shoutFlag = false;
var shoutStatus = null;
function shout(id, uid, type){//alert("type "+type+" shoutFlag "+shoutFlag+" shoutStatus "+shoutStatus);
	if(type== 1 && !shoutFlag){
		shoutStatus = $(id).innerHTML.trim();
		$('shoutTxtBox').innerHTML = '<input id="shoutText" type="text" name="shoutText" maxlength="32" style="width: 140px;" value="'+shoutStatus+'" />&nbsp;<img align="absmiddle" src="'+baseUrl+'images/shouter_tick.gif" class="cursorHand" onclick="saveShoutLine('+uid+')" />&nbsp;<img align="absmiddle" src="'+baseUrl+'images/shouter_close.gif" class="cursorHand" onclick="shout(\'shoutTxtBox\','+uid+',0); return false;" />';
		shoutFlag = true;
		$('shoutTxtBox').toggleClass('pad10px');
		$('shoutTxtBox').toggleClass('displayNone');
		$(id).toggleClass('displayNone');
	}
	if(type== 0 && shoutFlag){
		$('shout').innerHTML = shoutStatus;
		shoutFlag = false;
		$(id).toggleClass('pad10px');
		$(id).toggleClass('displayNone');
		$('shout').toggleClass('displayNone');
	}
}

function saveShoutLine(uid){
	data = 'uid='+uid+'&shoutLine='+$('shoutText').value;
	sendData(baseUrl+'DashBoard/shoutLine', data, 1);
}

function insertSmily(smily){
    var myBox = $('msgRply');
    var myForm = $('msgForm');
	  //IE support
    if(document.selection){
  	  myBox.focus();
      sel = document.selection.createRange();
      sel.text = smily;
      myForm.insert.focus();
    }
    //MOZILLA/NETSCAPE support
    else if (myBox.selectionStart || myBox.selectionStart == "0") {
    	var startPos = myBox.selectionStart;
      var endPos = myBox.selectionEnd;
      var chaineSql = myBox.value;
      myBox.value = chaineSql.substring(0, startPos) + smily + chaineSql.substring(endPos, chaineSql.length);
    } else {
       myBox.value += smily;
     }
}

function widget(flag){
	photoUploadTreeClose();
	if(flag==1){
	  flashOpen = 'none';
	  widgetOpen = 'block';

	}
	else{
	  flashOpen = 'block';
	  widgetOpen = 'none';
	}
	$('flashcontent').style.display = flashOpen;
	$('widgetcontent').style.display = widgetOpen;
}

function widgetEnable(flag){
  data = 'flag='+flag;
	sendData(baseUrl+'Tree/widgetEnable', data, 1);
}

function photoPrivacyChange(){
  data = 'pid[]='+10+'&privacy[10]='+1+'&pid[]='+20+'&privacy[20]='+0;
	sendData(baseUrl+'Photos/photoPrivacyChange', data, 1);
}

function CheckAvailability(flag){
	if($('name').value == ''){
		alert('Podaj unikalną nazwę dla swojego Sąsiedztwa');
		$('name').focus();
		return false;
	}
	else{
	  name = $('name').value;
    regu = /^([a-z0-9_\-])+$/i;
    if(regu.test(name)){
      data = 'neighbourhoodName='+$('name').value+'&flag='+flag;
	    sendData(baseUrl+'Neighborhood/checkAvailability', data, 1);
    }
    else{
      alert('Nazwa Sąsiedztwa może zawierać tylko alfanumeryczne znaki, podkreślniki oraz myślniki');
      $('name').focus();
      return false;
    }
	}
}

function neighbourhoodValidation(type){
  validFlag = 1;
  if(type == 'add') fields = new Array('name', 'title', 'pin', 'city', 'locality', 'country');
  else if(type == 'edit') fields = new Array('title', 'pin', 'city', 'locality', 'country');
  for(i=0; i<fields.length; i++){
    fieldName = fields[i];
    fieldValue = $(fieldName).value;
    if(fieldValue == ''){
      alert('Input a '+fieldName);
		  $(fieldName).focus();
		  validFlag=0;
		  return false;
    }
    else if(fieldName == 'pin'){
      if(fieldValue.length < 4){
	      alert(fieldName+' minimalna długość to 4 znaki');
		    $(fieldName).focus();
		    validFlag=0;
		    return false;
	    }
	    else if(fieldValue.length > 20){
	      alert(fieldName+' maksymalna długość to 20 znaków');
		    $(fieldName).focus();
		    validFlag=0;
		    return false;
	    }
    }
  }
  return validFlag == 1 ? true : false;
}

function joinNeighbour(nid, suid){
  data = 'nid='+nid;
  if(suid !='') data+='&suid='+suid;
	sendData(baseUrl+'Neighborhood/join', data, 1);
}

function acceptNeighbourRequest(nid, uid, flag){
 task = flag == 1 ? 'Akceptuj' : flag == 0 ? 'Odrzuć' : false;
 if(!task) return;
 data = 'nid='+nid+'&uid='+uid;
 sendData(baseUrl+'Neighborhood/'+task, data, 1);
}

function manageNeighbourhood(nid){
  if($('member').value == ''){
    alert('Wybierz członka');
    return false;
  }
  if($('task').value == ''){
    alert('Wybierz zadanie');
    return false;
  }
  data = 'nid='+nid+'&uid='+$('member').value+'&task='+$('task').value;
  sendData(baseUrl+'Neighborhood/ManageNeighbourhood', data, 1);
}

function openReply(did){
  obj = $('reply'+did);
  obj.style.display = obj.style.display == 'block' ? 'none' : 'block';
}

function addNedit(type){
 if(neighbourhoodValidation(type)) neighbourhoodConfirmPopup();
}

function neighbourhoodConfirmPopup(){
  //var neighbourhoodConfirm = '<div class="pad10px">This is to confirm that your<br /><br /><div class="fltLeft" style="width:150px;">Unique URL :</div> <span class="fltLeft textBolder">http://'+$('name').value+'.onefamily.com</span><div class="clrBoth"></div><br /><div class="fltLeft" style="width:150px;">Neighborhood Title :</div> <span class="fltLeft textBolder">'+$('title').value+'</span><div class="clrBoth"></div><br /><div class="fltLeft" style="width:150px;">Your Location :</div> <span class="fltLeft textBolder">'+$('locality').value+'</span><div class="clrBoth"></div><br /><div class="fltLeft" style="width:150px;">Your City :</div> <span class="fltLeft textBolder">'+$('city').value+'</span><div class="clrBoth"></div><br /><div class="fltLeft" style="width:150px;">Your Country :</div> <span class="fltLeft textBolder">'+$('country').value+'</span><div class="clrBoth"></div><br /><div class="fltLeft" style="width:150px;">Your Pincode :</div> <span class="fltLeft textBolder">'+$('pin').value+'</span><div class="clrBoth"></div><br /><div class="textBolder"><span>Note: </span><span style="color:#f33;">Please confirm all the above details entered by you, since they <br />cannot be changed / edited once the Neighbourhood is created.</span></div>';
  var neighbourhoodConfirm = '<div class="pad10px">To jest potwierdzenie, że twoja<br /><br /><div class="fltLeft" style="width:90px;">niepowtarzalny URL :</div> <span class="fltLeft textBolder">http://'+$('name').value+'.onefamily.com</span><div class="clrBoth"></div><br /><br /><br /><div class="textBolder"><span>Uwaga: </span><span class="error">Prosimy o potwierdzenie tego URL, jako, że nie można go zmieniać / edytować po stworzeniu Sąsiedztwa.</span></div>';
	dialog.open({header: 'Potwierdź wartości sąsiedztwa', body: neighbourhoodConfirm, footer: { button:[{text:'Potwierdz', action:'e()'},{text:'Anuluj', link:1}]} });
}

function e(){
  document.addform.submit();
}

function discussionDelete(nid, did){
  if(confirm('Czy na pewno chcesz anulować tą rozmowę?')){
    $('DDnid').value = nid;
    $('DDdid').value = did;
    document.discussionDelForm.submit();
  }
  else return false;
}