﻿/** 
  * DHTML Drop down menu
  *
  * This is a simple drop down menu whose layout is managed via CSS. It 
  *  is also accessible. You can tab through the menu. 
  * 
  * Menu allows limited customization in the way it shows submenus and 
  * marking steps. 
  *
  * Compatible:
  * I have tested the menu under IE6+, Firefox and Opera. Works also on 
  * IE 5.5 but there are some problems with CSS (padding and width) 
  * 
  * Please let me know if it works on other browsers. 
  *
  * @author Ivars Veksins (ivars [at] gmail [dot] com)
  *
  * IF YOU EVER USE THIS CODE PLEASE LEAVE THE HEADER AS 
  * IT IS. IT WOULD BE NICE IF YOU WOULD LET ME KNOW 
  * YOU ARE USING THIS DROP DOWN MENU BY E-MAILING ME.
  * 
  * ENJOY!
  */ 
  
  
/** 
  * Create a super class where we are going to extend 
  * our drop down menu functions. 
  */
function sideDHTML_Popup()
{
}

// implement garbage collector 
// garbage collector will call super functions dispose function 
// asking to release all allocated memory 
IMPLEMENT_GARBAGE(sideDHTML_Popup)

// settings configured by the user 
sideDHTML_Popup.DELAY = 500; 
sideDHTML_Popup.ID = "sideNavContainer"; 
sideDHTML_Popup.FLAGS = sideDHTML_Popup.NORMAL; 

// do not touch these settings
// by changing these you can break the functionality 
sideDHTML_Popup.TIMER = 0;

// status a menu can have
sideDHTML_Popup.HIDE = 1; 
sideDHTML_Popup.SHOW = 2; 
sideDHTML_Popup.HALT = 4; 
sideDHTML_Popup.MARK = 8; 


// variables where we save DOM references 
// in HTML page. 
sideDHTML_Popup.MENUS = null; 
sideDHTML_Popup.sideItemS = Array(); 

/** 
  * Garbage collector implementation. Release all allocated memory. 
  * As I understand global variables and DOM references have to deleted. 
  * 
  * IE leaks as hell, therefore do whatever you can. 
  */
sideDHTML_Popup.dispose = function() 
{ 
	// release all global properties
	sideDHTML_Popup.DELAY = null; 
	sideDHTML_Popup.ID = null;
	sideDHTML_Popup.HIDE = null; 
	sideDHTML_Popup.SHOW = null; 
	sideDHTML_Popup.HALT = null; 
	
	// set effect flags to null
	sideDHTML_Popup.NORMAL = null;
	sideDHTML_Popup.SCROLL_IN = null; 
	sideDHTML_Popup.SCROLL_OUT = null; 
	sideDHTML_Popup.SCROLL_INOUT = null; 
	sideDHTML_Popup.FADE_IN = null;
	sideDHTML_Popup.FADE_OUT = null; 
	sideDHTML_Popup.FADE_INOUT = null;

	// clear main timer 
	if (sideDHTML_Popup.TIMER) 
		clearTimeout(sideDHTML_Popup.TIMER);
		
	sideDHTML_Popup.MENUS = null; 
	var sideItems = sideDHTML_Popup.sideItemS; 
	for (var sidei = 0; sidei < sideItems.length; sidei++) 
	{ 
		var sideItem = sideItems[sidei]; 
		
		// delete all references 
		sideItem.$holding_menus = null; 
		sideItem.$owner = null; 
		
		sideItem = null; 
	}
	
	sideDHTML_Popup.sideItemS = null; 
}

/**
  * Function called onload event to lookup for all the unordered lists 
  * and apply all the nessecery events and start the main timer which will show and hide 
  * menus. 
  */
