function checkContactForm(form)
{
	return checkInput("form_name","Please enter your name.")
            &&
		checkEmail("form_email","Please enter e-mail.")
            &&
		checkTextarea("form_message","Please enter message.");
}

function checkNewsletterForm(form)
{
	return checkEmail("form_newsletter_email","Please enter e-mail.");
}

/* ----------------------------------------------------------------------
	DEFAULT VALIDATION FORMS
---------------------------------------------------------------------- */
function checkInput(inputId, errorMessage)
{
	var input = document.getElementById(inputId);
	if(!input)
	{
		alert( "Input " + inputId + " not found!");
		return false;
	}

	if( input.value == "" )
    	return focusFailedInput(inputId,errorMessage);

    return true;
}

function compareFields(fieldId1, fieldId2, errorMessage)
{
	var field1 = document.getElementById(fieldId1);
	if(!field1)
	{
		alert( "Element " + fieldId1 + " not found!");
		return false;
	}

	var field2 = document.getElementById(fieldId2);
	if(!field2)
	{
		alert( "Element " + fieldId2 + " not found!");
		return false;
	}

	if( field1.value != field2.value )
    	return focusFailedInput(fieldId2,errorMessage);

    return true;
}

function checkTextarea(inputId, errorMessage)
{
	var input = document.getElementById(inputId);
	if(!input)
	{
		alert( "Textarea " + inputId + " not found!");
		return false;
	}

	if( input.value.length <= 3 )
    	return focusFailedInput(inputId,errorMessage);

    return true;
}

function checkEmail(inputId,errorMessage)
{
	var input = document.getElementById(inputId);
	if(!input)
	{
		alert( "Input " + inputId + " not found!");
		return false;
	}

    if (!isValidEmail(input.value))
    {
        focusFailedInput(inputId,errorMessage);
        return false;
    }

    return true;
}

function isValidEmail(email)
{
 	var template = /^[0-9a-z]+[0-9a-z._-]*\@[0-9a-z]+[0-9a-z._-]*\.[0-9a-z]{2,}$/i;
  	if (template.test(email) == false) return false;
	return true;
}

function clearError()
{
	var labels = document.getElementsByTagName("label");

	for(var i = 0; i < labels.length; i++ )
	{
		var label = labels[i];
		label.className = label.className.replace("error", "");
	}
	return true;
}

function focusFailedInput(inputId, errorMessage)
{
	var labels = document.getElementsByTagName("label");

	var tmplabel;
	// set error class to correct label and remove error class from others
	for(var i = 0; i < labels.length; i++ )
	{
		var label = labels[i];
		label.className = label.className.replace("error", "");
		// if anything will be wrong, remove break statement
		if( label.htmlFor == inputId ) { label.className += " error"; break; }
	}

	if(errorMessage)
		alert(errorMessage);

	var element = document.getElementById(inputId);
	if(element)
	{
		element.onchange = clearError;
		element.focus();
	}

	return false;
}

function checkRadio(form, input, errorMessage, inputId)
{
	var i = 0;
	for( i ; i < form[input].length; i++ )
		if(form[input][i].checked == true) break;

	var tmp = inputId ? inputId : tmp;
	if( i == form[input].length )
    	return focusFailedInput(tmp,errorMessage);

    return true;
}

function checkFormLoginEmail(form){
    if (!checkInput("form_forgot_email","Please enter a valid email address."))
		return false;
    if (!isValidEmail(document.getElementById("form_forgot_email").value))
    {
        alert(document.getElementById("form_forgot_email").value+" is not a valid email");
        return false;
    }
    return true;
}

function checkLoginForm(form)
{
    if (!checkInput("form_login_login","Please enter a valid username."))
        return false;
    if (!checkInput("form_login_password","Please enter your password."))
        return false;
    if (document.getElementById("addTripID") != undefined
            &&
        document.getElementById("addTripID").checked != undefined
            &&
        document.getElementById("addTripID").checked
            &&
        !checkInput("updateStatusForTravelerID","Please enter a valid Trip ID."))
        return false;

    return true;
}

function checkHPLoginForm(form)
{
    if (!checkInput("login","Please enter a valid username."))
        return false;
    if (!checkInput("password","Please enter your password."))
        return false;

    form.submit();
}

function checkHPRegistrationForm(form)
{
    if (!checkInput("customer_id","Please enter a valid customer ID."))
        return false;
    if (!checkInput("tripID","Please enter a valid Trip ID."))
        return false;
    if (!checkInput("email","Please enter a valid email."))
        return false;
     if (!isValidEmail(document.getElementById("email").value))
     {
         alert("Invalid email address.");
         return false;
     }
    if (!checkInput("rlogin","Please enter a valid login."))
        return false;
    if (!checkInput("rpassword","Please enter your password."))
        return false;
    if (!checkInput("rrepassword","Please enter your re-password."))
        return false;
     if (document.getElementById("rpassword").value != document.getElementById("rrepassword").value)
     {
         alert("The two password fields are not the same.");
         return false;
     }

    form.submit();
}


function checkSearch(){
	form = document.formsearch;
	if (trim(form["search-clause"].value) != "")
		return true
	else
		return false
}

function checkLogin(){
	form = document.formlogin;
	if (trim(form["login"].value) != "" && trim(form["password"].value) != "")
		return true
	else
		return false
}

function switchTripIDRegion ()
{
    if (document.getElementById("addTripID").checked)
    {
        document.getElementById("tripRegion").style.visibility="visible";}
    else
    {
        document.getElementById("tripRegion").style.visibility="hidden";
    }
}

function checkRegisterForm ()
{
    return true;
}

function updateParentConfirmationSection()
{
    if (document.getElementById("c1").checked
            &&
        document.getElementById("13OrYounger") != undefined
            &&
        document.getElementById("sl_parent_name") != undefined
            &&
        document.getElementById("parent_name") != undefined)
    {
        document.getElementById("13OrYounger").style.visibility="visible";
        document.getElementById("sl_parent_name").style.visibility="visible";
        document.getElementById("parent_name").style.visibility="visible";
        document.getElementById("sl_parent_email").style.visibility="visible";
        document.getElementById("parent_email").style.visibility="visible";
    }

    if (document.getElementById("c2").checked
            &&
        document.getElementById("13OrYounger") != undefined
            &&
        document.getElementById("sl_parent_name") != undefined
            &&
        document.getElementById("parent_name") != undefined)
    {
        document.getElementById("13OrYounger").style.visibility="hidden";
        document.getElementById("sl_parent_name").style.visibility="hidden";
        document.getElementById("parent_name").style.visibility="hidden";
        document.getElementById("sl_parent_email").style.visibility="hidden";
        document.getElementById("parent_email").style.visibility="hidden";
    }
}

