/////////////////////////////////////////////////////////////////////////////
//  Goto Page
/////////////////////////////////////////////////////////////////////////////
function GotoPage()
	{
	theForm = document.FrmGotoPage;
	theForm.submit();
	}
/////////////////////////////////////////////////////////////////////////////
//  Edit Map
/////////////////////////////////////////////////////////////////////////////
function ValidateEditMap()
	{
	if (!CheckMbr())
		return false;
	return true;
	}	
/////////////////////////////////////////////////////////////////////////////
//  Scripts d'Edition de commentaires
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
//  Appel: Fermeture formulaire d'Edition de commentaire
/////////////////////////////////////////////////////////////////////////////
function Close_Map_Edit_Com(nId,bMod)
	{
	ShowLoading();
	szUrl="Push/Cont/Div/Cmt/"+nId+"/index.html";
	if (xmlHttp = GetxmlHttp())
		{
		xmlHttp.open("GET", szUrl);
		xmlHttp.onreadystatechange = function() {
						if (xmlHttp.readyState==4)
							{
							$('com_'+nId).innerHTML=xmlHttp.responseText;
							if (bMod)
								$('mod_'+nId).style.display="block";
							HideLoading();
							}
										};
		xmlHttp.send(null);
		}
	}
/////////////////////////////////////////////////////////////////////////////
//  Appel: Formulaire d'Edition de commentaire
/////////////////////////////////////////////////////////////////////////////
function Get_Map_Edit_Com(nId,bMod)
	{
	ShowLoading();
	szUrl="Push/Form/Edit/Cmt/"+nId+"/index.html";
	if (xmlHttp = GetxmlHttp())
		{
		xmlHttp.open("GET", szUrl);
		xmlHttp.onreadystatechange = function() {
						if (xmlHttp.readyState==4)
							{
							if (bMod)
								$('mod_'+nId).style.display="none";
							$('com_'+nId).innerHTML=xmlHttp.responseText;
							HideLoading();
							}
										};
		xmlHttp.send(null);
		}
	}
/////////////////////////////////////////////////////////////////////////////
//  Add Comment
/////////////////////////////////////////////////////////////////////////////
function ValidateAddCom(theForm)
	{
	if (!CheckMbr())
		return false;	
	return ValidateTheForm(theForm);
	}	
/////////////////////////////////////////////////////////////////////////////
//  Scripts de Downloads
/////////////////////////////////////////////////////////////////////////////	
/////////////////////////////////////////////////////////////////////////////
//  Download File
/////////////////////////////////////////////////////////////////////////////
function GoDown(sTyp,nId)
	{
	ShowLoading();		
	szUrl="Push/PreDown/"+sTyp+"/"+nId+"/index.html";
	if (xmlHttp = GetxmlHttp())
		{
		xmlHttp.open("GET", szUrl);
		xmlHttp.onreadystatechange = function() {
						if (xmlHttp.readyState==4)
							{		
							sResult=xmlHttp.responseText;
							HideLoading();
							HandleDownResponse(sResult);
							}
										};
		xmlHttp.send(null);
		}
	}
	
/////////////////////////////////////////////////////////////////////////////
//  Traitement retour initialisation Download
/////////////////////////////////////////////////////////////////////////////
function HandleDownResponse(sResult)
	{
	FileDatas = sResult.split('|');
	erNum=parseInt(FileDatas[0]);
	erTxt=FileDatas[1];

	if (erNum || erTxt!="")
		{
		alert(erTxt);
		return;
		}
	szUrl=GlblUrl+"Push/GetFile/index.html";
	document.location=szUrl;	
	}
