var MaxLengthLock = false;
var loginFlowBoxClickPriority = false;
var optionalPopupClickPriority = false;
var calendarClickPriority = false;
var detailStatsBoxPriority = false;
var messageWindowPriority = false;
var canPublish = false;
var addEventStarted = false;

function MaxLengthCount(fieldObj,fieldMaxLength,mess) 
{ 
  if (!MaxLengthLock) 
  { 
    MaxLengthLock = true; 
    if (fieldObj.value.length > fieldMaxLength) 
    { 
      alert(mess + " (" + fieldMaxLength +")"); 
      fieldObj.value = fieldObj.value.substring(0,fieldMaxLength); 
    } 
    var percentage = parseInt(100 - (( fieldMaxLength - fieldObj.value.length) * 100)/fieldMaxLength); 
    document.getElementById(fieldObj.id + "_PBar").style.width = parseInt((parseInt(fieldObj.offsetWidth)*percentage)/100)+"px"; 
    MaxLengthLock = false; 
  } 
} 

function itemCheck(inputCheck,imgCheck) {

   img_check_value = document.getElementById(inputCheck);
   img_check_img = document.getElementById(imgCheck);

   if (img_check_value.value == 0) {
    img_check_value.value = 1;
    img_check_img.src = img_check_img.src.split('-')[0] + "-" + "1.gif";
   } else {
    img_check_value.value = 0;
    img_check_img.src = img_check_img.src.split('-')[0] + "-" + "0.png";
   }
   
   if (document.getElementById('submitDay') != null) {
	checkIfSaved('');
    document.getElementById('submitDay').id = 'submitDay1';
   }
   
   if (document.getElementById('submitOldDay') != null) {
	checkIfSaved('');
    document.getElementById('submitOldDay').id = 'submitOldDay1';
   }
}

