//************************************************************************************
// CXSims.QuickLink Object - displays a QuickLink menu
// By: CXS Consulting,Inc.
// Date: September 2007
// Version: 1.0
//*************************************************************************************
// Input:
//  - caption = the Caption of the QuickLinks Frame (default="Quick Links")
//  - width   = the width of the QuickLink cell
//  - captionclass = the class for displaying the caption
//  - itemclass = the class for the items (see Note)
//  - itembreakclass = the class for horizonatal line
//  - backgroundclass = the Background of the LinkWindow
//*************************************************************************************
// Notes:
//   1)	Sub-class of the itemclass with a 'hover:', 'active:', 'link:', and 'visited:' 
//		must be setup in the CSS file.
//*************************************************************************************
function QuickLinks(caption,width,captionclass,itemclass,itembreakclass,backgroundclass)
{
	this.objName="QLink"+QuickLinks.count++;
	eval(this.objName+"=this");
	if(!width) this.width=120; else this.width=width;
	if(!caption) this.caption="Quick Links"; else this.caption=caption;
	if(!captionclass) this.captionclass=null; else this.captionclass=captionclass;
	if(!itemclass) this.itemclass=null; else this.itemclass=itemclass;
	if(!itembreakclass) this.itembreakclass=null; else this.itembreakclass=itembreakclass;
	if(!backgroundclass) this.backgroundclass=null; else this.backgroundclass=backgroundclass;
	this.height=null;
	this.links = new Array();
	
	this.ShowCaption=true;
	this.FixedWidth=true;
	
	var mbHasError =  false;
	
	//
	// Add a new hyperlink line
	//
	this.AddLink=function(href,text,tip,target)
	{
		if ((text==null) || (text==""))
		 	return false;
		 
		var iLength = this.links.push(new Object);
		var pLink = this.links[iLength-1];

		pLink.id="link_"+iLength;
		pLink.type="link";
		pLink.text = text;
		if (!href) pLink.href=""; else pLink.href=href;
		if (!tip) pLink.tip=""; else pLink.tip=tip;
		if ((typeof(target) == "undefined") || (target==null)) pLink.target="_parent"; else pLink.target=target;
	}
	
	//
	// Add a new hyperlink line with an OnClick action
	//
	this.AddOpenWindow=function(href,text,tip,winname,features)
	{
		if ((text==null) || (text==""))
		 	return false;
		 
		var iLength = this.links.push(new Object);
		var pLink = this.links[iLength-1];

		pLink.id="link_"+iLength;
		pLink.type="onclick";
		pLink.text = text;
		if (!href) pLink.href=""; else pLink.href=href;
		if (!tip) pLink.tip=""; else pLink.tip=tip;
		if (!winname) pLink.winname=pLink.id; else pLink.winname=winname;
		if (!features) pLink.features=""; else pLink.features=features;
	}
	
	//
	// Add a new hyperlink line with an OnClick action
	//
	this.AddActionCmd=function(cmd,text,tip)
	{
		if ((text==null) || (text=="") || (cmd==null) || (cmd==""))
		 	return false;
		 
		var iLength = this.links.push(new Object);
		var pLink = this.links[iLength-1];

		pLink.id="link_"+iLength;
		pLink.type="action";
		pLink.text = text;
		if (!cmd) pLink.href=""; else pLink.href=cmd;
		if (!tip) pLink.tip=""; else pLink.tip=tip;
	}
	
	//
	// Add a new horizontal line - ths leftpadding and rightpadding
	// determine if size and offsets - taking in consideration the
	// set QuickLinks.width. - It disragard the FixedWidth setting.
	//
	this.AddLine = function(leftPadding,rightPadding)
	{
		var iLength = this.links.push(new Object);
		var pLink = this.links[iLength-1];
		pLink.id="link_"+iLength;
		pLink.type="hr";
		
		pLink.leftPadding=0;
		if ((leftPadding != null) && (!isNaN(leftPadding)) && (leftPadding > 0))
		  pLink.leftPadding=leftPadding;
		
		var iWidth = this.width-pLink.leftPadding;
		if ((rightPadding != null) && (!isNaN(rightPadding)) && (rightPadding > 0))
			iWidth -= rightPadding;
			
		pLink.linewidth=iWidth;
	}
	
	//Set Wether the Caption is visisble or not
	this.SetShowCaption=function(doShow)
	{
		if ((doShow!=null) && (!doShow))
		 	this.ShowCaption = doShow;
		else
			this.ShowCaption = true;
	}
	
	//
	// Call from the page to generate the HTML for the Quicklinks Page
	//
	this.GetHTML = function()
	{
		var sHTML = "";
		mbHasError = false;
		try
		{
			if ((this.links==null) || (this.links.length == 0))
				return true;
		  	
		  sHTML = "<table";
		  if (this.backgroundclass != null)
		  	sHTML += " class='"+this.backgroundclass+"'";
		  	
		  sHTML += "align='left' cellpadding='0' cellspacing='0' border='0'";
		  if (this.height != null)
		  	sHTML += " height="+this.height.toFixed(0)+">";
		  
		  var sWidth = "100%";
		  if ((this.FixedWidth) && (this.width != null))
				sWidth = this.width.toFixed(0);
				
		  if (this.ShowCaption)
		  {
		  	sHTML += "<tr><td class='"+this.captionclass+"' width='"+sWidth;
		  	sHTML += "' valign='center'>"+this.caption+"</td></tr> ";
		  }
		  	
	  	sHTML += "<tr><td width='"+sWidth+"' valign='top'>"
		  for(i=0;i<this.links.length;i++)
		  {
		  	var pLink = this.links[i];
				var sSubHTML = ""
				var sID = this.objName+"_"+pLink.id;
		  	if (pLink.type=="hr")
		  	{
		  		sSubHTML += "<div";
		  		if (this.itembreakclass != null) 
		  			sSubHTML += " class='"+this.itembreakclass+"'";
		  		sSubHTML += "><hr class='"+this.itembreakclass +"'";
		  		sSubHTML += " style='margin-left:"+pLink.leftPadding.toFixed(0)+";'"; 
		  		sSubHTML += " width='"+pLink.linewidth.toFixed(0)+"'></div>";
		  	}
		  	else if (pLink.type=="onclick")
		  	{
			  	sSubHTML += "<div style='width=100%;'><a id='"+sID+"' ";
			  	if (this.itemclass != null) 
			  		sSubHTML += "class='"+this.itemclass+"' ";

		  		sSubHTML += "href='#' ";
			  	sSubHTML += "onclick='window.open(\""+pLink.href+"\",\""+
			  					 pLink.winname+"\",\""+pLink.features+"\"); return true;' ";
			  	sSubHTML += "onMouseOver='"+this.objName+".MouseOver(this); return true;' ";
			  	sSubHTML += "onMouseOut='"+this.objName+".MouseOut(this); return true;' ";
			  	sSubHTML += "tip='"+pLink.tip+"' title='"+pLink.tip+"'>"+ pLink.text+"</a></div> ";
			  }
		  	else if (pLink.type=="action")
		  	{
			  	sSubHTML += "<div style='width=100%;'><a id='"+sID+"' ";
			  	if (this.itemclass != null) 
			  		sSubHTML += "class='"+this.itemclass+"' ";

		  		sSubHTML += "href='#' ";
			  	sSubHTML += "onclick=\""+pLink.href+"\" ";
			  	sSubHTML += "onMouseOver='"+this.objName+".MouseOver(this); return true;' ";
			  	sSubHTML += "onMouseOut='"+this.objName+".MouseOut(this); return true;' ";
			  	sSubHTML += "tip='"+pLink.tip+"' title='"+pLink.tip+"'>"+ pLink.text+"</a></div> ";
			  }
		  	else
		  	{
			  	sSubHTML += "<div style='width=100%;'><a id='"+sID+"' ";
			  	if (this.itemclass != null) 
			  		sSubHTML += "class='"+this.itemclass+"' ";
			  	if (pLink.href != null) 
			  		sSubHTML += "href='"+pLink.href+"' ";
			  	sSubHTML += "target='"+pLink.target+"' ";
			  	sSubHTML += "onMouseOver='"+this.objName+".MouseOver(this); return true;' ";
			  	sSubHTML += "onMouseOut='"+this.objName+".MouseOut(this); return true;' ";
			  	sSubHTML += "tip='"+pLink.tip+"' title='"+pLink.tip+"'>"+ pLink.text+"</a></div> ";
			  }
			  
			  sHTML += sSubHTML;
		  }
	  	sHTML += "</td></tr></table> ";
  	}
		catch(ex)
		{
			sHTML = "QuickLinks.GetHTML Error: "+ex.message;
			mbHasError = true;
		}
		return sHTML;
	}
	
	//
	// Called to insert the QucikLinks' HTML as the InnerHTML.
	this.Output = function()
	{
		var sHTML = this.GetHTML();
		if (sHTML != null)
			document.write(sHTML);

		return mbHasError;	
	}
	
	//
	// MouseOver Event Handler
	//
	this.MouseOver=function(obj)
	{
	  if ((obj != null) && (obj.id != null))
	  {
			var pLink = document.getElementById(obj.id);
			if (pLink != null)
				window.defaultStatus =pLink.tip;
		}
	}
	
	//
	// MouseOut Event Handler
	//
	this.MouseOut=function(obj)
	{
		window.defaultStatus = "";
	}
}
QuickLinks.count=0;

