function setOptions(dest,val,defaultSelect)
{
	eval("arrayDest = "+dest.name);
	dest.length = 0;
	dest.options[0] = new Option(defaultSelect,''); 
	index = 1;
	
	if(val != '' && val != 0)
	{
	   for(i=0;i<arrayDest.length;i++)
	   {
		 if(arrayDest[i][2] == val || val == '')
		 {
			dest.options[index] = new Option(arrayDest[i][1],arrayDest[i][0]); 
			index++;
		 }
		
	   }
    }
	
}

function setOptions2(dest,val,val2,defaultSelect)
{
	
	eval("arrayDest = "+dest.name);
	dest.length = 0;
	dest.options[0] = new Option(defaultSelect,''); 
	index = 1;
	
	for(i=0;i<arrayDest.length;i++)
	{

		if((arrayDest[i][2] == val || val == '') && (arrayDest[i][3] == val2 || val2 == ''))
		{
			dest.options[index] = new Option(arrayDest[i][1],arrayDest[i][0]); 
			index++;
		}
		
	}
	
}


function setIndex(dest,index)
{
	selectedIndex = 0;
	for(i=0;i<dest.options.length;i++)
		if(dest.options[i].value == index)
			selectedIndex = i;
	dest.selectedIndex = selectedIndex;
}


function orderItems(s)
{
	for(i=0;i<s.length;i++)
	{
		if(s.options[i].selected && i>0)
		{
			preText = s.options[i-1].text;
			preValue = s.options[i-1].value;
			s.options[i-1].text = s.options[i].text;
			s.options[i-1].value = s.options[i].value;
			s.options[i].text=preText;
			s.options[i].value=preValue;
		}	
	}
}

//move selected options between the 2 menus, from source (s) to destination (d)
function moveItems(s,d)
{
	for(i=0;i<s.length;i++)
	{
		if(s.options[i].selected)
		{
			d.options[d.length]=new Option(s.options[i].text, s.options[i].value);
			s.options[i] = null;
			i--;
		}	
	}
}

//select All options in the menu
function selectAll(menu)
{
	for(i=0;i<menu.length;i++)
		menu.options[i].selected=true;
}

//check/Uncheck All checkboxes
function checkUncheckAll(theElement,selectAllFieldName) {
	
	var theForm = theElement.form, z = 0;
  
	for(z=0; z<theForm.length;z++)
    	if(theForm[z].type == 'checkbox')
		{
				/*theForm[z].checked = theElement.checked;*/
				theForm[z].checked = true;
		}
}
function UncheckAll(theElement,selectAllFieldName){
	
	var theForm = theElement.form, z = 0;
  
	for(z=0; z<theForm.length;z++)
    	if(theForm[z].type == 'checkbox')
		{
				theForm[z].checked = false;
		}
}

function checkUncheckAllWizard(theElement,selectAllFieldName) {

	var theForm = theElement, z = 0;
	
	if(typeof theForm.length == "undefined")
	{
		theForm.checked = selectAllFieldName.checked;
	}
	else
	{
		for(z=0; z<theForm.length;z++)
	  		theForm[z].checked = selectAllFieldName.checked;
	}
}

function SelectGateway(gateway, frm)
{
    //alert( frm.elements['payment_method'][2].checked)
    
    if(gateway == 'anz')   
    {
        frm.elements['payment_method'][2].checked = false;
        frm.elements['payment_method'][0].disabled = false;
        frm.elements['payment_method'][1].disabled = false;

        if(frm.elements['payment_method'][0].checked == false && frm.elements['payment_method'][1].checked == false)
            alert("Please select a Payment Method: Visa or Mastercard");
    }
    else
    {
        frm.elements['gateway'].checked = false;
        frm.elements['payment_method'][0].checked = false;
        frm.elements['payment_method'][1].checked = false;
        frm.elements['payment_method'][0].disabled = true;
        frm.elements['payment_method'][1].disabled = true;        
    }
}

//move selected options between the 2 menus, from source (s) to destination (d)
function moveItemsOptGroup(s,d)
{
    source_optgroup_length = s.getElementsByTagName('optgroup').length;
   // alert('source_optgroup_length='+source_optgroup_length);
	for(i=0; i< source_optgroup_length; i++)
	{
	    source_optgroup_element = s.getElementsByTagName('optgroup')[i];
	    source_options_length = source_optgroup_element.getElementsByTagName('option').length;
	    
	    //alert('source_options_length='+source_options_length);
	   
	    for(k=0; k < source_options_length; k++)
	    {
	    // alert('k='+k);
	       // alert('k='+k)
	        
	        var source_option_element = source_optgroup_element.getElementsByTagName('option')[k];
	        
	       // alert('k='+source_option_element.text)
	       
		    if(source_option_element.selected)
		    {
		        //NEW OPTION
		        new_option_text = document.createTextNode(source_option_element.text);
                new_option = document.createElement('option');
                new_option.appendChild(new_option_text);
    		    new_option.setAttribute("value", source_option_element.value);
    		    
    		    
		        foundoptgroupelement = "no";
    		    
		        optgrouplength = d.getElementsByTagName('optgroup').length;
    		    
    		   
		        for(j=0; j < optgrouplength; j++)
		        {
		            dest_optgroupe_element = d.getElementsByTagName('optgroup')[j];
    		        
		            if(dest_optgroupe_element.label == source_optgroup_element.label)
		            {
		                foundoptgroupelement = "yes";
    		           // optgroupelement.appendChild(source_option_element);
    		            
		               // new_opt_group = document.createElement('optgroup');
		               // new_opt_group.label = dest_optgroupe_element.label;
		               // new_opt_group.appendChild(new_option);
		                
		                //d.removeChild(dest_optgroupe_element);
		               // d.replaceChild(new_opt_group,dest_optgroupe_element);
		                
		                //optGroup = optgroupelement.cloneNode(true);
		                //optGroup.label = s.options[i].parentNode.label;
		               // optGroup.appendChild(theOption);
    		              
		                //d.removeChild(optgroupelement);
		               // d.appendChild(optGroup);
		               
		               //
		               dest_optgroupe_element.appendChild(new_option);
		               
                       // alert("krajno"+dest_optgroupe_element.label)
		            }
		        }//for(j=0; j < optgrouplength; j++)
    		    
		        if(foundoptgroupelement == "no")
		        {
                    new_opt_group = document.createElement('optgroup');
                    new_opt_group.label = source_optgroup_element.label;
                    
		            new_opt_group.appendChild(new_option);
		            d.appendChild(new_opt_group);
			    }

			    //remove
			    source_optgroup_element.removeChild(source_option_element);
			    k--;
			    source_options_length--;
		    }//if(source_option_element.selected)
		    
		}//for(k=0; k < source_options_length; k++)
	}//for(i=0; i< source_optgroup_length; i++)
}

function IsDefined(variable)
{
	return (typeof(variable) == "undefined")?  false: true;
}