var DApp = {};
/*
 * Global
 */
var YAHOO={lang:{}};
YAHOO.lang.isArray= function(o) {return Object.prototype.toString.apply(o) === '[object Array]';}
YAHOO.lang.isString=function(o) {return typeof o === 'string';}
YAHOO.lang.hasOwnProperty = (Object.prototype.hasOwnProperty) ?function(o, prop) {return o && o.hasOwnProperty(prop);} : function(o, prop) {return !L.isUndefined(o[prop]) && o.constructor.prototype[prop] !== o[prop];};
YAHOO.lang.JSON=(function(){var l=YAHOO.lang,_UNICODE_EXCEPTIONS=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,_ESCAPES=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,_VALUES=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,_BRACKETS=/(?:^|:|,)(?:\s*\[)+/g,_INVALID=/^[\],:{}\s]*$/,_SPECIAL_CHARS=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,_CHARS={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"};function _revive(data,reviver){var walk=function(o,key){var k,v,value=o[key];if(value&&typeof value==="object"){for(k in value){if(l.hasOwnProperty(value,k)){v=walk(value,k);if(v===undefined){delete value[k];}else{value[k]=v;}}}}return reviver.call(o,key,value);};return typeof reviver==="function"?walk({"":data},""):data;}function _char(c){if(!_CHARS[c]){_CHARS[c]="\\u"+("0000"+(+(c.charCodeAt(0))).toString(16)).slice(-4);}return _CHARS[c];}function _prepare(s){return s.replace(_UNICODE_EXCEPTIONS,_char);}function _isValid(str){return l.isString(str)&&_INVALID.test(str.replace(_ESCAPES,"@").replace(_VALUES,"]").replace(_BRACKETS,""));}function _string(s){return'"'+s.replace(_SPECIAL_CHARS,_char)+'"';}function _stringify(h,key,d,w,pstack){var o=typeof w==="function"?w.call(h,key,h[key]):h[key],i,len,j,k,v,isArray,a;if(o instanceof Date){o=l.JSON.dateToString(o);}else{if(o instanceof String||o instanceof Boolean||o instanceof Number){o=o.valueOf();}}switch(typeof o){case"string":return _string(o);case"number":return isFinite(o)?String(o):"null";case"boolean":return String(o);case"object":if(o===null){return"null";}for(i=pstack.length-1;i>=0;--i){if(pstack[i]===o){return"null";}}pstack[pstack.length]=o;a=[];isArray=l.isArray(o);if(d>0){if(isArray){for(i=o.length-1;i>=0;--i){a[i]=_stringify(o,i,d-1,w,pstack)||"null";}}else{j=0;if(l.isArray(w)){for(i=0,len=w.length;i<len;++i){k=w[i];v=_stringify(o,k,d-1,w,pstack);if(v){a[j++]=_string(k)+":"+v;}}}else{for(k in o){if(typeof k==="string"&&l.hasOwnProperty(o,k)){v=_stringify(o,k,d-1,w,pstack);if(v){a[j++]=_string(k)+":"+v;}}}}a.sort();}}pstack.pop();return isArray?"["+a.join(",")+"]":"{"+a.join(",")+"}";}return undefined;}return{isValid:function(s){return _isValid(_prepare(s));},parse:function(s,reviver){s=_prepare(s);if(_isValid(s)){return _revive(eval("("+s+")"),reviver);}throw new SyntaxError("parseJSON");},stringify:function(o,w,d){if(o!==undefined){if(l.isArray(w)){w=(function(a){var uniq=[],map={},v,i,j,len;for(i=0,j=0,len=a.length;i<len;++i){v=a[i];if(typeof v==="string"&&map[v]===undefined){uniq[(map[v]=j++)]=v;}}return uniq;})(w);}d=d>=0?d:1/0;return _stringify({"":o},"",d,w,[]);}return undefined;},dateToString:function(d){function _zeroPad(v){return v<10?"0"+v:v;}return d.getUTCFullYear()+"-"+_zeroPad(d.getUTCMonth()+1)+"-"+_zeroPad(d.getUTCDate())+"T"+_zeroPad(d.getUTCHours())+":"+_zeroPad(d.getUTCMinutes())+":"+_zeroPad(d.getUTCSeconds())+"Z";},stringToDate:function(str){if(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$/.test(str)){var d=new Date();d.setUTCFullYear(RegExp.$1,(RegExp.$2|0)-1,RegExp.$3);d.setUTCHours(RegExp.$4,RegExp.$5,RegExp.$6);return d;}return str;}};})(); /*"*/
if (!AJAX){
var AJAX = {
	elBusy:null,
	elMsg:null,
	elMask:null,
	elWait:null,
	init:function()
	{
		AJAX.elBusy = document.createElement('div');
		AJAX.elBusy.className ='ajax_busy';
		document.body.appendChild(AJAX.elBusy);
		AJAX.elMsg = document.createElement('div');
		AJAX.elMsg.className ='ajax_msg';
		document.body.appendChild(AJAX.elMsg);
		AJAX.elMask = document.createElement('div');
	},
	call:function(sFunctionName,fnCallback,oThis){
		var arrParam = [];
		for(var i=3; i<arguments.length; i++)
			arrParam[i-3] = arguments[i];
		var strPost = '_ajaxCall_=1&_ajaxFunc_='+escape(sFunctionName)+'&_ajaxParam_='+escape(YAHOO.lang.JSON.stringify(arrParam));
		sUrl = ''+document.location; //Type cast sUrl to STRING, to use replace
		sUrl = sUrl.replace(/\#.*$/,'');
		var request = AJAX.asyncRequest(
			'POST',
			sUrl,
			{
				success: function(o){
					if (!YAHOO.lang.JSON.isValid(o.responseText))
						var res = {code:002,debugmsg:'Returned Non Json\n'+o.responseText};
					else
						var res = YAHOO.lang.JSON.parse(o.responseText);
					AJAX.cb(res);
					fnCallback.call(oThis,res);
				},
				failure:function(o){dmp(o);}
			},
			strPost
		);
	},
	callurl:function(sUrl,sFunctionName,fnCallback,oThis){
		var arrParam = [];
		for(var i=4; i<arguments.length; i++)
			arrParam[i-4] = arguments[i];
		var strPost = '_ajaxCall_=1&_ajaxFunc_='+escape(sFunctionName)+'&_ajaxParam_='+escape(YAHOO.lang.JSON.stringify(arrParam));
		sUrl = sUrl.replace(/\#.*$/,'');
		var request = AJAX.asyncRequest(
			'POST',
			sUrl,
			{
				success: function(o){
					if (!YAHOO.lang.JSON.isValid(o.responseText))
						var res = {code:002,debugmsg:'Returned Non Json\n'+o.responseText};
					else
						var res = YAHOO.lang.JSON.parse(o.responseText);
					AJAX.cb(res);
					if (fnCallback) fnCallback.call(oThis,res);
				},
				failure:function(o){dmp(o);}
			},
			strPost
		);
	},
	showBusy:function(sMsg){AJAX.elBusy.innerHTML = sMsg || 'Loading ...';AJAX.elBusy.style.display='block';AJAX.repos(this.elBusy,2);},
	showMsg:function(sMsg){AJAX.elMsg.innerHTML = sMsg || 'Working ...';AJAX.elMsg.style.display='block';AJAX.repos(this.elMsg,2);if(AJAX.hideMsg_timer){clearTimeout(AJAX.hideMsg_timer);}AJAX.hideMsg_timer = setTimeout(AJAX.hideMsg,3000);},
	showWait:function(sMsg,sTitle){
	},
	showAlert:function(strMsg,strType,strTitle)
	{
		alert(strMsg);
	},
	hideBusy:function(){AJAX.elBusy.style.display='none';AJAX.hideMsg_timer=null;},
	hideWait:function(){
		if (this.panelWait)
			this.panelWait.hide();
	},
	hideMsg:function(){AJAX.elMsg.style.display='none';},
	repos:function(oEl,pY){oEl.style.top = (document.body.scrollTop+pY);},
	cbNop:function(){AJAX.hideBusy();},
	cb:function(res)
	{
		// Handle Callback
		if (res == null) {alert('There is an error on ajax communication.'); return;}
		if (res.debugmsg != null) alert('Debugger\n------------\n'+res.debugmsg);
		if (res.alert != null) alert(res.alert);
		if (res.redirect != null) document.location = res.redirect;
		if (res.user_exec)
		{
			var eachExec;
			for (var _iuc=0;_iuc<res.user_exec.length;_iuc++)
			{
				eachExec = res.user_exec[_iuc];
				if (eachExec.type=='HTTPPOST' || eachExec.type=='HTTPGET')
				{
					var userexecIFrame,ifm,iform,iinputq,isubmit,_iucp;
					userexecIFrame = document.createElement('iframe');
					userexecIFrame.setAttribute("name","iframe_user_exec_"+_iuc);
					userexecIFrame.setAttribute("id","iframe_user_exec_"+_iuc);
					userexecIFrame.setAttribute("style","display:none;");
					userexecIFrame.setAttribute("src","blank.html");
					userexecIFrame.style.width = '1px';
					userexecIFrame.style.height = '1px';
					userexecIFrame.style.display = 'none';
					document.body.appendChild(userexecIFrame);
					sHTML = '';
					sHTML += '<form name="form1" method="'+(eachExec.type=='HTTPPOST'?'POST':'GET')+'" action="'+eachExec.data.url+'" >'

					for (_iucp=0;_iucp<eachExec.data.param.length;_iucp++)
					{
						if (eachExec.data.param[_iucp].name != 'submit')
						{
							sHTML += '<input type="hidden" name="'+eachExec.data.param[_iucp].name+'" value="'+eachExec.data.param[_iucp].value+'"/>';
						}
					}

					sHTML += '</form>'
					sHTML += '<input type="submit"/>';
					window.frames["iframe_user_exec_"+_iuc].document.writeln(sHTML +'<scr'+'ipt>document.form1.submit();</scri'+'pt>');
				}
				else
				{
					alert('UNKNOWN AJAX_CB USER_EXEC '+eachExec.type);
				}
			};
		}
	},
	asyncRequest:function(method, uri, callback, postData)
	{
		var xmlHttp;
		try
		{ xmlHttp=new XMLHttpRequest(); }
		catch (e)
		{
			try
			{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }
			catch (e)
			{
				try
				{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
				catch (e)
				{ alert("Your browser does not support AJAX!");return false;}
			}
		}
		xmlHttp.onreadystatechange=function()
		{
			if(xmlHttp.readyState==4)
			{
				if (callback.success)
					callback.success(xmlHttp);
			}
		}
		postData = postData || '';
		xmlHttp.open(method,uri,true);
		xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xmlHttp.setRequestHeader("Content-Length", postData.length);
		xmlHttp.send(postData);
	}
};
}

function gebi(pName){return document.getElementById(pName);}
function exp(elname)
{
	var target = gebi('div_'+elname);
	if (!gebi('txt_'+elname))
	{
		if (target.style.display=='none')
			target.style.display='block';
		else
			target.style.display='none';
	}
	else
	{
		if (gebi('txt_'+elname).checked)
			target.style.display=(target.tagName=='TR'?'table-row':'block');
		else
			target.style.display='none';
	}
}
function setCombo(oObj,arrList,selectedId)
{
	while (oObj.options.length  > 0)
	{oObj.options[0] = null;}

	for (i=0;i<arrList.length;i++)
	{
		arrList[i].key = arrList[i].key || arrList[i].id;
		arrList[i].text = arrList[i].text || arrList[i].name;
		if (arrList[i].key == selectedId) {selected = true;} else {selected=false;}
		oObj.options[oObj.length] = new Option(arrList[i].text, arrList[i].key, false, selected);
	}
}
function redirect(url)
{
	document.location = url;
}
function dmp(obj,depth){alert(dump(obj,depth));}
function dump(obj,depth)
{
	if (depth==undefined) depth=20;
	depth=20-depth;
	return dumpObj(obj, '', '', depth)
}
function dumpObj(obj, name, indent, depth) {
    if (depth > 20) {
        return indent + name + ': <Maximum Depth Reached>\n';
    }
    if (typeof obj == 'object') {
        var child = null;
        var output = indent + name + '\n';
        indent += '\t';
        for (var item in obj){
            try {
                child = obj[item];
            } catch (e) {
                child = '<Unable to Evaluate>';
            }
            if (typeof child == 'object') {
                output += dumpObj(child, item, indent, depth + 1);
            } else {
                output += indent + item + ': ' + child + '\n';
            }
        }
        return output;
    } else {
        return obj;
    }
}
function purge(d)
{
	if (!d) return;
    var a = d.attributes, i, l, n;
    if (a) {
        l = a.length;
        for (i = 0; i < l; i += 1) {
            n = a[i].name;
            if (typeof d[n] === 'function') {
                d[n] = null;
            }
        }
    }
    a = d.childNodes;
    if (a) {
        l = a.length;
        for (i = 0; i < l; i += 1) {
            purge(d.childNodes[i]);
        }
    }
}
function format_currency(price)
{
	// fractal bug, push up by 4 digit to be later rounded back
	price=parseInt(price*1000);
	decimal = parseInt(price/1000);
	fractal = (parseInt(price/100)%10)+""+(parseInt(price/10)%10);
	return '$'+decimal+'.'+fractal;
}