//Preload Menu - Load all four image sets
var arrMenuImages_List      = new Array("menu", "catering", "giftcard", "LetsConnect", "funnews", "emplfran");
var iImageCnt               = 6         //arrMenuImages_List.length;
var iTempCnt                = 0;

var arrMenuImages_on        = new Array(iImageCnt);
var arrMenuImages_off       = new Array(iImageCnt);
var arrMenuImages_sel_on    = new Array(iImageCnt);
var arrMenuImages_sel_off   = new Array(iImageCnt);
var arrMenuImages_on_alt    = new Array("Menu, Locations & To Go","Catering","Gift Cards","Guest Feedback","Fun & News","Employment & Franchising"); //Added by Pinaki: CTS Bug/ Enhancement ID: IR_19095_MacaroniGrill_Website_Enhancements_v1.0.doc 

for (iTempCnt=0; iTempCnt<iImageCnt; iTempCnt++)
{
    arrMenuImages_sel_on[iTempCnt] = new Image();
    arrMenuImages_sel_on[iTempCnt].src = "../Images/NavMenu/" + arrMenuImages_List[iTempCnt] + "_sel_on.gif";
    
    arrMenuImages_sel_off[iTempCnt] = new Image();
    arrMenuImages_sel_off[iTempCnt].src = "../Images/NavMenu/" + arrMenuImages_List[iTempCnt] + "_sel_off.gif";
    
    arrMenuImages_on[iTempCnt] = new Image();
    arrMenuImages_on[iTempCnt].src = "../Images/NavMenu/" + arrMenuImages_List[iTempCnt] + "_on.gif";
    
    arrMenuImages_off[iTempCnt] = new Image();
    arrMenuImages_off[iTempCnt].src = "../Images/NavMenu/" + arrMenuImages_List[iTempCnt] + "_off.gif";
}


//Void function
function fnVoid(){}


	
//Trim the text
function fnTrim(p_sText)
{
	var regularExp;
	regularExp = /^( )+/g ;
	
	p_sText = String(p_sText);
	p_sText = p_sText.replace(regularExp,"");
	
	regularExp = /( )+$/g ;
	p_sText = p_sText.replace(regularExp,"");
	
	return p_sText;
}

//Show Terms & Privacy Policy
function fnShowPolicy()
{
	var oNewWindow = window.open("http://www.brinker.com/terms.asp", "TermsWindow", "width=600,height=400,left=100,top=100,scrollbars=yes,resizable=yes,location=no,menubar=no,status=no,toolbar=no");
	oNewWindow.focus();
}

//Check Field on Focus - If default text then clear the field
function fnCheckFocus(p_oField, p_sDefault)
{
	if(fnTrim(p_oField.value) == "" || fnTrim(p_oField.value.toUpperCase()) == p_sDefault.toUpperCase())
	{
		p_oField.value = "";
	}
}

//Check Field on Blur - If empty then fill with default text
function fnCheckBlur(p_oField, p_sDefault)
{
	if(fnTrim(p_oField.value) == "" || fnTrim(p_oField.value.toUpperCase()) == p_sDefault.toUpperCase())
	{
		p_oField.value = p_sDefault;
	}
}

//Set Selected Menu - Set Selected Image
function fnSetMenu()
{
	var l_sPath = escape(document.location);
	var l_sImageName
	var l_oImageNode
	var l_sRE
	
	if(l_sPath.indexOf("?") != -1)
	{
	    l_sPath = l_sPath.split("?")[0];
	}
    
    for (iTempCnt=0; iTempCnt<iImageCnt; iTempCnt++)
    {
        l_sRE = "" + arrMenuImages_List[iTempCnt] + "";
        
        if(l_sPath.match(RegExp(l_sRE, "ig")) != null)
        {
            if(l_sPath.match(RegExp(l_sRE, "ig")) != "")
            {
                l_sImageName = "_ctl0_oMenu_img_" + arrMenuImages_List[iTempCnt];
                l_oImageNode = document.getElementById(l_sImageName);
                l_oImageNode.src = arrMenuImages_sel_on[iTempCnt].src;
            }
        }
    }
}

//Menu Hover - Toggle Image On & Off
function fnHoverMenu(p_iImageIndex)
{
	var l_sImageName
	var l_sImagePath
	var l_oImageNode
	
    l_sImageName = "_ctl0_oMenu_img_" + arrMenuImages_List[p_iImageIndex];
    l_oImageNode = document.getElementById(l_sImageName);
    
    if(l_oImageNode)
    {
        l_sImagePath = l_oImageNode.src;
        
        if(l_sImagePath.indexOf("_sel_on.gif") != -1)
        {
            l_oImageNode.src = arrMenuImages_sel_off[p_iImageIndex].src;
        }
        else if(l_sImagePath.indexOf("_sel_off.gif") != -1)
        {
            l_oImageNode.src = arrMenuImages_sel_on[p_iImageIndex].src;
        }
        else if(l_sImagePath.indexOf("_on.gif") != -1)
        {
            l_oImageNode.src = arrMenuImages_off[p_iImageIndex].src;
        }
        else if(l_sImagePath.indexOf("_off.gif") != -1)
        {
            l_oImageNode.src = arrMenuImages_on[p_iImageIndex].src;
            // Start Changes :  Deepali , 16/4/2008
            if(l_sImageName == "_ctl0_oMenu_img_LetsConnect")          
            {
               l_oImageNode.alt = "Guest Survey & Comments";
               l_oImageNode.title =  "Guest Survey & Comments";
            }
            else
            // End Changes : Deepali , 16/4/2008
            {
               
                l_oImageNode.alt = arrMenuImages_on_alt[p_iImageIndex];//Added by Pinaki: CTS Bug/ Enhancement ID: IR_19095_MacaroniGrill_Website_Enhancements_v1.0.doc             
                l_oImageNode.title = arrMenuImages_on_alt[p_iImageIndex];//Added by Pinaki: CTS Bug/ Enhancement ID: IR_19095_MacaroniGrill_Website_Enhancements_v1.0.doc 
            }
            
        }
    }
}

//Validate Zip Code
function fnValidateZipCode(p_oField)
{
    var l_bPassed = true;
    var l_sZip = fnTrim(p_oField.value);
    var l_iLength = l_sZip.length;
    var l_iCnt;
    var l_sRE = "[0-9\-]";
    var l_arrZip;
    
    p_oField.value = l_sZip;
    
    for (l_iCnt = 0; l_iCnt < l_iLength; l_iCnt++)
    {
        l_sChar = l_sZip.charAt(l_iCnt);
        if(l_sChar.match(RegExp(l_sRE, "ig")) == null)
        {
            l_bPassed = false;
            break;
        }
    }
    
    if((l_bPassed) && (l_iLength > 0))
    {
        if(l_sZip.indexOf("-") == -1)
        {
            if(l_iLength != 5)
            {
                l_bPassed = false;
            }
        }
        else
        {
            l_arrZip = l_sZip.split("-");
            if((l_arrZip[0].length != 5) || (l_arrZip[1].length != 4))
            {
                l_bPassed = false;
            }
        }
    }
    
    if( l_iLength == 0 )
    {
        l_bPassed = false;
    }
    
    if(!l_bPassed)
    {
        alert ("Sorry! You must enter a valid ZIP Code.");
        p_oField.focus();
        return false;
    }
    else
    {
        return true;
    }
}

function fnValidateInteger(p_sValue)
{
    var l_oRE;
    l_oRE = /^\d+$/;
    
    if(/^\d+$/.test(p_sValue))
    {
        return true;
    }
    else
    {
        return false;
    }
}

//Validate City & State fields
function fnValidateCityState()
{
    var l_bPassed = true;
    var l_oCity = document.getElementById('_ctl0_oContainer_Main_txtCity');
    var l_sCity = fnTrim(l_oCity.value);
    var l_oState = document.getElementById('_ctl0_oContainer_Main_ddlState');
    var l_sState = fnTrim(l_oState.value);
    var l_iLength = l_sCity.length;
    var l_iCnt;
    var l_sRE = "[a-zA-Z0-9,'#\\s\*\.\-]";
    
    l_oCity.value = l_sCity;
    
    for (l_iCnt = 0; l_iCnt < l_iLength; l_iCnt++)
    {
        l_sChar = l_sCity.charAt(l_iCnt);
        if(l_sChar.match(RegExp(l_sRE, "ig")) == null)
        {
            alert ("Sorry! You must enter a valid City.");
            l_oCity.focus();
            l_bPassed = false;
            break;
        }
    }
    
    if(l_bPassed)
    {
        if((l_sCity == "") && (l_sState == ""))
	    {
		    alert("Sorry! You must enter City and State.");
		    l_oCity.focus();
		    l_bPassed = false;
	    }
	    else if((l_sCity != "") && (l_sState == ""))
	    {
		    alert("Sorry! You must select a State when entering a City.");
		    l_oState.focus();
		    l_bPassed = false;
	    }
	    else if(((l_sCity == "")) && (l_sState != ""))
	    {
		    alert("Sorry! You must enter a City when selecting a State.");
		    l_oCity.focus();
		    l_bPassed = false;
	    }
    	
	    if(l_bPassed)
	    {
	        document.getElementById('_ctl0_oContainer_Main_hidf_CitySearch').value = "Y";
	        document.getElementById('_ctl0_oContainer_Main_hidf_ZipSearch').value = "N";
	        document.aspnetForm.submit();
	    }
	}
}

// Setting default menu type as dinner when client time is 4:00 PM or after
//Start changes:deepali
//function fnSetMenuType()
//{
//    var l_oDate = new Date();
//    var l_iSeconds = 0;
//    alert("here");
//    l_iSeconds = l_oDate.getHours() * 3600 + l_oDate.getMinutes() * 60 + l_oDate.getSeconds();
//   
//    if(l_iSeconds > 57600)
//    {              
//        document.cookie = 'MenuType=DINNER';
//        alert("dinner");
//    }
//    else
//    {
//        document.cookie = 'MenuType=LUNCH';
//        alert("lunch");
//    }
//}
//End chnages:deepali


//Show GiftCard website
function fnShowGiftCard(p_sUrl)
{
    //Not to be deleted
    //var oNewWindow = window.open(p_sUrl, "NewWindow", "width=600,height=400,left=100,top=100,scrollbars=yes,resizable=yes,location=yes,menubar=yes,status=yes,toolbar=yes");
	//oNewWindow.focus();
	window.location.href = p_sUrl;
}

//Show Map
function fnShowMap(p_sUrl)
{
    var properties = "resizable=1,location=0,menubar=0,status=0,toolbar=0,scrollbars=yes,top=100,left=100,height=700,width=770"; 
    if (p_sUrl != "") {
	    var oNewWindow = window.open(p_sUrl, "", properties);
	    oNewWindow.focus();
    }
}


//Show Directions
function fnShowDirections(p_sUrl)
{
    var properties = "resizable=1,location=0,menubar=0,status=0,toolbar=0,scrollbars=yes,top=100,left=100,height=700,width=770"; 
    if (p_sUrl != "") {
	    var oNewWindow = window.open(p_sUrl, "", properties);
	    oNewWindow.focus();
    }
}

//Show Menu Item Image

function fnShowMenuItem(p_iItemID)
{  
      var l_oDiv;
    //Hide Last Item
      var l_sLastItem = document.getElementById('hidf_LastItemId').value;
      if(l_sLastItem != "")
      {
            l_oDiv = document.getElementById('divMenuItem' + l_sLastItem);
            if(l_oDiv)
            {
                  l_oDiv.style.visibility = "hidden";
            }
      }

      //Show Current Item
      l_oDiv = document.getElementById('divMenuItem' + p_iItemID);
      if(l_oDiv)
        {
                l_oDiv.style.visibility = "visible";
                document.getElementById('hidf_LastItemId').value = p_iItemID;
        }
}

//Hide Menu Item Image
function fnHideMenuItem()
{
    var l_oDiv;
    l_oDiv = document.getElementById('divMenuItem' + document.getElementById('hidf_LastItemId').value);
    if(l_oDiv)
    {
          l_oDiv.style.visibility = "hidden";
          document.getElementById('hidf_LastItemId').value = "";
    }
}


//Show Print Menu
function fnShowPrintMenu(p_sUrl)
{
    var oNewWindow = window.open(p_sUrl, "NewWindow", "width=600,height=500,left=100,top=100,scrollbars=yes,resizable=yes,location=no,menubar=no,status=no,toolbar=no");
	oNewWindow.focus();
}

/*CTS Bug/Enhancement ID: Online Menu Updates - Start changes
Date: 06/19/2008 Author:Deepali
*/
function fnShowMyAmoreStories(e,p_sUrl)
{     
     var posX = 0;

     var posy = 0;
     var screenHeight = 0;
     var thiswindowHeight = 400;
     if (!e) var e = window.event;
     posy = e.screenY;

     posX = e.screenX;
     
     screenHeight = screen.height - 250;
         
     if ((posy + thiswindowHeight) > screenHeight)
     {
        posy = screenHeight - thiswindowHeight ; //offset    
     }    

    //var oNewWindow = window.open(p_sUrl, "NewWindow","width=315px,height=400px,left=650px,top=" + posy +"px,scrollbars=yes,resizable=no,location=no,menubar=no,status=no,toolbar=no");
    var oNewWindow = window.open(p_sUrl, "NewWindow", "width=315px,height=400px,left=" + (posX + 300) +"px,top=" + posy + "px,scrollbars=yes,resizable=no,location=no,menubar=no,status=no,toolbar=no");
       
    oNewWindow.focus();
}
//CTS Bug/Enhancement ID: Online Menu Updates - End changes

//Show Nutritional Information PDF
function fnShowNutritionalInfo(p_sUrl)
{

    var oNewWindow = window.open(p_sUrl, "NewWindow", "width=600,height=400,left=100,top=100,scrollbars=yes,resizable=yes,location=no,menubar=no,status=no,toolbar=no");
	oNewWindow.focus();
}

//Validate Zip in the Home Page
function fnValidateZipCodeHome()
{
    if(fnValidateZipCode(document.getElementById('_ctl0_oHeader_txtZip'))==true)
    {
        document.getElementById("_ctl0_oContainer_hidf_GiftCard").value = "N";
        document.getElementById("_ctl0_oContainer_hidf_EVite").value = "N";
        document.getElementById('_ctl0_oHeader_hidf_Zip').value = "Y";
        document.aspnetForm.submit();
    }
}

