﻿var isIE        = (window.ActiveXObject ? 1 : 0);
var isOpera     = (navigator.userAgent.indexOf('Opera') > -1 ? 1 : 0);
var ns6         = (!document.all && document.getElementById && !isOpera);
var _balance    = null;

$(document).ready(function()
{
	if($('#alert').size() > 0)
		$('#alert').jqm({overlay: 30, modal: true, trigger: false}).jqmAddClose('#jqCloseButton');
	
	$(".defaultText").focus(function(src)
    {
        if ($(this).val() == $(this)[0].title)
        {
            $(this).removeClass("defaultTextActive");
            $(this).val('');
        }
    });
    
    $(".defaultText").blur(function()
    {
        if ($(this).val() == '')
        {
            $(this).addClass("defaultTextActive");
            $(this).val($(this)[0].title);
        }
    });
    
    var images = $('img[src$=menu/c_rc.gif],img[src$=c_blc.gif],img[src$=c_brc.gif]');
    var site = $my.get_siteUrl();
    
    if (site != undefined)
    {
        if(images.length > 0 && site.length > 0)
        {
		    images.each(function()
		    {
			    var prefix = '/' + site;
			    var src = $(this).attr('src');
    						
			    if(!src.toLowerCase().startsWith(prefix.toLowerCase()))
				    $(this).attr('src', prefix + '/' + src);
		    });
        }
    }
});

function footer()
{
	var Cache = window["Cache"];
	if(Cache == null)
	{
		Cache = new Object();
		
		Cache.wr = $('div[id$=Wrapper]:first');
		Cache.cn = $('div[id$=ContentWrapper]:first');
		Cache.ft = $('#vivafooter');
		Cache.sp = $('#spacer');
		Cache.mac = (navigator.userAgent.toLowerCase().indexOf('macintosh') > -1);
		Cache.hq = 0;
		
		if(($.browser.msie && $.browser.version < 8) || $.browser.opera || (mac && $.browser.safari))
			Cache.hq = 40;
		else if($.browser.safari || $.browser.mozilla)
			Cache.hq = 39;
		window["Cache"] = Cache;
	}

	var wr = Cache.wr;
	var cn = Cache.cn;
	var ft = Cache.ft;
	var sp = Cache.sp;
	var mac = Cache.mac;
	var addHeight = Cache.hq;
	
	if($(document).height() > ft.height() + ft.offset().top + addHeight)
	{
		var h = $(document).height() - (wr.height() + cn.height() + ft.height());
		if($.browser.msie)
			h -= 4;
		sp.height(1).height(h);
	}
	
	setTimeout("footer();", 500);
}

function _alert(msg)
{
	var _message = $('#alert');
    var title = 'Viva Alert';
    
    if(arguments.length > 1)
        title = arguments[1];

	_message.jqmShow()
		.find('div.title')
		.html(title)
		.parent()
		.find('div.content')
		.html(msg.replace(/\n/gi, '<br />'));
}

if(!window.ActiveXObject)
{
	Node.prototype.selectSingleNode = function(xPath)
	{
	    var nodes = this.evaluate(xPath, this, null, XPathResult.ANY_TYPE, null);
		var node = nodes.iterateNext(); 
		return(node);
	}

	Node.prototype.selectNodes = function(xPath) 
	{ 	
		var nodes = this.evaluate(xPath, this, null, 0, null);
		var nodelist = new Array();
		var node = nodes.iterateNext();
		while(node){nodelist.push(node); node = nodes.iterateNext();}
		return nodelist;
	}
}

function BrowserLib()
{
    this.opera = (navigator.userAgent.indexOf('Opera') > -1 ? 1 : 0);
    this.ie    = (window.ActiveXObject ? 1 : 0);
    this.ns6   = (!document.all && document.getElementById && !isOpera);
    return(this);
}

function _h(src, on){src.getElementsByTagName('a')[0].style.textDecoration = (on ? 'underline' : 'none');}
function _g(u){document.location.href=u;}
function _st(c, v){c.style.color=v;}
function _cs(button, validationGroup)
{
    if(typeof(Page_ClientValidate) == 'function')
    {
        if(Page_ClientValidate(validationGroup))
        {
            $get(button).click();
        }
    }
}

function _css(element, className){element.className=className;}

function do_print(url)
{
	var nw = window.open(url, 'nw', 'left=200,top=100,width=600,height=500,resizable=yes,statusbar=yes,scrollbars=yes');
	nw.focus();
}

function swap_bg(src, on)
{
	if(src.getAttribute('nomover') != '1')
	{
		if(on) src.setAttribute('prev', src.style.backgroundColor);	
		src.style.background = on ? '#F1F1F1' : src.getAttribute('prev');
	}
}

function swap(obj, img)
{	
	if(swap.arguments.length == 3)
		obj = obj.getElementsByTagName('img')[swap.arguments[2]];
		
	if(img.toLowerCase().indexOf('/media') > -1)
		obj.src = img;
    else
        obj.src = ImageBase + '/' + img;
}

function do_help(src, imgSrc)
{
	var img = src.getElementsByTagName('img')[0];
	img.src = '../images/' + imgSrc;
}

