﻿function showText(id, text) {
   /* try
    {
        if ($("#" + id).attr("value").length == 0) {
            $("#" + id).attr("value", text);
        }
    }
    catch(err){}*/
}

function removeText(id, text) {
   /* try {
        if ($("#" + id).attr("value") == text) {
            $("#" + id).attr("value", "");
        }
    }
    catch(err) { }*/
}

function changeImage(strImage, time, step, id, path) {
    var images = strImage.split("|");
    if (images.length > 1) {
        for (i = 0; i < images.length; i++) {
            if (step == i) {
                var values = images[i].split(",");
                $("#a_banner_" + id).attr({ style: "cursor:pointer;background:url(" + path + values[0] + ") no-repeat 0 0;" });
                $("#li_banner_" + id).attr({ style: "width:" + values[1] + "px;" });
                $("#ul_banner_" + id).attr({ style: "width:" + values[1] + "px;" });                
            }
        }
    }
    else {
        var values = strImage.split(",");
        $("#a_banner_" + id).attr({ style: "cursor:pointer;background:url(" + path + values[0] + ") no-repeat 0 0;" });
        $("#li_banner_" + id).attr({ style: "width:" + values[1] + "px;" });
        $("#ul_banner_" + id).attr({ style: "width:" + values[1] + "px;" });        
    }
    step++;

    if (step > images.length) {
        step = 0;
    }

    if (time != 0) {
        t = setTimeout("changeImage('" + strImage + "'," + time + "," + step + "," + id + ",'" + path + "')", time);
    }
}


function changeGroupImage(id, time, width, path, images, index, imageIndex) {
    var guid = "";
    for (var i = 0; i < 32; i++) {
        guid += parseInt(Math.random() * 16).toString(16);
    }

    //alert("Start - changeGroupImage(" + id + "," + time + "," + width + ",'" + path + "','" + images + "'," + index + "," + imageIndex + ")");
    
    var imagesArr = images.split("|");
    
    for (i = 0; i < imagesArr.length; i++) {
        if (index == i) {
            var values = imagesArr[i].split(",");
            for (j = 0; j < values.length; j++) {
                if (j == imageIndex) {
                    //$("#speaker_img_" + index).attr({ src: path + values[imageIndex] + "&guid=" + guid });
                    $("#speaker_img_" + index).attr({ src: path + values[imageIndex]});
                    break;
                }
            }
            imageIndex++;
            if (imageIndex > values.length-1) {
                imageIndex = 0;
            }
            
            break;
        }
    }
    
    //alert("End - changeGroupImage(" + id + "," + time + "," + width + ",'" + path + "','" + images + "'," + index + "," + imageIndex + ")");
    
    $("#li_banner_" + id).attr({ style: "width:" + width + "px;" });
    $("#ul_banner_" + id).attr({ style: "width:" + width + "px;" });
    
    if (time != 0) {
        t = setTimeout("changeGroupImage(" + id + "," + time + "," + width + ",'" + path + "','" + images + "'," + index + "," + imageIndex + ")", time);
    }
}


function submitOnEnter(e, button) {
    var c = e.which ? e.which : e.keyCode;
    if (c == 13) {
        $("#" + button).focus();
        $("#" + button).click();
    }
    return true;
}

function changeSponsorsLogo(images, time, steps, maxSteps) {
    
    var imagesArr = images.split("|");
    var stepsArr = steps.split("|");
    var maxStepsArr = maxSteps.split("|");
    var strStep = "";
    for (i = 0; i < imagesArr.length; i++) {
        var values = imagesArr[i].split(",");
        var step = stepsArr[i];
        var maxStep = maxStepsArr[i];
        
        if (step <= (maxStep - 1) ) {
            var hrefData = values[step].split("$");
            //$("#sponsors_img_" + (i + 1)).attr({ src: hrefData[0]});
            $("#sponsors_a_" + (i + 1)).attr({ style: "background:url(" + hrefData[0] + ") no-repeat 0 0;width:" + hrefData[2] });
            if (hrefData[1] != null) {
                if (hrefData[1].length > 0) {
                    $("#sponsors_a_" + (i + 1)).attr({ href: hrefData[1] });
                }
                else {
                    $("#sponsors_a_" + (i + 1)).removeAttr("href");                    
                }
            }
            step++;
        }
        if (step > (maxStep - 1)) {
            step = 0;
        }        
        strStep += step + "|";
    }
    strStep = strStep.substring(0, strStep.length - 1);
    
    if (time != 0) {
        t = setTimeout("changeSponsorsLogo('" + images + "'," + time + ",'" + strStep + "','" + maxSteps + "')", time);
    }

}

function changeSponsorsLogoById(images, time, step, maxStep, Id) {
    var values = images.split(",");
    if (step <= (maxStep - 1)) 
    {
        var hrefData = values[step].split("$");
        $("#sponsors_a_" + Id).attr({ style: "background:url(" + hrefData[0] + ") no-repeat 0 0;width:" + hrefData[2] });
        if (hrefData[1] != null) 
        {
            if (hrefData[1].length > 0) 
            {
                $("#sponsors_a_" + Id).attr({ href: hrefData[1] });
            }
            else 
            {
                $("#sponsors_a_" + Id).removeAttr("href");
            }
        }
        step++;
    }
    
    if (step > (maxStep - 1)) 
    {
        step = 0;
    }
        
    if (time != 0) {
        t = setTimeout("changeSponsorsLogoById('" + images + "'," + time + ",'" + step + "','" + maxStep + "','" + Id + "')", time);
    }

}
