/* FUNCTIONS
*
* writeSectionOne, writeSectionTwo, writeSectionThree
* writeSectionFour, writeSectionFive, writeSectionSix
* writeSectionSeven, writeSectionEight, writeSectionNoImage
* writeSectionImage
*
* DESCRIPTION
*
* These functions contain page specific code. This code
* and these functions are not reusable and will only
* generate code to display specific window contents.
*
*/

var global_text_ParentTextField = null;
var global_window_ThisWindow = null;
var global_strParentHyperlink = null;

function writeSectionOne(window_ThisWindow) {
    var str = '';

    str += '<TABLE cellSpacing=0 cellPadding=0 width=505 align=center border=0>';
    str += '<TBODY>';
    str += '<TR>';
    str += '<TD vAlign=top height=344>';

    window_ThisWindow.document.write(str);
}

function writeSectionTwo(window_ThisWindow) {
    var str = '';

    str += '<\/TD><\/TR>';
    str += '<TR class=lineTop><TD height=1><\/TD><\/TR>';
    str += '<TR>';
    str += '<TD vAlign=top>';
    str += '<TABLE cellSpacing=0 cellPadding=0 width=505 border=0>';
    str += '<TBODY>';
    str += '<TR>';
    str += '<TD height=17 colspan=5>';
    str += '<TABLE cellSpacing=0 cellPadding=0 width=505 border=0 class=bar1background>';
    str += '<TR>';
    str += '<TD width=8 height=17> <\/TD>';
    str += '<TD class=toBarTitle vAlign=center width=329>Informatión de la Entrada<\/TD>';
    str += '<TD class=toBarTitle vAlign=center width=64>Precio<\/TD>';
    str += '<TD class=toBarTitle vAlign=center width=51>Cantidad<\/TD>';
    str += '<TD vAlign=center width=53> <\/TD><\/TR>';
    str += '<\/TABLE><\/TD><\/TR>';
    str += '<TR class=bar1bottombackground><TD height=1 colspan=5><\/TD><\/TR>';
    str += '<TR>';
    str += '<TD colspan=5 class=ticketrowbackground>';
    str += '<TABLE cellSpacing=0 cellPadding=0 width=505 border=0>';
    str += '<TR>';
    str += '<TD height=27 width=8> <\/TD>';
    str += '<TD vAlign=middle width=329 class=toBarTitle>';

    window_ThisWindow.document.write(str);
}

function writeSectionThree(window_ThisWindow) {
    var str = '';

    str += '<\/TD>';
    str += '<TD vAlign=middle width=64 class=toBarTitle>';

    window_ThisWindow.document.write(str);
}

function writeSectionFour(window_ThisWindow) {
    var str = '';

    str += '<\/TD>';
    str += '<TD vAlign=middle width=51 align=center>';

    window_ThisWindow.document.write(str);
}

function writeSectionFive(window_ThisWindow) {
    var str = '';

    str += '<\/TD>';
    str += '<TD vAlign=middle align=center>';

    window_ThisWindow.document.write(str);
}

function writeSectionSix(window_ThisWindow) {
    var str = '';

    str += '<\/TD><\/TR>';
    str += '<\/TABLE><\/TD><\/TR>';
    str += '<TR class=grandstand_Top><TD height=1 colspan=5><\/TD><\/TR>';
    str += '<TR class=bar1background>';
    str += '<TD vAlign=middle><TABLE><TR><TD width=1><\/TD><TD class=toBarTitle>Información de la Tribuna<\/TD><\/TR><\/TABLE><\/TD>';
    str += '<\/TR>';
    str += '<TR><TD height=1 colspan=5 class=grandstand_bottom><\/TD><\/TR>';
    str += '<TR vAlign=middle class=greenbarBackground>';
    str += '<TD colSpan=5 height=25>';
    str += '<TABLE height=25 cellSpacing=0 cellPadding=0 border=0>';
    str += '<TBODY>';
    str += '<TR>';
    str += '<TD width=8 valign=top>';

    window_ThisWindow.document.write(str);
}

