﻿function checkMail(mailAddress) 
{
    var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,4})(\\]?)$";
    if (mailAddress.match(reg1str) == null &&
		    mailAddress.match(reg2str) != null)
    {
	    return true;
    }
    return false;
}

function checkURL(url) 
{
    var urlPattern = /^(?:(?:ftp|https?):\/\/)?(?:[a-z0-9](?:[-a-z0-9]*[a-z0-9])?\.)+(?:com|edu|biz|org|gov|int|info|mil|net|name|museum|coop|aero|[a-z][a-z])\b(?:\d+)?(?:\/[^;"'<>()\[\]{}\s\x7f-\xff]*(?:[.,?]+[^;"'<>()\[\]{}\s\x7f-\xff]+)*)?/;
    return urlPattern.test(url.toLowerCase());
}

var popupDiv = document.createElement('div');
var divIdName = 'popupDiv';
popupDiv.setAttribute('id',divIdName);
popupDiv.style.position = 'absolute';
var returnFocusElement = '';

function ShowMessage(msg, autoHide)
{
    var width = '220px';
	var height = '120px';
    var x = (document.body.clientWidth- parseInt(width))/2 + 'px';
    var y = (document.body.clientHeight- parseInt(height))/2 + 'px';
    popupDiv.style.backgroundColor = "#eeeeee";
    popupDiv.style.border = "solid black 1px";
    popupDiv.style.width = width;
    popupDiv.style.height = height;
    popupDiv.style.left = x;
    popupDiv.style.top = y;
    popupDiv.innerHTML = MessageTemplate(msg);   
    document.getElementsByTagName('BODY')[0].appendChild(popupDiv);
    document.getElementById('popupDiv').focus();
    if(autoHide)
    {
        window.setTimeout(HideMessage, 2000);
    }
}

function HideMessage()
{
    try
    {
        document.getElementsByTagName('BODY')[0].removeChild(popupDiv);
        if (returnFocusElement != '')
        {
            document.getElementById(returnFocusElement).focus();
            returnFocusElement = '';        
        }
    }
    catch(ex){}
}

function MessageTemplate(msg)
{
    var html="";
    html+="<table cellpadding='0' cellspacing='0' style=\"table-layout:fixed; width:100%; height:100%; direction:rtl;\" onmousedown='HideMessage();'>";
    html+="<tr style=\"background-color:#952b19; height:20px;\">";
    html+="<td style=\"text-align:right; padding-right:5px;\">";
    html+="<img src='Images/Icons/close.jpg' onclick='HideMessage()'>";
    html+="</td>";
    html+="</tr>";
    html+="<tr style=\"height:100px;\">";
    html+="<td style=\"text-align:center; padding: 10px; height:90px;\">";
    html+="<span style=\"font-family : Verdana, Arial; font-size:12px;\">"+msg+"</span>";
    html+="</td>";
    html+="</tr>";
    html+="</table>";
    
    return html;
}

function ReturnFocusOnMessageClose(returnFocus)
{
    returnFocusElement = returnFocus;   
}

document.onmousedown=right;
if (document.layers) window.captureEvents(Event.MOUSEDOWN);
	window.onmousedown=right;
function right(e) {
	if (navigator.appName == 'Netscape' && (e.which == 2 || e.which == 3)) {
		SetTitle();
		HideMessage();
		return false;
	}
	else if (navigator.appName == 'Microsoft Internet Explorer' && (event.button==2 || event.button == 3)) {
		SetTitle();
		HideMessage();
		return false;
	}
	return true;
}

function SetTitle()
{
    document.title="היומן";
}

function Event_Attach(targetElementId, targetEvent, targetFunction)
{
    try
    {
	    var targetElement = null;
    	
	    if (targetElementId == 'window')
	    {
		    targetElement = window;		
	    }
	    else if (targetElementId == 'document')
	    {
	        targetElement = document;
	    }
	    else
	    {
		    targetElement = document.getElementById(targetElementId);				
	    }
    				
	    if (typeof(targetElement.addEventListener) != 'undefined') 
	    {
		    targetElement.addEventListener(targetEvent, targetFunction, false);
	    } 
	    else if (typeof(targetElement.attachEvent) != 'undefined') 
	    {
		    targetElement.attachEvent('on' + targetEvent,targetFunction);
	    } 
	    else
	    {
		    alert('cant attach event ' + targetEvent + ' to element ' + elementId);
	    }
	}
	catch(e)
	{
	    alert('error attaching event');
	
	}
}

function Event_Detach(targetElementId, targetEvent, targetFunction)
{
    try
    {
	    var targetElement = null;
    	
	    if (targetElementId == 'window')
	    {
		    targetElement = window;		
	    }
	    else if (targetElementId == 'document')
	    {
	        targetElement = document;
	    }
	    else
	    {
		    targetElement = document.getElementById(targetElementId);				
	    }
    				
	    if (typeof(targetElement.removeEventListener) != 'undefined') 
	    {
		    targetElement.removeEventListener(targetEvent, targetFunction, false);
	    } 
	    else if (typeof(targetElement.detachEvent) != 'undefined') 
	    {
		    targetElement.detachEvent('on' + targetEvent,targetFunction);
	    } 
	    else
	    {
		    alert('cant detach event ' + targetEvent + ' to element ' + elementId);
	    }
	}
	catch(e)
	{
	    alert('error detaching event');	
	}
}

function IsIE()
{
    n=navigator.userAgent;
    w=n.indexOf("MSIE");
    if(w>0)
    {
        return true;
    }
    else
    {
        return false;
    }
}

function UnSupportedBrowserMessage()
{
    return 'דפדפן זה אינו תומך באופציה זו.';
}

function AddToFavorite()
{
    try
    {
        if (IsIE())
        {
            window.external.AddFavorite('http://www.hayoman.co.il','היומן - ניהול אירועים');
        }
        else
        {
            ShowMessage(UnSupportedBrowserMessage(),false);        
        }                             
    }
    catch(ex){}
}

function AddToDesktop()
{
    try
    {
        if (IsIE())
        {
            ShowMessage('לחץ על כפתור ימני בעכבר מחוץ לחלון זה ובחר ב:<br>Create shortcut/קיצור דרך',false);
        }
        else
        {
            ShowMessage(UnSupportedBrowserMessage(),false);        
        }                             
    }
    catch(ex){}
}

function MakeHomePage(sender)
{
    try
    {
        if (IsIE())
        {
            sender.style.behavior='url(#default#homepage)';
            sender.setHomePage('http://www.hayoman.co.il/');
        }
        else
        {
            ShowMessage(UnSupportedBrowserMessage(),false);        
        }                             
    }
    catch(ex){}
}

function CancelSubmit(evt)
{    
    var charCode = (evt.charCode) ? evt.charCode :
                   ((evt.keyCode) ? evt.keyCode :
                   ((evt.which) ? evt.which : 0));

    if (charCode == 13) 
    {
        if (!evt)
        {
            if (window.event)
            {
                evt = window.event;
            }
            else
            {
                return;
            }
        }
        if (evt.cancelBubble != null)
        {
            evt.cancelBubble = true;
        }
        if (evt.stopPropagation)
        {
            evt.stopPropagation();
        }
        if (evt.preventDefault)
        {
            evt.preventDefault();
        }
        if (window.event)
        {
            evt.returnValue = false;
        }
        if (evt.cancel != null)
        {
            evt.cancel = true;
        }
    }
}

function AttachCancelSubmit()
{
    Event_Attach('document', 'keypress', CancelSubmit);
}

function DetachCancelSubmit()
{
    Event_Detach('document', 'keypress', CancelSubmit);
}

AttachCancelSubmit();