function updateRegistrationCat ()
{
    if (document.getElementById("horizontal_fieldSet_div").style.visibility=="visible")
    {
        window.location.assign("/registration.xml?withChild=0"
                        +"&c1=" + document.getElementById("c1").checked
                        +"&c2="+document.getElementById("c2").checked
                        +"&c3="+document.getElementById("c3").checked
                        +"&fromLogin="+document.getElementById("fromLogin").value);
    }

    document.getElementById("horizontal_fieldSet_div").style.visibility="visible";

    //toggle between student and adult needs to reset the vertical radios.

    if ((document.getElementById("c1").checked
            ||
        document.getElementById("c2").checked)
            &&
        document.getElementById("withChild").value == "0")
    {
        document.getElementById("r1").checked = false;
        document.getElementById("r3").checked = false;
    }

    if (document.getElementById("c3").checked)
    {
        window.location.assign("/registration.xml?withChild=1"
                        +"&c1=" + (document.getElementById("c1").checked ? "on" : "off")
                        +"&c2="+ (document.getElementById("c2").checked ? "on" : "off")
                        +"&c3="+ (document.getElementById("c3").checked ? "on" : "off")
                        +"&fromLogin="+document.getElementById("fromLogin").value);
    }
    updateHelpLink();
}

/**
 * The vertical radio buttons.
 *
 * Student/Adult
 * -- I have already registered to go on a trip and would like to create my account
 *   $ Trip ID, Traveler ID, E-mail, Username, Password
 * -- I have travelled with worldStrides and have an account with previous trip.
 *   $ Trip ID, E-mail, Username, Password
 * -- This is my first time with WorldStrides
 *   & Trip ID, First Name, Last Name, E-mail, Username, Password
 *
 */
function updateStudentRegistrationForm ()
{
    try{
        document.getElementById("registration_form").style.visibility="visible";
        document.getElementById("registration_buttons").style.visibility="visible";
        if (document.getElementById("13OrYounger") != undefined)
            document.getElementById("13OrYounger").style.visibility="visible";

        if (!document.getElementById("c1").checked
                &&
            !document.getElementById("c2").checked
                &&
            !document.getElementById("c3").checked)
        {
            alert("You have to first select 'Registering as' first.");
        }

        if (document.getElementById("withChild").value == "0")
        {
            document.getElementById("sl_firstname").className="active";
            document.getElementById("s_firstname").className="active";
            document.getElementById("s_firstname").disabled=false;
            document.getElementById("sl_lastname").className="active";
            document.getElementById("s_lastname").className="active";
            document.getElementById("s_lastname").disabled=false;
            document.getElementById("sl_repass").className="active";
            document.getElementById("s_repass").className="active";
            document.getElementById("s_repass").disabled=false;
            document.getElementById("sl_traveller").className="active";
            document.getElementById("s_traveller").className="active";
            document.getElementById("s_traveller").disabled=false;

            if ((document.getElementById("r1").checked))
            {
                document.getElementById("sl_firstname").className="inactive";
                document.getElementById("s_firstname").disabled=true;
                document.getElementById("sl_lastname").className="inactive";
                document.getElementById("s_lastname").disabled=true;
            }
            else if ((document.getElementById("r3").checked))
            {
                document.getElementById("sl_traveller").className="inactive";
                document.getElementById("s_traveller").disabled=true;
            }
        }
    }catch (err)
    {
//        alert(err);
    }

}

/**
 * The vertical radio buttons.
 *
 * Parent
 * -- child has registered to go on a trip and would like to create my account
 *   $ Trip ID, Traveler ID, E-mail, Username, Password
 * -- My child has registered to go on a trip and would like to create our accounts
 *   $ Trip ID, Your First Name, Your Last Name, Your E-mail, Your Username,
 *      Your Password, Trip ID, Childs First Name, Childs Last Name, Childs E-mail, Username, Password
 * -- My child has traveled with WorldStrides and has an account
 *   & Trip ID, Username, Password
 * -- This is my first time with WorldStrides
 *   $ Trip ID, First Name, Last Name, E-mail, Username, Password
 */
function updateStudentParentForm ()
{
    document.getElementById("registration_form").style.visibility="visible";
    document.getElementById("registration_buttons").style.visibility="visible";
    if (document.getElementById("13OrYounger") != undefined)
        document.getElementById("13OrYounger").style.visibility="visible";

    if (!document.getElementById("c1").checked
            &&
        !document.getElementById("c2").checked
            &&
        !document.getElementById("c3").checked)
    {
        alert("You have to first select 'Registering as' first.");
    }
    if (document.getElementById("withChild").value == "1" || document.getElementById("c3").checked)
    {
        document.getElementById("pl_traveller").className="active";
        document.getElementById("p_traveller").className="active";
        document.getElementById("p_traveller").disabled=false;
        document.getElementById("pl_firstname").className="active";
        document.getElementById("p_firstname").className="active";
        document.getElementById("p_firstname").disabled=false;
        document.getElementById("pl_lastname").className="active";
        document.getElementById("p_lastname").className="active";
        document.getElementById("p_lastname").disabled=false;
        document.getElementById("pl_username").className="active";
        document.getElementById("p_username").className="active";
        document.getElementById("p_username").disabled=false;
        document.getElementById("pl_email").className="active";
        document.getElementById("p_email").className="active";
        document.getElementById("p_email").disabled=false;
        document.getElementById("pl_password").className="active";
        document.getElementById("p_password").className="active";
        document.getElementById("p_password").disabled=false;
        document.getElementById("pl_repass").className="active";
        document.getElementById("p_repass").className="active";
        document.getElementById("p_repass").disabled=false;

        if ((document.getElementById("r1").checked))
        {
            document.getElementById("pl_firstname").className="inactive";
            document.getElementById("p_firstname").disabled=true;
            document.getElementById("pl_lastname").className="inactive";
            document.getElementById("p_lastname").disabled=true;
        }
        else if (document.getElementById("r2") != undefined && (document.getElementById("r2").checked))
        {

        }
        else if (document.getElementById("r3") != undefined && (document.getElementById("r3").checked))
        {
            document.getElementById("pl_traveller").className="inactive";
            document.getElementById("p_traveller").disabled=true;
            document.getElementById("pl_firstname").className="inactive";
            document.getElementById("p_firstname").disabled=true;
            document.getElementById("pl_lastname").className="inactive";
            document.getElementById("p_lastname").disabled=true;
            document.getElementById("pl_username").className="inactive";
            document.getElementById("p_username").disabled=true;
            document.getElementById("pl_email").className="inactive";
            document.getElementById("p_email").disabled=true;
            document.getElementById("pl_password").className="inactive";
            document.getElementById("p_password").disabled=true;
            document.getElementById("pl_repass").className="inactive";
            document.getElementById("p_repass").disabled=true;
        }
        else if ((document.getElementById("r4").checked))
        {
            document.getElementById("pl_traveller").className="inactive";
            document.getElementById("p_traveller").disabled=true;
        }
    }
}
/**
 * yes, -- very complex logic to deal with all kinds of situations.
 *
 */
