function deletefavorites()
{
	Cookies.set('favorites', '', -10);
	$('#schowek').html( '0' );
	$('.ow').hide( 'slow' );
	$('.os').hide( 'slow' );
	$('.wyrtitle').hide( 'slow' );
	
}



function favorites( nr, opr, objid )
{
	///Cookies.set('favorites', 'sadasd', 8640000);
	//alert('ss');
	var cok = Cookies.get('favorites');
	if( cok != null )
	{
		var arr = Cookies.get('favorites').split(',');
		
	}
	else
	{
		var arr = new Array();
	}
	
	if( nr == '' || nr == null ){
	
		$('#schowek').html( ''+arr.length );
		return;
	} 
	
	
	
	if( opr == 'add' )
	{
		arr.push(nr);
		$('#'+objid).show();
		
		
	}
	else
	{
		//alert(arr.toString());
		for( var i=0; i<arr.length; i++ )
		{
			if( arr[i] == nr ) 
			{
				delete arr[i]; 
			}
		}
		
		
	}
	arr = arr.unique(  );
	
	$('#schowek').html( ''+arr.length );
	Cookies.set('favorites', arr.toString(), 8640000);
	$('#asdas').attr('value',arr.toString());
	//alert(arr.length );
	
	if( opr == 'delete'  )
	{
		$('#'+objid).hide('slow');
	}
	
}


Array.prototype.unique =
  function() {
    var a = [];
    var l = this.length;
    for(var i=0; i<l; i++) {
      for(var j=i+1; j<l; j++) {
        // If this[i] is found later in the array
        if (this[i] === this[j] )
          j = ++i;
      }
      if( this[i] !='' && this[i]!= undefined )
      a.push(this[i]);
    }
    return a;
  };


var Cookies = {
    set: function (name, value, seconds) {
        if (typeof(seconds) != 'undefined') {
            var date = new Date();
            date.setTime(date.getTime() + (seconds*1000));
            var expires = "; expires=" + date.toGMTString();
        }
        else {
            var expires = "";
        }
        document.cookie = name+"="
            +(typeof(encodeURI)!='undefined'
                ?encodeURI(value) :escape(value))
            +expires+"; path=/";
    },
    get: function (name, _default) {
        name = name + "=";
        var carray = document.cookie.split(';');

        for(var i=0;i < carray.length;i++) {
            var c = carray[i];
            while (c.charAt(0)==' ') c = c.substring(1,c.length);
            if (c.indexOf(name) == 0)
              return typeof(decodeURI)!='undefined'
                       ?decodeURI(c.substring(name.length,c.length))
                       :unescape(c.substring(name.length,c.length));
        }
        return (typeof(_default)!='undefined') ?_default :null;
    },
    del: function (name) {
        this.setCookie(name, "", -1);
    }
}


function limitTextArea( area_id, msg_id )
{

	var ileznakow = document.getElementById(area_id).value.length;
	
	if( ileznakow > 255 )
	{
		document.getElementById(area_id).value = document.getElementById(area_id).value.substr(0,255);
		var ileznakow = document.getElementById(area_id).value.length;
	}
	
	if(  255-ileznakow  == 0) $('#'+msg_id).html( '0' );
	else $('#'+msg_id).html( 255-ileznakow );
	
}


function selectNative()
{
	var wartosc = parseInt( document.getElementById('_id_przedmiot').value ); 
	var kto  = ( document.getElementById('_kto').checked == true) ? 1 : 2; 
	
	
	if(kto == 1 && wartosc >= 37 && wartosc <= 70  )
	{
		$('#natviespeaker').show();
	}
	else
	{
		$('#natviespeaker').hide();
	}

}


function selectText( myel )
{
	var obj = document.getElementById(myel);
    obj.select();
   
}

function deletephoto()
{
	//$('#myavatar').html('');
	ajaxget( '/myprofile/deletephoto');
	return false;
	
}


function submitForm()
{
	if( parseInt( document.getElementById('_idprzedmiot').value ) > 0  )
	{
		document.s1a.submit()
		return true;
	}
	else
	{
		window.alert('Wybierz przedmiot');
		return false;
	}
}



