﻿var CLIP_LENGTH = 10;

//Begin Global Variables related to ViewRecipe
var recipeId;
var varmessage;
var messageType;
//End Global Variables related to ViewRecipe


function trimString(str)
 {
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
 }
 
 function removeEnter(str)
 {
 	return str.replace(/\n+/g, ' ');
 }
 
function IsTotaltimeValid(sender, args)
{
    args.IsValid = isNaN(args.Value);
}

function setKeywordLabelText(checkbox,spanId)
{
/*as long as the two divs are not changed this will work*/
    var parentDiv = checkbox.parentNode.parentNode.parentNode;
    var divs = parentDiv.getElementsByTagName("div");
    var titleSpan = $get(spanId);
    if(titleSpan!=null)
    {
        displaySelectedKeywords(titleSpan,checkbox);
    }
}

function displaySelectedKeywords(titleSpan,checkbox)
{
    titleSpan.innerHTML = "";
    var isOneItemSelected = false;
    var parentDiv = checkbox.parentNode;
    var checkboxes = parentDiv.getElementsByTagName("input");
    var labelText = "";
    for(var i=0;i<checkboxes.length;i++)
    {
        if(checkboxes[i].checked)
        {
            isOneItemSelected = true;
            labelText += " " + checkboxes[i].nextSibling.innerHTML;
            if(labelText.length>CLIP_LENGTH)
            {
                labelText = labelText.substring(0,CLIP_LENGTH) + "...";
                break;
            }
        }
    }
    if(!isOneItemSelected)
        labelText = MESSAGE_SELECT;
    titleSpan.innerHTML = labelText;
}

function validateMainIngredients(sender,args)
{
    var mainIngDiv = $get("mainIngDiv");
    args.IsValid = isOneKeywordSelected(mainIngDiv);
}

function validateCookingMethod(sender,args)
{
    var mainIngDiv = $get("cookingMethodDiv");
    args.IsValid = isOneKeywordSelected(mainIngDiv);
}

function validateCourse(sender,args)
{
    var mainIngDiv = $get("courseDiv");
    args.IsValid = isOneKeywordSelected(mainIngDiv);
}

function isOneKeywordSelected(containerDiv)
{
    var checkboxes = containerDiv.getElementsByTagName("input");
    for(var i=0;i<checkboxes.length;i++)
    {
        if(checkboxes[i].type=="checkbox" && checkboxes[i].checked)
            return true;
    }
    return false;
}

function IsVisible(oDomElement)
{
    return (oDomElement.style.display=="block");
}

function setVisible(oDomElement, visibility)
{
    if(visibility)
    {
        oDomElement.style.display="block";
    }
    else
    {
        oDomElement.style.display="none";
    }
}

function IsKey(keyCode,e)
{
    var key;
	 if(window.event)
	 {
		  key = window.event.keyCode;     //IE
	 }
	 else
	 {
		  key = e.which;
	 }
	 return (keyCode==key);
}

function doClick(buttonName,e)
{
    var key;
    var isIE;
     if(window.event)
     {
          key = window.event.keyCode;     //IE
          isIE = true;
     }
     else
          key = e.which;     //firefox


    if (key == 13)
    {
        //Get the button the user wants to have clicked

        var btn = $get(buttonName);
        if (btn != null)
        { //If we find the button click it
            if(!isIE || window.opera != null)
            {
                //call this for FireFox and Opera browser
                e.preventDefault();
            }
            else
            {
              //call this for IE
              event.keyCode = 0;  
            }

            btn.click();
            //
            return false;
        }
    }
}

function $get(id){
    return document.getElementById(id);
}
//Keyword dropdown scripts

	var oMTPS_DD_PopUpDiv;
	var oMTPS_DD_Div;
	var img = new Image();
	var selValue="";
	img.src = PHOTO_URL+ "/arrow-on.jpg";
	var ddls = new Array();
      function checkBoxClicked(o,itemId,itemDesc,hidden,lbl,hiddendesc,txtlength)
    {  
        var lblText=$get(lbl);
        var lblhidden=$get(hidden);  
        var lblhiddendesc=$get(hiddendesc);  
        if(lblText.innerHTML == MESSAGE_SELECT)
        {
            lblText.innerHTML ='';           
        }    
             
        if(o.checked)
        {
           //get the itemId into hidden variable
            lblhidden.value += itemId+'|';  
            lblhiddendesc.value+=itemDesc+' ';
            //var selectedItem= lblText.innerHTML+' '+itemDesc;
            if(lblhiddendesc.value.length>txtlength)
            { 
                lblText.innerHTML =lblhiddendesc.value.substring(0,txtlength)+" ...";          

            }
            else
            {
              lblText.innerHTML =lblhiddendesc.value.substring(0,txtlength);                
            }            
        }
        else
        {
            //else remove it from hidden variable  
            var str1 =lblhidden.value;
            var str5=lblhiddendesc.value;
            var str2=itemId+'|';
            var str3=itemDesc+' ';
            var str4 =lblText.innerHTML ;
            lblhidden.value =str1.replace(str2, ' ');
            lblhiddendesc.value=str5.replace(str3, '');       
          
           if(lblhiddendesc.value.length>txtlength)
            {    
                lblText.innerHTML =lblhiddendesc.value.substring(0,txtlength)+" ..."; 
            }
            else
            {
                lblText.innerHTML =lblhiddendesc.value.substring(0,txtlength); 
            }         
        }         
        if(lblhidden.value.trim()=='' || lblhidden.value==null)
        {    
            lblText.innerHTML='';         
            lblText.innerHTML= MESSAGE_SELECT;  
            lblhiddendesc.value='';           
            
        }          
    }	


    function ChangeDropDownImage(hover,obj)
    {    
        var image=$get(obj);
		if(hover)
			image.src =  PHOTO_URL+ "/arrow-on.jpg";
		else
			image.src = PHOTO_URL+ "/arrow-off.jpg";
	}
	
    function closeOtherDropDowns(objId)
    {
        var theId;
        for(var i=ddls.length-1;i>=0;i--)
        {
            theId = ddls[i];
            if(theId!=objId)
            {
               if($get(theId).style.display != "none")
               {
                    $get(theId).style.display = "none";
                    ddls.pop();
               }
            }
        }
	        ddls.push(objId);
    }		
	
	function DDFilterOn(e,obj)
	{	
	    oMTPS_DD_PopUpDiv = $get(obj);
	    oMTPS_DD_Div = oMTPS_DD_PopUpDiv.parentNode.parentNode;
		if($get(obj).style.display != "block")
		{
		    closeOtherDropDowns(obj);
			$get(obj).style.display = "block";
            if(document.addEventListener)
            {       //  Commented for # 32609
	                document.addEventListener("click", TestForResizableAreaControl, false);
	                window.addEventListener("resize", TestForResizableAreaControl, false);			
            } 
            else
            { 
		            document.body.onclick = HideFromClick;	
            } 
	    }
		else
			setTimeout(HideThisMenu, 0);	
		
		e.cancelBubble = true;
		return;
	}   

