//<![CDATA[   

var bLoggedin = false;

$(document).ready(function() {
	
	//Email
	$("#fFeedbackEmail").focus(function() {
    	onObjectFocus("#fFeedbackEmail","email address (optional)");
    });//end focus

    $("#fFeedbackEmail").blur(function() {    	
	    onObjectBlur("#fFeedbackEmail","email address (optional)");    	
    });//end blur	
    
	//Feedback text
	$("#fFeedbackText").focus(function() {
    	onObjectFocus("#fFeedbackText","Let us know what you think");
    });//end focus

    $("#fFeedbackText").blur(function() {    	
	    onObjectBlur("#fFeedbackText","Let us know what you think");    	
    });//end blur
    
	$("#fFeedbackTab").click(function() {
		
		showItem('fFeedbackTab');;
		return false;
	});
	
	$("#fSendFeedback").click(function() {
		
		if (validateForm())
		{
		    gProcessAjaxForm("fFeedbackForm", "/data/account/SubmitFeedback.aspx", SubmitFeedback);
			sendItem();			
		}//end if
		
		return false;
	});
	
	$("#fCancelFeedback").click(function() {
		
		closeItem();
		return false;
	});
	
	$("#fFeedbackClose").click(function() {
		
		closeItem();
		return false;
	});

	
});	// End doc ready

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
    var curtop = 0;
    if (obj.offsetParent)
    {
	    while (obj.offsetParent)
	    {
		    curtop += obj.offsetTop
		    obj = obj.offsetParent;
	    }
    }
    else if (obj.y)
	    curtop += obj.y;
    return curtop;
}

function showItem(objName)
{
    var divObj = document.getElementById("FeedbackFormBlock");
    var xPos = findPosX(divObj) + "px";
    
    if (xPos == "0px")
    {
        divObj.style.left = "-235px";
        closeItem();
    }
    else
    {
        divObj.style.left = 0;            
    }
    
}

function sendItem()
{
    var divObjForm = document.getElementById("FeedbackForm");
    var divCompleteObj = document.getElementById("FeedbackFormComplete");
    
    divObjForm.style.display = "none";
    divCompleteObj.style.display = "block";
}

function closeItem()
{
    var divObjForm = document.getElementById("FeedbackForm");
    var divCompleteObj = document.getElementById("FeedbackFormComplete");
    var divObj = document.getElementById("FeedbackFormBlock");
    
    $("#fFeedbackEmail").val("email address (optional)");
    $("#fFeedbackText").val("Let us know what you think");
    onObjectBlur("#fFeedbackText","Let us know what you think"); 
    onObjectBlur("#fFeedbackEmail","email address (optional)");
    
    divCompleteObj.style.display = "none";
    divObjForm.style.display = "block";
    divObj.style.left = "-235px"; 
}

function validateForm()
{
    var email_reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    
    if ($("#fFeedbackEmail").val() != "email address (optional)")
    {
        if (!email_reg.test($("#fFeedbackEmail").val()))
        {
	        alert("The e-mail address you entered was invalid.");
	        $("#fFeedbackEmail").focus();
	        return false;
    		
        }//end if
    }
    
    if (($("#fFeedbackText").val() == "Let us know what you think") || ($("#fFeedbackText").val() == ""))
    {
        alert("You must enter comments to send.");
        $("#fFeedbackText").focus();
        return false;
    }
    
    return true;
}

// Focus function to handle search field items on focus	
function onObjectFocus(inObject,inText)
{
    if ($(inObject).attr("class").indexOf("feedbackfieldteaser") > -1)
    {
        if (($(inObject).val() == "") || ($(inObject).val() == inText))
        {
            $(inObject).val("");
            $(inObject).removeClass("feedbackfieldteaser");
        }
    }//end if
}//end ObjectFocus

// Blur function to handle search field items on blur
function onObjectBlur(inObject,inText)
{    
    if ($(inObject).attr("class").indexOf("feedbackfieldteaser") == -1)
    {
        if (($(inObject).val() == inText) || ($(inObject).val() == ""))
        {
            $(inObject).val(inText);
            $(inObject).addClass("feedbackfieldteaser");
	    }		
    }//end if
}// end ObjectBlur

//Function to set correct class on load
function checkOjbectActive(inObject,inText)
{
    if (($(inObject).val() != "") && ($(inObject).val() != inText))
    {
        $(inObject).removeClass("FriendSearchFieldTeaser");
    }
} //end MakeActive(inObject,inText)

function SubmitFeedback(inData, inError) {
	
	if (gProcessReportError(inError, true, null))
		return;
	
	var sResult = $(inData);
	var sError = "";
	var sDelimiter = "";
	
	sResult.find("status").each(function() { 
			
		if ($(this).text().indexOf("Success") == -1)
		{
			sError += sDelimiter + $(this).text();
			
			if (sDelimiter == "")
				sDelimiter = "\r\n";
			
		}//end if
	});//end each
	
	if (sError.length > 0)
		alert(sError);
	
	
}//end SubmitFeedback
//]]>
