//*** MODAL DIALOG
//*** pop modal dialog ***
/* This function opens a modal dialog. The following must be specified inside the onclick and onkeypress events that activates the function:

onclick="popDialog(['dUrl'],[dWidth],[dHeight],['dFunc']); return false;"
onkeypress="popDialog(['dUrl'],[dWidth],[dHeight],['dFunc']); return false;"

dUrl: 		Dialog url. String that specifies the URL of the document to load and display.
dWidth: 	Dialog width. Sets the dialog width in pixels.
dHeight: 	Dialog height. Sets the dialog height in pixels.
dFunc: 		Dialog function. Sets the function that retrieves the dialog arguments. Values: ['function name'],[false]. 
			If dFunc is set to false no values vill be passed from the dialog.

For retrieving values from the dialog copy, rename and modify the templateFunction_returnDialogValues(), templateFunction_getDialogReturnValues() below to fit your needs. */

function popDialog(dUrl,dWidth,dHeight,dFunc) {
	//pop dialog
	
	dialogReturns = window.showModalDialog(dUrl,"",'dialogHeight: ' + dHeight + 'px; dialogWidth: ' + dWidth + 'px; dialogTop: px; dialogLeft: px; edge: Raised; center: Yes; help: No; resizable: No; status: Off; scroll: No;');
	//run dialog function if dFunc is not set to false and if dialog returns values
	if (dialogReturns != null && dFunc != false) {
		var run = eval(dFunc + '()');
		run;
	}
	//else end function
	else {
		return false;
	}
}

function popDialog2(dUrl,dWidth,dHeight,dFunc) {
	//pop dialog
	
	dialogReturns = window.showModalDialog(dUrl,"",'dialogHeight: ' + dHeight + 'px; dialogWidth: ' + dWidth + 'px; dialogTop: px; dialogLeft: px; edge: Raised; center: Yes; help: No; resizable: No; status: Off; scroll: No;');
	//run dialog function if dFunc is not set to false and if dialog returns values
	if (dialogReturns != null && dFunc != false) {
		
		dialogReturns = "('" + dialogReturns + "')";
		var run = eval(dFunc + dialogReturns);
		run;
	}
	//else end function
	else {
		return false;
	}
}


//*** template function for returning dialog values ***
/* This is a template function for retrieving values from a modal dialog opened by popDialog(). This function should be placed in the 
document that is displayed inside the dialog.

The returnValue can be either strings, numbers or objects (such as arrays) */

function templateFunction_returnDialogValues() {
	//set return value
	returnValue = 'return value is a string';
	//close the dialog
	self.close();
}

//*** template function for retrieving dialog values ***
/* This is a template function for retrieving values from a modal dialog opened by popDialog(). The name of this function must be specified inside the onclick and onkeypress events that activates the popDialog() function like this:

onclick="popDialog(['dialog url'],[dialog width],[dialog height],['function name']); return false;"
onkeypress="popDialog(['dialog url'],[dialog width],[dialog height],['function name']); return false;"

dialogReturns contains the value/s passed by the modal dialog. These can be either strings, numbers or objects (such as arrays). */

function templateFunction_getDialogReturnValues() {
	//your functionality goes here:
	alert(dialogReturns);
}
//*** /MODAL DIALOG

//*** RELOAD CURRENT PAGE
//Reload this page when dialog closes
function pageReload() {
	location.reload();
}
//Reload this page when dialog closes
function pageReload2(url) {
	
	if(url == 'reload'){
		location.reload();
	}
	else if(url == ''){
	}
	else{
		window.open(url,'_self');
	}
	
	
}
//*** /RELOAD CURRENT PAGE

//*** DIALOG SCRIPTS */
//close dialog
function closeDialog() {
	returnValue = 'reload';
	self.close();
}
//initalize dialog
oDialog = this;
function initDialog() {
	oDialog.dialogHeight = document.all['dialogLastItem'].offsetTop + 87 + 'px';
	getDisabled();
}
//*** /DIALOG SCRIPTS */

//*** TABS
//Auto click tab link when clicking tab container
function clickTabLink() {
if  ( event.srcElement.tagName == 'TD') {
 event.srcElement.getElementsByTagName('A')[0].click();
}

}
//*** /TABS

//*** FORM ELEMENTS
//Checkbox field toggle
function toggleField(sFieldId) {
	if (event.srcElement.checked) {
		document.all[sFieldId].disabled = true;
		if (document.all[sFieldId].parentElement.className == 'block' ||document.all[sFieldId].parentElement.className == 'inline') {
			var cDivImages = document.all[sFieldId].parentElement.getElementsByTagName('IMG');
			if (cDivImages[0].src.indexOf('-on') != '-1') {
					cDivImages[0].src = cDivImages[0].src.substr(0,cDivImages[0].src.length-7) + '-off.gif';
			}
		}
	}
	else {
		document.all[sFieldId].disabled = false;
		if (document.all[sFieldId].parentElement.className == 'block' ||document.all[sFieldId].parentElement.className == 'inline') {
			var cDivImages = document.all[sFieldId].parentElement.getElementsByTagName('IMG');
			if (cDivImages[0].src.indexOf('-off') != '-1') {
					cDivImages[0].src = cDivImages[0].src.substr(0,cDivImages[0].src.length-8) + '-on.gif';
			}
		}
	}
	getDisabled();
}
//*** /FORM ELEMENTS

//*** SET APPEARANCE FOR DISABLED FIELDS
//set background color for disabled form elements
function getDisabled() {
	for (var i=0;i<document.forms[0].elements.length;i++) {
		//set runtimeStyle for disabled
		if (document.forms[0].elements[i].disabled) {
			//input type text
			if (document.forms[0].elements[i].type != 'checkbox' && document.forms[0].elements[i].type != 'radio' && document.forms[0].elements[i].type != 'textarea') {
				document.forms[0].elements[i].runtimeStyle.cssText = 'border: solid 1px #cccccc; background-color: #ededed; padding: 2px;';
			}
			//textarea
			if (document.forms[0].elements[i].type == 'textarea') {
				document.forms[0].elements[i].runtimeStyle.cssText = 'border: solid 2px #cccccc; background-color: #ededed; padding: 2px;';
			}
		}
		//remove any runtimeStyle for enabled
		else {
			document.forms[0].elements[i].runtimeStyle.cssText = '';
		}
	}
}
//*** /SET APPEARANCE FOR DISABLED FIELDS

