﻿
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 = {
	showPopUp: function(oRef) {
		oRef = $(oRef);
		if ($('globalPopUp')) {
			this.destroyPopUp();
		} else {

			var oLogin = new Element('div').setProperty('id', 'globalPopUp').setStyles({
				opacity: '0',
				overflow: 'hidden',
				zIndex: '40'
			}).inject(document.body, 'top');


			this.setPopUp(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, '600px'],
				top: [oRef.getPosition().y, oRef.getPosition().y - 100],
				left: [oRef.getPosition().x, oRef.getPosition().x + 250]
			});
		}
	},
	setPopUp: function(sForm) {
		var oLogin = $('globalPopUp');
		oLogin.set('html', '');
		switch (sForm) {
			case 1:
			
				oLogin.set('html',$('FAQ-add-form').get('html'));
				if (Browser.Engine.trident && Browser.Engine.version == 5) { // if bat shit disgusting IE7 is present
					oLogin.setStyle('background-position', '130px 0px');
					$('globalPopUp').setStyle('margin-top', '10px');
					oLogin.getElement('.contactFormTextarea').setStyle('margin', '0px');
				}
				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.destroyPopUp();"></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;
		}
	},
	destroyPopUp: function() {
		oRef = $('globalPopUp');
		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 + 110],
			left: [oRef.getPosition().x, oRef.getPosition().x - 250]
		}).chain(function() {
			if ($('globalPopUp')) $('globalPopUp').destroy();
		});
	}
}

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});
	}
}

var Global = {
	submitContact: function() {
		var bValid = true;
		if (bValid && ($('txtGlobalName').value == $('txtGlobalName').title)) {
			alert('נא הזן שם');
			$('txtGlobalName').focus();
			bValid = false;
		}
		if (bValid && ($('txtGlobalPhone').value == $('txtGlobalPhone').title)) {
			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
			})
			.send('txtName=' + $('txtGlobalName').value + '&txtEmail=' + $('txtGlobalEmail').value + '&txtPhone=' + $('txtGlobalPhone').value + '&txtComment=' + $('txtGlobalComment').value + '&txtActionID=3');
		}
}, 
	
	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 ProdGallery = {
	ChangeImage: function(imagePath, imageTitle) {
		$('productLargeImage').setStyle('background', 'url(' + imagePath + ') no-repeat center center');
		$('imageName').set('html',imageTitle);

	}

}

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').value;
		
		location.href = 'Search.aspx?txtActionID=202&txtRegionID=' + nRegionID + '&txtDestinationID=' + nDestinationID + '&txtDateFrom=' + sDateFrom + '&txtDateTo=' + sDateTo + '&txtGuideID=' + nGuideID + '&txtTypeID=' + nTypeID + 'txtTripText=' + sText;
	},
	
	populate: function(sRef, nItemID){
		$(sRef).load('Search.aspx?txtItemID=' + nItemID + '&txtActionID=101');
		$(sRef).disabled = false;
	}
}

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';
//	}

	$$('.athenaTabWrap DIV', '.athenaTabWrap A').each(function(oItem, nIndex){
		if(nIndex == 0) Athena.moveTo(oItem, false);
		oItem.addEvents({
			'click': function(oEvent){
				oEvent.stop();
				Athena.moveTo(this, true);
			}
		});
	});
	
	
	$$('input', 'textarea').each(function(oItem){
		var sOnColor = '#636c0b';
		var sOffColor = '#636c0b';
		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);
			}
		});
	});

});

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', '');
	});
	var myMenu = new UvumiDropdown('productNav', {
		closeDelay: 200,
		mode: 'horizontal' //default was 'horizontal'
	});

});


window.addEvent('resize', function(){

});



