function set_select(list,pid) {
	var i=0;
	var j=1;
	while (list.options[i] && j) {
		if (list.options[i].value==pid) {
			list.selectedIndex=i;
			j=0;
		}
		i++;
	}
}

function page_y()
{
	var v;
	var test1 = document.body.scrollHeight;
	var test2 = document.body.offsetHeight;
	if (test1 > test2) { // all but Explorer Mac
		v=document.body.scrollHeight;
	} else { // Explorer Mac, would also work in Explorer 6 Strict, Mozilla and Safari
		v=document.body.offsetHeight;
	}
	return v;
}

function page_x()
{
	var v;
	var test1 = document.body.scrollWidth;
	var test2 = document.body.offsetWidth;
	if (test1 > test2) { // all but Explorer Mac
		v=document.body.scrollWidth;
	} else { // Explorer Mac, would also work in Explorer 6 Strict, Mozilla and Safari
		v=document.body.offsetWidth;
	}
	return v;
}

function win_x()
{
	var v;
	v=window.innerWidth;
	if (!v) v=document.body.clientWidth;
	return v;
}

function win_y()
{
	var v;
	v=window.innerHeight;
	if (!v) v=document.body.clientHeight;
	return v;
}


function window_show(name,i)
{
	var st=document.getElementById(name).style;
	if (i==0) {
		st.visibility="hidden";
		st.display="none";
	} else {
		st.visibility="visible";
		st.display="block";
		if (name=="shader") {
			st.height=st.pixelHeight=page_y();
		}
		if (name=="galleryshader") {
			st.height=st.pixelHeight=page_y()-2;
			st.width=st.pixelidth=page_x()-2;
		}
		if (name=="popup") {
			st.left=st.pixelLeft=(win_x()-800)/2;
			st.top=st.pixelTop=(win_y()-500)/2+document.body.scrollTop;
		}
		if (name=="gallerypopup") {
			st.left=st.pixelLeft=(win_x()-128)/2;
			st.top=st.pixelTop=(win_y()-128)/2+document.body.scrollTop;
		}
	}
}

var popup_prefix;
function popup_open(url,prefix)
{
	popup_prefix=prefix;
	document.getElementById('popupfrm').src="about:blank";
	window_show('shader',1);
	window_show('popup',1);
	document.getElementById('popupfrm').src=url;
}

function popup_close()
{
	window_show('popup',0);
	window_show('shader',0);
}

function popup_commit(id,name)
{
	if (!document.forms.frm) alert("popup_commit: no document.forms.frm found!");
	if (!document.forms.frm[popup_prefix]) alert("popup_commit: no document.forms.frm."+popup_prefix+" found!");
	document.forms.frm[popup_prefix].value=id;
	document.getElementById(popup_prefix+'_text').innerHTML=name;
	popup_close();
}

function popup_image_commit(img)
{
	if (!document.forms.frm) alert("popup_commit: no document.forms.frm found!");
	if (!document.forms.frm[popup_prefix]) alert("popup_commit: no document.forms.frm."+popup_prefix+" found!");
	document.forms.frm[popup_prefix].value=img;
	popup_close();
}

var gimage=new Image();

gimage.onload=function(){
	document.getElementById('galleryimg').src=gimage.src;
	gallery_switch();
}

function gallery_open(url)
{
	document.getElementById('galleryimg').style.visibility='hidden';
	document.getElementById('galleryimg').style.display='none';
	document.getElementById('galleryprogress').style.visibility='visible';
	document.getElementById('galleryprogress').style.display='block';
	window_show('galleryshader',1);
	window_show('gallerypopup',1);
	gimage.src=url;
//	document.getElementById('galleryimg').src=url;
}

function gallery_close()
{
	window_show('gallerypopup',0);
	window_show('galleryshader',0);
}

function gallery_switch()
{
	setTimeout("gallery_switch2()",200);
}

function gallery_switch2()
{
	document.getElementById('galleryprogress').style.visibility='hidden';
	document.getElementById('galleryprogress').style.display='none';
	
	var st=document.getElementById('gallerypopup').style;
	var img=document.getElementById('galleryimg');
	st.left=st.pixelLeft=(win_x()-gimage.width)/2;
	st.top=st.pixelTop=(win_y()-gimage.height)/2+document.body.scrollTop;
	img.style.visibility='visible';
	img.style.display='block';
}

function admimgpopup(e,url)
{
	var t=document.getElementById('admimgpopuptable').style;
	if (e) {
		t.left=t.pixelLeft=e.clientX+10;
		t.top=t.pixelTop=e.clientY+10+document.body.scrollTop;
		t.visibility='visible';
		t.display='block';
	} else {
		t.visibility='hidden';
		t.display='none';
		return;
	}
	document.getElementById('admimgpopupimage').src='/shared/progress.gif';
	document.getElementById('admimgpopupimage').src=url;
}

function createRequestObject()
{
	if (window.XMLHttpRequest) {
		try {
			return new XMLHttpRequest();
		} catch (e){}
	} else if (window.ActiveXObject) {
		try {
			return new ActiveXObject('Msxml2.XMLHTTP');
		} catch (e){}
		try {
			return new ActiveXObject('Microsoft.XMLHTTP');
		} catch (e){}
	}
	return null;
}

function ajaj_frm(frm,callback)
{
	var params="ajaj=1";
	if (callback) params+="&callback="+callback;
	var i;
//	alert(frm.length);
	var j=0;
	var t;
	for(i=0;i<frm.length;i++) {
		t=frm.elements[i].type;
		switch (t) {
			case 'hidden':
			case 'text':
			case 'textarea':
				/*if (j) */params+="&";
				params+=escape(frm.elements[i].name);
				params+="=";
				params+=escape(frm.elements[i].value);
				j++;
				break;
			case 'checkbox':
				if (frm.elements[i].checked) {
					/*if (j) */params+="&";
					params+=escape(frm.elements[i].name);
					params+="=";
					params+=escape(frm.elements[i].value);
					j++;
				}
				break;
			case 'select':
			case 'select-one':
				/*if (j) */params+="&";
				params+=escape(frm.elements[i].name);
				params+="=";
				params+=escape(frm.elements[i].options[frm.elements[i].selectedIndex].value);
				j++;
				break;
			case 'button':
			case 'submit':
				break;
			default:
			alert("Unknown type "+t);
		}
	}
	var obj=createRequestObject();
	obj.open("POST",frm.action,true);
	obj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	obj.setRequestHeader("Connection", "close");
	obj.onreadystatechange = function() {ajaj_done(obj);}
	obj.send(params);
}
function ajaj_hash(url,callback,hash)
{
	var params="ajaj=1";
	if (callback) params+="&callback="+callback;
	var j=0;
	var t;
	for (var i in hash) {
		params+="&";
		params+=escape(i);
		params+="=";
		params+=escape(hash[i]);
		j++;
	}
	var obj=createRequestObject();
	obj.open("POST",frm.action,true);
	obj.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	obj.setRequestHeader("Connection", "close");
	obj.onreadystatechange = function() {ajaj_done(obj);}
	obj.send(params);

}

function ajaj_done(obj)
{
	//strResult=objHTTP.responseText;
	if(obj.readyState==4) {
		if (obj.status != 200) {
			alert(obj.responseText);
		}
		var resp=obj.responseText;
		eval(resp);
	}
}
