﻿// JScript File

var ShouldShowLeavePageWarning = true;

function CheckIfReservationTimeIsValid(strYear, strMonth, strDay, strHour, strMinutes){
        var r = new Date();
        r.setFullYear(strYear,strMonth-1,strDay);
        r.setHours(strHour,strMinutes,0,0);
        var now = new Date();
        
        if (r < now){
            //alert(ResourceManager.GetString("ReservationTimePassed"));
            return false;
        }
        else
            return true;
}

function ConfirmDelete(restaurantName, date){
        return confirm(ResourceManager.GetString("CancelReservationWarning",restaurantName, date)); 
}

function openSearchPopup(restaurantGuid){
            var newwindow = window.open("SearchPage.aspx?RestaurantId="+restaurantGuid+"&portal=ClickATable","SearchSeats", "height=477, width=750, scrollbars=yes, status=yes,resizable=yes, location=yes, top=50, left=100");
            if (window.focus) {newwindow.focus()}
}

function openSearchUpdatePopup(reservationID, ispopup){
        var url = "SearchPage.aspx?ReservationID={"+reservationID+"}";
        if (ispopup == null){ 
            var newwindow = window.open(url,"SearchSeats", "height=477, width=750, scrollbars=yes, status=yes,resizable=yes, location=yes, top=50, left=100");
            if (window.focus) {newwindow.focus()}
        }
        else{//is already a poup
            location.href=url;
        }
}

function openSearchCustomerUpdatePopup(reservationID, ispopup){
        var url = "SearchPage.aspx?ReservationID={"+reservationID+"}&q=1";
        if (ispopup == null){ 
            var newwindow = window.open(url,"SearchSeats", "height=477, width=750, scrollbars=yes, status=yes,resizable=yes, location=yes, top=50, left=100");
            if (window.focus) {newwindow.focus()}
        }
        else{//is already a poup
            location.href=url;
        }
}

function fixPopupSize(){
    var height;
    var winHeight = document.getElementById('winHeight');
    if(winHeight && winHeight.value != null)
    {
        height = winHeight.value;
    }
    else
    {
        height = 560;
    }

    var FFfactor = 0;
    if(navigator.userAgent.indexOf("Firefox")!=-1)
    {
        height = Number(height) + 5;
        FFfactor = 5
    }
    if (document.getElementById('divFrame'))
    {  
        document.getElementById('divFrame').style.height = height-232-FFfactor;            
    }

    window.resizeTo(780,(height*1)+30);
}

function getReservationIdFromQueryString()
{
    var url = location.href;
    url=url.toLowerCase();
    if (url.indexOf('reservationid=')>-1){
        var resid= url.substr(url.indexOf('reservationid=')+'reservationid='.length,36);
    }
    return resid;
}



//function Backward(oSpyID)
//{
//   // The hidden post-back spy or counter field
//   var spy = null;
//   // Total number of post-backs
//   var refreshes = new Number(0);
//   // Allows the actual previous page to be selected
//   var offset = new Number(1);

//   spy = document.getElementById(oSpyID);

//   refreshes = new Number(spy.value) + offset;
//               
//   history.go(-refreshes);
//   // Redirects to the actual previous page
//}
    
