//------------------------------------------------------------------------------
// Class:  Common
//------------------------------------------------------------------------------
// Author:  CL
// Date:  22/01/08
// Description:  This class is for the Common js
//------------------------------------------------------------------------------
function Common()
{
	// Variables:
	var maxMsgLength = 1000;
	this.x = 0;
	this.y = 0;
	
	// Methods:
	this.updateCharCount = updateCharCount;
	this.viewAlbum = viewAlbum;
	this.viewGallery = viewGallery;
	this.removeTabLineBreak = removeTabLineBreak;
	this.selectAllCheckBoxes = selectAllCheckBoxes;
	this.resizePage = resizePage;
	this.getMouseCoordinate = getMouseCoordinate;
	this.inputBoxSelectAll = inputBoxSelectAll;
	this.escapeHTML = escapeHTML;
	this.escapeQuotes = escapeQuotes;
	this.popupWindow = popupWindow;

	//--------------------------------------------------------------------------
		
	function updateCharCount(textarea, alertField, newMaxLength)
	{
		if(newMaxLength)
		{
			maxMsgLength = newMaxLength;
		}
		if (textarea.value.length > maxMsgLength)
		{
			textarea.value = textarea.value.substr(0, maxMsgLength);
			alertField.value = maxMsgLength - textarea.value.length;
		}
		else
		{
			alertField.value = maxMsgLength - textarea.value.length;
		}
	}
	
	//--------------------------------------------------------------------------
		
	function viewAlbum(URL,sTitle)
	{
		//var sStyle = "width=750px,height=500px,resize=1,scrolling=1,center=1";
		//var popup = dhtmlwindow.open("galleryadmin", "iframe", URL, sTitle, sStyle, "recal");
		URL = URL + "&isAdmin=1";
		var sStyle = "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1";
		var popup = window.open(URL,'viewAlbum',sStyle);
	}
	
	//--------------------------------------------------------------------------
		
	function viewGallery(URL,sTitle)
	{
		var sStyle = "status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=1,scrollbars=1";
		var popup = window.open(URL,'viewGallery',sStyle);
	}
	
	//--------------------------------------------------------------------------
		
	function removeTabLineBreak(sString)
	{
		var linebreak = new RegExp("\\n","g");
		var tab = new RegExp("\\t","g");
		var returnString = sString.replace(tab,"");
		returnString = returnString.replace(linebreak,"");
		return returnString;
	}
	
	//--------------------------------------------------------------------------
	
	function selectAllCheckBoxes(formName, fieldName, checkValue)
	{
		if(!document.forms[formName])
			return;
		
		var objCheckBoxes = document.forms[formName].elements[fieldName];
		if(!objCheckBoxes)
			return;
		
		var countCheckBoxes = objCheckBoxes.length;
		if(!countCheckBoxes)
			objCheckBoxes.checked = checkValue;
		else
		{
			for(var i=0; i < countCheckBoxes; i++)
				objCheckBoxes[i].checked = checkValue;
		}
	}
	
	//--------------------------------------------------------------------------
	
	function resizePage()
	{
		document.getElementById('header').style.width = document.body.clientWidth;
		document.getElementById('wrapper').style.width = document.body.clientWidth;
		document.getElementById('footer').style.width = document.body.clientWidth;
	}
	
	//--------------------------------------------------------------------------
	
	function getMouseCoordinate(e)
	{
		if (!e) e = window.event;
		
		if (e.pageX || e.pageY)
		{
			this.x = e.pageX;
			this.y = e.pageY;
		}
		else if (e.clientX || e.clientY)
		{
			this.x = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			this.y = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
		}
	}
	
	//--------------------------------------------------------------------------
	
	function inputBoxSelectAll(id)
	{
		document.getElementById(id).focus();
		document.getElementById(id).select();
	}	
	
	//--------------------------------------------------------------------------
	
	function escapeHTML(str)
	{
		var div = document.createElement('div');
		var text = document.createTextNode(str);
		div.appendChild(text);
		return div.innerHTML;
	}
	
	//--------------------------------------------------------------------------
	
	function escapeQuotes(str)
	{
		str = str.replace(/\'/g,'\\\'');
		str = str.replace(/\"/g,'\\"');
		return str;
	}
	
	//--------------------------------------------------------------------------
	
	function popupWindow(URL,sTitle,iWidth,iHeight,wName,wType)
	{
		var sStyle = "width=" + iWidth + ",height="+ iHeight + ",top=50px,left=150px,resize=0,scrolling=0,center=0";
		window.popUp = dhtmlwindow.open(wName, wType, URL, sTitle, sStyle, "recal");
		window.popUp.onclose=function(){
			window.frames["_iframe-galleryadmin"].location.replace('about:blank');
			return true;
		}
	}
}
// 
oCommon = new Common();
// JavaScript Document
