function openITmax(url,title,name) {
	var width, height;
	if ( window.screen.width && window.screen.height )	{
		width = window.screen.width;
		height = window.screen.height;
	}else if ( window.navigator.userAgent.indexOf("MSIE") != -1 )	{
		width = document.body.clientWidth;
		height = document.body.clientHeight;
	}else	{
		width = window.innerWidth;
		height = window.innerHeight;
	}
	openIT(url,title,name,width,height);
}

function openIT(url,title,name,width,height,clrborder,clrbordersel,clrtitle,clrtitlesel) {
	theURL=url
	wname=name
	W=width;
	H=height;
	if (!W) W = 500;
	if (!H) H = 500;
	if (!wname) wname = 'form';
	if (title)	windowREALtit = title;
	else			windowREALtit = 'TAHR Portal System';
	windowTIT 	= "<font face=verdana size=1>"+windowREALtit+"</font>";

	if (clrborder) 	{windowBORDERCOLOR = clrborder 			}else {windowBORDERCOLOR 		= "#666666"}
	if (clrbordersel) {windowBORDERCOLORsel = clrbordersel	}else {windowBORDERCOLORsel 	= "#dcdcdc"}
	if (clrtitle)		{windowTITBGCOLOR = clrtitle 				}else {windowTITBGCOLOR		= "#dcdcdc"}
	if (clrtitlesel)	{windowTITBGCOLORsel = clrtitlesel		}else {windowTITBGCOLORsel	= "#dcdcdc"}

	//windowCERRARa 		= "/images/chromeless/close_a.gif"
	windowCERRARd 		= "/images/chromeless/close_d.gif"
	windowCERRARo 		= "/images/chromeless/close_o.gif"
	windowNONEgrf 		= "/images/chromeless/none.gif"
	windowCLOCK			= "/images/chromeless/clock.gif"
	openchromeless(theURL, wname, W, H, windowCERRARa, windowCERRARd, windowCERRARo, windowNONEgrf, windowCLOCK, windowTIT, windowREALtit , windowBORDERCOLOR, windowBORDERCOLORsel, windowTITBGCOLOR, windowTITBGCOLORsel)
}

var checkflag = "false";
function check(field,controller) {
	if (checkflag == "false") {
		for (i = 0; i < field.length; i++) {
			field[i].checked = true;
		}
		checkflag = "true";
		return "Uncheck All";
	}else {
		for (i = 0; i < field.length; i++) {
			field[i].checked = false;
		}
		checkflag = "false";
		return "Check All";
	}
}
function uncheck(field,fall) {
	var un = 0;
	var ch = 0;
	for (i = 0; i < field.length; i++) {
		if(field[i].checked){ch++}
	}

	if(field.length != ch){fall.checked = false;}
	else{fall.checked = true;}
}
function checkChoice(field, i) {
   if (i == 0) { // "All" checkbox selected.
      if (field[0].checked == true) {
         for (i = 1; i < field.length; i++)
         field[i].checked = true;
         document.myForm.all.checked = false;
      }else{
         for (i = 1; i < field.length; i++)
         field[i].checked = false;
         document.myForm.all.checked = false;
      }
   }
   else  {  // A checkbox other than "Any" selected.
      if (field[i].checked == true) {
         field[0].checked = false;
         document.myForm.all.checked = false;
      }else{
         field[0].checked = false;
         document.myForm.all.checked = false;
      }
   }
}

function popup(url,width,height,name,top,left,status,scrollbar,resizable) {
	if (!width) {width=300};
	if (!height) {height=300};
	if (!name) {name='popup'};
	if (!top) {top=50};
	if (!left) {left=350};
	if (!status) {status='no'};
	if (!scrollbar) {scrollbar='auto'};
	popupWin = window.open(url,name,'top='+top+',left='+left+',resizable=yes,width='+width+',height='+height+',status='+status+',scrollbar='+scrollbar+',menubar=no,resizable=' + resizable)
	popupWin.focus();
}

function myConfirm(form,msg) {
	
	if(confirm(msg)){
		form.submit();
	}else{
		return false;
	}
}

function buttonConfirm(form,msg) {
	
	if(confirm(msg)){
		//form.submit();
	}else{
		return false;
	}
}

function checkDelete(form,msg){
	var ch = 0;
	for (i = 0; i < form.length; i++) {
		if(form[i].checked){ch++;}
	}
	if(ch != 0){
		if(confirm(msg)){
			//form.submit();
		}else{
			return false;
		}
	}
}

function redirect(url,msg) {
	//var url;
	if(confirm(msg)){
		window.location = url;
	}else{
		return false;
	}
}

