function openMyRoniMenu() {
	$.openDOMWindow({
        windowSourceURL: '/includes/Framework/panels/profile.cfm',
        functionCallOnOpen: function () {            
            activateSIFR();
			$("#DOMWindow").animate({
                height: $("#DOMWindow .panel").height() + 15
            }, 500);
        },
        height: 410,
        width: 700,
        positionType: 'anchoredSingleWindow',
        windowPadding: 20,
        borderColor: '#8eb5cc',
        borderSize: '3',
        anchoredSelector: '.windowAnchor',
        positionLeft: 128,
        positionTop: -58,
        modal: 1
    });
    return false;
}

function openLostPassword() {
	$.openDOMWindow({
        windowSourceURL: '/includes/Framework/panels/profile.cfm?panel=lostPassword',
        functionCallOnOpen: function () {
            activateSIFR();
			$("#DOMWindow").animate({
                height: $("#DOMWindow .panel").height() + 15
            }, 500);
        },
        height: 410,
        width: 700,
        positionType: 'anchoredSingleWindow',
        windowPadding: 20,
        borderColor: '#8eb5cc',
        borderSize: '3',
        anchoredSelector: '.windowAnchor',
        positionLeft: 128,
        positionTop: -58,
        modal: 1
    });
    return false;
}

function openMyRoniMenu_recipeexchange() {
    $.openDOMWindow({
        windowSourceURL: '/includes/Framework/panels/profile.cfm',
        functionCallOnOpen: function () {
            activateSIFR();
            $("#DOMWindow").animate({
                height: $("#DOMWindow .panel").height() + 15
            }, 500);
        },
        height: 380,
        width: 700,
        positionType: 'anchoredSingleWindow',
        windowPadding: 20,
        borderColor: '#8eb5cc',
        borderSize: '3',
        anchoredSelector: '.windowAnchor',
        positionLeft: 128,
        positionTop: 53,
        modal: 1
    });
    return false;
}

function openMealMaker() {
    activateSIFR();
    $.openDOMWindow({
        windowSourceURL: '/includes/Framework/panels/mealMaker.cfm',
        functionCallOnOpen: function () {
            activateSIFR();
        },
        height: 450,
        width: 700,
        positionType: 'anchoredSingleWindow',
        windowPadding: 20,
        borderColor: '#8eb5cc',
        borderSize: '3',
        anchoredSelector: '.windowAnchor',
        positionLeft: 128,
        positionTop: -58,
        modal: 1
    });
    return false;
}

function openMeatRecipes() {
    activateSIFR();
    $.openDOMWindow({
        windowSourceURL: '/includes/Framework/panels/meatRecipes.cfm',
        functionCallOnOpen: function () {
            activateSIFR();
        },
        height: 340,
        width: 710,
        positionType: 'anchoredSingleWindow',
        windowPadding: 20,
        borderColor: '#8eb5cc',
        borderSize: '3',
        anchoredSelector: '.windowAnchor',
        positionLeft: 128,
        positionTop: -58,
        modal: 1
    });
    return false;
}

function openeNewsletter() {
    $.openDOMWindow({
        windowSourceURL: '/includes/Framework/panels/eRecipe.cfm',
        functionCallOnOpen: function () {
            activateSIFR();
            $("#DOMWindow").animate({
                height: $("#DOMWindow .panel").height() + 15
            }, 500);        },
        height: 388,
        width: 700,
        positionType: 'anchoredSingleWindow',
        windowPadding: 20,
        borderColor: '#8eb5cc',
        borderSize: '3',
        anchoredSelector: '.windowAnchor',
        positionLeft: 128,
        positionTop: -58,
        modal: 1
    });
    return false;
}

function openUnsubscribe() {
    $.openDOMWindow({
        windowSourceURL: '/includes/Framework/panels/eRecipe.unsubscribe.cfm',
        functionCallOnOpen: function () {
        	activateSIFR();},
        height: 230,
        width: 700,
        positionType: 'anchoredSingleWindow',
        windowPadding: 20,
        borderColor: '#8eb5cc',
        borderSize: '3',
        anchoredSelector: '.windowAnchor',
        positionLeft: 128,
        positionTop: -58,
        modal: 1
    });
    return false;
}

