var activEditTags = new Array();
var activEditMaxLength = new Array();
var activEditCount = 0;

var formTags = new Array();
var formValidateType = new Array();
var formCount = 0;



/**
 * validate that the value is formatted as a telephone correctly
 * This pattern matches any US Telephone Number.
 * This regular expression excludes the first number, after the area code,from being 0 or 1;
 * it also allows an extension to be added where it does not have to be prefixed by 'x'.
 *
 * Matches: 
 * 617.219.2000 
 * 219-2000
 * (617)283-3599 x234
 * 1(222)333-4444
 * 1 (222) 333-4444
 * 222-333-4444
 * 1-222-333-4444
 * Non-Matches: 
 * 44-1344-458606
 * +44-1344-458606
 * +34-91-397-6611
 * 7-095-940-2000
 * +7-095-940-2000
 * +49-(0)-889-748-5516
*/
function CheckPhone(value, required)
{
	//trim whitespace before we validate
  value = value.replace(/^\s+/,'').replace(/\s+$/,'');

  if(required)
  {
    if( value.length == 0 )
    {
        return false;
    }
  }
  else {
    if( value.length == 0 )
    {
        return true;
    }
  }

	if (value.length == 0)
		return true;		

	return CheckRegEx(value, /^(((1))?[ ,\-,\.]?([\\(]?([1-9][0-9]{2})[\\)]?))?[ ,\-,\.]?([^0-1]){1}([0-9]){2}[ ,\-,\.]?([0-9]){4}(( )((x){0,1}([0-9]){1,5}){0,1})?$/, required);
}

/**
 * validate that the value is formatted as a USA zipcode correctly
 *
 * This pattern will match any us zip code
 * matches: 12345, 12345-1234
 */
function CheckZip(objectvalue, required)
{
	//trim whitespace before we validate
    objectvalue = objectvalue.replace(/^\s+/,'').replace(/\s+$/,'');

    if( required )
    {
        if( objectvalue.length == 0 )
        {
            return false;
        }
    }else{
        if( objectvalue.length == 0 )
        {
            return true;
        }
    }

	return CheckRegEx(objectvalue, /^([0-9]){5,5}$|(([0-9]){5,5}(-| ){1}([0-9]){4,4}$)/, required);
}


function CheckRegEx(objectvalue, regexPattern, required)
{
    if( required )
    {
        if( objectvalue.length == 0 )
        {
            return false;
        }
    }else{
        if( objectvalue.length == 0 )
        {
            return true;
        }
    }

	return regexPattern.test(objectvalue);
}


function ValidatePhone(object, required, message)
{
  if (! CheckPhone(object.value, required))
	{
	  if (object.value.length > 0 || required)
		{
		  alert(message);
			object.value = '';
			object.focus();
			return false;
		}
	}

	return true;
}


function CompareFields(id1, id2, message)
{

  try {
    object1 = document.getElementById(id1);
    object2 = document.getElementById(id2);

    if (object1.defaultValue != object1.value && object1.value != object2.value)
    {
      alert (message);
      object1.value = '';
      object2.value = '';
      object1.focus();
      return false;
    }
  }
  catch (E) {
  }
  
	return true;
}

function ShowSection(group,id) {

 nextId = document.getElementById(id);
 while(nextId != null) {
   if (nextId.id == id) {
     if (nextId.group == group) { 
       nextId.style.display=id;
     }
   }
   nextId = nextId.nextSibling;
 }
}

function HideSection(group, id) {

 nextId = document.getElementById(id);

 while(nextId != null) {
   if (nextId.id == id) {
     if (nextId.group == group) { 
       nextId.style.display='none';
     }
   }
   nextId = nextId.nextSibling;
 }
}

function ChangeAddlParms(object, tablename)
{
	var ParmList;
	var ParmValueList;
	var currentParmValueList;
	var arrayList = new Array("","","","","");
	var arrayValueList = new Array("","","","","");
	var currentarrayValueList = new Array("","","","","");
	var myObj;
	var myObjVal;
	var valueflag;
	var currentvalueflag;

  valueflag = 0;
  currentvalueflag = 0;

	try {
		ParmList = eval('sptid' + object.value);

		try {
		   		ParmValueList = eval('sptidv' + object.value);

		   		try {
		   		  currentParmValueList = eval('current' + object.value);
      		}
      		catch(error) {
      		  currentvalueflag = 1;
       		}
		}
		catch(error) {
		  valueflag = 1;

		}
	}
	catch(e) {

      for (j=1;j<6;j++)
      {
				myObj = document.getElementById(tablename + '-cAddlParmList-' + j.toString());
				myObjVal = document.getElementById(tablename + '-cAddlParmValueList-' + j.toString());

				if (myObj != null)
				{
				  myObj.value = '';
				  myObjVal.value = '';
					SetReadOnly(myObj.id,true);
					SetReadOnly(myObjVal.id,true);
				}
    	}
	}

  if (ParmList.length > 0) {

	  arrayList = ParmList.split(',');
  }
	arrayValueList = ParmValueList.split(',');

	if (currentParmValueList != null) {

	  currentarrayValueList = currentParmValueList.split(',');

	}

  for (j=1;j<6;j++)
  {
		myObj = document.getElementById(tablename + '-cAddlParmList-' + j.toString());
		myObjVal = document.getElementById(tablename + '-cAddlParmValueList-' + j.toString());
		if (myObj != null)
		{


		  if (arrayValueList[j - 1] != null)
		    arrayValueList[j - 1] = trim(arrayValueList[j - 1]);
      else
        arrayValueList[j - 1] = '';


			if (arrayList[j - 1] != null && arrayList[j - 1].length > 0)
			{
			  myObj.value = arrayList[j - 1];
			  if (currentvalueflag != 1) {
			    myObjVal.value = currentarrayValueList[j - 1];
			  }
				else if (valueflag != 1) {
			    myObjVal.value = arrayValueList[j - 1];

			  }
			 //myObjVal.value = '';
			  SetReadOnly(myObj.id,true);
			  if (valueflag != 1)
			  {
			    if (arrayValueList[j - 1] == 0)
		        SetReadOnly(myObjVal.id,false);
		      else
		        SetReadOnly(myObjVal.id,arrayValueList[j - 1].length != 0);
		    }
		    else
			    SetReadOnly(myObjVal.id,false);

			}
			else
			{
			  myObj.value = '';
			  myObjVal.value = '';
			  SetReadOnly(myObj.id,true);
			  SetReadOnly(myObjVal.id,true);
			}
		}
	}

}

function trim(sString)
{

    while (sString.substring(0,1) == ' ')
    {
    sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
    sString = sString.substring(0,sString.length-1);
    }
  return sString;
}


