function dropFile(btn){
	if(document.getElementById) {
		tr = btn;
		while (tr.tagName != 'TR') tr = tr.parentNode;
		tr.parentNode.removeChild(tr);
		checkForLast();
	}	
}
function addFile(btn){
	if(document.getElementById) {
		tr = btn;
		while (tr.tagName != 'TR') tr = tr.parentNode;
		var newTr = tr.parentNode.insertBefore(tr.cloneNode(true),tr.nextSibling);
		thisChilds = newTr.getElementsByTagName('td');
		for (var i = 0; i < thisChilds.length; i++){
			if (thisChilds[i].className == 'header') thisChilds[i].innerHTML = '';
		}
		checkForLast();
	}	
}
function checkForLast(){
	btns = document.getElementsByName('drop');
	for (i = 0; i < btns.length; i++){
		btns[i].disabled = (btns.length == 1) ? true : false;
	}
}
function preview_image(pic_src)
{
	if(pic_src.value != '')
	{
		viewer_obj = pic_src.nextSibling.nextSibling;
		if(viewer_obj.tagName == 'IMG')
		{
			viewer_obj.src = pic_src.value;
			viewer_obj.width = 100;
			viewer_obj.height = 100; 
		}
	}
}
function show_image(source, viewer){
  source_obj = document.getElementById(source);
  viewer_obj = document.getElementById(viewer);
  if(source_obj.value != '') { 
    viewer_obj.src = source_obj.value; 
    viewer_obj.width = 100; 
    viewer_obj.height = 100; 
  }
}
function select_all_checkboxs(checkboxs_name, form_id)
{
	var check_obj = document.getElementById(form_id).elements[checkboxs_name]
	if(check_obj)
	{
		if(typeof(check_obj.length) == 'undefined')
		{
			if(check_obj.checked) check_obj.checked = false
			else check_obj.checked = true
		}else
		{
			for(i=0;i<check_obj.length;i++)
			{
				if(check_obj[i].checked) check_obj[i].checked = false
				else check_obj[i].checked = true
			}
		}
	}
}

function mail_preview(mail_id)
{
	if(mail_id > 0)
	{
		window.open('mail_preview.php?mail_id=' + mail_id,'preview','resizable=yes,status=yes,toolbar=yes,location=yes,menu=yes,scrollbars=yes,width=800,height=500,top=5,left=5');	
	}else
	{
		document.getElementById('act1').value='preview';
		document.getElementById('mail_form').submit();
	}
}

function ie_insert_into_textarea(el_id, ins_str)
{
	textarr_obj = document.getElementById(el_id)
	textarr_obj.focus()
	var r=document.selection.createRange()
	r.text=ins_str+r.text
	r.select()
}
function MM_openBrWindow(theURL,winName,features)
{
	if(typeof(win_obj) == "undefined") win_obj = window.open(theURL,winName,features)
	else
	{
		try
		{
			win_obj.location.href = theURL
			win_obj.focus()
		}
		catch(e)
		{
			delete win_obj
			win_obj = window.open(theURL,winName,features)
		}
	}
}
function show_pics(club,event)
{
	MM_openBrWindow('show_party_pics.php?clid='+club+'&evid='+event,'show_pics','resizable=no,status=no,toolbar=no,location=no,menu=no,scrollbars=yes,width=810,height=820,top=10,left=50');
}
function show_big_pic(pic)
{
	MM_openBrWindow('show_big_pic.php?pic='+pic,'show_big_pic','resizable=yes,status=no,toolbar=no,location=no,menu=no,scrollbars=yes,width=400,height=400,top=5,left=100');
}

