var winId;	// reference to the popup window

// This function calls the popup window.
function popupInfo(action, formName, jsfAction, target, width, height, id) {

	features="height=" + height + ",width=" + width + ",status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes";			
	winId=window.open('',target,features);
	if (winId.window.focus) setTimeout('winId.focus()', 500);
	
	var hform = document.forms[formName]; // reference to the hidden form

	addField(formName,'hidden','popup','true');
			  				  
	// Copy to the corresponding field of the hidden form.
	hform[formName+":id"].value = id;
							  								  
	// This is an emulation of the action link being clicked.
	hform['autoScroll'].value=getScrolling();
	hform[formName+':_link_hidden_'].value=formName+':'+jsfAction;
	// Submit the hidden form. The output will be sent to the just opened window.
	hform.submit();
}

// This function calls the popup window.
function popupInfo2(formName, jsfAction, target, width, height) {

	features="height=" + height + ",width=" + width + ",status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes";			
	winId=window.open('',target,features);
	if (winId.window.focus) setTimeout('winId.focus()', 500);
	
	var hform = document.forms[formName]; // reference to the hidden form
			  				  							  								  
	addField(formName,'hidden','popup','true');

	// This is an emulation of the action link being clicked.
	hform['autoScroll'].value=getScrolling();
	hform[formName+':_link_hidden_'].value=formName+':'+jsfAction;
	// Submit the hidden form. The output will be sent to the just opened window.
	hform.submit();
}

// This function calls the popup window.
function popupInfo3(formName, jsfAction, target, width, height) {

	features="height=" + height + ",width=" + width + ",status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes";			
	winId=window.open('',target,features);
	if (winId.window.focus) setTimeout('winId.focus()', 500);
	
	var hform = document.forms[formName]; // reference to the hidden form
			  				  							  								  
	addField(formName,'hidden','popup','true');

	// This is an emulation of the action link being clicked.
	hform[formName+':_link_hidden_'].value=formName+':'+jsfAction;
	// Submit the hidden form. The output will be sent to the just opened window.
	hform.submit();
}  

function popupWin(url, target, width, height) {

	features="height=" + height + ",width=" + width + ",status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes";			
	winId=window.open(url,target,features);
	if (winId.window.focus) setTimeout('winId.focus()', 500);
}

// This function calls to submit form
function formSubmit(formName, jsfAction) {
	var hform = document.forms[formName]; // reference to the hidden form
			  				  							  								  
	// This is an emulation of the action link being clicked.
	hform['autoScroll'].value=getScrolling();
	hform[formName+':_link_hidden_'].value=formName+':'+jsfAction;
	// Submit the hidden form. The output will be sent to the just opened window.
	hform.submit();
}

function openerFormSubmit(formName, jsfAction) {
	var hform = opener.document.forms[formName]; // reference to the hidden form
			  				  							  								  
	// This is an emulation of the action link being clicked.
	hform[formName+':_link_hidden_'].value=formName+':'+jsfAction;
	// Submit the hidden form. The output will be sent to the just opened window.
	hform.submit();
}

function addField (formName, fieldType, fieldName, fieldValue) {
  var form = document.forms[formName];

  if (document.getElementById) {
    var input = document.createElement('INPUT');
      if (document.all) { // what follows should work 
                          // with NN6 but doesn't in M14
        input.type = fieldType;
        input.name = fieldName;
        input.value = fieldValue;
      }
      else if (document.getElementById) { // so here is the
                                          // NN6 workaround
        input.setAttribute('type', fieldType);
        input.setAttribute('name', fieldName);
        input.setAttribute('value', fieldValue);
      }
    form.appendChild(input);
  }
}

// This function submit a form
function submitForm(formName, jsfAction, id) {
	var hform = document.forms[formName]; // reference to the hidden form
	
	// Copy to the corresponding field of the hidden form.
	hform[formName+":id"].value = id;

	//configure jsf related fields
	hform['autoScroll'].value=getScrolling();
	hform[formName+':_link_hidden_'].value=formName+':'+jsfAction;
	// Submit the hidden form. The output will be sent to the just opened window.
	hform.submit();
}

