var arrIngredients = new Array();
var arrIngredientsNames = new Array();
// var strSiteURL = "http://localhost/";
var strSiteURL = "https://www.drinkmixguide.com/";
function getURLParamValue( strParamName, blnValueOnly ) {
if(blnValueOnly)
intReturnType = 1; //setting this to 1 returns only the value of the param
else
intReturnType = 0; //setting this to 0 returns the param and value
var strRegex = "[\\?&]"+strParamName+"=([^]*)";
var objRegex = new RegExp( strRegex );
var results = objRegex.exec( location.href );
if( results == null )
return '';
else
return results[intReturnType];
}
//will take a url and replace the current value of a param, or it will just add the param if new
function replaceURLParamValue(strURL, strParamName, strParamValue) {
strURLParam = getURLParamValue(strParamName, false);
strSeperator = '';
if(strURLParam == '') {
if(strURL.indexOf('&') < 0)
strSeperator = '?';
else
strSeperator = '&';
strNewURL = strURL + strSeperator + strParamName + '=' + strParamValue;
}
else {
if(strURLParam.charAt(0)=='?') {
strSeperator = '?';
}
strURLParam = strURLParam.replace('&', '');
strNewURL = strURL.replace(strURLParam, strSeperator+strParamName + '=' + strParamValue)
}
return strNewURL;
}
/*
* Desc: Function fills all the specified selection fields with specified values on the page
* Return: none
*/
function fillSelections( strForm, objSelects ) {
var objForm = document.getElementById( strForm );
for (var i in objSelects) {
if(objSelects[i] != '') { //&& parseInt(objSelects[i], 10) != 0
objForm.elements[i].value = objSelects[i];
}
}
}
function loadPage( intPage, strPageURL , strParams, blnAjax, strInto ) {
var strURL = '';
strPageURL = strPageURL.slice(1);
if( getURLParamValue('intPage') == '' ) {
if(strParams!='') strParams = strParams+'&';
strURL += strSiteURL+strPageURL + '?' + strParams + 'intPage=' + intPage;
}
else {
strURL += strSiteURL+strPageURL + '?' + strParams.replace(getURLParamValue('intPage').replace('?', ''), '&intPage=' + intPage);
}
//if( strURL != strVisitedURL ){
if( blnAjax )
//alert(strURL);
AjaxRequest( strURL, strInto, default_handle );
else
location.href = strURL;
//}
strVisitedURL = strURL;
}
function notLoggedIn() {
strTitle='You Must Login.';
strContent='You must Login to perform that action.'; //PENDING, add a login here...
showShadowBox(strTitle, strContent);
}
function IsNumeric(sText) {
var ValidChars = "0123456789.";
var IsNumber=true;
var Char;
for (i = 0; i < sText.length && IsNumber == true; i++)
{
Char = sText.charAt(i);
if (ValidChars.indexOf(Char) == -1)
{
IsNumber = false;
}
}
return IsNumber;
}
function formatItem(row) {
arrInfo = new Array();
arrInfo = row[1].split('_'); //arrInfo[0] - strDrinkURL ... arrInfo[1] - strCategory
strReturn = '';
strReturn += '' + row[0] + '
';
strReturn += '
Drink contains keyword '+objTextSearch.value+'
';
strReturn += '
';
return strReturn;
}
function formatItemIngredient(row) {
arrInfo = new Array();
//arrInfo = row[1].split('_'); //arrInfo[0] - strDrinkURL ... arrInfo[1] - strCategory
strReturn = '';
strReturn += '' + row[0] + '
';
strReturn += '
';
return strReturn;
}
function findValue(li) {
if( li == null ) return alert("No match!");
// if coming from an AJAX call, let's use the CityId as the value
if( !!li.extra ) var sValue = li.extra[0];
// otherwise, let's just display the value in the text box
else var sValue = li.selectValue;
alert("The value you selected was: " + sValue);
}
function selectItem(li) {
arrInfo = li.extra[0].split('_'); //arrInfo[0] - strDrinkURL ... arrInfo[1] - strCategory
window.location.href = strSiteURL+arrInfo[1]+'/' + arrInfo[0];
}
function selectItemIngredient(itemName, itemId) {
//arrInfo = li.extra[0].split('_');
//alert('Picked!');
//window.location.href = strSiteURL+arrInfo[1]+'/' + arrInfo[0];
addIngredientWithResults((itemName).stripslashes(), itemId);
}
function lookupAjax(){
var oSuggest = $("#txtJokeSearch")[0].autocompleter;
oSuggest.findValue();
return false;
}
function lookupLocal(){
var oSuggest = $("#CityLocal")[0].autocompleter;
oSuggest.findValue();
return false;
}
function showMoreCategory() {
document.getElementById('hiddenMore').style.display = 'block';
}
function hideMoreCategory() {
document.getElementById('hiddenMore').style.display = 'none';
}
function selectSearchTextBox(objThis) {
if(objThis.value == 'Enter drink here...')
objThis.value=''
}
function outSearchTextBox(objThis) {
if(objThis.value == '')
objThis.value='Enter drink here...'
}
function selectIngredientTextBox(objThis) {
if(objThis.value == '')
objThis.value=''
}
function outIngredientTextBox(objThis) {
if(objThis.value == '')
objThis.value=''
}
function searchDrink() {
if( objTextSearch.value == 'Enter drink here...' )
objTextSearch.focus();
else
window.location.href=strSiteURL+"search.php?strDrinkName="+objTextSearch.value;
}
function addIngredient(strIngredientName, intIngredientId) {
if(!arrIngredients.in_array(intIngredientId)) {
objSelectedIngredients = document.getElementById('selectedIngredients');
objResultsDrinks = document.getElementById('resultsDrinks');
objStrSearchIngredient = document.getElementById('strSearchIngredient');
var objNewIngredient = document.createElement('div');
objNewIngredient.setAttribute('id', 'ingredient_'+intIngredientId);
svgMinus = '';
strIngredient = strIngredientName + '' + svgMinus + '';
objNewIngredient.innerHTML = '' + strIngredient + '
';
objResultsDrinks.innerHTML = '';
if(objSelectedIngredients.innerHTML == 'No Ingredients Selected.') {
objSelectedIngredients.innerHTML = '';
}
objSelectedIngredients.appendChild(objNewIngredient);
objStrSearchIngredient.value = '';
arrIngredients.push(intIngredientId);//add ingredient id to js array
arrIngredientsNames.push(strIngredientName);
}
}
function addIngredientWithResults(strIngredientName, intIngredientId) {
addIngredient(strIngredientName, intIngredientId);
getResults();
}
function getResults() {
strIngredients=arrIngredients.join(','); // move array to string
strIngredientsNames=arrIngredientsNames.join(',');
if (strIngredients === '' || strIngredientsNames === '') {
return;
}
AjaxRequest(strSiteURL+'ajaxUpdateIngredientsResults.php?strIngredients='+strIngredients+'&strIngredientsNames='+strIngredientsNames, 'resultsDrinks', default_handle);
}
function removeIngredient(strIngredientName, intIngredientId) {
var d = document.getElementById('selectedIngredients');
var olddiv = document.getElementById('ingredient_'+intIngredientId);
objResultsDrinks = document.getElementById('resultsDrinks');
d.removeChild(olddiv);
removeItems(arrIngredients, intIngredientId);
removeItems(arrIngredientsNames, strIngredientName);
strIngredients=arrIngredients.join(','); // move array to string
strIngredientsNames = arrIngredientsNames.join(',');
objResultsDrinks.innerHTML = '';
AjaxRequest(strSiteURL+'ajaxUpdateIngredientsResults.php?strIngredients='+strIngredients+'&strIngredientsNames='+strIngredientsNames, 'resultsDrinks', default_handle);
}
function selectedIngredientCategory() {
objStrSelectIngredientCategory = document.getElementById('strSelectIngredientCategory');
objSelectIngredientsResults = document.getElementById('selectIngredientsResults');
strCategory = objStrSelectIngredientCategory.value;
objSelectIngredientsResults.innerHTML = '';
AjaxRequest(strSiteURL+'ajaxSearchIngredientCategory.php?strCategory='+strCategory, 'selectIngredientsResults', default_handle);
}
function selectOrderBy() {
strURL = window.location.href;
strParamValue = document.getElementById('strOrderBy').value;
strNewURL = replaceURLParamValue(strURL, 'strOrderBy', strParamValue);
strNewURL = strNewURL.replace(/&/g, '...');
window.location.href =strSiteURL+ 'process_drink.php?strProcessType=8&strOrderBy='+strParamValue+'&strURL='+strNewURL;
}
function removeItems(array, item) {
var i = 0;
while (i < array.length) {
if (array[i] == item) {
array.splice(i, 1);
} else {
i++;
}
}
return array;
}
Array.prototype.in_array = function(p_val) {
for(var i = 0, l = this.length; i < l; i++) {
if(this[i] == p_val) {
return true;
}
}
return false;
}
String.prototype.stripslashes = function () {
str=this.replace("'", "");
str=str.replace('"', '');
return str;
}
function getElementPosition( objThis ) {
var intPosLeft = intPosTop = 0;
if(objThis) {
if(objThis.offsetParent) {
do {
intPosLeft += objThis.offsetLeft;
intPosTop += objThis.offsetTop;
//alert(objThis.id +'|'+objThis.name+'|'+objThis.className + '|' + intPosTop);
} while (objThis = objThis.offsetParent);
}
//browser hacks.. this basically gets the positions on the same level for each browser.
if( BrowserDetect.browser==SA ){
intPosTop += 4;
} else if(BrowserDetect.browser==IE && BrowserDetect.version == 6) {
//intPosTop -= 22;
}
return [intPosLeft, intPosTop];
}
return false;
}
function showToolTip( objThis, strCaption, blnFlipped ) {
blnAnimation = false;
if(blnAnimation == false) {
arrPosition = getElementPosition( objThis );
//alert(arrPosition[0] + '|' + arrPosition[1]);
intPosLeft = arrPosition[0]-2;
intPosTop = arrPosition[1] - 26;
//alert(intPosLeft + ' | ' + intPosTop);
intCaptionLength = strCaption.length;
objToolTip = document.getElementById('tooltip');
objToolTipInfo = document.getElementById('tooltip_info');
objToolTipArrow = document.getElementById('tooltip_arrow');
objToolTip.className = 'vYes';
objToolTipArrow.className = 'tooltip';
objToolTip.style.left = intPosLeft+ 'px';
objToolTip.style.top = intPosTop+ 'px';
objToolTip.className = '';
objToolTipInfo.innerHTML = strCaption;
if( blnFlipped ){
objToolTip.style.width = (intCaptionLength * 7) + 'px';
objToolTipArrow.style.width = objToolTip.style.width; //(intCaptionLength * 7) + 'px';
intFlippedPosition = ( intPosLeft - objToolTip.offsetWidth + objThis.offsetWidth ) + 'px';
objToolTip.style.left = intFlippedPosition;
objToolTipArrow.style.backgroundPosition = 'top right'; // Doesn't work using CSS class
} else {
objToolTipArrow.style.backgroundPosition = 'top left'; // Things get weird if this isn't explicitly set
}
}
}
function showDrinkToolHelp(objThis) {
strCaption = 'Find drinks based on your Ingredients:
';
strCaption += 'Step 1:
';
strCaption += 'Add what ingredients you have by searching through categories or entered the ingredient name.
';
strCaption += 'Step 2:
';
strCaption += 'View/Edit the ingredients you have added.
';
strCaption += 'Step 3:
';
strCaption += 'See the possible drinks you can make with your ingredients and view the recipes.
';
showToolTip( objThis, strCaption, false )
}
function showDrinkSearchHelp(objThis) {
strCaption = 'Start typing in the name of your favourite drink and a list of suggested drinks will appear.';
showToolTip( objThis, strCaption, false )
}
function hideToolTip( ) {
objToolTip = document.getElementById('tooltip');
objToolTip.className = 'vNo';
}