confirmed = 0;
CLEAR_FEILDS = 1;
function do_it_all(div_id){
	s_str = window.location.search.toString();
	if(s_str.search(/confirm/) != -1){
		confirm();
	}else if(s_str.search(/remove/) != -1){
		remove();
	}
	if(div_id && typeof($(div_id)) != 'undefined'){
		$(div_id).style.display = 'block';
		signup_div_id = div_id
	}else{
		document.write('Please contact Solutions in Finance to signup to or be removed from our mailing list.');
	}
	return('');
}	
function show_remove(div_id){
	if(signup_div_id){
		$(signup_div_id).style.display = 'none';
	}
	if(div_id && typeof($(div_id)) != 'undefined'){
		$(div_id).style.display = 'block';
	}
}
function subscribe(){
	if(typeof(MAILER_CLIENT_ID) == 'undefined' || isNaN(Number(MAILER_CLIENT_ID))){
		alert('Newsletter signup is not configured correctly. Incorrect client id.');
		return('');
	}
	if($('subemail').value && $('subfirst_name').value){
		div = 'MAILER_MESSAGE_BOX';
		url = 'http://admin.thirstymailer.com/signup/'+MAILER_CLIENT_ID;
		pars = "e_mail="+$('subemail').value;
		pars += "&first_name="+$('subfirst_name').value;
		pars += "&last_name="+$('sublast_name').value;
		var response = document.createElement('img');
		response.src=(url+"?"+pars);
		response.id = 'resp_img';
		document.getElementsByTagName('body').item(0).appendChild(response);
		Event.observe('resp_img', 'load', sub_response, false);
	}else{
		sub_response(0);
	}
	return(true);
}
function conf_response_timeout(){
}
function confirm(){
	if(typeof(MAILER_CLIENT_ID) == 'undefined'){
		alert('Newsletter configuration is not correct. No client id defined.');
		return('');
	}
	s_str = window.location.search.toString();
	s_str = s_str.replace("?","");
	s_arr = s_str.split("&");
	data = new Array();
	s_arr.each( function(inputval){
			tmp = inputval.split("=");
			data[tmp[0]] = tmp[1];
		});
	if(data['confirm']){
		url = 'http://admin.thirstymailer.com/signup/confirm/'+MAILER_CLIENT_ID;
		pars = "confirm="+data['confirm'];
		var response = document.createElement('img');
		response.src=(url+"?"+pars);
		response.id = 'resp_img';
		document.getElementsByTagName('body').item(0).appendChild(response);
		Event.observe('resp_img', 'load', conf_response, false);
	}else{
		conf_response(0);
	}
}
function remove(manual){
	if(typeof(MAILER_CLIENT_ID) == 'undefined'){
		alert('Newsletter configuration is not correct. No client id defined.');
		return('');
	}
	s_str = window.location.search.toString();
	if(s_str){
		s_str = s_str.replace("?","");
		s_arr = s_str.split("&");
		data = new Array();
		s_arr.each( function(inputval){
				tmp = inputval.split("=");
				data[tmp[0]] = tmp[1];
			});
	}else{
		data=new Array();
	}
	if(manual){
		data['remove'] = '1';
		data['e_mail'] = $('rememail').value;
	}
	if(data['remove'] == '1' && data['e_mail']){
		url = 'http://admin.thirstymailer.com/signup/remove/'+MAILER_CLIENT_ID;
		pars = "e_mail="+data['e_mail'];
		var response = document.createElement('img');
		response.src=(url+"?"+pars);
		response.id = 'resp_img';
		document.getElementsByTagName('body').item(0).appendChild(response);
		Event.observe('resp_img', 'load', remove_response, false);
	}else{
		remove_response(0);
	}
}
	if( typeof(window[MAILER_MESSAGE]) == 'undefined'){
	
		var MAILER_MESSAGE = new Array();
	}

	/*----------------------------------------------------
	--													--
	--		Subscribe Response codes.					--
	--													--
	--	1.	success!									--
	--	2.	Could not find client in db.				--
	--	3.	Subscriber all ready exists.				--
	--	4.	Subscribed but could not send email			--
	--	5.	First Name not entered						--
	--	6.	Bad email format. 							--
	--	0.	incomplete information.(java check)			--
	--													--
	----------------------------------------------------*/
		if( typeof(window.MAILER_MESSAGE.subscribe) == 'undefined'){
			MAILER_MESSAGE['subscribe'] = new Array();
		}
		MAILER_MESSAGE['subscribe']['1'] = ( (typeof( window.MAILER_MESSAGE.subscribe['1'] ) != 'undefined') ? MAILER_MESSAGE['subscribe']['1'] : 'You should receive an email confirmation shortly.\n Please follow the instructions to complete your subscription.');
		MAILER_MESSAGE['subscribe']['2'] = ( (typeof( window.MAILER_MESSAGE.subscribe['2'] ) != 'undefined') ? MAILER_MESSAGE['subscribe']['2'] : 'There was an error processing this request please try again later.');
		MAILER_MESSAGE['subscribe']['3'] = ( (typeof( window.MAILER_MESSAGE.subscribe['3'] ) != 'undefined') ? MAILER_MESSAGE['subscribe']['3'] : 'You have been subscribed.');
		MAILER_MESSAGE['subscribe']['4'] = ( (typeof( window.MAILER_MESSAGE.subscribe['4'] ) != 'undefined') ? MAILER_MESSAGE['subscribe']['4'] : 'We have saved your information but there was an error when sending your confirmation email please contact us to complete subscription.');
		MAILER_MESSAGE['subscribe']['5'] = ( (typeof( window.MAILER_MESSAGE.subscribe['5'] ) != 'undefined') ? MAILER_MESSAGE['subscribe']['5'] : 'Please enter your first name.');
		MAILER_MESSAGE['subscribe']['6'] = ( (typeof( window.MAILER_MESSAGE.subscribe['6'] ) != 'undefined') ? MAILER_MESSAGE['subscribe']['6'] : 'Unrecognized email format please re-enter your email address. (example@domain.net)');
		MAILER_MESSAGE['subscribe']['0'] = ( (typeof( window.MAILER_MESSAGE.subscribe['0'] ) != 'undefined') ? MAILER_MESSAGE['subscribe']['0'] : 'You must fill out your name and email address to subscribe.');
		MAILER_MESSAGE['subscribe']['100'] = MAILER_MESSAGE['subscribe']['0'];
	
	/*------------------------------------------------
	--												--
	--		Conformation Response codes.			--
	--												--
	--	1.	success!								--
	--	2.	Confirmer was not found.				--
	--	3.	Bad Email Format.						--
	--	4.	Client not found.						--
	--	5.	Email not found.						--
	--	0.	incomplete information.(java check)	--
	--												--
	------------------------------------------------*/
		if( typeof(window.MAILER_MESSAGE.confirm) == 'undefined'){
			MAILER_MESSAGE['confirm'] = new Array();
		}
		MAILER_MESSAGE['confirm']['1'] = ( (typeof( window.MAILER_MESSAGE.confirm['1'] ) != 'undefined') ? MAILER_MESSAGE['confirm']['1'] : 'You have successfully been subscribed to our newsletter. Thank you.');
		MAILER_MESSAGE['confirm']['2'] = ( (typeof( window.MAILER_MESSAGE.confirm['2'] ) != 'undefined') ? MAILER_MESSAGE['confirm']['2'] : 'We could not find you in our records please contact us to complete your subscription.');
		MAILER_MESSAGE['confirm']['3'] = ( (typeof( window.MAILER_MESSAGE.confirm['3'] ) != 'undefined') ? MAILER_MESSAGE['confirm']['3'] : 'Your email address was not in a recignised format please contact us to complete your subscription.');
		MAILER_MESSAGE['confirm']['4'] = ( (typeof( window.MAILER_MESSAGE.confirm['4'] ) != 'undefined') ? MAILER_MESSAGE['confirm']['4'] : 'There was an error processing conformation please contact us or try again later.');
		MAILER_MESSAGE['confirm']['5'] = ( (typeof( window.MAILER_MESSAGE.confirm['5'] ) != 'undefined') ? MAILER_MESSAGE['confirm']['5'] : 'Your email address was not found in our records please contact us to complete your subscription.');
		MAILER_MESSAGE['confirm']['0'] = ( (typeof( window.MAILER_MESSAGE.confirm['0'] ) != 'undefined') ? MAILER_MESSAGE['confirm']['0'] : 'There was an error processing conformation please contact us or try again later.');
		MAILER_MESSAGE['confirm']['100'] = MAILER_MESSAGE['confirm']['0'];

	/*------------------------------------------------
	--												--
	--		Removal Response codes.					--
	--												--
	--	1.	success!								--
	--	2.	Remover was not found.					--
	--	3.	Bad Email Format.						--
	--	4.	Client not found.						--
	--	5.	Email not found.						--
	--	0.	incomplete information.(java check)		--
	--												--
	------------------------------------------------*/
		if( typeof(window.MAILER_MESSAGE.remove) == 'undefined'){
			MAILER_MESSAGE['remove'] = new Array();
		}
		MAILER_MESSAGE['remove']['1'] = ( (typeof( window.MAILER_MESSAGE.remove['1'] ) != 'undefined') ? MAILER_MESSAGE['remove']['1'] : 'You have been removed from our newsletter.');
		MAILER_MESSAGE['remove']['2'] = ( (typeof( window.MAILER_MESSAGE.remove['2'] ) != 'undefined') ? MAILER_MESSAGE['remove']['2'] : 'We could not find your information on file. Double check your information and try again. If you continue having problems please contact us.');
		MAILER_MESSAGE['remove']['3'] = ( (typeof( window.MAILER_MESSAGE.remove['3'] ) != 'undefined') ? MAILER_MESSAGE['remove']['3'] : 'Email was not in recignised format please re-enter and try again. (example@domain.net)');
		MAILER_MESSAGE['remove']['4'] = ( (typeof( window.MAILER_MESSAGE.remove['4'] ) != 'undefined') ? MAILER_MESSAGE['remove']['4'] : 'There was an error processing your request pleas contact us to be removed.');
		MAILER_MESSAGE['remove']['5'] = ( (typeof( window.MAILER_MESSAGE.remove['5'] ) != 'undefined') ? MAILER_MESSAGE['remove']['5'] : 'We could not find your information on file. Double check your information and try again. If you continue having problems please contact us.');
		MAILER_MESSAGE['remove']['0'] = ( (typeof( window.MAILER_MESSAGE.remove['0'] ) != 'undefined') ? MAILER_MESSAGE['remove']['0'] : 'Please fill out form completely to unsubscribe.');
		MAILER_MESSAGE['remove']['100'] = MAILER_MESSAGE['remove']['0'];

