var promovac = new Object();

promovac.reserve = function() {
	selects = getEl("containPrixDispo").getElementsByTagName("select");
	txt = "";
	tabRes = new Array();
	for(i=0; i < selects.length; i++)
	{
		idSel = selects[i].id;
		if(idSel.substr(0,4) == "qte_")
		{
			id = idSel.replace("qte_", "");
			if(parseInt(getEl("qte_"+id).value) > 0)
			{
				tmp = new Array(getEl("sel_"+id).value, getEl("qte_"+id).value);
				tabRes.push(tmp);
			}
		}		
	}
	
	for(i = 0; i < tabRes.length; i++)
	{
		if(i == tabRes.length - 1)
		{
			afterReserve = function()
			{
				location.href = '/reservation_1.html';
			}
		}
		lines = tabRes[i][0].split("#");
		for(j=0; j < lines.length; j++)
		{
			vars = lines[j].split("-");
			if(vars[3] > 0)
			{
				req = 0;	
			}
			else
			{
				req = 1;
			}
			reserve(vars[0], vars[1], vars[2], '', '', req, tabRes[i][1]);	
		}
	}
	
	if(tabRes.length == 0)
	{
		alert("Veuillez sélectionner le nombre d'hébergement que vous souhaitez réserver.");
	}
}

function goOmniture ()
{
	
		var s_account="karavelpromovacprod";
		src="http://www.service-voyages.com/z/go/resources/js/omniture/s_code.js";
		
		  s.pageName = 'ListeResCamping';
		  s.channel = 'Camping';
		  s.server = 'camping.promovacances.com';
		  s.prop11 = 'ListeResCamping';
	
		
		
		var s_code=s.t();
		if(s_code)
		{
			document.write(s_code);
		}
		/*
		if(navigator.appVersion.indexOf('MSIE 6.0')>=0)
		{
			document.write(unescape('%3C')+'\!-'+'-');
		}
	
		*/		
}



promovac.response = function(params)
{
	var xhr = getXhr();
	div = "main";
	dwait = getEl("wait");
	var siteId = getEl("siteId").value;
	//alert("test");
	if(!params)
	{
		params = "region_id="+getEl("search_region_id").value;
		params += "&dep_id="+getEl("search_dep_id").value;
		params += "&ville_id="+getEl("search_ville_id").value;
		params += "&capacite_id="+getEl("capacite_id").value;
		params += "&siteId="+getEl("siteId").value;
		params += "&date="+getEl("date").value;
		params += "&nuite_id="+getEl("nuite_id").value;
		params += "&nump="+getEl("nump").value;
	}

	dres = document.getElementById(div);

    xhr.onreadystatechange = function()
	{
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			dres.innerHTML = xhr.responseText;
			var searchForm = new SearchForm({siteId: siteId});
			//goOmniture();
			dwait.style.display="none";
		}
	}
	dwait.style.display="";
	dwait.style.left = (getLeft(div) + (getWidth(div) - getWidth("wait"))/2)+"px";
	dwait.style.top = (getTop(div) + 50 )+"px";

	xhr.open("GET", "/scripts/tati/response.php?"+params+"&d="+ (new Date()).getTime(), true);
	
    xhr.send(null);
}

function updateDate()
{
	e = getEl("calendrier");
	if(e.style.display == "")
	{
		e.style.display = "none";
	}
	else
	{
		e.style.left = getLeft("sf.dateText")+"px";
		e.style.top = (getTop("sf.dateText") + getHeight("sf.dateText"))+"px";
		e.innerHTML = "<div id='my_cal'><p style='text-align:center;color:#0071DB; font-size:10px;'><img src='/commun/images/common/loading.gif' style='margin:3px;' /></p></div>";
		e.style.display = "";
		setCalendar(getEl("sf.dateText").value);
	}
}

