url = document.location.href;
xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0, xend);


function ajax_do (url) {
	// Does URL begin with http?
	if (url.substring(0, 4) != 'http') {
			url = base_url + url;
	}

	// Create new JS element
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = url;

	// Append JS element (therefore executing the 'AJAX' call)
	document.body.appendChild (jsel);
}

function getobject_main(obj){
	  if (document.getElementById)
		 return document.getElementById(obj)
	  else if (document.all)
		 return document.all[obj]
}

function submitQuestion() {
	var myquestion = getobject_main("question").value;
	var randomString = new Date().getTime();
	
	var where_is_xanadu=myquestion.indexOf('Xanadu');

	myquestion=myquestion.replace(/\"/g,'\'');
	myquestion=myquestion.replace(/'/g,'\'');

	/*
	
	if (where_is_xanadu > 0) {
		
		alert("We'd appreciate it if your questions were more health-related instead of being specific to Xanadu. We'll reveal more details later as time progresses.\n\nPlease check your question and ensure that it is about general health issues!");
	
	} else 
	
	*/
	
	if (myquestion.length > 2) {
		
		ajax_do('save_question.php?question=' + myquestion + '&m=' + randomString);
	
	} else {
		
		alert("Please type in something before sending it. Thanks!");
	
	}
	
}

function submitNumber() {
	var myTicket = getobject_main("ticketNumber").value;
	var randomString = new Date().getTime();
	
	if (myTicket > 12784000 && myTicket < 12789999) {

		ajax_do('set_cookie.php?ticket=' + myTicket + '&m=' + randomString);
	} else {
		getobject_main("ticketTitle").innerHTML = '<img src="images/check_ticket_number_14.jpg" alt="Win a gym membership with Xanadu Health Club Inc. in Lakeshore, Ontario, womens gym, mens gym" width="660" height="80" />';
	}	
	
}

function isEmailAddr(str) {
  return str.match(/^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/);
}


function submitRegister() {
	var fname = getobject_main("firstName").value;
	var lname = getobject_main("lastName").value;
	var email = getobject_main("emailAddress").value;
	var address = getobject_main("address").value;
	var city = getobject_main("city").value;
	var postal = getobject_main("postalCode").value;
	var phone = getobject_main("phoneNumber").value;
	var winningTicket = getobject_main("winningTicket").value;
	
	var randomString = new Date().getTime();
	
	if (winningTicket.length > 2 && fname != null && lname != null && isEmailAddr(email) && address != null && city != null && postal != null && phone != null) {
		
	getobject_main("request").style.display = 'none';
	getobject_main("thanks").style.display = '';
		
	ajax_do('save_info.php?fname=' + fname + '&lname=' + lname + '&email=' + email + '&address=' + address + '&city=' + city + '&postal=' + postal + '&ticket=' + winningTicket + '&phone=' + phone + '&employer=&m=' + randomString);
	
	} else {
		alert("Please fill in all of the fields in order to receive more information.");
	}

	
}

function submitShort() {
	var fname = getobject_main("firstName").value;
	var lname = getobject_main("lastName").value;
	var email = getobject_main("emailAddress").value;
	var phone = getobject_main("phone").value;
	
	var randomString = new Date().getTime();
	
	if (fname != null && lname != null && isEmailAddr(email) && phone != null) {
	
		
	ajax_do('save_info.php?fname=' + fname + '&lname=' + lname + '&email=' + email + '&address=&city=&postal=&ticket=&phone=' + phone + '&employer=&m=' + randomString);
	

	location.href = "http://www.whatisxanadu.com/spitfires/thankyou.html";
	
	} else {
		alert("Please fill in your Name, Email and Postal Code.");
	}

	
}

function showRegister() {
	
	getobject_main("request").style.display = '';
	getobject_main("home").style.display = 'none';
	getobject_main("management").style.display = 'none';
	getobject_main("jobs").style.display = 'none';
	
}


function showManagement() {
	
	getobject_main("request").style.display = 'none';
	getobject_main("home").style.display = 'none';
	getobject_main("management").style.display = '';
	getobject_main("jobs").style.display = 'none';
	
}

function showEmployment() {
	
	getobject_main("request").style.display = 'none';
	getobject_main("home").style.display = 'none';
	getobject_main("management").style.display = 'none';
	getobject_main("jobs").style.display = '';
	
}

function showHome() {
	
	getobject_main("request").style.display = 'none';
	getobject_main("home").style.display = '';
	getobject_main("management").style.display = 'none';
	getobject_main("jobs").style.display = 'none';
	
}

function getApplication() {
	
	var randomString = new Date().getTime();
	
	ajax_do('count_aps.php?m='+ randomString);
	window.open('Xanadu_Application.pdf','Application');
}

function getBizX() {
	
	var randomString = new Date().getTime();
	
	ajax_do('count_bizx.php?m='+ randomString);
	window.open('BizX_October.pdf','BizX');
}

function getClubBiz() {
	
	var randomString = new Date().getTime();
	
	ajax_do('count_clubbiz.php?m='+ randomString);
	window.open('ihrsastory.jpg','Club');
}

function showletter() {

	getobject_main("letterintro").style.display = 'none';
	getobject_main("showletter").style.display = '';
}

function hideletter() {

	getobject_main("letterintro").style.display = '';
	getobject_main("showletter").style.display = 'none';
}