// JavaScript Document

var rootUrl="http://www.aurigashop.com/";

function color(obj)
{
	obj.style["backgroundColor"]="#eebed8";
}
function none(obj)
{
	obj.style["backgroundColor"]="white";
}
function refreshPage()
{
	location.reload();
}	

function colorInput(obj)
{
	obj.style["backgroundColor"]="#eebed8";
	obj.style["border"]='1px solid #CCC';
}
function discolorInput(obj)
{
	obj.style["backgroundColor"]="white";
	obj.style["border"]='1px solid #CCC';
}

function sendDataTraduction(code,id)
{
	wordFR = document.getElementById('wordFR_'+id).value;
	wordNL = document.getElementById('wordNL_'+id).value;	
	$.ajax({
		   type: "POST",
		   url: rootUrl+"rsk/ajax_query/query.php?query_number=21",
		   data: "id="+ id+"&wordFR="+wordFR+"&wordNL="+wordNL+"&code="+code,
		   success: function(msg){
				document.getElementById('boutton_'+id).innerHTML= msg;
		   }
		 });
}

function delPays(id)
{

	$.ajax({
		   type: "POST",
		   url: rootUrl+"rsk/ajax_query/query.php?query_number=6",
		   data: "id_prix="+ id,
		   success: function(msg){
			   if(msg==1){
				refreshPage();
			   }
			   else
			   {
					alert('Une erreur est survenue')   ;
			   }
		   }
		 });		
}
function selectPicture(picture)
{
	//alert(picture);
	document.getElementById('current_picture').value = picture;
		$.ajax({
		   type: "POST",
		   url: rootUrl+"rsk/ajax_query/query.php?query_number=8",
		   data: "picture="+ picture,
		   success: function(msg){
			   
			document.getElementById('vignette').innerHTML=msg;
			
		   }
		 });
	
}

function addQuantity(id)
{

	var value = document.getElementById("input_"+id).value;
	if(!isNaN(value))
	{
		if(value<99)
		{
			value++;
			document.getElementById("input_"+id).value = value;
		}
	}
	else
	{
		document.getElementById("input_"+id).value = 1;
	}
}
function removeQuantity(id)
{
	var value = document.getElementById("input_"+id).value;
	if(!isNaN(value))
	{
		if(value>0)
		{
			value--;
			document.getElementById("input_"+id).value = value;
		}
		else
		{
			document.getElementById("input_"+id).value = 0;
		}
	}
	else
	{
		document.getElementById("input_"+id).value = 1;
	}
}
function submitForm(id)
{
	form = "toBasket_"+id;
	document.forms[form].submit();						
}
function tempDisplayDivBasket(type)
{
	//setTimeout("alert('"+type+"')",3000);
	setTimeout("displayDivBasket('"+type+"')",0);
	//setTimeout("alert('"+type+"')",3000);	
}

function displayDivBasket(type)
{
	display =	document.getElementById('contenu_panier_bg').style["display"];
	
		switch(Number(type))
		{
			case 0:
				if(display=="none")
				{
					$("#contenu_panier_bg").fadeIn("slow");
				}
			break;
			case 1:
				if(display=="block")
				{			
					$("#contenu_panier_bg").fadeOut("slow");
				}
			break;
			default:

			break;
		}
}


function getInfo()
{
	
}
function eraseWindow()
{
	
}

function displayWindows(type, id_produit,id_div)
{
	if(type=='comment')
	{
		addComment(id_produit,id_div);
	}
			display =	document.getElementById('comment_global_'+id_div).style["display"];
	
	$.ajax({
		   type: "POST",
		   url: rootUrl+"rsk/ajax_query/query.php?query_number=19",
		   data: "type="+ type+"&id="+id_produit,
		   success: function(msg){

				if(display=="none" )
				{
					document.getElementById('window_'+id_div).innerHTML=msg;
					
					$('#comment_global_'+id_div).slideDown("normal");
				}
				else
				{
					
					if(document.getElementById('inprogress_'+id_div).innerHTML == type)
					{
						$('#comment_global_'+id_div).slideUp("normal");
					}
					else
					{
						document.getElementById('window_'+id_div).innerHTML=msg;
					}
					
				}
				document.getElementById('inprogress_'+id_div).innerHTML=type;
				if(document.getElementById('inprogress_'+id_div).innerHTML!='comment')
				{
					document.getElementById('add_comment_'+id_div).innerHTML='';
				}
		   }
		 });
}
function addComment(produit,id_div)
{

	$.ajax({
		   type: "POST",
		   url: rootUrl+"rsk/ajax_query/query.php?query_number=20",
		   data: "produit="+ produit,
		   success: function(msg){
				
			display =	document.getElementById('comment_global_'+id_div).style["display"];
	
				if(display=="none" )
				{
					document.getElementById('add_comment_'+id_div).innerHTML=msg;
			
					//$('#comment_global_'+id_div).slideDown("normal");
	
					check = "down";
				}
				else
				{
					document.getElementById('add_comment_'+id_div).innerHTML=msg;
				}
		   }
		 });
}

