
/*************************************************
DATE CREATED: 02/08/2001
SCRIPT NAME: utility_pack.js
SCRIPT DESCRIPTION: This script containing all custom functions to help coding....
***********************************************/
/************************************
Description: display number with commas and decimal
************************************/

//this first part is taken from prototype.js
if(!Class) 
{
	var Class = {
	  create: function() {
	    return function() {
	      this.initialize.apply(this, arguments);
	    }
	  }
	}
	Object.extend = function(destination, source) {
	  for (var property in source) {
	    destination[property] = source[property];
	  }
	  return destination;
	}
}


//function description: validating date input....
//function returned:  return true if date is valid otherwise return false
//created by:  Vuong Trinh
//created date:  8/20/2004
//function call: validate_date('01/31/2004','mm/dd/yyyy','date_column')
function validate_date(inputDate,dateFormat,fieldName){
	if(inputDate == '') return true;
	var entered_year = "" ;
	var entered_mon = "" ;
	var entered_day = "" ;
	if(dateFormat.toLowerCase() == 'mm/dd/yyyy'){
		arr_inputDate = inputDate.split('/');
		if(inputDate.indexOf("/") == -1 || arr_inputDate.length != 3){
			msg = (typeof(fieldName) != 'undefined')?"Invalid date format 'MM/DD/YYYY' for "+fieldName+".":"Invalid date format 'MM/DD/YYYY'."
			alert(msg);			
			return false;
		}
		entered_year = arr_inputDate[2];
		entered_mon = arr_inputDate[0];
		entered_day = arr_inputDate[1];
	}
	else if(dateFormat.toLowerCase() == 'mm-dd-yyyy'){
		arr_inputDate = inputDate.split('-');
		if(inputDate.indexOf("/") == -1 || arr_inputDate.length != 3){
			msg = (typeof(fieldName) != 'undefined')?"Invalid date format 'MM-DD-YYYY' for "+fieldName+".":"Invalid date format 'MM-DD-YYYY'."
			alert(msg);			
			return false;
		}
		entered_year = arr_inputDate[2];
		entered_mon = arr_inputDate[0];
		entered_day = arr_inputDate[1];
	}
	else if(dateFormat.toLowerCase() == 'yyyy/mm/dd'){
		arr_inputDate = inputDate.split('/');
		if(inputDate.indexOf("/") == -1 || arr_inputDate.length != 3){
			msg = (typeof(fieldName) != 'undefined')?"Invalid date format 'YYYY/MM/DD' for "+fieldName+".":"Invalid date format 'YYYY/MM/DD'."
			alert(msg);			
			return false;
		}
		entered_year = arr_inputDate[0];
		entered_mon = arr_inputDate[1];
		entered_day = arr_inputDate[2];
	}
	else if(dateFormat.toLowerCase() == 'yyyy-mm-dd'){
		arr_inputDate = inputDate.split('-');
		if(inputDate.indexOf("/") == -1 || arr_inputDate.length != 3){
			msg = (typeof(fieldName) != 'undefined')?"Invalid date format 'YYYY-MM-DD' for "+fieldName+".":"Invalid date format 'YYYY-MM-DD'.";
			alert(msg);			
			return false;
		}
		entered_year = arr_inputDate[0];
		entered_mon = arr_inputDate[1];
		entered_day = arr_inputDate[2];
	}
	
	if(isNaN(entered_year) || entered_year < 1){
		msg = (typeof(fieldName) != 'undefined')?entered_year+' is not a valid year for '+fieldName+'.':entered_year+' is not a valid year.';
		alert(msg);			
		return false;
	}
	if(entered_year.length != 4){
		msg = (typeof(fieldName) != 'undefined')?"Invalid year format 'YYYY' for "+fieldName+'.':"Invalid year format 'YYYY'.";
		alert(msg);	
		return false;			
	}
	if(isNaN(entered_mon) || entered_mon < 1 || entered_mon > 12){
		msg = (typeof(fieldName) != 'undefined')?entered_mon+' is not a valid month for '+fieldName+'.':entered_mon+' is not a valid month of the year.';
		alert(msg);		
		return false;
	}
	
	mm_31 = "'1','3','5','7','8','10','12'";
	month_desc = new Array('January','Febuary','March','April','May','June','July','August','September','October','November','December');
	mon_31 = "jan,mar,may,jul,aug,oct,dec"
	mm_30 = "'4','6','9','11'";
	mon_30 = "apr,jun,sep,nov";
	leaf_year = ((entered_year % 4) == 0);		
	if(isNaN(entered_day) || entered_day < 1){
		msg = (typeof(fieldName) != 'undefined')?entered_day+' is not a valid day for '+fieldName+'.':entered_day+' is not a valid day of the month.';
		alert(msg);		
		return false;
	}
	
	mm_temp = ("'"+parseInt(entered_mon)+"'");		
	temp = "'";
	if(mm_30.indexOf(mm_temp) != -1){
		if(entered_day < 1 || entered_day > 30){
			msg = (typeof(fieldName) != 'undefined')?entered_day+" is not a valid date for the month of "+month_desc[entered_mon-1]+" for "+fieldName+".\nPlease enter a date between 1 to 30.":entered_day+" is not a valid date for the month of "+month_desc[entered_mon-1]+".\nPlease enter a date between 1 to 30.";
			alert(msg);
			return false;
		}
	}		
	if(mm_31.indexOf(mm_temp) != -1){
		if(entered_day < 1 || entered_day > 31){
			msg = (typeof(fieldName) != 'undefined')?entered_day+" is not a valid date for the month of "+month_desc[entered_mon-1]+" for "+fieldName+".\nPlease enter a date between 1 to 31.":entered_day+" is not a valid date for the month of "+month_desc[entered_mon-1]+".\nPlease enter a date between 1 to 31.";
			alert(msg);
			return false;
		}
	}
	if(parseInt(entered_mon) == 2){
		if(leaf_year && (entered_day < 1 || entered_day > 29)){
			msg = (typeof(fieldName) != 'undefined')?entered_day+" is not a valid date for the month of "+month_desc[entered_mon-1]+" for "+fieldName+".\nPlease enter a date between 1 to 29.":entered_day+" is not a valid date for the month of "+month_desc[entered_mon-1]+".\nPlease enter a date between 1 to 29.";
			alert(msg);
			return false;
		}
		else if(!leaf_year && (entered_day < 1 || entered_day > 28)){
			msg = (typeof(fieldName) != 'undefined')?entered_day+" is not a valid date for the month of "+month_desc[entered_mon-1]+" for "+fieldName+".\nPlease enter a date between 1 to 28.":entered_day+" is not a valid date for the month of "+month_desc[entered_mon-1]+".\nPlease enter a date between 1 to 28.";
			alert(msg);
			return false;
		}
	}	

	return true;	
	
}// End of function fValidateDate().

