var winW = 630, winH = 460;
var navi = "";

 

if (parseInt(navigator.appVersion)>3) {

 if (navigator.appName.indexOf("Microsoft")!=-1) {
	 navi = "Microsoft";
 }
 else 
 {
		 navi = "Netscape";
 }
}

function clearVal(dom,val)
{
  if(dom.value == val)
  {
	dom.value = "";  
  }
}


function b(d,classes)
{
  dom(d).className=classes;
}

function a(link)
{
	document.location= root+'/'+link;
}


function preloadCssImages()
{
	preloadImages(root+"/Images/menuBtn2.png");
}

function onLoad()
{
	load("menuBg2.png");
	start();
}



var topCategoriesLeft = 0;
//var topCategoriesTop = 0; 

var minTop = 0;
var maxTop = 0; 

var logoHeight = 0;


function start()
{
	winW = f_clientWidth();
	winH = f_clientHeight();
	
	document_show("Services");
	servWidth = dom("Services").offsetWidth;
	document_hide("Services");
	dom("Services").style.top = (findPosY(dom("pageDiv")) + 37) + "px";
	dom("Services").style.left = (findPosX(dom("pageDiv")) + 610 - (parseInt(servWidth/2))) + "px";
	
}

function startOld()
{
	winW = f_clientWidth();
	winH = f_clientHeight();

	var leftX = parseInt((72/1200) * winW);
	var menuY = parseInt((122/600) * winH);
	dom("menu").style.top = menuY + "px";
	dom("menu").style.top = menuY + "px";
	dom("menu").style.left = leftX + "px";
	dom("menu").style.width = (winW - (leftX*2)) + "px";
	document_show("menu");
	
	logoWidth = parseInt((197/1200) * winW);
	if(logoWidth > 200)
	{
		topCategoriesLeft = leftX + (200 - parseInt((logoWidth/2))); 
	}
	else 
	{
		topCategoriesLeft = leftX; 
	}
	
	minTop = menuY + 30; 
	maxTop = parseInt((575/600) * winH);
	
	maxHeight = maxTop - minTop;
	
	dom("topCategories").style.left = topCategoriesLeft + "px";
	document_show("topCategories");
	topCategoriesHeight = dom("topCategories").offsetHeight;
	dom("topCategories").style.top =  (minTop + parseInt((maxHeight - topCategoriesHeight)/2)) + "px";
	
	cDivTop = minTop + parseInt((3/100)*winH); 
	cDivHeight = maxTop - cDivTop;
	cDivLeft = topCategoriesLeft + 204 + parseInt((3/100)*winW);
	cDivWidth = winW - leftX - cDivLeft;
	dom("cDiv").style.left = cDivLeft + "px";
	dom("cDiv").style.top = cDivTop + "px";
	dom("cDiv").style.width = cDivWidth + "px";
	dom("cDiv").style.height = cDivHeight + "px";
	document_show("cDiv");	
	
	
	document_show("offers");
	offersWidth = dom("offers").offsetWidth;
	document_hide("offers");
	offersLeft = findPosX(dom("offersDiv")) - parseInt(offersWidth/2) + parseInt(leftX/2);
	if(offersLeft + offersWidth > winW - leftX)
    {
		offersLeft = winW - leftX;
    }
	dom("offers").style.top = (menuY+28) + "px";
	dom("offers").style.left = offersLeft + "px";
	
	
	document_show("services");
	servicesWidth = dom("services").offsetWidth;
	document_hide("services");
	servicesLeft = findPosX(dom("servicesDiv")) - parseInt(servicesWidth/2) + parseInt(leftX/2);
	if(servicesLeft + servicesWidth > winW - leftX)
    {
		servicesLeft = winW - leftX;
    }
	dom("services").style.top = (menuY+28) + "px";
	dom("services").style.left = servicesLeft + "px";
	
	
	if(document.getElementById("cDivMain").offsetHeight>cDivHeight)
	{
	  dom("cDiv").style.width = (cDivWidth-17-5) + "px";
	  dom("scrollingDiv").style.left = (cDivWidth+cDivLeft-17) + "px";
	  dom("scrollingDiv").style.top = cDivTop + "px";	
	  dom("scrollingDiv").style.height = cDivHeight + "px";
	  canScroll = dom("cDivMain").offsetHeight;
	  //alert(document.getElementById("scrollingDiv").style.left);
	  document_show("scrollingDiv");
	  if (navigator.appName.indexOf("Microsoft") != -1) 
	  {
		  var fl = "<object id='scrollFlash' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' " +
			  	   "codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' " +
			  	   "width='17px' height="+cDivHeight+"px> " +
			  	   "<param name='movie' value='"+root+"//Flash/yScroll.swf' /> " +
			  	   "<param name='quality' value='high' />"+
			  	   "<param name='wmode' value='transparent' />"+
			  	   "<param name='scale' value='exactfit' />"+
			  	   "<param name='FlashVars' value='visibleHeight="+cDivHeight+"&contentHeight="+canScroll+"' />"+
			  	   "<p></p>"+
			  	   "</object>";
	  }
	  else 
	  {
		  var fl = "<object id='scrollFlash' type='application/x-shockwave-flash' " + 
		  	   " data='"+root+"//Flash/yScroll.swf' " +
		  	   "width='17px' height="+cDivHeight+"px> " +
		  	   "<param name='movie' value='"+root+"//Flash/yScroll.swf' /> " +
		  	   "<param name='quality' value='high' />"+
		  	   "<param name='wmode' value='transparent' />"+
		  	   "<param name='scale' value='exactfit' />"+
		  	   "<param name='FlashVars' value='visibleHeight="+cDivHeight+"&contentHeight="+canScroll+"' />"+
		  	   "<p></p>"+
		  	   "</object>";		  
		  //alert(fl);
	  }
	  //alert(fl);
	  dom("scrollingDiv").innerHTML = fl;
	  //alert(document.getElementById("scrollingDiv").innerHTML);
	  
	  setScrollingEvent(); 
	  //document.getElementById("cDiv").style.overflowY = "scroll";
	}
	else 
	{
		dom("scrollingDiv").innerHTML = "";
	}
	
	
}