function RefreshParentWindow()
{
	window.opener.location.reload(); 
}

function CloseWindow()
{
	window.close(); 
}


function ResetForm(form)
{
 form.reset();
 ResetCheckBox(form);
 SetFocus(form);
}

function ResetCheckBox(form)
{
  var j;
  var obj;
	var tagparts;
	var tagname;

  for (j=0;j<form.length;j++)
	{
	  if (form.elements[j].type == 'checkbox')
		{
			try {
			  tagparts = form.elements[j].name.split("-");
				if (tagparts.length == 2)
				{
					tagname = tagparts[0] + '-' + tagparts[1].substring(0,tagparts[1].indexOf("Dummy"));

					SetCheckedValue(form, tagname, '');
				}
				else if (tagparts.length == 3)
				{
					tagname = tagparts[0] + '-' + tagparts[1].substring(0,tagparts[1].indexOf("Dummy"));

					SetCheckedValue(form, tagname, "-" + tagparts[2]);
				}
			}
			catch(e) {

			  alert('Error Thrown in ResetCheckBox on object (' + form.elements[j].name);
			}

		}
	}

	return true;
}

function AddActivEditTagToValidate(tagName,maxLength)
{
	activEditTags[activEditCount] = tagName;
	activEditMaxLength[activEditCount] = maxLength;
  activEditCount++;

}

function ValidateActivEditTags()
{
  var FCKInstance;

  for (j=0; j < activEditCount;j++)
	{
	  try
		{
			FCKInstance = FCKeditorAPI.GetInstance(activEditTags[j]);
			FCKInstance.UpdateLinkedField();

			if (document.getElementById(activEditTags[j]).value.length > activEditMaxLength[j])
			{
				alert ('The Maximum length of Data allowed in editor is ' + activEditMaxLength[j] + ', there is ' + document.all.item(activEditTags[j]).value.length + ' characters.');
				alert ('Please restrict the number of characters to ' + activEditMaxLength[j]);
				return false;
			}

		}
		catch (e)
		{

		}
	}

	return true;

}

function AddFormTagToValidate(id, validateType)
{
	formTags[formCount] = id;
	formValidateType[formCount] = validateType;
  formCount++;        
}

function ValidateFormTags()
{
  var tagInstance;
	
  for (j=0; j < formCount;j++)
	{
	  try
		{
			tagInstance = document.getElementById(formTags[j]);
		
			if (formValidateType[j] == 1)
			{
				if (! checkdate(tagInstance.value, true))
				{
					alert ('Field requires a valid DATE.');
					tagInstance.focus();
				  return false;
				}
			}
			else if (formValidateType[j] == 2)
			{
				if (! checkinteger(tagInstance.value, true))
				{
					alert ('Field requires a valid INTEGER.');
					tagInstance.focus();
				  return false;
				}
			}
			else if (formValidateType[j] == 3)
			{
				if (! ValidateNotBlank(tagInstance, 'Field is required.  Please do not leave BLANK.'))
				{
					tagInstance.focus();
				  return false;
				}
			}
			else if (formValidateType[j] == 4)
			{
				if (! CheckPhone(tagInstance.value, true))
				{
					alert('Field is required and must conform to a valid phone format.');
					tagInstance.focus();
				  return false;
				}
			}
			
		}
		catch (e)
		{

		}
	}

	return true;

}


function imgRollImage (obj, src)
{
  obj.src = src;
}

function BlankIfZero(me, obj, readonly)
{
  if (! me.checked)
	{
		if (obj.type == 'checkbox')
			obj.checked = false;
		else
		 	obj.value = '';

		if (readonly != null)
			obj.disabled = true;
	}
	else if (readonly != null)
			obj.disabled = false;
}

function ZeroIfZero(me, obj)
{
  if (! me.checked)
	{
	 	obj.value = '0';

	}
}


function ShowTab(tabnumber) {
	try {
	ShowDiv('tab'+tabnumber.toString());
  	document.getElementById('link'+tabnumber.toString()).style.backgroundColor = "#E8E2DF";
  	document.getElementById('link'+tabnumber.toString()).style.color = "#000000";

  }
  catch(e)
  {
  }
}

function HideTab(tabnumber) {

	try {
	HideDiv('tab'+tabnumber.toString());
  	document.getElementById('link'+tabnumber.toString()).style.backgroundColor = "#aaaaaa";
  	document.getElementById('link'+tabnumber.toString()).style.color = "#E8E2DF";
	}
	catch(e)
	{
	}
}


function ShowDiv(tid) {
	try {
  	document.getElementById(tid).style.display = "";

  }
  catch(e)
  {
  }
}

function HideDiv(tid) {

	try {
		document.getElementById(tid).style.display = "none";
	}
	catch(e)
	{
	}
}

function SelectData ()
{
  var obj;
  var regex = new RegExp(String.fromCharCode(250),'g');

  for (j=0;j<arguments.length;j+=2)
	{

		if (arguments[j] != null)
		{
		  try {
			  try{
				  obj = window.opener.document.getElementById(arguments[j]);
				}
				catch(error)
				{
				  obj = window.opener.document.all.item(arguments[j]);

				}

  		  obj.value = arguments[j+1].replace(regex,"'");

				if (obj.onChange != null)
				{
					eval(obj.onChange);
				}
			}
			catch(error)
			{
        alert('Error while trying to assign Selected Information back to Parent Window Object');
	      alert('Reported Error: ' + error.description);
        alert('Argument: ' + j);
	      alert('Assignment To:' + arguments[j]);
	      alert('Assignment Value:' + arguments[j + 1]);
			}

		}
	}
}

function ClearData (TagList)
{
  var obj;
	var tags = TagList.split(',');

  for (j=0;j<tags.length;j++)
	{

		  try {
			  try{
				  obj = window.document.getElementById(tags[j]);
				}
				catch(error)
				{
				  obj = window.document.all.item(arguments[j]);
				}

  		  obj.value = "";

				if (obj.onChange != null)
				{
					eval(obj.onChange);
				}
			}
			catch(error)
			{
        alert('Error while trying to Clear Object.');
        alert('Argument: ' + j);
				alert('Assignment To:' + obj.name);
				alert('Assignment Value: ' + obj.value);
				alert('On Change: ' + obj.onChange);
				alert(error);
			}
	}
}

function SetFocus (form)
{
  for (j=0;j<form.length;j++)
	{
	  if (form.elements[j].type != 'hidden')
		{
			try {
			  form.elements[j].focus();
				return true;
			}
			catch (e) {
			}

		}
	}

	return false;
}