function checkIfSaved(form) {
	
	if (addEventStarted == false) {
	
		addEventStarted = true;
		
		hlaska = 'You have unsaved changes. Do you really want to leave the page?';
		
		/*
		/*
		/* resim okazy mimo
		*/
		// prochazim linky a pridavam udalost
		for ( var i in document.links )
		{
	
			var href = document.links[i].href;
			document.links[i].rel = href;
			
			// pokud se jedna o IE7 tak zapisuju do href #
			if (navigator.appName == 'Microsoft Internet Explorer' && 
				navigator.appVersion.search('MSIE 7') != -1) {
				document.links[i].href = '#';
			} else {
				document.links[i].href = 'javascript:void(0);';
			}
			
			
			
			addEvent( document.links[i], 'click', function()
				{ 
				var r=confirm(hlaska)
				if (r==true)
				  {
				  window.location = '' + this.rel;
				  return false;
				  }
				else
				  {
				  return false;
				  }
				}
			);
		}
		
		/*
		/*
		/* resim kalendar
		*/
		// nacitam mesic a rok
		var monthYear = (document.getElementById("display").firstChild.firstChild.firstChild.firstChild.firstChild.innerHTML);
		// resim rok
		var pos = monthYear.indexOf(", ");
		var year = monthYear.substr(pos+2,4);
		// resim mesic
		var monthName = monthYear.substr(0, pos);
		var months=new Array(12);
		months[1]="January";
		months[2]="February";
		months[3]="March";
		months[4]="April";
		months[5]="May";
		months[6]="June";
		months[7]="July";
		months[8]="August";
		months[9]="September";
		months[10]="October";
		months[11]="November";
		months[12]="December";
		
		var month;
		for ( var i in months )
		{
			if (months[i] == monthName) {
				month = i;	
			}
		};
		
		if (month < 10) month = '0' + month;
		
		// toto je link ktery se provede pokud user bude chtit pokracovat, prestoze nema ulozeny denicek
		var pathLink = 'y' + year + 'm' + month + 'd'; 
		
		// hledam vybrany den kalendare a kterym dnem zacina
		var day;
		var fdow = 2;
		for ( var i in document.getElementsByTagName("td"))
		{
			var obj = document.getElementsByTagName("td")[i];
			var cls = '' + obj.className;
			// zjistuju od ktereho dne je zobrazeny kalendar
			if (cls.search('name') != -1 && fdow == 2) {
					var dayName = document.getElementsByTagName("td")[i].innerHTML;
					fdow = dayName == 'Sun' ? 0 : 1;
			}
			// vybrany den
			if (cls.search('selected') != -1) {
					day = document.getElementsByTagName("td")[i].innerHTML;
					if (day < 10) day = '0' + day;
					break;
			}
			
		}
		if (fdow == 2) fdow = 0;
		
		// vyprazdnuju kalendar
		document.getElementById("display").innerHTML = '';
		// rusim mooznost brouzdani pomoci kalendare
		if (noEvent) noEvent = false;
		
		// formatuju dnesni datum a aktualni datum v kalendari
		var d = new Date();
		var tYear = d.getFullYear();
		var tMonth = d.getMonth() + 1; 
		if (tMonth < 10) tMonth = '0' + tMonth;
		var tDay = d.getDate();
		if (tDay < 10) tDay = '0' + tDay;
		var today = '' + tYear + tMonth + tDay;
		var iDate = '' + year + month + day;
		
		// stavim novy kalendar kde nefunguji kliknuti
		showFlatCalendar(iDate, fdow, today);
		
		// prochazim calendar a pridavam udalost
		for ( var i in document.getElementsByTagName("td"))
		{
				addEvent( document.getElementsByTagName("td")[i], 'click', function()
					{ 
					var r=confirm(hlaska)
					if (r==true)
					  {
					  var myDay = this.innerHTML;
					  if (myDay < 10) myDay = '0' + myDay;
					  window.location = '../' + pathLink + myDay;
					  return false;
					  }
					else
					  {
					  return false;
					  }
					}
				);
		}
	}
		/*
		/*
		/* resim odesilaci button
		*/
		var button = 'submitDay';
		if (form != 'tweet') {
				
				// pokud voli, tak povoluju klik na tlacitko save changes
				button = 'submitTweet';

				if (document.getElementById('submitDay')) {
					
					post = document.getElementById('submitDay');
					post.onclick = '';
					
					var newInput = document.createElement('input');
					newInput.type = 'button'; // that should work even with IE
					newInput.name = post.name;
					newInput.id = post.id;
					newInput.value = newInput.defaultValue = post.value;
					post.parentNode.replaceChild(newInput, post);
					
					addEvent( document.getElementById('submitDay'), 'click', function()
							{ 							
									facebookPublish();  
							}
						);
					
				}
				
				
		} 
			if (document.getElementById(button)) {
				// odstranuju udalost s post tlacitka status reports
				post = document.getElementById(button);
				post.onclick = '';
				//alert(post.type);
				//post.type = 'button';
				
				
				var newInput = document.createElement('input');
				newInput.type = 'button'; // that should work even with IE
				newInput.name = post.name;
				newInput.id = post.id;
				newInput.value = newInput.defaultValue = post.value;
				post.parentNode.replaceChild(newInput, post);
				
				
				// pridavam udalost na post tlacitko pro status reports
				addEvent( document.getElementById(button), 'click', function()
							{ 
							var r=confirm(hlaska)
							if (r==true)
							  {
							  if (form == 'tweet' || document.getElementById(button).id == 'submitTweet') {
								  	
									
									if (navigator.userAgent.search("Firefox") != -1) {
										facebookPublish();
									} else {
										if (window.event.srcElement.id == 'submitDay') {
											facebookPublish(); 
										} else {
											facebookTweetPublish();
										}
									}
							  } else {
									
									facebookPublish();  
							  }
							  return false;
							  }
							else
							  {
							  return false;
							  }
							}
						);
			}
		 
	
	
}

