function pop_up(win_name, top, left, width, height, status, location)
{
	pop_up_rtn(win_name, top, left, width, height, status, location);
}


function pop_up_rtn(win_name, top, left, width, height, status, location)
{
	var winStats = "";
	var winSize = "";
	var final_top = 0;
	var final_left = 0;
	
	if (status.indexOf('f') >= 0)
		winStats = winStats + 'fullscreen=yes';
	else
		winStats = winStats + 'fullscreen=no';

	if (status.indexOf('t') >= 0)
		winStats = winStats + ',toolbar=yes';
	else
		winStats = winStats + ',toolbar=no';
		
	if (status.indexOf('l') >= 0)
		winStats = winStats + ',location=yes';
	else
		winStats = winStats + ',location=no';

	if (status.indexOf('d') >= 0)
		winStats = winStats + ',directories=yes';
	else
		winStats = winStats + ',directories=no';

	if (status.indexOf('m') >= 0)
		winStats = winStats + ',menubar=yes';
	else
		winStats = winStats + ',menubar=no';

	if (status.indexOf('s') >= 0)
		winStats = winStats + ',scrollbars=yes';
	else
		winStats = winStats + ',scrollbars=no';

	if (status.indexOf('r') >= 0)
		winStats = winStats + ',resizable=yes';
	else
		winStats = winStats + ',resizable=no';

    //winStats='toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=yes';
    //if (navigator.appName.indexOf("Microsoft")>=0)
    //  winSize = ',left=' + String(window.screenLeft + Number(left)) + ',top=' + String(window.screenTop + Number(top)) + ',width=' + String(width) + ',height=' + String(height);

        //to get the final left coordinate in showing the window, ensure that the whole pop up is viewable
        if (window.screenLeft < 0)
			final_left = Number(left);
		else
		{
			if (window.screenLeft + Number(left) + Number(width) > screen.availwidth)
				final_left = screen.availwidth - Number(width) - 50;
			else
				final_left = window.screenLeft + Number(left);
				
		}

        //to get the final top coordinate in showing the window, ensure that the whole pop up is viewable
        if (window.screenTop < 0)
			final_top = Number(top);
		else
		{
			if ((window.screenTop + Number(top) + Number(height)) > screen.availheight)
				final_top = screen.availheight - Number(height) - 50;
			else
				//final_top = window.screenTop + Number(top);
				final_top = window.screenTop + Number(top) - 100;
			
		}

        winSize = ',left=' + String(final_left) + ',top=' + String(final_top) + ',width=' + String(width) + ',height=' + String(height);

        winStats += winSize;
    //else
    //    winStats+=',screenX=20,screenY=20,width=300,height=450';
	
	pop=window.open(location, win_name, winStats)
    
    pop.focus();
    
    return pop;
}

function rtrim(in_value)
{
	//input a string
	//output a string that space have been removed from the right hand side of input string
	
	var i, temp_value;
	
	temp_value = new String(in_value)
	for (i=temp_value.length-1; i >= 0; i--)
	{
		if ((temp_value.charAt(i) != ' ') && (temp_value.charAt(i) != '\t'))
			break;
	}

	if (i >= 0)
		return temp_value.substring(0, i+1);
	else
		return '';
}

function ltrim(in_value)
{
	//input a string
	//output a string that space have been removed from the left hand side of input string

	var i, temp_value;
	
	temp_value = new String(in_value)
	for (i=0; i<temp_value.length; i++)
	{
		if ((temp_value.charAt(i) != ' ') && (temp_value.charAt(i) != '\t'))
			break;
	}
	if (i != temp_value.length)
		return temp_value.substring(i, temp_value.length);
	else
		return '';
}

function trim(in_value)
{
	//input a string
	//output a string that space have been removed from right hand side and left hand side of input string

	var temp_value = new String(in_value);
	return rtrim(ltrim(temp_value));
}

function format_date(in_value, out_format)
{
	var index, temp_day, temp_mth, temp_year;
	
	//input a date format value
	//output a date string in format that provided (e.g. 'dd/mm/yyyy')
	
	index = out_format.indexOf("dd");
	if (index >= 0)
	{
		if (in_value.getDate() < 10)
			temp_day = '0' + String(in_value.getDate());
		else
			temp_day = String(in_value.getDate());
	}
		
	index = out_format.indexOf("mm");
	if (index >= 0)
	{
		if (in_value.getMonth() < 9)
			temp_mth = '0' + String(in_value.getMonth() + 1);
		else
			temp_mth = String(in_value.getMonth() + 1);
	}
		
	index = out_format.indexOf("yyyy");
	if (index >= 0)
	{
		temp_year = String(in_value.getYear());
	}
	
	out_format = out_format.replace(/dd/g, temp_day);
	out_format = out_format.replace(/mm/g, temp_mth);
	out_format = out_format.replace(/yyyy/g, temp_year);
	
	return out_format;
}

function format_number(in_number, in_decimal_place)
{
    // in_number: the number being format
    // in_decimal_place: number of decial place
    
    var head, tail
    
    in_number = String(in_number)
    var idx = in_number.indexOf(".");

    if (idx > -1)
    {
        head = String(in_number.substring(0, idx));
        if (idx==0)
            head="0";
        tail = String(in_number.substring(idx+1, in_number.length))
        tail += "00000"
        tail = "."+tail.substring(0, in_decimal_place);
    } else {
        head = in_number;
        tail = String(".00");
    }

    var neval = String()
    var i = 0
    for (var ct = (head.length-1) ; ct >= 0 ; ct --)
    {
        if (((i%3) == 0) && (i != 0))
            neval += String(",")
        neval += String(head.substring(ct,ct+1))
        i++
    }

    head = new String("")
    for (var ca = (neval.length-1) ; ca >= 0 ; ca --)
        head += neval.substring(ca,ca+1)
    
    return (head+tail)
}
