var win=0;

function popUp (url,w,h) {
    if(win) { 
	if(!win.closed) {win.close();} 
    }
    w+=20; h+=20;
    win = window.open(url,'winname','menubar=no,directories=no,location=no,resizable=yes,scrollbars=no, toolbar=no, width='+w +',height='+h);
    return false;
}

function confirmDelete(s) {
    return window.confirm(s);
}

function GoUrl(s)
{       var d = s.options[s.selectedIndex].value;
        window.top.location.href = d;
        s.selectedIndex=0;
}

function wndOpen(URL,imgWidth,imgHeight)
{

    window.open(URL,'w1','width='+imgWidth+',height='+imgHeight+',toolbar=no,menubar=no,location=no,status=no,resizable=no,scrollbars=no,top=50,left=50');
    return false;
}

function wndOpen2(URL,imgWidth,imgHeight)
{
    window.open(URL,'w1','width='+imgWidth+',height='+imgHeight+',toolbar=no,menubar=no,location=no,status=no,resizable=no,scrollbars=no,top=50,left=50');
}


function sprintf() {
	    if (!arguments || arguments.length < 1 || !RegExp)
	    {
		return;
	    }
	    var str = arguments[0];
	    var re = /([^%]*)%('.|0|\x20)?(-)?(\d+)?(\.\d+)?(%|b|c|d|u|f|o|s|x|X)(.*)/;
	    var a = b = [], numSubstitutions = 0, numMatches = 0;
	    while (a = re.exec(str))
	    {
		var leftpart = a[1], pPad = a[2], pJustify = a[3], pMinLength = a[4];
		var pPrecision = a[5], pType = a[6], rightPart = a[7];
		//alert(a + '\n' + [a[0], leftpart, pPad, pJustify, pMinLength, pPrecision);
		numMatches++;
		if (pType == '%')
		{
		    subst = '%';
		}
		else
		{
		    numSubstitutions++;
		    if (numSubstitutions >= arguments.length)
		    {
			alert('Error! Not enough function arguments (' + (arguments.length - 1) + ', excluding the string)\nfor the number of substitution parameters in string (' + numSubstitutions + ' so far).');
		    }
		    var param = arguments[numSubstitutions];
		    var pad = '';
		           if (pPad && pPad.substr(0,1) == "'") pad = leftpart.substr(1,1);
		      else if (pPad) pad = pPad;
		    var justifyRight = true;
		           if (pJustify && pJustify === "-") justifyRight = false;
		    var minLength = -1;
		           if (pMinLength) minLength = parseInt(pMinLength);
		    var precision = -1;
		           if (pPrecision && pType == 'f') precision = parseInt(pPrecision.substring(1));
		    var subst = param;
		           if (pType == 'b') subst = parseInt(param).toString(2);
		      else if (pType == 'c') subst = String.fromCharCode(parseInt(param));
		      else if (pType == 'd') subst = parseInt(param) ? parseInt(param) : 0;
		      else if (pType == 'u') subst = Math.abs(param);
		      else if (pType == 'f') subst = (precision > -1) ? Math.round(parseFloat(param) * Math.pow(10, precision)) / Math.pow(10, precision): parseFloat(param);
		      else if (pType == 'o') subst = parseInt(param).toString(8);
		      else if (pType == 's') subst = param;
		      else if (pType == 'x') subst = ('' + parseInt(param).toString(16)).toLowerCase();
		      else if (pType == 'X') subst = ('' + parseInt(param).toString(16)).toUpperCase();
		}
		str = leftpart + subst + rightPart;
	    }
	    return str;
}



// Removes leading whitespaces
function LTrim( value ) {
    
    var re = /\s*((\S+\s*)*)/;
    return value.replace(re, "$1");
    
}

// Removes ending whitespaces
function RTrim( value ) {
    
    var re = /((\s*\S+)*)\s*/;
    return value.replace(re, "$1");
    
}

// Removes leading and ending whitespaces
function trim( value ) {
    
    return LTrim(RTrim(value));
    
}

function ShowHide(id1, id2, id3)
{
   var res = expMenu(id1);
   if (id2 != '') expMenu(id2);
//   if (id3 != '') SetCookie(id3, res, exp);
}

function expMenu(id)
{
   var itm = null;
   if (document.getElementById)
   {
       itm = document.getElementById(id);
   }
   else if (document.all)
   {
       itm = document.all[id];
   }
   else if (document.layers)
   {
       itm = document.layers[id];
   }
   if (!itm)
   {
       // do nothing
   }
   else if (itm.style)
   {
       if (itm.style.display == "none")
       {
           itm.style.display = "";
           return 1;
       }
       else
       {
           itm.style.display = "none";
           return 2;
       }
   }
   else
   {
       itm.visibility = "show";
       return 1;
   }
}