/////////////////////////////////////////////////////////////////////////////
//  Lancer installation FTP
/////////////////////////////////////////////////////////////////////////////
function GoInst()
	{
	if (!CheckMbr())
		return;	
	theForm = document.FrmInstZip;
	theForm.btninstsubmit.disabled=true;

	if (!ValidateTheForm(theForm))
		{
		theForm.btninstsubmit.disabled=false;
		return;
		}

	if (confirm(_('debinstall')))
		{
		ShowMask();
		ShowLoading();
		szUrl="Push/GoInst/index.html";
		nId = theForm.Id.value;
		if (xmlHttp = GetxmlHttp())
			{
			var params = "";
			params 	+=	"Typ="+theForm.Typ.value;
			params 	+=	"&Id="+nId;
			params 	+=	"&ftpServ="+theForm.ftpServ.value;
			params 	+=	"&ftpHost="+theForm.ftpHost.value;
			params 	+=	"&ftpPort="+theForm.ftpPort.value;
			params 	+=	"&ftpLogin="+theForm.ftpLogin.value;
			params 	+=	"&ftpPass="+theForm.ftpPass.value;
			params 	+=	"&ftpDir="+theForm.ftpDir.value;
			if (theForm.ftpRpl.checked==true)
				params += "&ftpRpl=1";
			if (theForm.ftpPasv.checked==true)
				params += "&ftpPasv=1";
			if (theForm.ftpBz2.checked==true)
				params += "&ftpBz2=1";
			xmlHttp.open("POST", szUrl,true);
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", params.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = function() {
							if ((xmlHttp.readyState==4)&&(xmlHttp.status == 200))
								{																					
								sResult=xmlHttp.responseText;
								theForm.btninstsubmit.disabled=false;
								HideMask();
								HideLoading();
								HandleInstResponse(sResult,nId);
								return;
								}
											};

			xmlHttp.send(params);
			}
		}
	theForm.btninstsubmit.disabled=false;
	return;
	}
/////////////////////////////////////////////////////////////////////////////
//  Traitement retour initialisation Download
/////////////////////////////////////////////////////////////////////////////
function HandleInstResponse(sResult,nId)
	{
	FileDatas = sResult.split('|');
	erNum=parseInt(FileDatas[0]);
	if (erNum)
		{
		erTxt=FileDatas[1];
		alert(erTxt);
		}
	else
		{
		alert(_('ftpinst_ok'));
		if ($('inst_'+nId).style.display=="block")
			{
			CloseFtpInstForm(nId);
			return;
			}		
		}
	}	
/////////////////////////////////////////////////////////////////////////////
//  Download Ressource File
/////////////////////////////////////////////////////////////////////////////
function GoRes(nId)
	{
	GoDown("Res",nId);
	}
/////////////////////////////////////////////////////////////////////////////
//  Download individual Files
/////////////////////////////////////////////////////////////////////////////
function ValidateGetFiles(nId)
	{
	theForm = document.FrmGetFiles;																		
	var nSel=theForm.FilesLst.selectedIndex;
	if (nSel == -1)
		{
		alert(_('select_one'));
		return;
		}
	ShowLoading();		
	szLstFiles=""; 
	for (var i = 0; i < theForm.FilesLst.length; i++) 
		{
		if (theForm.FilesLst[i].selected)
			{ 
			szLstFiles = szLstFiles+theForm.FilesLst[i].text+";";
			}
		}
	szUrl="Push/PreDown/Fls/"+nId+"/index.html";
	if (xmlHttp = GetxmlHttp())
		{
		var params = "SelFls="+escape(szLstFiles);
		xmlHttp.open("POST", szUrl,false);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-length", params.length);
		xmlHttp.setRequestHeader("Connection", "close");										
		xmlHttp.send(params);
		sResult=xmlHttp.responseText;
		HideLoading();
		HandleDownResponse(sResult);
		return;
		}
	}