function only_number(src)
{
	if(event) e = event;	
	var KeyCode = (e.keyCode) ? e.keyCode : e.which;   		
	var isvalid =  ((KeyCode == 8) // backspace
			|| (KeyCode == 9) // tab
			|| (KeyCode == -37) // left arrow
			|| (KeyCode == -39) // right arrow
			|| (KeyCode == 46) // delete
		) ? 1 : 0;
	
	if(isvalid == 0)
		isvalid = 
			((KeyCode == -8) || (KeyCode == 46) ||
			((KeyCode > 47) && (KeyCode < 58)) // 0 - 9
			|| ((KeyCode > 94) && (KeyCode < 106)) 			
			) ? 2 : 0;
			
	if(!isvalid)
		return(false);
}

function __showCalendar(src)
{
	var _opener = src;
	if(src.tagName == 'IMG')
		src = src.parentElement.getElementsByTagName('input')[0];	
	
    var d = document.createElement('div');
    document.body.appendChild(d);
    _opener.style.position = 'relative';
    with(d)
    {
        id = '___calendarPicker';
        style.left = _opener.offsetLeft;
        style.top = _opener.offsetTop + _opener.offsetHeight;
        style.width = 250;
        style.zIndex = 100;
        style.position = 'absolute';            
        style.background = 'transparent';
        allowTransparency = true;            
        style.height = 200;
        var selectedDate = '';
        if(src.value.length > 0)
			selectedDate = src.value;
        innerHTML = '<iframe width="100%" allowTransparency="true" allow height="100%" frameborder="0" ' +	
					'border="0" src="calendar.aspx?field=' + src.id + '&d=' + selectedDate + '"></iframe>';
    
    }
    _opener.style.position = '';   
    return(false);
}
    
function __hideCalendar(e)
{
    var ns6 = (!document.all && document.getElementById);
    var caller = null;
    if(!e && event)
        e = event;            
    if(e)
		caller = (ns6 ? e.target : e.srcElement);
    if(!e || caller && !caller.getAttribute('calendar'))
    {
        if(src = document.getElementById('___calendarPicker'))
            document.body.removeChild(src);
    }        
}

function findObj(s)
{
	return document.getElementById(s);
}

function ImagePreloader(img)
{
	if(typeof(location) == 'undefined')return;
	
	var startUrl = location.protocol + '//' + location.hostname;
	if(location.href.toLowerCase().indexOf('/viva/') > -1)
		startUrl = startUrl + '/Viva/';
	
	// Preloader: [basePath, [ImageArray]]
	var preload = [
				// Tabs				
				['images/', ['internetOn.png', 'musicOn.png', 'mailOn.png', 'WelcomeBut.png']]
				];
				  	
	var img = null; var collection = null;
	var base = null;
	for(var i = 0; i < preload.length; i++)
	{
		basePath = preload[i][0];			
		collection = preload[i][1];
		for(var j = 0; j < collection.length; j++)
		{							
			img = new Image();				
			img.src = startUrl + basePath + collection[j];				
		}
	}	
}

function goUrl(url)
{
	document.location.href = url;
}


/* Custom Email Validator */
function isEmail(src, args)
{
	if(typeof(noMail) == 'undefined')
		noMail = 'a';
		
	if(findObj(noMail) && findObj(noMail).checked)
	{
		args.IsValid = true;
		return;
	}
	
	var str = args.Value;	
	args.IsValid = __isEmail(str);
}

function __isEmail(str) 
{
	// are regular expressions supported?
	var supported = 0;
	if (window.RegExp)
	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) 
		return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(str) && r2.test(str));
}

function XmlHttpRequest(url, parameters)
{	
	var Xml = null; // Response
	var rq = null; // Xml Document
	if(window.ActiveXObject) // Internet Explorer
		rq = new ActiveXObject('MSXML2.XmlHttp');		
	else // Other
		rq = new XMLHttpRequest();	
	rq.open("POST", url, false);	
	rq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	
	rq.send(parameters);	
	Xml = rq.responseXML;	
	rq = null;
	return Xml;
}


function get_file(id)
{
	if(!window.ActiveXObject)
		setTimeout("__getFile(" + id + ");", 100);	
	else
		__getFile(id);
}

function __getFile(id)
{
	var f = self.frames['down'];
	f.document.location.href = 'get.aspx?id=' + id;
}


function do_login()
{	
	var nw = window.open('index.aspx?autologin=yes&lang=' + escape(findObj('lang').value), 'nw');
	nw.focus();
}


function helpLink(src, on)
{
	try
	{
		var isIE = (navigator.userAgent.indexOf('MSIE') > -1 ? 1 : 0);
		var div = src.getElementsByTagName('div');
		if(isIE)	
			setFilter(div[1], 'Village/Help' + (on ? 'On' : '') + '.png');		
		else
			div[0].getElementsByTagName('img')[0].src = ImageBase + 'Village/Help' + (on ? 'On' : '') + '.png';
		if(div.length == 2)	
			div[2].className = 'helpLink' + (on ? 'Over' : '');
	} catch(e){}
}
	
function get_song(id)
{
	var _options = 'width=10,height=10,left=0,top=0,resizable=no,status=no,scrollbars=no';
	var nw = window.open('get.aspx?id=' + id, 'get', _options);
}
	