function changeSort( ktory, bar )
{
	//window.location.href=document.location.pathname+'?s2='+value
	
	if( bar == 'bottom' )
	{
		var sufx = 'bottom';
	}
	else
	{
		var sufx = '';
	}
	var tablink  = document.location.pathname.split('_');
	var len = tablink.length-1;
	var mylink = '';
	for( var i=0; i<len ; i++ )
	{
		if( i == 0 )
		{
			mylink = tablink[i];
		}
		else
		{
			mylink = mylink + '_' +tablink[i];
		}
	
	}
	if( ktory == 1 )
	mylink = mylink + '_1.html?s1='+$('#s1'+sufx).val()+'&s2='+$('#s2'+sufx).val();
	else
	mylink = mylink + '?s1='+$('#s1'+sufx).val()+'&s2='+$('#s2'+sufx).val();
	
	document.location.href = mylink;
	//alert( mylink );
}






function showhelp(myid, txt)
{
	$('#_help').html(txt);
	$('#_help').css("left", $('#'+myid).position().left); 
	$('#_help').css("top", $('#'+myid).position().top + 16); 
	
	$('#_help').show();
	


}

function hidehelp()
{
$('#_help').hide();
}



function addtoStart(obj)
{
if (document.all && navigator.appName != 'Netscape') { obj.style.behavior='url(#default#homepage)';obj.setHomePage(document.location.href); }

}

function addToFavorites()
 { 
 	 if (document.all && navigator.appName != 'Netscape')
      {
      	window.external.AddFavorite(location.href, document.title);
      }
      else
      {
      	window.alert('Aby dodać stronę do ulubionych skorzytaj z [ctrl+D]');
      }
      
} 


function pokazopcje( co , nr , wyroznione )
{
	if( co  == 'in' )
	{	
		$('#b'+nr).show();
		$('#r'+nr).css({ backgroundColor:"#F2F2F2"})
		
	}
	else
	{
		$('#b'+nr).hide();
		if( wyroznione == 1 )
		{
			$('#r'+nr).css({ backgroundColor:"#FFFBCC"})
		}
		else
		{
			$('#r'+nr).css({ backgroundColor:"#FFFFFF"})
		}
		
	}
	
	//
}

function me( myid, col, ev )
{
	if( col == 1 )
	{
		out = '414141';
		over = 'FEB300'; 
	
	}
	
	
	if( ev == 1 )
	{
		//over
		document.getElementById(myid).style.background = '#'+over;
		//alert('s');
	}
	else
	{
		//out
		document.getElementById(myid).style.background ='#'+out;
	
	}


}

/*
function zamknij(myid)
{
$('#'+myid).hide('slow');
}
*/

__przedmiot = '';

function p3(przedmiot, miasto, myid)
{
	$('#_miasta2').hide();
	$('#_miasta2').css("left", $('#'+myid).position().left); 
	$('#_miasta2').css("top", $('#'+myid).position().top + 14); 
	$('#_miasta2').show('slow');
	__przedmiot = przedmiot;
	
	
}

function ZmienForme(wartosc)
{

	if( wartosc == 2 )  
	{
		$('.t1').hide();
		$('.t2').hide();
		
		$('#f1').show();
		$('#f2').show();
		
		document.getElementById('cena').disabled = true;
		
	} 
	else 
	{
		$('.t1').show();
		$('.t2').show();
		document.getElementById('cena').disabled = false;
	}
	
	$('#f3').show();
	$('#f4').show();
	$('#f5').show();
	$('#f6').show();
	
	selectNative();
	
}

function p4( city )
{
	$('#miasto').val(city);
	$('#_miasta').toggle('slow');
}

function p2( city )
{
	//alert($('#miasto').position().left);
	//alert(__przedmiot);
	if( document.getElementById('kto').value == 1  )
	{
		var gdzie = 'korepetycje';
	}
	else
	{
		var gdzie = 'szukam_korepetytora';
	
	}
	
	
	document.location.href= gdzie+'_'+__przedmiot+'_'+city+'_1.html';
	
	//$('#miasto').val(city);
	//$('#_miasta').toggle('slow');

}

function p( myid )
{
	
	
	$('#'+myid).toggle('slow');
	

}


function mymenu( mytab )
{
	$('#kto').val(mytab);
	if( mytab == 1 )
	{
		$('#searchbar').css("background-color", "#D7D7D7");
		$('#opis1').text('Przeszukujesz teraz bazę korepetytorów');
		
		
	}
	else
	{
		$('#searchbar').css("background-color", "#7DCEF0");
		$('#opis1').text('Przeszukujesz teraz bazę uczniów, studentów');
	}
}


function rightbox( mytab )
{
	///id="_m1"
	$('#_m1').hide();
	$('#_m2').hide();
	$('#_m3').hide();
	$('#_m4').hide();
	$('#_m'+mytab).show('slow');
}


/**
 * @author grzegorz.banas
 */

