/*
	JavaScript Library
	------------------	
	Copyright    : Smart-Info Limited, All Right Reserved.
	Class        : F
	Description  : Common Functions
	
	Create Date  : 2 February 2009
	Last Modify  : 4 May 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
	
	- getAbsoluteOffsetTop			: 26 FEB 2009 by Jacky
	- getAbsoluteOffsetLeft			: 26 FEB 2009 by Jacky
	- getBodyScrollTop				: 26 FEB 2009 by Jacky
	- getBodyScrollLeft				: 26 FEB 2009 by Jacky
	
	- changeClass					: 4 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 in attributes [ attr ] ) 
					{ 
						if ( style.toUpperCase() == "BACKGROUNDIMAGE" )
						{
							element.style.backgroundImage = "url(" + attributes [ attr ] [ style ] + ")";
						} else {
							element.style [ style ] = attributes [ attr ] [ style ]; 
						}
					}
				} 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 ABSOLUTE OFFSET LEFT ~ 26 FEB 2009 by JACKY |___*/
		getAbsoluteOffsetLeft : function ( obj )
		{
			var LEFT = obj.offsetLeft;
			var PARENT = obj.offsetParent;
			while (PARENT != null) {
				LEFT += PARENT.offsetLeft;
				PARENT = PARENT.offsetParent;
			}
			return LEFT;
		},
		
	/*___| GET ABSOLUTE OFFSET TOP ~ 26 FEB 2009 by JACKY |___*/
		getAbsoluteOffsetTop : function ( obj )
		{
			var TOP = obj.offsetTop;
			var PARENT = obj.offsetParent;
			while (PARENT != null) {
				TOP += PARENT.offsetTop;
				PARENT = PARENT.offsetParent;
			}
			return TOP;
		},
		
	/*___| GET BODY SCROLL TOP ~ 26 FEB 2009 by JACKY |___*/
		getBodyScrollTop : function ( )
		{
			if ( window ) return window.pageYOffset;
			if ( document.documentElement ) return document.documentElement.scrollTop;
			if ( document.body ) return document.body.scrollTop;
		},
		
	/*___| GET BODY SCROLL LEFT ~ 26 FEB 2009 by JACKY |___*/
		getBodyScrollLeft : function ( )
		{
			if ( window ) return window.pageXOffset;
			if ( document.documentElement ) return document.documentElement.scrollLeft;
			if ( document.body ) return document.body.scrollLeft;
		},
		
	/*___| CHANGE CLASS NAME ~ 4 MAY 2009 by JACKY |___*/
		changeClass : function ( obj, name )
		{
			obj.className = name;
		},
		
	/*___| CHECK BROWSER |___*/
		checkBrowser : function ( )
		{
			if(window.XMLHttpRequest){ //Mozilla, Safari, IE7  
				if(!window.ActiveXObject){ // Mozilla, Safari,    
					return "mozilla";
				}else{    
					return "ie7";
				}
			}else {    
				return "ie6";
			}  
		}


		
};