	//
	// Cancle the filter effects of the image
	//@ parm:	img_id - the id of the image
	//
function noFilter( img_id ){
	changeStyle( img_id, false, 0);	
}
	//
	// Add filter effects to the image
	//@ parm:	img_id - the id of the image
	//
function getFilter( img_id ){
	changeStyle( img_id, "alpha(Opacity=50)", "2px solid #ff9900");	
}
	//
	// Change style of the element
	//@ parm:	element - the name of the element, on which the filter effect will be modified
	//			filter - new filter effect of the image
	//			border - new border style of the image
	//
function changeStyle( element, filter, border){
	element.style.filter= filter;
	element.style.border = border;	
}

	//
	// Relocate current active window to new URL
	// @parm:	url - new URL the window will display
	//
function locate( url ){
	document.URL = url;
}

	//
	// Pop up a new unnamed window in specific width (w) and height (h)
	// @parm:	url - new URL the pop up window will display
	//			w - the width of the window
	//			h - the height of the window 
	// 
function popup( url, w, h ){
  window.open(url, "", "left=20,top=20,scrollbars=yes,resizable=yes," + "width=" + w + ",height=" + h);
}
	//
	// ?Close current window
	//
function closewindow(){
  window.close();
}
	//
	// open a new unnamed window with specific width (w) and height (h)
	// @parm:	url - new URL the window will display
	//			w - the width of the window
	//			h - the height of the window 
	// 
function openwindow(url, w, h){
	var root = "http://ndlabs.com/new/";
	var newURL = root + url;	
	window.open(newURL, "", "left=20,top=20,toolbar=yes,menubar=yes,status=yes,scrollbars=yes,resizable=yes,width="+w +",height="+h);
}

	//
	// Squish out symbols like "-" "." "," "_"
	// @parm:	instr - input string needed to be trimed
	//
function trimSymbol( instr ){
	var outstr = "";
	if( instr.length > 1){				
		outstr = instr.replace(/-|\.|,|_/g, '');
	}		
	return outstr;
}

	//
	// Squish out all white space in a string
	// @parm:	instr - input string needed to be trimed
	//
function trimSpace( instr ){
	var outstr = "";
	if( instr.length > 1){		
		outstr = instr.replace(/\s/g, '');		
	}		
	return outstr;
}

	//
	// Trim the white space at the begin and end of a string
	// @parm:	instr - input string needed to be trimed
	//
function trim( instr ){
	var outstr = "";
	if( instr.length > 0 ){
		outstr = trimRight( instr );
		outstr = trimLeft( instr );
	}
	return outstr;	
}
	//
	// Trim the white space to the left of a string
	// @parm:	instr - input string needed to be trimed
	//
function trimRight( instr ){
	var outstr = "";
	var w_space = String.fromCharCode(32); // unicode of white space	
	if( instr.length > 0){
		var i = instr.length - 1;
		while( i >= 0 ){
			if( instr.charAt(i) != w_space ){
				outstr = instr.substring(0, i+1);
				break;			
			}
			i--;
		}	
	}	
	return outstr;
}
	//
	// Trim the white space to the right of a string
	// @parm:	instr - input string needed to be trimed
	//
function trimLeft( instr ){
	var outstr = "";
	var w_space = String.fromCharCode(32);	
	if( instr.length > 0){
		for( var i=0; i < instr.length; i++ ){
			if( instr.charAt(i) != w_space ){
				outstr = instr.substring(i, instr.length);
				break;			
			}			
		}		
	}	
	return outstr;
}

	//
	// verify correct credid card number,
	// * Improve: make field focus if return false
	// @ parm : strValue - string represents of the field value 	
	//
function isCreditcard( strValue ){
		//squish out all white space and symbles in the string
	var str = trimSpace( strValue );
	str = trimSymbol( str );
    if ( str == "0000000000000000"){// for test
		return true;
	}
	if ( !isInteger(str) || str.length == 0 || str.length > 16){		
		return false;
	}	
    	
		// now check mod10
	var doubledigit = str.length % 2 == 1 ? false : true;
	var checkdigit = 0;
	var tempdigit;
	for( var i = 0; i < str.length; i++ ){
		tempdigit = eval( str.charAt(i) );
		if ( doubledigit ){
			tempdigit *= 2;
			checkdigit += (tempdigit % 10);

			if ( (tempdigit / 10) >= 1.0 ){
				checkdigit++;
			}
			doubledigit = false;
		}
		else{
			checkdigit += tempdigit;
			doubledigit = true;
		}
	}	
	return (checkdigit % 10) == 0 ? true : false;	
}

	//
	// Varify credit card verification code
	// It has to a number with 3 or 4 digits
	// @ parm : value - string represents of the field value
	//