function highlightLogin()
{
	findObj('ctl00_ctl00_LoginBox_LoginBox_UserName').style.border = '1px solid blue';	
	findObj('ctl00_ctl00_LoginBox_LoginBox_Password').style.border = '1px solid blue';
	findObj('ctl00_ctl00_LoginBox_LoginBox_UserName').focus();
}

function validate_password(e)
{
	var ns6 = (!document.all && document.getElementById)
	var src = (ns6 ? e.target : event.srcElement);
	var key = (ns6 ? e.keyCode : event.keyCode);
	var key = (e.keyCode) ? e.keyCode : e.which;   		
	
	var isvalid =  
			((key > 32 && key < 127)
			|| (key == 8) // backspace
			|| (key == 9) // tab
			|| (key == -37) // left arrow
			|| (key == -39) // right arrow
			|| (key == 46) // delete
			|| (key == 13) // life feed
		) ? 1 : 0;

	if(isvalid == 0)
		isvalid = 
			((key == -8) || (key == 46) ||
			((key > 47) && (key < 58)) // 0 - 9
			|| ((key > 94) && (key < 106)) 			
			) ? 2 : 0;
		
	if(!isvalid)
	{
		alert('Δεν επιτρέπονται ελληνικοί χαρακτήρες.');
		return(false);
	}
}


function GlobalValidators()
{
	this.isMobile		= function(input) { return _isphone(input, 1) };
	this.isPhone		= function(input) { return _isphone(input) };
	this.isEmail		= ___isEmail;
	this.inRange		= _inrange;
		
	function _isphone(input, isMobile)
	{		
		var pattern = (isMobile == 1 ? /^69\d{8}/ : /^2\d{9}/);		
		var r = new RegExp(pattern);
		return r.test(input);
	}
	
	function ___isEmail(str) 
	{
		// are regular expressions supported?
		var supported = 0;
		if (window.RegExp)
		{
			var tempStr = "a";
			var tempReg = new RegExp(tempStr);
			if (tempReg.test(tempStr)) supported = 1;
		}
		if (!supported) 
			return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
		var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
		var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
		return (!r1.test(str) && r2.test(str));
	}
}

function setCookie(name, value)
{
	var cookie = '';
	if (name)
		cookie = cookie + escape(name)+"=";
	
	if (value)
		cookie = cookie + escape(value);

    cookie += ';path=/';
	document.cookie = cookie;        //  sets the cookie
}

function setPersistentCookie(name, value, expiredays)
{
    var dt = new Date();
    dt.setDate(dt.getDate() + expiredays);
    document.cookie = name + "=" + escape(value)+ ((expiredays == null) ? "" : ";expires=" + dt.toGMTString());
}

function getCookie(name)
{
	var start = document.cookie.indexOf(name + '=');
	var len = start + name.length + 1;
	if ((!start) && (name != document.cookie.substring(0, name.length)))
		return null;
	if (start == -1)
		return null;
	var end = document.cookie.indexOf(';', len);
	if (end == -1) end = document.cookie.length;
		return unescape(document.cookie.substring(len, end));
}

function _gototab()
{
	var s = getCookie('tab');
	if(s != '')
	{
		s = parseInt(s);
		if(s > 0 && s < 4)
		{
			goto_tab(s);
			// setCookie('tab', 0);
		}
	}
}

String.prototype.trim = function(){return this.toString().replace(/^\s*|\s*$/g,"");}
String.prototype.Format = _format;
String.prototype.right = _right;
String.prototype.left = _left;
String.prototype.endsWith = _endsWith;
String.prototype.endsWithRange = _endsWithRange;
String.prototype.startsWith = _startsWith;
String.prototype.startsWithRange = _startsWithRange;
String.prototype.contains = _contains;
String.prototype.isNullOrEmpty = _isNullOrEmpty;
String.prototype.reverse = _rev

function _endsWith(text){return (this.length > 0 && this.length >= text.length && this.right(text.length) == text);}
function _startsWith(text){return (this.length > 0 && this.length >= text.length && this.left(text.length) == text);}
function _contains(text){return this.indexOf(text) > -1}
function _isNullOrEmpty(){return (this == null || this.length == 0);}

function _startsWithRange(range)
{
	var result = false;
	for(var i = 0; i < range.length; i++)
	{
		if(this.startsWith(range[i]))
		{
			result = true;
			break;
		}
	}
	return(this.length > 0 && result);
}

function _endsWithRange(range)
{
	var result = false;
	for(var i = 0; i < range.length; i++)
	{
		if(this.endsWith(range[i]))
		{
			result = true;
			break;
		}
	}
	return(this.length > 0 && result);
}

function _left(len)
{
	if(this.length == 0)
		return '';
	else if(this.length <= len)
		return this;
	else
		return this.substring(0, len);
}

function _right(len)
{
	if(this.length == 0)
		return '';
	else if(this.length <= len)
		return this;
	else
		return this.substring(this.length - len);
}

function _format()
{
	var args = _format.arguments;	
	var text = this;
	for(var i = 0; i < args.length; i++)
		text = text.replace(eval('/[{]' + i + '[}]/gi'), args[i]);			
	return text;
}

