﻿///Copyright Dynamic Ventures, Inc. All rights reserved.
///
///http://www.dyve.com 
///http://www.dynamicventures.com
///
///This source code is offered by Dynamic Ventures, Inc. to its clients for non-exlusive use and is protected by copyright law and international treaties.
///

CreateFeedback();




var divFeedbackContent_textarea1;
function CreateFeedback()
{
        //<div id="_feedbackContainer">
        //    <div id="_feedbackQuestion" class="_feedback">
        //        <span class="block">Was this useful?</span><br/>
        //        <img src="images/thumb_up.gif" onclick="sendYesFeedback" /><span onclick="sendYesFeedback">Yes</span><img src="images/thumb_down.gif" onclick="displayFeedbackForm"/><span onclick="displayFeedbackForm">No</span>
        //    </div>
        //    <div id="_feedbackSubmited" class="_feedback">
        //        <span class="block"><img src="images/tick.gif" />Thank you for your feedback.</span>
        //    </div>
        //    <div id="_feedbackContent" class="_feedback">
        //        <span class="block">Please tell us what’s wrong with this answer:</span><br/>
        //        <textarea rows="2" cols="30" id="_feedbackText" ></textarea><br/>
        //        <a href="#" onclick="submitFeedbackForm()"><img src="images/btn_feedback.gif" /></a>
        //    </div>
        //</div>

        /*********************************
            General Container For The Feedback
        **********************************/

        var feedbackContainerID = "feedbackContainer";
        document.write("<div id='" + feedbackContainerID + "'></div>");
        var feedbackContainer = document.getElementById(feedbackContainerID)


        /*********************************
            Feedback question
        **********************************/

        //container for the feedback question
        var divFeedbackQuestion = document.createElement("div");
        divFeedbackQuestion.setAttribute("id","feedbackQuestion");
        feedbackContainer.appendChild(divFeedbackQuestion);

        //Was this useful? Span
        var divFeedbackQuestion_span1 = document.createElement("span");
        var divFeedbackQuestion_span1_text = document.createTextNode("Did you find what you were looking for?")
        divFeedbackQuestion_span1.appendChild(divFeedbackQuestion_span1_text);
        divFeedbackQuestion.appendChild(divFeedbackQuestion_span1);

        //BR
        var divFeedbackQuestion_br1 = document.createElement("br");
        divFeedbackQuestion.appendChild(divFeedbackQuestion_br1);

        //Thumb Up Image
        var divFeedbackQuestion_img1 = document.createElement("img");
        divFeedbackQuestion_img1.setAttribute("src","http://www.dyve.com/_CMN/img/feedback/thumb_up.gif");
        divFeedbackQuestion_img1.onclick = sendYesFeedback;
        divFeedbackQuestion.appendChild(divFeedbackQuestion_img1);

        //Yes Span
        var divFeedbackQuestion_span2 = document.createElement("span");
        var divFeedbackQuestion_span2_text = document.createTextNode("Yes")
        divFeedbackQuestion_span2.appendChild(divFeedbackQuestion_span2_text);
        divFeedbackQuestion_span2.onclick = sendYesFeedback;
        divFeedbackQuestion.appendChild(divFeedbackQuestion_span2);

        //Thumb Down Image
        var divFeedbackQuestion_img2 = document.createElement("img");
        divFeedbackQuestion_img2.setAttribute("src","http://www.dyve.com/_CMN/img/feedback/thumb_down.gif");
        divFeedbackQuestion_img2.onclick = displayFeedbackForm;
        divFeedbackQuestion.appendChild(divFeedbackQuestion_img2);

        //No Span
        var divFeedbackQuestion_span3 = document.createElement("span");
        var divFeedbackQuestion_span3_text = document.createTextNode("No")
        divFeedbackQuestion_span3.appendChild(divFeedbackQuestion_span3_text);
        divFeedbackQuestion_span3.onclick = displayFeedbackForm;
        divFeedbackQuestion.appendChild(divFeedbackQuestion_span3);


        /*********************************
            Feedback submited
        **********************************/

        //container for the feedback submited response
        var divFeedbackSubmited = document.createElement("div");
        divFeedbackSubmited.setAttribute("id","feedbackSubmited");
        divFeedbackSubmited.setAttribute("style","display:none");
        divFeedbackSubmited.style.display = "none";
        feedbackContainer.appendChild(divFeedbackSubmited);

        //Thank You For Your Feedback Span
        var divFeedbackSubmited_span1 = document.createElement("span");
        divFeedbackSubmited.appendChild(divFeedbackSubmited_span1);

        //Tick Image
        var divFeedbackSubmited_img1 = document.createElement("img");
        divFeedbackSubmited_img1.setAttribute("src","http://www.dyve.com/_CMN/img/feedback/tick.gif");
        divFeedbackSubmited_span1.appendChild(divFeedbackSubmited_img1);

        //Thank You For Your Feedback Text
        var divFeedbackSubmited_span1_text = document.createTextNode("Thank you for your feedback!")
        divFeedbackSubmited_span1.appendChild(divFeedbackSubmited_span1_text);



        /*********************************
            Feedback form
        **********************************/

        //container for the feedback form
        var divFeedbackContent = document.createElement("div");
        divFeedbackContent.setAttribute("id","feedbackContent");
        divFeedbackContent.setAttribute("style","display:none");
        divFeedbackContent.style.display = "none";
        feedbackContainer.appendChild(divFeedbackContent);

        //Please give us your feedback: Span
        var divFeedbackContent_span1 = document.createElement("span");
        var divFeedbackContent_span1_text = document.createTextNode("What were you looking for?");
        divFeedbackContent_span1.appendChild(divFeedbackContent_span1_text);
        divFeedbackContent.appendChild(divFeedbackContent_span1);

        //BR
        var divFeedbackContent_br1 = document.createElement("br");
        divFeedbackContent.appendChild(divFeedbackContent_br1);

        //Textarea 
        divFeedbackContent_textarea1 = document.createElement("textarea");
        divFeedbackContent_textarea1.setAttribute("id","feedbackText");
        divFeedbackContent_textarea1.setAttribute("rows","2");
        divFeedbackContent_textarea1.setAttribute("cols","30");
        divFeedbackContent.appendChild(divFeedbackContent_textarea1);

        //Send Feedback Button and Image
        var divFeedbackContent_a1 = document.createElement("a");
        divFeedbackContent_a1.onclick = submitFeedbackForm;
        divFeedbackContent_a1.setAttribute("href","#");

            var divFeedbackContent_img1 = document.createElement("img");
            divFeedbackContent_img1.onclick = submitFeedbackForm;
            divFeedbackContent_img1.setAttribute("src","http://www.dyve.com/_CMN/img/feedback/btn_feedback.gif");
            divFeedbackContent_img1.setAttribute("width","40");
            divFeedbackContent_img1.setAttribute("height","32");
            divFeedbackContent_img1.setAttribute("align","absmiddle");
            divFeedbackContent_a1.appendChild(divFeedbackContent_img1);

        divFeedbackContent.appendChild(divFeedbackContent_a1);
}