function paramCheck(oldvalue, newvalue, inputCheck, paramCheck1, paramCheck2, paramCheck3, paramCheck4, paramCheck5) {

   param_check_value = document.getElementById(inputCheck);
   param_check_one = document.getElementById(paramCheck1);
   param_check_two = document.getElementById(paramCheck2);
   param_check_three = document.getElementById(paramCheck3);
   param_check_four = document.getElementById(paramCheck4);
   param_check_five = document.getElementById(paramCheck5);
   
   if (oldvalue == 1) {
     param_check_one.src = param_check_one.src.split('-')[0] + "-" + "0.png";
   }
   if (oldvalue == 2) {
     param_check_two.src = param_check_two.src.split('-')[0] + "-" + "0.png";
   }
   if (oldvalue == 3) {
     param_check_three.src = param_check_three.src.split('-')[0] + "-" + "0.png";
   }
   if (oldvalue == 4) {
     param_check_four.src = param_check_four.src.split('-')[0] + "-" + "0.png";
   }
   if (oldvalue == 5) {
     param_check_five.src = param_check_five.src.split('-')[0] + "-" + "0.png";
   }
   
   if (newvalue == 1) {
     param_check_one.src = param_check_one.src.split('-')[0] + "-" + "1.png";
   }
   if (newvalue == 2) {
     param_check_two.src = param_check_two.src.split('-')[0] + "-" + "1.png";
   }
   if (newvalue == 3) {
     param_check_three.src = param_check_three.src.split('-')[0] + "-" + "1.png";
   }
   if (newvalue == 4) {
     param_check_four.src = param_check_four.src.split('-')[0] + "-" + "1.png";
   }
   if (newvalue == 5) {
     param_check_five.src = param_check_five.src.split('-')[0] + "-" + "1.png";
   }
   
   param_check_value.value = newvalue;
   
   if (oldvalue != newvalue) {
       if (document.getElementById('submitDay') != null) {
		checkIfSaved('');
        document.getElementById('submitDay').id = 'submitDay1';
       }
       
       if (document.getElementById('submitOldDay') != null) {
		checkIfSaved('');
        document.getElementById('submitOldDay').id = 'submitOldDay1';
       }
   }
}

function textAreaCounter(field,cntfield,maxlimit) {

if (field != '') {
  if (field.value.length > maxlimit) {
    field.value = field.value.substring(0, maxlimit);
  } else {
    if (field.value != 'Write a summary of your day here') {
      cntfield.value = maxlimit - field.value.length;
    } else {
      cntfield.value = maxlimit;
    }
  }
} else {
  cntfield.value = maxlimit;  
} 
   
   if(cntfield.id != 'counter') { //tyka se tweet textu
     if (document.getElementById('submitDay') != null) {
	  checkIfSaved('');
      document.getElementById('submitDay').id = 'submitDay1';
     }  
   }
   if(field.name == 'tweet') {
	   if (document.getElementById('submitTweet') != null) {
	   	if (document.getElementById('submitTweet').className == '') {
	   		if (document.getElementById('submitDay') != null) {
				checkIfSaved('tweet');
				//alert('kuk');
       			document.getElementById('submitTweet').className = 'tweetSend';
			}
		}
     }  
   }
}

function removeFriend(whose,who) {

  window.location = "/removeFriend.php?whose=" + whose + "&who=" + who;
}

function addFriendToTop(whose,who) {

  window.location = "/addFriendToTop.php?whose=" + whose + "&who=" + who;
}

function removeFriendFromTop(whose,who) {

  window.location = "/removeFriendFromTop.php?whose=" + whose + "&who=" + who;
}

function topFriendsFullAlert() {
  alert("friends TOP are full");
}

