	/************************************************************************************************************
	(C) www.dhtmlgoodies.com, October 2005
	
	This is a script from www.dhtmlgoodies.com. You will find this and a lot of other scripts at our website.	
	
	Terms of use:
	You are free to use this script as long as the copyright message is kept intact. However, you may not
	redistribute, sell or repost it without our permission.
	
	Updated:
		
		March, 14th, 2006 - Create new tabs dynamically
		March, 15th, 2006 - Dynamically delete a tab
		
	Thank you!
	
	www.dhtmlgoodies.com
	Alf Magne Kalleland
	
	************************************************************************************************************/		
	var textPadding = 3; // Padding at the left of tab text - bigger value gives you wider tabs
	var strictDocType = true; 
	var tabView_maxNumberOfTabs = 6;	// Maximum number of tabs
	
	/* Don't change anything below here */
	if(!dhtmlgoodies_tabObjProduct){
	    var dhtmlgoodies_tabObjProduct = new Array();
	}
	var activeTabIndexProduct = new Array();
	var MSIE = navigator.userAgent.indexOf('MSIE')>=0?true:false;
	
	var regExp = new RegExp(".*MSIE ([0-9]\.[0-9]).*","g");
	var navigatorVersion = navigator.userAgent.replace(regExp,'$1');
	
	var ajaxObjects = new Array();
	var tabView_countTabsProduct = new Array();
	var tabViewHeight = new Array();
	var tabDivCounter = 0;
	var closeImageHeight = 8;	// Pixel height of close buttons
	var closeImageWidth = 8;	// Pixel height of close buttons
	var tab_sepProduct='';
	var tab_sepProduct_active='';
	
	
	function setPaddingProduct(obj,padding){
		var span = obj.getElementsByTagName('SPAN')[0];
		span.style.paddingLeft = padding + 'px';	
		span.style.paddingRight = padding + 'px';	
	}
	
	function showTabProduct(parentId,tabIndex)
	{
		var parentId_div = parentId + "_";
		if(!document.getElementById('tabView' + parentId_div + tabIndex)){
			return;
		}
		if(activeTabIndexProduct[parentId]>=0){
			if(activeTabIndexProduct[parentId]==tabIndex){
				return;
			}
	
			var obj = document.getElementById('tabTab'+parentId_div + activeTabIndexProduct[parentId]);
			
			obj.className='tabInactiveProduct';
			var img = obj.getElementsByTagName('IMG')[0];
			if(img.src.indexOf('tab_')==-1)img = obj.getElementsByTagName('IMG')[1];
			/*img.src = 'images/tab_sep.gif';*/
			if(tab_sepProduct!=''){
				img.src = tab_sepProduct;
			} else {
				img.src = 'http://localhost/UDS/images/tab_sep.gif';
			}
			document.getElementById('tabView' + parentId_div + activeTabIndexProduct[parentId]).style.display='none';
		}
		
		var thisObj = document.getElementById('tabTab'+ parentId_div +tabIndex);	
			
		thisObj.className='tabActiveProduct';
		var img = thisObj.getElementsByTagName('IMG')[0];
		if(img.src.indexOf('tab_')==-1)img = thisObj.getElementsByTagName('IMG')[1];
		/*img.src = 'images/tab_sep_active.gif';*/
		if(tab_sepProduct_active!=''){
			img.src = tab_sepProduct_active;
		} else {
			img.src = 'http://localhost/UDS/images/tab_sep_active.gif';
		}
		document.getElementById('tabView' + parentId_div + tabIndex).style.display='block';
		activeTabIndexProduct[parentId] = tabIndex;
		

		var parentObj = thisObj.parentNode;
		var aTab = parentObj.getElementsByTagName('DIV')[0];
		countObjects = 0;
		var startPos = 2;
		var previousObjectActive = false;
		while(aTab){
			if(aTab.tagName=='DIV'){
				if(previousObjectActive){
					previousObjectActive = false;
					startPos-=2;
				}
				if(aTab==thisObj){
					startPos-=2;
					previousObjectActive=true;
					setPaddingProduct(aTab,textPadding+1);
				}else{
					setPaddingProduct(aTab,textPadding);
				}
				
				//aTab.style.left = startPos + 'px';
				countObjects++;
				startPos+=2;
			}			
			aTab = aTab.nextSibling;
		}
		
		return;
	}
	
	function tabClickProduct()
	{
		var idArray = this.id.split('_');		
		showTabProduct(this.parentNode.parentNode.id,idArray[idArray.length-1].replace(/[^0-9]/gi,''));
	}
	
	function rolloverTabProduct()
	{
		if(this.className.indexOf('tabInactiveProduct')>=0){
			this.className='inactiveTabOverProduct';
			var img = this.getElementsByTagName('IMG')[0];
			if(img.src.indexOf('tab_')<=0)img = this.getElementsByTagName('IMG')[1];
			/*img.src = 'images/tab_sep_active.gif';*/
			if(tab_sepProduct_active){
				img.src = tab_sepProduct_active;
			} else {
				img.src = 'http://localhost/UDS/images/tab_sep_active.gif';
			}
			
		}
		
	}
	function rolloutTabProduct()
	{
		if(this.className ==  'inactiveTabOverProduct'){
			this.className='tabInactiveProduct';
			var img = this.getElementsByTagName('IMG')[0];
			if(img.src.indexOf('tab_')<=0)img = this.getElementsByTagName('IMG')[1];
			/*img.src = 'images/tab_sep.gif';*/
			if(tab_sepProduct!=''){
				img.src = tab_sepProduct;
			} else {
				img.src = 'http://localhost/UDS/images/tab_sep.gif';
			}
		}
		
	}
	
	function hoverTabViewCloseButtonProduct()
	{
		this.src = this.src.replace('close.gif','close_over.gif');
	}
	
	function stopHoverTabViewCloseButtonProduct()
	{
		this.src = this.src.replace('close_over.gif','close.gif');
	}
	
	function initTabsProduct(mainContainerID,tabTitles,activeTab,width,height,closeButtonArray,additionalTab, imgtab)
	{
		if(imgtab!='undefined'){
			if(imgtab.indexOf(':')!=-1){
				tab_sepProduct=imgtab.substr(0,imgtab.indexOf(':'));
				imgtab=imgtab.substr(imgtab.indexOf(':')+1);
				if(imgtab.indexOf(':')!=-1){
					tab_sepProduct_active=imgtab.substr(0,imgtab.indexOf(':'));
				} else {
					tab_sepProduct_active=imgtab;
				}
			}
		}
		
		if(!closeButtonArray)closeButtonArray = new Array();
		
		if(!additionalTab || additionalTab=='undefined'){			
			dhtmlgoodies_tabObjProduct[mainContainerID] = document.getElementById(mainContainerID);
			width = width + '';
			if(width.indexOf('%')<0)width= width + 'px';
			dhtmlgoodies_tabObjProduct[mainContainerID].style.width = width;
						
			height = height + '';
			if(height.length>0){
				if(height.indexOf('%')<0)height= height + 'px';
				dhtmlgoodies_tabObjProduct[mainContainerID].style.height = height;
			}
			
			tabViewHeight[mainContainerID] = height;
			
			var tabDiv = document.createElement('DIV');		
			var firstDiv = dhtmlgoodies_tabObjProduct[mainContainerID].getElementsByTagName('DIV')[0];	
			
			dhtmlgoodies_tabObjProduct[mainContainerID].insertBefore(tabDiv,firstDiv);	
			tabDiv.className = 'dhtmlgoodies_tabPaneProduct';			
			tabView_countTabsProduct[mainContainerID] = 0;

		}else{
			var tabDiv = dhtmlgoodies_tabObjProduct[mainContainerID].getElementsByTagName('DIV')[0];
			var firstDiv = dhtmlgoodies_tabObjProduct[mainContainerID].getElementsByTagName('DIV')[1];
			height = tabViewHeight[mainContainerID];
			activeTab = tabView_countTabsProduct[mainContainerID];		
	
			
		}
		
		for(var no=0;no<tabTitles.length;no++){
			var aTab = document.createElement('DIV');
			aTab.id = 'tabTab' + mainContainerID + "_" +  (no + tabView_countTabsProduct[mainContainerID]);
			aTab.onmouseover = rolloverTabProduct;
			aTab.onmouseout = rolloutTabProduct;
			aTab.onclick = tabClickProduct;
			aTab.className='tabInactiveProduct';
			tabDiv.appendChild(aTab);
			var span = document.createElement('SPAN');
			span.innerHTML = tabTitles[no];
			span.style.position = 'relative';
			aTab.appendChild(span);
			
			if(closeButtonArray[no]){
				var closeButton = document.createElement('IMG');
				closeButton.src = 'images/close.gif';
				closeButton.height = closeImageHeight + 'px';
				closeButton.width = closeImageHeight + 'px';
				closeButton.setAttribute('height',closeImageHeight);
				closeButton.setAttribute('width',closeImageHeight);
				closeButton.style.position='absolute';
				closeButton.style.top = '6px';
				closeButton.style.right = '0px';
				closeButton.onmouseover = hoverTabViewCloseButtonProduct;
				closeButton.onmouseout = stopHoverTabViewCloseButtonProduct;
				
				span.innerHTML = span.innerHTML + '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';	
				
				var deleteTxt = span.innerHTML+'';

				closeButton.onclick = function(){ deleteTabProduct(this.parentNode.innerHTML) };
				span.appendChild(closeButton);
			}
			
			var img = document.createElement('IMG');
			img.valign = 'bottom';
			/*img.src = 'images/tab_sep.gif';*/
			if(tab_sepProduct!=''){
				img.src = tab_sepProduct;
			} else {
				img.src = 'http://localhost/UDS/images/tab_sep.gif';
			}
			// IE5.X FIX
			if((navigatorVersion && navigatorVersion<6) || (MSIE && !strictDocType)){
				img.style.styleFloat = 'none';
				img.style.position = 'relative';	
				img.style.top = '4px'
				span.style.paddingTop = '4px';
				aTab.style.cursor = 'hand';
			}	// End IE5.x FIX
			aTab.appendChild(img);
		}

		var tabs = dhtmlgoodies_tabObjProduct[mainContainerID].getElementsByTagName('DIV');
		var divCounter = 0;
		for(var no=0;no<tabs.length;no++){
			if(tabs[no].className=='dhtmlgoodies_aTabProduct' && tabs[no].parentNode.id == mainContainerID){
				if(height.length>0)tabs[no].style.height = height;
				tabs[no].style.display='none';
				tabs[no].id = 'tabView' + mainContainerID + "_" + divCounter;
				divCounter++;
			}			
		}	
		tabView_countTabsProduct[mainContainerID] = tabView_countTabsProduct[mainContainerID] + tabTitles.length;
		
		showTabProduct(mainContainerID,activeTab);

		return activeTab;
	}	
	
	function showAjaxTabContentProduct(ajaxIndex,parentId,tabId)
	{
		var obj = document.getElementById('tabView'+parentId + '_' + tabId);
		obj.innerHTML = ajaxObjects[ajaxIndex].response;		
		
		/*var obj = document.getElementById('tabView'+parentId + '_' + tabId);
		str=ajaxObjects[ajaxIndex].response;
		str=str.substr(str.indexOf('<form'));
		str=str.substr(str.indexOf('>')+1);
		str=str.substr(0,str.indexOf('</form'));
		
		alert(str);
		obj.innerHTML = str;
		*/
	}
	
	function resetTabIdsProduct(parentId)
	{
		var tabTitleCounter = 0;
		var tabContentCounter = 0;
		
		
		var divs = dhtmlgoodies_tabObjProduct[parentId].getElementsByTagName('DIV');

		
		for(var no=0;no<divs.length;no++){
			if(divs[no].className=='dhtmlgoodies_aTabProduct'){
				divs[no].id = 'tabView' + parentId + '_' + tabTitleCounter;
				tabTitleCounter++;
			}
			if(divs[no].id.indexOf('tabTab')>=0){
				divs[no].id = 'tabTab' + parentId + '_' + tabContentCounter;	
				tabContentCounter++;
			}	
			
				
		}
	
		tabView_countTabsProduct[parentId] = tabContentCounter;
	}
	
	
	function createNewTabProduct(parentId,tabTitle,tabContent,tabContentUrl,closeButton)
	{
		if(tabView_countTabsProduct[parentId]>=tabView_maxNumberOfTabs)return;	// Maximum number of tabs reached - return
		var div = document.createElement('DIV');
		div.className = 'dhtmlgoodies_aTabProduct';
		dhtmlgoodies_tabObjProduct[parentId].appendChild(div);		

		var tabId = initTabsProduct(parentId,Array(tabTitle),0,'','',Array(closeButton),true);
		if(tabContent)div.innerHTML = tabContent;
		if(tabContentUrl){		
			var ajaxIndex = ajaxObjects.length;
			ajaxObjects[ajaxIndex] = new sack();
			ajaxObjects[ajaxIndex].requestFile = tabContentUrl;	// Specifying which file to get

			ajaxObjects[ajaxIndex].onCompletion = function(){ showAjaxTabContentProduct(ajaxIndex,parentId,tabId); };	// Specify function that will be executed after file has been found
			ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function	
		
		}
				
	}
	
	function getTabIndexByTitleProduct(tabTitle)
	{
		var regExp = new RegExp("(.*?)&nbsp.*$","gi");
		tabTitle = tabTitle.replace(regExp,'$1');
		for(var prop in dhtmlgoodies_tabObjProduct){
		    var test = dhtmlgoodies_tabObjProduct[prop];
		    if(Object.isElement(test)){
			    var divs = test.getElementsByTagName('DIV');
			    for(var no=0;no<divs.length;no++){
				    if(divs[no].id.indexOf('tabTab')>=0){
					    var span = divs[no].getElementsByTagName('SPAN')[0];
					    var regExp2 = new RegExp("(.*?)&nbsp.*$","gi");
					    var spanTitle = span.innerHTML.replace(regExp2,'$1');
    					
					    if(spanTitle == tabTitle){
    						
						    var tmpId = divs[no].id.split('_');						
						    return Array(prop,tmpId[tmpId.length-1].replace(/[^0-9]/g,'')/1);
					    }		
				    }
			    }
			}
		}
		
		return -1;
		
	}
	
	/* Call this function if you want to display some content from external file in one of the tabs 
	Arguments: Title of tab and relative path to external file */
	
	function addAjaxContentToTabProduct(tabTitle,tabContentUrl)
	{
		var index = getTabIndexByTitleProduct(tabTitle);
		if(index!=-1){
			var ajaxIndex = ajaxObjects.length;
			tabId = index[1];
			parentId = index[0];
			ajaxObjects[ajaxIndex] = new sack();
			ajaxObjects[ajaxIndex].requestFile = tabContentUrl;	// Specifying which file to get

			ajaxObjects[ajaxIndex].onCompletion = function(){ showAjaxTabContentProduct(ajaxIndex,index[0],index[1]); };	// Specify function that will be executed after file has been found
			ajaxObjects[ajaxIndex].runAJAX();		// Execute AJAX function				
			
		}	
	}

	
	
	function deleteTabProduct(tabLabel,tabIndex,parentId)
	{

		if(tabLabel){
			var index = getTabIndexByTitleProduct(tabLabel);
			if(index!=-1){
				deleteTabProduct(false,index[1],index[0]);
			}
			
		}else if(tabIndex>=0){
			if(document.getElementById('tabTab' + parentId + '_' + tabIndex)){
				var obj = document.getElementById('tabTab' + parentId + '_' + tabIndex);
				var id = obj.parentNode.parentNode.id;
				obj.parentNode.removeChild(obj);
				var obj2 = document.getElementById('tabView' + parentId + '_' + tabIndex);
				obj2.parentNode.removeChild(obj2);
				resetTabIdsProduct(parentId);
				activeTabIndexProduct[parentId]=-1;
				showTabProduct(parentId,'0');
			}			
		}
	
		
	}
	
	
