﻿/////////////////////////////
// OPEN MOOPA WINDOW STUFF //
/////////////////////////////
function OpenMoopaWindow(URL,Target,Toolbar,Status,Location,Menubar,Directories,Scrollbars,Resizable,Top,Left,Width,Height) {
	
	if ((Width == 0) && (Height == 0)){
		if ((screen.Height >= 0) && (screen.Width >= 0))
		{
			var Width = screen.Width - 10;
			var Height = screen.Height - 100;
		}
		else if ((screen.availHeight >= 0) && (screen.availWidth >= 0)) {
			
			var Width = screen.availWidth - 10;
			var Height = screen.availHeight - 100;
		}
	}
	win = window.open(URL, Target, "toolbar=" + Toolbar + ",status=" + Status + ",location=" + Location + ",menubar=" + Menubar + ",directories=" + Directories + ",scrollbars=" + Scrollbars + ",resizable=" + Resizable + ",screenX=" + Left + ",screenY=" + Top + ",left=" + Left + ",top=" + Top + ",width=" + Width + ",height=" + Height); win.focus();
}



function MoopaMultipleSubmit(FormName){
	document.forms[FormName].submit();																
}
															

/* This script is Copyright (c) Paul McFedries and 
Logophilia Limited (http://www.mcfedries.com/).
Permission is granted to use this script as long as 
this Copyright notice remains in place.*/

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}

/////////////////////////////
// COLOR PALLET            //
/////////////////////////////
function _f(_a)
{
  var _o='';
  for(var i=0;i<_a.length;i++)
  {
  	_o+='<td width="14" height="14" bgcolor="'+_a[i]+'" valign="top"';
    _o+='<a href="#" onclick="window.opener.doIt(\''+_a[i]+'\');window.close()">';
    _o+='<IMG SRC="#application.ImagesURL#/shim.gif" width="14" height="14" border="0" alt="'+_a[i]+'"></a>';
	_o+='</a>';
	_o+='</td>';
  }
  return(_o);
}

