﻿// JScript File
    var ShowPopUp = false;
//for report Violation in recDetail page and recAllReview page
    function confirmReport(reviewID, recNo, url)
    {       
        var reviewID = reviewID;
        var recNo = recNo;
        var url = url;
    
        var win = confirm("Do you really want to submit this review as inappropriate?");
        
        if (win == true)
        {    
            window.open(url + 'RecReviewPopUp.aspx?c=3&s=' + reviewID + '&rid=' + recNo, 'CustomPopUp', 'width=348, height=200, menubar=no, resizable=no');
        }        
    }    
    function SwapChannelImage(MainImageDiv, Path, ImageLink, Tr0, Tr1, Tr2)
    {      
        var control =  document.getElementById(MainImageDiv);
        control.src = Path;
        document.getElementById('ctl00_DefaultContentHolder_ChannelTabTeaserUC_lnkMainImageLink').href = ImageLink;
    
        HideChannelTabs();
        DisplayChannelTab('TrChannelRow' + Tr0, 'TrChannelRow' + Tr1, 'TrChannelRow' + Tr2);
    }
    
    function HideChannelTabs()
    {
        var TrChannel10 = document.getElementById('TrChannelRow10');
        var TrChannel20 = document.getElementById('TrChannelRow20');
        var TrChannel30 = document.getElementById('TrChannelRow30');
        
        var TrChannelRow11 = document.getElementById('TrChannelRow11');
        var TrChannelRow12 = document.getElementById('TrChannelRow12');
        var TrChannelRow21 = document.getElementById('TrChannelRow21');
        var TrChannelRow22 = document.getElementById('TrChannelRow22');
        var TrChannelRow31 = document.getElementById('TrChannelRow31');
        var TrChannelRow32 = document.getElementById('TrChannelRow32');
        
        TrChannel10.style.display = "none";
        TrChannel20.style.display = "none";
        TrChannel30.style.display = "none";
        
        TrChannelRow11.style.display = "none";
        TrChannelRow12.style.display = "none";
        TrChannelRow21.style.display = "none";
        TrChannelRow22.style.display = "none";
        TrChannelRow31.style.display = "none";
        TrChannelRow32.style.display = "none";        
    }
    function DisplayChannelTab(Tr0, Tr1, Tr2)
    {
        var oTr0 = document.getElementById(Tr0);
        var oTr1 = document.getElementById(Tr1);
        var oTr2 = document.getElementById(Tr2);
        oTr0.style.display = "block";
        oTr1.style.display = "block";
        oTr2.style.display = "block";
    }
    
    function SwapImage(Div, MainImage, ImagePath, PathOff, PathOn,ImageAltText, ImageLink)
    {		
	    document.getElementById("tab1").style.background = 'url(' + PathOff + ') no-repeat';		
	    document.getElementById("tab2").style.background = 'url(' + PathOff + ') no-repeat';		
	    document.getElementById("tab3").style.background = 'url(' + PathOff + ') no-repeat';			
	    document.getElementById(Div).style.background = 'url(' + PathOn + ') no-repeat';		
	    document.getElementById(MainImage).src = ImagePath;
	    document.getElementById(MainImage).alt = ImageAltText;
        document.getElementById('ctl00_DefaultContentHolder_lnkMain').href = ImageLink;
	    
    }
    function HideTabs()
    {        
        document.getElementById("dvRecipes").style.display = "none";     
        document.getElementById("dvArticles").style.display = "none";        
        document.getElementById("dvKeywords").style.display = "none";        
        document.getElementById("tdRecipes").className = "NormalTab";
        document.getElementById("tdArticles").className = "NormalTab";
        document.getElementById("tdKeywords").className = "NormalTab";        
    }
    function ShowHideTab(TabId,DivId)
    {        
        HideTabs();        
        document.getElementById(DivId).style.display = "block";        
        document.getElementById(TabId).className= "SelectedTab";
        document.getElementById("hdnTab").value=TabId;
    }      
    function HighLightTab(TabId)
    {           
        document.getElementById(TabId).className= "SelectedTab";
    }
    function SetNormalTab(TabId)
    {   
        var HdnTabId;        
        HdnTabId = document.getElementById("hdnTab");        
        if (HdnTabId.value != TabId)    
            document.getElementById(TabId).className= "NormalTab";
    }
    function SetNormalTabFromRecDetail(TabId,SelectTab)
    {                         
        if (TabId != SelectTab)    
            document.getElementById(TabId).className= "NormalTab";
    }
    function HighLightTabFromSearchList(TabId,LinkId)
    {           
        document.getElementById(TabId).className= "SelectedTab";
        document.getElementById(LinkId).className= "MostPopNavTextSelected";
    }
    function SetNormalTabFromSearchList(TabId, LinkId)
    {   
        var HdnTabId;
        HdnTabId = document.getElementById("ctl00_DefaultContentHolder_SearchListUC_hdnSelectedTab");
        if (HdnTabId.value != TabId)    
        {
            document.getElementById(TabId).className= "NormalTab";
            document.getElementById(LinkId).className= "MostPopNavText";
        }
    }
	    function PreLoadHomeImages(HomeImage1, HomeImage2, HomeImage3)
        {            
            Image1 = new Image();
            Image1.src = HomeImage1;
            Image2 = new Image();
            Image2.src = HomeImage2;
            Image3 = new Image();
            Image3.src = HomeImage3;            
        }
        
        /* For Opening a Pop-Up Window*/
        function popupWindow(fileName) 
        {
	        //debugger
	        var MyWindow;
	        var ileft=0;
	        var itop=0;
	        var scrnWidth = 425;
	        var scrnHeight = 475;
	        
            ileft=(screen.width-scrnWidth)/2;
	        itop=(screen.height-scrnHeight)/2;
        	if (String(MyWindow)=="undefined"||MyWindow==null)
	        {
	            MyWindow=window.open(fileName,'win','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+scrnWidth+',height='+scrnHeight+',left='+ileft+',top='+itop);	
	        }
	        else
	        {
        	    if (MyWindow.closed==true)
	                MyWindow=window.open(fileName,'win','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+scrnWidth+',height='+scrnHeight+',left='+ileft+',top='+itop);	
		        else
				    MyWindow.window.location.href=fileName;	
		    }
	        
	        MyWindow.focus();	
        }       
        
        function CountCharacters(textBoxObj,objLabel,maxCharacterCount) 
        {
            
            myTextBox = document.getElementById(textBoxObj);            
            var myLblCount = document.getElementById(objLabel);
            
            if(myTextBox.value != "")
            {
                
                var myCharacterCount = myTextBox.value.length;                
                if (document.all)
                    myLblCount.innerText = maxCharacterCount - myCharacterCount;
                else                
                    myLblCount.textContent = maxCharacterCount - myCharacterCount;                
                if(myCharacterCount > maxCharacterCount)
                { 
                    alert("You have exceeded the Character Limit! Please shorten your description");
                    myTextBox.value = myTextBox.value.substring(0,maxCharacterCount);
                    myLblCount.innerText = 0;
                }
            }
            else
            {
                myLblCount.innerText = maxCharacterCount;
            }
        }
        function CountCharactersMessage(textBoxObj,objLabel,maxCharacterCount,strMessage) 
        {
            
            myTextBox = document.getElementById(textBoxObj);            
            var myLblCount = document.getElementById(objLabel);
            
            if(myTextBox.value != "")
            {
                
                var myCharacterCount = myTextBox.value.length;                
                if (document.all)
                    myLblCount.innerText = maxCharacterCount - myCharacterCount;
                else                
                    myLblCount.textContent = maxCharacterCount - myCharacterCount;                
                if(myCharacterCount > maxCharacterCount)
                { 
                    alert(strMessage);
                    myTextBox.value = myTextBox.value.substring(0,maxCharacterCount);
                    myLblCount.innerText = 0;
                }
            }
            else
            {
                myLblCount.innerText = maxCharacterCount;
            }
        }
        /* For Populating Correct label in the Search Bar UC*/
        function PopulateSearchLabel(obj)
        {
            //debugger;
            var mySelection ="";
            var optionLabel = document.getElementById('ctl00_PageHeaderUC_SearchBarUC_lblSearch');        
            if(obj == '1')
                mySelection = "RECIPE SEARCH";
            if(obj == '3')            
                mySelection = "COLLECTION SEARCH";              
            if(obj == '4')
                mySelection = "MENU SEARCH";
            if(obj == '5')
                mySelection = "PRODUCT SEARCH";             
           
            var HiddenSelection = document.getElementById('ctl00_PageHeaderUC_SearchBarUC_HiddenSelection');
            HiddenSelection.value = mySelection;
            optionLabel.innerText = HiddenSelection.value;
            optionLabel.innerHTML = HiddenSelection.value; 
            var SearchOptionsid=document.getElementById('ctl00_PageHeaderUC_SearchBarUC_SearchOptions');            
            SearchOptionsid.display = "none";
            
            
        }
        
        /* For Validating the User-Entry in the Search Bar UC*/
        function ValidateSearch(control)
        {
            var value = document.getElementById(control).value;
            if (value == "")
            {
                alert('Please enter the Search Criteria');
                document.getElementById(control).focus();
                return false;
            }
            else        
                return true;
        }       
      
        /*Cookie*/
        function checkCookie()
        {
            Set_Cookie('test', 'none', '', '/', '', '');
            // if Get_Cookie succeeds, cookies are enabled, since 
            //the cookie was successfully created.
            if (Get_Cookie('test'))
            {
	         //   alert( 'cookies are currently enabled.');
	            /* 
	            this is an example of a set cookie variable, if 
	            you want to use this on the page or on another script 
	            instead of writing to the page you would just check that value
	            for true or false and then do what you need to do.
	            */
	            cookie_set = true;
	            // and these are the parameters for Delete_Cookie:
	            // name, path, domain
	            // make sure you use the same parameters in Set and Delete Cookie.
	            Delete_Cookie('test', '/', '');
	            return true;
            }
            // if the Get_Cookie test fails, cookies 
            //are not enabled for this session.
            else
            {
	            alert('This action requires cookies to be enabled. Please enable cookies for the Cooking.com website to continue.');
	            cookie_set = false;
	            return false;
            }
        }
        function Set_Cookie( name, value, expires, path, domain, secure ) 
        {
            // set time, it's in milliseconds
            var today = new Date();
            today.setTime( today.getTime() );

            /*
            if the expires variable is set, make the correct 
            expires time, the current script below will set 
            it for x number of days, to make it for hours, 
            delete * 24, for minutes, delete * 60 * 24
            */
            if ( expires )
            {
            expires = expires * 1000 * 60 * 60 * 24;
            }
            var expires_date = new Date( today.getTime() + (expires) );

            document.cookie = name + "=" +escape( value ) +
            ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
            ( ( path ) ? ";path=" + path : "" ) + 
            ( ( domain ) ? ";domain=" + domain : "" ) +
            ( ( secure ) ? ";secure" : "" );
        }

        // this function gets the cookie, if it exists
        function Get_Cookie( name ) 
        {	
            var start = document.cookie.indexOf( name + "=" );
            var len = start + name.length + 1;
            if ( ( !start ) &&
            ( name != document.cookie.substring( 0, name.length ) ) )
            {
            return null;
            }
            if ( start == -1 ) return null;
            var end = document.cookie.indexOf( ";", len );
            if ( end == -1 ) end = document.cookie.length;
            return unescape( document.cookie.substring( len, end ) );
        }

        // this deletes the cookie when called
        function Delete_Cookie( name, path, domain ) 
        {
            if ( Get_Cookie( name ) ) document.cookie = name + "=" +
            ( ( path ) ? ";path=" + path : "") +
            ( ( domain ) ? ";domain=" + domain : "" ) +
            ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
        }