// Start of Locale Formatting
var globaloriginalvalue ="";
var globaleventvalue = "";
function getEventValue(value){
if (value != "" ) {
globaleventvalue = value;
}else {
globaleventvalue ="";
}
}
function getOrignalFieldValue(theField){
if ( theField.value != "" ) {
globaloriginalvalue = theField.value;
}else {
globaloriginalvalue ="";
}
}
function isValueContainsValidSeparator(numberValue,fractiondigits,eventName){
var fieldId = numberValue.id;
var value = numberValue.value;
var isValid = false;
var decimalseparator = ".";
var groupingseparator = "," ;
var countdecimalseparatorvalues = value.toString().match(new RegExp(escapeRegExp(decimalseparator),'g'));
var countdecimalseparator = (null == countdecimalseparatorvalues)?0:countdecimalseparatorvalues.length;
var countgroupingseparatorvalues = value.toString().match(new RegExp(escapeRegExp(groupingseparator),'g'));
var countgroupingseparator = (null == countgroupingseparatorvalues)?0:countgroupingseparatorvalues.length;
var countotherthansepartorvalues = value.toString().match(new RegExp("[^"+ escapeRegExp(decimalseparator)+escapeRegExp(groupingseparator)+"\\d"+"]",'g'));
var countotherthansepartor = (null == countotherthansepartorvalues)?0:countotherthansepartorvalues.length;
if(value.length == 1 && eventName == "blur"){
isValid = isBlurSingleCharacterDigit(numberValue,fractiondigits);
}else if(countdecimalseparator > 1 || countdecimalseparator >=1 && fractiondigits == 0 ){
alert("Error: Invalid Number Format , Please check the format entered; Ex. - " + exampleFromatting(fractiondigits));
handleInvalidValue(numberValue);
}else if(countotherthansepartor >= 1){
alert("Error: Invalid Number Format , Please check the format entered; Ex. - " + exampleFromatting(fractiondigits));
handleInvalidValue(numberValue);
}else{
document.getElementById(fieldId).value = value;
isValid = true;
}
return isValid;
}
function isValueContainsValidSeparatorCommonGlobal(numberValue,fractiondigits,eventName){
var fieldId = numberValue.id;
var value = numberValue.value;
var isValid = false;
var decimalseparator = ".";
var groupingseparator = "," ;
var countdecimalseparatorvalues = value.toString().match(new RegExp(escapeRegExp(decimalseparator),'g'));
var countdecimalseparator = (null == countdecimalseparatorvalues)?0:countdecimalseparatorvalues.length;
var countgroupingseparatorvalues = value.toString().match(new RegExp(escapeRegExp(groupingseparator),'g'));
var countgroupingseparator = (null == countgroupingseparatorvalues)?0:countgroupingseparatorvalues.length;
var countotherthansepartorvalues = value.toString().match(new RegExp("[^"+ escapeRegExp(decimalseparator)+escapeRegExp(groupingseparator)+"\\d"+"]",'g'));
var countotherthansepartor = (null == countotherthansepartorvalues)?0:countotherthansepartorvalues.length;
if(value.length == 1 && eventName == "blur"){
isValid = isBlurSingleCharacterDigitCommon(numberValue,fractiondigits);
}else if(countdecimalseparator > 1 || countdecimalseparator >=1 && fractiondigits == 0 ){
alert("Error: Invalid Number Format , Please check the format entered; Ex. -" + exampleFromatting(fractiondigits));
handleNonGlobalInvalidValue(numberValue);
}else if(countotherthansepartor >= 1){
alert("Error: Invalid Number Format , Please check the format entered; Ex. -" + exampleFromatting(fractiondigits));
handleNonGlobalInvalidValue(numberValue);
}else{
document.getElementById(fieldId).value = value;
isValid = true;
}
return isValid;
}
function isBlurSingleCharacterDigit(numberValue,fractiondigits){
isValid = false;
var value = numberValue.value;
var countotherthandigitvalues = value.toString().match(new RegExp("[^"+"\\d"+"]",'g'));
var countotherthandigit = (null == countotherthandigitvalues)?0:countotherthandigitvalues.length;
if(countotherthandigit > 0){
alert("Error: Invalid Number Format , Please check the format entered; Ex. - " + exampleFromatting(fractiondigits));
handleInvalidValue(numberValue);
}else{
isValid = true;
}
return isValid;
}
function isBlurSingleCharacterDigitCommon(numberValue,fractiondigits){
isValid = false;
var value = numberValue.value;
var countotherthandigitvalues = value.toString().match(new RegExp("[^"+"\\d"+"]",'g'));
var countotherthandigit = (null == countotherthandigitvalues)?0:countotherthandigitvalues.length;
if(countotherthandigit > 0){
alert("Error: Invalid Number Format , Please check the format entered; Ex. - " + exampleFromatting(fractiondigits));
handleNonGlobalInvalidValue(numberValue);
}else{
isValid = true;
}
return isValid;
}
function exampleFromatting(fractiondigits){
var value = null;
if(fractiondigits == 0){
value = "1,000";
}else if(fractiondigits == 1){
value = "1,000.0";
}else if(fractiondigits == 2){
value = "1,000.00";
}else if(fractiondigits == 3){
value = "1,000.000";
}else if(fractiondigits == 4){
value = "1,000.0000";
}else{
formatNumberToLocaleFormat(1000,fractiondigits);
}
return value;
}
function handleInvalidValue(theField){
document.getElementById( theField.id ).value = global;
window.setTimeout( "document.getElementById(\"" + theField.id + "\").focus();" , 10 );
window.setTimeout( "document.getElementById(\"" + theField.id + "\").select();" , 10 );
return;
}
function handleNonGlobalInvalidValue(theField){
document.getElementById( theField.id ).value = globaloriginalvalue;
window.setTimeout( "document.getElementById(\"" + theField.id + "\").focus();" , 10 );
window.setTimeout( "document.getElementById(\"" + theField.id + "\").select();" , 10 );
return;
}
function isThereValidSeparator(value){
var isValid = false;
if((typeof value === 'undefined') || (null == value)){
isValid = false;
}else{
var decimalseparator = ".";
var groupingseparator = "," ;
var countdecimalseparatorvalues = value.toString().match(new RegExp(escapeRegExp(decimalseparator),'g'));
var countdecimalseparator = (null == countdecimalseparatorvalues)?0:countdecimalseparatorvalues.length;
var countgroupingseparatorvalues = value.toString().match(new RegExp(escapeRegExp(groupingseparator),'g'));
var countgroupingseparator = (null == countgroupingseparatorvalues)?0:countgroupingseparatorvalues.length;
var countotherthansepartorvalues = value.toString().match(new RegExp("[^"+ escapeRegExp(decimalseparator)+escapeRegExp(groupingseparator)+"\\d"+"]",'g'));
var countotherthansepartor = (null == countotherthansepartorvalues)?0:countotherthansepartorvalues.length;
if(value.length == 1){
var countotherthandigitvalues = value.toString().match(new RegExp("[^"+"\\d"+"]",'g'));
var countotherthandigit = (null == countotherthandigitvalues)?0:countotherthandigitvalues.length;
isValid = (countotherthandigit > 0)?false:true;
}else if(countdecimalseparator > 1 ){
isValid = false;
}else if(countotherthansepartor >= 1){
isValid = false;
}else{
isValid = true;
}
}
return isValid;
}
function isThereInValidSeparator(value){
return (isThereValidSeparator(value))?false:true;
}
function isValuePositiveSingleDecimalOnly(value){
var isValid = false;
var decimalseparator = ".";
var countdecimalseparatorvalues = value.toString().match(new RegExp(escapeRegExp(decimalseparator),'g'));
var countdecimalseparator = (null == countdecimalseparatorvalues)?0:countdecimalseparatorvalues.length;
var countotherthansepartorvalues = value.toString().match(new RegExp("[^"+ escapeRegExp(decimalseparator)+"\\d"+"]",'g'));
var countotherthansepartor = (null == countotherthansepartorvalues)?0:countotherthansepartorvalues.length;
if(countdecimalseparator > 1 ){
alert('Invalid Locale Value');
}else if(countotherthansepartor >= 1){
alert('Invalid Number');
}else{
isValid = true;
}
return isValid;
}
function formatNumberToLocaleFormat(value, fractiondigits){
if(isValuePositiveSingleDecimalOnly(value)){
localeformattedValue = jsformatValueLocaleFormat(value,fractiondigits,1);
return (isThereValidSeparator(localeformattedValue))? localeformattedValue : getValueLocaleFormat(value,fractiondigits);
}else{
alert('Invalid Number');
return;
}
}
function formatNumberToLocaleFormatStandalone(value, fractiondigits){
if(isValuePositiveSingleDecimalOnly(value)){
localeformattedValue = jsformatValueLocaleFormat(value,fractiondigits,1);
return (isThereValidSeparator(localeformattedValue))? localeformattedValue : getValueLocaleFormatStandalone(value,fractiondigits);
}else{
alert('Invalid Number');
return;
}
}
function jsformatValueLocaleFormat(numberValue,fractiondigitsrequired,minimumintegerdigits){
var value = parseFloat(Math.round(numberValue*Math.pow(10,fractiondigitsrequired))/Math.pow(10,fractiondigitsrequired));
var digitssplitter = null;
var fractiondigits = 0;
var numberdigits = 0;
var groupednumberdigits= null;
var formattedfractiondigits = null;
var localeformatvalue = null;
// get values
var pattern = "#,##0.00";
var decimalseparator = ".";
var groupingseparator = "," ;
var regulardecimalseparator = ".";
// calculate the grouping interval
var patternsplitter = pattern.split(decimalseparator);
var lastgroupingseparatorinterval = patternsplitter[0].substring(patternsplitter[0].lastIndexOf(groupingseparator) + 1).length;
// split by regulardecimalseparator
digitssplitter = value.toString().split(regulardecimalseparator);
numberdigits = digitssplitter[0];
// determine fractiondigits
if(fractiondigitsrequired == 0){
fractiondigits =null;
numberdigits= value;
}else{
fractiondigits = (digitssplitter[1]== null)?concatenatedzerosbylength(fractiondigitsrequired):digitssplitter[1];
}
// formatthefractiondigits
if((null == fractiondigits) || (fractiondigits.length == fractiondigitsrequired)){
formattedfractiondigits = fractiondigits;
}else if(fractiondigits.length < fractiondigitsrequired){
formattedfractiondigits = fractiondigits.concat(concatenatedzerosbylength(fractiondigitsrequired - fractiondigits.length));
}
// inserting the grouping digits
if(numberdigits.length > lastgroupingseparatorinterval){
var numberdigitsarray = numberdigits.match(/\d/gi);
numberdigitsarray = insertgroupingseparator(numberdigitsarray,lastgroupingseparatorinterval,groupingseparator);
groupednumberdigits = numberdigitsarray.join("");
}else if(numberdigits.length == lastgroupingseparatorinterval){
groupednumberdigits = numberdigits;
}else if(numberdigits.length < minimumintegerdigits){
groupednumberdigits = concatenatedzerosbylength(minimumintegerdigits - numberdigits.length).concat(numberdigits);
}else if(numberdigits.length >= minimumintegerdigits ){
groupednumberdigits = numberdigits;
}
// appending the digits
if(fractiondigitsrequired == 0){
localeformatvalue = groupednumberdigits
}else{
localeformatvalue = groupednumberdigits + decimalseparator+formattedfractiondigits;
}
return localeformatvalue;
}
function concatenatedzerosbylength(value){
var cancatenatedvalue = null;
for(var i = 0; i < value ; i++){
cancatenatedvalue =(cancatenatedvalue == null)?"0": cancatenatedvalue.concat("0");
}
return cancatenatedvalue;
}
function insertgroupingseparator(numberdigitsarray,lastgroupingseparatorinterval,groupingseparator){
for (var i= numberdigitsarray.length;i > lastgroupingseparatorinterval; i = i-lastgroupingseparatorinterval){
numberdigitsarray.splice(i-lastgroupingseparatorinterval,0,groupingseparator);
}
return numberdigitsarray;
}
function escapeRegExp(str) {
var value = null;
if(str == " "){
value = "\\"+"s";
}else{
value = str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^$\|]/g, "\\"+str);
}
return (null == value)?str:value;
}
function isStartingWithDigit(theField){
var value = theField.value;
value.toString().match(new RegExp("[^"+ escapeRegExp(decimalseparator)+escapeRegExp(groupingseparator)+"\\d"+"]",'g'));
var startDigit = value.toString().match(new RegExp("^["+"\\d"+"]",'g'));
var isStartDigit = (null == startDigit)?false:true;
if(isStartDigit){
return true;
}else{
alert("Please enter a valid number!" );
window.setTimeout( "document.getElementById(\"" + theField.id + "\").focus();" , 10 );
window.setTimeout( "document.getElementById(\"" + theField.id + "\").select();" , 10 );
return;
}
}
function checkNumberLocaleFormat(numbervalue,fractiondigits)
{
if(isStartingWithDigit(numbervalue)){
if(validateFieldMoreThanOrEqualTo(numbervalue, 0)){
getAmountLocaleFormat(numbervalue,fractiondigits);
}
}
}
function getAmountLocaleFormat(numbervalue,fractiondigits){
var fieldId = numbervalue.id;
// Creating a new XMLHttpRequest object
var xmlhttp;
if (window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest(); // for IE7+, Firefox, Chrome, Opera,
// Safari
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // for IE6, IE5
}
// build the url
var url = "/dm/ActionServlet?action=locale_numberformat&numberValue=" + numbervalue.value +"&fractionDigits="+fractiondigits+"&valueConversion="+"no";
// Create a asynchronous GET request
xmlhttp.open("GET", url, true);
// When readyState is 4 then get the server output
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200)
{
var response = xmlhttp.responseText;
if (typeof JSON != "undefined" ) {
var data = JSON.parse(response);
if(data.error == "null") {
document.getElementById(fieldId).value = data.formattedValue;
} else {
document.getElementById(fieldId).value = '0.00';
alert('There was Error in your Input'+data.error);
}
}else{
//IE issue fix not recognising JSON object
if(response != null){
var valueDerived = parseLocaleJsonFormattedValue(response,false);
if(null != valueDerived ){
document.getElementById(fieldId).value = valueDerived ;
}else{
document.getElementById(fieldId).value = '0.00';
alert('There was Error in your Input'+response);
}
}
}
}
else
{
alert('Unable to Connect to Server !!');
}
}
};
xmlhttp.send(null);
}
function getValueLocaleFormat(numbervalue,fractiondigits){
var formattedNumberValue;
// Creating a new XMLHttpRequest object
var xmlhttp;
if (window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest(); // for IE7+, Firefox, Chrome, Opera,
// Safari
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // for IE6, IE5
}
// build the url
var url = "/dm/ActionServlet?action=locale_numberformat&numberValue=" + numbervalue +"&fractionDigits="+fractiondigits+"&valueConversion="+"yes";
// Create a synchronous GET request
xmlhttp.open("GET", url, false);
xmlhttp.send(null);
// When readyState is 4 then get the server output
if (xmlhttp.status == 200)
{
var response = xmlhttp.responseText;
if (typeof JSON != "undefined" ) {
var data = JSON.parse(response);
if(data.error == "null") {
formattedNumberValue = data.formattedValue;
} else {
alert('There was Error in your Input'+data.error);
}
} else{
//IE issue fix not recognising JSON object
if(response != null){
formattedNumberValue = parseLocaleJsonFormattedValue(response,true);
}
}
}else{
alert('Unable to Connect to Server !!');
}
return formattedNumberValue;
}
function getValueLocaleFormatStandalone(numbervalue, fractiondigits) {
if (isNaN(numbervalue)) {
alert("Provided value is not a number.");
return;
}
function formatByLocale(value, fractiondigits) {
return value.toLocaleString(undefined, {
minimumFractionDigits: fractiondigits,
maximumFractionDigits: fractiondigits
});
}
var formattedNumberValue;
try {
formattedNumberValue = formatByLocale(parseFloat(numbervalue), fractiondigits);
} catch (e) {
alert('There was an error in your input: ' + e.message);
return;
}
return formattedNumberValue;
}
function parseLocaleJsonFormattedValue(value, isAlertRequired){
var valueRemovedBracket ="";
if(value.toString().charAt(value.toString().length -1) == "}"){
valueRemovedBracket = value.toString().substring(0,value.toString().length -1);
}else{
alert('Invalid JSON ');
}
var errorValuePair = "\"error\":\"null\"";
var counterrorvalues = valueRemovedBracket.match(new RegExp(errorValuePair,'g'));
var counterror = (null == counterrorvalues)?0:counterrorvalues.length;
var numberValue = "";
if(counterror > 0){
var valueKeySplit = valueRemovedBracket.toString().trim().split("\"formattedValue\":");
var numberValue = valueKeySplit[1].toString().trim();
var quoteValue = "\"";
var closingBracket = "}"
var replaceRegEx = new RegExp([quoteValue+"|"+closingBracket], 'g');
numberValue = numberValue.toString().replace(replaceRegEx, "");
}else{
if(isAlertRequired){
alert('Invalid:'+ value);
}
}
return numberValue;
}
function localeFormatToNumber(txt,decimalseparator){
var numb = null;
var a = txt.toString();
if(null != txt){
var txtAlldigits = a.split(decimalseparator);
var numberDigits = matchJoinDigits(txtAlldigits[0].toString());
if( isNaN(numberDigits)){
if(!(globaleventvalue == "keyup")){
alert('Invalid value to format as Number');
}
}
if((txtAlldigits[1] != null) && (isNaN(txtAlldigits[1]))){
if(!(globaleventvalue == "keyup")){
alert('Invalid value to format as Number');
}
}
var fractiondigits = (null == txtAlldigits[1])?"0":matchJoinDigits(txtAlldigits[1].toString());
numb = numberDigits + "."+ fractiondigits;
}
return numb;
}
function matchJoinDigits(txt){
var numb = null;
if(null != txt){
numb = txt.match(/\d/g);
if(numb == null){
numb =txt.toString();
}else{
numb = numb.join("");
}
}
return numb;
}
// end of locale Formatting
// Other GENERAL FUNCTIONS
function isDefined(variable) {
return (typeof(window[variable]) == "undefined")? false: true;
}
/*
Trimming of all strings
*/
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$/g,"");
}
/*
This will add an item to theOriginal list, separating it with a comma if nececssary.
*/
function addCommaList(theOriginal,theString) {
if( "" == theOriginal ) {
return theString;
} else {
return theOriginal + ", " + theString;
}
}
/*
This will pad out the string with the character provided, to make it up to the specified length.
*/
function leftPad(text,padChar,length) {
text = "" + text;
while( text.length < length ) {
text = padChar + text;
}
return text;
}
/*
This will pad out the string with the character provided, to make it up to the specified length.
*/
function rightPad(text,padChar,length) {
text = "" + text;
while( text.length < length ) {
text = text + padChar;
}
return text;
}
/*
This will evaluate a string as a number. If it is not a number, this will return zero.
*/
function evalNumber(value) {
value = parseFloat( value );
if( isNaN( value ) ) {
return 0;
} else {
return value;
}
}
/*
This will evaluate a string as a number. If it is not a number, this will return zero.
*/
function evalInteger(value) {
value = parseInt( value );
if( isNaN( value ) ) {
return 0;
} else {
return value;
}
}
/*
This will find the x co-ordinate of the phsyical location in the window of the specified object.
*/
function findPosX(obj) {
var curleft = 0;
if (document.all || document.getElementById) {
while (obj.offsetParent) {
curleft += obj.offsetLeft;
obj = obj.offsetParent;
}
curleft += obj.offsetLeft;
} else if (document.layers) {
curleft += obj.x;
}
return curleft;
}
/*
This will find the y co-ordinate of the phsyical location in the window of the specified object.
*/
function findPosY(obj) {
var curtop = 0;
if (document.getElementById || document.all) {
while (obj.offsetParent) {
curtop += obj.offsetTop;
obj = obj.offsetParent;
}
curtop += obj.offsetTop;
} else if (document.layers) {
curtop += obj.y;
}
return curtop;
}
/*
This will take a value and format it with two decimal places.
*/
function parseCurrency(value) {
value+='';
value = value.replace( ',' , '.' );
value = round( value - 0 , 2 );
var frac = Math.floor( ( round( value - Math.floor( value ) , 2 ) ) * 100 );
if( frac == 0 ) {
value = ( "" + value ) + '.00';
} else if( mod(frac,10)==0 ) {
value = ( "" + value ) + '0';
}
return value;
}
function mod(X, Y) { return X - Math.floor(X/Y)*Y }
/*
This will round the number of the specified number of decimal places.
*/
function round(value,numDecimalPlaces) {
var factor = Math.pow( 10 , numDecimalPlaces );
return ( Math.round(value*factor) ) / factor;
}
/*
This will parse the date, validate it, and return a new string in the format of "dd month yyyy".
*/
function parseDateSimple(str_date) {
if( "" == str_date ) {
return "";
}
var theDate = parseDate( str_date );
return theDate.getDate() + " " + text_months[theDate.getMonth()] + " " + theDate.getFullYear();
}
function parseDateOrder(str_date) {
if( "" == str_date ) {
return "";
}
var theDate = parseDate( str_date );
return theDate.getDate() + " " + text_months[theDate.getMonth()] + " " + theDate.getFullYear()
}
/*
This will take a string containing a time and format it properly.
*/
function parseTime(str_time) {
if( "" + str_time == "" ) {
return "";
}
var str_temp = str_time.toLowerCase();
var hour = 0;
var minute = 0;
if( str_temp.indexOf( ":" ) >= 0 ) {
vals = str_temp.split( ":" );
if( vals.length > 1 ) {
hour = evalNumber( vals[0] );
minute = evalNumber( vals[1] );
} else if( vals.length == 1 ) {
hour = evalNumber( vals[0] );
minute = 0;
}
} else if( str_temp.indexOf( "." ) >= 0 ) {
vals = str_temp.split( "." );
if( vals.length > 1 ) {
hour = evalNumber( vals[0] );
minute = evalNumber( vals[1] );
} else if( vals.length == 1 ) {
hour = evalNumber( vals[0] );
minute = 0;
}
} else {
var v = evalNumber( str_temp );
hour = Math.floor( v / 100 );
minute = Math.floor( v % 100 );
}
hour = round( ( (hour) % 24 ) , 0 );
minute = round( ( (minute-1) % 60 ) + 1 , 0 );
return leftPad( hour , '0' , 2 ) + ":" + leftPad( minute , '0' , 2 );
}
// SPECIALIST FUNCTIONS
var globalActiveDropDown = null;
function onMouseLeaveSelector() {
var theFieldId = this.id.substring( 0 , this.id.length - 9 );
var theField = document.getElementById( theFieldId );
// Magic alert! We're not interested in MouseLeaves when it's a sublayer.
if( window.event.clientX != -1 ) {
showHideDropSelector( theField);
}
}
function showHideDateSelector(theField,timeOn) {
//my own perversion of calendar.setup
var format = "%d %b %Y";
if(timeOn) format = "%d %b %Y %H:%M"
Calendar.DMF({
inputField : theField, // id of the input field
ifFormat : format, // format of the input field (even if hidden, this format will be honored)
daFormat : format,// format of the displayed date
align : "Br", // alignment (defaults to "Bl")
showsTime : timeOn,
timeFormat : "24",
firstDay : 1,
weekNumbers : false,
singleClick : true
});
}
function showHideDateSelectorOld(theField) {
showHideDropSelector( theField , "
" + createCalendarHTML(theField.value,theField.offsetWidth) + "
" , 130 , "hidden" );
}
/*
This will create a generic drop-selector. The developer can pass his own HTML for the contents.
*/
function showHideDropSelector(theField,theHtmlContents,theHeight,theOverflow) {
// Get the position and dimensions of the drop text box
var left = findPosX(theField);// theField.offsetLeft
var top = findPosY(theField); // theField.offsetTop;
var width = theField.style.width;//theField.offsetWidth;
var height = theField.offsetHeight;
var showBorder = false;
if( theHeight == null ) {
theHeight = 120;
}
if( theOverflow == null ) {
theOverflow = "auto";
} else {
theOverflow = "hidden";
showBorder = 1;
}
// The Id that the selector div should have
var theContentDivId = theField.id + ".selector";
// If the selector div does not yet exist, we will create it now
var nextSibling = theField.nextSibling;
if( nextSibling.id != theContentDivId ) {
// Hide any existing drop-down
if( globalActiveDropDown != null ) {
showHideDropSelector( globalActiveDropDown );
}
// Create the div to hold the selector
var contentDiv = document.createElement( "div" );
contentDiv.id = theContentDivId;
contentDiv.style.position = "absolute";
contentDiv.style.left = left + "px";
contentDiv.style.top = top + "px";
contentDiv.style.width = width;
contentDiv.style.height = theHeight;
// contentDiv.style.overflow = "hidden";
// contentDiv.style.overflow = theOverflow; // AP: This breaks Firefox(!?)
if( showBorder ) {
contentDiv.style.border = "1px solid black";
}
if (theOverflow == "hidden"){
contentDiv.style.overflow = "hidden";
}
contentDiv.style.backgroundColor = "#ffffff";
contentDiv.style.verticalAlign = "top";
contentDiv.style.textAlign = "left";
contentDiv.style.zIndex = 999;
//Prevented advanced allocation feature from working on search_cons.jsp in ie8
//contentDiv.onmouseleave = onMouseLeaveSelector;
theField.parentNode.insertBefore( contentDiv , nextSibling );
theField.style.visibility = "hidden";
// Draw the contents of the selector
contentDiv.innerHTML = theHtmlContents;
// And activate the selector
globalActiveDropDown = theField;
if( contentDiv.focus ) {
contentDiv.focus();
}
} else {
// Remove the selector from the page
var contentDiv = document.getElementById( theContentDivId );
contentDiv.parentNode.removeChild( contentDiv );
// Make the input box visible again
theField.style.visibility = "visible";
globalActiveDropDown = null;
}
}
// Configuration
var color_day = "#eeeeee"; // Background colour for a normal day cell
var color_weekend = "#dddddd"; // Background colour for a weekend day cell
var color_selected = "#ff4444"; // Colour of text to mark selected day as
var color_hover = "#ffdddd"; // Background colour of the cell the mouse is over
var color_header_day = "#cccccc"; // Background colour of the day column headers
var cell_width = 28;
// Initialisation
var today = new Date();
var selected_date = parseDate( today.getDate() + "/" + (today.getMonth()+1) + "/" + today.getFullYear() );
var fieldWidth = 196;
var show_month = selected_date.getMonth();
var show_year = getYearValue( selected_date.getYear() );
var text_days = ["Mon","Tue","Wed","Thu","Fri","Sat","Sun"];
var text_months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
function getPageStartDate(month,year)
{
rv = new Date();
rv.setDate( 1 );
rv.setMonth( month );
rv.setYear( year );
return rv;
}
function getDaysPerMonth(month,year)
{
if( month == 0 ) return 31;
if( month == 1 && isLeapYear(year) ) return 29;
if( month == 1 && !isLeapYear(year) ) return 28;
if( month == 2 ) return 31;
if( month == 3 ) return 30;
if( month == 4 ) return 31;
if( month == 5 ) return 30;
if( month == 6 ) return 31;
if( month == 7 ) return 31;
if( month == 8 ) return 30;
if( month == 9 ) return 31;
if( month == 10 ) return 30;
if( month == 11 ) return 31;
return 31;
}
function isLeapYear(year)
{
if( ((year % 4) == 0 && (year % 100)!=0) || (year%400==0) )
{
return true;
}
else
{
return false;
}
}
function getDayIndex(dayno)
{
return ( ( dayno + 5 ) % 7 );
}
function onCalendarChanged()
{
show_month = document.getElementById( "month" ).value;
show_year = document.getElementById( "year" ).value;
document.getElementById( "calendar_target" ).innerHTML = createCalendarHTML();
}
function onDateSelected(date)
{
globalActiveDropDown.value = date + " " + (text_months[show_month]) + " " + show_year;
if( globalActiveDropDown.onchange ) {
globalActiveDropDown.onchange();
}
showHideDropSelector( globalActiveDropDown );
}
function createCalendarHTML(theValue,theWidth)
{
var out = "";
if( theValue ) {
selected_date = parseDate( theValue );
show_month = selected_date.getMonth();
show_year = getYearValue( selected_date.getYear() );
}
if( theWidth ) {
fieldWidth = theWidth;
}
var start_date = getPageStartDate( show_month , show_year );
out += "";
out += "";
out += "";
out += " | ";
out += "";
out += " | ";
out += "
";
out += "
";
out += "";
out += "Mo | ";
out += "Tu | ";
out += "We | ";
out += "Th | ";
out += "Fr | ";
out += "Sa | ";
out += "Su | ";
out += "
";
var cell_id = 0;
out += "";
for( ; cell_id <= getDayIndex( start_date.getDay() ); )
{
if( cell_id % 7 == 0 )
{
out += "
";
}
if( (cell_id % 7) == 5 || (cell_id % 7) == 6 )
{
out += " | ";
}
else
{
out += " | ";
}
cell_id++;
}
for( d = 1 ; d <= getDaysPerMonth( show_month , show_year ) ; d++ )
{
if( cell_id % 7 == 0 )
{
out += "
";
}
if( (cell_id % 7) == 5 || (cell_id % 7) == 6 )
{
out += "";
}
else
{
out += " | ";
}
if( selected_date.getDate() == d && selected_date.getMonth() == show_month && getYearValue( selected_date.getYear() ) == show_year )
{
out += "" + d + " | ";
}
else
{
out += "" + d + "";
}
cell_id++;
}
filler_day = 1;
v = 3;
while( (cell_id % 7 != 0) || (v > 0) )
{
if( cell_id % 7 == 0 )
{
out += "
";
v--;
}
if( (cell_id % 7) == 5 || (cell_id % 7) == 6 )
{
out += " | ";
}
else
{
out += " | ";
}
cell_id++;
filler_day++;
}
out += "
";
out += "
";
return out;
}
function getDateValue(input)
{
return evalNumber( input );
}
function getMonthValue(input)
{
if( input.indexOf( "jan" ) >= 0 ) return 1;
if( input.indexOf( "feb" ) >= 0 ) return 2;
if( input.indexOf( "mar" ) >= 0 ) return 3;
if( input.indexOf( "apr" ) >= 0 ) return 4;
if( input.indexOf( "may" ) >= 0 ) return 5;
if( input.indexOf( "jun" ) >= 0 ) return 6;
if( input.indexOf( "jul" ) >= 0 ) return 7;
if( input.indexOf( "aug" ) >= 0 ) return 8;
if( input.indexOf( "sep" ) >= 0 ) return 9;
if( input.indexOf( "oct" ) >= 0 ) return 10;
if( input.indexOf( "nov" ) >= 0 ) return 11;
if( input.indexOf( "dec" ) >= 0 ) return 12;
if( isNaN( input ) ) {
input = 0;
}
if( input >= 1 && input <= 12 ) return parseInt(input);
return 0;
}
function getYearValue(input)
{
input = input - 0;
input = evalNumber(input);
if( input < 50 ) {
input += 2000;
return evalNumber( input );
} else if( input > 1900 ) {
return evalNumber( input );
} else {
input += 1900;
return evalNumber( input );
}
}
function parseDate(str_date)
{
var date_out = new Date();
var str_temp = str_date.toLowerCase();
var date = 0;
var month = 0;
var year = 0;
if( str_temp.indexOf( "/" ) >= 0 )
{
// This is a number date
vals = str_temp.split( "/" );
if( vals.length >= 3 )
{
// Assuming the format DD/MM/YY, DD/MM/YYYY, DD/MMM/YY or DD/MMM/YYYY
date = getDateValue( vals[0] );
month = getMonthValue( vals[1] );
year = getYearValue( vals[2] );
}
else if( vals.length == 2 ) {
date = getDateValue( vals[0] );
month = getMonthValue( vals[1] );
year = today.getFullYear();
}
}
else if( str_temp.indexOf( " " ) >= 0 )
{
// This is a number date
vals = str_temp.split( " " );
if( vals.length >= 3 )
{
// Assuming the format DD MM YY, DD[th] MMM YY, DD[th] MMM YYYY
date = getDateValue( vals[0] );
month = getMonthValue( vals[1] );
year = getYearValue( vals[2] );
}
else if( vals.length == 2 ) {
date = getDateValue( vals[0] );
month = getMonthValue( vals[1] );
year = today.getFullYear();
}
}
else if( str_temp.indexOf( "." ) >= 0 )
{
// This is a number date
vals = str_temp.split( "." );
if( vals.length >= 3 )
{
// Assuming the format DD MM YY, DD[th] MMM YY, DD[th] MMM YYYY
date = getDateValue( vals[0] );
month = getMonthValue( vals[1] );
year = getYearValue( vals[2] );
}
else if( vals.length == 2 ) {
date = getDateValue( vals[0] );
month = getMonthValue( vals[1] );
year = today.getFullYear();
}
}
if( date == 0 || month == 0 || year == 0 )
{
date_out = new Date();
}
else
{
date_out = new Date( year , month - 1 , date );
}
return date_out;
}
/*
TABS
*/
function addTab(tabContainerId,tabId,theTitle) {
var theButtonContainer = document.getElementById( tabContainerId + "TabButtons" );
var theHtml;
var e;
// Do we need to initialise the tab container?
if( theButtonContainer == null ) {
theHtml = "" +
"" +
"" +
"" +
" " +
" | " +
"
" +
"" +
"" +
" | " +
"
" +
"
";
document.getElementById( tabContainerId ).innerHTML = theHtml;
theButtonContainer = document.getElementById( tabContainerId + "TabButtons" );
}
e = document.createElement( "input" );
e.type = "hidden";
e.id = tabId + "TabContainer";
e.value = tabContainerId;
theButtonContainer.appendChild( e );
// Create the tab button
var theButtonElement = document.createElement( "td" );
theButtonElement.id = tabId + "TabButton";
theButtonElement.className = "tabbutton-inactive";
theButtonElement.innerHTML = "" + theTitle + "";
theButtonElement.align = "center";
theButtonElement.style.backgroundColor = "#eeeeee";
theButtonContainer.insertBefore( theButtonElement , document.getElementById( tabContainerId + "LastButtonPos" ) );
// Create a gap
theButtonElement = document.createElement( "td" );
theButtonElement.width = 2;
theButtonElement.style.borderStyle = "none";
theButtonElement.style.borderBottomStyle = "solid";
theButtonElement.style.borderWidth = "1px";
theButtonElement.innerHTML = "
";
theButtonContainer.insertBefore( theButtonElement , document.getElementById( tabContainerId + "LastButtonPos" ) );
document.getElementById( tabContainerId + "TabContent" ).colSpan += 2;
var oldNode = document.getElementById( tabId );
document.getElementById( tabContainerId +"TabContent" ).appendChild( oldNode );
}
function activateTab(tabContainerId,tabId) {
var theTabContainer = document.getElementById( tabContainerId );
var theActiveTab = document.getElementById( tabContainerId + "ActiveTab" );
if( theActiveTab.value != "" ) {
document.getElementById( theActiveTab.value ).style.display = "none";
document.getElementById( theActiveTab.value + "TabButton" ).className = "tabbutton-inactive";
}
document.getElementById( tabId ).style.display = "inline";
document.getElementById( tabId + "TabButton" ).className = "tabbutton-active";
theActiveTab.value = tabId;
}
function setTabTitle(tabId,tabTitle) {
// document.getElementById( tabId + "TabButton" ).innerHTML = tabTitle;
}
//store javascript variables for display DM Help
var helpPageIds = new Array();
var helpPagePaths = new Array();
helpPageIds[ helpPageIds.length ] = 1;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 2;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 3;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 4;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 5;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 6;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 7;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 8;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 9;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 10;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 11;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 12;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 13;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 14;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 15;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 16;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 17;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 18;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 19;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 20;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 21;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 22;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 23;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 24;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 25;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 26;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 27;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 28;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 29;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 30;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 31;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 32;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 33;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 34;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 35;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 36;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 37;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 38;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 39;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 41;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 42;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 44;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 45;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 46;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 47;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 48;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 49;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 50;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 51;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 52;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 53;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 54;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 55;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 56;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 57;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 58;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 59;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 60;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 61;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 62;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 63;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 64;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 65;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 66;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 67;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 68;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 69;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 70;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 71;
helpPagePaths[ helpPagePaths.length ] = '/articles/360007853857-Creating-and-Allocating-a-test-Consignment';
helpPageIds[ helpPageIds.length ] = 72;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 76;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 77;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 78;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 79;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
helpPageIds[ helpPageIds.length ] = 83;
helpPagePaths[ helpPagePaths.length ] = '/sections/360005139558-Platform-Setup';
function showHelpTopic(pageID) {
var helpPageIndex = 0;
var helpPath = helpPagePaths[0];
for(var i = 0; i < helpPageIds.length; i++) {
if ( pageID == helpPageIds[i] ) {
helpPath = helpPagePaths[i];
break;
}
}
var theWindow = window.open( 'https://help.metapack.com/hc/en-gb' + helpPath , 'metapackHelpWindow' , 'top=0,left=0,toolbar=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,modal=no,height=' + screen.height + ',width=' + screen.width);
theWindow.focus();
}
function disableForSubmit() {
document.body.style.cursor = "wait";
var allElements = document.getElementsByTagName( "input" );
for( var i = 0 ; i < allElements.length ; i++ ) {
allElements[i].readOnly = true;
if ((allElements[i].type == 'button') || allElements[i].type == 'submit') {
allElements[i].disabled = true;
}
}
}
function enableForSubmit() {
document.body.style.cursor = "default";
var allElements = document.getElementsByTagName( "input" );
for( var i = 0 ; i < allElements.length ; i++ ) {
allElements[i].readOnly = false;
if ((allElements[i].type == 'button') ) {
allElements[i].disabled = false;
}
}
}
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+""+expires+"; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++) {
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
}
return "";
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
function dateDiff(date1,date2) {
return Math.round( date1 - date2 )/(1000*60*60*24);
}
/*
Field validation routines. Each takes a field which MUST have an id.
Usage:
... onBlur="if( validateFieldNumber(this) && validateFieldMoreThanOrEqualTo(this,1) );" ...
*/
function validateNotBlank(theField,theDisplayName) {
if( theField.value.trim() == "" ) {
alert( theDisplayName + " " + "cannot be left blank" );
window.setTimeout( "document.getElementById('" + theField.id + "').focus();" , 1 );
window.setTimeout( "document.getElementById('" + theField.id + "').select();" , 1 );
return false;
} else {
return true;
}
}
// The value must be a number
function validateFieldNumber(theField) {
if( isNaN( theField.value ) ) {
alert( "You must enter a number" );
window.setTimeout( "document.getElementById('" + theField.id + "').focus();" , 1 );
window.setTimeout( "document.getElementById('" + theField.id + "').select();" , 1 );
return false;
} else {
return true;
}
}
// Must be an integer
function validateFieldWholeNumber(theField) {
if( Math.round( theField.value ) != theField.value ) {
alert( "You must enter a whole number" );
window.setTimeout( "document.getElementById('" + theField.id + "').focus();" , 1 );
window.setTimeout( "document.getElementById('" + theField.id + "').select();" , 1 );
return false;
} else {
return true;
}
}
// The number must be more than...
function validateFieldMoreThan(theField,value) {
if( theField.value <= value ) {
alert( "You must enter a value more than" + " " + value );
window.setTimeout( "document.getElementById('" + theField.id + "').focus();" , 1 );
window.setTimeout( "document.getElementById('" + theField.id + "').select();" , 1 );
return false;
} else {
return true;
}
}
/// The number must be more than or equal to...
function validateFieldMoreThanOrEqualTo(theField,value) {
if( theField.value < value ) {
alert( "You must enter a value no less than" + " " + value );
window.setTimeout( "document.getElementById('" + theField.id + "').focus();" , 1 );
window.setTimeout( "document.getElementById('" + theField.id + "').select();" , 1 );
return false;
} else {
return true;
}
}
// The number nust be less than...
function validateFieldLessThan(theField,value) {
if( theField.value > value ) {
alert( "You must enter a value less than" + " " + value );
window.setTimeout( "document.getElementById('" + theField.id + "').focus();" , 1 );
window.setTimeout( "document.getElementById('" + theField.id + "').select();" , 1 );
return false;
} else {
return true;
}
}
// The number must be less than or equal to...
function validateFieldLessThanOrEqualTo(theField,value) {
if( theField.value >= value ) {
alert( "You must enter a value no more than" + " " + value );
window.setTimeout( "document.getElementById('" + theField.id + "').focus();" , 1 );
window.setTimeout( "document.getElementById('" + theField.id + "').select();" , 1 );
return false;
} else {
return true;
}
}
// The number must be between minValue and maxValue (inclusive)
function validateFieldBetweenInclusive(theField,minValue,maxValue) {
if( theField.value < minValue || theField.value > maxValue ) {
alert( "null" + " " + minValue +
" " +
"and" +
" " + maxValue +
" (" + "inclusive" + ")" );
window.setTimeout( "document.getElementById('" + theField.id + "').focus();" , 1 );
window.setTimeout( "document.getElementById('" + theField.id + "').select();" , 1 );
return false;
} else {
return true;
}
}
// The number must be between minValue and maxValue (excluding the ends)
function validateFieldBetweenExclusive(theField,minValue,maxValue) {
if( theField.value <= minValue || theField.value >= maxValue ) {
alert( "You must enter a value more than" +
" " + minValue + " " +
"but less than" + " " + maxValue );
window.setTimeout( "document.getElementById('" + theField.id + "').focus();" , 1 );
window.setTimeout( "document.getElementById('" + theField.id + "').select();" , 1 );
return false;
} else {
return true;
}
}
// Disable the input box
function disableInputBox(theInputElement) {
theInputElement.readOnly = true;
theInputElement.className = "input-box-disabled";
}
// Enable the input box
function enableInputBox(theInputElement) {
theInputElement.readOnly = false;
theInputElement.className = "input-box";
}
// Disable all text boxes in parent window
function disableParentElementsForSubmit() {
document.body.style.cursor = "wait";
var allElements = window.parent.opener.document.getElementsByTagName( "*" );
for( var i = 0 ; i < allElements.length ; i++ ) {
var tn = allElements[i].tagName.toLowerCase();
if( "input" == tn ) {
allElements[i].readOnly = true;
if( allElements[i].type && allElements[i].type.toLowerCase() == "text" ) {
allElements[i].className += " input-box-disabled";
}
}
}
}
// Gets the value of parameter in a URL. For example if the current URL is "...?opendocument&id=testid" then
// calling getURLParam("id") will return "testid".
function getURLParam(strParamName){
var strReturn = "";
var strHref = window.location.href;
if ( strHref.indexOf("?") > -1 ){
var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
var aQueryString = strQueryString.split("&");
for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
if ( aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ) {
var aParam = aQueryString[iParam].split("=");
strReturn = aParam[1];
break;
}
}
}
return unescape(strReturn);
}
// populateIframeWithUrl()
//
// This will fill the contents of the specified iframe with the URL specified.
function populateIframeWithUrl(theFrameName,theUrl) {
var theMagicForm = document.getElementById( "theMagicForm_populateIframeWithUrl" );
if( theMagicForm == null ) {
theMagicForm = document.body.appendChild( document.createElement( "form" ) );
theMagicForm.id = "theMagicForm_populateIframeWithUrl";
theMagicForm.name = "theMagicForm_populateIframeWithUrl";
theMagicForm.method = "POST";
}
theMagicForm.target = theFrameName;
theMagicForm.action = theUrl;
theMagicForm.submit();
}
function disableForSubmitWithoutWaitCursor() {
var allElements = document.getElementsByTagName( "input" );
for( var i = 0 ; i < allElements.length ; i++ ) {
allElements[i].readOnly = true;
if ((allElements[i].type == 'button') || allElements[i].type == 'submit') {
allElements[i].disabled = true;
}
}
}
//This prototype is provided by the Mozilla foundation and
//is distributed under the MIT license.
//http://www.ibiblio.org/pub/Linux/LICENSES/mit.license
if (!Array.prototype.indexOf)
{
Array.prototype.indexOf = function(elt /*, from*/)
{
var len = this.length;
var from = Number(arguments[1]) || 0;
from = (from < 0)
? Math.ceil(from)
: Math.floor(from);
if (from < 0)
from += len;
for (; from < len; from++)
{
if (from in this &&
this[from] === elt)
return from;
}
return -1;
};
}
String.prototype.startsWith = function(str) {
return (this.match("^"+str)==str);
}
String.prototype.endsWith = function(str) {
return (this.match(str+"$")==str);
}
/*
Some time & time-period functions (used when entering times into text boxes).
*/
function cleanFormatTime(theObject) {
var theText = theObject.value;
theText = theText.replace(/[^0-9]/g, '');
theText = theText.substring( 0 , 4 );
while( theText.length < 4 ) { theText = "0" + theText; }
theText = theText.substring( 0 , 2 ) + ":" + theText.substring( 2 , 4 );
if( theText.substring( 0 , 2 ) - 0 > 23 ) {
theText = "23:" + theText.substring( 3 , 5 );
}
if( theText.substring( 3 , 5 ) - 0 > 59 ) {
theText = theText.substring( 0 , 2 ) + ":59";
}
theObject.value = theText;
}
function cleanFormatTimeList(theObject) {
var theTextArray = theObject.value.split( "," );
var theOutputText = "";
for( var theTextArrayIndex = 0 ; theTextArrayIndex < theTextArray.length ; theTextArrayIndex++ ) {
var theText = theTextArray[ theTextArrayIndex ];
theText = theText.replace(/[^0-9]/g, '');
theText = theText.substring( 0 , 4 );
while( theText.length < 4 ) { theText = "0" + theText; }
theText = theText.substring( 0 , 2 ) + ":" + theText.substring( 2 , 4 );
if( theText.substring( 0 , 2 ) - 0 > 23 ) {
theText = "23:" + theText.substring( 3 , 5 );
}
if( theText.substring( 3 , 5 ) - 0 > 59 ) {
theText = theText.substring( 0 , 2 ) + ":59";
}
if( theOutputText.length > 0 ) theOutputText += ", ";
theOutputText += theText;
}
theObject.value = theOutputText;
}
function cleanFormatTimeRange(theObject) {
var theText = theObject.value;
if( theText.indexOf( "-" ) == -1 ) theText = theText + "-";
var theTextArray = theText.split( "-" );
var theOutputText = "";
for( var theTextArrayIndex = 0 ; theTextArrayIndex < 2 ; theTextArrayIndex++ ) {
var theText = theTextArray[ theTextArrayIndex ];
theText = theText.replace(/[^0-9]/g, '');
theText = theText.substring( 0 , 4 );
if( theText == "" && theTextArrayIndex > 0 ) theText = "2359";
while( theText.length < 4 ) { theText = "0" + theText; }
theText = theText.substring( 0 , 2 ) + ":" + theText.substring( 2 , 4 );
if( theText.substring( 0 , 2 ) - 0 > 23 ) {
theText = "23:" + theText.substring( 3 , 5 );
}
if( theText.substring( 3 , 5 ) - 0 > 59 ) {
theText = theText.substring( 0 , 2 ) + ":59";
}
if( theOutputText.length > 0 ) theOutputText += "-";
theOutputText += theText;
}
theObject.value = theOutputText;
}
function calcTimeRangeSpan(theRange) {
if( theRange.length != 11 ) {
alert( "Invalid time range: " + theRange );
return 0;
} else {
var theTextArray = theRange.split( "-" );
if( theTextArray.length != 2 ) {
alert( "Invalid time range: " + theRange );
return 0;
}
var fromV1 = theTextArray[0].replace(/[^0-9]/g, '') - 0;
var toV1 = theTextArray[1].replace(/[^0-9]/g, '') - 0;
var fromTime = Math.floor( fromV1 / 100 ) * 60 + ( fromV1 % 100 );
var toTime = Math.floor( toV1 / 100 ) * 60 + ( toV1 % 100 );
return toTime - fromTime;
}
}
function showMetricValueTooltip(metricField, unitType) {
var valueToConvert = document.getElementById(metricField).value;
var metricObject = convertToMetric(valueToConvert, unitType);
document.getElementById(metricField).title = metricValue.toFixed(metricObject.value) + metricObject.unit;
}
function convertToMetric(valueToConvert, unitType) {
var poundsToKgConversion = 0.45359237;
var inchesToCmConversion = 2.54;
var ouncesToMlsConversion = 29.57353;
var decimalPlaces = 4;
var metricValue;
switch(unitType) {
case "WEIGHT":
metricValue = valueToConvert * poundsToKgConversion;
metricUnit = "kg";
break;
case "LENGTH":
metricValue = valueToConvert * inchesToCmConversion;
metricUnit = "cm";
break;
case "VOLUME":
metricValue = valueToConvert * ouncesToMlsConversion;
metricUnit = "ml";
break;
}
return {
value: metricValue,
unit: metricUnit
};
}