/*****************************************************************************************************************************/
//function description:  set the maxlength for text input and count words length....
//created by:  Vuong Trinh
//created date:  8/20/2004
//function call:  f_wordCount('form_name','text_name','text_counter',256)
function f_wordCount(form_name,text_name,text_counter,text_length){
	if(eval("typeof(document."+form_name+")=='undefined'")) return false;
	fieldOBJ = eval("document."+form_name+"."+text_name);
	text_temp = fieldOBJ.value;
	if(document.getElementById(text_counter)!=null) document.getElementById(text_counter).innerHTML = (text_length - parseInt(text_temp.length));
	if((text_length - parseInt(text_temp.length)) <= -1){
		fieldOBJ.value = text_temp.substring(0,text_length);
		text_temp = fieldOBJ.value;
		if(document.getElementById(text_counter)!=null) document.getElementById(text_counter).innerHTML = (text_length - parseInt(text_temp.length));
	}
}// End of function f_wordCount().

/*****************************************************************************************************************************/
//function description:  round the number...
//function returned:  return a number with round decimal
//created by:  Vuong Trinh
//created date:  02/08/2001
//function call:  f_roundUp(10000,2)
function f_roundUp(number,dec){
	dec = (typeof(dec) == 'undefined' || isNaN(dec))?0:dec;
	this.roundNum='1';
	for(x=0;x<dec;x++)
		this.roundNum=this.roundNum+'0';		
	this.roundNum=parseInt(this.roundNum);
	this.number=Math.round(parseFloat(number)*this.roundNum)/this.roundNum;			
	
	return this.number;	
}// End of function insert_comma()



