// ******************************************************************
// User Created Functions //
// ******************************************************************

// ******************************************************************
/* Form object handler functions */
// ******************************************************************

function PrintPagePDF(url)
{
	var sURL = "http://www.mhmraharris.org/PDF/GetPagePDF.asp?url=";
	//var sURL = "http://localhost/mhmra/extranet_new/PDF/GetPagePDF.asp?url=";
	
	if (!(url)) 
	{
		url = location.href;
	}
	//alert(sURL+url);
	window.open(sURL+url)
}


function timedRefresh(timeoutPeriod)
{
	//alert(timeoutPeriod);
	setTimeout("WinReload();",timeoutPeriod);
}

function WinReload()
{
	document.location.href = document.location.href;
}

function setFocus(num)
{	
	//alert(num);
	if (num == undefined)
	{
		num = 0;
	}
	
	document.forms[0].elements[num].focus();
}

/* reload page */
function RefreshPage()
{
	document.location.href = document.location.href;
}

/* add events */
function addEvent(obj, evType, fn){ 
 if (obj.addEventListener){ 
   obj.addEventListener(evType, fn, false); 
   return true; 
 } else if (obj.attachEvent){ 
   var r = obj.attachEvent("on"+evType, fn); 
   return r; 
 } else { 
   return false; 
 } 
}
// example: addEvent(window, 'load', function);

/* prevent special character(s) */
function Prevent(e)
{
var keynum
var keychar
var numcheck

if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
keychar = String.fromCharCode(keynum)

// alert(keynum);
// alert(keychar);
// use keynum for javascript key code value
// use keychar for actual key value

	if (keychar == "'") // apostrophe
		if (keynum != 8)
		{
		alert("That character is not allowed.");
		return false;
		//window.event.returnValue = false;
		}
}

/* Phone Numbers */
function integerOnly(e)
{
var keynum
var keychar
var numcheck

if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
keychar = String.fromCharCode(keynum)

// alert(keynum);
// alert(keychar);
// use keynum for javascript key code value
// use keychar for actual key value

	if (keynum < 48 || keynum > 57)
		if (keynum != 8)
		{
		alert("Invalid character used. Digits ONLY. No paranthesis () or dashes - .");
		return false;
		}
}

/* Social Security (phone numbers) - phasing out */
function SSNoOnly(e)
{
var keynum
var keychar
var numcheck

if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
keychar = String.fromCharCode(keynum)

// alert(keynum);
// alert(keychar);
// use keynum for javascript key code value
// use keychar for actual key value

	if (keynum < 48 || keynum > 57)
		if (keynum != 45 && keynum != 8) // dash(-)
		{
		alert("Invalid character used. Digits and dashes - ONLY.");
		return false;
		}
}

/* Decimal or Money */
function numericOnly(e)
{
var keynum
var keychar
var numcheck

if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
keychar = String.fromCharCode(keynum)

// alert(keynum);
// alert(keychar);
// use keynum for javascript key code value
// use keychar for actual key value

	if (keynum < 48 || keynum >= 58)
		if (keynum != 46 && keynum != 8)  // decimal point (.)
		{
		alert("Invalid character used. Ex: 25000.00");
		return false;
		}
}

/* prevent ENTER from submitting */
/*add this to form element onkeypress="return noenter(event);"*/
function noenter(e)
{
var keynum
var keychar
var numcheck

if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
}
keychar = String.fromCharCode(keynum)

// alert(keynum);
// alert(keychar);
// use keynum for javascript key code value
// use keychar for actual key value

	if (keynum == 13)
		{
		return false;
		}
}

/* prevent radio buttons */
function cancelEvent()
{
	//alert("You are NOT authorized to use this section!");
	//var eSrc = window.event.srcElement
	//if (eSrc.className == "clsreadonly")
	{
		window.event.returnValue = false;
		window.event.cancelBubble = true;
	}
}

function doNothing()
{
	void(0);
}

function ClearPrefillText(id)
{
	document.getElementById(id).value = "";
}


// ******************************************************************
/* Format Phone number */
// ******************************************************************
var _OUTPUT=1; /* set to 1 to have the function output the result -return true if converted
                * set to 0 to have the function not output anything -returns the value
				*/
