function trim(str) {
   var temp = str;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = / +/g;
   temp = temp.replace(obj, " ");
   if (temp == " ") { temp = ""; }
   return temp;
}

String.prototype.trim = function() {
   var temp = this;
   var obj = /^(\s*)([\W\w]*)(\b\s*$)/;
   if (obj.test(temp)) { temp = temp.replace(obj, '$2'); }
   var obj = / +/g;
   temp = temp.replace(obj, " ");
   if (temp == " ") { temp = ""; }
   return temp;
}

function clearSpaces(str) {
	var tmp = "";
	var i = 0;
	for(i = 0; i < str.length; i++)
		if(str.charAt(i) != ' ' && str.charAt(i) != '\t' && str.charAt(i) != '\n' && str.charAt(i) != '\r')
			tmp = tmp + str.charAt(i);

	return tmp;
}

function StopEvent(pE)
{
   if (!pE)
     if (window.event)
	pE = window.event;
     else
	return;
   if (pE.cancelBubble != null)
      pE.cancelBubble = true;
   if (pE.stopPropagation)
      pE.stopPropagation();
   if (pE.preventDefault)
      pE.preventDefault();
   if (window.event)
      pE.returnValue = false;
   if (pE.cancel != null)
      pE.cancel = true;
}

function number_keypress(e) {
    var key = (document.all) ? e.keyCode : e.which;
    if ((key < 48 || key > 57) && key != 8 && key != 0)
	    StopEvent(e);
}

function number_space_keypress(e) {
    var key = (document.all) ? e.keyCode : e.which;
    if((key < 48 || key > 57) && key != 32 && key != 8 && key != 0)
	    StopEvent(e);
}

function decimal_keypress(e) {
    var key = (document.all) ? e.keyCode : e.which;
	if((key < 48 || key > 57) && key != 46 && key != 44 && key != 8 && key != 0)
	    StopEvent(e);
}

function decimal_changed() {
	event.srcElement.value = event.srcElement.value.replace(",", ".");
	try {
		var val = parseFloat(event.srcElement.value);
	} catch(ex) {
		event.srcElement.value = "";
	}
}

function strfill(size, character) {
	var str = '';
	for(sf=0; sf < size; sf++)
		str += character;

	return str;
}

function limitText(ctl, size)
{
    if (ctl.value.length>size)
        ctl.value = ctl.value.substring(0,size);
}

function showdeadcenterdiv(Xwidth,Yheight,divid) { 
    // First, determine how much the visitor has scrolled

    var scrolledX, scrolledY; 
    if( self.pageYOffset ) { 
    scrolledX = self.pageXOffset; 
    scrolledY = self.pageYOffset; 
    } else if( document.documentElement && document.documentElement.scrollTop ) { 
    scrolledX = document.documentElement.scrollLeft; 
    scrolledY = document.documentElement.scrollTop; 
    } else if( document.body ) { 
    scrolledX = document.body.scrollLeft; 
    scrolledY = document.body.scrollTop; 
    }

    // Next, determine the coordinates of the center of browser's window

    var centerX, centerY; 
    if( self.innerHeight ) { 
    centerX = self.innerWidth; 
    centerY = self.innerHeight; 
    } else if( document.documentElement && document.documentElement.clientHeight ) { 
    centerX = document.documentElement.clientWidth; 
    centerY = document.documentElement.clientHeight; 
    } else if( document.body ) { 
    centerX = document.body.clientWidth; 
    centerY = document.body.clientHeight; 
    }

    // Xwidth is the width of the div, Yheight is the height of the 
    // div passed as arguments to the function: 
    var leftOffset = scrolledX + (centerX - Xwidth) / 2; 
    var topOffset = scrolledY + (centerY - Yheight) / 2; 
    // The initial width and height of the div can be set in the 
    // style sheet with display:none; divid is passed as an argument to // the function 
    var o=document.getElementById(divid); 
    var r=o.style; 
    r.position='absolute'; 
    r.top = topOffset + 'px'; 
    r.left = leftOffset + 'px'; 
    r.display = "block"; 
}

function GetSynchronousJSONResponse(url, postData) {
    var xmlhttp = null;
    if (window.XMLHttpRequest)
        xmlhttp = new XMLHttpRequest();
    else if (window.ActiveXObject) {
        if (new ActiveXObject("Microsoft.XMLHTTP"))
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        else
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    url = url + "?rnd=" + Math.random(); 
    xmlhttp.open("POST", url, false);
    xmlhttp.setRequestHeader("Content-Type", "application/json; charset=utf-8");
    xmlhttp.send(postData);
    var responseText = xmlhttp.responseText;
    return responseText;
}