//	Only used by IE
function HideFromClick(event)
{
	var objClicked = window.event.srcElement;
	var objParent = objClicked.parentNode.parentNode;
	if (objParent.id != oMTPS_DD_PopUpDiv.id) 
	{
		setTimeout(HideThisMenu, 0);
		return;
	}
	else
	{
		window.event.cancelBubble = true;
		return;
	}
}
/// FF & NN only
function TestForResizableAreaControl(e)
{
	try
	{
	//	For keydown events
	if (e.type == "keydown")
	{
		if (e.which == 84 || e.which == 13)
		{
			setTimeout(HideThisMenu, 0);
			document.removeEventListener("keydown", TestForResizableAreaControl, false);
			e.cancelBubble = true;
			return;
		}
	}
	else if (e.type == "resize")
	{
		setTimeout(HideThisMenu, 0);
		window.removeEventListener("resize", TestForResizableAreaControl, false);
		e.cancelBubble = true;
		return;		
	}
	// for mousedown event
		if (e.type == "click")
		{
			if (e.which == 1 || e.which == 32)
			{	
				var eNode = e.target;
				if (eNode.id.length == 0)
				{	
					setTimeout(HideThisMenu, 0);
					document.removeEventListener("click", TestForResizableAreaControl, false);
					return false;
				}
				else
				{
					var pNode = $get(eNode.id).parentNode.parentNode;
					if (eNode.id != oMTPS_DD_PopUpDiv.id)
					{
						if (pNode.id != oMTPS_DD_PopUpDiv.id)
						{
							setTimeout(HideThisMenu, 0);
							document.removeEventListener("mousedown", TestForResizableAreaControl, false);
						}
					}			
				}
				return;
			}
		}
	}
	catch(err)
	{
		throw err;
	}
}	
// Persist Menu long enough for client to click check boxes

    function HideThisMenu()
    {
	    oMTPS_DD_PopUpDiv.style.display = "none";
//	    ImageSource();
	    document.body.onclick = null;
	    return;
    }
    	
    function ImageSource()
    {
        $get("DD_ImageArrow").src = PHOTO_URL+ "/arrow-off.jpg";
    }
    //Ends Keyword dropdown scripts
   //Tag scripts 
        function deleteTag(o,tagId,recipeId,userId)
        {
            if(userId==0)
                return;      
            PageMethods.DeleteTag(tagId,recipeId,userId,function(result){
                if(result)
                {
                    var theLI = o.parentNode;
                    var theUL = theLI.parentNode;
                    if(theUL!=null)
                    {
                        theUL.removeChild(theLI);
                    }
                }                
            },function(){});
        }
        
        function deleteTagByNameForSubmit(o,tag,recipeId,userId)
        {
            if(userId==0)
                return;
            PageMethods.DeleteTagByName(tag,recipeId,userId,function(result){
                if(result)
                {
                    var theLI = o.parentNode;
                    var theUL = theLI.parentNode;
                    if(theUL!=null)
                    {
                        theUL.removeChild(theLI);
                    }
                }                
            },function(){});
        }

        function addTag(tagElementId,recipeId,userId,divElementId)
        {         
            var tagName = $get(tagElementId);
            var tag = trimString(tagName.value);
            if(userId==0)
                return;
            var containerDiv = $get(divElementId);
            var theUL = containerDiv.getElementsByTagName("ul")[0];
            var result = true;
            if(tag!="" && !hasTag(tag,theUL))
            {
                PageMethods.AddTag(recipeId,userId,tag,function(result){
                    if(result)
                    { 
                        if(theUL==null)
                        {
                            theUL = document.createElement("ul");
                            theUL.className = "tag_list";
                            containerDiv.appendChild(theUL);
                        }
                        tagName.value = "";
                        var theLI = document.createElement("li");
                        var txtANode = document.createElement("a");
                        txtANode.href = "javascript:void(0);";
                        var txtNode = document.createTextNode(result);
                        txtANode.appendChild(txtNode);
                        theLI.appendChild(txtANode);
                        var imgClose = document.createElement("img");
                        var p = new Page();
                        imgClose.src = PHOTO_URL+ "/close.gif";
                        imgClose.style.cursor = "pointer";
                        imgClose.onclick = function()
                        {
                            PageMethods.DeleteTagByName(result,recipeId,userId,function(resultDel){
                                 if(resultDel){  
                                   theUL.removeChild(theLI);
                                   }
                            },function(){});
                        }
                        theLI.appendChild(imgClose);
                        theUL.appendChild(theLI);
                    }
                    },function(){});
            }
        }
        
        function hasTag(tagName,theUL)
        {
            if(theUL==null)
                return false;
            var anchors = theUL.getElementsByTagName("a");
            for(var i=0;i<anchors.length;i++)
            {
                if(anchors[i].innerHTML.toLowerCase()==tagName.toLowerCase())
                {
                    return true;
                    
                 }   
            }
            return false;
        }   
        
   //End Tagscripts       
   
   //Public SubmitRecipe
   
    var isEditmode=false;
 var isChanged=false;
 function IsEditMode()
 {
    isEditmode=true;
 }  