//function description:  insert commas format for the number...
//function returned:  return a number with commas format
//created by:  Vuong Trinh
//created date:  02/08/2001
//function call:  insert_comma(10000,2)
function insert_comma(number,dec){

	dec = typeof(dec)=='undefined' ? 0 : dec;
	var mask = '999,999,999,999,999,999';
	if(dec > 0){
		mask += '.';
		for(var x = 0; x < dec; x++)
			mask += '9';
	}	
	return numberFormat(number,mask);	
	
	
}// End of function insert_comma()

/*****************************************************************************************************************************/
//function description:  remove commas in the number
//function returned:  return a number without commas
//created by:  Vuong Trinh
//created date:  02/08/2001
//function call:  delete_comma(10000)
function delete_comma(number){
	this.numString = new String(number);		
	while(this.numString.indexOf(",") != -1)
		this.numString = this.numString.replace(",","");
	return parseFloat(this.numString);
}// End of function delete_comma()

/*****************************************************************************************************************************/
//function description:  rounding the number
//function returned:  return a rounded float number....
//created by:  Vuong Trinh
//created date:  02/08/2001
//function call:  round_number(10000,2)
function round_number(number,dec){
	if(isNaN(dec))dec=0;
	this.roundNum='1';
	for(x=0;x<dec;x++)
		this.roundNum=this.roundNum+'0';
	this.roundNum=parseInt(this.roundNum);
	return Math.round(parseFloat(number)*this.roundNum)/this.roundNum;
}// End of function round_number()

/*****************************************************************************************************************************/
//function description:  escapte the html tags such as <>&"
//created by:  Vuong Trinh
//created date:  02/08/2007
//function call:  escapeHTMLcode("put your string here")
function escapeHTMLcode(str){
	str = ReplaceNoCase(str,'&', '&amp;');
	str = ReplaceNoCase(str,'<', '&lt;');
	str = ReplaceNoCase(str,'>', '&gt;');
	str = ReplaceNoCase(str,'"', '&quot;');
	return str;
}// End of function round_number()



function special_replace(str,str1,str2){
    while(str.indexOf(str1)!=-1){
        str = str.replace(str1,str2);    
    }
    return str;
}

// default case sensitive
function $StringCompare$(str1,str2,isCase){
    isCase = typeof isCase == 'undefined';
    str1 = isCase ? str1 : str1.toUpperCase();
    str2 = isCase ? str2 : str2.toUpperCase();
    return str1 == str2;
}


/*****************************************************************************************************************************/
//function description:  replace any string
//function returned:  return a new string;
//function call:  ReplaceNoCase(my_string,string_to_replace,replaced_string)
function ReplaceNoCase(MyString, SString, RString){
    var regExp=eval('/'+SString+'/g');
    return MyString.replace(regExp,RString);    
}

/*****************************************************************************************************************************/
//function description:  left trim white spaces
//function returned:  return a string with no left trailing spaces;
function LTrim(MyString,pattern){ //default pattern is whitespaces(spaces,tabs,new line feeds,etc.)
    var retval = "";    
    if(!IsBlank(MyString)){
        var removed = (typeof(pattern) == 'undefined')?'\\s':pattern;
        regExp=eval("/^("+removed+"*)([^"+removed+"].*)$/g");
        retval = MyString.replace(regExp,"$2");
    }
    return retval
}

/*****************************************************************************************************************************/
//function description:  right trim white spaces
//function returned:  return a string with no right trailing spaces;
function RTrim(MyString,pattern){ //default pattern is whitespaces(spaces,tabs,new line feeds,etc.)
    var retval = "";    
    if(!IsBlank(MyString)){
        var removed = (typeof(pattern) == 'undefined')?'\\s':pattern;
        regExp=eval("/^(.*[^"+removed+"])("+removed+"*)$/g");
        retval = MyString.replace(regExp,"$1");;
    }        
    return retval
}

/*****************************************************************************************************************************/
//function description:  trim left and right white spaces
//function returned:  return a string with no left right trailing spaces;
function Trim(MyString,pattern){ //default pattern is whitespaces(spaces,tabs,new line feeds,etc.)
    var retval = "";    
    if(!IsBlank(MyString)){
        var removed = (typeof(pattern) == 'undefined')?'\\s':pattern;
        regExp=eval("/^("+removed+"*)([^"+removed+"].*[^"+removed+"])("+removed+"*)$/g");   
        retval = MyString.replace(regExp,"$2");
    }
    return retval;
}


