﻿
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;
		}
	},
	
	enterPressed: function(oEvent, sHref) {
		if (oEvent.keyCode == 13) {
			location.href = sHref;
		}
	},
	
	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);
		var nY = window.getScroll().y + (window.getSize().y / 2);
		oElement.setStyle('top', nY - (oElement.getSize().y / 2));
		oElement.setStyle('left', (window.getSize().x / 2) - (oElement.getSize().x / 2));
	},
	
	setDefaultText: function(oElement, bMode){
		var sText = oElement.getProperty('default-text');
		if(bMode){
			if(oElement.value == sText) oElement.value = '';
		}else if(oElement.value.length < 1) oElement.value = sText;
	},
	
	popupImage: function(oRef, bBlink){
		oRef = $(oRef);
		if(bBlink && !$('opusPopupImage')){
			var oImg = new Element('img').setStyles({
				position: 'absolute',
				width: 500,
				opacity: '0',
				'cursor': 'pointer',
				'border': 'solid 1px #999',
				zIndex: '60'
			}).setProperty('id', 'opusPopupImage').injectInside(document.body);
			
			var oBlink = new Fx.Morph(oImg, {duration: 500, transition: 'expo:out'});
			
			oImg.src = oRef.src.replace('&width=145', '&width=500').replace('&width=165', '&width=500');
			//alert(oImg.src);
			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{
			$('opusPopupImage').fireEvent('click');
		}
	},
	
	querystring: document.location.search.substring(1).parseQueryString()

}

var Search = {
	fetch: function(sTarget, sValue){
		new Request.HTML({
			url: 'Shop.aspx', 
			method: 'post',
			evalScripts: true,
			update: $(sTarget)
		}).send('txtCatID=' + sValue + '&txtSubCatID=' + ARGUS.querystring.txtSubCatID + '&txtActionID=201');
	},
	submit: function(sSessionID){
		var nCatID = $('txtHpCatID').value;
		var nSubCatID = $('txtHpSubCatID').value;
		var sFilter = $('txtHpFilter').value == $('txtHpFilter').getProperty('default-text') ? '' : $('txtHpFilter').value;
		
		if(nCatID == 0){
			alert('נא בחר/י חברה');
		}else{
			location.href = 'Default.aspx?txtCatID=' + nCatID + '&txtSubCatID=' + nSubCatID + '&txtFilter=' + sFilter + '&txtSID=' + sSessionID;
		}
	}
}
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 ],
				left: [oRef.getPosition().x, oRef.getPosition().x + 250]
			});
		}
	},
	setPopUp: function(sForm) {
		var oLogin = $('globalPopUp');
		oLogin.set('html', '');
		switch (sForm) {
			case 1:
				oLogin.set('html', '' +
					'<div style="WIDTH: 25px; HEIGHT: 25px; FLOAT: right; CURSOR: pointer; Z-INDEX: 10; margin:15px 15px 0px 0px" onclick="Opus.destroyPopUp();"></div>' +
					'	<form method="post" id="frmGlobalContact">' +
					'		<div id="globalContact" style="margin:30px 45px 0px 0px; width:480px; color:White; height:520px; padding-right:5px;">' +
					'		<div class="contactFormTextarea" style="margin-bottom:10px;">מלא את הפרטים בטופס ונציג שלנו יחזור אלייך לקביעת פגישה</div>' +
					'		<input type="hidden" name="txtGlobalActionID" value="1" />' +
					'		<div class="formCaption">שם חברה / שם משפחה *</div>' +
					'		<div class="formCaption">איש קשר / שם פרטי *</div>' +
					'		<div class="sep"></div>' +
					'		<div class="formElement"><input type="text" name="txtGlobalFname" /></div>' +
					'		<div class="formElement"><input type="text" name="txtGlobalLname" /></div>' +
					'		<div class="sep"></div>' +
					'		<div class="formCaption">אימייל *</div>' +
					'		<div class="formCaption">טלפון *</div>' +
					'		<div class="sep"></div>' +
					'		<div class="formElement"><input type="text" name="txtGlobalEmail" /></div>' +
					'		<div class="formElement"><input type="text" name="txtGlobalPhone" /></div>' +
					'		<div class="sep"></div>' +
					'		<div class="formCaption">הערות</div>' +
					'		<div class="sep"></div>' +
					'		<div class="formElement"><textarea name="txtGlobalComment"></textarea></div>' +
					'		<div class="sep"></div>' +
					'		<div class="contactFormTextarea"><input type="checkbox" name="txtGlobalSubscribe" checked value="1" />&nbsp;עם מסירת הפרטים הנ"ל הינך מביע/ה את הסכמתך לקבל באמצעות הדואר ו/או הדואר האלקטרוני הודעות ועדכונים, לרבות כאלו הכוללים מסרים פרסומיים ו/או שיווקיים של חברת אלפא פרקטים ושל חברות נוספות (צד שלישי) מטעמה.</div>' +
					'		<div class="sep"></div>' +
					'		<div class="divGlobalContactButtons">' +
					'			<input type="button" class="contactButton" onclick="" />' +
					'			<input type="reset" value="" class="resetButton" />' +
					'		</div>' +
					'	</form>' +
					'</div>');
				if(Browser.Engine.trident && Browser.Engine.version == 5){ // if bat shit disgusting IE7 is present
					oLogin.setStyle('background-position', '130px 0px');
					$('globalContact').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],
			left: [oRef.getPosition().x, oRef.getPosition().x - 250]
		}).chain(function() {
			if ($('globalPopUp')) $('globalPopUp').destroy();
		});
	}
}

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';
	}
	
	var oFlash = [];
	$$('.imageAsFlash').each(function(oItem, nIndex){
		var nWidth = oItem.getProperty('width') > 0 ? oItem.getProperty('width') : 200;
		var nHeight = oItem.getProperty('height') > 0 ? oItem.getProperty('height') : 150;
		var sSrc = oItem.getProperty('src');
		var oContainer = $('flash_' + nIndex) ? $('flash_' + nIndex) : $(oItem.parentNode);
		var oWrap = new Element('div').setProperties({
			'id': 'flash_' + nIndex
		}).inject(oItem, 'before');

		if(sSrc.length > 0){
			oFlash[nIndex] = new Swiff(sSrc, {
				id: 'flashMain' + nIndex,
				width: nWidth,
				height: nHeight,
				container: oContainer
			});
			oItem.destroy();
		}
	});

});

window.addEvent('load', function(){
	var myMenu = new UvumiDropdown('productNav',{
		closeDelay: 200,
		mode: 'horizontal' //default was 'horizontal'
	});
});

window.addEvent('resize', function(){

});



