// paging form negotiation
function getpage()
{
	var pm = getpage.arguments[0];
	var so = getpage.arguments[1];
	var sd = getpage.arguments[2];

	window.document.frmGetView.pm.value=pm;
	window.document.frmGetView.so.value=so;
	window.document.frmGetView.sd.value=sd;

	window.document.frmGetView.submit();
}

// basic div text change function
function SetINNERhtml(o, h)
{
	MM_findObj(o,document).innerHTML=h;
}

// cross browser hide and seek
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

// image functions
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

var retCTRL;

function getCTRLval()
{
	return (MM_findObj(retCTRL, '').value);
}

function getEDITCTRLval()
{
	var t = MM_findObj(retCTRL.name, '').value;
	if (t.value=='')
	{
		t='insert your text <b>here</b>';
	}
	return (t);
}

function HTML_preview()
{
	var dumm;
	var win1;
	var ctlHTML = HTML_preview.arguments[0];
	
	retCTRL = ctlHTML.name;

//	alert(ctlHTML.value);



// METHOD 1 :: MARK

	win1 = window.open('/stairs/DHTMLed/preview.asp', 'preview')
	
//	alert('b4 event?');
//	win1.onload="alert('yippee!');win1.document.all.divPreview.innerHTML=ctlHTML.value;"

//	win1.document.all.divPreview.innerHTML=ctlHTML.value;
//	win1.document.all.frmNavBack.retTarget.value=ctlHTML.name;



// METHOD 2 : MICROSOFT

//	showModalDialog('/stairs/DHTMLed/preview2.asp', ctlHTML.value );

	return false;
}

function HTML_edit()
{
	var win1;
	var ctlHTML = HTML_edit.arguments[0];

	retCTRL = ctlHTML.name;
	
//	alert(ctlHTML.name);
	
	win1 = window.open('/stairs/DHTMLed/dhtmlEdit.asp', 'edit')

//	if (ctlHTML.value=='')
//	{
//		win1.document.all.tbContentElement.DocumentHTML='insert your text <b>here</b>';
//	}
//	else
//	{
//		win1.document.all.tbContentElement.DocumentHTML=ctlHTML.value;
//	}

//	win1.document.all.frmNavBack.retTarget.value=ctlHTML.name;

	retCTRL = ctlHTML;

	return false;
}


function returnHTML()
{

	var ctlName = returnHTML.arguments[0];
	var ctlHTML = returnHTML.arguments[1];
	var iPos = ctlHTML.indexOf('<BODY>');

//	alert(ctlName);
//	alert(ctlHTML);
//	alert(iPos);

	if (iPos>0)
	{
//		alert('clipping');
		ctlHTML = ctlHTML.substring(iPos+6, ctlHTML.length-16);
	}

	retCTRL.value=ctlHTML;

}

function clearF(F)
{
	var i, e;
//	alert(F.name);
	for (i=0;i<F.elements.length;i++)
	{
		e = F.elements[i];
//		alert(e.name);
		switch (e.type) 
		{

			case "select-list" :
				e.selectedIndex=0;
				break;

			case "textbox" :
				e.value='';
				break;
				
			case "checkbox" :
				e.checked=false;
				break;
					
		}
	}
}