sideDHTML_Popup.install = function() 
{

	// get main container which holds all menus 
	// (DIV element user specified) 
	var sideContainer = sideDHTML_Popup.get_container(); 
	
	if (sideContainer == null)
		return false; 
		
	// get all menus container contains 
	var sidemenus = sideContainer.getElementsByTagName("UL"); 
	
	// go through all menus and install events 
	for (var sidei = 0; sidei < sidemenus.length; sidei++) 
	{
		// current menu 
		var sidemenu = sidemenus[sidei]; 
		
		// status what is happening with the menu 
		// default state is to hide 
		sidemenu.$status = sideDHTML_Popup.HIDE; 
		sidemenu.$visible = false; 

		// events which will change menu state to show or hide
		event_install(sidemenu,"onmouseover",sideDHTML_Popup.mouse_over_menu); 
		event_install(sidemenu,"onmouseout",sideDHTML_Popup.mouse_out_menu); 

		// check wether the menu is root menu 
		if (sidei == 0) 
			sidemenu.$root = true; 
		
		var sideItems = sidemenu.childNodes; 
		var last_valid_sideItem = null; 
		
		// go through all sideItems in the menu and set their 
		// events and any properties
		for (var siden = 0; siden < sideItems.length; siden++) 
		{ 
			var sideItem = sideItems[siden]; 
			
			if (!sideItem.innerHTML) 
				continue; 
			
			last_valid_sideItem = sideItem; 
			
			// set reference to owner menu 
			sideItem.$owner = sidemenu; 
			
			// install events to show menu only if the sideItem has any menus 
			if (sideDHTML_Popup.sideItem_has_menu(sideItem)) {

				// install events which check if the sub menu has to be showed or not 
				event_install(sideItem,"onmouseover",sideDHTML_Popup.mouse_over_sideItem); 
				event_install(sideItem,"onmouseout",sideDHTML_Popup.mouse_out_sideItem); 
				
				// manage keyboard with the same actions 
				// only anchors receive focus and blur properly
				var sideanchor = sideItem.getElementsByTagName("A"); 
				
				if (sideanchor.length > 0) {
					// set reference to sideItem 
					event_install(sideanchor[0],"onfocus",sideDHTML_Popup.sideItem_focused); 
					event_install(sideanchor[0],"onclick",sideDHTML_Popup.sideItem_clicked); 
				}
				
				// save references to sideItems
				sideDHTML_Popup.sideItemS.push(sideItem); 
			}
			
		} 
		
		// when the last sideItem is blured the holding menu has to be set to hidden 
		// last valid sideItem handles the onblur event
		if (last_valid_sideItem)
		{
			var sideanchor = last_valid_sideItem.getElementsByTagName("A"); 
			
			if (sideanchor.length > 0) 
				event_install(sideanchor[0],"onblur",sideDHTML_Popup.sideItem_blured); 
		}
					

	}	


	// save reference for later use
	sideDHTML_Popup.MENUS = sidemenus; 
	
	// start worker "thread" 
	sideDHTML_Popup.start_worker(); 
	
	// delete container reference 
	sidecontainer = null; 
	return true; 
}

event_install(window,"onload",sideDHTML_Popup.install); 



/** 
 * Keyboard accessible event which is trigered when a anchor receives 
 * a focus. On focus we are deciding which menus to show or to hide
 */
sideDHTML_Popup.sideItem_focused = function() 
{ 
	var sideItem = this.parentNode; 
	
	// fast tabbing causes to open to many menus 
	// check if is menu set to visible and not visible yet 
	var sidemenus = sideDHTML_Popup.MENUS;  
	
	for (var sidei = 0; sidei < sidemenus.length; sidei++) { 
		var sidemenu = sidemenus[sidei]; 
		
		if (sidemenu.$root) continue; 
		
		if (sideItem.$owner.$root) {	
			sidemenu.$status = sideDHTML_Popup.HIDE; 
			sideDHTML_Popup.menu_hide(sidemenu);
		} else { 
			// hide menu if set to hide and not hidden 
			if (sidemenu.$status & sideDHTML_Popup.HIDE && sidemenu.$visible) 
				sideDHTML_Popup.menu_hide(sidemenu);
				
			// hide menus which are set to show but not showed 
			if (sidemenu.$status & sideDHTML_Popup.SHOW && !sidemenu.$visible) 
				sidemenu.$status = sideDHTML_Popup.HIDE; 
		}
	}
	
	// activate new sideItem 
	var sideholding = sideItem.$holding_menus[0]; 
	
	if (sideholding) 
		sideholding.$status = sideDHTML_Popup.HALT | sideDHTML_Popup.SHOW | sideDHTML_Popup.MARK; 
	
}