function onSubmit()
{
	
	result = true;
	if(action()=='all')
	{
		var search = getElementValue("searchField").trim();
		
		while(search.indexOf("  ")!=-1)
		{
		  search = search.replace("  "," ");
		}
		
		if(search=="")
	    {
	      alert("Δεν έχετε εισαγάγει όρο αναζήτησης"); 
		  result = false; 		
	    }
		else if(search.length < 3)
		{
		   alert("Οι όροι αναζήτησης πρέπει να αποτελούνται από λέξεις με τουλάχιστον τρία γράμματα."); 
		   result = false; 		  
		}
		else if(search.indexOf(" ")!=-1)
		{
		  var parts = search.split(" ");
		  var length = parts.length;
		  var notOk = 0;
		  for(i=0;i<length; i++)
		  {
			if(parts[i].length<3)
			{
			  notOk++;
			}
		  }
		  if(notOk==length)
		  {
			alert("Οι όροι αναζήτησης πρέπει να αποτελούνται από λέξεις με τουλάχιστον τρία γράμματα."); 
			result = false; 			  
		  }
		}
	}
	else if(action()=="checkout")
	{
		var loc = document.location.href;
		if(loc.indexOf("Cart") == -1)
		{
			addElement("fromUrl",loc);
		}
	}
	else if(action()=="newsRegister")
	{
		var newsemail = getElementValue("newsemail").trim();
		if(!eMailValidate(newsemail))
	    {
	      alert("Δεν έχετε εισαγάγει έγκυρη διεύθυνση e-mail για να εγγραφείτε στα newsletter"); 
		  result = false; 		
	    }	
		else 
		{
			addElement("newsletterEmail",newsemail);
		}
	}
	else if(action()=="userLog")
	{
		var email = getElementValue("email").trim();
		var password = getElementValue("password").trim();
		if(!eMailValidate(email))
	    {
	      alert("Δεν έχετε εισαγάγει έγκυρη διεύθυνση e-mail για να συνδεθείτε στον λογαριασμό σας"); 
		  result = false; 		
	    }
		else if(password.length < 6)
		{
		  alert("Δεν έχετε εισαγάγει έγκυρο password για να συνδεθείτε στον λογαριασμό σας. Οι κωδικοί πρόσβασης έχουν τουλάχιστον έξι χαρακτήρες."); 
		  result = false; 					
		}
		else if(password=="password")
		{
		  alert("Δεν έχετε εισαγάγει password για να συνδεθείτε στον λογαριασμό σας."); 
		  result = false; 					
		}
		else 
		{
			addElement("userEMail",email);
			addElement("userPassword",MD5(password))
		}
	}
	return result;
}