function setCalendar(la_date)
{
  var xhr = getXhr();
  div = "calendrier";
  e = getEl(div);
  xhr.onreadystatechange = function()
	{
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			e.innerHTML = xhr.responseText;
		}
	}

  xhr.open("GET", "/scripts/promovac/calendrier.php?date="+la_date+"&div="+div+"&d="+ (new Date()).getTime(), true);
  xhr.send(null);
}

function setDate(d)
{
	getEl("sf.dateText").value=d;
	getEl('calendrier').style.display='none';
}

function displayFlash(swf, hauteur, largeur, alternatif)
{
 document.write('<object type="application/x-shockwave-flash" data="'+swf+'" width="'+hauteur+'" height="'+largeur+'">');
 document.write('<param name="allowScriptAccess" value="sameDomain" />');
 document.write('<param name="movie" value="'+swf+'" />');
 document.write(alternatif);
 document.write('</object>');
}

function beforeGetPricesGrid()
{
	getEl("tarifs").innerHTML = "<p style='text-align:center;color:#0071DB; font-size:10px;'>Recherche des prix<br /><img src='/commun/images/common/loading.gif' style='margin:3px;' /></p>";
}

function afterGetPricesGrid(xhr)
{

	getEl("tarifs").innerHTML = xhr.responseText;
	setTimeout('scrolldiv("tarifs_right",0,0,"tarifs_left")', 1000) ;
	
}



function afterReserve()
{
	getPanier();
}

function res_onglet(div)
{
	var tab = Array("tarifs", "heb");
	for(i = 0; i < tab.length; i++)
	{
		if(div == tab[i])
		{
			document.getElementById("panel_"+div).style.display = "";
			document.getElementById("onglet_"+div).className = "residence_1_3_1_1";
		}
		else
		{
			document.getElementById("panel_"+tab[i]).style.display = "none";
			document.getElementById("onglet_"+tab[i]).className = "residence_1_3_1_2";
		}
	}
}

function thumb_select(img, res)
{
	for(i=1; i< 15; i++)
	{
		if(document.getElementById("thumb_"+i))
		{
			if(i == img)
			{
				document.getElementById("thumb_"+i).src="/image_produitsmall-res_"+res+"_"+i+"_1.jpg";
			}
			else
			{
				document.getElementById("thumb_"+i).src="/image_produitsmall-res_"+res+"_"+i+"_0.jpg";
			}
		}
	}
}

function change_img(img, dest)
{
	document.getElementById(dest).src = img;
}

function getPrixDispo(produitId, duree,sejour)
{
	var xhr = getXhr();
    
    xhr.onreadystatechange = function()
	{
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			getEl("containPrixDispo").innerHTML = xhr.responseText;
		}
	}
    
    if(typeof part == "undefined")
    {
    	part = "";
    }
    if(typeof duree == "undefined")
    {
    	duree = "";
    }
    getEl("containPrixDispo").innerHTML = "<div id=\"containPrixDispo_attente\">les tarifs et disponibilités sont en cours de chargement.<br /> Merci de patienter.<br /><br /><img src=\"/commun/images/common/loading.gif\"/></div>";
	xhr.open("GET", "/scripts/promovac/prix_v2.php?produitId="+produitId+"&duree="+duree+"&sejour="+sejour+"&d="+ (new Date()).getTime(), true);
    xhr.send(null);
}
promovac.forward = function()
{
	var xhr = getXhr();
	xhr.onreadystatechange = function()
	{
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			location.href = xhr.responseText;
		}
	}

	xhr.open("GET", "/scripts/promovac/getPageRetour.php?d="+ (new Date()).getTime(), true);
    xhr.send(null);
}
function getImgs(produitId, start, end)
{
	var xhr = getXhr();
	xhr.onreadystatechange = function()
	{
		if(xhr.readyState == 4 && xhr.status == 200)
		{
			getEl("imgs").innerHTML = xhr.responseText;
		}
	}
	
	params = "produitId="+produitId+"&start="+start+"&end="+end;

	xhr.open("GET", "/scripts/tati/imgs.php?"+params+"&d="+ (new Date()).getTime(), true);
    xhr.send(null);
}
