            /* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function prevPage(){    
    document.getElementById('pageIndex').value--;
    document.getElementById('frmPage').submit();
}
function nextPage(){    
    document.getElementById('pageIndex').value++;
    document.getElementById('frmPage').submit();
}
function goToPage(p){    
    document.getElementById('pageIndex').value = p;
    document.getElementById('frmPage').submit();
}
function clearSearch(inObj, text){
    if (inObj.value == text)
        inObj.value = "";
}
function restoreSearch(inObj, text){
    if (inObj.value == "")
        inObj.value = text;
}


function submitSongSearch(form){
    //$(form).
    //$(form + ' hidden.offset').val(3);
    alert(form);
}
/**
 * Form validation
 */
function validate_email(field, alerttxt){
    with (field){
        apos=value.indexOf("@");
        dotpos=value.lastIndexOf(".");
        if (apos<1||dotpos-apos<2){
            alert(alerttxt);
            return false;
        }
        else {
            return true;
        }
        }
}
function validate_search_form(thisform){
    with (thisform){
        if ((search_input.value == 'search mixes') || (search_input.value == ''))
            return false;
        else
            return true;

    }
}
function validate_form(thisform){
    with (thisform){
        if (validate_email(email,"Not a valid e-mail address!")==false){
            email.style.border = "2px solid #DF6300";
            email.style.bgColor = "#F7DAD8";
            email.focus();
            return false;
        }
        }
}

/**
 * Sharing link
 */

function shareMix(domain, songId, songName){
    var url = "";
    switch(domain){
        case "FB":
            url = "http://facebook.com/share.php?title="+ songName +"&u=http://www.romplr.com/pages/media?id=" + songId;            
            window.open(url);
            break;
        case "TW":
            url = "http://twitter.com/home?status=Currently listening to http://www.romplr.com/pages/media?id=" + songId;
            window.open(url);
            break;
        case "MS":
            url = "http://www.myspace.com/index.cfm?fuseaction=postto&t=Currently listening&c="+songName+"&u=http://www.romplr.com/pages/media?id=" + songId;
            window.open(url);
            //url = "<a href="http://www.myspace.com/index.cfm?fuseaction=postto&t=CONTENT-TITLE&c=CONTENTS&u=CONTENT-URL&l=">Share with Facebook</a>";
            break;
        case "DG":
            url = "http://digg.com/submit?url=http://www.romplr.com/pages/media?id=" + songId;
            window.open(url);
            break;
        case "DL":
            url = "http://del.icio.us/post?url=http://www.romplr.com/pages/media?id=" + songId + "&title=" + songName;
            window.open(url);
            break;
    }

    return false;
}

function byId(id) {
    return document.getElementById(id);
}

function slideNext() {
    if(autoRotate) {
        autoRotate = false;
        clearTimeout(sTimer);
        setTimeout(function(){transitionTo(currentSlide, myNextSlide[currentSlide])}, 2000);
    } else {
        transitionTo(currentSlide, myNextSlide[currentSlide]);
    }
}

function slidePrev() {
    if(autoRotate) {
        autoRotate = false;
        clearTimeout(sTimer);
        setTimeout(function(){transitionTo(currentSlide, myPrevSlide[currentSlide])}, 2000);
    } else {
        transitionTo(currentSlide, myPrevSlide[currentSlide]);
    }
}

function transitionTo(oldId, newId) {
    currentSlide = newId;
    byId('romplrPrev').onclick = function() { if(autoRotate){ autoRotate = false; } };
    byId('romplrNext').onclick = function() { if(autoRotate){ autoRotate = false; } };

    FadeOpacity(oldId, 99, 0, 500, 10);

    setTimeout(function(){byId(oldId).className = "slide hidden"}, 501);
    setTimeout(function(){byId(newId).className = "slide"}, 502);
    setTimeout(function(){FadeOpacity(newId, 0, 99, 500, 10)}, 503);
    setTimeout(function(){byId(oldId + "_dot").className = "romplrDot"}, 504);
    setTimeout(function(){byId(newId + "_dot").className = "romplrDotSelected"}, 505);

    setTimeout(function(){ byId('romplrPrev').onclick = function() { slidePrev(); }; }, 503);
    setTimeout(function(){ byId('romplrNext').onclick = function() { slideNext(); }; }, 504);

    if(autoRotate)
        sTimer = setTimeout(function(){transitionTo(newId, myNextSlide[newId])}, 7000);
}

function SetOpacity(elem, opacityAsInt)
{
    var opacityAsDecimal = opacityAsInt;

    if (opacityAsInt > 100)
        opacityAsInt = opacityAsDecimal = 100;

    else if (opacityAsInt < 0)
        opacityAsInt = opacityAsDecimal = 0;

   opacityAsDecimal /= 100;

   if (opacityAsInt < 1)
       opacityAsInt = 1;

   elem.style.opacity = (opacityAsDecimal);
   elem.style.filter  = "alpha(opacity=" + opacityAsInt + ")";
}

function FadeOpacity(elemId, fromOpacity, toOpacity, time, fps)
{
   var steps = Math.ceil(fps * (time / 1000));
   var delta = (toOpacity - fromOpacity) / steps;

   FadeOpacityStep(elemId, 0, steps, fromOpacity,
                   delta, (time / steps));
}

function FadeOpacityStep(elemId, stepNum, steps, fromOpacity, delta, timePerStep)
{
   SetOpacity(document.getElementById(elemId), Math.round(parseInt(fromOpacity) + (delta * stepNum)));

   if (stepNum < steps)
       setTimeout("FadeOpacityStep('" + elemId + "', " + (stepNum+1) + ", " + steps + ", " + fromOpacity + ", " + delta + ", " + timePerStep + ");", timePerStep);
}
