function toggle_div(div_id)
{
	if ($(div_id).style.display == "none")
	{
		$(div_id).style.padding = "3px";
		$(div_id).style.display = "block";
	}
	else
	{
		$(div_id).style.padding = "0px";
		$(div_id).style.display = "none";
	}
}

function submit_lang()
{
	document.lang.submit();
}

function mail_ok(mail)
{
	if (window.RegExp) 
	{
		var reg1mail = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
		var reg2mail = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
		var reg1 = new RegExp(reg1mail);
		var reg2 = new RegExp(reg2mail);
		
		if (!reg1.test(mail) && reg2.test(mail)) 
		{
			return true;
		}

		return false;
	} 
	else 
	{
		if(mail.indexOf("@") >= 0)
		{
			return true;
		}
		return false;
	}
}

function show_large(link)
{
	document.getElementById('big_image').src = link;
}

function request_details(id_shop_item)
{
	window.open('/request_details.php?id_shop_item='+id_shop_item, 'WinE', 'width=300, height=400');
}

function open_dealers(id_dealer_company)
{
	window.open("/dealers_list.php?id_dealer_company="+id_dealer_company, "Win E", "width=650, height=500");
}

function change_pic(picture, id)
{
	var cur_big_image = $('big_image').title;
	
	$('big_image').src = "/pictures/occassions/big/"+$(id).title;
	$('big_image').title = $(id).title;
	
	$(id).src = "/pictures/occassions/thumb/"+cur_big_image;
	$(id).title = cur_big_image;
	
}

function setOrder(order, field, id_shop_category)
{
	window.location = '/occassions.php?id_shop_category='+id_shop_category+'&order='+order+'&orderby='+field;
}

function setMarkSelect(type)
{
	$('mark_select').innerHTML = "";
	new Ajax("/actions.php?action=createMarkSelect&id_shop_category="+type, {
			 method: 'get',
			 onComplete: function(text, xml)
			 {
			 	$('mark_select').innerHTML = text;
			 }
			}).request();
}

function setMark(value)
{
	$('mark').value = value;
	//$('id_mark').value = value;
}

function populateDepartmentsSelect()
{	
	$.get("/actions.php?action=getFieldsetLabels", {id_lang : id_lang}, 
			function (data)
			{
				$("#fieldset_label_title").html(data.fieldset_label_title);
				$("#lbl_td_department").html(data.lbl_td_department);
				$("#lbl_td_segment").html(data.lbl_td_segment);
				$("#lbl_select_department").html(data.lbl_td_department);
				$("#lbl_select_segment").html(data.lbl_td_segment);
			}
			, "json");
	
	$.get("/actions.php?action=getDepartments", {id_department : 0}, 
			function (data)
			{
				jQuery.each(data, function(key, value) 
				{
					$('#id_department').append($("<option></option>").attr("value",value).text(value));	
				});
				
			}
			, "json");
			
	return false;

}

function fillSegments()
{
	var dept = $("#id_department").val();
	//alert(document.getElementById('id_department').value);
	$.get("/actions.php?action=getSegments", {title : dept, id_lang: id_lang}, 
			function (data)
			{
				$("#id_segment").html("");
				jQuery.each(data, function(key, value) 
				{
					$('#id_segment').append($("<option></option>").attr("value",key).text(value));	
				});
				
			}
			, "json");
			
	return false;

}

function getDetails()
{
	var dept = $("#id_department").val();
	var segment = $("#id_segment").val();
	
	if (id_lang == 1)
	{
		var error = 'Vous devez sélectionner un département et un segment de marché';
	}
	else
	{
		var error = 'You must select a department and a market segment';
	}
	
	$.get("/actions.php?action=getDepartmentDetails", {title : dept, id_segment: segment}, 
			function (data)
			{
				if (data.phone == undefined)
				{
					alert(error);
				}
				else
				{
					$("#dept_details").html("<div style='margin-bottom: -10px; text-align: center; font-weight: bold;'>"+data.agency+"</div><p>Tel: "+data.phone+"&nbsp;&nbsp;&nbsp;Fax: "+data.fax+"&nbsp;&nbsp;&nbsp;<a onclick='fenetre1(\""+data.url+"&id_lang="+id_lang+"\");' href='#'><img src='/images/plan.png' valign='bottom' style='padding-left:10px;'></a></p>");
				}
			}
			, "json");
			
	return false;
}

function getCookie ( cookie_name ) {
  var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
  if ( results )
    return ( unescape ( results[2] ) );
  else
    return null;
}

function show_banner()
{
	var cnt = getCookie('nobanner');
	
    if ( cnt == null ) 
    {
		var cookie_date = new Date ( 2016, 01, 15 );
		document.cookie = "nobanner=1; expires="+ cookie_date.toGMTString()+"; domain=eneria.fr;";
		show = 1;
	} 
    else 
    {
		show = 0;
	}
	
	if (show == 1) 
    {
        tb_show('Eneria', '/banner.php?height=620&width=820', false);
	}

}