var MLeavePopUp;
function CreateLaeveBox(RepeatAfterDays)
{
    if(IsMobileDevice())
        return;
    MLeavePopUp = $(".MLeavePopUp");
    $(".MLeavePopUpclose").click(function () {
        MLeavePopUp.css("display", "none");
    });
    $(document).bind("mouseleave", function (e) {
        //console.log("y=" + e.clientY);
        //console.log("kook" + $.cookie("MLeavePopUpShown"));
        if (e.clientY < 0 || e.clientY<100)
        {
            if ((MLeavePopUp.css("display") === "none" || MLeavePopUp.css("display") === "")
                && ($.cookie("MLeavePopUpShown") === undefined || $.cookie("MLeavePopUpShown") === null || $.cookie("MLeavePopUpShown")===""))
             {
                MLeavePopUp.css("display", "block");
                if (RepeatAfterDays !== 0) {
                    var midnight = new Date();
                    midnight.setHours(23, 59, 59, 0);
                    if (RepeatAfterDays == -1) {
                        var midnight = new Date();
                        midnight.setHours(23, 59, 59, 0);
                        $.cookie('MLeavePopUpShown', '1', { expires: midnight, path: '/' });
                    }
                    {
                        $.cookie('MLeavePopUpShown', '1', { expires: RepeatAfterDays, path: '/' });
                    }
                }
             }
        }
    });
}
/*
var MLeavePopUp;
function CreateLaeveBox(RepeatAfterDays)
{
    if(IsMobileDevice())
        return;
    MLeavePopUp = $(".MLeavePopUp");
    $(".MLeavePopUpclose").click(function () {
        MLeavePopUp.css("display", "none");
    });
    $(document).bind("mouseleave", function (e) {
        //console.log("y=" + e.clientY);
        //console.log("kook" + $.cookie("MLeavePopUpShown"));
        if (e.clientY < 0 || e.clientY<100)
        {
            if ((MLeavePopUp.css("display") === "none" || MLeavePopUp.css("display") === "")
                && ($.cookie("MLeavePopUpShown") === undefined || $.cookie("MLeavePopUpShown") === null || $.cookie("MLeavePopUpShown")===""))
             {
                MLeavePopUp.css("display", "block");
                if(RepeatAfterDays !== 0)
                {
                    $.cookie('MLeavePopUpShown', '1', { expires: RepeatAfterDays, path: '/'});
                }
             }
        }
    });
}
*/
function IsMobileDevice()
{
    var isMobile = /iPhone|iPad|iPod|Android/i.test(navigator.userAgent);
    if (isMobile) {
        return true;
    }
    return false;
}
function validateLivePage(evt) {
	  var theEvent = evt || window.event;
	  var key = theEvent.keyCode || theEvent.which;
	  key = String.fromCharCode( key );
	  var regex = /[0-9]|\./;
	  if( !regex.test(key) ) {
	    theEvent.returnValue = false;
	    if(theEvent.preventDefault) theEvent.preventDefault();
	  }
	}		
function Checklivepage()
	{
		if(document.LivePage.Email.value!="")
		{
			ok = 0
			  email = document.LivePage.Email.value
			  for (i=0; i<email.length; i++)
			   {
			    	ch = email.substring(i,i+1)
			   		 if (ch == "@" && i!=0 && i!=email.length-1) 
					 {
			     		 ok = 1
			    	 }
			   		 if((ch>="?" && ch<="?")) {
			     		 ok = 0
			     	 break
			    	}
			  }
			 		 if(ok == 0)
			  		 {  
						document.LivePage.Email.style.borderColor   = "#ff4242"						
						document.LivePage.Email.focus();
						return false;
			 		 } 
					 else
					 {
						document.LivePage.Email.style.borderColor        = "#cccccc"
					 }
			 					
		}
		
		if(document.LivePage.TPhone.value!="")
		{					
				if (document.LivePage.TPhone.value=="" || document.LivePage.TPhone.value.length < 7) 
				{																															
					document.LivePage.TPhone.style.borderColor   = "#ff4242"						
					document.LivePage.TPhone.focus();
					return false;									
				}	
				else
				{							
					document.LivePage.TPhone.style.borderColor        = "#cccccc"						
				}	
	   }
	   
	   if(document.LivePage.TPhone.value=="" && document.LivePage.Email.value=="")
	   {
	   		document.getElementById("Alert_Message").innerHTML = '<table><tr><td height="25" valign="middle" class="Text12" style="color:red;font-size:15PX;padding-right:5PX;padding-left:5PX;" dir="rtl">נא להזין איימל או טלפון נייד</td></tr></table>';						
			document.LivePage.TPhone.focus();
			return false;	
	   }
	   else
	   {
	   	document.getElementById("Alert_Message").innerHTML = '';
	   }
		   if(document.LivePage.TPhone.value != "")
			{
				Prefix  = document.LivePage.Prefix.value;
				TPhone  = document.LivePage.TPhone.value;
				TUrl = "https://www.hotel4u.co.il/SendmobileToClub.asp?TMobile="+Prefix+TPhone+""
				postR(TUrl,'Alert_Message','0')
			}	
			if(document.LivePage.Email.value != "")
			{
					 ClubEmail = document.LivePage.Email.value;
					 mailformat = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;  
					if(ClubEmail.match(mailformat))  
					{  
						TUrl = "https://www.hotel4u.co.il/SendEmailToClub.asp?Email="+ClubEmail+""
						postR(TUrl,'Alert_Message','0')						
					}  				  																
				
			}
			
			 if((document.LivePage.TPhone.value != "") || (document.LivePage.Email.value != ""))
			 {
			 		document.getElementById('content-right').innerHTML = '<br><br><br><div align=center><h1 style="color:red;padding-top:5px;">ההרשמה בוצעה בהצלחה</h1></div>';
			 		var t = setTimeout("MLeavePopUp.css('display', 'none');",1800);
			 }
		   																			
		}