function validate_password(){
	dom_obj_pwd = document.getElementById('Password');
	dom_obj_cmf_pwd = document.getElementById('Confirm Password');
	
	if(dom_obj_pwd.value == ""){
		return "Password can not be empty\n";
	}				
	
	if(dom_obj_pwd.value != dom_obj_cmf_pwd.value){
		return "Passwords do not match\n";
	}
	
	return "";
}
			
function validate_string(id){
	dom_obj_string = document.getElementById(id);
	
	if(dom_obj_string.value == ""){
		error = dom_obj_string.id + " can not be empty\n";
		return error;
	}
	
	return "";
}

function validate_string2(id, label){
	dom_obj_string = document.getElementById(id);
	
	if(dom_obj_string.value == ""){
		dom_obj_string.style.backgroundColor= 'yellow';
		error = label + " can not be empty\n";
		return error;
	}else {
		dom_obj_string.style.backgroundColor= '';
	}
	return "";
}
function validate_integer(id){
	dom_obj_int = document.getElementById(id);
	
	 if ((isNaN(dom_obj_int.value)) || (dom_obj_int.value == "")){
	 		error = dom_obj_int.id + " must be a numeric value\n";
			return error;
	 }
	 
	return "";
}

function validate_integer2(id,label){
	dom_obj_int = document.getElementById(id);
	
	 if ((isNaN(dom_obj_int.value)) || (dom_obj_int.value == "")){
		 dom_obj_int.style.backgroundColor= 'yellow';
 		error = label + " must be a numeric value\n";
		return error;
	}else {
		dom_obj_int.style.backgroundColor= '';
	}
	return "";
}
function validate_integer_or_empty(id){
	dom_obj_int = document.getElementById(id);
	
	if((dom_obj_int.value == "")){
		return "";
	}
	
	 if ((isNaN(dom_obj_int.value))){
	 		error = dom_obj_int.id + " must be a numeric value\n";
			return error;
	 }
	 
	return "";
}

function validate_integer_or_empty2(id,label){
	dom_obj_int = document.getElementById(id);
	
	if((dom_obj_int.value == "")){
		return "";
	}
	
	if ((isNaN(dom_obj_int.value))){
 		error = label + " must be a numeric value\n";
 		dom_obj_int.style.backgroundColor= 'yellow';
		return error;
	}else {
		dom_obj_int.style.backgroundColor= '';
	}
	return "";
}

function validate_email(id,label, mandatory){
	dom_obj_email = document.getElementById(id);
	var error = '';	
    var check =
    /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    
    if (mandatory == 1) {
    	error += validate_string2(id,label);
    }
    //if not mandatory
    
    if (!check.test(dom_obj_email.value) && dom_obj_email.value != ''){
    	if (label != "") {
			error += label+" is no valid email address.\n";
    	}else {
			error += dom_obj_email.name+" is no valid email address.\n";
    	}
    	dom_obj_email.style.backgroundColor= 'yellow';
   	}
   	if (error == ''){
   		dom_obj_email.style.backgroundColor= '';
   	}
	return error;
}

function validate_confirm_email(confirm_email, email, mandatory){
	var error = '';
	dom_obj_confirm_email = document.getElementById(confirm_email);
	dom_obj_email = document.getElementById(email);
	
    if (mandatory == 1) {
    	error += validate_string2(confirm_email, "Confirm Email");
    }	
	if (dom_obj_confirm_email.value != dom_obj_email.value) {
		error = "Email and confirmation do not match.\n";
		dom_obj_confirm_email.style.backgroundColor= 'yellow';
		return error;
	}
   	if (error == ''){
   		dom_obj_confirm_email.style.backgroundColor= '';
   	}
	return error;
}

function is_valid_date(day, month, year){
    var day = document.getElementById(day);    
    var month = document.getElementById(month);
    var year = document.getElementById(year);
    
    if (day.value!= '' && month.value!='' && year.value!='')
    {
        var myDate = new Date();
        myDate.setFullYear( year.value, month.value -1, day.value );

        if ( myDate.getMonth() != month.value -1 ) {
	        day.style.backgroundColor= 'yellow';
	        month.style.backgroundColor= 'yellow';
	        year.style.backgroundColor= 'yellow';
            return "Invalid date\n";
        } else {
	        day.style.backgroundColor= '';
	        month.style.backgroundColor= '';
	        year.style.backgroundColor= '';        
            return '';
        }
    }
    return '';
}

