﻿/*
COMMON FUNCTIONS

LIST:

Browser Auto Detection
writePageSign				Write Footer Sign of Pages
addToFavorites				Add To Favorites Function
checkEmail					CHECK EMAIL Function
goTo						FORM OPTION Navigation Function
URLEncodeSpace				Replace 'empty spaces' of URLs
URLEncodeAmp				Replace '&' character of URLs
popUp						Pop-Up Window Function
popUpWindow					Pop-Up Window Advanced Function
swapImage					Swap Image Function
showHideLayer				Show - Hide Layers Function

*/



//********************************************************* Browser Detecting

var browser;
var newWin;

browser = 'NS4'; 

if (document.layers) {
	browser = 'NS4';	
}
else if (document.getElementById && !document.all) {
	browser = 'NS6';	
}
else if (document.all && navigator.userAgent.indexOf("Opera")>-1){
	browser = 'Opera';	
}
else if (document.all) {
	browser = 'IE';	
}
else {
	browser = 'Other';	
}



//********************************************************* Write Footer Sign of Pages
function writePageSign() {

	var sign;
		
	sign = '&nbsp;<br>' +
		   '<div align="center">' +
		   '<hr size="1" width="400">' +
		   '<span class="FontDarkBold"><a href="http://www.enter.gr" target="_blank">Created and Powered By Enter S.A.</a></span><br>' +
		   '<span class="FontFooter">Copyright © 1998-2001 Enter S.A., All Rights Reserved</span>' +
		   '</div><br>';
		   
    document.write(sign);
    
}    
    


//********************************************************* Add To Favorites Function
function addToFavorites(lang) {
	
	if (browser == "IE") {		
		
		var myIcon1, myIcon2, myIcon3;

		myIcon1 = new Image(); myIcon1.src = "favicon.ico";
		myIcon2 = new Image(); myIcon2.src = "/favicon.ico";
		myIcon3 = new Image(); myIcon3.src = "../favicon.ico";
	
		document.write('<a href="javascript:window.external.AddFavorite(location.href, document.title);">');
		if (lang == "gr") document.write('Προσθήκη στα Favorites');
		else document.write('Add to Favorites');
		document.write('</a>');
	}
	
}



//********************************************************* CHECK EMAIL Function
function checkEmail(thisEmail,msg1,msg2){
	var strEmail = thisEmail;
	
	if(strEmail<=1){
		alert(msg1);
		return false;
	}
	
	if(strEmail.indexOf("@")<1 || strEmail.indexOf(".")<0){
		alert(msg2);
		return false;
	}
	else {
		return true;
	}
}



//********************************************************* FORM OPTION Navigation Function

function goTo(item, page){
    var url;
    url = page + item[item.selectedIndex].value;
    if (url.length > 0 ) window.location.href = url;	
}



//********************************************************* Replace 'empty spaces' of URLs

function URLEncodeSpace(strExpression,newChar){
	var output,rExp,replacement;
	output = strExpression;
	
	if(strExpression.length>0){
		strExpression = new String(strExpression);
		rExp = / /gi;
		replacement = new String (newChar);
		output = strExpression.replace(rExp,replacement);	
	}
	
	return output;
}



//********************************************************* Replace '&' character of URLs

function URLEncodeAmp(strExpression,newChar){
	var output,rExp,replacement;
	output = strExpression;
	
	if(strExpression.length>0){
		strExpression = new String(strExpression);
		rExp = /&/gi;
		replacement = new String (newChar);
		output = strExpression.replace(rExp,replacement);	
	}
	
	return output;
}



//********************************************************* Pop-Up Window Function

function popUp(page,w,h,s,content){
   var thisWin;
   wWidth = window.screen.width;
   wHeight = window.screen.height;
   pWidth = w;
   pHeight = h;
   pScroll = s;
   xPos =  parseInt((wWidth-pWidth)/2);
   yPos =  parseInt((wHeight-pHeight)/2);
   winProp = "top="+yPos+",left="+xPos+",width="+pWidth+",height="+pHeight+",scrollbars="+pScroll+",resizable=yes"; 
         
   if(page.length > 0){	
		thisWin = window.open(page,"newWin",winProp);
		thisWin.focus();
   }	
   else if (content.length > 0) {
		thisWin = window.open("","newWin",winProp);
		thisWin.document.open();		
		thisWin.document.write(content);
		thisWin.document.close();	
		thisWin.focus();
   }
}



