﻿
/*
* @Author: Huy.Vo
* @Date: 7/19/2010 11:55:00 AM
* @Files:
D:\SVN\iSport.com\WorkingSourceCode_JIRA\Scripts\swim.countries_swim.js
D:\SVN\iSport.com\WorkingSourceCode_JIRA\Scripts\Queue.js
D:\SVN\iSport.com\WorkingSourceCode_JIRA\Scripts\swim.dhtml.js
D:\SVN\iSport.com\WorkingSourceCode_JIRA\Scripts\HtmlControlUtils.js
D:\SVN\iSport.com\WorkingSourceCode_JIRA\Scripts\swim.menu2.js
D:\SVN\iSport.com\WorkingSourceCode_JIRA\Scripts\swim.effects.js
D:\SVN\iSport.com\WorkingSourceCode_JIRA\Scripts\fadeout.js
*/

/*********** Begin D:\SVN\iSport.com\WorkingSourceCode_JIRA\Scripts\Ajax.js *****************/
var $ = jQuery;
function MyAJAX(file) {
    this.AjaxFailedAlert = "I'm sorry, your browser does not support Ajax.\n";
    this.requestFile = file;
    this.method = "POST";
    this.URLString = "";
    this.encodeURIString = true;
    this.execute = false;
    this.xmlhttp = null;
    this.onLoading = function() { };
    this.onLoaded = function() { };
    this.onInteractive = function() { };
    this.onCompletion = function() { };
    this.createAJAX = function() {
        try {
            this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (err) {
                this.xmlhttp = null;
            }
        }
        if (!this.xmlhttp && typeof XMLHttpRequest != "undefined")
            this.xmlhttp = new XMLHttpRequest();
        if (!this.xmlhttp) {
            this.failed = true;
        }
    };

    this.setVar = function(name, value) {
        if (this.URLString.length < 3) {
            this.URLString = name + "=" + value;
        } else {
            this.URLString += "&" + name + "=" + value;
        }
    }

    this.encVar = function(name, value) {
        var varString = encodeURIComponent(name) + "=" + encodeURIComponent(value);
        return varString;
    }

    this.encodeURLString = function(string) {
        varArray = string.split('&');
        for (i = 0; i < varArray.length; i++) {
            urlVars = varArray[i].split('=');
            if (urlVars[0].indexOf('amp;') != -1) {
                urlVars[0] = urlVars[0].substring(4);
            }
            varArray[i] = this.encVar(urlVars[0], urlVars[1]);
        }
        return varArray.join('&');
    }

    this.runResponse = function() {
        eval(this.response);
    }

    this.runAJAX = function(urlstring) {
        this.responseStatus = new Array(2);
        if (this.failed && this.AjaxFailedAlert) {
            alert(this.AjaxFailedAlert);
        } else {
            if (urlstring) {
                if (this.URLString.length) {
                    this.URLString = this.URLString + "&" + urlstring;
                } else {
                    this.URLString = urlstring;
                }
            }
            if (this.encodeURIString) {
                var timeval = new Date().getTime();
                this.URLString = this.encodeURLString(this.URLString);
                this.setVar("rndval", timeval);
            }
            if (this.element) { this.elementObj = document.getElementById(this.element); }
            if (this.xmlhttp) {
                var self = this;
                if (this.method == "GET") {
                    var totalurlstring = this.requestFile + "?" + this.URLString;
                    this.xmlhttp.open(this.method, totalurlstring, true);
                } else {
                    this.xmlhttp.open(this.method, this.requestFile, true);
                }
                if (this.method == "POST") {
                    try {
                        this.xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
                    } catch (e) { }
                }

                this.xmlhttp.send(this.URLString);
                this.xmlhttp.onreadystatechange = function() {
                    switch (self.xmlhttp.readyState) {
                        case 1:
                            self.onLoading();
                            break;
                        case 2:
                            self.onLoaded();
                            break;
                        case 3:
                            self.onInteractive();
                            break;
                        case 4:
                            self.response = self.xmlhttp.responseText;
                            self.responseXML = self.xmlhttp.responseXML;
                            self.responseStatus[0] = self.xmlhttp.status;
                            self.responseStatus[1] = self.xmlhttp.statusText;
                            self.onCompletion();
                            if (self.execute) { self.runResponse(); }
                            if (self.elementObj) {
                                var elemNodeName = self.elementObj.nodeName;
                                elemNodeName.toLowerCase();
                                if (elemNodeName == "input" || elemNodeName == "select" || elemNodeName == "option" || elemNodeName == "textarea") {
                                    self.elementObj.value = self.response;
                                } else {
                                    self.elementObj.innerHTML = self.response;
                                }
                            }
                            self.URLString = "";
                            break;
                    }
                };
            }
        }
    };
    this.createAJAX();
}
var arrayDiv;
var index_arrayDiv;
var arraySub;
var arrayOld;
function AutoSugguest(control, pageRequest, keycode) {
    var chars = $("#txt_search").val();
    if (chars == "") {
        $('#div_suggest').hide();
        return;
    }
    $.ajax({
        type: "GET",
        url: pageRequest,
        data: "char=" + chars,
        beforeSend: showLoader,
        complete: hideLoader,
        success: function(msg) {
            var data = msg;
            if (data != "") {
                $('#div_suggestCo').html(data);
                $('#div_suggest').show();
            }
            else {
                $('#div_suggestCo').html("");
                $('#div_suggest').hide();
            }
            arrayDiv = document.getElementById('div_suggestCo').childNodes;
            index_arrayDiv = -1;
        },
        error: function() {

        }
    });
}

function selectedSport(control) {
    try {
        if (index_arrayDiv >= 0) {
            arraySub = document.getElementById(arrayDiv[index_arrayDiv].id).childNodes;
            var j = '#' + arraySub[0].id;
            var i = '#' + $(j).parent().get(0).id;
            $(i).removeClass("iSHome-sugHlight");
        }
        if (arrayOld != null && arrayOld[0] != null) {
            var o = '#' + arrayOld[0].id;
            try {
                var p = '#' + $(o).parent().get(0).id;
                $(p).removeClass("iSHome-sugHlight");
            }
            catch (ex) { }
        }
        arraySub = control.childNodes;

        $("#txt_search").val(arraySub[0].innerHTML.replace("&amp;", "&"));
        $('#div_suggestCo').scrollTo(control);

        var k = '#' + arraySub[0].id;
        var m = '#' + $(k).parent().get(0).id;
        $(m).addClass("iSHome-sugHlight");

        for (var i = 0; i < arrayDiv.length; i++) {
            if (arrayDiv[i].innerHTML == control.innerHTML) {
                index_arrayDiv = i;
            }
        }
        arrayOld = arraySub;
        $('#txt_search').focus();
    }
    catch (ex) { return false; }
}

function showLoader() {
    
}

function hideLoader() {
    $('#div_loading').hide();
}

function monitorClick(e) {
    var evt = (e) ? e : event;

    var theElem = (evt.srcElement) ? evt.srcElement : evt.target;

    while (theElem != null) {
        if (theElem.id == "div_suggest" || theElem.id == "txt_search" && document.getElementById('div_suggest').style.display == 'none') {
            return true;
        }
        theElem = theElem.offsetParent;
    }
    document.getElementById('div_suggest').style.display = 'none';
    return true;
}
function ShowHide_iSport_AutoSuggest(control, pageRequest) {
    $(document).ready(function() {
        document.onclick = monitorClick;
        $("#txt_search").click(function() {
            AutoSugguest(control, pageRequest, -1);
        });

        $('#txt_search').bind('cut copy paste', function(e) {
            AutoSugguest(control, pageRequest, -1);
        });
        $('#txt_search').keypress(function(e) {
            if (e.keyCode == 13) {
                if (arrayDiv != null) {
                    e.preventDefault();
                    if (arrayDiv != null && arrayDiv.length > 0) {
                        for (var i = 0; i < arrayDiv.length; i++) {
                            var arrItem = arrayDiv[i].childNodes;
                            if (arrItem[0].innerHTML.replace("&amp;", "&").toLowerCase() == $("#txt_search").val().toLowerCase()) {
                                if (arrItem[0].id.indexOf('a_') >= 0) {
                                    var item_id = '#' + arrItem[0].id;
                                    var item_href = $(item_id).attr("href");
                                    window.location = item_href;
                                }
                            }
                        }
                    }
                }
                else {
                    return false;
                }
            }
        });
        $('#txt_search').keyup(function(e) {
            if (e.keyCode != 13 && e.keyCode != 36 && e.keyCode != 44 && e.keyCode != 45 && e.keyCode != 20 && e.keyCode != 27 && e.keyCode != 33 && e.keyCode != 34 && e.keyCode != 35 && e.keyCode != 19 && e.keyCode != 16 && e.keyCode != 17 && e.keyCode != 18 && e.keyCode != 37 && e.keyCode != 38 && e.keyCode != 39 && e.keyCode != 40)
                AutoSugguest(control, pageRequest, e.keyCode);
            else if (e.keyCode == 40) {
                try {
                    index_arrayDiv++;
                    arraySub = document.getElementById(arrayDiv[index_arrayDiv].id).childNodes;
                    if (arraySub != null && arraySub[0] != null) {
                        $("#txt_search").val(arraySub[0].innerHTML.replace("&amp;", "&"));
                        if (parseFloat(index_arrayDiv) - 1 > 0)
                            $('#div_suggestCo').scrollTo(arrayDiv[index_arrayDiv - 1]);

                        var j = '#' + arraySub[0].id;
                        var i = '#' + $(j).parent().get(0).id;
                        $(i).addClass('iSHome-sugHlight');

                        if (index_arrayDiv > 0) {
                            var arraySub_Prev = document.getElementById(arrayDiv[index_arrayDiv - 1].id).childNodes;
                            if (arraySub_Prev != null && arraySub_Prev[0] != null) {
                                var j_Prev = '#' + arraySub_Prev[0].id;
                                var i_Prev = '#' + $(j_Prev).parent().get(0).id;
                                $(i_Prev).removeClass("iSHome-sugHlight");
                            }
                        }
                    }
                }
                catch (ex) { if (index_arrayDiv > 0) index_arrayDiv--; return false; }
            }
            else if (e.keyCode == 38) {

                try {
                    if (parseInt(index_arrayDiv) <= 0)
                        index_arrayDiv = 1;

                    index_arrayDiv--;

                    arraySub = document.getElementById(arrayDiv[index_arrayDiv].id).childNodes;
                    if (arraySub != null && arraySub[0] != null) {
                        $("#txt_search").val(arraySub[0].innerHTML.replace("&amp;", "&"));
                        if (index_arrayDiv == 0)
                            $('#div_suggestCo').scrollTo(arrayDiv[index_arrayDiv]);
                        else
                            $('#div_suggestCo').scrollTo(arrayDiv[index_arrayDiv - 1]);
                    }

                    var j = '#' + arraySub[0].id;
                    var i = '#' + $(j).parent().get(0).id;
                    $(i).addClass('iSHome-sugHlight');

                    var arraySub_Prev = document.getElementById(arrayDiv[index_arrayDiv + 1].id).childNodes;
                    if (arraySub_Prev != null && arraySub_Prev[0] != null) {
                        var j_Prev = '#' + arraySub_Prev[0].id;
                        var i_Prev = '#' + $(j_Prev).parent().get(0).id;
                        $(i_Prev).removeClass("iSHome-sugHlight");
                    }
                }
                catch (ex) { return false; }
            }
        });
    });
}


/*********** Begin D:\SVN\iSport.com\WorkingSourceCode_JIRA\Scripts\swim.countries_swim.js *****************/
function countryItem(sCode2, sCode3, sName) {
    this.Code2 = sCode2;
    this.Code3 = sCode3;
    this.Name = sName;
}

var AllCountries = new Array(
    new countryItem('AF', 'AFG', 'Afghanistan'),
new countryItem('AL', 'ALB', 'Albania'),
new countryItem('DZ', 'DZA', 'Algeria'),
new countryItem('AS', 'ASM', 'American Samoa'),
new countryItem('AD', 'AND', 'Andorra'),
new countryItem('AO', 'AGO', 'Angola'),
new countryItem('AI', 'AIA', 'Anguilla'),
new countryItem('AG', 'AVG', 'Antigua And Barbuda'),
new countryItem('AR', 'ARG', 'Argentina'),
new countryItem('AM', 'ARM', 'Armenia'),
new countryItem('AW', 'ABW', 'Aruba'),
new countryItem('AU', 'AUS', 'Australia'),
new countryItem('AT', 'AUT', 'Austria'),
new countryItem('AZ', 'AZE', 'Azerbaijan'),
new countryItem('BS', 'BHS', 'Bahamas'),
new countryItem('BH', 'BHR', 'Bahrain'),
new countryItem('BD', 'BGD', 'Bangladesh'),
new countryItem('BB', 'BRB', 'Barbados'),
new countryItem('BY', 'BLR', 'Belarus'),
new countryItem('BE', 'BEL', 'Belgium'),
new countryItem('BZ', 'BLZ', 'Belize'),
new countryItem('BJ', 'BEN', 'Benin'),
new countryItem('BM', 'BMU', 'Bermuda'),
new countryItem('BT', 'BTN', 'Bhutan'),
new countryItem('BO', 'BOL', 'Bolivia'),
new countryItem('BA', 'BIH', 'Bosnia And Herzegowina'),
new countryItem('BW', 'BWA', 'Botswana'),
new countryItem('BV', 'BVT', 'Bouvet Island'),
new countryItem('BR', 'BRA', 'Brazil'),
new countryItem('IO', 'IOT', 'British Indian Ocean Territory'),
new countryItem('BN', 'BRN', 'Brunei Darussalam'),
new countryItem('BG', 'BGR', 'Bulgaria'),
new countryItem('BF', 'BFA', 'Burkina Faso'),
new countryItem('BD', 'BDI', 'Burundi'),
new countryItem('KH', 'KHM', 'Cambodia'),
new countryItem('CM', 'CMR', 'Cameroon'),
new countryItem('CA', 'CAN', 'Canada'),
new countryItem('CV', 'CPV', 'Cape Verde'),
new countryItem('KY', 'CYM', 'Cayman Islands'),
new countryItem('CF', 'CAF', 'Central African Republic'),
new countryItem('TD', 'TCD', 'Chad'),
new countryItem('CL', 'CHL', 'Chile'),
new countryItem('CN', 'CHN', 'China'),
new countryItem('CX', 'CXR', 'Christmas Island'),
new countryItem('CC', 'CCK', 'Cocos '),
new countryItem('CO', 'COL', 'Colombia'),
new countryItem('KM', 'COM', 'Comoros'),
new countryItem('CG', 'COG', 'Congo'),
new countryItem('CD', 'COD', 'Congo, The Drc'),
new countryItem('CK', 'COK', 'Cook Islands'),
new countryItem('CR', 'CRI', 'Costa Rica'),
new countryItem('CI', 'CIV', 'Cote D\'ivoire'),
new countryItem('HR', 'HRV', 'Croatia '),
new countryItem('CU', 'CUB', 'Cuba'),
new countryItem('CY', 'CYP', 'Cyprus'),
new countryItem('CZ', 'CZE', 'Czech Republic'),
new countryItem('DK', 'DNK', 'Denmark'),
new countryItem('DJ', 'DJI', 'Djibouti'),
new countryItem('DM', 'DMA', 'Dominica'),
new countryItem('DO', 'DOM', 'Dominican Republic'),
new countryItem('TP', 'TMP', 'East Timor'),
new countryItem('EC', 'ECU', 'Ecuador'),
new countryItem('EG', 'EGY', 'Egypt'),
new countryItem('SV', 'SLV', 'El Salvador'),
new countryItem('GQ', 'GNQ', 'Equatorial Guinea'),
new countryItem('ER', 'ERI', 'Eritrea'),
new countryItem('EE', 'EST', 'Estonia'),
new countryItem('ET', 'ETH', 'Ethiopia'),
new countryItem('FK', 'FLK', 'Falkland Islands '),
new countryItem('FO', 'FRO', 'Faroe Islands'),
new countryItem('FJ', 'FJI', 'Fiji'),
new countryItem('FI', 'FIN', 'Finland'),
new countryItem('FR', 'FRA', 'France'),
new countryItem('GF', 'GUF', 'French Guiana'),
new countryItem('PF', 'PYF', 'French Polynesia'),
new countryItem('TF', 'ATF', 'French Southern Territories'),
new countryItem('GA', 'GAB', 'Gabon'),
new countryItem('GM', 'GMB', 'Gambia'),
new countryItem('GE', 'GEO', 'Georgia'),
new countryItem('DE', 'DEU', 'Germany'),
new countryItem('GH', 'GHA', 'Ghana'),
new countryItem('GI', 'GIB', 'Gibraltar'),
new countryItem('GR', 'GRC', 'Greece'),
new countryItem('GL', 'GRL', 'Greenland'),
new countryItem('GD', 'GRD', 'Grenada'),
new countryItem('GP', 'GLP', 'Guadeloupe'),
new countryItem('GU', 'GUM', 'Guam'),
new countryItem('GT', 'GTM', 'Guatemala'),
new countryItem('GN', 'GIN', 'Guinea'),
new countryItem('GW', 'GNB', 'Guinea-bissau'),
new countryItem('GY', 'GUY', 'Guyana'),
new countryItem('HT', 'HTI', 'Haiti'),
new countryItem('HM', 'HMD', 'Heard And Mc Donald Islands'),
new countryItem('VA', 'VAT', 'Holy See '),
new countryItem('HN', 'HND', 'Honduras'),
new countryItem('HK', 'HKG', 'Hong Kong'),
new countryItem('HU', 'HUN', 'Hungary'),
new countryItem('IS', 'ISL', 'Iceland'),
new countryItem('IN', 'IND', 'India'),
new countryItem('ID', 'IDN', 'Indonesia'),
new countryItem('IR', 'IRN', 'Iran '),
new countryItem('IQ', 'IRQ', 'Iraq'),
new countryItem('IE', 'IRL', 'Ireland'),
new countryItem('IL', 'ISR', 'Israel'),
new countryItem('IT', 'ITA', 'Italy'),
new countryItem('JM', 'JAM', 'Jamaica'),
new countryItem('JP', 'JPN', 'Japan'),
new countryItem('JO', 'JOR', 'Jordan'),
new countryItem('KZ', 'KAZ', 'Kazakhstan'),
new countryItem('KE', 'KEN', 'Kenya'),
new countryItem('KI', 'KIR', 'Kiribati'),
new countryItem('KP', 'PRK', 'Korea, D.P.R.O.'),
new countryItem('KR', 'KOR', 'Korea, Republic Of'),
new countryItem('KW', 'KWT', 'Kuwait'),
new countryItem('KG', 'KGZ', 'Kyrgyzstan'),
new countryItem('LA', 'LAO', 'Laos'),
new countryItem('LV', 'LVA', 'Latvia'),
new countryItem('LB', 'LBN', 'Lebanon'),
new countryItem('LS', 'LSO', 'Lesotho'),
new countryItem('LR', 'LBR', 'Liberia'),
new countryItem('LY', 'LBY', 'Libyan Arab Jamahiriya'),
new countryItem('LI', 'LIE', 'Liechtenstein'),
new countryItem('LT', 'LTU', 'Lithuania'),
new countryItem('LU', 'LUX', 'Luxembourg'),
new countryItem('MO', 'MAC', 'Macau'),
new countryItem('MK', 'MKD', 'Macedonia'),
new countryItem('MG', 'MDG', 'Madagascar'),
new countryItem('MW', 'MWI', 'Malawi'),
new countryItem('MY', 'MYS', 'Malaysia'),
new countryItem('MV', 'MDV', 'Maldives'),
new countryItem('ML', 'MLI', 'Mali'),
new countryItem('MT', 'MLT', 'Malta'),
new countryItem('MH', 'MHL', 'Marshall Islands'),
new countryItem('MQ', 'MTQ', 'Martinique'),
new countryItem('MR', 'MRT', 'Mauritania'),
new countryItem('MU', 'MUS', 'Mauritius'),
new countryItem('YT', 'MYT', 'Mayotte'),
new countryItem('MX', 'MEX', 'Mexico'),
new countryItem('FM', 'FSM', 'Micronesia, Federated States Of'),
new countryItem('MD', 'MDA', 'Moldova, Republic Of'),
new countryItem('MC', 'MCO', 'Monaco'),
new countryItem('MN', 'MNG', 'Mongolia'),
new countryItem('MS', 'MSR', 'Montserrat'),
new countryItem('MA', 'MAR', 'Morocco'),
new countryItem('MZ', 'MOZ', 'Mozambique'),
new countryItem('MM', 'MMR', 'Myanmar '),
new countryItem('NA', 'NAM', 'Namibia'),
new countryItem('NR', 'NRU', 'Nauru'),
new countryItem('NP', 'NPL', 'Nepal'),
new countryItem('NL', 'NLD', 'Netherlands'),
new countryItem('AN', 'ANT', 'Netherlands Antilles'),
new countryItem('NC', 'NCL', 'New Caledonia'),
new countryItem('NZ', 'NZL', 'New Zealand'),
new countryItem('NI', 'NIC', 'Nicaragua'),
new countryItem('NE', 'NER', 'Niger'),
new countryItem('NG', 'NGA', 'Nigeria'),
new countryItem('NU', 'NIU', 'Niue'),
new countryItem('NF', 'NFK', 'Norfolk Island'),
new countryItem('MP', 'MNP', 'Northern Mariana Islands'),
new countryItem('NO', 'NOR', 'Norway'),
new countryItem('OM', 'OMN', 'Oman'),
new countryItem('PK', 'PAK', 'Pakistan'),
new countryItem('PW', 'PLW', 'Palau'),
new countryItem('PS', 'PSE', 'Palestinian Territory'),
new countryItem('PA', 'PAN', 'Panama'),
new countryItem('PG', 'PNG', 'Papua New Guinea'),
new countryItem('PY', 'PRY', 'Paraguay'),
new countryItem('PE', 'PER', 'Peru'),
new countryItem('PH', 'PHL', 'Philippines'),
new countryItem('PN', 'PCN', 'Pitcairn'),
new countryItem('PL', 'POL', 'Poland'),
new countryItem('PT', 'PRT', 'Portugal'),
new countryItem('PR', 'PRI', 'Puerto Rico'),
new countryItem('QA', 'QAT', 'Qatar'),
new countryItem('RE', 'REU', 'Reunion'),
new countryItem('RO', 'ROM', 'Romania'),
new countryItem('RU', 'RUS', 'Russia'),
new countryItem('RW', 'RWA', 'Rwanda'),
new countryItem('KN', 'KNA', 'Saint Kitts And Nevis'),
new countryItem('LC', 'LCA', 'Saint Lucia'),
new countryItem('VC', 'VCT', 'Saint Vincent And The Grenadines'),
new countryItem('WS', 'WSM', 'Samoa'),
new countryItem('SM', 'SMR', 'San Marino'),
new countryItem('ST', 'STP', 'Sao Tome And Principe'),
new countryItem('SA', 'SAU', 'Saudi Arabia'),
new countryItem('SN', 'SEN', 'Senegal'),
new countryItem('RS', 'SRB', 'Serbia'),
new countryItem('SC', 'SYC', 'Seychelles'),
new countryItem('SL', 'SLE', 'Sierra Leone'),
new countryItem('SG', 'SGP', 'Singapore'),
new countryItem('SK', 'SVK', 'Slovakia '),
new countryItem('SI', 'SVN', 'Slovenia'),
new countryItem('SB', 'SLB', 'Solomon Islands'),
new countryItem('SO', 'SOM', 'Somalia'),
new countryItem('ZA', 'ZAF', 'South Africa'),
new countryItem('GS', 'SGS', 'South Georgia And South S.S.'),
new countryItem('ES', 'ESP', 'Spain'),
new countryItem('LK', 'LKA', 'Sri Lanka'),
new countryItem('SH', 'SHN', 'St. Helena'),
new countryItem('PM', 'SPM', 'St. Pierre And Miquelon'),
new countryItem('SD', 'SDN', 'Sudan'),
new countryItem('SR', 'SUR', 'Suriname'),
new countryItem('SJ', 'SJM', 'Svalbard And Jan Mayen Islands'),
new countryItem('SZ', 'SWZ', 'Swaziland'),
new countryItem('SE', 'SWE', 'Sweden'),
new countryItem('CH', 'CHE', 'Switzerland'),
new countryItem('SY', 'SYR', 'Syrian Arab Republic'),
new countryItem('TW', 'TWN', 'Taiwan'),
new countryItem('TJ', 'TJK', 'Tajikistan'),
new countryItem('TZ', 'TZA', 'Tanzania, United Republic Of'),
new countryItem('TH', 'THA', 'Thailand'),
new countryItem('TG', 'TGO', 'Togo'),
new countryItem('TK', 'TKL', 'Tokelau'),
new countryItem('TO', 'TON', 'Tonga'),
new countryItem('TT', 'TTO', 'Trinidad And Tobago'),
new countryItem('TN', 'TUN', 'Tunisia'),
new countryItem('TR', 'TUR', 'Turkey'),
new countryItem('TM', 'TKM', 'Turkmenistan'),
new countryItem('TC', 'TCA', 'Turks And Caicos Islands'),
new countryItem('TV', 'TUV', 'Tuvalu'),
new countryItem('UM', 'UMI', 'U.S. Minor Islands'),
new countryItem('UG', 'UGA', 'Uganda'),
new countryItem('UA', 'UKR', 'Ukraine'),
new countryItem('AE', 'ARE', 'United Arab Emirates'),
new countryItem('GB', 'GBR', 'United Kingdom'),
new countryItem('US', 'USA', 'United States'),
new countryItem('UY', 'URY', 'Uruguay'),
new countryItem('UZ', 'UZB', 'Uzbekistan'),
new countryItem('VU', 'VUT', 'Vanuatu'),
new countryItem('VE', 'VEN', 'Venezuela'),
new countryItem('VN', 'VNM', 'Viet Nam'),
new countryItem('VG', 'VGB', 'Virgin Islands (British)'),
new countryItem('VI', 'VIR', 'Virgin Islands (U.S.)'),
new countryItem('WF', 'WLF', 'Wallis And Futuna Islands'),
new countryItem('EH', 'ESH', 'Western Sahara'),
new countryItem('YE', 'YEM', 'Yemen'),
new countryItem('YU', 'YUG', 'Yugoslavia '),
new countryItem('ZM', 'ZMB', 'Zambia'),
new countryItem('ZW', 'ZWE', 'Zimbabwe')
);
function getCountryByCode2(sCode2) {
    for (var i = 0; i < AllCountries.length; i++) {
        if (sCode2 == AllCountries[i].Code2) {
            return AllCountries[i];
        }
    }
    return null;
}
function changeCode2ToCode3(sCode2) {
    for (var i = 0; i < AllCountries.length; i++) {
        if (sCode2 == AllCountries[i].Code2) {
            return AllCountries[i];
        }
    }
    return null;
}

function changeCode3ToCode2(sCode3) {
    for (var i = 0; i < AllCountries.length; i++) {
        if (sCode3 == AllCountries[i].Code3) {
            return AllCountries[i];
        }
    }
}
var countryHelper = {
    addRemainCountryCode2: function(select, sSelectedValue) {
        var addedCountry = new Array();
        for (var i = 0; i < select.options.length; i++) {
            addedCountry[addedCountry.length] = select.options[i].value;
        }

        for (var i = 0; i < AllCountries.length; i++) {
            var isAdded = false;
            for (var j = 0; j < addedCountry.length; j++) {
                if (addedCountry[i] == AllCountries[i].Code2) {
                    isAdded = true;
                    break;
                }
            }
            if (isAdded) {
                continue;
            }
            var newOption = document.createElement('OPTION');
            newOption.value = AllCountries[i].Code2;
            newOption.text = AllCountries[i].Code2;
            select.options.add(newOption);
        }
        if ((sSelectedValue == null) || (sSelectedValue == "")) {
            sSelectedValue = qtek_dhtml.readCookie('Swim_Cookie_User_Country');
        }
        select.value = sSelectedValue;
    }
}

function makeCountryCode2Select(select, sSelectedValue) {
    if (select == null)
        return;

    if ((sSelectedValue == null) || (sSelectedValue == "")) {
        sSelectedValue = qtek_dhtml.readCookie('Swim_Cookie_User_Country');
    }

    if (select.options.length < 10) {
        for (var i = 0; i < AllCountries.length; i++) {
            var newOption = document.createElement('OPTION');
            newOption.value = AllCountries[i].Code2;
            newOption.text = AllCountries[i].Name;
            select.options.add(newOption);
        }
    }

    select.value = sSelectedValue;   //alert('code2 ' + select.id + ' ' + select.value);
}

function makeCountryCode3Select(select, sSelectedValue) {
    if ((sSelectedValue == null) || (sSelectedValue == "")) {
        alert('Swim_Cookie_User_Country');
        sSelectedValue = changeCode2ToCode3(qtek_dhtml.readCookie('Swim_Cookie_User_Country')).Code3;
    }
    for (var i = 0; i < AllCountries.length; i++) {
        var newOption = document.createElement('OPTION');
        newOption.value = AllCountries[i].Code3;
        newOption.text = AllCountries[i].Name;
        select.options.add(newOption);
    }
    select.value = sSelectedValue;   //alert('code3 ' + select.id + ' ' + select.value);
}

