﻿var tpWizSite = tpSite;

function GenerateTPCode(width, background, colour, encoded, preview) {
    var displayHTML = "<div id=\"tpWidgetOuter\">" +
							"<div id=\"tpWidgetInner\">" +
							"</div>" +
							"<div id=\"tpWidgetLinkOuter\">" +
								"<span id=\"tpWidgetLinkSpan\"></span><a href=\"http://www.tyre-shopper.co.uk\" id=\"tpWidgetLink\">Tyre Shopper</a>" +
							"</div>" +
						"</div>" +
	                    ((preview == "true")? "" : "<script type=\"text/javascript\" src=\"" + tpWizSite + "Scripts/Widget.js\"></script>") +
						((preview == "true")? "" :
						"<script type=\"text/javascript\" defer=\"defer\">" +
							"DrawTPWidget(\"" + width + "\", \"" + background + "\", \"" + colour + "\", \"" + preview + "\");" +
						"</script>"
						);

    if (encoded == "true")
        return displayHTML;
    else
        return displayHTML;
}

function MakeHTML(textInput) {
    var textEncoded = textInput.replace("&", "&amp;");
    textEncoded = textEncoded.replace("<", "&lt;");
    textEncoded = textEncoded.replace(">", "&gt;");

    //alert(textEncoded);
    
    return (textEncoded);
}

function ChangePreview() {
    var width = "";
    var colour = "";
    var background = "";

    if (document.getElementById("tpDimensions1").checked == true)
        width = "200";
    else
        width = "300";

    if (document.getElementById("tpColour1").checked == true)
        colour = "#000000";
    else if (document.getElementById("tpColour2").checked == true)
        colour = "#ffffff";
    else if (document.getElementById("tpColour3").checked == true)
        colour = "#ff0000";
    else
        colour = "#0000ff";

    if (document.getElementById("tpBackground1").checked == true)
        background = "#000000";
    else if (document.getElementById("tpBackground2").checked == true)
        background = "#ffffff";
    else if (document.getElementById("tpBackground3").checked == true)
        background = "#ff0000";
    else
        background = "#0000ff";

    CodeAndPreview(width, background, colour);
}

function CodeAndPreview(width, background, colour)
{
    // Code
    document.getElementById("htmlCode").value = GenerateTPCode(width, background, colour, "true", "false");

    // Preview
    document.getElementById("widgetPreview").innerHTML = GenerateTPCode(width, background, colour, "false", "true");
    
    DrawTPWidget(width, background, colour, "true");
}

function HighlightText(id)
{
    var highightArea = document.getElementById(id);
    highightArea.focus();
    highightArea.select();

    //Copy To Clipboard
    //
    range = highightArea.createTextRange();
    range.execCommand("Copy");
}