function IsChanged(changed)
 {
    if(isEditmode && changed)
    {
     isChanged=true;
    }  
 }
 function IsDataSaved()
 {
    isChanged=false;
    isEditmode=false;
 }
 window.onbeforeunload = function()
 {
    if(isChanged)
    {
        return MESSAGE_LEAVESITE;
    }
    else
    {
        return;
    }
 } 
  function IsSubmittedByTextEmpty(source, args)
  {   
    if(args.Value=='' || args.Value==null)
    {
        args.IsValid=false;
    }
  }
   
   //  
   
/* Begin Script for the Search.aspx Page */

function getModuleState(id) 
{
    var moduleDisplay = $get(id);
    if (moduleDisplay.style.display.indexOf("block") != -1) 
    {
        return "close";
    }
    return "open";
}


function setImageByParse(id, state) 
{
    var imageid = $get(id); 
    if(state == "open")
    {
        imageid.src = PHOTO_URL+ "/ic_expand.gif";
    }
    else
    {
        imageid.src = PHOTO_URL+ "/ic_collapse.gif";
    }
}

function toggleDisplay(titlespan,searchDiv,imageId)
{
    var titleobj = $get(titlespan);
    var searchobj = $get(searchDiv);
    var imageobj = $get(imageId);
    
    if(getModuleState(searchDiv) == "open")
    {
        setImageByParse(imageId,"open");
        searchobj.style.display = 'block';   
        imageobj.alt=' - ';
		imageobj.title=' - ';                         
    }
    else
    {
        setImageByParse(imageId,"close");
        searchobj.style.display = 'none';       
        imageobj.alt=' + ';
		imageobj.title=' + ';            
    }  
}
        
        
/* End scrit for the Search.aspx */
function updateRecipeView(recipeId)
{
    var am = new AsyncMethods();
    am.UpdateRecipeView(recipeId,function(){},function(){});
}
function UpdatePhotoView(photoId)
{
    var am = new AsyncMethods();
    am.UpdatePhotoView(photoId,function(){},function(){});
}
function UpdateProfileView(profileId)
{
       var as = new AsyncMethods();
       as.UpdateProfileView(profileId,function(){},function(){});
}

function doSearch(txtSearchId)
{
    var txtSearchbox = $get(txtSearchId);
    var p = new Page();
    if(txtSearchbox!=null && trimString(txtSearchbox.value)!="" && txtSearchbox.value!=MESSAGE_TITLE_WATERMARK)
    {
       window.location.href = p.resolveUrl(URL_SEARCH_RESULTS_TEXT + Url.encode(txtSearchbox.value));
    }
    else
    {
        window.location.href = p.resolveUrl(URL_SEARCH);
    }
    return false;
}

function doSearchHandleEnterKey(txtSearchId,e)
{
    var key;
    var isIE;
     if(window.event)
     {
          key = window.event.keyCode;     //IE
          isIE = true;
     }
     else
          key = e.which;     //firefox


    if (key == 13)
    {
        //Get the button the user wants to have clicked

        var txtBox = $get(txtSearchId);
        if (txtBox != null)
        { //If we find the button click it
            if(!isIE)
                e.preventDefault();
            else
              event.keyCode = 0;  
            doSearch(txtSearchId);
            //
            return false;
        }
    }
}

/*resolves the url*/
function Page()
{
    this.resolveUrl = function(relUrl)
    {
        var newUrl;
        newUrl = ROOT_URL + relUrl;
        return newUrl;
    }
}

//this.prototype.base = new Page();
function showKeywords(moreDivId, lessDivId)
{
    var moreDiv = $get(moreDivId);
    var lessDiv = $get(lessDivId);
    var theUL = moreDiv.nextSibling;
    if(theUL!=null)
    {
        toggleVisibility(theUL);
        toggleVisibility(moreDiv);
        toggleVisibility(lessDiv);
    }
}

function toggleVisibility(oDomElement)
{
    if(oDomElement.style.display=="none")
    {
        setVisible(oDomElement,true);
    }
    else
    {
        setVisible(oDomElement,false);
    }
}

function searchIngredients(txtTitleId,txtIngredientId,txtNoIngredientId,lblErrorDiv)
{
    var txtTitle = $get(txtTitleId);
    var text = removeEnter(txtTitle.value);
    text = trimString(text);
    var txtIngredient = $get(txtIngredientId);
    var ingredientText = trimString(removeEnter(txtIngredient.value));
    var txtNoIngredient = $get(txtNoIngredientId);
    var noIngredientText = trimString(removeEnter(txtNoIngredient.value));
    var p = new Page();
    var searchUrl = p.resolveUrl(URL_SEARCH_RESULTS);
    var searchTerms = new Array();

    if( (ingredientText == MESSAGE_INGREDIENT_WATERMARK || ingredientText == "" ) && noIngredientText == "" && text=="" )
    {   
         $get(lblErrorDiv).style.display = 'block';
     
      }
    
    if(text!="")
    {
        searchTerms.push(SEARCH_TEXT + "=" + Url.encode(text));
    }
    if(ingredientText!="" && ingredientText!=MESSAGE_INGREDIENT_WATERMARK)
    {
        searchTerms.push(SEARCH_INGREDIENT + "=" + Url.encode(ingredientText));
    }
    if(noIngredientText!="")
    {
        searchTerms.push(SEARCH_NO_INGREDIENT + "=" + Url.encode(noIngredientText));
    }
    var qs = searchTerms.join("&");
    if(qs!="")
    {
        window.location.href = searchUrl + qs;
    }
    
}

