
function trySavePlace( id ) {
	id = id.toString();
	var place = getValue( 'place_'+id );
	var points = getValue( 'points_'+id );
	var qualified = get( 'qualified_'+id ).checked;
	var ajax = new myAjax();
	ajax.action = 'trySavePlace';
	ajax.post( 'id='+id+'&place='+place+'&points='+points+'&qualified='+qualified );
	ajax.onLoad = function() {
		if( this.response == 'ok' ) {
			document.location.reload();
		} else {
			alert( this.response );
		}
	}
}

function tryCreateForum( creator ) {
	var ajax = new myAjax();
	ajax.action = 'tryCreateForum';
	var title = getValue( 'title' );
	ajax.post( 'title='+title+'&creator='+creator );
	ajax.onLoad = function() {
		var ar = this.response.split( '|' );
		if( ar[ 0 ] == 'ok' ) {
			hide( 'butek' );
			putHtml( 'forum', ar[ 1 ] );
		} else {
			putHtml( 'forum', ar[ 0 ] );
		}
	}
}

function trySendQuestion( id ) {
	var subj = getValue( 'd_subject_' + id.toString() );
	var quest = getValue( 'd_question_' + id.toString() );
	var nick = getValue( 'u_nick_' + id.toString() );
	var email = getValue( 'u_email_' + id.toString() );
	var f = 'question_form_' + id.toString();
	var fr = f + '_response';
	var ajax = new myAjax();
	ajax.action = 'trySendQuestion';
	hide( f );
	ajax.post( 'nick='+nick+'&email='+email+'&subject='+subj+'&question='+quest+'&parent='+id.toString() );
	ajax.onLoad = function() {
		var ar = this.response.split( '|' );
		if( ar[ 0 ] == 'error' ) {
			show( f );
			show( fr );
			putHtml( fr, ar[ 1 ] );
		} else {
			putHtml( fr, ar[ 0 ] );
			show( fr );
                        pageTracker._trackPageview($('#ptcode').val());
		}		
	}
}

function toggleCities( province, cities ) {
	if( typeof( province ) != 'string' ) province = 'province';
	if( typeof( cities ) != 'string' ) cities = 'cities';
	var ajax = new myAjax();
	ajax.action = 'toggleCities';
	ajax.post( 'province='+getValue( province ), cities );
}

function submitPoll( id ) {
	var s = getRadioValueByName( 'sonda_'+id );
	var ajax = new myAjax();
	ajax.action = 'submitPoll';
	ajax.post( 'id='+id+'&value='+s, 'sonda' );
}

function toggleGroups( id, g ) {
	var ajax = new myAjax();
	ajax.action = 'toggleGroups';
	if( g != undefined ) {
		ajax.post( 'category='+id+'&g='+g, 'groups' );
	} else {
		ajax.post( 'category='+id, 'groups' );		
	}
	ajax.onLoad = function() {
		reloadLeftLinksGroups();
	}
}

function reloadLeftLinksGroups() {
	var ajax = new myAjax();
	ajax.action = 'reloadLeftLinksGroups';
	ajax.post( '', 'left_links' );
}

function switchBrand( brand ) {
	var ajax = new myAjax();
	ajax.action = 'getModels';
	ajax.post( 'brand='+getValue( brand ) );
	ajax.onLoad = function() {
		get( 'model' ).innerHTML = this.response;
	}
}

function trySendNote( obj, id, note ) {
	var ajax = new myAjax();
	ajax.action = 'trySendNote';
	ajax.post( 'obj='+obj+'&id='+id+'&note='+note );
	ajax.onLoad = function() {
		if( this.response == 'ok' ) {
			window.location.reload();
		} else {
			alert( this.response );
		}
	}
}

function tryAddNote( note ) {
	var ajax = new myAjax();
	ajax.action = 'tryAddNote';
	var pc = getValue( 'note_class' );
	var pid = getValue( 'note_id' );
	ajax.post( 'pc='+pc+'&pid='+pid+'&note='+note );
	ajax.onLoad = function() {
		alert( this.response );
	}
}

function responseComment( tit ) {
	get( 'comment_title' ).value = 'Re: '+tit;
}

