/***********************************************************************
The following source code is licensed to Tom Nacos Group.
All usage of this code outside tomnacosgroup.com is strictly prohibited.
Copyright (c) Abstraction Media 2009 // All rights reserved
www.abstractionmedia.com
***********************************************************************/
opacity = 10;
delay = 45;
function loadcompany(value, form){
	var input = document.createElement("input");
	input.type = "hidden";
	input.name = "step3"
	form.appendChild(input);
	form.action = url +language+ "/" + value;
	form.submit();
}
function selectcheckbox(){
	document.getElementById("wildcard").checked = true;
}
function formatphonenumber(event, obj){
	if(event.keyCode != 8){
		var value = obj.value.replace(/[^0-9]/g, "");
		if(value.length == 3){
			obj.value = "(" +value+ ") ";
		}
		else if(value.length > 3 & value.length < 6){
			obj.value = "(" +value.substr(0, 3)+ ") " +value.substr(3, 3);
		}
		else if(value.length > 5){
			if(value.length < 10){
				obj.value = "(" +value.substr(0, 3)+ ") " +value.substr(3, 3)+ "-" +value.substr(6, 4);
			}
		}
	}
}
function flashup(id, value){
	var obj = document.getElementById(id);
	if(value < 11){
		var value = value + 1;
		obj.style.opacity = value/10;
		obj.style.filter = "alpha(opacity=" + value*10 + ")";
		setTimeout("flashup('" +id+ "', "+value+");", delay);
	}
}
function flash(id, value){
	var obj = document.getElementById(id);
	if(value > 2){
		var value = value - 1;
		obj.style.opacity = value/10;
		obj.style.filter = "alpha(opacity=" + value*10 + ")";
		setTimeout("flash('" +id+ "', "+value+");", delay);
	}
	else {
		setTimeout("flashup('" +id+ "', "+value+");", delay);
	}
}
if(language == "fr"){
	invalidentrytext = "Entrée invalide";
	emailconfirmationfailedtext = "La validation du courriel à échouée";
	wrongfiletypetext = "Type de fichier invalide";
}
else {
	invalidentrytext = "Invalid entry";
	emailconfirmationfailedtext = "The email validation failed";
	wrongfiletypetext = "Invalid file type";
}
function validatestep1(form){	
	var name = form.name.value.replace(/[^a-z]/gi, "");
	if(name.length < 2){
		alert(invalidentrytext);
		flash("nameinput", opacity);
		return false;
	}
	return true;
}
function validatestep2(form){
	var phonenumber = form.phonenumber.value.replace(/[^0-9]/g, "");
	var validation = form.email.value.match(/^[a-z0-9._-]+@[a-z0-9-]+\.[a-z.]{2,5}$/);
	if(phonenumber.length < 10){
		alert(invalidentrytext);
		flash("phonenumberinput", opacity);
		return false;
	}
	if(validation == null){
		alert(invalidentrytext);
		flash("emailinput", opacity);
		return false;
	}
	if(form.email.value != form.emailconfirmation.value){
		alert(emailconfirmationfailedtext);
		flash("emailconfirmationinput", opacity);
		return false;
	}
	return true;
}
function validatestep3(form){
	if(form.title.value == ""){
		alert(invalidentrytext);
		flash("titleinput", opacity);
		return false;
	}
	if(form.french.checked == false & form.english.checked == false & form.other.value == ""){
		alert(invalidentrytext);
		flash("languageinput", opacity);
		return false;
	}
	if(form.explanation.value == ""){
		alert(invalidentrytext);
		flash("explanationinput", opacity);
		return false;
	}
	if(form.resume.value == ""){
		alert(invalidentrytext);
		flash("resumeinput", opacity);
		flash("graphicalfileinput", opacity);
		return false;
	}
	return true;
}
var W3CDOM = (document.createElement && document.getElementsByTagName);
if(W3CDOM){
	function updatefileinputs(height, width){
		var fileInputReplacement = document.createElement("div");
		fileInputReplacement.className = "replacement";
		fileInputReplacement.id = "graphicalfileinput";
		var image = document.createElement("img");
		image.src = url+ "css/" +language+ "/input.jpg";
		fileInputReplacement.appendChild(image);
		fileInput = document.getElementById("resume");
		fileInput.parentNode.style.width = width+ "px";
		fileInput.parentNode.style.height = height+ "px";
		var offset = 0 - (fileInput.offsetWidth - width);
		fileInput.style.marginLeft = offset+ "px";
		fileInput.className = "file";
		fileInput.parentNode.appendChild(fileInputReplacement.cloneNode(true));
		fileInput.onchange = function(){
			if(this.value != ""){
				var nodes = this.parentNode.childNodes;
				if(nodes[0].value.match(/\.doc$/i) != null || nodes[0].value.match(/\.pdf$/i) != null){
					nodes[1].childNodes[0].src = url+ "css/" +language+ "/inputon.jpg";
				}
				else {
					nodes[1].childNodes[0].src = url+ "css/" +language+ "/input.jpg";
					alert(wrongfiletypetext);
					flash("resumeinput", 10);
					flash("graphicalfileinput", opacity);
					fileInput.value = "";
				}
			}
		}
	}
}
