//  Correct input expression
inputMoney = /[^$0123456789,.]/g
inputCounter = /[^0123456789]/g;
inputPercent = /[^0123456789,.%]/g;
inputDate = /[^0123456789\/]/g;

expMoney = /[^0123456789.]/g
expCounter = /[^0123456789]/g;
expPercent = /[^0123456789.]/g;
expDate = /[^0123456789\/]/g;

function format( type, obj ) {
	aIndex = type.indexOf( ":" );
	args = null;
	if ( aIndex != -1 ) {
		args = type.substring( aIndex + 1, type.length );
		type = type.substring( 0, aIndex );
	}
	value = obj.value.replace( /[ ]/g, "" );
	if ( value == null ) return "";
	if ( value.length == 0 ) return "";
	if ( type == "Money" ) {
		value = unformatter( expMoney, value );
		obj.value = formatMoney( value );
	} else if ( type == "Counter" ) {
		value = unformatter( expCounter, value );
		obj.value = formatCounter( value );
	} else if ( type == "Percent" ) {
		value = unformatter( expPercent, value );
		obj.value = formatPercent( value, args );
	} else if ( type == "Date" ) {
		obj.value = formatDate( value );
	}
	if ( obj.value == "error" ) {
		obj.value = "";
		obj.select();
		obj.focus();
	}
}

function unformat( type, obj ) {
	aIndex = type.indexOf( ":" );
	args = null;
	if ( aIndex != -1 ) {
		args = type.substring( aIndex + 1, type.length );
		type = type.substring( 0, aIndex );
	}
	if ( type == "Money" )
		obj.value = unformatter( expMoney, obj.value );
	if ( type == "Counter" )
		obj.value = unformatter( expCounter, obj.value );
	if ( type == "Percent" )
		obj.value = unformatter( expPercent, obj.value );

	obj.select();
	obj.focus();
}

function checkKeyUp( type, obj ) {
	value = obj.value;
	if ( type == "Money" ) {
		obj.value = value.replace( inputMoney, "" );
	} else if ( type == "Counter" ) {
		obj.value = value.replace( inputCounter, "" );
	} else if ( type == "Percent" ) {
		obj.value = value.replace( inputPercent, "" );
	} else if ( type == "Date" ) {
		obj.value = value.replace( inputDate, "" );
	}
}


function unformatter( exp, value ) {
	return value.replace( exp, "" );
}

// Money formatter
function formatMoney( value ) {
	if ( isNaN( value ) ) {
		alert( "Invalid input." );
		return "error";
	}
	number = value.replace( /[^0123456789.]/g, "" );
	intPart = number.match( /\d*/ );
	decPart = number.replace( /\d*/, "" ).replace( /\./g, "" ) + "00";
	return "$" + formatCounter(intPart) + "." + decPart.substring(0, 2);
}

// Counter formatter
function formatCounter( value ) {
	if ( isNaN( value ) ) {
		alert( "Invalid input." );
		return "error";
	}
	value = String( value );
	commaStr = "";
	for ( i = value.length - 3; i > 0 ; i -= 3 ) {
	   commaStr = "," + value.substring( i, i + 3 ) + commaStr;
	}
	reminder = value.substring(0, i + 3);
	return reminder + commaStr;
}

//  Percent formatter
function formatPercent( value, args ) {
	if ( isNaN( value ) ) {
		alert( "Invalid input." );
		return "error";
	}
	//  check decimal
	number = value.replace( /[^0123456789.]/g, "" );
	intPart = number.match( /\d*/ );
	decPart = number.replace( /\d*/, "" ).replace( /\./g, "" );
	for ( i = 0; i < args; i++ ) {
		decPart = decPart + "0";
	}
	intPart = intPart == "" ? 0 : intPart;
	return intPart + "." + decPart.substring( 0, args ) + "%";
}

//  Date formatter
function formatDate( value ) {
	value = value.replace( /[-]/g, "/" );
	index = value.indexOf( "/" );

	y2kCut = 90;
	date = null;
	month = null;
	year = null;

	if ( index > 0 ) {
		month = value.substring( 0, index++ );
		next = value.indexOf( "/", index );
		//  if no year enters
		if ( next == -1 ) next = value.length;
		date = value.substring( index, next );
		if ( next == value.length ) {
			var now = new Date();
			year = now.getFullYear();
		} else
			year = value.substring( next + 1, value.length );
	}
	if ( date == null || month == null || year == null ||
		 isNaN( date ) || isNaN( month ) || isNaN( year ) ) {
		alert( "Date must be in the form 'MM/DD/YYYY'." );
		return "error";
	}

	if ( !(eval( date ) >= 1 && eval( date ) <= 31) )

	century = year < y2kCut ? 2000 : 1900;

	date = date.length == 2 ? date : "0" + date;
	month = month.length == 2 ? month : "0" + month;
	year = String(year).length == 4 ? year : eval(century) + eval(year);

	now = new Date( year, month - 1, date );
	if ( year != now.getYear() ||
		 eval( month ) != (now.getMonth() + 1) ||
		 eval( date ) != now.getDate() ) {
		alert( "Invalid date." );
		return "error";
	}
	return month + "/" + date + "/" + year;
}

/*
 * Get the element from form
 */
function getFormElement( name ) {
	/* search for element in forms */
	var count = document.forms.length;
	for(var i = 0; i < count; i++) {
		element = document.forms[i].elements[name];
		if (element != null) return element;
	}
	return null;
}

/*
 * Get the element from form
 */