function OpenMessageWindow ()
{

    if (RootURL == null)
  	  window.open('/cfmodules/ObjMgr.cfm?obj=MessageWindow','MessageWindow','width=500,height=300,titlebar=yes,menubar=no,toolbar=no,resizable=yes,scrollbars=yes');
	  else
	  {
	    URL = RootURL + '/cfmodules/ObjMgr.cfm?obj=MessageWindow';

      try
        {
    	  window.open(URL,'MessageWindow','width=500,height=300,titlebar=yes,menubar=no,toolbar=no,resizable=yes,scrollbars=yes');
    	  }
        catch(error)
        {
          alert('Error while trying to Open Error Message Window');
          alert('Path opening: ' + URL);
          alert(error);
          return true;
        }
    }
}

function OpenLookupWindow (lookupobject, formname, fieldname)
{
  var passthrough = '';

	if (arguments[3] != null)
	{
	  if (lookupobject == 'ImageLookup')
		{
		  passthrough = '&ImageClass=' + arguments[3];
		}
		else
		{
		  passthrough = arguments[3];
		}
	}

  if (RootURL == null)
	  URL = '/cfmodules/ObjMgr.cfm?obj=' + lookupobject + '&Name=' + formname + '&Fields=' + fieldname + passthrough;
	else
	  URL = RootURL + '/cfmodules/ObjMgr.cfm?obj=' + lookupobject + '&Name=' + formname + '&Fields=' + fieldname + passthrough;

 	window.open(URL,'Lookup','titlebar=no,location=no,alwaysRaised=yes,menubar=no,toolbar=no,resizable=yes,scrollbars=yes');

}

function SetReadOnly(fieldname, readonly)
{
/*  object = window.document.all.item(fieldname); */
  object = window.document.getElementById(fieldname);
  if (object != null)
	{
	  object.readOnly = readonly;

		return true;
	}

	return false;
}

function SetDisabled(fieldname, disabled)
{
  object = window.document.getElementById(fieldname);

  if (object != null)
	{
	  object.disabled = disabled;

		return true;
	}

	return false;
}

function SetCheckedValue (form, fieldname, Extent)
{
    var dummyField;
		var Field;

	  if (Extent == null)
		  Extent = "";

    dummyField = fieldname + 'Dummy' + Extent;
		Field = fieldname + Extent;

    try {

			if (window.document.getElementById(dummyField).checked)
			  window.document.getElementById(Field).value = '1';
			else
			  window.document.getElementById(Field).value = '0';
		}
		catch(e) {

			  alert('Error Thrown in SetCheckedValue on object (' + dummyField);
			}

		return true;
}

function validatedate(form, fieldname, required, message)
{
  object = document.all.item(fieldname);

  if (!checkdate(object.value, required))
	{
	  if (object.value.length > 0)
		{
		  alert(message);
			object.value = '';
			object.focus();
			return false;
		}
	}

	return true;
}

function checkdate(object_value, required) {
  //Returns true if value is a date format or is NULL
  //otherwise returns false
  //trim whitespace before we validate
	var iSplit;
	var iOffet;
	var splitchr;
	
  object_value = object_value.replace(/^\s+/,'').replace(/\s+$/,'');
  object_value = object_value = object_value.replace(/{d \'/, '').replace(/'}/, '');

  if( required )
  {
  	if( object_value.length == 0 )
    {
    	return false;
    }
  }
	else {
  	if( object_value.length == 0 )
    {
    	return true;
    }
  }


  if (object_value.length == 0)
    return true;

  //Returns true if value is a date in the mm/dd/yyyy format
  isplit = object_value.indexOf('/');
	splitchr = "/";

	if (isplit == -1)
	{
		isplit = object_value.indexOf('-');
		splitchr = "-";
	}

	if (isplit == -1)
	{
		isplit = object_value.indexOf('.');
		splitchr = ".";
	}

	if (isplit == -1 || isplit == object_value.length)
		return false;

  var element1 = object_value.substring(0, isplit);
  // check for yyyy-mm-dd format
  if( element1.length == 4 )
  {
  	sYear = object_value.substring(0, isplit);
    isplit = object_value.indexOf(splitchr, isplit + 1);
    if (isplit == -1 || (isplit + 1 ) == object_value.length)
    	return false;
    sMonth = object_value.substring((sYear.length + 1), isplit);
    sDay = object_value.substring(isplit + 1);
  }
  else
  {
  	sMonth = object_value.substring(0, isplit);
    isplit = object_value.indexOf(splitchr, isplit + 1);
    if (isplit == -1 || (isplit + 1 ) == object_value.length)
      return false;
    sDay = object_value.substring((sMonth.length + 1), isplit);
    sYear = object_value.substring(isplit + 1);

		iOffset = sYear.indexOf(' ');
		if (iOffset > -1)
		{
	    sYear = sYear.substring(0, iOffset);
		}
  }

	if (!checkinteger(sMonth)) //check month
	  return false;
	else
	if (!checkrange(sMonth, 1, 12)) //check month
	  return false;
	else
	if (!checkinteger(sYear)) //check year
	  return false;
	else
	if( sYear.length != 1 && sYear.length != 2 && sYear.length != 4 )
	 return false;
	else
	if (!checkrange(sYear, 0, 9999)) //check year
	  return false;
	else
	if (!checkinteger(sDay)) //check day
	  return false;
	else
	if (!checkday(sYear, sMonth, sDay)) // check day
	  return false;
	else
	  return true;

 }

function checkday(checkYear, checkMonth, checkDay)
{
	maxDay = 31;

	if (checkMonth == 4 || checkMonth == 6 ||
		checkMonth == 9 || checkMonth == 11)
		maxDay = 30;
	else if (checkMonth == 2)
	{
		if (checkYear % 4 > 0)
			maxDay =28;
		else if (checkYear % 100 == 0 && checkYear % 400 > 0)
			maxDay = 28;
		else
			maxDay = 29;
	}

	return _CF_checkrange(checkDay, 1, maxDay);
}


function checkinteger(object_value, required)
{
	//trim whitespace before we validate
  object_value = object_value.replace(/^\s+/,'').replace(/\s+$/,'');
	//remove numeric noise
	object_value = object_value.replace(/[$ŁĄ€,~+]?/g, '');


  if( required )
  {
      if( object_value.length == 0 )
      {
          return false;
      }
  }else{
      if( object_value.length == 0 )
      {
          return true;
      }
  }


	var decimal_format = ".";
	var check_char = object_value.indexOf(decimal_format);

	if (check_char == -1)
		return checknumber(object_value);
	else
		return false;
}


function numberrange(object_value, min_value, max_value, required)
{
	//trim whitespace before we validate
	//object_value = object_value.replace(/^\s+/,'').replace(/\s+$/,'');

	if( required )
	{
	  if( object_value.length == 0 )
	  {
	      return false;
	  }
	}else{
	  if( object_value.length == 0 )
	  {
	      return true;
	  }
	}


	if (min_value != null)
	{
		if (object_value < min_value)
			return false;
	}

	if (max_value != null)
	{
		if (object_value > max_value)
			return false;
	}

	return true;
}

