// JavaScript Document

	
function imgCombo(obName, cmbWidth, cmbHeight, arItems, arIds, arImages, mgOpener, mgUp, mgDown, mgDims, plcHolder, lng)
{
	this.objName = obName;
	this.objWidth = cmbWidth;
	this.objHeight = cmbHeight;
	this.Items = this.getArray(arItems, -1);
	this.Ids = this.getArray(arIds, -1);
	this.Images = this.getArray(arImages, -1);
	this.imgOpener = mgOpener;
	this.imgArrowUp = mgUp;
	this.imgArrowDown = mgDown;
	this.placeHolder = plcHolder;
	this.lang = lng;
	
	
	this.imgOpenerWidth = this.getArray(mgDims, 0);
	this.imgOpenerHeight = eval(this.getArray(mgDims, 1)) - 2;
	this.imgArrowsWidth = this.getArray(mgDims, 2);
	this.imgArrowsHeight = this.getArray(mgDims, 3);
	
	this.imgOptWidth = this.getArray(mgDims, 4);
	this.imgOptHeight = this.getArray(mgDims, 5);
	
	this.tdImgOptWidth = eval(this.imgOptWidth) + 4;
	this.tdImgOptHeight = this.getArray(mgDims, 5);
	
	this.tdOptWidth = this.objWidth - eval(this.imgOpenerWidth) - eval(this.tdImgOptWidth) ;

	
	this.tblId = 'tbl_' + obName;
	this.openerId = 'opn_' + obName
	this.tdBoxId = 'td_' + obName;
	this.divId = 'dv_' + obName;
	this.dvScroll = 'dvScroll_' + obName;
	this.hdnInput = 'hdn_' + obName;
	this.imgTd = 'imgtd_' + obName;
	this.imgUp = 'imgUp_' + obName;
	this.imgDown = 'imgDown_' + obName;
	
	
	this.drawMainBox();
	this.drawCombo();
	this.drawList();
	
	var comboBox = this;
	
	// Combo onClick Action Open Close Combo//
	this.comboOpener = document.getElementById(this.tblId) ;
	
	this.comboOpener.onclick = function()
	{
		comboBox.openCombo();
	}
	
} // function imgCombo()


imgCombo.prototype.getArray = function(strArr, index)
{
	var valArray = new Array();
	
	valArray = strArr.split(',');
	if (index != -1)
		return valArray[index];
	else
		return valArray;
} // getArray


imgCombo.prototype.drawMainBox = function()
{
	dvWidth = eval(this.objWidth) - 2 ;  //fixing width
	
	dv = "<div id='"+this.divId+"' tabindex='-1' style='width:"+dvWidth+"px; height:"+this.objHeight+"px; display:none; z-index:1000;' class='divCombo'></div>";
	hdn = "<input id='"+this.hdnInput+"' type='hidden' value='' />";
	
	html = "<table id='"+this.tblId+"' cellspacing='0' cellpadding='0' border='0' align='center' width='"+this.objWidth+"' class='tblCombo'><tr>";
	
	if( this.lang == 'ar') {
		html += "<td width='"+this.imgOpenerWidth+"' valign='middle'><img id='"+this.openerId+"' border='0' src='"+this.imgOpener+"' /></td>";
		html += "<td id='' width='"+this.tdOptWidth+"' class='tdComboOption'><div id='"+this.tdBoxId+"' style='overflow:hidden'></div></td>";
		html += "<td id='"+this.imgTd+"' height='"+this.imgOpenerHeight+"' width='"+this.tdImgOptWidth+"' align='center' valign='middle'></td>";
	}
	else if( this.lang == 'en') {
		html += "<td id='"+this.imgTd+"' height='"+this.imgOpenerHeight+"' width='"+this.tdImgOptWidth+"' align='center' valign='middle'></td>";
		html += "<td id='"+this.tdBoxId+"' width='"+this.tdOptWidth+"' class='tdComboOption'></td>";
		html += "<td width='"+this.imgOpenerWidth+"' valign='middle'><img id='"+this.openerId+"' border='0' src='"+this.imgOpener+"' /></td>";
	}
	
	html += "</tr></table>";
	
	document.write(dv);
	document.write(hdn);
	document.getElementById(this.placeHolder).innerHTML = html ;
} // drawMainBox