//********************************************************* Pop-Up Window Advanced Function
/* 
Arguments:
	page: Page's relative path of popup Window
	x: The x position of popup Window
	y: The y position of popup Window
	w: The width of popup Window
	h: The height of popup Window
	scroll: The popup Window will be has scrollbars. Values: 'yes', 'no'.
	resize: The popup Window will be resizable. Values: 'yes', 'no'.
	content: HTML code of popup Window instead of loading another page	
Usage examples:
	<a href="javascript:popUpWindow('page.htm',20,20,100,200,'yes','yes','')">Link</a>
	<a href="javascript:popUpWindow('',20,20,100,200,'no','no','<p>Hello World</p>')">Link</a>	
*/

function popUpWindow(page,x,y,w,h,scroll,resize,content){
   
   var pWidth,pHeight,xPos,yPos,scrollThis,resizeThis;
  
   pWidth = w;
   pHeight = h;
   xPos =  x;
   yPos =  y;
   scrollThis = scroll;
   resizeThis = resize;
   winProp = "";
   
   if (xPos > 0 && yPos > 0) winProp = "top="+yPos+",left="+xPos+",";
   
   winProp = winProp + "width="+pWidth+",height="+pHeight+",scrollbars="+scrollThis+",resizable="+resizeThis; 
   
	if(typeof(newWin)=='object') {
		if(!newWin.closed && browser != 'Opera'){
			newWin.close();				
		}
	}
         
	if(page.length > 0){	
		newWin = window.open(page,"newWindow",winProp);
		newWin.focus();
	}	
	else if (content.length > 0) {
		newWin = window.open("","newWindow",winProp);
		newWin.document.open();		
		newWin.document.write(content);
		newWin.document.close();	
		newWin.focus();
	}
}



//********************************************************* Swap Image Function
/* 
Arguments
	imgName: value of "name" and "id" attribute in "img" tag
	imgPath: relative path of new image file
	imgLayer: if the target image is part of a layer, the layers's ID 
Note:
	"name" and "id" attributes for each "img" tag must have the same value 
Usage examples:
	onMouseOver="swapImage('imageName','newImageRelativePath','');"
	onMouseOver="swapImage('imageName','newImageReletivePath','LayerID');"
*/  

function swapImage(imgName, imgPath, imgLayer) {
	if (imgLayer.length <= 0) {						// Without Layers
		document.images[imgName].src = imgPath;	
	}
	else {											// With Layers
		if (browser == 'NS4') {
			document.layers[imgLayer].document.images[imgName].src = imgPath;
		}
		else if (browser == 'NS6') {
			document.getElementById(imgName).src = imgPath;
		}
		else {
			document.images[imgName].src = imgPath;
		}	
	}  
}  
 


//********************************************************* Show - Hide Layers Function
/* 
Arguments:
	layerID: value of "id" attribute in "div" tag
	action: Show or Hide a layer. Values: '', 'show', 'hide'.
Usage examples:
	onMouseOver="showHideLayer('LayerID','show');"
	onMouseOver="showHideLayer('LayerID','hide');"	
	onClick="showHideLayer('LayerID','');"	
*/
 
function showHideLayer(layerID,action) {
	
	var thisLayer;
	var thisAction;
	var visible;
	var hidden;
	
	if (browser == 'NS4') {
		thisLayer = document.layers[layerID];
		visible = 'show';
		hidden = 'hide';
	}
	else if (browser == 'NS6'){
		thisLayer = document.getElementById(layerID).style;
		visible = 'visible';
		hidden = 'hidden';
	}
	else if (browser == 'Opera') {
		thisLayer = document.all(layerID).style;
		visible = 'VISIBLE';
		hidden = 'HIDDEN';
	}
	else {
		thisLayer = document.all(layerID).style;
		visible = 'visible';
		hidden = 'hidden';				
	}
	
	if (action == '') {
		if (thisLayer.visibility == visible) {
			thisLayer.visibility = hidden;
		}
		else {
			thisLayer.visibility = visible;
		}
	}
	
	if (action == "show") {
		thisLayer.visibility = visible;		
	}
	else if (action == "hide") {
		thisLayer.visibility = hidden;
	}
	
} 