function makeCountryCode2SelectLocation(select, sSelectedValue) {
    if ((sSelectedValue == null) || (sSelectedValue == "")) {
        sSelectedValue = qtek_dhtml.readCookie('Swim_Cookie_User_Country');
    }
    for (var i = 0; i < AllCountries.length; i++) {
        var newOption = document.createElement('OPTION');
        newOption.value = AllCountries[i].Code2;
        newOption.text = AllCountries[i].Name.toUpperCase();
        select.options.add(newOption);
    }

    select.value = sSelectedValue;
}

/*********** Begin D:\SVN\iSport.com\WorkingSourceCode_JIRA\Scripts\Queue.js *****************/
/* Queue.js - a function for creating an efficient queue in JavaScript
*
* The author of this program, Safalra (Stephen Morley), irrevocably releases
* all rights to this program, with the intention of it becoming part of the
* public domain. Because this program is released into the public domain, it
* comes with no warranty either expressed or implied, to the extent permitted
* by law.
*
* For more public domain JavaScript code by the same author, visit:
*
* http://www.safalra.com/web-design/javascript/
*/


/* Creates a new Queue. A Queue is a first-in-first-out (FIFO) data structure.
* Functions of the Queue object allow elements to be enqueued and dequeued, the
* first element to be obtained without dequeuing, and for the current size of
* the Queue and empty/non-empty status to be obtained.
*/
function Queue() {

    // the list of elements, initialised to the empty array
    var queue = [];

    // the amount of space at the front of the queue, initialised to zero
    var queueSpace = 0;

    /* Returns the size of this Queue. The size of a Queue is equal to the number
    * of elements that have been enqueued minus the number of elements that have
    * been dequeued.
    */
    this.getSize = function() {

        // return the number of elements in the queue
        return queue.length - queueSpace;

    }

    /* Returns true if this Queue is empty, and false otherwise. A Queue is empty
    * if the number of elements that have been enqueued equals the number of
    * elements that have been dequeued.
    */
    this.isEmpty = function() {

        // return true if the queue is empty, and false otherwise
        return (queue.length == 0);

    }

    /* Enqueues the specified element in this Queue. The parameter is:
    *
    * element - the element to enqueue
    */
    this.enqueue = function(element) {
        queue.push(element);
    }

    /* Dequeues an element from this Queue. The oldest element in this Queue is
    * removed and returned. If this Queue is empty then undefined is returned.
    */
    this.dequeue = function() {

        // initialise the element to return to be undefined
        var element = undefined;

        // check whether the queue is empty
        if (queue.length) {

            // fetch the oldest element in the queue
            element = queue[queueSpace];

            // update the amount of space and check whether a shift should occur
            if (++queueSpace * 2 >= queue.length) {

                // set the queue equal to the non-empty portion of the queue
                queue = queue.slice(queueSpace);

                // reset the amount of space at the front of the queue
                queueSpace = 0;

            }

        }

        // return the removed element
        return element;

    }

    /* Returns the oldest element in this Queue. If this Queue is empty then
    * undefined is returned. This function returns the same value as the dequeue
    * function, but does not remove the returned element from this Queue.
    */
    this.getOldestElement = function() {

        // initialise the element to return to be undefined
        var element = undefined;

        // if the queue is not element then fetch the oldest element in the queue
        if (queue.length) element = queue[queueSpace];

        // return the oldest element
        return element;

    }

}

/*********** Begin D:\SVN\iSport.com\WorkingSourceCode_JIRA\Scripts\swim.dhtml.js *****************/
/****** This JavaScript file is used to manipulate HTML content on the client side *****/
/****** Copyright by QTek                                                          *****/
/****** Creation Date: May 30th, 2007                                              *****/

var qtek_dhtml = {
    language: null, initialized: false,
    isMinNS4: false, isMinIE4: false, isIE4: false, isMinIE5: false, isMinIE55: false, isMinIE6: false, isOpera: false, isMinOpera5: false, isMinOpera6: false, isMinOpera9: false,
    markX: 0, markY: 0, mouseX: 0, mouseY: 0, windowWidth: 0, windowHeight: 0, rootUrl: null,

    init: function(lang) {
        if (this.initialized) return;
        this.language = (lang ? lang : "EN");
        this.isMinNS4 = (navigator.appName.indexOf("Netscape") >= 0 && parseFloat(navigator.appVersion) >= 4) ? true : false;
        this.isMinIE4 = (document.all) ? true : false;
        this.isIE4 = (this.isMinIE4 && navigator.appVersion.indexOf("MSIE 4.") >= 0) ? true : false;
        this.isMinIE5 = (this.isMinIE55 || (this.isMinIE4 && navigator.appVersion.indexOf("MSIE 5.") >= 0)) ? true : false;
        this.isMinIE55 = (this.isMinIE6 || (this.isMinIE4 && navigator.appVersion.indexOf("MSIE 5.5") >= 0)) ? true : false;
        this.isMinIE6 = (this.isMinIE4 && navigator.appVersion.indexOf("MSIE 6.") >= 0) ? true : false;
        this.isOpera = (navigator.appName.toLowerCase().indexOf("opera") != -1) ? true : false;
        this.isMinOpera5 = (this.isOpera && parseFloat(navigator.appVersion) >= 5) ? true : false;
        this.isMinOpera6 = (this.isOpera && parseFloat(navigator.appVersion) >= 6) ? true : false;
        this.isMinOpera9 = (this.isOpera && parseFloat(navigator.appVersion) >= 9) ? true : false;

        if (typeof (window.innerWidth) == "number") {
            this.windowWidth = window.innerWidth;
            this.windowHeight = window.innerHeight;
        }
        else {
            if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) //IE 6+ in 'standards compliant mode'
            {
                this.windowWidth = document.documentElement.clientWidth;
                this.windowHeight = document.documentElement.clientHeight;
            }
            else if (document.body && (document.body.clientWidth || document.body.clientHeight)) //IE 4 compatible
            {
                this.windowWidth = document.body.clientWidth;
                this.windowHeight = document.body.clientHeight;
            }
        }

        if (this.isMinNS4) {
            document.captureEvents(Event.MOUSEMOVE);
            document.captureEvents(Event.CLICK);
        }
        document.onmousemove = this.getMousePosition;
        //document.onclick = this.getMouseClickPosition;//<<<<<<<An removed

        if (this.isMinIE55 && document.body.filters) {
            for (var i = 0; i < document.images.length; i++) {
                var img = document.images[i];
                var imgName = img.src.toUpperCase();
                if (imgName.substring(imgName.length - 3, imgName.length) == "PNG") {
                    var imgID = (img.id) ? "id='" + img.id + "' " : "";
                    var imgClass = (img.className) ? "class='" + img.className + "' " : "";
                    var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
                    var imgStyle = "display:inline-block;" + img.style.cssText;
                    if (img.align == "left") imgStyle = "float:left;" + imgStyle;
                    if (img.align == "right") imgStyle = "float:right;" + imgStyle;
                    if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
                    var strNewHTML = "<span " + imgID + imgClass + imgTitle
                                    + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
                                    + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'" + img.src + "\', sizingMethod='scale');\"></span>";
                    img.outerHTML = strNewHTML;
                    i = i - 1;
                }
            }
        }

        this.initialized = true;
        //alert("qtek_dhtml.init() called");
    }, //END init function

    /***** Common Methods *****/
    getElementById: function(elemId) {
        if (typeof (elemId) == "object" || elemId.style) return elemId;
        if (document.getElementById) return document.getElementById(elemId);
        else if (document.all) return document.all[elemId];
        else if (document.layers) return document.layers[elemId];
        return null;
    }, //END getElementById function
    getArrayItemIndex: function(array, item) {
        if (array != null && array.length > 0) {
            for (var i = 0; i < array.length; i++) {
                if (array[i].toString() == item.toString()) return i;
            }
        }
        return -1;
    }, //END getArrayItemIndex function
    trim: function(input) {
        if (typeof (input) == "object") {
            input.value = this.trim(input.value);
            return input.value;
        }
        var startpos = 0, endpos = input.length - 1;
        if (endpos == -1) return input;
        while (startpos <= input.length && input.substring(startpos, startpos + 1) == " ") startpos++;
        while (endpos >= 0 && input.substring(endpos, endpos + 1) == " ") endpos--;
        if (startpos > endpos) return "";
        else return input.substring(startpos, endpos + 1);
    }, //END trim function
    getCultureCode: function() {
        var code = (this.language ? this.language : "EN");
        if (arguments.length > 0 && arguments[0]) code = arguments[0];
        if (code.toUpperCase() == "VI") return 1; //Vietnamese
        return 0; //English
    }, //END getCultureCode function
    isDigit: function(digit) {
        var alldigit = new Array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
        for (var i = 0; i < alldigit.length; i++) {
            if (digit == alldigit[i]) return true;
        }
        return false;
    }, //END isDigit function
    isNumeric: function(value) {
        value = this.trim(value);
        if (value == "") return false;
        var arrayChars = value.split("");
        var i = 0;
        if (arrayChars[0] == "-") i = 1;
        for (i = i; i < arrayChars.length; i++) {
            if (!this.isDigit(arrayChars[i])) return false;
        }
        return true;
    }, //END isNumeric function

    /***** Key Code/Event *****/
    getKeyCode: function(e) {
        var keyEvent = (e) ? e : (window.event ? window.event : null);
        if (keyEvent) return (keyEvent.charCode ? keyEvent.charCode : (keyEvent.keyCode ? keyEvent.keyCode : (keyEvent.which ? keyEvent.which : 0)));
        return 0;
    }, //END getKeyCode function
    getKeyDown: function(e) {
        return js_getKeyCode(e);
    }, //END getKeyDown function

    /***** Mouse Event *****/
    getMousePosition: function(e) {
        if (this.isMinNS4) {
            this.mouseX = e.pageX;
            this.mouseY = e.pageY;
        }
        else if (this.isMinIE4) {
            this.mouseX = window.event.clientX + (document.body == null ? 0 : document.body.scrollLeft);
            this.mouseY = window.event.clientY + (document.body == null ? 0 : document.body.scrollTop);
        }
        return [this.mouseX, this.mouseY]
    }, //END getMousePosition function
    getMouseClickPosition: function(e) {
        if (this.isMinNS4) {
            this.markX = e.pageX;
            this.markY = e.pageY;
        }
        if (this.isMinIE4) {
            this.markX = window.event.clientX + document.body.scrollLeft;
            this.markY = window.event.clientY + document.body.scrollTop;
        }
        return [this.markX, this.markY];
    }, //END getMouseClickPosition function

    /***** Document and Elment dimensions *****/
    getDocumentHeight: function(doc) {
        var docHt = 0, sh, oh;
        if (doc.height) docHt = doc.height;
        else if (doc.body) {
            if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
            if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
            if (sh && oh) docHt = Math.max(sh, oh);
        }
        return docHt;
    }, //END getDocumentHeight function
    getDocumentWidth: function(doc) {
        if (!doc) doc = window.document;
        return qtek_dhtml.getElementWidth(window.document.body);
    }, //END getDocumentWidth function
    getElementHeight: function(layer) {
        var pvHeight = -1;
        if (typeof (layer) == "string") layer = this.getElementById(layer);
        if (this.isMinNS4 && navigator.appVersion.indexOf('4.') >= 0 && typeof layer.clip != 'undefined') pvHeight = layer.clip.height;
        else {
            if (this.isOpera && navigator.appVersion.indexOf('5.') >= 0) pvHeight = layer.style.pixelHeight;
            else {
                if (layer.offsetHeight) pvHeight = layer.offsetHeight;
                else pvHeight = layer.style.height;
            }
        }
        return pvHeight;
    }, //END getElementHeight function
    getElementWidth: function(layer) {
        var pvWidth = -1;
        if (typeof (layer) == "string") layer = this.getElementById(layer);
        if (this.isMinNS4 && navigator.appVersion.indexOf('4.') >= 0 && typeof layer.clip != 'undefined') pvHeight = layer.clip.width;
        else {
            if (this.isOpera && navigator.appVersion.indexOf('5.') >= 0) pvWidth = layer.style.pixelWidth;
            else {
                if (layer.offsetWidth) pvWidth = layer.offsetWidth;
                else pvWidth = layer.style.width;
            }
        }
        return pvWidth;
    }, //END getElementWidth function

    getLayerWidthHeight: function(layer) {
        var size = new Array();
        size[0] = this.getElementWidth(layer);
        size[1] = this.getElementHeight(layer);

        return size;
    },
    setLayerSize: function(layer, width, height) {
        var measureUnit = "";
        if (this.isMinNS4) measureUnit = "px";
        if (typeof (layer) == "string") layer = this.getElementById(layer);
        if (this.isMinNS4 && navigator.appVersion.indexOf('4.') >= 0 && typeof layer.clip != 'undefined') {
            layer.clip.width = width + measureUnit;
            layer.clip.height = height + measureUnit;
        }
        else {
            if (this.isOpera && navigator.appVersion.indexOf('5.') >= 0) {
                layer.style.pixelWidth = width + measureUnit;
                layer.style.pixelHeight = height + measureUnit;
            }
            else {
                layer.style.width = width + measureUnit;
                layer.style.height = height + measureUnit;
            }
        }
    }, //END setLayerSize function


    //--------------------------------------------------------------------
    // setLayerMargin Function
    // Description: Set Margin for country div - Add by Nhung Pham_28/04/08
    //---------------------------------------------------------------------
    setLayerMargin: function(layer, mgLeft, mgTop) {
        if (mgLeft != '') {
            layer.style.marginLeft = mgLeft + "px";
        }
        if (mgTop != '') {
            layer.style.marginTop = mgTop + "px";
        }

    }, //END setLayerSize function


    setIframeHeight: function(iframeName, height) {
        var iframeWin = window.frames[iframeName];
        var iframeEl = document.getElementById ? document.getElementById(iframeName) : document.all ? document.all[iframeName] : null;
        if (iframeEl && iframeWin) {
            iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous  
            if (!height) {
                var docHt = this.getDocumentHeight(iframeWin.document);
                height = docHt + 30; // need to add to height to be sure it will all show
            }
            iframeEl.style.height = height + "px";
        }
    }, //END setIframeHeight function

    /***** Positioning *****/
    getScrollXY: function() {
        var scrOfX = 0, scrOfY = 0;
        if (typeof (window.pageYOffset) == "number") //Netscape compliant
        {
            scrOfY = window.pageYOffset;
            scrOfX = window.pageXOffset;
        }
        else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) //DOM compliant
        {
            scrOfY = document.body.scrollTop;
            scrOfX = document.body.scrollLeft;
        }
        else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) //IE6 standards compliant mode
        {
            scrOfY = document.documentElement.scrollTop;
            scrOfX = document.documentElement.scrollLeft;
        }
        return [scrOfX, scrOfY];
    }, //END getScrollXY function
    getScreenCenterXY: function() {
        var js_centerX = 0;
        var js_centerY = 0;
        if (this.windowWidth > 0 && this.windowHeight > 0) {
            var scrollXY = getScrollXY();
            js_centerX = this.windowWidth / 2 + scrollXY[0];
            js_centerY = this.windowHeight / 2 + scrollXY[1];
        }
        return [js_centerX, js_centerY]
    }, //END getScreenCenterXY function
    getLayerTopLeft: function(layer) {
        var positionLeft = positionTop = 0;
        if (typeof (layer) == "string") layer = this.getElementById(layer);
        if (layer.offsetParent) {
            positionLeft = layer.offsetLeft;
            positionTop = layer.offsetTop;
            while (layer = layer.offsetParent) {
                positionLeft += layer.offsetLeft;
                positionTop += layer.offsetTop;
            }
        }
        return [positionLeft, positionTop];
    }, //END getLayerTopLeft function
    getLayerLeft: function(layer) {
        var pvPos = this.getLayerTopLeft(layer);
        if (pvPos) return pvPos[0];
        return -1;
    }, //END getLayerLeft function
    getLayerTop: function(layer) {
        var pvPos = this.getLayerTopLeft(layer);
        if (pvPos) return pvPos[1];
        return -1;
    }, //END getLayerTop function
    getLayerRight: function(layer) {
        var pvRight = -1;
        var pvLeft = this.getLayerLeft(layer);
        var pvWidth = this.getElementWidth(layer);
        if (pvLeft > -1 && pvWidth > -1) pvRight = pvLeft + pvWidth;
        return pvRight;
    }, //END getLayerRight function
    getLayerBottom: function(layer) {
        var pvBottom = -1;
        var pvTop = this.getLayerTop(layer);
        var pvHeight = this.getElementHeight(layer);
        if (pvTop > -1 && pvHeight > -1) pvBottom = pvTop + pvHeight;
        return pvBottom;
    }, //END getLayerBottom function
    isInArea: function(top, left, right, bottom, posX, posY) {
        if (posX <= right && posX >= left && posY >= top && posY <= bottom) return true;
        return false;
    }, //END isInArea function
    moveLayerTo: function(layer, x, y) {
        var measureUnit = "";
        if (this.isMinNS4) measureUnit = "px";
        if (typeof (layer) == "string") layer = this.getElementById(layer);
        if (document.layers) layer.moveTo(x, y);
        else {
            layer.style.left = x + measureUnit;
            layer.style.top = y + measureUnit;
        }
    }, //END moveLayerTo function
    moveLayerBy: function(layer, dx, dy) {
        var pvPos = this.getLayerTopLeft(layer);
        if (pvPos) {
            pvPos[0] += dx;
            pvPos[1] += dy;
            this.moveLayerTo(layer, pvPos[0], pvPos[1]);
        }
    }, //END moveLayerBy function
    moveLayerToX: function(layer, x) {
        var pvPos = this.getLayerTopLeft(layer);
        if (pvPos) this.moveLayerTo(layer, x, pvPos[1]);
    }, //END moveLayerToX function
    moveLayerToY: function(layer, y) {
        var pvPos = this.getLayerTopLeft(layer);
        if (pvPos) this.moveLayerTo(layer, pvPos[0], y);
    }, //END moveLayerToY function

    /***** Layer Visibility *****/
    showhideLayer: function(layer) //should add effect type in second argument
    {
        if (typeof (layer) == "string") layer = this.getElementById(layer);
        if (!layer) return;
        if (this.isVisible(layer)) this.hideLayer(layer);
        else this.showLayer(layer);
    }, //END showhideLayer function
    showLayer: function(layer) {
        if (typeof (layer) == "string") layer = this.getElementById(layer);
        layer.style.visibility = "visible";
        layer.style.display = "block";
        if (this.isMinNS4) {
            if (layer.visibility) layer.visibility = "show";
            else if (layer.style.visibility) layer.style.visibility = "visible";
        }
    }, //END showLayer function
    hideLayer: function(layer) {
        if (typeof (layer) == "string") layer = this.getElementById(layer);
        layer.style.visibility = "hidden";
        layer.style.display = "none";
        if (this.isMinNS4) {
            if (layer.visibility) layer.visibility = "hide";
            else if (layer.style.visibility) layer.style.visibility = "hidden";
        }
    }, //END hideLayer function
    isVisible: function(layer) {
        if (typeof (layer) == "string") layer = this.getElementById(layer);
        if (layer.style.visibility == "visible" || layer.style.display == "block" || layer.style.display == "inline") return true;
        return false;
    }, //END isVisible function

    /***** Style Changes *****/
    changeColor: function(layer, toColor) {
        if (typeof (layer) == "string") layer = this.getElementById(layer);
        if (layer) layer.style.color = toColor;
    }, //END changeBgColor function
    changeBgColor: function(layer, toColor) {
        if (typeof (layer) == "string") layer = this.getElementById(layer);
        if (layer) layer.style.backgroundColor = toColor;
    }, //END changeBgColor function
    changeBgImage: function(layer, toImageUrl) {
        if (typeof (layer) == "string") layer = this.getElementById(layer);
        if (layer) layer.style.backgroundImage = toImageUrl;
    }, //END changeBgImage function
    changeCursor: function(layer, cursor) {
        if (typeof (layer) == "string") layer = this.getElementById(layer);
        if (layer) layer.style.cursor = cursor;
    }, //END changeCursor function

    /***** Image Swap *****/
    swapImage: function(img, src1, src2) {
        img = this.getElementById(img);
        if (!img) return;
        if (img.src.toLowerCase() == src1.toLowerCase()) img.src = src2;
        else img.src = src1;
    }, //END swapImage function
    setImage: function(img, src) {
        img = this.getElementById(img);
        if (!img) return;
        img.src = src;
    }, //END setImage function
    /***** End Image Swap *****/

    /***** Url Parameters *****/
    appendUrlParameter: function(url, name, value) {
        var pair = (arguments.length > 3 && !arguments[3] ? name + "=" + value : this.encodeUrlParameter(name, value));
        if (!url || url.length < 3) return pair;
        if (url.indexOf("?") < 0) return (url + "?" + pair);
        else if (url.indexOf("?") == (url.length - 1)) return (url + pair);
        return (url + "&" + pair);
    }, //END appendUrlParameter function
    buildUrlParameter: function(list, name, value) {
        var pair = (arguments.length > 3 && !arguments[3] ? name + "=" + value : this.encodeUrlParameter(name, value));
        return (!list || list.length < 3 ? pair : (list + "&" + pair))
    }, //END buildUrlParameter function
    encodeUrlParameter: function(name, value) {
        return encodeURIComponent(name) + "=" + encodeURIComponent(value);
    }, //END encodeUrlParameter function
    encodeUrl: function(url) {
        var array = url.split('&');
        for (var i = 0; i < array.length; i++) {
            var nvpairs = array[i].split('=');
            if (nvpairs[0].indexOf('amp;') != -1)
                nvpairs[0] = nvpairs[0].substring(4);

            nvpairs[i] = this.encodeUrlParameter(nvpairs[0], nvpairs[1]);
        }
        return array.join('&');
    }, //END encodeUrl function

    /***** Cookies *****/

    createCookie: function(name, value, days) {
        var expire_option = "";
        if (!days) {
            days = 30;
        }
        if (days) {
            var current_time = new Date();
            current_time.setTime(current_time.getTime() + days * 24 * 60 * 60 * 1000);
            expire_option = "; expires=" + current_time.toGMTString();
        }
        document.cookie = name + "=" + value + expire_option + "; path=/; domain=" + cookieHelper.cookieDomain;
    }, //END createCookie function
    readCookie: function(name) {
        var nameEQ = name + "=";
        var ca = document.cookie.split(';');
        for (var i = 0; i < ca.length; i++) {
            var c = ca[i];
            while (c.charAt(0) == ' ') c = c.substring(1, c.length);
            if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
        }
        return null;
    }, //END readCookie function
    deleteCookie: function(name) {
        this.createCookie(name, "", -1);
    }, //END deleteCookie function
    /***** End Cookies *****/

    /***** Parsing *****/
    parseCurrency: function(incurrency) //convert currency to a value in specific culture
    {
        var culture = this.getCultureCode(arguments[1]); //no problem if arguments[1] is null
        var cents = 0, dollars = "";
        var cent_delim = (culture == 1 ? "," : ".");
        var dollar_delim = (culture == 1 ? "." : ",");
        var money_parts = incurrency.toString().split(cent_delim);
        if (money_parts.length > 1) {
            if (this.isNumeric(money_parts[1]) == false) {
                alert("invalid cent part in currency value " + incurrency);
                return false;
            }
            cents = parseInt(money_parts[1], 10);
        }
        money_parts = money_parts[0].toString().split(dollar_delim);
        for (var i = money_parts.length - 1; i >= 0; i--) {
            if (this.isNumeric(money_parts[i]) == false || (i > 0 && money_parts[i].length != 3)) {
                alert("invalid dollar part in currency value " + incurrency);
                return false;
            }
            else dollars = money_parts[i] + "" + dollars;
        }
        return parseFloat((dollars == "" ? "0" : dollars) + "" + (cents > 0 ? "." + cents : ""));
    }, //end parseCurrency function

    /***** formats *****/
    prefixZeros: function(input, finallength) //left padding
    {
        input = this.trim(input.toString());
        while (input.length < finallength) input = "0" + input;
        return input;
    }, //end prefixzeros function
    formatCurrency: function(incurrency) {
        var value = this.parseCurrency(incurrency, arguments[1]);
        if (!value) return incurrency;

        var culture = this.getCultureCode(arguments[1]);
        var cent_delim = (culture == 1 ? "," : ".");
        var dollar_delim = (culture == 1 ? "." : ",");
        var money_parts = value.toString().split(cent_delim);
        var cents = (money_parts.length > 1 ? money_parts[1].toString() : "0");
        var dollars = money_parts[0].toString();

        value = "";
        for (var i = 1; i <= dollars.length; i++) {
            value = dollars.charAt(dollars.length - i) + "" + value;
            if (i % 3 == 0 && i < dollars.length)
                value = dollar_delim + value;
        }
        return value + (parseInt(cents, 10) > 0 ? cent_delim + cents : "");
    } //end formatcurrency function
}; //END qtek_dhtml OBJECT
qtek_dhtml.init();

var ajaxQueue = new Queue();
var isSending = false;

function nextRequest() {
    setTimeout("sendAjax()", 100);
}
// input: ...<script ...> script content </script>...
// output: script content
function findScriptContent(rawText) {
    if (rawText == "") {
        return "";
    }
    var tempText = rawText.toLowerCase();
    var indexOfScript = tempText.indexOf("<script");
    if (indexOfScript < 0) {
        return "";
    }
    var startScriptIndex = tempText.indexOf(">", indexOfScript);
    if (startScriptIndex < indexOfScript) {
        return "";
    }
    var endScriptIndex = tempText.indexOf("</script>", startScriptIndex);
    if (endScriptIndex < startScriptIndex) {
        return "";
    }

    return rawText.substring(startScriptIndex + 1, endScriptIndex);
}
function dynamicScript() {
    this.srcs = new Array();
    this.runs = new Array();
    this.counter = 0;
    this.addSrc = function(src) {
        this.srcs[this.srcs.length] = src;
    }
    this.addRun = function(run) {
        this.runs[this.runs.length] = run;
    }
    this.eval = function() {
        for (var i = 0; i < this.srcs.length; i++) {
            var e = document.createElement("script");
            e.type = "text/javascript";
            //            e.l
            e.src = this.srcs[i];
            document.getElementsByTagName("head")[0].appendChild(e);
        }
    }
}
function addDynamicScript(sSrc) {
    var e = document.createElement("script");
    //    e.innerHTML = "function callMsg(msg){alert(msg)};";
    e.type = "text/javascript";
    e.src = sSrc;
    document.getElementsByTagName("head")[0].appendChild(e);
}

function evalScript(container) {
    var allSrcipts = container.getElementsByTagName("script");
    for (var i = 0; i < allSrcipts.length; i++) {
        if (allSrcipts[i].src != null && allSrcipts[i].src != "") {
            addDynamicScript(allSrcipts[i].src);
        }
        else {
            try {
                eval(allSrcipts[i].innerHTML);
            }
            catch (err) {

            }

        }
    }
}
var processAjaxContent = null;
function ajaxComplete(ajaxObj) {
    ajaxObj.responseText = ajaxObj.HttpRequest.responseText;
    ajaxObj.responseXML = ajaxObj.HttpRequest.responseXML;
    ajaxObj.responseStatus[0] = ajaxObj.HttpRequest.status;
    ajaxObj.responseStatus[1] = ajaxObj.HttpRequest.statusText;
    if (ajaxObj.responseContainer) {
        var isProcessNormal = false;
        var elemNodeName = ajaxObj.responseContainer.nodeName.toLowerCase();
        if (elemNodeName == "input" || elemNodeName == "select" || elemNodeName == "option" || elemNodeName == "textarea")
            ajaxObj.responseContainer.value = ajaxObj.responseText;
        else {
            if (ajaxObj.responseContainer != null && (processAjaxContent == null || !processAjaxContent(ajaxObj.responseText, ajaxObj.responseXML, ajaxObj.responseContainer, ajaxObj.requestUrl))) {
                ajaxObj.responseContainer.innerHTML = ajaxObj.responseText;
                isProcessNormal = true;
            }
        }
        // execute script in response text
        if (isProcessNormal) {
            evalScript(ajaxObj.responseContainer);
        }
        //	    eval("" + findScriptContent(ajaxObj.responseText));
    }
    if (ajaxObj.executeResponse) ajaxObj.evalResponse();
    isSending = false;
    ajaxObj.onComplete(); //should call last
}
function sendAjax() {
    if (isSending) {
        nextRequest();
    }
    if (ajaxQueue.isEmpty()) {
        return;
    }

    var ajaxObj = ajaxQueue.dequeue();

    ajaxObj.init();

    if (!ajaxObj.HttpRequest && ajaxObj.errorMessage) {
        //alert(ajaxObj.errorMessage);///////////////////////////////////////////////////////////////////////////////////////////AN COMMENT OUT
    }
    else {
        if (ajaxObj.responseContainer && typeof (ajaxObj.responseContainer) == "string") {
            ajaxObj.responseContainer = qtek_dhtml.getElementById(ajaxObj.responseContainer);
        }

        try {
            var sCurrentLocation = (window.location + '');

            var sTest3W = 'http://www.';
            var bRequestHave3W = !(ajaxObj.requestUrl.indexOf(sTest3W) < 0);
            var bCurrentLocationHave3W = !(sCurrentLocation.indexOf(sTest3W) < 0);

            //	        if( bRequestHave3W != bCurrentLocationHave3W ){
            //	            if( bCurrentLocationHave3W ){
            //	                ajaxObj.requestUrl = ajaxObj.requestUrl.replace('http://swim.com','http://www.swim.com');
            //	            }
            //	            else{
            //	                ajaxObj.requestUrl = ajaxObj.requestUrl.replace('http://www.swim.com','http://swim.com');
            //	            }
            //	        }
            ajaxObj.HttpRequest.open(ajaxObj.requestMethod, ajaxObj.requestUrl, true);
            if (ajaxObj.requestMethod == "POST") {
                try {
                    ajaxObj.HttpRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
                }
                catch (e) {
                    if (ajaxObj.errorMessage) alert("Error setting request header.");
                }
            }

            ajaxObj.HttpRequest.send(ajaxObj.params);
            isSending = true;
            ajaxObj.HttpRequest.onreadystatechange = function() {
                switch (ajaxObj.HttpRequest.readyState) {
                    case 1: ajaxObj.onLoad(); break;
                    case 2: ajaxObj.onLoaded(); break;
                    case 3: ajaxObj.onInteractive(); break;
                    case 4:
                        ajaxComplete(ajaxObj);
                        break;
                }
            };
        }
        catch (e) {
            //alert(ajaxObj.requestUrl );

            //if (ajaxObj.errorMessage) alert("Error executing ajax.");//////////////////////////////////////////////////AN COMMENT OUT
            isSending = false;
        }
    }
}
///***************************** Ajax with XMLHTTP ActiveX **********************************/
function qtek_ajax(url, method) {
    //set more query string to know that page is ajax
    if (url.indexOf('?') > -1) {
        url += "&is_ajax=true";
        url += "&rd=" + Math.random();
    }
    else {
        url += "?is_ajax=true";
        url += "&rd=" + Math.random();
    }
    this.errorMessage = "I am sorry that your browser does not support AJAX!\n";
    this.HttpRequest = null;
    this.requestUrl = url;
    this.requestMethod = (method ? method : "GET");
    this.responseStatus = new Array(2);
    this.responseText = "";
    this.responseXML = "";
    this.responseContainer = "";
    this.executeResponse = false;
    this.params = "";

    this.onLoad = function() { };
    this.onLoaded = function() { };
    this.onInteractive = function() { };
    this.onComplete = function() { };

    this.init = function() {
        try { this.HttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); }
        catch (ex) {
            try { this.HttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); }
            catch (oc) { }
        }
        if (!this.HttpRequest && typeof (XMLHttpRequest) != "undefined") this.HttpRequest = new XMLHttpRequest();
        //if (!this.HttpRequest && this.errorMessage) alert(this.errorMessage);//////////////////////////////////////AN COMMENT OUT
    }; //END init function

    this.execute = function(params) {
        this.params = params;
        ajaxQueue.enqueue(this);
        sendAjax();
    }; //END execute function

    this.evalResponse = function() {
        if (this.responseText) eval(this.responseText);
    }; //END evalResponse function

    //	this.init(); //initialize qtek_ajax object
} //END qtek_ajax object function


