naviki.dialog.help = function(id,uid,pageId,objectname,sys_language_uid){
	
	this.interval;
	this.helpDlg;
	this.body;
	this.uid    	= uid;
	this.id     	= id;
	this.pageId 	= pageId;
	this.objectname = objectname;
	this.sys_language_uid = sys_language_uid;
}; 

naviki.dialog.help.prototype.create = function(){

	this.parent   = document.getElementById(""+this.id);
	this.child    = document.createElement("div");
	this.child.id = this.id+"-"+this.uid;
	this.parent.appendChild(this.child);	
	
    var agent = navigator.userAgent.toLowerCase();  
	var host  = window.location.host;
	var src   = "http://"+host+"/index.php?id="+this.pageId+"&type=100&L="+this.sys_language_uid;

	var onload = "onLoad='"+
                 "this.style.height=0;" +
                 "this.style.width=\"300px\";" +
                 "if(this.Document!=null){" +
                 "h = this.Document.body.scrollHeight;" +
                 "w = this.Document.body.scrollWidth;"+
                 "tmp = this.Document.body.innerHTML.toUpperCase();"+
                 "}else{"+
                 "h = this.contentDocument.body.scrollHeight;" +
                 "w = this.contentDocument.body.scrollWidth;"+
                 "tmp = this.contentDocument.body.innerHTML.toUpperCase();"+                 
                 "}"+
                 "widthpos = tmp.search(/WIDTH/);"+
                 "if(widthpos>0){"+
                 "do{"+
                 "tmp = tmp.substring(widthpos,tmp.length);"+
                 "pos = tmp.search(/([0-9])/);"+
                 "tmp = tmp.substring(pos,tmp.length);"+
                 "pos = tmp.search(/([A-Za-z]|\")/);"+
                 "nw  = tmp.substring(0,pos);"+
                 "if(nw>w){"+
                 "w=nw;"+
                 "}"+
                 "widthpos = tmp.search(/WIDTH/);"+                   
                 "}while(widthpos>0);"+
                 "}"+                 
	             "if(w>(screen.width-100)){"+
                 "this.style.width = (window.innerWidth-100) + \"px\";" +
                 "this.width=window.innerWidth-100;"+
                 "}else{"+
                 "this.style.width = w + \"px\";" +
                 "this.width = w;}"+			   			   
                 "if(h>(screen.height-100)){"+
                 "this.style.height = (window.innerHeight-100) + \"px\";" +
                 "this.height=window.innerHeight-100;"+
                 "}else{"+
                 "this.style.height = h + \"px\";" +
                 "this.height = h;}' ";
	
	var def    = "<iframe style='overflow:hidden;width:100%;height:100%;' "+onload+" id='tx-naviki-help-"+this.uid+"' src='"+src+"' name='tx-naviki-help-"+this.uid+"' border='0' frameborder='0' scrolling='no'></iframe>";
	var safari = "<object style='overflow:hidden;width:100%;height:100%;' "+onload+" id='tx-naviki-help-"+this.uid+"' data='"+src+"' type='text/html'></object>";
	
	if(this.checkBrowserName('safari')){  
		this.body = def;
	}
	else{
		this.body = def;
	}
	
	this.helpDlg = new naviki.main.ModalDialog(
			      ""+this.child.id,
			      {  
			    	 fixedcenter: true,  
			 	     visible    : false,
				     modal      : true,
				     draggable  : true,
				     zindex     : 5,  
				     close      : true,  
				     constraintoviewport: true
			      }
	);
	this.helpDlg.setHeader(naviki.Lang.getLL('help_dialog_header'));
	this.helpDlg.setBody(this.body);
	this.helpDlg.render();
	
	this.helpDlg.hideEvent.subscribe(function(){
		this.setBody("");
	});
};

naviki.dialog.help.prototype.show = function(){

	if(this.helpDlg){
		this.helpDlg.setBody(this.body);
		this.helpDlg.show();
	}else{
		this.create();
		this.interval = window.setInterval(this.objectname+"['"+this.uid+"'].center()", 50);
	}
};

naviki.dialog.help.prototype.center = function(){
	
	var element = document.getElementById("tx-naviki-help-"+this.uid);
	var h;
	var w;
	
	if(element.height!=""){
		window.clearInterval(this.interval);
		w = parseInt(element.width) + 20;
		h = parseInt(element.height) + 50;
		w = w+"px";
		h = h+"px";
		this.helpDlg.cfg.queueProperty("width", w);
		this.helpDlg.cfg.queueProperty("height", h);
		this.helpDlg.render();
		this.helpDlg.show();
	}
};

naviki.dialog.help.prototype.checkBrowserName = function(name){  
	var agent = navigator.userAgent.toLowerCase();

	if (agent.indexOf(name.toLowerCase())>-1) {  
		return true;  
	}  
	return false;  
};  