function eMailValidate(str) 
{
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	return reg.test(str)
}


function scrollToTop()
{
	window.scroll(0,0); 
}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


var show = new Array(); 
var show2 = new Array();
function nOn(id)
{
	document_show("cats"+id);
	show2[id] = 1;
	if(findPosY(dom("cats"+id)) == 0)
	{	
		cattTop = findPosY(dom("catt"+id));
		catsHeight = dom("cats"+id).offsetHeight;
		catsTop = cattTop - parseInt(catsHeight/2) + 15;
		
		if(catsTop < minTop)
		{
			catsTop = minTop;
		}
	
		if(catsTop + catsHeight > maxTop)
		{
			catsTop = maxTop - catsHeight;
		}
	
		dom("cats"+id).style.left = (topCategoriesLeft + 204) + "px";
		dom("cats"+id).style.top = catsTop + "px";
	}
}



function hideMBar(id)
{
	  if(show[id]!=1 && show2[id]!=1)
	  {
		  document_hide("cats"+id);
	  }
}

function nOff(id)
{
  show2[id] = 0;
  setTimeout("hideMBar('"+id+"')",50);
}

function nOn2(id)
{
	show[id] = 1;
	dom("catt"+id).className = "hoverTopCategory";
	document_show("cats"+id);
}

function nOff2(id)
{
  show[id] = 0;
  dom("catt"+id).className = "topCategory";
  setTimeout("hideMBar('"+id+"')",50);
}

function findPosY(obj)
{
  var curtop = 0;
  if(obj.offsetParent)
      while(1)
      {
        curtop += obj.offsetTop;
        if(!obj.offsetParent)
        {
          break;
        }
        obj = obj.offsetParent;
      }
  else if(obj.y)
  {
      curtop += obj.y;
  }
  return curtop;
}

function findPosX(obj)
{
  var curleft = 0;
  if(obj.offsetParent)
      while(1) 
      {
        curleft += obj.offsetLeft;
        if(!obj.offsetParent)
          break;
        obj = obj.offsetParent;
      }
  else if(obj.x)
      curleft += obj.x;
  return curleft;
}

function setScrollingEvent()
{
	/** Initialization code. 
	 * If you use your own event management code, change it as required.
	 */
	if (window.addEventListener)
	        /** DOMMouseScroll is for mozilla. */
	        window.addEventListener('DOMMouseScroll', wheel, false);
	/** IE/Opera. */
	window.onmousewheel = document.onmousewheel = wheel;

}

function yScroll(yScr)
{
	dom("cDiv").scrollTop = yScr;
}


var isScrollingUp = false;

var isScrollingDown = false; 

/** This is high-level function.
 * It must react to delta being more/less than zero.
 */
