/*Check with one variable*/
function check1(variable, message){
    if(!hasValue(variable)){
        alert(message);
        variable.focus();
        return false;
    }
    else
        return true;
}
/*Check with two variables*/
function check2(variable1, variable2, message1, message2){
    if(hasValue(variable1)==false){
        alert(message1);
        variable1.focus();
        return false;
    }        
    else if(hasValue(variable2)==false){
        alert(message2);
        variable2.focus();
        return false;
    }
    else
        return true;
}
/*Check with three variables*/
function check3(variable1, variable2, variable3, message1, message2, message3){
    if(hasValue(variable1)==false){
        alert(message1);
        variable1.focus();
        return false;
    }        
    else if(hasValue(variable2)==false){
        alert(message2);
        variable2.focus();
        return false;
    }
    else if(hasValue(variable3)==false){
        alert(message3);
        variable3.focus();
        return false;
    }
    else
        return true;
}

function checkWeddingInfo(variable1, variable2, variable3, variable4, variable5, variable6, message)
{
    if( validEmail(variable1)==false ){
        alert("Please type a valid email address.");
        variable1.select();
    }
    else if( check2(variable2, variable3, message, message)==true &&
        check3(variable4, variable5, variable6, message, message, message)==true 
        )
        return true;
    return false;
}

function checklength(thisform){
    if(thisform.site_title.value.length > 50){
        alert("Please enter a title with no more than 50 characters.");
        thisform.reset();
        thisform.site_title.focus();
        return false;
    }
    else if(hasValue(thisform.site_title)==false){
        alert("Your webpage must have a title.");
        thisform.site_title.focus();
        return false;
    }
    else
        return true;
}

function hasValue(field){
    with (field){
        if (value==null||value==""){
            return false;
        }
        else 
            return true;
    }
}

function checkAddMultipleGuestForm(thisform) {
    with(thisform){
        numEntries=9;
        numFields=8;
        for(i=0;i<numEntries*numFields;i+=numFields){
            lastNameField = elements[i];
            firstNameField = elements[i+1];
            addressField = elements[i+2];
            cityField = elements[i+3];
            stateField = elements[i+4];
            postalCodeField = elements[i+5];
            if( !hasValue(lastNameField) && hasValue(firstNameField) ){
                alert("Please enter the last name.");
                lastNameField.focus();
                return false;
            }
            else if( hasValue(lastNameField) && !hasValue(firstNameField) ){
                alert("Please enter the first name.");
                firstNameField.focus();
                return false;
            }
            else if(    !hasValue(lastNameField) 
                     && !hasValue(firstNameField)
                     && (   hasValue(addressField)
                         || hasValue(cityField)
                         || hasValue(stateField)
                         || hasValue(postalCodeField) ) ){
                alert("Please enter the first and last name.");
                lastNameField.focus();
                return false;
            }
        }
        return true;
    }   
}

function checkeventinfo(thisform){
    with(thisform){
        if(hasValue(eventname)==false){
            alert("Please type an Event Name.");
            eventname.focus();
            return false;
        }
        else if(hasValue(eventdate)==false){
            alert("Please type an Event Date.");
            eventdate.focus();
            return false;
        }
        else if(hasValue(eventtime)==false){
            alert("Please type an Event Time.");
            eventtime.focus();
            return false;
        }
        else if(hasValue(location)==false){
            alert("Please type an Location for your event.");
            location.focus();
            return false;
        }
        else 
            return true;
    }
}

function checkaddphoto(thisform){
    with(thisform){
        if(photoalbumid.value=="0"){
            alert("Please choose the photo album this photo will be part of.");
            photoalbumid.focus();
            return false;
        }
        else if(hasValue(myphoto)==false){
            alert("Please Add a photo.");
            myphoto.focus();
            return false;
        }
        else 
            return true;
    }
}

function checkcontactinfo(thisform){
    with(thisform){
        if(contactusenabledno.checked)
            return true;
        if(!hasValue(contactus_email1) ||
           !validEmail(contactus_email1))
        {
            alert("Please type a valid email address for Email 1.");
            contactus_email1.select();
            return false;
        }
        if(!validEmail(contactus_email2)){
            alert("Please type a valid email address for Email 2.");
            contactus_email2.select();
            return false;
        }
        if(!validEmail(contactus_email3)){
            alert("Please type a valid email address for Email 3.");
            contactus_email3.select();
            return false;
        }
        if(!validEmail(contactus_email4)){
            alert("Please type a valid email address for Email 4.");
            contactus_email4.select();
            return false;
        }
        return true;
    }
}

function validEmail(email){
    if (!(/^\w+([\.\+\-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email.value))
        && hasValue(email)){
        return false;
    }
    else
        return true;
}

function checkRSVPdetails(thisform,action2){
    if(thisform.numcoming.value == "--"){
        var answer = confirm("If you press OK you will be cancelling the RSVP details for this guest. You will also loose all the information about the rest of the party.");
        if(answer){
            document.location.href = action2;
        }
        return false;
    }
    return true;
}

function changeAlert(numComing, newSelection) {
    if(numComing == '?')
        return;
    if(newSelection.value == '--')
        return;
    else if(parseInt(numComing)>newSelection.value)
        alert("When reducing the number of guests coming you may loose some guest party information.");
    return;
}
