//Trim a string from both ends
function strTrim(tmpStr)
{
	tmpStr = tmpStr.replace(/^\s+/,"");//remove leading
	tmpStr = tmpStr.replace(/\s+$/,"");//remove trailing
	return tmpStr;
}
//Trims all fields in a form
function trimFields()
{
	for(var i=0; i < obj.elements.length; i++)
	{
		if(obj.elements[i].type == "text" || obj.elements[i].type == "textarea" || obj.elements[i].type == "password")
		{
			obj.elements[i].value = strTrim(obj.elements[i].value);
		}
	}
}
//Email pattern check
function chkEmail(tmpStr)
{
	var email_pat = /^[a-z0-9][a-z0-9_\.\-']*[a-z0-9]@[a-z0-9]+[a-z0-9\.\-_]*\.[a-z]+$/i;
	return(email_pat.test(tmpStr))
}

//------------------------------------------------------------------------------------
function NewWindow(pageName, Width, Height)
{
	window.open(pageName, '', 'width='+Width+',height='+Height+',toolbar=0,menubar=0,location=0,left=50,top=100');
}

//Display picture in new window
 function openPictureWindow(imagePath,alt)
{
	var optIE='scrollbars=no,width=100,height=100,left='+50+',top='+50;
	newWindow = window.open("","newWindow",optIE);
	//var width,height;
	var doc = newWindow.document;
	doc.open();
	doc.write('<html>\n');
	doc.write('<head>\n');
	doc.write('<title>'+alt+'</title>\n');
	doc.write('<meta http-equiv="imagetoolbar" content="no">\n');
	doc.write('<script language="javascript">\n');
	doc.write('function resizeImage()');
	doc.write('{');
	doc.write('    window.resizeTo(document.images[0].width,document.images[0].height)');
	doc.write('}');
	doc.write('</script>\n');
	doc.write('</head>\n');
	doc.write('<body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" ondblclick="self.close();" onblur="self.close();" onload="resizeImage();">\n');
	doc.write('<img src=\"'+imagePath+'\"alt='+alt+'\n\"Double-click to Close this window\" border="0">\n');
	doc.write('</body>\n');
	doc.write('</html>\n');
	doc.close();
	newWindow.focus();
}

//Refreshes captcha image
function refreshCaptcha(imgid)
{
	var newimg = new Image();
	newimg.src = 'includes/captcha/captcha.php?hash='+parseInt(Math.random() * 10000000000);
	newimg.onload = function(){document.getElementById(imgid).src = newimg.src;}
}