function sub_response(response){
	if($('resp_img') ==  null){
		response = 0;
	}else{
		response = $('resp_img').width;
	}
	if(!response || response == 0){
		//ajax call was not made do to in complete information
		message = MAILER_MESSAGE['subscribe']['0'];
	}
	else{
		message = ((typeof( window.MAILER_MESSAGE.subscribe[response] ) != 'undefined') ? MAILER_MESSAGE['subscribe'][response] : '');
	}
	if(typeof(MAILER_MESSAGE_BOX) != 'undefined' && MAILER_MESSAGE_BOX && typeof($(MAILER_MESSAGE_BOX)) == 'object' && $(MAILER_MESSAGE_BOX)){
		$(MAILER_MESSAGE_BOX).innerHTML = message;
		$(MAILER_MESSAGE_BOX).style.display = 'block';
	}
	else{
		alert(message);
	}
	if((response == 1 || response == 3)&& CLEAR_FEILDS){
		$('subemail').value = '';
		$('subfirst_name').value = '';
		$('sublast_name').value = '';
	}else if(response == 1 || response == 3){
		subscribed();
	}
	if($('resp_img') !=  null){
		Event.stopObserving('resp_img', 'load', conf_response, false);
		img = $('resp_img')
		img.parentNode.removeChild(img);
	}
	return true;
}
function conf_response(response){
	if($('resp_img') ==  null){
		response = 0;
	}else{
		response = $('resp_img').width;
	}
	if(!response || response == 0){
		//ajax call was not made do to in complete information
		message = MAILER_MESSAGE['confirm']['0'];
	}
	else{
		message = ((typeof( window.MAILER_MESSAGE.confirm[response] ) != 'undefined') ? MAILER_MESSAGE['confirm'][response] : '');
	}
	if(typeof(MAILER_MESSAGE_BOX) != 'undefined' && MAILER_MESSAGE_BOX && typeof($(MAILER_MESSAGE_BOX)) == 'object' && $(MAILER_MESSAGE_BOX)){
		$(MAILER_MESSAGE_BOX).innerHTML = message;
		$(MAILER_MESSAGE_BOX).style.display = 'block';
	}
	else if(message){
		alert(message);
	}
	if($('resp_img') !=  null){
		Event.stopObserving('resp_img', 'load', conf_response, false);
		img = $('resp_img')
		img.parentNode.removeChild(img);
	}
}
function remove_response(response){
	if($('resp_img') ==  null){
		response = 0;
	}else{
		response = $('resp_img').width;
	}
	if(!response || response == 0){
		//ajax call was not made do to in complete information
		message = MAILER_MESSAGE['remove']['0'];
	}
	else{
		message = ((typeof( window.MAILER_MESSAGE.remove[response] ) != 'undefined') ? MAILER_MESSAGE['remove'][response] : '');
	}
	if(typeof(MAILER_MESSAGE_BOX) != 'undefined' && MAILER_MESSAGE_BOX && typeof($(MAILER_MESSAGE_BOX)) == 'object' && $(MAILER_MESSAGE_BOX)){
		$(MAILER_MESSAGE_BOX).innerHTML = message;
		$(MAILER_MESSAGE_BOX).style.display = 'block';
	}
	else{
		alert(message);
	}
	if($('resp_img') !=  null){
		Event.stopObserving('resp_img', 'load', remove_response, false);
		img = $('resp_img')
		img.parentNode.removeChild(img);
	}
}