var isNS4 = (navigator.appName=="Netscape")?1:0;

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function BodyOnLoad(elementno)
{
	if (document.forms[0].elements[elementno]) {
		document.forms[0].elements[elementno].focus();
		document.forms[0].elements[elementno].select();
	}
}

function StatusChange(action,recordid,name,newurl){

	document.forms[0].f_action.value = action;
	document.forms[0].f_recordid.value = recordid;
	document.forms[0].f_newurl.value = newurl;

	if (action == 'activate') {
		agree = confirm('Are you sure you want to activate this '+name+'?');
		if (agree) {
			document.forms[0].submit();
		}
	}
	if (action == 'deactivate') {
		agree = confirm('Are you sure you want to deactivate this '+name+'?');
		if (agree) {
			document.forms[0].submit();
		}
	}
	if (action == 'delete') {
		agree = confirm('Deleting is permanent. You will not be able to retrieve the data stored after deleting. \nAre you sure you want to delete this '+name+'?');
		if (agree) {
			document.forms[0].submit();
		}
	}
	if (action == 'delete_category') {
		agree = confirm('Deleting is permanent. All sub-categories will be deleted as well and you will not be able to retrieve the data stored after deleting. \nAre you sure you want to delete this '+name+'?');
		if (agree) {
			document.forms[0].submit();
		}
	}
	if (action == 'delete_folder') {
		agree = confirm('Deleting is permanent. All folder contents will be deleted as well and you will not be able to retrieve the data stored after deleting. \nAre you sure you want to delete this '+name+'?');
		if (agree) {
			document.forms[0].submit();
		}
	}
	if (action == 'delete_preview') {
		agree = confirm('Deleting is permanent. You will not be able to retrieve the data stored after deleting. \nAre you sure you want to delete this '+name+'?');
		if (agree) {
			document.forms[0].submit();
		}
	}
	if (action == 'delete_product') {
		agree = confirm('Deleting is permanent. You will not be able to retrieve the data stored after deleting. \nAre you sure you want to delete this '+name+'?');
		if (agree) {
			document.forms[0].submit();
		}
	}
	if (action == 'delete_final') {
		agree = confirm('Deleting is permanent. You will not be able to retrieve the data stored after deleting. \nAre you sure you want to delete this '+name+'?');
		if (agree) {
			document.forms[0].submit();
		}
	}
	if (action == 'urlredirect') {
			document.forms[0].submit();
	}
	if (action == 'orgchange') {
			document.forms[0].f_cfnewurl.value = document.forms[0].f_template_option_list.options[document.forms[0].f_template_option_list.selectedIndex].value
			document.forms[0].submit();
	}
	if (action == 'filter') {
			document.forms[0].submit();
	}
	if (action == 'publish') {
		agree = confirm('Are you sure you want to publish this '+name+'?');
		if (agree) {
			document.forms[0].submit();
		}
	}
	if (action == 'invoice') {
		agree = confirm('Are you sure you want change the status of this '+name+' to \''+newurl+'\'?');
		if (agree) {
			document.forms[0].submit();
		}
	}
}

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
		field.value = field.value.substring(0, maxlimit);
		// otherwise, update 'characters left' counter
	else 
		countfield.value = maxlimit - field.value.length;
}

function getSelectedRadio(buttonGroup) {
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
	  for (var i=0; i<buttonGroup.length; i++) {
		 if (buttonGroup[i].checked) {
			return i
		 }
	  }
   } else {
	  if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function dropdown_nav(formno, elementno) {
	var URL = document.forms[formno].elements[elementno].options[document.forms[formno].elements[elementno].selectedIndex].value;
	window.location.href = URL;
}