function getNowDateStatement(alt) {
  
  var date=new Date();
  var daystring = '';
  var month=date.getMonth();
  month++;
  
	if(month==1) {month = "January";}
	else if(month==2) {month = "February";}
	else if(month==3) {month = "March";}
	else if(month==4) {month = "April";}
	else if(month==5) {month = "May";}
	else if(month==6) {month = "June";}
	else if(month==7) {month = "July";}
	else if(month==8) {month = "August";}
	else if(month==9) {month = "September";}
	else if(month==10) {month = "October";}
	else if(month==11) {month = "November";}
	else if(month==12) {month = "December";}
  
  if(date.getDay()==0) {daystring = "Sunday";}
	else if(date.getDay()==1) {daystring = "Monday";}
	else if(date.getDay()==2) {daystring = "Tuesday";}
	else if(date.getDay()==3) {daystring = "Wednesday";}
	else if(date.getDay()==4) {daystring = "Thursday";}
	else if(date.getDay()==5) {daystring = "Friday";}
	else if(date.getDay()==6) {daystring = "Saturday";}

  return "<div id=\"dateStatement\"><span id=\"month\">" + month + "</span><span id=\"day\"><h1>" + date.getDate() + "</h1></span><span id=\"year\">" + date.getFullYear() + "</span><span id=\"dayString\"><strong>" + daystring + "</strong></span><div id=\"to_stats\"><a href=\"http://www.daileez.com/yesterday/\" title=\""+ alt +"\"><span class=\"dNone\">&laquo;</span></a></div></div>";
}

function loginBoxVisibilityHidden() {
  document.getElementById("loginFlowBox").style.visibility="hidden";
}

function loginBoxVisibility() {
  if (document.getElementById("loginFlowBox").style.visibility == "hidden") {
    document.getElementById("loginFlowBox").style.visibility="visible";
    document.getElementById('loginForm').getElementsByTagName('input')[1].focus();
  } else {
    document.getElementById("loginFlowBox").style.visibility="hidden";
  }
  loginFlowBoxClickPriority = true;
}

function disallowHiddenLoginBox() {
  loginFlowBoxClickPriority = true;
}

function disallowHiddenOptionalPopup() {
  optionalPopupClickPriority = true;
}

/**
 * global HIDDEN
 * 
 */  
function visibilityGlobalHidden() {
  if (!messageWindowPriority) {
    var messageWindow = document.getElementById("messageWindow"); 
    if (messageWindow != null) {
      messageWindow.style.visibility = "hidden"
    }
  }
  
  messageWindowPriority = false;
  
  if (!calendarClickPriority) {
    calendar = document.getElementById("display");
    if (calendar != null) {
      calendar.style.visibility = "hidden";
    }
  }
  
  calendarClickPriority = false;
  
  if (!loginFlowBoxClickPriority) {
    if (document.getElementById("loginFlowBox") != null) {
      if (document.getElementById("loginFlowBox").style.visibility == "visible") {
        document.getElementById("loginFlowBox").style.visibility="hidden";
      }
    }
  }
  
  loginFlowBoxClickPriority = false;
}

function visibilityGlobalHiddenPrefix() {
  
  if (!optionalPopupClickPriority) {
    var optionalSetupWindow = document.getElementById("optionalSetupWindow");
    if (optionalSetupWindow != null) {
      //optionalSetupWindow.style.visibility = "hidden";
    }
    
    var optionalSetupForm = document.getElementById("optionalSetupForm");
    if (optionalSetupForm != null) {
      //optionalSetupForm.style.visibility = "hidden";
    }
  }

  optionalPopupClickPriority = false;
  
  if (!detailStatsBoxPriority) {
    detailstatsbox = document.getElementById("detailStatsBox");
    if (detailstatsbox != null) {
      detailstatsbox.style.visibility = "hidden";
    }
  }

  detailStatsBoxPriority = false;
}