function isVerifyCode( strType, strValue ){
	var type = strType.toUpperCase();
	if( isInteger( strValue ) ){
		if( type == "AMEX" && strValue.length == 4){
			return true;
		}else if( type != "AMEX" && strValue.length == 3 ){
			return true;
		}
	}
	return false;
}

	//
	// Varify correct zip format in USA only
	// @ parm : strValue - string reprents of the field value
	//
function isZip( strValue ){
	if( isInteger( strValue ) ){
		if( strValue.length == 5 || strValue.length == 9){
			return true;
		}
	}
	return false;
}

	//
	// varify correct phone number format
	// It has to be 10 digits
	// @ parm: strValue - string reprents of the field value
	//
function isPhone( strValue ){
		// squish out all white space & symbols in a string
//alert("into func isPhone(), Phone NO = " + strValue );	//@@@ 
	var str = trimSpace( strValue );
	str = trimSymbol( str ); 
	if( str.length == 10 && isInteger( str ) ){
		return true;
	}	
	return false;
}

	//
	// verify email format
	// Regular expression is used if brower support it
	// otherwise by using loop comparing for checking (cost time complexity)
	// 	 - reg1: email should not contains patterns like: > 1 '@' or '.',
	//		'@.' or '.@' , and end at one or more '.'.
	//   - reg2: legal email pattern -- 
	//		1. One or more characters before the "@"
	//		2. An optional "[", because user@[255.255.255.0] is a valid e-mail
	//		3. A sequence of letters, numbers, and periods, which are all valid domain or IP address characters
	//		4. A period followed by a 2-3 letter suffix
	//		5. An optional "]"
	// @ parm: strValue - string reprents of the field value 
	//
function isEmail( strValue ){ 
  var str = trimSpace( strValue );
//alert("After trim, Email = " + str);	//@@@ 
  
  if (window.RegExp) {
    var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
    var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
    var reg1 = new RegExp(reg1str);
    var reg2 = new RegExp(reg2str);
    if (!reg1.test(str) && reg2.test(str)){
		return true; 
	}
  }
  else { // browser do not support regular expression
	var goodChars = "abcdefghijklmnopqrstuvwxyz0123456789_.@";
		//check length
	if( str.length > 5 ){
		var i = str.indexOf('@');
		if( i > 0 ){	// '@' not be first char
			var domain = str.substrig(i+1, str.length);
			if( domain.length > 3 ){
					// check valid char
				for (var j = 0; j < str.length; j++){
					var myChar = str.charAt(i).toLowerCase();
					if( goodChars.indexOf(mayChar) < 0){						
						return false;			
					}
				}// end for loop
				return true;				
			}// end check domain length
		}// end check index of "@"		
	}
  }
  return false;
}

	//@@@
	// Returns true if value is a number (not NULL)
    // otherwise returns false; improve this function by using Regular Expression
	// @ parm : strValue - string reprents of the field value 
	//
function isInteger( strValue ){	
	var rst = true;
	   // squish out separate symbles like: "-", or space
	var str = trimSpace( strValue );
	str = trimSymbol( str );
	if( str.length == 0 ){
        rst = false;
	}else{
		for ( var i=0; i <= str.length-1; i++) {
		  if (str.charAt(i) < "0" || str.charAt(i) > "9") {			
			rst = false;
		  }
		}
	}	
	return rst;  
}

	//
	// Test whether form object/field has value
	// * Note: Here, only check fields with text as value, includes textFeild, textArea...
	// @ parm:	obj - object's name with string value
	//			obj_type - string object type. It will be one of two types: 'text' or 'password'
	//
function hasValue(obj, obj_type){
	var rst = false;
	obj_type = obj_type.toUpperCase();	
    if( obj_type == "TEXT" || obj_type == "PASSWORD" ){
		var str = trim( obj.value ); // customized function trim() in libray.js
    	if ( str.length > 0 ) 
      		rst = true;
    }    
	return rst; 
}

	//
	// Prompt error message while one form field contains an error input.
	// In the meanwhile, select and focus on the field, on which an error occur.
	// @ parm:	errField - the field, on which an error occur
	//			msg - Error message will display on the prompt window
	//
function promptError( errField, msg ){
	errField.select();
	errField.focus();	      
	alert(msg);
}

	//
	// Clean all the values of the elements on a specified form
	// @ parm:	frm - the name of the form needed to be clean
	//
function clearForm( frm ){
	frm.reset(); //reset to default value first, good for none-text fields, like 'Select'
	for( var i = 0; i < frm.elements.length; i++){
		var e = frm.elements[i];
		var tp = e.type.toLowerCase();
		if( tp == "text" || tp == "textarea" || tp == "password"){
			e.value = "";
		}
		if( tp == "checkbox" || tp == "radio"){
			e.checked = false;		
		}
	}	
}

	// ?? Test the search element in ndform is not empty 
function checkblank(){  
   if(document.ndform.search.value==""){
     alert("Please enter in a item!");
	 return false;
   }
    else{ 
	  return true; 
	}
}
