function getRelLeft(el) {
	var pos = el.offsetLeft;
	while (el.offsetParent != null) { el = el.offsetParent; pos += el.offsetLeft; if (el.tagName == 'BODY') break; }
	return pos;
}

function getRelTop(el) {
	var pos = el.offsetTop;
	while (el.offsetParent != null) { el = el.offsetParent; pos += el.offsetTop; if (el.tagName == 'BODY') break; }
	return pos;
}

function getBodyHeight() {
	if (self.innerWidth) return self.innerHeight;
	else if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientHeight;
	else if (document.body) return document.body.clientHeight;
}

function getBodyWidth() {
	if (self.innerWidth) return self.innerWidth;
	else if (document.documentElement && document.documentElement.clientWidth) return document.documentElement.clientWidth;
	else if (document.body) return document.body.clientWidth;
}


function openAWindow( pageToLoad, winName, width, height, center, scroll){

xposition=0; yposition=0;
if ((parseInt(navigator.appVersion) >= 4 )){
 xposition = (screen.width - width) / 8;
 yposition = (screen.height - height) / 3;
}
if ((parseInt(navigator.appVersion) >= 4 ) &&(center)) {
	xposition = (screen.width - width) / 2;
	yposition = (screen.height - height) / 2;
}

args = "width=" + width + ","
+ "height=" + height + ","
+ "location=0,"
+ "menubar=0,"
+ "resizable=1,"
+ "scrollbars="+scroll+","
+ "status=0,"
+ "titlebar=0,"
+ "screenx=" + xposition + "," //NN Only
+ "screeny=" + yposition + "," //NN Only
+ "left=" + xposition + "," //IE Only
+ "top=" + yposition; //IE Only
window.open( pageToLoad, winName, args );

}

function openPic2(img,width, height)
{
 openAWindow (img,"_blank",width,height);
}


function openPic(img)
{
 openPic2(img,402,302);
}

function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}

function url_encode(str)
{
    var ret = '';

    for (i=0; i<str.length; i++)
    {
        var n = str.charCodeAt(i);
        if (n >= 0x410 && n <= 0x44F)
            n -= 0x350;
        else if (n == 0x451)
            n = 0xB8;
        else if (n == 0x401)
            n = 0xA8;
        if ((n < 65 || n > 90) && (n < 97 || n > 122) && n < 256)
        {
            if (n < 16)
                ret += '%0'+n.toString(16);
            else
                ret += '%'+n.toString(16);
        }
        else
            ret += String.fromCharCode(n);
    }

    return ret;
}

function strip_tags( s ){
	var re = /<[^>]*>/ig;
	s = s.replace( re, "" );
	return s;
}

function remove_double_cr( s ){
	var re = /\ {2,}/ig;
	s = s.replace( re, " " );
	var re = /(\s*\r|\n\s*){2,}/ig;
	s = s.replace( re, "\r\n" );
	return s;
}

// check that at least one radio is checked
function radioValue( form, radioName )
{
	result = '';
	for( i=0; i < form.length; i++ ) 
	{
		var element=form.elements[i];
	  	if( element.name == radioName )
	  	{ 
	  		if( element.type.toLowerCase() == "radio" )
	  		{
	  			if( element.checked )
	    			result = element.value;
	  		}
	  		else
    			result = element.value;
	  	}
	}
	return result;
}

function setRadioValue( form, radioName, value ){
	for( i=0; i < form.length; i++ ) 
	{
		var element=form.elements[i];
	  	if( element.name == radioName )
	  	{ 
	  		if( element.type.toLowerCase() == "radio" )
	  		{
	  			if( element.value == value )
	    			element.checked = true;
	    		else
	    			element.checked = false;
	  		}
	  	}
	}
}