/***************************** Form and Controls **********************************/
var qtek_form = {
    loadedforms: null, initialized: false,
    init: function() {
        if (this.initialized) return;
        this.loadedforms = document.forms; //save forms at first loaded state
        this.initialized = true;
    },

    /***** General methods *****/
    findForm: function(formName) {
        if (typeof (formName) == "object") return formName;
        var dforms = (arguments.length > 1 && typeof (arguments[1]) == "object" ? arguments[1] : document.forms);
        if (!formName && dforms.length > 0) return dforms[0];
        if (typeof (formName) == "string") {
            for (var i = 0; i < dforms.length; i++) {
                try {
                    if ((dforms[i].name != null) && (dforms[i].name.toUpperCase() == formName.toUpperCase())) return dforms[i];
                }
                catch (ex) {
                    return null;
                }
            }
        }
        return null;
    },
    findFormByField: function(fieldName) {
        if (typeof (fieldName) == "object") return fieldName.form;
        var dforms = document.forms;
        for (var i = 0; i < dforms.length; i++) {
            for (var j = 0; j < dforms[i].elements.length; j++) {
                if (dforms[i].elements[j].name.toUpperCase() == fieldName.toUpperCase()) return dforms[i];
            }
        }
        if (arguments.length == 1) alert("Could not find form that contains field " + fieldName + ".");
        return null;
    },
    findField: function(fieldName, formName) {
        if (typeof (fieldName) == "object") return fieldName;
        var i = 0, j = 0;
        if (formName) {
            formName = js_findForm(formName);
            for (j = 0; j < formName.elements.length; j++) {
                if (formName.elements[j].name.toUpperCase() == fieldName.toUpperCase()) return formName.elements[j];
            }
        }
        else {
            var dforms = document.forms;
            for (i = 0; i < dforms.length; i++) {
                for (j = 0; j < dforms[i].elements.length; j++) {
                    if (dforms[i].elements[j].name.toUpperCase() == fieldName.toUpperCase()) return dforms[i].elements[j];
                }
            }
        }
        if (arguments.length < 3) alert("Could not find field " + fieldName + ".");
        return null;
    },
    enable: function(controllist, valuelist, checkvalue) {
        if (typeof (controllist) == "object") {
            valuelist = qtek_dhtml.trim(valuelist);
            checkvalue = qtek_dhtml.trim(checkvalue);
            var valueFound = false;
            if (valuelist == checkvalue) valueFound = true;
            else if (valuelist != "") {
                var values = valuelist.split(";");
                for (var i = 0; i < values.length && valueFound == false; i++) {
                    if (values[i].toString() == checkvalue.toString())
                        valueFound = true;
                }
            }
            controllist.disabled = (valueFound ? false : true);
            return;
        }
        else if (controllist != "") {
            var controls = controllist.split(";");
            for (var i = 0; i < controls.length; i++) {
                var control = this.findField(controls[i]);
                if (control) this.enable(control, valuelist, checkvalue);
            }
        }
        return;
    },
    disable: function(controllist, valuelist, checkvalue) {
        if (typeof (controllist) == "object") {
            valuelist = qtek_dhtml.trim(valuelist);
            checkvalue = qtek_dhtml.trim(checkvalue);
            var valueFound = false;
            if (valuelist == checkvalue) valueFound = true;
            else if (valuelist != "") {
                var values = valuelist.split(";");
                for (var i = 0; i < values.length && valueFound == false; i++) {
                    if (values[i].toString() == checkvalue.toString())
                        valueFound = true;
                }
            }
            controllist.disabled = (valueFound ? true : false);
            return;
        }
        else if (controllist != "") {
            var controls = controllist.split(";");
            for (var i = 0; i < controls.length; i++) {
                var control = this.findField(controls[i]);
                if (control) this.disable(control, valuelist, checkvalue);
            }
        }
        return;
    },
    focus: function(field) {
        window.focus();
        field = this.findField(field, null);
        if (field) field.focus();
    },
    focusNext: function(nextField, eventKeyCode, e) //e is captured event
    {
        if (qtek_html.getKeyCode(e) == eventKeyCode) {
            nextField = this.findField(nextField, null);
            if (nextField) {
                qtek_html.trimForm(nextField.form);
                if (arguments.length > 3) {
                    var doFocus = false;
                    if (arguments[3] == "EMPTY" && nextField.value == "")
                        doFocus = true;

                    if (doFocus) nextField.focus();
                    else if (arguments.length > 4 && arguments[4] == "SUBMIT") nextField.form.submit();
                }
                else nextField.focus();
            }
        }
    },
    reset: function(form) {
        form = this.findForm(form);
        if (!form) return;

        var focusid = null;
        var originalform = this.findForm(form.name, this.loadedforms);
        if (!originalform) return;

        for (var i = 0; i < form.length; i++) {
            var fieldType = form[i].type.toLowerCase();
            if (fieldType == "text" || fieldType == "password" || fieldType == "textarea" || fieldType == "hidden") {
                form[i].value = originalform[i].value;
                if (focusid == null) focusid = i;
            }
            else if (fieldType == "checkbox" || fieldType == "radiobox") form[i].checked = originalform[i].checked;
            //need implementation for dropdown and list boxes
        }
        if (focusid != null) form[focusid].focus();
    },
    trim: function(form) {
        form = this.findForm(form);
        if (form) {
            for (var i = 0; i < form.length; i++) {
                if (form[i].type == "text" || form[i].type == "password" || form[i].type == "textarea") qtek_dhtml.trim(form[i]);
            }
        }
    },

    /***** Checkbox Fields *****/
    checkAll: function(form, checkName, checkDisabled, enableWithPrefix) {
        var fv_prefixes = null;
        if (enableWithPrefix) {
            fv_prefixes = enableWithPrefix.split(",");
        }

        form = this.findForm(form);
        for (var i = 0; i < form.length; i++) {
            if (form[i].type == "checkbox" && (checkDisabled || form[i].disabled == false)) {
                if (!checkName || checkName == form[i].name) {
                    form[i].checked = true;
                    if (enableWithPrefix) {
                        for (var j = 0; j < fv_prefixes.length; j++) {
                            var ctrlobj = this.findField(qtek_dhtml.trim(fv_prefixes[j]) + form[i].value, form, false);
                            if (ctrlobj && ctrlobj.disabled) ctrlobj.disabled = false;
                        }
                    }
                }
            }
        }
    },
    uncheckAll: function(form, checkName, checkval, disableWithPrefix) {
        var fv_prefixes = null;
        if (disableWithPrefix) {
            fv_prefixes = disableWithPrefix.split(",");
        }

        form = this.findForm(form);
        for (var i = 0; i < form.length; i++) {
            if (form[i].type == "checkbox") {
                if (!checkName || checkName == form[i].name) {

                    if (checkval && form[i].value == checkval) form[i].checked = true;
                    else {
                        form[i].checked = false;
                        if (disableWithPrefix) {
                            for (var j = 0; j < fv_prefixes.length; j++) {
                                var ctrlobj = this.findField(qtek_dhtml.trim(fv_prefixes[j]) + form[i].value, form, false);
                                if (ctrlobj && !ctrlobj.disabled) ctrlobj.disabled = true;
                            }
                        }

                    }
                }
            }
        }
    },
    countChecked: function(form, checkName) {
        var fvcnt = 0;
        form = this.findForm(form);
        for (var i = 0; i < form.length; i++) {
            if (form[i].type == "checkbox" && form[i].name == checkName && form[i].checked) fvcnt++;
        }
        return fvcnt;
    },
    getCheckedValues: function(checkName, delimiter) //delimiter can be passed as second parameter
    {
        checkName = this.findField(checkName);
        if (!checkName) return "";
        if (!delimiter) delimiter = ",";

        var fvcnt = 0, fvresult = "", form = checkName.form;
        for (var i = 0; i < form.length; i++) {
            if (form[i].type == "checkbox" && form[i].name == checkName.name && form[i].checked) {
                if (fvcnt > 0) fvresult = fvresult + delimiter + form[i].value;
                else fvresult = form[i].value;
                fvcnt++;
            }
        }
        return fvresult;
    },
    checkOnValue: function(checker, values) {
        checker = this.findField(checker);
        if (checker && values) {
            for (var i = 0; i < checker.form.length; i++) {
                if (checker.form[i].name == checker.name) {
                    var value_items = values.split(",");
                    for (var j = 0; j < value_items.length; j++) {
                        if (checker.form[i].value.toString() == value_items[j].toString()) {
                            checker.form[i].checked = true;
                            break;
                        }
                    }
                }
            }
        }
    },

    /***** Text Fields *****/
    getValue: function(field) //2nd parameter is form
    {
        if (arguments.length > 1) field = this.findField(field, arguments[1]);
        else field = this.findField(field, null);
        if (field) return field.value;
        return null;
    },
    isEmpty: function(field) //2nd parameter is form
    {
        var value = this.getValue(field, (arguments.length > 1 ? arguments[1] : null));
        return (value ? false : true);
    },
    validateTextLength: function(textfield, maxlength) {
        textfield = this.findField(textfield);
        if (textfield && textfield.value.length > maxlength)
            textfield.value = textfield.value.substring(0, maxlength);
    },

    /***** Dropdown/Listbox Fields *****/
    selectOptions: function(dropdownlist, values) //pass values=null to select all options
    {
        dropdownlist = this.findField(dropdownlist);
        if (dropdownlist && values != null) {
            for (var i = 0; i < dropdownlist.options.length; i++) {
                var value_items = values.toString().split(",");
                for (var j = 0; j < value_items.length; j++) {
                    if (value_items[j].toString() == dropdownlist.options[i].value.toString())
                        dropdownlist.options[i].selected = true;
                }
            }
        }
    },
    addOption: function(dropdownlist, value, text, selected) {
        dropdownlist = this.findField(dropdownlist);
        if (dropdownlist && typeof (dropdownlist) == "object") {
            var option = new Option(text, value);
            dropdownlist.options[dropdownlist.options.length] = option;
            if (selected) dropdownlist.options[dropdownlist.options.length - 1].selected = true;
        }
    },
    removeOption: function(dropdownlist, values, removeByValue) //values is a list of indexes; if removeByValue=true then values is an option value list
    {
        if (values == null || values.length == 0) return;
        var arrayValue = values.split(",");
        if (arrayValue.length > 1) {
            for (var i = 0; i < arrayValue.length; i++) {
                this.removeOption(dropdownlist, arrayValue[i], removeByValue);
            }
            return;
        }

        var dropdownlist = this.findField(dropdownlist);
        if (dropdownlist && typeof (dropdownlist) == "object") {
            var optionIndex = values; //values contains a single value and assuming it is an index value
            if (removeByValue) {
                optionIndex = -1;
                for (var i = 0; i < dropdownlist.options.length; i++) {
                    if (dropdownlist.options[i].value.toString() == values.toString()) {
                        optionIndex = i;
                        break;
                    }
                }
            }
            if (dropdownlist.options.length > 0 && optionIndex >= 0 && optionIndex < dropdownlist.options.length) {
                dropdownlist.options[optionIndex] = null;
                if (dropdownlist.options.length > optionIndex) dropdownlist.options[optionIndex].selected = true;
                else if (dropdownlist.options.length) dropdownlist.options[dropdownlist.options.length - 1].selected = true;
            }
        }
    },
    clearOptions: function(dropdownlist, fromIndex, toIndex) {
        dropdownlist = this.findField(dropdownlist);
        if (dropdownlist && typeof (dropdownlist) == "object") {
            if (!toIndex || toIndex <= 0) toIndex = dropdownlist.options.length - 1;
            if (!fromIndex || fromIndex < 0 || fromIndex > dropdownlist.options.length) fromIndex = 0;
            for (var i = fromIndex; i <= toIndex && i < dropdownlist.options.length; i++) {
                dropdownlist.options[i] = null;
            }
        }
    },
    getSelectedValues: function(dropdownlist, multiple) {
        dropdownlist = this.findField(dropdownlist);
        if (dropdownlist) {
            if (!multiple) return dropdownlist.options[dropdownlist.selectedIndex].value;
            var values = "";
            for (var i = 0; i < dropdownlist.options.length; i++) {
                if (dropdownlist.options[i].selected) {
                    if (values != "") values += ",";
                    values += dropdownlist.options[i].value.toString();
                }
            }
            return values;
        }
        return null;
    }
};
qtek_form.init(); //initialize qtek_form object


/***************************** Window Objects and Events **********************************/
var qtek_window = {
    popupwindow: null, popupdiv: null, reloadopener: false,

    init: function(popwin, popdiv) {
        this.popupwindow = (popwin ? popwin : "QTekPopupWin");
        this.popupdiv = qtek_dhtml.getElementById(popdiv ? popdiv : "DIV_Popup");
    },
    getOpener: function() {
        return (window.opener ? window.opener : (window.parent ? window.parent : window));
    },
    getOpenerUrl: function() {
        var opener = this.getOpener();
        return (opener ? opener.location.href : (arguments.length > 0 ? arguments[0] : ""));
    },
    reloadOpener: function() {
        if (this.reloadopener) {
            var winobj = this.getOpener();
            if (winobj != null && winobj != window) winobj.location.reload();
        }
    },
    reload: function() {
        if (this.reloadopener || (arguments.length > 0 && arguments[0] == true)) //the child window must set the variable qtek_window.reloadopener=true in order to force the opener window to reload
        {
            var winobj = this.getOpener();
            if (winobj != null && winobj != window) winobj.location.reload(); //= winobj.location.href;
        }
        else window.location.reload();
    },
    redirect: function(url) {
        if (arguments.length > 1 && arguments[1] == "opener") {
            var winobj = this.getOpener();
            if (winobj != null && winobj != window) winobj.document.location.href = url;
        }
        else window.document.location.href = url;
    },
    close: function() {
        window.close();
    },
    loadIframe: function(iframeName, url) {
        if (window.frames[iframeName] && window.frames[iframeName].location != url) {
            window.frames[iframeName].location = url;
            return false;
        }
        else return true;
    },

    popup: function(url, width, height, options) //options=window options
    {
        if (arguments.length > 4) {
            var control = this.getElementById(arguments[4]);
            if (control) {
                var valuelist = "";
                if (arguments[4].toLowerCase().indexOf("checker") >= 0) valuelist = qtek_form.getCheckedValues(eval("control.form." + arguments[4]), ",");
                if (valuelist.length > 0) {
                    if (url.indexOf("?") < 0) url += "?";
                    else if (url.substr(url.length - 1) != "?") url += "&";
                    url += "keys=" + valuelist;
                }
                else {
                    alert("Please select a value.");
                    return false;
                }
            }
            else {
                alert("Could not find field to generate id");
                return false;
            }
        }

        if (width <= 0) width = 720;
        if (height <= 0) height = 400;
        if (!options) options = "menubar=0,toolbar=0,location=0,status=0,resizable=0";
        var popup = window.open(url, this.popupwindow, options + ",width=" + width + ",height=" + height);
        popup.moveTo(window.screen.width / 2 - width / 2 - 25, window.screen.height / 2 - height / 2 - 25);

        return popup;
    },
    showContent: function(contentUrl, eventElement) {
        this.hideContent();
        if (!this.popupdiv) {
            alert("Missing popup container.");
            return false;
        }
        if (eventElement) qtek_dhtml.moveLayerTo(this.popupdiv, qtek_dhtml.getLayerRight(eventElement) - 5, qtek_dhtml.getLayerBottom(eventElement) - 5);
        this.popupdiv.innerHTML = "Loading";

        var ajax = new qtek_ajax(contentUrl, "GET");
        ajax.responseContainer = this.popupdiv;
        if (ajax.execute(null) == false) this.hideContent();
        else {
            if (qtek_dhtml.getLayerBottom(this.popupdiv) >= qtek_dhtml.windowHeight)
                qtek_dhtml.moveLayerToY(this.popupdiv, qtek_dhtml.windowHeight - qtek_dhtml.getElementHeight(this.popupdiv) - 2);
            if (qtek_dhtml.getLayerRight(this.popupdiv) >= qtek_dhtml.windowWidth)
                qtek_dhtml.moveLayerToX(this.popupdiv, qtek_dhtml.windowWidth - qtek_dhtml.getElementWidth(this.popupdiv) - 2);
        }
    },
    hideContent: function() {
        if (this.popupdiv) qtek_dhtml.hideLayer(this.popupdiv);
    },
    openUploader: function(scripturl, callbackscripts) {
        this.popup(scripturl, 400, 240);
    }
};
qtek_window.init(); //initialize qtek_window object

function isAjaxFinished() {
    return (ajaxQueue.getSize() == 0 && !isSending);
}


/*********** Begin D:\SVN\iSport.com\WorkingSourceCode_JIRA\Scripts\HtmlControlUtils.js *****************/
var fakeVirtualCmds = new Array('cmbHiddenWrap', 'cmbHiddenWrap_signup');

function handleEnterAndTab(e, funct) {
    e = e || window.event;
    var key = e.keyCode || e.which;
    switch (key) {
        case 13:
        case 9:
            var prevBodyKeypress = document.getElementsByTagName("body")[0].onkeypress;

            var bodyTag = document.getElementsByTagName("body")[0];
            bodyTag.onkeypress = disableEnterKey;

            funct();
            e.cancelBubble = true;
            e.returnValue = false;
            if (e.stopPropagation) {
                e.stopPropagation();
                e.preventDefault();
            }

            bodyTag.onkeypress = prevBodyKeypress;
            break;
    }
}
function setTimeoutAndRun(funct, time) {
    setTimeout("(" + funct + ")()", time);
}
function disableEnterKey(e) {
    var key;
    if (window.event)
        key = window.event.keyCode; //IE
    else
        key = e.which; //firefox     

    return (key != 13);
}


function handleEnterKey(e, funct) {
    e = e || window.event;
    var key = e.keyCode || e.which;
    if (key == 13) {
        setTimeoutAndRun(funct, 50);
        e.cancelBubble = true;
        e.returnValue = false;
    }
}
function getDocumentObject(id) {
    return document.getElementById(id);
}

function getCBSelectedValue(comboboxId) {
    var combobox = getDocumentObject(comboboxId);
    return combobox[combobox.selectedIndex].value;
}

function getCBSelectedText(comboboxId) {
    var combobox = getDocumentObject(comboboxId);
    return combobox[combobox.selectedIndex].text;
}

function getCheckboxStatus(checkboxId) {
    var checkbox = getDocumentObject(checkboxId);
    return checkbox.checked;
}

function getTextFieldText(txtId) {
    var txt = getDocumentObject(txtId);
    return txt.value;
}

function getLayerStatus(layerId) {
    var layer = getDocumentObject(layerId);
    if (layer == null) {
        return false;
    }
    return (layer.style.display != 'none');
}

function hide(id) {
    var obj = getDocumentObject(id);
    if (obj != null)
        obj.style.display = "none";
}
function show(id) {
    var obj = getDocumentObject(id);
    var frame = getDocumentObject('divStep3Answer4_frame');
    if (obj != null) {
        obj.style.display = "";
        if (frame != null)
            showframe(id, 'divStep3Answer4_frame')

    }

}


function addTagWithIdParent(parentId, tagName) {
    return addTagToParent(getDocumentObject(parentId), tagName);
}
function addTagToParent(parent, tagName) {
    var newEle = newTag(tagName);
    parent.appendChild(newEle);
    return newEle;
}
function addTextNodeToParent(parent, text) {
    var textNode = newTextNode(text);
    parent.appendChild(textNode);
    return textNode;
}

function setSelectedValue(comboId, selectValue) {
    var combo = getDocumentObject(comboId);

    if (combo == null) {
        return;
    }

    for (var i = 0; i < combo.length; i++) {
        var option = combo.options[i];
        if (option.value == selectValue) {
            combo.selectedIndex = i;
            break;
        }
    }
}

function getFirstChild(node) {
    if (!node) return null;
    if (node.childNodes.length <= 0) {
        return null;
    }
    var firstChild = node.childNodes[0];
    if (firstChild.nodeName == "#text") {
        firstChild = node.childNodes[1];
    }
    return firstChild;
}

function getLastChild(node) {
    var lastChild = node.childNodes[node.childNodes.length - 1];
    if (lastChild.nodeName == "#text") {
        lastChild = node.childNodes[node.childNodes.length - 2];
    }
    return lastChild;
}

function insertTagBefore(parent, nextNode, tagName) {
    var newNode = newTag(tagName);
    parent.insertBefore(newNode, nextNode);
    return newNode;
}

function insertTagAfter(parent, afterNode, tagName) {
    var newNode = newTag(tagName);
    if ((afterNode.nextSibling != undefined) && (afterNode.nextSibling != null)) {
        parent.insertBefore(newNode, afterNode.nextSibling);
    }
    else {
        parent.appendChild(newNode);
    }
    return newNode;
}
function removeTag(tag) {
    tag.parentNode.removeChild(tag);
}
function removeAllChild(node) {
    if (node.hasChildNodes()) {
        while (node.childNodes.length >= 1) {
            node.removeChild(node.firstChild);
        }
    }
}
function newTag(tagName) {
    return document.createElement(tagName);
}
function newTextNode(text) {
    return document.createTextNode(text);
}

function getEventTagetTag(e) {
    var targ;
    if (!e) {
        var e = window.event;
    }
    if (e.target) {
        targ = e.target;
    }
    else if (e.srcElement) {
        targ = e.srcElement;
    }

    return targ;
}

function isEffectByEvent(e, tagID) {
    var oEffectedRoot = getEventTagetTag(e);
    if (oEffectedRoot.id == tagID) {
        return true;
    }
    while (oEffectedRoot.parentNode != null) {
        if (oEffectedRoot.parentNode.id == tagID) {
            return true;
        }
        oEffectedRoot = oEffectedRoot.parentNode;
    }

    return false;
}

function isObjEffectByEvent(e, obj) {
    var oEffectedRoot = getEventTagetTag(e);
    if (oEffectedRoot == obj) {
        return true;
    }
    while (oEffectedRoot.parentNode != null) {
        if (oEffectedRoot.parentNode == obj) {
            return true;
        }
        oEffectedRoot = oEffectedRoot.parentNode;
    }

    return false;
}

function addOptions(sSelectID, iFrom, iTo, sSelected) {
    for (var i = iFrom; (iFrom < iTo) ? (i <= iTo) : (i >= iTo); ) {
        var newOption = document.createElement('OPTION');
        newOption.value = i + '';
        newOption.text = i + '';
        if (i + '' == sSelected) {
            newOption.selected = true;
        }
        getDocumentObject(sSelectID).options.add(newOption);
        if (iFrom < iTo) {
            i++;
        }
        else {
            i--;
        }
    }
}

function optionItem(sValue, sText, bSelected) {
    this.selected = bSelected;
    this.value = sValue;
    this.text = sText;
}

function addOptionItems(arrItems, sSelectID) {
    for (var i = 0; i < arrItems.length; i++) {
        var item = arrItems[i];
        var newOption = document.createElement('OPTION');
        newOption.value = item.value;
        newOption.text = item.text;
        newOption.selected = item.selected;

        getDocumentObject(sSelectID).options.add(newOption);
    }
}

function stringReplace(sOrigin, sReplace, sReplaced) {
    var sTarget = sOrigin;
    while (sTarget.indexOf(sReplace) >= 0) {
        sTarget = sTarget.replace(sReplace, sReplaced);
    }
    return sTarget;
}

function isDisplay(tag) {
    var travelTag = tag;
    while (travelTag.parentNode.tagName.toUpperCase() != 'BODY') {
        if ((travelTag.style != undefined) && (travelTag.style != null) && (travelTag.style.display == 'none')) {
            return false;
        }
        travelTag = travelTag.parentNode;
    }

    return true;
}

function isSelectContain(select, sValue) {
    for (var i = 0; i < select.options.length; i++) {
        if (select.options[i].value == sValue) {
            return true;
        }
    }

    return false;
}

function selectAOptions(sOptionsListName, sValue) {
    var optionsList = document.getElementsByName(sOptionsListName);
    for (var i = 0; i < optionsList.length; i++) {
        if (sValue == optionsList[i].value) {
            optionsList[i].checked = true;
            continue;
        }
    }
}
function removeHTMLTags(text) {
    var strInputCode = text;
    /*
    This line is optional, it replaces escaped brackets with real ones,
    i.e. < is replaced with < and > is replaced with >
    */
    strInputCode = strInputCode.replace(/&(lt|gt);/g, function(strMatch, p1) {
        return (p1 == "lt") ? "<" : ">";
    });

    var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
    //alert(”Output text:\n” + strTagStrippedText);
    // Use the alert below if you want to show the input and the output text
    // alert(”Input code:\n” + strInputCode + “\n\nOutput text:\n” + strTagStrippedText);

    return strTagStrippedText;
}

function ResetLayerHeight(sLayerID) {
    getDocumentObject(sLayerID).style.height = "";
    getDocumentObject(sLayerID).style.height = qtek_dhtml.getElementHeight(sLayerID) + "px";
}


function addListener(element, type, expression, bubbling) {
    bubbling = bubbling || false;
    if (element.addEventListener) { // Standard
        element.addEventListener(type, expression, bubbling);
        return true;
    } else if (element.attachEvent) { // IE
        element.attachEvent('on' + type, expression);
        return true;
    } else return false;

}
function getPreviousNode(el) {
    function isIgnorable(node) {
        // is a comment or contains only whitespace
        return (node.nodeType == 8 || /^[\t\n\r ]+$/.test(node.data));
    }

    var prev = el;
    while (prev = prev.previousSibling) {
        if (!isIgnorable(prev)) break;
    }

    return prev;
}

var collection = {
    namedValueItem: function(sName, sValue) {
        this.name = sName;
        this.value = sValue;
    }
}
var htmlHelper = {
    isParent: function(tag, tagParent) {
        var travelTag = tag.parentNode;
        if (travelTag == null) {
            return false;
        }
        while (travelTag.tagName.toUpperCase() != 'BODY') {
            if (travelTag == tagParent) {
                return true;
            }
            travelTag = travelTag.parentNode;
        }
        return false;
    }
}
var urlHelper = {
    getQueryOrigin: function() {
        return window.location.search.substring(1);
    },
    getAllQueryPairs: function(sQuerys) {
        var pairs = new Array();
        if (sQuerys == null || sQuerys == "") {
            return pairs;
        }
        hu = sQuerys;
        gy = hu.split("&");

        for (i = 0; i < gy.length; i++) {
            ft = gy[i].split("=");
            pairs[pairs.length] = new collection.namedValueItem(ft[0], ft[1]);
        }
        return pairs;
    },
    getCurrentQueryString: function(name) {
        var pairs = urlHelper.getAllQueryPairs(urlHelper.getQueryOrigin());
        for (var i = 0; i < pairs.length; i++) {
            if (pairs[i].name.toLowerCase() == name) {
                return pairs[i].value;
            }
        }
        return "";
    },
    setQueryString: function(queryOrigin, name, value) {
        var newQuery = "";
        var hasSetQuery = false;

        var pairs = urlHelper.getAllQueryPairs(queryOrigin);

        for (i = 0; i < pairs.length; i++) {
            newQuery += ((newQuery == "") ? "" : "&") + pairs[i].name;
            if (pairs[i].name == name) {
                newQuery += "=" + escape(value);
                hasSetQuery = true;
            }
            else {
                newQuery += "=" + pairs[i].value;
            }
        }
        if (!hasSetQuery) {
            newQuery += ((newQuery == "") ? "" : "&") + name;
            newQuery += "=" + escape(value);
        }
        return newQuery;
    }
}

