﻿// JScript File
var tempX;
var tempY;
var rid;
function showAddress(address, rName, ln) {
    var icon = new GIcon();
    icon.image = "images/MapCross.png";
    icon.iconSize = new GSize(40, 20);
    icon.shadowSize = new GSize(37, 34);
    icon.infoWindowAnchor = new GPoint(25, 0);
    icon.iconAnchor = new GPoint(25, 15);
    
    var geocoder = new GClientGeocoder();
  geocoder.getLatLng(
    address,
    function(point) {
      if (!point) {
        var add = address.split(',');
        address = add[1] + ',' + add[2] + ',' + add[3];
        if(markFlag == 0){showAddress(address, rName, ln);}else{return false;}
        markFlag = 1;
      } else {
        map.setCenter(point, 11);
        strInfo = "<div style='width: 100%;'>" + rName + "<div class='ListText' style='width: 120px;'>" + address + "</div></div>";
        map.addOverlay(createMarker(point, icon, strInfo, ln));
      }
    }
  );
}

// Find element x,y location
function findPosition( oLink ) {
 var posX = null;
 var posY = null;
 if( oLink.offsetParent ) {
 for( posX = 0, posY = 0; oLink.offsetParent; oLink = oLink.offsetParent ) {
 posX += oLink.offsetLeft;
 posY += oLink.offsetTop;
 }
return [ posX, posY ];
 } else {
 posX = oLink.x;
 posY = oLink.y;
 return [ posX, posY ];
 }
}

function createMarker(point, icon, info, ln) {
    var marker = new GMarker(point, icon);
    GEvent.addListener(marker, "mouseover", function() {
        var tlcLatLng = map.fromContainerPixelToLatLng(new GPoint(0,0), true);
        var tlcDivPixel = map.fromLatLngToDivPixel(tlcLatLng);
        var pointDivPixel = map.fromLatLngToDivPixel(this.getPoint());
        var c = new GPoint(pointDivPixel.x-tlcDivPixel.x, pointDivPixel.y-tlcDivPixel.y);
        var bb = map.getBounds();
        var mapPos = findPosition(map.getContainer());
        var tipLeft = c.x - this.getIcon().iconAnchor.x + mapPos[0];
        var tipTop = c.y - this.getIcon().iconAnchor.y + mapPos[1];
        showWindow(tipLeft, tipTop, info);
    });
    GEvent.addListener(marker, "click", function() {
        window.location = ln;
    });
    GEvent.addListener(marker, "mouseout", function() {
        var elem = document.getElementById('divRestMapDetail');
        elem.style.display = "none";
    });
    return marker;
}

function showWindow(x, y, info)
{
    var elem = document.getElementById('divRestMapDetail');
    elem.style.zIndex = "2000";
    elem.innerHTML = info;
    elem.style.display = "block";
    //alert(x);
    var wt = elem.offsetWidth;
    if(wt > 800)
    {
        wt = 300;
        elem.style.width = "300px";
    }
    elem.style.left = x - wt + 20 + "px";
    //alert(elem.style.left);
    elem.style.top = y - elem.offsetHeight + "px";
}

//Script for normal pages
function toggleFullCat(e)
{
    var elem = document.getElementById('divFullCat');
    var elmName = elem.id;
    if(elem.style.display == 'block')
        elem.style.display = 'none';
    else
    {
        getMouseXY(e);
        elem.style.left = tempX + 80 + 'px';
        elem.style.top = tempY - 360 + 'px';
        elem.style.display = 'block';
    }
}
function swapImg(elm, action)
{
    var strSrc = elm.src.split('.');
    if(action == 'over')
        elm.src = strSrc[0] + "Over.gif";
    else
        elm.src = strSrc[0].replace('Over', '') + ".gif";
}
function checkEnterd(e)
{
    if(e.keyCode == 13 || e.which == 13)
        goPage();
}