function trim(str){return str.replace(/^\s*|\s*$/g,"");}

function toggle_item(caller, n)
{

	var thedivs=document.getElementsByTagName("div");
	var src = findObj('item{0}'.Format(n));	
	var srcid=src.id;
	var answer = findObj('answer{0}'.Format(n));
	var answerid=answer.id;
	
	//alert(thedivs[0].className);
	for(i=0;i<thedivs.length-1;i++)
	{
		if(thedivs[i].style.fontWeight=='bold' && thedivs[i].className=='d_divfaq')
		{
			thedivs[i].style.fontWeight='normal';
		}
		if(thedivs[i].className=='d_text_v' && thedivs[i].id!=src.id &&document.getElementById(answerid).style.BorderColor!=''){
		thedivs[i].className='d_text';
		theid='answer'+(thedivs[i].id).substr(4);
		document.getElementById(theid).style.borderColor='';
		document.getElementById(theid).style.borderStyle='';
		}
	
	}

	if(src)
	{
		caller.style.fontWeight = (src.className == 'd_text' ? 'bold' : 'normal');
		src.className = (src.className == 'd_text' ? 'd_text_v' : 'd_text');
	}
	if(src.parentNode.className.endsWith('_s'))
		src.parentNode.className = src.parentNode.className.replace('_s', '');
	if(document.getElementById(answerid).style.borderColor=='' && document.getElementById(srcid).className=='d_text_v'){
		addborder(answerid);
	}
		else{
		remborder(answerid);
	}

}

function toggle_businessItem(caller, n)
{
    var thedivs = document.getElementsByTagName("div");
    var src = findObj('item{0}'.Format(n));
    var srcid = src.id;
    var answer = findObj('answer{0}'.Format(n));
    var answerid = answer.id;

    if (caller.className == 'biz_an_v'
		&& caller.id != src.id
			&& document.getElementById(answerid).style.BorderColor != '')
	{
        caller.className = 'biz_an';
        theid = 'answer' + (caller.id).substr(4);
        document.getElementById(theid).style.borderColor = '';
        document.getElementById(theid).style.borderStyle = '';
    }

    if (src)
    {
        src.className = (src.className == 'biz_an' ? 'biz_an_v' : 'biz_an');
        caller.innerHTML = (src.className == 'biz_an' ? '» Περισσότερα' : '» Λιγότερα');
    }
    
    if(src.parentNode.className.endsWith('_s'))
        src.parentNode.className = src.parentNode.className.replace('_s', '');
    
    if(document.getElementById(srcid).className == 'biz_an_v')
		addBusinessborder(answerid);
    else
		remBusinessborder(answerid);
}

function setActiveBusinessArea()
{
    var caller = document.getElementById('toggler1');
    caller.innerHTML = '» Λιγότερα';
    
    var s = $('table[id*=answerct]');
    if(s.size() > 0)
		addBusinessborder(s[0].id);
}

function addBusinessborder(caller)
{
    var object = document.getElementById(caller);
    if(object != null)
    {
		object.style.borderColor = '#e5efe3';
		object.style.background = '#f7f7f7';
	}
}

function remBusinessborder(caller)
{
    var object = document.getElementById(caller);
    object.style.borderColor = '#ffffff';
    object.style.background = '#ffffff';
}

function _rev()
{
	if(this.length > 0)
	{
		var rev = '';
		for(var i = 0; i < this.length; i++)
			rev = this.substr(i, 1) + rev;
		return rev;
	}
	else
		return this;
}

function _restore(text)
{	
	text = text.reverse();	
	text = text.replace(/[$]/gi, '@');
	text = text.replace(/[|]/gi, ' ');	
	return text;
}


function divPaint(src, on){src.style.textDecoration = (on ? 'underline' : 'none');}

function StringBuilder()
{
	var builder = new Array();
	if(StringBuilder.arguments.length > 0)
		builder.push(StringBuilder.arguments[0])
		
	this.Append			= _append;
	this.AppendFormat	= _appendFormat;
	this.AppendLine		= _appendLine;
	this.toString		= _toString;
	
	function _append(text){builder.push(text);}	
	function _appendFormat(format, text){builder.push(format.Format(text))}
	function _appendLine(){builder.push('\n');}
	function _toString(){return builder.join('');}
}

function isPassword(text, minLength)
{
	return(text.length >= minLength 
			&& /\W/.test(text)
				&& !/[Α-ω]/.test(text)
					&& /[0-9]/.test(text));	
}

function disable_validator(name)
{
	for(var i = 0; i < Page_Validators.length; i++)
	{
		vld = Page_Validators[i];
		if(vld.id == name)
		{
			vld.IsValid = true;					
			vld.style.display = 'none';			
		}
	}
}

function nav(source, on)
{	
	var div = source.getElementsByTagName('div')[1];		
	div.className = (on ? 'item_r_over' : 'item_r');
}