function checkRegistrationForm ()
{
    if (!document.getElementById("c1").checked
            &&
        !document.getElementById("c2").checked
            &&
        !document.getElementById("c3").checked)
    {
        alert("You have to first select 'Registering as' first.");
        return false;
    }

    if (document.getElementById("withChild").value == "0")
    {
        if (document.getElementById("c1").checked && document.getElementById("13oryoungerCheckbox").checked)
        {
          if (!checkInput ("parent_name", "Parent name is required."))
             return false;
          if (!checkInput ("parent_email", "Parent email is required."))
             return false;
          if (!isValidEmail(document.getElementById("parent_email").value))
          {
             alert("Invalid parent email address.");
             return false;
          }
        }
        if (!document.getElementById("r1").checked
                &&
            !document.getElementById("r3").checked)
        {
            alert("Please select the vertical radio button first");
            return false;
        }

        if ((document.getElementById("r1").checked))
        {
             if (!checkInput ("trip", "Trip ID is required."))
                 return false;
             if (!checkInput ("s_traveller", "Traveler ID is required."))
                 return false;
             if (!checkInput ("s_username", "User Name is required."))
                 return false;
             if (!checkInput ("s_email", "Email is required."))
                 return false;
             if (!isValidEmail(document.getElementById("s_email").value))
             {
                 alert("Invalid email address.");
                 return false;
             }
             if (!checkInput ("s_password", "Password is required."))
                 return false;
             if (!checkInput ("s_repass", "Retype Password is required."))
                 return false;
             if (document.getElementById("s_password").value != document.getElementById("s_repass").value)
             {
                 alert("The two password fields are not the same.");
                 return false;
             }
        }
        else if ((document.getElementById("r3").checked))
        {
            if (!checkInput ("trip", "Trip ID is required."))
                return false;
            if (!checkInput ("s_firstname", "First Name is required."))
                return false;
            if (!checkInput ("s_lastname", "Last Name is required."))
                return false;
            if (!checkInput ("s_username", "User Name is required."))
                return false;
            if (!checkInput ("s_email", "Email is required."))
                return false;
            if (!isValidEmail(document.getElementById("s_email").value))
            {
                alert("Invalid email address.");
                return false;
            }
            if (!checkInput ("s_password", "Password is required."))
                return false;
            if (!checkInput ("s_repass", "Retype Password is required."))
                return false;
            if (document.getElementById("s_password").value != document.getElementById("s_repass").value)
            {
                alert("The two password fields are not the same.");
                return false;
            }

        }

    }
    //parent
    else
    {
        if (!document.getElementById("r1").checked
                &&
            (document.getElementById("r2") != undefined && !document.getElementById("r2").checked)
                &&
            (document.getElementById("r3") != undefined && !document.getElementById("r3").checked)
                &&
            !document.getElementById("r4").checked)
        {
            alert("Please select the vertical radio button first");
            return false;
        }

        if ((document.getElementById("r1").checked))
        {
             if (!checkInput ("trip", "Trip ID is required."))
                 return false;
             if (!checkInput ("p_traveller", "Traveler ID is required."))
                 return false;
             if (!checkInput ("p_username", "User Name is required."))
                 return false;
             if (!checkInput ("p_email", "Email is required."))
                 return false;
             if (!isValidEmail(document.getElementById("p_email").value))
             {
                 alert("Invalid email address.");
                 return false;
             }
             if (!checkInput ("p_password", "Password is required."))
                 return false;
             if (!checkInput ("p_repass", "Retype Password is required."))
                 return false;
             if (document.getElementById("p_password").value != document.getElementById("p_repass").value)
             {
                 alert("The two password fields are not the same.");
                  return false;
             }
        }
        else if (document.getElementById("r2") != undefined && (document.getElementById("r2").checked))
        {
             if (!checkInput ("trip", "Trip ID is required."))
                 return false;
             if (!checkInput ("p_traveller", "Traveler ID is required."))
                 return false;
             if (!checkInput ("p_firstname", "First Name is required."))
                 return false;
             if (!checkInput ("p_lastname", "Last Name is required."))
                 return false;
             if (!checkInput ("p_username", "User Name is required."))
                 return false;
             if (!checkInput ("p_email", "Email is required."))
                 return false;
             if (!isValidEmail(document.getElementById("s_email").value))
             {
                 alert("Invalid email address.");
                 return false;
             }
             if (!checkInput ("p_password", "Password is required."))
                 return false;
             if (!checkInput ("p_repass", "Retype Password is required."))
                 return false;
             if (document.getElementById("p_password").value != document.getElementById("p_repass").value)
             {
                 alert("The two password fields are not the same.");
                  return false;
             }
             //children side
             if (!checkInput ("p_cfirstname", "Child First Name is required."))
                 return false;
             if (!checkInput ("p_clastname", "Child Last Name is required."))
                 return false;
             if (!checkInput ("p_cusername", "Child User Name is required."))
                 return false;
             if (!checkInput ("p_cemail", "Child Email is required."))
                 return false;
             if (!isValidEmail(document.getElementById("p_cemail").value))
             {
                 alert("Invalid email address.");
                 return false;
             }
             if (!checkInput ("p_cpassword", "Password is required."))
                 return false;
             if (!checkInput ("p_crepassword", "Child Retype Password is required."))
                 return false;
             if (document.getElementById("p_cpassword").value != document.getElementById("p_crepassword").value)
             {
                 alert("The Child two password fields are not the same.");
                  return false;
             }
        }
        else if (document.getElementById("r3") != undefined && (document.getElementById("r3").checked))
        {
             if (!checkInput ("trip", "Trip ID is required."))
                 return false;
             //children side
             if (!checkInput ("p_cusername", "Child User Name is required."))
                 return false;
             if (!checkInput ("p_cemail", "Child Email is required."))
                 return false;
             if (!isValidEmail(document.getElementById("p_cemail").value))
             {
                 alert("Invalid email address.");
                 return false;
             }
             if (!checkInput ("p_cpassword", "Password is required."))
                 return false;
        }
        else if ((document.getElementById("r4").checked))
        {
             if (!checkInput ("trip", "Trip ID is required."))
                 return false;
             //children side
             if (!checkInput ("p_username", "User Name is required."))
                 return false;
             if (!checkInput ("p_email", "Email is required."))
                 return false;
             if (!isValidEmail(document.getElementById("p_email").value))
             {
                 alert("Invalid email address.");
                 return false;
             }
             if (!checkInput ("p_password", "Password is required."))
                 return false;
             if (!checkInput ("p_repass", "Retype Password is required."))
                 return false;
             if (document.getElementById("p_password").value != document.getElementById("p_repass").value)
             {
                 alert("The two password fields are not the same.");
                  return false;
             }
        }

    }
    return true;
}
/**
 * yes, -- very complex logic to deal with all kinds of situations.
 *
 */
function checkRegistrationFD4Corm ()
{
    if (!checkInput ("d4c_login", "You are not supposed to use this page to register if you do not come from Discovery For Credit."))
        return false;
    if (!checkInput ("trip", "Trip ID is required."))
        return false;
    if (!checkInput ("s_firstname", "First Name is required."))
        return false;
    if (!checkInput ("s_lastname", "Last Name is required."))
        return false;
    if (!checkInput ("s_username", "User Name is required."))
        return false;
    if (!checkInput ("s_email", "Email is required."))
        return false;
    if (!isValidEmail(document.getElementById("s_email").value))
    {
        alert("Invalid email address.");
        return false;
    }
    if (!checkInput ("s_password", "Password is required."))
        return false;
    if (!checkInput ("s_repass", "Retype Password is required."))
        return false;
    if (document.getElementById("s_password").value != document.getElementById("s_repass").value)
    {
        alert("The two password fields are not the same.");
        return false;
    }

    if (document.getElementById("s_traveller").value != '')
    {
        document.getElementById("ireg_cat").value="account";
    }
    else
        document.getElementById("ireg_cat").value="1stTime";


    return true;

}