function formatPhone(num)
{
	//alert(num);
  	var _return=false;
  	/*
   	* 7181238748 to 1(718)123-8748
   	*/

  	if(num.length != 10)
  	{
    	/*
     	* if user did not enter 10 digit phone number then simply print whatever user entered
     	*/
		_return=_OUTPUT?num:false;
  	}
  	else
  	{
    	/* formating phone number here */
		_return="1(";
		var ini = num.substring(0,3);
		_return+=ini+")";
		var st = num.substring(3,6);
		_return+=st+"-";
		var end = num.substring(6,10);
		_return+=end;
  	}
  	return _return;
}


// ******************************************************************
// Dates 
// ******************************************************************

/* Get Today Date */
function TodayDate(field)
{
var DateTime;

var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
//alert(year);
//document.write(month + "/" + day + "/" + year)
DateTime = (month + "/" + day + "/" + year) + " "

if (document.getElementById(""+ field +"").value == "")
{
	document.getElementById(""+ field +"").value = Trim(DateTime);
}
}

function TodayDateTime(field)
{
var DateTime;

var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
//alert(year);
//document.write(month + "/" + day + "/" + year)
DateTime = (month + "/" + day + "/" + year) + " "

var hours = currentTime.getHours()
var temp = hours;
	if (temp > 12)
	{
		temp = (temp - 12);
	}
var minutes = currentTime.getMinutes()
if (minutes < 10)
minutes = "0" + minutes
DateTime = DateTime + (temp + ":" + minutes + " ")
if(hours > 11){
DateTime = DateTime + ("PM")
} else {
DateTime = DateTime + ("AM")
}

if (document.getElementById(""+ field +"").value == "")
{
	document.getElementById(""+ field +"").value = Trim(DateTime);
}
}


// ******************************************************************
// calendars  - DO NOT USE, use new code below with inline calendar
// ******************************************************************

/* Popup Calendar */
function popupCal(field)
{
	newWin = window.open('../../../includes/cal_pop.asp?field='+ field +'','cal','dependent=yes,top=10,left=300,width=210,height=230,titlebar=no,status=1')
}

/* Popup Calendar from Sub Directories */
function popupCal2(field,url)
{
	newWin = window.open(''+ url +'/includes/cal_pop.asp?field='+ field +'','cal','dependent=yes,top=10,left=300,width=210,height=230,titlebar=no,status=0')
}


// ******************************************************************
/* validate textarea length */
// ******************************************************************
function Textarea(thisObj,limit)
{
	var count = parseInt(limit);
	//alert(thisForm.value.length);
	//alert(limit);
  	if ((thisObj.value.length+1) > limit)
  	{
    	alert("Please limit your information to only "+ limit +" characters.\nYou have exceeded the limit by "+ ((thisObj.value.length+1)-limit));
		thisObj.value = thisObj.value.substring(0,limit-1);
    	thisObj.focus();
    	return (false);
  	}
}


// ******************************************************************
// images
// ******************************************************************

// ******************************************************************
// This function needs an original image and a new image to swap.
// The Address needs to be modified accordingly.
// ******************************************************************
function Toggle_Images(x,img,newimg)
{ 
//var Address = 'http://localhost/mhmra/extranet_new/images';
var Address = 'http://www.mhmraharris.org/images/';
x = document.getElementById(x)
//alert(x.src);
x.src = (x.src == Address+img)?Address+newimg:Address+img;
//alert(x.src);
} 

/* Image swap */
function ImgChange(imgNum,imgSrc) 
{
document.images[imgNum].src = imgSrc;
}

/* scroll 'over' to change image */
function swapimage(image)
{
	window.document.images[image].src = "images/red.gif";
}

/* scroll 'out' to change image */
function swapimageout(image)
{
	window.document.images[image].src = "images/transparent.gif";
}


// ******************************************************************
/* Toggle Visibility (actually display) - Show/Hide Anything that has an id attribute */
// ******************************************************************
function Toggle_Visibility(id) 
{
//alert(id);
var e = document.getElementById(id);
if(e.style.display == 'none')
e.style.display = 'block';
else
e.style.display = 'none';
}

/* added for centersite */
function Toggle(obj) 
{          
	if (obj.style.display == "") obj.style.display = "none";        
	else obj.style.display = "";          
	return false; 
}

