var IE = document.all?true:false



function ClearFields(){
     
	var tabs = document.getElementsByClassName('day free reserved');
//alert(tabs);
	var u= tabs.length;
  for(var i=0; i<u; i++){
    tabs[0].className = 'day free available';
  }
}


var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);

function checkAvailability(obj) {
	var link = obj;
	 for (i=1;i<=2;i++) {
		 if(link.hasClass('busy')||link.parent("div:last")) return false; 
		 link = link.next();
	 }
	 return true;
}
function ZamknijTerminarz() {
	$("#TerminarzZabiegow").fadeOut("fast",function () {
		$("#PageFade").fadeTo("slow", 0,function (){document.getElementById('PageFade').style.display = "none";} );
		
	}) ;
}
function OtworzTerminarz() {
	pageS = new Array();
	pages = getPageSize();
	document.getElementById('PageFade').style.height = pages[1]+'px';
	document.getElementById('PageFade').style.display = "block";
	$("#PageFade").fadeTo("slow",  0.6, function () {
		pollX = (pages[0]/2)-355+'px';
		document.getElementById('TerminarzZabiegow').style.left = pollX;
		
		if(IE)
		document.getElementById('TerminarzZabiegow').style.top = document.documentElement.scrollTop + 100 + 'px';
		else 
		document.getElementById('TerminarzZabiegow').style.top = window.pageYOffset + 100 + 'px';		
		document.getElementById('TerminarzZabiegow').style.display = "block";
	});
}


function ShowCom(){
	pageS = new Array();
	pages = getPageSize();
	CommentBox = (pages[0]/2)-175+'px';
	document.getElementById('Ulotka').style.left = CommentBox;
	if(IE)
	document.getElementById('Ulotka').style.top = document.documentElement.scrollTop + 100 + 'px';
	else 
	document.getElementById('Ulotka').style.top = window.pageYOffset + 100 + 'px';					
	document.getElementById('Ulotka').style.display = "block";	
}

function HideCom(){
	document.getElementById('Ulotka').style.display = "none";	
}


function getPageSize(){
	  var xScroll, yScroll;
	  if (window.innerHeight && window.scrollMaxY) {
	     xScroll = document.body.scrollWidth;
	     yScroll = window.innerHeight + window.scrollMaxY;
	  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
	     xScroll = document.body.scrollWidth;
	     yScroll = document.body.scrollHeight;
	  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
	     xScroll = document.body.offsetWidth;
	     yScroll = document.body.offsetHeight;
	  }
	  var windowWidth, windowHeight;
	  if (self.innerHeight) {   // all except Explorer
	     windowWidth = self.innerWidth;
	     windowHeight = self.innerHeight;
	  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
	     windowWidth = document.documentElement.clientWidth;
	     windowHeight = document.documentElement.clientHeight;
	  } else if (document.body) { // other Explorers
	     windowWidth = document.body.clientWidth;
	     windowHeight = document.body.clientHeight;
	  }
	  // for small pages with total height less then height of the viewport
	  if(yScroll < windowHeight){
	     pageHeight = windowHeight;
	  } else {
	     pageHeight = yScroll;
	  }
	  // for small pages with total width less then width of the viewport
	  if(xScroll < windowWidth){
	     pageWidth = windowWidth;
	  } else {
	     pageWidth = xScroll;
	  }
	  arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	  return arrayPageSize;
	}



function addOption(theSel, theText, theValue)
{
  var newOpt = new Option(theText, theValue);
  var selLength = theSel.length;
  theSel.options[selLength] = newOpt;
}

function deleteOption(theSel, theIndex)
{ 
  var selLength = theSel.length;
  if(selLength>0)
  {
    theSel.options[theIndex] = null;
  }
}

function addFriend(theSelFrom, theSelTo)
{
  
  var selLength = theSelFrom.length;
  var selectedText = new Array();
  var selectedValues = new Array();
  var selectedCount = 0;
  
  var i;
  
  // Find the selected Options in reverse order
  // and delete them from the 'from' Select.
  for(i=selLength-1; i>=0; i--)
  {
    if(theSelFrom.options[i].selected)
    {
      selectedText[selectedCount] = theSelFrom.options[i].text;
      selectedValues[selectedCount] = theSelFrom.options[i].value;
      deleteOption(theSelFrom, i);
      selectedCount++;
    }
  }
  
  // Add the selected text/values in reverse order.
  // This will add the Options to the 'to' Select
  // in the same order as they were in the 'from' Select.
  for(i=selectedCount-1; i>=0; i--)
  {
    addOption(theSelTo, selectedText[i], selectedValues[i]);
  }

  for(i=selectedCount-1; i>=0; i--)
  {
    theSelTo.options[i].selected = true;
  }  
  if(NS4) history.go(0);
}



