function changeImage()
{  
    var index = 0;
    //var today = new Date();
    //index = today.getMinutes() % 29;
    //index = today.getSeconds() % 29;
    
    index = rand(29)
     
    var imgSrc = "images/coverimages/coverimage" + index + ".jpg";
    document.coverimage.src=imgSrc;
}

function rand (n)
{
  return ( Math.floor ( Math.random ( ) * n + 1 ) );
}

function validateForm(formName)
{
    var form = document.getElementById(formName);    
    var hasErrors = false;
    
    var errMsg = "Please correct the following errors before submitting this form.\n\n"
    if (form.name != null && form.name.value == '')
    {
        errMsg += "Name cannot be blank\n";
        hasErrors = true;
    }
    
    if (form.email != null && form.email.value == '')
    {
        errMsg += "E-Mail cannot be blank\n";
        hasErrors = true;
    }
    
    if (form.appointmentDate != null && form.appointmentDate.value == '')
    {
        errMsg += "Please provide an appointment date\n";
        hasErrors = true;
    }
    
    if (form.how_did_you_find_out_about_lshandi !=null && form.how_did_you_find_out_about_lshandi.selectedIndex == 0)
    {
        errMsg += "Please indicate how you found out about L~Shandi\n"
        hasErrors = true;
    }
        
    if (form.description !=null && form.description.value == '')
    {
        errMsg += "Please provide a short description of your event\n"
        hasErrors = true;
    }

    if (form.city !=null && form.city.value == '')
    {
        errMsg += "Please provide the city where your event will take place\n"
        hasErrors = true;
    }
    
    if (form.date !=null && form.date.value == '')
    {
        errMsg += "Please provide the date of your event\n"
        hasErrors = true;
    }     

    if (form.address !=null && form.address.value == '')
    {
        errMsg += "Please provide an e-mail address\n"
        hasErrors = true;
    }
    
    if (form.captcha !=null && (form.captcha.value == '' || form.captcha.value != 'orange'))
    {
        errMsg += "You have to prove you're human by entering the word shown\n"
        hasErrors = true;
    } 
    
    errMsg += "\nThanks!";
    
    if (hasErrors)
    {
        alert(errMsg);
        return false;
    }
    else
    {        
        return true;
    }
}

function PageQuery(q) {
    if(q.length > 1) this.q = q.substring(1, q.length);
    else this.q = null;
    this.keyValuePairs = new Array();
    if(q) {
        for(var i=0; i < this.q.split("&").length; i++) {
            this.keyValuePairs[i] = this.q.split("&")[i];
        }
    }
    this.getKeyValuePairs = function() { return this.keyValuePairs; }
    this.getValue = function(s) {
        for(var j=0; j < this.keyValuePairs.length; j++) {
            if(this.keyValuePairs[j].split("=")[0] == s)
                return this.keyValuePairs[j].split("=")[1];
        }
        return false;
    }
    this.getParameters = function() {
        var a = new Array(this.getLength());
        for(var j=0; j < this.keyValuePairs.length; j++) {
            a[j] = this.keyValuePairs[j].split("=")[0];
        }
        return a;
    }
    this.getLength = function() { return this.keyValuePairs.length; }	
}

function queryString(key)
{
    var page = new PageQuery(window.location.search); 
    return unescape(page.getValue(key)); 
}

function loadQueryStringParams(formName)
{
    var form = document.getElementById(formName);

    if (queryString("comments") != "false")
    {
        var field = form.reason;
        if(field != null)
        {
            field.selectedIndex = 4;
        }
        
        field = form.comments;
        field.value = queryString("comments");
    }
}
