//Softcomplex
// URL: http://www.softcomplex.com/

var A_OBJECTS = [],o_UA;

function _objecta (a_vars,a_tpl){

	this.n_id = A_OBJECTS.length;
	A_OBJECTS[this.n_id] = this;
	this.flag_error = false;	
	this.cpobj = cp_obj;
	this.a_tpl = this.cpobj(a_tpl);
	this.a_vars = this.cpobj(a_vars);
	this.datemessage = cal_datemessage; 
	
	if(!this.a_vars.obj_iframe_src) {this.datemessage('need_iframe_src');return;}

	this.a_tpl['iframe_aspect']['src'] = this.a_vars.obj_iframe_src;
	
	if (!o_UA) 	o_UA = new _UserAgent();
	this.getattrs = obj_getattrs;
	this.getobj = obj_getobj;
	this.showobj = obj_show;
	this.resizeobj = obj_resize;
	this.create = obj_create;
	this.udpdatepos =  obj_udpdatepos;
	this.getabspos = obj_getabspos;
	this.iframe_style = [];
	
	this.obj_iframename = !this.a_vars.obj_iframe_name ? 'objiframe'+this.n_id : this.a_vars.obj_iframe_name;
	this.obj_posname = !this.a_vars.controlposition ? 'objpos'+this.n_id : this.a_vars.controlposition;
	
	this.e_pos = this.getobj(this.obj_posname);
				
	this.obj_typemodal = this.a_vars.obj_type_modal?true:false;
	
	this.iframe_style =  this.a_tpl['iframe_style_default'];
	
	if(this.a_vars.style && typeof(this.a_vars.style)=='object'){
		for(var i in this.a_vars.style) {
			this.iframe_style[i] = this.a_vars.style[i];
		}
	}
			
	if(!this.obj_typemodal)  this.create(true);
		
}

function obj_create (flaga){
	if(o_UA.ns4 || (this.obj_typemodal && (!document.body || !document.body.innerHTML))) return;
	if((!this.obj_typemodal && flaga) || (this.obj_typemodal && !flaga)) {
		var str_bufer = new acc();
		if(!this.obj_typemodal && flaga) {
			
			delete this.iframe_style['position'];
			
		}
			
		str_bufer.add('<iframe id="',this.obj_iframename,'" name="',this.obj_iframename,'" ',this.getattrs('iframe_aspect'),'   style="',this.getattrs(this.iframe_style),'"></iframe>');   
		if(this.obj_typemodal && !o_UA.opera6 && !o_UA.opera5 && this.n_id == 0) {str_bufer.add('<script language="JavaScript">window.onresize = function() {for (var n = 0; n < A_OBJECTS.length; n++) {	A_OBJECTS[n].udpdatepos();}}	</script>');	}
		document.write(str_bufer.say());
		this.e_boxstyle = this.getobj(this.obj_iframename);
		if(!this.e_boxstyle) {this.datemessage('need_object');return;}
	}
	
}

function obj_udpdatepos () {
var smx=0, smy=0, out_x, out_y;
	var win_height = o_UA.ie ? document.body.clientHeight : window.innerHeight - (o_UA.ns ? (this.a_vars.ns_scroll ? this.a_vars.ns_scroll : 0):0);
	var win_width = o_UA.ie ? document.body.clientWidth : window.innerWidth - (o_UA.ns ? (this.a_vars.ns_scroll ? this.a_vars.ns_scroll : 0):0);
	var pos_x = (!this.e_pos ? 0 : this.e_pos.x ? this.e_pos.x : (this.getabspos('Left')+smx)) + this.iframe_style['left'];
	var pos_y = (!this.e_pos ? 0 : this.e_pos.y ? this.e_pos.y : (this.getabspos('Top')+smy)) + this.iframe_style['top'];
	var _w = parseInt(this.e_boxstyle.style.width);
	var _h = parseInt(this.e_boxstyle.style.height);
	if( o_UA.ie && o_UA.mac) {
		 if (document.body.leftMargin)  smx = document.body.leftMargin * 1;
		 if (document.body.topMargin)  smy = document.body.topMargin * 1;
	}

	this.e_boxstyle.style.left = win_width <= _w ? 0 : win_width <= (pos_x + _w + this.iframe_style['left']) ? win_width - _w : pos_x;
	this.e_boxstyle.style.top = win_height <= _h ? 0 : win_height <= (pos_y + _h + this.iframe_style['top']) ? win_height - _h : pos_y ;
}

function obj_getabspos (s_coord) {
	var n_pos = 0, o_elem = this.e_pos;
	while (o_elem)	{
		n_pos += o_elem["offset" + s_coord];
		o_elem = o_elem.offsetParent;
	}
	
	return n_pos;
}

