function checkForm(frm, arr_ctrl) {
	var count= arr_ctrl.length ;
	var i=0  ;
	for(i=0; i< count; i++) {
		func= trim( arr_ctrl[i][0] ) ;
		//alert(func);
		if( eval( func ) ) { //==
			alert( arr_ctrl[i][1] ) ;
			if( arr_ctrl[i][2] != "" )
				eval( "frm."  + arr_ctrl[i][2] ).focus() ;
			return false ; //== Error
		}
	}
	return true ; //== OK
}

function isEmail(s)
{
	if (s.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]{2,4}$/) != -1)
            return true ;
        else
            return false ;

}
function trim(str) {
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function isNegative(str) {
	if( isNaN(str) || str <= 0 )
		return true ;
	return false ;
}
function isLeapYear( yyyy ) {
	if( ( yyyy%4==0 && yyyy % 100 !=0 ) || yyyy%400==0 )
		return true ;
	return false ;
}

function isBlank(str) {
	if( str == "" )
		return true ;
	return false ;
}
function isValidDate(dd, mm, yyyy){
	//alert(dd);
	if(dd<=0 || dd>31 ||  mm>12 || mm<1)
		return false;
    if (( mm == 4 || mm == 6 || mm == 9 || mm == 11) && dd > 30 ){
        return false;
    } else if ( mm == 2 && dd > 29 ) {
        return false;
    } else if (mm == 2 && ! isLeapYear(yyyy) && dd > 28){
        return false;
    }else if(yyyy<1800)
		return false;
	return true;
}//isValidDate

function  not_entered(input,default_val)
{

	if(isBlank(input)  ||	input==default_val)
		return true;
	return false;
}

var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}

function	writeLayer(text,id)
{
	if (document.getElementById)
	{
		x = document.getElementById(id);
		if(x=="undefined" || x==null)
		{
			alert("can not find layer "+id);
			return;
		}
		x.innerHTML = '';
		x.innerHTML = text;
	}
	else if (document.all)
	{
		x = document.all[id];
		x.innerHTML = text;
	}
	else if (document.layers)
	{
		x = document.layers[id];
		text2 = '<P CLASS="testclass">' + text + '</P>';
		x.document.open();
		x.document.write(text2);
		x.document.close();
	}
}
//get the value of selected item in listbox
function get_listbox_selected(obj)
{

	for (i=0;i<obj.length;i++)
	{

		if(obj[i].selected)
			return obj[i].value
	}

	return "";
}
function hilight(obj)
{
	obj.bgColor="#FAF4B6";
}
function no_hilight(obj)
{
	obj.bgColor="#D8E6ED";
}

function change_img(img_name,src)
{
	document.images[""+img_name+""].src=src;
}

function showTreeLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.display = "block";
}

function hideTreeLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.display = "none";
}
function showLayer(id) {
  var lyr = getElemRefs(id);
  if (lyr && lyr.css) lyr.css.visibility = "visible";
}

function hideLayer(id) {
  var lyr = getElemRefs(id);

  if (lyr && lyr.css) lyr.css.visibility = "hidden";

}

//--------------------------------------------------------------------------------------------
function hilight_color(obj,color)
{

	obj.bgColor=color;
}
//--------------------------------------------------------------------------------------------

function getElemRefs(id) {
	var el = (document.getElementById)? document.getElementById(id): (document.all)? document.all[id]: (document.layers)? document.layers[id]: null;
	if (el) el.css = (el.style)? el.style: el;
	return el;
}
//----------------------------------------------------------------------------------------------------------------
Array.prototype.in_array = function ( obj ) {
	var len = this.length;
	for ( var x = 0 ; x <= len ; x++ ) {
		if ( this[x] == obj ) return true;
	}
	return false;
}

//-----------------------------------------------------------
//below function is for Admin Button3_rollover CSS button



function getRadioValue(radioObj)
{

	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function isObject(o) {return (o && "object" == typeof o) || isFunction(o);}
function isFunction(o) {return "function" == typeof o;}
//show size in readable format
function formatFilesize(size,round)
{


	var iec = Array("B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB");
	var i=0;
	while ((size/1024)>1)
	{
	  size=size/1024;
	   i++;
	}
	size=size.toString();

	if(size.indexOf('.')>0)
		s=size.substr(0,size.indexOf('.')+3)+iec[i]
	else
		s=size+iec[i]
	if(round)
		s=Math.round(size)+iec[i];
	return s;
}

function openAddressBook()
{
 if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  URLStr="popup_addressbook.php";
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menub ar=no,scrollbar=no,resizable=no,copyhistory=yes,width='+650+',height='+500+',left='+10+', top='+100+',screenX='+100+',screenY='+100+'');
}

function Set_Cookie( name, value, expires, path, domain, secure )
{
	// alert("to start with, our cookie is:\n" + document.cookie );
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );

	/*
	if the expires variable is set, make the correct expires time, the current script below will set
	it for x number of days, to make it for hours, delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );

	var strCookie  = name + "=" +escape( value ) +
		( ( expires ) ? "; expires=" + expires_date.toUTCString() : "" ) +
		( ( path ) ? "; path=" + path : "" ) +
		( ( domain ) ? "; domain=" + domain : "" ) +
		( ( secure ) ? "; secure" : "" );
	// alert("We are setting cookie to:\n" + strCookie);
	document.cookie = strCookie;
	// alert("Now we have:\n" + document.cookie );
}

// [[ mmddyyyy 06302008 MPC CR13913 - Perform added form validation to ensure fields are within
//      the data type limits of the database.
//
//  PARAMS:
//      @field - the field that is being validated
//      @friendlyName - the friendly name of the form field that will be displayed to the user
//      @maxlength - the maximum length of text that the field should accept
function validateFieldLength(field, friendlyName, maxlength, newline)
{
    var nFieldLength = field.value.length;
    var msg = "";
    
    if(nFieldLength > maxlength)
	{
	    msg = "You have exceeded the maximum length of the '" + friendlyName + "' field by " + 
	        (nFieldLength - maxlength) + " character(s)." + newline;
	}
	
	return msg;
}

//  PARAMS:
//      @element - the element that the class will be applied to
//      @classname - the name of the CSS class being applied
function updateElementClass(element, classname)
{
    element.setAttribute("class", classname);
    element.setAttribute("className", classname);
}

//  PARAMS:
//      @field - the field that is being validated
//      @fieldValidator - the span tag that displays a message to the user
//      @maxLength - the maximum length of text that the field should accept
function updateFieldLengthCounter(field, fieldValidator, maxLength) 
{
    var validator = document.getElementById(fieldValidator);
    var nFieldLength = field.value.length;

    if(typeof(validator) == "object")
    {
        if(field.type == "text")
        {
            if (nFieldLength > maxLength)
            {
                validator.innerHTML = "[";
                validator.innerHTML += nFieldLength - maxLength;
                validator.innerHTML += " char(s) too long]";
                
                updateElementClass(validator, "fieldValidatorRed");
            }
            else
            {
                validator.innerHTML = "";
            }
        }
        
        if(field.type == "textarea")
        {
            if (nFieldLength > maxLength)
            {
                validator.innerHTML = "You have exceeded this field&#146;s max length by ";
                validator.innerHTML += nFieldLength - maxLength;
                validator.innerHTML += " character(s).";
                
                updateElementClass(validator, "fieldValidatorRed");
            }
            else
            {
                validator.innerHTML = maxLength - nFieldLength;
                validator.innerHTML += " characters left.";
                
                updateElementClass(validator, "fieldValidatorBlack");
            }
        }
    }
}
// ]]
