var uid;
var sid;

function NewLightbox(a,b){
	if(showerror==1) {showerror==0;$("#displaymessage").hide("blind");}
	uid=a;
	sid=b;
	document.getElementById('aep_win').style.width='210px';
	height=GetSize('h');
	var ScrollTop = window.pageYOffset || document.documentElement.scrollTop || 0; 
	ScrollTop=ScrollTop+((height/2)-100);
	marg= ScrollTop + 'px auto 0 auto';
	document.getElementById('aep_win').style.margin=marg;
	document.getElementById('aep_w').innerHTML='<span id="aep_prompt">Geef naam voor de nieuwe lightbox<br /><input type="text" id="newlb" name="newlb" value="" onKeyPress="if((event.keyCode==10)||(event.keyCode==13)) ae_clk(1); if (event.keyCode==27) ae_clk(0);" /></span><br><div style="text-align: right;"><input style="border: 1px solid #666; width: 60px;" id="aep_ok" onclick="ae_clk(1);" value="OK" type="button">&nbsp;<input style="border: 1px solid #666; width: 60px;" id="aep_cancel" onclick="ae_clk(0);" value="Cancel" type="button"></div>';
	ae_prompt(a_NewLightbox);
	document.getElementById('newlb').focus();
}

function a_NewLightbox(answer){
	if (answer !=null && answer!=""){
		newname=document.getElementById('newlb').value;
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null){
			document.getElementById("main").innerHTML="Your browser does not support AJAX!";
			return;
		}
		var url="phrasealb.php";
		url=url+"?action=newlb&name="+encodeURI(newname)+"&uid="+uid+"&sid="+sid+"&lng=nl";
		xmlHttp.onreadystatechange=r_NewLightbox;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
}

function r_NewLightbox(){
	if (xmlHttp.readyState==4){
		if(xmlHttp.responseText.substring(0,9)=='message||'){
			showerror=1;
			response=xmlHttp.responseText.split("||");
			if(response[1]=='error'){document.getElementById("displaymessage").style.border="1px solid #fd9999";document.getElementById("displaymessage").style.backgroundColor="#fedada";}
			if(response[1]=='oke'){document.getElementById("displaymessage").style.border="1px solid #bdd3a3";document.getElementById("displaymessage").style.backgroundColor="#d6e4c5";}
			document.getElementById("displaymessage").innerHTML=response[2];
			$("#displaymessage").show("blind");
			xmlHttp.responseText=response[3];
		}
		document.getElementById("eplightbox").innerHTML=xmlHttp.responseText;
		return true;
	}
}

function SelectLightbox(a,b,x){
	if(showerror==1) {showerror==0;$("#displaymessage").hide("blind");}
	uid=a;
	sid=b;
	lbid=x.options[x.selectedIndex].value;
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		document.getElementById("main").innerHTML="Your browser does not support AJAX!";
		return;
	}
	var url="phrasealb.php";
	url=url+"?action=selectlb&uid="+uid+"&sid="+sid+"&lbid="+lbid+"&lng=nl";
	xmlHttp.onreadystatechange=r_NewLightbox;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function r_SelectLightbox(){
	if (xmlHttp.readyState==4){
		document.getElementById("eplightbox").innerHTML=xmlHttp.responseText;
		return true;
	}
}

function AddToLB(sid,recordname,recordid){
	if(showerror==1) {showerror==0;$("#displaymessage").hide("blind");}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		document.getElementById("main").innerHTML="Your browser does not support AJAX!";
		return;
	}
	var url="phrasealb.php";
	url=url+"?action=addimg&recordname="+recordname+"&recordid="+recordid+"&sid="+sid+"&lng=nl";
	xmlHttp.onreadystatechange=r_AddToLB;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function r_AddToLB(){
	if (xmlHttp.readyState==4){
		if(xmlHttp.responseText.substring(0,9)=='message||'){
			showerror=1;
			response=xmlHttp.responseText.split("||");
			if(response[1]=='error'){document.getElementById("displaymessage").style.border="1px solid #fd9999";document.getElementById("displaymessage").style.backgroundColor="#fedada";}
			if(response[1]=='oke'){document.getElementById("displaymessage").style.border="1px solid #bdd3a3";document.getElementById("displaymessage").style.backgroundColor="#d6e4c5";}
			document.getElementById("displaymessage").innerHTML=response[2];
			$("#displaymessage").show("blind");
			xmlHttp.responseText=response[3];
		}
		document.getElementById("eplightbox").innerHTML=xmlHttp.responseText;
		return true;
	}
}
