//to check whether enter key pressed or not
function enterKeyPressed(e)
{
	var characterCode;
    if(e && e.which){  //if which property of event object is supported (NN4)
	 e = e;
     characterCode = e.which;
	}
	else {
	  e = e;
	  characterCode = e.keyCode //character code is contained in IE's keyCode property
   }

   if(characterCode == 13) //if generated character code is equal to ascii 13 (if enter key)
   	  return true;
   else	
      return false;	
}

//hide and show alternativee divs or spans ect..

function handlingForgotPasswordLink(textFieldId, hiddedFieldId, formId)
{
    textFieldObj = document.getElementById(textFieldId);
	if(textFieldObj != null) textFieldValue = textFieldObj.value;
	
	hiddenFieldObj = document.getElementById(hiddedFieldId);
		
    if(hiddenFieldObj != null && textFieldValue != null && textFieldValue != "")		
	{
		formObj = document.getElementById(formId);
		if(formObj != null)
		{
		  hiddenFieldObj.value = textFieldValue;
		  formObj.submit();
		}  
	}
	else
	{
		location.href = "/Password/Assist";
	}
		
}

function HideandShowAltBlocks(hide_block_id, show_block_id)
{	
	hide_block_obj = document.getElementById(hide_block_id); 
	show_block_obj = document.getElementById(show_block_id);

	//hiding one obj first
	hide_block_obj.style.display = 'none';
	//showing other obj
	//$("#"+show_block_id).slideToggle("slow");
	show_block_obj.style.display = 'block';
}

function HideandShowAltInlines(hide_inline_id, show_inline_id)
{	
	hide_block_obj = document.getElementById(hide_inline_id); 
	show_block_obj = document.getElementById(show_inline_id);

	//hiding one obj first
	hide_block_obj.style.display = 'none';
	//showing other obj
	show_block_obj.style.display = 'inline';
}

function hideShowTextFieldValue(obj,defaultValue,event)
{
	 if(event=="focus" && obj.value==defaultValue)
	 {
	 	obj.value = "";
	 }
	 else if(event=="blur" && obj.value=="")	
		obj.value = defaultValue;
}

function changeIngredientCheckStatus(imageObj)
{
	imageSrcParts = imageObj.src.split("?");
	imageSrcParts = imageSrcParts[0].split("images");
	imageSrc = imageSrcParts[1];

   	if(imageObj.className == "uncheck")
	{
		imageObj.src = "/images/general/ico-check-a.gif";
		imageObj.className = "check";
		imageObj.title = "I don't have this";
	}
	else if(imageObj.className == "check")
	{
		imageObj.src = "/images/general/ico-check.gif";
		imageObj.className = "uncheck";
		imageObj.title = "I have this";
	}
}

function changeIngredientCheckStatusOnMouseOver(imageObj)
{
	imageSrcParts = imageObj.src.split("?");
	imageSrcParts = imageSrcParts[0].split("images");
	imageSrc = imageSrcParts[1];
		
	if(imageSrc == "/general/ico-check.gif")
	  imageObj.src = "/images/general/ico-check-a.gif";
}

function changeIngredientCheckStatusOnMouseOut(imageObj)
{
	imageSrcParts = imageObj.src.split("?");
	imageSrcParts = imageSrcParts[0].split("images");
	imageSrc = imageSrcParts[1];
		
	if(imageSrc == "/general/ico-check-a.gif")
	  imageObj.src = "/images/general/ico-check.gif";
}

//capitalize all words and join with plus in content	
function capWordsAndJoinWithPlus(content)
{
   content = content.replace("+","%2B");
   words = content.split(" "); 
   for (i=0 ; i < words.length ; i++){
      testwd = words[i];
      firLet = testwd.substr(0,1); //lop off first letter
      rest = testwd.substr(1, testwd.length -1)
      words[i] = firLet.toUpperCase() + rest   
   }         
   return escape(words.join("+"));
}

//capitalize all words and join with hyphen in content	
function capWordsAndJoinWithHyphen(content)
{
   content = content.replace("-","%2D");
   words = content.split(" "); 
   for (i=0 ; i < words.length ; i++){
      testwd = words[i];
      firLet = testwd.substr(0,1); //lop off first letter
      rest = testwd.substr(1, testwd.length -1)
      words[i] = firLet.toUpperCase() + rest   
   }         
   return escape(words.join("-"));
}
		
