// Notifications

/*var IPAdd = 0;

function getIpAddress() {
	var IPAdd;
	$.getJSON("http://jsonip.appspot.com?callback=?",function(ipadd){
		IPAdd = ipadd.ip;
	});	
}*/

// Init general JS variables
var userNotes = '';

function feedback(email,text1,text2,text3) {
    //send the email
		$.ajax({
			url: '/miniBox/notificationErrorFeedBack',
			type: "GET",
			data: "email=" + email + "&text1=" + text1 + "&text2=" + text2 + "text3=" + text3,
			success: function(data) {
                $('#noteRedoSuccess').hide();
                $('#noteFeedBack').show();
			}
		});    
}

function notification(plId,pid,cn,cat,cur,emailGet,refCn,noteType,OKemail,OKnoteType,OKuser,emailChange,resubscribe,eid,createUser,emailChangeAlert,parentSource,pidOrg,isRepeat,emailInput,OKsession) {
	$.pidRedo = pid;
	$.plIdRedo = plId;
	$.cnRedo = cn;
	$.curRedo = cur;
	$.noteTypeRedo = noteType;
	$.catRed = cat;
//alert(eid);
	var email = encodeURIComponent(emailGet);
	var noteHeight = $('#tooltip-content-' + pidOrg + '').height();
	
	if (parentSource == 1) {
		// mm pop-up
		//var noteHeight = $('#noteMod-' + pid + '').height();
		if (typeof(email) == "undefined" || email == '') {
			$('#noteMain-' + pidOrg + '').hide();
			$('#noteMod-' + pidOrg + '').hide();
            //$('#noteNoEmailTitle-' + pidOrg + '').css('margin-top', noteHeight/6 + 'px');
            //$('#noteNoEmailInput-' + pidOrg + '').css('margin-top', noteHeight/6 + 'px');
            //$('#noteNoEmailInput-' + pidOrg + '').css('margin-bottom', noteHeight/6 + 'px');
			//$('#noteNoEmail-' + pidOrg + '').height(noteHeight).show();
            $('#noteNoEmail-' + pidOrg + '').show();
			var pass = false;
	  } else {
			//var IPAdd = getIpAddress();
			//alert(IPAdd);
			$('#noteLoading-' + pidOrg + '').height(noteHeight).show();
			$('#noteMain-' + pidOrg + '').hide();
			$('#noteMod-' + pidOrg + '').hide();	
			$('#noteNoEmail-' + pidOrg + '').hide();
			var pass = true;
		}			
	} else if (parentSource == 2) {
		
		//mm pop-up success
		if (typeof(email) == "undefined" || email == '') {					
			$('#redoNoteInvalidEmail').hide();
			$('#redoNoteEmptyEmail').show();
			var pass = false;
		}else {
			$('#noteRedoSuccess').hide();
			$('#noteRedoLoading').show();
			var pass = true;
		}
	}

	if (pass) {
		$.ajax({
			url: '/miniBox/mmNotificationStatus',
			type: "GET",
			data: "email=" + email + "&plId=" + plId + "&pid=" + pid + "&cn=" + cn + "&cur=" + cur + "&refCn=" + refCn + "&noteType=" + noteType + "&cat=" + cat
				+ "&OKemail=" + OKemail + "&OKnoteType=" + OKnoteType + "&OKuser=" + OKuser + "&emailChange=" + emailChange + "&resubscribe=" + resubscribe
				 + "&eid=" + eid + "&createUser=" + createUser + "&emailChangeAlert=" + emailChangeAlert + "&pidOrg=" + pidOrg + "&isRepeat=" + isRepeat
                  + "&emailInput=" + emailInput+ "&OKsession=" + OKsession,
				 
			success: function(data) {
				if ((parentSource == 1) || (parentSource == 2)) {
					$('#noteLoading-' + pidOrg + '').hide();
					$('#noteSuccess-' + pidOrg + '').show();
					$('#noteSuccess-' + pidOrg + '').html(data);					
				}
			}	
		});
    }
}

/*
function setDefaultplType() {
	plType = 1;
	//alert(plType);
}

function setModplType() {
	plType = 2;
	//alert(plType);
}
*/

function checkForEnter(event) {
	if (event.keyCode == 13) {
		alert("boo you hit the enter key");
	}  
}

function setEmailFields(email,plId,eid,noEmail) {    
       $('input.emailField').val(email);
       var eidSession = eid;
       $.each(userNotes, function(idx, note) {	
           if (noEmail == 0) {
               if (note.type == 1) {
                if ($('#alreadyNote-' + note.linkId).length > 0) { 
                    $('#alreadyNote-' + note.linkId).show();
                       $('#alreadyEmail-' + note.linkId).html(email);
                       $('input.e-' + note.linkId).val('');
                }
              }
           }
       });  
}

                //$('#alreadyNote-' + plId).show();
            //alert(note.id);
			//if ($('#alreadyNote-').length > 0) {} 
    //$('.emailNoteAlready').show();
    //$('#alreadyNote-' + plId + '').show();
    //$('.sessionEid').html(eid);