/* Method Related to inline edit */
  function InlineEditText(lblReviewText,txtReviewText,lblReviewDiv,txtReviewDiv)
    {
          $get(lblReviewDiv).style.display = 'none';
          $get(txtReviewDiv).style.display = 'block';
          $get(txtReviewText).value = $get(lblReviewText).innerHTML;  
          return false;
     }
    function InlineCancel(lblReviewDiv,txtReviewDiv)
    {
          $get(lblReviewDiv).style.display = 'block';
          $get(txtReviewDiv).style.display = 'none';    
          return false;
    }

    function InlineDeleteReview()
    {    
        if(confirm(MESSAGE_DELETE_REVIEW_CONFIRM))
        {
            return true;
        }
        return false;
    }
    
      function DeleteMyTweakMessage()
    {    
        if(confirm(MESSAGE_DELETE_TWEAK_CONFIRM))
        {
            return true;
        }
        return false;
    }
    
/*view tag functions*/
function addTagView(tagElementId,recipeId,userId,divElementId)
{
        var tagName = $get(tagElementId);
        var tag = trimString(tagName.value);
        if(userId==0)
            return;
        var containerDiv = $get(divElementId);
        var theUL = containerDiv.getElementsByTagName("ul")[0];
        //    var result = true;
        if(tag!="")
        {
            var asyncMethods = new AsyncMethods();
            asyncMethods.AddTag(recipeId,userId,tag,function(result){
                if(result!='')
                { 
                    tagName.value = "";
                    if(!hasTag(result,theUL))
                    {
                        if(theUL==null)
                        {
                            theUL = document.createElement("ul");
                            theUL.className = "tag_list";
                            containerDiv.appendChild(theUL);
                        }
                        var theLI = document.createElement("li");
                        var txtANode = document.createElement("a");
                        var p = new Page();
                        txtANode.href = p.resolveUrl(URL_SEARCH_RESULTS_TAG + Url.encode(result));
                       
                        var txtNode = document.createTextNode(result);
                        txtANode.appendChild(txtNode);
                        theLI.appendChild(txtANode);
                        var imgClose = document.createElement("img");
                        imgClose.src = PHOTO_URL+ "/close.gif";
                        imgClose.style.cursor = "pointer";
                        imgClose.onclick = function()
                        {
                            asyncMethods.DeleteTagByName(result,recipeId,userId,function(resultDel){
                                 if(resultDel){  
                                   theUL.removeChild(theLI);
                                   }
                            });
                        }
                        theLI.appendChild(imgClose);
                        theUL.appendChild(theLI);
                    }
                }
                });
        }
}    

function deleteTagForView(o,tagId,recipeId,userId)
{
    if(userId==0)
        return;   
    var am = new AsyncMethods();         
    am.DeleteTag(tagId,recipeId,userId,function(result){
        if(result)
        {
            var theLI = o.parentNode;
            var theUL = theLI.parentNode;
            if(theUL!=null)
            {
                theUL.removeChild(theLI);
            }
        }                
    },function(){});
}

function deleteTagByName(o,tag,recipeId,userId)
{
    if(userId==0)
        return;   
    var am = new AsyncMethods();         
    am.DeleteTagByName(tag,recipeId,userId,function(result){
        if(result)
        {
            var theLI = o.parentNode;
            var theUL = theLI.parentNode;
            if(theUL!=null)
            {
                theUL.removeChild(theLI);
            }
        }                
    },function(){});
}

