﻿function doPopup(theURL, theWinName, theLeft, theTop, theWidth, theHeight, theresize, thescrollbars, thestatusbar, themenu, thetools, thelocationbar, thedirs) {
	// EXAMPLE doPopup('popup.asp', 'popwin', 10, 10, 500, 300, 'no', 'no', 'yes', 'no', 'no', 'no', 'no')
	// USE theLeft AND theTop = -1 FOR AUTO-CENTER

	if (theLeft == -1 && theTop == -1) {
		theLeft = (screen.width - theWidth) / 2;
		theTop = (screen.height - theHeight) / 2;
	}
	var paramstr;
	paramstr = "width=" + theWidth + "px,height=" + theHeight + "px,left=" + theLeft + "px,top=" + theTop + "px,resizable=" + theresize + ",scrollbars=" + thescrollbars + ",status=" + thestatusbar + ",menubar=" + themenu + ",toolbar=" + thetools + ",location=" + thelocationbar + ",directories=" + thedirs;
	window.open(theURL, theWinName, paramstr);
}

function changeSelectedBox(obj){
	var parentDiv = obj.parentNode.parentNode;
	if(obj.checked){
		parentDiv.className = "greyLineSelected";
		
	} else {
		parentDiv.className = "greyLine";
	}
}
function fireEvent(){
    var fireOnThis = document.getElementById(document.getElementById("thickboxId").value);
    var evt="click";
    if (document.all)
	   alert("insdeMoz");
	else
	{
	    //alert("insdeMoz");
	    if( document.createEvent ) {
	    var evObj = document.createEvent('MouseEvents');
	    evObj.initEvent( evt, true, false );
	    fireOnThis.dispatchEvent(evObj);
	    } else if( document.createEventObject ) {
	    fireOnThis.fireEvent('on'+evt);
	    }
	}
	
}
function getThickValue()
{
    return 
}

function updateClock ( )
{
	var currentTime = new Date ( );

	var currentHours = currentTime.getHours ( );
	var currentMinutes = currentTime.getMinutes ( );
	var currentSeconds = currentTime.getSeconds ( );
	//var StrBreakfast = "<strong>breakfast</strong>";
	//var StrLunch = "<strong>lunch</strong>";
	//var StrDinner = "<strong>dinner</strong>";
	
//	var TheMeal = document.getElementById("StrClockMeal");
	//if (currentHours >= 23 && currentHours < 10)
	//{
	//	TheMeal.innerHTML = StrBreakfast;
	//}
	//else if (currentHours >= 10 && currentHours < 15)
	//{
	//	TheMeal.innerHTML = StrLunch;
	//}
	//else
	//{
	//	TheMeal.innerHTML = StrDinner;
	//}

	currentMinutes = ( currentMinutes < 10 ? "0" : "" ) + currentMinutes;
	currentSeconds = ( currentSeconds < 10 ? "0" : "" ) + currentSeconds;
	var timeOfDay = ( currentHours < 12 ) ? "AM" : "PM";
	//currentHours = ( currentHours > 12 ) ? currentHours - 12 : currentHours;
	currentHours = ( currentHours == 0 ) ? 12 : currentHours;
	//var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds + " " + timeOfDay;
	var currentTimeString = currentHours + ":" + currentMinutes + ":" + currentSeconds;
	document.getElementById("StrClock").firstChild.nodeValue = currentTimeString;
	document.getElementById("EntireClock").style.visibility = "visible";
}

var MapIsExpanded = false;
function ToggleMap()
{
	
	var TheRestaurantMap = document.getElementById("map_canvas");
	if (TheRestaurantMap && MapIsExpanded == false)
	{
		TheRestaurantMap.style.height = "500px";
		MapIsExpanded = true;
		return;
	}
	
	if (TheRestaurantMap && MapIsExpanded == true)
	{
		TheRestaurantMap.style.height = "137px";
		MapIsExpanded = false;
		return;
	}

}
//Rating texts
var rateTexts = new Array();
    rateTexts[0] = 'terrible';
    rateTexts[1] = 'average';
    rateTexts[2] = 'good';
    rateTexts[3] = 'very good';
    rateTexts[4] = 'excellent';

