function explode(delimiter, str)
{
	return str.split(delimiter);
}

function filename_to_desc(str)
{
	var bits		= explode(".", str);
	var filename	= trim(bits[0]);
	filename		= filename.replace(/_/g, " ");
	
	return filename;
}

function filename_to_desc_ie6(str)
{
	var path		= explode("\\", str);
	var path_count	= path.length;
	
	var fullfile	= path[path_count-1];
	
	var bits		= explode(".", fullfile);
	var filename	= trim(bits[0]);
	filename		= filename.replace(/_/g, " ");
	
	return filename;
}

function switch_this(obj)
{
		obj.disabled =! (obj.disabled);
}

function popup(uri, width, height)
{
	if(popup)
	{
		if(!popup.closed) popup.close();
	}
	
	var left	= (screen.width/2) - width/2;
	var top		= (screen.height/2) - height/2;
	var params	= 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=no,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	var popup	= open(uri,"popup", params);
}

function crop_popup(uri, width, height)
{
	if(crop_popup)
	{
		if(!crop_popup.closed) crop_popup.close();
	}
	
	var left	= (screen.width/2) - width/2;
	var top		= (screen.height/2) - height/2;
	var params	= 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbar=yes,resizable=yes,copyhistory=yes,width='+width+',height='+height+',left='+left+',top='+top+',screenX='+left+',screenY='+top;
	var crop_popup	= open(uri,"crop_popup", params);
}

function trim(str)
{
	return str.replace(/^\s*|\s*$/g,"");
}

function copy_id_to_name(from, to)
{
	if(to.value == "")
	{
		from = trim(from);
		from = from.replace(/ov_/g, ""); // remove ov_
		from = from.replace(/_/g, " "); // remove _
		
		to.value = from;
	}
}

function copy_input_text(from, to)
{
	if(to.value == "")
	{
		from = trim(from);
		
		to.value = from;
	}
}

function generate_keywords(str, to)
{
	if(to.value == "")
	{
		str = trim(str);
		
		to.value = str.split(" ");
	}
}

function generate_php_code(x)
{
	var ov_id		= document.getElementById("ov_id_"+x);
	var ov_name		= document.getElementById("ov_name_"+x);
	var php_click	= document.getElementById("php_click_"+x);
	var php_code	= document.getElementById("php_code_"+x);
	
	if(trim(ov_id.value) == "")
	{
		alert("you must enter an id before generating the code");
		
		ov_id.select();
	}
	else
	{
		var prefix = "";
		
		ov_id.value = trim(ov_id.value);
		
		if(ov_id.value.indexOf("$",0) != 0)
		{
			prefix = "$";
		}
		
		php_code.value				= "<?php echo "+prefix+ov_id.value+"; // "+ov_name.value+" ?>";
		php_code.style.display		= "block";
		php_click.style.display		= "none";
		
		php_code.select();
	}
}