/* Methods for collapsing and expanding divs for ReviewsCommentsPage and Tweaks Page */

 function ExpandCollapse(oImage,containerDiv,lblReviewDiv,txtReviewDiv)
        {
            var oDiv = $get(containerDiv);
            if(IsVisible(oDiv))
            {
                $get(lblReviewDiv).style.display= "block";
                $get(txtReviewDiv).style.display= "none";
                setVisible(oDiv,false);
                oImage.src = PHOTO_URL+ "/ic_plus_square.gif";
            }
            else
            {
                setVisible(oDiv,true);
                oImage.src = PHOTO_URL+ "/ic_minus_square.gif";
            }
        }
        function ExpandAll(hdnExpandCollapseAllValue)
        { 
            var clientIds = new Array();
            clientIds = hdnExpandCollapseAllValue.split(',');            
            for(i = 0;i< clientIds.length-1;i++)
            {
                $get(clientIds[i]).style.display= "block";
                i=i+1;
                $get(clientIds[i]).src = PHOTO_URL+ "/ic_minus_square.gif";
                i=i+1;
                $get(clientIds[i]).style.display= "block";
                i = i+1;
                //edit Textbox
                $get(clientIds[i]).style.display= "none";
            }                      
        }
        function CollapseAll(hdnExpandCollapseAllValue)
        {
            var clientIds = new Array();
            clientIds = hdnExpandCollapseAllValue.split(',');            
            for(i = 0;i< clientIds.length-1;i++)
            {
                $get(clientIds[i]).style.display= "none";
                i=i+1;
                $get(clientIds[i]).src = PHOTO_URL+ "/ic_plus_square.gif";
                i=i+1;
                $get(clientIds[i]).style.display= "block";
                i = i+1;
                //edit Textbox
                $get(clientIds[i]).style.display= "none";
            }  
        }
        
        
   //Begin Javascript function Related to ViewRecipe.aspx 

    function loadMessage(msgClientID,MsgTypeClientId) 
    {
        varmessage = msgClientID;
        messageType = MsgTypeClientId;                
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);                
    }          
           
    function EndRequestHandler(sender,args) 
    {               
        DisplayMessage(varmessage,messageType);              
    }    
    
    
    function DisplayMessage(varmessage,messageType)
    {
        var message = $get(varmessage).value;
        var msgType = $get(messageType).value;   
        $get("errorMsg").style.display = "block";            
        if(message == 'Success')
        {
            $get("SuccessMessage").style.display= "block";
            $get("errorMessage").style.display= "none";
        }
        if(message == 'Error')                         
        {
            $get("SuccessMessage").style.display= "none";
            $get("errorMessage").style.display= "block";
        }
    }
    
    function toggleRatingDiffcultyDiv(RatingDifficultyDiv)
    {
        var ratingDiv = $get(RatingDifficultyDiv);
        
        if(getCurrentState(RatingDifficultyDiv) == "open")
        {
              ratingDiv.style.display = 'block';                       
        }
        else
        {
              ratingDiv.style.display = 'none';      
        }  
    }
    
    function getCurrentState(id) 
    {
        var moduleDisplay = $get(id);
        if (moduleDisplay.style.display.indexOf("block") != -1) 
        {
            return "close";
        }
        return "open";
    } 
    
    function TweakValidator(src,args)
	{
		args.IsValid = true;	
	    var tweakTextBox = GetClientIDOfuxTweakTextBox();
	    var tweakText = $get(tweakTextBox).value;
	
		if(trimString(tweakText).length == 0)
		{			
			args.IsValid = false;					
		}
		else if(trimString(tweakText).length > 1500)
		{					
			args.IsValid = false;					
		}					
	}
	function ReviewValidator(src,args)
	{
		args.IsValid = true;	
	    var reviewkTextBox = GetClientIDOfuxAddCommentTextBox();
	    var reviewText = $get(reviewkTextBox).value;
	
		if(trimString(reviewText).length == 0)
		{			
			args.IsValid = false;					
		}
		else if(trimString(reviewText).length > 1500)
		{					
			args.IsValid = false;					
		}					
	}
	
	
	 
	
	//utility function to trim a string of its leading and trailing spaces
    function trimString(str)
    {
        return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
    }
    
    
    function RatingValidatorFunction(src,args)
    {
        args.IsValid = true;
        var ratinControlDiv = GetClientIDOfuxRatingControl();       	        
        var ratingControldDivObject = $get(ratinControlDiv);
        var ratingValue = ratingControldDivObject.getElementsByTagName("input")[0].value;        
	   
	    var madeRecipeCheckcontrol = GetClientIDOfuxMadeRecipeCheck();
	    var madeCheck = $get(madeRecipeCheckcontrol).checked;
	    
	    if(madeCheck)
	    {
            if( parseFloat(ratingValue) > 0 && parseFloat(ratingValue) <=5 )
            {			
                args.IsValid = true;					
            }
            else 
            {					
                args.IsValid = false;					
            }
        }					
    }
    
    function toggleRatingDifficultyDivX(o,ratingId,difficultyDivId){
			var ratingCntl = $find(ratingId);
			ratingCntl.set_ReadOnly(!o.checked);
			var parentDiv = $get(difficultyDivId);
			if(o.checked)
				$removeClass(parentDiv,"disableBg");
			else
				$addClass(parentDiv,"disableBg");
            var radiobuttonlist = parentDiv.getElementsByTagName("input");
            var pNode;
            var gpNode;
            for(var i =0; i<radiobuttonlist.length;i++)
            {
                if(radiobuttonlist[i].type == "radio")
                {
                    radiobuttonlist[i].disabled  = !o.checked;
					pNode = radiobuttonlist[i].parentNode;
					if(pNode!=null)
					{
						pNode.disabled = !o.checked;
					}
					gpNode = pNode.parentNode;
					if(gpNode!=null)
					{
						gpNode.disabled = !o.checked;					
					}
                }
            }			
    }
    
    //End Javascript function Related to ViewRecipe.aspx 
    
    
    //Begin Javascript of RecipeTweaksControl.ascx
    
    function EditRecipeTweak(TweakTextBox,TweakLabel,EditTweakDiv,UpdateTweakDiv,TweakTypeDropDown,TweakTypeLabel)
    {
        
        var tweakTextBoxControl = $get(TweakTextBox);              
        var tweakLabel = $get(TweakLabel);
        var tweakTypeDrop = $get(TweakTypeDropDown);
        var tweakType =  $get(TweakTypeLabel);
                               
        
        var editDivControl = $get(EditTweakDiv);
        editDivControl.style.display = 'none';
        var updateDivControl = $get(UpdateTweakDiv);
        updateDivControl.style.display = 'block';      

        tweakTypeDrop.style.display = 'inline';        
        tweakType.style.display = 'none';
        
        tweakTextBoxControl.style.display= 'block';
        tweakLabel.style.display= 'none';           
        tweakTextBoxControl.value = tweakLabel.innerHTML;            
                           
    } 
    
    function CancelRecipeTweak(TweakTextBox,TweakLabel,EditTweakDiv,UpdateTweakDiv,TweakTypeDropDown,TweakTypeLabel,TweakSummary,TweakRequired,TweakRegular)    
    {
        var tweakTextBoxControl = $get(TweakTextBox);              
        var tweakLabel = $get(TweakLabel); 
        var tweakTypeDrop = $get(TweakTypeDropDown);
        var tweakType =  $get(TweakTypeLabel);
        var summary = $get(TweakSummary);
        var required = $get(TweakRequired); 
        var regular = $get(TweakRegular);                                

        var editDivControl = $get(EditTweakDiv);
        editDivControl.style.display = 'block';
        var updateDivControl = $get(UpdateTweakDiv);
        updateDivControl.style.display = 'none';                 

        tweakTypeDrop.style.display = 'none';       
        tweakType.style.display = 'inline';
        tweakTextBoxControl.style.display= 'none';
        tweakLabel.style.display= 'block';           
        tweakTextBoxControl.value = '';    
        
        summary.style.display = 'none';
        required.style.display= 'none';
        regular.style.display = 'none'; 
        
    }
    
    function InlineDeleteTweak()
    {    
        if(confirm(MESSAGE_DELETE_TWEAK_CONFIRM))
        {
            return true;
        }
        return false;
    }
    
    function AddTweakHelpfulVoteCount(tweakId,UserId,countLabel,voteDiv)
    {
        var countLabelControl = $get(countLabel);
        var am = new AsyncMethods();      
        am.AddRecipeTweakHelpfulVote(tweakId,UserId,function(result)
        {
            if(result != "0")
            {
                countLabelControl.innerHTML = result;
                $get(voteDiv).style.visibility = "hidden";               
            }
            //window.location = "#"; 
        },function(){});         
    }
    
    
    //End Javascript of RecipeTweaksControl.ascx
    
    
    
    //End Javascript of ReviewRatingCommentsControl.ascx
    function EditRecipeReview(ReviewTextBox,ReviewLabel,EditImageButton,DeleteImageButton,UpdateImageButton,CancelImageButton,EditDiv,UpdateDiv,RatingReadDiv,RatingEditDiv,DifficultyLevel,DifficultyDiv)
    {
        
        var reviewTextBoxControl = $get(ReviewTextBox);              
        var ReviewLabel = $get(ReviewLabel);

        var editControl = $get(EditImageButton);
        var deleteControl = $get(DeleteImageButton);
        var updateControl = $get(UpdateImageButton);
        var cancelControl = $get(CancelImageButton);       
        
        var ratingReadOnlyDiv = $get(RatingReadDiv);
        var ratingEditableDiv = $get(RatingEditDiv);
        
        var difficultyLevelId = $get(DifficultyLevel);   
        
        var parentDiv;
        var radiobuttonlist;
        $get(DifficultyDiv).style.display = "block";
        
        if(navigator.appName == "Microsoft Internet Explorer")
        {
            parentDiv = difficultyLevelId.parentElement;
            radiobuttonlist = parentDiv.getElementsByTagName("input");
            
            for(var i =0; i<radiobuttonlist.length;i++)
            {
               
                if(radiobuttonlist[i].type == "radio")
                {
                    radiobuttonlist[i].disabled  = false;
                    ParentSpanControl = radiobuttonlist[i].parentElement;
                    ParentSpanControl.disabled =  false;
                    
                    if(i == 0)
                    {
                        var  parentspan  = ParentSpanControl.parentElement;
                        parentspan.disabled =  false;                     
                    }
                    
                }
            }
            
        }
        else
        {
            parentDiv = difficultyLevelId.parentNode
            radiobuttonlist = parentDiv.getElementsByTagName("input");        
            
            for(var i =0; i<radiobuttonlist.length;i++)
            {
                if(radiobuttonlist[i].type == "radio")
                {
                    radiobuttonlist[i].disabled  = false;
                    ParentSpanControl = radiobuttonlist[i].parentNode;
                    ParentSpanControl.disabled =  false 
                }
            }
        }
        
        ratingReadOnlyDiv.style.display = 'none';
        ratingEditableDiv.style.display = 'block';                        
        
        var editDivControl = $get(EditDiv);
        editDivControl.style.display = 'none';
        var updateDivControl = $get(UpdateDiv)
        updateDivControl.style.display = 'block';      

        reviewTextBoxControl.style.display= 'block';
        ReviewLabel.style.display= 'none';           
        reviewTextBoxControl.value = ReviewLabel.innerHTML;       
                           
    } 

    function CancelRecipeReview(ReviewTextBox,ReviewLabel,EditImageButton,DeleteImageButton,UpdateImageButton,CancelImageButton,EditDiv,UpdateDiv,RatingReadDiv,RatingEditDiv,DifficultyLevel,SelectedDifficulty,DifficultyDiv,ValidationSummary,CommentRequired,CommentValidator)    
    {
        var reviewTextBoxControl = $get(ReviewTextBox);                
        var ReviewLabel = $get(ReviewLabel);

        var editControl = $get(EditImageButton);
        var deleteControl = $get(DeleteImageButton);
        var updateControl = $get(UpdateImageButton);
        var cancelControl = $get(CancelImageButton); 
        
        var ratingReadOnlyDiv = $get(RatingReadDiv);
        var ratingEditableDiv = $get(RatingEditDiv); 
        
        var summary = $get(ValidationSummary);
        var required = $get(CommentRequired);
        var validator = $get(CommentValidator);
        
        ratingReadOnlyDiv.style.display = 'block';
        ratingEditableDiv.style.display = 'none';                       
        
        
        var difficultyLevelId = $get(DifficultyLevel); 
          
        var parentDiv;
        var radiobuttonlist;
        $get(DifficultyDiv).style.display = "none";
        if(navigator.appName == "Microsoft Internet Explorer")
        {
            parentDiv = difficultyLevelId.parentElement;
            radiobuttonlist = parentDiv.getElementsByTagName("input");
            
            for(var i =0; i<radiobuttonlist.length;i++)
            {
               
                if(radiobuttonlist[i].type == "radio")
                {
                    if(SelectedDifficulty == i+1)
                    {
                        radiobuttonlist[i].checked = true;
                    }  
                    radiobuttonlist[i].disabled  = true;
                    ParentSpanControl = radiobuttonlist[i].parentElement;
                    ParentSpanControl.disabled =  true;
                    
                    if(i == 0)
                    {
                        var  parentspan  = ParentSpanControl.parentElement;
                        parentspan.disabled =  true;                     
                    }
                    
                }
            }
            
        }
        else
        {
            parentDiv = difficultyLevelId.parentNode
            radiobuttonlist = parentDiv.getElementsByTagName("input");        
            
            for(var i =0; i<radiobuttonlist.length;i++)
            {
                if(radiobuttonlist[i].type == "radio")
                {
                    if(SelectedDifficulty == i+1)
                    {
                        radiobuttonlist[i].checked = true;
                    }  
                    radiobuttonlist[i].disabled  = true;
                    ParentSpanControl = radiobuttonlist[i].parentNode;
                    ParentSpanControl.disabled =  true 
                }
            }
        }  

        var editDivControl = $get(EditDiv);
        editDivControl.style.display = 'block';
        var updateDivControl = $get(UpdateDiv)
        updateDivControl.style.display = 'none';                 

        reviewTextBoxControl.style.display= 'none';
        ReviewLabel.style.display= 'block';           
        reviewTextBoxControl.value = '';    
        
        summary.style.display = 'none';
        required.style.display = 'none';
        validator.style.display = 'none';   
      
    }

    function InlineDeleteReview()
    {    
        if(confirm(MESSAGE_DELETE_REVIEW_CONFIRM))
        {
            return true;
        }
        return false;
    }
      
    //End Javascript of ReviewRatingCommentsControl.ascx  
    
    //Delete confirmation for MyPhotos
    function DeletePhoto()
    {    
        if(confirm(MESSAGE_DELETE_PHOTO_CONFIRM))
        {
            return true;
        }
        return false;
    }
    
    
    /* Begin the Javascript for the page EmailFriend.aspx */
    
    function EmailValidatorFunction(src,args)
    {
        args.IsValid = true;
        var friendsEmailControl = GetClientIDOfuxFriendsEmailTextBox();
        
        var emailCustomValidator = GetClientIDOfuxFriendsEmailTextBoxCustomValidator();
        var friendsEmailValidatorCotrolId = $get(emailCustomValidator)        
        
        var friendsEmails = $get(friendsEmailControl).value;
        var regularExp = /^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/;                         

        if(trimString(friendsEmails).length == 0)
        {
            args.IsValid = false;
            friendsEmailValidatorCotrolId.errormessage = MESSAGE_FRIEND_EMAIL_REQUIRED;
        }
        else if(trimString(friendsEmails).length > 800)
        {
            args.IsValid = false;
            friendsEmailValidatorCotrolId.errormessage = MESSAGE_FRIEND_EMAIL_LENGTH ;
        }
        else
        {
            var emails = friendsEmails.split(",");
            if(friendsEmails.length != 0 && friendsEmails.length <= 800)
            {
                if(emails.length == 0)
                {
                    args.IsValid = false;
                    friendsEmailValidatorCotrolId.errormessage = MESSAGE_FRIEND_EMAIL_MINIMUM_VALIDATOR;
                }            
                else if(emails.length > 20)
                {
                    args.IsValid = false;
                    friendsEmailValidatorCotrolId.errormessage = MESSAGE_FRIEND_EMAIL_MAXIMUM_VALIDATOR;
                }
                else
                {             
                    for(var i=0;i<emails.length;i++)
                    {                        
                        if(!regularExp.test(trimString(emails[i])))
                        {
                            args.IsValid = false;
                            friendsEmailValidatorCotrolId.errormessage = MESSAGE_FRIEND_EMAIL_INVALID;
                            break;
                        }
                    }                
                }
            }
        }
        
    } 
    
     /* End the Javascript for the page  EmailFriend.aspx */