function getWindowHeight() {
    var windowHeight = 0;
    if (typeof (window.innerHeight) == 'number') {
        windowHeight = window.innerHeight;
    }
    else {
        if (document.documentElement && document.documentElement.clientHeight) {
            windowHeight = document.documentElement.clientHeight;
        }
        else {
            if (document.body && document.body.clientHeight) {
                windowHeight = document.body.clientHeight;
            }
        }
    }
    return windowHeight;
}
function f_scrollTop() {
    return f_filterResults(
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function setCenterTag(tagId) {
    var $ = jQuery;
    $("#divAjaxWaiting").hide();
    SearchRs.ShowCenterMessage($('#' + tagId).parent().html());
    //	if ($("#divAjaxWaiting"))
    //        $("#divAjaxWaiting").css('height',$('body').attr('offsetHeight') + 'px');
}

/*********** Begin D:\SVN\iSport.com\WorkingSourceCode_JIRA\Scripts\swim.menu2.js *****************/
/*************************************************************************************************
* This library is based on the ideas of Dolphin Tabs Menu by JavaScript Kit (www.javascriptkit.com)
* Visit JavaScript Kit at http://www.javascriptkit.com/ for the original script and 100s more
**************************************************************************************************/


var mess_addCmt_detail = "Your comment was added successfully on this listing.";

var position_mess_swim_menu = 'divBigTitle*700*+70';

var qtek_menu2 = {
    showCurrent: true, tabs: [], popupmenus: [], menuPrefix: null, menuPopupPrefix: null, currentMenu: null, startPopup: null, currentPopup: null, menuContext: null,
    initialized: null,

    init: function(menuObject, selectMenu) {

        if (qtek_menu2.initialized) return;
        qtek_menu2.menuPrefix = "Menu_";
        qtek_menu2.menuPopupPrefix = "MenuPopup_";
        if (qtek_menu2.tabs.length == 0 && qtek_menu2.popupmenus.length == 0) {
            menuObject = qtek_dhtml.getElementById(menuObject);
            if (menuObject) {
                var tabItems = menuObject.getElementsByTagName("li");
                for (var i = 0; i < tabItems.length; i++) {
                    if (tabItems[i].getAttribute("id").substring(0, qtek_menu2.menuPrefix.length) == qtek_menu2.menuPrefix) {
                        qtek_menu2.tabs[qtek_menu2.tabs.length] = tabItems[i]; //store the tab menu (full <li>)
                        var popupList = tabItems[i].getElementsByTagName("ul");
                        if (!popupList || popupList.length == 0) qtek_menu2.popupmenus[qtek_menu2.popupmenus.length] = null;
                        else qtek_menu2.popupmenus[qtek_menu2.popupmenus.length] = popupList[0]; //should only have one <ul>
                    }
                } //END FOR LOOP

                qtek_menu2.initialized = true;
                if (qtek_menu2.showCurrent) {
                    qtek_menu2.setCurrentMenu(selectMenu);
                }
            }
            //else alert("Failed to initialize qtek_menu2 because the menu container " + menuObject + " does not exists.");
        }
    },
    setCurrentMenu: function(menuId) {
        if (menuId.substring(0, qtek_menu2.menuPrefix.length) != qtek_menu2.menuPrefix) menuId = qtek_menu2.menuPrefix + menuId;
        if (qtek_menu2.currentMenu != null && qtek_menu2.currentMenu.getAttribute("id") != menuId) qtek_menu2.currentMenu.getElementsByTagName("a")[0].className = "";

        var menuMore = -1;
        for (var i = 0; i < qtek_menu2.tabs.length; i++) {
            if (qtek_menu2.tabs[i].getAttribute("id") == menuId) {
                qtek_menu2.currentMenu = qtek_menu2.tabs[i];
                qtek_menu2.currentMenu.getElementsByTagName("a")[0].className = "current";
                menuMore = -1;
                break;
            }
            else if (qtek_menu2.tabs[i].getAttribute("id") == qtek_menu2.menuPrefix + "More") menuMore = i;
        } //END FOR LOOP

        if (menuMore >= 0 && qtek_menu2.popupmenus[menuMore]) //search in more list
        {
            var moremenus = qtek_menu2.popupmenus[menuMore].getElementsByTagName("li");
            if (moremenus && moremenus.length > 0) {
                for (var i = 0; i < moremenus.length; i++) {
                    var menu_id = qtek_menu2.menuPopupPrefix + "More_" + menuId.substring(qtek_menu2.menuPrefix.length);
                    if (moremenus[i].getAttribute("id") == menu_id) {
                        qtek_menu2.currentMenu = qtek_dhtml.getElementById("Menu_MoreItem");
                        qtek_menu2.currentMenu.getElementsByTagName("a")[0].href = moremenus[i].getElementsByTagName("a")[0].href;
                        qtek_menu2.currentMenu.getElementsByTagName("span")[0].innerHTML = moremenus[i].getElementsByTagName("a")[0].innerHTML;
                        qtek_menu2.currentMenu.getElementsByTagName("a")[0].className = "current";
                        qtek_dhtml.showLayer(qtek_menu2.currentMenu);
                        qtek_dhtml.hideLayer(moremenus[i]);

                        //                        var prevMore = getPreviousNode( qtek_menu2.currentMenu );
                        //                        qtek_dhtml.hideLayer(prevMore);
                        //                        var placePrevMoreTo = qtek_dhtml.getElementById("li_FromMainLand");
                        //                        placePrevMoreTo.getElementsByTagName("a")[0].href = prevMore.getElementsByTagName("a")[0].href;
                        //	                    placePrevMoreTo.getElementsByTagName("a")[0].innerHTML = prevMore.getElementsByTagName("span")[0].innerHTML ;
                        //                        qtek_dhtml.showLayer(placePrevMoreTo);

                        break;
                    }
                } //END FOR LOOP
            }
        }
    },
    showPopup: function(popupMenu, fromMenu) {
        qtek_menu2.menuContext = qtek_dhtml.getElementById(fromMenu);
        qtek_menu2.currentPopup = qtek_dhtml.getElementById(popupMenu);
        if (qtek_menu2.menuContext != null) {
            if (qtek_menu2.currentMenu != null)
                qtek_menu2.currentMenu.getElementsByTagName("a")[0].className = "current";

            qtek_menu2.menuContext.getElementsByTagName("a")[0].className = "current";
            if (qtek_menu2.currentPopup != null && qtek_dhtml.isMinIE6 && !qtek_dhtml.isMinIE7) //IE6 show up implementation
            {
                var popupPosition = qtek_dhtml.getLayerTopLeft(qtek_menu2.menuContext);
                var leftPos = popupPosition[0];
                var topPos = popupPosition[1] + 29;
                qtek_dhtml.moveLayerTo(qtek_menu2.currentPopup, leftPos, topPos);
                qtek_dhtml.showLayer(qtek_menu2.currentPopup);
            }
            qtek_menu2.startPopup = true;
        }
    }, //END showPopup function
    hidePopup: function() {
        if (qtek_menu2.menuContext != null) qtek_menu2.menuContext.getElementsByTagName("a")[0].className = "";
        if (qtek_menu2.currentMenu != null) qtek_menu2.currentMenu.getElementsByTagName("a")[0].className = "current";
        if (qtek_menu2.currentPopup != null && qtek_dhtml.isMinIE6 && !qtek_dhtml.isMinIE7) //IE6 implementation
        {
            var popup = qtek_menu2.currentPopup;
            var PopupTop = qtek_dhtml.getLayerTop(popup);
            var PopupLeft = qtek_dhtml.getLayerLeft(popup);
            var PopupRight = qtek_dhtml.getLayerRight(popup);
            var PopupBottom = qtek_dhtml.getLayerBottom(popup);
            if (qtek_dhtml.isInArea(PopupTop, PopupLeft, PopupRight, PopupBottom, qtek_dhtml.mouseX, qtek_dhtml.mouseY) == false) {
                if (arguments.length > 0) menu = qtek_dhtml.getElementById(arguments[0]); //why? no used
                if (popup != null) qtek_dhtml.hideLayer(popup);
            }
        }
        qtek_menu2.startPopup = false;
    } //END hidePopup function
};

function setCookie(c_name, value, expiredays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name + "=" + escape(value) +
    ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString());
}

function getCookie(c_name) {
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return "";
}

var qtek_searchPanel = {
    searchContent: null, formName: null, options: [], container: null, contentUrl: null, initialized: null, loadedContent: "loadedContent",

    init: function(formname, container, content_url) {
        if (qtek_searchPanel.initialized) return;
        qtek_searchPanel.formName = formname;
        qtek_searchPanel.contentUrl = content_url;
        qtek_searchPanel.container = qtek_dhtml.getElementById(container);
        if (qtek_searchPanel.formName && qtek_searchPanel.container) qtek_searchPanel.initialized = true;
    }, //END init function
    getContentUrl: function(menuId) {
        return qtek_searchPanel.contentUrl + "&content=" + menuId + "&r=" + Math.random(); //r=randowm is used to prevent browser cached content
    }, //END getContentUrl function	
    getPanel: function(menuId) {
        var form = qtek_form.findForm(qtek_searchPanel.formName);
        if (form) {
            for (var i = 0; i < form.length; i++) {
                qtek_searchPanel.addSearchOption(form[i]);
            }
        }
        if (menuId && typeof (menuId) == "object") menuId = qtek_form.getSelectedValues(menuId, false);
        qtek_searchPanel.searchContent = menuId;

        // don't need reload search panel
        //	    var contentInCookie = getCookie( qtek_searchPanel.loadedContent);
        //	    if( contentInCookie != "" ){
        //	        qtek_searchPanel.container.innerHTML = contentInCookie;
        //	        qtek_searchPanel.fillForm();
        //	        return;
        //	    }

        var ajaxObject = new qtek_ajax(qtek_searchPanel.getContentUrl(menuId), "GET");
        ajaxObject.responseContainer = qtek_searchPanel.container;
        ajaxObject.onComplete = qtek_searchPanel.fillForm;
        ajaxObject.execute(null);
    }, //END getPanel function
    fillForm: function() {

        //	    alert( 'ajax content ' + qtek_searchPanel.container.innerHTML );
        //	    setCookie( qtek_searchPanel.loadedContent, 'content in cookie', -1 );	   

        var form = qtek_form.findForm(qtek_searchPanel.formName);
        searchSelect1();
        //searchSelect2();
        //searchSwimLesson();

        if (!form || qtek_searchPanel.options.length == 0) return;
        for (var i = 0; i < form.length; i++) {
            if (form[i].name != "SearchContent") {
                for (var j = 0; j < qtek_searchPanel.options.length; j++) {
                    option = qtek_searchPanel.options[j];
                    if (form[i].name == option.name) {
                        if (option.type == "checkbox" || option.type == "radiobox") qtek_form.checkOnValue(form[i], option.value);
                        else if (option.type.substring(0, 6) == "select") qtek_form.selectOptions(form[i], option.value);
                        else form[i].value = option.value;
                        break;
                    }
                }
            }
            else qtek_form.selectOptions(form[i], qtek_searchPanel.searchContent);
        }
        qtek_form.focus("SearchText");
    },  //END fillForm function
    addSearchOption: function(formcontrol) {
        if (!formcontrol || formcontrol.name == "SearchContent") return null;
        var option = new qtek_searchOption(formcontrol.type, formcontrol.name, formcontrol.value);
        var foundIndex = qtek_searchPanel.options.length;

        for (var i = 0; i < qtek_searchPanel.options.length; i++) {
            if (qtek_searchPanel.options[i].name == formcontrol.name) {
                option = qtek_searchPanel.options[i];
                foundIndex = i;
                break;
            }
        }
        if (formcontrol.type == "checkbox" || formcontrol.type == "radiobox") //must implement qtek_form for radiobox
        {
            option.value = qtek_form.getCheckedValues(formcontrol, null);
        }
        else if (formcontrol.type.substring(0, 6) == "select") option.value = qtek_form.getSelectedValues(formcontrol, true);
        else option.value = formcontrol.value;
        qtek_searchPanel.options[foundIndex] = option; //set or update the option	    
    }, //END addSearchOption function
    doSearch: function(action_url) {
        alert("Not Yet Implement: " + action_url);
    }
};
function qtek_searchOption(type, name, value) {
    this.type = type;
    this.name = name;
    this.value = value;
}

var qtek_helper = {
    url_SignUp: null,
    showCountryList: function(url, container, storage, code) {
        //alert(container);

        if (getDocumentObject(container).style.display != "none") {
            if (storage == "IMG_Country") {
                Slide(container, { duration: 1, onComplete: function() { } }).up();
            }
            else {
                Slide(container, { duration: 1, onComplete: function() { } }).down2();
            }

            return false;
        }

        if (getDocumentObject('CountryList') != null && storage == "IMG_Country") {
            Slide(container, { duration: 1, onComplete: function() { getDocumentObject('CountryList').focus(); } }).down();
            return false;
        }
        else if (getDocumentObject('CountryList2') != null && storage == "IMG_Country2") {
            Slide(container, { duration: 1, onComplete: function() { getDocumentObject('CountryList2').focus(); } }).up2();
            return false;
        }

        container = qtek_dhtml.getElementById(container);
        container.innerHTML = "";
        if (!container) { return false; }

        storage = qtek_dhtml.getElementById(storage);
        if (!storage) { return false; }
        //var code = storage.alt;
        if (!storage.src) code = storage.innerHTML;

        //Phong code for redirect jobs
        var isSearch = "";
        if (getDocumentObject("hid_IsSearch") != null)
            isSearch = "1";
        var ajax = new qtek_ajax(url + "?country=" + code + "&container=" + container.id + (isSearch != "" ? "&isSearch=true" : "") + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            if (!storage) return;
            //var width = 250;
            //var height = 258;

            //HEADER
            if (storage.id == "IMG_Country") {
                var width = 204;
                var height = 290;
                var left = qtek_dhtml.getLayerLeft(storage);
                var bottom = qtek_dhtml.getLayerBottom(storage);
                var mgLeft = 96;
                var mgTop = 26;
                var docwidth = qtek_dhtml.getDocumentWidth(window.document);
                if (left > (docwidth / 2)) left = qtek_dhtml.getLayerRight(storage);
                left -= (width + 2);

                qtek_dhtml.setLayerSize(container, width, height);
                //qtek_dhtml.moveLayerTo(container, left, top);

                //-----------------------------------------------------------
                // Set Margin for country div - Add by Nhung Pham_28/04/08
                //  - Fix float when resize browser
                //  - Fix Margin
                //-----------------------------------------------------------

                if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x; vunguyen
                    //if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ 
                    var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
                    if (ieversion >= 5) {
                        //qtek_dhtml.setLayerMargin(container, mgLeft - 78, mgTop);
                        //qtek_dhtml.setLayerMargin(container, mgLeft - 45, mgTop);
                    }
                }
                else {
                    // qtek_dhtml.setLayerMargin(container, mgLeft+660, mgTop);

                }
                //-------------------------------------------------------------
                // qtek_dhtml.showLayer(container);	        
            }
            else {
                //FOOTER
                var mgLeft = -200;
                var mgTop = -290;

                if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
                    //if (/Opera[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ 
                    var ieversion = new Number(RegExp.$1) // capture x.x portion and store as a number
                    if (ieversion >= 5) {
                        mgLeft = container.style.marginLeft.replace('px', '');
                        qtek_dhtml.setLayerMargin(container, mgLeft, mgTop);

                    }
                }
                //                else{
                //                    qtek_dhtml.setLayerMargin(container, mgLeft+660, mgTop);
                //                    
                //                }
            }
        };
        ajax.execute(null);
    }, updateCountry: function(countrycode, cookie, countryname) {
        var img = qtek_dhtml.getElementById("IMG_Country");
        countryname = qtek_helper.upperFirstChar(countryname);

        if (img != null) {
            qtek_dhtml.setImage(img, qtek_dhtml.rootUrl + 'Images/Icon/' + countrycode + '_Flag.gif');
            img.title = countryname;
        }

        var img2 = qtek_dhtml.getElementById("IMG_Country2");
        if (img2 != null) {
            qtek_dhtml.setImage(img2, qtek_dhtml.rootUrl + 'Images/Icon/' + countrycode + '_Flag.gif');
            img2.title = countryname;
        }

        qtek_dhtml.deleteCookie(cookie);
        qtek_dhtml.createCookie(cookie, countrycode, 30);
        if (document.getElementById('cmbHidden') != null) {
            document.getElementById('cmbHidden').value = countrycode;
            document.getElementById('cmbHidden').onclick();
        }
        else {
            var invId = setInterval(function() {
                if (document.getElementById('cmbHidden') != null) {
                    document.getElementById('cmbHidden').value = countrycode;
                    document.getElementById('cmbHidden').onclick();
                    clearInterval(invId);
                }
            }, 300);
        }

        //alert(window.location); 
        //        if (document.getElementById('sSearch2') != null && document.getElementById('sSearch2').style.display != "none"
        //           && document.getElementById('div_for_country') != null && document.getElementById('div_for_country').style.display != "none") {
        //            if (window.location.toString().indexOf('r.aspx') > -1) {
        //                Search();
        //            }
        //            //            else if(document.getElementById('sSearch2') != null )
        //            //            {
        //            //                window.location.reload();
        //            //            }
        //        }
    }
    , upperFirstChar: function(val) {
        val = val.toLowerCase();

        newVal = '';
        val = val.split(' ');
        for (var c = 0; c < val.length; c++) {
            newVal += val[c].substring(0, 1).toUpperCase() + val[c].substring(1, val[c].length) + ' ';
        }
        return newVal;
    }


    ,
    getSearchPanel: function(menuId, method, responseContainer) {
        var url = 'SearchPanel_Ajax.aspx?menuId=' + menuId;
        // prevent cache on browser
        url += '&rand=' + Math.random();
        var ajaxObject = new qtek_ajax(url, method);
        if (responseContainer && responseContainer != '') {
            ajaxObject.responseContainer = responseContainer;
        }
        ajaxObject.execute(null);
        ajaxObject.onComplete = function() {
            // show responseText
        };
    },

    getEmailTemplate: function(responseContainer, i_EmailTemplateId) {
        if (i_EmailTemplateId == -1) {
            document.getElementById(responseContainer).value = "";
            return;
        }
        if (i_EmailTemplateId == -2) {
            document.getElementById(responseContainer).value = "Type your custom message here.";
            return;
        }
        var url = 'GetEmailTemplate.aspx?i_Id=' + i_EmailTemplateId;
        // prevent cache on browser
        url += '&rand=' + Math.random();
        var ajaxObject = new qtek_ajax(url, 'GET');
        if (responseContainer && responseContainer != '') {
            ajaxObject.responseContainer = responseContainer;
        }
        ajaxObject.execute(null);
        ajaxObject.onComplete = function() {
        };
    },

    updateViewCount: function(articleId) {
        var url = 'UpdateViewCount.aspx?l_Id=' + articleId;
        // prevent cache on browser
        url += '&rand=' + Math.random();

        var ajaxObject = new qtek_ajax(url, 'GET');
        ajaxObject.execute(null);
        ajaxObject.onComplete = function() {
        };
        return true;
    },

    updateNewsView: function(url) {
        // prevent cache on browser
        url += '&rand=' + Math.random();
        var ajaxObject = new qtek_ajax(url, 'GET');
        ajaxObject.execute(null);
        ajaxObject.onComplete = function() {
        };
        return true;
    },

    OpenOutlook: function(url, container) {
        container = qtek_dhtml.getElementById(container);
        // prevent cache on browser
        url += '&rand=' + Math.random();
        var ajaxObject = new qtek_ajax(url, 'GET');
        if (container && container != '') {
            ajaxObject.responseContainer = container;
        }
        ajaxObject.execute(null);
        ajaxObject.onComplete = function() {
            //window.open("mailto:"+container.innerHTML);
            location = "mailto:" + container.innerHTML;
        };
    },

    getLocationControl: function(responseContainer, url) {
        var imgsrc = "<img src='../images/icon/loading.gif'/>";
        if (url.indexOf("countryId") > 0) {
            document.getElementById("div_State").innerHTML = "";
            document.getElementById("div_State").innerHTML = imgsrc;
            document.getElementById("div_City").innerHTML = "";
        } else if (url.indexOf("stateId") > 0) {
            document.getElementById("div_City").innerHTML = "";
            document.getElementById("div_City").innerHTML = imgsrc;
        }
        // prevent cache on browser
        url += '&rand=' + Math.random();
        var ajaxObject = new qtek_ajax(url, 'GET');
        if (responseContainer && responseContainer != '') {
            ajaxObject.responseContainer = responseContainer;
        }
        ajaxObject.execute(null);
        ajaxObject.onComplete = function() {
            //alert(ajaxObject.responseText); 
        };
    },


    showCommentList: function(url, container, pageIndex, loadFirst) {
        var img = document.getElementById('imgLoad');
        if (img != null && loadFirst != 0) {
            img.style.display = '';
        }

        container = qtek_dhtml.getElementById(container);
        var backupContainerContent = container.innerHTML;
        if (!container) return false;
        //container.innerHTML = "<img src='../../../../../../images/loader.gif' />";
        var ajax = new qtek_ajax(url + "&pageIndex=" + pageIndex + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            if (container.innerHTML == 'SPAM') {
                container.innerHTML = backupContainerContent;
                showErrorMsg('txtCaptcha', 'The comment contains spam.<br />Please try again.');
            }



            qtek_dhtml.showLayer(container);

            if (loadFirst != 0) {
                if (img != null) {
                    img.style.display = 'none';
                }

                //alert('vv');
                FadeMessage('c_comment_y_listingdetail', 'pass', position_mess_swim_menu);
            }
        };
        ajax.execute(null);
    },

    viewProfile: function(url, container, link) {
        container = qtek_dhtml.getElementById(container);
        if (!container) return false;
        container.innerHTML = "<img src='../../images/loader.gif' />";
        link = qtek_dhtml.getElementById(link);
        var ajax = new qtek_ajax(url + "&container=" + container.id + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            if (!link) return;
            var width = 300;
            var height = 150;
            var left = qtek_dhtml.getLayerLeft(link);
            var top = qtek_dhtml.getLayerTop(link);
            var docwidth = qtek_dhtml.getDocumentWidth(window.document);
            if (left > (docwidth / 2)) left = qtek_dhtml.getLayerRight(link);
            left -= (width + 2);
            qtek_dhtml.setLayerSize(container, width, height);
            if (link.id.indexOf('divImage') > -1) {
                qtek_dhtml.moveLayerTo(container, left - 80, top);
            } else {
                if (link.id.indexOf('divReviewDetail') > -1) {
                    qtek_dhtml.moveLayerTo(container, left + width + 90, top);
                } else {
                    qtek_dhtml.moveLayerTo(container, left - width + 30, top);
                }
            }
            qtek_dhtml.showLayer(container);

        };
        ajax.execute(null);
    },
    viewInstructor: function(url, container, link) {
        container = qtek_dhtml.getElementById(container);
        if (!container) return false;
        container.innerHTML = "<img src='../../images/loader.gif' />";
        link = qtek_dhtml.getElementById(link);
        var ajax = new qtek_ajax(url + "&container=" + container.id + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            if (!link) return;
            var width = 300;
            var height = 150;
            var left = qtek_dhtml.getLayerLeft(link);
            var top = qtek_dhtml.getLayerTop(link);
            var docwidth = qtek_dhtml.getDocumentWidth(window.document);
            if (left > (docwidth / 2)) left = qtek_dhtml.getLayerRight(link);
            left -= (width + 2);
            qtek_dhtml.setLayerSize(container, width, height);
            if (link.id.indexOf('divPositionMainLession') > -1) {
                qtek_dhtml.moveLayerTo(container, left + width - 35, top);
            } else {
                qtek_dhtml.moveLayerTo(container, left - width + 30, top);
            }
            qtek_dhtml.showLayer(container);

        };
        ajax.execute(null);
    },
    viewVisitorProfile: function(url, container, link) {
        container = qtek_dhtml.getElementById(container);
        if (!container) return false;
        container.innerHTML = "<img src='../../images/loader.gif' />";
        link = qtek_dhtml.getElementById(link);
        var ajax = new qtek_ajax(url + "&container=" + container.id + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            if (!link) return;
            var width = 300;
            var height = 150;
            var left = qtek_dhtml.getLayerLeft(link);
            var top = qtek_dhtml.getLayerTop(link);
            var docwidth = qtek_dhtml.getDocumentWidth(window.document);
            if (left > (docwidth / 2)) left = qtek_dhtml.getLayerRight(link);
            left -= (width + 2);
            qtek_dhtml.setLayerSize(container, width, height);
            if (link.id.indexOf('divPositionProfile') > -1) {
                qtek_dhtml.moveLayerTo(container, left + width - 35, top);
            } else {
                qtek_dhtml.moveLayerTo(container, left - width + 30, top);
            }
            qtek_dhtml.showLayer(container);

        };
        ajax.execute(null);
    },

    showRelationshipList: function(url, container, mode) {
        container = qtek_dhtml.getElementById(container);
        if (!container) return false;
        container.style.display = 'none';

        //container.innerHTML = "<img src='../../../../../images/loader.gif' />";
        var ajax = new qtek_ajax(url + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {

            // process not login redirect to signup
            if (container.innerHTML == "FAIL") {
                location = qtek_helper.url_SignUp;
                return;
            }

            qtek_dhtml.showLayer(container);
            if (mode != "view") {
                var divFavoritesAndEmail = qtek_dhtml.getElementById('divFavoritesAndEmail');
                var left = qtek_dhtml.getLayerLeft(divFavoritesAndEmail);
                var top = qtek_dhtml.getLayerTop(divFavoritesAndEmail);

                var divMessage = qtek_dhtml.getElementById('divMessage');
                var messageContent = qtek_dhtml.getElementById('messageContent');
                if (mode == 'add')

                    FadeMessage('c_add_y_Relationship_addme', 'pass', position_mess_swim_menu);
                else {
                    hm('divRemoveRelationship');

                    FadeMessage('c_add_y_Relationship_removeme', 'pass', position_mess_swim_menu);
                }




            }
        };
        ajax.execute(null);
    },


    showAllRelationshipList: function(url, container, link, idx) {
        container = qtek_dhtml.getElementById(container);
        if (!container) return false;
        container.innerHTML = "<img src='../../images/loader.gif' />";
        link = qtek_dhtml.getElementById(link);
        var ajax = new qtek_ajax(url + "&container=" + container.id + "&idx=" + idx + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            sm('divAllRelationship', 650, 510);
            /*if (!link) return;
            var width = 650;
            var height = 510;	  
            var left = qtek_dhtml.getLayerLeft(link);
            var top = qtek_dhtml.getLayerTop(link);
            var docwidth = qtek_dhtml.getDocumentWidth(window.document);	        
            if (left > (docwidth / 2)) left = qtek_dhtml.getLayerRight(link);
            left -= (width + 2);
            qtek_dhtml.setLayerSize(container, width, height);		         	                   
            qtek_dhtml.moveLayerTo(container, left-width+370, top-200);	     	             	    
            qtek_dhtml.showLayer(container);*/
        };
        ajax.execute(null);
    },
    showIntructorPoolList: function(url, container) {
        container = qtek_dhtml.getElementById(container);
        if (!container) return false;
        container.innerHTML = "<img src='../../../../../images/loader.gif' />";
        var ajax = new qtek_ajax(url + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            qtek_dhtml.showLayer(container);
            //checkHeight();
        };
        ajax.execute(null);
    },
    showAllIntructorPoolList: function(url, container, link, idx) {
        container = qtek_dhtml.getElementById(container);
        if (!container) return false;
        container.innerHTML = "<img src='../../images/loader.gif' />";
        link = qtek_dhtml.getElementById(link);
        var ajax = new qtek_ajax(url + "&container=" + container.id + "&idx=" + idx + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            sm('divAllIntructorPool', 650, 510);
            /*if (!link) return;
            var width = 650;
            var height = 510;	  
            var left = qtek_dhtml.getLayerLeft(link);
            var top = qtek_dhtml.getLayerTop(link);
            var docwidth = qtek_dhtml.getDocumentWidth(window.document);	        
            if (left > (docwidth / 2)) left = qtek_dhtml.getLayerRight(link);
            left -= (width + 2);
            qtek_dhtml.setLayerSize(container, width, height);		         	                   
            qtek_dhtml.moveLayerTo(container, left-width+370, top-200);	     	             	    
            qtek_dhtml.showLayer(container);*/
        };
        ajax.execute(null);
    },
    checkDataInstructor: function(url, container, strform) {
        container = qtek_dhtml.getElementById(container);
        if (!container) return false;
        container.innerHTML = "<img src='../../images/loader.gif' />";
        var ajax = new qtek_ajax(url + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            if (container.innerHTML != "") {
                qtek_dhtml.showLayer(container);
                qtek_dhtml.getElementById("Statement").focus();
                DivInfoClick();
            }
            else {
                DivUploadClick();
            }
        };
        ajax.execute(null);
    },
    AddEmail: function(url, container, divText, divButton) {
        container = qtek_dhtml.getElementById(container);
        divText = qtek_dhtml.getElementById(divText);
        divButton = qtek_dhtml.getElementById(divButton);
        if (!container) return false;
        if (!divText) return false;
        if (!divButton) return false;
        qtek_dhtml.hideLayer(divText);
        qtek_dhtml.hideLayer(divButton);
        qtek_dhtml.showLayer(container);
        container.innerHTML = "<img src='images/loading-bar-long.gif' style=\"margin-left:-4px;\" />";

        var ajax = new qtek_ajax(url + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            if (container.innerHTML == "NO") {
                container.innerHTML = "Your request causes an error.<br />Please try again!";
                qtek_dhtml.showLayer(divText);
                qtek_dhtml.showLayer(divButton);
            }
            else {
                container.innerHTML = "Email Address Received. Thank you!";
            }
            qtek_dhtml.showLayer(container);
        };
        ajax.execute(null);
    },
    forgotpassword: function(url, divSendPass, divSendFail, divTitle, divLoad, email) {
        divSendPass = qtek_dhtml.getElementById(divSendPass);
        divSendFail = qtek_dhtml.getElementById(divSendFail);
        divTitle = qtek_dhtml.getElementById(divTitle);
        divLoad = qtek_dhtml.getElementById(divLoad);
        if (!divSendPass) return false;
        if (!divSendFail) return false;

        qtek_dhtml.showLayer(divLoad);
        //divSendPass.innerHTML = "<img src='../../images/loader.gif' />";
        //divSendFail.innerHTML = "<img src='../../images/loader.gif' />";

        var ajax = new qtek_ajax(url + "&r=" + Math.random(), "GET");
        ajax.responseContainer = divSendPass;
        ajax.onComplete = function() {

            if (!divTitle) return;
            var width = 506; // 545;// 405;
            var height = 89; // 83;	  
            var left = qtek_dhtml.getLayerLeft(divTitle);
            var top = qtek_dhtml.getLayerTop(divTitle);
            var docwidth = qtek_dhtml.getDocumentWidth(window.document);
            if (left > (docwidth / 2)) left = qtek_dhtml.getLayerRight(divTitle);
            left -= (width + 2);
            if (divSendPass.innerHTML == "0") {
                qtek_dhtml.hideLayer(divSendPass);
                qtek_dhtml.hideLayer(divLoad);

                //	            divSendFail.innerHTML = document.getElementById('divSendFail1').innerHTML;
                //	            qtek_dhtml.setLayerSize(divSendFail, width, height);		         	                   
                //	            qtek_dhtml.moveLayerTo(divSendFail, left+750, top-17);	
                //	            qtek_dhtml.showLayer(divSendFail);      
                //	            fade.init('divSendFail','99','1','40','1');

                FadeMessage('d_lost_pass_fail', 'fail', 'divTitle*750*-17');
            }
            else {
                qtek_dhtml.hideLayer(divSendFail);
                qtek_dhtml.hideLayer(divLoad);
                var email = divSendPass.innerHTML;

                //                divSendPass.innerHTML = document.getElementById('divSendPass1').innerHTML.replace('$email$', email);
                //	            qtek_dhtml.setLayerSize(divSendPass, width, height); 
                //	            qtek_dhtml.moveLayerTo(divSendPass, left+750, top-17);	     	         
                //	            qtek_dhtml.showLayer(divSendPass);          
                //	            fade.init('divSendPass','99','1','40','1');

                FadeDynamicContent('d_lost_pass_success', 'email', divSendPass.innerHTML, 'pass', 'divTitle*750*-17');
            }
        };
        ajax.execute(null);
    },
    addToFavorites: function(url, divAddFavorites, divSendFail, divFav, divLoad) {

        divAddFavorites = qtek_dhtml.getElementById(divAddFavorites);
        divSendFail = qtek_dhtml.getElementById(divSendFail);
        divFav = qtek_dhtml.getElementById(divFav);
        divLoad = qtek_dhtml.getElementById(divLoad);
        if (!divAddFavorites) return false;
        if (!divSendFail) return false;

        qtek_dhtml.showLayer(divLoad);

        var ajax = new qtek_ajax(url + "&r=" + Math.random(), "GET");
        ajax.responseContainer = divAddFavorites;
        ajax.onComplete = function() {
            // process not login redirect to signup
            if (divAddFavorites.innerHTML == "FAIL") {
                location = qtek_helper.url_SignUp;
                return;
            }

            if (!divFav) return;

            var result = divAddFavorites.innerHTML.substring(0, 1);
            qtek_dhtml.hideLayer(divLoad);

            if (result == "1")
                FadeDynamicContent2('c_add_y_favourite', 'dir', divAddFavorites.innerHTML.substring(1), 'pass', position_mess_swim_menu);
            else if (result == "0")
                FadeDynamicContent2('d_add_y_favourite_exists', 'dir', divAddFavorites.innerHTML.substring(1), 'fail', position_mess_swim_menu);
            else
                FadeMessage('c_fail_processdata', "fail", position_mess_swim_menu);


        };
        ajax.execute(null);
    },
    showInstructorDetail: function(url, container, link, IsAdd) {
        container = qtek_dhtml.getElementById(container);
        if (!container) return false;
        link = qtek_dhtml.getElementById(link);
        if (link.id.indexOf('divImageIntructor') > -1) {
            //container.innerHTML = "<img src='../../images/loader.gif' />";
            show("div_Loading");
        } else {
            container.innerHTML = "<img src='../images/loader.gif' />";
        }
        var ajax = new qtek_ajax(url + "&IdAdd=" + IsAdd + "&container=" + container.id + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            if (!link) return;
            var width = 400;
            var height = 295;
            var left = qtek_dhtml.getLayerLeft(link);
            var top = qtek_dhtml.getLayerTop(link);
            var docwidth = qtek_dhtml.getDocumentWidth(window.document);
            if (left > (docwidth / 2)) left = qtek_dhtml.getLayerRight(link);
            left -= (width + 2);
            qtek_dhtml.setLayerSize(container, width, height);
            if (link.id.indexOf('divImageIntructor') > -1) {
                hide("div_Loading");
                qtek_dhtml.moveLayerTo(container, left + width - 480, top - 130);
            } else {
                var screenwidth = screen.availWidth;
                screenwidth = screenwidth - 992;
                screenwidth = screenwidth / 2;
                var right = qtek_dhtml.getLayerRight(link);
                qtek_dhtml.moveLayerTo(container, right - screenwidth, top - 150);
            }
            qtek_dhtml.showLayer(container);
        };
        ajax.execute(null);
    },
    showInstructorDetailForMoodal: function(url, container, link, IsAdd) {
        qtek_dhtml.hideLayer(container);
        qtek_dhtml.showLayer('divAjaxWaitingForMoodal');

        container = qtek_dhtml.getElementById(container);
        //container.innerHTML = "";
        if (!container) return false;
        link = qtek_dhtml.getElementById(link);

        var ajax = new qtek_ajax(url + "&IdAdd=" + IsAdd + "&container=" + container.id + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            qtek_dhtml.hideLayer('divAjaxWaitingForMoodal');

            if (!link) return;
            var width = 400;
            var height = 295;
            qtek_dhtml.setLayerSize(container, width, height);

            var left = qtek_dhtml.getLayerLeft(link);
            var top = qtek_dhtml.getLayerTop(link) + 10;

            var docwidth = qtek_dhtml.getDocumentWidth(window.document);

            /*if (left > (docwidth / 2)) 
            {
            left = qtek_dhtml.getLayerRight(link);
            left -= (width);  
            left -= 355;   
            }
            else
            {
            left -= 355;
            }*/

            left = 130;
            top = 100;
            qtek_dhtml.moveLayerTo(container, left, top);
            qtek_dhtml.showLayer(container);
        };
        ajax.execute(null);
    },
    //*Begin VT
    showTotalReview: function(url, container) {
        container = qtek_dhtml.getElementById(container);
        if (!container) return false;
        var ajax = new qtek_ajax(url + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
        };
        ajax.execute(null);
    }
    ,
    showReviewList: function(action, url, container) {
        container = qtek_dhtml.getElementById(container);
        var loading = qtek_dhtml.getElementById('div_Loading');
        if (!container) return false;
        container.innerHTML = "<img src='../../../../../images/loader.gif' />";
        qtek_dhtml.showLayer(loading);
        var ajax = new qtek_ajax(url + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            document.getElementById('textareaReview').value = "";
            document.getElementById('rateNo').value = "0";
            qtek_dhtml.hideLayer(loading);
            qtek_dhtml.showLayer(container);
            if (action == 'add') {
                //var url1 = url.replace("action=add","action=loadTotalReview")
                //alert(url1);	        
                //qtek_helper.showTotalReview(url1, 'divTotalReview');       	                             
                var url1 = url.replace("action=add", "action=loadVote")
                qtek_helper.loadVoteReview(url1, 'divStarHead');

                //update enable the tab Review if any reviews were added
                document.getElementById('tabReview').src = '../../../../../Images/Btn/Btn_detailReviews.gif';
            }
        };
        ajax.execute(null);
    }
    ,

    showUserCommentList: function(action, url, container) {
        container = qtek_dhtml.getElementById(container);
        if (!container) return false;
        var backupContainerContent = container.innerHTML;
        container.innerHTML = "<img src='../../images/loader.gif' />";
        var ajax = new qtek_ajax(url + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            if (container.innerHTML == "SPAM") {
                container.innerHTML = backupContainerContent;
                showErrorMsg('', 'The comment contains spam.<br />Please try again.', 'DIV_BodyContent');
            }
            qtek_dhtml.showLayer(container);
        };
        ajax.execute(null);
    },
    LoadMSGList: function(url, container) {
        container = qtek_dhtml.getElementById(container);
        if (!container) return false;
        container.innerHTML = "<img src='../images/loader.gif' />";
        //qtek_dhtml.showLayer(loading);
        var ajax = new qtek_ajax(url + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            qtek_dhtml.showLayer(container);
        };
        ajax.execute(null);
    },
    LoadPreviewCard: function(url, type, container) {
        container = qtek_dhtml.getElementById(container);
        if (!container) return false;
        container.innerHTML = "<img src='../images/loader.gif' />";
        var ajax = new qtek_ajax(url + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            qtek_dhtml.showLayer(container);
            //ShowModalboxFadeout('LoadPreviewCard',830,470);
            //clearInterval(interval);
            //doReplacement(type);
        };
        ajax.execute("content");
    },
    LoadMSGSentList: function(url, container) {
        container = qtek_dhtml.getElementById(container);
        if (!container) return false;
        container.innerHTML = "<img src='../images/loader.gif' />";
        //qtek_dhtml.showLayer(loading);
        var ajax = new qtek_ajax(url + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            qtek_dhtml.showLayer(container);
        };
        ajax.execute(null);
    },
    CardList: function(url, container) {
        container = qtek_dhtml.getElementById(container);
        if (!container) return false;
        container.innerHTML = "<div><div style=\"text-align:center;width:736px\"><img src='../images/loader.gif' /></div></div>";
        //qtek_dhtml.showLayer(loading);
        var ajax = new qtek_ajax(url + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            qtek_dhtml.showLayer(container);
        };
        ajax.execute(null);
    },



    //Hung add
    showMSGSent2: function(url, container, link) {

        container = qtek_dhtml.getElementById(container);
        if (!container) return false;
        link = qtek_dhtml.getElementById(link);
        var ajax = new qtek_ajax(url + "&action=fadeout&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            if (!link) return;

        };
        ajax.execute(null);
    },

    showMSGSent: function(url, container, link) {
        //alert(url);
        container = qtek_dhtml.getElementById(container);
        if (!container) return false;
        link = qtek_dhtml.getElementById(link);
        var ajax = new qtek_ajax(url + "&action=fadeout&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            if (!link) return;
            var width = 415;
            var height = 84;
            var left = qtek_dhtml.getLayerLeft(link);
            var top = qtek_dhtml.getLayerTop(link);
            var docwidth = qtek_dhtml.getDocumentWidth(window.document);
            if (left > (docwidth / 2)) left = qtek_dhtml.getLayerRight(link);
            left -= (width + 2);
            qtek_dhtml.setLayerSize(container, width, height);
            if (link.id.indexOf('divPositionFadeOut') > -1) {


                qtek_dhtml.moveLayerTo(container, left + width + 270, top - 120);
            } else {

                qtek_dhtml.moveLayerTo(container, left - width + 30, top);
            }
            qtek_dhtml.showLayer(container);

        };
        ajax.execute(null);
    },
    showMSGAddFriend: function(url, container, link) {
        container = qtek_dhtml.getElementById(container);
        if (!container) return false;
        link = qtek_dhtml.getElementById(link);
        var ajax = new qtek_ajax(url + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            if (!link) return;
            var width = 400;
            var height = 90;
            var left = qtek_dhtml.getLayerLeft(link);
            var top = qtek_dhtml.getLayerTop(link);
            var docwidth = qtek_dhtml.getDocumentWidth(window.document);
            if (left > (docwidth / 2)) left = qtek_dhtml.getLayerRight(link);
            left -= (width + 2);
            qtek_dhtml.setLayerSize(container, width, height);
            if (link.id.indexOf('divPositionFadeOut') > -1) {
                qtek_dhtml.moveLayerTo(container, left + width + 270, top - 350);
            } else {
                qtek_dhtml.moveLayerTo(container, left - width + 30, top);
            }
            qtek_dhtml.showLayer(container);

        };
        ajax.execute(null);
    },

    addVoteReview: function(url, container) {
        container = qtek_dhtml.getElementById(container);
        if (!container) return false;
        container.innerHTML = "<img src='../../images/loader.gif' />";
        var ajax = new qtek_ajax(url + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            qtek_dhtml.showLayer(container);
        };
        ajax.execute(null);
    },
    loadVoteReview: function(url, container) {
        container = qtek_dhtml.getElementById(container);
        if (!container) return false;
        //container.innerHTML = "<img src='../../images/loader.gif' />";
        var ajax = new qtek_ajax(url + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            qtek_dhtml.showLayer(container);


            //hung add
            /// alert('a');
            //FailReview
            //Sorry, you have been reviewed this listing already!!!!!!!!!!!.
            var dv_failreview = document.getElementById('FailReview');
            //review success....
            if (dv_failreview == null) {

                FadeMessage('c_add_y_Review', 'pass', position_mess_swim_menu)
            }
            else {

                FadeMessage('c_add_y_Review_fail', 'pass', position_mess_swim_menu);

            }

        };
        ajax.execute(null);
    }
    ,
    loadLessonStep3: function(url, container) {
        container = qtek_dhtml.getElementById(container);
        if (!container) return false;
        container.innerHTML = "<img src='../../images/loader.gif' />";
        var ajax = new qtek_ajax(url + "&r=" + Math.random(), "GET");
        ajax.responseContainer = container;
        ajax.onComplete = function() {
            qtek_dhtml.showLayer(container);
        };
        ajax.execute(null);
    },
    checkDirectorySecurity: function(url, container, divTemp, link) {
        container = qtek_dhtml.getElementById(container);
        divTemp = qtek_dhtml.getElementById(divTemp);
        if (!container) return false;
        if (!divTemp) return false;
        var ajax = new qtek_ajax(url + "&r=" + Math.random(), "GET");
        ajax.responseContainer = divTemp;
        ajax.onComplete = function() {
            if (divTemp.innerHTML == "NO") {
                showErrorMsg('txtCaptcha', 'You have entered an invalid code.<br />Please try again.');
            }
            else {
                qtek_dhtml.hideLayer(container);
                qtek_window.redirect(link);
            }
        };
        ajax.execute(null);
    },
    /**CheckSendEmailToEditor**/
    checkSendEmailToEditor: function(url, container, divTemp) {
        if (document.getElementById("txtEmailFrom").value == '') {
            showErrorMsg('txtCaptcha1', 'Please enter your email.');
            return;
        }
        show('divWaiting');
        //container = qtek_dhtml.getElementById(container);  
        divTemp = qtek_dhtml.getElementById(divTemp);
        if (!container) return false;
        if (!divTemp) return false;
        var ajax = new qtek_ajax(url + "&r=" + Math.random(), "GET");
        ajax.responseContainer = divTemp;
        ajax.onComplete = function() {
            hide('divWaiting');
            //set to default value:

            qtek_dhtml.getElementById('txtCaptcha1').value = '';
            if (divTemp.innerHTML == "NO") {
                showErrorMsg('txtCaptcha1', 'The email is not sent successfully.<br />Please try again.');
            }
            else if (divTemp.innerHTML == "YES") {
                qtek_dhtml.getElementById('txtEmailContent').value = '';
                //showErrorMsg('txtCaptcha1','The email has been sent successfully.');
                hide(container);
                var divFav = qtek_dhtml.getElementById('divFav');
                var width = 374;
                var height = 87;
                var left = qtek_dhtml.getLayerLeft(divFav);
                var top = qtek_dhtml.getLayerTop(divFav);
                var docwidth = qtek_dhtml.getDocumentWidth(window.document);
                if (left > (docwidth / 2)) left = qtek_dhtml.getLayerRight(divFav);
                left -= (width + 2);

                var divAddFavorites = qtek_dhtml.getElementById('divAddFavorites');
                var htmlContent = '	<div style="font-family:arial; text-align:center; font-size:13px;color: #093246; margin-top:32px">The email has been sent successfully.</div>';
                divAddFavorites.innerHTML = htmlContent;
                qtek_dhtml.setLayerSize(divAddFavorites, width, height);
                qtek_dhtml.moveLayerTo(divAddFavorites, left - 260, top - 25);
                qtek_dhtml.showLayer(divAddFavorites);
                fade.init('divAddFavorites', '200', '1', '50', '1');

            }
            else if (divTemp.innerHTML == "SPAM") {
                showErrorMsg('txtCaptcha1', 'This is a spam email.<br />Please try again.');
            }
            else if (divTemp.innerHTML == "CODE") {
                showErrorMsg('txtCaptcha1', 'You have entered a invalid code.<br />Please try again.');
            }
            else {
                //alert(divTemp.innerHTML);
                showErrorMsg('txtCaptcha1', 'The email is not sent successfully.<br />Please try again.');
            }
        };
        ajax.execute(null);
    },
    IsLimitSendEmail: function(url, divTemp) {
        divTemp = qtek_dhtml.getElementById(divTemp);
        if (!divTemp) return false;
        var ajax = new qtek_ajax(url + "?r=" + Math.random(), "GET");
        ajax.responseContainer = divTemp;
        ajax.onComplete = function() {
            if (divTemp.innerHTML == "TRUE") {
                show('divCaptcha');
                isShowCaptcha = true;
                qtek_dhtml.getElementById('divRound').style.height = '300px';
                qtek_dhtml.getElementById('divInside').style.height = '300px';
            }
            else {
                hide('divCaptcha');
                isShowCaptcha = false;
                qtek_dhtml.getElementById('divRound').style.height = '220px';
                qtek_dhtml.getElementById('divInside').style.height = '220px';
            }
        };
        ajax.execute(null);
    },
    addDiscuss: function(url, divSendPass, divSendFail, block1, block0, divLoad, newCaptcha) {
        divSendPass = qtek_dhtml.getElementById(divSendPass);
        divSendFail = qtek_dhtml.getElementById(divSendFail);
        block1 = qtek_dhtml.getElementById(block1);
        block0 = qtek_dhtml.getElementById(block0);
        divLoad = qtek_dhtml.getElementById(divLoad);
        if (!divSendPass) return false;
        if (!divSendFail) return false;

        //qtek_dhtml.showLayer(divLoad);         
        divLoad.style.display = '';
        document.getElementById('btnAddDiscuss').style.display = 'none';

        var ajax = new qtek_ajax(url + "&r=" + Math.random(), "GET");
        ajax.responseContainer = divSendPass;
        ajax.onComplete = function() {
            if (divSendPass.innerHTML != "1") {
                divLoad.style.display = 'none';
                document.getElementById('btnAddDiscuss').style.display = '';

                if (!block1) return;
                //	            var width = 374;
                //                var height = 87;	  
                //                var left = qtek_dhtml.getLayerLeft(block1);
                //                var top = qtek_dhtml.getLayerTop(block1);
                //                var docwidth = qtek_dhtml.getDocumentWidth(window.document);	        
                //                if (left > (docwidth / 2)) left = qtek_dhtml.getLayerRight(block1);
                //                left -= (width + 2);	

                //	            qtek_dhtml.hideLayer(divSendPass);
                qtek_dhtml.hideLayer(divLoad);
                // var content = divSendPass.innerHTML;
                //	            if(content == "SPAM")
                //	            {
                //	                content ='The comment contains spam.<br />Please try again.';
                //	            }
                //	            var htmlContent = '	<div style="font-family:arial; text-align:center; font-size:13px;color: #093246; margin-top:32px">' + content + '</div>';	            
                //	            divSendFail.innerHTML = htmlContent ;
                //	            qtek_dhtml.setLayerSize(divSendFail, width, height);		         	                   
                //	            qtek_dhtml.moveLayerTo(divSendFail, left+520, top);	
                //	            qtek_dhtml.showLayer(divSendFail);    
                //	            fade.init('divSendFail','200','1','50','1');         
                FadeDynamicContent('c_add_y_spam_comment', 'BR', '<BR/>', 'fail', block0);
            }
            else {
                divLoad.style.display = 'none';
                document.getElementById('btnAddDiscuss').style.display = '';

                if (!block0) return;
                //	            var width = 374;
                //                var height = 87;	  
                //                var left = qtek_dhtml.getLayerLeft(block0);
                //                var top = qtek_dhtml.getLayerTop(block0);
                //                var docwidth = qtek_dhtml.getDocumentWidth(window.document);	        
                //                if (left > (docwidth / 2)) left = qtek_dhtml.getLayerRight(block0);
                //                left -= (width + 2);	

                //            qtek_dhtml.hideLayer(divSendFail); 
                qtek_dhtml.hideLayer(divLoad);
                //	            var htmlContent = '	<div style="font-family:arial; text-align:center; font-size:13px;color: #093246; margin-top:32px">Your comment has been added successfully!</div>';	            
                //	            divSendPass.innerHTML = htmlContent ;
                //	            qtek_dhtml.setLayerSize(divSendPass, width, height); 
                //	            qtek_dhtml.moveLayerTo(divSendPass,  left + 520, top+50);	         
                //	            qtek_dhtml.showLayer(divSendPass);          
                //	            scrollToAnchor('anchor0');
                //	            fade.init('divSendPass','100','1','50','1');	

                LoadDiscuss(0);
                FadeMessage('c_add_y_video_comment', 'pass', 'block0');
                qtek_dhtml.getElementById('content').value = 'Type your comment here';
                qtek_dhtml.getElementById('captcha').value = '';
                qtek_dhtml.getElementById('imgCaptcha').src = newCaptcha;

            }
        };
        ajax.execute(null);
    },
    addComment: function(url, divSendPass, divSendFail, block1, block0, divLoad, newCaptcha) {
        divSendPass = qtek_dhtml.getElementById(divSendPass);
        divSendFail = qtek_dhtml.getElementById(divSendFail);
        block1 = qtek_dhtml.getElementById(block1);
        block0 = qtek_dhtml.getElementById(block0);
        divLoad = qtek_dhtml.getElementById(divLoad);
        if (!divSendPass) return false;
        if (!divSendFail) return false;

        qtek_dhtml.showLayer(divLoad);

        var ajax = new qtek_ajax(url + "&r=" + Math.random(), "GET");
        ajax.responseContainer = divSendPass;
        ajax.onComplete = function() {
            if (divSendPass.innerHTML == "CheckSpamError") {
                if (!block1) return;
                //	            var width = 374;
                //                var height = 87;	  
                //                var left = qtek_dhtml.getLayerLeft(block1);
                //                var top = qtek_dhtml.getLayerTop(block1);
                //                var docwidth = qtek_dhtml.getDocumentWidth(window.document);	        
                //                if (left > (docwidth / 2)) left = qtek_dhtml.getLayerRight(block1);
                //                left -= (width + 2);	

                //	            qtek_dhtml.hideLayer(divSendPass);
                qtek_dhtml.hideLayer(divLoad);
                var content = divSendPass.innerHTML;
                if (content == "SPAM") {
                    content = 'Connect Server Check Spam raise Error.<br />Please try again.';
                }
                //	            var htmlContent = '	<div style="font-family:arial; text-align:center; font-size:13px;color: #093246; margin-top:32px">' + content + '</div>';	            
                //	            divSendFail.innerHTML = htmlContent ;
                //	            qtek_dhtml.setLayerSize(divSendFail, width, height);		         	                   
                //	            qtek_dhtml.moveLayerTo(divSendFail, left+520, top);	
                //	            qtek_dhtml.showLayer(divSendFail);    
                //	            fade.init('divSendFail','200','1','50','1');  
                FadeMessage('c_fail_processdata', 'fail', 'block0');
            }
            else if (divSendPass.innerHTML != "1") {
                if (!block1) return;
                //	            var width = 374;
                //                var height = 87;	  
                //                var left = qtek_dhtml.getLayerLeft(block1);
                //                var top = qtek_dhtml.getLayerTop(block1);
                //                var docwidth = qtek_dhtml.getDocumentWidth(window.document);	        
                //                if (left > (docwidth / 2)) left = qtek_dhtml.getLayerRight(block1);
                //                left -= (width + 2);	
                //            
                //	            qtek_dhtml.hideLayer(divSendPass);
                //	            qtek_dhtml.hideLayer(divLoad);
                //	            var content = divSendPass.innerHTML;
                //	            if(content == "SPAM")
                //	            {
                //	                content ='The comment contains spam.<br />Please try again.';
                //	            }
                //	            var htmlContent = '	<div style="font-family:arial; text-align:center; font-size:13px;color: #093246; margin-top:32px">' + content + '</div>';	            
                //	            divSendFail.innerHTML = htmlContent ;
                //	            qtek_dhtml.setLayerSize(divSendFail, width, height);		         	                   
                //	            qtek_dhtml.moveLayerTo(divSendFail, left+520, top);	
                //	            qtek_dhtml.showLayer(divSendFail);    
                //	            fade.init('divSendFail','200','1','50','1'); 
                FadeDynamicContent('c_add_y_spam_comment', 'BR', '<BR/>', 'fail', block0);
            }
            else {
                if (!block0) return;
                //	              
                //                var width = 374;
                //                var height = 87;	  
                //                var left = qtek_dhtml.getLayerLeft(block0);
                //                var top = qtek_dhtml.getLayerTop(block0);
                //                var docwidth = qtek_dhtml.getDocumentWidth(window.document);	        
                //                if (left > (docwidth / 2)) left = qtek_dhtml.getLayerRight(block0);
                //                left -= (width + 2);	

                //	            qtek_dhtml.hideLayer(divSendFail); 
                qtek_dhtml.hideLayer(divLoad);
                //	            var htmlContent = '	<div style="font-family:arial; text-align:center; font-size:13px;color: #093246; margin-top:32px">Your comment has been added successfully!</div>';	            
                //	            divSendPass.innerHTML = htmlContent ;
                //	            qtek_dhtml.setLayerSize(divSendPass, width, height); 
                //	            qtek_dhtml.moveLayerTo(divSendPass,  left + 520, top+50);	         
                //	            qtek_dhtml.showLayer(divSendPass);          
                //	            scrollToAnchor('anchor0');
                //	            fade.init('divSendPass','100','1','50','1');
                //	            var t=setTimeout("qtek_dhtml.hideLayer('"+divSendPass.id+"')",4000);

                FadeMessage('c_add_y_video_comment', 'pass', 'block0');

                LoadComment(0);
                qtek_dhtml.getElementById('txtComment').value = 'Type your comment here';
                qtek_dhtml.getElementById('txtCapCha').value = '';
                qtek_dhtml.getElementById('imgCapCha').src = newCaptcha;

            }
        };
        ajax.execute(null);
    }

};