function set_disable_div(div_id, container_id, img_id)
{				
	var ns6 = (document.getElementById && !document.all);
	var div = findObj(div_id);
	var obj = findObj(container_id);
	var img = findObj(img_id);
	
	img.style.display = '';						
				
	obj.style.position = 'relative';
	
	div.style.width = (obj.offsetWidth + 'px');
	div.style.height = (obj.offsetHeight + 'px');
	
	img.style.left = (div.offsetLeft + ((div.offsetWidth - img.offsetWidth) / 2)) + 'px';
	img.style.top = (div.offsetTop + ((div.offsetHeight - img.offsetHeight) / 2)) + 'px';
			
	div.style.background = 'gray';
	if(ns6)
	{
		div.style.MozOpacity = 0.5;
		//alert(div);
	}
	else
		div.style.filter = 'alpha(opacity=50)';
}

function set_closedivHandler(img_id, div_id)
{
	var div = findObj(img_id);
	div.getElementsByTagName('div')[0].onclick = new Function("close_yellow('" + div_id + "', '" + img_id + "');");
}

function close_yellow(div_id, img_id)
{
	var obj = null;
	if((obj = findObj(div_id)) != null)
		obj.style.display = 'none';
		
	if((obj = findObj(img_id)) != null)
		obj.style.display = 'none';
}

function hq_div(target)
{
	var div = findObj(target);
	var d = null;
	
	if(div != null)
	{
		var assosiatedId = div.getAttribute('assosiatedId');
		if(assosiatedId != null || typeof(assosiatedId) != 'undefined')
			d = findObj(assosiatedId);
		
		if(div != null && d == null)
		{
			window.scrollTo(0, div.offsetTop - 100);
			
			var d = document.createElement('div');
			document.body.appendChild(d);
			
			div.style.position = 'relative';
			d.setAttribute('retry', 1);
			d.id = target + '_div';			
				
			d.style.left = (div.offsetLeft + 'px');
			d.style.top = (div.offsetTop + 'px');
			d.style.width = ((div.offsetWidth - 4) + 'px');
			d.style.height = ((div.offsetHeight - 6) + 'px');
			d.style.position = 'absolute';
			d.style.zIndex = 10;			
			d.innerHTML = '&nbsp;';			
			
			d.style.border = '3px solid #faa41b';
			
			div.setAttribute('assosiatedId', d.id);
			
			setTimeout("toggle_div('" + d.id + "');", 500); 
		}
		else
		{			
			var tries = parseInt(d.getAttribute('retry'));
			if(tries > 6)
			{
				d.style.display = '';
				d.setAttribute('retry', 1);
				setTimeout("toggle_div('" + d.id + "');", 500); 
			}
		}
	}
}

function toggle_div(div_id)
{
	var div = findObj(div_id)
	if(div != null)
	{
		var tries = parseInt(div.getAttribute('retry'));
		if(tries <= 6)
		{
			div.style.display = (div.style.display == '' ? 'none' : '');
			div.setAttribute('retry', (tries + 1));
			setTimeout("toggle_div('" + div.id + "');", 500);
		}
		else
			div.style.display = 'none';
	}
}

function addborder(caller)
{
    var object = document.getElementById(caller); 

	object.style.borderColor = 'yellow';
	object.style.borderStyle = 'solid';
	object.borderWidth = '3px';
}

function remborder(caller)
{
	var object = document.getElementById(caller); 
	object.style.borderColor = '' ;
	object.style.borderStyle = ''	;
	object.borderWidth = '0px';
	
}

function disable_button(caller, flag, className)
{
    if(typeof(className) != 'undefined')
        caller.className = className;
    
    setTimeout("$get('" + caller.id + "').disabled = " + flag + ";", 10);
}

function positiontip(e)
{
    var cnt = $get('_TopContainer');
    var mn = $get('__mn');
    var tip = $get('HelperContent');

    if (tip)
    {

        var element = $get('_helper');
        var position = getElementPosition(element);
        tip.style.top = ((position.y) - tip.offsetHeight) + 'px';
        tip.style.left = (position.x - tip.offsetWidth + 35) + 'px';
    }
}

function getElementPosition(element)
{
    return { x: findPosX(element), y: findPosY(element) };
}

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 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 toggletip(e, caller)
{
    var tip = $get('HelperContent');

    if (tip)
    {
        if (tip.style.display == 'none')
        {
            tip.style.display = '';
            positiontip(e);
        }
        else
            tip.style.display = 'none';
    }
}

function EnableQuickMenu(target)
{
    var md = $find('Payments');
    if (md)
    {
        md.add_showing(function() { $get(target).className = 'loginAddPoints_active'; });
        md.add_hiding(function() { $get(target).className = 'loginAddPoints'; });
    }
}

function _errorHandler(sender, args)
{
	if(args.get_error() != undefined)
	{
		args.set_errorHandled(true);
		// CreateErrorDiv(null);
		var message = 'Παρουσιάστηκε κάποιο σφάλμα<br /><br />Πατήστε <a href="javascript: document.location.reload();">' + 
		              'εδώ</a> για ανανέωση της σελίδας.';

        message += '<br /><br />Details: <i>' + args.get_error().message + '</i>';
        
        $('#alert').find('.okButton').one('click', function(){$.unblockUI();});
        
        _alert(message);
	}
	
}