function goPage()
{
    if(document.getElementById('txtLocation').value > '')
    {
        if(document.getElementById('txtWhat').value > '')
            window.location = "CitySearch.aspx?l="+ document.getElementById('txtLocation').value + "&w=" + document.getElementById('txtWhat').value;
        else
            window.location = "CitySearch.aspx?l="+ document.getElementById('txtLocation').value;
    }
    else
        alert("Please type enter a location");
}    
//End of script for normal pages
function rptClosed(id, e)
{
    var divHTML = "<div id='divRevClose' style='position: absolute; z-index: 1000; left: 0px; top: 0px; display: none; border: 1px #CCCCCC solid;'>"+
                    "<table style='width: 100%; height: 100%; background-image: url(images/Send2PhoneBack.gif); background-repeat: repeat-x; padding-right: 5px; padding-left: 5px; padding-bottom: 5px; z-index: 100; border: gray 1px solid; display: block;'>"+
                        "<tr>"+
                            "<td colspan='3'>"+
                                "<div style='width: 100%; text-align: right; cursor: hand; cursor: pointer;'>"+
                                    "<a href='javascript:hideClose()' class='s1'><img src='images/CloseIcon.png' title='Close' style='border: 0px; cursor: hand; cursor: pointer; width: 16px; height: 16px;'/></a>"+
                                "</div>"+
                            "</td>"+
                        "</tr>"+
                        "<tr>"+
                            "<td align='center' colspan='3'>"+
                                "<div id='divClHead' class='ListText' style='width: 95%; vertical-align: middle; display: block; text-align: center; background-color: #FEE7C2;"+
                                    "border: 1px solid #D2B47A;'>"+
                                    "Please enter your email address."+
                                "</div>"+
                            "</td>"+
                        "</tr>"+
                        "<tr>"+
                            "<td style='font-family: Verdana; font-size: 12px; color: #555555;'>Email address:</td>"+
                            "<td style='text-align: left;'>"+
                                "<input type='text' id='txtCEmail' size='28' maxlength='100' />"+
                            "</td>"+
                        "</tr>"+
                        "<tr>"+
                            "<td colspan='2' align='center'>"+
                                "<input id='btnClose' type='button' value='Submit' onclick='chkClose("+id+");' />"+
                                "<input type='hidden' id='hidCLID' value='' />"+
                            "</td>"+
                        "</tr>"+
                    "</table>"+
                  "</div>";
    document.getElementById('divTempHTML').innerHTML = divHTML;
    getMouseXY(e);
    document.getElementById('divClHead').innerHTML = "Please enter your email address.";
    var elm = document.getElementById('divRevClose');
    if(navigator.appVersion.indexOf("MSIE")!=-1)
    {
        elm.style.zIndex = 1000;
        elm.style.left = tempX;
        elm.style.top = tempY-100;
        $("div#divRevClose").animate({height: 'toggle', opacity: 'show'}, "slow");
    }
    else
    {
        tempY = tempY - 100;
        elm.style.left = tempX;
        elm.style.top = tempY;
        $("div#divRevClose").animate({left: tempX, top: tempY, height: 'toggle', opacity: 'show'}, "slow");
    }
}