//Validate Zip in the Right Bar when ENTER key is pressed
/*
*Modified: 11/29/06 - David Beaudreau - SARK
*Commented lines performing form submit and added location.replace to redirect to the new SiteAdvantage Map Search page.
*/
function fnValidateZipCodeRightBarAtKeyPress(p_oEvent)
{
    if(fnValidateZipCode(document.getElementById('_ctl0_oContainer_RightBar_oPrefLoc_txtZip'))==true)
    {
        //document.getElementById('_ctl0_oContainer_RightBar_oPrefLoc_hidf_Zip').value = "Y";
        //document.aspnetForm.submit();
        zipCode = fnTrim(document.getElementById('_ctl0_oContainer_RightBar_oPrefLoc_txtZip').value);
        document.location.replace("../Menu/LocationSearch.aspx?template=map_search&transaction=search&address=&city=&stateProvince=&postalCode=" + zipCode + "&country=US&radius=10&search2=1&x=0&y=0");
    }
    //    if(p_oEvent.keyCode == 13)
    //    {
    //        p_oEvent.keyCode = 14;
    //    }
    //    return p_oEvent;
}

//Validate Zip in the Right Bar
/*
*Modified: 11/29/06 - David Beaudreau - SARK
*Commented lines performing form submit and added location.replace to redirect to the new SiteAdvantage Map Search page.
*/
function fnValidateZipCodeRightBar()
{
    if(fnValidateZipCode(document.getElementById('_ctl0_oContainer_RightBar_oPrefLoc_txtZip'))==true)
    {
        //document.getElementById('_ctl0_oContainer_RightBar_oPrefLoc_hidf_Zip').value = "Y";
        //document.aspnetForm.submit();
        zipCode = fnTrim(document.getElementById('_ctl0_oContainer_RightBar_oPrefLoc_txtZip').value);
        document.location.replace("../Menu/LocationSearch.aspx?template=map_search&transaction=search&address=&city=&stateProvince=&postalCode=" + zipCode + "&country=US&radius=10&search2=1&x=0&y=0");
    }
}

//Validate Zip in Location Search page
/*
*Modified: 11/29/06 - David Beaudreau - SARK
*Commented out function because it is not longer used by the location search page.
*/
//function fnValidateZipCodeSearchLocation()
//{
//    if(fnValidateZipCode(document.getElementById('_ctl0_oContainer_Main_txtZip'))==true)
//    {
//        document.getElementById('_ctl0_oContainer_Main_hidf_ZipSearch').value = "Y";
//        document.getElementById('_ctl0_oContainer_Main_hidf_CitySearch').value = "N";
//        document.aspnetForm.submit();
//    }
//}

//Validate Email in Home page
function fnValidateEmailHome(p_oEvent,p_sType)
{                               
    if(p_sType == "ENTER")
    {
        if(p_oEvent.keyCode == 13)
        {
            p_oEvent.keyCode = 14;
        }
        
        if(fnValidateEmail(document.getElementById('txtEmailOptin')))
        {
            window.location.href = document.getElementById('_ctl0_oContainer_hidEmailOptInURL').value + "&email=" + document.getElementById('txtEmailOptin').value;
        }
        
        return p_oEvent;
    }
    else
    {
        if(fnValidateEmail(document.getElementById('txtEmailOptin')))
        {
            window.location.href = document.getElementById('_ctl0_oContainer_hidEmailOptInURL').value + "&email=" + document.getElementById('txtEmailOptin').value;
        }
    }
}

function fnValidateEmailCatering(p_oEvent,p_sType)
{
    if(p_sType == "ENTER")
    {
        if(p_oEvent.keyCode == 13)
        {
            p_oEvent.keyCode = 14;
        }
        
        if(fnValidateEmail(document.getElementById('txtEmailOptin')))
        {
            window.location.href = document.getElementById('_ctl0_oContainer_Main_hidEmailOptInURL').value + "&email=" + document.getElementById('txtEmailOptin').value;
        }
        
        return p_oEvent;
    }
    else
    {
        if(fnValidateEmail(document.getElementById('txtEmailOptin')))
        {
            window.location.href = document.getElementById('_ctl0_oContainer_Main_hidEmailOptInURL').value + "&email=" + document.getElementById('txtEmailOptin').value;
        }
    }
}

//Validate Email in Right Bar when ENTER is pressed
function fnValidateEmailRightBarAtKeyPress(p_oEvent)
{
    if(p_oEvent.keyCode == 13)
    {
        p_oEvent.keyCode = 14;
    }
    
    if(fnValidateEmail(document.getElementById('txtEmailOptin')))
    {   
        window.location.href = document.getElementById('_ctl0_oContainer_RightBar_oInsideMacGrill_hidEmailOptInURL').value + "&email=" + document.getElementById('txtEmailOptin').value;
    }
    
    return p_oEvent;
}

//Validate Email in Home page
function fnValidateEmailRightBar()
{
    if(fnValidateEmail(document.getElementById('txtEmailOptin')))
    {
        window.location.href = document.getElementById('_ctl0_oContainer_RightBar_oInsideMacGrill_hidEmailOptInURL').value + "&email=" + document.getElementById('txtEmailOptin').value;
    }
}

