﻿//------: CHECK BROWSER
var version = "";
var browser ="";
var isIE6 = false;

function getBrowser() {	
	if (navigator.appVersion.indexOf("MSIE")>0){
		version = parseFloat(navigator.appVersion.split("MSIE")[1]);  
		browser = "MSIE";
	} else {
		browser = "not MSIE"
	}
}
getBrowser();

if(browser=="MSIE"){
	if(version<7){
		isIE6 = true;
	}
}



//FOR SUBMENU
var isexpanded = false;

//------: EVENTS
window.onload = function(){
	setBgAreaSize();
	setTopMargin();
}

window.onresize = function(){
	setBgAreaSize();
	setTopMargin();	
}

document.onmouseup = closeOpenedCombos;




//------: FUNCTIONS
function checkSize(){
	var uniwin = {
		width: window.innerWidth || document.documentElement.clientWidth
			|| document.body.offsetWidth,
		height: window.innerHeight || document.documentElement.clientHeight
			|| document.body.offsetHeight
	};
	return uniwin
}


function getFlashMovieObject(movieName){
	if (window.document[movieName]){
		  return window.document[movieName];
	}
	if (navigator.appName.indexOf("Microsoft Internet")==-1){
		if (document.embeds && document.embeds[movieName]){
			return document.embeds[movieName];
		}
	} else {// if (navigator.appName.indexOf("Microsoft Internet")!=-1)
	   return document.getElementById(movieName);
	   
	}
	return document.getElementById(movieName);
}


function setBgAreaSize(){
	var theDocSize = checkSize();
	HSize = theDocSize.height;
	WSize = theDocSize.width;
	
	var H
	
	if(HSize<708){	
		H = "708px";
		$("BgArea").style.height = "708px";
	} else {
		H = Number(HSize)+"px";
		$("BgArea").style.height = "100%";
	}
	
	if(WSize<1000){	
		$("BgArea").style.width = "1000px";
	} else {
		$("BgArea").style.width = "100%";
		
	}
	
	setFlashHeight(H);
	
}

function setFlashHeight(height){
	 var flashMovie = getFlashMovieObject("theFlashBg");
	 if (flashMovie!=null){
		 flashMovie.style.height = height;
	 } else {
		setTimeout("setFlashHeight('"+height+"')", 300); 
	 }
}

function setTopMargin(){
    var theDocSize = checkSize();
    var HSize = theDocSize.height;
    var obj = $("container");
    var topMarg = "145";
    var dif = 708 - HSize;
    if(HSize<708){ 
       if((topMarg-dif)>0){
            obj.style.top = topMarg-dif + "px";
       } else {
            obj.style.top = 0 + "px";
       }
    } else {
        obj.style.top = topMarg + "px";
    }
}


var selectedBg;
function changeFlashBg(num,loaded){
    if(num){
        randomBg = num;
    } else {
        randomBg = Math.ceil(Math.random()*9);        
    }
	selectedBg = randomBg;
	var flashMovie = getFlashMovieObject("theFlashBg");	
	if(loaded!='true') {
	    setTimeout("changeFlashBg("+num+",'true')", 200);	        
	}
	else if(loaded=='true') {	       
	    flashMovie.changetheBg(num);
	}

}

function searchNextBg(bg) {
    selectedbg = bg;
    var flashMovie = getFlashMovieObject("theFlashBg");	
    flashMovie.changetheBg(bg);
}

function nextBg(){
    if(!Number(selectedBg)){
        selectedBg = 0;
    }
    selectedBg++
    if(selectedBg>9){
        selectedBg = 1;
    }
    var flashMovie = getFlashMovieObject("theFlashBg");	
	flashMovie.changetheBg(selectedBg);
}
//var to store last position of magnifier
var magnifyLastPos;
//magnify for product gallery, magnify1 for series gallery