/*****************************************************************************************************************************/
//function description:  check for blank string.
//function returned:	true if blank otherwise false;
//function call:  IsBlank(my_string)
function IsBlank(MyString){ //default pattern is whitespaces(spaces,tabs,new line feeds,etc.)
    var removed = '\\s';
    regExp=eval("/^(["+removed+"]*)$/");
    return regExp.test(MyString);
}


//group all utility function into a package........
function utilityPackage(){
	this._IsBlank=IsBlank;
	this._replace=ReplaceNoCase;
	this._ltrim=LTrim;
	this._rtrim=RTrim;
	this._trim=Trim;
	this._round=round_number;
	this._commaFormat=insert_comma;
	this._deCommaFormat=delete_comma;
}
//initializing new util object.........
var util = new utilityPackage;





//get position
function getPosition(evt,pos){
	var x=y=0;
	if (document.getElementById){
		offsetX = document.body.scrollLeft + evt.clientX;//documentElement
		offsetY = document.body.scrollTop + evt.clientY;
	}
	else if(document.layers){
		offsetX = evt.pageX;
		offsetY = evt.pageY;
	}
	return {x:(pos && pos.toUpperCase()=='RIGHT')?offsetX-300:offsetX+20, y:offsetY+10}
}

/************************************
Description: Dynamic Title tag changing (works for IE only)
*************************************/
var message = new Array(),
    reps,speed,p,T,sT,
	mC = C = s = 0;
	
function f_setMessageArray(mgs1,mgs2){
	// Set the messages below -- follow the pattern.
	message[0] = ".Please Wait!.";
	message[1] = ".."+mgs1+"..";
	message[2] = "...still "+mgs2+"...";
	message[3] = "...."+mgs2+"....";
	
	// Set the number of repetitions (how many times the arrow	
	reps = 2;  // cycle repeats with each message).
	speed = 200;  // Set the overall speed (larger number = slower action).
	p = message.length;
	T = "";
	sT = null;
	reps = (reps < 1)?1:reps;
}
function A(){
	s++;
	s = (s > 5)?1:s;
	if (s == 1){ 
		if(document.all)
		    document.title = '>>====== '+T+'======<< '; 
	}
	if (s == 2){ 
	    if(document.all)
		    document.title = '==>>==== '+T+'====<<== ';  
	}
	if (s == 3){ 
		if(document.all)
		    document.title = '====>>== '+T+'==<<==== ';  
	}
	if (s == 4){   
		if(document.all)
		    document.title = '======>> '+T+'<<====== ';
	}
	if (s == 5){ 
		if(document.all)
		    document.title = '>>====== '+T+'======<< ';  
	}
	if (C < (5 * reps)){
		sT = setTimeout("A()", speed);
		C++;
	}
	else{
		C = s = 0;
		mC++;
		mC = (mC > p - 1)?0:mC;
		sT = null;
		T = message[mC];
		A();
   }
}
function doTheThing(mgs1,mgs2){
	f_setMessageArray(mgs1,mgs2);
	T = message[mC];
	A();
}

/************************************
Description: running dot.....
*************************************/
var str_dot="",countD=0;
this.myTimeOut_;
function dynamicDot(){
	if(document.getElementById && document.getElementById("dot")!=null){	
	//if(typeof(dot) == 'object' || (typeof(document.ildot) == 'object' && typeof(document.ildot.document.ldot) == 'object')){
		countD++;
		str_dot+='.';		
		if(countD <= 10){
			if (document.getElementById)
				document.getElementById("dot").innerHTML = str_dot;
			else if(document.layers){
				document.ildot.document.ldot.document.write("<b>"+str_dot+"</b>");
				document.ildot.document.ldot.document.close();	
			}
		}
		else{
			countD=1;
			str_dot='.';
			if (document.getElementById)
				document.getElementById("dot").innerHTML = str_dot;	
			else if(document.layers){
				document.ildot.document.ldot.document.write("<b>"+str_dot+"</b>");
				document.ildot.document.ldot.document.close();		
			}
		}	
		this.myTimeOut_ = setTimeout("dynamicDot()",200);
	}
}


//moving selected item(s) in the SELECT object(the object must set to multiple) from one to another...