/* added for centersite */
function expandCollapse() {
	for (var i=0; i<expandCollapse.arguments.length; i++) {
		//alert(expandCollapse.arguments[i]);
		var element = document.getElementById(expandCollapse.arguments[i]);
		element.style.display = (element.style.display == "none") ? "block" : "none";
	}
}

// ******************************************************************
// tabs functionality //
// ******************************************************************
function setTabs(n,i)
{
var j = 0;
	//alert(document.getElementsByName(n).length);
	var num = document.getElementsByName(n).length;
	
	for (j=0; j<num; j++)  // clear all tabs //
		{
		//alert(j);
		document.getElementsByName(n)[j].className = "";
		}
		
	//alert(i);
	document.getElementsByName(n)[i].className = "Active";
	//alert(document.getElementsByName(n)[i].className);
}

// ******************************************************************
// Toggle List of Layers - Show/Hide Layers(Containers) by passing id attribute and number of layers 
// ******************************************************************
function Toggle_Layers(id,no)
{
var num = parseInt(no); // number of layers to roll through //
var e = document.getElementById("Layer"+id);
var i = 0;
if (e.style.display == 'none')
	{
	e.style.display = 'inline';
	//alert(e);
	for (i=1; i<num+1; i++)  // roll through layers //
		{
		if (i!=id) // hide elements not equal to id //
			{
			document.getElementById("Layer"+i).style.display = 'none';
			//alert(i);
			}
		}
	}
// move each page to top //
window.scrollTo(0,0);
}
// end

// ******************************************************************
// Show List of Layers //
// ******************************************************************
function Show_Layers(idname,no)
{
var num = parseInt(no); // number of layers to roll through //
var i = 0;
	for (i=1; i<num+1; i++)  // roll through layers //
		{
			e = document.getElementById(idname+i);
			e.style.display = 'block';
		}
}
// end

// ******************************************************************
// Hide List of Layers //
// ******************************************************************
function Hide_Layers(idname,no)
{
var num = parseInt(no); // number of layers to roll through //
var i = 0;
//alert(i);
	for (i=1; i<num+1; i++)  // roll through layers //
		{
			e = document.getElementById(idname+i);
			//alert(e.style.display);
			e.style.display = 'none';
		}
}
// end

// ******************************************************************
/* Layer visibility - note:object takes up space on the page */
// ******************************************************************
ns4 = document.layers
ie4 = document.all 
nn6 = document.getElementById && !document.all 

// Show/Hide functions for pointer objects
function showObject(id) {
   if (ns4) {
      document.n1.visibility = "show";
   }
   else if (ie4) {
      document.all[id].style.visibility = "visible";
   }
   else if (nn6) {
      document.getElementById(id).style.visibility = "visible";
   }
}

function hideObject(id) {
   if (ns4) {
      document.n1.visibility = "hide";
   }
   else if (ie4) {
      document.all[id].style.visibility = "hidden";
   }
   else if (nn6) {
      document.getElementById(id).style.visibility = "hidden";
   }
}
// end

// ******************************************************************
/* custom left function for javascript */
// ******************************************************************