function getDocumentElement( name ) {
	/* search for element in document */
	alert( "Length: " + document.embeds.length );
	var element = document.embeds[name];
	return element == null ? null : element;
}

/*
 * Get form with element name
 */
function getForm( name ) {
	/* search for element in forms */
	var count = document.forms.length;
	for(var i = 0; i < count; i++) {
		element = document.forms[i].elements[name];
		if (element != null) return document.forms[i];
	}
	return null;
}

/*
 * Submit form with element name and value
 */
function submit( name, value ) {
	var form = getForm( name );
	var element = getFormElement( name );
	element.value = value;
	form.submit();
}

function getPos( el, sProp ) {
	var iPos = 0;
	while (el != null) {
		iPos += el["offset" + sProp];
		el = el.offsetParent;
	}
	return iPos;
}
function moveTo( elem, posX, posY ){
	// moves layer directly to new position
	elem.style.left = posX + "px";
	elem.style.top = posY + "px";
}
function menuOver( menuElem, subMenu ) {
//  alert(navigator.appName);
//	alert(navigator.appCodeName);
//	alert(navigator.appVersion);
	if (navigator.appVersion.indexOf("Macintosh") != -1) {
	    subMenuElem = document.getElementById(subMenu);
	    var smw = parseInt(subMenuElem.offsetWidth);
	    var l = getPos( menuElem, "Left" ) - 200;
        //if it's a mac IE (missy)
	    if (navigator.appName.indexOf("Microsoft") != -1) {
	        var ww = parseInt(window.document.body.clientWidth) - 5;
	    } else { //else it's not, and likely netscape!(missy)
	        var ww = parseInt(window.innerWidth) - 20;
	    }
	    if (ww < (l + smw)) l = ww - smw;
	    var t = getPos( menuElem, "Top" ) - 16;
	    moveTo( subMenuElem, l, t );
	} else { //it's not a mac! do whatever the heck you want! (missy)
		subMenuElem = document.getElementById(subMenu);
		var mw = parseInt(menuElem.offsetWidth);
		var smw = parseInt(subMenuElem.offsetWidth);
		if ( smw <= mw ) subMenuElem.style.width = mw;
		var l = getPos( menuElem, "Left" ) - (subMenuElem.offsetWidth - menuElem.offsetWidth);
		var t = getPos( menuElem, "Top" ) + menuElem.offsetHeight;
	    moveTo( subMenuElem, l, t );
	}
	//menuElem.className = "menuOver";
	subMenuElem.className = "subMenuOver";
	showElement( subMenuElem );
}
function menuOut( menuElem, subMenu ) {
	subMenuElem = document.getElementById(subMenu);
	//menuElem.className = "menu";
	subMenuElem.className = "subMenu";
	hideElement( subMenuElem );
}
function subMenuItemOver( item ) {
	item.className = "subMenuItemOver";
}
function subMenuItemOut( item ) {
	item.className = "subMenuItem";
}
function scrollUp( holder, content ) {
	holder = document.getElementById(holder);
	content = document.getElementById(content);
	var t = content.style.top;
	t = t == "" ? 0 : parseInt(t);
	var h = content.offsetHeight;
	var maxh = parseInt(holder.style.height);
	if ( (t + h) > maxh )
		content.style.top = t - 10;
}
function scrollDown( holder, content ) {
	holder = document.getElementById(holder);
	content = document.getElementById(content);
	var t = content.style.top;
	t = t == "" ? 0 : parseInt(t);
	var h = content.offsetHeight;
	var maxh = parseInt(holder.style.height);
	window.status = "Max: " + maxh + ", h: " + h + ", c: " + (t + h);
	if ( t < 0 )
		content.style.top = t + 10;
}
function showElement( elem ) {
	elem.style.visibility = "visible";
}
function hideElement( elem ) {
	elem.style.visibility = "hidden";
}

// Show messages on the Status Bar.
function scrollit(seed,msg) {
	var out = " ";
	var c   = 1;
	if (seed > 100) {
		seed--;
		var cmd="scrollit(" + seed + ",'" + msg + "')";
		timerTwo=window.setTimeout(cmd,100);
	}
	else if (seed <= 100 && seed > 0) {
		for (c=0 ; c < seed ; c++) {
			out+=" ";
		}
		out+=msg;
		seed--;
		var cmd="scrollit(" + seed + ",'" + msg + "')";
		window.status=out;
		timerTwo=window.setTimeout(cmd,100);
	}
	else if (seed <= 0) {
		if (-seed < msg.length) {
			out+=msg.substring(-seed,msg.length);
			seed--;
			var cmd="scrollit(" + seed + ",'" + msg + "')";
			window.status=out;
			timerTwo=window.setTimeout(cmd,100);
		}
		else {
			window.status=" ";
			timerTwo=window.setTimeout("scrollit(100,'" + msg + "')",75);
		}
	}
}



/*
 * WebKit JavaScript utility functions.
 */
var didSubmitElement = false;

function WKCheckDate(elementName) {
    var f = WKGetElement(elementName);
	f.value = checkDate(f.value, "false");
	return false;
}

function WKUpdateElement(elementName, value) {
    var f = WKGetElement(elementName);
	f.value = checkDate(value, "false");
	return false;
}

function WKSelectElement(elementName) {
	var count = document.forms.length;
	for(var i = 0; i < count; i++) {
    var element = document.forms[i].elements[elementName] ;
		if (element != null) {
            element.focus();
            if (element.select)
                element.select();
		}
	}
	return false;
}

