// Trim all extra whitespaces within string.
// First, leading and trailing spaces are removed from the string in a couple of statements. Build a regular expression statement that will find one or// more starting white space characters (space, tab, form feed, or line feed), then any character (\W\w ends up being anything), then one or more
// ending white spaces after a word boundary. If that pattern is found in the input string, maintain only the middle characters (the \W\w part).
function trim(value) {
   var temp = value;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = /  /g;
   while (temp.match(obj)) { temp = temp.replace(obj, " "); }
   return temp;
}

function isBlank(testStr)
{  	
	if (testStr.length == 0) { // nothing entered?
		return 'y';
	}
	for (var i = 0; i <= testStr.length-1; i++) { // all spaces?
		if (testStr.charAt(i) != " ") {
			return 'n';
		}	
	}
	return 'y';
}

function isNumeric(val)
{
   if(isNaN(val)) {
      return false;
   } else return true;
/*	  if(val!=''){
		  var regExp	=	/^[0-9\s+-]+$/;  
		  return regExp.test(val);
	  } else return false; */
}

function SetToFirstControl()
{
   alert(document.forms[0].elements.length);
   if( (document.forms.length >= 0) && (document.forms[0].elements.length > 0) ) {
      document.forms[0].elements[0].select();
      document.forms[0].elements[0].focus();
   }
}


function popupWin(url_add) {
   window.open(url_add,'welcome', 'width=900,height=440,menubar=yes,status=no,location=no,toolbar=no,scrollbars=yes');
}


function showHelpDiv (divID) { //alert(divID);
	var helpDiv = document.getElementById(divID);
	var coverFrame = document.getElementById('cover' + divID);
	
	coverFrame.style.top = helpDiv.style.top;
	coverFrame.style.left = helpDiv.style.left;
	coverFrame.style.width = helpDiv.style.width;
//	alert(document.forms[0].elements.length);
	coverFrame.style.height = document.forms[0].elements.length * 20;
	coverFrame.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
	//coverFrame.style.zIndex = helpDiv.style.zIndex - 1;
	
	if (helpDiv.style.display == 'block') {
		helpDiv.style.display = 'none';
	} else {
		helpDiv.style.display = 'block';
	}
	coverFrame.style.display = helpDiv.style.display;
	return true;
}


function hidesupplier1(frm) {
   //alert(frm);
	//alert(document.myForm.categories.selectedIndex);
    
	if(document.getElementById('cats1').selectedIndex == 0) {
		document.getElementById('manu1').style.display = '';		
		document.getElementById('manu2').style.display = 'none';
		//document.getElementById('wh').style.display = '';
	} else {
		document.getElementById('manu2').style.display = '';		
		document.getElementById('manu1').style.display = 'none';		
		//document.getElementById('wh').style.display = 'none';		
	}
	//document.getElementById('results').style.display = 'none';	
}

function confirmDeleteGlobal() {
  	if(confirm('Are you sure you want to delete?')){
  		return true;
  	} else return false;  	
}


function showHideElements(elem, func, speed) {
   
   if (elem == null) return;
   
   if(!speed) speed = "fast";
   
   if(!func) func = "show";
   
   var len = elem.length;
   for (var i = 0; i < len; i++) {
      if (func == 'show') {
         jQuery("#"+elem[i]).show(speed);
      } else {
         jQuery("#"+elem[i]).hide(speed);
      }   
   }
}


