// .js du bouton Mob-This v2

function mobThis_submit() {
	
	phone = $F('mobThis_cellphone');
	phone = phone.replace(/\+/i,'%2B').replace(/ /i,'');
	pars = 'login='+login+'&app_key='+app_key+'&app_id='+app_id+'&destination='+phone;

	$('mobThis_form_container').style.display = 'none';
	$('mobThis_waiting').style.display = 'block';
//	new Effect.Fade('mobThis_form_container');
//	new Effect.Appear('mobThis_waiting');
	
//	$('toto').innerHTML = 'http://wwwdev.mob-it.com/sms/send?'+pars;

// return false;

//	alert('http://'+wwwhost+'/mobthis/v3_send/?'+pars);

	myAjax = new Ajax.Request(
		'http://'+wwwhost+'/mobthis/v3_send/',
		{
			method: 'get', 
			parameters: pars,
			onComplete: mobThis_sms_send
		});


	return false;
}

function mobThis_sms_send(req) {
	resp = req.responseText;
	if (resp.slice(0,7) == 'Success') {
		$('mobThis_icon').src = 'http://'+wwwhost+'/bandoApps/appIcons/'+app_id;
		$('mobThis_icon').alt = 'Download application at http://'+waphost+'/'+app_id+'.jad';
		$('mobThis_link').href = 'http://'+waphost+'/'+app_id+'.jad';
		$('mobThis_link').title = 'Download application at http://'+waphost+'/'+app_id+'.jad';
		$('mobThis_error').style.display = 'none';
		$('mobThis_form_container').style.display = 'none';
		$('mobThis_waiting').style.display = 'none';
		$('mobThis_sent').style.display = 'block';
//		new Effect.Fade('mobThis_waiting');
//		new Effect.Appear('mobThis_sent');
	} else {
		$('mobThis_error_content').innerHTML = resp.slice(7);
		$('mobThis_sent').style.display = 'none';
		$('mobThis_form_container').style.display = 'none';
		$('mobThis_waiting').style.display = 'none';
		$('mobThis_error').style.display = 'block';
//		new Effect.Fade('mobThis_waiting');
//		new Effect.Appear('mobThis_error');
	}
}

function mobThis_about_show() {
	$('mobThis').style.display = 'none';
	$('mobThis_about').style.display = 'block';
	return false;
}

function mobThis_about_hide() {
	$('mobThis_about').style.display = 'none';
	$('mobThis').style.display = 'block';
	return false;
}

function mobThis_form_show() {
	$('mobThis_presentation').style.display = 'none';
	$('mobThis_form_container').style.display = 'block';
	return false;
}

$('mobThis_form').onsubmit = mobThis_submit;
$('mobThis_about_link').onclick = mobThis_about_show;
// $('mobThis_about_about').onclick = mobThis_about_hide;
$('mobThis_presentation').onclick = mobThis_form_show;