/////////////////////////////////////////////////////////////////////////////
//  Download Mappak
/////////////////////////////////////////////////////////////////////////////
function ValidateGetMapPak()
	{
	theForm = document.FrmMapPak;																		
	DisableBtnSub(true);
	if (NbrSel <2) 
		{
		alert(_('not_enough_sel'));
		DisableBtnSub(false);
		return;
		}

	if (confirm(_('long_operation')))
		{
		ShowLoading();
		var theMaps = document.getElementsByTagName('input');
		nMaps=""; 
		for (var i = 0; i < theMaps.length; i++) 
			{
			if (theMaps[i].name=="Maps[]")
				{
				if (theMaps[i].checked==true)
					{ 
					nMaps = nMaps+theMaps[i].value+";";
					}
				}
			}
		szUrl="Push/PreDown/Mpk/1/index.html";
		if (xmlHttp = GetxmlHttp())
			{
			var params = "Maps="+nMaps;
			if (theForm.Do17.checked==true)
				params += "&Do17=1";
			xmlHttp.open("POST", szUrl,true);
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", params.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = function() {
							if ((xmlHttp.readyState==4)&&(xmlHttp.status == 200))
								{																					
								sResult=xmlHttp.responseText;
								DisableBtnSub(false);
								HideLoading();
								HandleDownResponse(sResult);
								return;
								}
											};

			xmlHttp.send(params);
			}
		}
	DisableBtnSub(false);	
	}
/////////////////////////////////////////////////////////////////////////////
//  Installation Mappak
/////////////////////////////////////////////////////////////////////////////
function ValidateGetInst()
	{
	theForm = document.FrmMapPak;	

	alert(_('not_yet_implemented'));
	return;	
	
	DisableBtnSub(true);
	if (NbrSel <2) 
		{
		alert(_('not_enough_sel'));
		DisableBtnSub(false);
		return;
		}

	if (confirm(_('long_operation')))
		{
		ShowLoading();
		var theMaps = document.getElementsByTagName('input');
		nMaps=""; 
		for (var i = 0; i < theMaps.length; i++) 
			{
			if (theMaps[i].name=="Maps[]")
				{
				if (theMaps[i].checked==true)
					{ 
					nMaps = nMaps+theMaps[i].value+";";
					}
				}
			}
		szUrl="Push/Inst/Mpk/index.html";
		if (xmlHttp = GetxmlHttp())
			{
			var params = "Maps="+nMaps;
			if (theForm.Do17.checked==true)
				params += "&Do17=1";
			xmlHttp.open("POST", szUrl,true);
			xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xmlHttp.setRequestHeader("Content-length", params.length);
			xmlHttp.setRequestHeader("Connection", "close");
			xmlHttp.onreadystatechange = function() {
							if ((xmlHttp.readyState==4)&&(xmlHttp.status == 200))
								{																					
								sResult=xmlHttp.responseText;
								DisableBtnSub(false);
								HideLoading();
								HandlePkInstResponse(sResult);
								return;
								}
											};

			xmlHttp.send(params);
			}
		}
	DisableBtnSub(false);	
	}
/////////////////////////////////////////////////////////////////////////////
//  Handle Inst Pack Response
/////////////////////////////////////////////////////////////////////////////
function HandlePkInstResponse(sResult)
	{
	alert(sResult);
	}	
/////////////////////////////////////////////////////////////////////////////
//  Validation formulaire recherche
/////////////////////////////////////////////////////////////////////////////
function ValidateLstSearchForm(theForm)
	{
	return ValidateTheForm(theForm);
	}
/////////////////////////////////////////////////////////////////////////////
//  Validation Formulaire de Tri
/////////////////////////////////////////////////////////////////////////////
function ValidateLstSortForm(theForm)
	{
	return true;
	}
/////////////////////////////////////////////////////////////////////////////
//  Ajouter au panier
/////////////////////////////////////////////////////////////////////////////
function AddToCart(nId)
	{
	if (!CheckMaxItemsCart())
		return;
	if (!CheckMbr())
		return;
	ShowLoading();
	szUrl="Push/Cart/"+nId+"/index.html";
	if (xmlHttp = GetxmlHttp())
		{
		xmlHttp.open("GET", szUrl);
		xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState==4)
			{
			sResult = parseInt(xmlHttp.responseText);
			HideLoading();
			if (!sResult)
				{
				if (confirm(_('already_in_cart')))
					document.location=GlblUrl+"View/Cart/index.html";
				}
			else
				{
				$('CartMbrMaps').innerHTML=sResult;
				}
			}
										};
		xmlHttp.send(null);
		}
	}
		