var d;
var h;
var l;
var unit = 43.65;
//fill the appropraite boxes accroding to mouse coords
function setRating(evnt) {
    var evnt = (!evnt) ? window.event : evnt; // The mousemove event
    getMouseXY(evnt);
    if (ismouseover) {

        var initial_x = findPosX(d);

        var slidex = (tempX - initial_x);
        if (slidex > 217) { slidex = 217; }

        if (parseFloat(slidex) < unit)
        {
            l.innerHTML = rateTexts[0];
            d.style.width = unit + 'px';
            }
        else if (parseFloat(slidex) < (unit + unit ))
        {
            l.innerHTML = rateTexts[1];
            d.style.width = Math.round(unit + unit) + 'px';
            }
        else if (parseFloat(slidex) < (2 * unit + unit ))
        {
            l.innerHTML = rateTexts[2];
            d.style.width = Math.round(2 * unit + unit) + 'px';
            }
        else if (parseFloat(slidex) < (3 * unit + unit ))
        {
            l.innerHTML =  rateTexts[3];
            d.style.width = Math.round(3 * unit + unit) + 'px';
            }
        else if (parseFloat(slidex) < (4 * unit + unit ))
        {
            l.innerHTML =  rateTexts[4];
            d.style.width = Math.round(4 * unit + unit) + 'px';
            }
        else
        {
            l.innerHTML =  rateTexts[5];
            d.style.width = Math.round(5 * unit ) + 'px';
        }

        h.value = slidex;
        return false
    }
    return   
}