var MagnTimer;
function setMagnifyPosition(objRef) {
       

    if ($(objRef) != null) {
        if ($(objRef).clientHeight > 0) {
            clearTimeout(MagnTimer);
            if ($("magnify")) {
                var h = $(objRef).clientHeight;
                var hmagn = $("magnify").clientHeight;
                $("magnify").style.top = Number(h / 2 - hmagn / 2) + "px";
                magnifyLastPos = Number(h / 2 - hmagn / 2);
            }
            else if ($("magnify1")) {
                var h = $(objRef).clientHeight;
                var hmagn = $("magnify1").clientHeight;
                $("magnify1").style.top = Number(h / 2 - hmagn / 2) + "px";
            }
        } else {
            
            MagnTimer = setTimeout("setMagnifyPosition(" + objRef + ")", 500);
        }
    } else if (magnifyLastPos) {
        if ($("magnify"))
            $("magnify").style.top = magnifyLastPos + "px";
        else if ($("magnify1"))
            $("magnify1").style.top = magnifyLastPos + "px";

    } else {
        MagnTimer = setTimeout("setMagnifyPosition(" + objRef + ")", 500);
    } 
}

function showhideMagnify(cases){
	switch(cases){
		case "show":			
			$("magnify").style.display = "block";
			break;
		case "hide":
			$("magnify").style.display = "none";
			break;
	}
}

function changeClassName(obj,newName){
	$(obj).className = newName;
}


/*-- ALL MENU SCRIPTS: START --*/
var timer
function showSubMenu(obj){
    clearTimeout(timer);
    hideInsideItemsAll();	
	if(obj){
		hideInsideItemsAll();
		
		new Effect.Morph('SubMenu', {
		  style: 'width:213px;', // CSS Properties
		  duration: 0.5 // Core Effect properties
		});

		if(isexpanded==false){		    
			timer=setTimeout("showSubMenuTxt('"+obj+"')", 500);	
			isexpanded = true;
		} else {
			showSubMenuTxt(obj);
		}
		
	} else {	    
		hideSubMenu()
	}
}
function showSubMenuTxt(obj){
	$(obj).style.display = "block";
}

function hideSubMenu(){
	if(isexpanded){
		isexpanded = false;
		hideInsideItemsAll();
		new Effect.Morph('SubMenu', {
		  style: 'width:0px;', // CSS Properties
		  duration: 0.5 // Core Effect properties
		});
	}
}

function hideInsideItemsAll(){	
	var obj = "SubMenu";
	var i = 0;
	while($(obj+i)){
		$(obj+i).style.display = "none";
		i++
	}
}

/*-- COMBO BOX SCRIPTS: START --*/
function showDropDown(obj){
	if($(obj).style.display == "block"){
	    $(obj).style.display = "none";
		
	} else {	    
		$(obj).style.display = "block";
	}
}

function setText(obj,dropdown,cbtxt,hdnvalue){
    $(dropdown).style.display = "none";
    var str = $(obj).innerHTML;
    //if (str.length > 26) {
    //    str = str.substring(0, 26)+"...";
    //}
    $(cbtxt).innerHTML = str;
	deselectAll(obj);
	$(obj).className = "selected";
	$(hdnvalue).value = str; //$(obj).innerHTML;		
}
function initiateText(cbtxt, hdnvalue) {
    $(cbtxt).innerHTML = $(hdnvalue).value; // "<span>" + obj.innerHTML + "</span>";		
}