/************** ClientSide Resource Manager **************/
var ResourceManager = new RM();
function RM()
{
  this.list = new Array();
}
RM.prototype.AddString = function(key, value)
{
  this.list[key] = value;
}
RM.prototype.GetString = function(key)
{
  var result = this.list[key];  
  for (var i = 1; i < arguments.length; ++i)
  {
    result = result.replace("{" + (i-1) + "}", arguments[i]);
  }
  return result;
}
/********************************************************/
 function createCookie(name,value,days) {

	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function Maximize() 
{   if (document.documentElement.clientHeight<601)
    {
    
        window.resizeTo(800, 650);
    //    window.moveTo(0, 0);
    }
    else
    {
  //     var w=800;
  //      var h=800;
  //      var winl = (screen.width-w)/2;
  //      var wint = (screen.height-h)/2;
  //    window.resizeTo(w, h);
  //      window.moveTo(winl, wint);

    }
    alwaysLowered = false;
}


function AdjustPopup(){
//if (location.href.indexOf('RestaurantPage.aspx') > -1)
  if (window.opener != null)
      Maximize();
 
    var tdTopNav = document.getElementById('tdTopNav');
    if (tdTopNav){
        if (window.opener != null)
        {
            //tdTopNav.className = "header_links_short"
            if (document.referrer.indexOf('ReservationSummary.aspx') > -1)
                fixPopupSize();
            
        }
        else
        {
            tdTopNav.className = "header_links_long"
        }
    }
    RenderTopNavLinks();
}

function isEmail(string) 
{
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function CheckPhone(phone) 
{
  var mobile = new RegExp("^05[02457][0-9]{7}$");
  var bezeq = new RegExp("^0[23489][0-9]{7}$");
  var other = new RegExp("^07[2347][0-9]{7}$");
  if (phone.match(mobile) || phone.match(bezeq) || phone.match(other)) 
    return true;
    else
    return false;
}

/**
* DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*/
// Declaring valid date character, minimum year and maximum year

var dtCh = "/";
var minYear = 2000;
var maxYear = 2100;
var dateErrorMessage = "";

function isInteger(s) {
    var i;
    for (i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag) {
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++) {
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary(year) {
    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28);
}
function DaysArray(n) {
    for (var i = 1; i <= n; i++) {
        this[i] = 31
        if (i == 4 || i == 6 || i == 9 || i == 11) { this[i] = 30 }
        if (i == 2) { this[i] = 29 }
    }
    return this
}

function isDate(dtStr) {
    var daysInMonth = DaysArray(12)
    var pos1 = dtStr.indexOf(dtCh)
    var pos2 = dtStr.indexOf(dtCh, pos1 + 1)
    var strDay = dtStr.substring(0, pos1)
    var strMonth = dtStr.substring(pos1 + 1, pos2)
    var strYear = dtStr.substring(pos2 + 1)
    strYr = strYear
    if (strDay.charAt(0) == "0" && strDay.length > 1) strDay = strDay.substring(1)
    if (strMonth.charAt(0) == "0" && strMonth.length > 1) strMonth = strMonth.substring(1)
    for (var i = 1; i <= 3; i++) {
        if (strYr.charAt(0) == "0" && strYr.length > 1) strYr = strYr.substring(1)
    }
    month = parseInt(strMonth)
    day = parseInt(strDay)
    year = parseInt(strYr)
    if (pos1 == -1 || pos2 == -1) {
        dateErrorMessage = " אנא הכנס תאריך בפורמט יום חודש ושנה (dd/mm/yyyy)";
        return false
    }
    if (strMonth.length < 1 || month < 1 || month > 12) {
       dateErrorMessage="החודש שהוקלד אינו חוקי";
        return false
    }
    if (strDay.length < 1 || day < 1 || day > 31 || (month == 2 && day > daysInFebruary(year)) || day > daysInMonth[month]) {
       dateErrorMessage="היום שהוקלד אינו חוקי";
        return false
    }
    if (strYear.length != 4 || year == 0 || year < minYear || year > maxYear) {
       dateErrorMessage="יש להכניס שנה בת 4 ספרות בין " + minYear + " ל " + maxYear;
        return false
    }
    if (dtStr.indexOf(dtCh, pos2 + 1) != -1 || isInteger(stripCharsInBag(dtStr, dtCh)) == false) {
        dateErrorMessage="יש להזין תאריך חוקי";
        return false
    }
    return true
}

function RenderTopNavLinks() {
    if (window.opener != null) {
        RenderPopUpLinks();
        RenderFullScreenLinks();
    }
    else {
        RenderFullScreenLinks();
    }
}

function RenderPopUpLinks() {
    document.getElementById('navProfilePage').style.display = "inline";
    document.getElementById('sepProfilePage').style.display = "inline";
    document.getElementById('navFAQ').style.display = "inline";
    document.getElementById('sepFAQ').style.display = "inline";
    document.getElementById('navContactUs').style.display = "inline";
    RenderFullScreenLinks();
}

function RenderFullScreenLinks() {
    document.getElementById('navHomePage').style.display = "inline";
    document.getElementById('sepHomePage').style.display = "inline";
    document.getElementById('navProfilePage').style.display = "inline";
    document.getElementById('sepProfilePage').style.display = "inline";
    document.getElementById('navFAQ').style.display = "inline";
    document.getElementById('sepFAQ').style.display = "inline";
    document.getElementById('navRestaurateurs').style.display = "inline";
    document.getElementById('sepRestaurateurs').style.display = "inline"
    document.getElementById('navContactUs').style.display = "inline";
    document.getElementById('sepContactUs').style.display = "inline";
    document.getElementById('navAboutUs').style.display = "inline";

}

function FixAX(strSRC, w, h, type) {
    switch (type) {
        case "flash":
            {
                document.write("<OBJECT classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0 WIDTH=" + w + " HEIGHT=" + h + " id=searc>")
                document.write("<PARAM NAME=movie VALUE=" + strSRC)
                document.write("><PARAM NAME=quality VALUE=high><PARAM NAME=bgcolor VALUE=#FFFFFF><EMBED src=" + strSRC + " WIDTH=" + w + " HEIGHT=" + h + " NAME=searc ALIGN= TYPE=application/x-shockwave-flash PLUGINSPAGE=http://www.macromedia.com/go/getflashplayer></EMBED></OBJECT>")
            }
            break;
        case "tranflash":
            {
                document.write("<OBJECT classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000 codebase=http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0 WIDTH=" + w + " HEIGHT=" + h + " id=searc>")
                document.write("<PARAM NAME=movie VALUE=" + strSRC)
                document.write("><PARAM NAME=quality VALUE=high><param name=\"wmode\" value=\"transparent\" /><EMBED wmode=\"transparent\" src=" + strSRC + " WIDTH=" + w + " HEIGHT=" + h + " NAME=searc ALIGN= TYPE=application/x-shockwave-flash PLUGINSPAGE=http://www.macromedia.com/go/getflashplayer></EMBED></OBJECT>")
            }
            break;
    }
}