/** 
  * Focusing and bluring breaks the functionality if using mouse 
  * and user clicks a lot. 
  * A little hack which checks whether it is a click or a tab. 
  */
sideDHTML_Popup.sideItem_clicked = function() 
{
	var sideowner = this.parentNode.$owner; 
	if (!sideowner) 
		return; 
		
	sideowner.$clicked = true; 
}

/** 
 * Keyboard accessible event triggered when an anchor 
 * looses its focus. 
 */
sideDHTML_Popup.sideItem_blured = function() 
{ 
	var sideowner = this.parentNode.$owner; 
	
	if (!sideowner) 
		return; 

	if (sideowner.$clicked) 
	{ 
		sideowner.$clicked = false; 
		return; 
	}
	
	// root menu doesn't have to be hidden 
	if (sideowner.$root) 
		return; 

	var sideholding = this.parentNode.$holding_menus; 

	sideowner.style.zIndex = '1'; 
	
	if (sideholding && sideholding[0].$status & sideDHTML_Popup.SHOW) {
		// tell to hide all
		sideholding[0].$hide = sideowner; 
		
	} else { 
		if (sideowner.$hide) 
			sideowner.$hide.$status = sideDHTML_Popup.HIDE; 
	
		sideowner.$status = sideDHTML_Popup.HALT | sideDHTML_Popup.HIDE; 
	}
	
	// delete reference
	sideowner = null; 
}


/** 
  * Gets a container which holds all unordered lists 
  * @return DOM reference
  */
sideDHTML_Popup.get_container = function()
{
	var sidecontainer = document.getElementById(sideDHTML_Popup.ID); 
	
	if (sidecontainer == null) 
		ctad_error("sideDHTML_Popup container can not be found."); 
		
	return sidecontainer; 
}


/** 
 * function which goes through all menus in container and checks 
 * whether they have to be hidden or displayed. 
 * 
 * This function is executed in a delay specified 
 * sideDHTML_Popup.DELAY
 */
sideDHTML_Popup.start_worker = function() 
{	
	var sidemenus = sideDHTML_Popup.MENUS; 
	
	if (!sidemenus) 
		return; 
	
	// loop through all elements 
	for (var sidei = 0; sidei < sidemenus.length; sidei++) 
	{ 
		
		var sidemenu = sidemenus[sidei]; 
		
		// root menu never should be hidden 
		if (sidemenu.$root) 
			continue; 
			
		
		// check wether holding menu sideItem has to be marked 
		// or unmarked 
		if (sidemenu.$status & sideDHTML_Popup.MARK) {
			sideDHTML_Popup.mark(sidemenu.parentNode); 
		} else { 
			sideDHTML_Popup.unmark(sidemenu.parentNode); 
		}
		
		// check menu needs to be hidden or showed 
		if (sidemenu.$status & sideDHTML_Popup.HIDE ) {
			sideDHTML_Popup.menu_hide(sidemenu); 
		} else if (sidemenu.$status & sideDHTML_Popup.SHOW ) { 
			sideDHTML_Popup.menu_show(sidemenu); 
		}
	}
	
	sideDHTML_Popup.TIMER = setTimeout('sideDHTML_Popup.start_worker()', sideDHTML_Popup.DELAY ); 
}

/** 
  * Sets menu to invisible mode. 
  * @argument menu which needs to be hidden 
  */
sideDHTML_Popup.menu_hide = function(sidemenu) {
	
	if (!sidemenu.$visible) 
		return; 

	sideDHTML_Popup.custom_hide(sidemenu); 
	sidemenu.$visible = false; 
}


/** 
  * Sets menu to visible mode. 
  * @argument menu to be set to visible 
  */
sideDHTML_Popup.menu_show = function(sidemenu)
{
	if (sidemenu.$visible) 
		return; 

	// ie doesn't hide menus when not visible 
	// therefore we have to hide them ourselfs 
	// (BUG)
	var sidemenus = sidemenu.getElementsByTagName("UL"); 
	for (var sidei = 0; sidei < sidemenus.length; sidei++) 
	{ 
		var sidem = sidemenus[sidei]; 

		sidem.style.display = 'block'; 
		sidem.style.display = 'none'; 
	}

	sideDHTML_Popup.custom_show(sidemenu); 
	sidemenu.$visible = true; 
}; 