function preloadDetailStatsImages() {

  preloadI1 = new Image(); preloadI1.src = "http://daileez.com/_prefix/html/img/items/itemAVeryBad-0-30.png";
  preloadI2 = new Image(); preloadI2.src = "http://daileez.com/_prefix/html/img/items/itemABad-0-30.png";
  preloadI3 = new Image(); preloadI3.src = "http://daileez.com/_prefix/html/img/items/itemANormal-0-30.png";
  preloadI4 = new Image(); preloadI4.src = "http://daileez.com/_prefix/html/img/items/itemAGood-0-30.png";
  preloadI5 = new Image(); preloadI5.src = "http://daileez.com/_prefix/html/img/items/itemAVeryGood-0-30.png";
  
  preloadI6 = new Image(); preloadI6.src = "http://daileez.com/_prefix/html/img/items/itemBVeryBad-0-30.png";
  preloadI7 = new Image(); preloadI7.src = "http://daileez.com/_prefix/html/img/items/itemBBad-0-30.png";
  preloadI8 = new Image(); preloadI8.src = "http://daileez.com/_prefix/html/img/items/itemBNormal-0-30.png";
  preloadI9 = new Image(); preloadI9.src = "http://daileez.com/_prefix/html/img/items/itemBGood-0-30.png";
  preloadI10 = new Image(); preloadI10.src = "http://daileez.com/_prefix/html/img/items/itemBVeryGood-0-30.png";
  
  preloadI11 = new Image(); preloadI11.src = "http://daileez.com/_prefix/html/img/items/itemCVeryBad-0-30.png";
  preloadI12 = new Image(); preloadI12.src = "http://daileez.com/_prefix/html/img/items/itemCBad-0-30.png";
  preloadI13 = new Image(); preloadI13.src = "http://daileez.com/_prefix/html/img/items/itemCNormal-0-30.png";
  preloadI14 = new Image(); preloadI14.src = "http://daileez.com/_prefix/html/img/items/itemCGood-0-30.png";
  preloadI15 = new Image(); preloadI15.src = "http://daileez.com/_prefix/html/img/items/itemCVeryGood-0-30.png";
  
  preloadI16 = new Image(); preloadI16.src = "http://daileez.com/_prefix/html/img/items/itemDVeryBad-0-30.png";
  preloadI17 = new Image(); preloadI17.src = "http://daileez.com/_prefix/html/img/items/itemDBad-0-30.png";
  preloadI18 = new Image(); preloadI18.src = "http://daileez.com/_prefix/html/img/items/itemDNormal-0-30.png";
  preloadI19 = new Image(); preloadI19.src = "http://daileez.com/_prefix/html/img/items/itemDGood-0-30.png";
  preloadI20 = new Image(); preloadI20.src = "http://daileez.com/_prefix/html/img/items/itemDVeryGood-0-30.png";
  
  preloadI21 = new Image(); preloadI21.src = "http://daileez.com/_prefix/html/img/layout/iphone/bg_boxParamR.png";
  preloadI22 = new Image(); preloadI22.src = "http://daileez.com/_prefix/html/img/layout/iphone/bg_boxParam.png";
  
}

