// JavaScript Document
function getObjAttributes(obj){
	str = "";
	for(a in obj){
		str += (str==""?"":",\n ");
		str += a + "=" + obj[a];
	}
	return str;
}
function showPopUpHTMLSource(sourceCode){
	awin = window.open();
	awin.document.open();
	awin.document.write(sourceCode);
	awin.document.close();
	awin.focus();
}
var ie4 = document.all;
var ns4 = document.layers;
var ns6 = document.getElementById && !document.all; 

var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height, scrollbars)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  if(scrollbars==undefined||scrollbars!=true) scrollbars = "no";
  else scrollbars = "yes";
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scrollbars+',resizable=no,copyhistory=yes,width='+width+',height='+height+(left==null?'':(',left='+left+',screenX='+left))+(top==null?'':(', top='+top+',screenY='+top+'')));
}

function isValidDate(value){
	if(value==undefined) return false;
	value = value.replace(/^\s/, "");
	value = value.replace(/\s$/, "");
	if(value=="") return false;
	if(value.match(/^\d{1,2}\/\d{1,2}\/\d{1,4}$/)==null) return false;
	arr = value.split("/");
	aDate = new Date(Date.parse(arr[1]+'/'+arr[0]+'/'+arr[2]));
	//alert([value,aDate]);
	if((aDate.getDate()!=arr[0])||(aDate.getMonth()!=arr[1]-1)||(aDate.getFullYear()!=arr[2])) return false;
	return true;
}

function number_format(number, num_decimal_places, dec_seperator, thousands_seperator){
	rsl = "";
	negativeSign = '';
	if(number<0){ negativeSign='-'; number=Math.abs(number);}
	intVal = Math.floor(number);	intPart = "";
	decVal = (number - intVal );	decPart = "";
	while(true){
		modVal = (intVal%1000).toString();
		intVal = Math.floor(intVal/1000);
		if(intVal>0){ while(modVal.length<3){ modVal = '0'+modVal;} }
		intPart = modVal + (intPart==""?"":thousands_seperator) + intPart;
		if((intVal<=0)) break;
	}
	while(num_decimal_places>0){
		modVal = (Math.floor(decVal*10)).toString();
		decPart += modVal;
		num_decimal_places--;
	}
	if(decPart!="") decPart = dec_seperator + decPart;
	rsl = (negativeSign+intPart+decPart)
	return rsl;
}

// Example:
// alert( readCookie("myCookie") );

function readCookie(name){
  var cookieValue = "";
  var search = name + "=";
  if(document.cookie.length > 0){ 
    offset = document.cookie.indexOf(search);
    if (offset != -1){ 
      offset += search.length;
      end = document.cookie.indexOf(";", offset);
      if (end == -1) end = document.cookie.length;
      cookieValue = unescape(document.cookie.substring(offset, end))
    }
  }
  return cookieValue;
}

// Example:
// writeCookie("myCookie", "my name", 24);
// Stores the string "my name" in the cookie "myCookie" which expires after 24 hours.

function writeCookie(name, value, hours){
  var expire = "";
  if(hours != null) {
    expire = new Date((new Date()).getTime() + hours * 3600000);
    expire = "; expires=" + expire.toGMTString();
  }
  document.cookie = name + "=" + escape(value) + expire;
}

function getElementsByPrefixName(inPrefix,inRoot){ 
	var elem_array = new Array; 
	
	if(typeof inRoot.firstChild!= 'undefined'){ 
		var elem = inRoot.firstChild; 
		while (elem!= null){ 
			if(typeof elem.firstChild!= 'undefined'){ 
				elem_array = elem_array.concat(getElementsByPrefixName(inPrefix,elem)); 
			} 
			if(typeof elem.name!= 'undefined'){ 
				var reg = new RegExp ( '^'+inPrefix+'.*' ); 
				if(elem.name.match(reg)){ 
					elem_array.push(elem); 
				} 
			} 
			elem = elem.nextSibling; 
		} 
	} 
	return elem_array; 
} 
function toggleFilter(id){
	obj1 = document.getElementById(id);
	if(obj1){
		obj1.style.display=(obj1.style.display=='block'?obj1.style.display='none':obj1.style.display='block');
	}
}

function findPosition( oElement ) {
	var posX=0, posY=0, posW=0, posH=0;
	while((oElement!=undefined) && (oElement.tagName.toUpperCase()!='BODY')){
		posX += oElement.offsetLeft;
		posY += oElement.offsetTop;
		posW += oElement.offsetWidth;
		posH += oElement.offsetHeight;
		oElement = oElement.offsetParent;
	} 
	return [posX, posY, posW, posH];
}

function f_clientWidth() {
	return f_filterResults (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}

function f_clientHeight() {
	return f_filterResults (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}

function f_scrollLeft() {
	return f_filterResults (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}

function f_scrollTop() {
	return f_filterResults (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_filterResults(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}