function obj_getattrs (a_config) {
	var s_result = [],o_prop;
	if(typeof(a_config) == 'object') 
	{
		o_prop = a_config;
		for (var s_key in o_prop) s_result[s_result.length] = ' ' + s_key + ':'+o_prop[s_key]+'';
		return s_result.join(';');
	}
	
   	else if(typeof(a_config) == 'string') {
		o_prop = this.a_tpl[a_config];
		for (var s_key in o_prop) s_result[s_result.length] = ' ' + s_key + '="' + o_prop[s_key] + '"';
		return s_result.join('');
	}
		
}

function cp_obj(o_source){
	var o_destination;
	if(typeof(o_source)=='object'){
		o_destination=[];
		for(var i in o_source)
			o_destination[i]=cp_obj(o_source[i])
	}
	
	else o_destination=o_source;
	return o_destination;
}

function obj_resize(_width,_height) {
	this.e_boxstyle.style.width = _width;
	this.e_boxstyle.style.height = _height;
	if(this.obj_typemodal && this.e_pos) {this.udpdatepos();}
}

function obj_show() {
	
	if(o_UA.ns4 || !this.e_boxstyle) return;
	var s_visib = String(this.e_boxstyle.style.visibility).toLowerCase();
	if (s_visib == 'visible' || s_visib == 'show') {
		this.e_boxstyle.style.visibility = 'hidden';
		if(this.pict_type==1) 
		this.e_icon.src = this.a_tpl.caliconshow.src;
	}
	
	else {
		if(this.obj_typemodal && this.e_pos) {this.udpdatepos();}
		if(this.a_vars.replace) {
			for(i=0;i< A_OBJECTS.length;i++) {
				if(i!=this.n_id && this.obj_typemodal && A_OBJECTS[i].e_boxstyle && A_OBJECTS[i].obj_typemodal ) {
					A_OBJECTS[i].e_boxstyle.style.visibility = 'hidden';
				}
			}
		}
		this.e_boxstyle.style.visibility = 'visible';
		if(this.pict_type==1)
		this.e_icon.src = this.a_tpl.caliconhide.src;
	}
	
}

function obj_getobj (str_id, flag) {
	if (document.images && document.images[str_id]) return document.images[str_id];
	else if (this.form_name &&  document.forms[this.form_name].elements[str_id])  return document.forms[this.form_name].elements[str_id];
	else if (document.all && document.all[str_id])  return document.all[str_id];
	else if (document.getElementById)  return document.getElementById(str_id);
	else return null;
	
}

function acc() {
	this.arr = [];
	this.add = function () {
		var n = arguments.length;
		for (var i = 0; i < n; i++)
			this.arr[this.arr.length] = arguments[i];
	};
	this.say = function () {
		return this.arr.join('');
	};
}

function cal_datemessage (n_datestatus,flag) {
	switch (n_datestatus) {
	
		case 'need_iframe_src':
			messaga = ARR_STRINGS['need_iframe_src'];
			this.flag_error = true;
		break;
		case 'need_object':
			messaga = ARR_STRINGS['need_object'];
			this.flag_error = true;
		break;
		
	}
	alert(messaga);
}

function _UserAgent() {
	var b = navigator.appName;
	var v = this.version = navigator.appVersion;
	var re_num = /opera/;
	var re_num5 = /opera.5/;
	var ua=this.uas = navigator.userAgent.toLowerCase();
	this.v = parseInt(v);
	this.mozilla=false;
	this.ns = (b == "Netscape");
	this.ie = (b == "Microsoft Internet Explorer");
	this.opera = re_num.exec(ua)?true:false;
	if(this.opera) {
		this.opera5 = re_num5.exec(ua)?true:false;
	 	this.opera6 = ua.indexOf("opera 6")>0?true:false;
		this.opera7 = ua.indexOf("7")>0?true:false;
	}
	
	if(ua.indexOf("netscape") < 0 && ua.indexOf("msie") < 0  && ua.indexOf("opera") < 0 && this.v >= 5) {
		this.mozilla = true;
		this.ns = false;
	}
	
	if (this.ns) {
		if(ua.indexOf('netscape/7.1') > 0) this.ns71 = true; 
		else {
			this.v = parseInt(v);
			this.ns4 = (this.v==4);
		}
		
	}
	
	else if (this.opera || this.mozilla) {
		this.v = parseInt(v);
	}
	
	this.win32 = ua.indexOf("win")>-1;
	this.mac = ua.indexOf("mac")>-1;
	this.other = (!this.win32 && !this.mac);
}