function deselectAll(obj){
	var p = $(obj).parentNode;
	if(p!=null){
	    for (var i = 0; i < p.childNodes.length; i++) {			
		    if(p.childNodes[i].className){
			    p.childNodes[i].className = "";
		    }		
	    }
	}
}
var allcombosdropdown=null;
function closeCombos(){ //Closes all combos dropdown
	if(allcombosdropdown){
		if(allcombosdropdown.length>0){
			for(i=0;i<allcombosdropdown.length;i+=2){
			    if($(allcombosdropdown[i+1])!=null)
				    $(allcombosdropdown[i+1]).style.display = "none";
			}
		}
	}
}
function closeOpenedCombos(e){
	cursor = findMousePos(e);
	
	if(allcombosdropdown){
		if(allcombosdropdown.length>0){
			for(i=0;i<allcombosdropdown.length;i+=2){	
			    if($(allcombosdropdown[i+1])!=null)			
				    if($(allcombosdropdown[i+1]).style.display == "block"){
					    if(checkArea($(allcombosdropdown[i]), $(allcombosdropdown[i+1]), cursor)){ // If Mouse is not over the opened combobox
						    if($(allcombosdropdown[i+1])!=null)
						    $(allcombosdropdown[i+1]).style.display = "none";
					    }					
				    }
			}
		}
	}
}
function checkArea(combo, dropdown, cursor){	
	var comboSize = checkObjSize(combo);
	var dropdownSize = checkObjSize(dropdown);
	var gap = 5;
	var objArea = {X:(findPosX(combo)-gap), Y:(findPosY(combo)-gap), W:comboSize.width, H:(dropdownSize.height+comboSize.height)};
	var Platos = objArea.X + objArea.W+gap*2;
	var Ipsos = objArea.Y + objArea.H+gap*2;
	var isInsideX = false;
	var isInsideY = false;
	if(cursor.x<=Platos && cursor.x >=objArea.X){
		isInsideX = true;
	}
	if(cursor.y<=Ipsos && cursor.y >=objArea.Y){
		isInsideY = true;
	}
	if(isInsideX==true && isInsideY==true){
		return false;
	} else {
		return true;
	}
}
function checkObjSize(obj){

	var thesize = {
		width: obj.clientWidth,
		height: obj.clientHeight
	};
	return thesize
}

function findMousePos(e){
	e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
	return cursor;
}

function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

/*-- IMAGE GALLERY --*/
var ActiveSet=0;
var CurrentImage=0;

//function SetOfImages(item, obj, objA) {
//	var OutputForJSSmallArr = new Array();
//	OutputForJSSmallArr = OutputForJSSmall[item].split('|');
//	var OutputForJSLargeArr = new Array();
//	OutputForJSLargeArr = OutputForJSLarge[item].split('|');
//	var OutputForJSTitleArr = new Array();
//	OutputForJSTitleArr = OutputForJSTitle[item].split('|');

//	for (var i = 0; OutputForJSSmallArr[i]; i++) {
//		if (i == 0) {
//			document.getElementById(obj).src = OutputForJSSmallArr[i];
//			if (OutputForJSLargeArr[i] != '') {
//				document.getElementById(objA).setAttribute('href', OutputForJSLargeArr[i]);
//			}
//			else {
//				document.getElementById(objA).setAttribute('href', '');
//			}
//			document.getElementById(objA).setAttribute('title', OutputForJSTitleArr[i]);
//		}
//	}

//	for (var j = 0; document.getElementById('CurSet' + j); j++) {
//		document.getElementById('CurSet' + j).className = 'imgGalleryOuter';
//	}
//	if (document.getElementById('CurSet' + item)) {
//		document.getElementById('CurSet' + item).className = 'imgGalleryOuterHover';
//	}

//	ActiveSet = item;
//	CurrentImage = 0;