function generateDetailStatsBox(month,type,value1,value2,value3,value4,value5,mob) {
  
  if(month == 1) { lft = 334;
  } else if(month == 2) { lft = 331;
  } else if(month == 3) { lft = 328;
  } else if(month == 4) { lft = 186;
  } else if(month == 5) { lft = 183;
  } else if(month == 6) { lft = 179;
  } else if(month == 7) { lft = 4;
  } else if(month == 8) { lft = 1;
  } else if(month == 9) { lft = -3;
  } else if(month == 10) { lft = -143;
  } else if(month == 11) { lft = -146;
  } else { lft = -150;
  }
  
  urlImg = "http://daileez.com/_prefix/html/img";
  
  img1 = "url(" + urlImg + "/layout/iphone/bg_boxParamR.png)";
  img2 = "url(" + urlImg + "/layout/iphone/bg_boxParam.png)";
  
  obj = document.getElementById("detailStatsBox");
  
  if(mob=="y") {
	  obj.style.left = lft + "px";
	  (month > 3 && month < 7) || (month > 9) ? obj.style.backgroundImage=img1 : obj.style.backgroundImage=img2;
  }
  
  if(type=="weather") {
    document.getElementById("detailIcon1").src = urlImg + "/items/itemAVeryBad-0-30.png";
    document.getElementById("detailIcon2").src = urlImg + "/items/itemABad-0-30.png";
    document.getElementById("detailIcon3").src = urlImg + "/items/itemANormal-0-30.png";
    document.getElementById("detailIcon4").src = urlImg + "/items/itemAGood-0-30.png";
    document.getElementById("detailIcon5").src = urlImg + "/items/itemAVeryGood-0-30.png";
	if(mob=="y") {
		(month < 7) ? obj.style.marginTop = "155px" : obj.style.marginTop = "234px";
	} else {
		obj.style.marginTop = "70px";
  	}
  } else if (type=="happiness") {
    document.getElementById("detailIcon1").src = urlImg + "/items/itemBVeryBad-0-30.png";
    document.getElementById("detailIcon2").src = urlImg + "/items/itemBBad-0-30.png";
    document.getElementById("detailIcon3").src = urlImg + "/items/itemBNormal-0-30.png";
    document.getElementById("detailIcon4").src = urlImg + "/items/itemBGood-0-30.png";
    document.getElementById("detailIcon5").src = urlImg + "/items/itemBVeryGood-0-30.png";
	if(mob=="y") {
		(month < 7) ? obj.style.marginTop = "358px" : obj.style.marginTop = "437px";
	} else {
		obj.style.marginTop = "160px";
	}
  } else if (type=="sleep") {
    document.getElementById("detailIcon1").src = urlImg + "/items/itemCVeryBad-0-30.png";
    document.getElementById("detailIcon2").src = urlImg + "/items/itemCBad-0-30.png";
    document.getElementById("detailIcon3").src = urlImg + "/items/itemCNormal-0-30.png";
    document.getElementById("detailIcon4").src = urlImg + "/items/itemCGood-0-30.png";
    document.getElementById("detailIcon5").src = urlImg + "/items/itemCVeryGood-0-30.png";
	if(mob=="y") {
		(month < 7) ? obj.style.marginTop = "561px" : obj.style.marginTop = "640px";
	} else {
		obj.style.marginTop = "250px";
	}
  } else {
    document.getElementById("detailIcon1").src = urlImg + "/items/itemDVeryBad-0-30.png";
    document.getElementById("detailIcon2").src = urlImg + "/items/itemDBad-0-30.png";
    document.getElementById("detailIcon3").src = urlImg + "/items/itemDNormal-0-30.png";
    document.getElementById("detailIcon4").src = urlImg + "/items/itemDGood-0-30.png";
    document.getElementById("detailIcon5").src = urlImg + "/items/itemDVeryGood-0-30.png";
	if(mob=="y") {
		(month < 7) ? obj.style.marginTop = "764px" : obj.style.marginTop = "843px";
	} else {
		obj.style.marginTop = "340px";
	}
  }
  
  document.getElementById("detailValue1").innerHTML = value1;
  document.getElementById("detailValue2").innerHTML = value2;
  document.getElementById("detailValue3").innerHTML = value3;
  document.getElementById("detailValue4").innerHTML = value4;
  document.getElementById("detailValue5").innerHTML = value5;
  
  var max = 0;
  if (value1 > max) max = value1;
  if (value2 > max) max = value2;
  if (value3 > max) max = value3;
  if (value4 > max) max = value4;
  if (value5 > max) max = value5;
  
  if (max != 0) {
    var q = 60 / max;
  } else {
    var q = 60;
  }
  
  var barrelValue1 = Math.floor(q * value1);
  var barrelValue2 = Math.floor(q * value2);
  var barrelValue3 = Math.floor(q * value3);
  var barrelValue4 = Math.floor(q * value4);
  var barrelValue5 = Math.floor(q * value5);
  
  if (navigator.appName == "Microsoft Internet Explorer") {
    var marginTopExplorer = 8;
  } else {
    var marginTopExplorer = 0;
  }
  
  document.getElementById("barrel1").style.marginTop = (60 - barrelValue1 + marginTopExplorer) + "px";
  document.getElementById("barrel2").style.marginTop = (60 - barrelValue2 + marginTopExplorer) + "px";
  document.getElementById("barrel3").style.marginTop = (60 - barrelValue3 + marginTopExplorer) + "px";
  document.getElementById("barrel4").style.marginTop = (60 - barrelValue4 + marginTopExplorer) + "px";
  document.getElementById("barrel5").style.marginTop = (60 - barrelValue5 + marginTopExplorer) + "px";
  
  if (navigator.appName == "Microsoft Internet Explorer") {
    document.getElementById("barrel1").style.height = (barrelValue1 + 41) + "px";
    document.getElementById("barrel2").style.height = (barrelValue2 + 41) + "px";
    document.getElementById("barrel3").style.height = (barrelValue3 + 41) + "px";
    document.getElementById("barrel4").style.height = (barrelValue4 + 41) + "px";
    document.getElementById("barrel5").style.height = (barrelValue5 + 41) + "px";
  }

  document.getElementById("barrel1image").style.height = barrelValue1 + "px";
  document.getElementById("barrel2image").style.height = barrelValue2 + "px";
  document.getElementById("barrel3image").style.height = barrelValue3 + "px";
  document.getElementById("barrel4image").style.height = barrelValue4 + "px";
  document.getElementById("barrel5image").style.height = barrelValue5 + "px";
  
  obj.style.marginLeft = (90 + month * 55)+"px";
  obj.style.visibility = "visible";

  detailStatsBoxPriority = true;
}