function writeSectionSix_1(window_ThisWindow) {
    var str = '';

    str += '<\/TD><\/TR>';
    str += '<\/TABLE><\/TD><\/TR>';
    str += '<TR class=grandstand_Top><TD height=1 colspan=5><\/TD><\/TR>';
    str += '<TR class=bar1background>';
    str += '<TD vAlign=middle><TABLE><TR><TD width=1><\/TD><TD class=toBarTitle height=15><\/TD><\/TR><\/TABLE><\/TD>';
    str += '<\/TR>';
    str += '<TR><TD height=1 colspan=5 class=grandstand_bottom><\/TD><\/TR>';
    str += '<TR vAlign=middle class=greenbarBackground>';
    str += '<TD colSpan=5 height=25>';
    str += '<TABLE height=25 cellSpacing=0 cellPadding=0 border=0>';
    str += '<TBODY>';
    str += '<TR>';
    str += '<TD width=8 valign=top>';

    window_ThisWindow.document.write(str);
}

function writeSectionSeven(window_ThisWindow) {
    var str = '';

    str += '<\/TD><\/TR>';
    str += '<\/TBODY><\/TABLE><\/TD><\/TR><\/TBODY><\/TABLE><\/TD><\/TR>';
    str += '<TR>';
    str += '<TD vAlign=top height=10 class=greenbar_shadow>';
    str += '<\/TD><\/TR>';
    str += '<TR>';
    str += '<TD vAlign=top>';
    str += '<TABLE height=25 cellSpacing=0 cellPadding=0 width=505 border=0 class=infobackground>';
    str += '<TBODY>';
    str += '<TR>';
    str += '<TD width=8> <\/TD>';
    str += '<TD>';

    window_ThisWindow.document.write(str);
}

function writeSectionEight(window_ThisWindow) {
    var str = '';

    str += '<BR><BR><BR><BR><BR><BR><BR><BR><BR><\/TD>';
    str += '<TD width=8> <\/TD><\/TR>';
    str += '<TR>';
    str += '<TD colSpan=3><IMG height=10 src="/images\/leeg.gif" width=10>';
    str += '<\/TD><\/TR><\/TBODY><\/TABLE><\/TD><\/TR>';
    str += '<\/TBODY>';
    str += '<\/TABLE>';

    window_ThisWindow.document.write(str);
}

function writeSectionImage(window_ThisWindow, strDetails, strImage) {
    var str = '';

    str += '<\/TD>';
    str += '<TD vAlign=middle width=14>';
    str += '<IMG height=10 src="';
    str += '' + strImage + '"';
    str += 'width=14 align=absMiddle><\/TD><TD width=5><\/TD><TD vAlign=middle width=131 class=greenfont> ';
    str += '' + strDetails;

    window_ThisWindow.document.write(str);
}

function writeSectionNoImage(window_ThisWindow) {
    var str = '';

    str += '<\/TD>';
    str += '<TD vAlign=center width=0>';
    str += '<IMG height=17 src="/images\/leeg.gif" width=18 align=absMiddle> ';

    window_ThisWindow.document.write(str);
}


/* FUNCTION:
*
* runUpdateFunction
*
* DEPENDENCIES:
*
* [global] var global_text_ParentTextField
* [global] var global_window_ThisWindow
* [global] var global_strParentHyperlink
* [function] showProductWindow (functional dependency)
*
* DESCRIPTION:
*
* This function is called by showProductWindow and
* closes the window created in showProductWindow it then also
* updates a textfield value passed through showProductWindow
* and a hyperlink passed through showProductwindow.
*
* NOTE:
*
* This function should NOT be used without showProductWindow.
*
*
*/
function runUpdateFunction() {
    //fill the parent textfield
    if (global_text_ParentTextField != null
       && global_window_ThisWindow.document.form_ProductForm.text_ProductAmount != null) {
        global_text_ParentTextField.value = global_window_ThisWindow.document.form_ProductForm.text_ProductAmount.value;
    }

    //visit the parent hyperlink
    if (global_strParentHyperlink != '') {
        global_window_ThisWindow.opener.location.href = "" + global_strParentHyperlink;
    }

    //close the child window
    if (global_window_ThisWindow != null) {
        global_window_ThisWindow.close();
    }
}

