function preloader()
{

}

function submitCheckDepartement(myfield, e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13)
	{
		checkDepartement();
		return false;
	}
	else
		return true;
}

function submitCheckDepartementCgu(myfield, e)
{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;

	if (keycode == 13)
	{
		checkDepartementCgu();
		return false;
	}
	else
		return true;
}

function checkDepartement()
{
	var dpt = document.getElementById("dpt").value;
	$.ajax({
	  type: "POST",
	  url: "ajax/checkDepartement.php",
	  data: "dpt=" + dpt,
	  success: function(msg){
	    document.getElementById("cityChoice").innerHTML = msg;
	  }
	});
}


function checkDepartementCgu()
{
	var dpt = document.getElementById("dpt").value;
	$.ajax({
	  type: "POST",
	  url: "ajax/checkDepartementCgu.php",
	  data: "dpt=" + dpt,
	  success: function(msg){
	    document.getElementById("cguText").innerHTML = msg;
	  }
	});
}



function sendPassword()
{
	document.getElementById("sendPasswordDiv").innerHTML = "<b>Votre mot de passe vient de vous &ecirc;tre envoy&eacute; par mot de passe.</b>";
}


function sendToFriend()
{
	document.getElementById("sendToFriendDiv").innerHTML = "<b>L'offre vient d'&ecirc;tre envoy&eacute; &agrave; votre ami(e).</b>";
}


function chooseCity()
{
	var postalcode = document.getElementById("city").value;
	$.ajax({
	  type: "POST",
	  url: "ajax/chooseCity.php",
	  data: "postalcode=" + postalcode,
	  success: function(msg){
	    //document.getElementById("city").innerHTML = msg;
	    window.location.href="choose.php";
	  }
	});
}

function chooseSubCategory()
{
	var subcategory = document.getElementById("subcategory").value;
	window.location.href="list-shops.php?id_category=" + subcategory;
}

function chooseBrand()
{
	var brand = document.getElementById("brand").value;
	window.location.href="list-shops.php?id_brand=" + brand;
}

function chooseStreet()
{
	var street = document.getElementById("street").value;
	window.location.href="list-shops.php?street=" + street;
}



function selectOffer(id_partner_shop, id_offer)
{
	$.ajax({
	  type: "POST",
	  url: "ajax/selectOffer.php",
	  data: "id_partner_shop=" + id_partner_shop + "&id_offer=" + id_offer,
	  success: function(msg){
	    document.getElementById("bodyOffer").innerHTML = msg;
	  }
	});
}


function selectOfferBlock(id_offer_block)
{
	if (document.getElementById("offer0"))
	{
		document.getElementById("offer0").style.display = 'none';
		document.getElementById("offerPicture0").style.display = 'none';
	}
	if (document.getElementById("offer1"))
	{
		document.getElementById("offer1").style.display = 'none';
		document.getElementById("offerPicture1").style.display = 'none';
	}
	if (document.getElementById("offer2"))
	{
		document.getElementById("offer2").style.display = 'none';
		document.getElementById("offerPicture2").style.display = 'none';
	}
	document.getElementById("offer" + id_offer_block).style.display = 'block';
	document.getElementById("offerPicture" + id_offer_block).style.display = 'block';
}



function rollMenu(idContext, eventContext)
{
	var elem = document.getElementById(idContext);
	if (eventContext == 1)
		elem.className = 'divMenuButtonHover';
	else
		elem.className = 'divMenuButton';
}


function rollImg(imgName, imgContext)
{
	if(document.images)
	{
		if (imgContext == 2)
			document.images['menu'+imgName].src='templates/images/menu'+imgName+'.jpg';
		else
			document.images['menu'+imgName].src='templates/images/menu'+imgName+'Hover.jpg';
	}
	else
	{
		imgobj=eval("document."+imgName);
		if (imgContext == 2)
			imgobj.src=='templates/images/menu'+imgName+'.jpg';
		else
			imgobj.src=='templates/images/menu'+imgName+'Hover.jpg';
	}
}





function addBookmark(url, title)
{
	if (window.sidebar)
		return window.sidebar.addPanel(title, url, "");
	else if ( window.external )
		return window.external.AddFavorite( url, title);
	else if (window.opera && window.print)
		return true;
	return true;
}

function writeBookmarkLink(url, title, text, img)
{
	var insert = '';
	if (img)
		insert = writeBookmarkLinkObject(url, title, '<img src="' + img + '" alt="' + escape(text) + '" title="' + escape(text) + '" />') + '&nbsp';
	insert += writeBookmarkLinkObject(url, title, text);
	document.write(insert);
}

function writeBookmarkLinkObject(url, title, insert)
{
	if (window.sidebar || window.external)
		return ('<a href="javascript:addBookmark(\'' + escape(url) + '\', \'' + escape(title) + '\')">' + insert + '</a>');
	else if (window.opera && window.print)
		return ('<a rel="sidebar" href="' + escape(url) + '" title="' + escape(title) + '">' + insert + '</a>');
	return ('');
}