//parameters:	objRemove = select_object_name1
//				objAdd = select_object_name2
//				isMoveAll = true,false
function _moveSelectedItem(objRemove,objAdd,isMoveAll){
	
	objRemove = document.getElementById(objRemove);
	objAdd = document.getElementById(objAdd);	
	
	//if user selected all items....
	if(isMoveAll){
		for(x=0;x<objRemove.length;x++)
			objRemove.options[x].selected=(objRemove.options[x].value!='');
	}	
	
	//begin to move the selected item(s)
	while(objRemove.selectedIndex!=-1&&objRemove.options[objRemove.selectedIndex].value!=''){
		//add the selected item(s) to the second panel...		
		objAdd[objAdd.length] = new Option(objAdd.options[objAdd.length-1].text,objAdd.options[objAdd.length-1].value);
		objAdd[objAdd.length-2] = new Option(objRemove.options[objRemove.selectedIndex].text,objRemove.options[objRemove.selectedIndex].value);			
		addSelected = objAdd.length-2;
		//remove the selected item(s) from the first panel...
		removeSelected = objRemove.selectedIndex;
		objRemove.remove(removeSelected);	
	}
	if(typeof(addSelected)!='undefined') objAdd.selectedIndex = addSelected;
	if(typeof(removeSelected)!='undefined') objRemove.selectedIndex = removeSelected;
}

//moving selected item(s) in the SELECT object(the object must set to multiple) up and down position...
//parameters:	cntrlOBJ = document.form_name.select_object_name
//				     pos = 'up' or 'down'
function f_moveSelectedItemUpDown(cntrlOBJ,pos){		
	count=0;
	firstSelected=-1;
	//check for multiple select...
	for(x=0;x<cntrlOBJ.length;x++){
		if(cntrlOBJ.options[x].value=='') cntrlOBJ.options[x].selected = false;
		firstSelected = ((pos=='up'&&firstSelected==-1&&cntrlOBJ.options[x].selected)||(pos=='down'&&cntrlOBJ.options[x].selected))?x:firstSelected;
		count = (cntrlOBJ.options[x].selected)?count+1:count;
	}
	//validate before moving column up & down...
	if(cntrlOBJ.selectedIndex==-1||cntrlOBJ.options[cntrlOBJ.selectedIndex].value==''||(pos=='up'&&firstSelected-1==-1)||(pos=='down'&&firstSelected>cntrlOBJ.length-3)) return false;
	//moving up...
	if(pos=='up'){
		for(x=firstSelected;x<cntrlOBJ.length;x++){
			if(!cntrlOBJ.options[x].selected) continue;
			f_moveUD(cntrlOBJ,x-1,x);	
		}
	}
	else{
		for(x=firstSelected;x>=0;x--){
			if(!cntrlOBJ.options[x].selected) continue;
			f_moveUD(cntrlOBJ,x+1,x);	
		}	
	}
	//set columns list into arrays...
	//f_setArray(formOBJ);	
}
//moving selected item(s) up & down function...
function f_moveUD(cntrlOBJ,index,firstSelected){
	val=cntrlOBJ.options[index].value;
	txt=cntrlOBJ.options[index].text;
	//move up,down
	cntrlOBJ[index] = new Option(cntrlOBJ.options[firstSelected].text,cntrlOBJ.options[firstSelected].value);
	cntrlOBJ[firstSelected] = new Option(txt,val);
	cntrlOBJ.options[index].selected = true;
}
	

<!--
/****************************************************
	 Author: Eric King
	 Url: http://redrival.com/eak/index.shtml
	 This script is free to use as long as this info is left in
	 Featured on Dynamic Drive script library (http://www.dynamicdrive.com)
****************************************************/
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
	if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
	if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
	else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,myname,settings);
}
// -->


/************************************
Description: initializing structure
*************************************/
function structure(col){
	this.name = new String();	
	this.name = col;
}		


function getCharKey(){
	return String.fromCharCode(event.keyCode);
}

//check for numeric keys only
function checkNumericKey(){
	var charkey = getCharKey(),
		myValidKey = false,
		array_keys = new Array(8,9,13,16,17,18,19,20,27,33,34,35,36,37,38,39,40,45,46,91,93,112,113,114,115,116,117,118,119,120,121,122,123,144);
	//check for exceptional keys....
	for(var k=0; k<array_keys.length; k++){
		if(array_keys[k]==event.keyCode){
			myValidKey = true;
			break;
		}
	}		
	//alert(event.keyCode);
	
	if(isNaN(charkey) && !myValidKey){
		alert("Invalid number!");
		return false;
	}
	return true;	
}