function openRecipeBox() {
    $.openDOMWindow({
        windowSourceURL: '/includes/Framework/panels/favoriteRecipes.cfm?recipeID=' + $("#HiddenRecipeId").val(),
        functionCallOnOpen: function () {
            activateSIFR();
            $("#DOMWindow").animate({
                height: $("#DOMWindow .panel").height() + 15
            }, 500);        },
        windowHTTPType: 'get',
        height: 380,
        width: 700,
        positionType: 'anchoredSingleWindow',
        windowPadding: 20,
        borderColor: '#8eb5cc',
        borderSize: '3',
        anchoredSelector: '.windowAnchor',
        positionLeft: 128,
        positionTop: -58,
        modal: 1
    });

    return false;
}

function openRecipeBoxAdd() {
    $.openDOMWindow({
        windowSourceURL: '/includes/Framework/panels/favoriteRecipesAdd.cfm?recipeID=' + $("#HiddenRecipeId").val(),
        functionCallOnOpen: function () {
            activateSIFR();
            $("#DOMWindow").animate({
                height: $("#DOMWindow .panel").height() + 15
            }, 500);
        },
        windowHTTPType: 'get',
        height: 246,
        width: 700,
        positionType: 'anchoredSingleWindow',
        windowPadding: 20,
        borderColor: '#8eb5cc',
        borderSize: '3',
        anchoredSelector: '.windowAnchor',
        positionLeft: 128,
        positionTop: -58,
        modal: 1
    });
    return false;
}

function openRecipeSearch() {
    $.openDOMWindow({
        windowSourceURL: '/includes/Framework/panels/findRecipes.cfm',
        //functionCallOnOpen: function(){onFindRecipesReady(); }, //XXX: causes a gnarly inf-loop!
        functionCallOnOpen: function () {
            activateSIFR();
            $("#DOMWindow").animate({
                height: $("#DOMWindow .panel").height() + 15
            }, 500);
        },
        height: 380,
        width: 700,
        positionType: 'anchoredSingleWindow',
        windowPadding: 20,
        borderColor: '#8eb5cc',
        borderSize: '3',
        anchoredSelector: '.windowAnchor',
        positionLeft: 128,
        positionTop: -58,
        modal: 1
    });
    return false;
}

function openShoppingList() {
    $.openDOMWindow({
        windowSourceURL: '/includes/Framework/panels/shoppingList.cfm' + "?recipeID=" + $("#HiddenRecipeId").val(),
        functionCallOnOpen: function () {
            activateSIFR();
            $("#DOMWindow").animate({
                height: $("#DOMWindow .panel").height() + 15
            }, 500);
        },
        windowHTTPType: 'get',
        height: 342,
        width: 700,
        positionType: 'anchoredSingleWindow',
        windowPadding: 20,
        borderColor: '#8eb5cc',
        borderSize: '3',
        anchoredSelector: '.windowAnchor',
        positionLeft: 128,
        positionTop: -58,
        modal: 1
    });
    return false;
}

function openRatings() {
    $.openDOMWindow({
        windowSourceURL: '/includes/Framework/panels/raterecipe.cfm' + "?recipeID=" + $("#HiddenRecipeId").val(),
        functionCallOnOpen: function () {
            activateSIFR();
        },
		functionCallOnClose: function() {
			var url = "/includes/framework/incRecipeRating.cfm?recipeID=" + $("#HiddenRecipeId").val();
			$('#starRating').load(url);	
		},
        windowHTTPType: 'get',
        height: 200,
        width: 700,
        positionType: 'anchoredSingleWindow',
        windowPadding: 20,
        borderColor: '#8eb5cc',
        borderSize: '3',
        anchoredSelector: '.windowAnchor',
        positionLeft: 128,
        positionTop: -58,
        modal: 1
    });
    return false;
}