/* Begin Javascript  MoreTweaksControl.ascx*/

    function  EditMoreTweak(editTweakTypeDivId,readOnlyTweakDivId,tweakLabelId,updateTweakDivId,editTweakDivId)
    {
        var editTweakTypeDiv = $get(editTweakTypeDivId);
        var readOnlyTweakDiv = $get(readOnlyTweakDivId);
        var tweakLabel = $get(tweakLabelId);
        var updateTweakDiv = $get(updateTweakDivId);
        var editTweakDiv = $get(editTweakDivId);       
        
        editTweakTypeDiv.style.display = "inline";
        readOnlyTweakDiv.style.display = "none";
        tweakLabel.style.display = "none";
        updateTweakDiv.style.display = "block";
        editTweakDiv.style.display = "none";
    }
    
    function  CancelMoreTweak(editTweakTypeDivId,readOnlyTweakDivId,tweakLabelId,updateTweakDivId,editTweakDivId,TweakText,TweakSummary,Requiredvalidator,RegularValidator)
    {
        var editTweakTypeDiv = $get(editTweakTypeDivId);
        var readOnlyTweakDiv = $get(readOnlyTweakDivId);
        var tweakLabel = $get(tweakLabelId);
        var updateTweakDiv = $get(updateTweakDivId);
        var editTweakDiv = $get(editTweakDivId);
        var tweak = $get(TweakText);
        var summary = $get(TweakSummary); 
        var required = $get(Requiredvalidator);     
        var regular = $get(RegularValidator);
        
        editTweakTypeDiv.style.display = "none";
        readOnlyTweakDiv.style.display = "inline";
        tweakLabel.style.display = "block";
        updateTweakDiv.style.display = "none";
        editTweakDiv.style.display = "block";
        tweak.value = tweakLabel.innerHTML;
        summary.style.display = 'none';
        required.style.display = 'none';
        regular.style.display = 'none';
    } 
    
    function AddMoreTweakHelpfulVoteCount(tweakId,UserId,countLabel,voterDivId)
    {
        var countLabelControl = $get(countLabel);
        var am = new AsyncMethods();      
        am.AddRecipeTweakHelpfulVote(tweakId,UserId,function(result)
        {            
            var tweakVoteFailureDivId =  GetClientIDOfuxAddTweakVoteFailureDiv();
            var tweakVoteSuccessDivId =  GetClientIDOfuxAddTweakVoteSuccessDiv();
            var deleteMoreTweakSuccessDivId =  GetClientIDOfuxDeleteMoreTweakSuccessMessageDiv();
            
            if(result != "0")
            {
                countLabelControl.innerHTML = result;
                $get(voterDivId).style.visibility="hidden";
                $get(tweakVoteFailureDivId).style.display = "none";
                $get(tweakVoteSuccessDivId).style.display = "block";
                $get(deleteMoreTweakSuccessDivId).style.display = "none";
            }
            else
            {
                $get(voterDivId).style.visibility="hidden";
                $get(tweakVoteFailureDivId).style.display = "none";
                $get(tweakVoteSuccessDivId).style.display = "none";
                $get(deleteMoreTweakSuccessDivId).style.display = "none";            
            }
                        
            
        },function(){});        
    }