var _o='';
_o+='<HTML><HEAD><TITLE>Color Chart</TITLE><sc'+'ript>function loadfocus(){refButton = opener.document.FORM1.fieldName.value;window.focus()}</sc'+'ript></HEAD>';
_o+='<body onload="loadfocus()" onblur="window.focus()" bgcolor="#334455" leftmargin="0" marginwidth="0" topmargin="0" marginheight="0">';
_o+='<table border="1" bgcolor="#888888" cellpadding="0" cellspacing="0">';
_o+='<!-- RED --><tr>';
var _a$=new Array("#ffffff","#ffeeee","#ffdddd","#ffcccc","#ffbbbb","#ffaaaa","#ff9999","#ff8888","#ff7777","#ff6666","#ff5555","#ff4444","#ff3333","#ff2222","#ff1111","#ff0000","#ee0000","#dd0000","#cc0000","#bb0000","#aa0000","#990000","#880000","#770000","#660000","#550000","#440000","#330000","#220000","#110000","#000000");
_o+=_f(_a$);
_o+='</tr><!-- GREEN --><tr>';
var _b$=new Array("#ffffff","#eeffee","#ddffdd","#ccffcc","#bbffbb","#aaffaa","#99ff99","#88ff88","#77ff77","#66ff66","#55ff55","#44ff44","#33ff33","#22ff22","#11ff11","#00ff00","#00ee00","#00dd00","#00cc00","#00bb00","#00aa00","#009900","#008800","#007700","#006600","#005500","#004400","#003300","#002200","#001100","#000000");
_o+=_f(_b$);
_o+='</tr><!-- BLUE --><tr>';
var _c$=new Array("#ffffff","#eeeeff","#ddddff","#ccccff","#bbbbff","#aaaaff","#9999ff","#8888ff","#7777ff","#6666ff","#5555ff","#4444ff","#3333ff","#2222ff","#1111ff","#0000ff","#0000ee","#0000dd","#0000cc","#0000bb","#0000aa","#000099","#000088","#000077","#000066","#000055","#000044","#000033","#000022","#000011","#000000");
_o+=_f(_c$);
_o+='</tr><!-- YELLOW --><tr>';
var _d$=new Array("#ffffff","#ffffee","#ffffdd","#ffffcc","#ffffbb","#ffffaa","#ffff99","#ffff88","#ffff77","#ffff66","#ffff55","#ffff44","#ffff33","#ffff22","#ffff11","#ffff00","#eeee00","#dddd00","#cccc00","#bbbb00","#aaaa00","#999900","#888800","#777700","#666600","#555500","#444400","#333300","#222200","#111100","#000000");
_o+=_f(_d$);
_o+='</tr><!-- PURPLE --><tr>';
var _e$=new Array("#ffffff","#ffeeff","#ffddff","#ffccff","#ffbbff","#ffaaff","#ff99ff","#ff88ff","#ff77ff","#ff66ff","#ff55ff","#ff44ff","#ff33ff","#ff22ff","#ff11ff","#ff00ff","#ee00ee","#dd00dd","#cc00cc","#bb00bb","#aa00aa","#990099","#880088","#770077","#660066","#550055","#440044","#330033","#220022","#110011","#000000");
_o+=_f(_e$);
_o+='</tr><!-- CYAN --><tr>';
var _f$=new Array("#ffffff","#eeffff","#ddffff","#ccffff","#bbffff","#aaffff","#99ffff","#88ffff","#77ffff","#66ffff","#55ffff","#44ffff","#33ffff","#22ffff","#11ffff","#00ffff","#00eeee","#00dddd","#00cccc","#00bbbb","#00aaaa","#009999","#008888","#007777","#006666","#005555","#004444","#003333","#002222","#001111","#000000");
_o+=_f(_f$);
_o+='</tr><!-- ORANGE --><tr>';
var _g$=new Array("#ffffff","#fff7ee","#ffeedd","#ffe6cc","#ffddbb","#ffd5aa","#ffcc99","#ffc488","#ffbb77","#ffb366","#ffaa55","#ffa244","#ff9933","#ff9122","#ff8811","#ff8000","#ee7700","#dd6f00","#cc6600","#BB5E00","#AA5500","#994D00","#884400","#773C00","#663300","#552B00","#442200","#331A00","#221100","#110900","#000000");
_o+=_f(_g$);
_o+='</tr><!-- GRAY --><tr>';
var _h$=new Array("##ffffff","##F6F6F6","#EEEEEE","#E5E5E5","#DDDDDD","#D4D4D4","#CCCCCC","#C3C3C3","#BBBBBB","#B2B2B2","#AAAAAA","#A1A1A1","#999999","#909090","#888888","#7F7F7F","#777777","#6E6E6E","#666666","#5D5D5D","#555555","#4C4C4C","#444444","#3B3B3B","#333333","#2A2A2A","#222222","#191919","#111111","#080808","#000000");
_o+=_f(_h$);
_o+='</tr></table></BODY></HTML>';


var win= null;

function PickColorWindow(fieldName)
{// Save the name of the target input field to the hidden input
document.FORM1.fieldName.value=fieldName
// Opens the Color Chart Popup
win2=window.open('','PickColorWindow','height=130,width=500,top=0,left=0,scrollbars=no,resizable=no');
win2.document.open();
win2.document.write(_o);
win2.document.close();
}

function doIt(color)
{// Get the selected color and send it to the target input field
eval('document.FORM1.' + document.FORM1.fieldName.value + '.value=\'' + color + '\'');
eval('document.FORM1.' + document.FORM1.fieldName.value + '.style.backgroundColor=\'' + color + '\'');
eval('document.FORM1.' + document.FORM1.fieldName.value + '.style.color=\'' + color + '\'');
}



