
/*********************************************************************
*
*	"Shortcut" functions
*
*********************************************************************/

var fn_sa = "setAttribute", fn_ac = "appendChild", fn_rc = "removeChild", fn_s = "style", fn_ce = "createElement";

/*************************************
*	Create Element
*************************************/
function cE(elementName) {
	return document[fn_ce](elementName);
}

/*************************************
*	Set attibute
*************************************/
function sA(obj, attributName, attributeValue) {
	return obj[fn_sa](attributName, attributeValue);
}

/*************************************
*	Append Child
*************************************/
function aC(element, child) {
	return element[fn_ac](child);
}

/*************************************
*	Remove Child
*************************************/
function rC(element, child) {
	return element[fn_rc](child);
}

/*************************************
*	Create SPAN
*************************************/
function cE_S(the_id, the_innerHTML) {
	var m_span = cE("span");
	if (the_id != "") {
		m_span.id = the_id;
	}
	m_span.innerHTML = the_innerHTML;
	return m_span;
}

/*************************************
*	Create TD with parameters
*************************************/
function cE_TD(the_width, the_height, the_className) {
	var m_td = cE("td");
	if (the_width != "") {
		sA(m_td, "width", the_width);
	}
	
	if (the_height != "") {
		sS(m_td, "height", the_height);
	}
	
	if (the_className != "") {
		m_td.className = the_className;
	}
	return m_td;
}

/*************************************
*	Set object style
*************************************/
//function sS(obj, styleName, styleValue) {
//	return obj[fn_s][styleName] = styleValue;
//}

function sS(obj, styleName, styleValue) {
	//alert("[styleName = " + styleName + "] : [styleValue = " + styleValue + "]");
	if (obj != null) {
		if (is_array(styleName)&&is_array(styleValue)) {
			if (styleName.length != styleValue.length) {
				alert("Error!!!!");
			}
			else {
				for (var i = 0; i < styleName.length; i++) {
					obj[fn_s][styleName[i]] = styleValue[i];
				}
				return obj;
			}
		}
		else {
			return obj[fn_s][styleName] = styleValue;
		}
	}
}

/*************************************
*	Create Element Input Button
*************************************/
function cE_B(the_id, the_className, the_width, the_height, the_value) {
	var m_bttn = cE("input");
	sA(m_bttn, "type", "button");
	sA(m_bttn, "id", the_id);
	m_bttn.className = the_className;
	
	if (the_width != "") {
		sS(m_bttn, "width", the_width);
	}
	
	if (the_height != "") {
		sS(m_bttn, "height", the_height);
	}
	
	if (the_value != "") {
		sA(m_bttn, "value", the_value);
	}
	
	sS(m_bttn, "margin", "2px");
	return m_bttn;
}

/*************************************
*	Create Element Input Submit
*************************************/
function cE_SB(the_id, the_className, the_width, the_height, the_value) {
	var m_bttn = cE("input");
	sA(m_bttn, "type", "submit");
	sA(m_bttn, "id", the_id);
	m_bttn.className = the_className;
	
	if (the_width != "") {
		sS(m_bttn, "width", the_width);
	}
	
	if (the_height != "") {
		sS(m_bttn, "height", the_height);
	}
	
	if (the_value != "") {
		sA(m_bttn, "value", the_value);
	}
	
	sS(m_bttn, "margin", "2px");
	return m_bttn;
}

/*************************************
*	Create Element Div
*************************************/
function cE_Div(the_id, the_position, the_top, the_left, the_width, the_height, the_className, the_content) {
	var m_div = cE("div");
	sA(m_div, "id", the_id);
	sS(m_div, "position", the_position);
	if (the_top != "") sS(m_div, "top", the_top);
	if (the_left != "") sS(m_div, "left", the_left);
	if (the_width != "") sS(m_div, "width", the_width);
	if (the_height != "") sS(m_div, "height", the_height);
	if (the_className != "") m_div.className = the_className;
	if (the_content != "") m_div.innerHTML = the_content;
	return m_div;
}

/*************************************
*	Create Element Input Text
*************************************/
function cE_IT(the_id, the_name, the_value, the_className) {
	var m_IT = cE("input");
	sA(m_IT, "type", "text");
	sA(m_IT, "id", the_id);
	sA(m_IT, "name", the_name);
	sA(m_IT, "value", the_value);
	m_IT.className = the_className;
	return m_IT;
}

/*************************************
*	Create Element Input Password
*************************************/
function cE_IP(the_id, the_name, the_value, the_className) {
	var m_IT = cE("input");
	sA(m_IT, "type", "password");
	sA(m_IT, "id", the_id);
	sA(m_IT, "name", the_name);
	sA(m_IT, "value", the_value);
	m_IT.className = the_className;
	return m_IT;
}