/*End Javascript  MoreTweaksControl.ascx*/
//minified url encode/decode functions
var Url={
encode:function(string){
return escape(this._utf8_encode(string));
},
decode:function(string){
return this._utf8_decode(unescape(string));
},
_utf8_encode:function(string){
string=string.replace(/\r\n/g,"\n");
var utftext="";
for(var n=0;n<string.length;n++){
var c=string.charCodeAt(n);
if(c<128){
utftext+=String.fromCharCode(c);
}
else if((c>127)&&(c<2048)){
utftext+=String.fromCharCode((c>>6)|192);
utftext+=String.fromCharCode((c&63)|128);
}
else{
utftext+=String.fromCharCode((c>>12)|224);
utftext+=String.fromCharCode(((c>>6)&63)|128);
utftext+=String.fromCharCode((c&63)|128);
}
}
return utftext;
},
_utf8_decode:function(utftext){
var string="";
var i=0;
var c=0;
var c1=0;
var c2=0;
var c3;
while(i<utftext.length){
c=utftext.charCodeAt(i);
if(c<128){
string+=String.fromCharCode(c);
i++;
}
else if((c>191)&&(c<224)){
c2=utftext.charCodeAt(i+1);
string+=String.fromCharCode(((c&31)<<6)|(c2&63));
i+=2;
}
else{
c2=utftext.charCodeAt(i+1);
c3=utftext.charCodeAt(i+2);
string+=String.fromCharCode(((c&15)<<12)|((c2&63)<<6)|(c3&63));
i+=3;
}
}
return string;
}
};  

