﻿var popupStatus = 0;
function postchangepass(){
	var opw = $('oldpwd').value;
	var npw = $('newpwd').value;
	var rpw = $('repwd').value;
	if(opw == ""){
		Effect.Appear('err');
		$('err').innerHTML='Entrez votre mot de passe actuel';
		$('err').addClassName('err');
		$('oldpwd').focus();
	}else if(npw == ""){
		Effect.Appear('err');
		$('err').innerHTML='Entrez le nouveau de mot passe';
		$('err').addClassName('err');
		$('newpwd').focus();
	}else if(rpw == ""){
		Effect.Appear('err');
		$('err').innerHTML='Confirmez ce mot de passed';
		$('err').addClassName('err');
		$('repwd').focus();
	}else if(npw != rpw){
		Effect.Appear('err');
		$('err').innerHTML='Le mot de passe de confirmation ne correspond pas à celui renseigné';
		$('err').addClassName('err');
	}else{
		$('main').hide();
		Effect.Appear('err');
	
			$('err').innerHTML = '<img src="../images/loading.gif" >';
			new Ajax.Request('html/changepass.php',
		    {
			method:'post',
			parameters: {newpwd: npw,oldpwd:opw}
			,onSuccess: function(transport){
			  var response = transport.responseText;
			  
			  if(response == 1){
				  
				$('err').addClassName('msg');
			  	$('err').innerHTML = 'Votre mot de passe a été modifié';
			  }else{
				 $('main').show(); 
				$('err').addClassName('err');
				$('err').innerHTML = 'Le mot de passe actuel que vous avez renseigné est incorrect';  
			  }
			  
			},
			onFailure: function(){$('err').addClassName('err');	$('err').innerHTML = 'Mail sent fail'; }
		    });
	}
	return false;
}
function postforgotpass(email){
	
	var patt = new RegExp(/^(.+)@(.+)$/);
	
	if(patt.test(email)==true){
			//post
			$('main').hide();
			Effect.Appear('err');
			$('err').innerHTML = '<img src="../images/loading.gif" >';
			new Ajax.Request('html/forgotpass.php',
		    {
			method:'post',
			parameters: {email: email}
			,onSuccess: function(transport){
			  var response = transport.responseText;
			  
			  if(response == 1){
				  
				$('err').addClassName('msg');
			  	$('err').innerHTML = 'Votre mot de passe va vous être envoyé à l\'adresse email indiqué';
			  }else{
				  
				$('err').addClassName('err');
				$('err').innerHTML = 'Nous n\'avons pas pu envoyer l\'email';  
			  }
			  
			},
			onFailure: function(){$('err').addClassName('err');	$('err').innerHTML = 'Mail sent fail'; }
		    });
			
			//Effect.Fade('err');
	}
	else{
		Effect.Appear('err');
		$('err').innerHTML='Merci de renseigner l\'email avec lequel vous êtes insrit sur MeilleurVendeur.com';
		$('err').addClassName('err');
	}
	//$('message').addClassName('read');

}
function loadPopup(merchant){
	//loads popup only if it is disabled
	if(popupStatus==0){
		//$("backgroundPopup").setStyle({
		//	opacity: "0.7"
		//});
		Effect.Appear('backgroundPopup',{ duration: 1.0, from: 0, to: 0.7 });
		Effect.Appear('popupContact');
		//$("backgroundPopup").show();
		//$("popupContact").show();
		popupStatus = 1;
		
		new Ajax.Updater('popupContact', '/html/coupen.php?m='+merchant, { method: 'get' });
		//$("#popupContact").load("/html/script.php?m="+merchant);
	}
}


function loadPopup_forgot(merchant){
	//loads popup only if it is disabled
	if(popupStatus==0){
		//$("backgroundPopup").setStyle({
		//	opacity: "0.7"
		//});
		Effect.Appear('backgroundPopup',{ duration: 1.0, from: 0, to: 0.7 });
		Effect.Appear('popupContact');
		//$("backgroundPopup").show();
		//$("popupContact").show();
		popupStatus = 1;
		
		new Ajax.Updater('popupContact', '/html/forgotpass.php', { method: 'get' });
		//$("#popupContact").load("/html/script.php?m="+merchant);
	}
}

function loadPopup_changepass(merchant){
	//loads popup only if it is disabled
	if(popupStatus==0){
		//$("backgroundPopup").setStyle({
		//	opacity: "0.7"
		//});
		Effect.Appear('backgroundPopup',{ duration: 1.0, from: 0, to: 0.7 });
		Effect.Appear('popupContact');
		//$("backgroundPopup").show();
		//$("popupContact").show();
		popupStatus = 1;
		
		new Ajax.Updater('popupContact', '/html/changepass.php', { method: 'get' });
		//$("#popupContact").load("/html/script.php?m="+merchant);
	}
}
//loading popup with jQuery magic!
/*function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
		//$("#popupContact").load("/html/script.php?m="+merchant);
	}
}
*/
function disablePopup(){
	
	//disables popup only if it is enabled
	if(popupStatus==1){
		//$("backgroundPopup").hide();
		Effect.Fade('backgroundPopup');
		Effect.Fade('popupContact');
//		$("popupContact").hide();
		
		popupStatus = 0;
	}
}

