

function show(parameter)
{

  element = document.getElementById(parameter);

   
   if (navigator.appName.indexOf("Explorer")> -1) 
     temp="inline";
   else 
     temp="table-row";
   
     
  if(element.style.display=="none")
  {
 
    element.style.display=temp;
     
  }
  else
  {
    element.style.display="none";
    
  }

}



//Function to clear a Select list
function clearIt(elementId) {
   var temp = document.getElementById(elementId);
   temp.length = 0 ; 
}

function clearSelected(elementId)
{
   	var source = document.getElementById(elementId);
	var i = source.length
  	while(i--) if( source.options[i].selected) source.options[i] = null;
  	 else source.options[i].selected=true;
  				
}
function clearModule(elementId1,elementId2)
{
	//alert (elementId1);
   	var source = document.getElementById(elementId1);
	var source2 = document.getElementById(elementId2);
	source.value='';
  	source2.value='';
  				
}

function checkForm()
{
	
		
   	var title = document.getElementById('title');
   	var tree  = document.getElementById('treeName');
	var customer  = document.getElementById('customer');
   	//var version  = document.getElementById('version').options[0].text;
	var versionindex = document.getElementById("version").selectedIndex;
	var version = document.getElementById("version");
	//version.options[versionindex].selected=true;
	//document.getElementById('customer').size = 1;                // reduce screen size
	var customerpicked = '';
	for (i=0; i<document.getElementById('customer').options.length; i++) {
		if (document.getElementById('customer').options[i].value != "") { customerpicked += document.getElementById('customer').options[i].value+';'; }
	}
   	//alert(customerpicked);
   	if ( (title.value == '') || (tree.value == '') || (customerpicked.value == '') || (versionindex == '0')) 
   	{
   		//alert(customer.value);
		//alert('Version: '+version.value+' ' + versionindex);
   		if (title.value == '') title.style.backgroundColor='#FFFF99';
   		  else title.style.backgroundColor='#ffffff';
   		if (tree.value == '') tree.style.backgroundColor='#FFFF99';
   		  else tree.style.backgroundColor='#ffffff';
   		if (customerpicked == '') customer.style.backgroundColor='#FFFF99';
   		  else customer.style.backgroundColor='#ffffff';
		 if (versionindex == '0') version.style.backgroundColor='#FFFF99';
   		  else version.style.backgroundColor='#ffffff';

   		alert('Please add required fields');
   		
   		return false;	
   	}
   		
}


// function that opens popupwindow for customer select
function PopupWindow (w,h) {
  var args = 'width='+w+',height='+h+',resizable';
  F = window.open("../customer/popupSearch.ssp","Popup",args);
}

// function that opens popupwindowUser for user select
function PopupWindowUser (w,h,fieldBox) {
  var args = 'width='+w+',height='+h+',resizable';
  F = window.open("../popup/userSearch.ssp?field="+fieldBox,"Popup",args);
}

// function that opens popupwindowUser for ticket select
function PopupWindowHistory (path,w,h) {
  var args = 'width='+w+',height='+h+',resizable';
  F = window.open(path,"Popup",args);

}

// function that opens popup for selecting PSP Codes
function PopupPSPCodes (w,h) {
  var args = 'width='+w+',height='+h+',resizable';
  F = window.open("../popup/popupPSP.ssp","Popup",args);

}
// function that opens popupwindowUser for ticket select
function OpenBT (path) {
  F = window.open(path,"ptBTWindow");

}

// function that opens popupwindowUser for ticket select
function OpenCS (path) {
  F = window.open(path,"ptCSWindow");

}

// function that sets Focus and WindowName
function setNameAndFocusBT()
{
  if (window.focus) window.focus();
  window.name='ptBTWindow';
}

function setNameAndFocusCS()
{
  if (window.focus) window.focus();
  window.name='ptCSWindow';
}

function extractFilename(what) {
	
    if (what.indexOf('/') > -1)
        answer = what.substring(what.lastIndexOf('/')+1,what.length);
    else
        answer = what.substring(what.lastIndexOf('\\')+1,what.length);
    

    return answer;
}
   


function extract(what) {
    if (what.indexOf('/') > -1)
        answer = what.substring(what.lastIndexOf('/')+1,what.length);
        
    else answer = what.substring(what.lastIndexOf('\\')+1,what.length);
    
    var inputBox = document.getElementById('transition');
    
    inputBox.value = answer;
}

function submitToHidden(self,field) 
{
  var fileBox  = document.getElementById(self);
  var hiddenBox = document.getElementById(field);
  hiddenBox.value = fileBox.value;
}