/************* 1.8 Profile Photos Javascript *****************/
function OnFilterChanged(sort, filter, sortOrderParamName, filterByParamName)
{
    // find the control
    var sortField = $get(sort);
    var filterField = $get(filter);
    // initialize string as empty
    var urlWithOutQS = '';
    // find the QS starting position
    var position = window.location.href.indexOf("?");
    // if query string is present
    if(position != -1)
    {        
        // remove the query string from the href.
        urlWithOutQS = window.location.href.substring(0,position);
    }  
    else
    {
        // otherwise, same as current window href.
        urlWithOutQS = window.location.href;
    }
    // filter by value    
    var fb = filterField.options[filterField.selectedIndex].value;
    // sort by value
    var sb = sortField.options[sortField.selectedIndex].value;
    // new url for redirection.
    var redirectUrl = urlWithOutQS + "?" + sortOrderParamName + "=" + sb + "&" + filterByParamName + "=" + fb;
    // redirect to new url.
    window.location.href = redirectUrl;
}

function FilterResult(url,id)
{
	window.location.href= url+$get(id).value;
}


///added new methods for expand collapse functionality in the My comments/review page - start

 function ExpandCollapseC(oImage,containerDiv)
{
    var oDiv = $get(containerDiv);
    if(IsVisible(oDiv))
    {
        setVisible(oDiv,false);
        oImage.src = PHOTO_URL+ "/ic_plus_square.gif";
    }
    else
    {
        setVisible(oDiv,true);
        oImage.src = PHOTO_URL+ "/ic_minus_square.gif";
    }
}


function ExpandAllControls(hdnExpandCollapseAllValue)
{ 
    var clientIds = new Array();
    clientIds = hdnExpandCollapseAllValue.split(',');            
    for(i = 0;i< clientIds.length-1;i++)
    {
        $get(clientIds[i]).src = PHOTO_URL+ "/ic_minus_square.gif";
        i=i+1;
        $get(clientIds[i]).style.display= "block";
    }                      
}
function CollapseAllControls(hdnExpandCollapseAllValue)
{
    var clientIds = new Array();
    clientIds = hdnExpandCollapseAllValue.split(',');            
    for(i = 0;i< clientIds.length-1;i++)
    {
        $get(clientIds[i]).src = PHOTO_URL+ "/ic_plus_square.gif";
        i=i+1;
        $get(clientIds[i]).style.display= "none";
    }  
}

///added new methods for expand collapse functionlaity in the My comments/review page - end
$addClass = function(o,clsname)
{
   if (o.className)
      {
		var arrList = o.className.split(' ');
        var strClassUpper = clsname.toUpperCase();
        for(var i = 0; i < arrList.length; i++ )
        {
            if (arrList[i].toUpperCase() == strClassUpper)
               {
               arrList.splice(i, 1);
               i--;
               }
         }
      arrList[arrList.length] = clsname;
      o.className = arrList.join(' ');
      }
   else
      {
		 o.className = clsname;
      }

}
$removeClass = function(o,clsname)
{
	if (o.className)
      {
		  var arrList = o.className.split(' ');
		  var strClassUpper = clsname.toUpperCase();
		  for(var i = 0; i < arrList.length; i++ )
		  {
			 if (arrList[i].toUpperCase() == strClassUpper)
			 {
				arrList.splice(i, 1);
				i--;
			  }
		  }
		o.className = arrList.join(' ');
      }
}

function ValidateYield(src,args)
{
	args.IsValid=true;
	var YeildText=GetClientIDtxtYeild();
	var YeildUnitText=GetClientIDtxtYeildUnit();
	var Yeild=$get(YeildText).value;
	var YeildUnit=$get(YeildUnitText).value;  
	if((Yeild !=null && Yeild !="") && (YeildUnit == null || YeildUnit =="") )
	{ 
		src.errormessage = MESSAGE_YIELD_UNIT;
		args.IsValid=false;
		return false;  
	} 
	else if((YeildUnit !=null && YeildUnit !="") && (Yeild == null || Yeild==""))
	{   
		src.errormessage = MESSAGE_YIELD;   
		args.IsValid=false;
		return false;  
	}    
}