﻿/// <reference name="MicrosoftAjax.js" />
/// <reference path="~/js/jquery/jquery-1.4.2.js" />

/*************** Netwaiter Javascript functions ****************************
 * All Popup windows must be opened directly from JavaScript - no asp.net
 * event handlers - to ensure that they don't set off Popup blockers.
 ***************************************************************************/

 function orderIsPlaced( isOrdered )
{
    if( isOrdered == 'True' )
    {    
        alert('This order has already been placed!');
        window.location='ThankYou.aspx';
    }
    else if( isOrdered == 'False' )
        return;
}

function disableButton( theButton )
{
	var button = document.getElementById( theButton );
	button.disabled = true;
}

/* registeredTrademark - ouptuts the registered or trademark symbol
 *no parameters
 */
function registeredTrademark()
{	//&#0153 for TM
	//&#0174 for R with the circle around it
	document.write('<sup>&#0174;</sup>');
}

/* netwaiterLogo - outputs the netwaiter logo */
function netwaiterLogo()
{
	document.write("<b><i><span class=\"BigNWLogo\">N</span><span class=\"LittleNWLogo\">ET</span><span class=\"BigNWLogo\">W</span><span class=\"LittleNWLogo\">AITER<font size=3><script language=\"javascript\">registeredTrademark();</script></font></span></i></b>");
}

/* smNetwaiterLogo - outputs the netwaiter logo only smaller*/
function smNetwaiterLogo()
{
	document.write("<b><i><span class=\"BigNWLogoSm\">N</span><span class=\"LittleNWLogoSm\">ET</span><span class=\"BigNWLogoSm\">W</span><span class=\"LittleNWLogoSm\">AITER<font size=1><script language=\"javascript\">registeredTrademark();</script></font></span></i></b>");
}

function netwaiterLogoNoTrademark()
{
	document.write("<b><i><span class=\"BigNWLogo\">N</span><span class=\"LittleNWLogo\">ET</span><span class=\"BigNWLogo\">W</span><span class=\"LittleNWLogo\">AITER</span></i></b>");
}

function disableButton( form, id )
{
	document.form.id.disabled = true;
}

/* setFocus is used to automatically change the focus from one text control
 * to another. This is useful, for instance, in the case of 4-box cc entry
 * or 3-box phone entry
 * 
 * id: the id of the control that will recieve focus
 * input: a reference to the current text box
 * keyCode: the last key pressed
 * len: if the text in input exceeds len, change the focus to id.
 */
function setFocus( id, input, keyCode, len )
{
	//do not set focus if the key is a tab, shift, arrow key, etc.		
	if ((keyCode < 32) ||
		(keyCode >= 37 && keyCode <= 40))
	{
		return;
	}
	
	else if( input.value.length == len && id != input.id )
	{
		var textbox = document.getElementById(id);
		textbox.focus();
		textbox.select();
	}
}

function SelectAll(input)
{
	input.select();
}

/* validateCC uses the Luhn Algorithm to make sure the user has entered
 * a valid Credit Card Number.
 * TODO(V2): Fill this in, and link it to the Credit-Card validators to get client-side
 *			 validation.
 */
function validateCC(ccNum)
{
	return false;
}

/* CurrentTime: returns the current time */
function CurrentTime()
{
	var today = new Date();
	return today.toLocaleTimeString();
}

/*
ValidatePhone returns true if the phone number is valid, false otherwise
Since phone number is split across 3 text boxes, we must check each of them

params:
"Source" is an HTMLSpanElement
*/
function ValidatePhone(source, args)
{
	//assume that the phone boxes all have the same name except for a trailing number	
	var id1 = source.getAttribute("ControlToValidate");
	id1 = id1.slice(0, id1.length-1) + "1";
	
	var id2 = id1.slice(0, id1.length-1) + "2";
	var id3 = id1.slice(0, id1.length-1) + "3";
	
	var box1 = document.getElementById(id1);
	var box2 = document.getElementById(id2);
	var box3 = document.getElementById(id3);

	//test regular expressions here	
	if (box1 && box2 && box3)
	{
		var regEx1 = new RegExp(/^\d{3}$/);
		var matches1 = regEx1.exec(box1.value);
		
		var regEx2 = new RegExp(/^\d{3}$/);
		var matches2 = regEx2.exec(box2.value);
		
		var regEx3 = new RegExp(/^\d{4}$/);
		var matches3 = regEx3.exec(box3.value);
		
		return (matches1 != null && matches1[0] == box1.value &&
						matches2 != null && matches2[0] == box2.value &&
						matches3 != null && matches3[0] == box3.value);
	}

	result = false;
}

function Postback()
{
	__doPostBack('', '');
}

function TogglePortions(itemKey) {
    $('#Item' + itemKey + 'Portions').slideToggle('normal');
}

function ToggleIngredients(itemKey) {
    $('#Ingredients_' + itemKey).slideToggle('normal');
}

function HighlightPortions(itemKey) {
    var OriginalBackgroundColor = $('.container').css('background-color');
    $('.PortionCell_' + itemKey).css('background-color', '#ffff99');
    $('.PortionCell_' + itemKey).animate({ backgroundColor: OriginalBackgroundColor }, 1000)    
}

function GetWindowHeight() {
    return $(window).height();
}

function GetWindowWidth() {
    return $(window).width();
}

function HighlightPopularItems() {
    $('#divMostPopularItems').slideDown(2000, function() {
        var OriginalBackgroundColor = $('.container').css('background-color');
        $('#divMostPopularItems').css('background-color', '#FFFF33');
        $('#divMostPopularItems').animate({ backgroundColor: OriginalBackgroundColor }, 5000)
    });
}

function ShowPopularItems() {
    $('#divMostPopularItems').show();
}

function HighlightAddons() {
    $('[id$=divAddon]').slideDown(2000, function() {
        var OriginalBackgroundColor = $('.container').css('background-color');
        $('[id$=divAddon]').css('background-color', '#FFFF33');
        $('[id$=divAddon]').animate({ backgroundColor: OriginalBackgroundColor }, 5000);    
    });
}

function IsThisYourRestaurantClick() {
    $('#ClaimRestaurantTextBox').slideDown(2000);
}