/////////////////////////////
// SHOW HIDE               //
/////////////////////////////
function Show(object) {
    if (document.getElementById && document.getElementById(object) != null)
         node = document.getElementById(object).style.visibility='visible';
    else if (document.layers && document.layers[object] != null)
        document.layers[object].visibility = 'visible';
    else if (document.all)
        document.all[object].style.visibility = 'visible';
}

function Hide(object) {
    if (document.getElementById && document.getElementById(object) != null)
         node = document.getElementById(object).style.visibility='hidden';
    else if (document.layers && document.layers[object] != null)
        document.layers[object].visibility = 'hidden';
    else if (document.all)
         document.all[object].style.visibility = 'hidden';
}



/////////////////////////////
//  DATE VALIDATION        //
/////////////////////////////

var new_fieldname = "";

function chkdate(objName) {

//var strDatestyle = "US"; //United States date style
var strDatestyle = "EU";  //European date style
var strDate;
var strDateArray;
var strDay;
var strMonth;
var strYear;
var intday;
var intMonth;
var intYear;
var booFound = false;
var datefield = objName;
var strSeparatorArray = new Array("-"," ","/",".");
var strDateArray = new Array(1);
var intElementNr;
var err = 0;
var strMonthArray = new Array(12);
strMonthArray[0] = "Jan";
strMonthArray[1] = "Feb";
strMonthArray[2] = "Mar";
strMonthArray[3] = "Apr";
strMonthArray[4] = "May";
strMonthArray[5] = "Jun";
strMonthArray[6] = "Jul";
strMonthArray[7] = "Aug";
strMonthArray[8] = "Sep";
strMonthArray[9] = "Oct";
strMonthArray[10] = "Nov";
strMonthArray[11] = "Dec";
strDate = datefield.value;

if (strDate.length < 1) {
return true;
}


for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) {
	if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) {
		strDateArray = strDate.split(strSeparatorArray[intElementNr]);

		if (strDateArray.length != 3) {
		err = 1;
		return false;
		}
		else {
		strDay = strDateArray[0];
		strMonth = strDateArray[1];
		strYear = strDateArray[2];
		}
		
		booFound = true;
   }
}

if (strDateArray.length != 3) {
	err = 1;
	return false;
}

if (booFound == false) {
if (strDate.length>5) {
strDay = strDate.substr(0, 2);
strMonth = strDate.substr(2, 2);
strYear = strDate.substr(4);
   }
}

if (strYear.length == 2) {
strYear = '20' + strYear;
}

// US style
if (strDatestyle == "US") {
strTemp = strDay;
strDay = strMonth;
strMonth = strTemp;
}

intday = parseInt(strDay, 10);
if (isNaN(intday)) {
err = 2;
return false;
}
intMonth = parseInt(strMonth, 10);
if (isNaN(intMonth)) {
for (i = 0;i<12;i++) {
if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) {
intMonth = i+1;
strMonth = strMonthArray[i];
i = 12;
   }
}
if (isNaN(intMonth)) {
err = 3;
return false;
   }
}
intYear = parseInt(strYear, 10);
if (isNaN(intYear)) {
err = 4;
return false;
}
if (intMonth>12 || intMonth<1) {
err = 5;
return false;
}

if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) {
err = 6;
return false;
}
if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) {
err = 7;
return false;
}
if (intMonth == 2) {
if (intday < 1) {
err = 8;
return false;
}
if (LeapYear(intYear) == true) {
if (intday > 29) {
err = 9;
return false;
}
}
else {
if (intday > 28) {
err = 10;
return false;
}
}
}
if (strDatestyle == "US") {
datefield.value = strMonthArray[intMonth-1] + " " + intday+" " + strYear;
}
else {
datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear;
}
return true;
}
function LeapYear(intYear) {
if (intYear % 100 == 0) {
if (intYear % 400 == 0) { return true; }
}
else {
if ((intYear % 4) == 0) { return true; }
}
return false;
}