//eVite functions ------------------------------------------------------------------------------------------------------
    // converts min to hr if min = 60
    function fnCheckTime(sType)
    {
         var ctlHr      = document.getElementById("_ctl0_oContainer_Main_txtTimeHr");
         var ctlMin     = document.getElementById("_ctl0_oContainer_Main_txtTimeMin");
         var ctlAMPM    = document.getElementById("_ctl0_oContainer_Main_ddlTime");
         
         if(ctlMin.value == 60 )
         {
            ctlHr.value = parseInt(ctlHr.value) + 1;
            
            ctlAMPM.focus();
            ctlMin.value = "00";
         }

        if(sType == "Hour")
        {
            if(ctlHr.value != "" && !fnValidateInteger(ctlHr.value))
            {
                alert("Hour part of Event Time must be a proper number");
                ctlHr.focus();
                return false;
            }
        }
        
        if(sType == "Minute")
        {
            if(ctlMin.value != "" && !fnValidateInteger(ctlMin.value))
            {
                alert("Minute part of Event Time must be a proper number");
                ctlMin.focus();
                return false;
            }
        }
        
        return true;
    }
    
    function ValidateSearchInput()
    {
        var ctlCity = document.getElementById("_ctl0_oContainer_Main_txtCity");
        var ctlState = document.getElementById("_ctl0_oContainer_Main_ddlState");
        var ctlZip = document.getElementById("_ctl0_oContainer_Main_txtZip");
        var l_strMessage = "";
        var l_bPassed = true;
        
        if(document.getElementById("_ctl0_oContainer_Main_radZip").checked)
        {
            if(fnValidateZipCode(ctlZip)==false)
            {
                l_bPassed = false;
            }
        }
        else if(document.getElementById("_ctl0_oContainer_Main_radCity").checked)
        {
            if(!fnValidateEViteCityState())
            {
                l_bPassed = false;
            }
        }
        else
        {
            l_bPassed = false;
        }
        
        
        if(l_bPassed)
        {
            fnSaveGuestList();
        }
        
        if (!l_bPassed)
        {
            if(l_strMessage != "")
            {
                alert(l_strMessage);
            }
            return false;
        }
        else
        {
            return true;
        }
    }
    
    //Validate City & State fields
    function fnValidateEViteCityState()
    {
        var l_bPassed = true;
        var l_oCity = document.getElementById('_ctl0_oContainer_Main_txtCity');
        var l_sCity = fnTrim(l_oCity.value);
        var l_oState = document.getElementById('_ctl0_oContainer_Main_ddlState');
        var l_sState = fnTrim(l_oState.value);
        var l_iLength = l_sCity.length;
        var l_iCnt;
        var l_sRE = "[a-zA-Z0-9,'#\\s\*\.\-]";
            
        l_oCity.value = l_sCity;
        
        for (l_iCnt = 0; l_iCnt < l_iLength; l_iCnt++)
        {
            l_sChar = l_sCity.charAt(l_iCnt);
            if(l_sChar.match(RegExp(l_sRE, "ig")) == null)
            {
                alert ("Sorry! You must enter a valid City.");
                l_oCity.focus();
                l_bPassed = false;
                break;
            }
        }
        
        if(l_bPassed)
        {
            if((l_sCity == "") && (l_sState == ""))
	        {
		        alert("Sorry! You must enter City and State.");
		        l_oCity.focus();
		        l_bPassed = false;
	        }
	        else if((l_sCity != "") && (l_sState == ""))
	        {
		        alert("Sorry! You must select a State when entering a City.");
		        l_oState.focus();
		        l_bPassed = false;
	        }
	        else if(((l_sCity == "")) && (l_sState != ""))
	        {
		        alert("Sorry! You must enter a City when selecting a State.");
		        l_oCity.focus();
		        l_bPassed = false;
	        }
	    }
    	
	    return l_bPassed;
    }
    
    function ManageGroupRadioButtons()
    {
        var GRIDNAME;
        GRIDNAME = "grdvwLocationResults";
        var flagFieldForRestaurantPopulation;
        flagFieldForRestaurantPopulation = document.getElementById("_ctl0_oContainer_Main_hdnRestaurantPrePopulated");
        flagFieldForRestaurantPopulation.value = "0";
        
        var arrInputElements = document.getElementsByTagName("INPUT");
        var index = -1;
        var j = -1;
        for (i=0; i < arrInputElements.length; i++)
        {
            if ((arrInputElements[i].type == "radio") && (arrInputElements[i].id.indexOf("grdvwLocationResults") != -1))
            {
                j++;
                if (arrInputElements[i].checked)
                {
                    index = j;
                    break;
                 }
            }
        }
        
        if (index == -1) return false;
        
        document.getElementById("_ctl0_oContainer_Main_hdnRestaurantID").value = document.getElementsByName("RestaurantID")[index].innerHTML;
        
        document.getElementById("_ctl0_oContainer_Main_hdnRestaurantName").value = document.getElementsByName("RestaurantName")[index].innerHTML;
        
        var hdnAddressLine1 = document.getElementById("_ctl0_oContainer_Main_hdnAddressLine1");
        hdnAddressLine1.value = document.getElementsByName("AddressLine1")[index].innerText;
        if(navigator.userAgent.toUpperCase().indexOf("FIREFOX") != -1)
        {
            hdnAddressLine1.value = document.getElementsByName("AddressLine1")[index].textContent;
        }
        
        var hdnCity = document.getElementById("_ctl0_oContainer_Main_hdnCity");
        hdnCity.value = document.getElementsByName("City")[index].innerHTML;
        
        var hdnRestaurantState = document.getElementById("_ctl0_oContainer_Main_hdnRestaurantState");
        hdnRestaurantState.value = document.getElementsByName("State")[index].innerHTML;
        
        var hdnRestaurantZip = document.getElementById("_ctl0_oContainer_Main_hdnRestaurantZip");
        hdnRestaurantZip.value = document.getElementsByName("Zip")[index].innerHTML;
        
        var hdnRestaurantPhone = document.getElementById("_ctl0_oContainer_Main_hdnRestaurantPhone");
        hdnRestaurantPhone.value = document.getElementsByName("RestaurantPhone")[index].innerHTML;
        
        var hdnRestaurantCountry = document.getElementById("_ctl0_oContainer_Main_hdnRestaurantCountry");
        hdnRestaurantCountry.value = document.getElementsByName("Country")[index].innerHTML;
        
        return true;
    }
    
    function calendarPicker(strField)
    {
        var dateVal = "";
        var defaultDate = document.getElementById(strField).value;
        var calendarUrl;
        
        if(!fnValidateDate(defaultDate))
        {
            document.getElementById(strField).value = "";
        }
        
        //Set default to blank
        defaultDate = document.getElementById(strField).value;
        calendarUrl = 'DatePicker.aspx?field=' + strField + '&default='+ defaultDate + '&type=';
        
        if(window.showModalDialog)
        {
            //For Internet Explorer
            dateVal = window.showModalDialog(calendarUrl + 'SHOWMODAL','Dialog','dialogWidth:250px;dialogHeight:180px;center:yes;resizable:no;help:no;status:no;scroll:no;');
            if(dateVal == "" || dateVal == undefined)
            {
                //No item returned so retain the old value
            }
            else
            {
                document.getElementById(strField).value = dateVal;
            }
        }
        else
        {
            //For other browsers
            var oNewWindow = window.open(calendarUrl + 'OPEN','Dialog','height=158,width=250,left=300,top=200,center=yes,toolbars=0,resizable=0,scrollbars=0,modal=yes');
         }
    }
    
    function fnShowAddGuest( p_sType, p_sEviteId, tblID )
    {   
        var guestList = "";
        var totalRows;
        var rowCount;
        var guestName;
        var guestEmail;
        var arrGuestList = new Array();
        var counter;
        var arrGuest;
        
        if(p_sType == "RSVP")
        {
            if(navigator.userAgent.toUpperCase().indexOf("MSIE") != -1)
            {
                //For Internet Explorer
                var oNewWindow = window.open('AddGuests.aspx?Page=RSVP&EviteId=' + p_sEviteId, "NewWindow", "width=310,height=240,left=100,top=100,scrollbars=no,resizable=no,location=no,menubar=no,status=no,toolbar=no");
            }
            else
            {
                //For other browsers
                var oNewWindow = window.open('AddGuests.aspx?Page=RSVP&EviteId=' + p_sEviteId, "NewWindow", "width=310,height=240,left=100,top=100,scrollbars=no,resizable=no,location=no,menubar=no,status=no,toolbar=no");
            }
            oNewWindow.focus();
        }
        else if(p_sType == "EVENT")
        {
            totalRows = tblID.rows.length;
            for( rowCount=2; rowCount < totalRows; rowCount+=2 )
            {
                try
                {
                    guestName  = fnTrim(document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].cells[0].getElementsByTagName("input")[0].value);
                    guestEmail = fnTrim(document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].cells[2].getElementsByTagName("input")[0].value);
                }                    
                catch(e)
                {
                    guestName  = fnTrim(document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].childNodes[0].getElementsByTagName("input")[0].value);
                    guestEmail = fnTrim(document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].childNodes[2].getElementsByTagName("input")[0].value);
                }                   
                if( guestName == "" || guestEmail == "" )
                {
                    break;
                }
            }
            
            if( rowCount >= totalRows )
            {
                if(navigator.userAgent.toUpperCase().indexOf("MSIE") != -1)
                {
                    //For Internet Explorer
                    guestList = window.showModalDialog('AddGuests.aspx?Page=EventDetails', 'Dialog', 'dialogWidth:310px;dialogHeight:290px;scrollbars:no;help:no;resizable:no');
                    
                    if( guestList != "" &&  guestList != null )
                    {
                        arrGuestList = guestList.split('|');
                        
                        for(counter = 0; counter < arrGuestList.length ; counter++)
                        {
                            //Spacer row
                            lastRow = document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows.length;
                            row = document.getElementById("_ctl0_oContainer_Main_tblAddGuest").insertRow(lastRow);
                            
                            c = row.insertCell();
                            c.colspan = '3';
                            c.innerHTML  = '<img src="../images/Common/spacer.gif" height="4" width="1" border="0" />';
                            
                            //Data row
                            lastRow = document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows.length;
                            row = document.getElementById("_ctl0_oContainer_Main_tblAddGuest").insertRow(lastRow);
                	        
                            arrGuest = new Array();
                            arrGuest = arrGuestList[counter].split("^");
                		    
                            c1 = row.insertCell();
                            c1.align = 'left';
                            c1.innerHTML  = '<input type="text" class="Evite_DetailsBox" size="12" maxlength="100"/>';
                            c1.getElementsByTagName("input")[0].value = arrGuest[0];
                		   	
    		   	            c2 = row.insertCell();
                            c2.innerHTML  = '<img src="../images/Common/spacer.gif" height="1" width="8" border="0" />';
                		   	
                            c3 = row.insertCell();
                            c3.align = 'right';
                            c3.innerHTML  = '<input type="text" class="Evite_DetailsBox" size="21" maxlength="100"/>';
                            c3.getElementsByTagName("input")[0].value = arrGuest[1];
                        }
                    }
                }
                else
                {
                    //For other browsers
                    var oNewWindow = window.open('AddGuests.aspx?Page=EventDetails', "NewWindow", "width=310,height=290,left=300,top=200,scrollbars=no,help=no,resizable=no,modal=yes");
                }
            }
            else
            {
                alert( "Please fill in all the existing rows." );
                if( guestName == "" )
                {
                    try
                    {
                        document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].cells[0].getElementsByTagName("input")[0].focus();
                    }
                    catch(e)
                    {
                        document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].childNodes[0].getElementsByTagName("input")[0].focus();
                    }                                                
                }
                else if( guestEmail == "" )
                {
                    try
                    {
                        document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].cells[2].getElementsByTagName("input")[0].focus();
                    }
                    catch(e)
                    {
                        document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].childNodes[2].getElementsByTagName("input")[0].focus();
                    }                                                
                }
            }
        }
    }

    function SaveCardDetails()
    {
        var cardName = document.getElementById("_ctl0_oContainer_Main_lblCardName");
        var imagePath = document.getElementById("_ctl0_oContainer_Main_phImages");
        var txtBox = document.getElementById("_ctl0_oContainer_Main_hdnCardDetails");
        txtBox.value = cardName.innerText + "," + imagePath.src;		    
    }

    function ValidateInputAtPreview(tblID)
    {
        
        var totalRows = document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows.length;
        var rowCount;
        var noOfGuests = 0;
        var guestList = "";
        var l_SearchInput  = true;
        var l_oRadioButtonValue=document.getElementById("_ctl0_oContainer_Main_hidf_Radvalue");
        var l_sRadioButtonValue=fnTrim(l_oRadioButtonValue.value);
        var l_sRadiobuttons=true;
        l_sRadiobuttons = ManageGroupRadioButtons();
        
        if(document.getElementById("_ctl0_oContainer_Main_hdnPrefLoc").value == "N" && document.getElementById("_ctl0_oContainer_Main_hdnInternational").value == "N" && l_sRadioButtonValue == "N")
        {
            //Added for incorrect alert fix in Location Search
            ValidateSearchInput();
        }
        if(document.getElementById('_ctl0_oContainer_Main_radZip').checked==true && document.getElementById('_ctl0_oContainer_Main_txtZip').value == "" && l_sRadioButtonValue == "N" )
        {
            return false;
        }
        if((document.getElementById('_ctl0_oContainer_Main_radCity').checked==true && document.getElementById('_ctl0_oContainer_Main_txtCity').value == "" && l_sRadioButtonValue == "N") || (document.getElementById('_ctl0_oContainer_Main_radCity').checked==true && document.getElementById('_ctl0_oContainer_Main_ddlState').value == ""  && l_sRadioButtonValue == "N" ))
        {
             return false;
        }
        if(l_sRadioButtonValue == "N" )
        {
            alert("Please select a Restaurant first.");
            return false;
        }
        //if(l_SearchInput) Commented for incorrect alert fix in Location Search 
        //Added for incorrect alert fix in Location Search
        else if(l_sRadioButtonValue == "Y")
        {
            if(document.getElementById("_ctl0_oContainer_Main_hdnPrefLoc").value == "N")
            {
                if (ManageGroupRadioButtons())
                {
                    
                }
                else
                {
                    alert("Please select a Restaurant from the list.");
                    return false;
                }
            }
            if( fnValidateReqFields() && fnValidateNonReqFields())
            {
                if( document.getElementById( "_ctl0_oContainer_Main_txtPhone" ).value != "" )
                {
                    if( fnValidateTelephoneNo( document.getElementById( "_ctl0_oContainer_Main_txtPhone" ).value ) == false )
                    {
                        alert( "Sorry! You must enter a valid Telephone number." );
                        document.getElementById( "_ctl0_oContainer_Main_txtPhone" ).focus();
                        return false;
                    }
                }
                
                for(rowCount = 2; rowCount < totalRows ; rowCount = rowCount + 2)
                {
                    try
                    {
                        guestName = fnTrim(document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].cells[0].getElementsByTagName("input")[0].value);
                        guestEmail = fnTrim(document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].cells[2].getElementsByTagName("input")[0].value);
                    }
                    catch(e)
                    {
                        guestName = fnTrim(document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].childNodes[0].getElementsByTagName("input")[0].value);
                        guestEmail = fnTrim(document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].childNodes[2].getElementsByTagName("input")[0].value);
                    }
                    
                    if(guestName != "" && guestEmail == "")
                    {
                        alert("Sorry! You must enter a valid Email Address.");
                        try
                        {
                            document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].cells[2].getElementsByTagName("input")[0].focus();
                        }                           
                        catch(e)
                        {
                            document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].childNodes[2].getElementsByTagName("input")[0].focus();
                        }
                        return false;
                    }
                    else if(guestName == "" && guestEmail != "")
                    {
                        alert("Sorry! You must enter a valid Guest Name.");
                        try
                        {
                            document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].cells[0].getElementsByTagName("input")[0].focus();
                        }
                        catch(e)                            
                        {
                            document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].childNodes[0].getElementsByTagName("input")[0].focus();
                        }                            
                        return false;             
                    }
                    else if(guestName != "" && guestEmail != "")
                    {
                        //Check for duplicate emails in the guest list
                        var tmpName = "";
                        var tmpEmail = "";
                        try
                        {
                            tmpName = document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].cells[0].getElementsByTagName("input")[0];
                        }
                        catch(e)
                        {
                            tmpName = document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].childNodes[0].getElementsByTagName("input")[0];
                        }
                        try
                        {
                            tmpEmail = document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].cells[2].getElementsByTagName("input")[0];
                        }
                        catch(e)
                        {
                            tmpEmail = document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].childNodes[2].getElementsByTagName("input")[0];
                        }                                                    
                        if(!fnValidateEviteNamesField(tmpName))
                        {
                            alert( "Sorry! You must enter a valid Guest Name." );
                            try
                            {
                                document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].cells[0].getElementsByTagName("input")[0].focus();
                            }
                            catch(e)
                            {
                                document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].childNodes[0].getElementsByTagName("input")[0].focus();
                            }                                
                            return false;
                        }
                        else if(!fnValidateEmail(tmpEmail))
                        {
                            return false;
                        }
                        else if(guestEmail.toUpperCase() == fnTrim(document.getElementById("_ctl0_oContainer_Main_txtEmail").value).toUpperCase())
                        {
                            alert("There's no need to invite yourself to your own event as you are already the host");
                            try
                            {
                                document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].cells[2].getElementsByTagName("input")[0].focus();
                            }
                            catch(e)
                            {
                                document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].childNodes[2].getElementsByTagName("input")[0].focus();
                            }                                
                            return false;
                        }
                        guestList += guestName + "^";
                        guestList += guestEmail + "|";
                        noOfGuests += 1;
                    }
                }
                
                var txtBox = document.getElementById("_ctl0_oContainer_Main_hdnGuestList");
                if(noOfGuests == 0 )
                {
                    txtBox.value = "";
                    alert("At least one Guest is required.");
                    try
                    {
                        document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[2].cells[0].getElementsByTagName("input")[0].focus();
                    }
                    catch(e)
                    {
                        document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[2].childNodes[0].getElementsByTagName("input")[0].focus();
                    }                                                
                    return false;
                }
                else
                {
                    txtBox.value = (guestList.substring(0,guestList.length-1));
                }    
                
                //Check for duplicate guest email address
                if(noOfGuests > 1)
                {
                    guestList = guestList.substring(0,guestList.length-1);
                    for(rowCount = 2; rowCount < totalRows ; rowCount = rowCount + 2)
                    {
                        try
                        {
                            guestEmail = fnTrim(document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].cells[2].getElementsByTagName("input")[0].value);
                        }                                                        
                        catch(e)
                        {
                            guestEmail = fnTrim(document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].childNodes[2].getElementsByTagName("input")[0].value);
                        }
                        if(guestEmail != "")
                        {
                            guestList = guestList.replace(guestEmail,"");
                            if(guestList.indexOf(guestEmail) != -1)
                            {
                                alert("Sorry! You must not enter the same Guest Email more than once");
                                try
                                {
                                    document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].cells[2].getElementsByTagName("input")[0].focus();
                                }
                                catch(e)
                                {
                                    document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].childNodes[2].getElementsByTagName("input")[0].focus();
                                }                                                                                                            
                                return false;
                            }
                        }
                    }
                }

                fnSaveSelectedRestaurantId();
                SaveCardDetails();
                return true;
            }
            else
            {
                return false;
            }
        }
        else
        {
            return false;
        }
    }
    
    function fnSaveGuestList()
    {
        var totalRows = document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows.length;
        var rowCount;
        var noOfGuests = 0;
        var guestList = "";
        
        for(rowCount = 2; rowCount < totalRows ; rowCount = rowCount + 2)
        {
            try
            {
                guestName = fnTrim(document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].cells[0].getElementsByTagName("input")[0].value);
                guestEmail = fnTrim(document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].cells[2].getElementsByTagName("input")[0].value);
            }
            catch(e)
            {
                guestName = fnTrim(document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].childNodes[0].getElementsByTagName("input")[0].value);
                guestEmail = fnTrim(document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].childNodes[2].getElementsByTagName("input")[0].value);                
            }                
            
            if(guestName != "" && guestEmail != "")
            {
                guestList += guestName + "^";
                guestList += guestEmail + "|";
                noOfGuests += 1;
            }        
        }
                
        var txtBox = document.getElementById("_ctl0_oContainer_Main_hdnGuestList");
        txtBox.value = (guestList.substring(0,guestList.length-1));
        
        fnSaveSelectedRestaurantId();
        return true;
    }
    
    function fnSaveSelectedRestaurantId()
    {
        var GRIDNAME;
        GRIDNAME = "grdvwLocationResults";
        var flagFieldForRestaurantPopulation;
        flagFieldForRestaurantPopulation = document.getElementById("_ctl0_oContainer_Main_hdnRestaurantPrePopulated");
        flagFieldForRestaurantPopulation.value = "0";
        
        var arrInputElements = document.getElementsByTagName("INPUT");
        var index = -1;
        var j = -1;
        for (i=0; i < arrInputElements.length; i++)
        {
            if ((arrInputElements[i].type == "radio") && (arrInputElements[i].id.indexOf("grdvwLocationResults") != -1))
            {
                j++;
                if (arrInputElements[i].checked)
                {
                    index = j;
                    break;
                 }
            }
        }
        
        if (index == -1) return false;
        
        document.getElementById("_ctl0_oContainer_Main_hdnRestaurantID").value = document.getElementsByName("RestaurantID")[index].innerHTML;
        return true;
    }
    
    function fnSaveSelectedRestaurantIdForPaging()
    {
        var totalRows = document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows.length;
        var rowCount;
        var noOfGuests = 0;
        var guestList = "";
        
        var GRIDNAME;
        GRIDNAME = "grdvwLocationResults";
        var flagFieldForRestaurantPopulation;
        flagFieldForRestaurantPopulation = document.getElementById("_ctl0_oContainer_Main_hdnRestaurantPrePopulated");
        flagFieldForRestaurantPopulation.value = "0";
        
        var arrInputElements = document.getElementsByTagName("INPUT");
        var index = -1;
        var j = -1;
        for (i=0; i < arrInputElements.length; i++)
        {
            if ((arrInputElements[i].type == "radio") && (arrInputElements[i].id.indexOf("grdvwLocationResults") != -1))
            {
                j++;
                if (arrInputElements[i].checked)
                {
                    index = j;
                    break;
                 }
            }
        }
        
        if(index != -1)
        {
            document.getElementById("_ctl0_oContainer_Main_hdnRestaurantID").value = document.getElementsByName("RestaurantID")[index].innerHTML;
        }
        
        //Create Guest List
        for(rowCount = 2; rowCount < totalRows ; rowCount = rowCount + 2)
        {
            try
            {
                guestName = fnTrim(document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].cells[0].getElementsByTagName("input")[0].value);
                guestEmail = fnTrim(document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].cells[2].getElementsByTagName("input")[0].value);
            }
            catch(e)
            {
                guestName = fnTrim(document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].childNodes[0].getElementsByTagName("input")[0].value);
                guestEmail = fnTrim(document.getElementById("_ctl0_oContainer_Main_tblAddGuest").rows[rowCount].childNodes[2].getElementsByTagName("input")[0].value);
            }                            
            
            if(guestName != "" && guestEmail != "")
            {
                guestList += guestName + "^";
                guestList += guestEmail + "|";
                noOfGuests += 1;
            }        
        }
                
        var txtBox = document.getElementById("_ctl0_oContainer_Main_hdnGuestList");
        txtBox.value = "";
        txtBox.value = (guestList.substring(0,guestList.length-1));
        return true;
    }
    
    function addRow(tblID)
    {
	    var lastRow;
	    var row;
	    var rowCount;
	    var txtNameID;
	    var txtEmailID;
	    var totalRows = tblID.rows.length;
		
		for( rowCount=2; rowCount < totalRows; rowCount+=2 )
        {
            try
            {
                guestName  = fnTrim(tblID.rows[rowCount].cells[0].getElementsByTagName("input")[0].value);
                guestEmail = fnTrim(tblID.rows[rowCount].cells[2].getElementsByTagName("input")[0].value);
            }
            catch(e)
            {
                guestName  = fnTrim(tblID.rows[rowCount].childNodes[0].getElementsByTagName("input")[0].value);
                guestEmail = fnTrim(tblID.rows[rowCount].childNodes[2].getElementsByTagName("input")[0].value);
            }
               
            if( guestName == "" && guestEmail == "" )
            {
                break;
            }
        }
		
		if( rowCount >= totalRows )
		{
		    for(rowCount = 0; rowCount < 5 ; rowCount++)
	        {
	            //Spacer row
                lastRow = tblID.rows.length;
                //row = tblID.insertRow(lastRow);
                row = tblID.insertRow(-1);
                
                try
                {
                    c = row.insertCell();
                }
                catch(e)
                {
                    c = row.insertCell(-1);
                }
                c.colspan = '3';
                c.innerHTML  = '<img src="../images/Common/spacer.gif" height="4" width="1" border="0" />';
                
                //Data row
                lastRow = tblID.rows.length;
                //row = tblID.insertRow(lastRow);
                row = tblID.insertRow(-1);
    	        
    	        try
                {
                    c1 = row.insertCell();
                }
                catch(e)
                {
                    c1 = row.insertCell(-1);
                }
    	        c1.align = 'left';
                c1.innerHTML  = '<input type="text" class="Evite_DetailsBox" size="14" maxlength="100"/>';
                
		   	    try
                {
                    c2 = row.insertCell();
                }
                catch(e)
                {
                    c2 = row.insertCell(-1);
                }
		   	    c2.innerHTML  = '<img src="../images/Common/spacer.gif" height="1" width="8" border="0" />';
    		   	
                try
                {
                    c3 = row.insertCell();
                }
                catch(e)
                {
                    c3 = row.insertCell(-1);
                }
                c3.align = 'right';
                c3.innerHTML  = '<input type="text" class="Evite_DetailsBox" size="21" maxlength="100"/>';
	        }
	     }
	     else
	     {
	        alert( "Please fill in all the existing rows." );
	        try
	        {
                tblID.rows[rowCount].cells[0].getElementsByTagName("input")[0].focus();
            }
            catch(e)
            {
                tblID.rows[rowCount].childNodes[0].getElementsByTagName("input")[0].focus();
            }                                
	     }
    }

    function showValueInParent(tblID)
    {

	    if(ValidateInput(tblID))
	    { 
	        var guestList = "";
	        var totalRows = tblID.rows.length;
	        var rowCount;
	        var guestName;
	        var guestEmail;
	        
            for(rowCount = 2; rowCount < totalRows ; rowCount = rowCount + 2)
            {
                try
                {
                    guestName = fnTrim(tblID.rows[rowCount].cells[0].getElementsByTagName("input")[0].value);
                    guestEmail = fnTrim(tblID.rows[rowCount].cells[2].getElementsByTagName("input")[0].value);
                }
                catch(e)
                {
                    guestName = fnTrim(tblID.rows[rowCount].childNodes[0].getElementsByTagName("input")[0].value);
                    guestEmail = fnTrim(tblID.rows[rowCount].childNodes[2].getElementsByTagName("input")[0].value);
                }                    
                if(guestName != "" && guestEmail != "")
                {
                    guestList += guestName + "^";
                    guestList += guestEmail + "|";        
                }
            }
            
            if(guestList == "")
            {
                window.returnValue = "";
            }
            else
            {
                if(navigator.userAgent.toUpperCase().indexOf("MSIE") != -1)
                {
                    //For Internet Explorer
	                window.returnValue = (guestList.substring(0,guestList.length-1));
                }
                else
                {
                    //For other browsers
                    var arrGuestList = new Array();
                    arrGuestList = guestList.split('|');
                    var counter;
                    var arrGuest;
        	        var tblParent = window.opener.document.getElementById("_ctl0_oContainer_Main_tblAddGuest");
                    for(counter = 0; counter < arrGuestList.length - 1 ; counter++)
                    {
                        //Spacer row
                        lastRow = tblParent.rows.length;
                        //row = tblParent.insertRow(lastRow);
                        row = tblParent.insertRow(-1);
                        
                        c = row.insertCell(0);
                        c.colspan = '3';
                        c.innerHTML  = '<img src="../images/Common/spacer.gif" height="4" width="1" border="0" />';
                        
                        //Data row
                        lastRow = tblParent.rows.length;
                        //row = tblParent.insertRow(lastRow);
                        row = tblParent.insertRow(-1);
            	        
                        arrGuest = new Array();
                        arrGuest = arrGuestList[counter].split("^");
            		    
                        c1 = row.insertCell(0);
                        c1.align = 'left';
                        c1.innerHTML  = '<input type="text" class="Evite_DetailsBox" size="12" maxlength="100"/>';
                        c1.getElementsByTagName("input")[0].value = arrGuest[0];
            		   	
    		   	        c2 = row.insertCell(1);
                        c2.innerHTML  = '<img src="../images/Common/spacer.gif" height="1" width="8" border="0" />';
            		   	
                        c3 = row.insertCell(2);
                        c3.align = 'right';
                        c3.innerHTML  = '<input type="text" class="Evite_DetailsBox" size="21" maxlength="100"/>';
                        c3.getElementsByTagName("input")[0].value = arrGuest[1];
                    }
                }
                
	        }
	        window.close();
	    }
    }

    function ValidateInput(tblID)
    {
        var totalRows = tblID.rows.length;
        var rowCount;
        var guestListForDuplicate;
        
        for(rowCount = 2; rowCount < totalRows; rowCount = rowCount + 2)
        {
            try
            {
                guestName = fnTrim(tblID.rows[rowCount].cells[0].getElementsByTagName("input")[0].value);
                guestEmail = fnTrim(tblID.rows[rowCount].cells[2].getElementsByTagName("input")[0].value);
            }
            catch(e)
            {
                guestName = fnTrim(tblID.rows[rowCount].childNodes[0].getElementsByTagName("input")[0].value);
                guestEmail = fnTrim(tblID.rows[rowCount].childNodes[2].getElementsByTagName("input")[0].value);
            }                                
            
            if(guestName != "" && guestEmail == "")
            {
                alert("Sorry! You must enter a valid Email Address.");
                try
                {
                    tblID.rows[rowCount].cells[2].getElementsByTagName("input")[0].focus();
                }
                catch(e)
                {
                    tblID.rows[rowCount].childNodes[2].getElementsByTagName("input")[0].focus();
                }                                            
                return false;
            }
            else if(guestName == "" && guestEmail != "")
            {
                alert("Sorry! You must enter a valid Guest Name.");
                try
                {
                    tblID.rows[rowCount].cells[0].getElementsByTagName("input")[0].focus();
                }
                catch(e)
                {
                    tblID.rows[rowCount].childNodes[0].getElementsByTagName("input")[0].focus();
                }                                        
                return false;             
            }
            else if(guestName != "" && guestEmail != "")
            {
                var tmpEmailCtrl;
                try
                {
                    tmpEmailCtrl = tblID.rows[rowCount].cells[2].getElementsByTagName("input")[0];
                }
                catch(e)
                {
                    tmpEmailCtrl = tblID.rows[rowCount].childNodes[2].getElementsByTagName("input")[0];
                }                    
                if(!fnValidateEmail(tmpEmailCtrl))
                {
                    return false;
                }
            }
            
            guestListForDuplicate += guestName + "^";
            guestListForDuplicate += guestEmail + "|"; 
        }
        
        //Check for duplicate guest email address
        if(guestListForDuplicate != "")
        {
            guestListForDuplicate = guestListForDuplicate.substring(0,guestListForDuplicate.length-1);
            for(rowCount = 2; rowCount < totalRows ; rowCount = rowCount + 2)
            {
                try
                {
                    guestEmail = fnTrim(tblID.rows[rowCount].cells[2].getElementsByTagName("input")[0].value);
                }
                catch(e)
                {
                    guestEmail = fnTrim(tblID.rows[rowCount].childNodes[2].getElementsByTagName("input")[0].value);
                }                    
                if(guestEmail != "")
                {
                    guestListForDuplicate = guestListForDuplicate.replace(guestEmail,"");
                    if(guestListForDuplicate.indexOf(guestEmail) != -1)
                    {
                        alert("Sorry! You must not enter the same Guest Email more than once");
                        try
                        {
                            tblID.rows[rowCount].cells[2].getElementsByTagName("input")[0].focus();
                        }
                        catch(e)
                        {
                            tblID.rows[rowCount].cells[2].getElementsByTagName("input")[0].focus();
                        }
                        return false;
                    }
                }
            }
        }
        
        return true;
    }
    
    function fnValidateReqFields()
    {
            
         if( document.getElementById("_ctl0_oContainer_Main_txtDate").value == "" )
         { 
              //Modified by Ankur on 2/15/2007
              //alert("Sorry! You must enter a valid Event Date.");
              alert("Sorry! You must enter a valid Event Date in MM/DD/YYYY format only.");
              //End modification by Ankur on 2/15/2007
              document.getElementById("_ctl0_oContainer_Main_txtDate").focus();
              return false;
         }
         
         else if( fnValidateDate( document.getElementById("_ctl0_oContainer_Main_txtDate").value ) == false )
         {
              //Modified by Ankur on 2/15/2007
            //alert("Sorry! You must enter a valid Event Date.");
              alert("Sorry! You must enter a valid Event Date in MM/DD/YYYY format only.");
              //End modification by Ankur on 2/15/2007
            document.getElementById("_ctl0_oContainer_Main_txtDate").focus();
            return false;
         }
         
         else if(!CompareDate(document.getElementById("_ctl0_oContainer_Main_txtDate").value))
         {
            alert( "Sorry! Event Date cannot be less than Current Date." );
            document.getElementById("_ctl0_oContainer_Main_txtDate").focus();
            return false;
         }
         
         else if( document.getElementById("_ctl0_oContainer_Main_txtTimeHr").value == "" )
         {
            alert("Sorry! You must enter a valid Event Time.");
            document.getElementById("_ctl0_oContainer_Main_txtTimeHr").focus();
            return false;
         }
         
         else if( isNaN( document.getElementById( "_ctl0_oContainer_Main_txtTimeHr" ).value ) )
         {
            alert("Sorry! You must enter a valid Event Time.");
            document.getElementById( "_ctl0_oContainer_Main_txtTimeHr" ).focus();
            return false;
         }
         
         else if( document.getElementById("_ctl0_oContainer_Main_txtTimeHr").value > 12 )
         {
            alert("Sorry! Hour part cannot be greater than 12.");
            document.getElementById("_ctl0_oContainer_Main_txtTimeHr").focus();
            return false;
         }
         
         else if( document.getElementById("_ctl0_oContainer_Main_txtTimeHr").value < 0)
         {
            alert("Sorry! You must enter a valid Event Time.");
            document.getElementById("_ctl0_oContainer_Main_txtTimeHr").focus();
            return false;
         }
         else if( document.getElementById("_ctl0_oContainer_Main_txtTimeMin").value == "" )
         {
            alert("Sorry! You must enter a valid Event Time.");
            document.getElementById("_ctl0_oContainer_Main_txtTimeMin").focus();
            return false;
         }
         
         else if( isNaN( document.getElementById( "_ctl0_oContainer_Main_txtTimeMin" ).value ) )
         {
            alert("Sorry! You must enter a valid Event Time.");
            document.getElementById( "_ctl0_oContainer_Main_txtTimeMin" ).focus();
            return false;
         }
         
         else if( document.getElementById("_ctl0_oContainer_Main_txtTimeMin").value > 60 )
         {
            alert("Sorry! Minute part cannot be greater than 60.");
            document.getElementById("_ctl0_oContainer_Main_txtTimeMin").focus();
            return false;
         }
         
         else if( document.getElementById("_ctl0_oContainer_Main_txtTimeMin").value < 0)
         {
            alert("Sorry! You must enter a valid Event Time.");
            document.getElementById("_ctl0_oContainer_Main_txtTimeMin").focus();
            return false;
         }
         else if(!fnCheckForFutureTime(document.getElementById("_ctl0_oContainer_Main_txtDate").value, document.getElementById("_ctl0_oContainer_Main_txtTimeHr").value, document.getElementById( "_ctl0_oContainer_Main_txtTimeMin" ).value, document.getElementById( "_ctl0_oContainer_Main_ddlTime" ).value))
         {
            alert("Sorry! Your event cannot be organized in the past.");
            document.getElementById("_ctl0_oContainer_Main_txtTimeHr").focus();
            return false;
         }
         //Added on Nov 15, 2006
         else if(((parseInt(document.getElementById("_ctl0_oContainer_Main_txtTimeHr").value,10) < 11 || parseInt(document.getElementById("_ctl0_oContainer_Main_txtTimeHr").value,10) == 12) && document.getElementById("_ctl0_oContainer_Main_ddlTime").value == "AM") || ((parseInt(document.getElementById("_ctl0_oContainer_Main_txtTimeHr").value,10) > 9 && parseInt(document.getElementById("_ctl0_oContainer_Main_txtTimeHr").value,10) <= 11) && document.getElementById("_ctl0_oContainer_Main_ddlTime").value == "PM"))
         {
                alert("Sorry! Your event should occur between 11 A.M. and 9 P.M.");
                document.getElementById("_ctl0_oContainer_Main_txtTimeHr").focus();
                return false;
         }
        else if(
                (parseInt(document.getElementById("_ctl0_oContainer_Main_txtTimeHr").value,10) == 9 && parseInt(document.getElementById("_ctl0_oContainer_Main_txtTimeMin").value,10) > 0) 
                && document.getElementById("_ctl0_oContainer_Main_ddlTime").value == "PM"
                )
         {
                alert("Sorry! Your event should occur between 11 A.M. and 9 P.M.");
                document.getElementById("_ctl0_oContainer_Main_txtTimeHr").focus();
                return false;
         }
         //End of added section  
         else if( document.getElementById("_ctl0_oContainer_Main_txtName").value == "" )
         {
            alert("Sorry! You must enter your Name.");
            document.getElementById("_ctl0_oContainer_Main_txtName").focus();
            return false;
         }      
         else if( fnValidateEviteNamesField(document.getElementById("_ctl0_oContainer_Main_txtName")) == false)
         {
            alert("Sorry! You must enter a valid Name.");
            document.getElementById("_ctl0_oContainer_Main_txtName").focus();
            return false;
         }
         
         else if( document.getElementById("_ctl0_oContainer_Main_txtEmail").value == "" )
         {
            alert("Sorry! You must enter a valid Email Address.");
            document.getElementById("_ctl0_oContainer_Main_txtEmail").focus();
            return false;
         }
         
         else if( fnValidateEmail( document.getElementById("_ctl0_oContainer_Main_txtEmail") ) == false )
         {
            return false;
         }
         
         else
         {
            return true;
         }
         
    }

    // Validates a telephone number
    function fnValidateTelephoneNo( strValue )
    {
        var objRegExp = /(\(\d\d\d\))?\s*(\d\d\d)\s*[\.-]?\s*(\d\d\d\d)/;
        
        //check to see if in correct format
        if( !objRegExp.test( strValue ) )
        {
            return false;   // bad format
        } 
        else
        {
            return true;
        }
    }
    
    // Validates that a string contains only valid dates with 2 digit month, 2 digit day, 4 digit year. Date separator can be ., -, or /.
    // Uses combination of regular expressions and string parsing to validate date. Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy
    function fnValidateDate( dtDate )
    {
            var day,mon,year,status;
	    	status = false;
	    
	    	if(dtDate.indexOf("/")==-1)
	    	{
	    		return false;
	    	}
	    
	    
	    	if(dtDate.lastIndexOf("/") == dtDate.indexOf("/"))
	    	{
	    		return false;
	    	}
	    
	    	var DateVal=new Date(dtDate);
	    
	    	if (isNaN((DateVal)))
	    	{
	    		return false;
	    	}
	    	var arrDate=dtDate.split("/");
	    	
	    	mon = arrDate[0];
	    	day = arrDate[1];
	    	year = arrDate[2];
	    
	    	if(year.length < 4)
	    	{
	    		return false;
	    	}
	    	
	    	if(isNaN(mon))
	    	{
	    		return false;
	    	}
	    	
	    	if(isNaN(day))
	    	{
	    		return false;
	    	}
	    	
	    	if(isNaN(year)||year.length>4 || parseInt(year)<0)
	    	{
	    		return false;
	    	}
	    	
	    	if(mon == 01 || mon == 03 || mon == 05 || mon == 07 || mon == 08 || mon == 10 || mon == 12)
	    	{
	    		if(day <= 0 || day > 31)
	    		{
	    			return false;
	    		}
	    	}
	    	else if(mon == 04 || mon == 06 || mon == 09 || mon == 11)
	    	{
	    		if(day <= 0 || day > 30)
	    		{
	    			return false;
	    		}
	    	}
	    	else if(mon == 02)
	    	{
	    
	    		if((year%100)==0)
	    		{
	    			if((year%400)==0)
	    			{
	    				if(day <= 0 || day > 29)
	    				{
	    					return false;
	    				}
	    			}
	    			else if(day <= 0 || day > 28)
	    			{
	    				return false;
	    			}
	    		}
	    		else if((year%4)==0)
	    		{
	    			if(day <= 0 || day > 29)
	    			{
	    				return false;
	    			}
	    		}
	    		else if(day <= 0 || day > 28)
	    		{
	    			return false;
	    		}
	    	} 
	    	else
	    	{ 	
	    		return false;
	    	}
	    	
	    	return true;

    }
    
    // Add Guest function
    function ValidateInputAddGuest(tblID)
    {  
        var totalRows = tblID.rows.length;
        var rowCount;
        var noOfGuests = 0;
        var guestList = "";
        
        for(rowCount = 2; rowCount < totalRows ; rowCount = rowCount + 2)
        {
            try
            {
                guestName = fnTrim(tblID.rows[rowCount].cells[0].getElementsByTagName("input")[0].value);
                guestEmail = fnTrim(tblID.rows[rowCount].cells[2].getElementsByTagName("input")[0].value);
            }
            catch(e)
            {
                guestName = fnTrim(tblID.rows[rowCount].childNodes[0].getElementsByTagName("input")[0].value);
                guestEmail = fnTrim(tblID.rows[rowCount].childNodes[2].getElementsByTagName("input")[0].value);
            }
            
            if(guestName != "" && guestEmail == "")
            {
                alert("Sorry! You must enter a valid Email Address.");
                try
                {
                    tblID.rows[rowCount].cells[2].getElementsByTagName("input")[0].focus();
                }
                catch(e)
                {
                    tblID.rows[rowCount].childNodes[2].getElementsByTagName("input")[0].focus();
                }                    
                return false;
            }
            else if(guestName != "" && guestEmail != "")
            {
                var tmpNameCtrl = "";
                try
                {
                    tmpNameCtrl = tblID.rows[rowCount].cells[0].getElementsByTagName("input")[0];
                }
                catch(e)
                {
                    tmpNameCtrl = tblID.rows[rowCount].childNodes[0].getElementsByTagName("input")[0];                    
                }                    
                if(fnValidateEviteNamesField(tmpNameCtrl) == false)
                {
                    alert("Sorry! You must enter a valid Guest Name.");
                    try
                    {
                        tblID.rows[rowCount].cells[0].getElementsByTagName("input")[0].focus();
                    }
                    catch(e)
                    {
                        tblID.rows[rowCount].childNodes[0].getElementsByTagName("input")[0].focus();                                                
                    }                                                
                    return false;
                }
                var tmpEmailCtrl = "";
                try
                {
                    tmpEmailCtrl = tblID.rows[rowCount].cells[2].getElementsByTagName("input")[0];
                }
                catch(e)
                {
                    tmpEmailCtrl = tblID.rows[rowCount].childNodes[2].getElementsByTagName("input")[0];
                }                    
                if(fnValidateEmail(tmpEmailCtrl) == false)
                {
                    return false;
                }
                if(document.getElementById("hdnHostEmail").value == guestEmail)
                {
                    alert("There's no need to invite yourself to your own event as you are already the host");
                    return false;
                }
                guestList += guestName + "^";
                guestList += guestEmail + "|";
                noOfGuests += 1;
            }        
        }
        
        var txtBox = document.getElementById("hdnGuestList");
        if(noOfGuests == 0)
        {
            txtBox.value = "";
            alert("At least one Guest is required.");
            return false;
        }
        else
        {
            txtBox.value = (guestList.substring(0,guestList.length-1));
        }   
        return true;
        window.close();
    }
    
    function CompareDate(p_sEventDate)
    {
        var eventDate = new Date(p_sEventDate);
        var currentDate = new Date();
        var boolValidDate    = true;
        if(eventDate - currentDate > 0)
        {
            boolValidDate = true;
        }
        else
        {
            if(eventDate.getDate() == currentDate.getDate() && eventDate.getMonth() == currentDate.getMonth() && eventDate.getFullYear() == currentDate.getFullYear())
            {
                boolValidDate = true;
            }
            else
            {
                boolValidDate = false;
            }
        }
        return boolValidDate;
    }
    
    function fnCheckForFutureTime(p_dEventDate, p_iEventHr, p_iEventMin, p_sEventMeridian)
    {
        var l_iAbsTime;
        var eventDate = new Date(p_dEventDate);
        var currentDate = new Date();
        var boolValidTime    = false;
        
        if(p_iEventHr == '12')
        {
            p_iEventHr = '0';
        }
        
        if(p_sEventMeridian == 'PM')
        {
            p_iEventHr = parseInt(p_iEventHr,10) + 12;
        }
        l_iAbsTime = (p_iEventHr * 60) + parseInt(p_iEventMin,10);
        
        l_iAbsTime = eventDate.getTime() + (l_iAbsTime * 60 * 1000);
        if(eventDate - currentDate > 0)
        {
            boolValidTime = true;
        }
        else if(l_iAbsTime > currentDate.getTime())
        {
            boolValidTime = true;
        }
        
        return boolValidTime;
    }

    function fnValidateEviteNamesField( p_oField )
    {
        var l_bPassed = true;
        var l_sNamesField = fnTrim(p_oField.value);
        var l_iLength = l_sNamesField.length;
        var l_iCnt;
        var l_sRE = "[a-zA-Z\' ]";
        var l_arrNamesField;
        
        p_oField.value = l_sNamesField;
        
        for (l_iCnt = 0; l_iCnt < l_iLength; l_iCnt++)
        {
            l_sChar = l_sNamesField.charAt(l_iCnt);
            if(l_sChar.match(RegExp(l_sRE, "ig")) == null)
            {
                l_bPassed = false;
                break;
            }
        }
        
        if(!l_bPassed)
        {
            return false;
        }
        else
        {
            return true;
        }
    }

    function  fnHasSplCharacter(p_sString)
    {
        var regularExp;
	    regularExp = /[<"&%\\>^~]/ ;
	    if (regularExp.test(p_sString))
	    {
		    return true;
	    }
 	    return false;	

    }
    
    // To validate non-required fields in the event details page
    function fnValidateNonReqFields()
    {
         var l_bPassed = true;
         
         if( document.getElementById( "_ctl0_oContainer_Main_txtPhone" ).value != "" )
         {
             if( fnValidateTelephoneNo( document.getElementById( "_ctl0_oContainer_Main_txtPhone" ).value ) == false )
             {
                alert("Sorry! You must enter a valid Telephone Number.");
                document.getElementById( "_ctl0_oContainer_Main_txtPhone" ).focus();
                l_bPassed = false;
             }
                 
             else if( document.getElementById( "_ctl0_oContainer_Main_txtPhone" ).value < 0 )
             {
                 alert("Sorry! You must enter a valid Telephone Number.");
                 document.getElementById( "_ctl0_oContainer_Main_txtPhone" ).focus();
                 l_bPassed = false;
             }
          }
                
          else if( document.getElementById( "_ctl0_oContainer_Main_txtEventName" ).value != "" )
          {
             if( fnHasSplCharacter( document.getElementById( "_ctl0_oContainer_Main_txtEventName" ) ) == true )
             {
                 alert("Sorry! You must enter a valid Event Name.");
                 document.getElementById( "_ctl0_oContainer_Main_txtEventName" ).focus();
                 l_bPassed = false;
             }
          }
                
          else if( document.getElementById( "_ctl0_oContainer_Main_txtMessage" ).value != "" )
          {
              if( fnHasSplCharacter( document.getElementById( "_ctl0_oContainer_Main_txtMessage" ) ) == true )
              {
                 alert("Sorry! You must enter a valid Message.");
                 document.getElementById( "_ctl0_oContainer_Main_txtMessage" ).focus();
                 l_bPassed = false;
               }  
          }
          
          return l_bPassed;
    }
    
    function fnValidateRSVP()
    {
        if(fnValidateEviteNamesField(document.getElementById("_ctl0_oContainer_Main_txtGuestName")) == false)
         {
            alert("Sorry! You must enter a valid Name.");
            document.getElementById("_ctl0_oContainer_Main_txtGuestName").focus();
            return false;
         }
         
         if( fnValidateEmail( document.getElementById("_ctl0_oContainer_Main_txtGuestEmailID") ) == false )
         {
            return false;
         }
         
         if( fnValidateInteger( document.getElementById("_ctl0_oContainer_Main_txtTotalGuests").value ) == false )
         {
            alert("Sorry! You must enter a valid Number of Guests.");
            document.getElementById("_ctl0_oContainer_Main_txtTotalGuests").focus();
            return false;
         }
         
         if(document.getElementById("_ctl0_oContainer_Main_rdoInviteeAttendYes").checked || document.getElementById("_ctl0_oContainer_Main_rdoInviteeAttendMayBe").checked)
         {
            if(parseInt(document.getElementById("_ctl0_oContainer_Main_txtTotalGuests").value) <= 0)
             {
                alert("Please enter a non-zero value for the number of guests");
                document.getElementById("_ctl0_oContainer_Main_txtTotalGuests").focus();
                return false;
             }
         }
         return true;
    }
    
    // Display RSVP Comments
    function fnShowRSVPComment(p_iGuestID)
    {
         var l_oDiv;
        //Hide Last Comments
        var l_sLastGuest = document.getElementById('hidf_LastGuestId').value;
        if(l_sLastGuest != "")
        {
            l_oDiv = document.getElementById('divRSVPComment' + l_sLastGuest);
            if(l_oDiv)
            {
                l_oDiv.style.visibility = "hidden";
            }
        }

        //Show Current Comments
        l_oDiv = document.getElementById('divRSVPComment' + p_iGuestID);
        if(l_oDiv)
        {
            l_oDiv.style.visibility = "visible";
            document.getElementById('hidf_LastGuestId').value = p_iGuestID;
        }
    }
    //Hide RSVP Comments
    function fnHideRSVPComment()
    {
        var l_oDiv;
        l_oDiv = document.getElementById('divRSVPComment' + document.getElementById('hidf_LastGuestId').value);
        if(l_oDiv)
        {
              l_oDiv.style.visibility = "hidden";
              document.getElementById('hidf_LastGuestId').value = "";
        }
    }
    
	function fnChangeResponse(p_sType)
    {
        var txtTotalGuests = document.getElementById("_ctl0_oContainer_Main_txtTotalGuests");

        if(p_sType == "N")
        {
	        txtTotalGuests.value    = "0";
	        txtTotalGuests.disabled = true;
        }
        else
        {
	        txtTotalGuests.disabled = false;
	        txtTotalGuests.value    = "1"; 
        }
    }
    function ValidateSearchInputForUpdate()
    {
        var ctlCity = document.getElementById("_ctl0_oContainer_Main_txtCity");
        var ctlState = document.getElementById("_ctl0_oContainer_Main_ddlState");
        var ctlZip = document.getElementById("_ctl0_oContainer_Main_txtZip");
        var l_strMessage = "";
        var l_bPassed = true;
        
        if(document.getElementById("_ctl0_oContainer_Main_radZip").checked)
        {
            if(fnValidateZipCode(ctlZip)==false)
            {
                l_bPassed = false;
            }
        }
        else if(document.getElementById("_ctl0_oContainer_Main_radCity").checked)
        {
            if(!fnValidateEViteCityState())
            {
                l_bPassed = false;
            }
        }
        else
        {
            l_bPassed = false;
        }
        
        if (!l_bPassed)
        {
            if(l_strMessage != "")
            {
                alert(l_strMessage);
            }
            return false;
        }
        else
        {
            return true;
        }
    }
    
    function fnSaveSelectedRestaurantIdForUpdate()
    {
        var GRIDNAME;
        GRIDNAME = "grdvwLocationResults";
        var flagFieldForRestaurantPopulation;
        flagFieldForRestaurantPopulation = document.getElementById("_ctl0_oContainer_Main_hdnRestaurantPrePopulated");
        flagFieldForRestaurantPopulation.value = "0";
        
        var arrInputElements = document.getElementsByTagName("INPUT");
        var index = -1;
        var j = -1;
        for (i=0; i < arrInputElements.length; i++)
        {
            if ((arrInputElements[i].type == "radio") && (arrInputElements[i].id.indexOf("grdvwLocationResults") != -1))
            {
                j++;
                if (arrInputElements[i].checked)
                {
                    index = j;
                    break;
                 }
            }
        }
        
        if(index != -1)
        {
            document.getElementById("_ctl0_oContainer_Main_hdnRestaurantID").value = document.getElementsByName("RestaurantID")[index].innerHTML;
        }
        return true;
    }
    
    //Update Invitation Validation
    
    function fnValidateUpdateFields()
    { 
        var l_oRadioButtonValue=document.getElementById("_ctl0_oContainer_Main_hidf_Radvalue");
        var l_sRadioButtonValue=fnTrim(l_oRadioButtonValue.value);
        var l_sRadiobuttons=true;
        l_sRadiobuttons = ManageGroupRadioButtons();
        
        if(document.getElementById('_ctl0_oContainer_Main_radZip').checked==true && document.getElementById('_ctl0_oContainer_Main_txtZip').value == "" && l_sRadioButtonValue == "N" )
        {
            return false;
        }
        if((document.getElementById('_ctl0_oContainer_Main_radCity').checked==true && document.getElementById('_ctl0_oContainer_Main_txtCity').value == "" && l_sRadioButtonValue == "N") || (document.getElementById('_ctl0_oContainer_Main_radCity').checked==true && document.getElementById('_ctl0_oContainer_Main_ddlState').value == ""  && l_sRadioButtonValue == "N" ))
        {
             return false;
        }
        if(l_sRadioButtonValue == "N" )
        {
            alert("Please select a Restaurant first.");
            return false;
        }
        else if(document.getElementById('_ctl0_oContainer_Main_hidf_CurrentLocation').value == "N" && l_sRadioButtonValue == "Y")
        {
            if (ManageGroupRadioButtons())
            {
                
            }
            else
            {
                alert("Please select a Restaurant from the list.");
                return false;
            }
        }
        if( document.getElementById("_ctl0_oContainer_Main_txtDate").value == "" )
         { 
              //Modified by Ankur on 2/15/2007
              //alert("Sorry! You must enter a valid Event Date.");
              alert("Sorry! You must enter a valid Event Date in MM/DD/YYYY format only.");
              //End modification by Ankur on 2/15/2007
              document.getElementById("_ctl0_oContainer_Main_txtDate").focus();
              return false;
         }
         
         else if( fnValidateDate( document.getElementById("_ctl0_oContainer_Main_txtDate").value ) == false )
         {
              //Modified by Ankur on 2/15/2007
              //alert("Sorry! You must enter a valid Event Date.");
              alert("Sorry! You must enter a valid Event Date in MM/DD/YYYY format only.");
              //End modification by Ankur on 2/15/2007
            document.getElementById("_ctl0_oContainer_Main_txtDate").focus();
            return false;
         }
         
         else if(!CompareDate(document.getElementById("_ctl0_oContainer_Main_txtDate").value))
         {
            alert( "Sorry! Event Date cannot be less than Current Date." );
            document.getElementById("_ctl0_oContainer_Main_txtDate").focus();
            return false;
         }
         
         else if( document.getElementById("_ctl0_oContainer_Main_txtTimeHr").value == "" )
         {
            alert("Sorry! You must enter a valid Event Time.");
            document.getElementById("_ctl0_oContainer_Main_txtTimeHr").focus();
            return false;
         }
         
         else if( isNaN( document.getElementById( "_ctl0_oContainer_Main_txtTimeHr" ).value ) )
         {
            alert("Sorry! You must enter a valid Event Time.");
            document.getElementById( "_ctl0_oContainer_Main_txtTimeHr" ).focus();
            return false;
         }
         
         else if( document.getElementById("_ctl0_oContainer_Main_txtTimeHr").value > 12 )
         {
            alert("Sorry! Hour part cannot be greater than 12.");
            document.getElementById("_ctl0_oContainer_Main_txtTimeHr").focus();
            return false;
         }
         
         else if( document.getElementById("_ctl0_oContainer_Main_txtTimeHr").value < 0)
         {
            alert("Sorry! You must enter a valid Event Time.");
            document.getElementById("_ctl0_oContainer_Main_txtTimeHr").focus();
            return false;
         }
         
         else if( document.getElementById("_ctl0_oContainer_Main_txtTimeMin").value == "" )
         {
            alert("Sorry! You must enter a valid Event Time.");
            document.getElementById("_ctl0_oContainer_Main_txtTimeMin").focus();
            return false;
         }
         
         else if( isNaN( document.getElementById( "_ctl0_oContainer_Main_txtTimeMin" ).value ) )
         {
            alert("Sorry! You must enter a valid Event Time.");
            document.getElementById( "_ctl0_oContainer_Main_txtTimeMin" ).focus();
            return false;
         }
         
         else if( document.getElementById("_ctl0_oContainer_Main_txtTimeMin").value > 60 )
         {
            alert("Sorry! Minute part cannot be greater than 60.");
            document.getElementById("_ctl0_oContainer_Main_txtTimeMin").focus();
            return false;
         }
         
         else if( document.getElementById("_ctl0_oContainer_Main_txtTimeMin").value < 0)
         {
            alert("Sorry! You must enter a valid Event Time.");
            document.getElementById("_ctl0_oContainer_Main_txtTimeMin").focus();
            return false;
         }
         else if(!fnCheckForFutureTime(document.getElementById("_ctl0_oContainer_Main_txtDate").value, document.getElementById("_ctl0_oContainer_Main_txtTimeHr").value, document.getElementById( "_ctl0_oContainer_Main_txtTimeMin" ).value, document.getElementById( "_ctl0_oContainer_Main_ddlTime" ).value))
         {
            alert("Sorry! Your event cannot be organized in the past.");
            document.getElementById("_ctl0_oContainer_Main_txtTimeHr").focus();
            return false;
         }
         //Added on Nov 15, 2006
         else if(((document.getElementById("_ctl0_oContainer_Main_txtTimeHr").value < 11 || document.getElementById("_ctl0_oContainer_Main_txtTimeHr").value == 12) && document.getElementById("_ctl0_oContainer_Main_ddlTime").value == "AM") || ((document.getElementById("_ctl0_oContainer_Main_txtTimeHr").value > 9 && document.getElementById("_ctl0_oContainer_Main_txtTimeHr").value <= 11) && document.getElementById("_ctl0_oContainer_Main_ddlTime").value == "PM"))
         {
                alert("Sorry! Your event should occur between 11 A.M. and 9 P.M.");
                document.getElementById("_ctl0_oContainer_Main_txtTimeHr").focus();
                return false;
         }
         else if(
                (document.getElementById("_ctl0_oContainer_Main_txtTimeHr").value == 9 && parseInt(document.getElementById("_ctl0_oContainer_Main_txtTimeMin").value) > 0) 
                && document.getElementById("_ctl0_oContainer_Main_ddlTime").value == "PM"
                )
         {
                alert("Sorry! Your event should occur between 11 A.M. and 9 P.M.");
                document.getElementById("_ctl0_oContainer_Main_txtTimeHr").focus();
                return false;
         }
         //End of added section
        
        fnSaveSelectedRestaurantIdForUpdate();
    } 
//Functions for Cancel Invitation

function fnCancelEvent(p_sEviteId)
{
        if(navigator.userAgent.toUpperCase().indexOf("MSIE") != -1)
        {
            //For Internet Explorer
            var oNewWindow = window.open('CancelInvitation.aspx?EviteId=' + p_sEviteId, "NewWindow", "width=300,height=210,left=250,top=200,scrollbars=no,resizable=no,location=no,menubar=no,status=no,toolbar=no");
        }
        else
        {
            //For other browsers
            var oNewWindow = window.open('CancelInvitation.aspx?EviteId=' + p_sEviteId, "NewWindow", "width=300,height=210,left=250,top=200,scrollbars=no,resizable=no,location=no,menubar=no,status=no,toolbar=no");
        }
        oNewWindow.focus();
     
}

function fnValidateCancelEventMsg()
{
    if(fnTrim(document.getElementById("txtCancelMessage" ).value) != "")
    {
      if(fnHasSplCharacter(document.getElementById("txtCancelMessage").value))
      {
         alert("Sorry! You must enter a valid Message.");
         document.getElementById("txtCancelMessage").focus();
         return false;
       }
       else
       {
           return true;
       }
    }
    else
    {
        alert("Sorry! You must enter some message.");
        document.getElementById("txtCancelMessage").focus();
        return false;
    }  
}  
//eVite functions ------------------------------------------------------------------------------------------------------

//Show Wallpaper
 function fnOpenWallpaper(Color, Resolution)
{
    var strWallPaperName = "RMG_Wallpaper_" + Color + "_" + Resolution + ".jpg";
    var oNewWindow = window.open("../Downloads/Wallpapers/" + strWallPaperName, "NewWindow", "width=600,height=400,left=100,top=100,scrollbars=yes,resizable=yes,location=no,menubar=no,status=no,toolbar=no");
    oNewWindow.focus();
}

//Show News page
function fnOpenNewsPage(NewsId)
{
    var strURL = "NewsReader.aspx?#" + NewsId;
    var oNewWindow = window.open(strURL, "NewWindow", "width=600,height=400,left=100,top=100,scrollbars=yes,resizable=yes,location=no,menubar=no,status=no,toolbar=no");
	oNewWindow.focus();
}

//Show Franchise site
function fnShowFranchise()
{
    /*Start changes for  MacGrill Divestiture Web Changes on 07/11/2008*/
    //var oNewWindow = window.open("http://www.brinker.com/franchise/default.asp", "NewWindow", "width=800,height=500,left=100,top=100,scrollbars=yes,resizable=yes,toolbar=yes,menubar=yes,location=yes,status=yes");
    //var oNewWindow = window.open("EmplFranOpp.aspx", "NewWindow", "width=800,height=500,left=100,top=100,scrollbars=yes,resizable=yes,toolbar=yes,menubar=yes,location=yes,status=yes");
    /*End changes for  MacGrill Divestiture Web Changes on 07/11/2008*/
    oNewWindow.focus();
}

//Show Employment site
function fnShowEmployment()
{
    var oNewWindow = window.open("http://www.brinkerjobs.com", "NewWindow", "width=800,height=500,left=100,top=100,scrollbars=yes,resizable=yes,toolbar=yes,menubar=yes,location=yes,status=yes");
    oNewWindow.focus();
}

function fnOpenMealOnWheels()
{
    var oNewWindow = window.open("http://www.mowaa.org", "NewWindow", "width=800,height=500,left=100,top=100,scrollbars=yes,resizable=yes,toolbar=yes,menubar=yes,location=yes,status=yes");
    oNewWindow.focus();
}

//Show Survey site
function fnShowTakeTheSurvey(p_sURL)
{
    window.location.href = p_sURL;
}

//Show  Fraudulent Pop-Up
function fnShowFraudulentPopup()
{
    var oNewWindow = window.open("../FraudulentPopup.htm", "NewWindow", "width=400,height=175,left=100,top=100,scrollbars=no,resizable=no,location=no,menubar=no,status=no,toolbar=no");
	oNewWindow.focus();
}

/*start changes for  MacGrill Divestiture Web Changes on 07/11/2008*/

function fnShowTermsPopup()
{
    var oNewWindow = window.open("../terms.htm", "NewWindow", "width=600,height=400,left=100,top=100,scrollbars=yes,resizable=no,location=no,menubar=no,status=no,toolbar=no");
	oNewWindow.focus();
}
/*end changes for  MacGrill Divestiture Web Changes on 07/11/2008*/
//Show  No Fees Pop-Up
//function launchPopUp()
//{
//    var oNewWindow = window.open("../NoFeesPopup.htm", "NewWindow", "width=400,height=130,left=100,top=100,scrollbars=no,resizable=no,location=no,menubar=no,status=no,toolbar=no");
//	oNewWindow.focus();
//}

function fnShowSystemRequirements()
{
   
}
//Start Changes for - Guest contact Changes
//Feedback Form Validation
function fnValidateFeedback()
{
    var l_bPassed = true;
    var l_oFirstName = document.getElementById("_ctl0_oContainer_Main_txtFirst") 
    var l_sFirstName = fnTrim(l_oFirstName.value)
    var l_oLastName = document.getElementById("_ctl0_oContainer_Main_txtLast") 
    var l_sLastName = fnTrim(l_oLastName.value)
    var l_oEmail = document.getElementById("_ctl0_oContainer_Main_txtEmail") 
    var l_sEmail = fnTrim(l_oEmail.value)
    var l_oZipCode = document.getElementById("_ctl0_oContainer_Main_txtZipcode") 
    var l_sZipCode =fnTrim(l_oZipCode.value)
    var l_oCheckNum = document.getElementById("_ctl0_oContainer_Main_txtCheckNum") 
    var l_sCheckNum =fnTrim(l_oCheckNum.value)
    
    
    if(fnTrim(document.getElementById("_ctl0_oContainer_Main_ddlLocation").value) == "" && document.getElementById("_ctl0_oContainer_Main_ddlTopics").value == "1")
    {
    alert('Sorry! Location is a required field when you have a compliment or concern.');
    document.getElementById("_ctl0_oContainer_Main_ddlLocation").focus();
    l_bPassed = false;
    }
    

    if(l_bPassed == true && document.getElementById("_ctl0_oContainer_Main_ddlTopics").value == "1")
    {
    
        var l_iMonthVisit   = parseInt(document.getElementById("_ctl0_oContainer_Main_ddlMonV").value, 10);
        var l_iDayVisit     = parseInt(document.getElementById("_ctl0_oContainer_Main_ddlDdV").value, 10);
        var l_iYearVisit    = parseInt(document.getElementById("_ctl0_oContainer_Main_ddlYyV").value, 10);
        
        if((l_iMonthVisit == 0) && ( l_iDayVisit == 0) && (l_iYearVisit == 0))
        {
            alert('Sorry! Date of Visit is a required field when you have a compliment or concern.');
            document.getElementById("_ctl0_oContainer_Main_ddlMonV").focus();
            l_bPassed = false;
        }
        else if(l_iMonthVisit == 0) 
        {
            alert("Sorry! You must enter a valid Date of Visit.");
            document.getElementById("_ctl0_oContainer_Main_ddlMonV").focus();
            l_bPassed = false;
        }
        else if( l_iDayVisit == 0) 
        {
            alert("Sorry! You must enter a valid Date of Visit.");
            document.getElementById("_ctl0_oContainer_Main_ddlDdV").focus();
            l_bPassed = false;
        }
        else if(l_iYearVisit == 0) 
        {
            alert("Sorry! You must enter a valid Date of Visit.");
            document.getElementById("_ctl0_oContainer_Main_ddlYyV").focus();
            l_bPassed = false;
        }
        
        else if(((l_iMonthVisit == 4) || (l_iMonthVisit == 6) || (l_iMonthVisit == 9) || (l_iMonthVisit == 11)) && (l_iDayVisit > 30))
        {
            alert("Sorry! You must enter a valid Date of Visit.");
            document.getElementById("_ctl0_oContainer_Main_ddlDdV").focus();
            l_bPassed = false;
        }
        else if((l_iMonthVisit == 2) && (l_iYearVisit % 4 == 0) && (l_iDayVisit > 29))
        {
            alert("Sorry! You must enter a valid Date of Visit.");
            document.getElementById("_ctl0_oContainer_Main_ddlDdV").focus();
            l_bPassed = false;
        }
        else if((l_iMonthVisit == 2) && (l_iYearVisit % 4 != 0) && (l_iDayVisit > 28))
        {
            alert("Sorry! You must enter a valid Date of Visit.");
            document.getElementById("_ctl0_oContainer_Main_ddlDdV").focus();
            l_bPassed = false;
        }
        else if((l_iMonthVisit == 2) && (l_iYearVisit % 100 == 0) && (l_iYearVisit % 400 != 0) && (l_iDayVisit > 28))
        {
            alert("Sorry! You must enter a valid Date of Visit.");
            document.getElementById("_ctl0_oContainer_Main_ddlDdV").focus();
            l_bPassed = false;
        }
    }
    
    //Start changes for Contact Form Updates 04/17/2009
    if(document.getElementById("_ctl0_oContainer_Main_ddlTopics").value == "3")
    {
        var cardNumer = document.getElementById("_ctl0_oContainer_Main_txtGiftCardNum").value;
        if(cardNumer == "")
        {
            alert("Sorry! You must enter a Gift Card Number.");
            document.getElementById("_ctl0_oContainer_Main_txtGiftCardNum").focus();
            l_bPassed = false;
        }
        else 
        {
            if (IsGiftCardNumberValid(cardNumer) == true) 
            {
                if (cardNumer.length < 16) 
                {
                    alert("The gift card number should be 16 digit");
                    document.getElementById("_ctl0_oContainer_Main_txtGiftCardNum").focus();
                    return false;
                }
            }
            else 
            {
                alert("Sorry, the gift card number can be numberic characters only");
                document.getElementById("_ctl0_oContainer_Main_txtGiftCardNum").focus();
                return false;
            }
        }
    }
    
    //End changes for Contact Form Updates 04/17/2009
     

        
        
    if(l_bPassed == true)
    {
        var l_iMonthVisit   = parseInt(document.getElementById("_ctl0_oContainer_Main_ddlMonV").value, 10);
        var l_iDayVisit     = parseInt(document.getElementById("_ctl0_oContainer_Main_ddlDdV").value, 10);
        var l_iYearVisit    = parseInt(document.getElementById("_ctl0_oContainer_Main_ddlYyV").value, 10);

        if((l_iMonthVisit != 0) || ( l_iDayVisit != 0) || (l_iYearVisit != 0))
        {
            if(l_iMonthVisit == 0) 
            {
                alert("Sorry! You must enter a valid Date of Visit.");
                document.getElementById("_ctl0_oContainer_Main_ddlMonV").focus();
                l_bPassed = false;
            }
            else if( l_iDayVisit == 0) 
            {
                alert("Sorry! You must enter a valid Date of Visit.");
                document.getElementById("_ctl0_oContainer_Main_ddlDdV").focus();
                l_bPassed = false;
            }
            else if(l_iYearVisit == 0) 
            {
                alert("Sorry! You must enter a valid Date of Visit.");
                document.getElementById("_ctl0_oContainer_Main_ddlYyV").focus();
                l_bPassed = false;
            }
            
            else if(((l_iMonthVisit == 4) || (l_iMonthVisit == 6) || (l_iMonthVisit == 9) || (l_iMonthVisit == 11)) && (l_iDayVisit > 30))
            {
                alert("Sorry! You must enter a valid Date of Visit.");
                document.getElementById("_ctl0_oContainer_Main_ddlDdV").focus();
                l_bPassed = false;
            }
            else if((l_iMonthVisit == 2) && (l_iYearVisit % 4 == 0) && (l_iDayVisit > 29))
            {
                alert("Sorry! You must enter a valid Date of Visit.");
                document.getElementById("_ctl0_oContainer_Main_ddlDdV").focus();
                l_bPassed = false;
            }
            else if((l_iMonthVisit == 2) && (l_iYearVisit % 4 != 0) && (l_iDayVisit > 28))
            {
                alert("Sorry! You must enter a valid Date of Visit.");
                document.getElementById("_ctl0_oContainer_Main_ddlDdV").focus();
                l_bPassed = false;
            }
            else if((l_iMonthVisit == 2) && (l_iYearVisit % 100 == 0) && (l_iYearVisit % 400 != 0) && (l_iDayVisit > 28))
            {
                alert("Sorry! You must enter a valid Date of Visit.");
                document.getElementById("_ctl0_oContainer_Main_ddlDdV").focus();
                l_bPassed = false;
            }
        }
    }
    
    /* Start changes for guest relation form changes, july 2008*/
    if(l_bPassed == true && fnTrim(document.getElementById("_ctl0_oContainer_Main_ddlPurpose").value) == "" && document.getElementById("_ctl0_oContainer_Main_ddlTopics").value == "1")
    {
        alert('Sorry! Primary Purpose for visit is a required field when you have a compliment or concern.');
        document.getElementById("_ctl0_oContainer_Main_ddlPurpose").focus();
        l_bPassed = false;
    }
    
    
    if(l_bPassed == true && fnTrim(document.getElementById("_ctl0_oContainer_Main_ddlMealType").value) == "" && document.getElementById("_ctl0_oContainer_Main_ddlTopics").value == "1")
    {						
        alert("Sorry! Meal Type is a required field when you have a compliment or concern.");
        document.getElementById("_ctl0_oContainer_Main_ddlMealType").focus();
        l_bPassed = false;
    }
    
    /* End changes for guest relation form changes, july 2008*/
    if(document.getElementById("_ctl0_oContainer_Main_ddlTopics").value == "")
    {
        alert("Sorry! You must select a Topic.");
        document.getElementById("_ctl0_oContainer_Main_ddlTopics").focus();
        l_bPassed = false;
    }
    
    if(l_bPassed == true)
    {
       if(IsNumeric(l_sCheckNum) != true)
        {
            alert("Receipt Check Number can be numberical characters only.");
            l_oCheckNum.focus();
            l_bPassed = false;
        }
        else if(document.getElementById("_ctl0_oContainer_Main_ddlTitle").selectedIndex == "0")
        {
            alert("Sorry! You must select a Title.");
            document.getElementById("_ctl0_oContainer_Main_ddlTitle").focus();
           l_bPassed = false;
        }
        else if(l_sFirstName == "")
        {
            alert("Sorry! You must enter a valid First Name.");
            l_oFirstName.focus();
           l_bPassed = false;
        }
        else if(fnValidateNamesField(l_oFirstName)==false)
        {
            l_bPassed = false;
        }
        
        else if(l_sLastName == "")
        {
            alert("Sorry! You must Enter a valid Last Name.");
            l_oLastName.focus();
            l_bPassed = false;
        }
        else if(fnValidateNamesField(l_oLastName)==false)
        {
           l_bPassed = false;
        }
        else if(l_sEmail == "")
        {
            alert("Sorry! You must enter a valid Email Address.");
            l_oEmail.focus();
            l_bPassed = false;
        }
        else if(fnValidateEmail(l_oEmail)==false)
        {
           l_bPassed = false; 
        }
        else if(l_sZipCode == "")
        {
            alert("Sorry! You must enter a valid Zip Code.");
            l_oZipCode.focus();
            l_bPassed = false;
        }
        else if(fnValidateZipCode(l_oZipCode)==false)
        {
            l_bPassed = false;
        }
        else
        {
            document.getElementById('_ctl0_oContainer_Main_hidf_Feedback').value = "Y";
	        document.aspnetForm.submit();
        }
    }
    return l_bPassed;
}
//End changes for Guest contact form changes

//Validate if sText is a number
function IsNumeric(sText)
	{
	   var ValidChars = "0123456789.";
	   var IsNumber=true;
	   var Char;


	   for (i = 0; i < sText.length && IsNumber == true; i++)
	      {
	      Char = sText.charAt(i);
	      if (ValidChars.indexOf(Char) == -1)
		 {
		 IsNumber = false;
		 }
	      }
	   return IsNumber;
	}


//Validate Names Field in Feedback Form
function fnValidateNamesField(p_oField)
{
    var l_bPassed = true;
    var l_sNamesField = fnTrim(p_oField.value);
    var l_iLength = l_sNamesField.length;
    var l_iCnt;
    //var l_sRE = "[a-zA-Z\']";
    var l_sRE = "[a-zA-Z0-9\'& ]";
    var l_arrNamesField;
    
    p_oField.value = l_sNamesField;
    
    for (l_iCnt = 0; l_iCnt < l_iLength; l_iCnt++)
    {
        l_sChar = l_sNamesField.charAt(l_iCnt);
        if(l_sChar.match(RegExp(l_sRE, "ig")) == null)
        {
            l_bPassed = false;
            break;
        }
    }
    if(!l_bPassed)
    {
        alert ("Sorry! You must enter a valid Name.");
        p_oField.focus();
        return false;
    }
    else
    {
        return true;
    }
}

// Text Area text counter
function charCount() 
{
    var l_oTxtAra = document.getElementById("_ctl0_oContainer_Main_txtareaComment")
    var l_sTxtAra = l_oTxtAra.value;
    var l_iCntFld = document.getElementById("_ctl0_oContainer_Main_cntfield");
    var l_vCntFld = parseInt(l_iCntFld.value, 10);
    var l_iMaxLimit = 1200
    if (l_sTxtAra.length > l_iMaxLimit)
    {
        l_oTxtAra.value = l_oTxtAra.value.substring(0, l_iMaxLimit);
        document.getElementById("_ctl0_oContainer_Main_txtareaComment").focus();
        return false;
    } 
    else
    {
           l_iCntFld.value = l_iMaxLimit - l_sTxtAra.length;
    }
}

//Validate if sText is a number and greater than zero
function IsValidDate(sText)
	{
	   if(sText == "")
	     return false;
	     
	   var ValidChars = "0123456789";
	   var IsNumber=true;
	   var Char;

	   for (i = 0; i < sText.length && IsNumber == true; i++)
	      {
	          Char = sText.charAt(i);
	          if (ValidChars.indexOf(Char) == -1)
		         {
		            IsNumber = false;
		         }
	      }
	      
	   if(IsNumber)
	    {
	        var number = parseInt(sText);
	        if(number <= 0)
	            {
	                return false;
	            }
	    }   
	      
	   return IsNumber;
	}
	
//GSS Contact Form Validation
function fnValidateGSSForm()
{
    var l_bPassed = true;
    var l_oFirstName = document.getElementById("_ctl0_oContainer_Main_txtFirst") 
    var l_sFirstName = fnTrim(l_oFirstName.value)
    var l_oLastName = document.getElementById("_ctl0_oContainer_Main_txtLast") 
    var l_sLastName = fnTrim(l_oLastName.value)
    var l_oEmail = document.getElementById("_ctl0_oContainer_Main_txtEmail") 
    var l_sEmail = fnTrim(l_oEmail.value)
    var l_oZipCode = document.getElementById("_ctl0_oContainer_Main_txtZipcode") 
    var l_sZipCode = fnTrim(l_oZipCode.value)
    var l_oCity = document.getElementById("_ctl0_oContainer_Main_txtCity") 
    var l_sCity = fnTrim(l_oCity.value)
    var l_oState = document.getElementById("_ctl0_oContainer_Main_ddlState")
    var l_sState = l_oState.value
    
    //Start Changes GSS Required Field - Offshore - on date 09/12/2008
    
    var l_oLocation = document.getElementById("_ctl0_oContainer_Main_txtLocation")
    var l_sLOcation = fnTrim(l_oLocation.value)
    
    var l_oCheckNumber = document.getElementById("_ctl0_oContainer_Main_txtChkNo")
    var l_sCheckNumber = fnTrim(l_oCheckNumber.value)
    
    var l_oMonDDate = document.getElementById("_ctl0_oContainer_Main_txtMonDDate")
    var l_sMonDDate = fnTrim(l_oMonDDate.value)
    
    var l_oDayDDate = document.getElementById("_ctl0_oContainer_Main_txtDayDDate")
    var l_sDayDDate = fnTrim(l_oDayDDate.value)
    
    var l_oYrDDate = document.getElementById("_ctl0_oContainer_Main_txtYrDDate")
    var l_sYrDDate = fnTrim(l_oYrDDate.value)
    
    //End Changes GSS Required Field - Offshore - on date 09/12/2008
     
        if(l_sFirstName == "")
        {
            alert("Sorry! You must enter a valid First Name.");
            l_oFirstName.focus();
           l_bPassed = false;
        }
        else if(l_sLastName == "")
        {
            alert("Sorry! You must enter a valid Last Name.");
            l_oLastName.focus();
            l_bPassed = false;
        }

        else if(l_sEmail == "")
        {
            alert("Sorry! You must enter a valid Email Address.");
            l_oEmail.focus();
            l_bPassed = false;
        }
        else if(Emailformvalidation(l_oEmail)==false)
        {
           l_bPassed = false; 
        }
        else if(l_sCity == "")
        {
            alert("Sorry! You must enter a valid City name.");
            l_oCity.focus();
            l_bPassed = false;
        }
        else if(l_sState == "")
        {        
            alert("Sorry! You must select a State");
            document.getElementById("_ctl0_oContainer_Main_ddlState").focus();
            l_bPassed = false;
        }
        else if(!fnValidateZipCode(l_oZipCode))
        {
            l_bPassed = false;
        }
        
        //Start Changes GSS Required Field - Offshore - on date 09/12/2008
        
        else if(l_sLOcation == "")
        {
            alert("Sorry! You must enter a valid Restaurant Location.");
            l_oLocation.focus();
            l_bPassed = false;
        }
        else if(l_sCheckNumber == "")
        {
            alert("Sorry! You must enter a valid Check Number.");
            l_oCheckNumber.focus();
            l_bPassed = false;
        }
        else if(IsValidDate(l_sMonDDate) != true)
        {
            alert("Sorry! You must enter a valid Dine Date Month.");
            l_oMonDDate.focus();
            l_bPassed = false;
        }
        
        else if(IsValidDate(l_sDayDDate) != true)
        {
            alert("Sorry! You must enter a valid Dine Date Day.");
            l_oDayDDate.focus();
            l_bPassed = false;
        }
        else if(IsValidDate(l_sYrDDate) != true)
        {
            alert("Sorry! You must enter a valid Dine Date Year.");
            l_oYrDDate.focus();
            l_bPassed = false;
        }
        
        //End Changes GSS Required Field - Offshore - on date 09/12/2008
        
        else
        {
            document.getElementById('_ctl0_oContainer_Main_hidf_GSSContact').value = "Y";
	        document.aspnetForm.submit();
        }
    
    return l_bPassed;
}

//GSS Contact Form Email Validation
function Emailformvalidation(p_oField)
{
    if(!fnValidateEmail(p_oField))
    {
        return false;
    }
    else
	{
	    return true;
	}
}

// To check whether the giftcard image is clicked and set a flag
function fnGiftCardClicked()
{
    document.getElementById("_ctl0_oContainer_hidf_GiftCard").value = "Y";
    document.getElementById("_ctl0_oContainer_hidf_EVite").value = "N";
    document.aspnetForm.submit();
}

// To check whether the Invitation image is clicked and set a flag
function fnEViteClicked()
{
    document.getElementById("_ctl0_oContainer_hidf_EVite").value = "Y";
    document.getElementById("_ctl0_oContainer_hidf_GiftCard").value = "N";
    document.aspnetForm.submit();
}
//Start changes : Deepali, 18/4/2008
function fnEviteFrmFunNews()
{
    document.getElementById("_ctl0_oContainer_Main_hidf_EVite").value = "Y";
    document.aspnetForm.submit();
}
// End changes : Deepali, 18/4/2008
function fnRadioButtonClicked(strType)
{
    if(strType == "Zip")
    {
        document.getElementById("_ctl0_oContainer_Main_txtZip").disabled = false;
        document.getElementById("_ctl0_oContainer_Main_txtCity").disabled = true;
        document.getElementById("_ctl0_oContainer_Main_txtCity").value = "";
        document.getElementById("_ctl0_oContainer_Main_ddlState").disabled = true;
        document.getElementById("_ctl0_oContainer_Main_ddlState").selectedIndex = 0;
    }
    if(strType == "City")
    {
        document.getElementById("_ctl0_oContainer_Main_txtZip").value = "";
        document.getElementById("_ctl0_oContainer_Main_txtCity").disabled = false;
        document.getElementById("_ctl0_oContainer_Main_ddlState").disabled = false;
        document.getElementById("_ctl0_oContainer_Main_txtZip").disabled = true;
    }
}

//Display Fun News System Requirements
function fnShowSysReq()
{
    var l_oDiv;
    l_oDiv = document.getElementById('divSysReq');
    
    if(l_oDiv)
    {
        l_oDiv.style.visibility = "visible";
    }
}

//Hide Fun News System Requirements
function fnHideSysReq()
{
    var l_oDiv;
    l_oDiv = document.getElementById('divSysReq');
    
    if(l_oDiv)
    {
        l_oDiv.style.visibility = "hidden";
    }
}
//---------------------------------------------------- E-Mail Validations -----------------------------------------------------//
function charOccurences(argString, argChar) {
	var intCt = 0

	for(var intI=0; intI < argString.length; intI++)
		if (argString.charAt(intI) == argChar)
			intCt++
	
	return intCt
}

function fnValidateEmail(p_oField) 
{
    var argEmail = fnTrim(p_oField.value);
	if (charOccurences(argEmail, '@') + charOccurences(argEmail, '.') < 2)
	{
	    alert ("Sorry! You must enter a valid Email Address.");
        p_oField.focus();
		return false
	}

	var atPos = argEmail.indexOf('@')
	var dotPos = argEmail.indexOf('.')

	if((atPos == 0) || (atPos == (argEmail.length - 1)))
	{
	    alert ("Sorry! You must enter a valid Email Address.");
        p_oField.focus();
		return false;
	}

	if((dotPos == 0) || (dotPos == (argEmail.length - 1)))
	{
	    alert ("Sorry! You must enter a valid Email Address.");
        p_oField.focus();
		return false;
    }		
	
	var checkTLD=1;
 
	var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|COM|NET|ORG|EDU|INT|MIL|GOV|ARPA|BIZ|AERO|NAME|COOP|INFO|PRO|MUSEUM)$/;
 
	var emailPat=/^(.+)@(.+)$/;
 
	var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
 
 
	var validChars="\[^\\s" + specialChars + "\]";
 
 
	var quotedUser="(\"[^\"]*\")";
 
 
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
 
 
	var atom=validChars + '+';
 
	var word="(" + atom + "|" + quotedUser + ")";
 
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
 
 
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
 
 
 
	var matchArray=argEmail.match(emailPat);
 
	if (matchArray==null)
		{
		alert ("Sorry! You must enter a valid Email Address.");
        p_oField.focus();
		return false;
		}
	var user=matchArray[1];
	var domain=matchArray[2];
 
	for (i=0; i<user.length; i++)
		{
		if (user.charCodeAt(i)>127)
			{
			alert ("Sorry! You must enter a valid Email Address.");
            p_oField.focus();
			return false;
			}
		}
	for (i=0; i<domain.length; i++)
		{
		if (domain.charCodeAt(i)>127)
			{
			alert ("Sorry! You must enter a valid Email Address.");
            p_oField.focus();
			return false;
			}
		}
 
	if (user.match(userPat)==null)
		{
		alert ("Sorry! You must enter a valid Email Address.");
        p_oField.focus();
		return false;
	}
 
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null)
		{
		for (var i=1;i<=4;i++)
			{
			if (IPArray[i]>255)
				{
				alert ("Sorry! You must enter a valid Email Address.");
                p_oField.focus();
				return false;
				}
			}
		return true;
		}
 
 
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=domain.split(".");
	var len=domArr.length;
	for (i=0;i<len;i++)
		{
		if (domArr[i].search(atomPat)==-1)
			{
			alert ("Sorry! You must enter a valid Email Address.");
            p_oField.focus();
			return false;
			}
		}
 
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1)
		{
		alert ("Sorry! You must enter a valid Email Address.");
        p_oField.focus();
		return false;
		}
 
	if (len<2)
		{
		alert ("Sorry! You must enter a valid Email Address.");
        p_oField.focus();
		return false;
		}
 
	return true;
}
/*start changes for  MacGrill Divestiture Web Changes on 07/11/2008*/