/* FUNCTION:
*
* showProductWindow
*
* DEPENDENCIES:
*
* [global] var global_text_ParentTextField
* [global] var global_window_ThisWindow
* [global] var global_strParentHyperlink
* [function] function runUpdateFunction()
*
* DESCRIPTION:
*
* This function displays a specific window with a product from a shopping cart.
* The number of products to be ordered can be chosen or typed into a field
* and upon pressing a button the caller can be redirected to a new
* shopping cart function that adds to cart or buy or any other function.
*
* VARIABLES:
*
* [in/out] text_ParentTextfield:  A textfield that is included in this window and allows changes to the passed parent textfield
* [in]     strParentHyperlink:    A hyperlink position that redirects the calling parent to the hyperlink position
* [in]     strProductImage:       A main product image or window image
* [in]     strFirstIcon:          A first icon that depicts a product specific attribute
* [in]     strSecondIcon:         A second icon that depicts a product specific attribute
* [in]     strThirdIcon:          A third icon that depics a product specific attribute
* [in]     strPrice:              A price indicator for the product
* [in]     strCurrency:           A string that represents the currency
* [in]     bProductAvailable:     A product availability indicator either 'true' or 'false'
* [in]     strProductText:        A product descriptionary  text
* [in]     strProductName:        A product representative name
*
* EVENTS:
*
* [trigger] runUpdateFunction():   A function that closes window and updates parent
*                                  text_ParentTextfield value and redirects to strParentHyperlink
*/
function showProductWindow(text_ParentTextfield, strParentHyperlink, strProductImage, strFirstIcon, strSecondIcon, strThirdIcon, strPrice, strCurrency, bProductAvailable, strProductName, strProductText, iLocationX, iLocationY) {
    //set the window title
    var strPriceText = 'Precio: ';
    var strSoldOutText = 'Producto AGOTADO';
    var strProductDescriptionText = 'Descripción: ';
    var strProductNameText = 'Nombre: '
    var strWindowTitle = 'la carrera y el producto';

    if (strProductText == '') {
        var window_ThisWindow = newWindow('window', 505, 436, false);
    }
    else {
        var window_ThisWindow = newWindow('window', 505, 535, false);
    }

    //var window_ThisWindow = newWindow('window', 505, 535, false);

    if (strProductName == '') {
        strProductName = "No hay nombre";
    }

    //when there is get an empty like one
    if (strProductText == '') {
        strProductText = 'No hay Descripción';
    }

    //when there is no image get the empty one
    if (strProductImage == '') {
        strProductImage = "/images/leeg.jpg";
    }

    //there is no price set zero
    if (strPrice == '') {
        strPrice = "0";
    }

    //there is no currency set to euros
    if (strCurrency == '') {
        strCurrency = "EUR";
    }

    //point global window to this window
    if (window_ThisWindow != null) {
        global_window_ThisWindow = window_ThisWindow;
    }

    //point global textfield to parent texfield
    if (text_ParentTextfield != null) {
        global_text_ParentTextField = text_ParentTextfield;
    }

    //point global hyperlink to parent hyperlink
    if (strParentHyperlink != '') {
        global_strParentHyperlink = strParentHyperlink;
    }

    beginWindowHeader(window_ThisWindow, strWindowTitle, '/images/popupstyle.css');
    beginWindowInput(window_ThisWindow, 'form_ProductForm');

    writeSectionOne(window_ThisWindow);

    var strOverlay = "/images/circle.gif";
    var str = '';
    str += '<img src="' + strProductImage + '" border=0>';
    /*
    if (isJavaCompatible(window_ThisWindow) == false)
    {
    placeWindowImage(window_ThisWindow, strOverlay, "pointer", 19, 19);
    placeWindowImage(window_ThisWindow, strProductImage, "image", 505, 344);
    setWindowObjectPosition(window_ThisWindow, 'form_ProductForm', 'pointer', iLocationX, iLocationY);
    }

    if (isJavaCompatible(window_ThisWindow) == true)
    {
    placeWindowAppletHeader(window_ThisWindow, "GrandPrixAppletCustom.class", 505, 344);
    placeWindowAppletParameter(window_ThisWindow, "locationx", iLocationX);
    placeWindowAppletParameter(window_ThisWindow, "locationy", iLocationY);
    placeWindowAppletParameter(window_ThisWindow, "mode", "display");
    placeWindowAppletParameter(window_ThisWindow, "track", strProductImage);
    placeWindowAppletParameter(window_ThisWindow, "overlay",strOverlay);
    placeWindowAppletFooter(window_ThisWindow);
    }
    */
    window_ThisWindow.document.write(str);
    writeSectionTwo(window_ThisWindow);
    window_ThisWindow.document.write(strProductName);

    writeSectionThree(window_ThisWindow);
    window_ThisWindow.document.write(strCurrency + " " + strPrice);

    writeSectionFour(window_ThisWindow);
    if (bProductAvailable == "true") {
        placeWindowInputText(window_ThisWindow, 'text_ProductAmount', 2, 0, 2, 'inputhoeveelheid');
        writeSectionFive(window_ThisWindow);

        if (text_ParentTextfield != null) {
            window_ThisWindow.document.form_ProductForm.text_ProductAmount.value = text_ParentTextfield.value;
        }

        placeWindowInputButton(window_ThisWindow, 'button_ProductFunction', 'runUpdateFunction()', '/images/button_add.gif', 46, 17, '');
        if (strFirstIcon == '/images/leeg.gif' && strSecondIcon == '/images/leeg.gif' && strThirdIcon == '/images/leeg.gif') {
            writeSectionSix_1(window_ThisWindow);
        } else {
            writeSectionSix(window_ThisWindow);
        }
    }
    else if (bProductAvailable == "false") {
        writeSectionFive(window_ThisWindow);
        if (strFirstIcon == '/images/leeg.gif' && strSecondIcon == '/images/leeg.gif' && strThirdIcon == '/images/leeg.gif') {
            writeSectionSix_1(window_ThisWindow);
        } else {
            writeSectionSix(window_ThisWindow);
        }
    }

    //TODO: check ordering of numbered, tv and covered, then fit to code
    if (strFirstIcon == '/images/leeg.gif') {
        writeSectionNoImage(window_ThisWindow);
    } else {
        writeSectionImage(window_ThisWindow, 'sillas numeradas', strFirstIcon);
    }

    if (strSecondIcon == '/images/leeg.gif') {
        writeSectionNoImage(window_ThisWindow);
    } else {
        writeSectionImage(window_ThisWindow, 'pantallas de televisión', strSecondIcon);
    }

    if (strThirdIcon == '/images/leeg.gif') {
        writeSectionNoImage(window_ThisWindow);
    } else {
        writeSectionImage(window_ThisWindow, 'tribuna cubierta', strThirdIcon);
    }

    writeSectionSeven(window_ThisWindow);


    window_ThisWindow.document.write('<div id="scrollbar" valign=top>');
    window_ThisWindow.document.write('<p>' + strProductText + '</p></div>');
    //scrollable text
    window_ThisWindow.document.write('<style type="text/css">');
    window_ThisWindow.document.write('#scrollbar');
    window_ThisWindow.document.write('{');
    window_ThisWindow.document.write('  width: 490px;');
    window_ThisWindow.document.write('  height: 85px;');
    window_ThisWindow.document.write('  overflow: auto;');
    window_ThisWindow.document.write('  margin: 0px;');
    window_ThisWindow.document.write('  padding: 0px;');
    window_ThisWindow.document.write('  scrollbar-3dlight-color:99CE9A;');
    window_ThisWindow.document.write('  scrollbar-arrow-color:#FFFFFF;');
    window_ThisWindow.document.write('  scrollbar-base-color:#003366;');
    window_ThisWindow.document.write('  scrollbar-darkshadow-color:#083D09;');
    window_ThisWindow.document.write('  scrollbar-face-color:0E7A10;');
    window_ThisWindow.document.write('  scrollbar-highlight-color:#99CE9A;');
    window_ThisWindow.document.write('  scrollbar-track-color:#CBDECB;');
    window_ThisWindow.document.write('  scrollbar-shadow-color:#083D09');
    window_ThisWindow.document.write('}');
    window_ThisWindow.document.write('</style>');
    writeSectionEight(window_ThisWindow);
    endWindowInput(window_ThisWindow);
    endWindowHeader(window_ThisWindow);
}
