﻿
var ARGUS = {
	popup: function(sHref, nMode){
		var winPopup = [];
	
		switch(nMode){
			case 1: // RTE
				winPopup[nMode] = window.open(sHref, 'winPopup' + nMode, 'dependant=yes, toolbar=no, status=no, menubar=no, scrollbars=yes, movable=yes, resizable=yes, width=600, height=500');
				break;
			default:
				winPopup[nMode] = window.open(sHref, 'winPopup' + nMode, '');
				break;
		}
	},
	
	checkEmail: function(sEmail){
		var reFilter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if (reFilter.test(sEmail)){
			return true;
		}else{
			return false;
		}
	},
	
	centerWindow: function(oWindow){
		var nY = new Number((window.screen.availHeight - oWindow.document.body.offsetHeight) / 2 - 200);
		var nX = new Number((window.screen.availWidth - oWindow.document.body.offsetWidth) / 2);
		oWindow.moveTo(nX, nY);
	},
	
	fitWindow: function(oContainer){
		window.resizeTo(oContainer.offsetWidth + 20, oContainer.offsetHeight + 85);
	},
	
	centerElement: function(oElement){
		oElement = $(oElement);
		oElement.setStyle('top', ($(document.body).getSize().y / 2) - (oElement.getSize().y / 2));
		oElement.setStyle('left', ($(document.body).getSize().x / 2) - (oElement.getSize().x / 2));
	},
	
	setDefaultText: function(oElement, sText, bMode){
		if(bMode){
			if(oElement.value == sText) oElement.value = '';
		}else if(oElement.value.length < 1) oElement.value = sText;
	},
	
	addToFavorites: function(sTitle, sUrl){
		if (window.sidebar) // firefox
			window.sidebar.addPanel(sTitle, sUrl, "");
		else if(window.opera && window.print){ // opera
			var elem = document.createElement('a');
			elem.setAttribute('href', sUrl);
			elem.setAttribute('title', sTitle);
			elem.setAttribute('rel', 'sidebar');
			elem.click();
		} else if(document.all)// ie
			window.external.AddFavorite(sUrl, sTitle);
	},
	
	popupImage: function(oRef, bBlink){
		oRef = $(oRef);
		if(bBlink){
			var oImg = new Element('img').setStyles({
				position: 'absolute',
				width: 500,
				opacity: '0',
				'cursor': 'pointer',
				'border': 'solid 1px #999',
				zIndex: '10'
			}).injectInside(document.body);
			
			var oBlink = new Fx.Morph(oImg, {duration: 500, transition: 'expo:out'});
			
			oImg.src = oRef.src.replace('&width=90', '&width=500').replace('&width=165', '&width=500');
			oImg.addEvents({
				'load': function(){
					ARGUS.centerElement(oImg);
					oBlink.start({
						left: [oRef.getPosition().x, oImg.getPosition().x],
						top: [oRef.getPosition().y, oImg.getPosition().y],
						width: [oRef.getSize().x, oImg.getSize().x],
						height: [oRef.getSize().y, oImg.getSize().y],
						'opacity': [0, 1]
					});
				},
				'click': function(){
					ARGUS.centerElement(oImg);
					oBlink = new Fx.Morph(oImg, {duration: 500, transition: 'expo:in'})
					oBlink.start({
						left: [oImg.getPosition().x, oRef.getPosition().x],
						top: [oImg.getPosition().y, oRef.getPosition().y],
						width: [oImg.getSize().x, oRef.getSize().x],
						height: [oImg.getSize().y, oRef.getSize().y],
						'opacity': [1, 0]
					}).chain(function(){
						oImg.dispose();
					});
				}
			});
		}else{
			
		}
	},
	
	enterPressed: function(oEvent, sButton){
		if(oEvent.keyCode == 13){
			$(sButton).click();
		}
	},
	
	querystring: document.location.search.substring(1).parseQueryString()

}

var g_imgLoginBg = new Image();
g_imgLoginBg.src = '/img/loginBg.png';