/*********** Begin D:\SVN\iSport.com\WorkingSourceCode_JIRA\Scripts\swim.effects.js *****************/
// Spry.Effect.js - version 0.38 - Spry Pre-Release 1.6.1
//
// Copyright (c) 2006. Adobe Systems Incorporated.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//   * Redistributions of source code must retain the above copyright notice,
//     this list of conditions and the following disclaimer.
//   * Redistributions in binary form must reproduce the above copyright notice,
//     this list of conditions and the following disclaimer in the documentation
//     and/or other materials provided with the distribution.
//   * Neither the name of Adobe Systems Incorporated nor the names of its
//     contributors may be used to endorse or promote products derived from this
//     software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.

var Spry;

if (!Spry) Spry = {};

Spry.forwards = 1; // const
Spry.backwards = 2; // const

if (!Spry.Effect) Spry.Effect = {};

Spry.Effect.Transitions = {
    linearTransition: function(time, begin, change, duration) {
        if (time > duration) return change + begin;
        return begin + (time / duration) * change;
    },
    sinusoidalTransition: function(time, begin, change, duration) {
        if (time > duration) return change + begin;
        return begin + ((-Math.cos((time / duration) * Math.PI) / 2) + 0.5) * change;
    },
    squareTransition: function(time, begin, change, duration) {
        if (time > duration) return change + begin;
        return begin + Math.pow(time / duration, 2) * change;
    },
    squarerootTransition: function(time, begin, change, duration) {
        if (time > duration) return change + begin;
        return begin + Math.sqrt(time / duration) * change;
    },
    fifthTransition: function(time, begin, change, duration) {
        if (time > duration) return change + begin;
        return begin + Math.sqrt((-Math.cos((time / duration) * Math.PI) / 2) + 0.5) * change;
    },
    circleTransition: function(time, begin, change, duration) {
        if (time > duration) return change + begin;
        var pos = time / duration;
        return begin + Math.sqrt(1 - Math.pow((pos - 1), 2)) * change;
    },
    pulsateTransition: function(time, begin, change, duration) {
        if (time > duration) return change + begin;
        return begin + (0.5 + Math.sin(17 * time / duration) / 2) * change;
    },
    growSpecificTransition: function(time, begin, change, duration) {
        if (time > duration) return change + begin;
        var pos = time / duration;
        return begin + (5 * Math.pow(pos, 3) - 6.4 * Math.pow(pos, 2) + 2 * pos) * change;
    }
};
for (var trans in Spry.Effect.Transitions) {
    Spry[trans] = Spry.Effect.Transitions[trans];
}
//////////////////////////////////////////////////////////////////////
//
// Spry.Effect.Registry
//
//////////////////////////////////////////////////////////////////////

