﻿// JScript File

function ShowHide(tcControlID)
{
	var oControl = document.getElementById(tcControlID);
	if(oControl)
	{
		oControl.style.display = ("none" == oControl.style.display) ? "" : "none";
	}
}

function sfi(w_clientID, h1_clientID, h2_clientID, si_fraction)
{
    var sfi_w = document.getElementById(w_clientID);
    var sfi_h1 = document.getElementById(h1_clientID);
    var sfi_h2 = document.getElementById(h2_clientID);

    sfi_w.src = sfi_w.src.replace(/_selected/, "_deselected");
    sfi_h1.src = sfi_h1.src.replace(/_selected/, "_deselected");
    sfi_h2.src = sfi_h2.src.replace(/_selected/, "_deselected");

    switch (si_fraction)
    {
        case "w":
            {
                sfi_w.src = sfi_w.src.replace(/_deselected/, "_selected");
                break;
            }
        case "h1":
            {
                sfi_h1.src = sfi_h1.src.replace(/_deselected/, "_selected");
                break;
            }
        case "h2":
            {
                sfi_h2.src = sfi_h2.src.replace(/_deselected/, "_selected");
                break;
            }
    }
}

function SwitchSecureOrNot(secure)
{
    if (secure && "http://" == window.location.href.substr(0, 7))
    {
        window.location.href = "https://" + window.location.href.substr(7);
    }

    if (!secure && "https://" == window.location.href.substr(0, 8))
    {
        window.location.href = "http://" + window.location.href.substr(8);
    }
}

function HTTPLink(httpFile)
{
    var mainpath = "";
    if ("https://" == window.location.href.substr(0, 8))
    {
        mainpath = window.location.href.substr(8);
    }
    else
    {
        mainpath = window.location.href.substr(7);
    }

    if (mainpath.indexOf("?") > 0)
    {
        mainpath = mainpath.substr(0, mainpath.indexOf("?"));
    }

    window.location.href = "http://" + mainpath.substr(0, mainpath.lastIndexOf("/")) + "/" + httpFile;
}



function setMaxLength(textAreaElement, length)
{
    textAreaElement.maxlength = length;
    ASPxClientUtils.AttachEventToElement(textAreaElement, "keyup", createEventHandler("onKeyUpOrChange"));
    ASPxClientUtils.AttachEventToElement(textAreaElement, "change", createEventHandler("onKeyUpOrChange"));
}

function onKeyUpOrChange(evt)
{
    processTextAreaText(ASPxClientUtils.GetEventSource(evt));
}

function processTextAreaText(textAreaElement)
{
    var maxLength = textAreaElement.maxlength;
    var text = textAreaElement.value;
    var isAcceptable = (maxLength == 0) || (text.length <= maxLength);
    if (maxLength != 0 && text.length > maxLength)
        textAreaElement.value = text.substr(0, maxLength);
}

function createEventHandler(funcName)
{
    return new Function("event", funcName + "(event);");
}

function trim(t_t)
{
    return t_t.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

function GetCurrentUpsellIndex() {
	var SelectedIndex = 0;
	for (var i = 0; i < tblUpsells.rows.length; i++) {
		if (null == tblUpsells.rows[i].style.display || undefined == tblUpsells.rows[i].style.display || "" == tblUpsells.rows[i].style.display) {
			SelectedIndex = i;
			break;
		}
	}

	return SelectedIndex;
}

function UpdateUpsellLinks() {
	var SelectedIndex = GetCurrentUpsellIndex();
	document.getElementById('lnkPreviousOffer').style.display = (SelectedIndex > 0) ? "" : "none";
	document.getElementById('lnkNextOffer').style.display = (SelectedIndex < tblUpsells.rows.length-1) ? "" : "none";
}

function DeSelectUpsell(pIndex) {
	tblUpsells.rows[pIndex].style.display = "none";
}

function SelectUpsell(pIndex) {
	tblUpsells.rows[pIndex].style.display = ""; //"table-row";
}

function PreviousUpsell() {
	var SelectedIndex = GetCurrentUpsellIndex();

	DeSelectUpsell(SelectedIndex);
	SelectUpsell(SelectedIndex - 1);

	UpdateUpsellLinks();
}

function SetCurrentUpsell(pIndex) {
	DeSelectUpsell(GetCurrentUpsellIndex());
	SelectUpsell(pIndex);
	UpdateUpsellLinks();
}

function NextUpsell() {
	var SelectedIndex = GetCurrentUpsellIndex();

	DeSelectUpsell(SelectedIndex);
	SelectUpsell(SelectedIndex + 1);

	UpdateUpsellLinks();
}