var Opus = {
	showLogin: function(oRef){
		oRef = $(oRef);
		if($('globalLogin')){
			this.destroyLogin();
		}else{
		
			var oLogin = new Element('div').setProperty('id', 'globalLogin').setStyles({
				opacity: '0',
				overflow: 'hidden',
				zIndex: '40'
			}).inject(document.body, 'top');
			
			this.setLogin(1);
			
			var oLoginFx = new Fx.Morph(oLogin, {
				duration: 400, 
				transition: 'expo:out', 
				wait: true
			});
			
			oLoginFx.start({
				opacity: [0, 1],
				width: [oRef.getSize().x, '525px'],
				height: [oRef.getSize().y, '130px'],
				top: [oRef.getPosition().y, oRef.getPosition().y + 50],
				left: [oRef.getPosition().x, oRef.getPosition().x - 450]
			});
		}
	},
	
	setLogin: function(sForm){
		var oLogin = $('globalLogin');
		oLogin.set('html', '');
		switch(sForm){
			case 1:
				oLogin.set('html', '' +
					'<div style="RIGHT: 0px; TOP: 0px; WIDTH: 25px; HEIGHT: 25px; FLOAT: right; CURSOR: pointer; Z-INDEX: 10;" onclick="Opus.destroyLogin();"></div>' +
					'<h1 style="FLOAT: right; PADDING: 15px 10px 10px 0px; BACKGROUND: none;">כניסת לקוחות</h1>' +
					'<div class="sep"></div>' +
					'<div style="FLOAT: right; WIDTH: 80px; MARGIN: 2px 30px 0px 0px;">שם משתמש</div>' +
					'<div style="FLOAT: right; WIDTH: 120px"><input type="text" style="WIDTH: 100px;" id="txtGlobalUsername" /></div>' +
					'<div style="FLOAT: right; WIDTH: 60px; MARGIN-TOP: 2px;">סיסמה</div>' +
					'<div style="FLOAT: right; WIDTH: 120px"><input type="password" style="WIDTH: 100px;" id="txtGlobalPassword" /></div>' +
					'<div style="FLOAT: right; WIDTH: 60px;"><input type="button" value="כניסה" style="BACKGROUND: #EEE;" /></div>' +
					'<div class="sep"></div>' +
					'<div style="FLOAT: right; WIDTH: 100px; MARGIN: 10px 28px 0px 0px;"><input type="checkbox" id="txtGlobalRemember" checked />&nbsp;השאר רשום</div>' +
					'<div style="FLOAT: right; WIDTH: 80px; MARGIN: 13px 30px 0px 0px;"><a style="CURSOR: pointer;" onclick="Opus.setLogin(2);">שכחת סיסמה?</a></div>' +
					'<div class="sep"></div>');
				break;
			
			case 2:
				oLogin.set('html', '' +
					'<div style="RIGHT: 0px; TOP: 0px; WIDTH: 25px; HEIGHT: 25px; FLOAT: right; CURSOR: pointer; Z-INDEX: 10;" onclick="Opus.destroyLogin();"></div>' +
					'<h1 style="FLOAT: right; PADDING: 15px 10px 10px 0px; BACKGROUND: none;">שכחת סיסמה?</h1>' +
					'<div class="sep"></div>' +
					'<div style="FLOAT: right; WIDTH: 80px; MARGIN: 2px 30px 0px 0px;">דואר אלקטרוני</div>' +
					'<div style="FLOAT: right; WIDTH: 120px"><input type="text" style="WIDTH: 100px;" id="txtGlobalEmail" /></div>' +
					'<div style="FLOAT: right; WIDTH: 60px;"><input type="button" value="שלח" style="BACKGROUND: #EEE;" /></div>' +
					'<div class="sep"></div>' +
					'<div style="FLOAT: right; WIDTH: 80px; MARGIN: 13px 30px 0px 0px;"><a style="CURSOR: pointer;" onclick="Opus.setLogin(1);">כניסה למערכת</a></div>' +
					'<div class="sep"></div>');
				break;
		}
	},
	
	destroyLogin: function(){
		oRef = $('globalLogin');
		var oLoginFx = new Fx.Morph(oRef, {
			duration: 400, 
			transition: 'expo:out', 
			wait: true
		});
		
		oLoginFx.start({
			opacity: [1, 0],
			width: ['525px', '117px'],
			height: ['130px', '28px'],
			top: [oRef.getPosition().y, oRef.getPosition().y - 50],
			left: [oRef.getPosition().x, oRef.getPosition().x + 450]
		}).chain(function(){
			if($('globalLogin')) $('globalLogin').destroy();
		});
	}
}