function ShowGoogleMap( x, y)
{
	if (parseFloat(x) > 0 && parseFloat(y) > 0) 
	{
		x=  parseFloat(x);
		y=  parseFloat(y);
		//window.alert(x +'   '+ y);
		zoom = 12;
		
	}
	else
	{	x=  51.919438;
		y=  19.145136;
		zoom = 6;
	}
	
	load(x, y, zoom);
	document.getElementById('map').style.display = '';
	
	if (parseFloat(x) > 0 && parseFloat(y) > 0) 
	{
		var point = new GLatLng(x, y);
        map.setCenter(point,14); 
		
		var  marker = new GMarker(point);
        map.addOverlay(marker);
       	marker.openInfoWindowHtml(document.getElementById('google_marker').innerHTML);
      	
      
      	GEvent.addListener(marker, "click", function() {
         marker.openInfoWindowHtml(document.getElementById('google_marker').innerHTML);
        });
	}
	
}

function ShowGoogleMap2(x, y)
{
		x=  parseFloat(x);
		y=  parseFloat(y);
		load(x, y, 8);
	
}


function ShowAlert(myalert)
{
	if( myalert )
	{
		document.getElementById('alert').innerHTML = myalert;
		document.getElementById('alert').style.display = '';
		
	}
	else
	{
		document.getElementById('alert').style.display = 'none';
	}
	
}

var oldLink = null;
// code to change the active stylesheet
function setActiveStyleSheet(link, title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  if (oldLink) oldLink.style.fontWeight = 'normal';
  oldLink = link;
  link.style.fontWeight = 'bold';
  return false;
}

// This function gets called when the end-user clicks on some date.
function selected(cal, date) {
  cal.sel.value = date; // just update the date in the input field.
  if (cal.dateClicked && (cal.sel.id == "sel1" || cal.sel.id == "sel3"))
    // if we add this call we close the calendar on single-click.
    // just to exemplify both cases, we are using this only for the 1st
    // and the 3rd field, while 2nd and 4th will still require double-click.
    cal.callCloseHandler();
}

// And this gets called when the end-user clicks on the _selected_ date,
// or clicks on the "Close" button.  It just hides the calendar without
// destroying it.
function closeHandler(cal) {
  cal.hide();                        // hide the calendar
//  cal.destroy();
  _dynarch_popupCalendar = null;
}

// This function shows the calendar under the element having the given id.
// It takes care of catching "mousedown" signals on document and hiding the
// calendar if the click was outside.
function showCalendar(id, format, showsTime, showsOtherMonths) {
  var el = document.getElementById(id);
  if (_dynarch_popupCalendar != null) {
    // we already have some calendar created
    _dynarch_popupCalendar.hide();                 // so we hide it first.
  } else {
    // first-time call, create the calendar.
    var cal = new Calendar(1, null, selected, closeHandler);
    // uncomment the following line to hide the week numbers
    // cal.weekNumbers = false;
    if (typeof showsTime == "string") {
      cal.showsTime = true;
      cal.time24 = (showsTime == "24");
    }
    if (showsOtherMonths) {
      cal.showsOtherMonths = true;
    }
    _dynarch_popupCalendar = cal;                  // remember it in the global var
    cal.setRange(2008, 2070);        // min/max year allowed.
    cal.create();
  }
  _dynarch_popupCalendar.setDateFormat(format);    // set the specified date format
  _dynarch_popupCalendar.parseDate(el.value);      // try to parse the text in field
  _dynarch_popupCalendar.sel = el;                 // inform it what input field we use

  // the reference element that we pass to showAtElement is the button that
  // triggers the calendar.  In this example we align the calendar bottom-right
  // to the button.
  _dynarch_popupCalendar.showAtElement(el.nextSibling, "Br");        // show the calendar

  return false;
}


function MyScroller( IDkontener, ileWierszy, ilewidocznych )
{
	if( !document.getElementById(IDkontener) )
	{
		alert('Brak elementu kontenera');
		return ;
	}
	
	
	this.IDKontener = IDkontener;
	this.stopUp = ilewidocznych - ileWierszy; 
	this.wiersz = 1;
	
	this.move = function( typ ) 
	{
		try
		{
			if( typ == 'up' ) 
			{
				if( this.wiersz == this.stopUp  ) return ;
				
				$("#"+this.IDKontener).animate({"top": "-=93px"}, "slow");
				this.wiersz--;
			
			} 
			else
			{
				if( this.wiersz == 1  ) return ;
				$("#"+this.IDKontener).animate({"top": "+=93px"}, "slow");
				this.wiersz++;
				
			}
		}
		catch(e)
		{
			alert('Error in MyScroller.move');
		}
	}
}