function WKClickElement(elementName) {
	var count = document.forms.length;
	for(var i = 0; i < count; i++) {
    var element = document.forms[i].elements[elementName] ;
		if (element != null) {
            element.focus();
            if (element.select)
                element.click();
		}
	}
	return false;
}

function WKSubmitElement(elementName) {
    if (didSubmitElement) return;
	var count = document.forms.length;
	for(var i = 0; i < count; i++) {
		if (document.forms[i].elements[elementName] != null) {
			document.forms[i].submit();
            didSubmitElement = true;
			return;
		}
	}
	return;
}

function WKGetElement(elementName) {
	var count = document.forms.length;
	for(var i = 0; i < count; i++) {
		var e = document.forms[i].elements[elementName];
		if (e != null) {
			return e;
		}
	}
	return null;
}

/*
 * WKCloseWindow ([closeAction], [closeAll])
 * Input: closeAction - the action for close window.
 *        closeAll - the flag for close all windows.
 */
function WKCloseWindow() {
//    var msg = "\nYou are going to exit this window\n\n" + "Are you shure to close this window??";
//    confirm(msg);
//    setTimeout(closeWindow(),5000);
	var thisWindow = self;
	var openerWindow = thisWindow.opener;
	if(openerWindow != null) {
		if(arguments[1] != null) {
			if(typeof openerWindow.ChildrenArray != 'undefined') {
				for(var i = 0; i < openerWindow.ChildrenArray.length; i++) {
					if(!(openerWindow.ChildrenArray[i].closed)) {
						openerWindow.ChildrenArray[i].close();
					}
				}
			} else {
				thisWindow.close();
			}
		} else {
			thisWindow.close();
		}
        openerWindow.focus();
		if(arguments[0] != null) {
			var closeAction = new Function(arguments[0]);
			closeAction();
		}
	} else {
        if(typeof thisWindow.ChildrenArray != 'undefined') {
            for(var i = 0; i < thisWindow.ChildrenArray.length; i++) {
                if(!(thisWindow.ChildrenArray[i].closed)) {
                    thisWindow.ChildrenArray[i].close();
                }
            }
        }
	}
}

/*
 * This function toggles the sort icon displayed by the WKFilterBar component
 */
function WKToggleFilterBarSortIcon(resourcesURL, fieldName, iconName) {
    var f = WKGetElement( fieldName );
    var i = document.images[ iconName ];
    if (f.value == 'A') {
        i.src = resourcesURL + 'WKDescending.gif';
        f.value = 'D';
    } else if (f.value == 'D') {
        i.src = resourcesURL + 'WKUnsorted.gif';
        f.value = 'N';
    } else {
        i.src = resourcesURL + 'WKAscending.gif';
        f.value = 'A';
    }
    return false;
}

/*
 * Show Description Func.
 */
function popUpDescr(evt, currElem, wi, hi) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        if (document.all) {
            docObj = "document.all.";
        } else {
            docObj = "document.";
        }
        popUpWin = eval(docObj + currElem);
    } else {
        popUpWin = document.getElementById(currElem);
    }
    popUpWin.style.width = wi;
    popUpWin.style.height = hi;
    if (document.all) {
        var y = parseInt(evt.y) + 2;
        var x = parseInt(evt.x) + 2;
    } else {
        var y = parseInt(evt.pageY) + 2;
        var x = parseInt(evt.pageX) + 2;
    }
    if (navigator.appName.indexOf("Microsoft") != -1) {
        var ww = parseInt(window.document.body.clientWidth) - 5;
    } else {
        var ww = parseInt(window.innerWidth) - 20;
    }
    var ow = parseInt(popUpWin.style.width);
    popUpWin.style.top = y;
    popUpWin.style.left = Math.min(x, ww - ow);
    popUpWin.style.visibility = "visible";
    window.status = "";
}
function popDownDescr(currElem) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        if (document.all) {
            docObj = "document.all.";
        } else {
            docObj = "document.";
        }
        popUpWin = eval(docObj + currElem);
    } else {
        popUpWin = document.getElementById(currElem);
    }
    popUpWin.style.visibility = "hidden";
}
function clickDescr(currElem) {
    if (navigator.appName.indexOf("Microsoft") != -1) {
        if (document.all) {
            docObj = "document.all.";
        } else {
            docObj = "document.";
        }
        popUpWin = eval(docObj + currElem + 'Action');
        popUpWin.click();
    } else {
        popUpWin = document.links[currElem + "Action"];
        window.location = popUpWin;
    }
}

/*
 * Menu for right mouse button (IE Only).
 */
function deru() {
    rightMouseMenuElem = document.getElementById("RightMouseMenu");
    var migi = document.body.clientWidth-event.clientX;
    var sita = document.body.clientHeight-event.clientY;
    if (migi < rightMouseMenuElem.offsetWidth) {
        rightMouseMenuElem.style.left = document.body.scrollLeft + event.clientX - rightMouseMenuElem.offsetWidth;
    } else {
        rightMouseMenuElem.style.left = document.body.scrollLeft + event.clientX;
    }
    if (sita < rightMouseMenuElem.offsetHeight) {
        rightMouseMenuElem.style.top = document.body.scrollTop + event.clientY - rightMouseMenuElem.offsetHeight;
    } else {
        rightMouseMenuElem.style.top = document.body.scrollTop + event.clientY;
        rightMouseMenuElem.style.visibility = "visible";
    }
    return false;
}
function omenu() {
    rightMouseMenuElem = document.getElementById("RightMouseMenu");
    rightMouseMenuElem.style.visibility = "hidden";
}
function scol(className, color, backgroundColor) {
    if (event.srcElement.className == className) {
        event.srcElement.style.backgroundColor = backgroundColor;
        event.srcElement.style.color = color;
    }
}
function ocol(className, color, backgroundColor) {
    if (event.srcElement.className == className) {
        event.srcElement.style.backgroundColor = backgroundColor;
        event.srcElement.style.color = color;
        window.status = "";
    }
}
function tu(className) {
    if (event.srcElement.className == className) {
        if (event.srcElement.getAttribute("target") != null) {
            window.open(event.srcElement.url, event.srcElement.getAttribute("target"));
        } else {
            window.location = event.srcElement.url;
        }
    }
}