function validate_select_dropdown(id,label) {
	dom_obj_dropdown = document.getElementById(id);
	
	if (dom_obj_dropdown.value == '') {
		if (label != ''){
			error = label+ " must be selected.\n";
		}else {
			error = dom_obj_dropdown + " must be selected.\n";
		}
		dom_obj_dropdown.style.backgroundColor= 'yellow';
		return error;
	}else {
		dom_obj_dropdown.style.backgroundColor= '';
	}	
	return "";	
}

function getElementsByClassName(className, tag, elm){

      var testClass = new RegExp("(^|\s)" + className + "(\s|$)");	
      var tag = tag || "*";
      var elm = elm || document;
      var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);	
      var returnElements = [];	
      var current;	
      var length = elements.length;	
      for(var i=0; i<length; i++){
            current = elements[i];
            if(testClass.test(current.className)){
                  returnElements.push(current);
            }
      }
      return returnElements;
}

function validate_date(id){
	dom_obj_date = document.getElementById(id);
	var date_frmt = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
	
	if(!date_frmt.test(dom_obj_date.value)){
		error = dom_obj_date.id + " must be in the format dd/mm/yyyy\n";
		return error;	
	}
	return "";
}

function validate_club(id){
		dom_obj_club = document.getElementById(id);
		
		if(dom_obj_club.value == 0){
			error = "Please select a club\n";
			return error;
		}
		
		return "";
}

function validate_reports(id){
		dom_obj_club = document.getElementById(id);

		if(dom_obj_club.selectedIndex < 0){
			error = "Please select a report\n";
			return error;
		}
		
		return "";
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function show_hidden_alcohol(yes_or_no){

	surp = document.getElementById('surprise');
	
	if(yes_or_no == "Yes"){
		$("td.surprise").show("fast");
	} else if(yes_or_no == "No"){
		$("td.surprise").hide("fast");	
	}
}

function show_hidden_recip(yes_or_no){

	surp = document.getElementById('surprise_recip');
	
	if(yes_or_no == "Yes"){
		$("td.surprise_recip").show("fast");
	} else if(yes_or_no == "No"){
		$("td.surprise_recip").hide("fast");	
	}
}

function show_hidden_ticket(yes_or_no){

	surp = document.getElementById('surprise_ticket');
	
	if(yes_or_no == "Yes"){
		$("td.surprise_ticket").show("fast");
	} else if(yes_or_no == "No"){
		$("td.surprise_ticket").hide("fast");	
	}
}



function show_hidden_times(yes_or_no){

	surp = document.getElementById('surprise');
	
	if(yes_or_no == 1){
		$("td.surprise").show("fast");
	} else if(yes_or_no == 0){
		$("td.surprise").hide("fast");	
	}
}
			
function show_hidden_grand_stand(yes_or_no_grand){

	surp = document.getElementById('surprise_grand');
	
	if(yes_or_no_grand == "Yes"){
		$("td.surprise_grand").show("fast");
	} else if(yes_or_no_grand == "No"){
		$("td.surprise_grand").hide("fast");	
	}
	
}
		
function show_hidden_upgrade_options(yes_or_no){

	surp = document.getElementById('surprise');
	
	if(yes_or_no == "Yes"){
		$("td.surprise").show("fast");
		$("td.surpris").show("fast");
								
	} else if(yes_or_no == "No"){
		$("td.surprise").hide("fast");	
		$("td.surpris").hide("fast");
	}
	
}
		
function alter_package()
{
	package_box = document.getElementById('Package Style');
	selected_value = package_box.options[package_box.selectedIndex].value;
	list_of_package_types(selected_value);
}

function alter_clubs()
{
	club_box = document.getElementById('Clubs');
	selected_value_club = club_box.options[club_box.selectedIndex].value;
	return selected_value_club;
}		

function removeOptionSelected(id)
{
  var elSel = document.getElementById(id);
  var i;
	  for (i = elSel.length - 1; i>0; i--) {
	      elSel.remove(i);
	  }
}

function insertOptionBefore(id, club){

  var elSel = document.getElementById(id);
  var selected_club = club;
  
  var name_array = list_of_names();
  var club_array = list_of_clubs();
  var event_array = list_of_events();
  
  for(i = 0; i < name_array.length; i++){
	    	if(club_array[i] == selected_club){
				
			    var elOptNew = document.createElement('option');
		
			    elOptNew.text = name_array[i];
			    elOptNew.value = event_array[i];
			    
			    var elOptOld = elSel.options[1];  
			    try {
			      elSel.add(elOptNew, elOptOld); // standards compliant; doesn't work in IE
			    }
			    catch(ex) {
			      elSel.add(elOptNew, elSel.selectedIndex); // IE only
			    }
			    
			  }
  }
}