//	document.getElementById('divPhotosBack').style.display = 'none';
//	document.getElementById('divPhotosNext').style.display = 'none';
//	if (OutputForJSSmallArr[CurrentImage + 1]) {
//		document.getElementById('divPhotosNext').style.display = 'block';
//	}
//}
function PhotosBack(obj, objA) {
	document.getElementById('divPhotosBack').style.display = 'block';
	document.getElementById('divPhotosNext').style.display = 'block';

	if (CurrentImage > 0) {
		document.getElementById('divPhotosBack').style.display = 'block';
		if (OutputForJSSmallArr[CurrentImage - 1]) {
			document.getElementById('divPhotosBack').style.display = 'block';
			document.getElementById(obj).src = OutputForJSSmallArr[CurrentImage - 1];
			if (OutputForJSLargeArr[CurrentImage - 1] != '') {
				document.getElementById(objA).setAttribute('href', OutputForJSLargeArr[CurrentImage - 1]);
			}
			else {
				document.getElementById(objA).setAttribute('href', '');
			}
			document.getElementById(objA).setAttribute('title', OutputForJSTitleArr[CurrentImage - 1]);
			CurrentImage--;
			if (!OutputForJSSmallArr[CurrentImage - 1]) {
				document.getElementById('divPhotosBack').style.display = 'none';
			}
		}
		else {
			document.getElementById('divPhotosBack').style.display = 'none';
		}
	}
	else {
		document.getElementById('divPhotosBack').style.display = 'none';
	}
}
function PhotosNext(obj, objA) {
	document.getElementById('divPhotosBack').style.display = 'block';
	document.getElementById('divPhotosNext').style.display = 'block';
	
	if (CurrentImage >= 0) {
		if (OutputForJSSmallArr[CurrentImage + 1]) {
			document.getElementById('divPhotosNext').style.display = 'block';
			document.getElementById(obj).src = OutputForJSSmallArr[CurrentImage + 1];

			if (OutputForJSLargeArr[CurrentImage + 1] != '') {
				document.getElementById(objA).setAttribute('href', OutputForJSLargeArr[CurrentImage + 1]);
			}
			else {
				document.getElementById(objA).setAttribute('href', '');
			}
			document.getElementById(objA).setAttribute('title', OutputForJSTitleArr[CurrentImage + 1]);
			CurrentImage++;
			if (!OutputForJSSmallArr[CurrentImage + 1]) {
				document.getElementById('divPhotosNext').style.display = 'none';
			}
		}
		else {
			document.getElementById('divPhotosNext').style.display = 'none';
		}
	}
}
function setBackNextDisplay(z) {
    if(document.getElementById('divPhotosNext')!=null && document.getElementById('nextprevWrapper')!=null &&document.getElementById('divPhotosBack')!=null)
    {
		if (OutputForJSSmallArr[CurrentImage + 1]) {
			document.getElementById('divPhotosNext').style.display = 'block';
		} else {
			document.getElementById('divPhotosNext').style.display = 'none';
			document.getElementById('nextprevWrapper').style.display = "none";
		}
	    if(CurrentImage==0){
		document.getElementById('divPhotosBack').style.display = 'none';
	    }
	}
}




//------: DIKTIO FUNCTIONS: START
function setMap(obj,dropdown,cbtxt){
	$(dropdown).style.display = "none";
	$(cbtxt).innerHTML = $(obj).innerHTML;
	deselectAll(obj);
	$(obj).className = "selected";
		
	var place = obj.id;
	var loc = setRegionCompos(place);
	
	var flashMovie = getFlashMovieObject("FlashDiktio");
	flashMovie.setFlashMap(loc.continent, loc.country, loc.region, loc.city); 
}