function openSendtoFriend() {
    $.openDOMWindow({
        windowSourceURL: '/includes/Framework/panels/sendToFriend.cfm',
        functionCallOnOpen: function () {
            activateSIFR();
        },
        windowHTTPType: 'get',
        height: 373,
        width: 700,
        positionType: 'anchoredSingleWindow',
        windowPadding: 20,
        borderColor: '#8eb5cc',
        borderSize: '3',
        anchoredSelector: '.windowAnchor',
        positionLeft: 128,
        positionTop: -58,
        modal: 1
    });
    return false;
}

function openSendRecipeToFriend() {
    $.openDOMWindow({
        windowSourceURL: '/includes/Framework/panels/sendRecipeToFriend.cfm?recipeID=' + $("#HiddenRecipeId").val(),
        functionCallOnOpen: function () {
            activateSIFR();
        },
        windowHTTPType: 'get',
        height: 389,
        width: 700,
        positionType: 'anchoredSingleWindow',
        windowPadding: 20,
        borderColor: '#8eb5cc',
        borderSize: '3',
        anchoredSelector: '.windowAnchor',
        positionLeft: 128,
        positionTop: -58,
        modal: 1
    });
    return false;
}

function openSharePanel() {
    $.openDOMWindow({
        windowSourceURL: '/includes/Framework/panels/sharePage.cfm',
        functionCallOnOpen: function () {
            activateSIFR();
        },
        height: 275,
        width: 700,
        positionType: 'anchoredSingleWindow',
        windowPadding: 20,
        borderColor: '#8eb5cc',
        borderSize: '3',
        anchoredSelector: '.windowAnchor',
        positionLeft: 128,
        positionTop: -58,
        modal: 1
    });
    activateSIFR();
    return false;
}

function openMyxerPanel() {
    $.openDOMWindow({
        windowSourceURL: '/includes/Framework/panels/Myxer.cfm',
        functionCallOnOpen: function () {
            activateSIFR();
        },
        height: 400,
        width: 700,
        positionType: 'anchoredSingleWindow',
        windowPadding: 20,
        borderColor: '#8eb5cc',
        borderSize: '3',
        anchoredSelector: '.windowAnchor',
        positionLeft: 128,
        positionTop: -58,
        modal: 1
    });
    activateSIFR();
    return false;
}


$(document).ready(function () {
    $('.myRoniMenu').click(function () {
        openMyRoniMenu();
        return false;
    });
    

    $('#reviseSearch').click(function () {
        var window = $('#postType').val();
        if (window == 'mealmaker'){
        	openMealMaker()
        }else if(window =='meatRecipes'){
        	openRecipeSearch();
      	}else { 
      		openRecipeSearch();
      	}
        
        return false;
    });

    $('.findRecipeMenu').click(function () {
        openRecipeSearch();
        return false;
    });

    $('.MealMakerMenu').click(function () {
        openMealMaker();
        return false;
    });
    
    $('.MeatRecipeMenu').click(function () {
        openMeatRecipes();
        return false;
    });    

    $('.viewRecipesMenu').click(function () {
        openRecipeBox();
        return false;
    });

    $('#AddRecipeMenu').click(function () {
        openRecipeBoxAdd();
        return false;
    });

    $('.eNewsletterMenu').click(function () {
        openeNewsletter();
        return false;
    });

    $('.shoppingListMenu').click(function () {
        openShoppingList();
        return false;
    });

    $('.rateRecipeMenu').click(function () {
        openRatings();
        return false;
    });

    $('.sendToFriendMenu').click(function () {
        openSendtoFriend();
        return false;
    });

    $('.sendRecipeToFriendMenu').click(function () {
        openSendRecipeToFriend();
        return false;
    });

    $('.sharePageMenu').click(function () {
        openSharePanel();
        return false;
    });

    $('.myxerPageMenu').click(function () {
        openMyxerPanel();
        return false;
    });

    $('.newWindow').click(function (e) {
        e.preventDefault();
        window.open(e.currentTarget);
    });
    

});

function ResizeDomWindow(height) {
    $("#DOMWindow").animate({
        height: height
    }, 500);
}