function moveOver(){
	var boxLength = document.choiceForm.choiceBox.length;
	var selectedItem = document.choiceForm.available.selectedIndex;
	var selectedText = document.choiceForm.available.options[selectedItem].text;
	var selectedValue = document.choiceForm.available.options[selectedItem].value;
	var i;
	var isNew = true;
	if (boxLength != 0) {
		for (i = 0; i < boxLength; i++) {
			thisitem = document.choiceForm.choiceBox.options[i].text;
			if (thisitem == selectedText) {
				isNew = false;
				break;
	      }
	   }
	}
	if (isNew) {
		newoption = new Option(selectedText, selectedValue, false, false);
		document.choiceForm.choiceBox.options[boxLength] = newoption;
	}
	document.choiceForm.available.selectedIndex=-1;
}

function removeMe() {
	var boxLength = document.choiceForm.choiceBox.length;
	arrSelected = new Array();
	var count = 0;
	for (i = 0; i < boxLength; i++) {
		if (document.choiceForm.choiceBox.options[i].selected) {
			arrSelected[count] = document.choiceForm.choiceBox.options[i].value;
		}
		count++;
	}
	var x;
	for (i = 0; i < boxLength; i++) {
		for (x = 0; x < arrSelected.length; x++) {
			if (document.choiceForm.choiceBox.options[i].value == arrSelected[x]) {
				document.choiceForm.choiceBox.options[i] = null;
		   }
		}
		boxLength = document.choiceForm.choiceBox.length;
	}
}
function saveMe() {
	var strValues = "";
	var boxLength = document.choiceForm.choiceBox.length;
	var count = 0;
	if (boxLength != 0) {
		for (i = 0; i < boxLength; i++) {
			if (count == 0) {
				strValues = document.choiceForm.choiceBox.options[i].value;
			}
			else {
				strValues = strValues + "," + document.choiceForm.choiceBox.options[i].value;
			}
			count++;
	   }
	}
	if (strValues.length == 0) {
		//alert("You have not made any selections");
		//document.choiceForm.newtype.value = 0;
	}else {
		//alert("Here are the values you've selected:\r\n" + strValues);
		document.choiceForm.newsubmenu.value = strValues;
	}
}


function resetRadio(temp) {

	//alert('test');
	//var temp = document.images.repimg;
	if(temp){
		for (var i=0;i<temp.length;i++) {
			temp[i].checked = false;
		}
	}
}

function goToURL(url) {
  window.location=url;
  //alert(url);
}

function groupid(form,field){
	var strval = field.split("|");
	for (var i=0;i<form.length;i++) {
		for (var w=0;w<strval.length;w++) {
			if(form[i].value == strval[w]){
				if(form[i].checked){form[i].checked = false}
				else{form[i].checked = true;}
			}
		}
	}
}

function checkform(form,field){
	var strArr = field.split(",");
	for (var a=0;a<strArr.length;a++){
		var strval = strArr[a].split("=");

		var inputfield = form.elements[strval[0]];
		if((strval[1] == '1')||(!strval[1])){
			if(inputfield.value == ''){
				alert("Required  field " + strval[0]);
				inputfield.focus();
				return false;
			}
		}else if(strval[1] == '2'){
			var ch = 0;
			if(inputfield.length > 1){
				for (i = 0; i < inputfield.length; i++) {
					if(inputfield[i].checked){ch++}
				}
				if(ch == 0){
					alert("Required  field " + strval[0]);
					inputfield[0].focus();
					return false;
				}
			}else{
				if(inputfield.checked){ch++}
				if(ch == 0){
					alert("Required  field " + strval[0]);
					inputfield.focus();
					return false;
				}
			}
		}else if(strval[1] == '3'){
			if(inputfield.selectedIndex == 0)  {
				alert("Required  field " + strval[0]);
				inputfield.focus();
				return false;
			}
		}
	}
}

/**
 * This array is used to remember mark status of rows in browse mode
 */
var marked_row = new Array;


/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 3.3 ... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // Garvin: deactivated onclick marking of the checkbox because it's also executed
            // when an action (like edit/delete) on a single item is performed. Then the checkbox
            // would get deactived, even though we need it activated. Maybe there is a way
            // to detect if the row was clicked, and not an item therein...
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
            // document.getElementById('id_rows_to_delete' + theRowNum).checked = false;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
}// end of the 'setPointer()' function

function expand(sec)
{
	
	thisSec = eval(sec);
	if (thisSec != null){
		if (thisSec.length){
			if (thisSec[0].style.display != 'none'){
				for (var i=0;i<thisSec.length;i++) {thisSec[i].style.display = 'none'}
			}
			else{
				for (var i=0;i<thisSec.length;i++) {thisSec[i].style.display = 'inline'}
			}
		}
		else{
			if (thisSec.style.display != 'none')     {thisSec.style.display = 'none'}
			else{thisSec.style.display = 'inline'}
		}
	}

}

function expandClose(sec)
{
	
	thisSec = eval(sec);
	if (thisSec != null){
		if (thisSec.length){
			if (thisSec[0].style.display != 'none'){
				for (var i=0;i<thisSec.length;i++) {thisSec[i].style.display = 'none'}
			}
		}
		else{
			if (thisSec.style.display != 'none')     {thisSec.style.display = 'none'}
		}
	}

}
	