function checkrange(object_value, min_value, max_value, required)
{
	object_value = object_value.replace(/^\s+/,'').replace(/\s+$/,'');

	if( required )
	{
	  if( object_value.length == 0 )
	  {
	      return false;
	  }
	}
	else{
	  if( object_value.length == 0 )
	  {
	      return true;
	  }
	}


	if (!checknumber(object_value))
		return false;
	else
		return (numberrange((eval(object_value)), min_value, max_value));

	return true;
}


function checknumber(object_value, required)
{
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

	//trim whitespace before we validate
  object_value = object_value.replace(/^\s+/,'').replace(/\s+$/,'');
	//remove numeric noise
	object_value = object_value.replace(/[$ŁĄ€,~+]?/g, '');


	if( required )
	{
	  if( object_value.length == 0 )
	  {
	    return false;
	  }
	}else{
	  if( object_value.length == 0 )
	  {
	    return true;
	  }
	}



	check_char = start_format.indexOf(object_value.charAt(0));

	if (check_char == 1)
		decimal = true;
	else if (check_char < 1)
		return false;

	for (var i = 1; i < object_value.length; i++)
	{
		check_char = number_format.indexOf(object_value.charAt(i));
		if (check_char < 0)
			return false;
		else if (check_char == 1)
		{
			if (decimal)
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0)
		{
			if (decimal || digits)
				trailing_blank = true;
		}
		else if (trailing_blank)
			return false;
		else
			digits = true;
	}

	return true
}

function AutoFillField(objSource, objTarget, startOffset, length) {
 if (objTarget.value == "")
   objTarget.value = objSource.value.substring(startOffset,length);
}

function ValidateNotBlank(obj, message) {
	
  if (obj.value == "" || obj.value == null)
  {
  	alert(message);
		obj.value = obj.defaultValue;
		return false;
	}

  return true;

}

function ValidateNotZero(obj, message) {

  if (obj.value == "" || obj.value == null || obj.value == "0")
  {
  	alert(message);
		return false;
	}

  return true;

}

function ValidateInteger(obj, required, message)
{
  if (!checkinteger(obj.value, required))
	{
	  alert(message);
		obj.value = '';
		obj.focus();
		return false;
	}

	return true;
}



/*****************************************************************************************/
/****************************** Calendar Code Below **************************************/
/*****************************************************************************************/