var Global = {
	submitContact: function(){
		var bValid = true;
		if(bValid && $('txtGlobalName').value.length < 2){
			alert('נא הזן שם');
			$('txtGlobalName').focus();
			bValid = false;
		}
		if(bValid && $('txtGlobalPhone').value.length < 2){
			alert('נא הזן טלפון');
			$('txtGlobalPhone').focus();
			bValid = false;
		}
		if(bValid && !ARGUS.checkEmail($('txtGlobalEmail').value)){
			alert('כתובת הדואר האלקטרוני שהזנת אינה חוקית');
			$('txtGlobalEmail').focus();
			bValid = false;
		}
		
		if(bValid){
			new Request({
				url: 'Contact.aspx', 
				method: 'post',
				evalScripts: true,
				onComplete: function(){
					$('txtGlobalName').value = '';
					$('txtGlobalEmail').value = '';
					$('txtGlobalPhone').value = '';
					$('txtGlobalComment').value = '';
				}
			}).send('txtContact=' + $('txtGlobalName').value + '&txtEmail=' + $('txtGlobalEmail').value + '&txtPhone=' + $('txtGlobalPhone').value + '&txtComment=' + $('txtGlobalComment').value + '&txtActionID=2');
		}
	},
	
	submitLogin: function(){
		var bValid = true;
		
		if(bValid && !ARGUS.checkEmail($('txtHpEmail').value)){
			alert('כתובת הדואר האלקטרוני שהזנת אינה חוקית');
			$('txtHpEmail').focus();
			bValid = false;
		}
		if(bValid && $('txtHpPassword').value.length < 3){
			alert('נא הזן סיסמה');
			$('txtHpPassword').focus();
			bValid = false;
		}
		if(bValid){
			new Request({
				url: 'User.aspx', 
				method: 'post',
				evalScripts: true
			}).send('txtEmail=' + $('txtHpEmail').value + '&txtPassword=' + $('txtHpPassword').value + '&txtActionID=1');
		}
	},
	
	submitComment: function(sFormRef){
		var oForm = $(sFormRef);
		var bValid = true;
		if(bValid && (oForm['txtCommentName'].value == oForm['txtCommentName'].title || oForm['txtCommentName'].value.length < 2)){
			alert('יש להזין את שם כותב התגובה');
			oForm['txtCommentName'].focus();
			bValid = false;
		}
		if(bValid && (oForm['txtCommentTitle'].value == oForm['txtCommentTitle'].title || oForm['txtCommentTitle'].value.length < 2)){
			alert('יש להזין את כותרת התגובה');
			oForm['txtCommentTitle'].focus();
			bValid = false;
		}
		if(bValid && oForm['txtCommentEmail'].value != oForm['txtCommentEmail'].title){
			if(!ARGUS.checkEmail(oForm['txtCommentEmail'].value)){
				alert('כתובת הדואר האלקטרוני שהזנת אינה חוקית');
				oForm['txtCommentEmail'].focus();
				bValid = false;
			}
		}
		if(bValid){
			if(oForm['txtCommentEmail'].value == oForm['txtCommentEmail'].title) oForm['txtCommentEmail'].value = '';
			if(oForm['txtCommentText'].value == oForm['txtCommentText'].title) oForm['txtCommentText'].value = '';
			new Request({
				url: 'User.aspx', 
				method: 'post',
				evalScripts: true,
				onSuccess: function(){
					oForm['txtCommentName'].value = '';
					oForm['txtCommentEmail'].value = '';
					oForm['txtCommentTitle'].value = '';
					oForm['txtCommentText'].value = '';
					oForm.set('html', '<h3 style="MARGIN-RIGHT: 40px;">תגובתך התקבלה ונשתדל לפרסמה בהקדם בכפוף לתקנון</h3>');
				}
			}).send('txtCommentTypeID=' + oForm['txtCommentTypeID'].value + '&txtCommentItemID=' + oForm['txtCommentItemID'].value + '&txtCommentName=' + oForm['txtCommentName'].value + '&txtCommentEmail=' + oForm['txtCommentEmail'].value + '&txtCommentTitle=' + oForm['txtCommentTitle'].value + '&txtCommentText=' + oForm['txtCommentText'].value + '&txtActionID=3');
		}
	},
	
	blinkComment: function(oRef){
		oRef = $(oRef);
		var oWrap = $(oRef.getElement('p'));
		if(oWrap.getSize().y == 0){
			new Fx.Morph(oWrap, {duration: 300, transition: 'expo:out', wait: true}).start({'height': [0, $(oWrap.childNodes[0]).getSize().y]});
		}else{
			new Fx.Morph(oWrap, {duration: 300, transition: 'expo:out', wait: true}).start({'height': [$(oWrap.childNodes[0]).getSize().y, 0]});
		}
	}
}