/** 
  * When mouse is over an sideItem set its holding menu status 
  * to show. The main worker is going to show it. 
  */
sideDHTML_Popup.mouse_over_sideItem = function() 
{
	// get menu to show 
	var sidemenu = this.$holding_menus[0]; 

	// set menu status to show 
	if (sidemenu.$status & sideDHTML_Popup.HIDE) 
		sidemenu.$status = (sidemenu.$status & ~sideDHTML_Popup.HIDE) | sideDHTML_Popup.SHOW | sideDHTML_Popup.MARK; 
	
	// change z order
	sidemenu.style.zIndex = '2'; 
	
	sideDHTML_Popup.restart_worker(); 
	

}

/** 
  * When mouse is outside the sideItem set its holding menu status 
  * to be hidden. Again, the main worker hides it. 
  */
sideDHTML_Popup.mouse_out_sideItem = function() 
{
	// get menu to hide 
	var sidemenu = this.$holding_menus[0]; 
	
	if (sidemenu.$status & sideDHTML_Popup.SHOW)
		sidemenu.$status = (sidemenu.$status & ~(sideDHTML_Popup.SHOW | sideDHTML_Popup.MARK) ) | sideDHTML_Popup.HIDE; 
	
	// change z order 
	sidemenu.style.zIndex = '1'; 

	sideDHTML_Popup.restart_worker();
}


/**  
  * Event handler when mouse is over menu 
  * Sets status to halt to true. Forces menu to be dislpayed (locks it)
  */
sideDHTML_Popup.mouse_over_menu = function() 
{
	if (this.$status & sideDHTML_Popup.HALT)
		return; 

	this.$status |= sideDHTML_Popup.HALT; 
	sideDHTML_Popup.restart_worker(); 
}


/**  
  * Removes the lock from menu. Menu can be hidden by setting
  * HIDE flag. 
  */
sideDHTML_Popup.mouse_out_menu = function() 
{
	if ( this.$status & sideDHTML_Popup.HALT) 
		this.$status &= ~sideDHTML_Popup.HALT; 
	
	sideDHTML_Popup.restart_worker(); 
}



/** 
  * Stops main working "thread" and 
  * starts from begining 
  */
sideDHTML_Popup.restart_worker = function() 
{ 
	clearTimeout(sideDHTML_Popup.TIMER); 
	sideDHTML_Popup.TIMER = setTimeout('sideDHTML_Popup.start_worker()',sideDHTML_Popup.DELAY ); 
}

/** 
  * Checks wether an sideItem has another level 
  * menu inside. 
  * 
  * @argument LI DOM reference 
  * @return status 
  */
sideDHTML_Popup.sideItem_has_menu = function (sideItem) 
{ 
	var sidemenus = sideItem.getElementsByTagName("UL"); 
	
	if (sidemenus == null || sidemenus.length == 0) 
		return false; 
	
	// sets reference with menus inside the sideItem 
	sideItem.$holding_menus = sidemenus; 
	
	return true; 
}


/** 
  * Overridable function for marking active steps
  * @argument sideItem to mark 
  */
sideDHTML_Popup.mark = function (sideItem) 
{
}

/** 
  * Overridable function which resets the sideItem to normal state. 
  * @argument sideItem to unmark 
  */
sideDHTML_Popup.unmark = function (sideItem) 
{
}


/**
  * Function which performs custom show on menu. 
  * This function can also be overrided 
  */
sideDHTML_Popup.custom_show = function(sideItem) 
{
	sidemenu.style.display = 'block'; 
}

/**
  * Function which performs a custom hide on menu 
  * This function can also be overrided 
  */
sideDHTML_Popup.custom_hide = function(sidemenu) 
{
	sidemenu.style.display = 'none'; 
}

// --- EFFECTS --- // 


// scrolling effect 
function Scrolling() 
{
}

IMPLEMENT_GARBAGE(Scrolling); 