function changePasswordHidden() {
  box = document.getElementById("box_change");
  box.style.height = "1px";
  box.style.visibility = "hidden";
}

function changePassword() {
  box = document.getElementById("box_change");
  box_button = document.getElementById("box_change_button");
  box_button.disabled = "disabled";
  box.style.height = "125px";
  box.style.visibility = "visible";
}

function hidePopupCalendar() {
  calendar = document.getElementById("display");
  calendar.style.visibility = "hidden";
}

function showPopupCalendar() {
  calendar = document.getElementById("display");
  calendar.style.visibility = "visible";
  calendarClickPriority = true;
}

function disallowHiddenCalendar() {
  calendarClickPriority = true;
}

function googleAnalytics() {
  
  var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
  document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
  
  try {
    var pageTracker = _gat._getTracker("UA-11279790-1");
    pageTracker._setDomainName(".daileez.com");
	pageTracker._setAllowLinker(true);
	pageTracker._setAllowHash(false);
    pageTracker._trackPageview();
  } catch(err) {alert(err);}
}

function deactivateDeleteChanger($selection) {
  
  if ($selection == 0) {
    document.getElementById("box_change").style.fontWeight = "bold";
    document.getElementById("box_change1").style.fontWeight = "normal";
  } else {
    document.getElementById("box_change").style.fontWeight = "normal";
    document.getElementById("box_change1").style.fontWeight = "bold";
  }
}

function facebookPublish() {  

	
  if (!document.getElementById("send_facebook").checked) {
  	
    facebookCallback();
  
  } else {

	FB.login(function(response) {
	  if (response.session) {
		
		facebookCallback();
	  
	  } else {
		
		facebookCallback();
	  
	  }
	}, {perms:'publish_stream'});

    
  }
}


function facebookTweetPublish() {  
  
  if (!document.getElementById("send_tweet_facebook").checked) {
  
    facebookTweetCallback();
  
  } else {
  
    /*var odkaz = 'http://www.daileez.com';
  
    var attachment = {
      'name':'DAILEEZ.COM', 
      'href':odkaz
      };
      
    var action_links = [{'text':'www.daileez.com', 'href':' http://www.daileez.com'}]; */
    
    /*FB.Connect.streamPublish(document.getElementById("tweetTextArea").value, attachment, action_links, null, null, facebookTweetCallback);*/
	
	FB.login(function(response) {
	  if (response.session) {
		
		facebookPublishStatusReport();
	  
	  } else {
		
		facebookTweetCallback();
	  
	  }
	});
	
	
	
    
  }
}


function facebookPublishStatusReport() {


FB.ui(
	   {
		 method: 'stream.publish',
		 message: document.getElementById("tweetTextArea").value,
		 attachment: {
		   name: 'DAILEEZ.COM',
		   href: 'http://www.daileez.com'
		 },
		 action_links: [
		   {'text':'www.daileez.com', 'href':' http://www.daileez.com'}
		 ],
		 user_message_prompt: null
	   },
	   function(response) {
		 if (response && response.post_id) {
		   facebookTweetCallback();
		 } else {
		   facebookTweetCallback();
		 }
	   }
	 );

	
}