/*******************************************************

var weekend = [0,6];
var weekendColor = "#e0e0e0";
var fontface = "Verdana";
var fontsize = 2;
returnCalObject = 0;

var gNow = new Date();
var ggWinCal;
var gInputDate = new Date();

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"];

// Non-Leap year Month days..
Calendar.DOMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
// Leap year Month days..
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;
	this.gReturnCalObject = returnCalObject;

}

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) {
	//	Check for leap year ..
	//	1.Years evenly divisible by four are normally leap years, except for...
	//	2.Years also evenly divisible by 100 are not leap years, except for...
	//	3.Years also evenly divisible by 400 are leap years.

	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) {
	//	Will return an 1-D array with 1st element being the calculated month
	//	and second being the calculated year
	//	after applying the month increment/decrement as specified by 'incr' parameter.
	//	'incr' will normally have 1/-1 to navigate thru the months.

	var ret_arr = new Array();

	if (incr == -1) {
		// B A C K W A R D
		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) {
		// F O R W A R D
		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) {
	//	Will return an 1-D array with 1st element being the calculated month
	//	and second being the calculated year
	//	after applying the month increment/decrement as specified by 'incr' parameter.
	//	'incr' will normally have 1/-1 to navigate thru the months.

	var ret_arr = new Array();

	if (incr == -1) {
		// B A C K W A R D
		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) {
		// F O R W A R D
		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;
}

// This is for compatibility with Navigator 3, we have to create and discard one object before the prototype object exists.
new Calendar();

Calendar.prototype.getMonthlyCalendarCode = function() {
	var vCode = "";
	var vHeader_Code = "";
	var vData_Code = "";

	// Begin Table Drawing code here..
	vCode = vCode + "<TABLE BORDER=1 BGCOLOR=\"" + this.gBGColor + "\">";

	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();

	// Setup the page...
	this.wwrite("<html>");
	this.wwrite("<head><title>Calendar</title>");
	this.wwrite("</head>");

	this.wwrite("<body " +
		"link=\"" + this.gLinkColor + "\" " +
		"vlink=\"" + this.gLinkColor + "\" " +
		"alink=\"" + this.gLinkColor + "\" " +
		"text=\"" + this.gTextColor + "\">");
	this.wwriteA("<FONT FACE='" + fontface + "' SIZE=2><B>");
	this.wwriteA(this.gMonthName + " " + this.gYear);
	this.wwriteA("</B><BR>");

	// Show navigation buttons
	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.wwrite("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0'><TR><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" +
		"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)-1) + "', '" + this.gFormat + "' " +
		");" +
		"\"><<<\/A>]</TD><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" +
		"'" + this.gReturnItem + "', '" + prevMM + "', '" + prevYYYY + "', '" + this.gFormat + "' " +
		");" +
		"\"><<\/A>]</TD><TD ALIGN=center>");
	this.wwrite(" </TD><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" +
		"'" + this.gReturnItem + "', '" + nextMM + "', '" + nextYYYY + "', '" + this.gFormat + "' " +
		");" +
		"\">><\/A>]</TD><TD ALIGN=center>");
	this.wwrite("[<A HREF=\"" +
		"javascript:window.opener.Build(" +
		"'" + this.gReturnItem + "', '" + this.gMonth + "', '" + (parseInt(this.gYear)+1) + "', '" + this.gFormat + "' " +
		");" +
		"\">>><\/A>]</TD></TR></TABLE><BR>");

	// Get the complete calendar code for the month..
	vCode = this.getMonthlyCalendarCode();
	this.wwrite(vCode);

	this.wwrite("</font></body></html>");
	this.gWinCal.document.close();
}

Calendar.prototype.showY = function() {
	var vCode = "";
	var i;
	var vr, vc, vx, vy;		// Row, Column, X-coord, Y-coord
	var vxf = 285;			// X-Factor
	var vyf = 200;			// Y-Factor
	var vxm = 10;			// X-margin
	var vym;				// Y-margin
	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>");

	// Show navigation buttons
	var prevYYYY = parseInt(this.gYear) - 1;
	var nextYYYY = parseInt(this.gYear) + 1;

	this.wwrite("<TABLE WIDTH='100%' BORDER=1 CELLSPACING=0 CELLPADDING=0 BGCOLOR='#e0e0e0'><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();\">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>");

	// Get the complete calendar code for each month..
	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(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>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Sun</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Mon</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Tue</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Wed</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Thu</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='14%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Fri</B></FONT></TD>";
	vCode = vCode + "<TD WIDTH='16%'><FONT SIZE='2' FACE='" + fontface + "' COLOR='" + this.gHeaderColor + "'><B>Sat</B></FONT></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 = "";

	//	Get day for the 1st of the requested month/year..
	//	Place as many blank cells before the 1st day of the month as necessary.
	

	vCode = vCode + "<TR>";
	for (i=0; i<vFirstDay; i++) {
		vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(i) + "><FONT SIZE='2' FACE='" + fontface + "'> </FONT></TD>";
	}

	// Write rest of the 1st week
	for (j=vFirstDay; j<7; j++) {

		vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" +
			"<A HREF='#' " +
				"onClick=\"window.opener.document.getElementById('" + this.gReturnCalObject + "').value='" +
				this.format_data(vDay) +
				"';window.close();\">" +
				this.format_day(vDay) +
			"</A>" +
			"</FONT></TD>";
		vDay=vDay + 1;

//		vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" +
//			"<A HREF='#' " +
//				"onClick=\"self.opener.document." + this.gReturnItem + ".value='" +
//				this.format_data(vDay) +
//				"';window.close();\">" +
//				this.format_day(vDay) +
//			"</A>" +
//			"</FONT></TD>";
//		vDay=vDay + 1;

	}
	vCode = vCode + "</TR>";

	// Write the rest of the weeks
	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) + "><FONT SIZE='2' FACE='" + fontface + "'>" +
				"<A HREF='#' " +
					"onClick=\"window.opener.document.getElementById('" + this.gReturnCalObject + "').value='" +
					this.format_data(vDay) +
					"';window.close();\">" +
				this.format_day(vDay) +
				"</A>" +
				"</FONT></TD>";

//			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j) + "><FONT SIZE='2' FACE='" + fontface + "'>" +
//				"<A HREF='#' " +
//					"onClick=\"self.opener.document." + this.gReturnItem + ".value='" +
//					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;
	}

	// Fill up the rest of last week with proper blanks, so that we get proper square blocks
	for (m=1; m<(7-j); m++) {
		if (this.gYearly)
			vCode = vCode + "<TD WIDTH='14%'" + this.write_weekend_string(j+m) +
			"><FONT SIZE='2' FACE='" + fontface + "' COLOR='gray'> </FONT></TD>";
		else
			vCode = vCode + "<TD WIDTH='14%'" + 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 == gInputDate.getDate() && this.gMonth == (gInputDate.getMonth() - 1) && this.gYear == gInputDate.getFullYear())
	{
		return ("<FONT COLOR=\"LIGHTBLUE\"><B>" + vday + "</B></FONT>");
  }
	else 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;

	// Return special formatting for the weekend day.
	for (i=0; i<weekend.length; i++) {
		if (vday == weekend[i])
			return (" BGCOLOR=\"" + weekendColor + "\"");
	}

	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);

	// Customize your Calendar here..
	gCal.gBGColor="white";
	gCal.gLinkColor="black";
	gCal.gTextColor="black";
	gCal.gHeaderColor="darkgreen";

	// Choose appropriate show function
	if (gCal.gYearly)	gCal.showY();
	else	gCal.show();
}

function show_calendar(dtInDate, calObject) {
	//		p_month : 0-11 for Jan-Dec; 12 for All Months.
	//		p_year	: 4-digit year
	//		p_format: Date format (mm/dd/yyyy, dd/mm/yy, ...)
	//		p_item	: Return Item.
	

  returnCalObject = calObject;

	p_item = arguments[0];
	if (arguments[2] == null || arguments[2].length == 0)
	{
		p_month = new String(gNow.getMonth());
		p_year = new String(gNow.getFullYear().toString());
		p_day = new String(gNow.getDate());
	}
	else
	{
		inputdate = arguments[2].split("/");
		p_month = new String(inputdate[0]) - 1;
		p_day = new String(inputdate[1]);
		p_year = new String(inputdate[2]);
		gInputDate = new Date(inputdate[2],inputdate[0],inputdate[1],0,0,0,0);
  }

	if (arguments[3] == null)
		p_format = "MM/DD/YYYY";
	else
		p_format = arguments[3];

	vWinCal = window.open("", "Calendar", "width=250,height=250,status=no,resizable=no,top=200,left=200");
	vWinCal.opener = self;
	ggWinCal = vWinCal;

	Build(p_item, p_month, p_year, p_format);
}

// Yearly Calendar Code Starts here

function show_yearly_calendar(p_item, p_year, p_format) {
	// Load the defaults..
	if (p_year == null || p_year == "")
		p_year = new String(gNow.getFullYear().toString());
	if (p_format == null || p_format == "")
		p_format = "MM/DD/YYYY";

	var vWinCal = window.open("", "Calendar", "scrollbars=yes");
	vWinCal.opener = self;
	ggWinCal = vWinCal;

	Build(p_item, null, p_year, p_format);
}

********************************************************/

//Javascript name: My Date Time Picker
//Date created: 16-Nov-2003 23:19
//Scripter: TengYong Ng
//Website: http://www.rainforestnet.com
//Copyright (c) 2003 TengYong Ng
//FileName: DateTimePicker.js
//Version: 0.8
//Contact: contact@rainforestnet.com
// Note: Permission given to use this script in ANY kind of applications if
//       header lines are left unchanged.

//Global variables
var winCal;
var dtToday=new Date();
var Cal;
var docCal;
var MonthName=["January", "February", "March", "April", "May", "June","July", 
	"August", "September", "October", "November", "December"];
var WeekDayName=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];	
var exDateTime;//Existing Date and Time

//Configurable parameters
var cnTop="200";//top coordinate of calendar window.
var cnLeft="500";//left coordinate of calendar window
var WindowTitle ="DateTime Picker";//Date Time Picker title.
var WeekChar=2;//number of character for week day. if 2 then Mo,Tu,We. if 3 then Mon,Tue,Wed.
var CellWidth=20;//Width of day cell.
var DateSeparator="-";//Date Separator, you can change it to "/" if you want.
var TimeMode=24;//default TimeMode value. 12 or 24