function handle(delta) 
{
        if (delta < 0)
        {
        	isScrollingUp = true;
        	dom("scrollFlash").jsDown();
        	setTimeout("stopScrollingUp()",300);
        }
        else
        {
        	isScrollingDown = true;
        	dom("scrollFlash").jsUp();
        	setTimeout("stopScrollingDown()",300)
        }
		
}


function stopScrollingUp()
{
	if(!isScrollingUp)
	{
		dom("scrollFlash").jsStop();
	}
	else 
	{
		isScrollingUp = false;
		setTimeout("stopScrollingUp()",300);
	}
}

function stopScrollingDown()
{
	if(!isScrollingDown)
	{
		dom("scrollFlash").jsStop();
	}
	else 
	{
		isScrollingDown = false;
		setTimeout("stopScrollingDown()",300);
	}
}

function stopScrollingDown()
{
	dom("scrollFlash").jsStop();
}

/** Event handler for mouse wheel event.
 */
function wheel(event){
        var delta = 0;
        if (!event) /* For IE. */
                event = window.event;
        if (event.wheelDelta) { /* IE/Opera. */
                delta = event.wheelDelta/120;
                /** In Opera 9, delta differs in sign as compared to IE.
                 */
                if (window.opera)
                        delta = -delta;
        } else if (event.detail) { /** Mozilla case. */
                /** In Mozilla, sign of delta is different than in IE.
                 * Also, delta is multiple of 3.
                 */
                delta = -event.detail/3;
        }
        
        /** If delta is nonzero, handle it.
         * Basically, delta is now positive if wheel was scrolled up,
         * and negative, if wheel was scrolled down.
         */
        if (delta)
        {
        	handle(delta);
        }

        /** Prevent default actions caused by mouse wheel.
         * That might be ugly, but we handle scrolls somehow
         * anyway, so don't bother here..
         */
        if (event.preventDefault)
                event.preventDefault();
	event.returnValue = false;
}


var onFlash = new Array();
var onDiv = new Array();
var stoxos = new Array();

function flashOn(id)
{
	onFlash[id] = 1;
	setTimeout("showMenu('"+id+"')",100);
}

function flashOff(id)
{
	onFlash[id] = 0;
	setTimeout("hideMenu('"+id+"')",100);
}

function divOn(id)
{
	onDiv[id] = 1;
	onFlash[id] = 0;
	setTimeout("showMenu('"+id+"')",100);
}

function divOff(id)
{
	onDiv[id] = 0;
	setTimeout("hideMenu('"+id+"')",100);
}

function showMenu(id)
{
	//dom("cDivMain").innerHTML = onFlash[id] + ":" + onDiv[id] + ":" + dom(id).style.display;
	if(onFlash[id]!=0 || onDiv[id]!=0)
	{	
		if(dom(id).style.display=='none' || stoxos[id] == 0)
		{
			stoxos[id] = 1;
			changeOpacity(id);
		}
		dom("flashBg").menuOn(id);
	}
}

function hideMenu(id)
{
	//dom("cDivMain").innerHTML = onFlash[id] + ":" + onDiv[id] + ":" + dom(id).style.display;
	if(onFlash[id]!=1 && onDiv[id]!=1)
	{	
		if(dom(id).style.display=='' || stoxos[id] == 1)
		{
			stoxos[id] = 0;
			changeOpacity(id);
		}
		dom("flashBg").menuOff(id);
	}
}

function changeOpacity(id)
{
	op = parseInt(dom(id).style.opacity * 10) / 10;
	if(op == 0)
	{
		if(stoxos[id] == 0)
		{
			document_hide(id);
		}
		else
		{
			document_show(id);
		}
	}

	
	if(op != stoxos[id])
	{
		dif = stoxos[id] - op; 
		plus = dif>0?0.1:-0.1;
		newOp =  op + plus;
		newOp = Math.round(newOp * 10)/10;
		dom(id).style.filter = "alpha(opacity = "+(newOp*100)+")";
		dom(id).style.opacity=newOp;
		setTimeout("changeOpacity('"+id+"')",100);
	}
}
