﻿var recipenum="";
var locString=document.location.href;
var thisOne
var buyProduct

function showProduct_Off(category,brand){
    //alert(category);
    //alert(brand);
    //alert(document.images['product1'].src='/Products/' + category + '/images/' + brand + '/product1_off.jpg');
    //alert('showProduct_Off');
     document.getElementById('bigProduct1').style.display='none';
     document.getElementById('bigProduct2').style.display='none';
     if (document.location.href.search('Fla-Vor-Ice') != -1)
        {document.getElementById('bigProduct3').style.display='none';
         //document.getElementById('bigProduct4').style.display='none';
        }
     if (document.location.href.search('Royal') != -1){
         document.images['product1'].src="/Products/Desserts/images/Royal/Royal_Gelatin_flavND.jpg"
         document.images['product2'].src="/Products/Desserts/images/Royal/Royal_Pudding_INST_flavND.jpg"
         document.images['product3'].src="/Products/Desserts/images/Royal/Royal_Pudding_CS_flavND.jpg"
         document.images['product4'].src="/Products/Desserts/images/Royal/Royal_Gelatin_SF_flavND.jpg"
         document.images['product5'].src="/Products/Desserts/images/Royal/Royal_Pudding_SF_flavND.jpg"
         document.images['product6'].src="/Products/Desserts/images/Royal/Royal_Flan_flavND.jpg"
         document.getElementById('bigProduct3').style.display='none';
         document.getElementById('bigProduct4').style.display='none';
         document.getElementById('bigProduct5').style.display='none';
         document.getElementById('bigProduct6').style.display='none';
         }
     if ((document.location.href.search('Royal') == -1)&& (document.location.href.search('Fla-Vor-Ice')== -1)) {
        document.images['product1'].src='/Products/' + category + '/images/' + brand + '/product1.jpg';
        document.images['product2'].src='/Products/' + category + '/images/' + brand + '/product2.jpg';
        }
     //document.getElementById(thisone).style.display='none';
     document.getElementById('bigProductDiv').style.display='none';
     document.getElementById('defaultImg').style.visibility='visible';
}

function logo(){
    var fade=0,logo=document.getElementById(thisone).style,ms=(logo.opacity==0)?0:1,pace=setInterval(Fade,20);
    //alert(fade);
    function Fade(){if(fade<100){fade+=1;if(ms)logo.filter="alpha(opacity="+fade+")";else logo.opacity=(fade/100)}else clearInterval(pace)};
    }

function showProduct(product,category,brand){
    //alert(product);
    //document.getElementById('productBlocks').style.display='none';
     document.getElementById('defaultImg').style.visibility='hidden';
     thisone = 'bigProduct' + product;
     document.getElementById('bigProduct1').style.display='none';
     document.getElementById('bigProduct2').style.display='none';
     if (document.location.href.search('fla-vor-ice') != -1){
         document.getElementById('bigProduct3').style.display='none';
         //document.getElementById('bigProduct4').style.display='none';
         }
     if (document.location.href.search('Royal') != -1){
         document.images['product1'].src="/Products/Desserts/images/Royal/Royal_Gelatin_flavND2.jpg"
         document.images['product2'].src="/Products/Desserts/images/Royal/Royal_Pudding_INST_flavND2.jpg"
         document.images['product3'].src="/Products/Desserts/images/Royal/Royal_Pudding_CS_flavND2.jpg"
         document.images['product4'].src="/Products/Desserts/images/Royal/Royal_Gelatin_SF_flavND2.jpg"
         document.images['product5'].src="/Products/Desserts/images/Royal/Royal_Pudding_SF_flavND2.jpg"
         document.images['product6'].src="/Products/Desserts/images/Royal/Royal_Flan_flavND2.jpg"
         document.getElementById('bigProduct3').style.display='none';
         document.getElementById('bigProduct4').style.display='none';
         document.getElementById('bigProduct5').style.display='none';
         document.getElementById('bigProduct6').style.display='none';
         }
    if ((document.location.href.search('Royal') == -1)&& (document.location.href.search('Fla-Vor-Ice')== -1)) {
        document.images['product1'].src='/Products/' + category + '/images/' + brand + '/product1_off.jpg';
        document.images['product2'].src='/Products/' + category + '/images/' + brand + '/product2_off.jpg';
        }

     document.getElementById(thisone).style.display='block';
     document.getElementById('bigProductDiv').style.display='block';
     
     
     //document.getElementById(thisone).style.display='block';
    //alert(thisone);
    //logo();
    //
    
}
function showProductDouble(product){
    //alert(product);
    //document.getElementById('productBlocks').style.display='none';
     document.getElementById('defaultImg').style.visibility='hidden';
     thisone = 'bigProduct' + product;
     document.getElementById('bigProduct1').style.display='none';
     document.getElementById('bigProduct2').style.display='none';
     document.getElementById(thisone).style.display='block';
     document.getElementById('bigProductDiv').style.display='block';
     
     //document.getElementById(thisone).style.display='block';
    //alert(thisone);
    //logo();
    //
    
}
function recipePopup(whichRecipe){
    recipenum=whichRecipe;
    recipeWin = window.open("/Recipes-and-Ideas/Recipes/recipe_detail.aspx?recipenum=" + recipenum, "recipeWin", "width=548,height=585,scrollbars=no"); 
    recipeWin.focus();
    //self.blur();
}