var ShowLongMonth=true;//Show long month name in Calendar header. example: "January".
var ShowMonthYear=true;//Show Month and Year in Calendar header.
var MonthYearColor="#cc0033";//Font Color of Month and Year in Calendar header.
var WeekHeadColor="#0099CC";//Background Color in Week header.
var SundayColor="#6699FF";//Background color of Sunday.
var SaturdayColor="#CCCCFF";//Background color of Saturday.
var WeekDayColor="white";//Background color of weekdays.
var FontColor="blue";//color of font in Calendar day cell.
var TodayColor="#FFFF33";//Background color of today.
var SelDateColor="#FFFF99";//Backgrond color of selected date in textbox.
var YrSelColor="#cc0033";//color of font of Year selector.
var ThemeBg="";//Background image of Calendar window.
//end Configurable parameters
//end Global variable

function NewCal(pCtrl,pFormat,pShowTime,pTimeMode)
{
	Cal=new Calendar(dtToday);
	if ((pShowTime!=null) && (pShowTime))
	{
		Cal.ShowTime=true;
		if ((pTimeMode!=null) &&((pTimeMode=='12')||(pTimeMode=='24')))
		{
			TimeMode=pTimeMode;
		}		
	}	
	if (pCtrl!=null)
		Cal.Ctrl=pCtrl;
	if (pFormat!=null)
		Cal.Format=pFormat.toUpperCase();
	
	exDateTime=document.getElementById(pCtrl).value;
	if (exDateTime!="")//Parse Date String
	{
		var Sp1;//Index of Date Separator 1
		var Sp2;//Index of Date Separator 2 
		var tSp1;//Index of Time Separator 1
		var tSp1;//Index of Time Separator 2
		var strMonth;
		var strDate;
		var strYear;
		var intMonth;
		var YearPattern;
		var strHour;
		var strMinute;
		var strSecond;
		//parse month
		Sp1=exDateTime.indexOf(DateSeparator,0)
		Sp2=exDateTime.indexOf(DateSeparator,(parseInt(Sp1)+1));
		
		if ((Cal.Format.toUpperCase()=="DDMMYYYY") || (Cal.Format.toUpperCase()=="DDMMMYYYY"))
		{
			strMonth=exDateTime.substring(Sp1+1,Sp2);
			strDate=exDateTime.substring(0,Sp1);
		}
		else if ((Cal.Format.toUpperCase()=="MMDDYYYY") || (Cal.Format.toUpperCase()=="MMMDDYYYY"))
		{
			strMonth=exDateTime.substring(0,Sp1);
			strDate=exDateTime.substring(Sp1+1,Sp2);
		}
		if (isNaN(strMonth))
			intMonth=Cal.GetMonthIndex(strMonth);
		else
			intMonth=parseInt(strMonth,10)-1;	
		if ((parseInt(intMonth,10)>=0) && (parseInt(intMonth,10)<12))
			Cal.Month=intMonth;
		//end parse month
		//parse Date
		if ((parseInt(strDate,10)<=Cal.GetMonDays()) && (parseInt(strDate,10)>=1))
			Cal.Date=strDate;
		//end parse Date
		//parse year
		strYear=exDateTime.substring(Sp2+1,Sp2+5);
		YearPattern=/^\d{4}$/;
		if (YearPattern.test(strYear))
			Cal.Year=parseInt(strYear,10);
		//end parse year
		//parse time
		if (Cal.ShowTime==true)
		{
			tSp1=exDateTime.indexOf(":",0)
			tSp2=exDateTime.indexOf(":",(parseInt(tSp1)+1));
			strHour=exDateTime.substring(tSp1,(tSp1)-2);
			Cal.SetHour(strHour);
			strMinute=exDateTime.substring(tSp1+1,tSp2);
			Cal.SetMinute(strMinute);
			strSecond=exDateTime.substring(tSp2+1,tSp2+3);
			Cal.SetSecond(strSecond);
		}	
	}
	winCal=window.open("","DateTimePicker","toolbar=0,status=0,menubar=0,fullscreen=no,width=195,height=245,resizable=0,top="+cnTop+",left="+cnLeft);
	docCal=winCal.document;
	RenderCal();
}

function RenderCal()
{
	var vCalHeader;
	var vCalData;
	var vCalTime;
	var i;
	var j;
	var SelectStr;
	var vDayCount=0;
	var vFirstDay;

	docCal.open();
	docCal.writeln("<html><head><title>"+WindowTitle+"</title>");
	docCal.writeln("<script>var winMain=window.opener;</script>");
	docCal.writeln("</head><body background='"+ThemeBg+"' link="+FontColor+" vlink="+FontColor+"><form name='Calendar'>");

	vCalHeader="<table border=1 cellpadding=1 cellspacing=1 width='100%' align=\"center\" valign=\"top\">\n";
	//Month Selector
	vCalHeader+="<tr>\n<td colspan='7'><table border=0 width='100%' cellpadding=0 cellspacing=0><tr><td align='left'>\n";
	vCalHeader+="<select name=\"MonthSelector\" onChange=\"javascript:winMain.Cal.SwitchMth(this.selectedIndex);winMain.RenderCal();\">\n";
	for (i=0;i<12;i++)
	{
		if (i==Cal.Month)
			SelectStr="Selected";
		else
			SelectStr="";	
		vCalHeader+="<option "+SelectStr+" value >"+MonthName[i]+"\n";
	}
	vCalHeader+="</select></td>";
	//Year selector
	vCalHeader+="\n<td align='right'><a href=\"javascript:winMain.Cal.DecYear();winMain.RenderCal()\"><b><font color=\""+YrSelColor+"\"><</font></b></a><font face=\"Verdana\" color=\""+YrSelColor+"\" size=2><b> "+Cal.Year+" </b></font><a href=\"javascript:winMain.Cal.IncYear();winMain.RenderCal()\"><b><font color=\""+YrSelColor+"\">></font></b></a></td></tr></table></td>\n";	
	vCalHeader+="</tr>";
	//Calendar header shows Month and Year
	if (ShowMonthYear)
		vCalHeader+="<tr><td colspan='7'><font face='Verdana' size='2' align='center' color='"+MonthYearColor+"'><b>"+Cal.GetMonthName(ShowLongMonth)+" "+Cal.Year+"</b></font></td></tr>\n";
	//Week day header
	vCalHeader+="<tr bgcolor="+WeekHeadColor+">";
	for (i=0;i<7;i++)
	{
		vCalHeader+="<td align='center'><font face='Verdana' size='2'>"+WeekDayName[i].substr(0,WeekChar)+"</font></td>";
	}
	vCalHeader+="</tr>";	
	docCal.write(vCalHeader);
	
	//Calendar detail
	CalDate=new Date(Cal.Year,Cal.Month);
	CalDate.setDate(1);
	vFirstDay=CalDate.getDay();
	vCalData="<tr>";
	for (i=0;i<vFirstDay;i++)
	{
		vCalData=vCalData+GenCell();
		vDayCount=vDayCount+1;
	}
	for (j=1;j<=Cal.GetMonDays();j++)
	{
		var strCell;
		vDayCount=vDayCount+1;
		if ((j==dtToday.getDate())&&(Cal.Month==dtToday.getMonth())&&(Cal.Year==dtToday.getFullYear()))
			strCell=GenCell(j,true,TodayColor);//Highlight today's date
		else
		{
			if (j==Cal.Date)
			{
				strCell=GenCell(j,true,SelDateColor);
			}
			else
			{	 
				if (vDayCount%7==0)
					strCell=GenCell(j,false,SaturdayColor);
				else if ((vDayCount+6)%7==0)
					strCell=GenCell(j,false,SundayColor);
				else
					strCell=GenCell(j,null,WeekDayColor);
			}		
		}						
		vCalData=vCalData+strCell;

		if((vDayCount%7==0)&&(j<Cal.GetMonDays()))
		{
			vCalData=vCalData+"</tr>\n<tr>";
		}
	}
	docCal.writeln(vCalData);	
	//Time picker
	if (Cal.ShowTime)
	{
		var showHour;
		showHour=Cal.getShowHour();		
		vCalTime="<tr>\n<td colspan='7' align='center'>";
		vCalTime+="<input type='text' name='hour' maxlength=2 size=1 style=\"WIDTH: 22px\" value="+showHour+" onchange=\"javascript:winMain.Cal.SetHour(this.value)\">";
		vCalTime+=" : ";
		vCalTime+="<input type='text' name='minute' maxlength=2 size=1 style=\"WIDTH: 22px\" value="+Cal.Minutes+" onchange=\"javascript:winMain.Cal.SetMinute(this.value)\">";
//		vCalTime+=" : ";
		vCalTime+=" ";
		vCalTime+="<input type='hidden' name='second' maxlength=2 size=1 style=\"WIDTH: 22px\" value="+Cal.Seconds+" onchange=\"javascript:winMain.Cal.SetSecond(this.value)\">";
		if (TimeMode==12)
		{
			var SelectAm =(parseInt(Cal.Hours,10)<12)? "Selected":"";
			var SelectPm =(parseInt(Cal.Hours,10)>=12)? "Selected":"";

			vCalTime+="<select name=\"ampm\" onchange=\"javascript:winMain.Cal.SetAmPm(this.options[this.selectedIndex].value);\">";
			vCalTime+="<option "+SelectAm+" value=\"AM\">AM</option>";
			vCalTime+="<option "+SelectPm+" value=\"PM\">PM<option>";
			vCalTime+="</select>";
		}	
		vCalTime+="\n</td>\n</tr>";
		docCal.write(vCalTime);
	}	
	//end time picker
	docCal.writeln("\n</table>");
	docCal.writeln("</form></body></html>");
	docCal.close();
}