/*
 * Add Bookmark.
 */
function AddBookmark(url, name) {
    window.external.AddFavorite(url, name)
}

/*
 * This is for Hola.
 */
function commaFormat(number) {
   originalStr = String(number);
   if (originalStr == "") originalStr = String("0");
   commaStr = "";
   for (i=originalStr.length - 3; i>0; i -= 3) {
       commaStr = "," + originalStr.substring(i,i + 3) + commaStr;
   }
   reminder = originalStr.substring(0, i + 3);
   return reminder + commaStr;
}

function dollarFormat(aField) {
   var number = String(aField.value.replace(/[^0123456789.]/g,""));
   var intPart = String(number.match(/\d*/));
   var decPart = String(number.replace(/\d*/,"").replace(/\./g,"") + "00");
   aField.value = "$" + commaFormat(intPart) + "." + decPart.substring(0,2);
}

/*
 * formatCurrency(value [,message [,field]])
 *
 * Input: value - the value portin of the textfield or textarea (i.e this.value)
 *        message (optional) - displays this message if the amount is invalid
 *        field  (optional) - refocus to this field is the amount is invalue
 *
 * Output: return the field as format currency (i.e. $9,999.99)
 *
 * Use: this.value = formatCurrency(this.value, 'This is an incorrect amount')
 *
 * Notes: Use field parameter with cation. It may cause infinite looping
 */
function formatCurrency(ogValue){
  var negative = false;
  var cents = ".00";
  var decOffset;
  var dollars = 0;

  //returns zeros if field is empty
  if (ogValue==null){
	return "$0.00";
  }

  //insures that amount is a string
  amount=ogValue.toString();

  //removes currency formatting
  amount = stripCurrency(amount);
  if (isValidFormat("^-?\\d*\\.?\\d*$", amount)){
	if ( amount.charAt(0) == '-'){
	  negative=true;
	  amount = amount.substring(1);
	}

	// extract decimal part of number
	decOffset = amount.indexOf(".");
	if (decOffset != -1){
	  cents = amount.substring(decOffset,decOffset+2);
	  //validate decPart and foramt decimal
	  while (cents.length < 3){
		cents += "0";
	  }
	}

	// extract dollars
	if (decOffset != -1)
	  {dollars = amount.substring(0,decOffset)}
	else
	  {dollars = amount}

	// insert commas in wholeAmount
	var flen=dollars.length;
	for (var i=(flen-3); i>0; i-=3 ){
	  dollars = dollars.substring(0,i) + "," + dollars.substring(i,flen++);
	}

	// put it all back together
	if (negative)
	  {amount = "(" + "$" + dollars + cents + ")"}
	else
	  {amount = "$" + dollars + cents }
	return amount;
  }
  else{
	if (arguments[1] != null)
		alert(arguments[1]);
	else
		alert("You have entered an invalid dollar amount.");

	if (arguments[2] != null)
		arguments[2].focus();
	return ogValue;
  }
}

/*
 * checkdate(value [,flag [,field [,message]]])
 *
 * Input: value - the value portin of the textfield or textarea (i.e this.value)
 *        flag  (optional) - return without invalid messages.
 *        field  (optional) - refocus to this field is the amount is invalue
 *        message (optional) - displays this message if the amount is invalid
 *
 * Output: return the field as format date (i.e. 99/99/9999)
 *
 * Usaage: this.value = checkDate(this.value)
 *
 * Notes: Use field parameter with cation. It may cause infinite looping
 */
function checkDate(field){
	//******Cut off Date*******//
	var y2kCut = 70

	var formated_date
	var month
	var day
	var year

	//makes sure variable is a string
	field = field.toString()

	if (field.length > 0){

		//parses month day and year when enter in 'mm/dd/yyyy' format
		//fisrt occurence of '/'
		var indexf1 = field.indexOf('/')
		var indexf2 = field.indexOf('-')

		// M/D/Y
		if (indexf1 > -1) {  //parse date string
			month = field.substring(0,indexf1)
			var index2 = field.indexOf('/', (indexf1+=1) )
			day = field.substring(indexf1,index2)
			year = field.substring((index2+=1),field.length)
		}
		// M-D-Y
		else if (indexf2 > -1) {  //parse date string
			month = field.substring(0,indexf2)
			var index2 = field.indexOf('-', (indexf2+=1) )
			day = field.substring(indexf2,index2)
			year = field.substring((index2+=1),field.length)
		}
		//invalid format
		else {
			if (arguments[1] != null)
				return field

			if (arguments[3] != null)
				alert(arguments[3]);
			else
				alert ("Date must be in the form 'mm/dd/yyyy'.")

			if (arguments[2] != null)
				arguments[2].focus();

			return field
		}

		//pad month and day with zeros
		if ( (month.valueOf() < 10) && (month.length < 2) )
			month = "0" + month
		if ( (day.valueOf() < 10) && (day.length < 2) )
			day = "0" + day
		//convert year to 2000 if > 70 and 1900 if < 70
		if ( (year.valueOf() < 10) && (year.length < 2) )
			year = "0" + year
		if ( (year.valueOf() < 100) && (year.valueOf() > y2kCut) )
			year = "19" + year
		else if (year.valueOf() < 100)
			year= "20" + year

		//verify date before returing
		formated_date = month + "/" + day + "/" + year
		if(!isValidFormat("^\\d\\d/\\d\\d/\\d\\d\\d\\d$",formated_date)){
			if (arguments[1] != null)
				return field

			if (arguments[3] != null)
				alert(arguments[3]);
			else
				alert ("Date must be in the form 'mm/dd/yyyy'.")

			if (arguments[2] != null)
				arguments[2].focus();

			return field
		}
		return formated_date
	}
	return field
}