function checkNumber(myValue){
	if(isNaN(myValue)){
		alert(myValue+' is not a valid number.');
		myNumber = 0;
		return myNumber;
	}
	return myValue;
}

//reformat the the number (999,999.99)
function numberFormat(myNumber,mask){	
	
	var myMaskDecimalCount = mask.indexOf('.') != -1 ? mask.length - mask.indexOf('.') - 1 : 0;		// get mask decimal count
	var myValue = ReplaceNoCase(new String(myNumber),',','');	
	myValue = new String(f_roundUp(myNumber,myMaskDecimalCount));
	var myNumberDecimalCount = myValue.indexOf('.') != -1 ? myValue.length - myValue.indexOf('.') - 1 : 0;	// get pass in value decimal count
	var minusSign = myValue.indexOf('-') != -1 ? '-' : '';	// get negative sign	
	myValue = ReplaceNoCase(myValue,'-','');	// remove negative sign	
	
	while(myMaskDecimalCount > myNumberDecimalCount){
		myValue += '0';
		myNumberDecimalCount++;
	}
		
	var myMaskArray = mask.split(''),
		myMaskArrayCount = myMaskArray.length - 1,
		myFormatSymbol = '',
		myNewFormatedNumber = '';
	
	myValue = (IsBlank(myValue) || myValue == '.') ? '0' : ReplaceNoCase(myValue,'.','');		
	//check for invalid values...
	if(isNaN(myValue)){
		alert(myValue+' is not a valid number.');
		myNumber = 0;
		return myNumber;
	}
	
	//convert string to float when the string length is 5 then convert it back to string...
	if(myValue.length >= myMaskDecimalCount+1){
		myValue = parseFloat(myValue);
		myValue = new String(myValue);
	}
	
	//formating number
	if(myValue.length <= myMaskDecimalCount){
		myNewFormatedNumber = '.' + myValue;
	}
	else{
		var myNumberArray = myValue.split('');	
		for(var x=myNumberArray.length-1; x>=0; x--){
			myMaskArrayCount--;	
			myFormatSymbol = (myMaskArrayCount>=0 && !isNaN(myMaskArray[myMaskArrayCount])) ? '' : myMaskArray[myMaskArrayCount];
			myFormatSymbol = (x!=0) ? myFormatSymbol : '';
			
			myMaskArrayCount = (myFormatSymbol=='') ? myMaskArrayCount : myMaskArrayCount - 1;
			myNewFormatedNumber = myFormatSymbol + myNumberArray[x] + myNewFormatedNumber;
		}
	}
	
	myNewFormatedNumber = parseFloat(myNewFormatedNumber) == 0 ? 0 : myNewFormatedNumber;
	myValue = new String(myNewFormatedNumber);
	myNewFormatedNumber = myValue.indexOf('.') == 0 ? '0' + myValue : myValue;
	myNewFormatedNumber = minusSign+myNewFormatedNumber;	// add negative sign if number is negative
	
	return myNewFormatedNumber;
} 

/*highLight the row and de-highLight the row
 onmouseover="highLightRow(this,'#ffffcc');
 onmouseout="de_highLightRow(this);
*/
function highLightRow(obj,color){
   obj.style.backgroundColor = color;
}
function de_highLightRow(obj,color){
   color = typeof(color) == 'undefined' ? 'transparent' : color;
   obj.style.backgroundColor = color;
}

function getCurrentDate(){
    var d = new Date(),
        myDateString = d.toDateString().split(' '),
        myMonth = myDateString[1];
    myMonth = (myMonth=='Jan')?'01':(myMonth=='Feb')?'02':(myMonth=='Mar')?'03':(myMonth=='Apr')?'04':(myMonth=='May')?'05':(myMonth=='Jun')?'06':(myMonth=='Jul')?'07':(myMonth=='Aug')?'08':(myMonth=='Sep')?'09':(myMonth=='Oct')?'10':(myMonth=='Nov')?'11':'12';
    return myMonth+'/'+d.getDate()+'/'+d.getFullYear();
}

function getCurrentTime(){        
    var d = new Date(),
        myHour = parseInt(d.getHours()),
        myAMPM = (myHour <= 11) ? 'am' : 'pm';
    myHour = (myHour > 12) ? myHour - 12 : myHour;
    return myHour+':'+d.getMinutes()+myAMPM;
}

