
function noFilter( img_id ){
	changeStyle( img_id, false, 0);	
}

function getFilter( img_id ){	
	changeStyle( img_id, "alpha(Opacity=50)", 0);	
}

function changeStyle( element, filter, border){
	element.style.filter= filter;
	element.style.border = border;	
}

function checkblank(){  
   if(document.ndform.search.value==""){
     alert("Please enter in a item!");
	 return false;
   }
    else{ 
	  return true; 
	}
}

function locate( url ){
	location = url;
}

function popup(imgPath,x,y){
  window.open(imgPath,"","width=" + x + ",height=" + y + ",scrollbars=yes,resizable=yes");
}

function closewindow(){
  window.close();
}

function openwindow(url, w, h){
	var newURL = "http://ndlabs.com/new/" + url;	
	window.open(newURL, "", "toolbar=yes,menubar=yes,scrollbars=yes,resizable=yes,width="+w +",height="+h);
}

	// squish out symbols like "-" "." "," "_"
function trimSymbol( instr ){
	var outstr = "";
	if( instr.length > 1){				
		outstr = instr.replace(/-|\.|,|_/g, '');
	}		
	return outstr;
}
	
function trimSpace( instr ){
	var outstr = "";
	if( instr.length > 1){		
		outstr = instr.replace(/\s/g, '');		
	}		
	return outstr;
}

function trim( instr ){
	var outstr = "";
	if( instr.length > 0 ){
		outstr = trimRight( instr );
		outstr = trimLeft( instr );
	}
	return outstr;	
}

function trimRight( instr ){
	var outstr = "";
	var w_space = String.fromCharCode(32);	
	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;
}

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;
}

	//
	// 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
	//@ 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;
}

