/*

Milonic SCombo - JavaScript SELECTive Combo boxes.
Version 1.2 - Built: Tuesday August 24 2004
Copyright 2004 (c) Milonic Solutions Limited. All Rights Reserved.
This is a commercial software product, please visit http://www.milonic.com/ for more information.
See http://www.milonic.com/license.php for Commercial License Agreement
All Copyright statements must always remain in place in all files at all times
*******  PLEASE NOTE: THIS IS NOT FREE SOFTWARE, IT MUST BE LICENSED FOR ALL USE  ******* 

License Number: Unlicensed

*/

_d=document
SCombo = new Array()

// Custom Stuff goes here: ---------------------------------------------------------------
// Only the next 8 lines need to be edited. You need to tell SCombo which SELECT Boxes are 
// part of the SCombo system and you need to declare the names of the data arrays.


SCombo[0]=SComboLevel1      // Level1 Array Data
SCombo[1]=SComboLevel2      // Level2 Array Data 
SCombo[2]=SComboLevel3      // Level3 Array Data
SCombo[3]=SComboLevel4      // Level4 Array Data

frm1=_d.formi['Level1']   // Form SELECT container for Level1
frm2=_d.formi['Level2']   // Form SELECT container for Level2
frm3=_d.formi['Level3']   // Form SELECT container for Level3
frm4=_d.formi['Level4']   // Form SELECT container for Level4

                            // property: onlyPopulateNextBox
onlyPopulateNextBox=false;  // Set to true SCombo will only display data for the only next select box in the sequence.
                            // Set to false it will display ALL the data for all select Boxes
                            
                            
                            // property returnTextValues
returnTextValues=false;     // Set to true will change the values returned to your CGI script
                            // True will return the text equivalent and false will return the numerical indentifier

// End of custom stuff. ------------------------------------------------------------------

function changeReturnValues()
{
	if(returnTextValues)
	{
		for(_a=1;_a<=SCombo.length;_a++)
		{
			frm=eval("frm"+_a)
			fSi=frm.selectedIndex
			if(fSi>-1)
			{
				frm[fSi].value=frm[fSi].text
			}
		}
	}
}


function getSelNumber(sel)
{
	testnumber=0;
	gotnumber=0;
	while(!gotnumber)
	{
		testnumber++;
		if(eval("frm"+testnumber).name == sel.name)gotnumber=1;
	}
	return testnumber;
}

function getSelValue(sel)
{
	if (sel.selectedIndex == -1) return ("");
	return sel[sel.selectedIndex].value;
}

function pdchange(sel)
{
	num=getSelNumber(sel)
	populateBoxesTo=SCombo.length

	if(window.onlyPopulateNextBox)populateBoxesTo=num+1
	
	for(x=num;x<SCombo.length;x++)
	{
		par=SCombo[x]
		frm=eval("frm"+(x+1))
		frm.length=0;
		for(a=1;a<par.length;a++)
		{
			if(x<populateBoxesTo)
			{
			
				if(getSelValue(sel)==par[a+x-1])
				{
					opt=new Option(par[a+1+x], par[a+x]);
					j=frm.length;
					frm[j]=opt;
				}
			}
			a+=x+2
		}
	}

	parv=getSelNumber(sel)
	par=SCombo[getSelNumber(sel)-1]
	lnk=par[getSelValue(sel)*(parv+2)];
	if(lnk)location.href=lnk
	
}

function allFillSelect(what)
{
	par=SCombo[+what-1]
	frm=eval("frm"+what)
	frm.length = 0;
	for(a=1;a<par.length;a++)
	{
		opt=new Option(par[a+what], par[a+what-1]);
		j = frm.length;
		frm[j]=opt;		
		a=a+what+1
	}
}



function pdSet(sel, txt, bywhat)
{
	
	frm=eval("frm"+sel)
	if(frm.length<2)allFillSelect(sel)
	for(a=0;a<frm.length;a++)
	{
		if((bywhat=="text" && frm[a].text==txt) || (bywhat=="id" && frm[a].value==txt))
		{
			frm.selectedIndex=a
			pdchange(frm)
		}
	}
}