imgCombo.prototype.drawCombo = function()
{	
	optsBoxWidth = eval(this.objWidth) - this.imgOpenerWidth;
	scrollerSpace = eval(this.objHeight) - ( eval(this.imgArrowsHeight) * 2 );
	
	html = "<table width='"+this.objWidth+"' tabindex='-1' cellspacing='0' cellpadding='0' border='0'><tr>";
	
	if( this.lang == 'ar') {
		html += "<td height='"+this.objHeight+"' width='"+this.imgOpenerWidth+"'>";
		html += "<table tabindex='-1' cellspacing='0' cellpadding='0' border='0' width='"+this.imgOpenerWidth+"' class='tblScrollBar'><tr>";
		html += "<td id='"+this.imgUp+"' align='center' valign='middle' height='"+this.imgArrowsHeight+"'><img src='"+this.imgArrowUp+"' height='"+this.imgArrowsHeight+"' width='"+this.imgArrowsWidth+"' onclick='scrollAccelerate(\""+this.dvScroll+"\", \"down\")' onmouseover='scrollDown(\""+this.dvScroll+"\")' onmouseout='scrollStop()' /></td>";
		html += "</tr><tr><td height='"+scrollerSpace+"'> </td></tr><tr>";
		html += "<td id='"+this.imgDown+"' align='center' valign='middle' height='"+this.imgArrowsHeight+"'><img src='"+this.imgArrowDown+"' height='"+this.imgArrowsHeight+"' width='"+this.imgArrowsWidth+"' onclick='scrollAccelerate(\""+this.dvScroll+"\", \"up\")' onmouseover='scrollUp(\""+this.dvScroll+"\")' onmouseout='scrollStop()'/></td>";
		html += "</tr></table></td>";
				
		html += "<td height='"+this.objHeight+"' width='"+optsBoxWidth+"'>";
		html += "<div id='"+this.dvScroll+"' style='overflow: hidden; height: "+this.objHeight+"px;' tabindex='-1'></div></td>";
	}
	else if( this.lang == 'en') {
		html += "<td height='"+this.objHeight+"' width='"+optsBoxWidth+"'>";
		html += "<div id='"+this.dvScroll+"' style='overflow: hidden; height: "+this.objHeight+"px;' tabindex='-1'></div></td>";
				
		html += "<td height='"+this.objHeight+"' width='"+this.imgOpenerWidth+"'>";
		html += "<table tabindex='-1' cellspacing='0' cellpadding='0' border='0' width='"+this.imgOpenerWidth+"' class='tblScrollBar'><tr>";
		html += "<td id='"+this.imgUp+"' align='center' valign='middle' height='"+this.imgArrowsHeight+"'><img src='"+this.imgArrowUp+"' height='"+this.imgArrowsHeight+"' width='"+this.imgArrowsWidth+"' onclick='scrollAccelerate(\""+this.dvScroll+"\", \"down\")' onmouseover='scrollDown(\""+this.dvScroll+"\")' onmouseout='scrollStop()' /></td>";
		html += "</tr><tr><td height='"+scrollerSpace+"'> </td></tr><tr>";
		html += "<td id='"+this.imgDown+"' align='center' valign='middle' height='"+this.imgArrowsHeight+"'><img src='"+this.imgArrowDown+"' height='"+this.imgArrowsHeight+"' width='"+this.imgArrowsWidth+"' onclick='scrollAccelerate(\""+this.dvScroll+"\", \"up\")' onmouseover='scrollUp(\""+this.dvScroll+"\")' onmouseout='scrollStop()'/></td>";
		html += "</tr></table></td>";
	}
	
	html += "</tr></table>";
	
	divList = document.getElementById(this.divId);
	
	divList.innerHTML = html;
} // drawCombo