function expandbycond(sec,cur)
{
	
	thisSec = eval(sec);
	if (thisSec != null){
		if (thisSec.length){
			if (thisSec[0].style.display != 'none' && !cur){
				for (var i=0;i<thisSec.length;i++) {thisSec[i].style.display = 'none'}
			}
			else{
				for (var i=0;i<thisSec.length;i++) {thisSec[i].style.display = 'inline'}
			}
		}
		else{
			if (thisSec.style.display != 'none' && !cur)     {thisSec.style.display = 'none'}
			else{thisSec.style.display = 'inline'}
		}
	}

}

function CurrencyFormatted(amount)
{
	amount += '';
//	amount = amount.replace(',',"");
	amount = replaceAll(amount,',',"");
	var i = parseFloat(amount);
	if(isNaN(i)) { i = 0.00; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	i = parseInt((i + .005) * 100);
	i = i / 100;
	s = new String(i);
	if(s.indexOf('.') < 0) { s += '.00'; }
	if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
	s = minus + s;
	return s;
}

function replaceAll(text, strA, strB)
{
    return text.replace( new RegExp(strA,"g"), strB );    
}

function CommaFormatted(amount)
{		
//		alert(amount);
		amount += '';
		amount = replaceAll(amount,',',"");
//		alert(amount);
		if(amount.indexOf('.') < 0) { amount += '.00'; }
		
//		amount += '';
//	alert(amount);
//
//	if(amount ){
//		alert(amount);
//	}else{
//		amount += '.00';
//	}
//	alert(amount);
	var delimiter = ","; // replace comma if desired
	var a = amount.split('.',2);
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
}

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 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 checkCookie()
{
username=getCookie('username')
if (username!=null && username!="")
  {alert('Welcome again '+username+'!')}
else 
  {
  username=prompt('Please enter your name:',"")
  if (username!=null && username!="")
    {
    setCookie('username',username,365)
    }
  }
}

function ajaxReload(cooks){
	var curloc = getCookie(cooks);
	if(curloc){
		ajaxpage(curloc, 'ajaxcontentarea');
	}else{
		return false;
	}
}

function printThis(urls){
	//window.location.href = urls + '&template=print';
	//urls = urls.replace('#',"");
	
	var urls = location.href;		
	urls = urls.replace('#',"");
	var newurl = urls.split("?");
	var sep;
	if(newurl[1]){sep = '&';}
	else{sep = '?';}
	popupWin = window.open(urls + '' + sep + '' + 'template=print','print',"'','',resizable=yes,'','',status='no',scrollbar='yes',menubar=no");
	popupWin.focus();
}

//function openClose(ids){
//	//alert(length(document.getElementById('row_' + ids)));
//	var rows = document.getElementById('row_' + ids);
//	alert(rows.length);
//	if (document.getElementById('row_' + ids).style.display == 'none'){ 
//		document.getElementById('row_' + ids).style.display = ''; 
//	}else{
//		document.getElementById('row_' + ids).style.display = 'none'; 
//	}
//
//}


function openClose(sec,ico_plus,ico_minus)
{
	
	thisSec = eval(sec);
	if (thisSec != null){
		if (thisSec.length){
			if (thisSec[0].style.display != 'none'){
				for (var i=0;i<thisSec.length;i++) {
					thisSec[i].style.display = 'none'
					document.getElementById('icon_' + sec).src = ico_plus;
				}
			}
			else{
				for (var i=0;i<thisSec.length;i++) {
					thisSec[i].style.display = 'inline'
					document.getElementById('icon_' + sec).src = ico_minus;
				}
			}
		}
		else{
			if (thisSec.style.display != 'none')     {
				thisSec.style.display = 'none'
				document.getElementById('icon_' + sec).src = ico_plus;
			}
			else{
				thisSec.style.display = 'inline'
				document.getElementById('icon_' + sec).src = ico_minus;
			}
		}
	}

}


function setAndExecute(divId, innerHTML)  
{  
   var div = document.getElementById(divId);  
   div.innerHTML = innerHTML;  
   var x = div.getElementsByTagName("script");   
   for(var i=0;i<x.length;i++)  
   {  
       eval(x[i].text);  
   }  
} 

function getImageWidth(myImage) {
	var x, obj;
	if (document.layers) {
		var img = getImage(myImage);
		return img.width;
	} else {
		return getElementWidth(myImage);
	}
	return -1;
}

function getImageHeight(myImage) {
	var y, obj;
	if (document.layers) {
		var img = getImage(myImage);
		return img.height;
	} else {
		return getElementHeight(myImage);
	}
	return -1;
}


function addBookmark(loc, til){  
	if(loc == ''){loc = location.href;}
	if(til == ''){til = document.title}
	if (document.all){  
		window.external.AddFavorite(loc, til);  
	}else if (window.sidebar){  
		window.sidebar.addPanel(til, loc, "");  
	}else{
		var notifyuser = 'To bookmark this site, click \'Bookmarks | Add bookmark\' or press \'Ctrl+D\'.';
		alert(notifyuser);
	} 
} 