function copy_fields(source_id, destination_id)
{
	document.getElementById(destination_id).value = document.getElementById(source_id).value
}
function make_action(form_id, param_obj)
{
	for(i in param_obj) { document.getElementById(i).value=param_obj[i] }
	document.getElementById(form_id).submit()
}
function show_ip_range(selector_id, range_row_id)
{
	var sel_object = document.getElementById(selector_id);
	if(sel_object.options[sel_object.selectedIndex].value == 'direct') document.getElementById(range_row_id).style.display = 'block';
	else document.getElementById(range_row_id).style.display = 'none';
}
function preview(main_url)
{
	var message_object = document.getElementById("message_preview");
	var header_object = document.getElementById("header_preview");
	main_url = main_url + "?message_id=" + message_object.options[message_object.selectedIndex].value + "&header_id=" + header_object.options[header_object.selectedIndex].value
	MM_openBrWindow(main_url,"preview","resizable=yes,status=no,toolbar=no,location=no,menu=no,scrollbars=yes,width=800,height=500,top=5,left=5")
}
/*functions for insert text into textarea for mozila*/
function pnhGetSelectionStart(element) {
	var startpos = 0;
	startpos = element.selectionStart; // moz
	return startpos;
}

function pnhGetSelectionEnd(element) {
	var endpos = 0;
	endpos = element.selectionEnd; // moz
	return endpos;

}

function pnhSetSelectionStart(element,newposition) {
	element.selectionStart = newposition; // moz
}


function pnhSetSelectionEnd(element,newposition) {
	element.selectionEnd = newposition; // moz
}

function pnhSetSelection(element,newstart,newend) {
	pnhSetSelectionStart(element,newstart);
	pnhSetSelectionEnd(element,newend);
}


// Inserts a string at a given position
function pnhStringInsert(DOMEle,newtext,newpos) {
	DOMEle.value=DOMEle.value.slice(0,newpos)+newtext+DOMEle.value.slice(newpos);
}


function pnhEditTextarea(textarea_id, inserting_text) {
	// grab the textarea element off the dom tree
	var ta = document.getElementById(textarea_id);
	
	var firstPos = pnhGetSelectionStart(ta);
	pnhStringInsert(ta,inserting_text,firstPos);
	ta.focus();
	
	return false;
}
/*insert text into textarea for mozila*/
function update_statistics(params)
{
	if(typeof(params) == "object")
	{
		for(val in params)
		{
			var temp_obj = document.getElementById(val)
			if(val == 'progress_bar')
			{
				temp_obj.style.width = params[val] + 'px'
			} else
			{
				var temp_textnode = document.createTextNode(params[val])
				if(temp_obj.hasChildNodes()) temp_obj.removeChild(temp_obj.lastChild)
				temp_obj.appendChild(temp_textnode)
				if(val == 'mm_status') temp_obj.className = params[val]
			}
		}
	}
}

function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
} 
userAgent = window.navigator.userAgent;
browserVers = parseInt(userAgent.charAt(userAgent.indexOf("/")+1),10);
mustInitImg = true;
function findElement(n,ly) {
	var d = document;
	if (browserVers < 4)		return d[n];
	if ((browserVers >= 6) && (d.getElementById)) {initImgID; return(d.getElementById(n))}; 
	var cd = ly ? ly.document : d;
	var elem = cd[n];
	if (!elem) {
		for (var i=0;i<cd.layers.length;i++) {
			elem = findElement(n,cd.layers[i]);
			if (elem) return elem;
		}
	}
	return elem;
}
function changeImagesArray(array) {
	if (preloadFlag == true) {
		var d = document; var img;
		for (i=0;i<array.length;i+=2) {
			img = null; var n = array[i];
			if (d.images) {
				if (d.layers) {img = findElement(n,0);}
				else {img = d.images[n];}
			}
			if (!img && d.getElementById) {img = d.getElementById(n);}
			if (!img && d.getElementsByName) {
				var elms = d.getElementsByName(n);
				if (elms) {
					for (j=0;j<elms.length;j++) {
						if (elms[j].src) {img = elms[j]; break;}
					}
				}
			}
			if (img) {img.src = array[i+1];}
		}
	}
}
function changeImages() {
	changeImagesArray(changeImages.arguments);
} 