Spry.Effect.Registry = function() {
    this.effects = [];
};

Spry.Effect.Registry.prototype.getRegisteredEffect = function(element, options) {
    var a = {};
    a.element = Spry.Effect.getElement(element);
    a.options = options;

    for (var i = 0; i < this.effects.length; i++)
        if (this.effectsAreTheSame(this.effects[i], a))
        return this.effects[i].effect;

    return false;
};

Spry.Effect.Registry.prototype.addEffect = function(effect, element, options) {
    if (!this.getRegisteredEffect(element, options)) {
        var len = this.effects.length;
        this.effects[len] = {};
        var eff = this.effects[len];
        eff.effect = effect;
        eff.element = Spry.Effect.getElement(element);
        eff.options = options;
    }
};

Spry.Effect.Registry.prototype.effectsAreTheSame = function(effectA, effectB) {
    if (effectA.element != effectB.element)
        return false;

    var compare = Spry.Effect.Utils.optionsAreIdentical(effectA.options, effectB.options);
    // reset finish and setup functions
    if (compare) {
        if (typeof effectB.options.setup == 'function')
            effectA.options.setup = effectB.options.setup;

        if (typeof effectB.options.finish == 'function')
            effectA.options.finish = effectB.options.finish;
    }

    return compare;
};

var SpryRegistry = new Spry.Effect.Registry;

//////////////////////////////////////////////////////////////////////
//
// Spry.Effect.Utils
//
//////////////////////////////////////////////////////////////////////

if (!Spry.Effect.Utils) Spry.Effect.Utils = {};

Spry.Effect.Utils.showError = function(msg) {
    alert('Spry.Effect ERR: ' + msg);
};
Spry.Effect.Utils.showInitError = function(effect) {
    Spry.Effect.Utils.showError('The ' + effect + ' class can\'t be accessed as a static function anymore. ' + "\n" + 'Please read Spry Effects migration documentation.');
    return false;
};
Spry.Effect.Utils.Position = function() {
    this.x = 0; // left
    this.y = 0; // top
    this.units = "px";
};

Spry.Effect.Utils.Rectangle = function() {
    this.width = 0;
    this.height = 0;
    this.units = "px";
};

Spry.Effect.Utils.intToHex = function(integerNum) {
    var result = integerNum.toString(16);
    if (result.length == 1)
        result = "0" + result;
    return result;
};

Spry.Effect.Utils.hexToInt = function(hexStr) {
    return parseInt(hexStr, 16);
};

Spry.Effect.Utils.rgb = function(redInt, greenInt, blueInt) {
    var intToHex = Spry.Effect.Utils.intToHex;
    var redHex = intToHex(redInt);
    var greenHex = intToHex(greenInt);
    var blueHex = intToHex(blueInt);
    compositeColorHex = redHex.concat(greenHex, blueHex).toUpperCase();
    compositeColorHex = '#' + compositeColorHex;
    return compositeColorHex;
};