function detailPopup(url){
    detailWin = window.open(url, "detailWin", "width=617,height=628,scrollbars=no"); 
    //self.blur();
}
function TermsAndConditionsPopup(prodType) {
    termsConditionsWin = window.open("../TermsConditions/TermsConditionsPopup.aspx?prodType=" + prodType, "termsConditionsWin", "width=500,height=500,scrollbars=no"); 
    termsConditionsWin.focus();
    self.blur();
}

function getWidth(){
            //alert(document.getElementById('product_image').width);
            //alert(document.getElementById('product_image').height);
            var nutritionWidth =  document.getElementById('nutrition_image').width;
            var nutritionHeight =  document.getElementById('nutrition_image').height;
            var productWidth = document.getElementById('product_image').width;
            var productHeight = document.getElementById('product_image').height;
            var imageRatio = ((document.getElementById('product_image').height)/(document.getElementById('product_image').width));
            var nutritionRatio = ((document.getElementById('nutrition_image').width)/(document.getElementById('nutrition_image').height));
            var newHeight
            var newWidth
            if (document.getElementById('product_image').width > '250'){              
                document.getElementById('product_image').width='250';
                newHeight= (imageRatio) * (productHeight);
                document.getElementById('product_image').height=newHeight;
            }
            if (document.getElementById('nutrition_image').height > '400'){              
                document.getElementById('nutrition_image').height='400';
                newWidth= (nutritionRatio) * (nutritionWidth);
                document.getElementById('nutrition_image').width=newWidth;
            }
            
        }

function nutritionPopup(casecode){
    detailWin = window.open('/Products/detail.aspx?casecode=' + casecode, "detailWin", "width=617,height=628,scrollbars=no,top=0"); 
    //self.blur();
}

function getTheRecipe(){
    recNum = (locString.lastIndexOf('='));
    recipenum=(locString.substring(recNum + 1));
    //window.frames['recipeFrame'].location = "/Recipes-and-Ideas/Recipes/recipe_detail.aspx?recipenum=" + recipenum;
}