/////////////////////////////////////////////////////////////////////////////
//  Afficher Textures Wad
/////////////////////////////////////////////////////////////////////////////
var ActTexOpen=0;
function WadTexs(nId)
	{
	if ($('tex_'+nId).style.display=="block")
		{
		CloseTexWindow(nId);
		return;
		}
	if (ActTexOpen)
		CloseTexWindow(ActTexOpen);
	if (confirm(_('long_operation')))
		{
		ShowMask();
		ActTexOpen=nId;
		szUrl="Push/Texs/"+nId+"/index.html";
		if (xmlHttp = GetxmlHttp())
			{
			ShowLoading();
			xmlHttp.open("GET", szUrl);
			xmlHttp.onreadystatechange = function() {
							if (xmlHttp.readyState==4)
								{
								HideMask();
								HideLoading();
								sResult=xmlHttp.responseText;
								HandleTexsResponse(sResult,nId)
								return;
								}
											};
			xmlHttp.send(null);
			}
		}
	}
/////////////////////////////////////////////////////////////////////////////	
function CloseTexWindow(nId)
	{
	$('tex_'+nId).style.display="none";
	$('tex_'+nId).innerHTML=null;
	ActTexOpen=0;		
	}
/////////////////////////////////////////////////////////////////////////////
function HandleTexsResponse(sResult,nId)
	{
	FileDatas = sResult.split('|');
	erNum=parseInt(FileDatas[0]);

	if (erNum)
		{
		erTxt=FileDatas[1];
		alert(erTxt);
		}
	else
		{
		Cntnt=FileDatas[2];
		$('tex_'+nId).innerHTML=Cntnt;
		$('tex_'+nId).style.display="block";
		}
	}		
function Wad_OpenTex(szImg,nW,nH)
	{
	ShowMask();
	ShowLoading();
	Pause(250);
	var NewShot = new Image();
	NewShot.onload = function() 
		{
		Wad_MoveTex(nW,nH);
		HideLoading();
		$('ScreenshotImage').src=szImg;
		$('ScreenshotImage').style.width=nW+"px";
		$('ScreenshotImage').style.height=nH+"px";
		$('Screenshot').style.display="block";									
		}
	NewShot.src = szImg;
	}
function Wad_MoveTex(nW,nH)
	{
	var WScreen=GetSHW()[0];
	var HScreen=GetSHW()[1];	
	var VScroll=GetScrollXY()[1];
	var WShot=nW;
	var HShot=nH;
	var LShot=Math.round((WScreen-WShot)/2);
	var TShot=VScroll+Math.round((HScreen-HShot)/2);
	$('Screenshot').style.width=WShot+"px";
	$('Screenshot').style.height=HShot+"px";
	$('Screenshot').style.top=TShot+"px";
	$('Screenshot').style.left=LShot+"px";
	}	
function Wad_CloseTex()
	{
	HideMask();
	$('Screenshot').style.display="none";
	$('ScreenshotImage').src="Images/1x1.gif";
	$('ScreenshotImage').style.width="1px";
	$('ScreenshotImage').style.height="1px";
	}
/////////////////////////////////////////////////////////////////////////////
//  Rafraichir Liste Mini Serveurs
/////////////////////////////////////////////////////////////////////////////
function RefreshSmallSrvList()
	{
	if (!CheckMbr())
		return;	
	ShowLoading();
	szUrl=GlblUrl+"Push/Sml/Srv/Lst/index.html";
	if (xmlHttp = GetxmlHttp())
		{
		xmlHttp.open("GET", szUrl);
		xmlHttp.onreadystatechange = function() {
						if (xmlHttp.readyState==4)
							{
							sResult = xmlHttp.responseText;
							erNum=parseInt(sResult.substr(0,1));
							erTxt=sResult.substr(2);
							HideLoading();
							if (erNum)
								{
								alert(erTxt);
								return;
								}
							$('SrvSmallList').innerHTML=erTxt;
							}
										};
		xmlHttp.send(null);
		}
	}
	