function CreateErrorDiv(exception_details)
{

    if(Balance.get_display())
        Balance.stop();

    // Create a hidden button to save state
    var hidden = $get('HiddenButton');
    if(hidden == null)
    {
        hidden = document.createElement('input');
        hidden.type = 'button';
        hidden.id = 'HiddenButton';
        hidden.name = 'HiddenButton';
        hidden.style.display = 'none';
        document.forms[0].appendChild(hidden);
    }
    
    // Create the error panel
    var div = $get('Error_Pnl');
    if(div == null)
    {
        div = document.createElement(div);
        div.id = 'Error_Pnl';
        div.style.display = 'none';
        div.innerHTML = '<div class="modal-dialog">' +
                '<div class="container" style="padding: 20px;">' +
					'<div style="float: left"><img src="/images/alert.gif" border="0" /></div>' +
                    '<div style="float: left; margin: 0px 0px 0px 10px;">Παρουστιάστηκε κάποιο σφάλμα.<br /><br /> ' +
                    'Πατήστε <a href="javascript: document.location.reload();">εδώ</a> για ανανέωση της σελίδας.' +
                    '</div>' +
                '</div>' +
            '</div>';
        document.forms[0].appendChild(div);
    }

    // Create the extender
    $create(AjaxControlToolkit.ModalPopupBehavior,
    {
        "BackgroundCssClass": "modalBackground"
        ,"PopupControlID": "Error_Pnl"
        ,"dynamicServicePath": "/index.aspx"
        ,"id": "ErrorPopup"
    }
    ,null
    ,null
    ,$get("HiddenButton"));
    
    // Display the extender
    var err = $find('ErrorPopup');
    
    if(err != null)
        err.show();
}

function _sw(e, flag)
{
    var target = (isIE ? e.srcElement : e.target);
    if(target != null && target.tagName == 'IMG')
    {
        if(target.parentNode.getAttribute('selected') == null)
        {
            var img = target.parentNode.getAttribute('_nm');
            target.src = '/images/top/{0}But{1}.gif'.Format(img, (flag ? 'On' : ''));
        }
    }        
}

function __sw(e, flag)
{
    var target = $((isIE ? e.srcElement : e.target));
    
    if(target.size() > 0
		&& target[0].tagName == 'IMG')
    {
        if(target.parent().attr('selected') == null)
        {
            var img = target.parent().attr('_nm');
            target.attr('src', '/images/home/menu/micn_{0}{1}.png'.Format(img, (flag ? '_selected' : '')));
        }
    }        
}

function __flyoutPosition()
{
    var d = $get('flyout');
	d.style.display = '';
	d.style.left = ((document.body.offsetWidth / 2) - (parseInt(d.offsetWidth) / 2)) + 'px';
	d.style.top = '400px';
}

function _incomplete()
{
    if(getCookie('IncompleteRequestAlert') == '1')
    {
        $(document).ready(function()
        {
            var d = $('#incomplete')
            .find('#incompleteView').click(function()
            {
                setCookie('IncompleteRequestAlert', 0);
                document.location.href = '/Numbers/PendingNumbers.aspx';
                $.unblockUI();
            })
            .parent().find('#incompleteClose').click(function()
            {
                //if($('#dontask').is('[checked=true]'))
                    setCookie('IncompleteRequestAlert', 0);

                $.unblockUI();
            }).parent().parent();
                
            $.blockUI(
            {
                message: d
                ,overlayCSS:
                {
                    backgroundColor: '#000000'
                }
                ,css:
                {
                    border: '0px'
                }
            });
        });
    }
}

function HighlightCase()
{
    var url = window.location.href.toLowerCase();
    var cases = $('div.ch_container').size();

    if (url.indexOf('case') > -1)
    {
	
        for (var i=0; i<=cases; i++)
        {
            if (url.indexOf('case'+i) > -1)
		    $('div[id^=divcase'+i+']').addClass('highlight');
        }
    }
}

function __validate_vat(sender,args) {args.IsValid = MyViva.validators.is_vat(args.Value);}
function __validate_number(sender, args) { args.IsValid = MyViva.validators.is_validPhoneNumber(args.Value); }

function initCorners()
{
    var roundsettings = 
    {
      tl: { radius: 8 },
      tr: { radius: 8 },
      bl: { radius: 8 },
      br: { radius: 8 },
      antiAlias: true
    }
    
    var toproundsettings = 
    {
      tl: { radius: 8 },
      tr: { radius: 8 },
      bl: { radius: 0 },
      br: { radius: 0 },
      antiAlias: true
      ,autoPad: false
    }
    
    var bottomroundsettings = 
    {
      tl: { radius: 0 },
      tr: { radius: 0 },
      bl: { radius: 8 },
      br: { radius: 8 },
      antiAlias: true
    }
    
    var round5settings = 
    {
        tl: { radius: 5 },
        tr: { radius: 5 },
        bl: { radius: 5 },
        br: { radius: 5 },
        antiAlias: true
    }
    
    var noCorners = 
    {
        tl: { radius: 0 },
        tr: { radius: 0 },
        bl: { radius: 0 },
        br: { radius: 0 },
        antiAlias: true
    }
    
    var leftTopCorner = 
    {
        tl: { radius: 8 },
        tr: { radius: 0 },
        bl: { radius: 0 },
        br: { radius: 0 },
        antiAlias: true
    }
    
    curvyCorners(roundsettings, ".round");
    curvyCorners(toproundsettings, ".topround");
    curvyCorners(bottomroundsettings, ".bottomround");
    curvyCorners(round5settings, ".round5");
    curvyCorners(leftTopCorner, ".leftftopround");
}