// find x,y position of an object...
function findCoordinate(obj) {
    var coordinate = new Object();
    coordinate.x = coordinate.y = 0;
    if (obj.offsetParent) {
	    coordinate.x = obj.offsetLeft
	    coordinate.y = obj.offsetTop
	    while (obj = obj.offsetParent) {
		    coordinate.x += obj.offsetLeft
		    coordinate.y += obj.offsetTop
	    }
    }
    return coordinate;
}

function moveToCoordinate(obj,moveObj,x,y) {
    var coordinate = findCoordinate(obj);
    coordinate.x = typeof x == 'undefined' ? coordinate.x : (coordinate.x+x);
    coordinate.y = typeof y == 'undefined' ? coordinate.y : (coordinate.y+y);
    moveObj.style.left = coordinate.x+'px';
    moveObj.style.top = coordinate.y+'px';
    return coordinate;
}

// required jquery.js
function isHideOBJ(coor, objID, e){
    e = (!e) ? window.event : e;   
    isClose = false;
    if(coor != null){         
        mouseX = isIE() ? event.x : e.pageX;
        mouseY = isIE() ? event.y : e.pageY;
    
        objW = parseInt(coor.x) + parseInt($("#"+objID).width()) + 5;
        objH = parseInt(coor.y) + parseInt($("#"+objID).height()) + 5;  
        isClose = ((mouseX < parseInt(coor.x) - 5 || mouseX > objW) || (mouseY < parseInt(coor.y) + 5 || mouseY > objH));  
    }
    return isClose;
}

function isIE(){
    return navigator.appName.substring(0,3).toUpperCase() != "NET";
}


// search text in select object.
function f_setSelectedIndex(select_box,search_string){
	var my_selectOBJ = document.getElementById(select_box);
	for(var x=0; x<my_selectOBJ.length; x++){
		s_select = my_selectOBJ.options[x].text;
		my_selectOBJ.selectedIndex = -1;
		if(s_select.substring(0,search_string.length) == search_string){
			my_selectOBJ.selectedIndex = x;
			break;
		}
	}
}
	
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){
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch (e){
				alert("Your browser does not support AJAX!");
				return xmlHttp;
			}
		}
	}
	return xmlHttp;
}

function _rand(range){
	return randomnumber=Math.floor(Math.random()*range);	
}



//select all item in the select box...
function _selectAll(objName){
	var obj = document.getElementById(objName);
	for(var x = 0; x < obj.length; x++)
		obj.options[x].selected = true;		
	
	if(obj.length > 1 && obj.options[0].value == '')
		obj.options[0].selected = false;	
}



// returns true if the string only contains characters A-Z, a-z or 0-9
function isAlphaNumeric(str){
  var regExp = /[^a-zA-Z0-9]/g
  if (regExp.test(str)) return false;
  return true;
}

// returns true if the string is a valid email
function isEmail(str){
  if(IsBlank(str)) return false;
  var regExp = /^[^\s()<>@,;:\/]+@\w[\w\.-]+\.[a-z]{2,}$/i
  return regExp.test(str);
}

// returns true if the string only contains characters A-Z or a-z
function isAlpha(str){
  var regExp = /[^a-zA-Z]/g
  if (regExp.test(str)) return false;
  return true;
}

// returns true if the string only contains characters 0-9
function isNumeric(str){
  var regExp = /[\D]/g
  if (regExp.test(str)) return false;
  return true;
}

// returns true if the string is a US phone number formatted as...
// (000)000-0000, (000) 000-0000, 000-000-0000, 000.000.0000, 000 000 0000, 0000000000
function isPhoneNumber(str){
  var regExp = /^\(?[2-9]\d{2}[\)\.-]?\s?\d{3}[\s\.-]?\d{4}$/
  return regExp.test(str);
}

// returns true if the string is a valid date formatted as...
// mm dd yyyy, mm/dd/yyyy, mm.dd.yyyy, mm-dd-yyyy
function isDate(str){
  var regExp = /^(\d{1,2})[\s\.\/-](\d{1,2})[\s\.\/-](\d{4})$/
  if (!regExp.test(str)) return false;
  var result = str.match(regExp);
  var m = parseInt(result[1]);
  var d = parseInt(result[2]);
  var y = parseInt(result[3]);
  if(m < 1 || m > 12 || y < 1900 || y > 2100) return false;
  if(m == 2){
          var days = ((y % 4) == 0) ? 29 : 28;
  }else if(m == 4 || m == 6 || m == 9 || m == 11){
          var days = 30;
  }else{
          var days = 31;
  }
  return (d >= 1 && d <= days);
}