/*************************************
*	Create Element Table
*************************************/
function cE_T(the_width, the_height, the_cellpadding, the_cellspacing, the_styles) {
	var mTable = cE("table");
	if (the_width != "") {
		sS(mTable, "width", the_width);
	}
	
	if (the_height != "") {
		sS(mTable, "height", the_height);
	}
	
	if (the_cellpadding != "") {
		mTable.cellPadding = the_cellpadding;
	}
	
	if (the_cellspacing != "") {
		mTable.cellSpacing = the_cellspacing;
	}
	
	if (the_styles != "") {
		sS(mTable, the_styles[0], the_styles[1]);
	}
	
	return mTable;
}

/*************************************
*	Create Element Input hidden
*************************************/
function cE_IH(the_id, the_name, the_value) {
	var oHidden = cE("input");
	sA(oHidden, "type", "hidden");
	sA(oHidden, "id", the_id);
	sA(oHidden, "name", the_name);
	sA(oHidden, "value", the_value);
	return oHidden;
}

/*************************************
*	Create Element Input Checkbox
*************************************/
function cE_ICHK(the_id, the_name, the_checked) {
	var oCheckbox = cE("input");
	sA(oCheckbox, "type", "checkbox");
	sA(oCheckbox, "id", the_id);
	sA(oCheckbox, "name", the_name);
	if (the_checked != "") {
		sA(oCheckbox, "checked", the_checked);
	}
	return oCheckbox;
}

/*************************************
*	Create Element Image
*************************************/
function cE_I(the_id, the_src, the_style, onClickFunction, params) {
	var m_I = cE("img");
	
	if (the_id != "") {
		sA(m_I, "id", the_id);
	}
	
	if (the_src != "") {
		sA(m_I, "src", the_src);
	}
	
	if (the_style != "") {
		if (the_style.charAt(the_style.length - 1) == ";") {
			the_style = the_style.substring(0, the_style.length - 1);
		}
		var the_styles = the_style.split("; ");
		for (var i = 0; i < the_styles.length; i++) {
			//cursor: pointer; margin-top: 2px; margin-bottom: 2px;
			sS(m_I, the_styles[i].split(": ")[0], the_styles[i].split(": ")[1]);
		}
	}
	if ((onClickFunction != "null")&&(onClickFunction != "")) {
		m_I.onclick = function () {
			if (params == "this") {
				onClickFunction(m_I);
			}
			else {
				onClickFunction(params);
			}
		}
	}
	return m_I;
}

/*************************************
*	Create element Option
*************************************/
function cE_O(the_value, the_label, the_selected) {
	var m_O = cE("option");
	m_O.value = the_value;
	m_O.text = the_label;
	m_O.selected = the_selected;
	return m_O;
}

/*************************************
*	Create element Text node
*************************************/
function cE_Text(the_value) {
	return document.createTextNode(the_value);
}

/*************************************
*	Create Element Link
*************************************/
function cE_A(the_id, the_className, the_href, the_label) {
	var oLink = cE("a");
	oLink.id = the_id;
	oLink.className = the_className;
	oLink.href = the_href;
	oLink.innerHTML = the_label;
	return oLink;
}

/*************************************
*	Create calendar Object
*************************************/
function cCalendar(the_id, the_name, the_default_value, show_time, onchange_function) {
	var m_table, m_tbody, m_row, m_cell, m_img, m_input;
	m_table = cE("table");
	sA(m_table, "cellPadding", 0);
	sA(m_table, "cellSpacing", 0);
	sS(m_table, "margin", "0px auto");
	m_tbody = cE("tbody");
		m_row = cE("tr");
			m_cell = cE("td");
				m_input = cE_IT(the_id, the_name, the_default_value, "form-input");
				sS(m_input, "width", "120px");
				m_input.onchange = function() {
					if (onchange_function != "") {
						onchange_function(m_input);
					}
				}
				aC(m_cell, m_input);
			aC(m_row, m_cell);
			
			m_cell = cE("td");
			sS(m_cell, "verticalAlign", "middle");
				m_img = cE("img");
				sA(m_img, "src", "/ui/img/admin/calendar.png");
				sS(m_img, "cursor", "pointer");
				sS(m_img, "marginLeft", "3px");
				m_img.onclick = function() {
					myHint.hide();
					showCalendar(m_img, posy + 20, posx + 20, show_time);
				}
				aC(m_cell, m_img);
			aC(m_row, m_cell);
		aC(m_tbody, m_row);
	aC(m_table, m_tbody);
	return m_table;
}

/*************************************
*	get specified style value
*************************************/
function gS(obj, styleName) {
	return obj[fn_s][styleName].replace('px', '');
}

/*********************************************************************
*
*	End "Shortcut" functions
*
*********************************************************************/

Array.prototype.in_array = function ( obj ) {
	var len = this.length;
	for ( var x = 0 ; x <= len ; x++ ) {
		if ( this[x] == obj ) return true;
	}
	return false;
}

function is_array(input){
	return typeof(input)=='object'&&(input instanceof Array);
}


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		return [curleft,curtop];
	}
}
