function gotoRegister(){
	var spec = getValue( 'specialist' );
	if( trim( spec ) == '' ) {
		alert( 'Proszę wybrać lekarza' );
	} else {
		document.location.href = '/rejestracja/'+spec;
	}
}

function validateContact() {
	var name = getValue( 'name' );
	var email = getValue( 'email' );
	var phone = getValue( 'phone' );
	var comment = getValue( 'comment' );
	var err = '';
	if( name == '' ) {
		err+= "Proszę wpisać imię i nazwisko\n";
	}
	if( email == '' ) {
		err+= "Proszę wpisać adres e-mail\n";
	}
	if( phone == '' ) {
		err+= "Proszę wpisać numer telefonu\n";
	}
	if( comment == '' ) {
		err+= "Proszę wpisać treść wiadomości\n";
	}
	if( err != '' ) {
		alert( err );
	} else {
		document.forms[ 'contactForm' ].submit();
	}
}

function validateRegister() {
	var spec = getValue( 'specialist' );
	var name = getValue( 'name' );
	var email = getValue( 'email' );
	var phone = getValue( 'phone' );
	var visit = getValue( 'visit' );
	var err = '';
	if( spec == '' ) {
		err+= "Proszę wybrać lekarza\n";
	}
	if( name == '' ) {
		err+= "Proszę wpisać imię i nazwisko\n";
	}
	if( email == '' ) {
		err+= "Proszę wpisać adres e-mail\n";
	}
	if( phone == '' ) {
		err+= "Proszę wpisać numer telefonu\n";
	}
	if( err != '' ) {
		alert( err );
	} else {
		document.forms[ 'register' ].submit();
	}
}

function showSubSectionMenu(id) {
	document.getElementById(id).style.display="block";
}

function hideSubSectionMenu(id) {
    document.getElementById(id).style.display="none";
}

function togglePhoto( linker ) {
	get( 'ph_main' ).src = linker;
}

function triggerNotes( id, note ) {
	for( i = 1; i <= 5; i++ ) {
		var img = get( 'note_'+i.toString() );
		if( id >= i ) {
			img.src = getNoteSrc( i, 5 );
		} else {
			img.src = getNoteSrc( i, 0 );
		}
	}
}

function detriggerNotes( id, note ) {
	for( i = 1; i <= 5; i++ ) {
		var img = get( 'note_'+i.toString() );
		img.src = getNoteSrc( i, note );
	}	
}

function getNoteSrc( id, note ) {
	var tmp = '/graph/grade-star-ZERO.gif';
	if( ( id <= note ) && ( note - id != -0.5 ) ) {
		return tmp.replace( 'ZERO', 'full' );
	} else if( note - id == -0.5 ) {
		return tmp.replace( 'ZERO', 'half' );
	} else {
		return tmp.replace( 'ZERO', 'empty' );
	}
}



function sendAvatar() {
		
}


function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}




function saveNewPassword() {
	var op = get( 'old_pass' ).value;
	var np = get( 'new_pass' ).value;
	var npr = get( 'new_pass_repeat' ).value;
	var ajax = new myAjax();
	ajax.action = 'saveNewPassword';
	ajax.post( 'op='+op+'&np='+np+'&npr='+npr );
	ajax.onLoad = function() {
		var d = get( 'passwordMessage' );
		switch( this.response ) {
			case 'ok':
				putHtml( d, 'Zapisano nowe hasło' );
				break;
			case 'not_empty':
				putHtml( d, 'Hasło nie może być puste' );
				break;
			case 'bad_compare':
				putHtml( d, 'Hasło nie zgadza się z powtórzeniem hasła' );
				break;
			case 'bad_pass':
				putHtml( d, 'Stare hasło jest nieprawidłowe' );
				break;
			default:
				putHtml( d, this.response );
				break;
		}
	}
}

function sifr_replace() {
	if(typeof sIFR == "function"){
		sIFR.replaceElement(named({ sSelector:"div#login_panel div.sifr_l_ht", sFlashSrc:"/swf/sifr_century_gothic.swf", sColor:"#ffffff", sLinkColor:"#ffffff", sHoverColor:"#ffffff", sBgColor:'transparent', sWmode:'transparent' }));
	}
}

function searcher( target ) {
	var t = getSearch( target );
	if( t.length < 3 ) {
		alert( 'Wyszukiwany tekst musi mieć conajmniej 3 znaki' );
	} else {
		document.location = '/szukaj/'+t;//+'/kategoria/'+o;
	}
}

function searchCurrent( target, linker ) {
	var t = getSearch( target );
	if( t.length < 3 ) {
		alert( 'Wyszukiwany tekst musi mieć conajmniej 3 znaki' );
	} else {
		var h = linker;
		var len = h.length;
		var ls = h.substr( len - 1, 1 );
		if( ls == '/' ) {
			h = h.substr( 0, len - 1 );
		}
		document.location.href = h + '/szukaj/'+t;
	}
}

function getSearch( target ) {
	get( target ).value = trim( getValue( target ) );
	return getValue( target ).split( ' ' ).join( '+' );
}

function publicLogout() {
	top.location = "/module/logout";
}

function loginThisPage() {
	var l 	= getValue( 'login' );
	var p	= getValue( 'password' );
	if( l == '' || p == '' ){
		alert( 'Brak loginu lub hasła!' );
		return false;
	}

	var ajax = new myAjax();
	var pstr = 'login='+l+'&pass='+p+'&cn=Client';

	ajax.action = 'publicLogin';
	ajax.post ( pstr );
	ajax.onLoad = function() {
		if( this.response == 'ok' ) {
			document.location.reload();
		} else {
			alert( this.response );
			return false;
		}
	}
}

function publicLogin() {
	var l 	= getValue( 'public_login' );
	var p	= getValue( 'public_password' );
	if( l == '' || p == '' ){
		alert( 'Brak loginu lub hasła!' );
		return false;
	}

	var g = getRadioValueByName( 'save_pass' );
//	get( 'loginMessage' ).value = '';
	var ajax = new myAjax();
	var pstr = 'login='+l+'&pass='+p+'&save_pass='+g+'&cn=Client';
	ajax.action = 'publicLogin';
//	ajax.post ( pstr, 'loginMessage' );
	ajax.post ( pstr );
	ajax.onLoad = function() {
		if( this.response == 'ok' ) {
			document.location.reload();
		} else {
			alert( this.response );
		}
	}
}


