String.prototype.trim = function() { return this.replace(/^\s*/, "").replace(/\s*$/, "");};
function GBI(id)
{		   
	return document.getElementById(id);
}
function bookmark(url, description)
{
	netscape="Netscape User's hit CTRL+D on your keyboard to add a bookmark to this site."
	if (navigator.appName=='Microsoft Internet Explorer')
	{
		window.external.AddFavorite(url, description);
	}
	else if (navigator.appName=='Netscape')
	{
		alert(netscape);
	}
}
function GoTo(url)
{
	top.location.href=url;
}

function CheckImgEx(id) 
{
	var filename = new String();
		
	//Get file name
	if(GBI(id))
	{
		filename = String(GBI(id).value);
	}
	
	if (!filename)
	{
		alert('Please select an image file from your computer by clicking the "Browse" button. \n Then click the "Upload Picture button"');
		return false;
	}
	
	filename = filename.substring(filename.lastIndexOf('.',0), filename.length - filename.lastIndexOf('.',0));
	filename = filename.toLocaleLowerCase();
	if(filename != '.gif' && filename != '.jpg' && filename != '.jpeg' && filename != '.png')
	{
		alert("Please only upload image files width EXTENSION of .gif, jpg, jpeg, bmp and png" );
		return false;
	}
	
	return true;
	
} 
function Confirm(contentCtrl)
{
	var popup = GBI(contentCtrl);
	popup.style.display = 'block';
	popup.style.position = 'absolute';
	popup.style.top = (document.body.clientHeight/2)  - (popup.offsetHeight/2)+ 'px';
	popup.style.left = (document.body.clientWidth/2)  - (popup.offsetWidth/2)+ 'px';
}
function CloseConfirm(contentCtrl)
{
	GBI(contentCtrl).style.display ='none';
}
function showhide(id)
{
	var ctrl = GBI(id);
	if(ctrl && ctrl.className == 'shown')
	{
		ctrl.className = 'hidden';
	}
	else
	{
		ctrl.className = 'shown';
	}
}
function SelectText(ctrl)
{
	if(!ctrl)return;
	ctrl.select();
	return true;
	
}
function ShowCommentInput(ctrl)
{
	if(!CheckLogin())
	{
		alert('You need to login to make comments');
		return false;
	}
	
	if(ctrl)
	{
		var nextCtrl = ctrl.parentNode.nextSibling;
		while (nextCtrl.nodeType == 3) 
		{ 
			// Fix for Mozilla/FireFox Empty Space becomes a TextNode 
			nextCtrl = nextCtrl.nextSibling;
		}
				
		if(nextCtrl.style.display == 'block')
		{
			nextCtrl.style.display = 'none';
		}
		else
		{
			nextCtrl.style.display = 'block';
		}
	}
	return true;
}
function HideCommentInput(ctrl)
{
	if(ctrl)
	{
		ctrl = ctrl.parentNode;
				
		if(ctrl.style.display == 'block')
		{
			ctrl.style.display = 'none';
		}
		else
		{
			ctrl.style.display = 'block';
		}
	}
	return true;
}
function EditPhotoInfo_Handler(action)
{	
	if(action){CloseConfirm('div_EditPhotoInfo');return true;}
	else {CloseConfirm('div_EditPhotoInfo');return false;}
}
function MovePhoto_Handler(action)
{	
	if(action){CloseConfirm('div_Move');return true;}
	else {CloseConfirm('div_Move');return false;}
}
function PopShare(type, url, title)
{
    if(type == 'fb')
    {
        window.open('http://www.facebook.com/sharer.php?u=http://www.freepiceditor.com' + url + '&t=' + title,'fpeShare','location=0,status=0,menubar=0,toolbar=0,height=500,width=600',1);
    }
    else if(type == 'tw')
    {
        window.open('http://twitter.com/home?status=Currently looking at http://www.freepiceditor.com/' + url + '&source=http://www.freepiceditor.com&t=' + title,'fpeShare','location=0,status=0,menubar=0,toolbar=0,height=500,width=600',1);
    }
}
function select(t) 
{
    if(t)
    {
        t.focus();
        t.select();
    }
}