function loadLostPassword(redirect) {
	var date = (new Date()).getTime();
	var url = '/includes/Framework/pageProcessor.cfm?';
	url += "doAction=favoriteRecipes.profile.lostpassword&unique=" + date;
	url += "&redirectTo=" + redirect;
	
    $('#DOMWindowAjax').load(url, function () {
        $("#DOMWindow").animate({
            height: $("#DOMWindow .panel").height() + 15
        }, 500);
        activateSIFR();
    });
}
function findLostPassword(redirect) {
	var errors = false;
	if(!IsValidEmail($("#j_username").val())) {
		errors = true;
		$("#j_username").css('background-color','#FEB1A3');	
		$("#Email_Side_Label").css('color','#B20D27');	
	}
	if(!errors) {
		var date = (new Date()).getTime();
		var url = "";
		url = url + '/includes/Framework/pageProcessor.cfm?';		
		url = url + "doAction=SecurePasswordLookup&j_username=" + $('#j_username').val() + "&unique=" + date;
		url += "&redirectTo=" + redirect;
		
		$('#DOMWindowAjax').load(url, function () {
			$("#DOMWindow").animate({
				height: $("#DOMWindow .panel").height() + 15
			}, 500);
			activateSIFR();
		});
		
	}
    return false;
}

function logout() {
	var url = '/includes/Framework/pageProcessor.cfm?doAction=secureLogOut';
    $('#DOMWindowAjax').load(url, function () {
    	$("#DOMWindow").animate({
            height: $("#DOMWindow .panel").height() + 15
        }, 500);
    	activateSIFR();
    });
}

function createProfileDataforrecipe(form) {
    var url = "";
    url = url + '/includes/Framework/pageProcessor.cfm?';
    var date = (new Date()).getTime();
    url = url + "doAction=" + document.getElementById('doActionCreateProfile').value + "&oldEmail=" + document.getElementById('oldEmail').value + "&Email=" + document.getElementById('Email_RegForm').value + "&Password=" + document.getElementById('Password_RegForm').value + "&ScreenName=" + document.getElementById('ScreenName').value + "&FirstName=" + document.getElementById('FirstName').value + "&LastName=" + document.getElementById('LastName').value + "&StreetAddress=" + document.getElementById('StreetAddress').value + "&City=" + document.getElementById('City').value + "&State=" + document.getElementById('state').value + "&ZipCode=" + document.getElementById('ZipCode').value + "&Gender=" + get_radio_value() + "&HomePhone=" + document.getElementById('phone').value + "&unique=" + date;
    if (document.myForm.Subscribe.checked == true) url = url + "&Subscribe=" + document.myForm.Subscribe.value;
    doSignInforrecipeAJAX(url);
}

function doSignInforrecipeAJAX(url) {
    var ajaxRequest = createRequestObject(); // The variable that makes Ajax possible!
    // Create a function that will receive data sent from the server
    ajaxRequest.onreadystatechange = function () {

        if (ajaxRequest.readyState == 4) {
            document.getElementById('DOMWindowAjax').innerHTML = ajaxRequest.responseText;
            activateSIFR();
        }
    }
    ajaxRequest.open("POST", url, true);
    ajaxRequest.send(null);
}

function log(s){
	if(typeof console!="undefined" && typeof console.debug!="undefined"){
		console.log(s);
	} else{
		alert(s);
	}
}


function handleChange(event) {
    var index, rel, path = event.path;
    if (path.substr(path.length - 1) != '/') {
        path += '/';
    }

    var parameters = '';
    for (var p in event.parameters) {
        parameters += '&' + p + '=' + event.parameters[p];
    }

    switch (event.path) {
    case 'findarecipe':
        openRecipeSearch();
        break;
    case 'mealmaker':
        openMealMaker();
        break;
    case 'justaddmeat':
    	openMeatRecipes();
        break;        
    case 'erecipe':
        openeNewsletter();
        break;
    case 'recipebox':
        openRecipeBox();
        break;
    case 'newsletter':
        openeNewsletter();
        break;
    case 'unsubscribe':
        openUnsubscribe();
        break;
    case 'profile':
    	openMyRoniMenu();
        break;
      
    }
}
SWFAddress.addEventListener(SWFAddressEvent.CHANGE, handleChange);