function clearTable(table, leaveRows){
		if (leaveRows == null){
			leaveRows = 1;
		}
		var countRows = table.rows.length;
		for(var i = countRows - 1; i>=leaveRows; i--){
			table.deleteRow(i);
		}
}
function IsNumeric(sText) {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char; 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         	IsNumber = false;
         }
      }
   return IsNumber;
   
}
function show_jspopup(title, text, method, absolute)
{
    if (document.all) {
        topoffset=document.body.scrollTop;
        leftoffset=document.body.scrollLeft;
        WIDTH=document.body.clientWidth;
        HEIGHT=document.body.clientHeight;
    } else {
        topoffset=pageYOffset;
        leftoffset=pageXOffset;
        WIDTH=window.innerWidth;
        HEIGHT=window.innerHeight;
    }
    if(WIDTH%2!=0) WIDTH--;
    if(HEIGHT%2!=0) HEIGHT--;
    newtop=((HEIGHT-200)/2)+topoffset;
    if (document.all) {
        newleft = 150;
    } else {
        newleft = ((WIDTH-400)/2)+leftoffset;
    }
    
    if (document.getElementById('helpdiv') == null)  {
    	var d = '<div id="helpdiv"><div id="helpdiv-hide"><a href="javascript:hide_jspopup();">[X]</a></div><div id="helpdiv-title"></div><div id="helpdiv-content"><div id="help-text"></div></div></div>';
    	if (document.getElementById('div-for-helpdiv')){
    		document.getElementById('div-for-helpdiv').innerHTML = d;
    	} else {
    		var body_obj = document.getElementsByTagName('body')[0];
    		body_obj.innerHTML = d + body_obj.innerHTML;
    	}
    }
	if (absolute){
		document.getElementById('helpdiv').style.position = 'absolute';
	}
    document.getElementById('helpdiv').style.left= newleft;
    document.getElementById('helpdiv').style.top = newtop;

    if (method == 'ajax'){
		getContentByAjax('helpdiv', title, function(){document.getElementById('helpdiv').style.display = 'block';});
    } else {
    	settext_jspopup(title, text);
    	document.getElementById('helpdiv').style.display = 'block';
    }
}
function settext_jspopup(title, text){
    document.getElementById('helpdiv-title').innerHTML = title;
    document.getElementById('help-text').innerHTML = text;	
}

function hide_jspopup()
{
    document.getElementById('helpdiv').style.display = 'none';
    document.getElementById('helpdiv-title').innerHTML = "";
    document.getElementById('help-text').innerHTML = "";
}
function getAjaxObj() {
	var xmlHttp;
	try {
		xmlHttp = new XMLHttpRequest();
    } catch (e) {
    	try {
			xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch (e) {
        		alert("Your browser does not support AJAX!");
        		return false;
			}
		}
	}
	return xmlHttp;
}
function getContentByAjax(element_id, url, funcadditional) {
	var xh = getAjaxObj();	
	if (!xh) return;
	xh.onreadystatechange=function() {
		if(xh.readyState == 4) {
	  		var obj = document.getElementById(element_id);
	  		if (obj){
	  			obj.innerHTML = xh.responseText;
	  			var scripts = getScriptsFromText(xh.responseText)	  			
	  			for(var i = 0; i < scripts.length; i++ ){
	  				try {
	  					document.eval(scripts[i]);
	  				} catch(e) {
	  					eval(scripts[i]);
	  				}
	  			}
	  		}	
	  		  		
	  		if (funcadditional){
	  			funcadditional(xh.responseText);	  			
	  		}	
		}
	}
	xh.open("GET", url, true);	
	xh.send(null);
}
function nl2br(str) {
	if (str != null) {
		return str.split("\n").join("<br>");
	} else {
		return "";
	}
}
function getScriptsFromText(tmp) {
	var scripts = [];
	try{
		while( tmp.indexOf("<script>") != -1) {
			var startindex = tmp.indexOf("<script>");
			var endindex   = tmp.indexOf("<\/script>");
			var newstartindex = startindex + "<script>".length;
			scripts[scripts.length] = tmp.substr(newstartindex, endindex - newstartindex);
			var newendindex = endindex + "<\/script>".length;
			tmp = tmp.substr(newendindex, tmp.length - newendindex);
		}
	} catch(e){}
	return scripts;
}
function newWin(source, wid, hei) {
     w = screen.width;
     h = screen.height;
     pos_x = Math.round((screen.width - wid)/2);
     pos_y = Math.round((screen.height - hei)/2);   
     strFeatures="height="+hei+", width="+wid+", channelmode=0, directories=0, fullscreen=0, location=0, menubar=0, status=0, toolbar=0, Top="+pos_y+", left="+pos_x + "";
     retVal = window.open(source,"_blank",strFeatures);
}

