var bwc_crew_candidate_xml_http;
var bwc_crew_customer_xml_http;

var bwc_contact_form_xml_http;

function sendContactEmail(p_action, p_name, p_company, p_email, p_phone, p_country_id, p_subject, p_question) { 
	bwc_contact_form_xml_http = sendContactEmailHttpObject()
	if (bwc_contact_form_xml_http == null) {
		alert ("Browser does not support HTTP Request")
		return
	}
 	
	var url = "contact_form.php"
	var params = "action=" + p_action
	params += "&name=" + urlencode(p_name)
	params += "&company=" + urlencode(p_company)
	params += "&email=" + urlencode(p_email)
	params += "&phone=" + urlencode(p_phone)
	params += "&country_id=" + p_country_id
	params += "&subject=" + urlencode(p_subject)
	params += "&question=" + urlencode(p_question)
	
	bwc_contact_form_xml_http.onreadystatechange = sendContactEmailStateChanged 
	bwc_contact_form_xml_http.open("POST", url, true)
	bwc_contact_form_xml_http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	bwc_contact_form_xml_http.setRequestHeader("Content-length", params.length);
	bwc_contact_form_xml_http.setRequestHeader("Connection", "close");
	bwc_contact_form_xml_http.send(params);	
}

function sendContactEmailStateChanged() {
	if (bwc_contact_form_xml_http.readyState == 4 || bwc_contact_form_xml_http.readyState == "complete") { 
		document.getElementById("div_contact_form").innerHTML = bwc_contact_form_xml_http.responseText 
	} 
	if (bwc_contact_form_xml_http.readyState == 1 || bwc_contact_form_xml_http.readyState == "Loading") { 
		document.getElementById("div_contact_form").innerHTML = "<div class=\"listing_border\" style=\"background-color: #FFFFFF; padding: 10px;\"><img src=\"_images/_icons/16x16/icon_clock.gif\" width=\"16\" height=\"16\" align=\"absmiddle\"> Sending !</div>";
	}
}