function fix_corners()
{
	var noCorners = 
    {
        tl: { radius: 5 },
        tr: { radius: 5 },
        bl: { radius: 5 },
        br: { radius: 5 },
        antiAlias: true
    }
    
    var pn = $get('ctl00_LoginBox_PaymentsPanel');
    curvyCorners(noCorners, pn);
}

function initCarousels()
{
	$('#jcvivaUpdates').jcarousel(
	{
	    vertical: true
	    ,scroll: 1
	});
    
    $('#autoscroll').jcarousel(
    {
        auto: 10,
        scroll: 1,
        wrap: 'circular',
        itemVisibleInCallback: {onBeforeAnimation: mycarousel_itemVisibleInCallback},
        itemVisibleOutCallback: {onAfterAnimation: mycarousel_itemVisibleOutCallback}
    });
}

function mycarousel_itemVisibleInCallback(carousel, item, i, state, evt)
{
    // The index() method calculates the index from a
    // given index who is out of the actual item range.
    var idx = carousel.index(i, mycarousel_itemList.length);
    carousel.add(i, mycarousel_getItemHTML(mycarousel_itemList[idx - 1]));
};
 
function mycarousel_itemVisibleOutCallback(carousel, item, i, state, evt)
{
    carousel.remove(i);
};


function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function()
    {
        carousel.startAuto(0);
    });
 
    carousel.buttonPrev.bind('click', function()
    {
        carousel.startAuto(0);
    });
 
    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function()
    {
        carousel.stopAuto();
    }, function()
    {
        carousel.startAuto();
    });
};

function mycarousel_getItemHTML(item)
{    
    var arr = new Array();
    
    arr.push('<div class="item">');
    //arr.push('<div class="left w40">&nbsp;</div>');
    arr.push('<h4>' + item.title + '</h4>');
    arr.push('<div style="margin-right:10px; float:left;"><a href="'+ item.url +'"><img src="'+ item.image +'" alt="'+ item.alt +'" border="0" /></a></div>');
    arr.push('<div style="float:left; width:70px;">'+ item.description +'<div class="s10"></div><a class="redlink" href="'+ item.url +'" title="'+ item.alt +'">Περισσότερα</a></div>');
    arr.push('<div class="clear"></div>');
    arr.push('</div>');
    return arr.join('');
}

function fixPNG()
{
    if ($.browser.msie && ($.browser.version < 7))
    {
        $('img[src$=.png]').each(function()
        {
            this.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + this.src + ",sizingMethod='scale')";
        });
    }
}

function SiteSearch()
{
	var q = $('input#query');

	if(q.val().length < 2 || q.val() == 'Αναζήτηση')
	{
		alert('Συμπληρώστε τουλάχιστον δύο γράμματα για αναζήτηση');
		q.focus();
	}
	else
	{
		var url = '/Search/?location=2&q={0}&size=10'.Format(q.val());
		document.location.href = url;
	}
}

function SupportSearch()
{
	var q = $('input#supportquery');

	if(q.val().length < 3 || q.val() == 'Αναζήτηση')
	{
		alert('Συμπληρώστε τουλάχιστον τρία γράμματα για αναζήτηση');
		q.focus();
	}
	else
	{
		var url = '/support/search.aspx?q={0}'.Format(q.val());
		document.location.href = url;
	}
}

function setPaymentsMenu()
{
	$('a[id$=AddPoints]:first').mouseover(function()
    {
		var panel = $('div[id$=PaymentsPanel]:first');
		//if(!panel.is(':visible'))
		//{
			var position = $(this).position();
			
			$(this).attr('class', 'loginAddPoints_active');
			
			panel.css(
			{
				left: position.left
				,top: position.top + $(this).height()
			})
		//}
		
		if(!panel.is(':visible'))
			panel.slideDown('fast');
    });
    
    var hide = function()
    {
		var panel = $('div[id$=PaymentsPanel]:first');
		panel.slideUp('fast', function()
		{
			$('a[id$=AddPoints]:first').attr('class', 'loginAddPoints');
		});
    }
    
    $('div[id$=PaymentsPanel]:first').click(function(event)
    {
		event.stopPropagation();
		hide();
    });
    
    $(document).click(hide);
}

$.fn.maxLength = function(_options)
{
	var options =
	{
		showCharCount: false
		,charCountElement: null
	};
	
	$.extend(options, _options);
	
	return this.each(function()
	{
		$(this).keypress(function(event)
		{
			var key = event.which;
			//all keys including return.
			if(key >= 33 || key == 13)
			{
				var maxLength = $(this).attr("_maxLength");
				var length = this.value.length;
				if(length >= maxLength)
					event.preventDefault();
			}
		})
		
		if(options.showCharCount)
		{
			if(options.charCountElement == null)
				options.charCountElement = $('<span></span>').insertAfter($(this));
				
			$(this).keyup(function()
			{
				options.charCountElement.html($(this).val().length);
			}).keyup();
		}
	});
}