// there can be multiple menus to be hidden but only one has to be shown at 
// time. Therefore show menu reference is a direct reference, but menus to hide 
// array 
Scrolling.$hidden = []; 
Scrolling.$active_out = null; 

Scrolling.$show = null; 

// scrolling step 
Scrolling.$step_size = 10; 


Scrolling.dispose = function() 
{ 
	Scrolling.$hidden = null; 
	Scrolling.$active_out = null; 
	Scrolling.$show = null; 
	Scrolling.$step_size = null; 
}

// scrolls from 1 to the original height of menu 
Scrolling.do_scrolling_in = function() 
{
	var sidemenu = Scrolling.$show; 
	if (!sidemenu) 
		return; 
	
	if (sidemenu.clientHeight < sidemenu.$original_height) 
	{
		sidemenu.style.height = (sidemenu.clientHeight + Scrolling.$step_size) + 'px';
		setTimeout('Scrolling.do_scrolling_in()',10); 
		
	} else { 
		// finished scrolling 
		
		sidemenu.style.height =  'auto'; 
		sidemenu.style.overflow = 'visible'; 
		
		Scrolling.$show = null; 	
	}
}

// scroll froms original height to 1 
Scrolling.do_scrolling_out = function() 
{
	var sidemenu = Scrolling.$active_out; 
	
	if (!sidemenu)
		return; 
		
	sidemenu.$height -= Scrolling.$step_size;
	
	if (sidemenu.$height > 0) 
	{
		sidemenu.style.height = sidemenu.$height + 'px'; 
		setTimeout('Scrolling.do_scrolling_out()',10); 
	} else { 
		
		sidemenu.style.display = 'none'; 

		sidemenu.style.overflow = 'visible'; 
		sidemenu.style.height = sidemenu.$original_height + 'px'; 

		// check for next element 
		Scrolling.$active_out = Scrolling.$hidden.pop(); 
		
		if (Scrolling.$active_out) 
			Scrolling.do_scrolling_out();
	}
}

// indicates that a menu has to be scrolled in 
// prepares menu and starts scrolling 
Scrolling.scroll_in = function(sidemenu) 
{ 
	// have to set to be displayed as block 
	// otherwise the height is incorrect
	sidemenu.style.display = 'block'; 
	
	// save the original height 
	if (!sidemenu.$original_height) 
		sidemenu.$original_height = sidemenu.clientHeight; 
	
	// otherwise anchors are as they are 
	sidemenu.style.overflow = 'hidden'; 
	sidemenu.style.height = '1px'; 
	
	// global reference 
	Scrolling.$show = sidemenu; 
	
	// start scrolling 
	Scrolling.do_scrolling_in(); 
}

// indicates that the menu has to be hidden 
// and asks to start scrolling out 
Scrolling.scroll_out = function(sidemenu) 
{
	sidemenu.style.overflow = 'hidden'; 
	
	if (!sidemenu.$original_height) 
		sidemenu.$original_height = sidemenu.clientHeight;

	sidemenu.$height = sidemenu.$original_height; 
	
	Scrolling.$hidden.push(sidemenu); 

	if (!Scrolling.$active_out) 
	{
		Scrolling.$active_out = Scrolling.$hidden.pop(); 
		Scrolling.do_scrolling_out(); 
	}
}


function NewsletterRegister()
{
    var eMail = document.getElementById("mm_newemail").value;
    if(eMail=="")
    {
        alert("יש למלא דואר אלקטרוני");
        document.getElementById("mm_newemail").focus();
        return false;
    }
    else
    {
        var testresults
        var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
        			
        if (filter.test(eMail))
        {
        		
        }
        else
        {
            alert("דואר אלקטרוני אינו תקין");
            document.getElementById("mm_newemail").focus();
            return false;	
        }
    }
    document.getElementById("mm_details").style.display="none";
    document.getElementById("mm_button").style.display="none";
    document.getElementById("mm_okMsg").style.display="";
    document.getElementById("mm_iframe").src="http://www.mymarketing.co.il/PerformOptIn.aspx?mm_userid=446&mm_newemail="+ eMail +"";
    
   
}