function fillFields()
{
	
 var source = document.getElementById("liste1");

  for(var i = 0; i < 10; i++)
  
        {
              switch(i) {
 		case 0:
 		  col = "tab_col1";
 		  break;
 		case 1:
 		  col = "tab_col2";
 		  break;
 		case 2:
 		  col = "tab_col3";
 		  break;
 		case 3:
		  col = "tab_col4";
 		  break;
 		case 4:
 		  col = "tab_col5";
 		  break;
 		case 5:
 		  col = "tab_col6";
 		  break;
 		case 6:
 		  col = "tab_col7";
 		  break;
 		case 7:
		  col = "tab_col8";
 		  break;
 		case 8:
		  col = "tab_col9";
 		  break;
 		case 9:
		  col = "tab_col10";
 		  break;  
		
	     }	
	     
	     var selectedCol = document.getElementById(col);
	     if (selectedCol)
	     {
	      
	     
	     if (selectedCol.text != '')
	     {
	       for(var j = 0; j < source.length; j++)
               {
                  var s = source.options[j].text;
                
                  
                  if (s == selectedCol.value)  
                  {
                  	source.selectedIndex=j;
                    	moveTo(document.forms["testform"],"liste1","liste2",true,false);
                    	break;
                  }
               } 
             }
        }
	   
	     
	 }
	
}

function moveTo(form, from, to, del,update)
{
	
    if(!form || !form.elements) return alert('Kein Formular');

    var source = document.getElementById(from);
    var target = document.getElementById(to);

    if(!source) return alert(from + ' existiert nicht im Formular!');
    var idx = source.selectedIndex;

    if(target)
    {
        for(var i = 0; i < source.length; i++)
        {
              var s = source.options[i];
              if(s.selected) target[target.length] = new Option(  s.text, s.value);
        
        }
    }
    // einträge löschen
    if(!target || del)
    {
         var i = source.length;
         while(i--) if( source.options[i].selected) source.options[i] = null;
    }
    
    source.selectedIndex = idx-1;

   
    if (update) updateCols(document);
     
}


function moveToList(form, from, to, del)
{
	
    if(!form || !form.elements) return alert('Kein Formular');

    var source = document.getElementById(from);
    var target = document.getElementById(to);

    if(!source) return alert(from + ' existiert nicht im Formular!');
    var idx = source.selectedIndex;

    if(target)
    {
        for(var i = 0; i < source.length; i++)
        {
              var s = source.options[i];
              if(s.selected) target[target.length] = new Option(  s.text, s.value);
        
        }
    }
    // einträge löschen
    if(!target || del)
    {
         var i = source.length;
         while(i--) if( source.options[i].selected) source.options[i] = null;
    }
    
    source.selectedIndex = idx-1;

 
    for(var i = 0; i < target.length; i++)
        {target.options[i].selected = true}

    for(var i = 0; i < source.length; i++)
        {source.options[i].selected = true}
        
}

function exchangeElements(listBox,up)
{
	
    
    var source = document.getElementById(listBox);
    var idx = source.selectedIndex;


    if (up) 
    {   
    	if (idx > 0)
    	{
    	  var element = source.options[idx-1].text;
    	  source.options[idx-1].text = source.options[idx].text;
    	  source.options[idx].text = element;
    	  source.selectedIndex = idx-1;   
    	}
    	
        
    }
    else
    {
	if (idx < source.length-1)
    	{
    	  var element = source.options[idx+1].text;	
    	  source.options[idx+1].text = source.options[idx].text;
    	  source.options[idx].text = element;  
    	  source.selectedIndex = idx+1;  
    	}
            	
    }

   	
   updateCols(document);
   
}

function updateCols(doc)

{
  var target = doc.getElementById("liste2");
 
 
        for(var i = 0; i < 10; i++)
        {
              switch(i) {
 		case 0:
 		  col = "tab_col1";
 		  break;
 		case 1:
 		  col = "tab_col2";
 		  break;
 		case 2:
 		  col = "tab_col3";
 		  break;
 		case 3:
		  col = "tab_col4";
 		  break;
 		case 4:
 		  col = "tab_col5";
 		  break;
 		case 5:
 		  col = "tab_col6";
 		  break;
 		case 6:
 		  col = "tab_col7";
 		  break;
 		case 7:
		  col = "tab_col8";
 		  break;
 		case 8:
		  col = "tab_col9";
 		  break;
 		case 9:
		  col = "tab_col10";
 		  break;  
		
	     }
	        var hiddenBox = doc.getElementById(col);
	        
	      
	        if (i < target.length  )
	        {
                  var s = target.options[i].text;
                  hiddenBox.value = s;
                }
                
                else hiddenBox.value = '';
        }
        
       
        
  
    
    
}