function pdSetByText(sel,txt)
{
	allFillSelect(sel)
	frm=eval("frm"+sel)
	for(a=0;a<frm.length;a++)
	{
		if(frm[a].text==txt)	
		{
			frm.selectedIndex=a
			pdchange(frm)
		}
	}
}

function pdSetByID(sel,txt)
{
	allFillSelect(sel)
	frm=eval("frm"+sel)
	for(a=0;a<frm.length;a++)
	{
		if(frm[a].value==txt)	
		{
			frm.selectedIndex=a
			pdchange(frm)
		}
	}
}

function changeData(what)
{
	par=SCombo[+what-1]
	frm=eval("frm"+what)
	frm.length = 0;
	for(a=1;a<par.length;a++)
	{
		opt=new Option(par[a+what], par[a]);
		j = frm.length;
		frm[j]=opt;		
		a=a+what
	}
}


var string = location.search.toLowerCase();
pdWhat(string);

function pdWhat(string){
if (string.indexOf("?add-")!=-1){
  allFillSelect(1)
  var x = string.split("-")
  document.formi.MemberItemCode.value = x[1];
}else if (string.indexOf("?mcode=")!=-1){
  allFillSelect(1)
}else if (string.indexOf("?edit-")!=-1){
  var x = string.split("-")
  Mode = x[0]
  ID = x[1]
  id1 = x[2]
  id2 = x[3]
  id3 = x[4]
  id4 = x[5]
  if(id1 != ""){pdSet(1,id1, "id")}
  if(id2 != ""){pdSet(2,id2, "id")}
  if(id3 != ""){pdSet(3,id3, "id")}
  if(id4 != ""){pdSet(4,id4, "id")}
  document.formi.ProductID.value = ID;
}else{
  allFillSelect(1)
 }
}


//pdSet(1,"Europe","text")             // Tell SCombo to jump to the text item: 'Europe' in Box 1
//pdSet(2,"United Kingdom","text")     // Tell SCombo to jump to the text item: 'United Kingdom' in box 2
//pdSet(3,"West Midlands","text")      // Tell SCombo to jump to the text item: 'West Midlands' in box 3
//pdSet(4,"West Midlands","text")      // Tell SCombo to jump to the text item: 'West Midlands' in box 4


//pdSet(1,2,"id")                        // Tell SCombo to jump to the item with id of 6 in box 1
//pdSet(2,10,"id")                       // Tell SCombo to jump to the item with id of 193 in box 2
//pdSet(3,34,"id")                      // Tell SCombo to jump to the item with id of 106 in box 3
//pdSet(4,36,"id")                       // Tell SCombo to jump to the item with id of 106 in box 4


//allFillSelect(1)                     // Tell SCombo to show ALL data in box 1
//allFillSelect(2)                     // Tell SCombo to show ALL data in box 2
//allFillSelect(3)                     // Tell SCombo to show ALL data in box 3
//allFillSelect(4)                     // Tell SCombo to show ALL data in box 4



//#################################################################


_d=document
SComboa = new Array()

// Custom Stuff goes here: ---------------------------------------------------------------
// Only the next 8 lines need to be edited. You need to tell SCombo which SELECT Boxes are 
// part of the SCombo system and you need to declare the names of the data arrays.


SComboa[0]=SComboLevel1a      // Level1 Array Data
SComboa[1]=SComboLevel2a      // Level2 Array Data 
SComboa[2]=SComboLevel3a      // Level3 Array Data
SComboa[3]=SComboLevel4a      // Level4 Array Data

frma1=_d.formi['Level1a']   // Form SELECT container for Level1
frma2=_d.formi['Level2a']   // Form SELECT container for Level2
frma3=_d.formi['Level3a']   // Form SELECT container for Level3
frma4=_d.formi['Level4a']   // Form SELECT container for Level4

                            // property: onlyPopulateNextBox