function invitationValidate()
{
	email = document.getElementById('email')  //email object
	passwd = document.getElementById('passwd')  //passwd object 
	page_loading = document.getElementById('page_loading')  //page_loading object 
			
	if(email.value=="")
	{
	 	alert('Enter Email.');
		email.focus();
	 	return false;
	}
	else
	{
		if(passwd.value=="")
		{
	 		alert('Enter Password.');
			passwd.focus();
		 	return false;
		}
		else
		{
     		page_loading.style.display='inline';
     		return true
		}		
	}
}

function getCheckedInterests(formObj, commonIdInCheckbox, totalInterests, hiddenFieldId)
{
	totalCheckedInterests = 0;
	
	/* checking each interest status. whether it was checked or not. */
	var checkedInterestsIds = new Array();
	for(i = 1;  i<=totalInterests; i++)
	{
		checkBoxId = commonIdInCheckbox+i;
		checkBoxObj = document.getElementById(checkBoxId);
		if(checkBoxObj != null && checkBoxObj.checked) 
		{
		   checkedInterestsIds.push(checkBoxObj.value);
		   totalCheckedInterests += 1;
		} 
	}
	
	if(totalCheckedInterests == 0)
	  alert("No iterest was checked");
	else
	{
	  hiddenFieldObj = document.getElementById(hiddenFieldId);
	  if(hiddenFieldObj != null) hiddenFieldObj.value = checkedInterestsIds.join(',');
	  //alert( hiddenFieldObj.value);
	  formObj.submit(); 
	}  
}

function isValidEmail(email)
{		
	 return (email.indexOf(".") > 2) && (email.indexOf("@") > 0);	
}	

function notifyCheckedEmails(formObj, allEmails,checkedEmailsListId,checkBoxCommonId)
{
	allEmailsList = allEmails.split(',');
  	totalEmails = allEmailsList.length;
	checkedEmailsList = "";
			
	for(j=1; j<=totalEmails; j++)
	{
	   if(document.getElementById(checkBoxCommonId+j.toString()).checked == true)
	   {  
		 if(checkedEmailsList == "")
	        checkedEmailsList = checkedEmailsList+allEmailsList[j-1];
		 else
		   checkedEmailsList = checkedEmailsList+","+allEmailsList[j-1];	   	 
	   }
	}
			
	if(checkedEmailsList != "")
	{
	    document.getElementById(checkedEmailsListId).value = checkedEmailsList;
		return true;
	}
	else
	{
		alert("Select Email.");
		return false;
	}
} 

function checkAll(name, checkboxesCount)
{
	for(i=1; i<=checkboxesCount; i++)
	{
		checkboxId = name+i.toString();
		document.getElementById(checkboxId).checked = true; 
	}
}

function uncheckAll(name, checkboxesCount)
{
	for(i=1; i<=checkboxesCount; i++)
	{
		checkboxId = name+i.toString();
		document.getElementById(checkboxId).checked = false;
	}
}

//returns true if enter key is pree
function isEnterKeyPressed(event) 
{
    var keyNum = 0;
    if (window.event) // IE
    {
        keyNum = event.keyCode;
    }
    else if (event.which) // Netscape/Firefox/Opera
    {
        keyNum = event.which;
    }
    else return false;  
    
	if (keyNum == 13) // Enter Key pressed, then start search, else do nothing.
      return true;
    else
      return false;
}

/* returns single space as search keyword when it is empty or null */
function searchKeyword(keyword)
{
	if(keyword == "" || keyword == null) keyword = " "; 
    return keyword;
}

function setHome()
{
   if (document.all) 
   {
	   document.body.style.behavior='url(#default#homepage)'; 
	   document.body.setHomePage('http://123recipes.com'); 
   }
   else if (window.sidebar) 
   { 
	   if(window.netscape) 
	   {
		   try 
		   { 
			   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
		   } 
		   catch(e) 
		   { 
			   alert("this action was aviod by your browser\nif you want to enable\nplease enter about:config in your address line,and change the value of signed.applets.codebase_principal_support to true"); 
		   } 
		} 
		var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch); 
		prefs.setCharPref('browser.startup.homepage','http://123recipes.com'); 
   } 
}

function imposeMaxLength(event, object, MaxLen)
{
    var key = event.keyCode ? event.keyCode : event.which;
	if(key == 8 || key == 46) // 8 is the keycode for the backspace key and 46 is the keycode for delete
	{   
       return true;
    }
	else
	{
        return (object.value.length < MaxLen);
    }
}



$(document).ready(function(){
	// scroll to top
	$('a.what-is-inside').click(function (){
		$("#what-is-inside-bottom").toggle();   
		$("#what-is-inside").slideToggle();
		   setTimeout(function () {
		    $.scrollTo("#what-is-inside-bottom", 500 );   
		   }, 500);
		return false;			
	});
});



