
var checkAll = true;
function ChangeAll(form, item){
	if(form.elements == undefined) {
		return;
	}
	for (var i=0;i<form.elements.length;i++) {
		var e = form.elements[i];
		if(item == e.name) {
			if(checkAll) {
				e.checked = true;
			}
			else {
				e.checked = false;
			}
		}
	}
	checkAll = !checkAll;
}


function disableElements(form){
	for (var i = 0 ;i < form.elements.length ;i++) {
		var e = form.elements[i];
		e.disabled = true ;
	}
}

function switchDiv(div_id, mode){
  div_id.style.display	=	mode ;
}


	function getObj(name){
		//modify by tony 2008.02.27 18:22:00
		var obj = null;
		if (document.getElementById)
			obj = document.getElementById(name);
		else if (document.layers)
			obj = document.layers[name];
		else if (document.all)
			obj = document.all[name];
		if(obj==null)
		{
		obj = document.all[name];
		}
		return obj;
	}

function addToBookmark(strURL,strTitle){
	if ( document.all ) {
		window.external.AddFavorite(strURL, strTitle);
	}
}

function addToClipboard(obj){
	// window.external.menuArguments.clipboardData.setData("Text", str) ;
	var rng = document.body.createTextRange();
	rng.moveToElementText(obj);
	rng.execCommand("Copy");
}


function jumpTo(b){
	javascript:window.location.hash=b;
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function initSelectField(selectObj, defaultValue){
	for(i=0;i<selectObj.options.length;i++){
		if(selectObj.options[i].value == defaultValue){
			selectObj.options[i].selected = true;
		}
	}
}

function initRadioField(radioObj, defaultValue){
	for (i=0;i<radioObj.length;i++){
		if (radioObj[i].value == defaultValue){
			radioObj[i].checked = true;
		}
	}
}

/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/

function setJSCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

function getJSCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/

function deleteJSCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function ltrim(str) {
    var whitespace = new String(" \t\n\r");
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(0)) != -1)
    {
        var j=0, i = s.length;
        while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
        {
            j++;
        }
        s = s.substring(j, i);
    }
    return s;
}

function rtrim(str) {
    var whitespace = new String(" \t\n\r");
    var s = new String(str);
    if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
    {
        var i = s.length - 1;
        while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
        {
            i--;
        }
        s = s.substring(0, i+1);
    }
    return s;

}

function trim(str) {
    return rtrim(ltrim(str));
}