function copyTextToInput(){

  var a = document.getElementById('my_select');
  for(var i = 0; i < a.length; i++) {
    if (a.options[i].selected == true) {
      var tekst=a.options[i].text;//+'&&'+a.options[i].text;
      document.getElementById('miasto_id').value=tekst;
     }
    }

}

function checkKey(event)
{
NS4 = (document.layers) ? true : false; 
var code = 0;

if (NS4) {
code = event.which;
}
else {
code = event.keyCode;
}
if (code==40) {
//alert(code);
//document.getElementById('my_select').options[1].selected=true;
document.getElementById('my_select').focus();
}
}


function checkEnter4(e)
{
 e=e||event;
 var code = e.which? e.which : e.keyCode;
  
if (code==13) {
  xajax_pass_remind(xajax.getFormValues('przypomnij'));
  
  //document.forms['szukanie_placowek'].akcja.value='szukaj';
  //document.forms['szukanie_placowek'].submit();
}

}

function checkEnter3(e)
{
 e=e||event;
 var code = e.which? e.which : e.keyCode;

if (code==13) {

  document.forms['szukanie_placowek'].akcja.value='szukaj';
  document.forms['szukanie_placowek'].submit();
}

}


function checkEnter2(e)
{
 e=e||event;
 var code = e.which? e.which : e.keyCode;

if (code==13) {
document.getElementById('login_form2').submit();
}

}

function checkEnter(e)
{
 e=e||event;
 var code = e.which? e.which : e.keyCode;

if (code==13) {
document.getElementById('login_form').submit();
}

} 

function productVote(id,type,msg) {
$('input[type=radio].star').rating({
	cancel : 'Cancel'
});
pageS = new Array();
pages = getPageSize();
//alert(pages[1]);
//document.getElementById('PageFade').style.width = pages[2]+'px';
document.getElementById('PageFade').style.height = pages[1]+'px';
document.getElementById('PageFade').style.display = 'block';
pollX = (pages[0]/2)-158+'px';
document.getElementById('productVote').style.left = pollX;

if(IE)
document.getElementById('productVote').style.top = document.documentElement.scrollTop + 350 + 'px';
else 
document.getElementById('productVote').style.top = window.pageYOffset + 250 + 'px';

document.getElementById('productVote').style.display = 'block';

document.getElementById('productVoteMSG').innerHTML = msg;
document.getElementById('productVoteID').value = id;
document.getElementById('productVoteTYPE').value = type;
}

function CloseProductVote() {
document.getElementById('PageFade').style.display = 'none';
document.getElementById('productVote').style.display = 'none';
}

function changeView(view) {
  document.getElementById('placesView').className = view;
}


function AddArtComment() {
document.getElementById('komunikat').innerHTML = "  ";
document.getElementById('ArtComments').style.display = "none";
document.getElementById('AddArtComments').style.display = "block";
}

function AddArtCommentBack() {

document.getElementById('ArtComments').style.display = "block";
document.getElementById('AddArtComments').style.display = "none";
}
function chgArticleBg(obj, spin) {
  if(spin==1) 
    obj.className = "articleItemOn";
  if(spin==0)
    obj.className = "articleItem";
}
function chgReviewBg(obj, spin) {
	  if(spin==1) 
	    obj.className = "reviewItemOn";
	  if(spin==0)
	    obj.className = "articleItem";
	}

function chgInfoBg(obj, spin) {
  if(spin==1) {
    obj.className = "infoItemOn";
    obj.style.backgroundColor = "#8bbb40";
  }
  if(spin==0) {
    obj.className = "infoItem";
    obj.style.backgroundColor = null;
  }
}


function ShowNewsletter() {
pageS = new Array();
pages = getPageSize();
//alert(pages[1]);
//document.getElementById('PageFade').style.width = pages[2]+'px';
document.getElementById('PageFade').style.height = pages[1]+'px';
document.getElementById('PageFade').style.display = 'block';
pollX = (pages[0]/2)-158+'px';
document.getElementById('NewsletterBox').style.left = pollX;

if(IE)
document.getElementById('NewsletterBox').style.top = document.documentElement.scrollTop + 350 + 'px';
else 
document.getElementById('NewsletterBox').style.top = window.pageYOffset + 250 + 'px';

document.getElementById('NewsletterBox').style.display = 'block';
}

function CloseNewsletter() {
document.getElementById('PageFade').style.display = 'none';
document.getElementById('NewsletterBox').style.display = 'none';
}