/*function displayComment(id)
{
	alert(document.getElementById('inprogress').innerHTML);
		$.ajax({
		   type: "POST",
		   url: rootUrl+"rsk/ajax_query/query.php?query_number=16",
		   data: "comment="+ id,
		   success: function(msg){
			   
			   
			
			document.getElementById('inprogress').innerHTML="commentaire";
			alert (display =	document.getElementById('comment_global').style["display"]);
			alert(display);
			if(display=="none" )
			{
				$("#comment_global").slideDown("normal");
			}
			else
			{
				$("#comment_global").slideUp("normal");	
				document.getElementById('more').innerHTML="";
				document.getElementById('effect').innerHTML="";
				document.getElementById('comments').innerHTML=msg;				
				$("#comment_global").slideDown("normal");
			}
			
		   }
		 });
}
function displayEffect(id)
{
		$.ajax({
		   type: "POST",
		   url: rootUrl+"rsk/ajax_query/query.php?query_number=17",
		   data: "comment="+ id,
		   success: function(msg){
						
			display =	document.getElementById('comment_global').style["display"];
		
			if(display=="none" )
			{
				$("#comment_global").slideDown("normal");
			}
			else
			{
				$("#comment_global").slideUp("normal");	
				document.getElementById('more').innerHTML="";
				document.getElementById('effect').innerHTML=msg;
				document.getElementById('comments').innerHTML="";				
				$("#comment_global").slideDown("normal");
			}
		   }
		 });
}
function displayMoreProduct(id)
{
		$.ajax({
		   type: "POST",
		   url: rootUrl+"rsk/ajax_query/query.php?query_number=18",
		   data: "comment="+ id,
		   success: function(msg){
			   
			document.getElementById('more').innerHTML=msg;
			document.getElementById('effect').innerHTML="";
			document.getElementById('comments').innerHTML="";
			
			document.getElementById('inprogress').innerHTML="plus";			
			display =	document.getElementById('comment_global').style["display"]
			alert(display);
			if(display=="none")
			{
				$("#comment_global").slideDown("normal");
			}
			else
			{
				$("#comment_global").slideUp("normal");	
			}
			
		   }
		 });
}*/
function redirection(page)
{
	window.location=page;
}

function echeck(str) 
{
	
		var at='@';
		var dot='.';
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		
		if (str.indexOf(at)==-1) return false;
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;
		if (str.indexOf(at,(lat+1))!=-1) return false;
		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false;
		if (str.indexOf(dot,(lat+2))==-1) return false;
		if (str.indexOf("..",lat)!=-1) return false;
		if (str.indexOf(" ")!=-1) return false;
		return true;			
		
	}
function checkEmailAjax(input,affichage)
{
	
	var email = document.getElementById(input).value;

	if(email!='')
	{
	$.ajax({ 
			   type: "POST", 
			   url: rootUrl+"rsk/ajax_query/query.php?query_number=23",
			   data: "email="+ email,
			   success: function(msg)
			   { 
				if(msg==1)
				{
					document.getElementById(affichage).innerHTML = "<img src=\""+rootUrl+"rsk/images/ok.png\" width=\"17\" height=\"17\" />";
					document.getElementById('email_ok').value = 1;
				}
				else if(msg==0)
				{
					document.getElementById(affichage).innerHTML = "<img src=\""+rootUrl+"rsk/images/warning.png\" width=\"17\" height=\"17\" />";
					document.getElementById('email_ok').value = 0;					
				}
			   } 
		   });
	}
}