imgCombo.prototype.drawList = function()
{
	optsBoxWidth = eval(this.objWidth) - this.imgOpenerWidth;
	tmpWidth = optsBoxWidth - eval(this.tdImgOptWidth) ;
	
	html = "<table cellspacing='0' cellpadding='1' border='0' width='"+optsBoxWidth+"' class='tblComboList'>";
	
	itemsCount = this.Items.length;
	
	for( i=0; i<itemsCount; i++ ){
		html += "<tr class='rowComboMousOut' onclick='slectComboOption(this, \""+this.objName+"\","+this.Ids[i]+")' onmouseover='setComboRowClass(this, \"over\")' onmouseout='setComboRowClass(this, \"out\")'>";
		
		if( this.lang == 'ar') {
			html += "<td align='left' width='"+tmpWidth+"' class='tdComboOption'>"+this.Items[i]+"</td>";
			html += "<td align='center' valign='middle' width='"+this.tdImgOptWidth+"'><img height='"+this.imgOptHeight+"' width='"+this.imgOptWidth+"' src='"+this.Images[i]+"'/></td>";
		}
		else if( this.lang == 'en') {
			html += "<td align='center' valign='middle' width='"+this.tdImgOptWidth+"'><img height='"+this.imgOptHeight+"' width='"+this.imgOptWidth+"' src='"+this.Images[i]+"'/></td>";
			html += "<td align='right' width='"+tmpWidth+"' class='tdComboOption'>"+this.Items[i]+"</td>";
		}
		
		html += "</tr>";
	} // for( i=0; i<itemsCount; i++ )
	
	html += "</table>";
    
	divScroller = document.getElementById(this.dvScroll);
	
	divScroller.innerHTML = html;
} // drawList


imgCombo.prototype.openCombo = function()
{
	var divList = document.getElementById(this.divId);
	
	if (divList.style.display != 'none') {
		divList.style.display = 'none';
	}
	else {
		var tblCombo = document.getElementById(this.tblId);
		
		x = this.findPosX(tblCombo);
		y = this.findPosY(tblCombo) + this.imgOpenerHeight;
		
		divList.style.position = 'absolute';
		divList.style.left = x + 'px'; //fixing position
		divList.style.top = y + 4 + 'px'; //fixing position
		divList.style.display = '';
	}
} // openCombo()



imgCombo.prototype.findPosX = function(obj)
{
    var curleft = 0;
	
    if(obj.offsetParent)
		while(1) {
			curleft += obj.offsetLeft;
			if(!obj.offsetParent)
			break;
			obj = obj.offsetParent;
		}
    else if(obj.x)
        curleft += obj.x;
		
    return curleft;
} // findPosX()


imgCombo.prototype.findPosY = function(obj)
{
    var curtop = 0;
	
    if(obj.offsetParent)
		while(1) {
			curtop += obj.offsetTop;
			if(!obj.offsetParent)
			break;
			obj = obj.offsetParent;
		}
    else if(obj.y)
        curtop += obj.y;
		
    return curtop;
} // findPosY()





function setComboRowClass(obj, opt)
{
	if (opt == 'over')
		obj.className = 'rowComboMousOver';
	else if (opt == 'out')
		obj.className = 'rowComboMousOut';
} // setComboRowClass


var timeOutId = 0;
var scrollAmout = 3;

function scrollUp(obj)
{
	dvScroller = document.getElementById(obj);
	dvScroller.scrollTop = dvScroller.scrollTop + scrollAmout ;
	timeOutId = setTimeout("scrollUp('"+obj+"');", 50) ;
} // scrollUp()


function scrollDown(obj)
{
	dvScroller = document.getElementById(obj);
	dvScroller.scrollTop = dvScroller.scrollTop - scrollAmout ;
	timeOutId = setTimeout("scrollDown('"+obj+"');", 50) ;
} // scrollDown()


function scrollAccelerate(obj, where)
{
	clearTimeout(timeOutId) ;			
	scrollAmout += 1 ;
	
	if (where == 'up')
		scrollUp(obj) ;
	else if (where == 'down')
		scrollDown(obj) ;
} // scrollAccelerate()


function scrollStop()
{
	clearTimeout(timeOutId) ;
	scrollAmout = 3 ;
} // scrollStop()


function slectComboOption(row, obj, val)
{
	var hdnValue = document.getElementById('hdn_' + obj) ;
	var txtBox = document.getElementById('td_' + obj) ;
	var dvList = document.getElementById('dv_' + obj) ;
	var tdImage = document.getElementById('imgtd_' + obj) ;
	
	var selectedItem = row.cells[0].innerHTML;
	var selectedImage = row.cells[1].innerHTML;
	
	txtBox.innerHTML = selectedItem;
	tdImage.innerHTML = selectedImage;
	hdnValue.value = val;
	dvList.style.display = 'none'
	redirect('inner', 'convacs', val) ;
} // slectComboOption()

