﻿
var IFrameObj; // our IFrame object
var reviewText;
  function RemoveHTML( strText )
    {
	    var regEx = /<[^>]*>/g;
	    return strText.replace(regEx, "");
    }
    
function GoTo (url)
{
    url = url.replace(/#/g,'&');
    location.href = url.replace('$','?').replace('#','&');
}
    
function callToServer(page, firstQueryString, secQueryString, thirdQueryString) {

        if(document.aspnetForm != null)
        {
        
            if(document.aspnetForm.txtReviewBox != null)
            {
                reviewText = RemoveHTML(document.aspnetForm.txtReviewBox.value);
                reviewText = reviewText.replace(/\r\n/g,"<br>");
            }
        }
          
          if (!document.createElement) {return true};
          var IFrameDoc;
          var URL = '/'+page+'?'+firstQueryString+'';
          if(secQueryString != '')
            URL  += '&'+secQueryString;
          
            if(thirdQueryString != '')
            {
                URL += '&'+thirdQueryString;
                URL +='&review='+reviewText+'';
            }
         
           if (!IFrameObj && document.createElement) {
            // create the IFrame and assign a reference to the
            // object to our global variable IFrameObj.
            // this will only happen the first time 
            // callToServer() is called
           try {
              var tempIFrame=document.createElement('iframe');
              tempIFrame.setAttribute('id','RSIFrame');
              tempIFrame.style.border='0px';
              tempIFrame.style.width='0px';
              tempIFrame.style.height='0px';
              IFrameObj = document.body.appendChild(tempIFrame);
              if (document.frames) {
                // this is for IE5 Mac, because it will only
                // allow access to the document object
                // of the IFrame if we access it through
                // the document.frames array
                IFrameObj = document.frames['RSIFrame'];
              }
            } catch(exception) {
              // This is for IE5 PC, which does not allow dynamic creation
              // and manipulation of an iframe object. Instead, we'll fake
              // it up by creating our own objects.
              iframeHTML='\<iframe id="RSIFrame" style="';
              iframeHTML+='border:0px;';
              iframeHTML+='width:0px;';
              iframeHTML+='height:0px;';
              iframeHTML+='"><\/iframe>';
              document.body.innerHTML+=iframeHTML;

              IFrameObj = new Object();
              IFrameObj.document = new Object();
              IFrameObj.document.location = new Object();
              IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
              IFrameObj.document.location.replace = function(location) {
                this.iframe.src = location;
              }
            }
          }
          
          if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
            // we have to give NS6 a fraction of a second
            // to recognize the new IFrame
            setTimeout('callToServer()',10);
            return false;
          }
          
          if (IFrameObj.contentDocument) {
            // For NS6
            IFrameDoc = IFrameObj.contentDocument; 
          } else if (IFrameObj.contentWindow) {
            // For IE5.5 and IE6
            IFrameDoc = IFrameObj.contentWindow.document;
          } else if (IFrameObj.document) {
            // For IE5
            IFrameDoc = IFrameObj.document;
          } else {
            return true;
          }
          
          IFrameDoc.location.replace(URL);
             
          return false;
   
}

function AddToRecipeBox(AssetID)
{
    //Omniture Tracking
    _sTrackAddtoRecipeBox();
    callToServer('server.aspx','boxAssetID='+AssetID+'','','');
    
}

 function handleResponse(rVal) 
    {
      if(document["saveRecipe"] != null)
      {
        document["saveRecipe"].src =  "/Images/saveRecipeBoxOn.gif";
      }
      
    }
     function handleResponseEmail(rVal) 
    {
        document.aspnetForm.ctl00$ContentPlaceHolder1$ZAK5xup3.value = "";
        document.aspnetForm.ctl00$ContentPlaceHolder1$hajuB8ux.value ="";
        document.aspnetForm.ctl00$ContentPlaceHolder1$zaS2ephe.value = "";
        document.aspnetForm.ctl00$ContentPlaceHolder1$XUYej8th.value = "";
        document.aspnetForm.ctl00$ContentPlaceHolder1$d2Suy5qu.value = "";
        document.getElementById("lblMsg").innerHTML = rVal+"<br><br>"; 

  
    }
    
    
    //Send Email

    function SendEmail(recID, recName)
    {
        var fName = document.aspnetForm.ctl00$ContentPlaceHolder1$ZAK5xup3.value
        var fEmail = document.aspnetForm.ctl00$ContentPlaceHolder1$hajuB8ux.value
        var tName = document.aspnetForm.ctl00$ContentPlaceHolder1$zaS2ephe.value
        var tEmail = document.aspnetForm.ctl00$ContentPlaceHolder1$XUYej8th.value
        var msg = document.aspnetForm.ctl00$ContentPlaceHolder1$d2Suy5qu.value
        //Omniture Tracking
        _sTrackSendToFriend();
               
        SendEmailFromServer(recID,recName,tEmail,tName,fEmail,fName, msg);
        
    }
    function SendEmailFromServer(recipeID, recipeName, toEmail, toName, fromEmail, fromName, msg) {

       
          if (!document.createElement) {return true};
          var IFrameDoc;
          var URL = '/server.aspx?RecipeID='+recipeID+'&RecipeName='+recipeName+'&toEmail='+toEmail+'&toName='+toName+'&fromName='+fromName+'&fromEmail='+fromEmail+'&message='+msg+'';

           if (!IFrameObj && document.createElement) {
            // create the IFrame and assign a reference to the
            // object to our global variable IFrameObj.
            // this will only happen the first time 
            // callToServer() is called
           try {
              var tempIFrame=document.createElement('iframe');
              tempIFrame.setAttribute('id','RSIFrame');
              tempIFrame.style.border='0px';
              tempIFrame.style.width='0px';
              tempIFrame.style.height='0px';
              IFrameObj = document.body.appendChild(tempIFrame);
              if (document.frames) {
                // this is for IE5 Mac, because it will only
                // allow access to the document object
                // of the IFrame if we access it through
                // the document.frames array
                IFrameObj = document.frames['RSIFrame'];
              }
            } catch(exception) {
              // This is for IE5 PC, which does not allow dynamic creation
              // and manipulation of an iframe object. Instead, we'll fake
              // it up by creating our own objects.
              iframeHTML='\<iframe id="RSIFrame" style="';
              iframeHTML+='border:0px;';
              iframeHTML+='width:0px;';
              iframeHTML+='height:0px;';
              iframeHTML+='"><\/iframe>';
              document.body.innerHTML+=iframeHTML;

              IFrameObj = new Object();
              IFrameObj.document = new Object();
              IFrameObj.document.location = new Object();
              IFrameObj.document.location.iframe = document.getElementById('RSIFrame');
              IFrameObj.document.location.replace = function(location) {
                this.iframe.src = location;
              }
            }
          }
          
          if (navigator.userAgent.indexOf('Gecko') !=-1 && !IFrameObj.contentDocument) {
            // we have to give NS6 a fraction of a second
            // to recognize the new IFrame
            setTimeout('callToServer()',10);
            return false;
          }
          
          if (IFrameObj.contentDocument) {
            // For NS6
            IFrameDoc = IFrameObj.contentDocument; 
          } else if (IFrameObj.contentWindow) {
            // For IE5.5 and IE6
            IFrameDoc = IFrameObj.contentWindow.document;
          } else if (IFrameObj.document) {
            // For IE5
            IFrameDoc = IFrameObj.document;
          } else {
            return true;
          }
          
          IFrameDoc.location.replace(URL);
             
          return false;
   
}