function Left(str, n)
{
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

// ******************************************************************
/* custom right function for javascript */
// ******************************************************************
function Right(str, n)
{
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

// ******************************************************************
/* custom trim function for javascript */
// ******************************************************************

function Trim(str)
{
   	var str = String(str);
	str = str.replace(/^\s*|\s*$/g,"");
	return String(str);
	
	/*var temp = "";
	for(j=0; j< str.length+1; j++)		
	{
	if ((str.charCodeAt(j) >= 46) && (str.charCodeAt(j) <= 57) && (str.charAt(j) != "-"))			//numerical including '.' & '/'
		{
		temp += str.charAt(j);
		}
	}
	
	return String(temp)*/
}

// ******************************************************************
/* for moving across text boxes automatically  - example: SSN fields */
// ******************************************************************
function MoveNext(oThis, NextField, PreviousField)
{
	var oTxtRange
	var entrylength
	entrylength = oThis.form.elements[PreviousField].value.length;
		
     if (oThis.maxLength)
     {
          if (oThis.value.length == oThis.maxLength)
          {
               if (oThis.form.elements[NextField])
               {
                    oThis.form.elements[NextField].focus();
               }
          }
     }
	 if (oThis.value.length == 0)
	 {
	 	//alert(entrylength);
		if (document.selection && document.selection.createRange) {
  		// the Internet Explorer 4.0x code
		oTxtRange = oThis.form.elements[PreviousField].createTextRange();
		oTxtRange.move("character", entrylength);
		oTxtRange.select();

		} else if (document.getSelection) {
  		// the Navigator 4.0x code
		//oTxtRange = oThis.form.elements[PreviousField].setSelectionRange(0, entrylength);
		oTxtRange = oThis.form.elements[PreviousField].focus();
		} else {
  		// the alternative code
		}
  	}
}

// ******************************************************************
/* Handle radio buttons - validate */
// ******************************************************************

//alert(document.getElementsByName("elementname").length);
function Rdo_Handler(ElementName)
{
//alert(document.getElementsByName(ElementName).length);
var Element = 0;
var sReturn = "";
var i = 0;
for (i=0; i<((document.getElementsByName(ElementName).length)); i++)
{
	//alert(document.getElementsByName(ElementName)[i].checked);
	if (document.getElementsByName(ElementName)[i].checked == true)
	{
		Element = Element + 1;
		//alert(document.getElementsByName(ElementName)[i].value);
		sReturn = document.getElementsByName(ElementName)[i].value;
		//alert(Element);
	}
	else 
	{
		Element = Element + 0;
		//alert(Element);
	}
}
//alert(Element);
if (Element == 0)
{
	//alert("Please Select a(n) "+ ElementName +".");
	//document.getElementsByName(ElementName)[0].focus();
	return (false);
}
else
{
	return sReturn;
}
}
// End radio buttons //

// ******************************************************************
/* send email from form element using mailto */
// ******************************************************************

function SendEmail(thisObj)
{
	//alert(thisObj.value);
	if (thisObj.value == null || thisObj.value == "") // undefined = null
	{
		alert("No Email Address");
    	thisObj.focus();
    	return (false);
	}
	else
	{
	location.href = "mailto:" + thisObj.value;
	}
}

// ******************************************************************
/* Clear Form */
// ******************************************************************

/*function Reset(formname)
{
for (i = 0; i < document.form[formname].elements.length; i++)
	document.getElementsByName(fld)[i].checked = true;
}*/

// ******************************************************************
// counter function for number of checkboxes selected //
// ******************************************************************

var Counter = 0;			// global variable for counter //
// obj = input, num = how many can be checked, field = name of hidden counter box //
function SelectedCounter(obj,num,field)
{
	if (obj.checked == true)
	{
		document.getElementById(field).value = parseInt(document.getElementById(field).value) + 1;
	}
	else
	{
		document.getElementById(field).value = parseInt(document.getElementById(field).value) - 1;
	}
	
	if (document.getElementById(field).value > num)
	{
		alert("Please select only "+ num +".");
		obj.checked = false;
		document.getElementById(field).value = parseInt(document.getElementById(field).value) - 1;
		return (false);
	}
}

// ******************************************************************
// roll through and select or UN-select all checkboxes - must be incremental //
// ******************************************************************

function checkAll(obj,fld)
{
var i = 0;
	//alert(obj.checked);
	if (obj.checked)
	{
		for (i = 0; i < document.getElementsByName(fld).length; i++)
		{
			if (document.getElementsByName(fld)[i].checked == false)
			{
			//document.getElementsByName(fld)[i].checked = true;
			document.getElementsByName(fld)[i].click();
			}
		}
	}
	else
	{
		for (i = 0; i < document.getElementsByName(fld).length; i++)
		{
			if (document.getElementsByName(fld)[i].checked == true)
			{
			//document.getElementsByName(fld)[i].checked = true;
			document.getElementsByName(fld)[i].click();
			}
		}
	}
}

// ******************************************************************
/* Find Screen Size */
// ******************************************************************
var screenW = 640, screenH = 480;

//if (parseInt(navigator.appVersion)>3) {
//	screenW = screen.width;
// 	screenH = screen.height;
//}

function GetScreenSize(show)
{
if (parseInt(navigator.appVersion)>3) {
 screenW = screen.width;
 screenH = screen.height;
}
else if (navigator.appName == "Netscape" 
    && parseInt(navigator.appVersion)==3
    && navigator.javaEnabled()
   ) 
{
 var jToolkit = java.awt.Toolkit.getDefaultToolkit();
 var jScreenSize = jToolkit.getScreenSize();
 screenW = jScreenSize.width;
 screenH = jScreenSize.height;
}

if (show == "YesShow")
{
document.write(
 "Screen width = "+screenW+"<br>"
+"Screen height = "+screenH
)
}

}

/* Reset Captcha image */
function reloadCAPTCHA(str) 
{
	document.getElementById('CAPTCHA').src='CAPTCHA_image.asp?Detail='+str+'&mid='+Math.random();
}


/* Textarea - check character count */
function SizeCheck(strData) {
  if (strData.value.length >= 250) {
  alert('The maximum number of characters allowed for this field is 250.');
  strData.value = strData.value.substring(0,249);
  return false;
  }
}

function SizeCheck(strData, nLimit) {
  if (strData.value.length >= nLimit) {
  alert('The maximum number of characters allowed for this field is ' + nLimit + '.');
  strData.value = strData.value.substring(0,nLimit-1);
  return false;
  }
}

// ******************************************************************
// This function accepts a string variable and verifies if it is a
// proper date or not. It validates format matching either
// mm-dd-yyyy or mm/dd/yyyy. Then it checks to make sure the month
// has the proper number of days, based on which month it is.

// The function returns true if a valid date, false if not.
// ******************************************************************

function isDate(dateStr) {

var errorMsg = "";

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?

if (matchArray == null) {
//alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
return false;
}

month = matchArray[1]; // p@rse date into variables
day = matchArray[3];
year = matchArray[5];

if (month < 1 || month > 12) { // check month range
//alert("Month must be between 1 and 12.");
errorMsg = "Month must be between 1 and 12."
return false;
}

if (day < 1 || day > 31) {
//alert("Day must be between 1 and 31.");
errorMsg = "Day must be between 1 and 31."
return false;
}

if ((month==4 || month==6 || month==9 || month==11) && day==31) {
//alert("Month "+month+" doesn`t have 31 days!")
errorMsg = "Month "+month+" doesn`t have 31 days!"
return false;
}

if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day > 29 || (day==29 && !isleap)) {
//alert("February " + year + " doesn`t have " + day + " days!");
errorMsg = "February " + year + " doesn`t have " + day + " days!"
return false;
//return errorMsg;
}
}
return true; // date is valid
}