function checkRegistrationPLForm ()
{
    if (!checkInput ("plid", "PLID is required."))
        return false;
    if (!checkInput ("username", "Username is required."))
        return false;
    if (!checkInput ("password", "Password is required."))
        return false;
    if (!checkInput ("repassword", "Repeat password is required."))
        return false;
     if (document.getElementById("password").value != document.getElementById("repassword").value)
     {
         alert("The two password fields are not the same.");
          return false;
     }
}
/**
 * Basically for the refresh of the page in case of errors.
 *
 * @param customerCat
 * @param regCat
 */
function initializeRegistrationForm (customerCat, regCat)
{
    if (document.getElementById("r1") != undefined)
    {
        document.getElementById("r1").checked = false;
    }
    if (document.getElementById("r3") != undefined)
    {
        document.getElementById("r3").checked = false;
    }
    if (document.getElementById("r4") != undefined)
    {
        document.getElementById("r4").checked = false;
    }

    //
    if (document.getElementById("c1").checked
        ||
        document.getElementById("c2").checked
        ||
        document.getElementById("c3").checked)
    {
        document.getElementById("horizontal_fieldSet_div").style.visibility="visible";
    }

    if (customerCat=="student")
    {
        document.getElementById("c1").checked=true;
        if (regCat == "account")
        {
            document.getElementById("r1").checked = true;
            updateStudentRegistrationForm();
        }
        else if (regCat == "1stTime")
        {
            document.getElementById("r3").checked = true;
            updateStudentRegistrationForm();
        }
    }
    else if (customerCat=="adult")
    {
        document.getElementById("c2").checked=true;
        if (regCat == "account")
        {
            document.getElementById("r1").checked = true;
            updateStudentRegistrationForm();
        }
        else if (regCat == "1stTime")
        {
            document.getElementById("r3").checked = true;
            updateStudentRegistrationForm();
        }
    }
    else if (customerCat=="parent")
    {
        document.getElementById("c3").checked=true;
        if (regCat == "myaccount")
        {
            document.getElementById("r1").checked = true;
            updateStudentParentForm();
        }
        else if (regCat == "already")
        {
            document.getElementById("r3").checked = true;
            updateStudentParentForm();
        }
        else if (regCat == "1stTime")
        {
            document.getElementById("r4").checked = true;
            updateStudentParentForm();
        }
    }

    updateHelpLink();
}

function updateHelpLink ()
{
    if (document.getElementById("c1").checked
        ||
        document.getElementById("c2").checked
        ||
        document.getElementById("c3").checked)
    {
        document.getElementById("horizontal_fieldSet_div").style.visibility="visible";
        document.getElementById("register_helper").style.visibility="visible";
        if (document.getElementById("c1").checked)
        {
            document.getElementById("selection").value ="register_student";
        }
        else if (document.getElementById("c2").checked)
        {
            document.getElementById("selection").value ="register_adult";
        }
        else
        {
            document.getElementById("selection").value ="register_parent";
        }
    }
}

/**
 * For the main menu items -- see if
 * the user selected a valid trip first
 *
 * @param nextLocation
 */
function goToNextLocation (nextLocation)
{
    if (document.getElementById("selected_trip").value == '')
    {
        alert("You must select a valid trip first.");
        return false;
    }
    window.location.assign(nextLocation+"&tripID="+document.getElementById("selected_trip").value);
}
/**
 * For the main menu items -- see if
 * the user selected a valid trip first
 *
 * @param nextLocation
 */
function goToNextLocationPhoto (nextLocation)
{
    if (document.getElementById("selected_trip").value == '')
    {
        alert("You must select a valid trip first.");
        return false;
    }
    window.open(nextLocation+"&tripID="+document.getElementById("selected_trip").value);
}
/**
 * For the PL resource -- see if
 * the user selected a valid trip first
 *
 * @param nextLocation
 */
function goToNextLocationPLResource (tdid, hash, performing, tourType)
{
    if (document.getElementById("selected_trip").value == '')
    {
        alert("You must select a valid trip first.");
        return false;
    }
    if (performing=='0')
        window.open("http://olr.worldstrides.net/plresources/default.asp?TDID="+tdid+"&"
                +"Hash="+hash + "&TripID="+document.getElementById("selected_trip").value
                +"&TType="+tourType);
    else
        window.open("https://olr.worldstrides.net/scripts/cgiip.exe/RoomingList/Rats.htm?TDID="+tdid+"&"+"securityHash="
                +hash + "&tripno="+document.getElementById("selected_trip").value
                +"&TType="+tourType);
}

/**
 * When user clicks the schedule list, schedule form will be updated
 *
 * @param componentID
 */
function updateTheScheduleForm (componentID)
{
    document.getElementById('removeSchedule').disabled=false;
    document.getElementById('selected_schedule_id').value=componentID;
    document.getElementById('title').value=document.getElementById('h_title'+componentID).value;

    select_Value_Set('_status', document.getElementById('h_status'+componentID).value);

    document.getElementById('date').value=document.getElementById('h_date'+componentID).value;
    document.getElementById('hour').value=document.getElementById('h_hour'+componentID).value;
    document.getElementById('min').value=document.getElementById('h_min'+componentID).value;
    alert(document.getElementById('h_message'+componentID).value);
    document.getElementById('message').innerHTML=document.getElementById('h_message'+componentID).value;
    alert(document.getElementById('message').innerHTML);
    document.getElementById('alternate').value=document.getElementById('h_alternate'+componentID).value;
    document.getElementById('name').value=document.getElementById('h_1file'+componentID).value;
    document.getElementById('name1').value=document.getElementById('h_2file'+componentID).value;
    document.getElementById('name2').value=document.getElementById('h_3file'+componentID).value;
}

/**
 * When user clicks the schedule list, schedule form will be updated
 *
 * @param componentID
 */
function blankOutTheScheduleForm ()
{
    document.getElementById('removeSchedule').disabled=true;
    document.getElementById('selected_schedule_id').value='';
    document.getElementById('title').value='';

    select_Value_Set('_status', 'available');

    document.getElementById('date').value='';
    document.getElementById('hour').value='';
    document.getElementById('min').value='';
    document.getElementById('message').value='';
    document.getElementById('alternate').value='';
    document.getElementById('name').value='';
    document.getElementById('name1').value='';
    document.getElementById('name2').value='';
}

/**
 *
 * @param selectName
 * @param Value
 */
function select_Value_Set(selectName, Value)
{
    for(index = 0; index < document.getElementById(selectName).length; index++)
    {
        if(document.getElementById(selectName).options[index].value == Value)
        {
            document.getElementById(selectName).options.selectedIndex = index;
        }
    }
}


