

function openTiddlyWindow(url,height,width)
        {
	       if (!height) {height=700;} 
               if (!width) {width=500};
               var strControls='height=' + height + ',width=' + width + ',scrollbars=1,resizable=1,menubar=0,toolbar0,status=0,location=0,directories=0,left=10,top=10'
               TiddlyWindow = window.open(url,'subWind',strControls);
				if (TiddlyWindow.opener == null) TiddlyWindow.opener = self;
        }


function popupform(myform, windowname)
{
	if (! window.focus)return true;
	NewWindow=window.open('', windowname, 'height=700,width=500,scrollbars=1,resizable=0,menubar=0,toolbar0,status=1,directories=0');
	if (NewWindow.opener == null) {	
		NewWindow.opener = self;
		return true;
	}
	myform.target=windowname;
	return true;
}



function SetExplodedDateTimeControlToNow(strFormName,strDummyDateTimePrefix,strFieldName) {

	var now=new Date();

	document[strFormName][strDummyDateTimePrefix  + "day-" +  strFieldName].value=now.getDate();
	document[strFormName][strDummyDateTimePrefix  + "month-" +  strFieldName].value=now.getMonth()+1;
	document[strFormName][strDummyDateTimePrefix  + "year-" +  strFieldName].value=GetYearFromDateObj(now);
	document[strFormName][strDummyDateTimePrefix  + "hour-" +  strFieldName].value=now.getHours();
	document[strFormName][strDummyDateTimePrefix  + "minute-" +  strFieldName].value=now.getMinutes();

	return true;

}

function GetYearFromDateObj(objDate)
{

	//Y2K Fix for these ***** browsers as Mozilla and IE support getYear in a different way...
	//http://www.quirksmode.org/js/introdate.html

	x = objDate.getYear();
	var y = x % 100;
	y += (y < 38) ? 2000 : 1900;
	return y;
}


function ForceNumericInput(objControl,e,strLocale,lngDecimalPlaces,strWarningColor){

	// Chris Barnes 2007: http://www.cdbuk.net
	// Currently only supports US/UK locale. ie
	// Depends on non inbuilt functions: GetKeyCode, strpos, GetCartePosition
	// Flashes red when user tries to enter invalid chars


	var lngComma=44;
	var lngPoint=46;
	var lngBackSpace=8;
	var lngCursorLeft=37;
	var lngCursorRight=39;
	var lngForwardSlash=47;
	var strResetColor;

	if (isUndefined(strLocale)){
		strLocale="US";
	}

	if (isUndefined(strWarningColor)){
		strWarningColor="#ff0000";
	}
	var lngColorResetTime=5;

	// There are sometimes problems accessing the "form" property of a control which makes this code unreliable
	// If this control and form are properly named, this string allows us to reset color of the control having fiddled !
	//if (!isUndefined(objControl.name) && !isUndefined(objControl.name)){
	//	strResetColor="document." + objControl.form.name + "." + objControl.name + ".style.background='" + objControl.style.background +"'";
	//}

	if (isUndefined(lngDecimalPlaces)){
		lngDecimalPlaces=2;
	}

	var keycode=GetKeyCode(e);


	
	if (keycode==lngBackSpace || keycode==lngCursorLeft || keycode==lngCursorRight || keycode==13 || keycode==9){
		return true;
	}

	if (keycode==191 || keycode==32){ // Forward Slash or space
		e.returnValue=false;
		return false;
	}

	var strEntered=String.fromCharCode(keycode);
	strEntered=strEntered.toString();

	// Load existing value in control
	var strText=objControl.value; //Note this is the value prior to update
	strText=strText.toString();
	var lngDescPos=strpos(strText, ".");


	if (keycode==lngPoint){
		// Disallow more than 1 decimal separator
		if (lngDescPos >0){
			//if (!isUndefined(strResetColor)){
			//	objControl.style.background=strWarningColor;
			//	setTimeout(strResetColor,lngColorResetTime);
			//}
			e.returnValue=false;
			return false;
		} else {
			return true;
		}

	}

	// Non numbers are disallowed (now we've handled punctuation)
	if (isNaN(strEntered)){

		if (!isUndefined(strResetColor)){
			objControl.style.background=strWarningColor;
			setTimeout(strResetColor,lngColorResetTime);
		}
		e.returnValue=false;
		return false;
	}


	// Get Decimal Place postion if available
	var lngPos=GetCaretPosition(objControl);

	if (lngDescPos > 0){

		// Allow insert of numbers before existing decimal point
		if (lngPos < lngDescPos){
			return TRUE;
		}

		var lngTextLength=strText.length;
		// Lock to allowed number of decimal places
		if (eval(lngTextLength)-eval(lngDescPos) > lngDecimalPlaces){
			if (!isUndefined(strResetColor)){
				objControl.style.background=strWarningColor;
				setTimeout(strResetColor,lngColorResetTime);
			}
			e.returnValue=false;
			return false;
		}

	}



	return true;

}


function js_textctrl_minute_timer(strControlID){

	//Chris Barnes 2008
	// If you want to be able to stop the clock, 
	// ensure your text control has the following: onclick="this.boolStopClock=!this.boolStopClock;"

	var text_control = document.getElementById(strControlID);
	var dblMinutes;

	if (!text_control.boolStopClock){

		if (!text_control.value){
			dblMinutes=0;
		} else {
			dblMinutes=text_control.value;
		}
		dblMinutes= parseFloat(dblMinutes) + 0.01
		dblMinutes=dblMinutes.toFixed(2);
		intMinutes=parseInt(dblMinutes);

		if (parseFloat(dblMinutes - intMinutes) > 0.59){
			dblMinutes=intMinutes + 1;
			dblMinutes=dblMinutes.toFixed(2);
		}

		text_control.value = dblMinutes;
		text_control.style.background="";
		text_control.style.color="";

	} else {
		text_control.style.background="#aaaaaa;";
		text_control.style.color="#ffffff;";
	}


	setTimeout("js_textctrl_minute_timer(" + "'" + strControlID + "'" + ")", 1000);
}

