String.prototype.trim = function()
{
    return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.lTrim = function()
{
    return this.replace(/(^[\s]*)/g, "");
}
String.prototype.rTrim = function()
{
    return this.replace(/([\s]*$)/g, "");
}

//Check all boxes
function checkUncheckAll(theElement) {
	var theForm = theElement.form, z = 0;
	for(i=0; i<theForm.length;i++){
		if(theForm[i].type == 'checkbox' && theForm[i].name != 'checkall'){
			theForm[i].checked = theElement.checked;
		}
	}
}

//Confirm form when delete
function confirmSubmit()
{
var agree=confirm("Are you sure you wish to continue?");
if (agree)
	return true ;
else
	return false ;
}

//prevent form submission when ENTER is hit in text field
function noenter() {
  return !(window.event && window.event.keyCode == 13); 
}

//show arrow position in communityHome, eventHome, etc. page
function showArrow(index){
	for(i=0;i<document.all.arrow.length;i++){
		document.all.arrow[i].style.display = "none";
	}
	document.all.arrow[index].style.display = "";
}

function dynIframeSize(iframename) {
  var pTar = null;
  if (document.getElementById){
    pTar = document.getElementById(iframename);
  }
  else{
    eval('pTar = ' + iframename + ';');
  }
  if (pTar && !window.opera){
    //begin resizing iframe
    pTar.style.display="block"
    
    if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight){
      //ns6 syntax
      pTar.height = pTar.contentDocument.body.offsetHeight; 
    }
    else if (pTar.Document && pTar.Document.body.scrollHeight){
      //ie5+ syntax
      pTar.height = pTar.Document.body.scrollHeight;
    }
  }
}

function textCounter(form,field,maxlimit) { 
	textForm = eval('document.'+ form);
	//textForm.remLen.value = (maxlimit-field.value.length);
	//var remainChar = textForm.remLen.value;
	if (field.value.length > maxlimit)
	{ 
		field.value = field.value.substring(0, maxlimit);
		//textForm.remLen.value = 0; 
	}
	else 
		textForm.remLen.value = maxlimit - field.value.length;
}

//******************************************************************************
//How to use the following function to display or hide the block:
//1. Please put your content what you want to display or hide into the 
//   "div" tag, and define the "div" as "<div class="collapse" id="yourElement"></div>".
//2. You want to use button or <a> link to display or hide the block, 
//    use like this in the button or <a> link:
//    want to expand:   onClick="javascript:setClassById('yourElement','expand');"
//    want to collapse: onClick="javascript:setClassById('yourElement','collapse');".
//3. The function will use the css.css to display or hide the block.
//4. The detail example please view the "/en/common/user/community/communityEdit.jsp".
function getObject(objectId) 
{
if (document.all && !document.getElementById) 
{
return document.all(objectId);
} 
else 
{
return document.getElementById(objectId);
}
}

function setClassById(idVal, classVal) 
{
getObject(idVal).className=classVal;
}
//******************************************************************************

var isOpen = 0;
//var isClosing = 0;
function viewHelp(openLink){
	//if(isClosing) return;
	//alert("isOpen1:" + isOpen);
	if(isOpen) 
		return;
	else{
	window.open(openLink, "", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=620,height=430");
	}
	isOpen = 1;
	//alert("isOpen2:" + isOpen);
}

function helpClose(){
	isOpen = opener.isOpen;
	//alert("opener isOpen1:" + isOpen);
	window.close();
	isOpen = 0;
	opener.isOpen = isOpen;
	//alert("opener isOpen2:" + isOpen);
}

function closeonunload(){
	//alert('?????');
	opener.isOpen = 0;
	//alert("opener isOpen3:" + opener.isOpen);
}

// get form element by id
function $(idname){
	if (document.getElementById){ return document.getElementById(idname); } 
	else if (document.all) { return document.all[idname];} 
	else if (document.layers) {	return document.layers[idname];	}
	else { return null; }
}

function bLength(str)
{
	return str.replace(/[^\x00-\xff]/g,"**").length;
}

//***************************************
//Get a parameter value on url
//
function getUrlParameter( name )
{
     var regexS = "[\\?&]"+name+"=([^&#]*)";
     var regex = new RegExp( regexS );
     var tmpURL = window.location.href;
     var results = regex.exec( tmpURL );
     if( results == null )
       return "";
     else
       return results[1];
}

function gotoUrlInNewWindow(url, width, height) 
{
  window.open(url, '', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,width=' + width + ',height=' + height);
}   

