function trySendQuestion( id ) {
	var subj = getValue( 'd_subject_' + id.toString() );
	var quest = getValue( 'd_question_' + id.toString() );
	var f = 'question_form_' + id.toString();
	var fr = f + '_response';
	var ajax = new myAjax();
	ajax.action = 'trySendQuestion';
	hide( f );
	ajax.post( 'subject='+subj+'&question='+quest+'&parent='+id.toString() );
	ajax.onLoad = function() {
		var ar = this.response.split( '|' );
		if( ar[ 0 ] == 'error' ) {
			show( f );
			putHtml( fr, ar[ 1 ] );
		} else {
			putHtml( fr, ar[ 0 ] );
		}		
	}
}

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 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 tryAddComment() {
	var ajax = new myAjax();
	ajax.action = 'tryAddComment';
	var pc = getValue( 'comment_class' );
	var pid = getValue( 'comment_id' );
	var tex = getValue( 'titx' );
	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' );
	var ajax = new myAjax();
	hide( 'response' );
	show( 'message' );
	ajax.action = 'tryAddResponsePost';
	ajax.post( 'id='+id+'&b='+b );
	ajax.onLoad = function() {
		var loc = window.location;
		var resp = this.response;
		var pn = resp.substr( 0, resp.indexOf( '#' ) );
		if( loc.pathname == pn ) {
			loc.reload();
		} else {
			loc.href = resp;
		}
	}
}

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 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 tryBoxContanctFormSubmit(){
    var email_pat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
     
    var name = $.trim( $('#bc_name').val() );
    var company = $.trim( $('#bc_company').val() );
    var interested = $.trim( $('#bc_interested').val() );
    var phone = $.trim( $('#bc_phone').val() );
    var email = $.trim( $('#bc_email').val() );
    
    var error = '';
    if ( name == '' ) {
        error += lang['error_name']+"\n";
    }
     if ( company == '' ) {
        error += lang['error_company']+"\n";
    }
    if ( interested == '' ) {
         error += lang['error_message2']+"\n";
    }
     if ( email == '' ||
          !email.match(email_pat)
         ) {
        error += lang['error_email']+"\n";
    }
    
   
    if (error != '') {
        alert(error);
        return false;
        
    }
    
    var ajax = new myAjax();
    ajax.action = 'boxContanctFormSubmit';
    ajax.post( 'name='+name+'&company='+company+'&interested='+interested+'&phone='+phone+'&email='+email );
    ajax.onLoad = function() {
            var response =  trim(this.response);
            if (response == 'ok') {
                alert(lang['sended']);
                $('#bc_name').val('');
                $('#bc_company').val('');
                $('#bc_interested').val('');
                $('#bc_phone').val('');
                $('#bc_email').val('');
            }
           
     }
    
    
    
    return false;
}

function tryContanctFormSubmit(){
    var email_pat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
     
    var name = $.trim( $('#bc_name').val() );
    var surname = $.trim( $('#bc_surname').val() );
    var email = $.trim( $('#bc_email').val() );
    var phone = $.trim( $('#bc_phone').val() );
    var title = $.trim( $('#bc_title').val() );
    var question = $.trim( $('#bc_question').val() );
   
    
    var error = '';
    if ( name == '' ) {
        error += lang['error_name']+"\n";
    }
     if (surname == '' ) {
        error += lang['error_surname']+"\n";
    }
    if ( email == '' ||
          !email.match(email_pat)
         ) {
        error += lang['error_email']+"\n";
    }
    if ( question == '' ) {
         error += lang['error_message']+"\n";
    }
     
    
   
    if (error != '') {
        alert(error);
        return false;
        
    }
    
    var ajax = new myAjax();
    ajax.action = 'contanctFormSubmit';
    ajax.post( 'name='+name+'&surname='+surname+'&email='+email+'&question='+question+'&title='+title+'&phone='+phone );
    ajax.onLoad = function() {
            var response =  trim(this.response);
            if (response == 'ok') {
                alert(lang['sended']);
                $('#bc_name').val('');
                $('#bc_surname').val('');
                $('#bc_email').val('');
                $('#bc_phone').val('');
                $('#bc_title').val('');
                $('#bc_question').val('');
            }
           
     }
    
    
    
    return false;
}