function facebookCallback() {
  
  document.form.submit();
}

function facebookTweetCallback() {
  
  document.tweetForm.submit();
}

function newAccountSubmit() {
  
  if(
    document.getElementById("user_name").value == '' ||
    document.getElementById("user_email").value == '' ||
    document.getElementById("user_password").value == '' ||
    document.getElementById("user_password_znovu").value == '' ||
    document.getElementById("timezone").value == '' ||
    document.getElementById("captcha").value == '' ||
    !document.getElementById("termsAndPrivacy").checked)
  {    
    document.getElementById("messageWindow").style.visibility = "visible";
    messageWindowPriority = true;
  
  } else {
    document.form.submit();
  }
}

function FBnewAccountSubmit() {
  
  if(
    document.getElementById("user_name").value == '' ||
    !document.getElementById("termsAndPrivacy").checked)
  {    
    document.getElementById("messageWindow").style.visibility = "visible";
    messageWindowPriority = true;
  
  } else {
    document.form.submit();
  }
}

function messageWindowHidden() {
  if (document.getElementById("messageWindow") != null) {
    document.getElementById("messageWindow").style.visibility = "hidden";
  }
}

function refreshCaptcha() {

    var http_request = false;

    if (window.XMLHttpRequest) {
        http_request = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        try {
          http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (eror) {
          http_request = new ActiveXObject("Microsoft.XMLHTTP");
        }
    }

    http_request.onreadystatechange = function() { zpracujAjax(http_request); };
    http_request.open('GET', 'http://www.daileez.com/_www/generateCaptcha.php', true);
    http_request.send(null);
}

function zpracujAjax(http_request) {
  if (http_request.readyState == 4) {
    if (http_request.status == 200) {
      document.getElementById("captchaImg").src = http_request.responseText;
    }
  }
}

function clearIfDefault(textArea) {
  if (textArea.value == 'Write a summary of your day here' || textArea.value == 'Write what you\'re thinking, feeling, or doing at the moment here') {
    textArea.value = '';
  }
}

function printMail(start, middle, end) {
	majl = start + "@" + middle + "." + end;
	html = '<a href="mailto:' + majl + '">' + majl + '</a>';
	return document.write(html);
}
/*
function loginUser() {
	window.location = 'http://www.daileez.com/?act=fblogin';	
}*/

function logoutUser() {
	//FB.Connect.logout(function() { window.location = 'http://www.daileez.com/?act=fblogout'; });
	
	var odkaz = '' + window.location;
	var dialog = {
	method: 'fbml.dialog',
	fbml: '<fb:header icon="false" decoration="no_padding"><div style="background-color: #6d84b4; color: #fff; padding: 10px; border-bottom: 1px solid #3b5998;">Logged Out of Facebook</div></fb:header><div style="padding: 20px 10px;">You are logging out of both this site and Facebook.</div><div style="background-color: #f7f7f7; padding: 10px; border-top: 1px solid #cccccc;"><a style="float: right; display: block; width: 58px; height: 20px; background: url('+ odkaz +'/html/img/layout/FBclose.png) no-repeat;" href="http://www.daileez.com/?act=fblogout" target="_parent"><span style="display: none;">close</span></a><div style="clear:both; height: 0; line-height: 0; font-size: 0;"></div></div>',
	width: 800,
	height: 100
	  };
	  FB.ui(dialog, FBlogout());
}

function FBlogout() {
	
	FB.logout(function(response) {
		setTimeout("window.location = 'http://www.daileez.com/?act=fblogout'", 2000);
	})
}


function addEvent( obj, type, fn ) {
  if ( obj.attachEvent ) {
    obj['e'+type+fn] = fn;
    obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
    obj.attachEvent( 'on'+type, obj[type+fn] );
  } else
    obj.addEventListener( type, fn, false );
}
function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, obj[type+fn] );
    obj[type+fn] = null;
  } else
    obj.removeEventListener( type, fn, false );
}

