// show-hide help

function setStyles() {
		document.getElementById('phone').style.display = "none";
		document.getElementById('online').style.display = "none";
		document.getElementById('complaint').style.display = "none";
		document.getElementById('feedback').style.display = "none";
		document.getElementById('office').style.display = "none";
	
}


var subs_array = new Array("phone","online","complaint","feedback","office");// Put the id's of your hidden divs in this array

function displaySubs(the_sub){
	if (document.getElementById(the_sub).style.display==""){
	document.getElementById(the_sub).style.display = "none";
	return
  }
  for (i=0;i<subs_array.length;i++){
	var my_sub = document.getElementById(subs_array[i]);
	my_sub.style.display = "none";

	}
  	document.getElementById(the_sub).style.display = "";

  }


var arrow_array = new Array("phonei","onlinei","complainti","feedbacki","officei");// 

function changeArrow (the_arrow) {
	if (document.getElementById(the_arrow).style.backgroundImage=="url(/images/less.gif)"){
	document.getElementById(the_arrow).style.backgroundImage = "url(/images/more.gif)";
	return
  }
  for (i=0;i<arrow_array.length;i++){
	var my_arrow = document.getElementById(arrow_array[i]);
	my_arrow.style.backgroundImage = "url(/images/more.gif)";

	}
  	document.getElementById(the_arrow).style.backgroundImage = "url(/images/less.gif)";
	
}

//START Experience validation functions

function validateComp() {

	if (! isValidEmailComp(document.complaint.comp_email.value)) {
        alert("Please enter a valid email address");
        return false;
    }	
}


function isValidEmailComp(email, required) {
    if (required==undefined) {    //if not specified, assume it's required
        required=false;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {   //check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) {   //must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {   //last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {   //@ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) {  //two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {   //. must not be the last character
	return false;
    }
    return true;
}

//feedback
function validateFeedback() {

	if (document.feedback.yourname.value.length < 1) {
		alert("Please enter your name.");
		document.feedback.yourname.focus();
		return false;	
	}
	if (! isValidEmail(document.feedback.email.value)) {
        alert("Please enter a valid email address");
        return false;
    }	
}

function isValidEmail(email, required) {
    if (required==undefined) {    //if not specified, assume it's required
        required=true;
    }
    if (email==null) {
        if (required) {
            return false;
        }
        return true;
    }
    if (email.length==0) {  
        if (required) {
            return false;
        }
        return true;
    }
    if (! allValidChars(email)) {   //check to make sure all characters are valid
        return false;
    }
    if (email.indexOf("@") < 1) {   //must contain @, and it must not be the first character
        return false;
    } else if (email.lastIndexOf(".") <= email.indexOf("@")) {   //last dot must be after the @
        return false;
    } else if (email.indexOf("@") == email.length) {   //@ must not be the last character
        return false;
    } else if (email.indexOf("..") >=0) {  //two periods in a row is not valid
	return false;
    } else if (email.indexOf(".") == email.length) {   //. must not be the last character
	return false;
    }
    return true;
}

function allValidChars(email) {
  var parsed = true;
  var validchars = "abcdefghijklmnopqrstuvwxyz0123456789@.-_";
  for (var i=0; i < email.length; i++) {
    var letter = email.charAt(i).toLowerCase();
    if (validchars.indexOf(letter) != -1)
      continue;
    parsed = false;
    break;
  }
  return parsed;
}


//START Ask a Skilling Queenslanders for Work question

function validateSkill() {

	if (document.skill.skillfirst.value.length < 1) {
		alert("Please enter your first name.");
		document.skill.skillfirst.focus();
		return false;	
	}
	if (document.skill.skillfamily.value.length < 1) {
		alert("Please enter your family name.");
		document.skill.skillfamily.focus();
		return false;	
	}
	if (! isValidEmail(document.skill.skillemail.value)) {
        alert("Please enter a valid email address");
		document.skill.skillemail.focus();
        return false;
    }
	if (document.skill.skillexplain.value.length > 2000) {
		alert('Too much data in the text box! Please remove '+ (document.skill.skillexplain.value.length - 2000)+ ' characters');
		document.skill.skillexplain.focus();
		return false;
	}
}