function GetUrl()
{
    // alert(document.getElementById('ddlSubject').value);
     var input= document.getElementById('ddlSubject').value;
     if (input==0)
     {
        //alert ("i  am in if");
      self.location.href="/Contact-Us/Complaints-Form.aspx";//return false;
     }
     else
     {
    self.location.href="/Contact-Us/Complaints-Form.aspx";//return false;
     }
      
}
    function testPop(whichProduct){
        alert(whichProduct + 'coming from flash');
    }

	var whichProduct
    //whichProduct
	var url = String(locString);
	if (url.search('Products=') != -1) {
	    alert('whichProduct Name is "' + whichProduct);

        if (url.search('freezerBars') != -1) {whichProduct='freezerBars';}
		else if (url.search('beverages') != -1) {whichProduct='beverages';}
		else if (url.search('desserts') != -1) {whichProduct='desserts';}
        else if (url.search('canadian') != -1) {whichProduct='';}
		else {whichProduct='';}
    }
    else
    {
        whichProduct = '';
        //alert('whichProduct Name is not found"' );
    }


    function flashName(thisfile) {
        alert('File Name is "' + thisfile);
    }


    function addFlash(thisfile, height, width) {
		document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"');
		document.write('codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"'); 
		document.write('width="');
		document.write(width);
		document.write('"');
		document.write('height="');
		document.write (height);
		document.write ('" id="');
		document.write (thisfile);
		document.write ('" align="top">');
		document.write ('<param name="wmode" value="transparent">');
		document.write('<param name="allowScriptAccess" value="always" />');
		document.write('<param name="movie" value="/flash/' + thisfile + '.swf" />');
		document.write (' <param name=FlashVars value="whichProduct=  ');
		document.write (whichProduct) + 
		document.write (' " />') +
		document.write('<param name="quality" value="high" />');
		document.write('<param name="bgcolor" value="#ffffff" />');
		document.write('<embed src="/flash/'); 
		document.write(thisfile);
		document.write('.swf"');
		document.write('FlashVars="whichProduct=');
		document.write(whichProduct + '"');
		document.write('wmode="transparent"');
		document.write('quality="high" bgcolor="#ffffff"'); 
		document.write('width="');
		document.write(width);
		document.write('"');
		document.write(' height="');
		document.write(height);
		document.write ('" name="');
		document.write (thisfile);
		document.write('" align="top" allowScriptAccess="always" ');
		document.write('type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
		document.write('</object>');
		}
		
		
		// ----- code for displaying parts of contact us submission page -----
		
		function HideAndShow(){
		  var subject= document.getElementById('ddlsubjectHtml').value;
		  var age =document.getElementById('ddlage').value;
//		  alert(age);
//		  alert(subject);

          if(age=='0')  //the 'Choose' value.. display nothing
		  {
		 	document.getElementById('divContact').style.display='none';
		    document.getElementById('complaint').style.display='none';
		    document.getElementById('generalContact').style.display='none'; 
		    document.getElementById('under13Name').style.display='none';
		    document.getElementById('over13Name').style.display='none';
		  } 
		 
		 else if(age=='1')  // user is under 18
		  {
		    //alert('i am underage); 
		    WriteUnder18Cookie() 
		    document.getElementById('divContact').style.display='none';
            document.getElementById('complaint').style.display='none';
		    document.getElementById('generalContact').style.display='none';
		    document.getElementById('over13Name').style.display='none';
		    document.getElementById('under13Name').style.display='block';
		  } 
		  
		  else if (age>='2' && (subject=='1' || subject=='2' || subject=='4' )) // age 2 or greater means user says they are 18 or older
		  {
//		    alert('i am in if');
		    if (PreventUnder18Submit())
		    {
		    //alert('i am in share thoughts');
		        document.getElementById('complaint').style.display='none';
		        document.getElementById('divContact').style.display='block';
		        document.getElementById('generalContact').style.display='block';
		        document.getElementById('over13Name').style.display='block';
		        document.getElementById('under13Name').style.display='none';
		    }
		  }
 
		  else if (age>='2' && subject=='3') //3 = complaint
		  {
		    //alert('i am in if');
		    if (PreventUnder18Submit())
		    {
		        document.getElementById('complaint').style.display='block';
		        document.getElementById('divContact').style.display='none';
		        document.getElementById('generalContact').style.display='block';
		        document.getElementById('over13Name').style.display='block';
		        document.getElementById('under13Name').style.display='none';
		     }
		  }
		  
		  else if (age>='2' && subject=='0')  //display nothing since subject not selected
		  {
	        document.getElementById('divContact').style.display='none';
	        document.getElementById('complaint').style.display='none';
	        document.getElementById('generalContact').style.display='none';
	        document.getElementById('over13Name').style.display='none';
	        document.getElementById('under13Name').style.display='none';
		  }
		  else
		  {
		    if (PreventUnder18Submit())
		    {
		        document.getElementById('divContact').style.display='block';
		        document.getElementById('complaint').style.display='none';
		        document.getElementById('generalContact').style.display='block';
		        document.getElementById('under13Name').style.display='none';
		     } 
		  }
		}


    // -------------     begin of under13 code  ------------- 
    
        var cname = "under18" // name of the cookie 
        var data ="1";    // data to be stored(should not be null) 
        var cpath = "";   // path for which allowed [Optional] 
        var cdomain = ""; // domain for which allowed [Optional] 

        function PreventUnder18Submit()
        {
          //check if the form has been submitted before
          if( ExistsCookie(cname) )
          {
             //alert("does not collect information from children under 18.");
            document.getElementById('divContact').style.display='none';
            document.getElementById('complaint').style.display='none';
		    document.getElementById('generalContact').style.display='none';
		    document.getElementById('over13Name').style.display='none';
		    document.getElementById('under13Name').style.display='block';
 
            //reset the dropdown lists so not to confuse the young ones 
            document.getElementById('ddlage').value = 1;
            document.getElementById('ddlsubjectHtml').value = 0;
             return false;
          }
          else   // Under 13 Form has not been submitted before
          {
            //alert("will collect information from adults over 18.");
            return true;
          }
        }
         

        // Writes the specified data to the cookie file set to expire after 1 day
        function WriteUnder18Cookie() 
        {   
           // alert('in WriteUnder18Cookie function');
 
            // Set expiry Date to 1 day from now 
//            now= new Date();  // get current date and time 
//            var expiryDate = new Date(); 
//            expiryDate.setTime((now.getTime() + 1*24*60*60*1000)); 
//             var Cookie = cname + "=" + escape(data) 
//                +((expiryDate)?"; expires="+expiryDate.toGMTString():"") 
//                + ((cpath)? "; path=" + cpath : "" ) 
//                + ((cdomain)?"; domain=" + cdomain : "" ); 
            //Set cookie 
           // alert('setting cookie');
           // document.cookie = Cookie; 

            // do not set expiry Date so cookie expires when session ends (browser is closed)                  
            var under18;
            document.cookie = 'under18=' + under18;
           return true; 
        } 
 
 
        //Checks if the specified cookie exists or not 
        function ExistsCookie(name) 
         { 
         //alert('in ExistsCookie function');
              // cookies are separated by semicolons 
              var aCookie = document.cookie.split("; "); 
              for (var i=0; i < aCookie.length; i++) 
              { 
                // a name/value pair is separated by an = sign 
                var aCrumb = aCookie[i].split("="); 
                if (name == aCrumb[0])  
                  return true; 
              } 
              // a cookie with the requested name does not exist 
              return false; 
        } 

    // -------------     end of under13 code  ------------- 
   
    

function OpenNewWin(url,windowName) {
agent = navigator.userAgent;
params  = "";
params += "toolbar=1,";
params += "location=1,";
params += "directories=1,";
params += "status=1,";
params += "menubar=1,";
params += "scrollbars=1,";
params += "resizable=1,";
params += "width=325,";
params += "height=400";  
   
win = window.open(url, windowName , params);
if (agent.indexOf("Mozilla/2") != -1 && agent.indexOf("Win") == -1) {
	win = window.open(url, windowName , params);
}
if (!win.opener) {
	win.opener = window;
}
}

//Script used to write Privacy Alert Popups
function PrivacyAlert(Website) 
{
        //alert(Website);
		confirmWindow=window.open("","exitWindow","width=420,height=225,directories=0,resizable=0,location=0, menubar=0, scrollbars=0,toolbar=0");
		confirmWindow.document.write("<html><head><title>Now Leaving JelSert.com</title></head><body bgcolor='#bfe5fa' onload='self.focus()'>");
		confirmWindow.document.write("<font face='helvetica' size='2'><br><b> You are now leaving JelSert.com.</b><br><br>This link will take you to a Web site to where our ");
		confirmWindow.document.write("<a href='javascript:void(0)' onclick=javascript:top.window.opener.location.href='/Privacy-Policy.aspx';> Privacy Policy</a> does not apply.");
		confirmWindow.document.write(" We encourage you to read the privacy policy of every Web site you visit.");
		confirmWindow.document.write("<br><br><a href='javascript:self.close()'>Cancel</a><br><br>");
		confirmWindow.document.write("<a href='javascript:void(0)' onclick=javascript:window.open('" + Website + "','NewWindow');self.close();>Continue</a></font></body></html>");
		confirmWindow.document.close();

}