/***************************************************
    Feedback Form Events
***************************************************/
function sendYesFeedback()
{
    if(typeof callHandler == 'function' && typeof Hit == 'string')
    {
        callHandler(Hit,'',true);
    }
    switchElements('feedbackQuestion','feedbackSubmited', defaultSteps, defaultDuration);
}

function displayFeedbackForm()
{
    switchElements('feedbackQuestion','feedbackContent', defaultSteps, defaultDuration);
    setTimeout('divFeedbackContent_textarea1.focus();', defaultDuration*2);
}

function submitFeedbackForm()
{
    if(typeof callHandler == 'function' && typeof Hit == 'string')
    {
        callHandler(Hit,'',false,document.getElementById('feedbackText').value);
    }
    switchElements('feedbackContent','feedbackSubmited', defaultSteps, defaultDuration);
    return false;
}


/***************************************************
    Utils - Show/Hide Elements
***************************************************/
var defaultSteps = 40;
var defaultDuration = 500;

function setOpacity(id, level) {
    var element = document.getElementById(id); 
    element.style.zoom = 1;
    element.style.opacity = level;
    element.style.MozOpacity = level;
    element.style.KhtmlOpacity = level;
    element.style.filter = "alpha(opacity=" + (level * 100) + ");";
    element.style.display = 'inline';
}

function fadeIn(id, steps, duration){  
    var fadeInComplete;
    for (i = 0; i <= 1; i += (1 / steps)) {
      setTimeout("setOpacity('" + id + "', " + i + ")", i * duration); 
      fadeInComplete = i * duration;             
    }
}

function fadeOut(id, steps, duration) {
    var fadeOutComplete;       
    for (i = 0; i <= 1; i += (1 / steps)) {
      setTimeout("setOpacity('" + id + "', "  + (1 - i) + ")", i * duration);
      fadeOutComplete = i * duration;
    }      
    //completely hide the displayed message after the fade effect is complete
    setTimeout("hide('" + id + "')", fadeOutComplete);
}   

function switchElements(fadeoutID, fadeinID, steps, duration)
{
    fadeOut(fadeoutID, steps, duration);
    setTimeout("fadeIn('" + fadeinID + "','" + steps + "','" + duration + "')", duration + 0.5); 
}

function hide(id){
    document.getElementById(id).style.display = 'none';
}