var Search = {
    submit: function () {
        var nRegionID = $('txtSearchRegionID').value;
        var nDestinationID = $('txtSearchDestinationID').value;
        var sDateFrom = $('txtSearchDateFrom').title != $('txtSearchDateFrom').value ? $('txtSearchDateFrom').value : '';
        var sDateTo = $('txtSearchDateTo').title != $('txtSearchDateTo').value ? $('txtSearchDateTo').value : '';
        var nGuideID = $('txtSearchGuideID').value;
        var nTypeID = $('txtSearchTripTypeID').value;
        var sText = $('txtSearchTripText').title != $('txtSearchTripText').value ? $('txtSearchTripText').value : '';

        location.href = 'Search.aspx?txtActionID=202&txtRegionID=' + nRegionID + '&txtDestinationID=' + nDestinationID + '&txtDateFrom=' + sDateFrom + '&txtDateTo=' + sDateTo + '&txtGuideID=' + nGuideID + '&txtTypeID=' + nTypeID + '&txtTripText=' + sText;
    },

    reset: function () {
        $('txtSearchRegionID').value = 0;
        $('txtSearchDestinationID').value = 0;
        $('txtSearchDateFrom').value = $('txtSearchDateFrom').title;
        $('txtSearchDateTo').value = $('txtSearchDateTo').title;
        $('txtSearchGuideID').value = 0;
        $('txtSearchTripTypeID').value = 0;
        $('txtSearchTripText').value = $('txtSearchTripText').title;
    },

    populate: function (sRef, nParentID, nItemID) {
        $(sRef).load('Search.aspx?txtParentID=' + nParentID + '&txtItemID=' + nItemID + '&txtActionID=101');
        $(sRef).disabled = false;
    }
}

var Athena = {
	moveTo: function(oRef, bButtonBlink){
		oRef = $(oRef);
		var oTabWrap = $(oRef.parentNode);
		var oContentWrap = $(oRef.parentNode).getNext();

		if(bButtonBlink){
			oTabWrap.getElements('div').each(function(oItem){
				if(oItem.hasClass('on')) oItem.removeClass('on').addClass('off');
			});
			oTabWrap.getElements('a').each(function(oItem){
				if(oItem.hasClass('on')) oItem.removeClass('on').addClass('off');
			});
			oRef.removeClass('off').addClass('on');
		}
		new Fx.Morph(oContentWrap.getElement('ul'), {duration: 800, transition: 'expo:in:out', wait: true}).start({'right': (oContentWrap.getElement('li').getSize().x * oRef.getProperty('item_id')) * -1});
	}
}


