var ajax_video_url = '/ajax_video.php';

function open_video(type,id) {
	var req = new Request({
		method: 'get',
		url: ajax_video_url,
		data: {
			'type':type,
			'id':id
		},
		//onRequest: function() { alert('Request made. Please wait...'); },
		onComplete: function(response) {
			var reg1=new RegExp("[KO]","g");
			if(response.match(reg1)) {
				OpenRegistration(id);
			} else {
				open_greybox(response);
			}
		}
	}).send();
}

function submit_login_video(id) {
	user_online = '0';
	var req = new Request({
		method: 'post',
		url: ajax_registration_url,
		data: {
			'action':'login',
			'email':email_login[0].value,
			'pwd':pwd_login[0].value
		},
		//onRequest: function() { alert('Request made. Please wait...'); },
		onComplete: function(response) {
			var reg1=new RegExp("[OK]","g");
			if(response.match(reg1)) {
				user_online = '1';
				open_video('video',id);
			} else {
				alert(response);
				user_online = '0';
			}
		}
	}).send();
}

function check_src() {
	var req = new Request({
		method: 'get',
		url: ajax_video_url,
		data: {
			'action':'check_video'
		},
		//onRequest: function() { alert('Request made. Please wait...'); },
		onComplete: function(response) {
			if(response == 'OK') {
				document.getElementById('greybox_iframe').className='greybox_iframe_video_mode';
			}
		}
	}).send();
}

// All in one

function submit_login_all_in_one(id) {
	user_online = '0';
	var req = new Request({
		method: 'post',
		url: ajax_registration_url,
		data: {
			'action':'login',
			'email':email_login[0].value,
			'pwd':pwd_login[0].value
		},
		//onRequest: function() { alert('Request made. Please wait...'); },
		onComplete: function(response) {
			var reg1=new RegExp("[OK]","g");
			if(response.match(reg1)) {
				user_online = '1';
				location.reload();
			} else {
				alert(response);
				user_online = '0';
			}
		}
	}).send();
}

function check_allopass(id) {
	user_online = '0';
	var allopass = document.getElementsByName('allopass_code');
	
	var req = new Request({
		method: 'post',
		url: '/ajax_check_allopass.php',
		data: {
			'allopass':allopass[0].value,
			'idvideo':id
		},
		//onRequest: function() { alert('Request made. Please wait...'); },
		onComplete: function(response) {
			var reg1=new RegExp("[OK]","g");
			if(response.match(reg1)) {
				user_online = '1';
				location.reload();
			} else {
				alert(response);
				user_online = '0';
			}
		}
	}).send();	
}

function submit_premium() {
	var email = document.getElementsByName('email_premium');
	var emaillogin = document.getElementsByName('email_login');
	var emailpwd = document.getElementsByName('pwd_login');
	var req = new Request({
		method: 'post',
		url: '/ajax_all_in_one_registration.php',
		data: {
			'action':'process',
			'email':email[0].value
		},
		//onRequest: function() { alert('Request made. Please wait...'); },
		onComplete: function(response) {
			var reg1=new RegExp("[OK]","g");
			if(response.match(reg1)) {
				set_step_premium(2);
				//alert("Ton inscription a bien été prise en compte,"+"\n"+"choisi maintenant ton abonnement PREMIUM."+"\n"+"Un rappel de tes identifiants"+"\n"+"te sera envoyé par email."+"\n"+"Tu pourras personnaliser ton profil"+"\n"+"dans la rubrique 'mon mur'.");
			} else {
				alert(response);
				
				if(response != 'Adresse email non valide')
				{
					emaillogin[0].value = email[0].value;
					email[0].value = '';
					emailpwd[0].focus();
				}
			}
		}
	}).send();	
}

function set_step_premium(step) {
	var req = new Request({
		method: 'get',
		url: '/ajax_all_in_one_step.php',
		data: {
			'step':step
		},
		//onRequest: function() { alert('Request made. Please wait...'); },
		onComplete: function(response) {
			document.getElementById('premium_step').innerHTML = response;
		}
	}).send();	
}

function paiement_all_in_one() {
	var idd = document.getElementById('idd_value');//document.getElementsByName('idd');
	var req = new Request({
		method: 'get',
		url: '/ajax_all_in_one_step.php',
		data: {
			'step':'allopass_form',
			'idd':idd.value
		},
		//onRequest: function() { alert('Request made. Please wait...'); },
		onComplete: function(response) {
			open_greybox_profile(response);
			document.getElementById('launch_allopass_form').submit();
		}
	}).send();	
}

function check_frame_path(frame_id)
{
//	var path = document.getElementById(frame_id).src;//contentDocument.location.href;
	var path = document.all.DisplaySub.src;
	alert(path);
}

function close_greybox_all_in_one()
{
	greybox_content_profile.innerHTML = '';
	grey_box_profile.style.display = 'none';
	greybox_content.innerHTML = '';
	grey_box.style.display = 'none';
	
	// check paiement status
	var req = new Request({
		method: 'get',
		url: '/ajax_all_in_one_step.php',
		data: {
			'step':'check_allopass'
		},
		//onRequest: function() { alert('Request made. Please wait...'); },
		onComplete: function(response) {
			var reg1=new RegExp("[OK]","g");
			if(response.match(reg1)) {
				location.reload();//history.go(-1);
				//set_step_premium(3);
			} else {
				alert(response);
			}
		}
	}).send();		
}

function make_choice_all_in_one(abo_type) {
	switch(abo_type) {
		case 1:
			// 114242/818027/1974544
			document.getElementById('idd_value').value = '818027';
			break;
		case 2:
			// 114242/818030/1974544
			document.getElementById('idd_value').value = '818030';
			break;
		case 3:
			// 114242/818023/1974544
			document.getElementById('idd_value').value = '818023';
			break;
	}
}