function sendContactEmailHttpObject() {
	var bwc_contact_form_xml_http = null;
	try {
		// Firefox, Opera 8.0+, Safari
		 bwc_contact_form_xml_http = new XMLHttpRequest();
	} catch (e) {
		//Internet Explorer
		try {
			bwc_contact_form_xml_http = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			bwc_contact_form_xml_http = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return bwc_contact_form_xml_http;
}



/***********************************/
/* Actions                         */
/***********************************/
function showCrewCandidateRegisterLogin() { 
	bwc_crew_candidate_xml_http = crewCandidateRegisterGetXmlHttpObject()
	if (bwc_crew_candidate_xml_http == null) {
		alert ("Browser does not support HTTP Request")
		return
	}
 	
	var url = "index_candidate_register.php"
	var params = "action=register_login"
	
	bwc_crew_candidate_xml_http.onreadystatechange = crewCandidateRegisterStateChanged 
	bwc_crew_candidate_xml_http.open("POST", url, true)
	bwc_crew_candidate_xml_http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	bwc_crew_candidate_xml_http.setRequestHeader("Content-length", params.length);
	bwc_crew_candidate_xml_http.setRequestHeader("Connection", "close");
	bwc_crew_candidate_xml_http.send(params);	
}

function showCrewCandidateRegisterLoginCheck(p_email) { 
	bwc_crew_candidate_xml_http = crewCandidateRegisterGetXmlHttpObject()
	if (bwc_crew_candidate_xml_http == null) {
		alert ("Browser does not support HTTP Request")
		return
	}
 	
	var url = "index_candidate_register.php"
	var params = "action=register_login_check"
	params += "&email=" + urlencode(p_email)
	
	bwc_crew_candidate_xml_http.onreadystatechange = crewCandidateRegisterStateChanged 
	bwc_crew_candidate_xml_http.open("POST", url, true)
	bwc_crew_candidate_xml_http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	bwc_crew_candidate_xml_http.setRequestHeader("Content-length", params.length);
	bwc_crew_candidate_xml_http.setRequestHeader("Connection", "close");
	bwc_crew_candidate_xml_http.send(params);	
}

function showCrewCandidateRegisterPersonalInformationCheck(p_gender, p_first_name, p_last_name) { 
	bwc_crew_candidate_xml_http = crewCandidateRegisterGetXmlHttpObject()
	if (bwc_crew_candidate_xml_http == null) {
		alert ("Browser does not support HTTP Request")
		return
	}
 	
	var url = "index_candidate_register.php"
	var params = "action=personal_information_check"
	params += "&gender=" + urlencode(p_gender)
	params += "&first_name=" + urlencode(p_first_name)
	params += "&last_name=" + urlencode(p_last_name)
	
	bwc_crew_candidate_xml_http.onreadystatechange = crewCandidateRegisterStateChanged 
	bwc_crew_candidate_xml_http.open("POST", url, true)
	bwc_crew_candidate_xml_http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	bwc_crew_candidate_xml_http.setRequestHeader("Content-length", params.length);
	bwc_crew_candidate_xml_http.setRequestHeader("Connection", "close");
	bwc_crew_candidate_xml_http.send(params);	
}

function showCrewCandidateRegisterPasswordCheck(p_password, p_confirm_password) { 
	bwc_crew_candidate_xml_http = crewCandidateRegisterGetXmlHttpObject()
	if (bwc_crew_candidate_xml_http == null) {
		alert ("Browser does not support HTTP Request")
		return
	}
 	
	var url = "index_candidate_register.php"
	var params = "action=password_check"
	params += "&password=" + urlencode(p_password)
	params += "&confirm_password=" + urlencode(p_confirm_password)
	
	bwc_crew_candidate_xml_http.onreadystatechange = crewCandidateRegisterStateChanged 
	bwc_crew_candidate_xml_http.open("POST", url, true)
	bwc_crew_candidate_xml_http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	bwc_crew_candidate_xml_http.setRequestHeader("Content-length", params.length);
	bwc_crew_candidate_xml_http.setRequestHeader("Connection", "close");
	bwc_crew_candidate_xml_http.send(params);	
}

function processCrewCandidateLogon(p_login, p_password) { 
	bwc_crew_candidate_xml_http = crewCandidateRegisterGetXmlHttpObject()
	if (bwc_crew_candidate_xml_http == null) {
		alert ("Browser does not support HTTP Request")
		return
	}
 	
	var url = "index_crew_logon.php"
	var params = "action=logon"
	
	params += "&login=" + urlencode(p_login)
	params += "&password=" + urlencode(p_password)
	
	bwc_crew_candidate_xml_http.onreadystatechange = crewCandidateLogonStateChanged 
	bwc_crew_candidate_xml_http.open("POST", url, true)
	bwc_crew_candidate_xml_http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	bwc_crew_candidate_xml_http.setRequestHeader("Content-length", params.length);
	bwc_crew_candidate_xml_http.setRequestHeader("Connection", "close");
	bwc_crew_candidate_xml_http.send(params);	
}

function showCrewCandidateLogon() { 
	bwc_crew_candidate_xml_http = crewCandidateRegisterGetXmlHttpObject()
	if (bwc_crew_candidate_xml_http == null) {
		alert ("Browser does not support HTTP Request")
		return
	}
 	
	var url = "index_logon_form.php"
	var params = ""
	
	bwc_crew_candidate_xml_http.onreadystatechange = crewCandidateRegisterStateChanged 
	bwc_crew_candidate_xml_http.open("POST", url, true)
	bwc_crew_candidate_xml_http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	bwc_crew_candidate_xml_http.setRequestHeader("Content-length", params.length);
	bwc_crew_candidate_xml_http.setRequestHeader("Connection", "close");
	bwc_crew_candidate_xml_http.send(params);	
}

function showCrewCandidatePasswordRecovery() { 
	bwc_crew_candidate_xml_http = crewCandidateRegisterGetXmlHttpObject()
	if (bwc_crew_candidate_xml_http == null) {
		alert ("Browser does not support HTTP Request")
		return
	}
 	
	var url = "index_candidate_password_recovery_form.php"
	var params = ""
	
	bwc_crew_candidate_xml_http.onreadystatechange = crewCandidateRegisterStateChanged 
	bwc_crew_candidate_xml_http.open("POST", url, true)
	bwc_crew_candidate_xml_http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	bwc_crew_candidate_xml_http.setRequestHeader("Content-length", params.length);
	bwc_crew_candidate_xml_http.setRequestHeader("Connection", "close");
	bwc_crew_candidate_xml_http.send(params);	
}

function processCrewCandidatePasswordRecovery(p_email) { 
	bwc_crew_candidate_xml_http = crewCandidateRegisterGetXmlHttpObject()
	if (bwc_crew_candidate_xml_http == null) {
		alert ("Browser does not support HTTP Request")
		return
	}
 	
	var url = "index_candidate_password_recovery.php"
	var params = "action=recover"
	params += "&email=" + urlencode(p_email)
	
	bwc_crew_candidate_xml_http.onreadystatechange = crewCandidateRegisterStateChanged 
	bwc_crew_candidate_xml_http.open("POST", url, true)
	bwc_crew_candidate_xml_http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	bwc_crew_candidate_xml_http.setRequestHeader("Content-length", params.length);
	bwc_crew_candidate_xml_http.setRequestHeader("Connection", "close");
	bwc_crew_candidate_xml_http.send(params);	
}

function crewCandidateRegisterStateChanged() { 
	if (bwc_crew_candidate_xml_http.readyState == 4 || bwc_crew_candidate_xml_http.readyState == "complete") { 
		document.getElementById("div_logon_form").innerHTML = bwc_crew_candidate_xml_http.responseText 
	} 
	if (bwc_crew_candidate_xml_http.readyState == 1 || bwc_crew_candidate_xml_http.readyState == "Loading") { 
		document.getElementById("div_logon_form").innerHTML = "Loading ..." 
	}
}

function crewCandidateLogonStateChanged() { 
	if (bwc_crew_candidate_xml_http.readyState == 4 || bwc_crew_candidate_xml_http.readyState == "complete") { 
		if (bwc_crew_candidate_xml_http.responseText == "bwc_logon_ok") { 
			window.location = '_candidates/welcome.php'; 
		} else {
			document.getElementById("div_logon_form").innerHTML = bwc_crew_candidate_xml_http.responseText 
		}
	}
	if (bwc_crew_candidate_xml_http.readyState == 1 || bwc_crew_candidate_xml_http.readyState == "Loading") { 
		document.getElementById("div_logon_form").innerHTML = "Logon in progess ..." 
	}
}

function crewCandidateRegisterGetXmlHttpObject() {
	var bwc_crew_candidate_xml_http = null;
	try {
		// Firefox, Opera 8.0+, Safari
		 bwc_crew_candidate_xml_http = new XMLHttpRequest();
	} catch (e) {
		//Internet Explorer
		try {
			bwc_crew_candidate_xml_http = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			bwc_crew_candidate_xml_http = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return bwc_crew_candidate_xml_http;
}




function processCrewCustomerLogon(p_login, p_password) { 
	bwc_crew_customer_xml_http = crewCustomerGetXmlHttpObject()
	if (bwc_crew_customer_xml_http == null) {
		alert ("Browser does not support HTTP Request")
		return
	}
 	
	var url = "index_customer_logon.php"
	var params = "action=logon"
	params += "&login=" + urlencode(p_login)
	params += "&password=" + urlencode(p_password)
	
	bwc_crew_customer_xml_http.onreadystatechange = crewCustomerLogonStateChanged 
	bwc_crew_customer_xml_http.open("POST", url, true)
	bwc_crew_customer_xml_http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	bwc_crew_customer_xml_http.setRequestHeader("Content-length", params.length);
	bwc_crew_customer_xml_http.setRequestHeader("Connection", "close");
	bwc_crew_customer_xml_http.send(params);	
}

function crewCustomerStateChanged() { 
	if (bwc_crew_customer_xml_http.readyState == 4 || bwc_crew_customer_xml_http.readyState == "complete") { 
		if (bwc_crew_customer_xml_http.responseText == "bwc_logon_ok") { 
			window.location = '_customers/welcome.php'; 
		} else {
			document.getElementById("div_logon_form").innerHTML = bwc_crew_customer_xml_http.responseText 
		}
	}
	if (bwc_crew_customer_xml_http.readyState == 1 || bwc_crew_customer_xml_http.readyState == "Loading") { 
		document.getElementById("div_logon_form").innerHTML = "Loading ..." 
	}
}

function crewCustomerLogonStateChanged() { 
	if (bwc_crew_customer_xml_http.readyState == 4 || bwc_crew_customer_xml_http.readyState == "complete") { 
		if (bwc_crew_customer_xml_http.responseText == "bwc_logon_ok") { 
			window.location = '_customers/welcome.php'; 
		} else if (bwc_crew_customer_xml_http.responseText == "bwc_password_expired") { 
			window.location = '_customers/bwc_customer_account.php';
		} else {
			document.getElementById("div_logon_form").innerHTML = bwc_crew_customer_xml_http.responseText 
		}
	}
	if (bwc_crew_customer_xml_http.readyState == 1 || bwc_crew_customer_xml_http.readyState == "Loading") { 
		document.getElementById("div_logon_form").innerHTML = "Logon in progess ..." 
	}
}

function showCrewCustomerLogon() { 
	bwc_crew_customer_xml_http = crewCustomerGetXmlHttpObject()
	if (bwc_crew_customer_xml_http == null) {
		alert ("Browser does not support HTTP Request")
		return
	}
 	
	var url = "index_logon_form.php"
	var params = "login_type=employer"
	
	bwc_crew_customer_xml_http.onreadystatechange = crewCustomerStateChanged 
	bwc_crew_customer_xml_http.open("POST", url, true)
	bwc_crew_customer_xml_http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	bwc_crew_customer_xml_http.setRequestHeader("Content-length", params.length);
	bwc_crew_customer_xml_http.setRequestHeader("Connection", "close");
	bwc_crew_customer_xml_http.send(params);	
}

function crewCustomerGetXmlHttpObject() {
	var bwc_crew_customer_xml_http = null;
	try {
		// Firefox, Opera 8.0+, Safari
		 bwc_crew_customer_xml_http = new XMLHttpRequest();
	} catch (e) {
		//Internet Explorer
		try {
			bwc_crew_customer_xml_http = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			bwc_crew_customer_xml_http = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return bwc_crew_customer_xml_http;
}





/*********************/
/* Process logon     */
/*********************/
function processLogon(p_type, p_login, p_password) { 
	bwc_logon_xml_http = logonGetXmlHttpObject()
	if (bwc_logon_xml_http == null) {
		alert ("Browser does not support HTTP Request")
		return
	}
 	

	// Crew
	if (p_type == "crew") {	
		
		var url = "index_crew_logon.php"
		var params = "action=logon"
		params += "&login=" + urlencode(p_login)
		params += "&password=" + urlencode(p_password)	
		
		bwc_logon_xml_http.onreadystatechange = logonCrewStateChanged 
	
	// Employer
	} else if (p_type == "employer") {
	
		var url = "index_customer_logon.php"
		var params = "action=logon"
		params += "&login=" + urlencode(p_login)
		params += "&password=" + urlencode(p_password)	
		
		bwc_logon_xml_http.onreadystatechange = logonCustomerStateChanged 
	}
	
	bwc_logon_xml_http.open("POST", url, true)
	bwc_logon_xml_http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	bwc_logon_xml_http.setRequestHeader("Content-length", params.length);
	bwc_logon_xml_http.setRequestHeader("Connection", "close");
	bwc_logon_xml_http.send(params);
}


function logonCrewStateChanged() { 
	if (bwc_logon_xml_http.readyState == 4 || bwc_logon_xml_http.readyState == "complete") { 
		if (bwc_logon_xml_http.responseText == "bwc_logon_ok") { 
			window.location = '_candidates/welcome.php';
		} else {
			document.getElementById("div_logon_form").innerHTML = bwc_logon_xml_http.responseText 
		}
	}
	if (bwc_logon_xml_http.readyState == 1 || bwc_logon_xml_http.readyState == "Loading") { 
		document.getElementById("div_logon_form").innerHTML = "Logon in progess ..." 
	}
}

function logonCustomerStateChanged() { 
	if (bwc_logon_xml_http.readyState == 4 || bwc_logon_xml_http.readyState == "complete") { 
		if (bwc_logon_xml_http.responseText == "bwc_logon_ok") { 
			window.location = '_customers/welcome.php';
		} else {
			document.getElementById("div_logon_form").innerHTML = bwc_logon_xml_http.responseText 
		}
	}
	if (bwc_logon_xml_http.readyState == 1 || bwc_logon_xml_http.readyState == "Loading") { 
		document.getElementById("div_logon_form").innerHTML = "Logon in progess ..." 
	}
}

function logonGetXmlHttpObject() {
	var bwc_logon_xml_http = null;
	try {
		// Firefox, Opera 8.0+, Safari
		 bwc_logon_xml_http = new XMLHttpRequest();
	} catch (e) {
		//Internet Explorer
		try {
			bwc_logon_xml_http = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			bwc_logon_xml_http = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return bwc_logon_xml_http;
}