/**
* Function to add an event to a DOM object
* 
* @author unknown
* @return NULL
*/

function set_oms_time(h,i,s)
{
	if (s < 59)
	{
		s++;
	}
	else
	{
		s = 0;
		
		if (i < 59)
		{
			i++;
		}
		else
		{
			i = 0;
			
			if (h < 23)
			{
				h++;
			}
			else
			{
				h = 0;
			}
		}
	}
	
	s = s.toString();
	i = i.toString();
	h = h.toString();
	
	s = s.length < 2 ? ('0' + s) : s;
	i = i.length < 2 ? ('0' + i) : i;
	h = h.length < 2 ? ('0' + h) : h;
	
	document.getElementById('oms_time').innerHTML = h + ':' + i + ':' + s;
	
	setTimeout ( function(){ set_oms_time(h,i,s) }, 1000 );
}

function addEvent(el, eType, func) 
{
    (typeof el.addEventListener != "undefined") ?
    el.addEventListener(eType,func,false) : el.attachEvent("on"+eType,func);    
}	

function removeEvent(el, eType, func) 
{
    (typeof el.removeEventListener != "undefined") ?
    el.removeEventListener(eType,func,false) : el.detachEvent("on"+eType,func);    
}	


/**
* Function that returns the HTTP object for AJAX
* 
* @author unknown
* @return obj
*/
function getHTTPObject()
{
	if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest) return new XMLHttpRequest();
	else 
    {
		alert("Your browser does not support AJAX.");
		return null;
	}
}

function $(a){return document.getElementById(a)};

function tags(a,b){if(!a) return false; else return a.getElementsByTagName(b)};

function getByClass(C,A) {var i,n,arr=[],p=new RegExp("(^|\\s)"+C+"(\\s|$)");for(i=0;A[i];i++) {n=A[i].className;if(n=='')continue;if(n==C){arr.push(A[i]);continue;}if(p.test(n))arr.push(A[i]);}return arr;};


/**
* Function that sets up the IE rollovers for the nav
* 
* @author unknown
* @return NULL
*/
function ieNav() 
{
		
    var navs = tags($('nav'),'li');
		
    var arr = [];
		
    for(var i=0;navs[i];i++) {
		
        if(tags(navs[i],'ul')[0]) {
		
            arr.push(navs[i])
		
            navs[i].ul = tags(navs[i],'ul')[0];
		
        }
		
    }
		
    for(var i=0;arr[i];i++) {
		
        arr[i].onmouseover = function() {
		
            this.ul.style.display = "block";
		
        }
		
        arr[i].onmouseout = function() {
		
            this.ul.style.display = "none";
		
        }
		
    }
		
} 

function show_hide_help()
{
	var help_text = document.getElementById('help_text');
	
	help_text.style.display = help_text.style.display != 'block' ? 'block' : 'none';

}

/**
* Function that removes all the <options> from a dropdown
*/
function removeAllOptions(selectbox)
{
    var i;
    for(i = selectbox.options.length-1; i >= 0; i--)
    {
        selectbox.remove(i);
    }
}

/**
* Function that adds a new <option> to a drop down
*/

function addOption(selectbox, text, value)
{
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    selectbox.options.add(optn);
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date")
		return false
	}
return true
}




// set up the nav in IE
addEvent(window, "load", ieNav);


    
