function removeSpace(field)
{
	field.value = (field.value).replace(/^\s*|\s*$/g,'');
}

function isValidEmail(str) 
{
   return (str.indexOf(".") > 1) && (str.indexOf("@") > 0);
}

function trim(val)
{
	re=/\s+$|^\s+/g;
	with (val)
	{
		val=val.replace(re,"");
	}
	return val;
}

function ltrim(val)
{
	re=/^\s+/g;
	with (val)
	{
		val=val.replace(re,"");
	}
	return val;
}

function rtrim(val)
{
	re=/\s+$/g;
	with (val)
	{
		val=val.replace(re,"");
	}
	return val;
}

function Show_Img(img, w, h) 
{
	if(w<400){w=400;}

	if(img=="")
	{
		return; // set the options as you like
	}
	winleft = (screen.width - w - 22)/2; 
	wintop = (screen.height - h)/2 - 50; 
	if(typeof(SmallWin)!="undefined")
	{
		SmallWin.close();
	}
	SmallWin = window.open('./viewimg.php?img='+img, 'ImgWindow','scrollbars,resizable=no,height=' +(h+24)+ ',width=' +(w+24)+',top=' +wintop+ ',left=' +winleft+ ', margin=0');
	SmallWin.focus() 
	SmallWin.width=w;
	SmallWin.height=h;
}

function SWFDelegate(url,caption,gallery) {
   var objLink = document.createElement('a');
   objLink.setAttribute('href',url);
   
   if(gallery==1)
   {
   	objLink.setAttribute('rel','lightbox[gallery]');
   } else 
   {
   	objLink.setAttribute('rel','lightbox[images]');
   }
   
   objLink.setAttribute('title',unescape(unescape(caption)));
   Lightbox.prototype.start(objLink);
}

function setcenterframe()
{
	var arrayPageSize = viewPageSize();
	//Element.setWidth('bg_hideTP', arrayPageSize[0]);
	//Element.setHeight('bg_hideTP', arrayPageSize[1]);
	
	if(arrayPageSize[1]>del_height+min_height)
	{
		var newheight=arrayPageSize[1]-del_height;
		document.getElementById('centerframe').height=newheight;
	} else
	{
		document.getElementById('centerframe').height=min_height;
	}
}

function get_radio_value(radiusname)
{
	var rad_val=0;
	var rname=eval(radiusname);

	for (var i=0; i < rname.length; i++)
	{
		if (rname[i].checked)
		{
			rad_val = rname[i].value;
		}
	}
	return rad_val;
}

function viewPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