function getMouseXY(e) {

    if (IE) { // grab the x-y pos.s if browser is IE
        tempX = event.clientX + document.body.scrollLeft;
        tempY = event.clientY + document.body.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;
}

var ismouseover = false;

// moveSlider: Handles the start of a slider move.
function slide(evnt, div_id, hdn_id, ltl_id) {
    if (!evnt) evnt = window.event;

    ismouseover = true;
    d = document.getElementById(div_id);
    h = document.getElementById(hdn_id);
    l = document.getElementById(ltl_id);
    setRating(evnt);

    document.onmousemove = setRating;   // Start the action if the mouse is dragged.
    document.onmouseup = slideMouseUp;  // Stop sliding.
}
// sliderMouseup: Handles the mouseup event after moving a slider.
// Snaps the slider position to allowed/displayed value. 
function slideMouseUp() {

    if (h != null) {
        var slidex = h.value;
        var currentWidth = d.style.width;
        var current_x = parseInt(currentWidth.replace("px", ""));
        //alert(current_x);
        //alert(h.value);
        
        // oldest versions of mozilla are supposed to use different eventRemoveEventListener function so try.. catch
        try {
            ismouseover = false;  // Stop the sliding.


            if (parseInt(h.value) < unit ) {
                d.style.width = unit + 'px';
                h.value = '1';
                //setTimeout('hideText(l)', 200);
            }
            else if (parseInt(h.value) < (unit + unit)) {
                d.style.width = Math.round(unit + unit) + 'px';
                h.value = '2';
                //setTimeout('hideText(l)', 200);
            }
            else if (parseInt(h.value) < (2 * unit + unit)) {
                d.style.width = Math.round(2 * unit + unit) + 'px';
                h.value = '3';
                //setTimeout('hideText(l)', 200);
            }
            else if (parseInt(h.value) < (3 * unit + unit)) {
                //setTimeout('hideText(l)', 200);
                h.value = '4';
                d.style.width = Math.round(3 * unit + unit) + 'px';
            }
            else if (parseInt(h.value) < (4 * unit + unit)) {
                d.style.width = Math.round(4 * unit + unit) + 'px';
                h.value = '5';
                //setTimeout('hideText(l)', 200);
            }
            else {
                d.style.width = 217 + 'px';
                h.value = '5';
                //setTimeout('hideText(l)', 200);
            }           

            if (document.removeEventListener) { // Remove event listeners from 'document' (Moz&co).
                document.removeEventListener('mousemove', setRating,false);
                document.removeEventListener('mouseup', slideMouseUp,false);
            }
            else if (document.detachEvent) { // Remove event listeners from 'document' (IE&co).
                document.detachEvent('onmousemove', setRating);
                document.detachEvent('onmouseup', slideMouseUp);
            }

        }
        catch (err) {
            ismouseover = false;  // Stop the sliding.


            if (parseInt(h.value) < unit) {
                d.style.width = unit + 'px';
                h.value = '1';
                //setTimeout('hideText(l)', 200);
            }
            else if (parseInt(h.value) < (unit + unit)) {
                d.style.width = Math.round(unit + unit) + 'px';
                h.value = '2';
                //setTimeout('hideText(l)', 200);
            }
            else if (parseInt(h.value) < (2 * unit + unit)) {
                d.style.width = Math.round(2 * unit + unit) + 'px';
                h.value = '3';
                //setTimeout('hideText(l)', 200);
            }
            else if (parseInt(h.value) < (3 * unit + unit)) {
                //setTimeout('hideText(l)', 200);
                h.value = '4';
                d.style.width = Math.round(3 * unit + unit) + 'px';
            }
            else if (parseInt(h.value) < (4 * unit + unit)) {
                d.style.width = Math.round(4 * unit + unit) + 'px';
                h.value = '5';
                //setTimeout('hideText(l)', 200);
            }
            else {
                d.style.width = 217 + 'px';
                h.value = '5';
                //setTimeout('hideText(l)', 200);
            }



            if (document.removeEventListener) { // Remove event listeners from 'document' (Moz&co).
                document.removeEventListener('mousemove', setRating);
                document.removeEventListener('mouseup', slideMouseUp);
            }
            else if (document.detachEvent) { // Remove event listeners from 'document' (IE&co).
                document.detachEvent('onmousemove', setRating);
                document.detachEvent('onmouseup', slideMouseUp);
            }

        }

        d = null;
        h = null;
    }
    
}

// carpeGetElementByID: Cross-browser version of "document.getElementById()"
function carpeGetElementById(element) {
    if (document.getElementById) element = document.getElementById(element);
    else if (document.all) element = document.all[element];
    else element = null;
    return element;
}
// carpeLeft: Cross-browser version of "element.style.left"
function carpeLeft(elmnt, pos) {
    if (!(elmnt = carpeGetElementById(elmnt))) return 0;
    if (elmnt.style && (typeof (elmnt.style.left) == 'string')) {
        if (typeof (pos) == 'number') elmnt.style.left = pos + 'px';
        else {
            pos = parseInt(elmnt.style.left);
            if (isNaN(pos)) pos = 0;
        }
    }
    else if (elmnt.style && elmnt.style.pixelLeft) {
        if (typeof (pos) == 'number') elmnt.style.pixelLeft = pos;
        else pos = elmnt.style.pixelLeft;
    }
    return pos;
}
// carpeTop: Cross-browser version of "element.style.top"
function carpeTop(elmnt, pos) {
    if (!(elmnt = carpeGetElementById(elmnt))) return 0;
    if (elmnt.style && (typeof (elmnt.style.top) == 'string')) {
        if (typeof (pos) == 'number') elmnt.style.top = pos + 'px';
        else {
            pos = parseInt(elmnt.style.top);
            if (isNaN(pos)) pos = 0;
        }
    }
    else if (elmnt.style && elmnt.style.pixelTop) {
        if (typeof (pos) == 'number') elmnt.style.pixelTop = pos;
        else pos = elmnt.style.pixelTop;
    }
    return pos;
}


function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

var previousText='null';
function ShowInstructions(id) {
    if (previousText == 'null') {
        previousText = document.getElementById(id).innerHTML;
        document.getElementById(id).innerHTML = '>> click to rate';
    }
}

function hideText(object) {
    object.innerHTML = '';
    previousText = '';

}

function hideRateText(id) {
    document.getElementById(id).innerHTML = '';   
}


//the span element that contains the  '>> click to rate'; text
var clcikSpan;

function HideInstructions(id) {
    clcikSpan = document.getElementById(id);
    setTimeout('hideText(clcikSpan)', 2500)
}