/////////////////////////////////////////////////////////////////////////////
//  Configuration Serveur
/////////////////////////////////////////////////////////////////////////////
function CloseEdtSrvForm()
	{
	$('FrmEdtSrv').style.display='none';
	$('FrmEdtSrv').innerHTML=null;
	return;					
	}
////////////////////////////////////	
function PushSrvConfFrm(nSvId)
	{
	if (!CheckMbr())
		return;
	if ($('FrmEdtSrv').style.display=='block')
		{
		$('FrmEdtSrv').style.display='none';
		$('FrmEdtSrv').innerHTML=null;
		return;			
		}

	if (oRfhAuto)
		{
		window.clearTimeout(oRfhAuto);	
		oRfhAuto=null;		
		}

	ShowLoading();		
	szUrl="Push/Frm/Srv/"+nSvId+"/index.html";
	if (xmlHttp = GetxmlHttp())
		{
		xmlHttp.open("GET", szUrl);
		xmlHttp.onreadystatechange = function() {
						if (xmlHttp.readyState==4)
							{
							HideLoading();								
							sResult = xmlHttp.responseText;
							if (sResult=="")
								return;
							$('FrmEdtSrv').innerHTML=sResult;
							$('FrmEdtSrv').style.display='block';
							return;
							}
										};
		xmlHttp.send(null);
		}
	}

/////////////////////////////////////////////////////////////////////////////
//  Ajouter Favori
/////////////////////////////////////////////////////////////////////////////
function PushAddFavFrm()
	{
	if (!CheckMbr())
		return;	
	if ($('FrmEdtSrv').style.display=='block')
		{
		$('FrmEdtSrv').style.display='none';
		$('FrmEdtSrv').innerHTML=null;
		return;			
		}
	ShowLoading();		
	szUrl="Push/Frm/AddFav/index.html";
	if (xmlHttp = GetxmlHttp())
		{
		xmlHttp.open("GET", szUrl);
		xmlHttp.onreadystatechange = function() {
						if (xmlHttp.readyState==4)
							{
							HideLoading();								
							sResult = xmlHttp.responseText;
							if (sResult=="")
								return;
							$('FrmEdtSrv').innerHTML=sResult;
							$('FrmEdtSrv').style.display='block';
							}
										};
		xmlHttp.send(null);
		}
	}
/////////////////////////////////////////////////////////////////////////////
//  Supprimer Serveur
/////////////////////////////////////////////////////////////////////////////
function DelSrv(nSvId)
	{
	if (!confirm(_('delete_server')))
		return;
	szUrl=GlblUrl+"Del/Srv/"+nSvId+"/index.html";
	document.location=szUrl;	
	}
/////////////////////////////////////////////////////////////////////////////
//  Validation Notation
/////////////////////////////////////////////////////////////////////////////
function ValNote(theForm)
	{
	vote1=parseInt(getCheckedValue(theForm.vote1));
	vote2=parseInt(getCheckedValue(theForm.vote2));
	vote3=parseInt(getCheckedValue(theForm.vote3));
	if (!vote1 && !vote2 && !vote3)
		{
		alert(_('no_all_zero'));
		return false;
		}
	return true;
	}	
/////////////////////////////////////////////////////////////////////////////
//  Afficher ecran soumission screenshot
/////////////////////////////////////////////////////////////////////////////
function Toggle_Sub_Screen_Frm(nMapId,bScrOk)
	{
	if (!CheckMbr())
		return;
	if (!bScrOk)
		{
		alert(_('main_scr'));
		return;		
		}
	$ActDisp = $('scrsht_'+nMapId).style.display;
	$('scrsht_'+nMapId).style.display = $ActDisp=="block" ? "none" : "block";
	}		
	