﻿

// Object Start
var obj = new Object();
obj.length = function(obj) {
    var count = 0;
    for (i in obj) { count += 1; }
    return count;
}
obj.add = function(parent, childP, childV) {    // parent:obj,child:string,childV:obj
    eval('parent' + '.' + childP + " = " + 'childV');
    return parent;
}
// Object End

// prototype start
var z = new Object();
z.inArray = function(sample, needle) {
    switch (typeof (needle)) {
        case 'string':
            for (var i in sample) if (sample[i] == needle) return i;
            else return false;
            break;
        case 'array': // not complete
            break;
    }
    return false;
}
z.arrEleInArr = function  ( a , b ) {
	for ( var i in a )
		for ( var l in b )
			if ( a[i] == '' || b[l] == '' )
				continue;
			else if ( a[i].toLowerCase() == b[l].toLowerCase() )
				return true;
	return false;
}

// prototype end

// Input Start
var In = new Object();
In.legend = function ( legend , html , addon )
{
	addon = addon || '';
	return "<fieldset "+addon+" ><legend>"+legend+"</legend>"+html+"</fieldset>";
}
In.text = function ( name , value , addon )
{
	return "<input type='text' name='"+name+"' value='"+value+"'  "+addon+" />";
}
In.textarea = function ( name , value , addon )
{
	addon = addon || '';
	return "<textarea name='"+name+"' "+addon+" >" + value + "</textarea>";
}
In.radio = function(name, value, check) {
    check = check || 'default';
    var str = '';
    for (var i in value) {
        if (i == check) str += "<input type='radio' name='" + name + "' value='" + i + "' checked />" + value[i] + " ";
        else str += "<input type='radio' name='" + name + "' value='" + i + "' />" + value[i] + " ";
    }
    return str;
}
In.ckbox = function(name, value, check) {
    check = check || [];
    var str = '';
    for (var i in value)
        if (check[i] == true || check[i].toLowerCase() == "true") str += "<input type='checkbox' name='" + name + "' value='" + i + "' checked />" + value[i] + " ";
    else str += "<input type='checkbox' name='" + name + "' value='" + i + "' />" + value[i] + " ";
    return str;
}
In.options = function ( arr ){
	//html = arr[0];
	//value = arr[1];
	//selected = arr[2];
	//addon = arr[3];
	//addon = addon||'';selected = selected || 0;value=value||html;
	var result='';
	for (var i in arr)
		if (arr[i][2] =='selected')
			result += '<option value="' + arr[i][1] + '" selected ' + arr[i][3] + ' >' + arr[i][0] + '</option>';
		else
			result += '<option value="' + arr[i][1] + '" ' + arr[i][3] + ' >' + arr[i][0] + '</option>';
    return result;
}
In.file = function ( name , cls , addon )
{
	name = name || 'file'; cls = cls || ''; addon = addon || '';
	return '<input type="file" name="'+name+'" class="'+cls+'" '+addon+' />';
}
In.hidden = function ( name , val )
{
	return '<input type="hidden" name="'+name+'" id="'+name+'" value="'+val+'" />';
}

// Input End

// DIV MSG Lightbox start
var msg = new Object();
msg.HTML = function(htmlmsg) {
    htmlmsg = htmlmsg || '';
    var btncloseStyle = "style='background:white url(img/sys/close.gif);border:0;cursor:pointer;position:absolute;right:1px;top:1px;width:45px;height:20px' onclick = 'msg.close()'";
    var msgStyle = "style='display: none;position: absolute;top: 25%;left: 35%;width: 30%;height: auto;padding: 16px;border: 16px solid orange;background-color: white;z-index:1002;overflow: auto;'";
    var fadeStyle = "style='display: none;position: fixed;top: 0;left: 0;width: 100%;height: 100%;background-color:black;z-index:1001;-moz-opacity: 0.8;opacity:.80;filter: alpha(opacity=80);'";
    return div('msg', '', htmlmsg + div('btn-close', '', '', btncloseStyle), msgStyle) + div('fade', '', '', fadeStyle);
}
msg.comfirm = function ( htmlmsg  ) {	//comfirm button
	if ($('#msg').length == 0) { $('html').prepend(this.HTML(htmlmsg)); }
		$('#msg,#fade').css('display','block');
}
msg.show = function(htmlmsg) {
	if ($('#msg').length == 0) { $('html').prepend(this.HTML(htmlmsg)); }
		$('#msg,#fade').css('display','block');
}
msg.close = function() { $('#msg,#fade').css('display', 'none'); }
// DIV MSG Lightbox end


// DIV Loading Lightbox start
msg.loadImg = "<img src='img/sys/load.gif' alt='loading...' />";
msg.loadStart = function(htmlmsg) {
    htmlmsg = htmlmsg || 'Loading';
    this.show(htmlmsg + this.loadImg);
}
// DIV Loading Lightbox end


function div(id, cls, html, addon) {
    id = id || ''; cls = cls || ''; addon = addon || ''; html = html || '';
    html = '<div id="' + id + '" class="' + cls + '" ' + addon + ' >' + html + '</div>';
    return html;
}
function table(id, cls, html, addon) {
    id = id || ''; cls = cls || ''; addon = addon || ''; html = html || '';
    html = '<table id="' + id + '" class="' + cls + '" ' + addon + ' >' + html + '</table>';
    return html;
}
function tr( html , cls , id, addon) {
    id = id || ''; cls = cls || ''; addon = addon || ''; html = html || '';
    html = '<tr id="' + id + '" class="' + cls + '" ' + addon + ' >' + html + '</tr>';
    return html;
}
function td( html , cls , id , addon) {
    id = id || ''; cls = cls || ''; addon = addon || ''; html = html || '';
    html = '<td id="' + id + '" class="' + cls + '" ' + addon + ' >' + html + '</td>';
    return html;
}
function a( href , html , cls , id , addon ){
    id = id || ''; cls = cls || ''; addon = addon || ''; html = html || ''; href = href || 'javascript:void(0)';
    html = '<a href="'+ href +'" id="' + id + '" class="' + cls + '" ' + addon + ' >' + html + '</a>';
    return html;
}