// ******************************************************************
// This function accepts a string variable and verifies the string
// is a proper time using regexp.
// The function returns true if a valid, false if not.
// Times accepted are military, HH:MM:SS AM/PM, HH:MM AM/PM
// ******************************************************************
//var timeFilter = /^[0-9]+:[0-9]+ [aApP]+[mM]+$/;
//var timeFilter = /^\d{1,2}:\d{2}([ap]m)?$/;
function isTime(field)
  {
    var errorMsg = "";

    // regular expression to match required time format
    re = /^(\d{1,2}):(\d{2})(:00)?([ap]m)?$/;
    
    if(field.value != '') {
      if(regs = field.value.match(re)) {
        if(regs[4]) {
          // 12-hour time format with am/pm
          if(regs[1] < 1 || regs[1] > 12) {
            errorMsg = "Invalid value for hours: " + regs[1];
          }
        } else {
          // 24-hour time format
          if(regs[1] > 23) {
            errorMsg = "Invalid value for hours: " + regs[1];
          }
        }
        if(!errorMsg && regs[2] > 59) {
          errorMsg = "Invalid value for minutes: " + regs[2];
        }
      } else {
        errorMsg = "Invalid time format: " + field.value;
      }
    }
	else
	{
		errorMsg = "Blank";
	}

    if(errorMsg != "") {
      //alert(errorMsg);
      //field.focus();
      return false;
	  //return errorMsg;
    }
    
    return true; // time is valid
  }

// ******************************************************************
// This function accepts a string variable and verifies each character
// is numeric '0123456789'. 
// The function returns true if a valid number, false if not.
// ******************************************************************