function validateF(F)
{
	var bRet, bVal, sFalses;
	bRet = true;
	sFalses = '';
//	alert(F.name);
//	F = window.document.frmForm;
	var i, e, n, di;
	for (i=0;i<F.elements.length;i++)
	{
		e = F.elements[i];
		n = e.name;
//		alert(n);
		if ((n.length>3) && (n.charAt(3)=='0'))
		{
			// control is labelled as required.
			// check control type [by naming convention]
			switch (n.substr(0, 2)) 
			{
				case "fm" :			// form variable (probably hidden)
					// ignore
					break;
				case "fx" :			// fixed
					// ignore
					break;
				case "hd" :			// hidden
					// ignore
					break;
				case "do" :			// display only
					// ignore
					break;

				case "op" :			// option (radio button)
	// *** need to iterate all items to ensure one is selected here...
//					di = MM_findObj('div'+n);
//					bVal = ((e.value!='') && (e.value!='0'));
//					if (bVal==false) {sFalses+=e.name;}
////					alert ('name:' + e.name + '\nvalue:' + e.value + '\nbVal:' + bVal + '\n' + 'okay?');
//					setValidationColour (di, bVal);
					break;

				case "cb" :			// combo box (drop down)
					di = MM_findObj('div'+n);
					bVal = ((e.value!='') && (e.value!='0'));
					if (bVal==false) {sFalses+=e.name;}
//					alert ('name:' + e.name + '\nvalue:' + e.value + '\nbVal:' + bVal + '\n' + 'okay?');
					setValidationColour (di, bVal);
					break;

				default : // tx, ta
					di = MM_findObj('div'+n);
					bVal = (e.value!='');
					if (bVal==false) {sFalses+=e.name;}
//					alert ('name:' + e.name + '\nvalue:' + e.value + '\nbVal:' + bVal + '\n' + 'okay?');
					setValidationColour (di, bVal);
					break;
			}
		}
		if (bVal==false) {bRet=false}
	}
	if (bRet==false)
	{
//		alert(sFalses);
		alert('please fill out the required fields\nthank you');
	}
	return (bRet);
}

function validateF_trunc(F)
{
	var bRet, bVal, sFalses;
	bRet = true;
	sFalses = '';
//	alert(F.name);
//	F = window.document.frmForm;
	var i, e, n, di, din;
	for (i=0;i<F.elements.length;i++)
	{
		e = F.elements[i];
		n = e.name;
//		alert(n);
		// control is labelled as required.
		// check control type [by naming convention]
//		alert(n+'\n'+e.type) ;
		switch (e.type)
		{
			case "hidden" :			// hidden
				// ignore
				break;

			case "button" :			// regular button
				// ignore
				break;

			case "submit" :			// submit button
				// ignore
				break;

			case "checkbox" :		// checkbox - nullable? doubt it!
				// ignore
				break;

			case "radio" :			// option (radio button)
// *** need to iterate all items to ensure one is selected here...
//					di = MM_findObj('div'+n);
//					bVal = ((e.value!='') && (e.value!='0'));
//					if (bVal==false) {sFalses+=e.name;}
////					alert ('name:' + e.name + '\nvalue:' + e.value + '\nbVal:' + bVal + '\n' + 'okay?');
//					setValidationColour (di, bVal);
				break;

			case "select-one" :			// combo box (drop down)
				di = MM_findObj('div'+n);
				din = di.name;
				if (din.charAt(6)=='0')
				{
//					alert(din+' is NOT nullable');
					bVal = ((e.value!='') && (e.value!='0'));
					if (bVal==false)
					{
						sFalses+=e.name;
//						alert('Empty NOT Null Field!!!'+n);
					}
//					alert ('name:' + e.name + '\nvalue:' + e.value + '\nbVal:' + bVal + '\n' + 'okay?');
					setValidationColour (di, bVal);
				}
				break;

			default : // text
				di = MM_findObj('div'+n);
				din = di.name;
				if (din.charAt(6)=='0')
				{
//					alert(din+' is NOT nullable');
					bVal = (e.value!='');
					if (bVal==false)
					{
						sFalses+=e.name;
//						alert('Empty NOT Null Field!!!'+n);
					}
//					alert ('name:' + e.name + '\nvalue:' + e.value + '\nbVal:' + bVal + '\n' + 'okay?');
					setValidationColour (di, bVal);
				}
				break;
		}
		if (bVal==false) {bRet=false}
	}
	if (bRet==false)
	{
//		alert(sFalses);
		alert('please fill out the required fields\nthank you');
	}
	return (bRet);
}


function setValidationColour(oDiv, bSet)
{

if (oDiv!=null)
{
	if (bSet==false)
	{
		if ((oDiv.style) && (oDiv.style.backgroundColor!=null)) 
		{
			oDiv.style.backgroundColor='firebrick';
			oDiv.style.color='#ffffff';
		}
	}
	else
	{
	//	alert('i am here');
		if ((oDiv.style) && (oDiv.style.backgroundColor!=null)) 
		{
			oDiv.style.backgroundColor=oDiv.parentNode.style.backgroundColor; // '#ffffff';
			oDiv.style.color=oDiv.parentNode.style.color;
		}
	}					
}

return true;

}