function getPageSize(){
  var xScroll, yScroll;
  if (window.innerHeight && window.scrollMaxY) {
     xScroll = document.body.scrollWidth;
     yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
     xScroll = document.body.scrollWidth;
     yScroll = document.body.scrollHeight;
  } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
     xScroll = document.body.offsetWidth;
     yScroll = document.body.offsetHeight;
  }
  var windowWidth, windowHeight;
  if (self.innerHeight) {   // all except Explorer
     windowWidth = self.innerWidth;
     windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
     windowWidth = document.documentElement.clientWidth;
     windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
     windowWidth = document.body.clientWidth;
     windowHeight = document.body.clientHeight;
  }
  // for small pages with total height less then height of the viewport
  if(yScroll < windowHeight){
     pageHeight = windowHeight;
  } else {
     pageHeight = yScroll;
  }
  // for small pages with total width less then width of the viewport
  if(xScroll < windowWidth){
     pageWidth = windowWidth;
  } else {
     pageWidth = xScroll;
  }
  arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
  return arrayPageSize;
}
function ShowFriendsList() {
	document.getElementById('friendsList').style.display = "block";
}
function HideFriendsList() {
	document.getElementById('friendsList').style.display = "none";
}


function selectAllCheck(theform) {
	for (i = 0; i < theform.elements.length; i++) {
		
	}
}


function CheckboxCheck(oObject, bMode)
{
var iObjectElements = document.getElementById(oObject).elements.length;
var bMode = (bMode === true) ? true : false;

for (iElement = 0; iElement < iObjectElements; iElement++)
{
if(document.getElementById(oObject).elements[iElement].type == "checkbox" && document.getElementById(oObject).elements[iElement].disabled == false)
{
document.getElementById(oObject).elements[iElement].checked = bMode;
}
}
}


function ShowClipboard() {
	pageS = new Array();
	pages = getPageSize();
	document.getElementById('PageFade').style.height = pages[1]+'px';
	document.getElementById('PageFade').style.display = "block";
	$("#PageFade").fadeTo("slow",  0.6, function () {
		pollX = (pages[0]/2)-158+'px';
		document.getElementById('clipboardBox').style.left = pollX;
		
		if(IE)
		document.getElementById('clipboardBox').style.top = document.documentElement.scrollTop + 100 + 'px';
		else 
		document.getElementById('clipboardBox').style.top = window.pageYOffset + 100 + 'px';		
		$("#clipboardBox").fadeIn("def", function () {
	myScroll2 = new ScrollVObj(20,87,380,"scrTrack2","scrDec2","scrInc2","scrDrag2","scrContentMask2","scrContent2");});
	});


}
function CloseClipboard(){
	$("#clipboardBox").fadeOut("fast",function () {
		$("#PageFade").fadeTo("slow", 0,function (){document.getElementById('PageFade').style.display = "none";} );
		
	}) ;
}

function initTerminarz(){
	 $("div.Weekday div.day a").hover(
			 function(){
				 link = $(this).parent();
				 if(link.hasClass("available")) {
					 for(i=0;i<dlZabiegu;i++){
					 link.addClass("reserved");
					 link = link.next();
					 }
				 }
			 },
			 function(){
				 link = $(this).parent();
				 if(link.hasClass("available")) {
				 for(i=0;i<dlZabiegu;i++){
				 link.removeClass("reserved");
				 link = link.next();
				 }
				 }
			 }
	 )
	 
	 $("div.Weekday div.day a").click(function(){
		 link = link1 = $(this).parent();
		 if(link.hasClass("available")) {
			 for(i=0;i<dlZabiegu;i++){
			 link.removeClass("available");
			 link1.removeClass("available");
			 //link.addClass("reserved");
			 link = link.next();
			 link1 = link1.prev();
			 } 
		 }
	 })	
}

 $(document).ready(function(){
	 
	 jPages = getPageSize();
	 initTerminarz();
	 //$('#formFote').customFileInput();
	 $("#KonkursDiv").css({
		 'left' : (jPages[0]/2)-325+'px',
		 'display' : 'block'
	 });
	 
   $(this).css("color","red");
   
   $("span.showMenu").hover(
      function () {
        $(this).css("text-decoration","underline");
      }, 
      function () {
        $(this).css("text-decoration","none");
      }
    );

$("span.showMenu").click(function(){
  if(_zwiniete==0) {
   xajax_zwinRozwin();
    $(this).addClass("showMenuON");
	$(this).text("rozwiń");
	$("div.profilBOX").slideUp();
	$("div#socLogout").addClass("greenBotOut");
	$("div.greenBot:first").css("background-position","left bottom");
  } else
  {
  xajax_zwinRozwin();
    $(this).removeClass("showMenuON");
	$(this).text("zwiń");
	$("div.profilBOX").slideDown();
	$("div#socLogout").removeClass("greenBotOut");
	$("div.greenBot:first").css("background-position","left top");
  }
});
   
//   
// $("input[type=file]").filestyle({ 
//     image: _templates_dir+"gfx/file-button.gif",
//     imageheight : 20,
//     imagewidth : 115,
//     width : 200
// });




});

 function Zacheta(){
	 
 }
 
 function KonkursDivClose() {
	 document.getElementById('KonkursDiv').style.display = "none";
 }