function isNumeric(numStr) 
{
var i = 0;
	if (numStr != '')
	{
	//alert(numStr);	
	for (i = 0; i <= (numStr.length-1); i++) 
		{
		if ('0123456789'.indexOf(numStr.charAt(i)) < 0) 
			{
				//alert('0123456789'.indexOf(strinput.charAt(i)));
				return false;
			}
		}
	}
return true;
}

// ******************************************************************
// This function accepts a string variable and verifies each character
// is a proper email address using regexp.
// The function returns true if a valid, false if not.
// ******************************************************************
var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;

function checkmail(e)
{
//alert(e);
//alert(emailFilter.test(e));
if (!(emailFilter.test(e))) 
{ 
	return false;
}
else
{
	return true;
}
}

// ******************************************************************
// Instantiate XMLHttp - AJAX //
// ******************************************************************
var xmlHttp;

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
} 


// ******************************************************************
// cookies
// ******************************************************************

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""
}

function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString())
}

function checkCookie(c_name)
{
var cookiename;
cookiename=getCookie(c_name)
if (cookiename!=null && cookiename!="")
  	{
  		//alert('Cookie data: '+cookiename+'!')
		alert('true')
		return true;
	}
else 
  {
  	//cookiename=prompt('Please enter your cookie name:',"")
  	//if (cookiename!=null && cookiename!="")
    //{
    //	setCookie(c_name,cookiename,365)
    //}
		alert('false');
		return false;
  }
}

// ******************************************************************
// inline popup dropdown - used with calendar_inline.js
// ******************************************************************
var element_id;

function GetBodyOffsetX(el_name, shift)
{
	var x;
	var y;
	x = 0;
	y = 0;

	var elem = document.all[el_name];
	do 
	{
		x += elem.offsetLeft;
		y += elem.offsetTop;
		if (elem.tagName == "BODY")
			break;
		elem = elem.offsetParent; 
	} while  (1 > 0);

	shift[0] = x;
	shift[1] = y;
	return  x;
}	

function SetPopupOnElement(el_name,pop_name)
{
	if (el_name=="") 
	el_name = element_id;
	var shift = new Array(2);
	GetBodyOffsetX(el_name, shift);
	document.all[pop_name].style.pixelLeft  = shift[0]; //  - document.all.calendar.offsetLeft;
	document.all[pop_name].style.pixelTop = shift[1] + 20 ;
}
           
function ShowPopup(elem_name,pop_name)
{
		if (elem_name=="")
		elem_name = element_id;

		element_id	= elem_name; // element_id is global variable
		//newCalendar();
		SetPopupOnElement(element_id,pop_name);
		//document.all.calendar.style.visibility = "visible";
		document.all[pop_name].style.display="inline";
}

function HidePopup(pop_name)
{
	//document.all.calendar.style.visibility="hidden";
	document.all[pop_name].style.display="none";
}

function togglePopup(elem_name,pop_name)
{
	//if (document.all.calendar.style.visibility == "hidden")
	if(document.all[pop_name].style.display=="none")
		ShowPopup(elem_name,pop_name);
	else 
		HidePopup(pop_name);
}


// ******************************************************************
// add the getMonthName() and getDayName() methods 
// ******************************************************************

Date.prototype.getMonthName = function() {
var m = ['January','February','March','April','May','June','July',
'August','September','October','November','December'];
return m[this.getMonth()];
} 

Date.prototype.getDayName = function() {
var d = ['Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday'];
return d[this.getDay()];
}

// ******************************************************************
// This js function will find the index of an array element with the given value in an array.
// ******************************************************************

Array.prototype.findIndex = function(value){
var ctr = "";
for (var i=0; i < this.length; i++) {
// use === to check for Matches. ie., identical (===), ;
if (this[i] == value) {
return i;
}
}
return ctr;
};


// ******************************************************************
// This js function will find the index of an array element with the given value in an array.
// multidimensional 
// ******************************************************************

Array.prototype.findIndexByCol = function(value,cIdx){
var ctr = "";
for (var i=0; i < this.length; i++) {
// use === to check for Matches. ie., identical (===), ;
if (this[i][cIdx] == value) {
//alert(this[i][cIdx]+"===="+value);
return i;
}
}
return ctr;
};