function GenCell(pValue,pHighLight,pColor)//Generate table cell with value
{
	var PValue;
	var PCellStr;
	var vColor;
	var vHLstr1;//HighLight string
	var vHlstr2;
	var vTimeStr;
	
	if (pValue==null)
		PValue="";
	else
		PValue=pValue;
	
	if (pColor!=null)
		vColor="bgcolor=\""+pColor+"\"";
	else
		vColor="";	
	if ((pHighLight!=null)&&(pHighLight))
		{vHLstr1="color='red'><b>";vHLstr2="</b>";}
	else
		{vHLstr1=">";vHLstr2="";}	
	
	if (Cal.ShowTime)
	{
//		vTimeStr="winMain.document.getElementById('"+Cal.Ctrl+"').value+=' '+"+"winMain.Cal.getShowHour()"+"+':'+"+"winMain.Cal.Minutes"+"+':'+"+"winMain.Cal.Seconds";
		vTimeStr="winMain.document.getElementById('"+Cal.Ctrl+"').value+=' '+"+"winMain.Cal.getShowHour()"+"+':'+"+"winMain.Cal.Minutes";
		if (TimeMode==12)
			vTimeStr+="+' '+winMain.Cal.AMorPM";
	}	
	else
		vTimeStr="";		
	PCellStr="<td "+vColor+" width="+CellWidth+" align='center'><font face='verdana' size='2'"+vHLstr1+"<a href=\"javascript:winMain.document.getElementById('"+Cal.Ctrl+"').value='"+Cal.FormatDate(PValue)+"';"+vTimeStr+";window.close();\">"+PValue+"</a>"+vHLstr2+"</font></td>";
	return PCellStr;
}

function Calendar(pDate,pCtrl)
{
	//Properties
	this.Date=pDate.getDate();//selected date
	this.Month=pDate.getMonth();//selected month number
	this.Year=pDate.getFullYear();//selected year in 4 digits
	this.Hours=pDate.getHours();	
	
	if (pDate.getMinutes()<10)
		this.Minutes="0"+pDate.getMinutes();
	else
		this.Minutes=pDate.getMinutes();
	
	if (pDate.getSeconds()<10)
		this.Seconds="0"+pDate.getSeconds();
	else		
		this.Seconds=pDate.getSeconds();
		
	this.MyWindow=winCal;
	this.Ctrl=pCtrl;
	this.Format="ddMMyyyy";
	this.Separator=DateSeparator;
	this.ShowTime=false;
	if (pDate.getHours()<12)
		this.AMorPM="AM";
	else
		this.AMorPM="PM";	
}

function GetMonthIndex(shortMonthName)
{
	for (i=0;i<12;i++)
	{
		if (MonthName[i].substring(0,3).toUpperCase()==shortMonthName.toUpperCase())
		{	return i;}
	}
}
Calendar.prototype.GetMonthIndex=GetMonthIndex;

function IncYear()
{	Cal.Year++;}
Calendar.prototype.IncYear=IncYear;

function DecYear()
{	Cal.Year--;}
Calendar.prototype.DecYear=DecYear;
	
function SwitchMth(intMth)
{	Cal.Month=intMth;}
Calendar.prototype.SwitchMth=SwitchMth;

function SetHour(intHour)
{	
	var MaxHour;
	var MinHour;
	if (TimeMode==24)
	{	MaxHour=23;MinHour=0}
	else if (TimeMode==12)
	{	MaxHour=12;MinHour=1}
	else
		alert("TimeMode can only be 12 or 24");		
	var HourExp=new RegExp("^\\d\\d$");
	if (HourExp.test(intHour) && (parseInt(intHour,10)<=MaxHour) && (parseInt(intHour,10)>=MinHour))
	{	
		if ((TimeMode==12) && (Cal.AMorPM=="PM"))
		{
			if (parseInt(intHour,10)==12)
				Cal.Hours=12;
			else	
				Cal.Hours=parseInt(intHour,10)+12;
		}	
		else if ((TimeMode==12) && (Cal.AMorPM=="AM"))
		{
			if (intHour==12)
				intHour-=12;
			Cal.Hours=parseInt(intHour,10);
		}
		else if (TimeMode==24)
			Cal.Hours=parseInt(intHour,10);	
	}
}
Calendar.prototype.SetHour=SetHour;