/**
 * check the required fields in schedule form
 *
 */
function checkRequiredFieldsInScheduleForm ()
{
    if (document.getElementById('removeSchedule').checked)
    {
        var c = confirm("Are you sure you want to delete the record?");
        if (c)
        {

        }
        else
        {
            return false;
        }
    }
    if (document.getElementById('title').value=='')
    {
        alert("title can not be empty");
        return false;
    }

    if (document.getElementById('date').value=='')
    {
        alert("date can not be empty");
        return false;
    }
    else
    {
        var inputDate = new Date(document.getElementById('date').value);
        var currentDate = new Date();
        currentDate.setDate(currentDate.getDate()-1);
        if (inputDate<currentDate)
        {
            alert("The date you have entered has lapsed. Please enter a valid date.");
            return false;
        }
    }
    if (document.getElementById('hour').value!='')
    {
        if (isNaN(document.getElementById('hour').value))
        {
            alert("Hour needs to be a number");
            return false;
        }
    }

    if (document.getElementById('min').value!='')
    {
        if (isNaN(document.getElementById('min').value))
        {
            alert("Minute needs to be a number");
            return false;
        }
    }

    return true;

}
/**
 * check the required fields in schedule form
 *
 */
function checkRequiredFieldsInAnnouncementForm ()
{
    if (document.getElementById('removeSchedule').checked)
    {
        var c = confirm("Are you sure you want to delete the record?");
        if (c)
        {

        }
        else
        {
            return false;
        }
    }
    if (document.getElementById('title').value=='')
    {
        alert("title can not be empty");
        return false;
    }
    return true;

}

/**
 * When user clicks the schedule list, schedule form will be updated
 *
 * @param componentID
 */
function blankTheSiteForm (componentID)
{
    document.getElementById('selected_site_id').value='';
    document.getElementById('name').value = '';
    document.getElementById('description').value = '';
    document.getElementById('url').value = '';
    document.getElementById('site_thumbnail').style.visibility = 'hidden';
    document.getElementById('map_thumbnail').src='/images/pl/dummy.jpg';
}

/**
 * When user clicks the schedule list, schedule form will be updated
 *
 * @param componentID
 */
function updateTheSiteForm (componentID)
{
    document.getElementById('selected_site_id').value=componentID;
    document.getElementById('name').value=document.getElementById('h_title'+componentID).value;
    document.getElementById('description').value=document.getElementById('h_message'+componentID).value;
    document.getElementById('url').value=document.getElementById('h_url'+componentID).value;
    document.getElementById('map_thumbnail').src=document.getElementById('h_thumbnail'+componentID).value;
}


/**
 * check the required fields in schedule form
 *
 */
function checkRequiredFieldsInSiteForm ()
{

    if (document.getElementById('name').value=='')
    {
        alert("name can not be empty");
        return false;
    }
    if (document.getElementById('url').value=='')
    {
        alert("URL can not be empty");
        return false;
    }
    return true;

}


function updateCustomerAccountInfo (Category)
{
    if (Category == "travelStatus")
    {
        if (document.getElementById("travelerid").value=="")
        {
            alert ("Traveler ID can not be null");
            return false;
        }
        document.getElementById("accountFom").action +="&cat=travelStatus";
        document.getElementById("accountFom").submit();
    }
    if (Category == "myInfo")
    {
        if (document.getElementById("fname").value=="")
        {
            alert ("First name can not be null");
            return false;
        }
        if (document.getElementById("lname").value=="")
        {
            alert ("Last name can not be null");
            return false;
        }
        document.getElementById("accountFom").action +="&cat=myInfo";
        document.getElementById("accountFom").submit();
    }
    if (Category == "pw")
    {
        if (document.getElementById("password").value=="")
        {
            alert ("password name can not be null");
            return false;
        }
        if (document.getElementById("rpassword").value=="")
        {
            alert ("Repeat password can not be null");
            return false;
        }
        if (document.getElementById("rpassword").value !=
            document.getElementById("password").value)
        {
            alert ("Password are repeat password are not the same");
            return false;
        }
        document.getElementById("accountFom").action +="&cat=pw";
        document.getElementById("accountFom").submit();
    }
    if (Category == "tripParent")
    {

        document.getElementById("accountFom").action +="&cat=tripParent";
        document.getElementById("accountFom").submit();
    }
    if (Category == "trip")
    {
        if (document.getElementById("new_tripid").value=="")
        {
            alert ("Trip ID can not be empty");
            return false;
        }
        document.getElementById("accountFom").action +="&cat=trip";
        document.getElementById("accountFom").submit();
    }
    return false;
}
function updatePLAccountInfo (Category)
{
    if (Category == "myInfo")
    {
        if (document.getElementById("fname").value=="")
        {
            alert ("First name can not be null");
            return false;
        }
        if (document.getElementById("lname").value=="")
        {
            alert ("Last name can not be null");
            return false;
        }
        document.getElementById("accountFom").action +="&cat=myInfo";
        document.getElementById("accountFom").submit();
    }
    if (Category == "pw")
    {
        if (document.getElementById("password").value=="")
        {
            alert ("password name can not be null");
            return false;
        }
        if (document.getElementById("rpassword").value=="")
        {
            alert ("Repeat password can not be null");
            return false;
        }
        if (document.getElementById("rpassword").value !=
            document.getElementById("password").value)
        {
            alert ("Password are repeat password are not the same");
            return false;
        }
        document.getElementById("accountFom").action +="&cat=pw";
        document.getElementById("accountFom").submit();
    }
    return false;
}

function updateCustomerMyAccountInfo (Category, tripID)
{
    if (Category == "traveler_update")
    {
        if (document.getElementById("traveler_id").value=="")
        {
            alert ("Traveler ID cannot be blank");
            return false;
        }
        document.getElementById("accountFom").action +="&cat=traveler_update";
        document.getElementById("accountFom").submit();
    }
    if (Category == "myInfo")
    {
        if (document.getElementById("fname").value=="")
        {
            alert ("First name can not be null");
            return false;
        }
        if (document.getElementById("lname").value=="")
        {
            alert ("Last name can not be null");
            return false;
        }
        document.getElementById("accountFom").action +="&cat=myInfo";
        document.getElementById("accountFom").submit();
    }
    if (Category == "pw")
    {
        if (document.getElementById("login").value=="")
        {
            alert ("Username cannot be blank");
            return false;
        }
        if (document.getElementById("password").value=="")
        {
            alert ("Password cannot be blank. Please enter your password in the spaces provided.");
            return false;
        }
        if (document.getElementById("rpassword").value=="")
        {
            alert ("Repeat password can not be null");
            return false;
        }
        if (document.getElementById("rpassword").value !=
            document.getElementById("password").value)
        {
            alert ("Password are repeat password are not the same");
            return false;
        }
        document.getElementById("accountFom").action +="&cat=pw";
        document.getElementById("accountFom").submit();
    }
    if (Category == "removeTrip")
    {
        if (confirm("Are you sure you want to remove the link to the trip?"))
        {
            document.getElementById("accountFom").action += ("&cat=removeTrip&thisTrip="+tripID);
            document.getElementById("accountFom").submit();
        }
        else
        {
            return false;
        }
    }
    if (Category == "addTrip")
    {
        if (document.getElementById("new_tripid").value !='')
        {
            document.getElementById("accountFom").action += ("&cat=addTrip");
            document.getElementById("accountFom").submit();
        }
        else
        {
            alert("You have put in a valid Trip ID.");
            return false;
        }
    }
    if (Category == "registerTrip" || Category == "addTraveler")
    {
        if (document.getElementById("new_traveler_id_"+tripID).value !='')
        {
            document.getElementById("accountFom").action += ("&cat="+Category+"&thisTrip="+tripID);
            document.getElementById("accountFom").submit();
        }
        else
        {
            alert("You have put in a valid Traveler ID.");
            return false;
        }
    }
    return false;
}