/*******************************************
 *NEW FUNCTIONS                            *
 *******************************************/
function newWindow(url, windowName,windowArgs,currentRow){
   	winHandle = open(url, windowName, windowArgs);
    winHandle.focus();
	highlightRowUp(currentRow);
}

/*******************************************
 *Private functions                        *
 *******************************************/
function isValidFormat(regExp,str){
  _regExp = new RegExp(regExp, "i")
  if (str.match(_regExp) == null)
	return false
  else
	return true
}

function stripCurrency(amount){
  var negative = false

  //strips off dollar sign
  indexDollar = amount.indexOf("$")
  if (indexDollar != -1) {
	amount = amount.substring(0,indexDollar) + amount.substring(indexDollar+1,amount.length)
  }

  //left bracket indicate number is negitive
  if (amount.substring(0,1) == "(") {
	amount = amount.substring(1,amount.length)
	negative = true
  }
  //right bracket, doesn't indicate negitive number
  if (amount.substring(amount.length-1,amount.length) == ")") {
	  amount = amount.substring(0,amount.length-1)
  }

  //strips off commas
  index = amount.indexOf(',')
  while (index != -1){
	amount = amount.substring(0,index) + amount.substring(index+1,amount.length)
	index = amount.indexOf(',')
  }

  if (negative){
	amount = '-' + amount
  }

  return amount
}


/***************************************
 * Unused functions                    *
 ***************************************/
function checkField(mask,field, msg){
  if (!isValidFormat(mask,field)){
	alert(msg);
		return false
  }
	return true
}