function tryAddComment() {
	var ajax = new myAjax();
	ajax.action = 'tryAddComment';
	var pc = getValue( 'comment_class' );
	var pid = getValue( 'comment_id' );
	var tex = getValue( 'titx' );
	tex = tex.replace(/&/g,'ampersand');
	ajax.post( 'pc='+pc+'&pid='+pid+'&tex='+tex );
	ajax.onLoad = function() {
		if( this.response == 'ok' ) {
			window.location.reload();
		} else {
			alert( this.response );
		}
	}
}

function tryResponsePost( id ) {
	var b = getValue( 'post_response' );
	b = b.replace(/&/g,'ampersand');
	var ajax = new myAjax();
	hide( 'response' );
	show( 'message' );
	ajax.action = 'tryAddResponsePost';
	ajax.post( 'id='+id+'&b='+b );
	//setTimeout("alert('id='+id+'&b='+b)",5000);
    //window.alert( 'id='+id+'&b='+b );
	ajax.onLoad = function() {
		var loc = window.location;
		
		var resp = this.response;
		var pn = resp.substr( 0, resp.indexOf( '#' ) );
		//alert( loc.pathname+' '+pn+' '+resp );

		if( loc.pathname == pn ) {
			document.location.reload();
		} else {
			loc.href = resp;
		}
	}
}

function switchDocsPerPage( dpp ) {
	var ajax = new myAjax();
	ajax.action = 'switchDocsPerPage';
	ajax.post( 'p='+dpp );
	ajax.onLoad = function() {
		document.location.reload();
	}
}

function findFriend() {
	var f = getValue( 'friend' );
	var ajax = new myAjax();
	ajax.action = 'findFriend';
	ajax.post( 'f='+f, 'responses' );
	ajax.onLoad = function() {
		
	}
}

function tryAddResponsePost() {
	var b = getValue( 'body' );
	var id = getValue( 'threadId' );
	var ajax = new myAjax();
	ajax.action = 'tryAddResponsePost';
	ajax.post( 'b='+b+'&id='+id );
	ajax.onLoad = function() {
		switch( this.response ) {
			case 'ok':
				window.location.reload();
				break;
			default:
				get( 'errorMessage' ).innerHTML = this.response;
				break;
		}
	}
}

function tryAddPost() {
	var t = getValue( 'title' );
	var b = getValue( 'body' );
	var ajax = new myAjax();
	ajax.action = 'tryAddPost';
	ajax.post( 't='+t+'&b='+b );
	ajax.onLoad = function() {
		switch( this.response ) {
			case 'ok':
				document.forms[ 'addPostForm' ].submit();
				break;
			default:
				get( 'errorMessage' ).innerHTML = this.response;
				break;
		}
	}
}

function tryAddGroup() {
	var t = getValue( 'title' );
	var ajax = new myAjax();
	ajax.action = 'tryAddGroup';
	ajax.post( 't='+t );
	ajax.onLoad = function() {
		switch( this.response ) {
			case 'ok':
				document.forms[ 'form_1' ].submit();
				break;
			case 'group_exists':
				alert( 'Już istnieje taka grupa, musisz wybrać inną nazwę dla grupy' );
				break;
		}
	}
}

function tryRegister( script ) {
	var h		= get( 'hashcode' );	
	var l		= getValue( 'login' );
	var p		= getValue( 'password' );
	var pr	= getValue( 'password_repeat' );
	var e 	= getValue( 'email' );	
	var n 	= getValue( 'name' );
	var sn	= getValue( 'surname' );
	var r		= get( 'regulamin' );
	h.value = 'latajacepsy';
	hide( 'rejestracja' );
	var ajax = new myAjax();
	ajax.action = 'tryRegister';
	ajax.post( 'l='+l+'&p='+p+'&pr='+pr+'&e='+e+'&n='+n+'&sn='+sn+'&hashcode='+h.value+'&regulamin='+r.checked, 'register_message' );
	ajax.onLoad = function() {
		if( this.response == 'ok' ) {
			document.location.href = script;			
		} else {
			show( 'rejestracja' );
		}
	}
}

