function openWin(pic,width,height) 
{
   vard = 'width='+width+',height='+height+',status=no,adress=no,menu=no,toolbar=no';
   picwin = open(pic,'',vard);
}

function openPickImage(form, field)
{
	win = open('pages/dialog.pick-image.php?form=' + form + '&field=' + field,'','width=400,height=400,scrollbars=yes');
}

function openPickCustomImage(dir, form, field)
{
	win = open('pages/dialog.pick-custom-image.php?dir=' + dir + '&form=' + form + '&field=' + field,'','width=400,height=400,scrollbars=yes');
}

function openDeleteImage()
{
	win = open('pages/dialog.delete-image.php', '', 'width=400,height=400,scrollbars=yes');
}

function openDeleteCustomImage(dir)
{
	win = open('pages/dialog.delete-custom-image.php?dir=' + dir, '', 'width=400,height=400,scrollbars=yes');
}

function openUpload() 
{
	win = open('pages/dialog.upload-file.php', '', 'width=450,height=650');
}

var target = null;

function getTarget(el) 
{
	target = (document.getElementById) ? document.getElementById(el) : 0;
}

function storeCursor(el) 
{
if (document.all && el.createTextRange) 
	el.cursorPos = document.selection.createRange().duplicate();
}

function validate(id_array)
{
	ret_array = new Array();
	for ( i = 0; i < id_array.length; i++ )
	{
		if ( document.forms[0].elements[id_array[i]].value == "" )
		{
			ret_array.push(id_array[i]);
		}
	}
	return ret_array;
}

function get_error_string(id_array)
{
	error = "The following error(s) occured.\n";
	for ( i = 0; i < id_array.length; i++ )
	{
		error += id_array[i] + " value is not valid.\n";
	}
	error += "Do you want to continue?";
	return error;
}

function submit_check(id)
{
	ret = validate(id);
	if ( ret.length > 0 )
	{
		if ( confirm(get_error_string(ret)) )
			document.forms[0].submit();
	}
	else
		document.forms[0].submit();
}

function putStr(text) 
{
	if (target) 
	{
		if (document.all && target.cursorPos) 
		{
			target.cursorPos.text = text;
		} 
		else 
		{
			if (target.selectionStart != undefined) 
			{
				var sStart = target.selectionStart;
				var sEnd = target.selectionEnd;
				target.value = target.value.substr(0, sStart) + text + target.value.substr(sEnd, target.value.length);
				target.selectionStart = (sStart == sEnd)? sStart + text.length:sStart;
				target.selectionEnd = sStart + text.length;
			}
			else 
			{
				target.focus();
				target.value += text;
			}
		}
		target.focus();
		storeCursor(target);
	}
}

