/**
* JavaScript Lib for helping the catalogues in the Chairman Enterprise Application Suite
* @copy Mayflower GmbH 2005-2006
* @author Gregor Streng <streng@mayflower.de>
* @version $Id: catalogue_edit.js,v 1.2 2006/01/17 16:01:28 gregor Exp $
*/


/**
* Retrieve a value by a prompt and submit a form
*
* @param fieldname string the name of the field
* @param formname string the name of the form
*
* @return mixed string or false
*/
function getValueAndSubmit(fieldname, formname, text) {
	var field = document.getElementById(fieldname);
	var form = document.getElementById(formname);
	if(field && form) {
		var name=prompt(text, field.value);
		if(name=='' || name==null) return false;
	} else {
		return alert('Could not find form or field object');
	}
	field.value=name;
	form.submit();
	return true;
}

/**
* Show a Confirm Dialog and redirect to a url
*
* @param string text The Text to be confirmed
* @param string url the url to be redirected to
*
* @return bool;
*/
function checkAndSubmit(text, url) {
		if (confirm(text)) {
			window.top.location=url;
			return true;
		}
		return false;
}

/**
* Check if the Input Form for proposals is completely filled out
*
* @param string the name of the Form
*
* @return bool
*/
function checkNewItem(formname) {
	var mytitle=document.getElementById('newtitle');
	var mypath=document.getElementById('newpath');
	var myurl=document.getElementById('newurl');
	if(mytitle && mypath && myurl) {
		if(mytitle.value=='' && (mypath.value=='' || myurl.value=='')) {
			alert('Please enter a Title and Url or file');
			return false;
		}
		return true;
	}
	return false;
}



/**
* Shows or hides a object
*
* @param string objectname the id of the object
*
* @return bool
*/
function showHideObject(objectname) {
    var obj=document.getElementById(objectname);
	if(!obj || !obj.style) return false;
	var v=obj.style.visibility; 
	v=(v=='visible')? 'hidden': 'visible'; 
    obj.style.visibility=v;
	return true;	
}

/**
* Sets the name and value of the ParentCat to the hidden inputfields
* in the parentWindow
*
* @param int id the id of the parentCat
* @param string name the name of the parent cat
*
* @return bool
*/
function setSelectedCat(id, name) {
	var idobj = parent.document.getElementById('parentid');
	var nameobj = parent.document.getElementById('parentname');
	if(idobj && nameobj) {
		idobj.value=id;
		nameobj.value=name;
		return true;
	}
	return false;
}