$(document).keydown(function(ev)
{
	if(!window['loaded'])
	{
		var previousKey = window['_key'];
		if(ev.ctrlKey && ev.keyCode == 77 && previousKey == 77)
		{
			$.getScript('/aidive/js/jquery/jsnow.js', function()
			{
				$().jSnow(
				{
					flakes: 300
					,flakeMaxSize: 10
					,flakeMinSize: 10
					,flakeCode: ['/images/snow.gif', '/images/snow3.gif']
					//,flakeColor: ['red', 'green', 'blue']
					,interval: 10
				});
			});
			
			window['loaded'] = true;
		}
		window['_key'] = ev.keyCode;
	}
});

function _hideNumbersReminder()
{
//    var checked = $('#dontshow').is('[checked=true]');
//    if(checked)
    //setPersistentCookie('.NumbersReminder', '1', 1);
    setPersistentCookieNumbersReminder('.NumbersReminder', '1', 1); //add one minute to cookie
    }

    function setPersistentCookieNumbersReminder(name, value, expireminutes) {
        var dt = new Date();
        dt.setMinutes(dt.getMinutes() + expireminutes);
        document.cookie = name + "=" + escape(value) + ((expireminutes == null) ? "" : ";expires=" + dt.toGMTString());
    }


//Bubble Script by Lisa (issa@lissaexplains.com, http://lissaexplains.com)
//Based on code by Altan d.o.o. (snow@altan.hr)
//For full source code and installation instructions to this script, visit http://www.dynamicdrive.com
var no=15;var speed=2;var snow=new Array();snow[0]="/images/bubble.gif";snow[1]="/images/bubble.gif";snow[2]="/images/bubble.gif";var ns4up=(document.layers)?1:0;var ie4up=(document.all)?1:0;var ns6up=(document.getElementById&&!document.all)?1:0;var dx,xp,yp;var am,stx,sty;var i,doc_width=800,doc_height=1800;if(ns4up||ns6up){doc_width=self.innerWidth;doc_height=self.innerHeight;}else if(ie4up){doc_width=document.body.clientWidth;doc_height=document.body.clientHeight;}
dx=new Array();xp=new Array();yp=new Array();am=new Array();stx=new Array();sty=new Array();j=0;for(i=0;i<no;++i){dx[i]=0;xp[i]=Math.random()*(doc_width-50);yp[i]=Math.random()*doc_height;am[i]=Math.random()*20;stx[i]=0.02+Math.random()/10;sty[i]=0.7+Math.random();if(ns4up){if(i==0){document.write("<layer name=\"dot"+i+"\" left=\"15\" top=\"15\" visibility=\"show\"><img src=\""+snow[j]+"\" border=\"0\"></layer>");}else{document.write("<layer name=\"dot"+i+"\" left=\"15\" top=\"15\" visibility=\"show\"><img src=\""+snow[j]+"\" border=\"0\"></layer>");}}else if(ie4up||ns6up){if(i==0)
{document.write("<div id=\"dot"+i+"\" style=\"POSITION: absolute; Z-INDEX: "+i+"VISIBILITY: visible; TOP: -15px; LEFT: -15px; width:1;\"><img src=\""+snow[j]+"\" border=\"0\"></div>");}else{document.write("<div id=\"dot"+i+"\" style=\"POSITION: absolute; Z-INDEX: "+i+"VISIBILITY: visible; TOP: -15px; LEFT: -15px; width:1;\"><img src=\""+snow[j]+"\" border=\"0\"></div>");}}
if(j==(snow.length-1)){j=0;}else{j+=1;}}
function snowNS(){for(i=0;i<no;++i){yp[i]-=sty[i];if(yp[i]<-50){xp[i]=Math.random()*(doc_width-am[i]-30);yp[i]=doc_height;stx[i]=0.02+Math.random()/10;sty[i]=0.7+Math.random();doc_width=self.innerWidth;doc_height=self.innerHeight;}
dx[i]+=stx[i];document.layers["dot"+i].top=yp[i]+pageYOffset;document.layers["dot"+i].left=xp[i]+
am[i]*Math.sin(dx[i]);}
setTimeout("snowNS()",speed);}
function snowIE_NS6(){for(i=0;i<no;++i){yp[i]-=sty[i];if(yp[i]<-50){xp[i]=Math.random()*(doc_width-am[i]-30);yp[i]=doc_height;stx[i]=0.02+Math.random()/10;sty[i]=0.7+Math.random();doc_width=ns6up?window.innerWidth-5:document.body.clientWidth;doc_height=ns6up?window.innerHeight-5:document.body.clientHeight;}
dx[i]+=stx[i];if(ie4up){document.all["dot"+i].style.pixelTop=yp[i]+document.body.scrollTop;document.all["dot"+i].style.pixelLeft=xp[i]+am[i]*Math.sin(dx[i]);}
else if(ns6up){document.getElementById("dot"+i).style.top=yp[i]+pageYOffset;document.getElementById("dot"+i).style.left=xp[i]+am[i]*Math.sin(dx[i]);}}
setTimeout("snowIE_NS6()",speed);}