//disabling popup with jQuery magic!
/*function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}*/
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("popupContact").getHeight();
	var popupWidth = $("popupContact").getWidth();
	//alert(windowWidth +":"+popupWidth);
	//centering
	$("popupContact").setStyle({
		backgroundColor: "#FFFFFF",
		top: eval(windowHeight/2-popupHeight/2) + 'px',
		left: eval(windowWidth/2-popupWidth/2) + 'px'
	});
	//only need force for IE6
	
	$("backgroundPopup").setStyle({
		"height": windowHeight
	});
	
	
}
//centering popup
/*function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}
*/
function poponclick(merchant){
		//centering with css
		centerPopup();
		//load popup
		loadPopup(merchant);
}

function poponclick_changepass(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup_changepass();
}

function poponclick_forgot(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup_forgot();
}

function poponclick_comment(articleid){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("popupcomment").getHeight();
	var popupWidth = $("popupcomment").getWidth();
	//alert(windowWidth +":"+popupWidth);
	//centering
	$("popupcomment").setStyle({
		backgroundColor: "#FFFFFF",
		top: eval(windowHeight/2-popupHeight/2) + 'px',
		left: eval(windowWidth/2-popupWidth/2) + 'px'
	});
	//only need force for IE6
	
	$("backgroundPopup").setStyle({
		"height": windowHeight
	});
	
	loadPopup_comment(articleid);
}

function loadPopup_comment(articleid){
	//loads popup only if it is disabled
	if(popupStatus==0){
		//$("backgroundPopup").setStyle({
		//	opacity: "0.7"
		//});
		Effect.Appear('backgroundPopup',{ duration: 1.0, from: 0, to: 0.7 });
		Effect.Appear('popupcomment');
		//$("backgroundPopup").show();
		//$("popupContact").show();
		popupStatus = 1;

		new Ajax.Updater('popupcomment', '/html/ecocommentpost.php?ecoid='+articleid, { method: 'get'});
		
		//$("#popupContact").load("/html/script.php?m="+merchant);
	}
}
function disablePopupcomment(){
	
	//disables popup only if it is enabled
	if(popupStatus==1){
		//$("backgroundPopup").hide();
		Effect.Fade('backgroundPopup');
		Effect.Fade('popupcomment');
//		$("popupContact").hide();
		
		popupStatus = 0;
	}
}

function poponclick_comment1(articleid){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("popupcomment").getHeight();
	var popupWidth = $("popupcomment").getWidth();
	//alert(windowWidth +":"+popupWidth);
	//centering
	$("popupcomment").setStyle({
		backgroundColor: "#FFFFFF",
		top: eval(windowHeight/2-popupHeight/2) + 'px',
		left: eval(windowWidth/2-popupWidth/2) + 'px'
	});
	//only need force for IE6
	
	$("backgroundPopup").setStyle({
		"height": windowHeight
	});
	
	loadPopup_comment1(articleid);
}

function loadPopup_comment1(articleid){
	//loads popup only if it is disabled
	if(popupStatus==0){
		//$("backgroundPopup").setStyle({
		//	opacity: "0.7"
		//});
		Effect.Appear('backgroundPopup',{ duration: 1.0, from: 0, to: 0.7 });
		Effect.Appear('popupcomment');
		//$("backgroundPopup").show();
		//$("popupContact").show();
		popupStatus = 1;

		new Ajax.Updater('popupcomment', '/html/ct_commentpost.php?ctid='+articleid, { method: 'get'});
		//$("#popupContact").load("/html/script.php?m="+merchant);
	}
}

function poponclick_comment2(articleid){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("popupcomment").getHeight();
	var popupWidth = $("popupcomment").getWidth();
	//alert(windowWidth +":"+popupWidth);
	//centering
	$("popupcomment").setStyle({
		backgroundColor: "#FFFFFF",
		top: eval(windowHeight/2-popupHeight/2) + 'px',
		left: eval(windowWidth/2-popupWidth/2) + 'px'
	});
	//only need force for IE6
	
	$("backgroundPopup").setStyle({
		"height": windowHeight
	});
	
	loadPopup_comment2(articleid);
}

function loadPopup_comment2(articleid){
	//loads popup only if it is disabled
	if(popupStatus==0){
		//$("backgroundPopup").setStyle({
		//	opacity: "0.7"
		//});
		Effect.Appear('backgroundPopup',{ duration: 1.0, from: 0, to: 0.7 });
		Effect.Appear('popupcomment');
		//$("backgroundPopup").show();
		//$("popupContact").show();
		popupStatus = 1;

		new Ajax.Updater('popupcomment', '/html/ma_commentpost.php?maid='+articleid, { method: 'get'});
		//$("#popupContact").load("/html/script.php?m="+merchant);
	}
}

Event.observe(document, 'click', function(event){ var element = event.element();
if(element.id == 'backgroundPopup' || element.id == 'popupContactClose' || element.id == 'popupContactClose1'){
	disablePopup();
}
if(element.id == 'backgroundPopup' || element.id == 'popupcommentclose' || element.id == 'popupcommentclose1'){
	disablePopupcomment();
}});

Event.observe(document, 'keypress', function(event){ if(event.keyCode ==27 && popupStatus==1) {disablePopup();disablePopupcomment();}});


//CONTROLLING EVENTS IN jQuery
/*$(document).ready(function(){
	
	//LOADING POPUP
	//Click the button event!
	$("#button").click(function(){
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	$("#popupContactClose1").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});

});*/