onlyPopulateNextBox=false;  // Set to true SCombo will only display data for the only next select box in the sequence.
                            // Set to false it will display ALL the data for all select Boxes
                            
                            
                            // property returnTextValues
returnTextValues=false;     // Set to true will change the values returned to your CGI script
                            // True will return the text equivalent and false will return the numerical indentifier

// End of custom stuff. ------------------------------------------------------------------

function changeReturnValues1()
{
	if(returnTextValues)
	{
		for(_a=1;_a<=SComboa.length;_a++)
		{
			frm=eval("frma"+_a)
			fSi=frm.selectedIndex
			if(fSi>-1)
			{
				frm[fSi].value=frm[fSi].text
			}
		}
	}
}


function getSelNumber1(sel)
{
	testnumber=0;
	gotnumber=0;
	while(!gotnumber)
	{
		testnumber++;
		if(eval("frma"+testnumber).name == sel.name)gotnumber=1;
	}
	return testnumber;
}

function getSelValue1(sel)
{
	if (sel.selectedIndex == -1) return ("");
	return sel[sel.selectedIndex].value;
}

function pdchange1(sel)
{
	num=getSelNumber1(sel)
	populateBoxesTo=SComboa.length

	if(window.onlyPopulateNextBox)populateBoxesTo=num+1
	
	for(x=num;x<SComboa.length;x++)
	{
		par=SComboa[x]
		frm=eval("frma"+(x+1))
		frm.length=0;
		for(a=1;a<par.length;a++)
		{
			if(x<populateBoxesTo)
			{
			
				if(getSelValue1(sel)==par[a+x-1])
				{
					opt=new Option(par[a+1+x], par[a+x]);
					j=frm.length;
					frm[j]=opt;
				}
			}
			a+=x+2
		}
	}

	parv=getSelNumber1(sel)
	par=SComboa[getSelNumber1(sel)-1]
	lnk=par[getSelValue1(sel)*(parv+2)];
	if(lnk)location.href=lnk
	
}

function allFillSelect1(what)
{
	par=SComboa[+what-1]
	frm=eval("frma"+what)
	frm.length = 0;
	for(a=1;a<par.length;a++)
	{
		opt=new Option(par[a+what], par[a+what-1]);
		j = frm.length;
		frm[j]=opt;		
		a=a+what+1
	}
}



function pdSet1(sel, txt, bywhat)
{
	
	frm=eval("frma"+sel)
	if(frm.length<2)allFillSelect1(sel)
	for(a=0;a<frm.length;a++)
	{
		if((bywhat=="text" && frm[a].text==txt) || (bywhat=="id" && frm[a].value==txt))
		{
			frm.selectedIndex=a
			pdchange1(frm)
		}
	}
}




function pdSetByText1(sel,txt)
{
	allFillSelect1(sel)
	frm=eval("frma"+sel)
	for(a=0;a<frm.length;a++)
	{
		if(frm[a].text==txt)	
		{
			frm.selectedIndex=a
			pdchange1(frm)
		}
	}
}

function pdSetByID1(sel,txt)
{
	allFillSelect1(sel)
	frm=eval("frma"+sel)
	for(a=0;a<frm.length;a++)
	{
		if(frm[a].value==txt)	
		{
			frm.selectedIndex=a
			pdchange1(frm)
		}
	}
}

function changeData1(what)
{
	par=SComboa[+what-1]
	frm=eval("frma"+what)
	frm.length = 0;
	for(a=1;a<par.length;a++)
	{
		opt=new Option(par[a+what], par[a]);
		j = frm.length;
		frm[j]=opt;		
		a=a+what
	}
}


var string = location.search.toLowerCase();
pdWhat1(string);

function pdWhat1(string){
if (string.indexOf("?mcode=")!=-1){
  allFillSelect1(1)
 }
}

//#################################################################