// returns true if the string contains only whitespace
// cannot check a password type input for whitespace
function isWhitespace(str){ // NOT USED IN FORM VALIDATION
  var regExp = /[\S]/g
  if (regExp.test(str)) return false;
  return true;
}



function changeColor(cName, obj)
{
	obj.className = cName;
}	



// find list item
function ListFindNoCase(valueList, val, delimiters){
    delimiters = (typeof(delimiters) == 'undefined') ? ',' : delimiters;    
    //regExp1=eval("/(^|,)(00)(,|$)/gi");   // global search..
    regExp1=eval("/(^|"+delimiters+")("+val+")("+delimiters+"|$)/");   // first match..
    return regExp1.test(valueList);
}

// remove the list item..
function ListDelete(valueList, val, delimiters){
    delimiters = (typeof(delimiters) == 'undefined') ? ',' : delimiters;
    var regExp=eval('/'+
                    delimiters+val+delimiters+ // between 2 ',' e.g: ",56,"
                    '|^'+val+delimiters+ // very first number e.g "56,32,78"
                    '|'+delimiters+val+'$'+ // very last number e.g ",56"
                    '|^'+val+'$'+ // it is the only number in the list e.g "56"
                    '/gi');
    
    while(ListFindNoCase(valueList, val))
    {
        valueList = valueList.replace(regExp,',');      
    }         
    
    first = valueList.substring(0,delimiters.length);
    if(first == delimiters)
        valueList = valueList.substring(delimiters.length,valueList.length);   
    
    last = valueList.substring((valueList.length - delimiters.length),valueList.length);
    if(last == delimiters)
        valueList = valueList.substring(0,valueList.length - delimiters.length);   
            
    return valueList;    
}

// append new value into a list..
function ListAppend(valueList, val, delimiters){
    delimiters = (typeof(delimiters) == 'undefined') ? ',' : delimiters;
    valueList = (valueList == '') ? val : valueList + delimiters + val;    
    return valueList;
}

// Check for valid userid
function IsValidUserId(UserID){
    var regExp = eval("/^([a-zA-Z])([a-zA-Z0-9._-]{3,20})$/");
    return regExp.test(UserID);
}




























///* Scroll To Bottom of the Div..
//   //Create a new instance with the name of the div;
//   var divScroll = new chatscroll.Pane('divExample');
//   
//   //When ever you add something to the div call the method activeScroll.
//   divScroll.activeScroll();
// */
//var chatscroll = new Object();
//chatscroll.Pane = function(scrollContainerId){
//    this.bottomThreshold = 20;
//    this.scrollContainerId = scrollContainerId;
//    this._lastScrollPosition = 100000000;
//}
//chatscroll.Pane.prototype.activeScroll = function(){

//    var _ref = this;
//    var scrollDiv = document.getElementById(this.scrollContainerId);
//    var currentHeight = 0;

//    var _getElementHeight = function(){
//        var intHt = 0;
//        if(scrollDiv.style.pixelHeight)intHt = scrollDiv.style.pixelHeight;
//        else intHt = scrollDiv.offsetHeight;
//        return parseInt(intHt);
//    }

//    var _hasUserScrolled = function(){
//        if(_ref._lastScrollPosition == scrollDiv.scrollTop || _ref._lastScrollPosition == null)
//            return false;
//        return true;
//    }

//    var _scrollIfInZone = function(){
//        if( !_hasUserScrolled || 
//            (currentHeight - scrollDiv.scrollTop - _getElementHeight() <= _ref.bottomThreshold)){
//            scrollDiv.scrollTop = currentHeight;
//            _ref._isUserActive = false;
//        }
//    }

//    if (scrollDiv.scrollHeight > 0)currentHeight = scrollDiv.scrollHeight;
//    else if(scrollDiv.offsetHeight > 0)currentHeight = scrollDiv.offsetHeight;

//    _scrollIfInZone();

//    _ref = null;
//    scrollDiv = null;

//}


/*
function setBodyHeightToContentHeight() {
    document.body.style.height = Math.max(document.documentElement.scrollHeight, document.body.scrollHeight)+"px";
}
setBodyHeightToContentHeight();
window.attachEvent('onresize', setBodyHeightToContentHeight);
*/