function getMouseXY(e) {
  if (document.all) { // grab the x-y pos.s if browser is IE    
    tempX = event.clientX + document.documentElement.scrollLeft
    tempY = event.clientY + document.documentElement.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  return true
}

function chkClose(id)
{
    var strEm = document.getElementById('txtCEmail');
    var AbHead = document.getElementById('divClHead');
    var match = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(strEm.value);
    if(!match)
    {
        strEm.focus();
        AbHead.style.display = "block";
        AbHead.innerHTML = "Enter a valid email address";
        return false;
    }
    else
    {
        reportClosed(id, strEm.value);
        AbHead.innerHTML = "Thank you for reporting. We will review your request.";
        setTimeout("hideClose()", 1500);
    }
}

function hideClose()
{
    if(document.getElementById('divRevClose').style.display == "block")
        $("div#divRevClose").animate({height: 'toggle', opacity: 'hide'}, "slow");
}

function reportClosed(id, em)
{
    //alert(id + " " + em);
    var strR = "";
    $.ajax({
       type: "POST",
       url: "ap/RevAb.aspx?ac=2",
       data: "r=" + id + "&e=" + em,
       success: function(msg){
         if(msg != "EXISTS")
         {
            return 1;
         }
         else
         {
            return -1;
         }
       }
     });
}

function sendToPhone(id, e)
{
    var strHTML = "<div style='width: 100%; color: #555555; border-bottom: 1px solid #CCCCCC; font-family: Verdana; font-size: 14px;'>" +
                    "<table style='width: 100%;'>" +
                        "<tr>" +
                            "<td align='left' style='width: 90%; color: #932623;'><b>Text to Mobile</b></td>" +
                            "<td align='right' style='width: 10%;'><img src='images/CloseIcon.png' title='Close' style='cursor: hand; cursor: pointer; width: 16px; height: 16px;' onclick='closeS2Phone();' /></td>" +
                        "</tr>" +
                    "</table>" +
                    "</div>" +
                    "<div id='divSContent'>" +
                        "<table style='width: 100%; color: #555555; font-family: Verdana; font-size: 11px; border: 1px solid #CCCCCC;'>" +
                            "<tr>" +
                                "<td align='center' colspan='2'>" +
                                    "<div id='divStat' style='border: 1px solid rgb(210, 180, 122); width: 95%; vertical-align: middle; display: none; text-align: center; background-color: rgb(254, 231, 194); padding: 5px;' class='ListText'></div>" +
                                "</td>" +
                            "</tr>" +
                            "<tr>" +
                                "<td>Phone Number <span style='color: Red;'>*</span></td>" +
                                "<td><input id='txtSPhone' maxlength='50' /></td>" +
                            "</tr>" +
                            "<tr>" +
                                "<td colspan='2' style='border: 1px solid #555555;'>" +
                                    "<div id='divSend' style='width: 95%; padding: 5px; margin: 5px;'></div>" +
                                "</td>" +
                            "</tr>" +
                            "<tr>" +
                                "<td colspan='2'>" +
                                    "<input id='chkSend' type='checkbox' /> I accept to the <a href='javascript:showTerms();'>terms and conditions</a> for sending the text message." +
                                    "<div id='divTerms' style='text-align: left; display: none; padding: 10px; border: 1px solid #CCCCCC;'>DiningAid.com does not charge for this service but standard Mobile Carrier rates may apply. " +
                                        "All information gathered on this site is strictly confidential and will not be shared with outside sources without your consent.</div>"+
                                "</td>" +
                            "</tr>" +
                            "<tr>" +
                                "<td align='center' colspan='2'><input type='button' id='btnSend' value='Send' onclick='procSend();' /></td>" +
                            "</tr>" +
                        "</table>" +
                    "</div>";
    document.getElementById('divS2Phone').innerHTML = strHTML;
    rid= id;
    var rName;
    var rAdd;
    var rPhone;
    if(document.getElementById("divAddress"))
    {
        document.getElementById('divSend').style.textAlign = 'left';
        rName = "<b>" + document.getElementById("divRestaurantName").innerHTML + "</b>";
        rAdd = document.getElementById("divAddress").innerHTML;
        rPhone = "";
    }
    else
    {
        rName = document.getElementById("ln" + id).innerHTML.split('.')[1];
        rAdd = document.getElementById("divAd" + id).innerHTML;
        rPhone = document.getElementById("spnP" + id).innerHTML;
    }
    document.getElementById('divSend').innerHTML = rName + "<br>" + rAdd + "<br>" + rPhone;
    
    getMouseXY(e);
    var elem = document.getElementById('divS2Phone');
    var elmName = elem.id;
    elem.style.left = tempX - 200 + 'px';
    elem.style.top = tempY - 200 + 'px';
    $("div#divS2Phone").animate({height: 'toggle', opacity: 'show'}, "slow");
}

function closeS2Phone()
{$('div#divS2Phone').animate({height: 'toggle', opacity: 'hide'}, 'slow');}

function showTerms()
{document.getElementById('divTerms').style.display = "block";}

function procSend()
{
    var id = rid;
    if(id > "")
    {
    //var strEm = document.getElementById('txtSEmail');
    var AbHead = document.getElementById('divStat');
    AbHead.style.display = "none";
//    if(!checkEmail(strEm.value))
//    {
//        strEm.focus();
//        AbHead.style.display = "block";
//        AbHead.innerHTML = "Enter a valid email address";
//        return false;
//    }
//    else
    {
        var rPhone = document.getElementById('txtSPhone').value;
        //if(rName != "")
            if(rPhone != "")
            {
                var match = /^([0-9]{10})$/.test(rPhone);
                if(!match)
                {
                    document.getElementById('txtSPhone').focus();
                    AbHead.style.display = "block";
                    AbHead.innerHTML = "Please enter a valid phone number, ex: 3101233124";
                }
                else
                {
                    if(document.getElementById('chkSend').checked)
                    {
                        var sendChr = "r=" + id + "&p=" + rPhone + "&n= ";// + "&e=" + strEm.value;
                        document.getElementById('divSend').style.textAlign = 'center';
                        document.getElementById('divSend').innerHTML = "<img src='images/progress.gif' />";
                        $.ajax({
                           type: "POST",
                           url: "ap/S2Phone.aspx?ac=1",
                           data: sendChr,
                           success: function(msg){
                                if(msg == "Success")
                                {
                                 AbHead.style.display = "block";
                                 document.getElementById('divSend').innerHTML = "";
                                 AbHead.innerHTML = "Thank you for using this service. You will receive the message shortly.";
                                 setTimeout("$('div#divS2Phone').animate({height: 'toggle', opacity: 'hide'}, 'slow');", 5000);
                                }
                                else
                                    document.getElementById('divSend').innerHTML = "There was an error in sending the message. Please try again later";
                           }
                         });
                     }
                     else
                     {
                        document.getElementById('chkSend').focus();
                        AbHead.style.display = "block";
                        AbHead.innerHTML = "Inorder to use this service you have to accept to the terms and conditions.";
                     }
                }
            }
            else
            {
                AbHead.style.display = "block";
                AbHead.innerHTML = "Please enter your Phone number";
                document.getElementById('txtSPhone').focus();
            }
//        else
//        {
//            AbHead.style.display = "block";
//            AbHead.innerHTML = "Please enter your Name";
//            document.getElementById('txtSName').focus();
//        }
    }
   }
}


function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

function emailFriend(id, e)
{
 var strHTML = "<div style='width: 100%; color: #555555; border-bottom: 1px solid #CCCCCC; font-family: Verdana; font-size: 14px;'>" +
                    "<table style='width: 100%;'>" +
                        "<tr>" +
                            "<td align='left' style='width: 90%; color: #932623;'><b>Tell a friend</b></td>" +
                            "<td align='right' style='width: 10%;'><img src='images/CloseIcon.png' title='Close' style='cursor: hand; cursor: pointer; width: 16px; height: 16px;' onclick='closeS2Phone();' /></td>" +
                        "</tr>" +
                    "</table>" +
                    "</div>" +
                    "<div id='divSContent'>" +
                        "<table style='width: 100%; color: #555555; font-family: Verdana; font-size: 11px; border: 1px solid #CCCCCC;'>" +
                            "<tr>" +
                                "<td align='center' colspan='2'>" +
                                    "<div id='divStat' style='border: 1px solid rgb(210, 180, 122); width: 95%; vertical-align: middle; display: none; text-align: center; background-color: rgb(254, 231, 194);' class='ListText'></div>" +
                                "</td>" +
                            "</tr>" +
                            "<tr>" +
                                "<td>Your Name <span style='color: Red;'>*</span></td>" +
                                "<td><input id='txtSName' maxlength='50' /></td>" +
                            "</tr>" +
                            "<tr>" +
                                "<td>Recipient's Email <span style='color: Red;'>*</span></td>" +
                                "<td><input id='txtTEmail' maxlength='50' /></td>" +
                            "</tr>" +
                            "<tr>" +
                                "<td>Recipient's Name <span style='color: Red;'>*</span></td>" +
                                "<td><input id='txtTName' maxlength='50' /></td>" +
                            "</tr>" +
                            "<tr>" +
                                "<td colspan='2'>" +
                                    "<div id='divSend' style='width: 95%; padding: 5px; margin: 5px;'></div>" +
                                "</td>" +
                            "</tr>" +
                            "<tr>" +
                                "<td colspan='2'>" +
                                    "<input id='chkSend' type='checkbox' checked='checked' /> I accept the <a href='terms.aspx#sendtophone'>terms</a> for sending the text message." +
                                "</td>" +
                            "</tr>" +
                            "<tr>" +
                                "<td align='center' colspan='2'><input type='button' id='btnSend' value='Send' onclick='procESend();' /></td>" +
                            "</tr>" +
                        "</table>" +
                    "</div>";
    document.getElementById('divS2Phone').innerHTML = strHTML;   
    rid= id;
    var rSName;
    var rTName;
    var rTEmail;
    
    getMouseXY(e);
    var elem = document.getElementById('divS2Phone');
    var elmName = elem.id;
    elem.style.left = tempX - 200 + 'px';
    elem.style.top = tempY - 200 + 'px';
    $("div#divS2Phone").animate({height: 'toggle', opacity: 'show'}, "slow");
}

function procESend()
{
    var id = rid;
    if(id > "")
    {
    var strTEm = document.getElementById('txtTEmail');
    var AbHead = document.getElementById('divStat');
    AbHead.style.display = "none";
    
        
    if(!checkEmail(strTEm.value))
    {
        strTEm.focus();
        AbHead.style.display = "block";
        AbHead.innerHTML = "Enter a valid email address";
        return false;
    }
    else
    {
        var rName = document.getElementById('txtSName').value;
        var tName = document.getElementById('txtTName').value;
        if(rName != "")
        {
            if(tName != "")
            {
                if(document.getElementById('chkSend').checked)
                {
                    var sendChr = "r=" + id + "&tn=" + tName + "&n=" + rName + "&e=" + strTEm.value;
                    document.getElementById('divSend').style.textAlign = 'center';
                    document.getElementById('divSend').innerHTML = "<img src='images/progress.gif' />";
                    $.ajax({
                       type: "POST",
                       url: "ap/S2Phone.aspx?ac=2",
                       data: sendChr,
                       success: function(msg){
                            if(msg == "Success")
                            {
                             AbHead.style.display = "block";
                             document.getElementById('divSend').innerHTML = "";
                             AbHead.innerHTML = "Thank you for using this service. Your email has been sent successfully.";
                             setTimeout("$('div#divS2Phone').animate({height: 'toggle', opacity: 'hide'}, 'slow');", 5000);
                            }
                            else
                                document.getElementById('divSend').innerHTML = "There was an error in sending the email. Please try again later";
                       }
                     });
                 }
                 else
                 {
                    document.getElementById('chkSend').focus();
                    AbHead.style.display = "block";
                    AbHead.innerHTML = "Inorder to use this service you have to accept to the terms and conditions.";
                 }
            }
            else
            {
                AbHead.style.display = "block";
                AbHead.innerHTML = "Please enter recipient's name";
                document.getElementById('txtTName').focus();
            }
        }
        else
        {
            AbHead.style.display = "block";
            AbHead.innerHTML = "Please enter your Name";
            document.getElementById('txtSName').focus();
        }
    }
   }
}

function checkEmail(strEmail)
{
    var match = /^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/.test(strEmail);
    if(!match)
    {        
        return false;
    }
    else
        return true;
}