/*
	JavaScript Library
	------------------	
	Copyright    : Smart-Info Limited, All Right Reserved.
	Class        : F
	Description  : Common Functions
	
	Create Date  : 2 February 2009
	Last Modify  : 3 February 2009
*/

/*
	Functions Summary
	-----------------
	- createElement                 : 3 JAN 2009 by Jacky
	- popup                         : 2 FEB 2009 by Jacky
	- include                       : 3 FEB 2009 by Jacky
	- confirmDelete					: 4 FEB 2009 by Jacky
	- getURL						: 27 MAY 2009 by Jacky
*/

var F = 
{
	/*___| CREATE ELEMENT ~ 3 JAN 2009 by JACKY |___*/
		createElement : function ( type, id, attributes, mouseEvent )
		{
			var element = document.createElement ( type );
			for ( var attr in attributes ) 
			{ 
				if ( attr.toUpperCase() == "STYLE" )
				{
					for ( var STYLE_ATTR in attributes [ attr ] ) 
					{
						switch ( STYLE_ATTR )
						{
							case "backgroundImage":
								element.style [ STYLE_ATTR ] = "url("+attributes [ attr ] [ STYLE_ATTR ] + ")";
								break;
							default:
								element.style [ STYLE_ATTR ] = attributes [ attr ] [ STYLE_ATTR ]; 
								break;
						}
					}
				} else {
					element [ attr ] = attributes [ attr ]; 
				}
			}
			if ( id != null ) element.setAttribute ( "id", id );
			if ( mouseEvent != undefined )
			{
				if ( mouseEvent.mousedown != undefined ) { element.onmousedown = mouseEvent.mousedown; }
				if ( mouseEvent.mouseup   != undefined ) { element.onmouseup   = mouseEvent.mouseup;   }
				if ( mouseEvent.mouseover != undefined ) { element.onmouseover = mouseEvent.mouseover; }
				if ( mouseEvent.mouseout  != undefined ) { element.onmouseout  = mouseEvent.mouseout;  }
			}
			return element;
		},

	/*___| POPUP ~ 2 FEB 2009 by JACKY |___*/
		popup : function ( url, attributes )
		{
			var parameters = "";
			for ( var attr in attributes ) { if ( attr != "target" ) { parameters += ( parameters != "" ) ? "," : ""; parameters += attr + "=" + attributes [ attr ]; }	}
			if ( attributes == null ) attributes = {};
			if ( attributes != null ) { if ( attributes.target == undefined ) target = ""; 	}
			window.open(url, target, parameters);
		},
		
	/*___| INCLUDE ~ 3 FEB 2009 by JACKY |___*/
		include : function ( filename )
		{
			var SCRIPT = this.createElement ( "script", null, { type:"text/javascript", src:filename } );
			document.getElementsByTagName ( "head" )[0].appendChild ( SCRIPT );
		},
		
	/*___| CONFIRM DELETE MESSAGE BOX ~ 4 FEB 2009 by JACKY |___*/
		confirmDelete : function ( ) 
		{ 
			if(confirm("Delete this order?"))
			{
				return true; 
			} else { return false; }
		},
		
	/*___| GET URL ~ 27 MAY 2009 by JACKY |___*/
		getURL : function ( url ) 
		{ 
			location.href = url;
		}
		
};
