﻿// Java Script functions for thessaloniki city guide index.php page
function addFavourite() {
  var BookmarkURL="http://www.thessalonikicityguide.gr"
  var BookmarkTitle="Thessaloniki City Guide"
  // If the browser is Internet Explorer
  if (document.all)
  {
   // Add to Favorites (Internet Explorer)
   window.external.AddFavorite(BookmarkURL,BookmarkTitle)
  }
  else
  {
   // Add to Bookmarks (Mozilla Firefox)
   window.sidebar.addPanel(BookmarkTitle, BookmarkURL, ''); 
  }
} 

function redirect() {
  // this function redirects to the index.php?kindOfEventValue= ** depending on category selected from the drop down box **
  var dropDown = document.getElementById('kindOfEventDropDown');
  var parameter = dropDown.options [dropDown.selectedIndex].value;
  window.location.href='index.php?kindOfEventValue='+parameter;
}

function favouriteCursorType() {

if (document.all)
  {
     document.getElementById("favourite").style.cursor="hand";
  }
  else
  {
     document.getElementById("favourite").style.cursor="pointer";


  }


}

function calcHeight() { 
 var colLeft = document.getElementById("leftColumn").offsetHeight;
 var colMiddle = document.getElementById("middleColumn").offsetHeight;
 var colRight = document.getElementById("rightColumn").offsetHeight;   
 if(colLeft > colMiddle && colLeft > colRight) {  
   colLeft+=150;
   document.getElementById("middleColumn").style.height=colLeft;   
   document.getElementById("rightColumn").style.height=colLeft;  
 } else if(colLeft < colMiddle && colMiddle > colRight) {
   colMiddle+=150;
   document.getElementById("leftColumn").style.height=colMiddle;   
   document.getElementById("rightColumn").style.height=colMiddle;  
 } else if(colRight > colMiddle && colRight > colLeft) {
   colRight+=150;
   document.getElementById("leftColumn").style.height=colRight;  
   document.getElementById("middleColumn").style.height=colRight;  
 } 
}

function toggleMenu(currMenu){
 if(document.getElementById){
  thisMenu=document.getElementById(currMenu).style;
  if(thisMenu.display=="block"){
    thisMenu.display="none"
  }
  else {
   thisMenu.display="block"
  }
  return false
 }
 else {
  return true
 }
}

function bcolor(d_name) {
    var thestyle=document.getElementById(d_name).style;	
 		var rgb=hex2num("#d75d28");
    var bgcol="rgb(";
    for(var i=0; i<3; i++){     
      bgcol+=rgb[i]+", ";
    }
    // εδω χρειάζεται να λειτουργει για ολα τα χρωματα ανεξαρτητα αριθμου rgb!!!
    bgcol=bgcol.substr(0,15)+")";     
    if(thestyle.color=="#d75d28" || thestyle.color== bgcol)
		{
		 	thestyle.color="#4a568e";
		 	document.body.style.cursor='default'
		} 
		else {	
		  thestyle.color="#d75d28";
		 	document.body.style.cursor='hand'
		 }	
 	 
}

function changeBackground(cell,cellFont,monthDay){  
  if(monthDay==cell.substr(4,2)) {
    return false;
  }
  var rgb=hex2num("#ffffff");
  var bgcol="rgb(";
  for(var i=0; i<3; i++){
    bgcol+=rgb[i]+", ";
  }
  bgcol=bgcol.substr(0,17)+")";   
  if(document.getElementById(cell).style.backgroundColor==bgcol || document.getElementById(cell).style.backgroundColor=="#ffffff"){    
    document.getElementById(cell).style.backgroundColor="#bfc3db";
    document.getElementById(cellFont).style.color="#ffffff";
  } 
  else {
    document.getElementById(cell).style.backgroundColor="#ffffff";
    document.getElementById(cellFont).style.color="#000000";
  }
}

//Convert a hex value to its decimal value - the inputted hex must be in the
//	format of a hex triplet - the kind we use for HTML colours. The function
//	will return an array with three values.
function hex2num(hex) {
	if(hex.charAt(0) == "#") hex = hex.slice(1); //Remove the '#' char - if there is one.
	hex = hex.toUpperCase();
	var hex_alphabets = "0123456789ABCDEF";
	var value = new Array(3);
	var k = 0;
	var int1,int2;
	for(var i=0;i<6;i+=2) {
		int1 = hex_alphabets.indexOf(hex.charAt(i));
		int2 = hex_alphabets.indexOf(hex.charAt(i+1)); 
		value[k] = (int1 * 16) + int2;
		k++;
	}
		//alert("hex:"+hex);

	return(value);
}
//Give a array with three values as the argument and the function will return
//	the corresponding hex triplet.
function num2hex(triplet) {
	var hex_alphabets = "0123456789ABCDEF";
	var hex = "#";
	var int1,int2;
	for(var i=0;i<3;i++) {
		int1 = triplet[i] / 16;
		int2 = triplet[i] % 16;

		hex += hex_alphabets.charAt(int1) + hex_alphabets.charAt(int2); 
	}
	return(hex);
	
}

function newWindow(bigImage,w,h) {        
						
			leftPos=0;
			if(screen){		
				leftPos=(screen.width)/2-(w/2);
			}	
			bigWin=window.open(bigImage,"bigImage","width="+w+",height="+h+",scrollbars=yes,resizable=yes, left="+leftPos+",top=20").focus();	  
			
		}