Spry.Effect.Utils.longColorVersion = function(color) {
    if (color.match(/^#[0-9a-f]{3}$/i)) {
        var tmp = color.split('');
        var color = '#';
        for (var i = 1; i < tmp.length; i++) {
            color += tmp[i] + '' + tmp[i];
        }
    }
    return color;
};

Spry.Effect.Utils.camelize = function(stringToCamelize) {
    if (stringToCamelize.indexOf('-') == -1) {
        return stringToCamelize;
    }
    var oStringList = stringToCamelize.split('-');
    var isFirstEntry = true;
    var camelizedString = '';

    for (var i = 0; i < oStringList.length; i++) {
        if (oStringList[i].length > 0) {
            if (isFirstEntry) {
                camelizedString = oStringList[i];
                isFirstEntry = false;
            }
            else {
                var s = oStringList[i];
                camelizedString += s.charAt(0).toUpperCase() + s.substring(1);
            }
        }
    }

    return camelizedString;
};

Spry.Effect.Utils.isPercentValue = function(value) {
    var result = false;
    if (typeof value == 'string' && value.length > 0 && value.lastIndexOf("%") > 0)
        result = true;

    return result;
};

Spry.Effect.Utils.getPercentValue = function(value) {
    var result = 0;
    try {
        result = Number(value.substring(0, value.lastIndexOf("%")));
    }
    catch (e) { Spry.Effect.Utils.showError('Spry.Effect.Utils.getPercentValue: ' + e); }
    return result;
};

Spry.Effect.Utils.getPixelValue = function(value) {
    var result = 0;
    if (typeof value == 'number') return value;
    var unitIndex = value.lastIndexOf("px");
    if (unitIndex == -1)
        unitIndex = value.length;
    try {
        result = parseInt(value.substring(0, unitIndex), 10);
    }
    catch (e) { }
    return result;
};

Spry.Effect.Utils.getFirstChildElement = function(node) {
    if (node) {
        var childCurr = node.firstChild;
        while (childCurr) {
            if (childCurr.nodeType == 1) // Node.ELEMENT_NODE
                return childCurr;

            childCurr = childCurr.nextSibling;
        }
    }

    return null;
};

Spry.Effect.Utils.fetchChildImages = function(startEltIn, targetImagesOut) {
    if (!startEltIn || startEltIn.nodeType != 1 || !targetImagesOut)
        return;

    if (startEltIn.hasChildNodes()) {
        var childImages = startEltIn.getElementsByTagName('img');
        var imageCnt = childImages.length;
        for (var i = 0; i < imageCnt; i++) {
            var imgCurr = childImages[i];
            var dimensionsCurr = Spry.Effect.getDimensions(imgCurr);
            targetImagesOut.push([imgCurr, dimensionsCurr.width, dimensionsCurr.height]);
        }
    }
};

Spry.Effect.Utils.optionsAreIdentical = function(optionsA, optionsB) {
    if (optionsA == null && optionsB == null)
        return true;

    if (optionsA != null && optionsB != null) {
        var objectCountA = 0;
        var objectCountB = 0;

        for (var propA in optionsA) objectCountA++;
        for (var propB in optionsB) objectCountB++;

        if (objectCountA != objectCountB)
            return false;

        for (var prop in optionsA) {
            var typeA = typeof optionsA[prop];
            var typeB = typeof optionsB[prop];
            if (typeA != typeB || (typeA != 'undefined' && optionsA[prop] != optionsB[prop]))
                return false;
        }

        return true;
    }

    return false;
};

Spry.Effect.Utils.DoEffect = function(effectName, element, options) {
    if (!options)
        var options = {};

    options.name = effectName;
    var ef = SpryRegistry.getRegisteredEffect(element, options);
    if (!ef) {
        ef = new Spry.Effect[effectName](element, options);
        SpryRegistry.addEffect(ef, element, options);
    }
    ef.start();
    return true;
};
//////////////////////////////////////////////////////////////////////
//
//  The notification class
//
//////////////////////////////////////////////////////////////////////
if (!Spry.Utils) Spry.Utils = {};

Spry.Utils.Notifier = function() {
    this.observers = [];
    this.suppressNotifications = 0;
};

Spry.Utils.Notifier.prototype.addObserver = function(observer) {
    if (!observer)
        return;

    // Make sure the observer isn't already on the list.

    var len = this.observers.length;
    for (var i = 0; i < len; i++)
        if (this.observers[i] == observer) return;

    this.observers[len] = observer;
};

Spry.Utils.Notifier.prototype.removeObserver = function(observer) {
    if (!observer)
        return;

    for (var i = 0; i < this.observers.length; i++) {
        if (this.observers[i] == observer) {
            this.observers.splice(i, 1);
            break;
        }
    }
};

Spry.Utils.Notifier.prototype.notifyObservers = function(methodName, data) {
    if (!methodName)
        return;

    if (!this.suppressNotifications) {
        var len = this.observers.length;
        for (var i = 0; i < len; i++) {
            var obs = this.observers[i];
            if (obs) {
                if (typeof obs == "function")
                    obs(methodName, this, data);
                else if (obs[methodName])
                    obs[methodName](this, data);
            }
        }
    }
};

Spry.Utils.Notifier.prototype.enableNotifications = function() {
    if (--this.suppressNotifications < 0) {
        this.suppressNotifications = 0;
        Spry.Effect.Utils.showError("Unbalanced enableNotifications() call!\n");
    }
};

Spry.Utils.Notifier.prototype.disableNotifications = function() {
    ++this.suppressNotifications;
};

//////////////////////////////////////////////////////////////////////
//
// DHTML manipulation
//
//////////////////////////////////////////////////////////////////////

Spry.Effect.getElement = function(ele) {
    var element = ele;
    if (typeof ele == "string")
        element = document.getElementById(ele);

    if (element == null)
        Spry.Effect.Utils.showError('Element "' + ele + '" not found.');

    return element;
};

Spry.Effect.getStyleProp = function(element, prop) {
    var value;
    var camelized = Spry.Effect.Utils.camelize(prop);
    try {
        if (element.style)
            value = element.style[camelized];

        if (!value) {
            if (document.defaultView && document.defaultView.getComputedStyle) {
                var css = document.defaultView.getComputedStyle(element, null);
                value = css ? css.getPropertyValue(prop) : null;
            }
            else if (element.currentStyle) {
                value = element.currentStyle[camelized];
            }
        }
    }
    catch (e) { Spry.Effect.Utils.showError('Spry.Effect.getStyleProp: ' + e); }

    return value == 'auto' ? null : value;
};

Spry.Effect.setStyleProp = function(element, prop, value) {
    try {
        element.style[Spry.Effect.Utils.camelize(prop)] = value;
    }
    catch (e) { Spry.Effect.Utils.showError('Spry.Effect.setStyleProp: ' + e); }
};

Spry.Effect.getStylePropRegardlessOfDisplayState = function(element, prop, displayElement) {
    var refElement = displayElement ? displayElement : element;
    var displayOrig = Spry.Effect.getStyleProp(refElement, 'display');
    var visibilityOrig = Spry.Effect.getStyleProp(refElement, 'visibility');

    if (displayOrig == 'none') {
        Spry.Effect.setStyleProp(refElement, 'visibility', 'hidden');
        Spry.Effect.setStyleProp(refElement, 'display', 'block');

        if (window.opera) // opera needs focus to calculate the size for hidden elements
            refElement.focus();
    }

    var styleProp = Spry.Effect.getStyleProp(element, prop);

    if (displayOrig == 'none') // reset the original values
    {
        Spry.Effect.setStyleProp(refElement, 'display', 'none');
        Spry.Effect.setStyleProp(refElement, 'visibility', visibilityOrig);
    }
    return styleProp;
};

Spry.Effect.makePositioned = function(element) {
    var pos = Spry.Effect.getStyleProp(element, 'position');
    if (!pos || pos == 'static') {
        element.style.position = 'relative';

        // Opera returns the offset relative to the positioning context, when an
        // element is position relative but top and left have not been defined
        if (window.opera) {
            element.style.top = 0;
            element.style.left = 0;
        }
    }
};

Spry.Effect.isInvisible = function(element) {
    var propDisplay = Spry.Effect.getStyleProp(element, 'display');
    if (propDisplay && propDisplay.toLowerCase() == 'none')
        return true;

    var propVisible = Spry.Effect.getStyleProp(element, 'visibility');
    if (propVisible && propVisible.toLowerCase() == 'hidden')
        return true;

    return false;
};

Spry.Effect.enforceVisible = function(element) {
    var propDisplay = Spry.Effect.getStyleProp(element, 'display');
    if (propDisplay && propDisplay.toLowerCase() == 'none')
        Spry.Effect.setStyleProp(element, 'display', 'block');

    var propVisible = Spry.Effect.getStyleProp(element, 'visibility');
    if (propVisible && propVisible.toLowerCase() == 'hidden')
        Spry.Effect.setStyleProp(element, 'visibility', 'visible');
};

Spry.Effect.makeClipping = function(element) {
    var overflow = Spry.Effect.getStyleProp(element, 'overflow');
    if (!overflow || (overflow.toLowerCase() != 'hidden' && overflow.toLowerCase() != 'scroll')) {
        // IE 7 bug: set overflow property to hidden changes the element height to 0
        // -> therefore we save the height before changing the overflow property and set the old size back
        var heightCache = 0;
        var needsCache = /MSIE 7.0/.test(navigator.userAgent) && /Windows NT/.test(navigator.userAgent);
        if (needsCache)
            heightCache = Spry.Effect.getDimensionsRegardlessOfDisplayState(element).height;

        Spry.Effect.setStyleProp(element, 'overflow', 'hidden');

        if (needsCache)
            Spry.Effect.setStyleProp(element, 'height', heightCache + 'px');
    }
};

Spry.Effect.cleanWhitespace = function(element) {
    var childCountInit = element.childNodes.length;
    for (var i = childCountInit - 1; i >= 0; i--) {
        var node = element.childNodes[i];
        if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
            try {
            element.removeChild(node);
        }
        catch (e) { Spry.Effect.Utils.showError('Spry.Effect.cleanWhitespace: ' + e); }
    }
};

Spry.Effect.getComputedStyle = function(element) {
    return /MSIE/.test(navigator.userAgent) ? element.currentStyle : document.defaultView.getComputedStyle(element, null);
};

Spry.Effect.getDimensions = function(element) {
    var dimensions = new Spry.Effect.Utils.Rectangle;
    var computedStyle = null;

    if (element.style.width && /px/i.test(element.style.width))
        dimensions.width = parseInt(element.style.width, 10); // without padding
    else {
        computedStyle = Spry.Effect.getComputedStyle(element);
        var tryComputedStyle = computedStyle && computedStyle.width && /px/i.test(computedStyle.width);

        if (tryComputedStyle)
            dimensions.width = parseInt(computedStyle.width, 10); // without padding, includes css

        if (!tryComputedStyle || dimensions.width == 0) // otherwise we might run into problems on safari and opera (mac only)
            dimensions.width = element.offsetWidth;   // includes padding
    }

    if (element.style.height && /px/i.test(element.style.height))
        dimensions.height = parseInt(element.style.height, 10); // without padding
    else {
        if (!computedStyle)
            computedStyle = Spry.Effect.getComputedStyle(element);

        var tryComputedStyle = computedStyle && computedStyle.height && /px/i.test(computedStyle.height);

        if (tryComputedStyle)
            dimensions.height = parseInt(computedStyle.height, 10); // without padding, includes css

        if (!tryComputedStyle || dimensions.height == 0) // otherwise we might run into problems on safari and opera (mac only)
            dimensions.height = element.offsetHeight;   // includes padding
    }
    return dimensions;
};

Spry.Effect.getDimensionsRegardlessOfDisplayState = function(element, displayElement) {
    // If the displayElement display property is set to 'none', we temporarily set its
    // visibility state to 'hidden' to be able to calculate the dimension.

    var refElement = displayElement ? displayElement : element;
    var displayOrig = Spry.Effect.getStyleProp(refElement, 'display');
    var visibilityOrig = Spry.Effect.getStyleProp(refElement, 'visibility');

    if (displayOrig == 'none') {
        Spry.Effect.setStyleProp(refElement, 'visibility', 'hidden');
        Spry.Effect.setStyleProp(refElement, 'display', 'block');

        if (window.opera) // opera needs focus to calculate the size for hidden elements
            refElement.focus();
    }

    var dimensions = Spry.Effect.getDimensions(element);

    if (displayOrig == 'none') // reset the original values
    {
        Spry.Effect.setStyleProp(refElement, 'display', 'none');
        Spry.Effect.setStyleProp(refElement, 'visibility', visibilityOrig);
    }
    return dimensions;
};

Spry.Effect.getOpacity = function(element) {
    var o = Spry.Effect.getStyleProp(element, "opacity");
    if (typeof o == 'undefined' || o == null)
        o = 1.0;
    return o;
};

Spry.Effect.getBgColor = function(ele) {
    return Spry.Effect.getStyleProp(ele, "background-color");
};

Spry.Effect.intPropStyle = function(e, prop) {
    var i = parseInt(Spry.Effect.getStyleProp(e, prop), 10);
    if (isNaN(i))
        return 0;
    return i;
};

Spry.Effect.getPosition = function(element) {
    var position = new Spry.Effect.Utils.Position;
    var computedStyle = null;

    if (element.style.left && /px/i.test(element.style.left))
        position.x = parseInt(element.style.left, 10); // without padding
    else {
        computedStyle = Spry.Effect.getComputedStyle(element);
        var tryComputedStyle = computedStyle && computedStyle.left && /px/i.test(computedStyle.left);

        if (tryComputedStyle)
            position.x = parseInt(computedStyle.left, 10); // without padding, includes css

        if (!tryComputedStyle || position.x == 0) // otherwise we might run into problems on safari and opera (mac only)
            position.x = element.offsetLeft;   // includes padding
    }

    if (element.style.top && /px/i.test(element.style.top))
        position.y = parseInt(element.style.top, 10); // without padding
    else {
        if (!computedStyle)
            computedStyle = Spry.Effect.getComputedStyle(element);

        var tryComputedStyle = computedStyle && computedStyle.top && /px/i.test(computedStyle.top);

        if (tryComputedStyle)
            position.y = parseInt(computedStyle.top, 10); // without padding, includes css

        if (!tryComputedStyle || position.y == 0) // otherwise we might run into problems on safari and opera (mac only)
            position.y = element.offsetTop;   // includes padding
    }
    return position;
};

Spry.Effect.getOffsetPosition = Spry.Effect.getPosition; // deprecated

//////////////////////////////////////////////////////////////////////
//
// Spry.Effect.Animator
// (base class)
//
//////////////////////////////////////////////////////////////////////

Spry.Effect.Animator = function(options) {
    Spry.Utils.Notifier.call(this);

    this.name = 'Animator';
    this.element = null;
    this.startMilliseconds = 0;
    this.repeat = 'none';
    this.isRunning = false;
    this.timer = null;
    this.cancelRemaining = 0;

    if (!options)
        var options = {};

    if (options.toggle)
        this.direction = false;
    else
        this.direction = Spry.forwards;

    var self = this;
    if (options.setup != null)
        this.addObserver({ onPreEffect: function() { try { self.options.setup(self.element, self); } catch (e) { Spry.Effect.Utils.showError('Spry.Effect.Animator.prototype.start: setup callback: ' + e); } } });

    if (options.finish != null)
        this.addObserver({ onPostEffect: function() { try { self.options.finish(self.element, self); } catch (e) { Spry.Effect.Utils.showError('Spry.Effect.Animator.prototype.stop: finish callback: ' + e); } } });

    this.options = {
        duration: 1000,
        toggle: false,
        transition: Spry.linearTransition,
        interval: 16 // ca. 62 fps
    };

    this.setOptions(options);
    if (options.transition)
        this.setTransition(options.transition);

    if (options.fps)
        this.setFps(options.fps);
};
Spry.Effect.Animator.prototype = new Spry.Utils.Notifier();
Spry.Effect.Animator.prototype.constructor = Spry.Utils.Animator;

Spry.Effect.Animator.prototype.notStaticAnimator = true;

Spry.Effect.Animator.prototype.setOptions = function(options) {
    if (!options)
        return;
    for (var prop in options)
        this.options[prop] = options[prop];
};
Spry.Effect.Animator.prototype.setTransition = function(transition) {
    if (typeof transition == 'number' || transition == "1" || transition == "2")
        switch (parseInt(transition, 10)) {
        case 1: transition = Spry.linearTransition; break;
        case 2: transition = Spry.sinusoidalTransition; break;
        default: Spry.Effect.Utils.showError('unknown transition');
    }

    else if (typeof transition == 'string') {
        if (typeof window[transition] == 'function')
            transition = window[transition];
        else if (typeof Spry[transition] == 'function')
            transition = Spry[transition];
        else
            Spry.Effect.Utils.showError('unknown transition');
    }

    this.options.transition = transition;
    if (typeof this.effectsArray != 'undefined') {
        var l = this.effectsArray.length;
        for (var i = 0; i < l; i++)
            this.effectsArray[i].effect.setTransition(transition);
    }
};

Spry.Effect.Animator.prototype.setDuration = function(duration) {
    this.options.duration = duration;
    if (typeof this.effectsArray != 'undefined') {
        var l = this.effectsArray.length;
        for (var i = 0; i < l; i++) {
            this.effectsArray[i].effect.setDuration(duration);
        }
    }
};

Spry.Effect.Animator.prototype.setFps = function(fps) {
    this.options.interval = parseInt(1000 / fps, 10);
    this.options.fps = fps;
    if (typeof this.effectsArray != 'undefined') {
        var l = this.effectsArray.length;
        for (var i = 0; i < l; i++) {
            this.effectsArray[i].effect.setFps(fps);
        }
    }
};

Spry.Effect.Animator.prototype.start = function(withoutTimer) {
    if (!this.element)
        return;

    if (arguments.length == 0)
        withoutTimer = false;

    if (this.isRunning)
        this.cancel();

    this.prepareStart();
    var currDate = new Date();
    this.startMilliseconds = currDate.getTime();

    if (this.element.id)
        this.element = document.getElementById(this.element.id);

    if (this.cancelRemaining != 0 && this.options.toggle) {
        if (this.cancelRemaining < 1 && typeof this.options.transition == 'function') {
            var startTime = 0;
            var stopTime = this.options.duration;
            var start = 0;
            var stop = 1;
            var emergency = 0;
            this.cancelRemaining = Math.round(this.cancelRemaining * 1000) / 1000;
            var found = false;
            var middle = 0;
            while (!found) {
                if (emergency++ > this.options.duration) break;
                var half = startTime + ((stopTime - startTime) / 2);
                middle = Math.round(this.options.transition(half, 1, -1, this.options.duration) * 1000) / 1000;
                if (middle == this.cancelRemaining) {
                    this.startMilliseconds -= half;
                    found = true;
                }
                if (middle < this.cancelRemaining) {
                    stopTime = half;
                    stop = middle;
                }
                else {
                    startTime = half;
                    start = middle;
                }
            }
        }
        this.cancelRemaining = 0;
    }
    this.notifyObservers('onPreEffect', this);

    if (withoutTimer == false) {
        var self = this;
        this.timer = setInterval(function() { self.drawEffect(); }, this.options.interval);
    }
    this.isRunning = true;
};
Spry.Effect.Animator.prototype.stopFlagReset = function() {
    if (this.timer) {
        clearInterval(this.timer);
        this.timer = null;
    }
    this.startMilliseconds = 0;
};
Spry.Effect.Animator.prototype.stop = function() {
    this.stopFlagReset();
    this.notifyObservers('onPostEffect', this);
    this.isRunning = false;
};

Spry.Effect.Animator.prototype.cancel = function() {
    var elapsed = this.getElapsedMilliseconds();
    if (this.startMilliseconds > 0 && elapsed < this.options.duration)
        this.cancelRemaining = this.options.transition(elapsed, 0, 1, this.options.duration);

    this.stopFlagReset();
    this.notifyObservers('onCancel', this);
    this.isRunning = false;
};

Spry.Effect.Animator.prototype.drawEffect = function() {
    var isRunning = true;

    this.notifyObservers('onStep', this);
    var timeElapsed = this.getElapsedMilliseconds();

    if (typeof this.options.transition != 'function') {
        Spry.Effect.Utils.showError('unknown transition');
        return;
    }
    this.animate();

    if (timeElapsed > this.options.duration) {
        isRunning = false;
        this.stop();
    }
    return isRunning;
};

Spry.Effect.Animator.prototype.getElapsedMilliseconds = function() {
    if (this.startMilliseconds > 0) {
        var currDate = new Date();
        return (currDate.getTime() - this.startMilliseconds);
    }
    return 0;
};

Spry.Effect.Animator.prototype.doToggle = function() {
    if (!this.direction) {
        this.direction = Spry.forwards;
        return;
    }
    if (this.options.toggle == true) {
        if (this.direction == Spry.forwards) {
            this.direction = Spry.backwards;
            this.notifyObservers('onToggle', this);
        }
        else if (this.direction == Spry.backwards) {
            this.direction = Spry.forwards;
        }
    }
};

Spry.Effect.Animator.prototype.prepareStart = function() {
    if (this.options && this.options.toggle)
        this.doToggle();
};

Spry.Effect.Animator.prototype.animate = function() { };
Spry.Effect.Animator.prototype.onStep = function(el) {
    if (el != this)
        this.notifyObservers('onStep', this);
};
//////////////////////////////////////////////////////////////////////
//
// Spry.Effect.Move
//
//////////////////////////////////////////////////////////////////////

Spry.Effect.Move = function(element, fromPos, toPos, options) {
    this.dynamicFromPos = false;
    if (arguments.length == 3) {
        options = toPos;
        toPos = fromPos;
        fromPos = Spry.Effect.getPosition(element);
        this.dynamicFromPos = true;
    }

    Spry.Effect.Animator.call(this, options);

    this.name = 'Move';
    this.element = Spry.Effect.getElement(element);
    if (!this.element)
        return;

    if (fromPos.units != toPos.units)
        Spry.Effect.Utils.showError('Spry.Effect.Move: Conflicting units (' + fromPos.units + ', ' + toPos.units + ')');

    this.units = fromPos.units;
    this.startX = Number(fromPos.x);
    this.stopX = Number(toPos.x);
    this.startY = Number(fromPos.y);
    this.stopY = Number(toPos.y);
};

Spry.Effect.Move.prototype = new Spry.Effect.Animator();
Spry.Effect.Move.prototype.constructor = Spry.Effect.Move;

Spry.Effect.Move.prototype.animate = function() {
    var left = 0;
    var top = 0;
    var floor = Math.floor;
    var elapsed = this.getElapsedMilliseconds();
    if (this.direction == Spry.forwards) {
        left = floor(this.options.transition(elapsed, this.startX, this.stopX - this.startX, this.options.duration));
        top = floor(this.options.transition(elapsed, this.startY, this.stopY - this.startY, this.options.duration));
    }
    else if (this.direction == Spry.backwards) {
        left = floor(this.options.transition(elapsed, this.stopX, this.startX - this.stopX, this.options.duration));
        top = floor(this.options.transition(elapsed, this.stopY, this.startY - this.stopY, this.options.duration));
    }

    this.element.style.left = left + this.units;
    this.element.style.top = top + this.units;
};

Spry.Effect.Move.prototype.prepareStart = function() {
    if (this.options && this.options.toggle)
        this.doToggle();

    if (this.dynamicFromPos == true) {
        var fromPos = Spry.Effect.getPosition(this.element);
        this.startX = fromPos.x;
        this.startY = fromPos.y;

        this.rangeMoveX = this.startX - this.stopX;
        this.rangeMoveY = this.startY - this.stopY;
    }
};

//////////////////////////////////////////////////////////////////////
//
// Spry.Effect.Size
//
//////////////////////////////////////////////////////////////////////

Spry.Effect.Size = function(element, fromRect, toRect, options) {
    this.dynamicFromRect = false;

    if (arguments.length == 3) {
        options = toRect;
        toRect = fromRect;
        fromRect = Spry.Effect.getDimensionsRegardlessOfDisplayState(element);
        this.dynamicFromRect = true;
    }

    Spry.Effect.Animator.call(this, options);

    this.name = 'Size';
    this.element = Spry.Effect.getElement(element);
    if (!this.element)
        return;

    element = this.element;

    if (fromRect.units != toRect.units) {
        Spry.Effect.Utils.showError('Spry.Effect.Size: Conflicting units (' + fromRect.units + ', ' + toRect.units + ')');
        return false;
    }

    this.units = fromRect.units;

    var originalRect = Spry.Effect.getDimensionsRegardlessOfDisplayState(element);
    this.originalWidth = originalRect.width;
    this.originalHeight = originalRect.height;

    this.startWidth = fromRect.width;
    this.startHeight = fromRect.height;
    this.stopWidth = toRect.width;
    this.stopHeight = toRect.height;
    this.childImages = new Array();

    if (this.options.useCSSBox) {
        Spry.Effect.makePositioned(this.element);
        var intProp = Spry.Effect.intPropStyle;
        this.startFromBorder_top = intProp(element, 'border-top-width');
        this.startFromBorder_bottom = intProp(element, 'border-bottom-width');
        this.startFromBorder_left = intProp(element, 'border-left-width');
        this.startFromBorder_right = intProp(element, 'border-right-width');
        this.startFromPadding_top = intProp(element, 'padding-top');
        this.startFromPadding_bottom = intProp(element, 'padding-bottom');
        this.startFromPadding_left = intProp(element, 'padding-left');
        this.startFromPadding_right = intProp(element, 'padding-right');
        this.startFromMargin_top = intProp(element, 'margin-top');
        this.startFromMargin_bottom = intProp(element, 'margin-bottom');
        this.startFromMargin_right = intProp(element, 'margin-right');
        this.startFromMargin_left = intProp(element, 'margin-left');
        this.startLeft = intProp(element, 'left');
        this.startTop = intProp(element, 'top');
    }

    if (this.options.scaleContent)
        Spry.Effect.Utils.fetchChildImages(element, this.childImages);

    this.fontFactor = 1.0;
    var fontSize = Spry.Effect.getStyleProp(this.element, 'font-size');
    if (fontSize && /em\s*$/.test(fontSize))
        this.fontFactor = parseFloat(fontSize);

    var isPercent = Spry.Effect.Utils.isPercentValue;

    if (isPercent(this.startWidth)) {
        var startWidthPercent = Spry.Effect.Utils.getPercentValue(this.startWidth);
        this.startWidth = originalRect.width * (startWidthPercent / 100);
    }

    if (isPercent(this.startHeight)) {
        var startHeightPercent = Spry.Effect.Utils.getPercentValue(this.startHeight);
        this.startHeight = originalRect.height * (startHeightPercent / 100);
    }

    if (isPercent(this.stopWidth)) {
        var stopWidthPercent = Spry.Effect.Utils.getPercentValue(this.stopWidth);
        this.stopWidth = originalRect.width * (stopWidthPercent / 100);
    }

    if (isPercent(this.stopHeight)) {
        var stopHeightPercent = Spry.Effect.Utils.getPercentValue(this.stopHeight);
        this.stopHeight = originalRect.height * (stopHeightPercent / 100);
    }

    this.enforceVisible = Spry.Effect.isInvisible(this.element);
};

Spry.Effect.Size.prototype = new Spry.Effect.Animator();
Spry.Effect.Size.prototype.constructor = Spry.Effect.Size;

Spry.Effect.Size.prototype.animate = function() {
    var width = 0;
    var height = 0;
    var fontSize = 0;
    var direction = 0;
    var floor = Math.floor;
    var elapsed = this.getElapsedMilliseconds();

    if (this.direction == Spry.forwards) {
        width = floor(this.options.transition(elapsed, this.startWidth, this.stopWidth - this.startWidth, this.options.duration));
        height = floor(this.options.transition(elapsed, this.startHeight, this.stopHeight - this.startHeight, this.options.duration));
        direction = 1;
    } else if (this.direction == Spry.backwards) {
        width = floor(this.options.transition(elapsed, this.stopWidth, this.startWidth - this.stopWidth, this.options.duration));
        height = floor(this.options.transition(elapsed, this.stopHeight, this.startHeight - this.stopHeight, this.options.duration));
        direction = -1;
    }

    var propFactor = width / this.originalWidth;
    fontSize = this.fontFactor * propFactor;

    var elStyle = this.element.style;
    if (width < 0)
        width = 0;

    if (height < 0)
        height = 0;

    elStyle.width = width + this.units;
    elStyle.height = height + this.units;

    if (typeof this.options.useCSSBox != 'undefined' && this.options.useCSSBox == true) {
        var intProp = Spry.Effect.intPropStyle;
        var origTop = intProp(this.element, 'top');
        var origLeft = intProp(this.element, 'left');
        var origMarginTop = intProp(this.element, 'margin-top');
        var origMarginLeft = intProp(this.element, 'margin-left');

        var widthFactor = propFactor;
        var heightFactor = height / this.originalHeight;
        var border_top = floor(this.startFromBorder_top * heightFactor);
        var border_bottom = floor(this.startFromBorder_bottom * heightFactor);
        var border_left = floor(this.startFromBorder_left * widthFactor);
        var border_right = floor(this.startFromBorder_right * widthFactor);
        var padding_top = floor(this.startFromPadding_top * heightFactor);
        var padding_bottom = floor(this.startFromPadding_bottom * heightFactor);
        var padding_left = floor(this.startFromPadding_left * widthFactor);
        var padding_right = floor(this.startFromPadding_right * widthFactor);
        var margin_top = floor(this.startFromMargin_top * heightFactor);
        var margin_bottom = floor(this.startFromMargin_bottom * heightFactor);
        var margin_right = floor(this.startFromMargin_right * widthFactor);
        var margin_left = floor(this.startFromMargin_left * widthFactor);

        elStyle.borderTopWidth = border_top + this.units;
        elStyle.borderBottomWidth = border_bottom + this.units;
        elStyle.borderLeftWidth = border_left + this.units;
        elStyle.borderRightWidth = border_right + this.units;
        elStyle.paddingTop = padding_top + this.units;
        elStyle.paddingBottom = padding_bottom + this.units;
        elStyle.paddingLeft = padding_left + this.units;
        elStyle.paddingRight = padding_right + this.units;
        elStyle.marginTop = margin_top + this.units;
        elStyle.marginBottom = margin_bottom + this.units;
        elStyle.marginLeft = margin_left + this.units;
        elStyle.marginRight = margin_right + this.units;

        // compensate the margin shrinking
        elStyle.left = floor(origLeft + origMarginLeft - margin_left) + this.units;
        elStyle.top = floor(origTop + origMarginTop - margin_top) + this.units;
    }

    if (this.options.scaleContent) {

        for (var i = 0; i < this.childImages.length; i++) {
            this.childImages[i][0].style.width = propFactor * this.childImages[i][1] + this.units;
            this.childImages[i][0].style.height = propFactor * this.childImages[i][2] + this.units;
        }
        this.element.style.fontSize = fontSize + 'em';
    }

    if (this.enforceVisible) {
        Spry.Effect.enforceVisible(this.element);
        this.enforceVisible = false;
    }
};

Spry.Effect.Size.prototype.prepareStart = function() {
    if (this.options && this.options.toggle)
        this.doToggle();

    if (this.dynamicFromRect == true) {
        var fromRect = Spry.Effect.getDimensions(this.element);
        this.startWidth = fromRect.width;
        this.startHeight = fromRect.height;

        this.widthRange = this.startWidth - this.stopWidth;
        this.heightRange = this.startHeight - this.stopHeight;
    }
};

//////////////////////////////////////////////////////////////////////
//
// Spry.Effect.Opacity
//
//////////////////////////////////////////////////////////////////////

Spry.Effect.Opacity = function(element, startOpacity, stopOpacity, options) {
    this.dynamicStartOpacity = false;
    if (arguments.length == 3) {
        options = stopOpacity;
        stopOpacity = startOpacity;
        startOpacity = Spry.Effect.getOpacity(element);
        this.dynamicStartOpacity = true;
    }

    Spry.Effect.Animator.call(this, options);

    this.name = 'Opacity';
    this.element = Spry.Effect.getElement(element);
    if (!this.element)
        return;

    // make this work on IE on elements without 'layout'
    if (/MSIE/.test(navigator.userAgent) && (!this.element.hasLayout))
        Spry.Effect.setStyleProp(this.element, 'zoom', '1');

    this.startOpacity = startOpacity;
    this.stopOpacity = stopOpacity;
    this.enforceVisible = Spry.Effect.isInvisible(this.element);
};

Spry.Effect.Opacity.prototype = new Spry.Effect.Animator();
Spry.Effect.Opacity.prototype.constructor = Spry.Effect.Opacity;

Spry.Effect.Opacity.prototype.animate = function() {
    var opacity = 0;
    var elapsed = this.getElapsedMilliseconds();
    if (this.direction == Spry.forwards)
        opacity = this.options.transition(elapsed, this.startOpacity, this.stopOpacity - this.startOpacity, this.options.duration);
    else if (this.direction == Spry.backwards)
        opacity = this.options.transition(elapsed, this.stopOpacity, this.startOpacity - this.stopOpacity, this.options.duration);

    if (opacity < 0)
        opacity = 0;

    if (/MSIE/.test(navigator.userAgent)) {
        var tmpval = Spry.Effect.getStyleProp(this.element, 'filter');
        if (tmpval) {
            tmpval = tmpval.replace(/alpha\(opacity=[0-9]{1,3}\)/g, '');
        }
        this.element.style.filter = tmpval + "alpha(opacity=" + Math.floor(opacity * 100) + ")";
    }
    else
        this.element.style.opacity = opacity;

    if (this.enforceVisible) {
        Spry.Effect.enforceVisible(this.element);
        this.enforceVisible = false;
    }
};

Spry.Effect.Opacity.prototype.prepareStart = function() {
    if (this.options && this.options.toggle)
        this.doToggle();

    if (this.dynamicStartOpacity == true) {
        this.startOpacity = Spry.Effect.getOpacity(this.element);
        this.opacityRange = this.startOpacity - this.stopOpacity;
    }
};

//////////////////////////////////////////////////////////////////////
//
// Spry.Effect.Color
//
//////////////////////////////////////////////////////////////////////

Spry.Effect.Color = function(element, startColor, stopColor, options) {
    this.dynamicStartColor = false;
    if (arguments.length == 3) {
        options = stopColor;
        stopColor = startColor;
        startColor = Spry.Effect.getBgColor(element);
        this.dynamicStartColor = true;
    }

    Spry.Effect.Animator.call(this, options);

    this.name = 'Color';
    this.element = Spry.Effect.getElement(element);
    if (!this.element)
        return;

    this.startColor = startColor;
    this.stopColor = stopColor;
    this.startRedColor = Spry.Effect.Utils.hexToInt(startColor.substr(1, 2));
    this.startGreenColor = Spry.Effect.Utils.hexToInt(startColor.substr(3, 2));
    this.startBlueColor = Spry.Effect.Utils.hexToInt(startColor.substr(5, 2));
    this.stopRedColor = Spry.Effect.Utils.hexToInt(stopColor.substr(1, 2));
    this.stopGreenColor = Spry.Effect.Utils.hexToInt(stopColor.substr(3, 2));
    this.stopBlueColor = Spry.Effect.Utils.hexToInt(stopColor.substr(5, 2));
};

Spry.Effect.Color.prototype = new Spry.Effect.Animator();
Spry.Effect.Color.prototype.constructor = Spry.Effect.Color;

Spry.Effect.Color.prototype.animate = function() {
    var redColor = 0;
    var greenColor = 0;
    var blueColor = 0;
    var floor = Math.floor;
    var elapsed = this.getElapsedMilliseconds();

    if (this.direction == Spry.forwards) {
        redColor = floor(this.options.transition(elapsed, this.startRedColor, this.stopRedColor - this.startRedColor, this.options.duration));
        greenColor = floor(this.options.transition(elapsed, this.startGreenColor, this.stopGreenColor - this.startGreenColor, this.options.duration));
        blueColor = floor(this.options.transition(elapsed, this.startBlueColor, this.stopBlueColor - this.startBlueColor, this.options.duration));
    }
    else if (this.direction == Spry.backwards) {
        redColor = floor(this.options.transition(elapsed, this.stopRedColor, this.startRedColor - this.stopRedColor, this.options.duration));
        greenColor = floor(this.options.transition(elapsed, this.stopGreenColor, this.startGreenColor - this.stopGreenColor, this.options.duration));
        blueColor = floor(this.options.transition(elapsed, this.stopBlueColor, this.startBlueColor - this.stopBlueColor, this.options.duration));
    }

    this.element.style.backgroundColor = Spry.Effect.Utils.rgb(redColor, greenColor, blueColor);
};

Spry.Effect.Color.prototype.prepareStart = function() {
    if (this.options && this.options.toggle)
        this.doToggle();

    if (this.dynamicStartColor == true) {
        this.startColor = Spry.Effect.getBgColor(element);
        this.startRedColor = Spry.Effect.Utils.hexToInt(startColor.substr(1, 2));
        this.startGreenColor = Spry.Effect.Utils.hexToInt(startColor.substr(3, 2));
        this.startBlueColor = Spry.Effect.Utils.hexToInt(startColor.substr(5, 2));
        this.redColorRange = this.startRedColor - this.stopRedColor;
        this.greenColorRange = this.startGreenColor - this.stopGreenColor;
        this.blueColorRange = this.startBlueColor - this.stopBlueColor;
    }
};

//////////////////////////////////////////////////////////////////////
//
// Spry.Effect.Cluster
//
//////////////////////////////////////////////////////////////////////

Spry.Effect.Cluster = function(options) {
    Spry.Effect.Animator.call(this, options);

    this.name = 'Cluster';
    this.effectsArray = new Array();
    this.currIdx = -1;
    var _ClusteredEffect = function(effect, kind) {
        this.effect = effect;
        this.kind = kind; // "parallel" or "queue"
        this.isRunning = false;
    };

    this.ClusteredEffect = _ClusteredEffect;
};

Spry.Effect.Cluster.prototype = new Spry.Effect.Animator();
Spry.Effect.Cluster.prototype.constructor = Spry.Effect.Cluster;

Spry.Effect.Cluster.prototype.setInterval = function(interval) {
    var l = this.effectsArray.length;
    this.options.interval = interval;
    for (var i = 0; i < l; i++) {
        this.effectsArray[i].effect.setInterval(interval);
    }
};
Spry.Effect.Cluster.prototype.drawEffect = function() {
    var isRunning = true;
    var allEffectsDidRun = false;
    var baseEffectIsStillRunning = false;
    var evalNextEffectsRunning = false;

    if ((this.currIdx == -1 && this.direction == Spry.forwards) || (this.currIdx == this.effectsArray.length && this.direction == Spry.backwards))
        this.initNextEffectsRunning();

    var start = this.direction == Spry.forwards ? 0 : this.effectsArray.length - 1;
    var stop = this.direction == Spry.forwards ? this.effectsArray.length : -1;
    var step = this.direction == Spry.forwards ? 1 : -1;
    for (var i = start; i != stop; i += step) {
        if (this.effectsArray[i].isRunning == true) {
            baseEffectIsStillRunning = this.effectsArray[i].effect.drawEffect();
            if (baseEffectIsStillRunning == false && i == this.currIdx) {
                this.effectsArray[i].isRunning = false;
                evalNextEffectsRunning = true;
            }
        }
    }

    if (evalNextEffectsRunning == true)
        allEffectsDidRun = this.initNextEffectsRunning();

    if (allEffectsDidRun == true) {
        this.stop();
        isRunning = false;
        for (var i = 0; i < this.effectsArray.length; i++)
            this.effectsArray[i].isRunning = false;

        this.currIdx = this.direction == Spry.forwards ? this.effectsArray.length : -1;
    }
    return isRunning;
};

Spry.Effect.Cluster.prototype.initNextEffectsRunning = function() {
    var allEffectsDidRun = false;
    var step = this.direction == Spry.forwards ? 1 : -1;
    var stop = this.direction == Spry.forwards ? this.effectsArray.length : -1;
    this.currIdx += step;
    if ((this.currIdx > (this.effectsArray.length - 1) && this.direction == Spry.forwards) || (this.currIdx < 0 && this.direction == Spry.backwards))
        allEffectsDidRun = true;
    else
        for (var i = this.currIdx; i != stop; i += step) {
        if ((i > this.currIdx && this.direction == Spry.forwards || i < this.currIdx && this.direction == Spry.backwards) && this.effectsArray[i].kind == "queue")
            break;
        this.effectsArray[i].effect.start(true);
        this.effectsArray[i].isRunning = true;
        this.currIdx = i;
    }

    return allEffectsDidRun;
};

Spry.Effect.Cluster.prototype.toggleCluster = function() {
    if (!this.direction) {
        this.direction = Spry.forwards;
        return;
    }

    if (this.options.toggle == true) {
        if (this.direction == Spry.forwards) {
            this.direction = Spry.backwards;
            this.notifyObservers('onToggle', this);
            this.currIdx = this.effectsArray.length;
        }
        else if (this.direction == Spry.backwards) {
            this.direction = Spry.forwards;
            this.currIdx = -1;
        }
    }
    else {
        if (this.direction == Spry.forwards)
            this.currIdx = -1;
        else if (this.direction == Spry.backwards)
            this.currIdx = this.effectsArray.length;
    }
};

Spry.Effect.Cluster.prototype.doToggle = function() {
    this.toggleCluster();

    // toggle all effects of the cluster, too
    for (var i = 0; i < this.effectsArray.length; i++) {
        if (this.effectsArray[i].effect.options && (this.effectsArray[i].effect.options.toggle != null))
            if (this.effectsArray[i].effect.options.toggle == true)
            this.effectsArray[i].effect.doToggle();
    }
};

Spry.Effect.Cluster.prototype.cancel = function() {
    for (var i = 0; i < this.effectsArray.length; i++)
        if (this.effectsArray[i].effect.isRunning)
        this.effectsArray[i].effect.cancel();

    var elapsed = this.getElapsedMilliseconds();
    if (this.startMilliseconds > 0 && elapsed < this.options.duration)
        this.cancelRemaining = this.options.transition(elapsed, 0, 1, this.options.duration);
    this.stopFlagReset();
    this.notifyObservers('onCancel', this);
    this.isRunning = false;
};

Spry.Effect.Cluster.prototype.addNextEffect = function(effect) {
    effect.addObserver(this);
    this.effectsArray[this.effectsArray.length] = new this.ClusteredEffect(effect, "queue");
    if (this.effectsArray.length == 1) {
        // with the first added effect we know the element
        // that the cluster is working on
        this.element = effect.element;
    }
};

Spry.Effect.Cluster.prototype.addParallelEffect = function(effect) {
    if (this.effectsArray.length == 0 || this.effectsArray[this.effectsArray.length - 1].kind != 'parallel')
        effect.addObserver(this);

    this.effectsArray[this.effectsArray.length] = new this.ClusteredEffect(effect, "parallel");
    if (this.effectsArray.length == 1) {
        // with the first added effect we know the element
        // that the cluster is working on
        this.element = effect.element;
    }
};

Spry.Effect.Cluster.prototype.prepareStart = function() {
    this.toggleCluster();
};

//////////////////////////////////////////////////////////////////////
//
// Combination effects
// Custom effects can be build by combining basic effect bahaviour
// like Move, Size, Color, Opacity
//
//////////////////////////////////////////////////////////////////////

Spry.Effect.Fade = function(element, options) {
    if (!this.notStaticAnimator)
        return Spry.Effect.Utils.showInitError('Fade');

    Spry.Effect.Cluster.call(this, options);

    this.name = 'Fade';
    var element = Spry.Effect.getElement(element);
    this.element = element;
    if (!this.element)
        return;
    var durationInMilliseconds = 1000;
    var fromOpacity = 0.0;
    var toOpacity = 100.0;
    var doToggle = false;
    var transition = Spry.fifthTransition;
    var fps = 60;
    var originalOpacity = 0;
    if (/MSIE/.test(navigator.userAgent))
        originalOpacity = parseInt(Spry.Effect.getStylePropRegardlessOfDisplayState(this.element, 'filter').replace(/alpha\(opacity=([0-9]{1,3})\)/g, '$1'), 10);
    else
        originalOpacity = parseInt(Spry.Effect.getStylePropRegardlessOfDisplayState(this.element, 'opacity') * 100, 10);

    if (isNaN(originalOpacity))
        originalOpacity = 100;

    if (options) {
        if (options.duration != null) durationInMilliseconds = options.duration;
        if (options.from != null) {
            if (Spry.Effect.Utils.isPercentValue(options.from))
                fromOpacity = Spry.Effect.Utils.getPercentValue(options.from) * originalOpacity / 100;
            else
                fromOpacity = options.from;
        }
        if (options.to != null) {
            if (Spry.Effect.Utils.isPercentValue(options.to))
                toOpacity = Spry.Effect.Utils.getPercentValue(options.to) * originalOpacity / 100;
            else
                toOpacity = options.to;
        }
        if (options.toggle != null) doToggle = options.toggle;
        if (options.transition != null) transition = options.transition;
        if (options.fps != null) fps = options.fps;
        else this.options.transition = transition;
    }

    fromOpacity = fromOpacity / 100.0;
    toOpacity = toOpacity / 100.0;

    options = { duration: durationInMilliseconds, toggle: doToggle, transition: transition, from: fromOpacity, to: toOpacity, fps: fps };
    var fadeEffect = new Spry.Effect.Opacity(element, fromOpacity, toOpacity, options);
    this.addNextEffect(fadeEffect);
};

Spry.Effect.Fade.prototype = new Spry.Effect.Cluster();
Spry.Effect.Fade.prototype.constructor = Spry.Effect.Fade;

Spry.Effect.Blind = function(element, options) {
    if (!this.notStaticAnimator)
        return Spry.Effect.Utils.showInitError('Blind');

    Spry.Effect.Cluster.call(this, options);

    this.name = 'Blind';
    var element = Spry.Effect.getElement(element);
    this.element = element;
    if (!this.element)
        return;
    var durationInMilliseconds = 1000;
    var doToggle = false;
    var kindOfTransition = Spry.circleTransition;
    var fps = 60;
    var doScaleContent = false;

    Spry.Effect.makeClipping(element);

    var originalRect = Spry.Effect.getDimensionsRegardlessOfDisplayState(element);
    var fromHeightPx = originalRect.height;
    var toHeightPx = 0;
    var optionFrom = options ? options.from : originalRect.height;
    var optionTo = options ? options.to : 0;
    var fullCSSBox = false;


    if (options) {
        if (options.duration != null) durationInMilliseconds = options.duration;
        if (options.from != null) {
            if (Spry.Effect.Utils.isPercentValue(options.from))
                fromHeightPx = Spry.Effect.Utils.getPercentValue(options.from) * originalRect.height / 100;
            else
                fromHeightPx = Spry.Effect.Utils.getPixelValue(options.from);
        }
        if (options.to != null) {
            if (Spry.Effect.Utils.isPercentValue(options.to))
                toHeightPx = Spry.Effect.Utils.getPercentValue(options.to) * originalRect.height / 100;
            else
                toHeightPx = Spry.Effect.Utils.getPixelValue(options.to);
        }
        if (options.toggle != null) doToggle = options.toggle;
        if (options.transition != null) kindOfTransition = options.transition;
        if (options.fps != null) fps = options.fps;
        if (options.useCSSBox != null) fullCSSBox = options.useCSSBox;
    }

    var fromRect = new Spry.Effect.Utils.Rectangle;
    fromRect.width = originalRect.width;
    fromRect.height = fromHeightPx;

    var toRect = new Spry.Effect.Utils.Rectangle;
    toRect.width = originalRect.width;
    toRect.height = toHeightPx;

    options = { duration: durationInMilliseconds, toggle: doToggle, transition: kindOfTransition, scaleContent: doScaleContent, useCSSBox: fullCSSBox, from: optionFrom, to: optionTo, fps: fps };
    var blindEffect = new Spry.Effect.Size(element, fromRect, toRect, options);
    this.addNextEffect(blindEffect);
};

Spry.Effect.Blind.prototype = new Spry.Effect.Cluster();
Spry.Effect.Blind.prototype.constructor = Spry.Effect.Blind;

Spry.Effect.Highlight = function(element, options) {
    if (!this.notStaticAnimator)
        return Spry.Effect.Utils.showInitError('Highlight');

    Spry.Effect.Cluster.call(this, options);

    this.name = 'Highlight';
    var durationInMilliseconds = 1000;
    var toColor = "#ffffff";
    var doToggle = false;
    var kindOfTransition = Spry.sinusoidalTransition;
    var fps = 60;
    var element = Spry.Effect.getElement(element);
    this.element = element;
    if (!this.element)
        return;
    var fromColor = Spry.Effect.getBgColor(element);
    if (fromColor == "transparent") fromColor = "#ffff99";

    if (options) {
        if (options.duration != null) durationInMilliseconds = options.duration;
        if (options.from != null) fromColor = options.from;
        if (options.to != null) toColor = options.to;
        if (options.toggle != null) doToggle = options.toggle;
        if (options.transition != null) kindOfTransition = options.transition;
        if (options.fps != null) fps = options.fps;
    }

    if (fromColor.indexOf('rgb') != -1)
        var fromColor = Spry.Effect.Utils.rgb(parseInt(fromColor.substring(fromColor.indexOf('(') + 1, fromColor.indexOf(',')), 10), parseInt(fromColor.substring(fromColor.indexOf(',') + 1, fromColor.lastIndexOf(',')), 10), parseInt(fromColor.substring(fromColor.lastIndexOf(',') + 1, fromColor.indexOf(')')), 10));

    if (toColor.indexOf('rgb') != -1)
        var toColor = Spry.Effect.Utils.rgb(parseInt(toColor.substring(toColor.indexOf('(') + 1, toColor.indexOf(',')), 10), parseInt(toColor.substring(toColor.indexOf(',') + 1, toColor.lastIndexOf(',')), 10), parseInt(toColor.substring(toColor.lastIndexOf(',') + 1, toColor.indexOf(')')), 10));

    var fromColor = Spry.Effect.Utils.longColorVersion(fromColor);
    var toColor = Spry.Effect.Utils.longColorVersion(toColor);

    this.restoreBackgroundImage = Spry.Effect.getStyleProp(element, 'background-image');

    options = { duration: durationInMilliseconds, toggle: doToggle, transition: kindOfTransition, fps: fps };
    var highlightEffect = new Spry.Effect.Color(element, fromColor, toColor, options);
    this.addNextEffect(highlightEffect);

    this.addObserver({
        onPreEffect:
		function(effect) {
		    Spry.Effect.setStyleProp(effect.element, 'background-image', 'none');
		},
        onPostEffect:
		function(effect) {
		    Spry.Effect.setStyleProp(effect.element, 'background-image', effect.restoreBackgroundImage);

		    if (effect.direction == Spry.forwards && effect.options.restoreColor)
		        Spry.Effect.setStyleProp(element, 'background-color', effect.options.restoreColor);
		}
    });
};

Spry.Effect.Highlight.prototype = new Spry.Effect.Cluster();
Spry.Effect.Highlight.prototype.constructor = Spry.Effect.Highlight;

Spry.Effect.Slide = function(element, options) {
    if (!this.notStaticAnimator)
        return Spry.Effect.Utils.showInitError('Slide');

    Spry.Effect.Cluster.call(this, options);

    this.name = 'Slide';
    var element = Spry.Effect.getElement(element);
    this.element = element;
    if (!this.element)
        return;
    var durationInMilliseconds = 1000;
    var doToggle = false;
    var kindOfTransition = Spry.sinusoidalTransition;
    var fps = 60;
    var slideHorizontally = false;
    var firstChildElt = Spry.Effect.Utils.getFirstChildElement(element);
    var direction = -1;

    // IE 7 does not clip static positioned elements -> make element position relative
    if (/MSIE 7.0/.test(navigator.userAgent) && /Windows NT/.test(navigator.userAgent))
        Spry.Effect.makePositioned(element);

    Spry.Effect.makeClipping(element);

    // for IE 6 on win: check if position is static or fixed -> not supported and would cause trouble
    if (/MSIE 6.0/.test(navigator.userAgent) && /Windows NT/.test(navigator.userAgent)) {
        var pos = Spry.Effect.getStyleProp(element, 'position');
        if (pos && (pos == 'static' || pos == 'fixed')) {
            Spry.Effect.setStyleProp(element, 'position', 'relative');
            Spry.Effect.setStyleProp(element, 'top', '');
            Spry.Effect.setStyleProp(element, 'left', '');
        }
    }

    if (firstChildElt) {
        Spry.Effect.makePositioned(firstChildElt);
        Spry.Effect.makeClipping(firstChildElt);

        var childRect = Spry.Effect.getDimensionsRegardlessOfDisplayState(firstChildElt, element);
        Spry.Effect.setStyleProp(firstChildElt, 'width', childRect.width + 'px');
    }

    var fromDim = Spry.Effect.getDimensionsRegardlessOfDisplayState(element);

    var initDim = new Spry.Effect.Utils.Rectangle();
    var toDim = new Spry.Effect.Utils.Rectangle();
    initDim.width = toDim.width = fromDim.width;
    initDim.height = toDim.height = fromDim.height;

    if (!this.options.to) {
        if (!options)
            options = {};

        options.to = '0%';
    }

    if (options && options.horizontal !== null && options.horizontal === true)
        slideHorizontally = true;

    if (options.duration != null) durationInMilliseconds = options.duration;

    if (options.from != null) {
        if (slideHorizontally) {
            if (Spry.Effect.Utils.isPercentValue(options.from))
                fromDim.width = initDim.width * Spry.Effect.Utils.getPercentValue(options.from) / 100;
            else
                fromDim.width = Spry.Effect.Utils.getPixelValue(options.from);
        }
        else {
            if (Spry.Effect.Utils.isPercentValue(options.from))
                fromDim.height = initDim.height * Spry.Effect.Utils.getPercentValue(options.from) / 100;
            else
                fromDim.height = Spry.Effect.Utils.getPixelValue(options.from);
        }
    }

    if (options.to != null) {
        if (slideHorizontally) {
            if (Spry.Effect.Utils.isPercentValue(options.to))
                toDim.width = initDim.width * Spry.Effect.Utils.getPercentValue(options.to) / 100;
            else
                toDim.width = Spry.Effect.Utils.getPixelValue(options.to);
        }
        else {
            if (Spry.Effect.Utils.isPercentValue(options.to))
                toDim.height = initDim.height * Spry.Effect.Utils.getPercentValue(options.to) / 100;
            else
                toDim.height = Spry.Effect.Utils.getPixelValue(options.to);
        }
    }
    if (options.toggle != null) doToggle = options.toggle;
    if (options.transition != null) kindOfTransition = options.transition;
    if (options.fps != null) fps = options.fps;

    options = { duration: durationInMilliseconds, transition: kindOfTransition, scaleContent: false, toggle: doToggle, fps: fps };
    var size = new Spry.Effect.Size(element, fromDim, toDim, options);
    this.addParallelEffect(size);

    if ((fromDim.width < toDim.width && slideHorizontally) || (fromDim.height < toDim.height && !slideHorizontally))
        direction = 1;

    var fromPos = new Spry.Effect.Utils.Position();
    var toPos = new Spry.Effect.Utils.Position();
    toPos.x = fromPos.x = Spry.Effect.intPropStyle(firstChildElt, 'left');
    toPos.y = fromPos.y = Spry.Effect.intPropStyle(firstChildElt, 'top');
    toPos.units = fromPos.units;

    if (slideHorizontally)
        toPos.x = parseInt(fromPos.x + direction * (fromDim.width - toDim.width), 10);
    else
        toPos.y = parseInt(fromPos.y + direction * (fromDim.height - toDim.height), 10);

    if (direction == 1) {
        var tmp = fromPos;
        var fromPos = toPos;
        var toPos = tmp;
    }

    options = { duration: durationInMilliseconds, transition: kindOfTransition, toggle: doToggle, from: fromPos, to: toPos, fps: fps };
    var move = new Spry.Effect.Move(firstChildElt, fromPos, toPos, options);
    this.addParallelEffect(move);
};

Spry.Effect.Slide.prototype = new Spry.Effect.Cluster();
Spry.Effect.Slide.prototype.constructor = Spry.Effect.Slide;

Spry.Effect.Grow = function(element, options) {
    if (!element)
        return;
    if (!this.notStaticAnimator)
        return Spry.Effect.Utils.showInitError('Grow');

    Spry.Effect.Cluster.call(this, options);

    this.name = 'Grow';
    var durationInMilliseconds = 1000;
    var doToggle = false;
    var doScaleContent = true;
    var calcHeight = false;
    var growFromCenter = true;
    var fullCSSBox = false;
    var kindOfTransition = Spry.squareTransition;
    var fps = 60;
    var element = Spry.Effect.getElement(element);
    this.element = element;
    if (!this.element)
        return;

    Spry.Effect.makeClipping(element);

    var dimRect = Spry.Effect.getDimensionsRegardlessOfDisplayState(element);
    var originalWidth = dimRect.width;
    var originalHeight = dimRect.height;
    var propFactor = (originalWidth == 0) ? 1 : originalHeight / originalWidth;

    var fromRect = new Spry.Effect.Utils.Rectangle;
    fromRect.width = 0;
    fromRect.height = 0;

    var toRect = new Spry.Effect.Utils.Rectangle;
    toRect.width = originalWidth;
    toRect.height = originalHeight;

    var optionFrom = options ? options.from : dimRect.width;
    var optionTo = options ? options.to : 0;
    var pixelValue = Spry.Effect.Utils.getPixelValue;

    if (options) {
        if (options.growCenter != null) growFromCenter = options.growCenter;
        if (options.duration != null) durationInMilliseconds = options.duration;
        if (options.useCSSBox != null) fullCSSBox = options.useCSSBox;
        if (options.scaleContent != null) doScaleContent = options.scaleContent;
        if (options.from != null) {
            if (Spry.Effect.Utils.isPercentValue(options.from)) {
                fromRect.width = originalWidth * (Spry.Effect.Utils.getPercentValue(options.from) / 100);
                fromRect.height = originalHeight * (Spry.Effect.Utils.getPercentValue(options.from) / 100);
            }
            else {
                if (calcHeight) {
                    fromRect.height = pixelValue(options.from);
                    fromRect.width = pixelValue(options.from) / propFactor;
                }
                else {
                    fromRect.width = pixelValue(options.from);
                    fromRect.height = propFactor * pixelValue(options.from);
                }
            }
        }
        if (options.to != null) {
            if (Spry.Effect.Utils.isPercentValue(options.to)) {
                toRect.width = originalWidth * (Spry.Effect.Utils.getPercentValue(options.to) / 100);
                toRect.height = originalHeight * (Spry.Effect.Utils.getPercentValue(options.to) / 100);
            }
            else {
                if (calcHeight) {
                    toRect.height = pixelValue(options.to);
                    toRect.width = pixelValue(options.to) / propFactor;
                }
                else {
                    toRect.width = pixelValue(options.to);
                    toRect.height = propFactor * pixelValue(options.to);
                }
            }
        }
        if (options.toggle != null) doToggle = options.toggle;
        if (options.transition != null) kindOfTransition = options.transition;
        if (options.fps != null) fps = options.fps;
    }

    options = { duration: durationInMilliseconds, toggle: doToggle, transition: kindOfTransition, scaleContent: doScaleContent, useCSSBox: fullCSSBox, fps: fps };
    var sizeEffect = new Spry.Effect.Size(element, fromRect, toRect, options);
    this.addParallelEffect(sizeEffect);

    if (growFromCenter) {
        Spry.Effect.makePositioned(element);

        var startOffsetPosition = new Spry.Effect.Utils.Position();
        startOffsetPosition.x = parseInt(Spry.Effect.getStylePropRegardlessOfDisplayState(element, "left"), 10);
        startOffsetPosition.y = parseInt(Spry.Effect.getStylePropRegardlessOfDisplayState(element, "top"), 10);
        if (!startOffsetPosition.x) startOffsetPosition.x = 0;
        if (!startOffsetPosition.y) startOffsetPosition.y = 0;

        options = { duration: durationInMilliseconds, toggle: doToggle, transition: kindOfTransition, from: optionFrom, to: optionTo, fps: fps };
        var fromPos = new Spry.Effect.Utils.Position;
        fromPos.x = startOffsetPosition.x + (originalWidth - fromRect.width) / 2.0;
        fromPos.y = startOffsetPosition.y + (originalHeight - fromRect.height) / 2.0;

        var toPos = new Spry.Effect.Utils.Position;
        toPos.x = startOffsetPosition.x + (originalWidth - toRect.width) / 2.0;
        toPos.y = startOffsetPosition.y + (originalHeight - toRect.height) / 2.0;

        var moveEffect = new Spry.Effect.Move(element, fromPos, toPos, options);
        this.addParallelEffect(moveEffect);
    }
};

Spry.Effect.Grow.prototype = new Spry.Effect.Cluster();
Spry.Effect.Grow.prototype.constructor = Spry.Effect.Grow;

Spry.Effect.Shake = function(element, options) {
    if (!this.notStaticAnimator)
        return Spry.Effect.Utils.showInitError('Shake');

    Spry.Effect.Cluster.call(this, options);

    // toggle is not supported
    this.options.direction = false;
    if (this.options.toggle)
        this.options.toggle = false;

    this.name = 'Shake';

    var element = Spry.Effect.getElement(element);
    this.element = element;
    if (!this.element)
        return;
    var durationInMilliseconds = 100;
    var kindOfTransition = Spry.linearTransition;
    var fps = 60;
    var steps = 4;

    if (options) {
        if (options.duration != null) steps = Math.ceil(this.options.duration / durationInMilliseconds) - 1;
        if (options.fps != null) fps = options.fps;
        if (options.transition != null) kindOfTransition = options.transition;
    }

    Spry.Effect.makePositioned(element);

    var startOffsetPosition = new Spry.Effect.Utils.Position();
    startOffsetPosition.x = parseInt(Spry.Effect.getStyleProp(element, "left"), 10);
    startOffsetPosition.y = parseInt(Spry.Effect.getStyleProp(element, "top"), 10);
    if (!startOffsetPosition.x) startOffsetPosition.x = 0;
    if (!startOffsetPosition.y) startOffsetPosition.y = 0;

    var centerPos = new Spry.Effect.Utils.Position;
    centerPos.x = startOffsetPosition.x;
    centerPos.y = startOffsetPosition.y;

    var rightPos = new Spry.Effect.Utils.Position;
    rightPos.x = startOffsetPosition.x + 20;
    rightPos.y = startOffsetPosition.y + 0;

    var leftPos = new Spry.Effect.Utils.Position;
    leftPos.x = startOffsetPosition.x + -20;
    leftPos.y = startOffsetPosition.y + 0;

    options = { duration: Math.ceil(durationInMilliseconds / 2), toggle: false, fps: fps, transition: kindOfTransition };
    var effect = new Spry.Effect.Move(element, centerPos, rightPos, options);
    this.addNextEffect(effect);

    options = { duration: durationInMilliseconds, toggle: false, fps: fps, transition: kindOfTransition };
    var effectToRight = new Spry.Effect.Move(element, rightPos, leftPos, options);
    var effectToLeft = new Spry.Effect.Move(element, leftPos, rightPos, options);

    for (var i = 0; i < steps; i++) {
        if (i % 2 == 0)
            this.addNextEffect(effectToRight);
        else
            this.addNextEffect(effectToLeft);
    }
    var pos = (steps % 2 == 0) ? rightPos : leftPos;

    options = { duration: Math.ceil(durationInMilliseconds / 2), toggle: false, fps: fps, transition: kindOfTransition };
    var effect = new Spry.Effect.Move(element, pos, centerPos, options);
    this.addNextEffect(effect);
};
Spry.Effect.Shake.prototype = new Spry.Effect.Cluster();
Spry.Effect.Shake.prototype.constructor = Spry.Effect.Shake;
Spry.Effect.Shake.prototype.doToggle = function() { };

Spry.Effect.Squish = function(element, options) {
    if (!this.notStaticAnimator)
        return Spry.Effect.Utils.showInitError('Squish');

    if (!options)
        options = {};
    if (!options.to)
        options.to = '0%';
    if (!options.from)
        options.from = '100%';

    options.growCenter = false;
    Spry.Effect.Grow.call(this, element, options);
    this.name = 'Squish';
};
Spry.Effect.Squish.prototype = new Spry.Effect.Grow();
Spry.Effect.Squish.prototype.constructor = Spry.Effect.Squish;

Spry.Effect.Pulsate = function(element, options) {
    if (!this.notStaticAnimator)
        return Spry.Effect.Utils.showInitError('Pulsate');

    Spry.Effect.Cluster.call(this, options);

    // toggle is not supported
    this.options.direction = false;
    if (this.options.toggle)
        this.options.toggle = false;

    var element = Spry.Effect.getElement(element);
    var originalOpacity = 0;
    this.element = element;
    if (!this.element)
        return;

    this.name = 'Pulsate';
    var durationInMilliseconds = 100;
    var fromOpacity = 100.0;
    var toOpacity = 0.0;
    var doToggle = false;
    var kindOfTransition = Spry.linearTransition;
    var fps = 60;
    if (/MSIE/.test(navigator.userAgent))
        originalOpacity = parseInt(Spry.Effect.getStylePropRegardlessOfDisplayState(this.element, 'filter').replace(/alpha\(opacity=([0-9]{1,3})\)/g, '$1'), 10);
    else
        originalOpacity = parseInt(Spry.Effect.getStylePropRegardlessOfDisplayState(this.element, 'opacity') * 100, 10);

    if (isNaN(originalOpacity)) {
        originalOpacity = 100;
    }

    if (options) {
        if (options.from != null) {
            if (Spry.Effect.Utils.isPercentValue(options.from))
                fromOpacity = Spry.Effect.Utils.getPercentValue(options.from) * originalOpacity / 100;
            else
                fromOpacity = options.from;
        }
        if (options.to != null) {
            if (Spry.Effect.Utils.isPercentValue(options.to))
                toOpacity = Spry.Effect.Utils.getPercentValue(options.to) * originalOpacity / 100;
            else
                toOpacity = options.to;
        }
        if (options.transition != null) kindOfTransition = options.transition;
        if (options.fps != null) fps = options.fps;
    }

    options = { duration: durationInMilliseconds, toggle: doToggle, transition: kindOfTransition, fps: fps };
    fromOpacity = fromOpacity / 100.0;
    toOpacity = toOpacity / 100.0;

    var fadeEffect = new Spry.Effect.Opacity(element, fromOpacity, toOpacity, options);
    var appearEffect = new Spry.Effect.Opacity(element, toOpacity, fromOpacity, options);
    var steps = parseInt(this.options.duration / 200, 10);
    for (var i = 0; i < steps; i++) {
        this.addNextEffect(fadeEffect);
        this.addNextEffect(appearEffect);
    }
};
Spry.Effect.Pulsate.prototype = new Spry.Effect.Cluster();
Spry.Effect.Pulsate.prototype.constructor = Spry.Effect.Pulsate;
Spry.Effect.Pulsate.prototype.doToggle = function() { };

Spry.Effect.Puff = function(element, options) {
    if (!this.notStaticAnimator)
        return Spry.Effect.Utils.showInitError('Puff');

    Spry.Effect.Cluster.call(this, options);

    var element = Spry.Effect.getElement(element);
    this.element = element;
    if (!this.element)
        return;
    this.name = 'Puff';
    var doToggle = false;
    var doScaleContent = false;
    var durationInMilliseconds = 1000;
    var kindOfTransition = Spry.fifthTransition;
    var fps = 60;

    Spry.Effect.makePositioned(element); // for move

    if (options) {
        if (options.toggle != null) doToggle = options.toggle;
        if (options.duration != null) durationInMilliseconds = options.duration;
        if (options.transition != null) kindOfTransition = options.transition;
        if (options.fps != null) fps = options.fps;
    }
    var originalRect = Spry.Effect.getDimensions(element);
    var startWidth = originalRect.width;
    var startHeight = originalRect.height;

    options = { duration: durationInMilliseconds, toggle: doToggle, transition: kindOfTransition, fps: fps };

    var fromOpacity = 1.0;
    var toOpacity = 0.0;
    var opacityEffect = new Spry.Effect.Opacity(element, fromOpacity, toOpacity, options);
    this.addParallelEffect(opacityEffect);

    var fromPos = Spry.Effect.getPosition(element);

    var toPos = new Spry.Effect.Utils.Position;
    toPos.x = startWidth / 2.0 * -1.0;
    toPos.y = startHeight / 2.0 * -1.0;

    options = { duration: durationInMilliseconds, toggle: doToggle, transition: kindOfTransition, from: fromPos, to: toPos, fps: fps };
    var moveEffect = new Spry.Effect.Move(element, fromPos, toPos, options);
    this.addParallelEffect(moveEffect);

    var self = this;
    this.addObserver({
        onPreEffect: function() { if (self.direction == Spry.backwards) { self.element.style.display = 'block'; } },
        onPostEffect: function() { if (self.direction == Spry.forwards) { self.element.style.display = 'none'; } }
    });
};
Spry.Effect.Puff.prototype = new Spry.Effect.Cluster;
Spry.Effect.Puff.prototype.constructor = Spry.Effect.Puff;

Spry.Effect.DropOut = function(element, options) {
    if (!this.notStaticAnimator)
        return Spry.Effect.Utils.showInitError('DropOut');

    Spry.Effect.Cluster.call(this, options);

    var element = Spry.Effect.getElement(element);
    this.element = element;
    if (!this.element)
        return;
    var durationInMilliseconds = 1000;
    var fps = 60;
    var kindOfTransition = Spry.fifthTransition;
    var direction = Spry.forwards;
    var doToggle = false;
    this.name = 'DropOut';

    Spry.Effect.makePositioned(element);

    if (options) {
        if (options.duration != null) durationInMilliseconds = options.duration;
        if (options.toggle != null) doToggle = options.toggle;
        if (options.fps != null) fps = options.fps;
        if (options.transition != null) kindOfTransition = options.transition;
        if (options.dropIn != null) direction = -1;
    }

    var startOffsetPosition = new Spry.Effect.Utils.Position();
    startOffsetPosition.x = parseInt(Spry.Effect.getStyleProp(element, "left"), 10);
    startOffsetPosition.y = parseInt(Spry.Effect.getStyleProp(element, "top"), 10);
    if (!startOffsetPosition.x) startOffsetPosition.x = 0;
    if (!startOffsetPosition.y) startOffsetPosition.y = 0;

    var fromPos = new Spry.Effect.Utils.Position;
    fromPos.x = startOffsetPosition.x + 0;
    fromPos.y = startOffsetPosition.y + 0;

    var toPos = new Spry.Effect.Utils.Position;
    toPos.x = startOffsetPosition.x + 0;
    toPos.y = startOffsetPosition.y + (direction * 160);

    options = { from: fromPos, to: toPos, duration: durationInMilliseconds, toggle: doToggle, transition: kindOfTransition, fps: fps };
    var moveEffect = new Spry.Effect.Move(element, options.from, options.to, options);
    this.addParallelEffect(moveEffect);

    var fromOpacity = 1.0;
    var toOpacity = 0.0;
    options = { duration: durationInMilliseconds, toggle: doToggle, transition: kindOfTransition, fps: fps };
    var opacityEffect = new Spry.Effect.Opacity(element, fromOpacity, toOpacity, options);
    this.addParallelEffect(opacityEffect);

    var self = this;
    this.addObserver({
        onPreEffect: function() { self.element.style.display = 'block'; },
        onPostEffect: function() { if (self.direction == Spry.forwards) { self.element.style.display = 'none'; } }
    });

};
Spry.Effect.DropOut.prototype = new Spry.Effect.Cluster();
Spry.Effect.DropOut.prototype.constructor = Spry.Effect.DropOut;

Spry.Effect.Fold = function(element, options) {
    if (!this.notStaticAnimator)
        return Spry.Effect.Utils.showInitError('Fold');

    Spry.Effect.Cluster.call(this, options);

    var element = Spry.Effect.getElement(element);
    this.element = element;
    if (!this.element)
        return;
    this.name = 'Fold';
    var durationInMilliseconds = 1000;
    var doToggle = false;
    var doScaleContent = true;
    var fullCSSBox = false;
    var kindOfTransition = Spry.fifthTransition;
    var fps = fps;

    Spry.Effect.makeClipping(element);

    var originalRect = Spry.Effect.getDimensionsRegardlessOfDisplayState(element);
    var startWidth = originalRect.width;
    var startHeight = originalRect.height;

    var stopWidth = startWidth;
    var stopHeight = startHeight / 5;

    var fromRect = new Spry.Effect.Utils.Rectangle;
    fromRect.width = startWidth;
    fromRect.height = startHeight;

    var toRect = new Spry.Effect.Utils.Rectangle;
    toRect.width = stopWidth;
    toRect.height = stopHeight;

    if (options) {
        if (options.duration != null) durationInMilliseconds = Math.ceil(options.duration / 2);
        if (options.toggle != null) doToggle = options.toggle;
        if (options.useCSSBox != null) fullCSSBox = options.useCSSBox;
        if (options.fps != null) fps = options.fps;
        if (options.transition != null) kindOfTransition = options.transition;
    }

    options = { duration: durationInMilliseconds, toggle: doToggle, scaleContent: doScaleContent, useCSSBox: fullCSSBox, transition: kindOfTransition, fps: fps };
    var sizeEffect = new Spry.Effect.Size(element, fromRect, toRect, options);
    this.addNextEffect(sizeEffect);

    fromRect.width = toRect.width;
    fromRect.height = toRect.height;
    toRect.width = '0%';
    var sizeEffect = new Spry.Effect.Size(element, fromRect, toRect, options);
    this.addNextEffect(sizeEffect);
};

Spry.Effect.Fold.prototype = new Spry.Effect.Cluster();
Spry.Effect.Fold.prototype.constructor = Spry.Effect.Fold;

//////////////////////////////////////////////////////////////
// 																													//
// The names of some of the static effect functions 		 		//
// changed in Spry 1.5. These wrappers will insure that we 	//
// remain compatible with previous versions of Spry.				//
// 																													//
//////////////////////////////////////////////////////////////

Spry.Effect.DoFade = function(element, options) {
    return Spry.Effect.Utils.DoEffect('Fade', element, options);
};

Spry.Effect.DoBlind = function(element, options) {
    return Spry.Effect.Utils.DoEffect('Blind', element, options);
};

Spry.Effect.DoHighlight = function(element, options) {
    return Spry.Effect.Utils.DoEffect('Highlight', element, options);
};

Spry.Effect.DoSlide = function(element, options) {
    return Spry.Effect.Utils.DoEffect('Slide', element, options);
};

Spry.Effect.DoGrow = function(element, options) {
    return Spry.Effect.Utils.DoEffect('Grow', element, options);
};

Spry.Effect.DoShake = function(element, options) {
    return Spry.Effect.Utils.DoEffect('Shake', element, options);
};

Spry.Effect.DoSquish = function(element, options) {
    return Spry.Effect.Utils.DoEffect('Squish', element, options);
};

Spry.Effect.DoPulsate = function(element, options) {
    return Spry.Effect.Utils.DoEffect('Pulsate', element, options);
};

Spry.Effect.DoPuff = function(element, options) {
    return Spry.Effect.Utils.DoEffect('Puff', element, options);
};

Spry.Effect.DoDropOut = function(element, options) {
    return Spry.Effect.Utils.DoEffect('DropOut', element, options);
};

Spry.Effect.DoFold = function(element, options) {
    return Spry.Effect.Utils.DoEffect('Fold', element, options);
};

/*********** Begin D:\SVN\iSport.com\WorkingSourceCode_JIRA\Scripts\fadeout.js *****************/
var slideInUse = new Array();

function Slide(objId, options) {
    this.obj = document.getElementById(objId);
    this.duration = 1;
    this.height = parseInt(this.obj.style.height);

    if (typeof options != 'undefined') { this.options = options; } else { this.options = {}; }
    if (this.options.duration) { this.duration = this.options.duration; }

    this.up = function() {
        this.curHeight = this.height;
        this.newHeight = '1';
        if (slideInUse[objId] != true) {
            var finishTime = this.slide();
            window.setTimeout("Slide('" + objId + "').finishup(" + this.height + ");", finishTime);
        }
    }

    this.down = function() {
        this.newHeight = this.height;
        this.curHeight = '1';
        if (slideInUse[objId] != true) {
            this.obj.style.height = '1px';
            this.obj.style.display = 'block';
            this.slide();
        }
    }

    // for effect from bottom to top
    this.up2 = function() {
        this.curHeight = '1';
        this.newHeight = this.height;

        if (slideInUse[objId] != true) {
            show('divCountryListFooterGroup');
            this.obj.style.display = 'block';
            this.slide2();
        }
    }

    this.down2 = function() {
        this.newHeight = '1';
        this.curHeight = this.height;

        if (slideInUse[objId] != true) {
            var finishTime = this.slide2();
            window.setTimeout("Slide('" + objId + "').finishup(" + this.height + ");hide('divCountryListFooterGroup');", finishTime);
            //this.obj.style.height = '1px';
            //this.obj.style.display = 'none';

        }
    }

    this.down3 = function(fnGetHeight) {
        this.curHeight = '1';
        if (slideInUse[objId] != true) {
            this.obj.style.height = '1px';
            this.obj.style.display = 'block';
            this.newHeight = fnGetHeight();
            //alert(this.newHeight);
            this.slide();
        }
    }

    this.slide = function() {
        slideInUse[objId] = true;
        var frames = 30 * duration; // Running at 30 fps

        var tIncrement = (duration * 500) / frames; //(duration*1000) / frames;
        tIncrement = Math.round(tIncrement);
        var sIncrement = (this.curHeight - this.newHeight) / frames;

        var frameSizes = new Array();
        for (var i = 0; i < frames; i++) {
            if (i < frames / 2) {
                frameSizes[i] = (sIncrement * (i / frames)) * 4;
            } else {
                frameSizes[i] = (sIncrement * (1 - (i / frames))) * 4;
            }
        }

        for (var i = 0; i < frames; i++) {
            this.curHeight = this.curHeight - frameSizes[i];
            window.setTimeout("document.getElementById('" + objId + "').style.height='" + Math.round(this.curHeight) + "px';", tIncrement * i);
        }

        window.setTimeout("delete(slideInUse['" + objId + "']);", tIncrement * i);

        if (this.options.onComplete) {
            window.setTimeout(this.options.onComplete, tIncrement * (i - 2));
        }

        return tIncrement * i;
    }

    // slide from bottom to top
    this.slide2 = function() {
        slideInUse[objId] = true;
        var frames = 30 * duration; // Running at 30 fps

        var tIncrement = (duration * 500) / frames; //(duration*1000) / frames;
        tIncrement = Math.round(tIncrement);
        var sIncrement = (this.curHeight - this.newHeight) / frames;

        var frameSizes = new Array();
        for (var i = 0; i < frames; i++) {
            if (i < frames / 2) {
                frameSizes[i] = (sIncrement * (i / frames)) * 4;
            } else {
                frameSizes[i] = (sIncrement * (1 - (i / frames))) * 4;
            }
        }
        //alert('ok');
        for (var i = 0; i < frames; i++) {
            this.curHeight = this.curHeight - frameSizes[i];
            //window.setTimeout("document.getElementById('"+objId+"').style.height='"+Math.round(this.curHeight)+"px';",tIncrement * i);
            window.setTimeout("document.getElementById('" + objId + "').style.marginTop='-" + Math.round(this.curHeight) + "px';", tIncrement * i);

        }

        window.setTimeout("delete(slideInUse['" + objId + "']);", tIncrement * i);

        if (this.options.onComplete) {
            window.setTimeout(this.options.onComplete, tIncrement * (i - 2));
        }

        return tIncrement * i;
    }

    this.finishup = function(height) {
        this.obj.style.display = 'none';
        this.obj.style.height = height + 'px';
    }

    return this;
}

/*********** For login *****************/
var tempForm;
function submitForm() {
    if (checkValidString('s_Email') && checkValidString('s_Password')) {
        tempForm.submit();
    }
}
function loginEnter(e, form) {
    f = form;
    tempForm = form;

    handleEnterKey(e, submitForm);
}

function submitForm1() {
    if (checkValidString('s_Email1') && checkValidString('s_Password1')) {
        tempForm.submit();
    }
}

function checkValidString(txtId) {
    var txt = document.getElementById(txtId);

    if ((txt == null) || (txt.value == null)) {
        return false;
    }
    else {
        if (txt.value.indexOf("<") != -1) {
            Show_Alert_MSG(txtId, 0, 0, 'Please enter a valid string.');
            return false;
        }
        return true;
    }
}

/*********** Begin D:\SVN\iSport.com\WorkingSourceCode_JIRA\Scripts\slider.j *****************/
var fadeInterval;

var fade = {
    step: 18,
    speed: 0.1,
    finalOpacity: 30,
    currentOpacity: 100,
    absolute: true,
    elID: null,

    doFade: function(obj) {
        obj = document.getElementById(fade.elID);
        if (fade.step > 0 && (fade.currentOpacity - fade.step > fade.finalOpacity)) {
            var newOpacity = fade.currentOpacity - fade.step;
            if (newOpacity < 10) newOpacity = '0' + newOpacity;
            obj.style.opacity = "." + (newOpacity);
            obj.style.filter = "alpha(opacity=" + newOpacity + ")";
            fade.currentOpacity = newOpacity;
        }
        else if (fade.step < 0 && (fade.currentOpacity - fade.step < fade.finalOpacity)) {
            var newOpacity = fade.currentOpacity - fade.step;
            if (newOpacity < 10) newOpacity = '0' + newOpacity;
            obj.style.opacity = "." + (newOpacity);
            obj.style.filter = "alpha(opacity=" + newOpacity + ")";
            fade.currentOpacity = newOpacity;
        }
        else {
            var newOpacity = fade.finalOpacity;
            if (newOpacity < 10) newOpacity = '0' + newOpacity;
            obj.style.opacity = "." + (newOpacity);
            obj.style.filter = "alpha(opacity=" + newOpacity + ")";
            fade.currentOpacity = newOpacity;
            clearInterval(fadeInterval);
            if (fade.step > 0) {
                obj.style.display = 'none';
            }
        }
    },
    init: function(el) {
        fade.elID = el;
        if (arguments.length > 1) {
            fade.currentOpacity = arguments[1];
            fade.finalOpacity = arguments[2];
            fade.speed = arguments[3];
            if (fade.currentOpacity < fade.finalOpacity) {
                fade.step *= -1;
            }
        }
        if (arguments.length > 4)
            fade.step = arguments[4];

        if (!document.getElementById(el)) return;

        obj = document.getElementById(fade.elID);
        obj.style.position = (fade.absolute ? 'absolute' : obj.style.position);
        //alert(fade.absolute);
        //alert(obj.style.position);
        fade.doFade();
        obj.style.display = '';

        if (arguments.length > 5) {
            fade.centerScreen(obj);
        }


        fadeInterval = setInterval('fade.doFade()', fade.speed);


    },
    centerScreen: function(obj) {
        var scrollY;
        var w = obj.offsetWidth;
        var h = obj.offsetHeight;

        switch (navigator.appName) {
            case 'Microsoft Internet Explorer':
                var myregex = /MSIE 7\.0/i;
                var myArray = navigator.appVersion.match(myregex);
                if (myArray.length > 0)
                    scrollY = document.documentElement.scrollTop;
                else
                    scrollY = document.body.scrollTop;
                break;
            default:
                scrollY = window.pageYOffset;
        }

        obj.style.top = scrollY + screen.height / 2 - h + 'px';
        obj.style.left = screen.width / 2 - w + 'px';

    },
    stepShow: 7,
    show: function(divID) {
        fade.absolute = false;
        fade.init(divID, 1, 99, 20, -1 * fade.stepShow);
        fade.absolute = true;
    },
    hide: function(divID) {
        fade.absolute = false;
        fade.init(divID, 99, 1, 20, fade.stepShow);
        fade.absolute = true;
    }
}