function messagingUpdateSelection ()
{
    var path = "/messaging_pl.xml?tripID="+document.getElementById("trip_id").value;
    path += getMessaingCheckBoxSelection();

    window.location.assign(path);
}
/**
 * cool staff
 *
 * @param column
 * @param existingSortColumn
 * @param exisitngOrder
 */
function messagingSortData (column, existingSortColumn, exisitngOrder)
{
    var path = "/messaging_pl.xml?tripID="+document.getElementById("trip_id").value;
    path += getMessaingCheckBoxSelection();
    if (column == existingSortColumn)
    {
        if (exisitngOrder=='asc')
           path += ("&sort="+column+"&order=desc");
        else
           path += ("&sort="+column+"&order=asc");
    }
    else
    {
        path += ("&sort="+column+"&order=asc");
    }
    window.location.assign(path);
}
/**
 *
 */
function checkAddToMyGroupSubmit ()
{
    if (!checkInput ("fname", "First Name is required."))
        return false;
    if (!checkInput ("lname", "Last Name is required."))
        return false;
    if (!checkInput ("group", "Group is required."))
        return false;
    if (!checkEmail ("email", "email Name is required."))
        return false;

    document.getElementById("addToMyGroupID").action += getMessaingCheckBoxSelection();
    return true;
}
/**
 *
 */
function checkMessagingEmailSubmit ()
{
    var elements = document.getElementsByTagName("input");
    var atLeastOneSelected = false;
    for (var i =0; i < elements.length; i++)
    {
        if (elements[i].id.indexOf("selected_customer_") >= 0
                &&
            elements[i].checked)
        {
            atLeastOneSelected = true;
            break;
        }
    }

    if (!atLeastOneSelected)
    {
       alert("At least one user must be selected");
       return false;
    }

    if (document.getElementById("subject").value == "")
    {
        alert("Subject can not be null");
        return false;
    }


    var emessage = document.getElementById ('message').value.replace("\n", "<br>");
    while (emessage.indexOf("\n") > 0)
        emessage = emessage.replace("\n", "<br>");

    emessage = escape(emessage);
    document.getElementById("sendEmail").action += (getMessaingCheckBoxSelection()+"&emailMessage="+emessage);
    return true;
}
/**
 *
 * @param module
 */