function setRegionCompos(place, flashtxt) {
	var loc = ({continent:"",country:"",region:"",city:""});
	var cases = getMapType(place)
	switch(cases){
	    case "continents":
		    loc.continent = place;
		    
			if(flashtxt){
			   $("combo1text").innerHTML = flashtxt;
			}		    
			deselectAll("greece");
			deselectAll("thraki");				
			$("combo3").style.display = "none"; //Hide region combo
			$("combo4").style.display = "none"; //Hide city combo
			$("combo2text").innerHTML = iniText[1];
			$("combo3text").innerHTML = iniText[2];
			$("combo4text").innerHTML = iniText[3];		
			
			
			if(continents.length>0 && countries.length>0){
				for(i=0;i<continents.length; i+=2){
					for(z=0;z<countries.length; z+=2){
						if(continents[i]==place){
							if(continents[i+1]==countries[z+1]){
								$(countries[z]).style.display = "block";
							} else {
								$(countries[z]).style.display = "none";
							}								
						}						
					}
				}
			}
			
			
			break;
		case "countries":

		    loc.country = place;
		
			if(flashtxt){			    
			    $("combo2text").innerHTML = flashtxt;
			}
			deselectAll("greece");
			
			if(place==countries[0]){ //Greece
				$("combo3").style.display = "block"; //Show region combo for Greece
				
			} else {
                $("combo3").style.display = "none"; //Hide region combo
			}
			$("combo3text").innerHTML = iniText[2];
			
			$("combo4").style.display = "none"; //Hide city combo
			$("combo4text").innerHTML = iniText[3];	
						
			
			if(continents.length>0 && countries.length>0){
				for(i=0;i<countries.length; i+=2){
					if(countries[i]==place){						
						for(z=0;z<continents.length; z+=2){
							if(countries[i+1]==continents[z+1]){
								$("combo1text").innerHTML = $(continents[z]).innerHTML;
								loc.continent = continents[z];
							}
						}
					}
				}				
			}
			
					
			
			break;
		case "regions":
			loc.region = place;
			if(flashtxt){
			    $("combo3text").innerHTML = flashtxt;
			}
			$("combo4text").innerHTML = iniText[3];	
			deselectAll("evrou");
			$("combo4").style.display = "block"; //Show region combo for Greece			
			
			
			if(continents.length>0 && countries.length>0 && regions.length>0 && cities.length>0){
				
				for(i=0;i<regions.length; i+=2){
					if(regions[i]==place){
						loc.country = countries[regions[i+1]];
						for(z=0;z<cities.length;z+=2){
						    if(cities[z+1]==place){
						        $(cities[z]).style.display = "block";
						    } else {
						        $(cities[z]).style.display = "none";
						    }
						}					
					}
				}
				
				for(i=0;i<countries.length; i+=2){
					if(countries[i]==loc.country){						
						for(z=0;z<continents.length; z+=2){
							if(countries[i+1]==continents[z+1]){
								$("combo1text").innerHTML = $(continents[z]).innerHTML;
								loc.continent = continents[z];
								
							} 
						}						
					}
				}
			}			
			
			break;			
		case "cities":
		    loc.city = place;
		    
		    $("combo1text").innerHTML = $(continents[2]).innerHTML;
		    $("combo2text").innerHTML = $(countries[0]).innerHTML; //Greece
		    $("combo3").style.display = "block";
		    	    
		    
		    if(flashtxt){
			    $("combo4text").innerHTML = flashtxt;
			}
		    $("combo4").style.display = "block"; //Show region combo for Greece
		    
		    
		    if(continents.length>0 && countries.length>0 && regions.length>0 && cities.length>0){
		        for(i=0;i<cities.length; i+=2){
					if(cities[i]==place){
					    loc.region = cities[i+1];
					    loc.country = countries[0]; //Greece
					    loc.continent = continents[2]; //Europe					    
					} else {
					    $(cities[i]).style.display = "none";
					}
				}		    
		    }
		    break;
		case "none":
			break;
	}
	return loc;
}
function getMapType(place){
	var i;
	if(continents.length>0 && countries.length>0 && regions.length>0){
		for(i=0;i<continents.length; i+=2){
			if(place == continents[i]){
				return "continents";
			}
		}
		for(i=0;i<countries.length; i+=2){
			if(place == countries[i]){
				return "countries";
			}
		}
		for(i=0;i<regions.length; i+=2){
			if(place == regions[i]){
				return "regions";
			}
		}
		for(i=0;i<cities.length; i+=2){
			if(place == cities[i]){
				return "cities";
			}
		}
		return "none";		
	} else {
		return "none";
	}
}

function showHideCounty(show){
    if(show=="true"){        
        $("combo3").style.display = "block";
    } else {
        $("combo3").style.display = "none";
    }
}
function comboGetFlashPlaces(place, flashtxt, optionalRegion){
    deselectAll("america");
    deselectAll("greece");
    deselectAll("thraki");
    deselectAll("evrou");
    if (optionalRegion) {
        $("combo3text").innerHTML = optionalRegion;
    }
    var loc = setRegionCompos(place, flashtxt);
}






//------: DIKTIO FUNCTIONS: END


function deactivateButton(tableObj) {
    var newimg = document.createElement("img");
    newimg.src = "/Assets/Images/ajax-loader.gif";
    newimg.id = "pleasewait";
    newimg.style.position="absolute"
    newimg.style.width = "128px";    
    newimg.style.left="30px"
    newimg.style.height = "15px";
    tableObj.parentNode.appendChild(newimg);
    tableObj.style.display = "none";
    //document.getElementById("searchbtndiv").style.background="none";
}