function SetMinute(intMin)
{
	var MinExp=new RegExp("^\\d\\d$");
	if (MinExp.test(intMin) && (intMin<60))
		Cal.Minutes=intMin;
}
Calendar.prototype.SetMinute=SetMinute;

function SetSecond(intSec)
{	
	var SecExp=new RegExp("^\\d\\d$");
	if (SecExp.test(intSec) && (intSec<60))
		Cal.Seconds=intSec;
}
Calendar.prototype.SetSecond=SetSecond;

function SetAmPm(pvalue)
{
	this.AMorPM=pvalue;
	if (pvalue=="PM")
	{
		this.Hours=(parseInt(this.Hours,10))+12;
		if (this.Hours==24)
			this.Hours=12;
	}	
	else if (pvalue=="AM")
		this.Hours-=12;	
}
Calendar.prototype.SetAmPm=SetAmPm;

function getShowHour()
{
	var finalHour;
    if (TimeMode==12)
    {
    	if (parseInt(this.Hours,10)==0)
		{
			this.AMorPM="AM";
			finalHour=parseInt(this.Hours,10)+12;	
		}
		else if (parseInt(this.Hours,10)==12)
		{
			this.AMorPM="PM";
			finalHour=12;
		}		
		else if (this.Hours>12)
		{
			this.AMorPM="PM";
			if ((this.Hours-12)<10)
				finalHour="0"+((parseInt(this.Hours,10))-12);
			else
				finalHour=parseInt(this.Hours,10)-12;	
		}
		else
		{
			this.AMorPM="AM";
			if (this.Hours<10)
				finalHour="0"+parseInt(this.Hours,10);
			else
				finalHour=this.Hours;	
		}
	}
	else if (TimeMode==24)
	{
		if (this.Hours<10)
			finalHour="0"+parseInt(this.Hours,10);
		else	
			finalHour=this.Hours;
	}	
	return finalHour;	
}				
Calendar.prototype.getShowHour=getShowHour;		

function GetMonthName(IsLong)
{
	var Month=MonthName[this.Month];
	if (IsLong)
		return Month;
	else
		return Month.substr(0,3);
}
Calendar.prototype.GetMonthName=GetMonthName;

function GetMonDays()//Get number of days in a month
{
	var DaysInMonth=[31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	if (this.IsLeapYear())
	{
		DaysInMonth[1]=29;
	}	
	return DaysInMonth[this.Month];	
}
Calendar.prototype.GetMonDays=GetMonDays;

function IsLeapYear()
{
	if ((this.Year%4)==0)
	{
		if ((this.Year%100==0) && (this.Year%400)!=0)
		{
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		return false;
	}
}
Calendar.prototype.IsLeapYear=IsLeapYear;

function FormatDate(pDate)
{
	if (this.Format.toUpperCase()=="DDMMYYYY")
		return (pDate+DateSeparator+(this.Month+1)+DateSeparator+this.Year);
	else if (this.Format.toUpperCase()=="DDMMMYYYY")
		return (pDate+DateSeparator+this.GetMonthName(false)+DateSeparator+this.Year);
	else if (this.Format.toUpperCase()=="MMDDYYYY")
		return ((this.Month+1)+DateSeparator+pDate+DateSeparator+this.Year);
	else if (this.Format.toUpperCase()=="MMMDDYYYY")
		return (this.GetMonthName(false)+DateSeparator+pDate+DateSeparator+this.Year);			
}
Calendar.prototype.FormatDate=FormatDate;	










/*****************************************************************************************/
/****************************** Calendar Code END ****************************************/
/*****************************************************************************************/



/*****************************************************************************************/
/******************************  Menu Popup Help  ****************************************/
/*****************************************************************************************/


var DH = 0;
var an = 0;
var al = 0;
var ai = 0;

if (document.getElementById) {
    ai = 1;
    DH = 1;
}
else {
  if (document.all) {
    al = 1;
    DH = 1;
  }
  else {
    browserVersion = parseInt(navigator.appVersion);
    if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) {
      an = 1;
      DH = 1;
    }
  }
}

function fd(oi, wS) {
  if (ai) return wS ? document.getElementById(oi).style:document.getElementById(oi);
  if (al) return wS ? document.all[oi].style: document.all[oi];
  if (an) return document.layers[oi];
}

function pw() {
  return window.innerWidth != null? window.innerWidth: document.body.clientWidth != null? document.body.clientWidth:null;
}

function mouseX(evt) {

  if (evt.pageX) return evt.pageX;
  else if (evt.clientX)return evt.clientX + (document.documentElement.scrollLeft ?  document.documentElement.scrollLeft : document.body.scrollLeft);
  else return null;
}

function mouseY(evt) {
  if (evt.pageY) return evt.pageY;
  else if (evt.clientY)return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
  else return null;
}

function hidePopUp(offset, evt,oi) {

  var anchorX = [301, 412, 529, 640, 764];

  if (DH) {
    ds = fd(oi,1);

    try {
	    ds.visibility = "hidden";

    }
  	catch(e) {
    }
  }
}

function showPopUp(offset, evt,oi) {

  var anchorX = [146, 257, 374, 485, 609];
  var pageWidth = 760;
  var startingX = 0;

  if (DH) {
    var wp = pw();
    ds = fd(oi,1);
    dm = fd(oi,0);
    st = ds.visibility;
    if (dm.offsetWidth) ew = dm.offsetWidth;
    else if (dm.clip.width) ew = dm.clip.width;

		try {
			lv = evt.target.x;
			tv = evt.target.y + evt.target.height ;

		}
		catch(e) {
		 tv = mouseY(evt) + 20;
		 tv = 108;
		 lv = mouseX(evt) - (ew/4);
		 if (document.body.clientWidth>760)
		   startingX = (document.body.clientWidth - 760) / 2;
		 lv = startingX + anchorX[offset - 1];

		 // + (ew/2);
		}


		if (lv < 2) lv = 2;
		else if (lv + ew > wp) lv -= ew/2;

		if (!an) {
		lv += 'px';
		tv += 'px';
		}
		ds.visibility = "hidden";
		ds.left = lv;
		ds.top = tv;
		ds.visibility = "visible";
  }
}


/*****************************************************************************************/
/****************************  Menu Popup Help End  **************************************/
/*****************************************************************************************/

function Showlinkurl(linkurl)
{
  
  window.open(linkurl,"ShowLinkURL", "width=650,height=600,status=no,resizable=yes,scrollbars=yes,top=50,left=100");
	return true;		
}