window.addEvent('domready', function(){
//	if(Browser.Engine.trident && Browser.Engine.version <= 4){
//		//alert('WARNING!!! WARNING!!!\n You\'re using Internet Explorer 6, upgrade or begone!');
//		location.href = '/IE6.html';
//	}
	
	new  SmoothScroll({  duration:700  }, window);

	var nHpStartTab = $defined(Cookie.read('hpStartTab')) ? Cookie.read('hpStartTab') : 0;
	var bAtHp = false;
	if(nHpStartTab == 0) $$('.athenaTabWrap DIV', '.athenaTabWrap A').each(function(oItem, nIndex){
		if(oItem.get('text') == 'אירופה ואגן הים התיכון') nHpStartTab = nIndex;
		if(!bAtHp && oItem.hasClass('hp')) bAtHp = true;
	});

	$$('.athenaTabWrap DIV', '.athenaTabWrap A').each(function(oItem, nIndex){
		oItem.addEvents({
			'click': function(oEvent){
				oEvent.stop();
				if(!this.hasClass('hp') && bAtHp) Cookie.write('hpStartTab', nIndex);
				if(!this.hasClass('hp') && bAtHp) new Fx.Scroll(document.body).start(0, this.getPosition().y - 5);
				Athena.moveTo(this, true);
			}
		});
		if(nIndex == 0) Athena.moveTo(oItem, false);
		if(nIndex == nHpStartTab) Athena.moveTo(oItem, true);
	});
	
	
	MooTools.lang.set('he-IL', 'Date', {
		months: ['ינואר', 'פברואר', 'מרץ', 'אפריל', 'מאי', 'יוני', 'יולי', 'אוגוסט', 'ספטמבר', 'אוקטובר', 'נובמבר', 'דצמבר'],
		days: ['א', 'ב', 'ג', 'ד', 'ה', 'ו', 'ש'],
		dateOrder: ['date', 'month', 'year', '/']
	});
	MooTools.lang.setLanguage('he-IL')
	
	try{
		var oFrom = new CalendarEightysix('txtSearchDateFrom', {'format': '%Y-%n-%d', 'alignX': 'left', 'offsetX': -215, 'offsetY': -10, 'disallowUserInput': false, 'prefill': false, 'minDate': new Date()});
		var oTo = new CalendarEightysix('txtSearchDateTo', {'format': '%Y-%n-%d', 'alignX': 'left', 'offsetX': -215, 'offsetY': -10, 'disallowUserInput': false, 'prefill': false, 'minDate': Date.parse($('txtSearchDateFrom').value)});
		if($('txtSearchDateTo').value.indexOf('-') > 0) oTo.options.minDate = Date.parse($('txtSearchDateFrom').value);

		oFrom.addEvent('change', function(date) {
			date = date.clone().increment(); 
			oTo.options.minDate = date; 
			if(oTo.getDate().diff(date) >= 1) oTo.setDate(date); 
			else oTo.render(); 
		});
	}catch(ex){
		alert(ex.description + '\nThis browser version is not yet supported for the Calendar module. An update is expected soon');
	}
	
	$$('input', 'textarea').each(function(oItem){
		var sOnColor = '#333';
		var sOffColor = '#999';
		oItem.setStyle('color', sOffColor);
		if(oItem.title.length > 0 && oItem.value.length == 0){
			oItem.value = oItem.title;
		}else oItem.setStyle('color', sOnColor);
		oItem.addEvents({
			'focus': function(){
				if(oItem.value == oItem.title) oItem.value = '';
				oItem.setStyle('color', sOnColor);
			},
			'blur': function(){
				if(oItem.value.length < 1){
					oItem.setStyle('color', sOffColor);
					oItem.value = oItem.title;
				} else oItem.setStyle('color', sOnColor);
			}
		});
	});
	
	//alert(ARGUS.querystring.txtDestinationID);
	if(ARGUS.querystring.txtDestinationID) Search.populate('txtSearchDestinationID', ARGUS.querystring.txtRegionID, ARGUS.querystring.txtDestinationID);

});

window.addEvent('load', function(){
	$$('.newsImage').each(function(oItem){
		var oImage1 = oItem.getChildren('.newsItemImage1');
		var oImage2 = oItem.getChildren('.newsItemImage2');
		oItem.setStyles({
			background: 'url(' + oImage1[0].src + ')',
			width: oImage1[0].width,
			height: oImage1[0].height
		}).addEvents({
			'mouseenter': function(oEvent){
				oEvent.stop();
				this.setStyle('background', 'url(' + oImage2[0].src + ')');
			},
			'mouseleave': function(oEvent){
				oEvent.stop();
				this.setStyle('background', 'url(' + oImage1[0].src + ')');
			}
		}).set('html', '');
	});
	
});

window.addEvent('resize', function(){

});