/*Franchise Request Consideration Form Validation*/

function fnValidateFranchiseForm()
{
    var l_bPassed = true;
    var l_oCompanyName = document.getElementById("_ctl0_oContainer_Main_txtCompanyName"); 
    var l_sCompanyName = fnTrim(l_oCompanyName.value);
    var l_oPrincipalName = document.getElementById("_ctl0_oContainer_Main_txtPrincipalName"); 
    var l_sPrincipalName = fnTrim(l_oPrincipalName.value);
    var l_oAddress = document.getElementById("_ctl0_oContainer_Main_txtAddress") ;
    var l_sAddress = fnTrim(l_oAddress.value);
    var l_oCity = document.getElementById("_ctl0_oContainer_Main_txtCityName"); 
    var l_sCity =fnTrim(l_oCity.value);
    var l_oZipcode = document.getElementById("_ctl0_oContainer_Main_textZipcode"); 
    var l_sZipcode =fnTrim(l_oZipcode.value);
    var l_oPhone = document.getElementById("_ctl0_oContainer_Main_txtPhone"); 
    var l_sPhone =fnTrim(l_oPhone.value);
    var l_oEmail = document.getElementById("_ctl0_oContainer_Main_email"); 
    var l_sEmail =fnTrim(l_oEmail.value);
    var l_oYearsofOwner = document.getElementById("_ctl0_oContainer_Main_yearsOfExp"); 
    var l_sYearsofOwner =fnTrim(l_oYearsofOwner.value);
    var l_oYearsofExp = document.getElementById("_ctl0_oContainer_Main_yearsOfExpinLocalMarket") ;
    var l_sYearsofExp =fnTrim(l_oYearsofExp.value);
    
    
    if( l_bPassed = true)
    {
        if(l_sCompanyName == "")
        {
            alert("Sorry! You must enter a valid Company Name.");
            l_oCompanyName.focus();
            l_bPassed = false;
        }
        else if(fnValidateNamesField(l_oCompanyName)==false)
        {
            l_bPassed = false;
        }
        else if(l_sPrincipalName == "")
         {
            alert("Sorry! You must enter a valid principal Name.");
            l_oPrincipalName.focus();
            l_bPassed = false;
        }
        else if(fnValidateNamesField(l_oPrincipalName)==false)
        {
            l_bPassed = false;
        }
        else if(l_sAddress == "")
        {
            alert("Sorry! You must enter an address.");
            l_oAddress.focus();
            l_bPassed = false;
        }      
        else if(l_sCity == "")
         {
            alert("Sorry! You must enter a valid city.");
            l_oCity.focus();
            l_bPassed = false;
        }       
        else if(document.getElementById("_ctl0_oContainer_Main_stateDDList").selectedIndex == "0")
        {
            alert("Sorry! You must select a State.");
            document.getElementById("_ctl0_oContainer_Main_stateDDList").focus();
            l_bPassed = false;
        }
        else if(l_sZipcode == "")
        {
            alert("Sorry! You must enter a valid Zip Code.");
            l_oZipcode.focus();
            l_bPassed = false;
        }  
        else if(fnValidateZipCode(l_oZipcode)== false)
        {                
           l_bPassed = false; 
        }
             
        else if(document.getElementById("_ctl0_oContainer_Main_countryDDList").selectedIndex == "0")
        {
            alert("Sorry! You must select a country.");
            document.getElementById("_ctl0_oContainer_Main_countryDDList").focus();
            l_bPassed = false;
        }       
        else if(l_sPhone == "")
        {
            alert("Sorry! You must enter a valid Phone Number.");
            l_oPhone.focus();
            l_bPassed = false;
        }
         else if(l_sEmail == "")
         {
            alert("Sorry! You must enter a valid email address.");
            l_oEmail.focus();
            l_bPassed = false;
        }
        else if(fnValidateEmail(l_oEmail)== false)
        {
                
           l_bPassed = false; 
        }  
        
        else if(document.getElementById("_ctl0_oContainer_Main_DropDownList1").selectedIndex == "0")
         {
            alert("Sorry! You must select a Market interest.");
            document.getElementById("_ctl0_oContainer_Main_DropDownList1").focus();
            l_bPassed = false;
        }
        else if(l_sYearsofOwner == "")
         {
            alert("Sorry! You must enter a valid years of owner.");
            l_oYearsofOwner.focus();
            l_bPassed = false;
        }
        else if( !fnValidateInteger(l_sYearsofOwner))
        {
            alert("Sorry! You must enter a valid years of owner.");
            l_oYearsofOwner.focus();
            l_bPassed = false;
        }
         else if(l_sYearsofExp == "")
         {
            alert("Sorry! You must enter a valid years of experience.");
            l_oYearsofExp.focus();
            l_bPassed = false;
        }
        else if( !fnValidateInteger(l_sYearsofExp))
        {
            alert("Sorry! You must enter a valid years of owner.");
            l_oYearsofOwner.focus();
            l_bPassed = false;
        }            
    }    
    return l_bPassed;   
    
}

/*End changes for  MacGrill Divestiture Web Changes on 07/11/2008*/

/*Start changes for Contact Form Updates 04/17/2009*/
function TopicOnChange()
{
    var txtGiftCardNum = document.getElementById("_ctl0_oContainer_Main_txtGiftCardNum");
   
    if (document.getElementById("_ctl0_oContainer_Main_ddlTopics").selectedIndex == "3")
    {   
	    txtGiftCardNum.disabled = false;
	    txtGiftCardNum.style.background ="white";

    }
    else
    {
        txtGiftCardNum.value = "";
        txtGiftCardNum.disabled = true;
        txtGiftCardNum.style.background ="#B3B3B3";
    }
}
function IsGiftCardNumberValid(sText) 
{
    var ValidChars = "0123456789";
    var IsValidNumber = true;
    var Char;

    for (i = 0; i < sText.length && IsValidNumber == true; i++) 
    {
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1) 
        {
            IsValidNumber = false;
        }
    }
    return IsValidNumber;
}

/*Start changes for Contact Form Updates 04/17/2009*/