function tryRegister2( f ) {
	var hd = get( 'yes' ).checked;
	var dc = getValue( 'dogs_n' );
	var s = true;
	if( hd ) {
		var ar = new Array();
		var arD = new Array();
		var x = 1;
		for( var ii=1; ii<= ((2*dc)-1); ii=ii+2 ){
			ar[ ii-1 ] = 'name_'+x;
			ar[ ii ] = 'breed_'+x;

			arD[ ii-1 ] = 'Imię psa '+x;
			arD[ ii ] = 'Rasa psa '+x;
			x++;
		}
		var str = '';
		for( i in ar ) {
			var itema = ar[ i ];
			if( getValue( itema ) == '' ) {
				str += arD[ i ] + "\n";
			}
		}
		if( str != '' ) {
			alert( "Proszę wypełnić dane:\n" + str );
			s = false;
		}
	}
	if( s ) {
		document.forms[ 'reg_form' ].submit();
	}
}

function try_contact() {
	var h		= get( 'hashcode' );	
	var e 	= getValue( 'email' );
	var b 	= getValue( 'body' );
	if( ( e == '' ) || ( b == '' ) ) {
		alert( 'Wprowadź swój adres e-mail i wpisz wiadomość' );
	} else {
		h.value = 'foto';
		var ajax	= new myAjax();
		hide( 'div_contact' );
		ajax.action = 'try_contact';
		ajax.post( 'email=' + e + '&body=' + b + '&hashcode='+h.value, 'contact_message' );
		ajax.onLoad = function() {
			if( this.response == 'ok' ) {
				show( 'contact_message_send' );
			} else {
				show( 'div_contact' );
			}
		}
	}
}

function pollSave( id ) {
	id = id.toString();
	var poll = document.forms[ 'poll_' + id ];
	var bradio = poll.elements[ 'question_' + id ];
	var ret = 'poll_questions_' + id;
	var q = getRadioValue( bradio );
	var reg = new RegExp( '[0-9]+' );
	if( !q.match( reg ) ) {
		alert( 'Proszę wybrać którąś z odpowiedzi' );
	} else {
		hide( ret );
		var ajax = new myAjax();
		ajax.action = 'pollSave';
		ajax.post( 'poll='+id+'&answer=' + q, ret );
		ajax.onLoad = function() {
			show( ret );
		}
	}
}


function submitForm( f ) {
	get( f ).submit();
}

function ajax_delMessages( arrays ){
	arrays = arrays+'';
	var kilka = false;
	if( arrays.indexOf('|') > -1 ){ kilka = true; }
	var ajax	= new myAjax();
	ajax.action = 'delMessages';
	ajax.post( 'msgs=' + arrays );
	ajax.onLoad = function() {
		alert( this.response );
		if( this.response == 'ok' ) {
			alert( 'Wiadomość(i) usunięte.' );
			if( kilka )
				var loc = window.location+'';
			else
				var loc = '/profil/skrzynka';

			window.location = loc;
		} else {
			alert( this.response );
		}
	}
}

function overuse( clas, id, cid ){
	var ajax = new myAjax();
	ajax.action = 'overuse';
	ajax.post( 'clas='+clas+'&id='+id+'&cid='+cid );
	ajax.onLoad = function() {
		var ar = this.response.split( '|' );
		if( ar[ 0 ] == 'ok' ) {
			alert( 'Nadużycie zostało zgłoszone do Moderatora');
			var loc = window.location+'';
			loc = loc.replace( '#', '' );
			window.location = loc;
		} else {
			alert( 'Błąd 214. Spróbuj ponownie za chwilę.');
		}
	}
}

function add_to_public( id ){
	var ajax = new myAjax();
	ajax.action = 'add_to_public';
	ajax.post( 'id='+id );
	ajax.onLoad = function() {
		var ar = this.response.split( '|' );
		if( ar[ 0 ] == 'ok' ) {
			alert( 'Dodano zdjęcie do galerii serwisu');
			var loc = window.location+'';
			loc = loc.replace( '#', '' );
			window.location = loc;
		} else {
			alert( 'Błąd 217. Spróbuj ponownie za chwilę.');
		}
	}
}

function changeRotatorType( val, im, path ) {
    var rot 	= document.getElementById( 'rot' );
    var ajax	= new myAjax();
	ajax.action = 'changeRotatorType';
	ajax.post( 'isflash=' + val + '&im=' + im + '&path=' + path);
	ajax.onLoad = function() {
		rot.innerHTML = this.response;
    };
}
