﻿var fieldtoset;
function getCalendar(filepath, type)
{
  //document.forms.frmTemp.datetype.value = type;
  fieldtoset=type;
  
  window.open(filepath, '','width=300,height=300'); 
}
function GetDate(val)
{
  var date, month, day, year;
  if(val != null)
  {
    var oDate = new Date();
    
    month = oDate.getMonth();
    day = oDate.getDate();
    year = oDate.getYear();
    if(val!=0)
      date = FormatDate(val, month, day, year);
    else
      date = (month+1) + "/" + day + "/" + year;
  }
  return date;
}

function validateUSDate( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only
    valid dates with 2 digit month, 2 digit day,
    4 digit year. Date separator can be ., -, or /.
    Uses combination of regular expressions and
    string parsing to validate date.
    Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy

PARAMETERS:
   strValue - String to be tested for validity

RETURNS:
   True if valid, otherwise false.

REMARKS:
   Avoids some of the limitations of the Date.parse()
   method such as the date separator character.
*************************************************/
  var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/

  //check to see if in correct format
  if(!objRegExp.test(strValue))
    return false; //doesn't match pattern, bad date
  else{
    var strSeparator = strValue.substring(2,3) //find date separator
    var arrayDate = strValue.split(strSeparator); //split date into month, day, year
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
    var intDay = arrayDate[1];

    //check if month value and day value agree
    if(arrayLookup[arrayDate[0]] != null) {
      if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
        return true; //found in lookup table, good date
    }

    //check for February
    var intYear = parseInt(arrayDate[2]);
    var intMonth = parseInt(arrayDate[0]);
    if( ((intYear % 4 == 0 && intDay <= 29) || (intYear % 4 != 0 && intDay <=28)) && intDay !=0)
      return true; //Feb. had valid number of days
  }
  return false; //any other values, bad date
}
function SetSelectedNodeStyle(treeviewId, elemId)
{
	var treeview = document.getElementById(treeviewId)
	var treenodes = treeview.getElementsByTagName("Table");
	
	var i = 0;
	for(i = 0; i < treenodes.length; i++)
	{
		var treenode = treenodes[i];
		var anodes = treenode.getElementsByTagName("A");
		var j = 0;
		var anode = null;
		for(j = 0; j < anodes.length; j++)
		{
			var id = anodes[j].id;
			id = id.replace(treeview.id , "");
			if(id.charAt(0) == "t")
			{
				anode = anodes[j];
				break;
			}
		}
		anode.parentElement.className = "";
	}

	var elem = document.getElementById(elemId);
	if(elem)
	{
		elem.parentElement.className = "EmailAlertSelectedCategory";	
	}
}