function addAccess (module)
{
    var domain = document.getElementById("pl_site").checked ? "pl" : "st";

    if (domain == 'st' && module=='referral')
    {
        alert("There is no referral module for student site.");
        return false;
    }

    if (document.getElementById("pl_site").checked)
    {
        document.getElementById("access_control").innerHTML = document.getElementById("access_control").innerHTML.replace(/#Access_To_st_schedule#/g, "");
        document.getElementById("access_control_field").value = document.getElementById("access_control_field").value.replace(/#Access_To_st_schedule#/g, "");
        document.getElementById("access_control").innerHTML = document.getElementById("access_control").innerHTML.replace(/#Access_To_st_announcement#/g, "");
        document.getElementById("access_control_field").value = document.getElementById("access_control_field").value.replace(/#Access_To_st_announcement#/g, "");
        document.getElementById("access_control").innerHTML = document.getElementById("access_control").innerHTML.replace(/#Access_To_st_photo#/g, "");
        document.getElementById("access_control_field").value = document.getElementById("access_control_field").value.replace(/#Access_To_st_photo#/g, "");
    }
    else
    {
        document.getElementById("access_control").innerHTML = document.getElementById("access_control").innerHTML.replace(/#Access_To_pl_schedule#/g, "");
        document.getElementById("access_control_field").value = document.getElementById("access_control_field").value.replace(/#Access_To_pl_schedule#/g, "");
        document.getElementById("access_control").innerHTML = document.getElementById("access_control").innerHTML.replace(/#Access_To_pl_announcement#/g, "");
        document.getElementById("access_control_field").value = document.getElementById("access_control_field").value.replace(/#Access_To_pl_announcement#/g, "");
        document.getElementById("access_control").innerHTML = document.getElementById("access_control").innerHTML.replace(/#Access_To_pl_photo#/g, "");
        document.getElementById("access_control_field").value = document.getElementById("access_control_field").value.replace(/#Access_To_pl_photo#/g, "");
        document.getElementById("access_control").innerHTML = document.getElementById("access_control").innerHTML.replace(/#Access_To_pl_referral#/g, "");
        document.getElementById("access_control_field").value = document.getElementById("access_control_field").value.replace(/#Access_To_pl_photo#/g, "");
    }

    document.getElementById("access_control").innerHTML += "\n#Access_To_"+domain+"_"+module+"#";
    document.getElementById("access_control_field").value += "\n#Access_To_"+domain+"_"+module+"#";

}
/**
 *
 * @param module
 */
function removeAccess (module)
{
    var domain = document.getElementById("pl_site").checked ? "pl" : "st";
    if (document.getElementById("pl_site").checked)
    {
        if (module == 'schedule')
        {
            document.getElementById("access_control").innerHTML = document.getElementById("access_control").innerHTML.replace(/#Access_To_pl_schedule#/g, "");
            document.getElementById("access_control_field").value = document.getElementById("access_control_field").value.replace(/#Access_To_pl_schedule#/g, "");
        }
        else if (module == 'announcement')
        {
            document.getElementById("access_control").innerHTML = document.getElementById("access_control").innerHTML.replace(/#Access_To_pl_announcement#/g, "");
            document.getElementById("access_control_field").value = document.getElementById("access_control_field").value.replace(/#Access_To_pl_announcement#/g, "");
        }
        else if (module == 'referral')
        {
            document.getElementById("access_control").innerHTML = document.getElementById("access_control").innerHTML.replace(/#Access_To_pl_referral#/g, "");
            document.getElementById("access_control_field").value = document.getElementById("access_control_field").value.replace(/#Access_To_pl_referral#/g, "");
        }
        else
        {
            document.getElementById("access_control").innerHTML = document.getElementById("access_control").innerHTML.replace(/#Access_To_pl_photo#/g, "");
            document.getElementById("access_control_field").value = document.getElementById("access_control_field").value.replace(/#Access_To_pl_photo#/g, "");
        }
    }
    else
    {
        if (module == 'schedule')
        {
            document.getElementById("access_control").innerHTML = document.getElementById("access_control").innerHTML.replace(/#Access_To_st_schedule#/g, "");
            document.getElementById("access_control_field").value = document.getElementById("access_control_field").value.replace(/#Access_To_st_schedule#/g, "");
        }
        else if (module == 'announcement')
        {
            document.getElementById("access_control").innerHTML = document.getElementById("access_control").innerHTML.replace(/#Access_To_st_announcement#/g, "");
            document.getElementById("access_control_field").value = document.getElementById("access_control_field").value.replace(/#Access_To_st_announcement#/g, "");
        }
        else
        {
            document.getElementById("access_control").innerHTML = document.getElementById("access_control").innerHTML.replace(/#Access_To_st_photo#/g, "");
            document.getElementById("access_control_field").value = document.getElementById("access_control_field").value.replace(/#Access_To_st_photo#/g, "");
        }
    }
}
/**
 *
 */
function getMessaingCheckBoxSelection ()
{
    var path = "";
    path += ("&allusers="+document.getElementById ("allusers").checked);
    path += ("&interested_students="+document.getElementById ("interested_students").checked);
    path += ("&registered_students="+document.getElementById ("registered_students").checked);
    path += ("&travelled_students="+document.getElementById ("travelled_students").checked);
    path += ("&cancelled_students="+document.getElementById ("cancelled_students").checked);
    path += ("&allstudents="+document.getElementById ("allstudents").checked);
    path += ("&interested_parents="+document.getElementById ("interested_parents").checked);
    path += ("&registered_parents="+document.getElementById ("registered_parents").checked);
    path += ("&travelled_parents="+document.getElementById ("travelled_parents").checked);
    path += ("&cancelled_parents="+document.getElementById ("cancelled_parents").checked);
    path += ("&allparents="+document.getElementById ("allparents").checked);
    path += ("&interested_adults="+document.getElementById ("interested_adults").checked);
    path += ("&registered_adults="+document.getElementById ("registered_adults").checked);
    path += ("&travelled_adults="+document.getElementById ("travelled_adults").checked);
    path += ("&cancelled_adults="+document.getElementById ("cancelled_adults").checked);
    path += ("&alladults="+document.getElementById ("alladults").checked);
    path += ("&promotional="+document.getElementById ("promotional").checked);
    {
        var userGroups = document.getElementById("user_groups").value;
        var mySplitResult = userGroups.split("|");

        for(i = 0; i < mySplitResult.length; i++){
            if (mySplitResult[i].indexOf("=")>0)
            {
                var eachGroup = mySplitResult[i].split("=");
                if (document.getElementById (eachGroup[0]) != undefined)
                    path += ("&"+eachGroup[0]+"="+document.getElementById (eachGroup[0]).checked);
            }
        }

    }

    return path;
}


/**
 * cool staff
 *
 * @param column
 * @param existingSortColumn
 * @param exisitngOrder
 */
function tripComponentSortData (module, tripID, column, existingSortColumn, exisitngOrder)
{
    var path = "/"+module+".xml?tripID="+tripID;
    if (column == existingSortColumn)
    {
        if (exisitngOrder=='asc')
           path += ("&sort="+column+"&order=desc");
        else
           path += ("&sort="+column+"&order=asc");
    }
    else
    {
        path += ("&sort="+column+"&order=asc");
    }
    window.location.assign(path);
}
/**
 * cool staff
 *
 * @param column
 * @param existingSortColumn
 * @param exisitngOrder
 */
function tripFileSortData (prefix, module, tripID, column, existingSortColumn, exisitngOrder, entity, queryString, actionParam)
{
    if (prefix.substr(1,2) == 'hp')
        module = "hp_" + module;

    var path = ""+module+"?tripID=" + tripID + "&"+entity + "=" + getParameter(queryString, entity);
    if (column == existingSortColumn)
    {
        if (exisitngOrder=='asc')
           path += ("&fileSortColumn="+column+"&fileSortOrder=desc");
        else
           path += ("&fileSortColumn="+column+"&fileSortOrder=asc");
    }
    else
    {
        path += ("&fileSortColumn="+column+"&fileSortOrder=asc");
    }
    path += "&action="+actionParam;
    window.location.assign(path);
}

function getParameter ( queryString, parameterName ) {
    // Add "=" to the parameter name (i.e. parameterName=value)
    var parameterName = parameterName + "=";
    if ( queryString.length > 0 )
    {
        // Find the beginning of the string
        begin = queryString.indexOf ( parameterName );
        // If the parameter name is not found, skip it, otherwise return the value
        if ( begin != -1 ) {
            // Add the length (integer) to the beginning
            begin += parameterName.length;
            // Multiple parameters are separated by the "&" sign
            end = queryString.indexOf ( "&" , begin );
            if ( end == -1 ) {
                end = queryString.length
            }
            // Return the string
            return unescape ( queryString.substring ( begin, end ) );
        }
        // Return "null" if no parameter has been found
        return "null";
    }
}

function confirmArchiveAction ()
{
   return confirm ("View archive will cause the unsaved information to be lost, are you sure to proceed?");

}

function updateArchiveImagePath (imagePath)
{
    document.getElementById("image").value=imagePath;
}

function toggleMessagingUserSelection ()
{
	var inputs = document.getElementsByTagName("input");

	for(var i = 0; i < inputs.length; i++ )
	{
		var input = inputs[i];
		if (input.type=="checkbox"
                &&
           input.id.indexOf("selected_customer_")==0)
        {
            if (input.checked)
                input.checked = false;
            else
                input.checked = true;
        }

	}
}

function checkSurveySelection ()
{
    var totalSelected = 0;
    for (var i =0; i <12; i++)
    {
        if (document.getElementById("c"+(i+1)).checked)
        {
//            if (i==12 && !checkInput ("ur_own", "You have to compose a valid issue."))
//            {
//                return false;
//            }
            totalSelected ++;
        }
    }


//    if (  !document.getElementById("president1").checked
//        &&
//          !document.getElementById("president2").checked
//        &&
//          !document.getElementById("president3").checked
//        &&
//          !document.getElementById("president4").checked
//            )
//    {
//        alert ("Please choose your 2008 president candidate.");
//        return false;
//    }

    if (totalSelected != 4)
    {
        alert ("You must make and only make 4 selections");
        return false;
    }

    if (!checkInput ("fname", "First name is required."))
        return false;

    if (!checkInput ("lname", "Last name is required."))
        return false;

    if (!checkInput ("grade", "Grade is required."))
        return false;

    if (!checkInput ("state", "State is required."))
        return false;

    if (!confirm("You only can vote once, are you sure about your choices?"))
    {
        return false;
    }

    return true;
}

function registerEventhandler()
{
    document.getElementById('moreGroup').onclick = works_for_all;
}

function works_for_all(evnt)
{
    if (document.getElementById("addGroup").style.display == "block")
    {
        document.getElementById("moreGroup").src = "/images/hp/jan_images/upload_files_01.gif";
        document.getElementById("addGroup").style.display = "none";
        return false;
    }

    document.getElementById("addGroup").style.display = "block";
    document.getElementById("moreGroup").src = "/images/hp/jan_images/upload_files_01.gif";

    var X = 0;
    var Y = 0;
    if(evnt)
    {
      X = evnt.pageX;
      Y = evnt.pageY;
    }
    else
    {
  	  var coords = {left:0, top:0};
		coords.left = event.clientX + document.body.scrollLeft - document.body.clientLeft;
		coords.top = event.clientY + document.body.scrollTop - document.body.clientTop;
		// include html element space, if applicable
		if (document.body.parentElement && document.body.parentElement.clientLeft)
		{
			var bodParent = document.body.parentElement;
			coords.left += bodParent.scrollLeft - bodParent.clientLeft;
			coords.top += bodParent.scrollTop - bodParent.clientTop;
		}
      X = coords.left;
      Y = coords.top;
    }

    var dd=document.getElementById("moreGroup");
    document.getElementById("addGroup").style.top = (Y+20+"px");
    document.getElementById("addGroup").style.left = (X-260+"px");
}


function checkInputAndHiddenAddGroupBlock ()
{
    if (document.getElementById("newGroup").value=="")
    {
        alert("You have to input a valid group name.");
        return false;
    }

    window.location.assign("/messaging_pl.xml?action=addNewGroup&tripID="
            + document.getElementById("trip_id").value
            + "&newGroup="
            + document.getElementById("newGroup").value
            );
    return false;
}

function confirmDeleteUser (name, id)
{
   if (confirm("Are you sure you want to remove "+name))
        window.location.assign("/messaging_pl.xml?action=removeUser&tripID="
                    + document.getElementById("trip_id").value
                    + "&userID="+ id
                    + "&userName="+ name
                    + getMessaingCheckBoxSelection()
                    );
   else
    return false;
}

function precheckUserGroupCheckbox (selected)
{
    var selected_groups = selected.split(";");
    for (i=0; i < selected_groups.length; i++)
    {
        document.getElementById(selected_groups[i]).checked = true;
    }
}

function swopButton (id)
{
    document.getElementById("remove_"+id).style.display="none";
    document.getElementById("save_"+id).style.display="block";

}

function saveIndividualUserInformation (id)
{
    if (!checkInput ("customer_"+id+"_email", "Email can not be null"))
        return false;
    if (!checkInput ("customer_"+id+"_name", "Name can not be null"))
        return false;
    window.location.assign("/messaging_pl.xml?action=saveIndividualUser&tripID="
                + document.getElementById("trip_id").value
                + "&email="+ document.getElementById("customer_"+id+"_email").value
                + "&name="+  document.getElementById("customer_"+id+"_name").value
                + "&id="+  id
                + getMessaingCheckBoxSelection()
                );
    return false;

}

function decideChildBoxDisplay ()
{
    if (document.getElementById("13oryoungerCheckbox").checked)
    {
        document.getElementById("child_box").style.visibility="visible";
    }
    else
        document.getElementById("child_box").style.visibility="hidden";
}

function getRegistrationSelectHelpChoice ()
{
    var cat = "register_default";
    if (document.getElementById('selection') != undefined
            &&
        document.getElementById('selection').value != undefined
            &&
        document.getElementById('selection').value != '')
        cat = document.getElementById('selection').value;
    window.open('/help.xml?code='+cat, cat, 'width=625,height=580,location=no,menubar=no,toolbar=no,scrollbars=yes');
    return false;
}


function confirmDeletingItem (path)
{
    if (confirm("Please NOTE: Removing an announcement will delete all the associated Sub Categories as well. Are you sure you want to Remove the item? ") )
    {
        window.location.assign(path);
        return false;
    }

}


function confirmDeletingFile (path)
{
    if (confirm("Are you sure you wish to permanently remove this upload? ") )
    {
        window.location.assign(path);
        return false;
    }

}

function goToSubCategory (path, meID)
{
    var id = document.getElementById("subcategory"+meID).value;

    if (id =='')
        return false;
    else if (id.charAt(0) == 's' && confirm("Are you sure to be redirected to this sub category?"))
    {
        window.location.assign(path
                +"tripID="+document.getElementById("tripID").value
                +"&announcementID="+id.replace("s", "")
                +"&action=goToSubcategory"
                );
    }
    else if (id.charAt(0) == 'c' && confirm("Are you sure to be redirected to this announcement?"))
    {
        window.location.assign(path
                +"tripID="+document.getElementById("tripID").value
                +"&announcementID="+id.replace("c", "")
                );
    }
    return false;
}

function userUploadFile ()
{
    if (document.getElementById('subcategory_choice').value =='')
    {
        alert("You have to choose which announcement or subcatory you want to upload the file to.");
        return false;
    }
    if (document.getElementById('fileName').value =='')
    {
        alert("You have to name the file.");
        return false;
    }
    if (document.getElementById('filePath').value =='')
    {
        alert("You have to choose a valid file from your drive.");
        return false;
    }
    document.getElementById('addGroup').style.display = 'none';
    this.form.submit();
    return false;
}

function hideBox ()
{
    document.getElementById('addGroup').style.display = 'none';
}

function choosePlaceToUploadTo (topic_component_id, elementID)
{
    //it means that this is a sub category
    if (topic_component_id != '' && document.getElementById(elementID).value.charAt(0)=='c')
    {
        document.getElementById("uploadFilebutton").style.display='none';
    }
    else
    {
        document.getElementById("uploadFilebutton").style.display='block';
    }

}


function confirmAllowUserViewFiles (existingValue)
{
    if (existingValue==''
            &&
        document.getElementById("allow_all_user_view").checked==true
            &&
        !confirm("Are you sure you want to allow all users to view the uploaded files?"))
    {
        document.getElementById("allow_all_user_view").checked = false;
    }
}


function fireUpWSPage (tdid, securityKey, pay)
{
    window.location.assign("https://olr.worldstrides.net/scripts/cgiip.exe/TDCentral/MyTrip/CustProfile.htm?customerID="+tdid+"&securityHash="+securityKey+"&pay="+pay+"&hotlink=yes&src=ebill");
}

function partiallyUpdateDivOnPage (elementID, path, parameterName, parameterPath)
{
    new Ajax.Updater(elementID, path+"?"+parameterName+"="+parameterPath, {
                     method: 'post',
                     insertion: Insertion.Top
                     });
}

function logMeIn (login, password)
{
    window.location.assign("/login.xml?form-id=login&login="+login+"&password="+password);
}

function redirectToLoginPage(login, password)
{
    setTimeout ("logMeIn('"+login+"', '"+password+"')", 3000);
    return true;
}

function confirmReferralSubmission ()
{
    return confirm("Are you sure? Submit referral form now?");
}

function copy_content (div_name)
{
    alert(document.getElementById(div_name).innerHTML);
    try {
        textRange = document.getElementById(div_name).innerHTML.createTextRange();
        textRange.execCommand("RemoveFormat");
        textRange.execCommand("Copy");
    } catch(ex) {
        alert(ex);
    }
}