/*
 * WebKit JavaScript calendar functions.
 */
    var resourcesURL = '/WebObjects/Frameworks/WWWKit.framework/WebServerResources/';
    var weekend = [0,6];
    var weekendColor = "#F1F3F3";
    var fontface = "Verdana";
    var fontsize = 2;

    var gNow = new Date();
    var ggWinCal;
    isNav = (navigator.appName.indexOf("Netscape") != -1) ? true : false;
    isIE = (navigator.appName.indexOf("Microsoft") != -1) ? true : false;

    Calendar.Months = ["January", "February", "March", "April", "May", "June",
    "July", "August", "September", "October", "November", "December"];


    Calendar.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];

    Calendar.lDOMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];


    function Calendar(p_item, p_WinCal, p_month, p_year, p_format) {
        if ((p_month == null) && (p_year == null))	return;

        if (p_WinCal == null)
            this.gWinCal = ggWinCal;
        else
            this.gWinCal = p_WinCal;

        if (p_month == null) {
            this.gMonthName = null;
            this.gMonth = null;
            this.gYearly = true;
        } else {
            this.gMonthName = Calendar.get_month(p_month);
            this.gMonth = new Number(p_month);
            this.gYearly = false;
        }

        this.gYear = p_year;
        this.gFormat = p_format;
        this.gBGColor = "white";
        this.gFGColor = "black";
        this.gTextColor = "black";
        this.gHeaderColor = "black";
        this.gReturnItem = p_item;
    }

    Calendar.get_month = Calendar_get_month;
    Calendar.get_daysofmonth = Calendar_get_daysofmonth;
    Calendar.calc_month_year = Calendar_calc_month_year;
    Calendar.print = Calendar_print;

    function Calendar_get_month(monthNo) {
        return Calendar.Months[monthNo];
    }

    function Calendar_get_daysofmonth(monthNo, p_year) {

        if ((p_year % 4) == 0) {
            if ((p_year % 100) == 0 && (p_year % 400) != 0)
                return Calendar.DOMonth[monthNo];

            return Calendar.lDOMonth[monthNo];
        } else
            return Calendar.DOMonth[monthNo];
    }

    function Calendar_calc_month_year(p_Month, p_Year, incr) {

        var ret_arr = new Array();

        if (incr == -1) {

            if (p_Month == 0) {
                ret_arr[0] = 11;
                ret_arr[1] = parseInt(p_Year) - 1;
            }
            else {
                ret_arr[0] = parseInt(p_Month) - 1;
                ret_arr[1] = parseInt(p_Year);
            }
        } else if (incr == 1) {

            if (p_Month == 11) {
                ret_arr[0] = 0;
                ret_arr[1] = parseInt(p_Year) + 1;
            }
            else {
                ret_arr[0] = parseInt(p_Month) + 1;
                ret_arr[1] = parseInt(p_Year);
            }
        }

        return ret_arr;
    }

    function Calendar_print() {
        ggWinCal.print();
    }

    function Calendar_calc_month_year(p_Month, p_Year, incr) {

        var ret_arr = new Array();

        if (incr == -1) {

            if (p_Month == 0) {
                ret_arr[0] = 11;
                ret_arr[1] = parseInt(p_Year) - 1;
            }
            else {
                ret_arr[0] = parseInt(p_Month) - 1;
                ret_arr[1] = parseInt(p_Year);
            }
        } else if (incr == 1) {

            if (p_Month == 11) {
                ret_arr[0] = 0;
                ret_arr[1] = parseInt(p_Year) + 1;
            }
            else {
                ret_arr[0] = parseInt(p_Month) + 1;
                ret_arr[1] = parseInt(p_Year);
            }
        }

        return ret_arr;
    }


    new Calendar();

    Calendar.prototype.getMonthlyCalendarCode = function() {
        var vCode = "";
        var vHeader_Code = "";
        var vData_Code = "";


        vCode = vCode + "<TABLE BORDER=0 style='margin-top: 4; border: 2 solid #8CA6CE'>";

        vHeader_Code = this.cal_header();
        vData_Code = this.cal_data();
        vCode = vCode + vHeader_Code + vData_Code;

        vCode = vCode + "</TABLE>";

        return vCode;
    }

    Calendar.prototype.show = function() {
        var vCode = "";

        this.gWinCal.document.open();


        this.wwrite("<html>");
        this.wwrite("<head><title>Select Date</title>");
        this.wwrite("<link rel='stylesheet' type='text/css' href='" + resourcesURL + "WKCalendar.css'/>");
        this.wwrite("</head>");

        this.wwrite("<body topmargin='8' leftmargin='8'" +
            "link=\"" + this.gLinkColor + "\" " +
            "vlink=\"" + this.gLinkColor + "\" " +
            "alink=\"" + this.gLinkColor + "\" " +
            "text=\"" + this.gTextColor + "\">");



        var prevMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, -1);
        var prevMM = prevMMYYYY[0];
        var prevYYYY = prevMMYYYY[1];

        var nextMMYYYY = Calendar.calc_month_year(this.gMonth, this.gYear, 1);
        var nextMM = nextMMYYYY[0];
        var nextYYYY = nextMMYYYY[1];

        this.wwriteA("<FONT FACE='" + fontface + "' SIZE=2><B>");
        this.wwriteA("<img border='0' src='" + resourcesURL + "WKCalendar.gif' />");
        this.wwriteA("&nbsp;&nbsp;");
        this.wwriteA(this.gMonthName + " " + this.gYear);
        this.wwriteA("</B><BR>");

        vCode = this.getMonthlyCalendarCode();
        this.wwrite(vCode);

        this.wwrite("<TABLE WIDTH='100%' BORDER=0 CELLSPACING=2 CELLPADDING=0><TR><TD ALIGN=center nowrap>");

        this.wwrite("<A HREF=\"" +
                "javascript:window.opener.Build(" +
                "'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)-1) + "', '" + this.gFormat + "'" +
                ");" +
                "\">" +
                "<img border='0' src='" + resourcesURL + "WKPreviousBatch.gif' title='Previous Year' style='margin-left: 0; margin-right: -5' />" +
                "<img border='0' src='" + resourcesURL + "WKPreviousBatch.gif' title='Previous Year' />" +
                "</A></TD><TD ALIGN=center nowrap>");
            this.wwrite("<A HREF=\"" +
                "javascript:window.opener.Build(" +
                "'" + this.gReturnItem + "', '" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "'" +
                ");" +
                "\">" +
                "<img border='0' src='" + resourcesURL + "WKPreviousBatch.gif' title='Previous Month' />" +
                "</A></TD><TD ALIGN=center width='35%' nowrap>");
            this.wwrite("<A HREF=\"javascript:window.print();\"></A></TD><TD ALIGN=center>");
            this.wwrite("<A HREF=\"" +
                "javascript:window.opener.Build(" +
                "'" + this.gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "'" +
                ");" +
                "\">" +
                "<img border='0' src='" + resourcesURL + "WKNextBatch.gif' title='Next Month'/>" +
                "</A></TD><TD ALIGN=center nowrap>");
            this.wwrite("<A HREF=\"" +
                "javascript:window.opener.Build(" +
                "'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)+1) + "', '" + this.gFormat + "'" +
                ");" +
                "\">" +
                "<img border='0' src='" + resourcesURL + "WKNextBatch.gif' title='Next Year' style='margin-left: 0; margin-right: -5' />" +
                "<img border='0' src='" + resourcesURL + "WKNextBatch.gif' title='Next Year' />" +
                "<\/A></TD></TR></TABLE><BR>");

        this.wwrite("</font></body></html>");
        this.gWinCal.document.close();
    }

    Calendar.prototype.showY = function() {
        var vCode = "";
        var i;
        var vr, vc, vx, vy;
        var vxf = 285;
        var vyf = 200;
        var vxm = 10;
        var vym;
        if (isIE)	vym = 75;
        else if (isNav)	vym = 25;

        this.gWinCal.document.open();

        this.wwrite("<html>");
        this.wwrite("<head><title>Calendar</title>");
        this.wwrite("<style type='text/css'>\n<!--");
        for (i=0; i<12; i++) {
            vc = i % 3;
            if (i>=0 && i<= 2)	vr = 0;
            if (i>=3 && i<= 5)	vr = 1;
            if (i>=6 && i<= 8)	vr = 2;
            if (i>=9 && i<= 11)	vr = 3;

            vx = parseInt(vxf * vc) + vxm;
            vy = parseInt(vyf * vr) + vym;

            this.wwrite(".lclass" + i + " {position:absolute;top:" + vy + ";left:" + vx + ";}");
        }
        this.wwrite("-->\n</style>");
        this.wwrite("</head>");

        this.wwrite("<body " +
            "link=\"" + this.gLinkColor + "\" " +
            "vlink=\"" + this.gLinkColor + "\" " +
            "alink=\"" + this.gLinkColor + "\" " +
            "text=\"" + this.gTextColor + "\">");
        this.wwrite("<FONT FACE='" + fontface + "' SIZE=2><B>");
        this.wwrite("Year : " + this.gYear);
        this.wwrite("</B><BR>");

        var prevYYYY = parseInt(this.gYear) - 1;
        var nextYYYY = parseInt(this.gYear) + 1;

        this.wwrite("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0><TR><TD ALIGN=center>");
        this.wwrite("[<A HREF=\"" +
            "javascript:window.opener.Build(" +
            "'" + this.gReturnItem + "', null, '" + prevYYYY + "', '" + this.gFormat + "'" +
            ");" +
            "\" alt='Prev Year'><<<\/A>]</TD><TD ALIGN=center>");
        this.wwrite("[<A HREF=\"javascript:window.print();\"></A>]</TD><TD ALIGN=center>");
        this.wwrite("[<A HREF=\"" +
            "javascript:window.opener.Build(" +
            "'" + this.gReturnItem + "', null, '" + nextYYYY + "', '" + this.gFormat + "'" +
            ");" +
            "\">>><\/A>]</TD></TR></TABLE><BR>");

        var j;
        for (i=11; i>=0; i--) {
            if (isIE)
                this.wwrite("<DIV ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");
            else if (isNav)
                this.wwrite("<LAYER ID=\"layer" + i + "\" CLASS=\"lclass" + i + "\">");

            this.gMonth = i;
            this.gMonthName = Calendar.get_month(this.gMonth);
            vCode = this.getMonthlyCalendarCode();
            this.wwrite("TEST");
            this.wwrite(this.gMonthName + "/" + this.gYear + "<BR>");
            this.wwrite(vCode);

            if (isIE)
                this.wwrite("</DIV>");
            else if (isNav)
                this.wwrite("</LAYER>");
        }

        this.wwrite("</font><BR></body></html>");
        this.gWinCal.document.close();
    }

    Calendar.prototype.wwrite = function(wtext) {
        this.gWinCal.document.writeln(wtext);
    }

    Calendar.prototype.wwriteA = function(wtext) {
        this.gWinCal.document.write(wtext);
    }

    Calendar.prototype.cal_header = function() {
        var vCode = "";

        vCode = vCode + "<TR class='tableHeaderRow'>";
        vCode = vCode + "<TD WIDTH='14%'>Sun</TD>";
        vCode = vCode + "<TD WIDTH='14%'>Mon</TD>";
        vCode = vCode + "<TD WIDTH='14%'>Tue</TD>";
        vCode = vCode + "<TD WIDTH='14%'>Wed</TD>";
        vCode = vCode + "<TD WIDTH='14%'>Thu</TD>";
        vCode = vCode + "<TD WIDTH='14%'>Fri</TD>";
        vCode = vCode + "<TD WIDTH='16%'>Sat</TD>";
        vCode = vCode + "</TR>";

        return vCode;
    }

    Calendar.prototype.cal_data = function() {
        var vDate = new Date();
        vDate.setDate(1);
        vDate.setMonth(this.gMonth);
        vDate.setFullYear(this.gYear);

        var vFirstDay=vDate.getDay();
        var vDay=1;
        var vLastDay=Calendar.get_daysofmonth(this.gMonth, this.gYear);
        var vOnLastDay=0;
        var vCode = "";


        vCode = vCode + "<TR>";
        for (i=0; i<vFirstDay; i++) {
            vCode = vCode + "<TD WIDTH='14%' " + "><FONT SIZE='2' FACE='" + fontface + "'> </FONT></TD>";
        }

        for (j=vFirstDay; j<7; j++) {
            vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + " bgcolor='#E7EFF7'><FONT SIZE='2' FACE='" + fontface + "'>" +
                "<A HREF='#' " +
                    "onClick=\"self.opener.WKUpdateElement('" + this.gReturnItem + "','" +
                    this.format_data(vDay) +
                    "');window.close();\">" +
                    this.format_day(vDay) +
                "</A>" +
                "</FONT></TD>";
            vDay=vDay + 1;
        }
        vCode = vCode + "</TR>";

        for (k=2; k<7; k++) {
            vCode = vCode + "<TR>";

            for (j=0; j<7; j++) {
                vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + " bgcolor='#E7EFF7'><FONT SIZE='2' FACE='" + fontface + "'>" +
                "<A HREF='#' " +
                    "onClick=\"self.opener.WKUpdateElement('" + this.gReturnItem + "','" +
                    this.format_data(vDay) +
                    "');window.close();\">" +
                    this.format_day(vDay) +
                "</A>" +
                    "</FONT></TD>";
                vDay=vDay + 1;

                if (vDay > vLastDay) {
                    vOnLastDay = 1;
                    break;
                }
            }

            if (j == 6)
                vCode = vCode + "</TR>";
            if (vOnLastDay == 1)
                break;
        }

        for (m=1; m<(7-j); m++) {
            if (this.gYearly)
                vCode = vCode + "<TD WIDTH='14%' bgcolor='white'" + this.write_weekend_string(j+m) +
                "><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'> </FONT></TD>";
            else
                vCode = vCode + "<TD WIDTH='14%' bgcolor='white'" + this.write_weekend_string(j+m) +
                "><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'>" + m + "</FONT></TD>";
        }

        return vCode;
    }

    Calendar.prototype.format_day = function(vday) {
        var vNowDay = gNow.getDate();
        var vNowMonth = gNow.getMonth();
        var vNowYear = gNow.getFullYear();

        if (vday == vNowDay && this.gMonth == vNowMonth && this.gYear == vNowYear)
            return ("<FONT COLOR=\"RED\"><B>" + vday + "</B></FONT>");
        else
            return (vday);
    }

    Calendar.prototype.write_weekend_string = function(vday) {
        var i;

        for (i=0; i<weekend.length; i++) {
            if (vday == weekend[i])
                return (" bgcolor=\"" + "#F1F3F3" + "\"");
        }

        return "";
    }

    Calendar.prototype.format_data = function(p_day) {
        var vData;
        var vMonth = 1 + this.gMonth;
        vMonth = (vMonth.toString().length < 2) ? "0" + vMonth : vMonth;
        var vMon = Calendar.get_month(this.gMonth).substr(0,3).toUpperCase();
        var vFMon = Calendar.get_month(this.gMonth).toUpperCase();
        var vY4 = new String(this.gYear);
        var vY2 = new String(this.gYear.substr(2,2));
        var vDD = (p_day.toString().length < 2) ? "0" + p_day : p_day;

        switch (this.gFormat) {
            case "MM\/DD\/YYYY" :
                vData = vMonth + "\/" + vDD + "\/" + vY4;
                break;
            case "MM\/DD\/YY" :
                vData = vMonth + "\/" + vDD + "\/" + vY2;
                break;
            case "MM-DD-YYYY" :
                vData = vMonth + "-" + vDD + "-" + vY4;
                break;
            case "MM-DD-YY" :
                vData = vMonth + "-" + vDD + "-" + vY2;
                break;

            case "DD\/MON\/YYYY" :
                vData = vDD + "\/" + vMon + "\/" + vY4;
                break;
            case "DD\/MON\/YY" :
                vData = vDD + "\/" + vMon + "\/" + vY2;
                break;
            case "DD-MON-YYYY" :
                vData = vDD + "-" + vMon + "-" + vY4;
                break;
            case "DD-MON-YY" :
                vData = vDD + "-" + vMon + "-" + vY2;
                break;

            case "DD\/MONTH\/YYYY" :
                vData = vDD + "\/" + vFMon + "\/" + vY4;
                break;
            case "DD\/MONTH\/YY" :
                vData = vDD + "\/" + vFMon + "\/" + vY2;
                break;
            case "DD-MONTH-YYYY" :
                vData = vDD + "-" + vFMon + "-" + vY4;
                break;
            case "DD-MONTH-YY" :
                vData = vDD + "-" + vFMon + "-" + vY2;
                break;

            case "DD\/MM\/YYYY" :
                vData = vDD + "\/" + vMonth + "\/" + vY4;
                break;
            case "DD\/MM\/YY" :
                vData = vDD + "\/" + vMonth + "\/" + vY2;
                break;
            case "DD-MM-YYYY" :
                vData = vDD + "-" + vMonth + "-" + vY4;
                break;
            case "DD-MM-YY" :
                vData = vDD + "-" + vMonth + "-" + vY2;
                break;

            default :
                vData = vMonth + "\/" + vDD + "\/" + vY4;
        }

        return vData;
    }

    function Build(p_item, p_month, p_year, p_format) {
        var p_WinCal = ggWinCal;
        gCal = new Calendar(p_item, p_WinCal, p_month, p_year, p_format);

        gCal.gBGColor="blue";
        gCal.gLinkColor="black";
        gCal.gTextColor="green";
        gCal.gHeaderColor="green";

        if (gCal.gYearly)	gCal.showY();
        else	gCal.show();
    }

    function show_calendar() {

        p_item = arguments[0];
        if (arguments[1] == null)
            p_month = new String(gNow.getMonth());
        else
            p_month = arguments[1];
        if (arguments[2] == "" || arguments[2] == null)
            p_year = new String(gNow.getFullYear().toString());
        else
            p_year = arguments[2];
        if (arguments[3] == null)
            p_format = "MM/DD/YYYY";
        else
            p_format = arguments[3];
        if (arguments[4] != null)
            resourcesURL = arguments[4];

        vWinCal = window.open("#", "Calendar",
            "width=250,height=215,status=no,resizable=no,top=200,left=200");
        vWinCal.opener = self;
        ggWinCal = vWinCal;

        vWinCal.focus();

        Build(p_item, p_month, p_year, p_format);
    }

    function show_yearly_calendar(p_item, p_year, p_format) {
        if (p_year == null || p_year == "")
            p_year = new String(gNow.getFullYear().toString());
        if (p_format == null || p_format == "")
            p_format = "MM/DD/YYYY";

        vWinCal = window.open("#", "Calendar", "scrollbars=yes");
        vWinCal.opener = self;
        ggWinCal = vWinCal;

        vWinCal.focus();

        Build(p_item, null, p_year, p_format);
    }
